@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.
- package/CHANGELOG.md +3 -0
- package/dist/needle-engine.bundle.js +1467 -222
- package/dist/needle-engine.bundle.light.js +1467 -222
- package/dist/needle-engine.bundle.light.min.js +32 -32
- package/dist/needle-engine.bundle.light.umd.cjs +3 -3
- package/dist/needle-engine.bundle.min.js +3 -3
- package/dist/needle-engine.bundle.umd.cjs +3 -3
- package/dist/needle-engine.light.d.ts +9 -9
- package/lib/engine/engine_types.d.ts +162 -17
- package/lib/engine-components/Animator.d.ts +129 -21
- package/lib/engine-components/Animator.js +115 -21
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.d.ts +161 -32
- package/lib/engine-components/AnimatorController.js +176 -29
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioListener.d.ts +16 -5
- package/lib/engine-components/AudioListener.js +16 -5
- package/lib/engine-components/AudioListener.js.map +1 -1
- package/lib/engine-components/AudioSource.d.ts +120 -28
- package/lib/engine-components/AudioSource.js +120 -37
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/AvatarLoader.d.ts +61 -0
- package/lib/engine-components/AvatarLoader.js +61 -1
- package/lib/engine-components/AvatarLoader.js.map +1 -1
- package/lib/engine-components/AxesHelper.d.ts +19 -1
- package/lib/engine-components/AxesHelper.js +19 -1
- package/lib/engine-components/AxesHelper.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.d.ts +26 -0
- package/lib/engine-components/BoxHelperComponent.js +26 -0
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +126 -37
- package/lib/engine-components/Camera.js +139 -37
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CameraUtils.js +20 -0
- package/lib/engine-components/CameraUtils.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +95 -21
- package/lib/engine-components/Collider.js +100 -23
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +554 -106
- package/lib/engine-components/Component.js +352 -81
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/DragControls.d.ts +95 -21
- package/lib/engine-components/DragControls.js +126 -32
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/DropListener.d.ts +99 -16
- package/lib/engine-components/DropListener.js +119 -14
- package/lib/engine-components/DropListener.js.map +1 -1
- package/lib/engine-components/Light.d.ts +102 -5
- package/lib/engine-components/Light.js +102 -44
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/NeedleMenu.d.ts +28 -11
- package/lib/engine-components/NeedleMenu.js +28 -11
- package/lib/engine-components/NeedleMenu.js.map +1 -1
- package/lib/engine-components/Networking.d.ts +37 -5
- package/lib/engine-components/Networking.js +37 -5
- package/lib/engine-components/Networking.js.map +1 -1
- package/lib/engine-components/SceneSwitcher.js +44 -0
- package/lib/engine-components/SceneSwitcher.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.d.ts +66 -1
- package/lib/engine-components/SpatialTrigger.js +74 -2
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.d.ts +66 -4
- package/lib/engine-components/SpectatorCamera.js +132 -6
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SyncedTransform.d.ts +45 -6
- package/lib/engine-components/SyncedTransform.js +45 -6
- package/lib/engine-components/SyncedTransform.js.map +1 -1
- package/lib/engine-components/TransformGizmo.d.ts +49 -3
- package/lib/engine-components/TransformGizmo.js +49 -3
- package/lib/engine-components/TransformGizmo.js.map +1 -1
- package/lib/engine-components/webxr/WebXR.d.ts +131 -22
- package/lib/engine-components/webxr/WebXR.js +132 -23
- package/lib/engine-components/webxr/WebXR.js.map +1 -1
- package/lib/engine-components-experimental/networking/PlayerSync.d.ts +82 -9
- package/lib/engine-components-experimental/networking/PlayerSync.js +76 -11
- package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_types.ts +179 -18
- package/src/engine-components/Animator.ts +142 -22
- package/src/engine-components/AnimatorController.ts +184 -34
- package/src/engine-components/AudioListener.ts +16 -5
- package/src/engine-components/AudioSource.ts +126 -37
- package/src/engine-components/AvatarLoader.ts +61 -2
- package/src/engine-components/AxesHelper.ts +21 -1
- package/src/engine-components/BoxHelperComponent.ts +26 -0
- package/src/engine-components/Camera.ts +147 -41
- package/src/engine-components/CameraUtils.ts +20 -0
- package/src/engine-components/Collider.ts +102 -27
- package/src/engine-components/Component.ts +605 -129
- package/src/engine-components/DragControls.ts +134 -38
- package/src/engine-components/DropListener.ts +143 -23
- package/src/engine-components/Light.ts +105 -44
- package/src/engine-components/NeedleMenu.ts +29 -11
- package/src/engine-components/Networking.ts +37 -6
- package/src/engine-components/SceneSwitcher.ts +48 -1
- package/src/engine-components/SpatialTrigger.ts +80 -3
- package/src/engine-components/SpectatorCamera.ts +136 -18
- package/src/engine-components/SyncedTransform.ts +50 -7
- package/src/engine-components/TransformGizmo.ts +49 -4
- package/src/engine-components/webxr/WebXR.ts +144 -27
- 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=X.isMobileDevice()||X
|
|
|
130
130
|
#__vconsole .vc-mask {
|
|
131
131
|
overflow: hidden;
|
|
132
132
|
}
|
|
133
|
-
`,Qi?.prepend(n),s===!0&&Dm()<=0&&ob(),console.log("\u{1F335} Debug console has loaded")}},t.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),cc=!1,hi=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function fP(){if(!globalThis.VConsole)return;const s=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+s._id+" iframe");return s.on("renderTab",function(i){const n=globalThis["needle:codegen_files"];if(!n||n.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);s.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';i(h)}),s.on("show",function(){const i=t();i&&i.src!==s.fullUrl&&(i.src=s.fullUrl)}),s.on("hide",function(){const i=t();i&&(i.src="")}),s.on("addTopBar",function(i){var n=new Array;n.push({name:"Open in new window \u2197",onClick:function(o){window.open(s.fullUrl,"_blank"),hi?.hide()}}),n.push({name:"Reload",onClick:function(o){const r=t();r&&(r.src=s.fullUrl)}}),n.push({name:"Fullscreen",onClick:function(o){const r=t();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),i(n)}),s}function yP(){return document.querySelector("#__vconsole .vc-switch")||null}function vP(){return document.querySelector("#__vconsole")||null}const cb=O("debugdefines");uo('if(!globalThis[""4.3.0-alpha""]) globalThis[""4.3.0-alpha""] = "0.0.0";'),uo('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),uo('if(!globalThis[""
|
|
133
|
+
`,Qi?.prepend(n),s===!0&&Dm()<=0&&ob(),console.log("\u{1F335} Debug console has loaded")}},t.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),cc=!1,hi=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function fP(){if(!globalThis.VConsole)return;const s=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+s._id+" iframe");return s.on("renderTab",function(i){const n=globalThis["needle:codegen_files"];if(!n||n.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);s.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';i(h)}),s.on("show",function(){const i=t();i&&i.src!==s.fullUrl&&(i.src=s.fullUrl)}),s.on("hide",function(){const i=t();i&&(i.src="")}),s.on("addTopBar",function(i){var n=new Array;n.push({name:"Open in new window \u2197",onClick:function(o){window.open(s.fullUrl,"_blank"),hi?.hide()}}),n.push({name:"Reload",onClick:function(o){const r=t();r&&(r.src=s.fullUrl)}}),n.push({name:"Fullscreen",onClick:function(o){const r=t();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),i(n)}),s}function yP(){return document.querySelector("#__vconsole .vc-switch")||null}function vP(){return document.querySelector("#__vconsole")||null}const cb=O("debugdefines");uo('if(!globalThis[""4.3.0-alpha.1""]) globalThis[""4.3.0-alpha.1""] = "0.0.0";'),uo('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),uo('if(!globalThis[""Mon Mar 03 2025 10:03:55 GMT+0100 (Central European Standard Time)""]) globalThis[""Mon Mar 03 2025 10:03:55 GMT+0100 (Central European Standard Time)""] = "unknown";'),uo('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";'),uo('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.3.0-alpha.1";'),uo('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),uo('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Mar 03 2025 10:03:55 GMT+0100 (Central European Standard Time)";'),uo('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');const _s="4.3.0-alpha.1",Rd="undefined",tg="Mon Mar 03 2025 10:03:55 GMT+0100 (Central European Standard Time)";cb&&console.log(`Engine version: ${_s} (generator: ${Rd})
|
|
134
134
|
Project built at ${tg}`);const dc="npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9",Sn="needle_isActiveInHierarchy",_r="builtin_components",uc="needle_editor_guid";function uo(s){try{(0,eval)(s)}catch(t){cb&&console.error(t)}}const bP='<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>',_P=btoa(bP),wP="data:image/svg+xml;base64,"+_P,xP=wP,SP=`<?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(SP);const CP='<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>',OP=btoa(CP),PP="data:image/svg+xml;charset=utf-8;base64,"+OP,kP=PP,MP=O("debugpatch");function Td(s,t,i,n){const o=MP===t;if(!i&&!n)return;const r=t+"___needle";TP(s,t,i,n);const l=Object.getOwnPropertyDescriptor(s,t),c=s[t];o&&console.log("Patch",s.constructor.name,t,l,c),l?(o&&console.log("Apply patch with existing descriptor",s.constructor.name,t,l),typeof l.value=="function"&&(s[t]=db(l.value,s,t))):(o&&console.log("Create patch with new property",s.constructor.name,t,l),Object.defineProperty(s,t,{set:function(h){if(typeof h=="function")this[r]=db(h,s,t);else{const d=this[r];ub(s,t,this,d,h),this[r]=h,pb(s,t,this,d,h)}},get:function(){const h=this[r];return typeof h=="function"&&h[r]?h[r]:h}}))}function RP(s,t,i){const n=sg(s,t);if(n)for(let o=n.length-1;o>=0;o--){const r=n[o];r.prefix===i&&(r.prefix=null),r.postfix===i&&(r.postfix=null),!r.prefix&&!r.postfix&&n.splice(o,1)}}const hb=Symbol("Needle:Patches:WrappedFunction");function db(s,t,i){if(s[hb])return s;const n=function(...o){ub(t,i,this,...o);const r=s.apply(this,o);return pb(t,i,this,r,...o),r};return n[hb]=!0,n}const Ed="Needle:Patches";function ig(){return globalThis[Ed]||(globalThis[Ed]=new WeakMap),globalThis[Ed]}function sg(s,t){const i=ig().get(s);return i?i.get(t):null}function TP(s,t,i,n){let o=ig().get(s);o||(o=new Map,ig().set(s,o));let r=o.get(t);r||(r=[],o.set(t,r)),r.push({prefix:i,postfix:n})}function ub(s,t,i,...n){var o;if(!i)return;const r=sg(s,t);if(r)for(const l of r)(o=l.prefix)==null||o.call(i,...n)}function pb(s,t,i,n,...o){var r;if(!i)return;const l=sg(s,t);if(l)for(const c of l)(r=c.postfix)==null||r.call(i,n,...o)}const ka=[];function Ad(s){ka.indexOf(s)===-1&&ka.push(s)}function EP(s){const t=ka.indexOf(s);t!==-1&&ka.splice(t,1)}const Ma=[];function ng(s){Ma.indexOf(s)===-1&&Ma.push(s)}function AP(s){const t=Ma.indexOf(s);t!==-1&&Ma.splice(t,1)}function mb(s){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:s}));for(let t=0;t<ka.length;t++)ka[t](s)}function gb(s){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:s}));for(let t=0;t<Ma.length;t++)Ma[t](s)}const pt=O("debuginput");var Id=(s=>(s.Mouse="mouse",s.Touch="touch",s.Controller="controller",s.Hand="hand",s))(Id||{}),Be=(s=>(s.PointerDown="pointerdown",s.PointerUp="pointerup",s.PointerMove="pointermove",s.KeyDown="keydown",s.KeyUp="keyup",s.KeyPressed="keypress",s))(Be||{});class Cn extends PointerEvent{constructor(t,i,n){super(t,n),a(this,"clientZ"),a(this,"deviceIndex"),a(this,"origin"),a(this,"source"),a(this,"mode"),a(this,"_ray"),a(this,"space"),a(this,"isClick",!1),a(this,"isDoubleClick",!1),a(this,"_used",!1),a(this,"_pointerid"),a(this,"_pointerType"),a(this,"_type"),a(this,"metadata",{}),a(this,"intersections",new Array),a(this,"_immediatePropagationStopped",!1),a(this,"_propagationStopped",!1),this.clientZ=n.clientZ,this._pointerid=n.pointerId,this._pointerType=n.pointerType,this._type=t,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 no(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(t){this._ray=t}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 t;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(t=this.source)==null||t.stopImmediatePropagation()}stopPropagation(){var t;this._propagationStopped=!0,super.stopPropagation(),(t=this.source)==null||t.stopPropagation(),pt&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class pc extends KeyboardEvent{constructor(t,i,n){super(t,n),a(this,"source"),this.source=i}stopImmediatePropagation(){var t;super.stopImmediatePropagation(),(t=this.source)==null||t.stopImmediatePropagation()}}class IP{constructor(t){a(this,"key"),a(this,"keyType"),a(this,"source"),this.key=t.key,this.keyType=t.type,this.source=t}}var Oi=(s=>(s[s.Early=-100]="Early",s[s.Default=0]="Default",s[s.Late=100]="Late",s))(Oi||{});class fb{constructor(t){a(this,"_eventListeners",{}),a(this,"_doubleClickTimeThreshold",.2),a(this,"_longPressTimeThreshold",1),a(this,"_setCursorTypes",[]),a(this,"context"),a(this,"_pointerDown",[!1]),a(this,"_pointerUp",[!1]),a(this,"_pointerClick",[!1]),a(this,"_pointerDoubleClick",[!1]),a(this,"_pointerPressed",[!1]),a(this,"_pointerPositions",[new oe]),a(this,"_pointerPositionsLastFrame",[new oe]),a(this,"_pointerPositionsDelta",[new oe]),a(this,"_pointerPositionsRC",[new oe]),a(this,"_pointerPositionDown",[new x]),a(this,"_pointerDownTime",[]),a(this,"_pointerUpTime",[]),a(this,"_pointerUpTimestamp",[]),a(this,"_pointerIds",[]),a(this,"_pointerTypes",[""]),a(this,"_mouseWheelChanged",[!1]),a(this,"_mouseWheelDeltaY",[0]),a(this,"_pointerEvent",[]),a(this,"_pointerEventsPressed",[]),a(this,"_pointerSpace",[]),a(this,"_pressedStack",new Map),a(this,"_htmlEventSource"),a(this,"onLostFocus",()=>{for(const i in this.keysPressed)this.keysPressed[i].pressed=!1}),a(this,"_receivedPointerMoveEventsThisFrame",new Array),a(this,"onEndOfFrame",()=>{this._receivedPointerMoveEventsThisFrame.length=0;for(let i=0;i<this._pointerUp.length;i++)this._pointerUp[i]=!1;for(let i=0;i<this._pointerDown.length;i++)this._pointerDown[i]=!1;for(let i=0;i<this._pointerClick.length;i++)this._pointerClick[i]=!1;for(let i=0;i<this._pointerDoubleClick.length;i++)this._pointerDoubleClick[i]=!1;for(const i of this._pointerPositionsDelta)i.set(0,0);for(let i=0;i<this._mouseWheelChanged.length;i++)this._mouseWheelChanged[i]=!1;for(let i=0;i<this._mouseWheelDeltaY.length;i++)this._mouseWheelDeltaY[i]=0}),a(this,"onContextMenu",i=>{this.canReceiveInput(i)!==!1&&i instanceof PointerEvent&&i.pointerType}),a(this,"keysPressed",{}),a(this,"onKeyDown",i=>{if(pt&&console.log(`key down ${i.code}, ${this.context.application.hasFocus}`,i),!this.context.application.hasFocus)return;const n=this.keysPressed[i.code];if(n&&n.pressed)return;this.keysPressed[i.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:i.key,code:i.code};const o=new pc("keydown",i,i);this.onDispatchEvent(o)}),a(this,"onKeyPressed",i=>{if(!this.context.application.hasFocus)return;const n=this.keysPressed[i.code];if(!n)return;n.pressed=!0,n.frame=this.context.time.frameCount+1;const o=new pc("keypress",i,i);this.onDispatchEvent(o)}),a(this,"onKeyUp",i=>{if(!this.context.application.hasFocus)return;const n=this.keysPressed[i.code];if(!n)return;n.pressed=!1,n.frame=this.context.time.frameCount+1;const o=new pc("keyup",i,i);this.onDispatchEvent(o)}),a(this,"onWheelWindow",i=>{document.pointerLockElement&&this.onMouseWheel(i)}),a(this,"onMouseWheel",i=>{if(this.canReceiveInput(i)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const n=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=n+i.deltaY}),a(this,"onPointerDown",i=>{if(this.context.isInAR||this.canReceiveInput(i)===!1)return;i.target instanceof HTMLElement&&i.target.setPointerCapture(i.pointerId);const n=this.getPointerId(i);pt&&Le(`pointer down #${n}, identifier:${i.pointerId}`);const o=this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),r=new Cn("pointerdown",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:i.button,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:o,pressure:i.pressure});this.onDown(r)}),a(this,"onPointerMove",i=>{if(this.context.isInAR||this._receivedPointerMoveEventsThisFrame.includes(i.pointerId))return;this._receivedPointerMoveEventsThisFrame.push(i.pointerId);let n=i.button;i.pointerType==="mouse"&&(n=this.getFirstPressedButtonForPointer(0)??0);const o=this.getPointerId(i,n);n===-1&&(n=o);const r=this.getAndUpdateSpatialObjectForScreenPosition(o,i.clientX,i.clientY),l=new Cn("pointermove",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:o,button:n,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:r,pressure:i.pressure});this.onMove(l)}),a(this,"onPointerCancel",i=>{this.context.isInAR||(pt&&console.log("Pointer cancel",i),this.onPointerUp(i))}),a(this,"onPointerUp",i=>{if(this.context.isInAR)return;i.target instanceof HTMLElement&&i.target.releasePointerCapture(i.pointerId);const n=this.getPointerId(i),o=new Cn("pointerup",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:i.button,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),pressure:i.pressure});this.onUp(o),this._pointerIds[n]=-1,pt&&console.log("ID="+n,"PointerId="+i.pointerId,"ALL:",[...this._pointerIds])}),a(this,"onTouchStart",i=>{if(this.context.isInAR)for(let n=0;n<i.changedTouches.length;n++){const o=i.changedTouches[n],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new Cn("pointerdown",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onDown(c)}}),a(this,"onTouchMove",i=>{if(this.context.isInAR)for(let n=0;n<i.changedTouches.length;n++){const o=i.changedTouches[n],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new Cn("pointermove",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onMove(c)}}),a(this,"onTouchEnd",i=>{if(this.context.isInAR)for(let n=0;n<i.changedTouches.length;n++){const o=i.changedTouches[n],r=this.getPointerIndex(o.identifier),l=new Cn("pointerup",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),pressure:o.force});this.onUp(l),this._pointerIds[r]=-1}}),a(this,"tempNearPlaneVector",new x),a(this,"tempFarPlaneVector",new x),a(this,"tempLookMatrix",new ne),this.context=t,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(t,i,n){if(this._eventListeners[t]||(this._eventListeners[t]=[]),!i||typeof i!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}n?n={...n}:n={};let o=0;n?.queue!=null&&(o=n.queue);const r=this._eventListeners[t],l=r.find(c=>c.priority===o);l?l.listeners.push({callback:i,options:n}):(r.push({priority:o,listeners:[{callback:i,options:n}]}),r.sort((c,h)=>c.priority-h.priority))}removeEventListener(t,i,n){if(!this._eventListeners[t]||!i)return;const o=this._eventListeners[t];if(n?.queue!=null){const r=o.find(c=>c.priority===n.queue);if(!r)return;const l=r.listeners.findIndex(c=>c.callback===i);l>=0&&r.listeners.splice(l,1)}else for(const r of o){const l=r.listeners.findIndex(c=>c.callback===i);l>=0&&r.listeners.splice(l,1)}}dispatchEvent(t){var i,n,o,r;let l=!1;if(t instanceof pc){const c=this._eventListeners[t.type];if(c)for(const h of c)for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((n=(i=u.options)==null?void 0:i.signal)!=null&&n.aborted){h.listeners.splice(d,1),d--;continue}u.options.once&&(h.listeners.splice(d,1),d--),u.callback(t)}}if(t instanceof Cn){const c=this._eventListeners[t.type];if(c)for(const h of c){if(l)break;for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((r=(o=u.options)==null?void 0:o.signal)!=null&&r.aborted){h.listeners.splice(d,1),d--;continue}if(t.immediatePropagationStopped){l=!0,pt&&console.log("immediatePropagationStopped",t.type);break}else t.propagationStopped&&(l=!0,pt&&console.log("propagationStopped",t.type));u.options.once&&(h.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 i=this._setCursorTypes.length-1;i>=0;i--)if(this._setCursorTypes[i]===t){this._setCursorTypes.splice(i,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 i of this._pointerEventsPressed)if(i.pointerId===t&&i.used)return!0;return!1}getPointerPressedCount(){let t=0;for(let i=0;i<this._pointerPressed.length;i++)this._pointerPressed[i]&&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 i=0;i<this._pointerPressed.length;i++)this._pointerPressed[i]&&this.getIsTouch(i)&&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 i=0;i<this._pointerTypes.length;i++)if(this._pointerIsActive(i)){if(t!==void 0){const n=this._pointerTypes[i];if(Array.isArray(t)){let o=!1;for(const r of t)if(n===r){o=!0;break}if(!o)continue}else if(t!==n)continue}yield i}}*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,i){let n=this._pressedStack.get(t);n||(n=[],this._pressedStack.set(t,n)),n.push(i)}onReleaseButton(t,i){const n=this._pressedStack.get(t);if(!n)return;const o=n.indexOf(i);o>=0&&n.splice(o,1)}getFirstPressedButtonForPointer(t){const i=this._pressedStack.get(t);if(i)return i[0]}getLatestPressedButtonForPointer(t){const i=this._pressedStack.get(t);if(i)return i[i.length-1]}getKeyDown(){for(const t in this.keysPressed){const i=this.keysPressed[t];if(i.startFrame===this.context.time.frameCount)return i.key}return null}getKeyPressed(){for(const t in this.keysPressed){const i=this.keysPressed[t];if(i.pressed)return i.key}return null}isKeyDown(t){var i;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const n=this.getCodeForCommonKeyName(t);if(n!==null){for(const o of n)if(this.isKeyDown(o))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 n=this.getCodeForCommonKeyName(t);if(n!==null){for(const o of n)if(this.isKeyUp(o))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 n=this.getCodeForCommonKeyName(t);if(n!==null){for(const o of n)if(this.isKeyPressed(o))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":pt&&Le("Create Pointer down"),this.onDownButton(t.deviceIndex,t.button),this.onDown(t);break;case"pointermove":pt&&Le("Create Pointer move"),this.onMove(t);break;case"pointerup":pt&&Le("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,i;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),(i=this._htmlEventSource)==null||i.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 i;return t.target===((i=this.context.renderer)==null?void 0:i.domElement)||t.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&t.target===document.body&&X.isMozillaXR()?!0:(pt&&console.warn("CanReceiveInput:False for",t.target),!1)}getPointerId(t,i){return t.pointerType==="mouse"?0+(i??t.button):this.getPointerIndex(t.pointerId)}getButtonName(t){const i=t.button;if(t.pointerType==="mouse")switch(i){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(t,i,n){let o=this._pointerSpace[t];o||(o=new I,this._pointerSpace[t]=o),this._pointerSpace[t]=o;const r=this.context.mainCamera;if(r){const l=this.tempNearPlaneVector.set(i,n,-1);this.convertScreenspaceToRaycastSpace(l);const c=this.tempFarPlaneVector.set(l.x,l.y,1);l.unproject(r),c.unproject(r);const h=r.worldUp||G(0,1,0).applyQuaternion(Oe(r));this.tempLookMatrix.lookAt(c,l,h),o.position.set(l.x,l.y,l.z),o.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return o}isInRect(t){if(this.context.isInXR)return!0;const i=this.context.domElement.getBoundingClientRect(),n=t.clientX,o=t.clientY,r=n>=i.x&&n<=i.right&&o>=i.y&&o<=i.bottom;return pt&&!r&&console.log("Not in rect",i,n,o),r}onDown(t){const i=t.pointerId;if(this.getPointerPressed(i)&&console.warn(`Received pointerDown for pointerId that is already pressed: ${i}`,pt?t:""),pt&&console.log(t.pointerType,"DOWN",i),!!this.isInRect(t)){for(this.setPointerState(i,this._pointerPressed,!0),this.setPointerState(i,this._pointerDown,!0),this.setPointerStateT(i,this._pointerEvent,t.source);i>=this._pointerTypes.length;)this._pointerTypes.push(t.pointerType);for(this._pointerTypes[i]=t.pointerType;i>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new x);for(this._pointerPositionDown[i].set(t.clientX,t.clientY,t.clientZ??0);i>=this._pointerPositions.length;)this._pointerPositions.push(new oe);this._pointerPositions[i].set(t.clientX,t.clientY),i>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[i]=this.context.time.realtimeSinceStartup,this.updatePointerPosition(t),this._pointerEventsPressed.push(t),this.onDispatchEvent(t)}}onMove(t){const i=t.pointerId,n=this.getPointerPressed(i);n===!1&&!this.isInRect(t)||t.pointerType==="touch"&&!n||(this.updatePointerPosition(t),this.setPointerStateT(i,this._pointerEvent,t.source),this.onDispatchEvent(t))}onUp(t){const i=t.pointerId;if(!this.getPointerPressed(i)){pt&&console.log(t.pointerType,"UP",i,"was not down");return}pt&&console.log(t.pointerType,"UP",i),this.setPointerState(i,this._pointerPressed,!1),this.setPointerStateT(i,this._pointerEvent,t.source),this.setPointerState(i,this._pointerUp,!0),this.updatePointerPosition(t);for(let c=this._pointerEventsPressed.length-1;c>=0;c--)if(this._pointerEventsPressed[c].pointerId===i){this._pointerEventsPressed.splice(c,1);break}if(!this._pointerPositionDown[i]){pt&&xe("Received pointer up event without matching down event for button: "+i),console.warn("Received pointer up event without matching down event for button: "+i);return}const n=this._pointerUpTime[i],o=this._pointerDownTime[i],r=this.context.time.realtimeSinceStartup,l=r-o;if(i>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),this._pointerUpTime[i]=r,l<1){let c=t.clientX-this._pointerPositionDown[i].x,h=t.clientY-this._pointerPositionDown[i].y,d=0;if(t.isSpatial&&t.clientZ!=null&&(d=t.clientZ-this._pointerPositionDown[i].z,c*=200,h*=200,d*=200),Math.abs(c)<5&&Math.abs(h)<5&&Math.abs(d)<5){this.setPointerState(i,this._pointerClick,!0),t.isClick=!0;const u=r-n;pt&&console.log("CLICK",i,c,h,d,u),u<this._doubleClickTimeThreshold&&u>0&&(this.setPointerState(i,this._pointerDoubleClick,!0),t.isDoubleClick=!0)}}this.onDispatchEvent(t)}updatePointerPosition(t){const i=t.pointerId;for(;i>=this._pointerPositions.length;)this._pointerPositions.push(new oe);for(;i>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new oe);for(;i>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new oe);const n=this._pointerPositionsLastFrame[i];n.copy(this._pointerPositions[i]);const o=this._pointerPositionsDelta[i];let r=t.clientX-n.x,l=t.clientY-n.y;if(t.source instanceof MouseEvent||t.source instanceof TouchEvent){const u=t.source;r===0&&u.movementX!==0&&(r=u.movementX||0),l===0&&u.movementY!==0&&(l=u.movementY||0)}o.x+=r,o.y+=l,this._pointerPositions[i].x=t.clientX,this._pointerPositions[i].y=t.clientY;const c=t.clientX,h=t.clientY;for(;i>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new oe);const d=this._pointerPositionsRC[i];d.set(c,h),this.convertScreenspaceToRaycastSpace(d)}getPointerIndex(t){let i=-1;for(let n=0;n<this._pointerIds.length;n++){if(this._pointerIds[n]===t)return n;i===-1&&this._pointerIds[n]===-1&&(i=n)}return i!==-1?(this._pointerIds[i]=t,i):(pt&&console.log("PUSH pointerId:",t),this._pointerIds.push(t),this._pointerIds.length-1)}setPointerState(t,i,n){i[t]=n}setPointerStateT(t,i,n){return i[t]=n,n}onDispatchEvent(t){const i=ee.Current;try{ee.Current=this.context,this.dispatchEvent(t)}finally{ee.Current=i}}}const Ra=new ne().makeRotationY(Math.PI),Yi=new V().setFromAxisAngle(new x(0,1,0),Math.PI),jP=O("debugwebxr");class DP{constructor(){if(a(this,"priority",-1e5),a(this,"gameObject"),this.gameObject=new I,this.gameObject.name="Implicit XR Rig",jP){const t=_g(16733661);t.position.y+=.5,this.gameObject.add(t)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const On=O("debugwebxr"),jd=O("debugcustomgesture"),LP="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",BP="generic-trigger",FP=new V().setFromEuler(new Ut(vn.degToRad(0),vn.degToRad(-90),vn.degToRad(-90))),zP=new x(.04,-.04,0);class og{constructor(t,i,n){a(this,"xr"),a(this,"inputSource"),a(this,"index",0),a(this,"emitEvents",!0),a(this,"_connected",!0),a(this,"_isTracking",!1),a(this,"__gamepad"),a(this,"__hand"),a(this,"__side"),a(this,"_hitTestSource"),a(this,"_hasSelectEvent",!1),a(this,"_isMxInk",!1),a(this,"_isMetaQuestTouchController",!1),a(this,"_handJointPoses",new Map),a(this,"_gripMatrix",new ne),a(this,"_gripPosition",new x),a(this,"_gripQuaternion",new V),a(this,"_linearVelocity",new x),a(this,"_rayPositionRaw",new x),a(this,"_rayRotationRaw",new V),a(this,"_rayMatrix",new ne),a(this,"_rayPosition",new x),a(this,"_rayQuaternion",new V),a(this,"_gripWorldPosition",new x),a(this,"_gripWorldQuaternion",new V),a(this,"_rayWorldPosition",new x),a(this,"_rayWorldQuaternion",new V),a(this,"_pinchPosition",new x),a(this,"_ray"),a(this,"_hand_wristDotUp"),a(this,"_object"),a(this,"_gripSpaceObject"),a(this,"_raySpaceObject"),a(this,"model",null),a(this,"_debugAxesHelper",new wi(.15)),a(this,"_debugGripAxesHelper",new wi(.07)),a(this,"_debugRayAxesHelper",new wi(.07)),a(this,"_hitTestSourcePromise",null),a(this,"onPointerHits",o=>{}),a(this,"_needleGamepadButtons",{}),a(this,"_buttonMap",new Map),a(this,"_motioncontroller"),a(this,"_layout"),a(this,"getMotionController"),a(this,"emitPointerDownEvent",!0),a(this,"emitPointerUpEvent",!0),a(this,"emitPointerMoveEvent",!0),a(this,"pointerMoveDistanceThreshold",.03),a(this,"pointerMoveAngleThreshold",.05),a(this,"_selectButtonIndex"),a(this,"_squeezeButtonIndex"),a(this,"onSelectStart",o=>{var r,l,c,h;if(!this.emitPointerDownEvent||this.inputSource!==o.inputSource)return;this.onUpdateFrame(o.frame),this._hasSelectEvent=!0;const d=(r=this._layout)==null?void 0:r.selectComponentId,u=(h=(c=(l=this._layout)==null?void 0:l.components[d])==null?void 0:c.gamepadIndices)==null?void 0:h.button;u!==void 0&&(this._selectButtonIndex=u),!jd&&(On&&q.DrawDirection(this.rayWorldPosition,G(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(Be.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSelectEnd",o=>{this.emitPointerUpEvent&&(jd||this.inputSource===o.inputSource&&this.emitPointerEvent(Be.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSequeezeStart",o=>{var r,l,c;this.emitPointerDownEvent&&this.inputSource===o.inputSource&&(this._squeezeButtonIndex=(c=(l=(r=this._layout)==null?void 0:r.components["xr-standard-squeeze"])==null?void 0:l.gamepadIndices)==null?void 0:c.button,this._squeezeButtonIndex!==void 0&&(On&&q.DrawDirection(this.rayWorldPosition,G(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(Be.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)))}),a(this,"onSequeezeEnd",o=>{this.emitPointerUpEvent&&this.inputSource===o.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(Be.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)}),a(this,"states",{}),a(this,"_didMoveLastFrame",!1),a(this,"_lastPointerMovePosition",new x),a(this,"_lastPointerMoveQuaternion",new V),a(this,"pointerInit"),this.xr=t,this.inputSource=i,this.index=n,this._object=new I,this._object.name=`NeedleXRController_${n}`,On&&(this._object.add(this._debugAxesHelper),this._gripSpaceObject=new I,this._raySpaceObject=new I,this._gripSpaceObject.name=`NeedleXRController_${n}_gripSpace`,this._raySpaceObject.name=`NeedleXRController_${n}_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 no,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,i){var n;if(i=i||this.xr.frame,!this.hand||!(i!=null&&i.getJointPose)||!this.xr.referenceSpace)return null;let o=(n=this._handJointPoses)==null?void 0:n.get(t);return o||(o=i.getJointPose(t,this.xr.referenceSpace),o&&this._handJointPoses.set(t,o),o)}get gripPosition(){return G(this._gripPosition)}get gripQuaternion(){return vs(this._gripQuaternion)}get gripMatrix(){return this._gripMatrix}get gripLinearVelocity(){return G(this._linearVelocity).applyQuaternion(Yi)}get rayPosition(){return G(this._rayPosition)}get rayQuaternion(){return vs(this._rayQuaternion)}get gripWorldPosition(){return G(this._gripWorldPosition)}get gripWorldQuaternion(){return vs(this._gripWorldQuaternion)}get rayWorldPosition(){return G(this._rayWorldPosition)}updateRayWorldPosition(){var t;const i=(t=this.xr.context.mainCamera)==null?void 0:t.parent;this._rayWorldPosition.copy(this._rayPositionRaw),i&&this._rayWorldPosition.applyMatrix4(i.matrixWorld)}get rayWorldQuaternion(){return vs(this._rayWorldQuaternion)}get pinchPosition(){return G(this._pinchPosition)}updateRayWorldQuaternion(){var t;const i=(t=this.xr.context.mainCamera)==null?void 0:t.parent,n=i?Oe(i):void 0;this._rayWorldQuaternion.copy(this._rayRotationRaw).multiply(Yi),n&&this._rayWorldQuaternion.premultiply(n)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(G(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get handWristDotUp(){var t;if(this._hand_wristDotUp!==void 0)return this._hand_wristDotUp;const i=(t=this.handObject)==null?void 0:t.joints.wrist;if(i){const n=G(0,1,0).applyQuaternion(i.quaternion),o=G(0,1,0).dot(n);return this._hand_wristDotUp=o}}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(i=>i?.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(i=>(this._hitTestSourcePromise=null,this.connected?this._hitTestSource=i:(i.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 t;q.DrawSphere(this.rayWorldPosition,.003),q.DrawDirection(this.rayWorldPosition,G(0,0,10).applyQuaternion(this.rayWorldQuaternion));const i=(this.inputSource.gripSpace?this.gripWorldPosition:this.object.worldPosition).sub(this.object.worldForward.multiplyScalar(.1)),n=this.inputSource.profiles.join(`
|
|
135
135
|
`);let o=`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&&(o+=`
|
|
@@ -922,7 +922,7 @@ Using the assigned clip instead:`,this.clip),s=this.clip);let o=!this.sound||s&&
|
|
|
922
922
|
Audio:`,r.getAudioTracks(),`
|
|
923
923
|
Video:`,r.getVideoTracks()),this._stream=r,n==="incoming"){const l=new Nw(t,r,this);this.dispatchEvent(l)}}),i.on("close",()=>{this.dispatchEvent(new Sf(t,n))})}get stream(){return this._stream}close(){this._isDisposed||(this._isDisposed=!0,this.call.close(),Ks(this._stream))}get isOpen(){var t;return((t=this.call.peerConnection)==null?void 0:t.connectionState)==="connected"}get isOpening(){var t;return((t=this.call.peerConnection)==null?void 0:t.connectionState)==="connecting"}get isClosed(){return!this.isOpen||this._isDisposed}}function Vw(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 Gc=class extends fm{constructor(s,t){super(),a(this,"updateCalls",()=>{var i;for(let n=this._incomingCalls.length-1;n>=0;n--){const o=this._incomingCalls[n];o.isClosed&&!o.isOpening&&this._incomingCalls.splice(n,1)}for(let n=this._outgoingCalls.length-1;n>=0;n--){const o=this._outgoingCalls[n];let r=!1;o.isClosed&&!o.isOpening&&((i=o.stream)!=null&&i.active?nt&&console.warn("!!! Stream is still active, don't remove call",o.userId,"Your id: "+this.context.connection.connectionId):(nt&&console.warn("!!! Remove closed call",o.userId),r=!0)),this.context.connection.userIsInRoom(o.userId)===!1&&(nt&&console.warn("!!! User is not in room anymore, remove call",o.userId),r=!0),r&&(o.close(),this._outgoingCalls.splice(n,1))}}),a(this,"id"),a(this,"context"),a(this,"_incomingCalls",[]),a(this,"_outgoingCalls",[]),a(this,"_peer"),a(this,"_enabled",!1),a(this,"_enabledPeer",!1),a(this,"onConnectRoomFn",this.onConnectRoom.bind(this)),a(this,"onPeerConnect",i=>{if(nt&&console.log("PEER opened as",i),i===null){console.error("Peer connection failed",i);return}this.context.connection.send("peer-user-connected",new EM(this,i))}),a(this,"onPeerClose",()=>{nt&&console.log("PEER closed"),this.updateCalls()}),a(this,"onPeerDisconnected",()=>{nt&&console.log("PEER disconnected"),this.updateCalls()}),a(this,"onPeerError",i=>{nt&&console.error("PEER error",i)}),a(this,"onPeerReceivingCall",i=>{i.answer(void 0,{sdpTransform:n=>Vw(n)}),this.registerCall(i,"incoming",null)}),this.context=s,this.id=t,this.setupPeer(),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia}static getOrCreate(s,t){if(Gc.instances.has(t))return Gc.instances.get(t);const i=new Gc(s,t);return Gc.instances.set(t,i),i}getMyPeerId(){if(this.context.connection.connectionId)return this.getPeerIdFromUserId(this.context.connection.connectionId)}getPeerIdFromUserId(s){return this.id+"-"+s}getUserIdFromPeerId(s){return s.substring(this.id.length+1)}makeCall(s,t){var i;if(!(t!=null&&t.id)){nt?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:t.id},sdpTransform:r=>Vw(r)},o=(i=this._peer)==null?void 0:i.call(s,t,n);if(o){const r=this.registerCall(o,"outgoing",t);return nt&&console.warn(`\u{1F4DE} CALL ${s}`,`
|
|
924
924
|
Outgoing:`,this._outgoingCalls,`
|
|
925
|
-
Incoming:`,this._incomingCalls),r}else nt&&console.error("Failed to make call",s,t,this._peer)}closeAll(){for(const s of this._incomingCalls)s.close();for(const s of this._outgoingCalls)s.close();this.updateCalls()}get peer(){return this._peer}get incomingCalls(){return this._incomingCalls}enable(){this._enabled||(this._enabled=!0,this.context.connection.beginListen(ie.JoinedRoom,this.onConnectRoomFn),this.subscribePeerEvents())}disable(){this._enabled&&(this._enabled=!1,this.context.connection.stopListen(ie.JoinedRoom,this.onConnectRoomFn),this.unsubscribePeerEvents())}onConnectRoom(){this.setupPeer()}setupPeer(){if(this.context.connection.connectionId&&!this._enabledPeer){if(this._enabledPeer=!0,!this._peer){const s=this.getMyPeerId();s?this._peer=Ob(s):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(s,t,i){const n=s.metadata;(!n||!n.userId)&&console.error("Missing call metadata",s);const o=n.userId;t==="incoming"&&nt?console.warn("\u2190 Receive call from",s.metadata,s.connectionId):nt&&console.warn("\u2192 Make call to",s.metadata);const r=t==="incoming"?this._incomingCalls:this._outgoingCalls,l=new AM(o,s,t,i);return r.push(l),s.on("error",c=>{console.error("Call error",c)}),s.on("close",()=>{nt&&console.log("Call ended",s.metadata);const c=r.indexOf(l);c!==-1&&r.splice(c,1),l.close(),this.dispatchEvent(new Sf(o,t))}),l.addEventListener("call-ended",c=>{this.dispatchEvent(c)}),t==="incoming"&&(l.addEventListener("receive-stream",c=>{this.dispatchEvent(c)}),s.on("stream",()=>{nt&&console.log("Received stream for call",s.metadata);let c=0;const h=setInterval(()=>{const d=c===0;!l.isOpen&&d&&(nt&&console.warn("Close call because stream is not active",s.metadata),c+=1,clearInterval(h),l.close())},2e3)})),l}};let Xc=Gc;a(Xc,"instances",new Map);class cd extends fm{constructor(t,i){if(super(),a(this,"context"),a(this,"peer"),a(this,"_sendingStreams",new Map),a(this,"debug",!1),a(this,"_enabled",!1),a(this,"_tickIntervalId"),a(this,"tick",()=>{this.updateSendingCalls()}),a(this,"onJoinedRoom",n=>{this._sendingStreams.size>0&&(this.debug&&console.warn(`${n!=null&&n.userId?`User ${n.userId}`:"You"} joined room`,n,this._sendingStreams.size),this.updateSendingCalls())}),a(this,"onLeftRoom",n=>{this.debug&&console.warn(`${n?.userId||"You"} left room`,n),this.stopCallsToUsersThatAreNotInTheRoomAnymore(),this.peer.closeAll()}),a(this,"onCallStreamReceived",n=>{this.debug&&console.log("Call with "+n.userId+" started"),this.dispatchEvent({type:"receive-stream",target:this,stream:n.stream,userId:n.userId}),this.debug&&this.debugLogCurrentState()}),a(this,"onCallEnded",n=>{this.debug&&console.log("Call with "+n.userId+" ended"),this.dispatchEvent(n),this.debug&&this.debugLogCurrentState()}),a(this,"onUserConnected",n=>{if(this.peer.id===n.guid){this.debug&&console.log("PEER USER CONNECTED",n.guid,n,this._sendingStreams.size);const o=this._sendingStreams.keys().next().value;this.peer.makeCall(n.peerId,o)}else nt&&console.log("Unknown user connected",n.guid,n.peerId)}),a(this,"onUserLeft",n=>{this.debug&&console.log("User left room: "+n.userId),this.stopCallsToUsersThatAreNotInTheRoomAnymore()}),Bw(t)){const n=t;t=n.context,i=Xc.getOrCreate(n.context,n.guid)}else typeof i=="string"&&(i=Xc.getOrCreate(t,i));if(t){if(!(t instanceof ee))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=t,this.peer=i,nt&&(this.debug=!0)}static create(t,i){const n=Xc.getOrCreate(t.context,i||t.context.connection.connectionId||t.guid);return new cd(t.context,n)}startSendingStream(t){this._sendingStreams.has(t)?console.warn("Received start sending stream with stream that is already being sent"):(this._sendingStreams.set(t,[]),this.updateSendingCalls())}stopSendingStream(t){if(t){const i=this._sendingStreams.get(t);if(i){for(const n of i)n.close();i.length=0}this._sendingStreams.delete(t),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(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ie.UserJoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ie.UserLeftRoom,this.onUserLeft),this.context.connection.beginListen(ie.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(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ie.UserJoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ie.UserLeftRoom,this.onUserLeft),this.context.connection.stopListen(ie.LeftRoom,this.onLeftRoom),this._tickIntervalId!=null&&(clearInterval(this._tickIntervalId),this._tickIntervalId=void 0))}updateSendingCalls(){const t=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===t)continue;const r=this.peer.getPeerIdFromUserId(o);if(n.find(l=>{var c;return l.peerId===r&&l.direction==="outgoing"&&!l.isClosed&&((c=l.stream)==null?void 0:c.active)}))nt&&console.debug("Already have a call with user "+o+" / peer "+r);else{const l=this.peer.makeCall(r,i);l&&n.push(l)}}this._sendingStreams.set(i,n)}this.stopCallsToUsersThatAreNotInTheRoomAnymore()}stopCallsToUsersThatAreNotInTheRoomAnymore(){for(const t of this._sendingStreams.keys()){const i=this._sendingStreams.get(t);if(i)for(let n=i.length-1;n>=0;n--){const o=i[n];this.context.connection.userIsInRoom(o.userId)?nt&&(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}`)):(nt&&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(t=>t.userId).join(", ")})`,this.peer.incomingCalls)}}function Ks(s){if(s&&s instanceof MediaStream)for(const t of s.getTracks())t.stop()}var IM=Object.defineProperty,jM=Object.getOwnPropertyDescriptor,Cf=(s,t,i,n)=>{for(var o=n>1?void 0:n?jM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&IM(t,i,o),o};const DM="noVoip",LM=O("debugvoip");class Eo extends A{constructor(){super(...arguments),a(this,"autoConnect",!0),a(this,"runInBackground",!0),a(this,"createMenuButton",!0),a(this,"debug",!1),a(this,"_net"),a(this,"_menubutton"),a(this,"_allowSending",!0),a(this,"_outputStream",null),a(this,"onJoinedRoom",async()=>{this.debug&&console.log("VOIP: Joined room"),await ys(300),this.autoConnect&&!this.isSending&&this._allowSending&&this.connect()}),a(this,"onLeftRoom",()=>{this.debug&&console.log("VOIP: Left room"),this.disconnect();for(const t of this._incomingStreams.values())Ks(t.srcObject);this._incomingStreams.clear()}),a(this,"_incomingStreams",new Map),a(this,"onReceiveStream",t=>{const i=t.target.userId,n=t.stream;let o=this._incomingStreams.get(i);o||(o=new Audio,this._incomingStreams.set(i,o)),o.srcObject=n,o.setAttribute("autoplay","true"),Rn.registerWaitForInteraction(()=>{o?.play().catch(r=>{console.error("VOIP: Failed to play audio",r)})})}),a(this,"onStreamEnded",t=>{const i=this._incomingStreams.get(t.userId);Ks(i?.srcObject),this._incomingStreams.delete(t.userId)}),a(this,"onEnabledChanged",()=>{for(const t of this._incomingStreams){const i=t[1];i.muted=!this.enabled}}),a(this,"onVisibilityChanged",()=>{if(this.runInBackground)return;const t=document.visibilityState!=="visible";this.setMuted(t);for(const i of this._incomingStreams){const n=i[1];n.muted=t}})}awake(){LM&&(this.debug=!0),this.debug&&(console.log("VOIP debugging: press 'v' to toggle mute or 'c' to toggle connect/disconnect"),window.addEventListener("keydown",async t=>{switch(t.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=cd.create(this)),this.debug&&(this._net.debug=!0),this._net.addEventListener(Ys.StreamReceived,this.onReceiveStream),this._net.addEventListener(Ys.StreamEnded,this.onStreamEnded),this._net.enable(),this.autoConnect&&this.context.connection.isConnected&&this.connect(),this.context.connection.beginListen(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ie.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.addEventListener("visibilitychange",this.onVisibilityChanged)}onDisable(){var t;this._net&&(this._net.stopSendingStream(this._outputStream),this._net.removeEventListener(Ys.StreamReceived,this.onReceiveStream),this._net.removeEventListener(Ys.StreamEnded,this.onStreamEnded),(t=this._net)==null||t.disable()),this.context.connection.stopListen(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ie.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.removeEventListener("visibilitychange",this.onVisibilityChanged)}onDestroy(){var t;(t=this._menubutton)==null||t.remove(),this._menubutton=void 0}get isSending(){return this._outputStream!=null&&this._outputStream.active}async connect(t){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 X.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),Ks(this._outputStream),this._outputStream=await this.getAudioStream(t),this._outputStream?(this.debug&&console.log("VOIP: Got audio stream"),(n=this._net)==null||n.startSendingStream(this._outputStream),this.updateButton(),!0):(this.updateButton(),await X.microphonePermissionsGranted()?console.error("VOIP: Could not get audio stream - please make sure to connect an audio device and grant microphone permissions"):lc("Microphone permissions not granted: Please grant microphone permissions to use voice chat"),(this.debug||F())&&console.log("VOIP: Failed to get audio stream"),!1)}disconnect(t){var i;t!=null&&t.remember&&(this._allowSending=!1),(i=this._net)==null||i.stopSendingStream(this._outputStream),Ks(this._outputStream),this._outputStream=null,this.updateButton()}setMuted(t){var i;const n=(i=this._outputStream)==null?void 0:i.getAudioTracks();if(n)for(const o of n)o.enabled=!t}get isMuted(){var t;if(this._outputStream===null)return!1;const i=(t=this._outputStream)==null?void 0:t.getAudioTracks();if(i){for(const n of i)if(!n.enabled)return!0}return!1}async updateButton(){var t;if(this.createMenuButton){if(this._menubutton||(this._menubutton=document.createElement("button"),this._menubutton.addEventListener("click",()=>{this.isSending?this.disconnect({remember:!0}):this.connect(),X.microphonePermissionsGranted().then(i=>{i||xe("<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 X.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(kt(n)),this.context.connection.isConnected==!1?this._menubutton.setAttribute("disabled",""):this._menubutton.removeAttribute("disabled")}}else this.activeAndEnabled||(t=this._menubutton)==null||t.remove()}getFrequency(t){return this.unsupported_getfrequency||(this.unsupported_getfrequency=!0,F()&&xe("VOIP: getFrequency is currently not supported"),console.warn("VOIP: getFrequency is currently not supported")),null}async getAudioStream(t){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(r=>(console.warn("VOIP failed getting audio stream",r),null)),n=await i(t);if(!n)return null;if(X.isiOS()&&t?.deviceId===void 0){const o=(await navigator.mediaDevices.enumerateDevices()).find(r=>(r.kind==="audioinput"||r.kind==="audiooutput")&&!r.label.includes("iPhone"));if(o){const r=Object.assign({},t);return r.deviceId=o.deviceId,await i(r)}}return n}}Cf([m()],Eo.prototype,"autoConnect",2),Cf([m()],Eo.prototype,"runInBackground",2),Cf([m()],Eo.prototype,"createMenuButton",2);var BM=Object.defineProperty,FM=Object.getOwnPropertyDescriptor,Hw=(s,t,i,n)=>{for(var o=n>1?void 0:n?FM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&BM(t,i,o),o};const zM=O("debugmouth");class Qc extends A{constructor(){super(...arguments),a(this,"idle",[]),a(this,"talking",[]),a(this,"marker",null),a(this,"voip",null),a(this,"lastMouthChangeTime",0),a(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=P.findObjectOfType(Eo,this.context),this.marker||(this.marker=P.getComponentInParent(this.gameObject,Tt))},3e3)}update(){var t;if(!this.voip||this.context.time.frameCount%10!==0)return;let i=((t=this.marker)==null?void 0:t.connectionId)??null;if(!i){zM&&(i=null);return}const n=this.voip.getFrequency(i)??0;this.updateLips(n)}updateLips(t){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&t>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(t,i){if(t){t!=this.idle?this.idle.map(n=>n.visible=!1):this.talking.map(n=>n.visible=!1);for(let n=0;n<t.length;n++){const o=t[n];o&&(o.visible=n===i)}}}}Hw([m(I)],Qc.prototype,"idle",2),Hw([m(I)],Qc.prototype,"talking",2);class Of extends A{constructor(){super(...arguments),a(this,"voip",null),a(this,"marker",null),a(this,"_startPosition",null)}awake(){this.voip=P.findObjectOfType(Eo,this.context),this.marker=P.getComponentInParent(this.gameObject,Tt)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const t=this.marker.connectionId,i=this.voip.getFrequency(t);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 UM=Object.defineProperty,NM=Object.getOwnPropertyDescriptor,WM=(s,t,i,n)=>{for(var o=n>1?void 0:n?NM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&UM(t,i,o),o};const Za=O("debugxrflags"),$w=O("disablexrflags");$w&&console.warn("XRFlags are disabled");var Zs=(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))(Zs||{});const qw=class{constructor(){a(this,"Mask",17)}Has(s){return(this.Mask&s)!==0}Set(s){Za&&console.warn("Set XR flag state to",s),this.Mask=s,Ai.Apply()}Enable(s){this.Mask|=s,Ai.Apply()}Disable(s){this.Mask&=~s,Ai.Apply()}Toggle(s){this.Mask^=s,Ai.Apply()}EnableAll(){this.Mask=-1,Ai.Apply()}DisableAll(){this.Mask=0,Ai.Apply()}};let Kt=qw;a(Kt,"Global",new qw);var Yc;const An=(Yc=class extends A{constructor(){super(...arguments),a(this,"visibleIn")}static Apply(){for(const s of this.registry)s.UpdateVisible(Kt.Global)}awake(){An.registry.push(this)}onEnable(){An.firstApply?this.UpdateVisible(Kt.Global):(An.firstApply=!0,An.Apply())}onDestroy(){const s=An.registry.indexOf(this);s>=0&&An.registry.splice(s,1)}get isOn(){return this.gameObject.visible}UpdateVisible(s=null){if($w)return;let t;const i=s;if(i&&typeof i=="number"&&(console.assert(typeof i=="number","XRFlag.UpdateVisible: state must be a number",i),Za&&console.log(i),An.buffer.Mask=i,s=An.buffer),s instanceof Kt?(Za&&console.warn(this.name,"use passed in mask",s.Mask,this.visibleIn),t=s.Has(this.visibleIn)):(Za&&console.log(this.name,"use global mask"),Kt.Global.Has(this.visibleIn)),t!==void 0)if(t)Za&&console.log(this.name,"is visible",this.gameObject.uuid),P.setActive(this.gameObject,!0);else{if(Za&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},a(Yc,"registry",[]),a(Yc,"firstApply"),a(Yc,"buffer",new Kt),Yc);let Ai=An;WM([m()],Ai.prototype,"visibleIn",2);var VM=Object.defineProperty,HM=Object.getOwnPropertyDescriptor,Nu=(s,t,i,n)=>{for(var o=n>1?void 0:n?HM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&VM(t,i,o),o};class zr extends A{constructor(){super(...arguments),a(this,"eyes",[]),a(this,"lastBlinkTime",0),a(this,"blinkLength",0),a(this,"eyesOpen",!0),a(this,"state",null)}awake(){this.state=P.getComponentInParent(this.gameObject,Ai)}update(){if(!(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)&&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 t of this.eyes)t&&(t.visible=this.eyesOpen)}}}Nu([m(I)],zr.prototype,"eyes",2),Nu([m()],zr.prototype,"lastBlinkTime",2),Nu([m()],zr.prototype,"blinkLength",2),Nu([m()],zr.prototype,"eyesOpen",2);var $M=Object.defineProperty,qM=Object.getOwnPropertyDescriptor,Pf=(s,t,i,n)=>{for(var o=n>1?void 0:n?qM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&$M(t,i,o),o},kf;const Gw=(kf=class extends A{constructor(){super(...arguments),a(this,"head",null),a(this,"eyes",null),a(this,"target",null),a(this,"brain",null),a(this,"vec",new x),a(this,"currentTargetPoint",new x)}awake(){this.brain||(this.brain=P.getComponentInParent(this.gameObject,qc)),this.brain||(this.brain=P.addComponent(this.gameObject,qc)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const s=this.target;if(s&&this.head){const t=this.eyes;if(t){const i=te(s);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const n=te(this.head),o=this.vec.copy(this.currentTargetPoint).sub(n).normalize();if(o.length()<.1)return;const r=Gw.forward;if(r.set(0,0,1),r.applyQuaternion(Oe(this.head)),r.dot(o)>.45)for(let l=0;l<t.length;l++)t[l].lookAt(this.currentTargetPoint)}}}},a(kf,"forward",new x(0,0,1)),kf);let Ja=Gw;Pf([m(I)],Ja.prototype,"head",2),Pf([m(I)],Ja.prototype,"eyes",2),Pf([m(I)],Ja.prototype,"target",2);const Kc=O("debugavatar");class Wu{constructor(t,i,n,o){a(this,"root"),a(this,"head"),a(this,"leftHand"),a(this,"rigthHand");var r;this.root=t,this.head=i,this.leftHand=n,this.rigthHand=o,(r=this.root)==null||r.traverse(l=>l.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class Mf{constructor(){a(this,"avatarRegistryUrl",null)}async getOrCreateNewAvatarInstance(t,i){if(!i)return console.error("Can not create avatar: failed to provide id or root object"),null;let n=null;if(typeof i=="string"){if(n=await this.loadAvatar(t,i),!n){const r=new Ls;n=P.instantiate(Ca(i,t.scene),r)}}else n=i;if(!n)return null;const o=this.findAvatar(n);return o.isValid?(Kc&&console.log("[Custom Avatar] valid config",i,Kc?o:""),o):(console.warn("[Custom Avatar] config isn't valid",i,Kc?o:""),null)}async loadAvatar(t,i){if(console.assert(i!=null&&typeof i=="string","Avatar id must not be null"),i.length<=0||!i)return null;if(Kc&&console.log("[Custom Avatar] "+i+", loading..."),i.endsWith(".glb")||(i+=".glb"),this.avatarRegistryUrl===null){const o=await fetch("./"+i);let r=null;if(o.ok){const c=await o.blob();c&&(r=await c.arrayBuffer())}if(!r)return null;const l=await fs().parseSync(t,r,null,0);return l?.scene??null}const n=new gr;return Su(n,t),new Promise((o,r)=>{const l=this.avatarRegistryUrl+"/"+i;n.load(l,async c=>{await fs().createBuiltinComponents(t,l,c,null,void 0),o(c.scene)},c=>{Kc&&console.log("[Custom Avatar] "+c.loaded/c.total*100+"% loaded of "+c.total/1024+"kB")},c=>{console.error("[Custom Avatar] Error when loading: "+c),o(null)})})}cacheModel(t,i){}findAvatar(t){const i=t;let n=i;n.children.length==1&&(n=t.children[0]);let o=this.findAvatarPart(n,["head"]);const r=this.findAvatarPart(n,["left","hand"]),l=this.findAvatarPart(n,["right","hand"]);if(!o){o=i;const c=new x;new _i().setFromObject(o).getSize(c);const h=Math.max(c.x,c.y,c.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+h+" meters! Should be < 0.3m"),h>.3&&o.scale.multiplyScalar(1/h*.3)}return new Wu(i,o,r,l)}findAvatarPart(t,i){const n=t.name.toLowerCase();let o=!0;for(const r of i){if(!o)break;n.indexOf(r)===-1&&(o=!1)}if(o)return t;if(t.children)for(const r of t.children){const l=this.findAvatarPart(r,i);if(l)return l}return null}handleCustomAvatarErrors(t){if(!t.ok)throw Error(t.statusText);return t}}var GM=Object.defineProperty,XM=Object.getOwnPropertyDescriptor,Rf=(s,t,i,n)=>{for(var o=n>1?void 0:n?XM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&GM(t,i,o),o};class el extends A{constructor(){super(...arguments),a(this,"length",1),a(this,"depthTest",!0),a(this,"isGizmo",!1),a(this,"_axes",null)}onEnable(){if(this.isGizmo&&!Cc)return;this._axes||(this._axes=new wi(this.length)),this._axes.layers.disableAll(),this._axes.layers.set(this.layer),this.gameObject.add(this._axes);const t=this._axes.material;t&&t.depthTest!==void 0&&(t.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}Rf([m()],el.prototype,"length",2),Rf([m()],el.prototype,"depthTest",2),Rf([m()],el.prototype,"isGizmo",2);class Tf extends A{constructor(){super(...arguments),a(this,"from"),a(this,"to"),a(this,"hint"),a(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const t=te(this.to).clone(),i=te(this.from).clone(),n=t.distanceTo(i),o=t.clone();o.sub(i);const r=i.clone();r.add(t),r.multiplyScalar(.5);const l=te(this.hint).clone();l.sub(r);const c=new x;c.crossVectors(l,o),c.crossVectors(o,c),c.normalize();const h=n*.5,d=Math.max(this.desiredDistance,h),u=Math.sqrt(d*d-h*h),p=c.clone();p.multiplyScalar(u),p.add(r),ut(this.gameObject,p);const g=r.clone();g.sub(c),this.gameObject.lookAt(g)}}const QM=O("gizmos"),YM=O("debugboxhelper"),Js=class extends A{constructor(){super(...arguments),a(this,"box",null),a(this,"_lastMatrixUpdateFrame",-1),a(this,"_helper",null),a(this,"_color",null)}isInBox(s){var t;if(!s)return;if(this.box||(this.box=new _i),ci([s],void 0,void 0,Js.testBox),Js.testBox.isEmpty()){const n=te(s,Js._position);Js.testBox.setFromCenterAndSize(n,Js._emptyObjectSize)}this.updateBox();const i=(t=this.box)==null?void 0:t.intersectsBox(Js.testBox);return i&&YM&&q.DrawWireBox3(Js.testBox,16711680,5),i}intersects(s){return s?this.updateBox(!1).intersectsBox(s):!1}updateBox(s=!1){if(this.box||(this.box=new _i),s||this.context.time.frameCount!=this._lastMatrixUpdateFrame){const t=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;const i=t,n=te(this.gameObject,Js._position,i),o=Je(this.gameObject,Js._size);this.box.setFromCenterAndSize(n,o)}return this.box}awake(){this._helper=null,this._color=null,this.box=null}showHelper(s=null,t=!1){var i;if(!(!QM&&!t)){if(this._helper){s&&((i=this._color)==null||i.set(s)),this.gameObject.add(this._helper);return}this._helper=_g(s),this.gameObject.add(this._helper)}}};let is=Js;a(is,"testBox",new _i),a(is,"_position",new x),a(is,"_size",new x(.01,.01,.01)),a(is,"_emptyObjectSize",new x(.01,.01,.01));var KM=Object.defineProperty,ZM=Object.getOwnPropertyDescriptor,ui=(s,t,i,n)=>{for(var o=n>1?void 0:n?ZM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&KM(t,i,o),o};class pi extends A{constructor(){super(...arguments),a(this,"attachedRigidbody",null),a(this,"isTrigger",!1),a(this,"sharedMaterial"),a(this,"membership",[0]),a(this,"filter"),a(this,"updateProperties",()=>{var t;(t=this.context.physics.engine)==null||t.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}onDisable(){var t;(t=this.context.physics.engine)==null||t.removeBody(this)}get body(){var t;return(t=this.context.physics.engine)==null?void 0:t.getBody(this)}updatePhysicsMaterial(){var t;(t=this.context.physics.engine)==null||t.updatePhysicsMaterial(this)}}ui([m(ve)],pi.prototype,"attachedRigidbody",2),ui([m()],pi.prototype,"isTrigger",2),ui([m()],pi.prototype,"sharedMaterial",2),ui([m()],pi.prototype,"membership",2),ui([m()],pi.prototype,"filter",2);class tl extends pi{constructor(){super(...arguments),a(this,"radius",.5),a(this,"center",new x(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addSphereCollider(this),_d(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),Am(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}ui([Rt(),m()],tl.prototype,"radius",2),ui([m(x)],tl.prototype,"center",2);const Xw=class extends pi{constructor(){super(...arguments),a(this,"size",new x(1,1,1)),a(this,"center",new x(0,0,0))}static add(s,t){const i=Mi(s,Xw);return i.autoFit(),t?.rigidbody===!0&&Mi(s,ve,{isKinematic:!1}),i}onEnable(){var s;super.onEnable(),(s=this.context.physics.engine)==null||s.addBoxCollider(this,this.size),_d(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),Am(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}autoFit(s){const t=this.gameObject,i=t.position.clone(),n=t.quaternion.clone(),o=t.scale.clone(),r=t.parent;t.position.set(0,0,0),t.quaternion.set(0,0,0,1),t.scale.set(1,1,1),t.parent=null,t.updateMatrix();const l=ci([t]);t.position.copy(i),t.quaternion.copy(n),t.scale.copy(o),t.parent=r,s?.debug===!0&&q.DrawWireBox3(l,16768256,20),this.size=l.getSize(new x)||new x(1,1,1),this.center=l.getCenter(new x)||new x(0,0,0),this.size.length()<=0&&this.size.set(.01,.01,.01)}};let il=Xw;ui([Rt(),m(x)],il.prototype,"size",2),ui([m(x)],il.prototype,"center",2);class Ao extends pi{constructor(){super(...arguments),a(this,"sharedMesh"),a(this,"convex",!1)}onEnable(){var t,i,n;if(super.onEnable(),!this.context.physics.engine)return;(t=this.sharedMesh)!=null&&t.isMesh||(this.gameObject instanceof K||this.gameObject instanceof oo)&&(this.sharedMesh=this.gameObject);const o=0;if((i=this.sharedMesh)!=null&&i.isMesh)this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex),it.assignMeshLOD(this.sharedMesh,o).then(r=>{r&&this.activeAndEnabled&&this.context.physics.engine&&this.sharedMesh&&(this.context.physics.engine.removeBody(this),this.sharedMesh.geometry=r,this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex))});else{const r=this.sharedMesh;if(r!=null&&r.isGroup){console.warn(`MeshCollider mesh is a group "${((n=this.sharedMesh)==null?void 0:n.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 r.children){const h=r.children[c];h.isMesh&&(this.context.physics.engine.addMeshCollider(this,h,this.convex),l.push(it.assignMeshLOD(h,o)))}Promise.all(l).then(c=>{var h,d;if(c.some(p=>p)==!1)return;(h=this.context.physics.engine)==null||h.removeBody(this);const u=new K;for(const p of c)p&&this.activeAndEnabled&&(u.geometry=p,(d=this.context.physics.engine)==null||d.addMeshCollider(this,u,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)}}}ui([m(K)],Ao.prototype,"sharedMesh",2),ui([m()],Ao.prototype,"convex",2);class In extends pi{constructor(){super(...arguments),a(this,"center",new x(0,0,0)),a(this,"radius",.5),a(this,"height",2)}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addCapsuleCollider(this,this.height,this.radius)}}ui([m(x)],In.prototype,"center",2),ui([m()],In.prototype,"radius",2),ui([m()],In.prototype,"height",2);var JM=Object.defineProperty,eR=Object.getOwnPropertyDescriptor,jn=(s,t,i,n)=>{for(var o=n>1?void 0:n?eR(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&JM(t,i,o),o};const Qw=O("debugcharactercontroller");class Ur extends A{constructor(){super(...arguments),a(this,"center",new x(0,0,0)),a(this,"radius",.5),a(this,"height",2),a(this,"_rigidbody",null),a(this,"_activeGroundCollisions"),a(this,"_contactVelocity",new x)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(ve),this._rigidbody||(this._rigidbody=this.gameObject.addComponent(ve)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const t=this.rigidbody;let i=this.gameObject.getComponent(In);i||(i=this.gameObject.addComponent(In)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height;const n=new x(0,0,1),o=new x(1,0,0),r=new x(0,1,0),l=this.gameObject.getWorldDirection(new x);l.y=0;const c=o.dot(l)<0?-1:1,h=n.angleTo(l)*c;this.gameObject.setRotationFromAxisAngle(r,h),t.lockRotationX=!0,t.lockRotationY=!0,t.lockRotationZ=!0}move(t){this.gameObject.position.add(t)}onCollisionEnter(t){(t.contacts.length==0||t.contacts.some(i=>i.normal.y>.2))&&(this._activeGroundCollisions.add(t),Qw&&console.log(`Collision(${this._activeGroundCollisions.size}): ${t.contacts.map(i=>i.normal.y.toFixed(2)).join(", ")} - ${this.isGrounded}`))}onCollisionExit(t){this._activeGroundCollisions.delete(t),Qw&&console.log(`Collision(${this._activeGroundCollisions.size}) - ${this.isGrounded}`)}get isGrounded(){return this._activeGroundCollisions.size>0}get contactVelocity(){var t;this._contactVelocity.set(0,0,0);for(const i of this._activeGroundCollisions){const n=(t=this.context.physics.engine)==null?void 0:t.getLinearVelocity(i.collider);n&&(this._contactVelocity.x+=n.x,this._contactVelocity.y+=n.y,this._contactVelocity.z+=n.z)}return this._contactVelocity}}jn([m(x)],Ur.prototype,"center",2),jn([m()],Ur.prototype,"radius",2),jn([m()],Ur.prototype,"height",2);class Dn extends A{constructor(){super(...arguments),a(this,"controller"),a(this,"movementSpeed",2),a(this,"rotationSpeed",2),a(this,"jumpForce",1),a(this,"doubleJumpForce",2),a(this,"animator"),a(this,"lookForward",!0),a(this,"lookInput",new oe(0,0)),a(this,"moveInput",new oe(0,0)),a(this,"jumpInput",!1),a(this,"_currentSpeed",new x(0,0,0)),a(this,"_currentAngularSpeed",new x(0,0,0)),a(this,"_temp",new x(0,0,0)),a(this,"_jumpCount",0),a(this,"_currentRotation"),a(this,"_raycastOptions",new Ws)}awake(){this._currentRotation=new V}update(){const t=this.context.input;t.isKeyPressed("KeyW")?this.moveInput.y+=1:t.isKeyPressed("KeyS")&&(this.moveInput.y-=1),t.isKeyPressed("KeyD")?this.lookInput.x+=1:t.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=t.isKeyDown("Space"))}move(t){this.moveInput.add(t)}look(t){this.lookInput.add(t)}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(t,i,n){var o,r,l,c,h,d,u,p,g,y,f;if((o=this.controller)!=null&&o.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((r=this.animator)==null||r.setBool("doubleJump",!1))),this._currentSpeed.z+=t.y*this.movementSpeed*this.context.time.deltaTime,(l=this.animator)==null||l.setBool("running",t.length()>.01),(h=this.animator)==null||h.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+=W.toRadians(-i.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const v=this.context.mainCameraComponent.forward;v.y=0,v.normalize(),this._currentRotation.setFromUnitVectors(new x(0,0,1),v),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 v=(d=this.controller)==null?void 0:d.isGrounded;if(this.doubleJumpForce>0&&!((u=this.controller)!=null&&u.isGrounded)&&this._jumpCount===1&&(v=!0,(p=this.animator)==null||p.setBool("doubleJump",!0)),v){this._jumpCount+=1;const b=this.controller.rigidbody,w=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;b.applyImpulse(new x(0,1,0).multiplyScalar(w))}}if(this.controller){const v=(g=this.controller)==null?void 0:g.rigidbody.getVelocity().y;if(v<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new no),this._raycastOptions.ray.origin.copy(te(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const b=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const w=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(b),(w.length&&w[0].distance>2||v<-10)&&((y=this.animator)==null||y.setBool("falling",!0))}else(f=this.animator)==null||f.setBool("falling",!1)}}}jn([m(Ur)],Dn.prototype,"controller",2),jn([m()],Dn.prototype,"movementSpeed",2),jn([m()],Dn.prototype,"rotationSpeed",2),jn([m()],Dn.prototype,"jumpForce",2),jn([m()],Dn.prototype,"doubleJumpForce",2),jn([m(Mt)],Dn.prototype,"animator",2);var tR=Object.defineProperty,iR=Object.getOwnPropertyDescriptor,sl=(s,t,i,n)=>{for(var o=n>1?void 0:n?iR(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&tR(t,i,o),o};const Zc=O("debugcontactshadows");kw(s=>{const t=s.domElement.getAttribute("contactshadows");t!=null&&t!="0"&&t!="false"&&ks.auto(s)});var Ef;const Jc=(Ef=class extends A{constructor(){super(...arguments),a(this,"autoFit",!1),a(this,"darkness",.5),a(this,"opacity",.5),a(this,"blur",4),a(this,"occludeBelowGround",!1),a(this,"backfaceShadows",!0),a(this,"minSize"),a(this,"shadowsRoot",new I),a(this,"shadowCamera"),a(this,"shadowGroup",new oo),a(this,"renderTarget"),a(this,"renderTargetBlur"),a(this,"plane"),a(this,"occluderMesh"),a(this,"blurPlane"),a(this,"depthMaterial"),a(this,"horizontalBlurMaterial"),a(this,"verticalBlurMaterial"),a(this,"textureSize",512)}static auto(s){if(s||(s=ee.Current),!s)throw new Error("No context provided and no current context set.");let t=this._instances.get(s);if(!t||t.destroyed){const i=new I;t=Mi(i,Jc,{autoFit:!1,occludeBelowGround:!1}),this._instances.set(s,t)}return s.scene.add(t.gameObject),t.fitShadows(),t}fitShadows(){Zc&&console.warn("Fitting shadows to scene"),Od(this.shadowsRoot,!1);const s=ci(this.context.scene.children,[this.shadowsRoot]),t=Math.max(1,this.blur/32),i=s.max.x-s.min.x,n=s.max.z-s.min.z;s.expandByVector(new x(t*i,0,t*n)),Zc&&q.DrawWireBox3(s,16776960,60),this.gameObject.parent&&s.applyMatrix4(this.gameObject.parent.matrixWorld.clone().invert());const o=s.min,r=Math.max(1e-5,(s.max.y-o.y)*.002);s.max.y+=r,this.shadowsRoot.position.set((o.x+s.max.x)/2,o.y-r,(o.z+s.max.z)/2),this.shadowsRoot.scale.set(s.max.x-o.x,s.max.y-o.y,s.max.z-o.z),this.applyMinSize(),this.shadowsRoot.matrixWorldNeedsUpdate=!0,Zc&&console.log("Fitted shadows to scene",this.shadowsRoot.scale.clone())}awake(){Jc._instances.set(this.context,this),this.shadowsRoot.hideFlags=Uu.DontExport,Od(this.shadowsRoot,!1)}start(){Zc&&console.log("Create ContactShadows on "+this.gameObject.name,this),this.gameObject.add(this.shadowsRoot),this.shadowsRoot.add(this.shadowGroup),this.renderTarget=new ao(this.textureSize,this.textureSize),this.renderTarget.texture.generateMipmaps=!1,this.renderTargetBlur=new ao(this.textureSize,this.textureSize),this.renderTargetBlur.texture.generateMipmaps=!1;const s=new Fs(1,1).rotateX(Math.PI/2);this.gameObject instanceof K&&(console.warn("ContactShadows can not be added to a Mesh. Please add it to a Group or an empty Object"),Mn(this.gameObject,!1));const t=new Re({map:this.renderTarget.texture,opacity:this.opacity,color:0,transparent:!0,depthWrite:!1,side:lo});this.plane=new K(s,t),this.plane.scale.y=-1,this.plane.layers.set(2),this.shadowsRoot.add(this.plane),this.plane&&(this.plane.renderOrder=1),this.occluderMesh=new K(this.plane.geometry,new Re({depthWrite:!0,stencilWrite:!0,colorWrite:!1,side:ym})).translateY(-1e-4),this.occluderMesh.renderOrder=-100,this.occluderMesh.layers.set(2),this.shadowsRoot.add(this.occluderMesh),this.blurPlane=new K(s),this.blurPlane.visible=!1,this.shadowGroup.add(this.blurPlane);const i=0,n=1;this.shadowCamera=new mm(-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 AS,this.depthMaterial.userData.darkness={value:this.darkness},this.depthMaterial.blending=IS,this.depthMaterial.blendEquation=jS,this.depthMaterial.onBeforeCompile=o=>{this.depthMaterial&&(o.uniforms.darkness=this.depthMaterial.userData.darkness,o.fragmentShader=`
|
|
925
|
+
Incoming:`,this._incomingCalls),r}else nt&&console.error("Failed to make call",s,t,this._peer)}closeAll(){for(const s of this._incomingCalls)s.close();for(const s of this._outgoingCalls)s.close();this.updateCalls()}get peer(){return this._peer}get incomingCalls(){return this._incomingCalls}enable(){this._enabled||(this._enabled=!0,this.context.connection.beginListen(ie.JoinedRoom,this.onConnectRoomFn),this.subscribePeerEvents())}disable(){this._enabled&&(this._enabled=!1,this.context.connection.stopListen(ie.JoinedRoom,this.onConnectRoomFn),this.unsubscribePeerEvents())}onConnectRoom(){this.setupPeer()}setupPeer(){if(this.context.connection.connectionId&&!this._enabledPeer){if(this._enabledPeer=!0,!this._peer){const s=this.getMyPeerId();s?this._peer=Ob(s):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(s,t,i){const n=s.metadata;(!n||!n.userId)&&console.error("Missing call metadata",s);const o=n.userId;t==="incoming"&&nt?console.warn("\u2190 Receive call from",s.metadata,s.connectionId):nt&&console.warn("\u2192 Make call to",s.metadata);const r=t==="incoming"?this._incomingCalls:this._outgoingCalls,l=new AM(o,s,t,i);return r.push(l),s.on("error",c=>{console.error("Call error",c)}),s.on("close",()=>{nt&&console.log("Call ended",s.metadata);const c=r.indexOf(l);c!==-1&&r.splice(c,1),l.close(),this.dispatchEvent(new Sf(o,t))}),l.addEventListener("call-ended",c=>{this.dispatchEvent(c)}),t==="incoming"&&(l.addEventListener("receive-stream",c=>{this.dispatchEvent(c)}),s.on("stream",()=>{nt&&console.log("Received stream for call",s.metadata);let c=0;const h=setInterval(()=>{const d=c===0;!l.isOpen&&d&&(nt&&console.warn("Close call because stream is not active",s.metadata),c+=1,clearInterval(h),l.close())},2e3)})),l}};let Xc=Gc;a(Xc,"instances",new Map);class cd extends fm{constructor(t,i){if(super(),a(this,"context"),a(this,"peer"),a(this,"_sendingStreams",new Map),a(this,"debug",!1),a(this,"_enabled",!1),a(this,"_tickIntervalId"),a(this,"tick",()=>{this.updateSendingCalls()}),a(this,"onJoinedRoom",n=>{this._sendingStreams.size>0&&(this.debug&&console.warn(`${n!=null&&n.userId?`User ${n.userId}`:"You"} joined room`,n,this._sendingStreams.size),this.updateSendingCalls())}),a(this,"onLeftRoom",n=>{this.debug&&console.warn(`${n?.userId||"You"} left room`,n),this.stopCallsToUsersThatAreNotInTheRoomAnymore(),this.peer.closeAll()}),a(this,"onCallStreamReceived",n=>{this.debug&&console.log("Call with "+n.userId+" started"),this.dispatchEvent({type:"receive-stream",target:this,stream:n.stream,userId:n.userId}),this.debug&&this.debugLogCurrentState()}),a(this,"onCallEnded",n=>{this.debug&&console.log("Call with "+n.userId+" ended"),this.dispatchEvent(n),this.debug&&this.debugLogCurrentState()}),a(this,"onUserConnected",n=>{if(this.peer.id===n.guid){this.debug&&console.log("PEER USER CONNECTED",n.guid,n,this._sendingStreams.size);const o=this._sendingStreams.keys().next().value;this.peer.makeCall(n.peerId,o)}else nt&&console.log("Unknown user connected",n.guid,n.peerId)}),a(this,"onUserLeft",n=>{this.debug&&console.log("User left room: "+n.userId),this.stopCallsToUsersThatAreNotInTheRoomAnymore()}),Bw(t)){const n=t;t=n.context,i=Xc.getOrCreate(n.context,n.guid)}else typeof i=="string"&&(i=Xc.getOrCreate(t,i));if(t){if(!(t instanceof ee))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=t,this.peer=i,nt&&(this.debug=!0)}static create(t,i){const n=Xc.getOrCreate(t.context,i||t.context.connection.connectionId||t.guid);return new cd(t.context,n)}startSendingStream(t){this._sendingStreams.has(t)?console.warn("Received start sending stream with stream that is already being sent"):(this._sendingStreams.set(t,[]),this.updateSendingCalls())}stopSendingStream(t){if(t){const i=this._sendingStreams.get(t);if(i){for(const n of i)n.close();i.length=0}this._sendingStreams.delete(t),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(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ie.UserJoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ie.UserLeftRoom,this.onUserLeft),this.context.connection.beginListen(ie.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(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ie.UserJoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ie.UserLeftRoom,this.onUserLeft),this.context.connection.stopListen(ie.LeftRoom,this.onLeftRoom),this._tickIntervalId!=null&&(clearInterval(this._tickIntervalId),this._tickIntervalId=void 0))}updateSendingCalls(){const t=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===t)continue;const r=this.peer.getPeerIdFromUserId(o);if(n.find(l=>{var c;return l.peerId===r&&l.direction==="outgoing"&&!l.isClosed&&((c=l.stream)==null?void 0:c.active)}))nt&&console.debug("Already have a call with user "+o+" / peer "+r);else{const l=this.peer.makeCall(r,i);l&&n.push(l)}}this._sendingStreams.set(i,n)}this.stopCallsToUsersThatAreNotInTheRoomAnymore()}stopCallsToUsersThatAreNotInTheRoomAnymore(){for(const t of this._sendingStreams.keys()){const i=this._sendingStreams.get(t);if(i)for(let n=i.length-1;n>=0;n--){const o=i[n];this.context.connection.userIsInRoom(o.userId)?nt&&(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}`)):(nt&&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(t=>t.userId).join(", ")})`,this.peer.incomingCalls)}}function Ks(s){if(s&&s instanceof MediaStream)for(const t of s.getTracks())t.stop()}var IM=Object.defineProperty,jM=Object.getOwnPropertyDescriptor,Cf=(s,t,i,n)=>{for(var o=n>1?void 0:n?jM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&IM(t,i,o),o};const DM="noVoip",LM=O("debugvoip");class Eo extends A{constructor(){super(...arguments),a(this,"autoConnect",!0),a(this,"runInBackground",!0),a(this,"createMenuButton",!0),a(this,"debug",!1),a(this,"_net"),a(this,"_menubutton"),a(this,"_allowSending",!0),a(this,"_outputStream",null),a(this,"onJoinedRoom",async()=>{this.debug&&console.log("VOIP: Joined room"),await ys(300),this.autoConnect&&!this.isSending&&this._allowSending&&this.connect()}),a(this,"onLeftRoom",()=>{this.debug&&console.log("VOIP: Left room"),this.disconnect();for(const t of this._incomingStreams.values())Ks(t.srcObject);this._incomingStreams.clear()}),a(this,"_incomingStreams",new Map),a(this,"onReceiveStream",t=>{const i=t.target.userId,n=t.stream;let o=this._incomingStreams.get(i);o||(o=new Audio,this._incomingStreams.set(i,o)),o.srcObject=n,o.setAttribute("autoplay","true"),Rn.registerWaitForInteraction(()=>{o?.play().catch(r=>{console.error("VOIP: Failed to play audio",r)})})}),a(this,"onStreamEnded",t=>{const i=this._incomingStreams.get(t.userId);Ks(i?.srcObject),this._incomingStreams.delete(t.userId)}),a(this,"onEnabledChanged",()=>{for(const t of this._incomingStreams){const i=t[1];i.muted=!this.enabled}}),a(this,"onVisibilityChanged",()=>{if(this.runInBackground)return;const t=document.visibilityState!=="visible";this.setMuted(t);for(const i of this._incomingStreams){const n=i[1];n.muted=t}})}awake(){LM&&(this.debug=!0),this.debug&&(console.log("VOIP debugging: press 'v' to toggle mute or 'c' to toggle connect/disconnect"),window.addEventListener("keydown",async t=>{switch(t.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=cd.create(this)),this.debug&&(this._net.debug=!0),this._net.addEventListener(Ys.StreamReceived,this.onReceiveStream),this._net.addEventListener(Ys.StreamEnded,this.onStreamEnded),this._net.enable(),this.autoConnect&&this.context.connection.isConnected&&this.connect(),this.context.connection.beginListen(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ie.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.addEventListener("visibilitychange",this.onVisibilityChanged)}onDisable(){var t;this._net&&(this._net.stopSendingStream(this._outputStream),this._net.removeEventListener(Ys.StreamReceived,this.onReceiveStream),this._net.removeEventListener(Ys.StreamEnded,this.onStreamEnded),(t=this._net)==null||t.disable()),this.context.connection.stopListen(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ie.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.removeEventListener("visibilitychange",this.onVisibilityChanged)}onDestroy(){var t;(t=this._menubutton)==null||t.remove(),this._menubutton=void 0}get isSending(){return this._outputStream!=null&&this._outputStream.active}async connect(t){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 X.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),Ks(this._outputStream),this._outputStream=await this.getAudioStream(t),this._outputStream?(this.debug&&console.log("VOIP: Got audio stream"),(n=this._net)==null||n.startSendingStream(this._outputStream),this.updateButton(),!0):(this.updateButton(),await X.microphonePermissionsGranted()?console.error("VOIP: Could not get audio stream - please make sure to connect an audio device and grant microphone permissions"):lc("Microphone permissions not granted: Please grant microphone permissions to use voice chat"),(this.debug||F())&&console.log("VOIP: Failed to get audio stream"),!1)}disconnect(t){var i;t!=null&&t.remember&&(this._allowSending=!1),(i=this._net)==null||i.stopSendingStream(this._outputStream),Ks(this._outputStream),this._outputStream=null,this.updateButton()}setMuted(t){var i;const n=(i=this._outputStream)==null?void 0:i.getAudioTracks();if(n)for(const o of n)o.enabled=!t}get isMuted(){var t;if(this._outputStream===null)return!1;const i=(t=this._outputStream)==null?void 0:t.getAudioTracks();if(i){for(const n of i)if(!n.enabled)return!0}return!1}async updateButton(){var t;if(this.createMenuButton){if(this._menubutton||(this._menubutton=document.createElement("button"),this._menubutton.addEventListener("click",()=>{this.isSending?this.disconnect({remember:!0}):this.connect(),X.microphonePermissionsGranted().then(i=>{i||xe("<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 X.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(kt(n)),this.context.connection.isConnected==!1?this._menubutton.setAttribute("disabled",""):this._menubutton.removeAttribute("disabled")}}else this.activeAndEnabled||(t=this._menubutton)==null||t.remove()}getFrequency(t){return this.unsupported_getfrequency||(this.unsupported_getfrequency=!0,F()&&xe("VOIP: getFrequency is currently not supported"),console.warn("VOIP: getFrequency is currently not supported")),null}async getAudioStream(t){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(r=>(console.warn("VOIP failed getting audio stream",r),null)),n=await i(t);if(!n)return null;if(X.isiOS()&&t?.deviceId===void 0){const o=(await navigator.mediaDevices.enumerateDevices()).find(r=>(r.kind==="audioinput"||r.kind==="audiooutput")&&!r.label.includes("iPhone"));if(o){const r=Object.assign({},t);return r.deviceId=o.deviceId,await i(r)}}return n}}Cf([m()],Eo.prototype,"autoConnect",2),Cf([m()],Eo.prototype,"runInBackground",2),Cf([m()],Eo.prototype,"createMenuButton",2);var BM=Object.defineProperty,FM=Object.getOwnPropertyDescriptor,Hw=(s,t,i,n)=>{for(var o=n>1?void 0:n?FM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&BM(t,i,o),o};const zM=O("debugmouth");class Qc extends A{constructor(){super(...arguments),a(this,"idle",[]),a(this,"talking",[]),a(this,"marker",null),a(this,"voip",null),a(this,"lastMouthChangeTime",0),a(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=P.findObjectOfType(Eo,this.context),this.marker||(this.marker=P.getComponentInParent(this.gameObject,Tt))},3e3)}update(){var t;if(!this.voip||this.context.time.frameCount%10!==0)return;let i=((t=this.marker)==null?void 0:t.connectionId)??null;if(!i){zM&&(i=null);return}const n=this.voip.getFrequency(i)??0;this.updateLips(n)}updateLips(t){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&t>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(t,i){if(t){t!=this.idle?this.idle.map(n=>n.visible=!1):this.talking.map(n=>n.visible=!1);for(let n=0;n<t.length;n++){const o=t[n];o&&(o.visible=n===i)}}}}Hw([m(I)],Qc.prototype,"idle",2),Hw([m(I)],Qc.prototype,"talking",2);class Of extends A{constructor(){super(...arguments),a(this,"voip",null),a(this,"marker",null),a(this,"_startPosition",null)}awake(){this.voip=P.findObjectOfType(Eo,this.context),this.marker=P.getComponentInParent(this.gameObject,Tt)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const t=this.marker.connectionId,i=this.voip.getFrequency(t);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 UM=Object.defineProperty,NM=Object.getOwnPropertyDescriptor,WM=(s,t,i,n)=>{for(var o=n>1?void 0:n?NM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&UM(t,i,o),o};const Za=O("debugxrflags"),$w=O("disablexrflags");$w&&console.warn("XRFlags are disabled");var Zs=(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))(Zs||{});const qw=class{constructor(){a(this,"Mask",17)}Has(s){return(this.Mask&s)!==0}Set(s){Za&&console.warn("Set XR flag state to",s),this.Mask=s,Ai.Apply()}Enable(s){this.Mask|=s,Ai.Apply()}Disable(s){this.Mask&=~s,Ai.Apply()}Toggle(s){this.Mask^=s,Ai.Apply()}EnableAll(){this.Mask=-1,Ai.Apply()}DisableAll(){this.Mask=0,Ai.Apply()}};let Kt=qw;a(Kt,"Global",new qw);var Yc;const An=(Yc=class extends A{constructor(){super(...arguments),a(this,"visibleIn")}static Apply(){for(const s of this.registry)s.UpdateVisible(Kt.Global)}awake(){An.registry.push(this)}onEnable(){An.firstApply?this.UpdateVisible(Kt.Global):(An.firstApply=!0,An.Apply())}onDestroy(){const s=An.registry.indexOf(this);s>=0&&An.registry.splice(s,1)}get isOn(){return this.gameObject.visible}UpdateVisible(s=null){if($w)return;let t;const i=s;if(i&&typeof i=="number"&&(console.assert(typeof i=="number","XRFlag.UpdateVisible: state must be a number",i),Za&&console.log(i),An.buffer.Mask=i,s=An.buffer),s instanceof Kt?(Za&&console.warn(this.name,"use passed in mask",s.Mask,this.visibleIn),t=s.Has(this.visibleIn)):(Za&&console.log(this.name,"use global mask"),Kt.Global.Has(this.visibleIn)),t!==void 0)if(t)Za&&console.log(this.name,"is visible",this.gameObject.uuid),P.setActive(this.gameObject,!0);else{if(Za&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},a(Yc,"registry",[]),a(Yc,"firstApply"),a(Yc,"buffer",new Kt),Yc);let Ai=An;WM([m()],Ai.prototype,"visibleIn",2);var VM=Object.defineProperty,HM=Object.getOwnPropertyDescriptor,Nu=(s,t,i,n)=>{for(var o=n>1?void 0:n?HM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&VM(t,i,o),o};class zr extends A{constructor(){super(...arguments),a(this,"eyes",[]),a(this,"lastBlinkTime",0),a(this,"blinkLength",0),a(this,"eyesOpen",!0),a(this,"state",null)}awake(){this.state=P.getComponentInParent(this.gameObject,Ai)}update(){if(!(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)&&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 t of this.eyes)t&&(t.visible=this.eyesOpen)}}}Nu([m(I)],zr.prototype,"eyes",2),Nu([m()],zr.prototype,"lastBlinkTime",2),Nu([m()],zr.prototype,"blinkLength",2),Nu([m()],zr.prototype,"eyesOpen",2);var $M=Object.defineProperty,qM=Object.getOwnPropertyDescriptor,Pf=(s,t,i,n)=>{for(var o=n>1?void 0:n?qM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&$M(t,i,o),o},kf;const Gw=(kf=class extends A{constructor(){super(...arguments),a(this,"head",null),a(this,"eyes",null),a(this,"target",null),a(this,"brain",null),a(this,"vec",new x),a(this,"currentTargetPoint",new x)}awake(){this.brain||(this.brain=P.getComponentInParent(this.gameObject,qc)),this.brain||(this.brain=P.addComponent(this.gameObject,qc)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const s=this.target;if(s&&this.head){const t=this.eyes;if(t){const i=te(s);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const n=te(this.head),o=this.vec.copy(this.currentTargetPoint).sub(n).normalize();if(o.length()<.1)return;const r=Gw.forward;if(r.set(0,0,1),r.applyQuaternion(Oe(this.head)),r.dot(o)>.45)for(let l=0;l<t.length;l++)t[l].lookAt(this.currentTargetPoint)}}}},a(kf,"forward",new x(0,0,1)),kf);let Ja=Gw;Pf([m(I)],Ja.prototype,"head",2),Pf([m(I)],Ja.prototype,"eyes",2),Pf([m(I)],Ja.prototype,"target",2);const Kc=O("debugavatar");class Wu{constructor(t,i,n,o){a(this,"root"),a(this,"head"),a(this,"leftHand"),a(this,"rigthHand");var r;this.root=t,this.head=i,this.leftHand=n,this.rigthHand=o,(r=this.root)==null||r.traverse(l=>l.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class Mf{constructor(){a(this,"avatarRegistryUrl",null)}async getOrCreateNewAvatarInstance(t,i){if(!i)return console.error("Can not create avatar: failed to provide id or root object"),null;let n=null;if(typeof i=="string"){if(n=await this.loadAvatar(t,i),!n){const r=new Ls;n=P.instantiate(Ca(i,t.scene),r)}}else n=i;if(!n)return null;const o=this.findAvatar(n);return o.isValid?(Kc&&console.log("[Custom Avatar] valid config",i,Kc?o:""),o):(console.warn("[Custom Avatar] config isn't valid",i,Kc?o:""),null)}async loadAvatar(t,i){if(console.assert(i!=null&&typeof i=="string","Avatar id must not be null"),i.length<=0||!i)return null;if(Kc&&console.log("[Custom Avatar] "+i+", loading..."),i.endsWith(".glb")||(i+=".glb"),this.avatarRegistryUrl===null){const o=await fetch("./"+i);let r=null;if(o.ok){const c=await o.blob();c&&(r=await c.arrayBuffer())}if(!r)return null;const l=await fs().parseSync(t,r,null,0);return l?.scene??null}const n=new gr;return Su(n,t),new Promise((o,r)=>{const l=this.avatarRegistryUrl+"/"+i;n.load(l,async c=>{await fs().createBuiltinComponents(t,l,c,null,void 0),o(c.scene)},c=>{Kc&&console.log("[Custom Avatar] "+c.loaded/c.total*100+"% loaded of "+c.total/1024+"kB")},c=>{console.error("[Custom Avatar] Error when loading: "+c),o(null)})})}cacheModel(t,i){}findAvatar(t){const i=t;let n=i;n.children.length==1&&(n=t.children[0]);let o=this.findAvatarPart(n,["head"]);const r=this.findAvatarPart(n,["left","hand"]),l=this.findAvatarPart(n,["right","hand"]);if(!o){o=i;const c=new x;new _i().setFromObject(o).getSize(c);const h=Math.max(c.x,c.y,c.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+h+" meters! Should be < 0.3m"),h>.3&&o.scale.multiplyScalar(1/h*.3)}return new Wu(i,o,r,l)}findAvatarPart(t,i){const n=t.name.toLowerCase();let o=!0;for(const r of i){if(!o)break;n.indexOf(r)===-1&&(o=!1)}if(o)return t;if(t.children)for(const r of t.children){const l=this.findAvatarPart(r,i);if(l)return l}return null}handleCustomAvatarErrors(t){if(!t.ok)throw Error(t.statusText);return t}}var GM=Object.defineProperty,XM=Object.getOwnPropertyDescriptor,Rf=(s,t,i,n)=>{for(var o=n>1?void 0:n?XM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&GM(t,i,o),o};class el extends A{constructor(){super(...arguments),a(this,"length",1),a(this,"depthTest",!0),a(this,"isGizmo",!1),a(this,"_axes",null)}onEnable(){if(this.isGizmo&&!Cc)return;this._axes||(this._axes=new wi(this.length)),this._axes.layers.disableAll(),this._axes.layers.set(this.layer),this.gameObject.add(this._axes);const t=this._axes.material;t&&t.depthTest!==void 0&&(t.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}Rf([m()],el.prototype,"length",2),Rf([m()],el.prototype,"depthTest",2),Rf([m()],el.prototype,"isGizmo",2);class Tf extends A{constructor(){super(...arguments),a(this,"from"),a(this,"to"),a(this,"hint"),a(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const t=te(this.to).clone(),i=te(this.from).clone(),n=t.distanceTo(i),o=t.clone();o.sub(i);const r=i.clone();r.add(t),r.multiplyScalar(.5);const l=te(this.hint).clone();l.sub(r);const c=new x;c.crossVectors(l,o),c.crossVectors(o,c),c.normalize();const h=n*.5,d=Math.max(this.desiredDistance,h),u=Math.sqrt(d*d-h*h),p=c.clone();p.multiplyScalar(u),p.add(r),ut(this.gameObject,p);const g=r.clone();g.sub(c),this.gameObject.lookAt(g)}}const QM=O("gizmos"),YM=O("debugboxhelper"),Js=class extends A{constructor(){super(...arguments),a(this,"box",null),a(this,"_lastMatrixUpdateFrame",-1),a(this,"_helper",null),a(this,"_color",null)}isInBox(s){var t;if(!s)return;if(this.box||(this.box=new _i),ci([s],void 0,void 0,Js.testBox),Js.testBox.isEmpty()){const n=te(s,Js._position);Js.testBox.setFromCenterAndSize(n,Js._emptyObjectSize)}this.updateBox();const i=(t=this.box)==null?void 0:t.intersectsBox(Js.testBox);return i&&YM&&q.DrawWireBox3(Js.testBox,16711680,5),i}intersects(s){return s?this.updateBox(!1).intersectsBox(s):!1}updateBox(s=!1){if(this.box||(this.box=new _i),s||this.context.time.frameCount!=this._lastMatrixUpdateFrame){const t=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;const i=t,n=te(this.gameObject,Js._position,i),o=Je(this.gameObject,Js._size);this.box.setFromCenterAndSize(n,o)}return this.box}awake(){this._helper=null,this._color=null,this.box=null}showHelper(s=null,t=!1){var i;if(!(!QM&&!t)){if(this._helper){s&&((i=this._color)==null||i.set(s)),this.gameObject.add(this._helper);return}this._helper=_g(s),this.gameObject.add(this._helper)}}};let is=Js;a(is,"testBox",new _i),a(is,"_position",new x),a(is,"_size",new x(.01,.01,.01)),a(is,"_emptyObjectSize",new x(.01,.01,.01));var KM=Object.defineProperty,ZM=Object.getOwnPropertyDescriptor,ui=(s,t,i,n)=>{for(var o=n>1?void 0:n?ZM(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&KM(t,i,o),o};class pi extends A{constructor(){super(...arguments),a(this,"attachedRigidbody",null),a(this,"isTrigger",!1),a(this,"sharedMaterial"),a(this,"membership",[0]),a(this,"filter"),a(this,"updateProperties",()=>{var t;(t=this.context.physics.engine)==null||t.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}onDisable(){var t;(t=this.context.physics.engine)==null||t.removeBody(this)}get body(){var t;return(t=this.context.physics.engine)==null?void 0:t.getBody(this)}updatePhysicsMaterial(){var t;(t=this.context.physics.engine)==null||t.updatePhysicsMaterial(this)}}ui([m(ve)],pi.prototype,"attachedRigidbody",2),ui([m()],pi.prototype,"isTrigger",2),ui([m()],pi.prototype,"sharedMaterial",2),ui([m()],pi.prototype,"membership",2),ui([m()],pi.prototype,"filter",2);class tl extends pi{constructor(){super(...arguments),a(this,"radius",.5),a(this,"center",new x(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addSphereCollider(this),_d(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),Am(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}ui([Rt(),m()],tl.prototype,"radius",2),ui([m(x)],tl.prototype,"center",2);const Xw=class extends pi{constructor(){super(...arguments),a(this,"size",new x(1,1,1)),a(this,"center",new x(0,0,0))}static add(s,t){const i=Mi(s,Xw);return i.autoFit(),t?.rigidbody===!0&&Mi(s,ve,{isKinematic:!1}),i}onEnable(){var s;super.onEnable(),(s=this.context.physics.engine)==null||s.addBoxCollider(this,this.size),_d(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),Am(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}autoFit(s){const t=this.gameObject,i=t.position.clone(),n=t.quaternion.clone(),o=t.scale.clone(),r=t.parent;t.position.set(0,0,0),t.quaternion.set(0,0,0,1),t.scale.set(1,1,1),t.parent=null,t.updateMatrix();const l=ci([t]);t.position.copy(i),t.quaternion.copy(n),t.scale.copy(o),t.parent=r,s?.debug===!0&&q.DrawWireBox3(l,16768256,20),this.size=l.getSize(new x)||new x(1,1,1),this.center=l.getCenter(new x)||new x(0,0,0),this.size.length()<=0&&this.size.set(.01,.01,.01)}};let il=Xw;ui([Rt(),m(x)],il.prototype,"size",2),ui([m(x)],il.prototype,"center",2);class Ao extends pi{constructor(){super(...arguments),a(this,"sharedMesh"),a(this,"convex",!1)}onEnable(){var t,i,n;if(super.onEnable(),!this.context.physics.engine)return;(t=this.sharedMesh)!=null&&t.isMesh||(this.gameObject instanceof K||this.gameObject instanceof oo)&&(this.sharedMesh=this.gameObject);const o=0;if((i=this.sharedMesh)!=null&&i.isMesh)this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex),it.assignMeshLOD(this.sharedMesh,o).then(r=>{r&&this.activeAndEnabled&&this.context.physics.engine&&this.sharedMesh&&(this.context.physics.engine.removeBody(this),this.sharedMesh.geometry=r,this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex))});else{const r=this.sharedMesh;if(r!=null&&r.isGroup){console.warn(`MeshCollider mesh is a group "${((n=this.sharedMesh)==null?void 0:n.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 r.children){const h=r.children[c];h.isMesh&&(this.context.physics.engine.addMeshCollider(this,h,this.convex),l.push(it.assignMeshLOD(h,o)))}Promise.all(l).then(c=>{var h,d;if(c.some(p=>p)==!1)return;(h=this.context.physics.engine)==null||h.removeBody(this);const u=new K;for(const p of c)p&&this.activeAndEnabled&&(u.geometry=p,(d=this.context.physics.engine)==null||d.addMeshCollider(this,u,this.convex))})}else(F()||O("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)}}}ui([m(K)],Ao.prototype,"sharedMesh",2),ui([m()],Ao.prototype,"convex",2);class In extends pi{constructor(){super(...arguments),a(this,"center",new x(0,0,0)),a(this,"radius",.5),a(this,"height",2)}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addCapsuleCollider(this,this.height,this.radius)}}ui([m(x)],In.prototype,"center",2),ui([m()],In.prototype,"radius",2),ui([m()],In.prototype,"height",2);var JM=Object.defineProperty,eR=Object.getOwnPropertyDescriptor,jn=(s,t,i,n)=>{for(var o=n>1?void 0:n?eR(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&JM(t,i,o),o};const Qw=O("debugcharactercontroller");class Ur extends A{constructor(){super(...arguments),a(this,"center",new x(0,0,0)),a(this,"radius",.5),a(this,"height",2),a(this,"_rigidbody",null),a(this,"_activeGroundCollisions"),a(this,"_contactVelocity",new x)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(ve),this._rigidbody||(this._rigidbody=this.gameObject.addComponent(ve)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const t=this.rigidbody;let i=this.gameObject.getComponent(In);i||(i=this.gameObject.addComponent(In)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height;const n=new x(0,0,1),o=new x(1,0,0),r=new x(0,1,0),l=this.gameObject.getWorldDirection(new x);l.y=0;const c=o.dot(l)<0?-1:1,h=n.angleTo(l)*c;this.gameObject.setRotationFromAxisAngle(r,h),t.lockRotationX=!0,t.lockRotationY=!0,t.lockRotationZ=!0}move(t){this.gameObject.position.add(t)}onCollisionEnter(t){(t.contacts.length==0||t.contacts.some(i=>i.normal.y>.2))&&(this._activeGroundCollisions.add(t),Qw&&console.log(`Collision(${this._activeGroundCollisions.size}): ${t.contacts.map(i=>i.normal.y.toFixed(2)).join(", ")} - ${this.isGrounded}`))}onCollisionExit(t){this._activeGroundCollisions.delete(t),Qw&&console.log(`Collision(${this._activeGroundCollisions.size}) - ${this.isGrounded}`)}get isGrounded(){return this._activeGroundCollisions.size>0}get contactVelocity(){var t;this._contactVelocity.set(0,0,0);for(const i of this._activeGroundCollisions){const n=(t=this.context.physics.engine)==null?void 0:t.getLinearVelocity(i.collider);n&&(this._contactVelocity.x+=n.x,this._contactVelocity.y+=n.y,this._contactVelocity.z+=n.z)}return this._contactVelocity}}jn([m(x)],Ur.prototype,"center",2),jn([m()],Ur.prototype,"radius",2),jn([m()],Ur.prototype,"height",2);class Dn extends A{constructor(){super(...arguments),a(this,"controller"),a(this,"movementSpeed",2),a(this,"rotationSpeed",2),a(this,"jumpForce",1),a(this,"doubleJumpForce",2),a(this,"animator"),a(this,"lookForward",!0),a(this,"lookInput",new oe(0,0)),a(this,"moveInput",new oe(0,0)),a(this,"jumpInput",!1),a(this,"_currentSpeed",new x(0,0,0)),a(this,"_currentAngularSpeed",new x(0,0,0)),a(this,"_temp",new x(0,0,0)),a(this,"_jumpCount",0),a(this,"_currentRotation"),a(this,"_raycastOptions",new Ws)}awake(){this._currentRotation=new V}update(){const t=this.context.input;t.isKeyPressed("KeyW")?this.moveInput.y+=1:t.isKeyPressed("KeyS")&&(this.moveInput.y-=1),t.isKeyPressed("KeyD")?this.lookInput.x+=1:t.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=t.isKeyDown("Space"))}move(t){this.moveInput.add(t)}look(t){this.lookInput.add(t)}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(t,i,n){var o,r,l,c,h,d,u,p,g,y,f;if((o=this.controller)!=null&&o.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((r=this.animator)==null||r.setBool("doubleJump",!1))),this._currentSpeed.z+=t.y*this.movementSpeed*this.context.time.deltaTime,(l=this.animator)==null||l.setBool("running",t.length()>.01),(h=this.animator)==null||h.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+=W.toRadians(-i.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const v=this.context.mainCameraComponent.forward;v.y=0,v.normalize(),this._currentRotation.setFromUnitVectors(new x(0,0,1),v),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 v=(d=this.controller)==null?void 0:d.isGrounded;if(this.doubleJumpForce>0&&!((u=this.controller)!=null&&u.isGrounded)&&this._jumpCount===1&&(v=!0,(p=this.animator)==null||p.setBool("doubleJump",!0)),v){this._jumpCount+=1;const b=this.controller.rigidbody,w=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;b.applyImpulse(new x(0,1,0).multiplyScalar(w))}}if(this.controller){const v=(g=this.controller)==null?void 0:g.rigidbody.getVelocity().y;if(v<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new no),this._raycastOptions.ray.origin.copy(te(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const b=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const w=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(b),(w.length&&w[0].distance>2||v<-10)&&((y=this.animator)==null||y.setBool("falling",!0))}else(f=this.animator)==null||f.setBool("falling",!1)}}}jn([m(Ur)],Dn.prototype,"controller",2),jn([m()],Dn.prototype,"movementSpeed",2),jn([m()],Dn.prototype,"rotationSpeed",2),jn([m()],Dn.prototype,"jumpForce",2),jn([m()],Dn.prototype,"doubleJumpForce",2),jn([m(Mt)],Dn.prototype,"animator",2);var tR=Object.defineProperty,iR=Object.getOwnPropertyDescriptor,sl=(s,t,i,n)=>{for(var o=n>1?void 0:n?iR(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&tR(t,i,o),o};const Zc=O("debugcontactshadows");kw(s=>{const t=s.domElement.getAttribute("contactshadows");t!=null&&t!="0"&&t!="false"&&ks.auto(s)});var Ef;const Jc=(Ef=class extends A{constructor(){super(...arguments),a(this,"autoFit",!1),a(this,"darkness",.5),a(this,"opacity",.5),a(this,"blur",4),a(this,"occludeBelowGround",!1),a(this,"backfaceShadows",!0),a(this,"minSize"),a(this,"shadowsRoot",new I),a(this,"shadowCamera"),a(this,"shadowGroup",new oo),a(this,"renderTarget"),a(this,"renderTargetBlur"),a(this,"plane"),a(this,"occluderMesh"),a(this,"blurPlane"),a(this,"depthMaterial"),a(this,"horizontalBlurMaterial"),a(this,"verticalBlurMaterial"),a(this,"textureSize",512)}static auto(s){if(s||(s=ee.Current),!s)throw new Error("No context provided and no current context set.");let t=this._instances.get(s);if(!t||t.destroyed){const i=new I;t=Mi(i,Jc,{autoFit:!1,occludeBelowGround:!1}),this._instances.set(s,t)}return s.scene.add(t.gameObject),t.fitShadows(),t}fitShadows(){Zc&&console.warn("Fitting shadows to scene"),Od(this.shadowsRoot,!1);const s=ci(this.context.scene.children,[this.shadowsRoot]),t=Math.max(1,this.blur/32),i=s.max.x-s.min.x,n=s.max.z-s.min.z;s.expandByVector(new x(t*i,0,t*n)),Zc&&q.DrawWireBox3(s,16776960,60),this.gameObject.parent&&s.applyMatrix4(this.gameObject.parent.matrixWorld.clone().invert());const o=s.min,r=Math.max(1e-5,(s.max.y-o.y)*.002);s.max.y+=r,this.shadowsRoot.position.set((o.x+s.max.x)/2,o.y-r,(o.z+s.max.z)/2),this.shadowsRoot.scale.set(s.max.x-o.x,s.max.y-o.y,s.max.z-o.z),this.applyMinSize(),this.shadowsRoot.matrixWorldNeedsUpdate=!0,Zc&&console.log("Fitted shadows to scene",this.shadowsRoot.scale.clone())}awake(){Jc._instances.set(this.context,this),this.shadowsRoot.hideFlags=Uu.DontExport,Od(this.shadowsRoot,!1)}start(){Zc&&console.log("Create ContactShadows on "+this.gameObject.name,this),this.gameObject.add(this.shadowsRoot),this.shadowsRoot.add(this.shadowGroup),this.renderTarget=new ao(this.textureSize,this.textureSize),this.renderTarget.texture.generateMipmaps=!1,this.renderTargetBlur=new ao(this.textureSize,this.textureSize),this.renderTargetBlur.texture.generateMipmaps=!1;const s=new Fs(1,1).rotateX(Math.PI/2);this.gameObject instanceof K&&(console.warn("ContactShadows can not be added to a Mesh. Please add it to a Group or an empty Object"),Mn(this.gameObject,!1));const t=new Re({map:this.renderTarget.texture,opacity:this.opacity,color:0,transparent:!0,depthWrite:!1,side:lo});this.plane=new K(s,t),this.plane.scale.y=-1,this.plane.layers.set(2),this.shadowsRoot.add(this.plane),this.plane&&(this.plane.renderOrder=1),this.occluderMesh=new K(this.plane.geometry,new Re({depthWrite:!0,stencilWrite:!0,colorWrite:!1,side:ym})).translateY(-1e-4),this.occluderMesh.renderOrder=-100,this.occluderMesh.layers.set(2),this.shadowsRoot.add(this.occluderMesh),this.blurPlane=new K(s),this.blurPlane.visible=!1,this.shadowGroup.add(this.blurPlane);const i=0,n=1;this.shadowCamera=new mm(-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 AS,this.depthMaterial.userData.darkness={value:this.darkness},this.depthMaterial.blending=IS,this.depthMaterial.blendEquation=jS,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 ms(LC),this.horizontalBlurMaterial.depthTest=!1,this.verticalBlurMaterial=new ms(BC),this.verticalBlurMaterial.depthTest=!1,this.shadowGroup.visible=!1,this.autoFit?this.fitShadows():this.applyMinSize()}onDestroy(){var s,t,i,n,o,r,l,c;Jc._instances.get(this.context)===this&&Jc._instances.delete(this.context),(s=this.renderTarget)==null||s.dispose(),(t=this.renderTargetBlur)==null||t.dispose(),(i=this.depthMaterial)==null||i.dispose(),(n=this.horizontalBlurMaterial)==null||n.dispose(),(o=this.verticalBlurMaterial)==null||o.dispose(),(r=this.blurPlane)==null||r.geometry.dispose(),(l=this.plane)==null||l.geometry.dispose(),(c=this.occluderMesh)==null||c.geometry.dispose()}onBeforeRender(s){if(!this.renderTarget||!this.renderTargetBlur||!this.depthMaterial||!this.shadowCamera||!this.blurPlane||!this.shadowGroup||!this.plane||!this.horizontalBlurMaterial||!this.verticalBlurMaterial){Zc&&console.error("ContactShadows: not initialized yet");return}const t=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 K&&Mn(this.gameObject,!1);const r=t.background;t.background=null,t.overrideMaterial=this.depthMaterial,this.backfaceShadows?this.depthMaterial.side=xi:this.depthMaterial.side=lo;const l=i.getClearAlpha();i.setClearAlpha(0);const c=i.xr.enabled;i.xr.enabled=!1;const h=this.context.scene.matrixWorldAutoUpdate;this.context.scene.matrixWorldAutoUpdate=!1;const d=i.renderLists.get(t,0),u=d.transparent;Yw.length=0,d.transparent=Yw,Af.length=0;for(const g of d.opaque){if(!g.object.visible)continue;const y=g.material;let f=g.material.colorWrite==!1||y.wireframe===!0||Jv(g.object)===!1;!f&&g.material.isLineMaterial&&(f=!0),!f&&g.material.isPointsMaterial&&(f=!0),f&&(Af.push(g.object),g.object["needle:visible"]=g.object.visible,g.object.visible=!1)}i.setRenderTarget(this.renderTarget),i.clear(),i.render(t,this.shadowCamera),d.transparent=u;for(const g of Af)g["needle:visible"]!=null&&(g.visible=g["needle:visible"]);t.overrideMaterial=null;const p=Math.max(this.blur,.05);this.blurShadow(p*2),this.blurShadow(p*.5),this.shadowGroup.visible=!1,this.occluderMesh&&(this.occluderMesh.visible=this.occludeBelowGround),this.plane.visible=o,i.setRenderTarget(n),i.setClearAlpha(l),t.background=r,i.xr.enabled=c,this.context.scene.matrixWorldAutoUpdate=h}blurShadow(s){if(!this.blurPlane||!this.shadowCamera||!this.renderTarget||!this.renderTargetBlur||!this.horizontalBlurMaterial||!this.verticalBlurMaterial)return;this.blurPlane.visible=!0;const t=this.shadowsRoot.worldScale,i=(t.x+t.z)/2,n=t.z/i,o=t.x/i;this.blurPlane.material=this.horizontalBlurMaterial,this.blurPlane.material.uniforms.tDiffuse.value=this.renderTarget.texture,this.horizontalBlurMaterial.uniforms.h.value=s*1/this.textureSize*n;const r=this.context.renderer,l=r.getRenderTarget();r.setRenderTarget(this.renderTargetBlur),r.render(this.blurPlane,this.shadowCamera),this.blurPlane.material=this.verticalBlurMaterial,this.blurPlane.material.uniforms.tDiffuse.value=this.renderTargetBlur.texture,this.verticalBlurMaterial.uniforms.v.value=s*1/this.textureSize*o,r.setRenderTarget(this.renderTarget),r.render(this.blurPlane,this.shadowCamera),this.blurPlane.visible=!1,r.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))}},a(Ef,"_instances",new Map),Ef);let ks=Jc;sl([m()],ks.prototype,"autoFit",2),sl([m()],ks.prototype,"darkness",2),sl([m()],ks.prototype,"opacity",2),sl([m()],ks.prototype,"blur",2),sl([m()],ks.prototype,"occludeBelowGround",2),sl([m()],ks.prototype,"backfaceShadows",2);const Yw=[],Af=new Array,sR=O("logstats");class If extends A{onEnable(){console.log(this),sR&&this.startCoroutine(this.run(),Me.OnAfterRender)}*run(){for(;this.enabled;){const t=this.context.renderer.info;console.log(t.memory,t.render,t.programs),yield}}}class eh extends A{constructor(){super(...arguments),a(this,"isUsed",!0),a(this,"usedBy",null)}}class jf extends A{}const Kw=O("debugdeletable"),Vu=class extends is{onEnable(){Vu._instances.push(this)}onDisable(){const s=Vu._instances.indexOf(this);s>=0&&Vu._instances.splice(s,1)}};let th=Vu;a(th,"_instances",[]);class Df extends A{update(){for(const t of th._instances){const i=this.gameObject;if(t.isInBox(i)===!0){const n=P.getComponentInParent(this.gameObject,eh);if(n)Kw&&console.warn("DeleteBox: Not deleting object with usage marker",this.guid,n);else{if(Kw)try{if(t.box){const o=t.box,r=is.testBox;q.DrawWireBox3(o,16711680,5),q.DrawWireBox3(r,255,5),console.log("DeleteBox: Destroying",this.gameObject,{deleteBoxArea:o,deletedObjectArea:r})}else console.log("DeleteBox: Destroying",this.gameObject)}catch{}Sc(this.gameObject,this.context.connection)}}}}}var nR=Object.defineProperty,oR=Object.getOwnPropertyDescriptor,rR=(s,t,i,n)=>{for(var o=n>1?void 0:n?oR(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&nR(t,i,o),o};class Hu extends A{constructor(){super(...arguments),a(this,"visibleOn")}onEnable(){this.apply()}apply(){this.test()||P.setActive(this.gameObject,!1)}test(){return this.visibleOn<0?!0:X.isMobileDevice()?(this.visibleOn&2)!==0:(this.visibleOn&1)!==0}}rR([m()],Hu.prototype,"visibleOn",2);var aR=Object.defineProperty,lR=Object.getOwnPropertyDescriptor,Nr=(s,t,i,n)=>{for(var o=n>1?void 0:n?lR(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&aR(t,i,o),o};const en=O("debugdrag"),Lf=[];var Bf=(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))(Bf||{}),ih;const ss=(ih=class extends A{constructor(){super(...arguments),a(this,"dragMode",3),a(this,"snapGridResolution",0),a(this,"keepRotation",!0),a(this,"xrDragMode",1),a(this,"xrKeepRotation",!1),a(this,"xrDistanceDragFactor",1),a(this,"showGizmo",!1),a(this,"_rigidbody",null),a(this,"_targetObject",null),a(this,"_dragHelper",null),a(this,"_draggingRigidbodies",[]),a(this,"_potentialDragStartEvt",null),a(this,"_dragHandlers",new Map),a(this,"_totalMovement",new x),a(this,"_marker",null),a(this,"_isDragging",!1),a(this,"_didDrag",!1)}static get HasAnySelected(){return this._active>0}static get CurrentlySelected(){Lf.length=0;for(const s of this._instances)s._isDragging&&Lf.push(s);return Lf}get draggedObject(){return this._targetObject}setTargetObject(s){var t,i;this._targetObject=s;for(const o of this._dragHandlers.values())o.setTargetObject(s);const n="_rigidbody-was-kinematic";((t=this._rigidbody)==null?void 0:t[n])===!1&&(this._rigidbody.isKinematic=!1,this._rigidbody[n]=void 0),this._rigidbody=null,s&&(this._rigidbody=P.getComponentInChildren(s,ve),((i=this._rigidbody)==null?void 0:i.isKinematic)===!1&&(this._rigidbody.isKinematic=!0,this._rigidbody[n]=!1))}awake(){this._potentialDragStartEvt=null,this._dragHandlers=new Map,this._totalMovement=new x,this._marker=null,this._isDragging=!1,this._didDrag=!1,this._dragHelper=null,this._draggingRigidbodies=[]}start(){this.gameObject.getComponentInParent(Ei)||this.gameObject.addComponent(Ei)}onEnable(){ss._instances.push(this)}onDisable(){ss._instances=ss._instances.filter(s=>s!==this)}allowEdit(s=null){return this.context.connection.allowEditing}onPointerEnter(s){if(!this.allowEdit(this.gameObject)||s.mode!=="screen"||(s.event.mode==="tracked-pointer"||s.event.mode==="transient-pointer"?this.xrDragMode:this.dragMode)===5)return;const t=P.getComponentInParent(s.object,ss);!t||t!==this||(ss.lastHovered=s.object,this.context.domElement.style.cursor="pointer")}onPointerMove(s){(this._isDragging||this._potentialDragStartEvt!==null)&&s.use()}onPointerExit(s){this.allowEdit(this.gameObject)&&s.mode==="screen"&&ss.lastHovered===s.object&&(this.context.domElement.style.cursor="auto")}onPointerDown(s){if(!(!this.allowEdit(this.gameObject)||s.used||(s.mode==="tracked-pointer"||s.mode==="transient-pointer"?this.xrDragMode:this.dragMode)===5)&&(ss.lastHovered=s.object,s.button===0)){this._dragHandlers.size===0&&(this._didDrag=!1,this._totalMovement.set(0,0,0),this._potentialDragStartEvt=s),this._targetObject||this.setTargetObject(this.gameObject),ss._active+=1;const t=new Ff(this,this._targetObject);if(this._dragHandlers.set(s.event.space,t),t.onDragStart(s),this._dragHandlers.size===2){const i=this._dragHandlers.values(),n=i.next().value,o=i.next().value;if(n instanceof Ff&&o instanceof Ff){const r=new cR(this,this._targetObject,n,o);this._dragHandlers.set(this.gameObject,r),r.onDragStart(s)}else console.error("Attempting to construct a MultiTouchDragHandler with invalid DragPointerHandlers. This is likely a bug.",{a:n,b:o})}s.use()}}onPointerUp(s){if(en&&q.DrawLabel(s.point??this.gameObject.worldPosition,"POINTERUP:"+s.pointerId+", "+s.button,.03,3),!this.allowEdit(this.gameObject)||s.button!==0)return;this._potentialDragStartEvt=null;const t=this._dragHandlers.get(s.event.space),i=this._dragHandlers.get(this.gameObject);i&&(i.handlerA===t||i.handlerB===t)&&(this._dragHandlers.delete(this.gameObject),i.onDragEnd(s)),t&&(ss._active>0&&(ss._active-=1),this.setTargetObject(null),t.onDragEnd&&t.onDragEnd(s),this._dragHandlers.delete(s.event.space),this._dragHandlers.size===0&&this.onLastDragEnd(s),s.use())}update(){for(const s of this._dragHandlers.values())s.collectMovementInfo&&s.collectMovementInfo(),s.getTotalMovement&&this._totalMovement.add(s.getTotalMovement());if(this._potentialDragStartEvt){if(!this._didDrag)if(this._totalMovement.length()>3e-4)this._didDrag=!0;else return;const s=this._potentialDragStartEvt;this._potentialDragStartEvt=null,this.onFirstDragStart(s)}for(const s of this._dragHandlers.values())s.onDragUpdate&&s.onDragUpdate(this._dragHandlers.size);this._dragHelper&&this._dragHelper.hasSelected&&this.onAnyDragUpdate()}onFirstDragStart(s){if(!s||!s.object)return;const t=P.getComponentInParent(s.object,ss);if(!t||t!==this&&t._isDragging)return;const i=this._targetObject||this.gameObject;if(!i)return;this._isDragging=!0;const n=P.getComponentInChildren(i,qs);en&&console.log("DRAG START",n,i),n&&(n.fastMode=!0,n?.requestOwnership()),this._marker=P.addComponent(i,eh),this._draggingRigidbodies.length=0;const o=P.getComponentsInChildren(i,ve);o&&this._draggingRigidbodies.push(...o)}onAnyDragUpdate(){if(!this._dragHelper)return;this._dragHelper.showGizmo=this.showGizmo,this._dragHelper.onUpdate(this.context);for(const t of this._draggingRigidbodies)t.wakeUp(),t.resetVelocities(),t.resetForcesAndTorques();const s=this._targetObject||this.gameObject;cs.markDirty(s)}onLastDragEnd(s){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,s!=null&&s.object){const i=P.getComponentInChildren(s.object,qs);i&&(i.fastMode=!1)}if(this._marker&&this._marker.destroy(),!this._dragHelper)return;const t=this._dragHelper.selected;en&&console.log("DRAG END",t,t?.visible),this._dragHelper.setSelected(null,this.context)}},a(ih,"_active",0),a(ih,"_instances",[]),a(ih,"lastHovered"),ih);let mi=ss;Nr([m()],mi.prototype,"dragMode",2),Nr([m()],mi.prototype,"snapGridResolution",2),Nr([m()],mi.prototype,"keepRotation",2),Nr([m()],mi.prototype,"xrDragMode",2),Nr([m()],mi.prototype,"xrKeepRotation",2),Nr([m()],mi.prototype,"xrDistanceDragFactor",2),Nr([m()],mi.prototype,"showGizmo",2);class cR{constructor(t,i,n,o){a(this,"handlerA"),a(this,"handlerB"),a(this,"context"),a(this,"settings"),a(this,"gameObject"),a(this,"_handlerAAttachmentPoint",new x),a(this,"_handlerBAttachmentPoint",new x),a(this,"_followObject"),a(this,"_manipulatorObject"),a(this,"_deviceMode"),a(this,"_followObjectStartWorldQuaternion",new V),a(this,"_manipulatorPosOffset",new x),a(this,"_manipulatorRotOffset",new V),a(this,"_manipulatorScaleOffset",new x),a(this,"_tempVec1",new x),a(this,"_tempVec2",new x),a(this,"_tempVec3",new x),a(this,"tempLookMatrix",new ne),a(this,"_initialScale",new x),a(this,"_initialDistance",0);var r,l;this.context=t.context,this.settings=t,this.gameObject=i,this.handlerA=n,this.handlerB=o,this._followObject=new I,this._manipulatorObject=new I,this.context.scene.add(this._manipulatorObject);const c=(l=(r=J.active)==null?void 0:r.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),c&&(c.worldToLocal(this._tempVec1),c.worldToLocal(this._tempVec2)),this._initialDistance=this._tempVec1.distanceTo(this._tempVec2),this._initialDistance<.02?(en&&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 \u2013 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(i.scale),en){this._followObject.add(new wi(2)),this._manipulatorObject.add(new wi(5));const h=d=>`${d.x.toFixed(2)}, ${d.y.toFixed(2)}, ${d.z.toFixed(2)}`;q.DrawLine(this._tempVec1,this._tempVec2,65535,0,!1),q.DrawLabel(this._tempVec3,"A:B "+this._initialDistance.toFixed(2)+`
|
|
@@ -1202,7 +1202,7 @@ dateFormat X
|
|
|
1202
1202
|
axisFormat %s
|
|
1203
1203
|
`;const g=Array.from(r),y=new Set;for(const w of g)if(w.affectedObjects&&typeof w.affectedObjects!="string"){if(Array.isArray(w.affectedObjects))for(const _ of w.affectedObjects)y.add(_);else y.add(w.affectedObjects);l&&(p+=`section ${w.animationName} (${w.id})
|
|
1204
1204
|
`,p+=`${w.id} : ${w.start}, ${w.duration}s
|
|
1205
|
-
`)}l&&r.size&&console.log(p);const f=new Set;for(const w of y){w.getPath||console.error("USDZExporter: Animation target object has no getPath method. This is likely a bug",w);let _=w.getPath();_.startsWith("<")&&(_=_.substring(1)),_.endsWith(">")&&(_=_.substring(0,_.length-1)),f.add({path:_,obj:w})}const v=Array.from(f).sort((w,_)=>w.path.length-_.path.length),b=new Array;for(let w=0;w<v.length;w++)for(let _=w+1;_<v.length;_++)if(v[_].path.startsWith(v[w].path)){const C=v[_],R=v[w];b.push({child:C.obj.displayName+" ("+C.path+")",parent:R.obj.displayName+" ("+R.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:r})}for(const p of new Set([...i,...n]))if(Array.isArray(p))for(const g of p)o.add(g.uuid);else o.add(p.uuid);dp&&console.log("All Behavior trigger sources and action targets",i,n,o),this.targetUuids=new Set(o)}onAfterHierarchy(t,i){var n;if((n=this.behaviours)!=null&&n.length){i.beginBlock('def Scope "Behaviors"');for(const o of this.behaviours)o.writeTo(this,t.document,i);i.closeBlock()}}async onAfterSerialize(t){dp&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const i of this.behaviourComponentsCopy)typeof i.afterSerialize=="function"&&(i.afterSerialize.constructor.name==="AsyncFunction"?await i.afterSerialize(this,t):i.afterSerialize(this,t));for(const{clipUrl:i,filesKey:n}of this.audioClipsCopy){if(t.files[n])return;const o=await(await(await fetch(i)).blob()).arrayBuffer(),r=new Uint8Array(o);t.files[n]=r}this.behaviourComponentsCopy.length=0,this.audioClipsCopy.length=0}}var mT=Object.defineProperty,gT=Object.getOwnPropertyDescriptor,$e=(s,t,i,n)=>{for(var o=n>1?void 0:n?gT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&mT(t,i,o),o};const Ux=O("debugusdzbehaviours");function hh(s){s&&(s.getComponentInParent(Xa)||(F()&&console.debug('Raycaster on "'+s.name+'" was automatically added, because no raycaster was found in the parent hierarchy.'),s.addComponent(Ei)))}class qr extends A{constructor(){super(...arguments),a(this,"object"),a(this,"target"),a(this,"duration",1),a(this,"relativeMotion",!1),a(this,"coroutine",null),a(this,"targetPos",new x),a(this,"targetRot",new V),a(this,"targetScale",new x)}start(){hh(this.gameObject)}onPointerClick(t){t.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 t=te(this.object).clone(),i=te(this.target).clone(),n=Oe(this.object).clone(),o=Oe(this.target).clone(),r=Je(this.object).clone(),l=Je(this.target).clone(),c=t.distanceTo(i),h=n.angleTo(o),d=r.distanceTo(l);if(c<.01&&h<.01&&d<.01){ut(this.object,i),Gi(this.object,o),Pa(this.object,l),this.coroutine=null;return}let u=0,p=0;for(;u<1;)u+=this.context.time.deltaTime/this.duration,u>1&&(u=1),p=u<.5?4*u*u*u:1-Math.pow(-2*u+2,3)/2,this.targetPos.lerpVectors(t,i,p),this.targetRot.slerpQuaternions(n,o,p),this.targetScale.lerpVectors(r,l,p),ut(this.object,this.targetPos),Gi(this.object,this.targetRot),Pa(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const t=this.object.position.clone(),i=this.object.quaternion.clone(),n=this.object.scale.clone(),o=this.target.position.clone(),r=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(r),this.targetScale.copy(this.object.scale).multiply(l);let c=0,h=0;for(;c<1;)c+=this.context.time.deltaTime/this.duration,c>1&&(c=1),h=c<.5?4*c*c*c:1-Math.pow(-2*c+2,3)/2,this.object.position.lerpVectors(t,this.targetPos,h),this.object.quaternion.slerpQuaternions(i,this.targetRot,h),this.object.scale.lerpVectors(n,this.targetScale,h),yield;this.coroutine=null}beforeCreateDocument(t){var i;if(this.target&&this.object&&this.gameObject){const n=new Et("Move to "+((i=this.target)==null?void 0:i.name),xt.tapTrigger(this.gameObject),ye.transformAction(this.object,this.target,this.duration,this.relativeMotion?"relative":"absolute"));t.addBehavior(n)}}}$e([m(I)],qr.prototype,"object",2),$e([m(I)],qr.prototype,"target",2),$e([m()],qr.prototype,"duration",2),$e([m()],qr.prototype,"relativeMotion",2);var fl;const ti=(fl=class extends A{constructor(){super(...arguments),a(this,"materialToSwitch"),a(this,"variantMaterial"),a(this,"fadeDuration",0),a(this,"_objectsWithThisMaterial",null),a(this,"selfModel"),a(this,"targetModels")}start(){var s;this._objectsWithThisMaterial=this.objectsWithThisMaterial,hh(this.gameObject),F()&&this._objectsWithThisMaterial.length<=0&&console.warn('ChangeMaterialOnClick: No objects found with material "'+((s=this.materialToSwitch)==null?void 0:s.name)+'"')}onPointerEnter(s){this.context.input.setCursor("pointer")}onPointerExit(s){this.context.input.unsetCursor("pointer")}onPointerClick(s){if(s.use(),!!this.variantMaterial)for(let t=0;t<this.objectsWithThisMaterial.length;t++){const i=this.objectsWithThisMaterial[t];i.material=this.variantMaterial}}get objectsWithThisMaterial(){return this._objectsWithThisMaterial!=null?this._objectsWithThisMaterial:(this._objectsWithThisMaterial=[],this.variantMaterial&&this.materialToSwitch&&this.context.scene.traverse(s=>{if(s instanceof K)if(Array.isArray(s.material)){for(const t of s.material)if(t===this.materialToSwitch){this.objectsWithThisMaterial.push(s);break}}else s.material===this.materialToSwitch?this.objectsWithThisMaterial.push(s):m_(s.material,this.materialToSwitch)&&this.objectsWithThisMaterial.push(s)}),this._objectsWithThisMaterial)}async beforeCreateDocument(s,t){this.targetModels=[],ti._materialTriggersPerId={},ti.variantSwitchIndex=0,this.materialToSwitch&&await it.assignTextureLOD(this.materialToSwitch,0),this.variantMaterial&&await it.assignTextureLOD(this.variantMaterial,0)}createBehaviours(s,t,i){this.objectsWithThisMaterial.find(n=>n.uuid===t.uuid)&&this.targetModels.push(t),this.gameObject.uuid===t.uuid&&(this.selfModel=t,this.materialToSwitch&&(ti._materialTriggersPerId[this.materialToSwitch.uuid]||(ti._materialTriggersPerId[this.materialToSwitch.uuid]=[]),ti._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(s,t){if(!this.materialToSwitch)return;const i=ti._materialTriggersPerId[this.materialToSwitch.uuid];if(i){const n={};for(const o of i){const r=o.createVariants();r&&r.length>0&&(n[o.selfModel.uuid]=r)}for(const o of i){const r=[];for(const l in n)l!==o.selfModel.uuid&&r.push(...n[l]);o.createAndAttachBehaviors(s,n[o.selfModel.uuid],r)}}delete ti._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(s,t,i){const n=[],o=Math.max(0,this.fadeDuration);n.push(ye.fadeAction([...this.targetModels,...i],o,!1)),n.push(ye.fadeAction(t,o,!0)),s.addBehavior(new Et("Select_"+this.selfModel.name,xt.tapTrigger(this.selfModel),ye.parallel(...n))),ti._parallelStartHiddenActions.push(...t),ti._startHiddenBehaviour||(ti._startHiddenBehaviour=new Et("StartHidden_"+this.selfModel.name,xt.sceneStartTrigger(),ye.fadeAction(ti._parallelStartHiddenActions,o,!1)),s.addBehavior(ti._startHiddenBehaviour))}static getMaterialName(s){return Ts(s.name||"Material")+"_"+s.id}createVariants(){if(!this.variantMaterial)return null;const s=[];for(const t of this.targetModels){const i=t.clone();i.name+="_Variant_"+ti.variantSwitchIndex+++"_"+ti.getMaterialName(this.variantMaterial),i.displayName=i.displayName+": Variant with material "+this.variantMaterial.name,i.material=this.variantMaterial,i.geometry=t.geometry,i.transform=t.transform,(!t.parent||!t.parent.isEmpty())&&Zt.createEmptyParent(t),t.parent&&t.parent.add(i),s.push(i)}return s}},a(fl,"_materialTriggersPerId",{}),a(fl,"_startHiddenBehaviour",null),a(fl,"_parallelStartHiddenActions",[]),a(fl,"variantSwitchIndex",0),fl);let yl=ti;$e([m(ke)],yl.prototype,"materialToSwitch",2),$e([m(ke)],yl.prototype,"variantMaterial",2),$e([m()],yl.prototype,"fadeDuration",2);var vl;const qe=(vl=class extends A{constructor(){super(...arguments),a(this,"target"),a(this,"toggleOnClick",!1),a(this,"targetState",!0),a(this,"hideSelf",!0),a(this,"selfModel"),a(this,"selfModelClone"),a(this,"targetModel"),a(this,"toggleModel"),a(this,"stateBeforeCreatingDocument",!1),a(this,"targetStateBeforeCreatingDocument",!1)}start(){hh(this.gameObject)}onPointerClick(s){s.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(s,t,i){t.uuid===this.gameObject.uuid&&(this.selfModel=t,this.selfModelClone=t.clone())}beforeCreateDocument(){this.target&&(this.gameObject[qe.wasVisible]===void 0&&(this.gameObject[qe.wasVisible]=this.gameObject.activeSelf),this.target[qe.wasVisible]===void 0&&(this.target[qe.wasVisible]=this.target.activeSelf),this.stateBeforeCreatingDocument=this.gameObject[qe.wasVisible],this.targetStateBeforeCreatingDocument=this.target[qe.wasVisible],this.gameObject.visible=!0,this.target.visible=!0)}afterCreateDocument(s,t){if(!this.target)return;this.targetModel=t.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())&&Zf.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.deepClone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel);else{if(!this.gameObject[qe.toggleClone]){const c=this.selfModelClone.clone();c.setMatrix(new ne),c.name+="_toggle"+qe.clonedToggleIndex++,i.add(c),this.gameObject[qe.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[qe.toggleClone];if(!this.gameObject[qe.reverseToggleClone]){const c=this.selfModelClone.clone();c.setMatrix(new ne),c.name+="_toggleReverse"+qe.clonedToggleIndex++,i.add(c),this.gameObject[qe.reverseToggleClone]=c}this.toggleModel=this.gameObject[qe.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(ye.fadeAction(n,0,!1)),l.push(ye.fadeAction(this.toggleModel,0,!0)),l.push(ye.fadeAction(this.targetModel,0,o)),s.addBehavior(new Et("Toggle_"+n.name+"_ToggleTo"+(o?"On":"Off"),xt.tapTrigger(n),ye.parallel(...l)));const c=[];c.push(ye.fadeAction(this.toggleModel,0,!1)),c.push(ye.fadeAction(n,0,!0)),c.push(ye.fadeAction(this.targetModel,0,!o)),s.addBehavior(new Et("Toggle_"+n.name+"_ToggleTo"+(o?"Off":"On"),xt.tapTrigger(this.toggleModel),ye.parallel(...c)))}}else{const l=[];this.hideSelf&&l.push(ye.fadeAction(n,0,!1)),l.push(ye.fadeAction(this.targetModel,0,o)),s.addBehavior(new Et("Toggle_"+n.name+"_ToggleTo"+(o?"On":"Off"),xt.tapTrigger(n),l.length>1?ye.parallel(...l):l[0]))}const r=new Array;this.targetStateBeforeCreatingDocument||r.push(this.targetModel),this.stateBeforeCreatingDocument||r.push(i),this.toggleModel&&r.push(this.toggleModel),bl.add(r,s)}}afterSerialize(s,t){this.gameObject[qe.wasVisible]!==void 0&&(this.gameObject.visible=this.gameObject[qe.wasVisible],delete this.gameObject[qe.wasVisible]),this.target&&this.target[qe.wasVisible]!==void 0&&(this.target.visible=this.target[qe.wasVisible],delete this.target[qe.wasVisible]),delete this.gameObject[qe.toggleClone],delete this.gameObject[qe.reverseToggleClone]}},a(vl,"clonedToggleIndex",0),a(vl,"wasVisible",Symbol("usdz_SetActiveOnClick_wasVisible")),a(vl,"toggleClone",Symbol("clone for toggling")),a(vl,"reverseToggleClone",Symbol("clone for reverse toggling")),vl);let Gr=qe;$e([m(I)],Gr.prototype,"target",2),$e([m()],Gr.prototype,"toggleOnClick",2),$e([m()],Gr.prototype,"targetState",2),$e([m()],Gr.prototype,"hideSelf",2);const Do=class extends A{constructor(){super(...arguments),a(this,"wasVisible",!1)}static add(s,t){const i=Array.isArray(s)?s:[s];for(const n of i)Do._fadeObjects.includes(n)||(console.log("adding hide on start",n),Do._fadeObjects.push(n));Do._fadeBehaviour===void 0&&(Do._fadeBehaviour=new Et("HideOnStart",xt.sceneStartTrigger(),ye.fadeAction(Do._fadeObjects,0,!1)),t.addBehavior(Do._fadeBehaviour))}start(){P.setActive(this.gameObject,!1)}createBehaviours(s,t,i){t.uuid===this.gameObject.uuid&&(this.wasVisible||Do.add(t,s))}beforeCreateDocument(){this.wasVisible=P.isActiveSelf(this.gameObject)}};let bl=Do;a(bl,"_fadeBehaviour"),a(bl,"_fadeObjects",[]);class _l extends A{constructor(){super(...arguments),a(this,"target"),a(this,"duration",.5),a(this,"motionType","bounce")}beforeCreateDocument(){}createBehaviours(t,i,n){if(this.target&&i.uuid===this.gameObject.uuid){const o=new Et("emphasize "+this.name,xt.tapTrigger(this.gameObject),ye.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));t.addBehavior(o)}}afterCreateDocument(t,i){}}$e([m()],_l.prototype,"target",2),$e([m()],_l.prototype,"duration",2),$e([m()],_l.prototype,"motionType",2);class Lo extends A{constructor(){super(...arguments),a(this,"target"),a(this,"clip",""),a(this,"toggleOnClick",!1),a(this,"trigger","tap")}start(){hh(this.gameObject)}ensureAudioSource(){if(!this.target){const t=this.gameObject.addComponent(We);t&&(this.target=t,t.spatialBlend=1,t.volume=1,t.loop=!1,t.preload=!0)}}onPointerClick(t){var i;t.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(t,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 r=this.target?this.target.gameObject:this.gameObject;dr.getName(o);const l=this.target?this.target.volume:1,c=this.target&&this.target.spatialBlend==0?"nonSpatial":"spatial";let h=!1;this.gameObject.traverse(g=>{g instanceof K&&g.visible&&(h=!0)}),h=!0;const d=t.addAudioClip(o);let u=ye.playAudioAction(r,d,"play",l,c);this.target&&this.target.loop&&(u=ye.sequence(u).makeLooping());const p=this.name?"_"+this.name:"";if(h&&this.trigger==="tap"){this.toggleOnClick&&(u.multiplePerformOperation="stop");const g=new Et("playAudio"+p,xt.tapTrigger(i),u);t.addBehavior(g)}if(this.target&&this.target.playOnAwake&&this.target.enabled)if(h&&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 Et("playAudioOnStart"+p,xt.sceneStartTrigger(),u);t.addBehavior(g)}}}}$e([m(We)],Lo.prototype,"target",2),$e([m(URL)],Lo.prototype,"clip",2),$e([m()],Lo.prototype,"toggleOnClick",2);var pp;const nn=(pp=class extends A{constructor(){super(...arguments),a(this,"animator"),a(this,"stateName"),a(this,"trigger","tap"),a(this,"animation"),a(this,"selfModel"),a(this,"stateAnimationModel"),a(this,"animationSequence",new Array),a(this,"animationLoopAfterSequence",new Array),a(this,"randomOffsetNormalized",0)}get target(){var s,t;return((s=this.animator)==null?void 0:s.gameObject)||((t=this.animation)==null?void 0:t.gameObject)}start(){hh(this.gameObject)}onPointerClick(s){var t;s.use(),this.target&&this.stateName&&((t=this.animator)==null||t.play(this.stateName,0,0,.1))}createBehaviours(s,t,i){t.uuid===this.gameObject.uuid&&(this.selfModel=t)}afterSerialize(){if(nn.rootsWithExclusivePlayback.size>1){const s='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.';F()&&xe(s),console.warn(s,...nn.rootsWithExclusivePlayback)}nn.animationActions=[],nn.rootsWithExclusivePlayback=new Set}afterCreateDocument(s,t){if(this.animationSequence===void 0&&this.animationLoopAfterSequence===void 0||!this.stateAnimationModel||!this.target)return;const i=t.document,n=t.extensions.find(l=>l instanceof ch);if(!n)return;const o=n.getClipCount(this.target)>1;o&&(F()&&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."),nn.rootsWithExclusivePlayback.add(this.target));const r=this.name?this.name:"";i.traverse(l=>{var c,h;if(l.uuid===((c=this.target)==null?void 0:c.uuid)){const d=nn.getActionForSequences(i,l,this.animationSequence,this.animationLoopAfterSequence,this.randomOffsetNormalized),u=new Et(this.trigger+"_"+r+"_toPlayAnimation_"+this.stateName+"_on_"+((h=this.target)==null?void 0:h.name),this.trigger=="tap"?xt.tapTrigger(this.selfModel):xt.sceneStartTrigger(),d);o&&u.makeExclusive(!0),s.addBehavior(u)}})}static getActionForSequences(s,t,i,n,o){const r=(c,h)=>{let d=nn.animationActions.find(u=>u.affectedObjects==c&&u.start==h.start&&u.duration==h.duration&&u.animationSpeed==h.speed);return d||(d=ye.startAnimationAction(c,h),nn.animationActions.push(d)),d},l=ye.sequence();if(i&&i.length>0)for(const c of i)l.addAction(r(t,c));if(n&&n.length>0){const c=l.actions.length==0?l:ye.sequence();for(const h of n)c.addAction(r(t,h));c.makeLooping(),l!==c&&l.addAction(c)}return o&&o>0&&l.actions.unshift(ye.waitAction(o)),l}static getAndRegisterAnimationSequences(s,t,i){var n,o,r,l,c,h,d,u;if(!t)return;const p=t.getComponent(Mt),g=t.getComponent(Wt);if(!p&&!g)return;if(p&&!i)throw new Error("PlayAnimationOnClick: No stateName specified for animator "+p.name+" on "+t.name);let y=[],f=[];if(g){const M=s.registerAnimation(t,g.clip);M&&(g.loop?f.push(M):y.push(M));let T=0;if(g.minMaxOffsetNormalized){const j=g.minMaxOffsetNormalized.x,L=g.minMaxOffsetNormalized.y;T=(((n=g.clip)==null?void 0:n.duration)||1)*(j+Math.random()*(L-j))}return{animationSequence:y,animationLoopAfterSequence:f,randomTimeOffset:T}}const v=p?.runtimeAnimatorController;let b=v?.findState(i),w=[],_=[];if(v&&b){const M=new Array;M.push(b);let T=!1;for(;M.length<100;){if(!b||b===null||!b.transitions||b.transitions.length===0){(o=b.motion)!=null&&o.isLooping&&(T=!0);break}const j=b.transitions.find(U=>U.conditions.length===0),L=j?v.getState(j.destinationState,0):null;if(L&&M.includes(L)){b=L,T=!0;break}else if(j){if(b=L,!b)break;M.push(b)}else{T=((r=b.motion)==null?void 0:r.isLooping)??!1;break}}if(T&&b){const j=M.indexOf(b);w=M.slice(0,j),_=M.slice(j),Ux&&console.log("found loop from "+i,"states until loop",w,"states looping",_)}else w=M,_=[],Ux&&console.log("found no loop from "+i,"states",w);if(!_.length){const j=w[w.length-1],L=(l=j.motion)==null?void 0:l.clip;if(L){let U;if(s.holdClipMap.has(L))U=s.holdClipMap.get(L);else{const B=j.name+"_hold";U=L.clone(),U.duration=1,U.name=B;const Y=L.duration;U.tracks=L.tracks.map($=>{const E=$.clone();E.times=new Float32Array([0,Y]);const z=$.values.length,H=$.getValueSize(),se=$.values.slice(z-H,z);return E.values=new Float32Array(2*H),E.values.set(se,0),E.values.set(se,H),E}),U.name=B,s.holdClipMap.set(L,U)}if(U){const B={name:U.name,motion:{clip:U,isLooping:!1,name:U.name},speed:1,transitions:[],behaviours:[],hash:j.hash+1};_.push(B)}}}}if(w.length===1&&(!((c=w[0].motion)!=null&&c.clip)||((d=(h=w[0].motion)==null?void 0:h.clip.tracks)==null?void 0:d.length)===0)){y=new Array;const M=s.registerAnimation(t,null);M&&y.push(M);return}if(w=w.filter(M=>{var T,j,L;return((T=M.motion)==null?void 0:T.clip)&&((L=(j=M.motion)==null?void 0:j.clip.tracks)==null?void 0:L.length)>0}),_=_.filter(M=>{var T,j,L;return((T=M.motion)==null?void 0:T.clip)&&((L=(j=M.motion)==null?void 0:j.clip.tracks)==null?void 0:L.length)>0}),w.length===0&&_.length===0){console.warn("No clips found for state "+i+" on "+p?.name+", can't export animation data");return}const C=(M,T)=>{if(!t)return;const j=s.registerAnimation(t,M.motion.clip??null);j?(j.speed=M.speed,T.push(j)):console.warn("Couldn't register animation for state "+M.name+" on "+p?.name)};if(w.length>0){y=new Array;for(const M of w)C(M,y)}if(_.length>0){f=new Array;for(const M of _)C(M,f)}let R=0;if(p&&v&&p.minMaxOffsetNormalized){const M=p.minMaxOffsetNormalized.x,T=p.minMaxOffsetNormalized.y,j=w.length?w[0]:_.length?_[0]:null;R=(((u=j?.motion.clip)==null?void 0:u.duration)||1)*(M+Math.random()*(T-M))}return{animationSequence:y,animationLoopAfterSequence:f,randomTimeOffset:R}}createAnimation(s,t,i){if(!this.target||!this.animator&&!this.animation)return;const n=nn.getAndRegisterAnimationSequences(s,this.target,this.stateName);n&&(this.animationSequence=n.animationSequence,this.animationLoopAfterSequence=n.animationLoopAfterSequence,this.randomOffsetNormalized=n.randomTimeOffset,this.stateAnimationModel=t)}},a(pp,"animationActions",[]),a(pp,"rootsWithExclusivePlayback",new Set),pp);let Xr=nn;$e([m(Mt)],Xr.prototype,"animator",2),$e([m()],Xr.prototype,"stateName",2);class wl extends A{constructor(){super(...arguments),a(this,"target")}getType(){}getDuration(){}}$e([m(I)],wl.prototype,"target",2);class dh extends A{constructor(){super(...arguments),a(this,"target")}}$e([m(wl)],dh.prototype,"target",2);class uh extends wl{constructor(){super(...arguments),a(this,"type",1),a(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}$e([m()],uh.prototype,"type",2),$e([m()],uh.prototype,"duration",2);class d0 extends dh{}class mp{get extensionName(){return"Physics"}onExportObject(t,i,n){const o=P.getComponents(t,ve).filter(h=>h.enabled),r=P.getComponents(t,pi).filter(h=>h.enabled&&!h.isTrigger);let l=o.length>0?o[0]:null;const c=r.length>0?r[0]:null;c&&!l&&(l=new ve,l.isKinematic=!0),l&&i.addEventListener("serialize",(h,d)=>{var u,p,g;if(l){if(h.appendLine(),h.beginBlock('def RealityKitComponent "RigidBody"',"{",!0),l.useGravity||h.appendLine("bool gravityEnabled = 0"),h.appendLine('uniform token info:id = "RealityKit.RigidBody"'),l.isKinematic&&h.appendLine('token motionType = "Kinematic"'),h.beginBlock('def RealityKitStruct "massFrame"',"{",!0),h.appendLine(`float m_mass = ${l.mass}`),h.beginBlock('def RealityKitStruct "m_pose"',"{",!0),h.appendLine(`float3 position = (${l.centerOfMass.x}, ${l.centerOfMass.y}, ${l.centerOfMass.z})`),h.closeBlock("}"),h.closeBlock("}"),r.length>0){const y=r[0];h.beginBlock('def RealityKitStruct "material"',"{",!0);const f=y.sharedMaterial;f&&f.dynamicFriction!==void 0&&h.appendLine(`double dynamicFriction = ${(u=y.sharedMaterial)==null?void 0:u.dynamicFriction}`),f&&f.bounciness!==void 0&&h.appendLine(`double restitution = ${(p=y.sharedMaterial)==null?void 0:p.bounciness}`),f&&f.staticFriction!==void 0&&h.appendLine(`double staticFriction = ${(g=y.sharedMaterial)==null?void 0:g.staticFriction}`),h.closeBlock("}")}h.closeBlock("}")}}),c&&(i.addEventListener("serialize",(h,d)=>{var u;h.beginBlock('def RealityKitComponent "Collider"',"{",!0),h.appendLine("uint group = 1"),h.appendLine('uniform token info:id = "RealityKit.Collider"'),h.appendLine("uint mask = 4294967295");const p=c.isTrigger?"Trigger":"Default";if(h.appendLine(`token type = "${p}"`),h.beginBlock('def RealityKitStruct "Shape"',"{",!0),c instanceof tl){const g=c;h.appendLine('token shapeType = "Sphere"'),h.appendLine(`float radius = ${g.radius}`)}else if(c instanceof il){const g=c;h.appendLine('token shapeType = "Box"'),h.appendLine(`float3 extent = (${g.size.x}, ${g.size.y}, ${g.size.z})`)}else if(c instanceof In){const g=c;h.appendLine('token shapeType = "Capsule"'),h.appendLine(`float radius = ${g.radius}`),h.appendLine(`float height = ${g.height}`)}else if(c instanceof Ao&&(u=c.sharedMesh)!=null&&u.geometry){const g=c.sharedMesh.geometry;g.boundingBox||g.computeBoundingBox();const y=c.sharedMesh.geometry.boundingBox;y&&(h.appendLine('token shapeType = "Box"'),h.appendLine(`float3 extent = (${y.max.x-y.min.x}, ${y.max.y-y.min.y}, ${y.max.z-y.min.z})`),console.log("[USDZ] Only Box, Sphere, and Capsule colliders are supported in visionOS/iOS. MeshCollider will be exported as Box",c))}else console.warn("[USDZ] Only Box, Sphere, and Capsule colliders are supported in visionOS/iOS. Ignoring collider:",c);h.beginBlock('def RealityKitStruct "pose"',"{",!0),h.closeBlock("}"),h.closeBlock("}"),h.closeBlock("}")}),r.length>1&&console.log("WARNING: Multiple colliders detected. visionOS / iOS can only support objects with a single collider, only exporting the first collider: ",c))}}class u0{get extensionName(){return"DocumentExtension"}onAfterBuildDocument(t){}}var fT=Object.defineProperty,yT=Object.getOwnPropertyDescriptor,ph=(s,t,i,n)=>{for(var o=n>1?void 0:n?yT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&fT(t,i,o),o};const p0=O("debugui"),m0=O("debuguilayout");class g0{constructor(){a(this,"width"),a(this,"height")}}class f0{constructor(){a(this,"x"),a(this,"y"),a(this,"width"),a(this,"height")}}const Es=new x,mh=new ne,gp=new V,Nx=class extends ls{constructor(){super(...arguments),a(this,"_anchoredPosition"),a(this,"sizeDelta",new oe(100,100)),a(this,"pivot",new oe(.5,.5)),a(this,"anchorMin",new oe(0,0)),a(this,"anchorMax",new oe(1,1)),a(this,"minWidth"),a(this,"minHeight"),a(this,"lastMatrix"),a(this,"rectBlock"),a(this,"_transformNeedsUpdate",!1),a(this,"_initialPosition"),a(this,"_parentRectTransform"),a(this,"_lastUpdateFrame",-1),a(this,"_lastAnchoring"),a(this,"_createdBlocks",[]),a(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 oe),this._anchoredPosition}set anchoredPosition(s){this._anchoredPosition=s}get width(){let s=this.sizeDelta.x;if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const t=this._parentRectTransform.width,i=this.anchorMax.x-this.anchorMin.x;s=t*i,s+=this.sizeDelta.x}return this.minWidth!==void 0&&s<this.minWidth?this.minWidth:s}get height(){let s=this.sizeDelta.y;if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const t=this._parentRectTransform.height,i=this.anchorMax.y-this.anchorMin.y;s=t*i,s+=this.sizeDelta.y}return this.minHeight!==void 0&&s<this.minHeight?this.minHeight:s}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new oe),this.lastMatrix=new ne,this.rectBlock=new I,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,Ya(this,"_anchoredPosition",()=>{this.markDirty()}),Ya(this,"sizeDelta",()=>{this.markDirty()}),Ya(this,"pivot",()=>{this.markDirty()}),Ya(this,"anchorMin",()=>{this.markDirty()}),Ya(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var s;super.onEnable(),this.rectBlock||(this.rectBlock=new I),this.lastMatrix||(this.lastMatrix=new ne),this._lastAnchoring||(this._lastAnchoring=new oe),this._initialPosition||(this._initialPosition=new x),this._anchoredPosition||(this._anchoredPosition=new oe),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(s=this.canvas)==null||s.registerTransform(this)}onDisable(){var s;super.onDisable(),this.removeShadowComponent(),(s=this.canvas)==null||s.unregisterTransform(this)}onParentRectTransformChanged(s){this._transformNeedsUpdate||this.onApplyTransform(m0?`${s.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(m0&&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(s){var t;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const i=this.shadowComponent;if(!i)return;this.gameObject.parent?this._parentRectTransform=P.getComponentInParent(this.gameObject.parent,Nx):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,m0&&console.warn("RectTransform \u2192 ApplyTransform",this.name+" because "+s),this.isRoot()?this.Root.screenspace||(i.rotation.y=Math.PI):(i.matrix.identity(),i.matrixAutoUpdate=!1,Es.set(0,0,0),this.applyPivot(Es),i.matrix.setPosition(Es.x,Es.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(gp.copy(this.gameObject.quaternion),gp.x*=-1,gp.z*=-1,mh.makeRotationFromQuaternion(gp),i.matrix.premultiply(mh)),Es.set(0,0,0),this.applyAnchoring(Es),(t=this.canvas)!=null&&t.screenspace?Es.z+=.1:Es.z+=.01,mh.identity(),mh.setPosition(Es.x,Es.y,Es.z),i.matrix.premultiply(mh),i.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const n=!0;for(const o of ou(this.gameObject,ls,n,1)){if(o===this||!o.activeAndEnabled)continue;const r=o;r.onParentRectTransformChanged&&r.onParentRectTransformChanged(this)}}applyAnchoring(s){this._lastAnchoring||(this._lastAnchoring=new oe);const t=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=t.x,this.gameObject.position.y+=t.y,this._lastAnchoring.copy(this._anchoredPosition),s.x+=this._initialPosition.x-this.gameObject.position.x,s.y+=this._initialPosition.y-this.gameObject.position.y,s.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,s.y+=n;let r=0;const l=1-this.anchorMax.x-this.anchorMin.x;r-=i.width*.5*l,s.x+=r}}applyPivot(s){if(this.pivot&&!this.isRoot()){const t=this.pivot.x-.5;s.x-=t*this.sizeDelta.x*this.gameObject.scale.x;const i=this.pivot.y-.5;s.y-=i*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const s={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(s),s}ensureValidSize(s,t=1e-4){return s.width<=0&&(s.width=t),s.height<=0&&(s.height=1e-4),s}createNewBlock(s){s={...this.getBasicOptions(),...s},p0&&console.log(this.name,s);const t=new yv(s);return this._createdBlocks.push(t),t}createNewText(s){p0&&console.log(s),s={...this.getBasicOptions(),...s},p0&&console.log(this.name,s);const t=new fv(s);return this._createdTextBlocks.push(t),t}};let Ht=Nx;ph([m(oe)],Ht.prototype,"anchoredPosition",1),ph([m(oe)],Ht.prototype,"sizeDelta",2),ph([m(oe)],Ht.prototype,"pivot",2),ph([m(oe)],Ht.prototype,"anchorMin",2),ph([m(oe)],Ht.prototype,"anchorMax",2);var vT=Object.defineProperty,bT=Object.getOwnPropertyDescriptor,Wx=(s,t,i,n)=>{for(var o=n>1?void 0:n?bT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&vT(t,i,o),o};class xl extends A{constructor(){super(...arguments),a(this,"effectColor"),a(this,"effectDistance")}}Wx([m(Se)],xl.prototype,"effectColor",2),Wx([m(oe)],xl.prototype,"effectDistance",2);var _T=Object.defineProperty,wT=Object.getOwnPropertyDescriptor,Vx=(s,t,i,n)=>{for(var o=n>1?void 0:n?wT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&_T(t,i,o),o};const fp={backgroundColor:new re(1,1,1),backgroundOpacity:1,borderColor:new re(1,1,1),borderOpacity:1};var y0;const gh=(y0=class extends ls{constructor(){super(...arguments),a(this,"_alphaFactor",1),a(this,"sRGBColor",new re(1,0,1)),a(this,"raycastTarget",!0),a(this,"uiObject",null),a(this,"_color",null),a(this,"_rect",null),a(this,"_stateManager",null),a(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new Se(1,1,1,1)),this._color}set color(s){(!this._color||this._color.r!==s.r||this._color.g!==s.g||this._color.b!==s.b||this._color.alpha!==s.alpha)&&(this._color||(this._color=new Se(1,1,1,1)),this._color.copy(s),this.onColorChanged())}setAlphaFactor(s){this._alphaFactor=s,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(this.sRGBColor.copy(this._color),this.sRGBColor.convertLinearToSRGB(),fp.backgroundColor=this.sRGBColor,fp.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(fp,this._alphaFactor),this.uiObject.set(fp),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=P.getComponent(this.gameObject,Ht)),!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 s;(s=this.uiObject)==null||s.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(s){return super.__internalNewInstanceCreated(s),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone()),this}setState(s){this.makePanel(),this.uiObject&&(this.uiObject.setState(s),this==null||this.markDirty())}setupState(s){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new cO(this.uiObject)),this.uiObject.setupState(s.state,s.attributes))}setOptions(s){this.makePanel(),this.uiObject&&this.uiObject.set(s)}awake(){super.awake(),this.makePanel(),Ya(this,"_color",()=>vM(this,this.onColorChanged))}onEnable(){var s;super.onEnable(),this.uiObject&&((s=this.rectTransform.shadowComponent)==null||s.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 s=.015,t={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:s};this.onBeforeCreate(t),this.applyEffects(t),this.onCreate(t),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated(),this.onColorChanged()}onBeforeCreate(s){}onCreate(s){this.uiObject=this.rectTransform.createNewBlock(s),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(s,t=1){var i;const n=(i=this.gameObject)==null?void 0:i.getComponent(xl);n&&(n.effectDistance&&(s.borderWidth=Math.max(Math.abs(n.effectDistance.x),Math.abs(n.effectDistance.y))),n.effectColor&&(s.borderColor=n.effectColor,s.borderOpacity=n.effectColor.alpha*t))}async setTexture(s){if(this.setOptions({backgroundOpacity:0}),s){if(gh.textureCache.has(s))s=gh.textureCache.get(s);else if(!s.isRenderTargetTexture){const t=s.clone();t.colorSpace=mr,gh.textureCache.set(s,t),s=t}this.setOptions({backgroundImage:s,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"}),it.assignTextureLOD(s,0).then(t=>{t instanceof De&&(s&&gh.textureCache.set(s,t),this.setOptions({backgroundImage:t}),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)}},a(y0,"textureCache",new Map),y0);let Qr=gh;Vx([m(Se)],Qr.prototype,"color",1),Vx([m()],Qr.prototype,"raycastTarget",2);class fh extends Qr{constructor(){super(...arguments),a(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var xT=Object.defineProperty,ST=Object.getOwnPropertyDescriptor,Wn=(s,t,i,n)=>{for(var o=n>1?void 0:n?ST(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&xT(t,i,o),o};const Yr=O("debugtext");var gt=(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))(gt||{}),Hx=(s=>(s[s.Normal=0]="Normal",s[s.Bold=1]="Bold",s[s.Italic=2]="Italic",s[s.BoldAndItalic=3]="BoldAndItalic",s))(Hx||{});class $t extends Qr{constructor(){super(...arguments),a(this,"alignment",0),a(this,"verticalOverflow",0),a(this,"horizontalOverflow",0),a(this,"lineSpacing",1),a(this,"supportRichText",!1),a(this,"font"),a(this,"fontStyle",0),a(this,"sRGBTextColor",new re(1,0,1)),a(this,"_text",""),a(this,"_fontSize",12),a(this,"_textMeshUi",null),a(this,"_didHandleTextRenderOnTop",!1)}setAlphaFactor(t){var i;super.setAlphaFactor(t),(i=this.uiObject)==null||i.set({fontOpacity:this.color.alpha*this.alphaFactor}),this.markDirty()}get text(){return this._text}set text(t){t!==this._text&&(this._text=t,this.feedText(this.text,this.supportRichText),this.markDirty())}set_text(t){this.text=t}get fontSize(){return this._fontSize}set fontSize(t){var i;this._fontSize=t,(i=this.uiObject)==null||i.set({fontSize:t})}onColorChanged(){var t;this.sRGBTextColor.copy(this.color),this.sRGBTextColor.convertLinearToSRGB(),(t=this.uiObject)==null||t.set({color:this.sRGBTextColor,fontOpacity:this.color.alpha})}onParentRectTransformChanged(){super.onParentRectTransformChanged(),this.uiObject&&this.updateOverflow()}onBeforeCanvasRender(t){this.updateOverflow()}updateOverflow(){var t;const i=(t=this.uiObject)==null?void 0:t._overflow;i&&(i._needsUpdate=!0)}onCreate(t){Yr&&console.log(this),this.horizontalOverflow==1&&(t.whiteSpace="pre"),this.verticalOverflow==0&&(this.context.renderer.localClippingEnabled=!0,t.overflow="hidden"),this.horizontalOverflow==1&&this.verticalOverflow==0,t.lineHeight=this.lineSpacing,delete t.backgroundOpacity,delete t.backgroundColor,Yr&&(t.backgroundColor=16750848,t.backgroundOpacity=.5);const i=this.rectTransform;t={...t,...this.getTextOpts()},this.getAlignment(t),Yr&&(t.backgroundColor=Math.random()*16777215,t.backgroundOpacity=.1),this.uiObject=i.createNewText(t),this.feedText(this.text,this.supportRichText)}onAfterAddedToScene(){super.onAfterAddedToScene(),this.handleTextRenderOnTop()}getTextOpts(){const t=this.fontSize,i={color:this.color,fontOpacity:this.color.alpha,fontSize:t,fontKerning:"normal"};return this.setFont(i,this.fontStyle),i}onEnable(){var t;super.onEnable(),this._didHandleTextRenderOnTop=!1,this.uiObject&&this.uiObject.addAfterUpdate(()=>{this.setShadowComponentOwner(this.uiObject),this.markDirty()}),setTimeout(()=>this.markDirty(),10),(t=this.canvas)==null||t.registerEventReceiver(this)}onDisable(){var t;super.onDisable(),(t=this.canvas)==null||t.unregisterEventReceiver(this)}getAlignment(t){switch(t.flexDirection="column",this.alignment){case 0:case 3:case 6:t.textAlign="left";break;case 1:case 4:case 7:t.textAlign="center";break;case 2:case 5:case 8:t.textAlign="right";break}switch(this.alignment){default:case 0:case 1:case 2:t.alignItems="start";break;case 3:case 4:case 5:t.alignItems="center";break;case 6:case 7:case 8:t.alignItems="end";break}return t}feedText(t,i){var n,o,r;if(Yr&&console.log("feedText",this.uiObject,t,i),!!this.uiObject)if(this._textMeshUi||(this._textMeshUi=[]),this.uiObject.children.length=0,!i||t.length===0)this.uiObject.textContent=t;else{let l=this.getNextTag(t);if(l){if(l.startIndex>0){for(let d=this.uiObject.children.length-1;d>=0;d--){const u=this.uiObject.children[d];u.isUI&&(this.uiObject.remove(u),u.clear())}const h=new Pm({textContent:t.substring(0,l.startIndex),color:"inherit"});this.uiObject.add(h)}}else{this.uiObject.textContent="",this.setOptions({textContent:t});return}const c=[];for(;l;){const h=this.getNextTag(t,l.endIndex),d={fontFamily:(n=this.uiObject)==null?void 0:n.get("fontFamily"),color:"inherit",textContent:""};if(h){d.textContent=this.getText(t,l,h),this.handleTag(l,d,c);const u=new Pm(d);(o=this.uiObject)==null||o.add(u)}else{d.textContent=t.substring(l.endIndex),this.handleTag(l,d,c);const u=new Pm(d);(r=this.uiObject)==null||r.add(u)}l=h}}}handleTextRenderOnTop(){this._didHandleTextRenderOnTop||(this._didHandleTextRenderOnTop=!0,this.startCoroutine(this.renderOnTopCoroutine()))}*renderOnTopCoroutine(){if(!this.canvas)return;const t=[],i=this.canvas,n={renderOnTop:i.renderOnTop,depthWrite:i.depthWrite,doubleSided:i.doubleSided};for(;;){let o=!1;if(this._textMeshUi)for(let r=0;r<this._textMeshUi.length;r++){if(t[r]===!0)continue;o=!0;const l=this._textMeshUi[r];l.textContent&&(Lu(l,n),t[r]=!0)}if(!o)break;yield}}handleTag(t,i,n){if(!t.isEndTag){if(t.type.includes("color")){const o=new v0(t,{color:i.color});if(n.push(o),t.type.length>6){const r=parseInt("0x"+t.type.substring(7));i.color=r}else i.color=new re(1,1,1)}else if(t.type=="b"){this.setFont(i,1);const o=new v0(t,{fontWeight:700});n.push(o)}else if(t.type=="i"){this.setFont(i,2);const o=new v0(t,{fontStyle:"italic"});n.push(o)}}}getText(t,i,n){return t.substring(i.endIndex,n.startIndex)}getNextTag(t,i=0){const n=t.indexOf("<",i),o=t.indexOf(">",n);if(n>=0&&o>=0){const r=t.substring(n+1,o);return{type:r,startIndex:n,endIndex:o+1,isEndTag:r.startsWith("/")}}return null}setFont(t,i){if(!this.font)return;const n=this.font,o=this.getFamilyNameWithCorrectSuffix(n,i);Yr&&console.log("Selected font family:"+o);let r=vv.getFontFamily(o);switch(r||(r=vv.addFontFamily(o)),t.fontFamily=r,i){default:case 0:t.fontWeight=400,t.fontStyle="normal";break;case 1:t.fontWeight=700,t.fontStyle="normal";break;case 2:t.fontWeight=400,t.fontStyle="italic";break;case 3:t.fontStyle="italic",t.fontWeight=400}let l=r.getVariant(t.fontWeight,t.fontStyle);if(!l){let c=o;c!=null&&c.endsWith("-msdf.json")||(c+="-msdf.json");let h=o;h!=null&&h.endsWith(".png")||(h+=".png"),l=r.addVariant(t.fontWeight,t.fontStyle,c,h),l?.addEventListener("ready",()=>{this.markDirty()})}}getFamilyNameWithCorrectSuffix(t,i){var n;const o=t.lastIndexOf("-");if(o<0)return t;const r=(n=t.substring(o+1))==null?void 0:n.toLowerCase();if(CT.includes(r))return Yr&&console.warn("Unsupported font style: "+r),t;const l=t.lastIndexOf("/");let c=t;l>=0&&(c=c.substring(l+1));const h=c[0]===c[0].toUpperCase(),d=t.substring(0,o);switch(Yr&&console.log("Select font: ",t,Hx[i],c,h,d),i){case 0:return h?d+"-Regular":d+"-regular";case 1:return h?d+"-Bold":d+"-bold";case 2:return h?d+"-Italic":d+"-italic";case 3:return h?d+"-BoldItalic":d+"-bolditalic";default:return t}}}Wn([m()],$t.prototype,"alignment",2),Wn([m()],$t.prototype,"verticalOverflow",2),Wn([m()],$t.prototype,"horizontalOverflow",2),Wn([m()],$t.prototype,"lineSpacing",2),Wn([m()],$t.prototype,"supportRichText",2),Wn([m(URL)],$t.prototype,"font",2),Wn([m()],$t.prototype,"fontStyle",2),Wn([m()],$t.prototype,"text",1),Wn([m()],$t.prototype,"fontSize",1);class v0{constructor(t,i){a(this,"tag"),a(this,"previousValues"),this.tag=t,this.previousValues=i}}const CT=["medium","mediumitalic","black","blackitalic","thin","thinitalic","extrabold","light","lightitalic","semibold"];class Bo{constructor(t){a(this,"id"),a(this,"content",""),a(this,"font",[]),a(this,"pointSize",144),a(this,"width"),a(this,"height"),a(this,"depth"),a(this,"wrapMode"),a(this,"horizontalAlignment"),a(this,"verticalAlignment"),a(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,i){var n;i.beginBlock(`def Preliminary_Text "${this.id}"`,"(",!1),i.appendLine('prepend apiSchemas = ["MaterialBindingAPI"]'),i.closeBlock(")"),i.beginBlock(),this.content&&i.appendLine(`string content = "${this.content}"`),(!this.font||this.font.length<=0)&&(this.font||(this.font=[]),(n=this.font)==null||n.push("sans-serif"));const o=this.font.map(r=>`"${r}"`).join(", ");i.appendLine(`string[] font = [ ${o} ]`),i.appendLine(`double pointSize = ${this.pointSize}`),typeof this.width=="number"&&i.appendLine(`double width = ${this.width}`),typeof this.height=="number"&&i.appendLine(`double height = ${this.height}`),typeof this.depth=="number"&&i.appendLine(`double depth = ${this.depth}`),this.wrapMode&&i.appendLine(`token wrapMode = "${this.wrapMode}"`),this.horizontalAlignment&&i.appendLine(`token horizontalAlignment = "${this.horizontalAlignment}"`),this.verticalAlignment&&i.appendLine(`token verticalAlignment = "${this.verticalAlignment}"`),this.material!==void 0&&i.appendLine(`rel material:binding = </StageRoot/Materials/${i0(this.material)}>`),i.closeBlock()}}a(Bo,"global_id",0);class yp{static singleLine(t,i,n){const o=new Bo("text_"+Bo.getId());return o.content=t,i&&(o.pointSize=i),n&&(o.depth=n),o}static multiLine(t,i,n,o,r,l){const c=new Bo("text_"+Bo.getId());return c.content=t,c.width=i,c.height=n,c.horizontalAlignment=o,c.verticalAlignment=r,l!==void 0&&(c.wrapMode=l),c}}const OT=new ne().makeRotationY(Math.PI),PT=new ne().makeScale(-1,1,-1);class yh{get extensionName(){return"text"}exportText(t,i,n){const o=P.getComponent(t,$t);if(!o)return;const r=P.getComponent(t,Ht);let l=100,c=100;r&&(l=r.width,c=r.height);const h=OT.clone();r&&h.premultiply(PT),i.setMatrix(h);const d=o.color.clone();i.material=new li({color:d,emissive:d}),i.addEventListener("serialize",(u,p)=>{let g=o.text;g=g.replace(/\r/g,""),g=g.replace(/\n/g,"\\n");const y=yp.multiLine(g,l,c,"center","bottom","flowing");this.setTextAlignment(y,o.alignment),this.setOverflow(y,o),i.material&&(y.material=i.material),y.pointSize=this.convertToTextSize(o.fontSize),y.depth=.001,y.writeTo(void 0,u)})}convertToTextSize(t){return 1/.0502*144*t}setOverflow(t,i){i.horizontalOverflow?t.wrapMode="singleLine":t.wrapMode="flowing"}setTextAlignment(t,i){switch(i){case gt.LowerLeft:case gt.MiddleLeft:case gt.UpperLeft:t.horizontalAlignment="left";break;case gt.LowerCenter:case gt.MiddleCenter:case gt.UpperCenter:t.horizontalAlignment="center";break;case gt.LowerRight:case gt.MiddleRight:case gt.UpperRight:t.horizontalAlignment="right";break}switch(i){case gt.LowerLeft:case gt.LowerCenter:case gt.LowerRight:t.verticalAlignment="bottom";break;case gt.MiddleLeft:case gt.MiddleCenter:case gt.MiddleRight:t.verticalAlignment="middle";break;case gt.UpperLeft:case gt.UpperCenter:case gt.UpperRight:t.verticalAlignment="top";break}}}var kT=Object.defineProperty,MT=Object.getOwnPropertyDescriptor,lt=(s,t,i,n)=>{for(var o=n>1?void 0:n?MT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&kT(t,i,o),o};const $x=O("debuguilayout");class Fo{constructor(){a(this,"left",0),a(this,"right",0),a(this,"top",0),a(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}lt([m()],Fo.prototype,"left",2),lt([m()],Fo.prototype,"right",2),lt([m()],Fo.prototype,"top",2),lt([m()],Fo.prototype,"bottom",2);class ji extends A{constructor(){super(...arguments),a(this,"_rectTransform",null),a(this,"_needsUpdate",!1),a(this,"childAlignment",0),a(this,"reverseArrangement",!1),a(this,"spacing",0),a(this,"padding"),a(this,"minWidth",0),a(this,"minHeight",0),a(this,"flexibleHeight",0),a(this,"flexibleWidth",0),a(this,"preferredHeight",0),a(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(t){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&($x&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){$x&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(Ht);const t=this.gameObject.getComponentInParent(At);t&&t.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const t=this.gameObject.getComponentInParent(At);t&&t.unregisterLayoutGroup(this)}set m_Spacing(t){t!==this.spacing&&(this._needsUpdate=!0,this.spacing=t)}get m_Spacing(){return this.spacing}}lt([m()],ji.prototype,"childAlignment",2),lt([m()],ji.prototype,"reverseArrangement",2),lt([m()],ji.prototype,"spacing",2),lt([m(Fo)],ji.prototype,"padding",2),lt([m()],ji.prototype,"minWidth",2),lt([m()],ji.prototype,"minHeight",2),lt([m()],ji.prototype,"flexibleHeight",2),lt([m()],ji.prototype,"flexibleWidth",2),lt([m()],ji.prototype,"preferredHeight",2),lt([m()],ji.prototype,"preferredWidth",2);class zo extends ji{constructor(){super(...arguments),a(this,"childControlHeight",!0),a(this,"childControlWidth",!0),a(this,"childForceExpandHeight",!1),a(this,"childForceExpandWidth",!1),a(this,"childScaleHeight",!1),a(this,"childScaleWidth",!1)}onCalculateLayout(t){var i;const n=this.primaryAxis,o=t.width;let r=o;const l=t.height;let c=l;r-=this.padding.horizontal,c-=this.padding.vertical,n==="x"?this.padding.horizontal:this.padding.vertical;const h=n==="x",d=h?"y":"x",u=h?this.childControlWidth:this.childControlHeight,p=h?this.childControlHeight:this.childControlWidth,g=h?this.childForceExpandWidth:this.childForceExpandHeight,y=h?this.childForceExpandHeight:this.childForceExpandWidth,f=h?c:r,v=h?o:l,b=.5*(h?this.childAlignment%3:Math.floor(this.childAlignment/3));let w=0;h?w+=this.padding.left:w+=this.padding.top;let _=0,C=0;for(let L=0;L<this.gameObject.children.length;L++){const U=this.gameObject.children[L],B=P.getComponent(U,Ht);B!=null&&B.activeAndEnabled&&(C+=1,h?_+=B.width:_+=B.height)}let R=0;const M=this.spacing*(C-1);if(g||u){let L=0;h?L=r-=M:L=c-=M,C>0&&(R=L/C)}let T=0;T+=this.padding.left,T-=this.padding.right,b!==0&&(w=v-_,w*=b,w-=M*b,h?(w-=this.padding.right*b,w+=this.padding.left*(1-b),w<this.padding.left&&(w=this.padding.left)):(w-=this.padding.bottom*b,w+=this.padding.top*(1-b),w<this.padding.top&&(w=this.padding.top)));let j=1;for(let L=0;L<this.gameObject.children.length;L++){const U=this.gameObject.children[L],B=P.getComponent(U,Ht);if(B!=null&&B.activeAndEnabled){(i=B.pivot)==null||i.set(.5,.5),B.anchorMin.set(0,1),B.anchorMax.set(0,1);const Y=o*.5+T*.5;B.anchoredPosition.x!==Y&&(B.anchoredPosition.x=Y);const $=l*-.5;B.anchoredPosition.y!==$&&(B.anchoredPosition.y=$),y&&p&&B.sizeDelta[d]!==f&&(B.sizeDelta[d]=f),g&&u&&B.sizeDelta[n]!==R&&(B.sizeDelta[n]=R);const E=h?B.width:B.height,z=E*.5;if(w+=z,g){const se=R*j-R*.5;se>w&&(w=se-R*.5+E+this.padding.left,w-=z)}let H=w;n==="y"&&(H=-H),B.anchoredPosition[n]!==H&&(B.anchoredPosition[n]=H),w+=z,w+=this.spacing,j+=1}}}}lt([m()],zo.prototype,"childControlHeight",2),lt([m()],zo.prototype,"childControlWidth",2),lt([m()],zo.prototype,"childForceExpandHeight",2),lt([m()],zo.prototype,"childForceExpandWidth",2),lt([m()],zo.prototype,"childScaleHeight",2),lt([m()],zo.prototype,"childScaleWidth",2);class b0 extends zo{get primaryAxis(){return"y"}}class _0 extends zo{get primaryAxis(){return"x"}}class w0 extends ji{onCalculateLayout(){}}var RT=Object.defineProperty,TT=Object.getOwnPropertyDescriptor,on=(s,t,i,n)=>{for(var o=n>1?void 0:n?TT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&RT(t,i,o),o},qx=(s=>(s[s.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",s[s.ScreenSpaceCamera=1]="ScreenSpaceCamera",s[s.WorldSpace=2]="WorldSpace",s[s.Undefined=-1]="Undefined",s))(qx||{});const x0=O("debuguilayout"),Gx=class extends Vc{constructor(){super(...arguments),a(this,"_renderOnTop"),a(this,"_depthWrite",!1),a(this,"_doubleSided",!0),a(this,"_castShadows",!1),a(this,"_receiveShadows",!1),a(this,"_renderMode",-1),a(this,"_rootCanvas"),a(this,"_scaleFactor",1),a(this,"worldCamera"),a(this,"planeDistance",-1),a(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this)),a(this,"previousParent",null),a(this,"_lastMatrixWorld",null),a(this,"_rectTransforms",[]),a(this,"_layoutGroups",new Map),a(this,"_receivers",[]),a(this,"onBeforeRenderRoutine",()=>{var s,t,i,n;if(this.previousParent=this.gameObject.parent,((s=this.context.xr)!=null&&s.isVR||(t=this.context.xr)!=null&&t.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(),ai.ensureUpdateMeshUI(bv,this.context))}),a(this,"onAfterRenderRoutine",()=>{var s,t,i,n,o;if(((s=this.context.xr)!=null&&s.isVR||(t=this.context.xr)!=null&&t.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?.add(this.gameObject)}else this.previousParent.add(this.gameObject);const r=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(),ai.ensureUpdateMeshUI(bv,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=r,this.context.renderer.autoClearColor=l,this.previousParent.add(this.gameObject)}(o=this._lastMatrixWorld)==null||o.copy(this.gameObject.matrixWorld)}),a(this,"_updateRenderSettingsRoutine"),a(this,"_activeRenderMode",-1),a(this,"_lastWidth",-1),a(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(s){s!==this._renderOnTop&&(this._renderOnTop=s,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(s){this._depthWrite!==s&&(this._depthWrite=s,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(s){this._doubleSided!==s&&(this._doubleSided=s,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(s){this._castShadows!==s&&(this._castShadows=s,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(s){this._receiveShadows!==s&&(this._receiveShadows=s,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(s){this._renderMode!==s&&(this._renderMode=s,this.onRenderSettingsChanged())}set rootCanvas(s){this._rootCanvas instanceof Gx||(this._rootCanvas=s)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(s){this._scaleFactor=s}awake(){var s;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,x0&&console.log("Canvas.Awake()",((s=this.previousParent)==null?void 0:s.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new ne,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 s=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);s!==-1&&this.context.pre_render_callbacks.splice(s,1);const t=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);t!==-1&&this.context.post_render_callbacks.splice(t,1)}registerTransform(s){this._rectTransforms.push(s)}unregisterTransform(s){const t=this._rectTransforms.indexOf(s);t!==-1&&this._rectTransforms.splice(t,1)}registerLayoutGroup(s){const t=s.gameObject;this._layoutGroups.set(t,s)}unregisterLayoutGroup(s){const t=s.gameObject;this._layoutGroups.delete(t)}registerEventReceiver(s){this._receivers.push(s)}unregisterEventReceiver(s){const t=this._receivers.indexOf(s);t!==-1&&this._receivers.splice(t,1)}async onEnterXR(s){this.screenspace?(s.xr.isVR||s.xr.isPassThrough)&&(this.gameObject.visible=!1):(this.gameObject.visible=!1,await ec(1).then(()=>{this.gameObject.visible=!0}))}onLeaveXR(s){this.screenspace&&(s.xr.isVR||s.xr.isPassThrough)&&(this.gameObject.visible=!0)}invokeBeforeRenderEvents(){var s;for(const t of this._receivers)(s=t.onBeforeCanvasRender)==null||s.call(t,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new ne);const s=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);x0&&s&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const t=!1;for(const i of this._rectTransforms){s&&i.markDirty();let n=this._layoutGroups.get(i.gameObject);i.isDirty&&!n&&(n=i.gameObject.getComponentInParent(ji)),(i.isDirty||n!=null&&n.isDirty)&&(x0&&!t&&console.log("CANVAS UPDATE ### "+i.name+" ##################################### "+this.context.time.frame),n?.updateLayout(),i.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),Me.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),Lu(this.shadowComponent,this);for(const s of P.getComponentsInChildren(this.gameObject,ls))Lu(s.shadowComponent,this)}}onUpdateRenderMode(s=!1){if(!s&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let t=this.context.mainCameraComponent,i=10;switch(t&&t.nearClipPlane>0&&t.farClipPlane>0&&(i=W.lerp(t.nearClipPlane,t.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(t=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,!t)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(Ht);let r=!1;o.sizeDelta.x!==this.context.domWidth&&(r=!0),o.sizeDelta.y!==this.context.domHeight&&(r=!0);const l=t.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,r&&(o.sizeDelta.x=this.context.domWidth,o.sizeDelta.y=this.context.domHeight,o?.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let At=Gx;on([m()],At.prototype,"renderOnTop",1),on([m()],At.prototype,"depthWrite",1),on([m()],At.prototype,"doubleSided",1),on([m()],At.prototype,"castShadows",1),on([m()],At.prototype,"receiveShadows",1),on([m()],At.prototype,"renderMode",1),on([m(At)],At.prototype,"rootCanvas",1),on([m()],At.prototype,"scaleFactor",1),on([m(Pe)],At.prototype,"worldCamera",2),on([m()],At.prototype,"planeDistance",2);var ET=Object.defineProperty,AT=Object.getOwnPropertyDescriptor,S0=(s,t,i,n)=>{for(var o=n>1?void 0:n?AT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&ET(t,i,o),o};class Uo extends A{constructor(){super(...arguments),a(this,"_alpha",1),a(this,"interactable",!0),a(this,"blocksRaycasts",!0),a(this,"_isDirty",!1),a(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(t){t!==this._alpha&&(this._alpha=t,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),Me.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){this._buffer.length=0;for(const t of P.getComponentsInChildren(this.gameObject,ls,this._buffer)){const i=t;i.setAlphaFactor&&i.setAlphaFactor(this._alpha)}}}S0([m()],Uo.prototype,"alpha",1),S0([m()],Uo.prototype,"interactable",2),S0([m()],Uo.prototype,"blocksRaycasts",2);class vp{get extensionName(){return"tmui"}onExportObject(t,i,n){const o=P.getComponent(t,At);if(o&&o.enabled&&o.renderMode===qx.WorldSpace){const r=new yh,l=P.getComponent(t,Ht),c=P.getComponent(t,Uo),h=new Array;if(l){if(!P.isActiveSelf(t)){const p=P.isActiveSelf(t);P.setActive(t,!0),l.onEnable(),l.updateTransform(),h.push(()=>{l.onDisable(),P.setActive(t,p)})}t.traverse(p=>{if(!P.isActiveInHierarchy(p)){const g=P.isActiveSelf(p);P.setActive(p,!0);const y=P.getComponent(p,ls);y&&(y.onEnable(),h.push(()=>{y.onDisable()}));const f=P.getComponent(p,Ht);f&&(f.onEnable(),f.updateTransform(),f.onApplyTransform(),h.push(()=>{f.onDisable()}));const v=P.getComponent(p,$t);v&&(v.onEnable(),h.push(()=>{v.onDisable()})),h.push(()=>{P.setActive(p,g)})}}),l.width,l.height;const d=Zt.createEmpty(),u=l.shadowComponent;if(i.add(d),u){const p=u.matrix;d.setMatrix(p);const g=new Map,y=new Map;g.set(u,d),y.set(u,c?c.alpha:1),u.traverse(f=>{if(f===u)return;const v=Zt.createEmpty();v.setMatrix(f.matrix);const b=f.parent,w=!!b&&typeof b.textContent=="string"&&b.textContent.length>0;let _=y.get(b)||1;const C=P.getComponent(f,Uo);if(C&&(_*=C.alpha),f instanceof K&&w){const M=f[ts];M?r.exportText(M.gameObject,v,n):console.error("Error when exporting UI: shadow component owner not found. This is likely a bug.",f)}if(f instanceof K&&!w){const M=f.geometry.clone();M.scale(1,1,-1),this.flipWindingOrder(M),v.geometry=M;const T=new re,j=f.material.opacity;T.copy(f.material.color),v.material=new Re({color:T,opacity:j*_,map:f.material.map,transparent:!0})}g.set(f,v),y.set(f,_);const R=g.get(b);if(!R){console.error("Error when exporting UI: shadow component parent not found!",f,f.parent);return}R.add(v)})}}for(const d of h)d()}}flipWindingOrder(t){const i=t.index.array;for(let n=0,o=i.length/3;n<o;n++){const r=i[n*3];i[n*3]=i[n*3+2],i[n*3+2]=r}t.index.needsUpdate=!0}}const Xx=class{constructor(){a(this,"_quicklookButton"),a(this,"_arButton"),a(this,"_vrButton"),a(this,"_sendToQuestButton")}static create(){return new Xx}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 Tn.getOrCreate().createQRCode()}createQuicklookButton(){if(this._quicklookButton)return this._quicklookButton;const s=document.createElement("button");this._quicklookButton=s,s.dataset.needle="quicklook-button";const t=X.supportsQuickLookAR();s.innerText="View in AR",s.prepend(kt("view_in_ar"));let i=!1,n=null;return s.addEventListener("click",()=>{n=Zd(Ge),n||(i=!0,n=new Ge),i&&(n.objectToExport=ee.Current.scene),n?(s.classList.add("this-mode-is-requested"),n.exportAndOpen().then(()=>{s.classList.remove("this-mode-is-requested")}).catch(o=>{s.classList.remove("this-mode-is-requested"),console.error(o)})):console.warn("No USDZExporter component found in the scene")}),this.hideElementDuringXRSession(s),s}createARButton(s){var t;if(this._arButton)return this._arButton;const i="immersive-ar",n=document.createElement("button");return this._arButton=n,n.classList.add("webxr-button"),n.dataset.needle="webxr-ar-button",n.innerText="Enter AR",n.prepend(kt("view_in_ar")),n.title="Click to start an AR session",n.addEventListener("click",()=>J.start(i,s)),this.updateSessionSupported(n,i),this.listenToXRSessionState(n,i),this.hideElementDuringXRSession(n),this.isSecureConnection||(n.disabled=!0,n.title="WebXR requires a secure connection (HTTPS)"),X.isMozillaXR()||(t=navigator.xr)==null||t.addEventListener("devicechange",()=>this.updateSessionSupported(n,i)),n}createVRButton(s){var t;if(this._vrButton)return this._vrButton;const i="immersive-vr",n=document.createElement("button");return this._vrButton=n,n.classList.add("webxr-button"),n.dataset.needle="webxr-vr-button",n.innerText="Enter VR",n.prepend(kt("panorama_photosphere")),n.title="Click to start a VR session",n.addEventListener("click",()=>J.start(i,s)),this.updateSessionSupported(n,i),this.listenToXRSessionState(n,i),this.hideElementDuringXRSession(n),this.isSecureConnection||(n.disabled=!0,n.title="WebXR requires a secure connection (HTTPS)"),X.isMozillaXR()||(t=navigator.xr)==null||t.addEventListener("devicechange",()=>this.updateSessionSupported(n,i)),n}createSendToQuestButton(){var s;if(this._sendToQuestButton)return this._sendToQuestButton;const t="https://oculus.com/open_url/?url=",i=document.createElement("button");return this._sendToQuestButton=i,i.dataset.needle="webxr-sendtoquest-button",i.innerText="Open on Quest",i.prepend(kt("share_windows")),i.title="Click to send this page to the Oculus Browser on your Quest",i.addEventListener("click",()=>{const n=encodeURIComponent(window.location.href),o=t+n;window.open(o)==null&&Le("This page doesn't allow popups. Please paste "+o+" into your browser.")}),this.listenToXRSessionState(i),this.hideElementDuringXRSession(i),X.isMozillaXR()||(s=navigator.xr)==null||s.addEventListener("devicechange",()=>{var n;(n=navigator.xr)!=null&&n.isSessionSupported("immersive-vr")?i.style.display="none":i.style.display=""}),i}createQRCode(){return Tn.getOrCreate().createQRCode()}updateSessionSupported(s,t){if(!("xr"in navigator)){s.style.display="none";return}J.isSessionSupported(t).then(i=>{s.style.display=i?"":"none",F()&&!i&&console.log('[WebXR] "'+t+'" is not supported on this device \u2013 make sure your server runs using HTTPS and you have a device connected that supports '+t)})}hideElementDuringXRSession(s){Ad(t=>{s["previous-display"]=s.style.display,s.style.display="none"}),ng(t=>{s["previous-display"]!=null&&(s.style.display=s["previous-display"])})}listenToXRSessionState(s,t){t&&(J.onSessionRequestStart(i=>{i.mode===t?s.classList.add("this-mode-is-requested"):(s["was-disabled"]=s.disabled,s.disabled=!0,s.classList.add("other-mode-is-requested"))}),J.onSessionRequestEnd(i=>{s.classList.remove("this-mode-is-requested"),s.classList.remove("other-mode-is-requested"),s.disabled=s["was-disabled"]}))}};let Kr=Xx;a(Kr,"_instance");var IT=Object.defineProperty,jT=Object.getOwnPropertyDescriptor,St=(s,t,i,n)=>{for(var o=n>1?void 0:n?jT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&IT(t,i,o),o};const bp=O("debugspriterenderer"),DT=O("wireframe"),C0=class{static getOrCreateGeometry(s){if(s.__cached_geometry)return s.__cached_geometry;if(s.guid&&C0.cache[s.guid])return bp&&console.log("Take cached geometry for sprite",s.guid),C0.cache[s.guid];const t=new bn;s.__cached_geometry=t;const i=new Float32Array(s.triangles.length*3),n=new Float32Array(s.triangles.length*2);for(let o=0;o<s.triangles.length;o+=1){const r=s.triangles[o];i[o*3]=-s.vertices[r].x,i[o*3+1]=s.vertices[r].y,i[o*3+2]=0;const l=s.uv[r];n[o*2]=l.x,n[o*2+1]=1-l.y}return t.setAttribute("position",new yt(i,3)),t.setAttribute("uv",new yt(n,2)),s.guid&&(this.cache[s.guid]=t),bp&&console.log("Built sprite geometry",s,t),t}};let vh=C0;a(vh,"cache",{});class LT{constructor(){a(this,"x"),a(this,"y")}}function Qx(s){s&&(s.colorSpace!=gs&&(s.colorSpace=gs,s.needsUpdate=!0),s.minFilter==md&&s.magFilter==md&&(s.anisotropy=1,s.needsUpdate=!0))}let rn=class{constructor(s){a(this,"guid"),a(this,"texture"),a(this,"triangles"),a(this,"uv"),a(this,"vertices"),a(this,"__cached_geometry"),a(this,"_mesh"),a(this,"_material"),s&&(this.texture=s,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 K(vh.getOrCreateGeometry(this),this.material)),this._mesh}get material(){return this._material||(this.texture&&Qx(this.texture),this._material=new Re({map:this.texture,color:16777215,side:xi,transparent:!0})),this._material}getGeometry(){return vh.getOrCreateGeometry(this)}};St([m()],rn.prototype,"guid",2),St([m(De)],rn.prototype,"texture",2),St([$a()],rn.prototype,"triangles",2),St([$a()],rn.prototype,"uv",2),St([$a()],rn.prototype,"vertices",2);const O0=Symbol("spriteOwner");class No{constructor(){a(this,"sprites")}}St([m(rn)],No.prototype,"sprites",2);const Yx=class{constructor(){a(this,"spriteSheet"),a(this,"index",0)}static create(){const s=new Yx;return s.spriteSheet=new No,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 No,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 i=this.spriteSheet.sprites[t],n=i?.texture;if(n&&(Qx(n),!i.__hasLoadedProgressive)){i.__hasLoadedProgressive=!0;const o=n;it.assignTextureLOD(n,0).then(r=>{r instanceof De&&(i.texture=r,s?.map===o&&(s.map=r,s.needsUpdate=!0))})}}};let Vn=Yx;St([m(No)],Vn.prototype,"spriteSheet",2),St([m()],Vn.prototype,"index",2);class fi extends A{constructor(){super(...arguments),a(this,"drawMode",0),a(this,"size",{x:1,y:1}),a(this,"color"),a(this,"sharedMaterial"),a(this,"transparent",!0),a(this,"cutoutThreshold",0),a(this,"castShadows",!1),a(this,"renderOrder",0),a(this,"toneMapped",!0),a(this,"_spriteSheet"),a(this,"_currentSprite")}set texture(t){var i;if(!this._spriteSheet)return;const n=(i=this._spriteSheet.spriteSheet)==null?void 0:i.sprites[this.spriteIndex];n&&(n.texture=t,this.updateSprite())}addSprite(t,i=!1){var n,o;if(this._spriteSheet||(this._spriteSheet=Vn.create()),!this._spriteSheet.spriteSheet)return-1;(n=this._spriteSheet.spriteSheet)==null||n.sprites.push(t);const r=((o=this._spriteSheet.spriteSheet)==null?void 0:o.sprites.length)-1;return i&&(this.spriteIndex=r),r}get sprite(){return this._spriteSheet}set sprite(t){if(t!==this._spriteSheet)if(typeof t=="number"){const i=Math.floor(t);this.spriteIndex=i;return}else t instanceof rn?(this._spriteSheet||(this._spriteSheet=Vn.create()),this._spriteSheet.sprite!=t&&(this._spriteSheet.sprite=t,this.updateSprite())):t!=this._spriteSheet&&(this._spriteSheet=t,this.updateSprite())}set spriteIndex(t){this._spriteSheet&&t!==this.spriteIndex&&(this._spriteSheet.index=t,this.updateSprite())}get spriteIndex(){var t;return((t=this._spriteSheet)==null?void 0:t.index)??0}get spriteFrames(){var t,i;return((i=(t=this._spriteSheet)==null?void 0:t.spriteSheet)==null?void 0:i.sprites.length)??0}awake(){this._currentSprite=void 0,this._spriteSheet||(this._spriteSheet=new Vn,this._spriteSheet.spriteSheet=new No),bp&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(t=!1){var i;if(!this.__didAwake&&!t)return!1;const n=this._spriteSheet;if(!((i=n?.spriteSheet)!=null&&i.sprites))return console.warn("SpriteRenderer has no data or spritesheet assigned..."),!1;const o=n.spriteSheet.sprites[this.spriteIndex];if(!o)return bp&&console.warn("Sprite not found",this.spriteIndex,n.spriteSheet.sprites),!1;if(this._currentSprite)this._currentSprite.geometry=vh.getOrCreateGeometry(o),this._currentSprite.material.map=o.texture;else{const r=new Re({color:16777215,side:xi});if(DT&&(r.wireframe=!0),this.color&&(r.color||(r.color=new re),r.color.copy(this.color),r.opacity=this.color.alpha),r.transparent=!0,r.toneMapped=this.toneMapped,o.texture&&!r.wireframe){let l=o.texture;l[O0]!==void 0&&l[O0]!==this&&this.spriteFrames>1&&(l=o.texture=l.clone()),l[O0]=this,r.map=l}this.sharedMaterial=r,this._currentSprite=new K(vh.getOrCreateGeometry(o),r),this._currentSprite.renderOrder=Math.round(this.renderOrder),it.assignTextureLOD(r,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,n?.update(this.sharedMaterial),!0}}St([m()],fi.prototype,"drawMode",2),St([m(LT)],fi.prototype,"size",2),St([m(Se)],fi.prototype,"color",2),St([m(ke)],fi.prototype,"sharedMaterial",2),St([m()],fi.prototype,"transparent",2),St([m()],fi.prototype,"cutoutThreshold",2),St([m()],fi.prototype,"castShadows",2),St([m()],fi.prototype,"renderOrder",2),St([m()],fi.prototype,"toneMapped",2),St([m(Vn)],fi.prototype,"sprite",1);const Kx=O("debugwebxr"),BT=new ne().makeRotationY(Math.PI);class Hn extends A{constructor(){super(...arguments),a(this,"_arScale",1),a(this,"invertForward",!1),a(this,"customReticle"),a(this,"arTouchTransform",!0),a(this,"autoPlace",!1),a(this,"autoCenter",!1),a(this,"useXRAnchor",!1),a(this,"_isPlacing",!0),a(this,"_startOffset",new ne),a(this,"_createdPlacementObject",null),a(this,"_reparentedComponents",[]),a(this,"_placementScene",new qi),a(this,"_reticle",[]),a(this,"_hits",[]),a(this,"_placementStartTime",-1),a(this,"_rigPlacementMatrix"),a(this,"_anchor",null),a(this,"userInput"),a(this,"onPlaceScene",t=>{var i;if(this._isPlacing==!1||t!=null&&t.used)return;let n=this._reticle[0];if(!n){console.warn("No reticle to place...");return}if(!n.visible&&!this.autoPlace){console.warn("Reticle is not visible (can not place)");return}if((i=J.active)!=null&&i.isTrackingImages){console.warn("Scene Placement is disabled while images are being tracked");return}let o=this._hits[0];if(t&&t.origin instanceof og){const r=this._reticle[t.origin.index];r&&(n=r,o=this._hits[t.origin.index])}if(t&&(t.stopImmediatePropagation(),t.stopPropagation(),t.use()),this._isPlacing=!1,this.context.input.removeEventListener("pointerup",this.onPlaceScene),this.onRevertSceneChanges(),n.position.copy(n.lastPos),n.quaternion.copy(n.lastQuat),this.onApplyPose(n),this.useXRAnchor&&this.onCreateAnchor(J.active,o),this.context.xr)for(const r of this.context.xr.controllers)r.cancelHitTestSource()}),a(this,"upVec",new x(0,1,0)),a(this,"lookPoint",new x),a(this,"worldUpVec",new x(0,1,0))}static onPlaced(t){const i="placed";return this._eventListeners[i]||(this._eventListeners[i]=[]),this._eventListeners[i].push(t),()=>{const n=this._eventListeners[i].indexOf(t);n>=0&&this._eventListeners[i].splice(n,1)}}get arScale(){return this._arScale}set arScale(t){t!==this._arScale&&(this._arScale=t,this.onScaleChanged())}onEnable(){var t;(t=this.customReticle)==null||t.preload()}supportsXR(t){return t==="immersive-ar"}onEnterXR(t){Kx&&console.log("ENTER WEBXR: SessionRoot start..."),this._anchor=null,this.gameObject.updateMatrixWorld(),this._startOffset.copy(this.gameObject.matrixWorld);const i=new I;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=ci(this._placementScene.children),o=n.getCenter(new x),r=n.getSize(new x),l=new ne;l.makeTranslation(o.x,o.y-r.y*.5,o.z),this._startOffset.multiply(l)}this._reparentedComponents.length=0,this._reparentedComponents.push({comp:this,originalObject:this.gameObject}),P.addComponent(i,this);for(const n of this._reticle)Ri(n);this._reticle.length=0,this._isPlacing=!0,this.context.input.addEventListener("pointerup",this.onPlaceScene,{queue:Oi.Early})}onLeaveXR(){this.context.input.removeEventListener("pointerup",this.onPlaceScene,{queue:Oi.Early}),this.onRevertSceneChanges(),this._anchor=null,this._rigPlacementMatrix=void 0}onUpdateXR(t){var i,n,o,r;if(t.xr.isTrackingImages){for(const l of this._reticle)l.visible=!1;return}if(this._isPlacing){const l=(i=t.xr.rig)==null?void 0:i.gameObject;l&&l.parent!==this.context.scene&&this.context.scene.add(l);let c=!1;if(t.xr.isPassThrough&&t.xr.controllers.length>0&&!this.autoPlace)for(const h of t.xr.controllers){const d=h.getHitTest();d&&(c=!0,this.updateReticleAndHits(t.xr,h.index,d,t.xr.rigScale))}if(!c){const h=t.xr.getHitTest();h&&this.updateReticleAndHits(t.xr,0,h,t.xr.rigScale)}}else{if(this._anchor&&t.xr.referenceSpace){const l=t.xr.frame.getPose(this._anchor.anchorSpace,t.xr.referenceSpace);if(l&&this.context.time.frame%20===0){const c=t.xr.convertSpace(l.transform),h=this._reticle[0];h&&(h.position.copy(c.position),h.quaternion.copy(c.quaternion),this.onApplyPose(h))}}if(this.arTouchTransform?(this.userInput||(this.userInput=new _p(this.context)),(n=this.userInput)==null||n.enable()):(o=this.userInput)==null||o.disable(),this.arTouchTransform&&(r=this.userInput)!=null&&r.hasChanged){if(t.xr.rig){const l=t.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(t,i,n,o){this._hits[i]=n.hit;let r=this._reticle[i];if(!r){if(this.customReticle)if(this.customReticle.asset)r=Ua(this.customReticle.asset);else{this.customReticle.loadAssetAsync();return}else r=new K(new aC(.07,.09,32).rotateX(-Math.PI/2),new Re({side:xi,depthTest:!1,depthWrite:!1,transparent:!0,opacity:1,color:15658734})),r.name="AR Placement Reticle";if(Kx){const l=new wi(1);l.position.y+=.01,r.add(l)}this._reticle[i]=r,r.matrixAutoUpdate=!1,r.visible=!1}if(r.lastPos=r.lastPos||n.position.clone(),r.lastQuat=r.lastQuat||n.quaternion.clone(),r.position.copy(r.lastPos.lerp(n.position,this.context.time.deltaTime/.1)),r.lastPos.copy(r.position),r.quaternion.copy(r.lastQuat.slerp(n.quaternion,this.context.time.deltaTime/.05)),r.lastQuat.copy(r.quaternion),r.scale.set(o,o,o),this.customReticle&&this.applyViewBasedTransform(r),r.updateMatrix(),r.visible=!0,r.parent!==this.context.scene&&this.context.scene.add(r),this._placementStartTime<0&&(this._placementStartTime=this.context.time.realtimeSinceStartup),this.autoPlace)if(this.upVec.set(0,1,0).applyQuaternion(r.quaternion),this.upVec.dot(G(0,1,0))>.9){let l=r["autoplace:timer"]||0;l>=1?(r.visible=!1,this.onPlaceScene(null)):(l+=this.context.time.deltaTime,r["autoplace:timer"]=l)}else r["autoplace:timer"]=0}onScaleChanged(){}onRevertSceneChanges(){var t;for(const i of this._reticle)i&&(i.visible=!1,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)}(t=this._createdPlacementObject)==null||t.removeFromParent();for(const i of this._reparentedComponents)P.addComponent(i.originalObject,i.comp)}async onCreateAnchor(t,i){if(i.createAnchor===void 0){console.warn("Hit does not support creating an anchor",i),F()&&xe("Hit does not support creating an anchor");return}else{const n=await i.createAnchor(t.viewerPose.transform);t.running&&n&&(this._anchor=n)}}applyViewBasedTransform(t){const i=this.context.mainCamera,n=t,o=i.worldPosition,r=n.worldPosition;this.upVec.set(0,1,0).applyQuaternion(t.quaternion);const l=i.worldPosition;l&&t.position.clone().sub(l).angleTo(this.upVec)<Math.PI/2&&this.upVec.negate();const c=this.upVec.angleTo(this.worldUpVec)*180/Math.PI,h=30;c>h&&c<180-h||c<-h&&c>-180+h?(this.lookPoint.copy(t.position).add(this.upVec),this.lookPoint.y=t.position.y,t.lookAt(this.lookPoint)):(o.y=r.y,t.lookAt(o))}onApplyPose(t){var i,n,o,r;const l=(n=(i=J.active)==null?void 0:i.rig)==null?void 0:n.gameObject;if(!l){console.warn("No rig object to place");return}(o=J.active)!=null&&o.rigScale;const c=l.parent||this.context.scene;this._rigPlacementMatrix?(r=this._rigPlacementMatrix)==null||r.decompose(l.position,l.quaternion,l.scale):this._rigPlacementMatrix=l.matrix.clone(),this.applyViewBasedTransform(t),t.updateMatrix(),this.context.scene.add(t),t.attach(l),t.removeFromParent(),l.scale.set(this.arScale,this.arScale,this.arScale),l.position.multiplyScalar(this.arScale),l.updateMatrix(),this.invertForward&&l.matrix.premultiply(BT),l.matrix.premultiply(this._startOffset),l.matrix.decompose(l.position,l.quaternion,l.scale),c.add(l)}}a(Hn,"_eventListeners",{});const P0=class{constructor(s){a(this,"oneFingerDrag",!0),a(this,"twoFingerRotate",!0),a(this,"twoFingerScale",!0),a(this,"factor",1),a(this,"context"),a(this,"offset"),a(this,"plane"),a(this,"_scale",1),a(this,"_hasChanged",!1),a(this,"_enabled",!1),a(this,"currentlyUsedPointerIds",new Set),a(this,"currentlyUnusedPointerIds",new Set),a(this,"onPointerDownEarly",t=>{this.isActive&&t.stopPropagation()}),a(this,"onPointerDownLate",t=>{t.used?this.currentlyUsedPointerIds.add(t.pointerId):this.currentlyUsedPointerIds.size<=0&&this.currentlyUnusedPointerIds.add(t.pointerId)}),a(this,"onPointerUpEarly",t=>{this.currentlyUsedPointerIds.delete(t.pointerId),this.currentlyUnusedPointerIds.delete(t.pointerId)}),a(this,"prev",new Map),a(this,"_didMultitouch",!1),a(this,"touchStart",t=>{if(!t.defaultPrevented)for(let i=0;i<t.changedTouches.length;i++){const n=t.changedTouches[i],o=X.isAndroidDevice()&&n.clientY<window.innerHeight*.1;this.prev.has(n.identifier)||this.prev.set(n.identifier,{ignore:o,x:0,z:0,screenx:0,screeny:0});const r=this.prev.get(n.identifier);if(r){const l=this.getPositionOnPlane(n.clientX,n.clientY);r.x=l.x,r.z=l.z,r.screenx=n.clientX,r.screeny=n.clientY}}}),a(this,"touchEnd",t=>{t.touches.length<=0&&(this._didMultitouch=!1);for(let i=0;i<t.changedTouches.length;i++){const n=t.changedTouches[i];this.prev.delete(n.identifier)}}),a(this,"touchMove",t=>{if(!t.defaultPrevented&&this.isActive){if(t.touches.length===1){if(this._didMultitouch)return;const i=t.touches[0],n=this.prev.get(i.identifier);if(!n||n.ignore)return;const o=this.getPositionOnPlane(i.clientX,i.clientY),r=o.x-n.x,l=o.z-n.z;if(r===0&&l===0)return;this.oneFingerDrag&&this.addMovement(r,l),n.x=o.x,n.z=o.z,n.screenx=i.clientX,n.screeny=i.clientY;return}else if(t.touches.length===2){this._didMultitouch=!0;const i=t.touches[0],n=t.touches[1],o=this.prev.get(i.identifier),r=this.prev.get(n.identifier);if(!o||!r)return;if(this.twoFingerRotate){const l=Math.atan2(i.clientY-n.clientY,i.clientX-n.clientX),c=Math.atan2(o.screeny-r.screeny,o.screenx-r.screenx),h=l-c;Math.abs(h)>.001&&this.addRotation(h)}if(this.twoFingerScale){const l=i.clientX-n.clientX,c=i.clientY-n.clientY,h=Math.sqrt(l*l+c*c),d=o.screenx-r.screenx,u=o.screeny-r.screeny,p=Math.sqrt(d*d+u*u),g=h-p;Math.abs(g)>2&&this.addScale(g)}o.screenx=i.clientX,o.screeny=i.clientY,r.screenx=n.clientX,r.screeny=n.clientY}}}),a(this,"_raycaster",new ud),a(this,"_intersection",new x),a(this,"_screenPos",new x),a(this,"_tempMatrix",new ne),this.context=s,this.offset=new ne,this.plane=new pr,this.plane.setFromNormalAndCoplanarPoint(P0.up,P0.zero)}reset(){this._scale=1,this.offset.identity()}get hasChanged(){return this._hasChanged}applyMatrixTo(s,t){this._hasChanged=!1,t?(this.offset.invert(),s.premultiply(this.offset)):s.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:Oi.Early}),this.context.input.addEventListener("pointerdown",this.onPointerDownLate,{queue:Oi.Late}),this.context.input.addEventListener("pointerup",this.onPointerUpEarly,{queue:Oi.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:Oi.Early}),this.context.input.removeEventListener("pointerdown",this.onPointerDownLate,{queue:Oi.Late}),this.context.input.removeEventListener("pointerup",this.onPointerUpEarly,{queue:Oi.Early}),window.removeEventListener("touchstart",this.touchStart),window.removeEventListener("touchmove",this.touchMove),window.removeEventListener("touchend",this.touchEnd))}getPositionOnPlane(s,t){const i=this.context.mainCamera;return this._screenPos.x=s/window.innerWidth*2-1,this._screenPos.y=-(t/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(s,t){s/=this._scale,t/=this._scale,s*=this.factor,t*=this.factor,this.offset.elements[12]+=s,this.offset.elements[14]+=t,(s!==0||t!==0)&&(this._hasChanged=!0)}addScale(s){s/=window.innerWidth,s*=-1,this._scale*=1+s,this._tempMatrix.makeScale(1-s,1-s,1-s),this.offset.premultiply(this._tempMatrix),s!==0&&(this._hasChanged=!0)}addRotation(s){s*=-1,this._tempMatrix.makeRotationY(s),this.offset.premultiply(this._tempMatrix),s!==0&&(this._hasChanged=!0)}};let _p=P0;a(_p,"up",new x(0,1,0)),a(_p,"zero",new x(0,0,0)),a(_p,"one",new x(1,1,1));const Wo=O("debugautosync"),k0=Symbol("syncerId");class FT{constructor(){a(this,"_syncers",{})}getOrCreateSyncer(t){if(!t.guid)return null;if(this._syncers[t.guid])return this._syncers[t.guid];const i=new zT(t);return i[k0]=t.guid,this._syncers[i[k0]]=i,i}removeSyncer(t){delete this._syncers[t[k0]]}}const M0=new FT;class zT{constructor(t){a(this,"comp"),a(this,"hasChanges",!1),a(this,"changedProperties",{}),a(this,"_isReceiving",!1),a(this,"_isInit",!1),a(this,"onHandleSending",()=>{if(!this.hasChanges)return;this.hasChanges=!1;const i=this.comp.context.connection;if(!i||!i.isConnected||!i.isInRoom){for(const n in this.changedProperties)delete this.changedProperties[n];return}for(const n in this.changedProperties){const o=this.changedProperties[n];Wo&&console.log("SEND",this.comp.guid,this.networkingKey),i.send(this.networkingKey,{guid:this.comp.guid,property:n,data:o},ws.Queued),delete this.changedProperties[n]}}),a(this,"onHandleReceiving",i=>{if(Wo&&console.log("SYNCFIELD RECEIVE",this.comp.name,this.comp.guid,i),!!this._isInit&&this.comp&&i.guid===this.comp.guid)try{this._isReceiving=!0,this.comp[i.property]=i.data}catch(n){console.error(n)}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 i=this.comp.context.connection.tryGetState(this.comp.guid);i&&this.onHandleReceiving(i)}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,i){this._isReceiving||(Wo&&console.log("Property changed: "+t,i),this.hasChanges=!0,this.changedProperties[t]=i)}}function UT(s,t){let i=t!==s;return!i&&s&&t&&(Array.isArray(s)&&Array.isArray(t)||typeof s=="object"&&typeof t=="object")&&(i=!0),i}const bh=Symbol("AutoSyncHandler");function NT(s){if(s[bh])return s[bh];const t=M0.getOrCreateSyncer(s);return t?.init(s),s[bh]=t,t}function WT(s){const t=s[bh];t&&(M0.removeSyncer(t),t.destroy(),delete s[bh])}const R0=function(s=null){return function(t,i){var n;let o="";typeof i=="string"?o=i:o=i.name;let r=null,l;typeof s=="string"?l=t[s]:typeof s=="function"&&(l=s),l==null&&(F()||Wo)&&s!=null&&console.warn('syncField: no callback function found for property "'+o+'"','"'+s+'"');const c=t,h=c.__internalAwake;if(typeof h!="function"){(Wo||F())&&console.error('@syncField can currently only used on Needle Engine Components, custom object of type "'+((n=t?.constructor)==null?void 0:n.name)+'" is not supported',t);return}Wo&&console.log(o);const d=Symbol(o);c.__internalAwake=function(){if(this[d]!==void 0)return;this[d]=this[o],r=M0.getOrCreateSyncer(this);const p=Object.getOwnPropertyDescriptor(this,o);if(p?.set===void 0){let g=!1;Object.defineProperty(this,o,{set:function(y){var f;const v=this[d];if(this[d]=y,g){(F()||Wo)&&console.warn("Recursive call detected",o);return}g=!0;try{const b=UT(y,v);Wo&&console.log("SyncField assignment",o,"changed?",b,y,l),b&&l?.call(this,y,v)!==!1&&((f=NT(this))==null||f.notifyChanged(o,y))}finally{g=!1}},get:function(){return this[d]},configurable:!0,enumerable:!0})}r?.init(this),h.call(this)};const u=c.__internalDestroy;c.__internalDestroy=function(){WT(this),u.call(this)}}};var VT=Object.defineProperty,HT=Object.getOwnPropertyDescriptor,wp=(s,t,i,n)=>{for(var o=n>1?void 0:n?HT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&VT(t,i,o),o};const ii=O("debugplayersync"),Zx=class extends A{constructor(){super(...arguments),a(this,"autoSync",!0),a(this,"asset"),a(this,"onPlayerSpawned"),a(this,"_localInstance"),a(this,"onJoinedRoom",()=>{ii&&console.log("PlayerSync.joinedRoom. autoSync is set to "+this.autoSync),this.autoSync&&this.getInstance()}),a(this,"destroyInstance",()=>{var s;(s=this._localInstance)==null||s.then(t=>{ii&&console.log("PlayerSync.destroyInstance",t),Sc(t,this.context.connection,!0,{saveInRoom:!1})}),this._localInstance=void 0})}static async setupFrom(s,t){const i=ae.getOrCreateFromUrl(s);if(!i.asset){const r=await i.loadAssetAsync();r&&P.getOrAddComponent(r,Di)}const n=new Zx;n._internalInit(t),n.asset=i;const o=new I;return o.guid=s,P.addComponent(o,n),n}awake(){this.watchTabVisible(),this.onPlayerSpawned||(this.onPlayerSpawned=new _e)}onEnable(){this.context.connection.beginListen(ie.RoomStateSent,this.onJoinedRoom),this.context.connection.beginListen(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ie.LeftRoom,this.destroyInstance),this.context.connection.isInRoom&&this.onJoinedRoom()}onDisable(){this.context.connection.stopListen(ie.RoomStateSent,this.onJoinedRoom),this.context.connection.stopListen(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ie.LeftRoom,this.destroyInstance)}async getInstance(){var s,t,i,n,o,r;if(this._localInstance)return this._localInstance;if(ii&&console.log("PlayerSync.createInstance",(s=this.asset)==null?void 0:s.url),!((t=this.asset)!=null&&t.asset)&&!((i=this.asset)!=null&&i.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=(n=this.asset)==null?void 0:n.instantiateSynced({parent:this.gameObject,deleteOnDisconnect:!0},!0);const l=await this._localInstance;if(l){const c=P.getComponentsInChildren(l,Di);if(ii&&console.log(`PlayerSync.createInstance: found ${c?.length} PlayerState components. Owner: ${this.context.connection.connectionId}`),c!=null&&c.length){for(const h of c)h.owner=this.context.connection.connectionId;(o=this.onPlayerSpawned)==null||o.invoke(l)}else this._localInstance=void 0,console.error("<strong>Failed finding PlayerState on "+((r=this.asset)==null?void 0:r.url)+"</strong>: please make sure the asset has a PlayerState component!"),P.destroySynced(l)}else this._localInstance=void 0,console.warn("PlayerSync: failed instantiating asset!");return this._localInstance}watchTabVisible(){window.addEventListener("visibilitychange",s=>{if(document.visibilityState==="visible")for(let t=Di.all.length-1;t>=0;t--){const i=Di.all[t];(!i.owner||!this.context.connection.userIsInRoom(i.owner))&&i.doDestroy()}})}};let Sl=Zx;wp([m()],Sl.prototype,"autoSync",2),wp([m(ae)],Sl.prototype,"asset",2),wp([m(_e)],Sl.prototype,"onPlayerSpawned",2);var Jx=(s=>(s.OwnerChanged="ownerChanged",s))(Jx||{}),_h;const It=(_h=class extends A{constructor(){super(...arguments),a(this,"onOwnerChangeEvent",new _e),a(this,"onFirstOwnerChangeEvent",new _e),a(this,"hasOwner",!1),a(this,"owner"),a(this,"dontDestroy",!1),a(this,"onUserLeftRoom",s=>{if(s.userId===this.owner){ii&&console.log("PLAYERSYNC LEFT",this.owner),this.doDestroy();return}})}static get all(){return It._all}static get local(){return It._local}static getFor(s){if(s instanceof I)return P.getComponentInParent(s,It);if(s instanceof A)return P.getComponentInParent(s.gameObject,It)}static isLocalPlayer(s){const t=It.getFor(s);return t?.isLocalPlayer??!1}static addEventListener(s,t){return this._callbacks[s]||(this._callbacks[s]=[]),this._callbacks[s].push(t),t}static removeEventListener(s,t){if(!this._callbacks[s])return;const i=this._callbacks[s].indexOf(t);i>=0&&this._callbacks[s].splice(i,1)}static dispatchEvent(s,t){if(this._callbacks[s])for(const i of this._callbacks[s])i(t)}get isLocalPlayer(){return this.owner===this.context.connection.connectionId}onOwnerChange(s,t){var i,n;ii&&console.log(`PlayerSync.onOwnerChange: ${t} \u2192 ${s} (me: ${this.context.connection.connectionId})`);const o=It._local.indexOf(this);o>=0&&It._local.splice(o,1);const r={playerState:this,oldValue:t,newValue:s};if(this.hasOwner||(this.hasOwner=!0,(i=this.onFirstOwnerChangeEvent)==null||i.invoke(r)),(n=this.onOwnerChangeEvent)==null||n.invoke(r),this.owner===this.context.connection.connectionId){It._local.push(this);const c=new CustomEvent("local-owner-changed",{detail:r});this.dispatchEvent(c)}const l=new CustomEvent("owner-changed",{detail:r});this.dispatchEvent(l),It.dispatchEvent("ownerChanged",l)}awake(){It.all.push(this),ii&&console.log("Registered new PlayerState",this.guid,It.all.length-1,It.all),this.context.connection.beginListen(ie.UserLeftRoom,this.onUserLeftRoom)}async start(){ii&&console.log("PLAYERSTATE.START, owner: "+this.owner,this.context.connection.usersInRoom([])),this.owner?(this.context.connection.isInRoom||await ys(300),this.context.connection.userIsInRoom(this.owner)==!1&&(ii&&console.log(`PlayerSync.start \u2192 doDestroy "${this.name}" because user "${this.owner}" is not in room anymore...`,"Currently in room:",...this.context.connection.usersInRoom()),this.doDestroy())):this.owner||(ii&&console.warn("PlayerState.start \u2192 owner is undefined!",this.name),setTimeout(()=>{!this.destroyed&&!this.owner?this.dontDestroy?ii&&console.warn("PlayerState.start \u2192 owner is still undefined but dontDestroy is set to true",this.name):(ii&&console.warn(`PlayerState.start \u2192 owner is still undefined: destroying "${this.name}" instance now`),this.doDestroy()):ii&&console.log("PlayerState.start \u2192 owner is assigned",this.owner)},2e3))}doDestroy(){ii&&console.log("PlayerSync.doDestroy \u2192 syncDestroy",this.name),Sc(this.gameObject,this.context.connection,!0,{saveInRoom:!1})}onDestroy(){if(ii&&console.warn("PlayerState.onDestroy",this.owner),this.context.connection.stopListen(ie.UserLeftRoom,this.onUserLeftRoom),It.all.splice(It.all.indexOf(this),1),this.isLocalPlayer){const s=It._local.indexOf(this);s>=0&&It._local.splice(s,1)}}},a(_h,"_all",[]),a(_h,"_local",[]),a(_h,"_callbacks",{}),_h);let Di=It;wp([R0(Di.prototype.onOwnerChange)],Di.prototype,"owner",2);var $T=Object.defineProperty,qT=Object.getOwnPropertyDescriptor,Cl=(s,t,i,n)=>{for(var o=n>1?void 0:n?qT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&$T(t,i,o),o};class an extends A{constructor(){super(...arguments),a(this,"position","bottom"),a(this,"showNeedleLogo",!0),a(this,"showSpatialMenu"),a(this,"createFullscreenButton"),a(this,"createMuteButton"),a(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&&(X.isMobileDevice()||this.context.menu.showQRCodeButton(!0))}}Cl([m()],an.prototype,"position",2),Cl([m()],an.prototype,"showNeedleLogo",2),Cl([m()],an.prototype,"showSpatialMenu",2),Cl([m()],an.prototype,"createFullscreenButton",2),Cl([m()],an.prototype,"createMuteButton",2),Cl([m()],an.prototype,"createQRCodeButton",2);var GT=Object.defineProperty,XT=Object.getOwnPropertyDescriptor,T0=(s,t,i,n)=>{for(var o=n>1?void 0:n?XT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&>(t,i,o),o};const wh=O("debugwebxr"),e1=new V().setFromAxisAngle(new x(0,1,0),Math.PI);class Vo extends A{constructor(){super(...arguments),a(this,"head"),a(this,"leftHand"),a(this,"rightHand"),a(this,"_leftHandMeshes"),a(this,"_rightHandMeshes"),a(this,"_syncTransforms")}async onEnterXR(t){if(!this.activeAndEnabled)return;wh&&console.warn("AVATAR ENTER XR",this.guid,this.sourceId,this,this.activeAndEnabled),this._syncTransforms&&(this._syncTransforms.length=0),await this.prepareAvatar();const i=Di.getFor(this);if(i!=null&&i.owner){const n=this.gameObject.addComponent(Tt);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(t){const i=this.gameObject.getComponent(Tt);i&&i.destroy()}onUpdateXR(t){var i,n;if(!this.activeAndEnabled)return;const o=Di.isLocalPlayer(this);if(!o)return;const r=t.xr;if(r.rig&&r.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),r.rig.gameObject.add(this.gameObject)),this._syncTransforms&&o)for(const u of this._syncTransforms)u.fastMode=!0,u.isOwned()||u.requestOwnership();if(this.head&&this.context.mainCamera){const u=this.head.asset;if(u.position.copy(this.context.mainCamera.position),u.position.x*=-1,u.position.z*=-1,u.quaternion.copy(this.context.mainCamera.quaternion),u.quaternion.x*=-1,this.context.time.frameCount%10===0&&this.head.asset){const p=P.getComponentsInChildren(this.head.asset,Ai);for(const g of p)g.enabled=!1,g.gameObject.visible=!1}}const l=t.xr.leftController,c=(i=this.leftHand)==null?void 0:i.asset;l&&c?(c.position.copy(l.gripPosition),c.quaternion.copy(l.gripQuaternion),c.quaternion.multiply(e1),c.visible=l.isTracking,this.updateHandVisibility(l,c,this._leftHandMeshes)):c&&c.visible&&(c.visible=!1);const h=t.xr.rightController,d=(n=this.rightHand)==null?void 0:n.asset;h&&d?(d.position.copy(h.gripPosition),d.quaternion.copy(h.gripQuaternion),d.quaternion.multiply(e1),d.visible=h.isTracking,this.updateHandVisibility(h,d,this._rightHandMeshes)):d&&d.visible&&(d.visible=!1)}onBeforeRender(){this.context.xr&&this.context.time.frame%10===0&&this.updateRemoteAvatarVisibility()}updateHandVisibility(t,i,n){if(n){const o=t.model&&t.model.visible&&t.model!==i;n.forEach(r=>{Mn(r,!o)})}}updateRemoteAvatarVisibility(){var t,i,n;if(this.context.connection.isConnected){const o=Di.getFor(this);if(o&&o.isLocalPlayer==!1){const r=J.getXRSync(this.context);if(r&&r.hasState(o.owner)){this.tryFindAvatarObjectsIfMissing();const l=(t=this.leftHand)==null?void 0:t.asset;l&&(l.visible=r?.isTracking(o.owner,"left")??!1);const c=(i=this.rightHand)==null?void 0:i.asset;c&&(c.visible=r?.isTracking(o.owner,"right")??!1)}if((n=this.head)!=null&&n.asset){const l=P.getComponentsInChildren(this.head.asset,Ai);for(const c of l)c.enabled=!1,c.gameObject.visible=!0}}}}tryFindAvatarObjectsIfMissing(){if(!this.head||!this.leftHand||!this.rightHand){const t={head:this.head,leftHand:this.leftHand,rightHand:this.rightHand};Nb.tryFindAvatarObjects(this.gameObject,this.sourceId||"",t),t.head&&(this.head=t.head),t.leftHand&&(this.leftHand=t.leftHand),t.rightHand&&(this.rightHand=t.rightHand)}}async prepareAvatar(){var t,i;if(this.tryFindAvatarObjectsIfMissing(),this.head)this.head instanceof I&&(this.head=new ae("",this.sourceId,this.head));else{const n=new I;n.name="Head";const o=mo.createPrimitive(wr.Cube);n.add(o),this.gameObject.add(n),this.head=new ae("",this.sourceId,n),wh&&console.log("Create head",n)}if(this.rightHand)this.rightHand instanceof I&&(this.rightHand=new ae("",this.sourceId,this.rightHand));else{const n=new I;n.name="Right Hand",this.gameObject.add(n),this.rightHand=new ae("",this.sourceId,n),wh&&console.log("Create right hand",n)}if(this.leftHand)this.leftHand instanceof I&&(this.leftHand=new ae("",this.sourceId,this.leftHand));else{const n=new I;n.name="Left Hand",this.gameObject.add(n),this.leftHand=new ae("",this.sourceId,n),wh&&console.log("Create left hand",n)}await this.loadAvatarObjects(this.head,this.leftHand,this.rightHand),this._leftHandMeshes=[],(t=this.leftHand.asset)==null||t.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)}),Di.isLocalPlayer(this.gameObject)&&(this._syncTransforms=P.getComponentsInChildren(this.gameObject,qs))}async loadAvatarObjects(t,i,n){const o=t.loadAssetAsync(),r=i.loadAssetAsync(),l=n.loadAssetAsync(),c=new Array;o&&c.push(o),r&&c.push(r),l&&c.push(l);const h=await wd(c);wh&&console.log("Avatar loaded results:",h)}}T0([m(ae)],Vo.prototype,"head",2),T0([m(ae)],Vo.prototype,"leftHand",2),T0([m(ae)],Vo.prototype,"rightHand",2);var QT=Object.defineProperty,YT=Object.getOwnPropertyDescriptor,xp=(s,t,i,n)=>{for(var o=n>1?void 0:n?YT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&QT(t,i,o),o};const $n=O("debugwebxr"),Ho=new Array;class ln extends A{constructor(){super(...arguments),a(this,"createControllerModel",!0),a(this,"createHandModel",!0),a(this,"customLeftHand"),a(this,"customRightHand"),a(this,"_models",new Array)}supportsXR(t){return t==="immersive-vr"||t==="immersive-ar"}async onXRControllerAdded(t){var i;if(!(t.xr.isVR||t.xr.isPassThrough))return;const{controller:n}=t;if($n&&console.warn("Add Controller Model for",n.side,n.index),this.createControllerModel||this.createHandModel){if(n.hand){if(this.createHandModel){const o=await this.loadHandModel(this,n);if(!o||!n.connected||!n.isHand){o!=null&&o.handObject&&za(o.handObject,!1),(i=o?.handObject)==null||i.destroy();return}this._models.push({controller:n,model:o.handObject,handmesh:o.handmesh}),this._models.sort((r,l)=>r.controller.index-l.controller.index),this.scene.add(o.handObject),n.model=o.handObject}}else if(this.createControllerModel){const o=await n.getModelUrl();if(o){const r=await this.loadModel(n,o);if(!r||!n.connected||n.isHand)return;this._models.push({controller:n,model:r}),this._models.sort((l,c)=>l.controller.index-c.controller.index),this.scene.add(r),r.traverse(l=>{l.layers.set(2),l.matrixAutoUpdate=!1,l.updateMatrix()}),n.model=r}else n.targetRayMode!=="transient-pointer"&&console.warn("XRControllerModel: no model found for "+n.side)}}}onXRControllerRemoved(t){console.debug("XR Controller Removed",t.controller.side,t.controller.index);const i=this._models.findIndex(o=>o.controller===t.controller),n=this._models[i];n&&(this._models.splice(i,1),n.model&&(za(n.model,!1),n.model.destroy(),n.model=void 0))}onBeforeXR(t,i){this.createHandModel&&(this.customLeftHand||this.customRightHand)&&(i.optionalFeatures=i.optionalFeatures||[],i.optionalFeatures.includes("hand-tracking")||i.optionalFeatures.push("hand-tracking"))}onLeaveXR(t){for(const i of this._models)i&&(i.model&&(za(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(J.active&&($n&&(Ho[0]=Date.now()),this.updateRendering(J.active),$n)){const t=Date.now()-Ho[0];Ho.push(t),Ho.length>=30&&(Ho[0]=0,Ho.reduce((i,n)=>i+n,0)/Ho.length,Ho.length=0)}}updateRendering(t){var i,n,o,r,l;for(let c=0;c<this._models.length;c++){const h=this._models[c];if(!h)continue;const d=h.controller;if(!d.connected){$n&&console.warn("XRControllerModel.onUpdateXR: controller is not connected anymore",d.side,d.hand);continue}if(h.model&&!h.handmesh)h.model.matrixAutoUpdate=!1,h.model.matrix.copy(d.gripMatrix),h.model.visible=d.isTracking,(i=t.rig)==null||i.gameObject.add(h.model);else if(d.inputSource.hand&&h.handmesh){const u=t.referenceSpace,p=this.context.renderer.xr.getHand(d.index);if(u&&t.frame.getJointPose){for(const g of d.inputSource.hand.values()){const y=p.joints[g.jointName];if(y){const f=d.getHandJointPose(g);if(f){const v=f.transform.position,b=f.transform.orientation;y.position.copy(v),y.quaternion.copy(b),y.matrixAutoUpdate=!1}y.visible=f!=null}}h.model&&(h.model.visible=d.isTracking,h.model.visible&&h.model.parent!==((n=t.rig)==null?void 0:n.gameObject)&&((o=t.rig)==null||o.gameObject.add(h.model))),(r=h.model)!=null&&r.visible&&((l=h.handmesh)==null||l.updateMesh(),h.model.matrixAutoUpdate=!1,h.model.matrix.identity(),h.model.applyMatrix4(Ra))}}}}async loadModel(t,i){var n;if(!t.connected)return console.warn("XRControllerModel.onXRControllerAdded: controller is not connected anymore",t.side),null;const o=await ae.getOrCreate("",i).instantiate();return za(o),(n=J.active)!=null&&n.isPassThrough&&o.traverseVisible(r=>{this.makeOccluder(r)}),o}async loadHandModel(t,i){const n=this.context,o=n.renderer.xr.getHand(i.index);o||($n?q.DrawLabel(i.rayWorldPosition,"No hand found for index "+i.index,.05,5):console.warn("No hand found for index "+i.index));const r=new gr;Su(r,n),await Zu(r,n,this.sourceId??"");const l=Ku(r);let c="";const h=i.side==="left"?this.customLeftHand:this.customRightHand;h?(c=h.url.split(".").slice(0,-1).join("."),r.setPath("")):(c=i.inputSource.handedness==="left"?"left":"right",r.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/"));const d=new I;za(d);const u=new UC(d,o,r.path,c,r,p=>{var g;const y=l.gltf;((g=y?.scene.children)==null?void 0:g.length)===0&&(y.scene.children[0]=p),fs().createBuiltinComponents(t.context,t.sourceId||c,l.gltf,null,l),p.traverse(f=>{var v;f.layers.set(2),(v=J.active)!=null&&v.isPassThrough&&!h&&this.makeOccluder(f),f instanceof K&&it.assignMeshLOD(f,0)}),i.connected||($n&&q.DrawLabel(i.rayWorldPosition,"Hand is loaded but not connected anymore",.05,5),p.removeFromParent())});if($n&&d.add(new wi(.5)),i.inputSource.hand){$n&&console.log(i.inputSource.hand);for(const p of i.inputSource.hand.values())if(o.joints[p.jointName]===void 0){const g=new oo;g.matrixAutoUpdate=!1,g.visible=!0,o.joints[p.jointName]=g,o.add(g)}}else $n&&q.DrawLabel(i.rayWorldPosition,"No inputSource.hand found for index "+i.index,.05,5);return{handObject:d,handmesh:u}}makeOccluder(t){if(t instanceof K){let i=t.material;i instanceof ke&&(i=t.material=i.clone(),i.depthWrite=!0,i.depthTest=!0,i.colorWrite=!1,t.receiveShadow=!1,t.renderOrder=-100)}}}a(ln,"factory",new zC),xp([m()],ln.prototype,"createControllerModel",2),xp([m()],ln.prototype,"createHandModel",2),xp([m(ae)],ln.prototype,"customLeftHand",2),xp([m(ae)],ln.prototype,"customRightHand",2);class Sp extends A{}var KT=Object.defineProperty,ZT=Object.getOwnPropertyDescriptor,$o=(s,t,i,n)=>{for(var o=n>1?void 0:n?ZT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&KT(t,i,o),o};const E0=O("debugwebxr");class Li extends A{constructor(){super(...arguments),a(this,"movementSpeed",1.5),a(this,"rotationStep",30),a(this,"useTeleport",!0),a(this,"usePinchToTeleport",!0),a(this,"useTeleportTarget",!1),a(this,"useTeleportFade",!1),a(this,"showRays",!0),a(this,"showHits",!0),a(this,"isXRMovementHandler",!0),a(this,"xrSessionMode","immersive-vr"),a(this,"_didApplyRotation",!1),a(this,"_didTeleport",!1),a(this,"_teleportBuffer",new Array),a(this,"_plane",null),a(this,"_lines",[]),a(this,"_hitDiscs",[]),a(this,"_hitDistances",[]),a(this,"_lastHitDistances",[]),a(this,"hitPointRaycastFilter",t=>t.type==="SkinnedMesh"?"continue in children":!0)}onUpdateXR(t){const i=t.xr.rig;if(!(i!=null&&i.gameObject)||t.xr.isPassThrough)return;const n=t.xr.leftController,o=t.xr.rightController;n&&this.onHandleMovement(n,i.gameObject),o&&(this.onHandleRotation(o,i.gameObject),this.useTeleport&&this.onHandleTeleport(o,i.gameObject))}onLeaveXR(t){for(const i of this._lines)i.removeFromParent();for(const i of this._hitDiscs)i?.removeFromParent()}onBeforeRender(){var t;(t=this.context.xr)!=null&&t.running&&(this.showRays&&this.renderRays(this.context.xr),this.showHits&&this.renderHits(this.context.xr))}onHandleMovement(t,i){const n=t.getStick("xr-standard-thumbstick");if(n.x!=0||n.y!=0){const o=G(n.x,0,n.y);o.multiplyScalar(this.context.time.deltaTimeUnscaled*this.movementSpeed);const r=Je(i);o.multiplyScalar(r.x),o.applyQuaternion(t.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(t,i){if(t._isMxInk)return;const n=t.getStick("xr-standard-thumbstick").x;if(this._didApplyRotation)Math.abs(n)<.3&&(this._didApplyRotation=!1);else if(Math.abs(n)>.5){this._didApplyRotation=!0;const o=n>0?1:-1,r=te(this.context.mainCamera).clone();i.rotateY(o*W.toRadians(this.rotationStep));const l=te(this.context.mainCamera).clone().sub(r);l.y=0,i.position.sub(l)}}onHandleTeleport(t,i){var n,o,r,l,c;let h=0;if(t.hand&&this.usePinchToTeleport&&t.isTeleportGesture){const d=t.getPointerId("primary");if(d!=null&&this.context.input.getIsPointerIdInUse(d))return;const u=t.getGesture("pinch");u&&(h=u.value)}else h=(n=t.getStick("xr-standard-thumbstick"))==null?void 0:n.y;if(this._didTeleport)h>=0&&h<.4?this._didTeleport=!1:h<0&&h>-.4&&(this._didTeleport=!1);else if(h>.8){this._didTeleport=!0;const d=this.context.physics.raycastFromRay(t.ray)[0];if(d&&d.object instanceof Sa){const p=(o=d.normal)==null?void 0:o.dot(G(0,1,0));if(p!==void 0&&p<.4)return}let u=d?.point;if(!u&&!this.useTeleportTarget){this._plane||(this._plane=new pr(new x(0,1,0),0));const p=i.worldPosition;this._plane.setFromNormalAndCoplanarPoint(new x(0,1,0),p);const g=t.ray;u=p.clone(),this._plane.intersectLine(new lC(g.origin,G(g.direction).multiplyScalar(1e4).add(g.origin)),u),u.distanceTo(p)>i.scale.x*10&&(u=null)}if(u){if(this.useTeleportTarget&&!P.getComponentInParent(d.object,Sp))return;const p=u.clone();if(E0&&q.DrawSphere(u,.025,16711680,5),(r=this.context.mainCamera)==null?void 0:r.position){const g=(l=this.context.xr)==null?void 0:l.getUserOffsetInRig();g&&(g.y=0,p.sub(g),E0&&q.DrawWireSphere(g.add(p),.025,65280,5))}this._teleportBuffer.push(i.matrix.clone()),this._teleportBuffer.length>10&&this._teleportBuffer.shift(),this.useTeleportFade?(c=t.xr.fadeTransition())==null||c.then(()=>{i.worldPosition=p}):i.worldPosition=p}}else if(h<-.8&&(this._didTeleport=!0,this._teleportBuffer.length>0)){const d=this._teleportBuffer.pop();d&&d.decompose(i.position,i.quaternion,i.scale)}}renderRays(t){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<t.controllers.length;n++){const o=t.controllers[n];let r=this._lines[n];if(!o.connected||!o.isTracking||!o.ray||o.targetRayMode==="transient-pointer"||!o.hasSelectEvent){r&&(r.visible=!1);continue}r||(r=this.createRayLineObject(),r.scale.z=.5,this._lines[n]=r),o.updateRayWorldPosition(),o.updateRayWorldQuaternion();const l=o.rayWorldPosition,c=o.rayWorldQuaternion;r.position.copy(l),r.quaternion.copy(c);const h=t.rigScale,d=this.usePinchToTeleport&&o.isTeleportGesture,u=this._lastHitDistances[n],p=this._hitDistances[n]!=null,g=u??h;r.scale.set(h,h,g),r.visible=!0,r.layers.disableAll(),r.layers.enable(2);let y=r.material.opacity;d?y=1:this.showHits&&g<t.rigScale*.5?y=0:(i=o.getButton("primary"))!=null&&i.pressed?y=.5:y=p?.2:.1,r.material.opacity=W.lerp(r.material.opacity,y,this.context.time.deltaTimeUnscaled/.1),r.parent!==this.context.scene&&this.context.scene.add(r)}}renderHits(t){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<t.controllers.length;n++){const o=t.controllers[n];if(!o.connected||!o.isTracking||!o.ray||!o.hasSelectEvent)continue;let r=this._hitDiscs[n],l=!0;const c=o.getPointerId("primary");c!=null&&this.context.input.getIsPointerIdInUse(c)&&(r&&(r.visible=!1),this._hitDistances[n]=null,this._lastHitDistances[n]=0,l=!1);const h=this.context.time.smoothedFps>=59?1:10;if((this.context.time.frame+o.index)%h!==0&&(l=!1),!l){const p=this._hitDiscs[n];p&&p.visible&&p.hit&&this.updateHitPointerPosition(o,p,p.hit.distance);continue}const d=this.context.physics.raycastFromRay(o.ray,{testObject:this.hitPointRaycastFilter,precise:!1});let u=d.find(p=>this.usePinchToTeleport&&o.isTeleportGesture?!0:this.isObjectWithInteractiveComponent(p.object));if(u||(u=d[0]),r&&(r.controller=o,r.hit=u),this._hitDistances[n]=u?.distance||null,u){this._lastHitDistances[n]=u.distance;const p=t.rigScale??1;E0&&(q.DrawWireSphere(u.point,.025*p,16711680),q.DrawLabel(G(0,.2,0).add(u.point),u.object.name,.02,0)),r||(r=this.createHitPointObject(),this._hitDiscs[n]=r),r.hit=u,r.visible=u.distance>p*.05;let g=.01*(p+u.distance);const y=(i=o.getButton("primary"))==null?void 0:i.pressed;y&&(g*=1.1),r.scale.set(g,g,g),r.layers.set(2);let f=r.material.opacity;if(y?f=1:f=u.distance<.15*p?.2:.6,r.material.opacity=W.lerp(r.material.opacity,f,this.context.time.deltaTimeUnscaled/.1),r.visible){if(u.normal){this.updateHitPointerPosition(o,r,u.distance);const v=u.normal.applyQuaternion(Oe(u.object));r.quaternion.setFromUnitVectors(JT,v)}else this.updateHitPointerPosition(o,r,u.distance);r.parent!==this.context.scene&&this.context.scene.add(r)}}else this._hitDiscs[n]&&(this._hitDiscs[n].visible=!1)}}isObjectWithInteractiveComponent(t,i=0){return Tu(t)||t.isUI===!0?!0:t.isScene?!1:t.parent?this.isObjectWithInteractiveComponent(t.parent,i+1):!1}updateHitPointerPosition(t,i,n){const o=G(t.rayWorldPosition);o.add(G(0,0,n-.01).applyQuaternion(t.rayWorldQuaternion)),i.position.lerp(o,this.context.time.deltaTimeUnscaled/.05)}createHitPointObject(){const t=new K(new hd(.3,6,6),new Re({color:15658734,opacity:.7,transparent:!0,depthTest:!1,depthWrite:!1,side:xi}));return t.layers.disableAll(),t.layers.enable(2),t}createRayLineObject(){const t=new NC;t.layers.disableAll(),t.layers.enable(2);const i=new WC;t.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 r=new VC({color:16777215,vertexColors:!0,worldUnits:!0,linewidth:.004,transparent:!0,depthWrite:!1,blending:iv,dashed:!1});return t.material=r,t}}$o([m()],Li.prototype,"movementSpeed",2),$o([m()],Li.prototype,"rotationStep",2),$o([m()],Li.prototype,"useTeleport",2),$o([m()],Li.prototype,"usePinchToTeleport",2),$o([m()],Li.prototype,"useTeleportTarget",2),$o([m()],Li.prototype,"useTeleportFade",2),$o([m()],Li.prototype,"showRays",2),$o([m()],Li.prototype,"showHits",2);const JT=new x(0,1,0);var eE=Object.defineProperty,tE=Object.getOwnPropertyDescriptor,Ct=(s,t,i,n)=>{for(var o=n>1?void 0:n?tE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&eE(t,i,o),o};const xh=O("debugwebxr"),iE=O("debugusdz");var A0;const Ol=(A0=class extends A{constructor(){super(...arguments),a(this,"createVRButton",!0),a(this,"createARButton",!0),a(this,"createSendToQuestButton",!0),a(this,"createQRCode",!0),a(this,"useDefaultControls",!0),a(this,"showControllerModels",!0),a(this,"showHandModels",!0),a(this,"usePlacementReticle",!0),a(this,"customARPlacementReticle"),a(this,"usePlacementAdjustment",!0),a(this,"arScale",1),a(this,"useXRAnchor",!1),a(this,"autoPlace",!0),a(this,"autoCenter",!1),a(this,"useQuicklookExport",!1),a(this,"useDepthSensing",!1),a(this,"useSpatialGrab",!0),a(this,"defaultAvatar"),a(this,"_playerSync"),a(this,"_createdComponentsInSession",[]),a(this,"_usdzExporter"),a(this,"_exitXRMenuButton"),a(this,"_previousXRState",0),a(this,"_spatialGrabRaycaster"),a(this,"onAvatarSpawned",s=>{xh&&console.log("WebXR.onAvatarSpawned",s),P.getComponentInChildren(s,Vo)??(e=P.addComponent(s,Vo))}),a(this,"_buttonFactory"),a(this,"_buttons",[])}awake(){J.getXRSync(this.context)}onEnable(){var s,t;window.location.protocol!=="https:"&&xe('<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&&(P.findObjectOfType(Ge)||(xh&&console.log("WebXR: Adding USDZExporter"),this._usdzExporter=P.addComponent(this.gameObject,Ge),this._usdzExporter.objectToExport=this.context.scene,this._usdzExporter.autoExportAnimations=!0,this._usdzExporter.autoExportAudioSources=!0)),this.handleCreatingHTML(),this.handleOfferSession(),this.defaultAvatar===!0&&(xh&&console.warn("WebXR: No default avatar set, using static default avatar"),this.defaultAvatar=new ae("https://cdn.needle.tools/static/avatars/DefaultAvatar.glb")),this.defaultAvatar&&(this._playerSync=this.gameObject.getOrAddComponent(Sl),this._playerSync.autoSync=!1),this._playerSync&&typeof this.defaultAvatar!="boolean"&&(this._playerSync.asset=this.defaultAvatar,(s=this._playerSync.onPlayerSpawned)==null||s.removeEventListener(this.onAvatarSpawned),(t=this._playerSync.onPlayerSpawned)==null||t.addEventListener(this.onAvatarSpawned))}onDisable(){var s;(s=this._usdzExporter)==null||s.destroy(),this.removeButtons()}async handleOfferSession(){return this.createVRButton&&await J.isVRSupported()&&this.createVRButton?J.offerSession("immersive-vr","default",this.context):this.createARButton&&await J.isARSupported()&&this.createARButton?J.offerSession("immersive-ar","default",this.context):!1}get session(){return J.active??null}get sessionMode(){return J.activeMode??null}async enterVR(s){return J.start("immersive-vr",s,this.context)}async enterAR(s){return J.start("immersive-ar",s,this.context)}exitXR(){J.stop()}get isActiveWebXR(){return!Ol.activeWebXRComponent||Ol.activeWebXRComponent===this}onBeforeXR(s,t){var i;if(!this.isActiveWebXR){console.warn(`WebXR: another WebXR component is already active (${(i=Ol.activeWebXRComponent)==null?void 0:i.name}). This is ignored: ${this.name}`);return}Ol.activeWebXRComponent=this,s=="immersive-ar"&&this.useDepthSensing&&(t.optionalFeatures=t.optionalFeatures||[],t.optionalFeatures.push("depth-sensing"))}async onEnterXR(s){if(!this.isActiveWebXR)return;xh&&console.log("WebXR onEnterXR"),this._previousXRState=Kt.Global.Mask;const t=s.xr.isVR;if(Kt.Global.Set(t?Zs.VR:Zs.AR),s.xr.isAR){let i=P.findObjectOfType(Hn);if(!i)if(this.usePlacementReticle){const n=new I;for(const o of this.context.scene.children)n.add(o);this.context.scene.add(n),i=P.addComponent(n,Hn),this._createdComponentsInSession.push(i)}else(xh||F())&&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=P.findObjectOfType(Qa)??void 0,this._spatialGrabRaycaster||(this._spatialGrabRaycaster=this.gameObject.addComponent(Qa))),this.createLocalAvatar(s.xr),s.xr.isScreenBasedAR||(this._exitXRMenuButton=this.context.menu.appendChild({label:"Quit XR",onClick:()=>this.exitXR(),icon:"exit_to_app",priority:2e4}))}onUpdateXR(s){this.isActiveWebXR&&this._spatialGrabRaycaster&&(this._spatialGrabRaycaster.enabled=this.useSpatialGrab)}onLeaveXR(s){var t,i;if((t=this._exitXRMenuButton)==null||t.remove(),!!this.isActiveWebXR){Kt.Global.Set(this._previousXRState),(i=this._playerSync)==null||i.destroyInstance();for(const n of this._createdComponentsInSession)n.destroy();this._createdComponentsInSession.length=0,this.handleOfferSession(),ec(1).then(()=>Ol.activeWebXRComponent=null)}}setDefaultMovementEnabled(s){let t=this.gameObject.getComponent(Li);return!t&&s&&(t=this.gameObject.addComponent(Li),this._createdComponentsInSession.push(t)),t&&(t.enabled=s),t}setDefaultControllerRenderingEnabled(s){let t=this.gameObject.getComponent(ln);return!t&&s&&(t=this.gameObject.addComponent(ln),this._createdComponentsInSession.push(t),t.createControllerModel=this.showControllerModels,t.createHandModel==this.showHandModels),t&&(t.enabled=s),t}async createLocalAvatar(s){this._playerSync&&s.running&&typeof this.defaultAvatar!="boolean"&&(this._playerSync.asset=this.defaultAvatar,await this._playerSync.getInstance())}getButtonsContainer(){return this.getButtonsFactory()}getButtonsFactory(){return this._buttonFactory||(this._buttonFactory=Kr.getOrCreate()),this._buttonFactory}handleCreatingHTML(){if(this.createARButton||this.createVRButton||this.useQuicklookExport){if((X.isiOS()&&X.isSafari()||iE)&&this.useQuicklookExport){const s=P.findObjectOfType(Ge);if(!s||s&&s.allowCreateQuicklookButton){const t=this.getButtonsFactory().createQuicklookButton();this.addButton(t,50)}}if(this.createARButton){const s=this.getButtonsFactory().createARButton();this.addButton(s,50)}if(this.createVRButton){const s=this.getButtonsFactory().createVRButton();this.addButton(s,50)}}if(this.createSendToQuestButton&&!X.isQuest()&&J.isVRSupported().then(s=>{if(!s){const t=this.getButtonsFactory().createSendToQuestButton();this.addButton(t,50)}}),this.createQRCode){const s=Zd(an);if(s&&s.createQRCodeButton===!1)F()&&console.warn("WebXR: QRCode button is disabled in the Needle Menu component");else if(!X.isMobileDevice()){const t=Tn.getOrCreate().createQRCode();this.addButton(t,50)}}}addButton(s,t){this._buttons.push(s),s.setAttribute("priority",t.toString()),this.context.menu.appendChild(s)}removeButtons(){for(const s of this._buttons)s.remove();this._buttons.length=0}},a(A0,"activeWebXRComponent",null),A0);let tt=Ol;Ct([m()],tt.prototype,"createVRButton",2),Ct([m()],tt.prototype,"createARButton",2),Ct([m()],tt.prototype,"createSendToQuestButton",2),Ct([m()],tt.prototype,"createQRCode",2),Ct([m()],tt.prototype,"useDefaultControls",2),Ct([m()],tt.prototype,"showControllerModels",2),Ct([m()],tt.prototype,"showHandModels",2),Ct([m()],tt.prototype,"usePlacementReticle",2),Ct([m(ae)],tt.prototype,"customARPlacementReticle",2),Ct([m()],tt.prototype,"usePlacementAdjustment",2),Ct([m()],tt.prototype,"arScale",2),Ct([m()],tt.prototype,"useXRAnchor",2),Ct([m()],tt.prototype,"autoPlace",2),Ct([m()],tt.prototype,"autoCenter",2),Ct([m()],tt.prototype,"useQuicklookExport",2),Ct([m()],tt.prototype,"useDepthSensing",2),Ct([m()],tt.prototype,"useSpatialGrab",2),Ct([m(ae)],tt.prototype,"defaultAvatar",2);const Sh=O("debugusdz");function sE(s,t){var i;const n=[],o=P.getComponentsInChildren(s,Mt),r=P.getComponentsInChildren(s,Wt),l=new Array,c=new Array;if(t.injectImplicitBehaviours)for(const h of o){if(!h||!h.runtimeAnimatorController||!h.enabled)continue;const d=h.runtimeAnimatorController.activeState;if(!d||!d.motion||!d.motion.clip||((i=d.motion.clip.tracks)==null?void 0:i.length)<1||l.includes(h))continue;const u=new Xr;u.animator=h,u.stateName=d.name,u.trigger="start",u.name="PlayAnimationOnClick_implicitAtStart_"+u.stateName;const p=new I;P.addComponent(p,u),c.push(p),l.push(h),s.add(p)}else for(const h of o){if(!h||!h.runtimeAnimatorController||!h.enabled)continue;Sh&&console.log(h);const d=[];for(const u of h.runtimeAnimatorController.enumerateActions()){Sh&&console.log(u);const p=u.getClip();d.includes(p)||d.push(p)}n.push({root:h.gameObject,clips:d})}if(t.injectImplicitBehaviours)for(const h of r){if(!h||!h.clip||!h.enabled||!h.playAutomatically||l.includes(h))continue;const d=new Xr;d.animation=h,d.stateName=h.clip.name,d.trigger="start",d.name="PlayAnimationOnClick_implicitAtStart_"+d.stateName;const u=new I;P.addComponent(u,d),c.push(u),l.push(h),s.add(u)}else for(const h of r){Sh&&console.log(h);const d=[];for(const u of h.animations)d.includes(u)||d.push(u);n.push({root:h.gameObject,clips:d})}Sh&&n?.length>0&&console.log("USDZ Animation Clips without behaviours",n);for(const h of n)for(const d of h.clips)t.registerAnimation(h.root,d);return c}function nE(s,t){const i=P.getComponentsInChildren(s,We),n=P.getComponentsInChildren(s,Lo),o=new Array,r=new Array;Sh&&console.log({audioSources:i,playAudioOnClicks:n});for(const l of n){if(!l.target)continue;const c=i.indexOf(l.target);c>-1&&i.splice(c,1)}for(const l of i){if(!l||!l.clip||l.volume<=0||o.includes(l))continue;const c=new Lo;c.target=l,c.name="PlayAudioOnClick_implicitAtStart_",c.trigger="start";const h=new I;P.addComponent(h,c),console.log("implicit PlayAudioOnStart",h,c),r.push(h),o.push(l),s.add(h)}return r}function oE(s){return new Et("DisableAtStart",xt.sceneStartTrigger(),ye.fadeAction(s,0,!1))}function t1(s,t){const i=s.domElement.shadowRoot.querySelector("link[rel='ar']");if(i)return i;const n=document.createElement("div");n.classList.add("menu"),n.classList.add("quicklook-menu"),n.style.display="none",n.style.visibility="hidden";const o=document.createElement("button");o.id="open-in-ar",t?(o.innerText="View in AR",o.title="View this scene in AR. The scene will be exported to USDZ and opened with Apple's QuickLook."):(o.innerText="View in AR",o.title="Download this scene for AR. Open the downloaded USDZ file to view it in AR using Apple's QuickLook."),n.appendChild(o);const r=document.createElement("a");r.id="needle-usdz-link",r.style.display="none",r.rel="ar",r.href="",r.target="_blank",n.appendChild(r);const l=document.createElement("img");return l.id="button",r.appendChild(l),s.domElement.shadowRoot.appendChild(n),r}var rE=Object.defineProperty,aE=Object.getOwnPropertyDescriptor,jt=(s,t,i,n)=>{for(var o=n>1?void 0:n?aE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&rE(t,i,o),o};const Bi=O("debugusdz"),lE=O("debugusdzpruning");class qo{constructor(){a(this,"callToAction"),a(this,"checkoutTitle"),a(this,"checkoutSubtitle"),a(this,"callToActionURL")}}jt([m()],qo.prototype,"callToAction",2),jt([m()],qo.prototype,"checkoutTitle",2),jt([m()],qo.prototype,"checkoutSubtitle",2),jt([m()],qo.prototype,"callToActionURL",2);var Cp;const I0=(Cp=class extends A{constructor(){super(...arguments),a(this,"objectToExport"),a(this,"autoExportAnimations",!0),a(this,"autoExportAudioSources",!0),a(this,"exportFileName"),a(this,"customUsdzFile"),a(this,"customBranding"),a(this,"anchoringType","plane"),a(this,"maxTextureSize",2048),a(this,"planeAnchoringAlignment","horizontal"),a(this,"interactive",!0),a(this,"physics",!0),a(this,"allowCreateQuicklookButton",!0),a(this,"quickLookCompatible",!0),a(this,"extensions",[]),a(this,"link"),a(this,"button"),a(this,"onClickedOpenInARElement",s=>{s.preventDefault(),this.exportAndOpen()}),a(this,"_currentExportTasks",new Map),a(this,"_previousTimeScale",1),a(this,"lastCallback"),a(this,"_rootSessionRootWasAppliedTo",null),a(this,"_rootPositionBeforeExport",new x),a(this,"_rootRotationBeforeExport",new V),a(this,"_rootScaleBeforeExport",new x)}start(){var s,t,i;Bi&&(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),!((t=(s=this.objectToExport)==null?void 0:s.children)!=null&&t.length)&&!((i=this.objectToExport)!=null&&i.isMesh)&&(this.objectToExport=this.context.scene)}onEnable(){var s;const t=X.supportsQuickLookAR(),i=X.isiOS()||X.isiPad();!this.button&&(Bi||t||i)&&(this.allowCreateQuicklookButton&&(this.button=this.createQuicklookButton()),this.lastCallback=this.quicklookCallback.bind(this),this.link=t1(this.context,t),this.link.addEventListener("message",this.lastCallback)),Bi&&Le("USDZ Exporter enabled: "+this.name),(s=document.getElementById("open-in-ar"))==null||s.addEventListener("click",this.onClickedOpenInARElement),fc.registerExporter(this)}onDisable(){var s,t,i;(s=this.button)==null||s.remove(),(t=this.link)==null||t.removeEventListener("message",this.lastCallback),Bi&&Le("USDZ Exporter disabled: "+this.name),(i=document.getElementById("open-in-ar"))==null||i.removeEventListener("click",this.onClickedOpenInARElement),fc.unregisterExporter(this)}async exportAsync(){return this.exportAndOpen()}async exportAndOpen(){var s;let t=this.exportFileName??((s=this.objectToExport)==null?void 0:s.name)??this.name;if(t+="-"+yx(),bo()||(t!==""&&(t+="-"),t+="MadeWithNeedle"),this.link||(this.link=t1(this.context,X.supportsQuickLookAR())),this.customUsdzFile)return Bi&&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 i=await this.export(this.objectToExport);return i?(Bi&&console.log("USDZ generation done. Downloading as "+t),this.openInQuickLook(i,t),i):(console.error("USDZ generation failed. Please report a bug",this),null)}async export(s){if(!s)return console.warn("No object to export"),null;const t=this._currentExportTasks.get(s);if(t)return t;const i=this.internalExport(s);return i instanceof Promise?(this._currentExportTasks.set(s,i),i.then(n=>(this._currentExportTasks.delete(s),n)).catch(n=>(this._currentExportTasks.delete(s),console.error("Error during USDZ export \u2013 please report a bug!",n),null))):i}async internalExport(s){ce.start("export-usdz",{onProgress:C=>{this.dispatchEvent(new CustomEvent("export-progress",{detail:{progress:C}}))}}),ce.report("export-usdz",{message:"Starting export",totalSteps:40,currentStep:0}),ce.report("export-usdz",{message:"Load progressive textures",autoStep:5}),ce.start("export-usdz-textures","export-usdz");const t=P.getComponentsInChildren(s,fi);for(const C of t)C&&C.enabled&&C.updateSprite(!0);const i=P.getComponentsInChildren(s,et),n=new Array;let o=0;for(const C of i){for(const R of C.sharedMeshes)if(R){const M=it.assignMeshLOD(R,0);M instanceof Promise&&n.push(new Promise((T,j)=>{M.then(()=>{o++,ce.report("export-usdz-textures",{message:"Loaded progressive mesh",currentStep:o,totalSteps:n.length}),T()}).catch(L=>j(L))}))}for(const R of C.sharedMaterials)if(R){const M=it.assignTextureLOD(R,0);M instanceof Promise&&n.push(new Promise((T,j)=>{M.then(()=>{o++,ce.report("export-usdz-textures",{message:"Loaded progressive texture",currentStep:o,totalSteps:n.length}),T()}).catch(L=>j(L))}))}}Bi&&Le("Progressive Loading: "+n.length),await Promise.all(n),Bi&&Le("Progressive Loading: done"),ce.end("export-usdz-textures");const r=Kt.Global.Mask;Kt.Global.Set(Zs.AR);const l=new xx,c=new ch(this.quickLookCompatible);let h;const d=[];this.interactive&&(d.push(new up),d.push(new dr),globalThis.true&&P.getComponentsInChildren(s,ve).length>0&&(this.physics?(h=new mp,d.push(h)):F()&&console.warn("USDZExporter: Physics export is disabled, but there are active Rigidbody components in the scene. They will not be exported.")),d.push(new yh),d.push(new vp));const u=[c,...d,...this.extensions],p={self:this,exporter:l,extensions:u,object:s};ce.report("export-usdz","Invoking before-export"),this.dispatchEvent(new CustomEvent("before-export",{detail:p})),this.applyWebARSessionRoot(),this._previousTimeScale=this.context.time.timeScale,this.context.time.timeScale=0,ce.report("export-usdz","auto export animations and audio sources");const g=new Array;this.autoExportAnimations&&g.push(...sE(s,c)),u.find(C=>C.extensionName==="Audio")&&this.autoExportAudioSources&&g.push(...nE(s)),l.debug=Bi,l.pruneUnusedNodes=!lE;const y=Hr.instance.objs.map(C=>C.batchedMesh);l.keepObject=C=>{let R=!0;const M=P.getComponent(C,et);return M&&!M.enabled&&(R=!1),R&&y.includes(C)&&(R=!1),R&&P.getComponentInParent(C,ks)&&(R=!1),R&&P.getComponentInParent(C,Hs)&&(R=!1),Bi&&!R&&console.log("USDZExporter: Discarding object",C),R},l.beforeWritingDocument=()=>{if(F()&&c&&h){const C=c.animatedRoots;for(const R of C){const M=P.getComponentsInChildren(R,ve).filter(j=>j.enabled),T=P.getComponents(R,pi).filter(j=>j.enabled&&!j.isTrigger);(M.length>0||T.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 f=new Array;this.objectToExport&&this.quickLookCompatible&&this.interactive&&this.objectToExport.traverse(C=>{C.visible||f.push(C)});const v=u.find(C=>C.extensionName==="Behaviour");this.interactive&&v&&f.length>0&&v.addBehavior(oE(f));let b=!0;this.quickLookCompatible&&!this.interactive&&(b=!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"),ce.report("export-usdz","Invoking exporter.parse");const w=await l.parse(this.objectToExport,{ar:{anchoring:{type:this.anchoringType},planeAnchoring:{alignment:this.planeAnchoringAlignment}},extensions:u,quickLookCompatible:this.quickLookCompatible,maxTextureSize:this.maxTextureSize,exportInvisible:b}),_=new Blob([w],{type:"model/vnd.usdz+zip"});this.revertWebARSessionRoot(),this.context.time.timeScale=this._previousTimeScale,ce.report("export-usdz","Invoking after-export"),this.dispatchEvent(new CustomEvent("after-export",{detail:p}));for(const C of g)P.destroy(C);return Kt.Global.Set(r),ce.end("export-usdz"),_}openInQuickLook(s,t){const i=s instanceof Blob?URL.createObjectURL(s):s,n=this.buildQuicklookOverlay();Bi&&console.log("QuickLook Overlay",n);const o=n.callToAction?encodeURIComponent(n.callToAction):"",r=n.checkoutTitle?encodeURIComponent(n.checkoutTitle):"",l=n.checkoutSubtitle?encodeURIComponent(n.checkoutSubtitle):"";this.link.href=i+`#callToAction=${o}&checkoutTitle=${r}&checkoutSubtitle=${l}&callToActionURL=${n.callToActionURL}`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=t+".usdz",this.link.click()}download(s,t){I0.save(s,t)}static save(s,t){const i=document.createElement("a");i.style.display="none",document.body.appendChild(i),typeof s=="string"?i.href=s:i.href=URL.createObjectURL(s),i.download=t,i.click(),i.remove()}quicklookCallback(s){if(s?.data=="_apple_ar_quicklook_button_tapped"){Bi&&xe("Quicklook closed via call to action button");var t=new CustomEvent("quicklook-button-tapped",{detail:this});if(this.dispatchEvent(t),!t.defaultPrevented){const i=new URLSearchParams(this.link.href);if(i){const n=i.get("callToActionURL");Bi&&Le("Quicklook url: "+n),n&&(bo()?globalThis.open(n,"_blank"):console.warn("Quicklook closed: custom redirects require a Needle Engine Pro license: https://needle.tools/pricing",n))}}}}buildQuicklookOverlay(){var s,t,i,n,o,r;const l={};return this.customBranding&&Object.assign(l,this.customBranding),bo()||(console.log("Custom Quicklook banner text requires pro license: https://needle.tools/pricing"),l.callToAction="Close",l.checkoutTitle="\u{1F335} Made with Needle",l.checkoutSubtitle="_"),(((s=l.callToAction)==null?void 0:s.length)||((t=l.checkoutTitle)==null?void 0:t.length)||((i=l.checkoutSubtitle)==null?void 0:i.length))&&((n=l.callToAction)!=null&&n.length||(l.callToAction="\0"),(o=l.checkoutTitle)!=null&&o.length||(l.checkoutTitle="\0"),(r=l.checkoutSubtitle)!=null&&r.length||(l.checkoutSubtitle="\0")),this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:l})),l}getARScaleAndTarget(){if(!this.objectToExport)return{scale:1,_invertForward:!1,target:this.gameObject,sessionRoot:null};const s=P.findObjectOfType(tt);let t=P.getComponentInParent(this.objectToExport,Hn);t||(t=P.getComponentInChildren(this.objectToExport,Hn));let i=1,n=!1;const o=this.objectToExport;return s?i=s.arScale:t&&(i=t.arScale,n=t.invertForward),{scale:1/i,_invertForward:n,target:o,sessionRoot:t?.gameObject??null}}applyWebARSessionRoot(){if(!this.objectToExport)return;const{scale:s,_invertForward:t,target:i,sessionRoot:n}=this.getARScaleAndTarget(),o=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(s),t&&i.quaternion.multiply(I0.invertForwardQuaternion),i.updateMatrix(),i.updateMatrixWorld(!0),n&&o&&i.matrix.premultiply(o)}revertWebARSessionRoot(){if(!this.objectToExport||!this._rootSessionRootWasAppliedTo)return;const s=this._rootSessionRootWasAppliedTo;s.position.copy(this._rootPositionBeforeExport),s.quaternion.copy(this._rootRotationBeforeExport),s.scale.copy(this._rootScaleBeforeExport),s.updateMatrix(),s.updateMatrixWorld(!0),this._rootSessionRootWasAppliedTo=null}createQuicklookButton(){const s=Kr.getOrCreate().createQuicklookButton();return s.parentNode||this.context.menu.appendChild(s),s}},a(Cp,"invertForwardMatrix",new ne().makeRotationY(Math.PI)),a(Cp,"invertForwardQuaternion",new V().setFromEuler(new Ut(0,Math.PI,0))),Cp);let Ge=I0;jt([m(I)],Ge.prototype,"objectToExport",2),jt([m()],Ge.prototype,"autoExportAnimations",2),jt([m()],Ge.prototype,"autoExportAudioSources",2),jt([m()],Ge.prototype,"exportFileName",2),jt([m(URL)],Ge.prototype,"customUsdzFile",2),jt([m(qo)],Ge.prototype,"customBranding",2),jt([m()],Ge.prototype,"anchoringType",2),jt([m()],Ge.prototype,"maxTextureSize",2),jt([m()],Ge.prototype,"planeAnchoringAlignment",2),jt([m()],Ge.prototype,"interactive",2),jt([m()],Ge.prototype,"physics",2),jt([m()],Ge.prototype,"allowCreateQuicklookButton",2),jt([m()],Ge.prototype,"quickLookCompatible",2);var cE=Object.defineProperty,hE=Object.getOwnPropertyDescriptor,j0=(s,t,i,n)=>{for(var o=n>1?void 0:n?hE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&cE(t,i,o),o};class Pl extends A{constructor(){super(...arguments),a(this,"_fog")}get fog(){return this._fog||(this._fog=new $y(0,0,50)),this._fog}get mode(){return 1}set near(t){this.fog.near=t}get near(){return this.fog.near}set far(t){this.fog.far=t}get far(){return this.fog.far}set color(t){this.fog.color.copy(t)}get color(){return this.fog.color}onEnable(){this.scene.fog=this.fog}onDisable(){this.scene.fog===this._fog&&(this.scene.fog=null)}}j0([m()],Pl.prototype,"near",1),j0([m()],Pl.prototype,"far",1),j0([m(re)],Pl.prototype,"color",1);var dE=Object.defineProperty,uE=Object.getOwnPropertyDescriptor,D0=(s,t,i,n)=>{for(var o=n>1?void 0:n?uE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&dE(t,i,o),o};class Zr extends A{constructor(){super(...arguments),a(this,"objectBounds",!1),a(this,"color"),a(this,"isGizmo",!0),a(this,"_gizmoObject",null),a(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!Cc||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new cC(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=_g(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),Me.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){for(var t;this._boxHelper;)(t=this._boxHelper)==null||t.update(),yield}}D0([m()],Zr.prototype,"objectBounds",2),D0([m(re)],Zr.prototype,"color",2),D0([m()],Zr.prototype,"isGizmo",2);var pE=Object.defineProperty,mE=Object.getOwnPropertyDescriptor,L0=(s,t,i,n)=>{for(var o=n>1?void 0:n?mE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&pE(t,i,o),o};class kl extends A{constructor(){super(...arguments),a(this,"isGizmo",!1),a(this,"color0"),a(this,"color1"),a(this,"gridHelper"),a(this,"size"),a(this,"divisions"),a(this,"offset")}onEnable(){if(this.isGizmo&&!Cc)return;const t=this.size,i=this.divisions;this.gridHelper||(this.gridHelper=new cm(t,i,this.color0??new re(.4,.4,.4),this.color1??new re(.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)}}L0([m()],kl.prototype,"isGizmo",2),L0([m(re)],kl.prototype,"color0",2),L0([m(re)],kl.prototype,"color1",2);var gE=Object.defineProperty,fE=Object.getOwnPropertyDescriptor,B0=(s,t,i,n)=>{for(var o=n>1?void 0:n?fE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&gE(t,i,o),o};class F0 extends A{constructor(){super(...arguments),a(this,"connectedBody"),a(this,"_rigidBody",null)}get rigidBody(){return this._rigidBody}onEnable(){this._rigidBody||(this._rigidBody=this.gameObject.getComponent(ve)),this.rigidBody&&this.connectedBody&&this.startCoroutine(this.create())}*create(){yield,this.rigidBody&&this.connectedBody&&this.activeAndEnabled&&this.createJoint(this.rigidBody,this.connectedBody)}}B0([m(ve)],F0.prototype,"connectedBody",2);class z0 extends F0{createJoint(t,i){var n;(n=this.context.physics.engine)==null||n.addFixedJoint(t,i)}}class Ch extends F0{constructor(){super(...arguments),a(this,"anchor"),a(this,"axis")}createJoint(t,i){var n;this.axis&&this.anchor&&((n=this.context.physics.engine)==null||n.addHingeJoint(t,i,this.anchor,this.axis))}}B0([m(x)],Ch.prototype,"anchor",2),B0([m(x)],Ch.prototype,"axis",2);var yE=Object.defineProperty,vE=Object.getOwnPropertyDescriptor,cn=(s,t,i,n)=>{for(var o=n>1?void 0:n?vE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&yE(t,i,o),o};function U0(s){return s*Math.PI/180}const i1=300,Go=O("debuglights");class yi extends A{constructor(){super(...arguments),a(this,"type",0),a(this,"range",1),a(this,"spotAngle",1),a(this,"innerSpotAngle",1),a(this,"_color",new re(16777215)),a(this,"_shadowNearPlane",.1),a(this,"_shadowBias",0),a(this,"_shadowNormalBias",0),a(this,"_overrideShadowBiasSettings",!1),a(this,"_shadows",1),a(this,"lightmapBakeType",4),a(this,"_intensity",-1),a(this,"_shadowDistance"),a(this,"shadowWidth"),a(this,"shadowHeight"),a(this,"_shadowResolution"),a(this,"light"),a(this,"_webXRStartedListener"),a(this,"_webXREndedListener"),a(this,"_webARRoot")}set color(t){this._color=t,this.light!==void 0&&(this.light.color=t)}get color(){return this.light?this.light.color:this._color}set shadowNearPlane(t){var i,n;if(t!==this._shadowNearPlane&&(this._shadowNearPlane=t,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.camera)!==void 0)){const o=this.light.shadow.camera;o.near=t}}get shadowNearPlane(){return this._shadowNearPlane}set shadowBias(t){var i,n;t!==this._shadowBias&&(this._shadowBias=t,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.bias)!==void 0&&(this.light.shadow.bias=t,this.light.shadow.needsUpdate=!0))}get shadowBias(){return this._shadowBias}set shadowNormalBias(t){var i,n;t!==this._shadowNormalBias&&(this._shadowNormalBias=t,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.normalBias)!==void 0&&(this.light.shadow.normalBias=t,this.light.shadow.needsUpdate=!0))}get shadowNormalBias(){return this._shadowNormalBias}set shadows(t){this._shadows=t,this.light&&(this.light.castShadow=t!==0,this.updateShadowSoftHard())}get shadows(){return this._shadows}set intensity(t){var i;if(this._intensity=t,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=t*n}Go&&console.log("Set light intensity to "+this._intensity,t,this)}get intensity(){return this._intensity}get shadowDistance(){const t=this.light;return t!=null&&t.shadow?t.shadow.camera.far:-1}set shadowDistance(t){this._shadowDistance=t;const i=this.light;if(i!=null&&i.shadow){const n=i.shadow.camera;n.far=t,n.updateProjectionMatrix()}}get shadowResolution(){const t=this.light;return t!=null&&t.shadow?t.shadow.mapSize.x:-1}set shadowResolution(t){if(t===this._shadowResolution)return;this._shadowResolution=t;const i=this.light;i!=null&&i.shadow&&(i.shadow.mapSize.set(t,t),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(t){return this.light?this.type===1?this.light.getWorldPosition(t).multiplyScalar(1):this.light.getWorldPosition(t):t}awake(){this.color=new re(this.color??16777215),Go&&console.log(this.name,this)}onEnable(){Go&&console.log("ENABLE LIGHT",this.name),this.createLight(),!this.isBaked&&(this.light&&(this.light.visible=!0,this.light.intensity=this._intensity,Go&&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(),Me.LateUpdate))}onDisable(){Go&&console.log("DISABLE LIGHT",this.name),this.light&&(this.selfIsLight?this.light.intensity=0:this.light.visible=!1)}onEnterXR(t){this._webARRoot=P.getComponentInParent(this.gameObject,Hn)??void 0}onLeaveXR(t){}createLight(){const t=this.selfIsLight;if(t&&!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 hm(this.color,this.intensity*Math.PI);if(i.position.set(0,0,-i1*.5).applyQuaternion(this.gameObject.quaternion),this.gameObject.add(i.target),yr(i.target,0,0,0),this.light=i,this.gameObject.position.set(0,0,0),this.gameObject.rotation.set(0,0,0),Go){const l=new dC(this.light,.2,this.color);this.context.scene.add(l)}break;case 0:const n=new hC(this.color,this.intensity*Math.PI,this.range,U0(this.spotAngle/2),1-U0(this.innerSpotAngle/2)/U0(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 r=new qy(this.color,this.intensity*Math.PI,this.range);this.light=r;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),Go&&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=i1*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,Go&&this.context.scene.add(new uC(i))}this.isBaked?this.light.removeFromParent():t||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(t){t.add(t.target),t.target.position.set(0,0,-1)}}a(yi,"allowChangingRendererShadowMapType",!0),cn([m()],yi.prototype,"type",2),cn([m(re)],yi.prototype,"color",1),cn([m()],yi.prototype,"shadowNearPlane",1),cn([m()],yi.prototype,"shadowBias",1),cn([m()],yi.prototype,"shadowNormalBias",1),cn([m()],yi.prototype,"shadows",1),cn([m()],yi.prototype,"lightmapBakeType",2),cn([m()],yi.prototype,"intensity",1),cn([m()],yi.prototype,"shadowDistance",1),cn([m()],yi.prototype,"shadowResolution",1),new x(0,0,0);var bE=Object.defineProperty,_E=Object.getOwnPropertyDescriptor,Oh=(s,t,i,n)=>{for(var o=n>1?void 0:n?_E(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&bE(t,i,o),o};const N0=O("debuglods"),wE=O("nolods");class Jr{constructor(){a(this,"screenRelativeTransitionHeight"),a(this,"distance"),a(this,"renderers")}}Oh([m()],Jr.prototype,"screenRelativeTransitionHeight",2),Oh([m()],Jr.prototype,"distance",2),Oh([m(et)],Jr.prototype,"renderers",2);class xE{constructor(t){a(this,"model"),this.model=t}get renderers(){return this.model.renderers}}class Ph extends A{constructor(){super(...arguments),a(this,"fadeMode",0),a(this,"localReferencePoint"),a(this,"lodCount",0),a(this,"size",0),a(this,"animateCrossFading",!1),a(this,"lodModels"),a(this,"_lods",[]),a(this,"_settings",[]),a(this,"_lodsHandler"),a(this,"_distanceFactor",1)}start(){if(N0&&console.log("LODGROUP",this.name,this.lodModels,this),!wE&&!this._lodsHandler&&this.gameObject&&this.lodModels&&Array.isArray(this.lodModels)){const t=[];for(const n of this.lodModels){const o=new xE(n);this._lods.push(o);for(const r of o.renderers)t.includes(r)||t.push(r)}this._lodsHandler=new Array;for(let n=0;n<t.length;n++){const o=new pC;this._lodsHandler.push(o),this.gameObject.add(o)}const i=new I;i.name="Cull "+this.name;for(let n=0;n<t.length;n++){const o=t[n],r=this._lodsHandler[n],l=o.gameObject;N0&&console.log(n,l.name);for(const c of this._lods){const h=c.model.distance;let d=null;if(c.renderers.includes(o)?d=l:d=i,d.type==="Group"){console.warn(`LODGroup ${this.name}: Group or MultiMaterial object's are not supported as LOD object: ${d.name}`);continue}N0&&console.log("LEVEL",d.name,h),r.autoUpdate=!1,this.onAddLodLevel(r,d,c.model.distance)}}}}onAfterRender(){if(!this.gameObject||!this._lodsHandler)return;const t=this.context.mainCamera;if(t)for(const i of this._lodsHandler){i.update(t);const n=i.getCurrentLevel(),o=i.levels[n];i.layers.mask=o.object.layers.mask}}onAddLodLevel(t,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}t.addLevel(i,n*this._distanceFactor,.01);const o={lod:t,levelIndex:t.levels.length-1,distance:n};this._settings.push(o)}distanceFactor(t){if(t!==this._distanceFactor){this._distanceFactor=t;for(const i of this._settings){const n=i.lod.levels[i.levelIndex];n.distance=i.distance*t}}}}Oh([m(x)],Ph.prototype,"localReferencePoint",2),Oh([m(Jr)],Ph.prototype,"lodModels",2);var SE=Object.defineProperty,CE=Object.getOwnPropertyDescriptor,OE=(s,t,i,n)=>{for(var o=n>1?void 0:n?CE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&SE(t,i,o),o};const Op=O("debugnestedgltf");class Pp extends A{constructor(){super(...arguments),a(this,"filePath"),a(this,"loadAssetInParent",!0),a(this,"_isLoadingOrDoneLoading",!1)}listenToProgress(t){var i;(i=this.filePath)==null||i.beginListenDownload(t)}preload(){var t;(t=this.filePath)==null||t.preload()}async start(){var t,i,n,o,r;if(this._isLoadingOrDoneLoading)return;Op&&console.log(this,this.guid);const l=this.gameObject.parent;if(l){this._isLoadingOrDoneLoading=!0;const c=new Ls;c.idProvider=new zt(this.hash(this.guid)),c.parent=this.loadAssetInParent!==!1?l:this.gameObject,this.gameObject.updateMatrix();const h=this.gameObject.matrix;Op&&console.log("Load nested:",((t=this.filePath)==null?void 0:t.url)??this.filePath,this.gameObject.position);const d=await((n=(i=this.filePath)==null?void 0:i.instantiate)==null?void 0:n.call(this.filePath,c));Op&&console.log("Nested loaded:",((o=this.filePath)==null?void 0:o.url)??this.filePath,d),d&&this.loadAssetInParent!==!1&&(d.matrixAutoUpdate=!1,d.matrix.identity(),d.applyMatrix4(h),d.matrixAutoUpdate=!0,d.layers.disableAll(),d.layers.set(this.layer),this.dispatchEvent(new CustomEvent("loaded",{detail:{instance:d,assetReference:this.filePath}}))),Op&&console.log("Nested loading done:",((r=this.filePath)==null?void 0:r.url)??this.filePath,d)}}onDestroy(){var t;(t=this.filePath)==null||t.unload()}hash(t){let i=0;for(let n=0;n<t.length;n++)i=t.charCodeAt(n)+((i<<5)-i);return i}}OE([m(ae)],Pp.prototype,"filePath",2);var PE=Object.defineProperty,kE=Object.getOwnPropertyDescriptor,W0=(s,t,i,n)=>{for(var o=n>1?void 0:n?kE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&PE(t,i,o),o};const ME=O("debugnet"),V0=class extends A{constructor(){super(...arguments),a(this,"url",null),a(this,"urlParameterName",null),a(this,"localhost",null)}awake(){ME&&console.log(this),this.context.connection.registerProvider(this)}getWebsocketUrl(){let s=this.url?V0.GetUrl(this.url,this.localhost):null;if(this.urlParameterName){const i=O(this.urlParameterName);i&&typeof i=="string"&&(s=i)}if(!s)return null;const t=new RegExp("(((https?)|(?<socket_prefix>wss?))://)?(www.)?(?<url>.+)","gm").exec(s);return t!=null&&t.groups?t?.groups.socket_prefix?s:"wss://"+t?.groups.url:null}static GetUrl(s,t){let i=s;const n=V0.IsLocalNetwork()&&t;if(n&&(i=t),s!=null&&s.startsWith("/")){const o=n?i:window.location.origin;o!=null&&o.endsWith("/")&&s.startsWith("/")&&(s=s.substring(1)),i=o+s}return i}static IsLocalNetwork(s=window.location.hostname){return Gt(s)}};let Ml=V0;W0([m()],Ml.prototype,"url",2),W0([m()],Ml.prototype,"urlParameterName",2),W0([m()],Ml.prototype,"localhost",2);var RE=Object.defineProperty,TE=Object.getOwnPropertyDescriptor,kp=(s,t,i,n)=>{for(var o=n>1?void 0:n?TE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&RE(t,i,o),o};class ea extends A{constructor(){super(...arguments),a(this,"referenceSpace"),a(this,"from"),a(this,"affectPosition",!1),a(this,"affectRotation",!1),a(this,"alignLookDirection",!1),a(this,"levelLookDirection",!1),a(this,"levelPosition",!1),a(this,"positionOffset",new x(0,0,0)),a(this,"rotationOffset",new x(0,0,0)),a(this,"offset",new x(0,0,0))}update(){if(!this.from)return;var t=te(this.from),i=Oe(this.from);this.offset.copy(this.positionOffset);const n=this.offset.length();if(this.referenceSpace&&this.offset.transformDirection(this.referenceSpace.matrixWorld).multiplyScalar(n),t.add(this.offset),this.levelPosition&&this.referenceSpace){const c=new pr(this.gameObject.up,0),h=te(this.referenceSpace);c.setFromNormalAndCoplanarPoint(this.gameObject.up,h);const d=new x(0,0,0);c.projectPoint(t,d),t.copy(d)}this.affectPosition&&ut(this.gameObject,t);const o=new Ut(this.rotationOffset.x,this.rotationOffset.y,this.rotationOffset.z),r=new V().setFromEuler(o);this.affectRotation&&Gi(this.gameObject,i.multiply(r));const l=new x;this.from.getWorldDirection(l).multiplyScalar(50),this.levelLookDirection&&(l.y=0),this.alignLookDirection&&this.gameObject.lookAt(l)}}kp([m(P)],ea.prototype,"referenceSpace",2),kp([m(P)],ea.prototype,"from",2),kp([m(x)],ea.prototype,"positionOffset",2),kp([m(x)],ea.prototype,"rotationOffset",2);var EE=Object.defineProperty,AE=Object.getOwnPropertyDescriptor,k=(s,t,i,n)=>{for(var o=n>1?void 0:n?AE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&EE(t,i,o),o};const Mp=O("debugparticles");var qn=(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))(qn||{});class Xo{constructor(){a(this,"alphaKeys",[]),a(this,"colorKeys",[])}get duration(){return 1}evaluate(t,i){let n,o=0,r=null,l=0;for(let c=0;c<this.alphaKeys.length;c++){const h=this.alphaKeys[c];(h.time<t||!n)&&(n=h,o=c)}for(let c=0;c<this.colorKeys.length;c++){const h=this.colorKeys[c];(h.time<t||!r)&&(r=h,l=c)}if(r)if(l+1<this.colorKeys.length){const c=this.colorKeys[l+1],h=W.remap(t,r.time,c.time,0,1);i.r=W.lerp(r.color.r,c.color.r,h),i.g=W.lerp(r.color.g,c.color.g,h),i.b=W.lerp(r.color.b,c.color.b,h)}else i.r=r.color.r,i.g=r.color.g,i.b=r.color.b;if(n)if(o+1<this.alphaKeys.length){const c=this.alphaKeys[o+1],h=W.remap(t,n.time,c.time,0,1);i.alpha=W.lerp(n.alpha,c.alpha,h)}else i.alpha=n.alpha;return i}}k([m()],Xo.prototype,"alphaKeys",2),k([m()],Xo.prototype,"colorKeys",2);var kh=(s=>(s[s.Local=0]="Local",s[s.World=1]="World",s[s.Custom=2]="Custom",s))(kh||{}),Rp=(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))(Rp||{});const Mh=class{constructor(){a(this,"mode","Constant"),a(this,"constant"),a(this,"constantMin"),a(this,"constantMax"),a(this,"curve"),a(this,"curveMin"),a(this,"curveMax"),a(this,"curveMultiplier")}static constant(s){const t=new Mh;return t.setConstant(s),t}static betweenTwoConstants(s,t){const i=new Mh;return i.setMinMaxConstant(s,t),i}static curve(s,t=1){const i=new Mh;return i.setCurve(s,t),i}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 s,t,i;const n=new Mh;return n.mode=this.mode,n.constant=this.constant,n.constantMin=this.constantMin,n.constantMax=this.constantMax,n.curve=(s=this.curve)==null?void 0:s.clone(),n.curveMin=(t=this.curveMin)==null?void 0:t.clone(),n.curveMax=(i=this.curveMax)==null?void 0:i.clone(),n.curveMultiplier=this.curveMultiplier,n}evaluate(s,t){const i=t===void 0?Math.random():t;switch(this.mode){case 0:case"Constant":return this.constant;case 1:case"Curve":return s=W.clamp01(s),this.curve.evaluate(s)*this.curveMultiplier;case 2:case"TwoCurves":const n=s*this.curveMin.duration,o=s*this.curveMax.duration;return W.lerp(this.curveMin.evaluate(n),this.curveMax.evaluate(o),i%1)*this.curveMultiplier;case 3:case"TwoConstants":return W.lerp(this.constantMin,this.constantMax,i%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 i=0;i<s.keys.length;i++){const n=s.keys[i];n.value>t&&(t=n.value)}return t}};let Q=Mh;k([m()],Q.prototype,"mode",2),k([m()],Q.prototype,"constant",2),k([m()],Q.prototype,"constantMin",2),k([m()],Q.prototype,"constantMax",2),k([m(Lr)],Q.prototype,"curve",2),k([m(Lr)],Q.prototype,"curveMin",2),k([m(Lr)],Q.prototype,"curveMax",2),k([m()],Q.prototype,"curveMultiplier",2);var Tp;const Dt=(Tp=class{constructor(){a(this,"mode",0),a(this,"color"),a(this,"colorMin"),a(this,"colorMax"),a(this,"gradient"),a(this,"gradientMin"),a(this,"gradientMax")}static constant(s){const t=new Dt;return t.constant(s),t}static betweenTwoColors(s,t){const i=new Dt;return i.betweenTwoColors(s,t),i}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 i=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,Dt._temp),Dt._temp;case 2:case"TwoColors":return Dt._temp.lerpColors(this.colorMin,this.colorMax,i);case 3:case"TwoGradients":return this.gradientMin.evaluate(s,Dt._temp),this.gradientMax.evaluate(s,Dt._temp2),Dt._temp.lerp(Dt._temp2,i);case 4:case"RandomColor":const n=Math.random();return this.gradientMin.evaluate(s,Dt._temp),this.gradientMax.evaluate(s,Dt._temp2),Dt._temp.lerp(Dt._temp2,n)}return Dt._temp.set(16777215),Dt._temp.alpha=1,Dt._temp}},a(Tp,"_temp",new Se(0,0,0,1)),a(Tp,"_temp2",new Se(0,0,0,1)),Tp);let si=Dt;k([m()],si.prototype,"mode",2),k([m(Se)],si.prototype,"color",2),k([m(Se)],si.prototype,"colorMin",2),k([m(Se)],si.prototype,"colorMax",2),k([m(Xo)],si.prototype,"gradient",2),k([m(Xo)],si.prototype,"gradientMin",2),k([m(Xo)],si.prototype,"gradientMax",2);var H0=(s=>(s[s.Hierarchy=0]="Hierarchy",s[s.Local=1]="Local",s[s.Shape=2]="Shape",s))(H0||{});class Lt{constructor(){a(this,"cullingMode"),a(this,"duration"),a(this,"emitterVelocityMode"),a(this,"flipRotation"),a(this,"gravityModifier"),a(this,"gravityModifierMultiplier"),a(this,"loop"),a(this,"maxParticles"),a(this,"playOnAwake"),a(this,"prewarm"),a(this,"ringBufferLoopRange"),a(this,"ringBufferMode"),a(this,"scalingMode"),a(this,"simulationSpace"),a(this,"simulationSpeed"),a(this,"startColor"),a(this,"startDelay"),a(this,"startDelayMultiplier"),a(this,"startLifetime"),a(this,"startLifetimeMultiplier"),a(this,"startRotation"),a(this,"startRotationMultiplier"),a(this,"startRotation3D"),a(this,"startRotationX"),a(this,"startRotationXMultiplier"),a(this,"startRotationY"),a(this,"startRotationYMultiplier"),a(this,"startRotationZ"),a(this,"startRotationZMultiplier"),a(this,"startSize"),a(this,"startSize3D"),a(this,"startSizeMultiplier"),a(this,"startSizeX"),a(this,"startSizeXMultiplier"),a(this,"startSizeY"),a(this,"startSizeYMultiplier"),a(this,"startSizeZ"),a(this,"startSizeZMultiplier"),a(this,"startSpeed"),a(this,"startSpeedMultiplier"),a(this,"stopAction"),a(this,"useUnscaledTime")}}k([m(Q)],Lt.prototype,"gravityModifier",2),k([m(si)],Lt.prototype,"startColor",2),k([m(Q)],Lt.prototype,"startDelay",2),k([m(Q)],Lt.prototype,"startLifetime",2),k([m(Q)],Lt.prototype,"startRotation",2),k([m(Q)],Lt.prototype,"startRotationX",2),k([m(Q)],Lt.prototype,"startRotationY",2),k([m(Q)],Lt.prototype,"startRotationZ",2),k([m(Q)],Lt.prototype,"startSize",2),k([m(Q)],Lt.prototype,"startSizeX",2),k([m(Q)],Lt.prototype,"startSizeY",2),k([m(Q)],Lt.prototype,"startSizeZ",2),k([m(Q)],Lt.prototype,"startSpeed",2);class Rh{constructor(){a(this,"cycleCount"),a(this,"maxCount"),a(this,"minCount"),a(this,"probability"),a(this,"repeatInterval"),a(this,"time"),a(this,"count"),a(this,"_performed",0)}reset(){this._performed=0}run(t){if(t<=this.time)return 0;let i=0;if(this.cycleCount===0||this._performed<this.cycleCount){const n=this.time+this.repeatInterval*this._performed;if(t>=n&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:i=this.count.constant;break;case 3:i=W.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:i=this.count.curve.evaluate(Math.random());break;case 2:const o=Math.random();i=W.lerp(this.count.curveMin.evaluate(o),this.count.curveMax.evaluate(o),Math.random());break}}return i}}class hn{constructor(){a(this,"enabled"),a(this,"bursts"),a(this,"rateOverTime"),a(this,"rateOverTimeMultiplier"),a(this,"rateOverDistance"),a(this,"rateOverDistanceMultiplier"),a(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(i=>i.reset())}getBurst(){let t=0;if(this.burstCount>0)for(let i=0;i<this.burstCount;i++){const n=this.bursts[i];this.system.main.loop&&n.time>=this.system.time&&n.reset(),t+=Math.round(n.run(this.system.time))}return t}}k([m()],hn.prototype,"enabled",2),k([m()],hn.prototype,"bursts",2),k([m(Q)],hn.prototype,"rateOverTime",2),k([m()],hn.prototype,"rateOverTimeMultiplier",2),k([m(Q)],hn.prototype,"rateOverDistance",2),k([m()],hn.prototype,"rateOverDistanceMultiplier",2);class Th{constructor(){a(this,"enabled"),a(this,"color")}}k([m(si)],Th.prototype,"color",2);class Qo{constructor(){a(this,"enabled"),a(this,"separateAxes"),a(this,"size"),a(this,"sizeMultiplier"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier"),a(this,"_time",0),a(this,"_temp",new x)}evaluate(t,i,n){if(i||(i=this._temp),!this.enabled)return i.x=i.y=i.z=1,i;if(this.separateAxes)i.x=this.x.evaluate(t,n)*this.xMultiplier,i.y=this.y.evaluate(t,n)*this.yMultiplier,i.z=this.z.evaluate(t,n)*this.zMultiplier;else{const o=this.size.evaluate(t,n)*this.sizeMultiplier;i.x=o}return i}}k([m(Q)],Qo.prototype,"size",2),k([m(Q)],Qo.prototype,"x",2),k([m(Q)],Qo.prototype,"y",2),k([m(Q)],Qo.prototype,"z",2);var Ep;const Eh=(Ep=class{constructor(){a(this,"shapeType",5),a(this,"enabled",!0),a(this,"alignToDirection",!1),a(this,"angle",0),a(this,"arc",360),a(this,"arcSpread"),a(this,"arcSpeedMultiplier"),a(this,"arcMode"),a(this,"boxThickness"),a(this,"position"),a(this,"rotation"),a(this,"_rotation",new Ut),a(this,"scale"),a(this,"radius"),a(this,"radiusThickness"),a(this,"sphericalDirectionAmount"),a(this,"randomDirectionAmount"),a(this,"randomPositionAmount"),a(this,"meshShapeType"),a(this,"meshRenderer"),a(this,"_meshObj"),a(this,"_meshGeometry"),a(this,"system"),a(this,"_space"),a(this,"_worldSpaceMatrix",new ne),a(this,"_worldSpaceMatrixInverse",new ne),a(this,"_vector",new x(0,0,0)),a(this,"_temp",new x(0,0,0)),a(this,"_triangle",new mC),a(this,"_dir",new x),a(this,"_loopTime",0),a(this,"_loopDirection",1),Mp&&console.log(this)}get type(){return Rp[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 Eh}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,i,n){this.system=s,this._space=i,i===1&&(this._worldSpaceMatrix.copy(n.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=W.toRadians(this.rotation.x),this._rotation.y=W.toRadians(this.rotation.y),this._rotation.z=W.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),i=this._space===1;i&&t.applyQuaternion(this.system.worldQuaternion);let n=this.radius;if(i&&(n*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:Mp&&q.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,n,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,n,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,n,this.radiusThickness,this.arc,this._vector);break;case 13:const o=this.meshRenderer;o?.destroyed==!1&&this.setMesh(o);const r=s.mesh=this._meshObj,l=s.mesh_geometry=this._meshGeometry;if(r&&l)switch(this.meshShapeType){case 0:{const c=l.getAttribute("position"),h=Math.floor(Math.random()*c.count);this._vector.fromBufferAttribute(c,h),this._vector.applyMatrix4(r.matrixWorld),s.mesh_normal=h}break;case 1:break;case 2:{const c=l.index;if(c){let h=Math.random(),d=Math.random();h+d>1&&(h=1-h,d=1-d);const u=Math.floor(Math.random()*(c.count/3));let p=u*3,g=u*3+1,y=u*3+2;p=c.getX(p),g=c.getX(g),y=c.getX(y);const f=l.getAttribute("position");this._triangle.a.fromBufferAttribute(f,p),this._triangle.b.fromBufferAttribute(f,g),this._triangle.c.fromBufferAttribute(f,y),this._vector.set(0,0,0).addScaledVector(this._triangle.a,h).addScaledVector(this._triangle.b,d).addScaledVector(this._triangle.c,1-(h+d)),this._vector.applyMatrix4(r.matrixWorld),s.mesh_normal=u}}break}break;default:this._vector.set(0,0,0),F()&&!globalThis.__particlesystem_shapetype_unsupported&&(console.warn("ParticleSystem ShapeType is not supported:",Rp[this.shapeType]),globalThis.__particlesystem_shapetype_unsupported=!0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),i&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),Mp&&q.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(s,t){var i;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 n=t.x,o=t.y,r=t.z;this._dir.set(n,o,r),(i=this.system)!=null&&i.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;case 13:const l=s.mesh,c=s.mesh_geometry;if(l&&c)switch(this.meshShapeType){case 0:{const h=c.getAttribute("normal"),d=s.mesh_normal;this._dir.fromBufferAttribute(h,d)}break;case 1:break;case 2:{const h=c.index;if(h){const d=s.mesh_normal,u=h.getX(d*3),p=h.getX(d*3+1),g=h.getX(d*3+2),y=c.getAttribute("position"),f=G(),v=G(),b=G();f.fromBufferAttribute(y,u),v.fromBufferAttribute(y,p),b.fromBufferAttribute(y,g),f.sub(v),b.sub(v),f.cross(b),this._dir.copy(f).multiplyScalar(-1);const w=Oe(l);this._dir.applyQuaternion(w)}}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),Mp&&(q.DrawSphere(t,.01,8925952,.5,!0),q.DrawDirection(t,this._dir,8925952,.5,!0)),this._dir}randomizePosition(s,t){if(t<=0)return;const i=Eh._tempVec;i.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),i.x*=t*this.scale.x,i.y*=t*this.scale.y,i.z*=t*this.scale.z,s.add(i)}randomizeDirection(s,t){if(t===0)return;const i=Eh._randomQuat,n=Eh._tempVec;n.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),i.setFromAxisAngle(n,t*Math.random()*Math.PI),s.applyQuaternion(i)}spherizeDirection(s,t){if(t===0)return;const i=Math.random()*Math.PI*2,n=Math.acos(1-Math.random()*2),o=Math.sin(n)*Math.cos(i),r=Math.sin(n)*Math.sin(i),l=Math.cos(n),c=new x(o,r,l);s.lerp(c,t)}randomSpherePoint(s,t,i,n,o){const r=Math.random(),l=Math.random(),c=2*Math.PI*r*(n/360),h=Math.acos(2*l-1),d=W.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*t,u=s.x+this.scale.x*(-d*Math.sin(h)*Math.cos(c)),p=s.y+this.scale.y*(d*Math.sin(h)*Math.sin(c)),g=s.z+this.scale.z*(d*Math.cos(h));o.x=u,o.y=p,o.z=g}randomCirclePoint(s,t,i,n,o){const r=Math.random(),l=2*Math.PI*r*(n/360),c=W.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*t,h=s.x+this.scale.x*c*Math.cos(l),d=s.y+this.scale.y*c*Math.sin(l),u=s.z;o.x=h,o.y=d,o.z=u}randomConePoint(s,t,i,n,o,r,l){let c=0,h=0;switch(r){case 0:c=Math.random(),h=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:c=.5,h=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let d=2*Math.PI*c*(o/360);switch(r){case 2:case 1:d+=Math.PI+.5,d+=this._loopTime*Math.PI*2,d%=W.toRadians(o);break}const u=Math.acos(2*h-1),p=W.lerp(1,1-Math.pow(1-Math.random(),Math.PI),n)*i,g=s.x+-p*Math.sin(u)*Math.cos(d),y=s.y+p*Math.sin(u)*Math.sin(d),f=s.z;l.x=g*this.scale.x,l.y=y*this.scale.y,l.z=f*this.scale.z}},a(Ep,"_randomQuat",new V),a(Ep,"_tempVec",new x),Ep);let Xe=Eh;k([m()],Xe.prototype,"shapeType",2),k([m()],Xe.prototype,"enabled",2),k([m()],Xe.prototype,"alignToDirection",2),k([m()],Xe.prototype,"angle",2),k([m()],Xe.prototype,"arc",2),k([m()],Xe.prototype,"arcSpread",2),k([m()],Xe.prototype,"arcSpeedMultiplier",2),k([m()],Xe.prototype,"arcMode",2),k([m(x)],Xe.prototype,"boxThickness",2),k([m(x)],Xe.prototype,"position",2),k([m(x)],Xe.prototype,"rotation",2),k([m(x)],Xe.prototype,"scale",2),k([m()],Xe.prototype,"radius",2),k([m()],Xe.prototype,"radiusThickness",2),k([m()],Xe.prototype,"sphericalDirectionAmount",2),k([m()],Xe.prototype,"randomDirectionAmount",2),k([m()],Xe.prototype,"randomPositionAmount",2),k([m()],Xe.prototype,"meshShapeType",2),k([m(rh)],Xe.prototype,"meshRenderer",2);class Ce{constructor(){a(this,"damping"),a(this,"enabled"),a(this,"frequency"),a(this,"octaveCount"),a(this,"octaveMultiplier"),a(this,"octaveScale"),a(this,"positionAmount"),a(this,"quality"),a(this,"remap"),a(this,"remapEnabled"),a(this,"remapMultiplier"),a(this,"remapX"),a(this,"remapXMultiplier"),a(this,"remapY"),a(this,"remapYMultiplier"),a(this,"remapZ"),a(this,"remapZMultiplier"),a(this,"scrollSpeedMultiplier"),a(this,"separateAxes"),a(this,"strengthMultiplier"),a(this,"strengthX"),a(this,"strengthXMultiplier"),a(this,"strengthY"),a(this,"strengthYMultiplier"),a(this,"strengthZ"),a(this,"strengthZMultiplier"),a(this,"_noise"),a(this,"_time",0),a(this,"_temp",new x)}update(t){this._time+=t.time.deltaTime*this.scrollSpeedMultiplier}apply(t,i,n,o,r,l){if(!this.enabled)return;this._noise||(this._noise=JC(()=>0));const c=this._temp.set(i.x,i.y,i.z).multiplyScalar(this.frequency),h=this._noise(c.x,c.y,c.z,this._time),d=this._noise(c.x,c.y,c.z,this._time+1e3*this.frequency),u=this._noise(c.x,c.y,c.z,this._time+2e3*this.frequency);this._temp.set(h,d,u).normalize();const p=r/l;let g=this.positionAmount.evaluate(p);this.separateAxes?(this._temp.x*=g*this.strengthXMultiplier,this._temp.y*=g*this.strengthYMultiplier,this._temp.z*=g*this.strengthZMultiplier):(this.strengthX&&(g*=this.strengthX.evaluate(p)*1.5),this._temp.multiplyScalar(g)),n.x+=this._temp.x,n.y+=this._temp.y,n.z+=this._temp.z}}k([m()],Ce.prototype,"damping",2),k([m()],Ce.prototype,"enabled",2),k([m()],Ce.prototype,"frequency",2),k([m()],Ce.prototype,"octaveCount",2),k([m()],Ce.prototype,"octaveMultiplier",2),k([m()],Ce.prototype,"octaveScale",2),k([m(Q)],Ce.prototype,"positionAmount",2),k([m()],Ce.prototype,"quality",2),k([m(Q)],Ce.prototype,"remap",2),k([m()],Ce.prototype,"remapEnabled",2),k([m()],Ce.prototype,"remapMultiplier",2),k([m(Q)],Ce.prototype,"remapX",2),k([m()],Ce.prototype,"remapXMultiplier",2),k([m(Q)],Ce.prototype,"remapY",2),k([m()],Ce.prototype,"remapYMultiplier",2),k([m(Q)],Ce.prototype,"remapZ",2),k([m()],Ce.prototype,"remapZMultiplier",2),k([m()],Ce.prototype,"scrollSpeedMultiplier",2),k([m()],Ce.prototype,"separateAxes",2),k([m()],Ce.prototype,"strengthMultiplier",2),k([m(Q)],Ce.prototype,"strengthX",2),k([m()],Ce.prototype,"strengthXMultiplier",2),k([m(Q)],Ce.prototype,"strengthY",2),k([m()],Ce.prototype,"strengthYMultiplier",2),k([m(Q)],Ce.prototype,"strengthZ",2),k([m()],Ce.prototype,"strengthZMultiplier",2);class Ue{constructor(){a(this,"enabled"),a(this,"attachRibbonToTransform",!1),a(this,"colorOverLifetime"),a(this,"colorOverTrail"),a(this,"dieWithParticles",!0),a(this,"inheritParticleColor",!0),a(this,"lifetime"),a(this,"lifetimeMultiplier"),a(this,"minVertexDistance",.2),a(this,"mode",0),a(this,"ratio",1),a(this,"ribbonCount",1),a(this,"shadowBias",0),a(this,"sizeAffectsLifetime",!1),a(this,"sizeAffectsWidth",!1),a(this,"splitSubEmitterRibbons",!1),a(this,"textureMode",0),a(this,"widthOverTrail"),a(this,"widthOverTrailMultiplier"),a(this,"worldSpace",!1)}getWidth(t,i,n,o){const r=this.widthOverTrail.evaluate(n,o);return t*=r,t}getColor(t,i,n){const o=this.colorOverTrail.evaluate(n),r=this.colorOverLifetime.evaluate(i);t.x*=o.r*r.r,t.y*=o.g*r.g,t.z*=o.b*r.b,"alpha"in o&&"alpha"in r&&(t.w*=o.alpha*r.alpha)}}k([m()],Ue.prototype,"enabled",2),k([m()],Ue.prototype,"attachRibbonToTransform",2),k([m(si)],Ue.prototype,"colorOverLifetime",2),k([m(si)],Ue.prototype,"colorOverTrail",2),k([m()],Ue.prototype,"dieWithParticles",2),k([m()],Ue.prototype,"inheritParticleColor",2),k([m(Q)],Ue.prototype,"lifetime",2),k([m()],Ue.prototype,"lifetimeMultiplier",2),k([m()],Ue.prototype,"minVertexDistance",2),k([m()],Ue.prototype,"mode",2),k([m()],Ue.prototype,"ratio",2),k([m()],Ue.prototype,"ribbonCount",2),k([m()],Ue.prototype,"shadowBias",2),k([m()],Ue.prototype,"sizeAffectsLifetime",2),k([m()],Ue.prototype,"sizeAffectsWidth",2),k([m()],Ue.prototype,"splitSubEmitterRibbons",2),k([m()],Ue.prototype,"textureMode",2),k([m(Q)],Ue.prototype,"widthOverTrail",2),k([m()],Ue.prototype,"widthOverTrailMultiplier",2),k([m()],Ue.prototype,"worldSpace",2);class Qe{constructor(){a(this,"enabled"),a(this,"space",0),a(this,"orbitalX"),a(this,"orbitalY"),a(this,"orbitalZ"),a(this,"orbitalXMultiplier"),a(this,"orbitalYMultiplier"),a(this,"orbitalZMultiplier"),a(this,"orbitalOffsetX"),a(this,"orbitalOffsetY"),a(this,"orbitalOffsetZ"),a(this,"speedModifier"),a(this,"speedModifierMultiplier"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier"),a(this,"_system"),a(this,"_temp",new x),a(this,"_temp2",new x),a(this,"_temp3",new x),a(this,"_hasOrbital",!1),a(this,"_index",0),a(this,"_orbitalMatrix",new ne)}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,i,n,o,r,l,c){var h;if(!this.enabled)return;const d=l/c,u=this.speedModifier.evaluate(d)*this.speedModifierMultiplier,p=this.x.evaluate(d),g=this.y.evaluate(d),y=this.z.evaluate(d);if(this._temp.set(-p,g,y),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((h=this._system)==null?void 0:h.worldPos)){const f=this._temp2.set(n.x,n.y,n.z),v=this.orbitalXMultiplier,b=this.orbitalYMultiplier,w=this.orbitalZMultiplier,_=u*Math.PI*2*10,C=Math.cos(_*v),R=Math.sin(_*v),M=Math.cos(_*b),T=Math.sin(_*b),j=Math.cos(_*w),L=Math.sin(_*w),U=f.x*(M*j)+f.y*(M*L)+f.z*-T,B=f.x*(R*T*j-C*L)+f.y*(R*T*L+C*j)+f.z*(R*M),Y=f.x*(C*T*j+R*L)+f.y*(C*T*L-R*j)+f.z*(C*M),$=this._temp3.set(f.x-U,f.y-B,f.z-Y);$.normalize(),$.multiplyScalar(.2/r*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),o.x+=$.x,o.y+=$.y,o.z+=$.z}o.x+=this._temp.x,o.y+=this._temp.y,o.z+=this._temp.z,o.x*=u,o.y*=u,o.z*=u}}k([m()],Qe.prototype,"enabled",2),k([m()],Qe.prototype,"space",2),k([m(Q)],Qe.prototype,"orbitalX",2),k([m(Q)],Qe.prototype,"orbitalY",2),k([m(Q)],Qe.prototype,"orbitalZ",2),k([m()],Qe.prototype,"orbitalXMultiplier",2),k([m()],Qe.prototype,"orbitalYMultiplier",2),k([m()],Qe.prototype,"orbitalZMultiplier",2),k([m()],Qe.prototype,"orbitalOffsetX",2),k([m()],Qe.prototype,"orbitalOffsetY",2),k([m()],Qe.prototype,"orbitalOffsetZ",2),k([m(Q)],Qe.prototype,"speedModifier",2),k([m()],Qe.prototype,"speedModifierMultiplier",2),k([m(Q)],Qe.prototype,"x",2),k([m()],Qe.prototype,"xMultiplier",2),k([m(Q)],Qe.prototype,"y",2),k([m()],Qe.prototype,"yMultiplier",2),k([m(Q)],Qe.prototype,"z",2),k([m()],Qe.prototype,"zMultiplier",2);class Bt{constructor(){a(this,"animation"),a(this,"enabled"),a(this,"cycleCount"),a(this,"frameOverTime"),a(this,"frameOverTimeMultiplier"),a(this,"numTilesX"),a(this,"numTilesY"),a(this,"startFrame"),a(this,"startFrameMultiplier"),a(this,"rowMode"),a(this,"rowIndex"),a(this,"spriteCount"),a(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 i=this.numTilesX*this.numTilesY;t=t*this.cycleCount;let n=this.frameOverTime.evaluate(t%1);return n*=this.frameOverTimeMultiplier,n*=i,n=n%i,n=Math.floor(n),n}}k([m()],Bt.prototype,"animation",2),k([m()],Bt.prototype,"enabled",2),k([m()],Bt.prototype,"cycleCount",2),k([m(Q)],Bt.prototype,"frameOverTime",2),k([m()],Bt.prototype,"frameOverTimeMultiplier",2),k([m()],Bt.prototype,"numTilesX",2),k([m()],Bt.prototype,"numTilesY",2),k([m(Q)],Bt.prototype,"startFrame",2),k([m()],Bt.prototype,"startFrameMultiplier",2),k([m()],Bt.prototype,"rowMode",2),k([m()],Bt.prototype,"rowIndex",2),k([m()],Bt.prototype,"spriteCount",2),k([m()],Bt.prototype,"timeMode",2);class ns{constructor(){a(this,"enabled"),a(this,"separateAxes"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier")}evaluate(t,i){return this.enabled?this.separateAxes?0:this.z.evaluate(t,i)*-1:0}}k([m()],ns.prototype,"enabled",2),k([m()],ns.prototype,"separateAxes",2),k([m(Q)],ns.prototype,"x",2),k([m()],ns.prototype,"xMultiplier",2),k([m(Q)],ns.prototype,"y",2),k([m()],ns.prototype,"yMultiplier",2),k([m(Q)],ns.prototype,"z",2),k([m()],ns.prototype,"zMultiplier",2);class Fi{constructor(){a(this,"enabled"),a(this,"range"),a(this,"separateAxes"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier")}evaluate(t,i){if(!this.enabled)return 0;if(!this.separateAxes){const n=W.lerp(this.range.x,this.range.y,i);return this.z.evaluate(n)*-1}return 0}}k([m()],Fi.prototype,"enabled",2),k([m()],Fi.prototype,"range",2),k([m()],Fi.prototype,"separateAxes",2),k([m(Q)],Fi.prototype,"x",2),k([m()],Fi.prototype,"xMultiplier",2),k([m(Q)],Fi.prototype,"y",2),k([m()],Fi.prototype,"yMultiplier",2),k([m(Q)],Fi.prototype,"z",2),k([m()],Fi.prototype,"zMultiplier",2);class ct{constructor(){a(this,"enabled"),a(this,"dampen"),a(this,"drag"),a(this,"dragMultiplier"),a(this,"limit"),a(this,"limitMultiplier"),a(this,"separateAxes"),a(this,"limitX"),a(this,"limitXMultiplier"),a(this,"limitY"),a(this,"limitYMultiplier"),a(this,"limitZ"),a(this,"limitZMultiplier"),a(this,"multiplyDragByParticleSize",!1),a(this,"multiplyDragByParticleVelocity",!1),a(this,"space"),a(this,"_temp",new x),a(this,"_temp2",new x)}apply(t,i,n,o,r,l,c){if(this.enabled){const h=this.limit.evaluate(r)*this.limitMultiplier;if(i.length()>h){this._temp.copy(i).normalize().multiplyScalar(h);const d=this.dampen*.5;i.x=W.lerp(i.x,this._temp.x,d),i.y=W.lerp(i.y,this._temp.y,d),i.z=W.lerp(i.z,this._temp.z,d),n.x=W.lerp(n.x,this._temp.x,d),n.y=W.lerp(n.y,this._temp.y,d),n.z=W.lerp(n.z,this._temp.z,d)}}}}k([m()],ct.prototype,"enabled",2),k([m()],ct.prototype,"dampen",2),k([m(Q)],ct.prototype,"drag",2),k([m()],ct.prototype,"dragMultiplier",2),k([m(Q)],ct.prototype,"limit",2),k([m()],ct.prototype,"limitMultiplier",2),k([m()],ct.prototype,"separateAxes",2),k([m(Q)],ct.prototype,"limitX",2),k([m()],ct.prototype,"limitXMultiplier",2),k([m(Q)],ct.prototype,"limitY",2),k([m()],ct.prototype,"limitYMultiplier",2),k([m(Q)],ct.prototype,"limitZ",2),k([m()],ct.prototype,"limitZMultiplier",2),k([m()],ct.prototype,"multiplyDragByParticleSize",2),k([m()],ct.prototype,"multiplyDragByParticleVelocity",2),k([m()],ct.prototype,"space",2);const s1=class{constructor(){a(this,"enabled"),a(this,"curve"),a(this,"curveMultiplier"),a(this,"mode"),a(this,"system"),a(this,"_temp",new x),a(this,"_firstUpdate",!0),a(this,"_frames",0)}clone(){var s;const t=new s1;return t.enabled=this.enabled,t.curve=(s=this.curve)==null?void 0:s.clone(),t.curveMultiplier=this.curveMultiplier,t.mode=this.mode,t}get _lastWorldPosition(){return this.system._iv_lastWorldPosition||(this.system._iv_lastWorldPosition=new x),this.system._iv_lastWorldPosition}get _velocity(){return this.system._iv_velocity||(this.system._iv_velocity=new x),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,i){if(this.enabled&&this.system&&this.system.worldspace!==!1&&this.mode===1){const n=this.curve.evaluate(t,i);this._temp.copy(this._velocity).multiplyScalar(n),s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z}}};let Yo=s1;k([m()],Yo.prototype,"enabled",2),k([m(Q)],Yo.prototype,"curve",2),k([m()],Yo.prototype,"curveMultiplier",2),k([m()],Yo.prototype,"mode",2);class ni{constructor(){a(this,"enabled"),a(this,"range"),a(this,"separateAxes"),a(this,"size"),a(this,"sizeMultiplier"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier")}evaluate(t,i,n,o){const r=t.length(),l=W.remap(r,this.range.x,this.range.y,0,1),c=this.size.evaluate(l,n);return o.x*=c,o.y*=c,o.z*=c,o}}k([m()],ni.prototype,"enabled",2),k([m(oe)],ni.prototype,"range",2),k([m()],ni.prototype,"separateAxes",2),k([m(Q)],ni.prototype,"size",2),k([m()],ni.prototype,"sizeMultiplier",2),k([m(Q)],ni.prototype,"x",2),k([m()],ni.prototype,"xMultiplier",2),k([m(Q)],ni.prototype,"y",2),k([m()],ni.prototype,"yMultiplier",2),k([m(Q)],ni.prototype,"z",2),k([m()],ni.prototype,"zMultiplier",2);class ta{constructor(){a(this,"enabled"),a(this,"range"),a(this,"color")}evaluate(t,i,n){const o=t.length(),r=W.remap(o,this.range.x,this.range.y,0,1),l=this.color.evaluate(r,i);n.x*=l.r,n.y*=l.g,n.z*=l.b,"alpha"in l&&(n.w*=l.alpha)}}k([m()],ta.prototype,"enabled",2),k([m(oe)],ta.prototype,"range",2),k([m(si)],ta.prototype,"color",2),new x(1,1,1),new x(0,0,1);class Ap{constructor(t,i,n,o){a(this,"type","NeedleParticleSubEmitter"),a(this,"emitterType"),a(this,"emitterProbability"),a(this,"q_",new V),a(this,"v_",new x),a(this,"v2_",new x),a(this,"_emitterMatrix",new Om),a(this,"_circularBuffer"),this.system=t,this.particleSystem=i,this.subSystem=n,this.subParticleSystem=o,this.subParticleSystem&&this.subParticleSystem&&(this.subParticleSystem.onlyUsedByOther=!0);const r=1e3;this._circularBuffer=new Si(()=>new Om,r)}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===$0.Birth&&this.run(t)}update(t,i){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 i=this.system.deltaTime;if(this.emitterType===$0.Death){let o=t.life;if(t[Rl]!==void 0&&(o=t[Rl]),!(t.age+i*1.2>=o))return;const r=this.subSystem.main.maxParticles-this.subSystem.currentParticles;t.emissionState.waitEmiting=r}const n=new Om;n.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||n.multiplyMatrices(this._emitterMatrix,n),this.subParticleSystem.emit(i,t.emissionState,n)}}var IE=Object.defineProperty,jE=Object.getOwnPropertyDescriptor,Ye=(s,t,i,n)=>{for(var o=n>1?void 0:n?jE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&IE(t,i,o),o};const Ko=O("debugparticles"),DE=O("noprogressive"),LE=O("debugprogressive");var $0=(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))($0||{});class os extends A{constructor(){super(...arguments),a(this,"renderMode"),a(this,"particleMaterial"),a(this,"trailMaterial"),a(this,"particleMesh"),a(this,"maxParticleSize"),a(this,"minParticleSize"),a(this,"velocityScale"),a(this,"cameraVelocityScale"),a(this,"lengthScale")}start(){if(this.maxParticleSize!==.5&&this.minParticleSize!==0&&F()){const t=`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(t)}}get transparent(){var t;return((t=this.particleMaterial)==null?void 0:t.transparent)??!1}getMaterial(t=!1){let i=t===!0&&this.trailMaterial?this.trailMaterial:this.particleMaterial;if(i){if(i.type==="MeshStandardMaterial"){Ko&&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=mr,i.map.premultiplyAlpha=!1);const n=new Re;n.copy(i),t?this.trailMaterial=n:this.particleMaterial=n}i.map&&(i.map.colorSpace=mr,i.map.premultiplyAlpha=!1),t&&i.side===lo&&(i=i.clone(),i.side=ym,t?this.trailMaterial=i:this.particleMaterial=i)}return i&&!DE&&i._didRequestTextureLOD===void 0&&(i._didRequestTextureLOD=0,LE&&console.log("Load material LOD",i.name),it.assignTextureLOD(i,0)),i}getMesh(t){let i=null;if(!i&&(this.particleMesh instanceof K&&(i=this.particleMesh.geometry),i===null)){i=new Fs(1,1);const n=i.attributes.uv;for(let o=0;o<n.count;o++)n.setX(o,1-n.getX(o))}return new K(i,this.getMaterial())}}Ye([m()],os.prototype,"renderMode",2),Ye([m(ke)],os.prototype,"particleMaterial",2),Ye([m(ke)],os.prototype,"trailMaterial",2),Ye([m()],os.prototype,"maxParticleSize",2),Ye([m()],os.prototype,"minParticleSize",2),Ye([m()],os.prototype,"velocityScale",2),Ye([m()],os.prototype,"cameraVelocityScale",2),Ye([m()],os.prototype,"lengthScale",2);class Ip{constructor(t,i=1){a(this,"_curve"),a(this,"_factor"),a(this,"type","function"),this._curve=t,this._factor=i}startGen(t){}genValue(t,i){return this._curve.evaluate(i,Math.random())*this._factor}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}}class q0{constructor(t){a(this,"type","value"),a(this,"system"),this.system=t}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}startGen(t){}}class BE extends q0{genValue(){return this.system.textureSheetAnimation.getStartIndex()}}class FE extends q0{constructor(){super(...arguments),a(this,"_lastPosition",new x),a(this,"_lastDistance",0)}update(){const t=te(this.system.gameObject);this._lastDistance=this._lastPosition.distanceTo(t),this._lastPosition.copy(t)}genValue(){if(!this.system.isPlaying||!this.system.emission.enabled||this.system.currentParticles>=this.system.maxParticles)return 0;let t=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 r=this._lastDistance/this.system.deltaTime*o;Number.isFinite(r)||(r=0),t+=r}const i=this.system.emission.getBurst();i>0&&(t+=i/this.system.deltaTime);const n=this.system.maxParticles-this.system.currentParticles;return W.clamp(t,0,n/this.system.deltaTime)}}class zE extends q0{genValue(){return this.system.isPlaying,0}}class Zo{constructor(t){a(this,"system"),a(this,"type"),this.type=Object.getPrototypeOf(this).constructor.name||"ParticleSystemBaseBehaviour",t&&(this.system=t)}get context(){return this.system.context}initialize(t){}update(t,i){}frameUpdate(t){}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}reset(){}}class UE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleTextureSheet")}update(t,i){const n=this.system.textureSheetAnimation;if(n.enabled){const o=t.age/t.life,r=n.evaluate(o);r!==void 0&&(t.uvTile=r)}}}const n1=Symbol("particleRotation");class NE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleRotation")}initialize(t){t[n1]=Math.random()}update(t,i){if(t.rotation===void 0)return;const n=t.age/t.life;if(typeof t.rotation=="number"&&(this.system.rotationOverLifetime.enabled?t.rotation+=this.system.rotationOverLifetime.evaluate(n,t[n1])*i:this.system.renderer.renderMode===qn.Billboard&&(t.rotation=Math.PI),this.system.rotationBySpeed.enabled)){const o=t.velocity.length();t.rotation+=this.system.rotationBySpeed.evaluate(n,o)*i}}}const o1=Symbol("sizeLerpFactor"),WE=new x;class VE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleSize"),a(this,"_minSize",0),a(this,"_maxSize",1)}initialize(t){t[o1]=Math.random(),this._minSize=this.system.renderer.minParticleSize,this._maxSize=this.system.renderer.maxParticleSize}update(t,i){const n=t.age/t.life;let o=1;this.system.sizeOverLifetime.enabled&&(o*=this.system.sizeOverLifetime.evaluate(n,void 0,t[o1]).x);let r=1;this.system.renderer.renderMode!==qn.Mesh&&(r=this.system.worldScale.x/this.system.cameraScale);const l=G(t.startSize).multiplyScalar(o*r);if(t.size.set(l.x,l.y,l.z),this.system.localspace){const c=h1(this.system,WE);t.size.x*=c.x,t.size.y*=c.y,t.size.z*=c.z}}}const Rl=Symbol("particleLife"),G0=Symbol("trailLifetime"),r1=Symbol("trailStartLength"),X0=Symbol("trailWidthRandom");class HE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleTrail")}initialize(t){t instanceof gv&&(t[Rl]=t.life,this.system.trails.enabled&&this.system.trails.dieWithParticles===!1&&(t[G0]=this.system.trails.lifetime.evaluate(Math.random(),Math.random()),t.life+=t[G0]),t[r1]=t.length,t[X0]=Math.random())}update(t){var i;if((i=this.system.trails)!=null&&i.enabled&&t instanceof gv){const n=t,o=t.age/t[Rl],r=t.previous.values(),l=t.previous.length;for(let c=0;c<l;c++){const h=r.next().value,d=1-c/(l-1),u=t.size;if(u.x<=0&&!this.system.trails.sizeAffectsWidth){const p=20*this.system.trails.widthOverTrail.evaluate(.5,n[X0]);u.x=p,u.y=p,u.z=p}h.size=this.system.trails.getWidth(u.x,o,d,n[X0]),h.color.copy(t.color),this.system.trails.getColor(h.color,o,d)}if(t.age>t[Rl]){t.velocity.set(0,0,0);const c=(t.age-t[Rl])/t[G0];n.length=W.lerp(t[r1],0,c)}}}}const jp=Symbol("startVelocity"),a1=Symbol("gravityModifier"),Q0=Symbol("gravitySpeed"),Dp=Symbol("velocity lerp factor"),Y0=new x;class $E extends Zo{constructor(){super(...arguments),a(this,"type","NeedleVelocity"),a(this,"_gravityDirection",new x)}initialize(t){var i,n;const o=this.system.main.simulationSpeed;t.startSpeed=this.system.main.startSpeed.evaluate(Math.random(),Math.random());const r=this.system.shape.getDirection(t,t.position);t.velocity.x=r.x*t.startSpeed,t.velocity.y=r.y*t.startSpeed,t.velocity.z=r.z*t.startSpeed,(i=this.system.inheritVelocity)!=null&&i.enabled&&this.system.inheritVelocity.applyInitial(t.velocity),t[jp]?t[jp].copy(t.velocity):t[jp]=t.velocity.clone();const l=this.system.main.gravityModifier.evaluate(Math.random(),Math.random());t[a1]=l*o,t[Q0]=l*o*.5,t[Dp]=Math.random(),(n=this.system.velocityOverLifetime)==null||n.init(t),this._gravityDirection.set(0,-1,0),this.system.main.simulationSpace===kh.Local&&this._gravityDirection.applyQuaternion(this.system.worldQuaternionInverted).normalize()}update(t,i){var n;const o=t[jp],r=t[a1];if(r!==0){const g=r*t[Q0];Y0.copy(this._gravityDirection).multiplyScalar(g),t[Q0]+=i*.05,o.add(Y0)}t.velocity.copy(o);const l=t.age/t.life;(n=this.system.inheritVelocity)!=null&&n.enabled&&this.system.inheritVelocity.applyCurrent(t.velocity,l,t[Dp]);const c=this.system.noise;c.enabled&&c.apply(0,t.position,t.velocity,i,t.age,t.life);const h=this.system.sizeBySpeed;h!=null&&h.enabled&&(t.size=h.evaluate(t.velocity,l,t[Dp],t.size));const d=this.system.colorBySpeed;d!=null&&d.enabled&&d.evaluate(t.velocity,t[Dp],t.color);const u=this.system.velocityOverLifetime;u.enabled&&u.apply(t,0,t.position,t.velocity,i,t.age,t.life);const p=this.system.limitVelocityOverLifetime;if(p.enabled&&p.apply(t.position,o,t.velocity,t.size,l,i,1),this.system.worldspace){const g=this.system.worldScale;t.velocity.x*=g.x,t.velocity.y*=g.y,t.velocity.z*=g.z}}}const l1=Symbol("colorLerpFactor"),c1=new Se(1,1,1,1),ia=new Se(1,1,1,1);class qE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleColor")}initialize(t){}_init(t){const i=this.system.renderer.particleMaterial;ia.copy(this.system.main.startColor.evaluate(Math.random())),i!=null&&i.color&&(c1.copy(i.color),ia.multiply(c1)),ia.convertLinearToSRGB(),t.startColor.set(ia.r,ia.g,ia.b,ia.alpha),t.color.copy(t.startColor),t[l1]=Math.random()}update(t,i){if(t.age===0&&this._init(t),this.system.colorOverLifetime.enabled){const n=t.age/t.life,o=this.system.colorOverLifetime.color.evaluate(n,t[l1]);t.color.set(o.r,o.g,o.b,"alpha"in o?o.alpha:1).multiply(t.startColor)}else t.color.copy(t.startColor)}}class GE{constructor(t){a(this,"system"),a(this,"emission"),a(this,"autoDestroy"),a(this,"startLength"),a(this,"emissionBursts"),a(this,"onlyUsedByOther"),a(this,"behaviors",[]),a(this,"rendererEmitterSettings",{startLength:new nO(220),followLocalOrigin:!1}),a(this,"flatWhiteTexture"),a(this,"clonedTexture",{original:void 0,clone:void 0}),this.system=t,this.emission=new FE(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 Ip(this.system.main.startLifetime)}get startSpeed(){return new Ip(this.system.main.startSpeed)}get startRotation(){return new Ip(this.system.main.startRotation)}get startSize(){return new Ip(this.system.main.startSize)}get startColor(){return new iO(new sO(1,1,1,1))}get emissionOverTime(){return this.emission}get emissionOverDistance(){return new zE(this.system)}get instancingGeometry(){return this.system.renderer.getMesh(this.system.renderer.renderMode).geometry}get renderMode(){if(this.system.trails.enabled===!0)return xn.Trail;switch(this.system.renderer.renderMode){case qn.Billboard:return xn.BillBoard;case qn.Stretch:return xn.StretchedBillBoard;case qn.HorizontalBillboard:return xn.HorizontalBillBoard;case qn.VerticalBillboard:return xn.VerticalBillBoard;case qn.Mesh:return xn.Mesh}return xn.BillBoard}get speedFactor(){var t;let i=this.system.main.simulationSpeed;return((t=this.system.renderer)==null?void 0:t.renderMode)===qn.Stretch&&(i*=this.system.renderer.velocityScale??1),i}get texture(){const t=this.material;if(t&&t.map){const i=t.map;if(this.clonedTexture.original!==i||!this.clonedTexture.clone){const n=i.clone();n.premultiplyAlpha=!1,n.colorSpace=mr,this.clonedTexture.original=i,this.clonedTexture.clone=n}return this.clonedTexture.clone}return this.flatWhiteTexture||(this.flatWhiteTexture=Kg(new Se(1,1,1,1),1)),this.flatWhiteTexture}get startTileIndex(){return new BE(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)??gC}get transparent(){return this.system.renderer.transparent}get worldSpace(){return this.system.main.simulationSpace===kh.World}}class XE{constructor(){a(this,"burstParticleIndex",0),a(this,"burstParticleCount",0),a(this,"isBursting",!1),a(this,"travelDistance",0),a(this,"previousWorldPos"),a(this,"burstIndex",0),a(this,"burstWaveIndex",0),a(this,"time",0),a(this,"waitEmiting",0)}}const Lp=class extends A{constructor(){super(...arguments),a(this,"_state"),a(this,"colorOverLifetime"),a(this,"main"),a(this,"emission"),a(this,"sizeOverLifetime"),a(this,"shape"),a(this,"noise"),a(this,"trails"),a(this,"velocityOverLifetime"),a(this,"limitVelocityOverLifetime"),a(this,"inheritVelocity"),a(this,"colorBySpeed"),a(this,"textureSheetAnimation"),a(this,"rotationOverLifetime"),a(this,"rotationBySpeed"),a(this,"sizeBySpeed"),a(this,"_cameraScale",1),a(this,"__worldQuaternion",new V),a(this,"_worldQuaternionInverted",new V),a(this,"_worldScale",new x),a(this,"_worldPositionFrame",-1),a(this,"_worldPos",new x),a(this,"_renderer"),a(this,"_batchSystem"),a(this,"_particleSystem"),a(this,"_interface"),a(this,"_container"),a(this,"_time",0),a(this,"_isPlaying",!0),a(this,"_isUsedAsSubsystem",!1),a(this,"_didPreWarm",!1),a(this,"_bursts"),a(this,"_subEmitterSystems"),a(this,"_lastBatchesCount",-1)}play(s=!1){var t;s&&P.foreachComponent(this.gameObject,i=>{i instanceof Lp&&i!==this&&i.play(!1)},!0),this._isPlaying=!0,this._particleSystem&&(this._particleSystem.emissionState.time=0,this._particleSystem.emitEnded=!1),(t=this.emission)==null||t.reset()}pause(s=!0){s&&P.foreachComponent(this.gameObject,t=>{t instanceof Lp&&t!==this&&t.pause(!1)},!0),this._isPlaying=!1}stop(s=!0,t=!1){s&&P.foreachComponent(this.gameObject,i=>{i instanceof Lp&&i!==this&&i.stop(!1,t)},!0),this._isPlaying=!1,this._time=0,t&&this.reset()}reset(){var s;this._time=0,this._particleSystem&&(this._particleSystem.particleNum=0,this._particleSystem.emissionState.time=0,this._particleSystem.emitEnded=!1,(s=this.emission)==null||s.reset())}emit(s){if(this._particleSystem){this.onUpdate(),s=Math.min(s,this.maxParticles-this.currentParticles),this._state||(this._state=new XE),this._state.waitEmiting=s,this._state.time=0;const t=this._particleSystem.emitEnded;this._particleSystem.emitEnded=!1,this._particleSystem.emit(this.deltaTime,this._state,this._particleSystem.emitter.matrixWorld),this._particleSystem.emitEnded=t}}get playOnAwake(){return this.main.playOnAwake}set playOnAwake(s){this.main.playOnAwake=s}get renderer(){return this._renderer}get isPlaying(){return this._isPlaying}get currentParticles(){var s;return((s=this._particleSystem)==null?void 0:s.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===kh.World}get localspace(){return this.main.simulationSpace===kh.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,te(this.gameObject,this._worldPos)),this._worldPos}get matrixWorld(){return this._container.matrixWorld}get isSubsystem(){return this._isUsedAsSubsystem}addBehaviour(s){return this._particleSystem?(s instanceof Zo&&(s.system=this),(F()||Ko)&&console.debug("Add custom ParticleSystem Behaviour",s),this._particleSystem.addBehavior(s),!0):!1}removeBehaviour(s){if(!this._particleSystem)return!1;const t=this._particleSystem.behaviors,i=t.indexOf(s);return i!==-1&&((F()||Ko)&&console.debug("Remove custom ParticleSystem Behaviour",i,s),t.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(s){for(let t=0;t<s.length;t++){const i=s[t];if(!(i instanceof Rh)){const n=new Rh;La(n,i),s[t]=n}}this._bursts=s}set subEmitterSystems(s){for(let t=0;t<s.length;t++){const i=s[t];if(!(i instanceof Ah)){const n=new Ah;La(n,i),s[t]=n}}Ko&&s.length>0&&console.log("SubEmitters: ",s,this),this._subEmitterSystems=s}onAfterDeserialize(s){if(this._subEmitterSystems&&Array.isArray(this._subEmitterSystems))for(const t of this._subEmitterSystems)t._deserialize(this.context,this.gameObject)}awake(){if(this._worldPositionFrame=-1,this._renderer=this.gameObject.getComponent(os),!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 I,this._container.matrixAutoUpdate=!1,this.context.scene.add(this._container),this._batchSystem=new eO,this._batchSystem.name=this.gameObject.name,this._container.add(this._batchSystem),this._interface=new GE(this),this._particleSystem=new tO(this._interface),this._particleSystem.addBehavior(new VE(this)),this._particleSystem.addBehavior(new qE(this)),this._particleSystem.addBehavior(new UE(this)),this._particleSystem.addBehavior(new NE(this)),this._particleSystem.addBehavior(new $E(this)),this._particleSystem.addBehavior(new HE(this)),this._batchSystem.addSystem(this._particleSystem);const s=this._particleSystem.emitter;this.context.scene.add(s),this.inheritVelocity.system&&this.inheritVelocity.system!==this&&(this.inheritVelocity=this.inheritVelocity.clone()),this.inheritVelocity.awake(this),Ko&&(console.log(this),this.gameObject.add(new wi(1)))}start(){this.addSubParticleSystems(),this.updateLayers(),this.renderer.particleMesh instanceof K&&this._interface.renderMode==xn.Mesh&&it.assignMeshLOD(this.renderer.particleMesh,0).then(s=>{s&&this.particleSystem&&this._interface.renderMode==xn.Mesh&&(this.particleSystem.instancingGeometry=s)})}onDestroy(){var s,t,i,n;(s=this._container)==null||s.removeFromParent(),(t=this._batchSystem)==null||t.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 s;this.main&&(this._didPreWarm===!1&&((s=this.main)==null?void 0:s.prewarm)===!0&&(this._didPreWarm=!0,this.preWarm()),this.onUpdate(),this.onSimulate(this.deltaTime))}preWarm(){var s;if(!((s=this.emission)!=null&&s.enabled)||this.emission.rateOverTime.getMax()<=0)return;const t=1/60,i=this.main.duration,n=this.main.startLifetime.getMax(),o=1e3,r=Math.min(Math.max(i,n)/Math.max(.01,this.main.simulationSpeed),o),l=Math.ceil(r/t),c=Date.now();Ko&&console.log(`Particles ${this.name} - Prewarm for ${l} frames (${r} sec). Duration: ${i}, Lifetime: ${n}`);for(let h=0;h<l&&!(this.currentParticles>=this.maxParticles);h++){const d=Date.now()-c;if(d>2e3){console.warn(`Particles ${this.name} - Prewarm took too long. Aborting: ${d}`);break}this.onUpdate(),this.onSimulate(t)}}onSimulate(s){if(this._batchSystem){let t=this.context.time.frameCount%60===0;this._lastBatchesCount!==this._batchSystem.batches.length&&(this._lastBatchesCount=this._batchSystem.batches.length,t=!0),t&&this.updateLayers(),this._batchSystem.update(s)}this._time+=s,this._time>this.duration&&(this._time=0)}updateLayers(){if(this._batchSystem)for(let s=0;s<this._batchSystem.batches.length;s++){const t=this._batchSystem.batches[s];t.layers.disableAll();const i=this.layer;t.layers.mask=1<<i}}onUpdate(){var s,t;if(this._bursts&&(this.emission.bursts=this._bursts,delete this._bursts),!this._isPlaying)return;const i=this.context.mainCamera;if(i){const r=Je(i);this._cameraScale=r.x}const n=!this.worldspace,o=this.gameObject;if(Oe(o,this.__worldQuaternion),this._worldQuaternionInverted.copy(this.__worldQuaternion).invert(),Je(this.gameObject,this._worldScale),n&&this._container&&(s=this.gameObject)!=null&&s.parent){const r=h1(this,Y0);this._container.matrix.makeScale(r.x,r.y,r.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),(t=this.inheritVelocity)==null||t.update(this.context),this.velocityOverLifetime.update(this)}addSubParticleSystems(){var s;if(this._subEmitterSystems&&this._particleSystem)for(const t of this._subEmitterSystems){t.particleSystem&&(t.particleSystem.__internalAwake?t.particleSystem.__internalAwake():F()&&console.warn("SubParticleSystem serialization issue(?)",t.particleSystem,t));const i=(s=t.particleSystem)==null?void 0:s._particleSystem;if(i){t.particleSystem._isUsedAsSubsystem=!0;const n=new Ap(this,this._particleSystem,t.particleSystem,i);n.emitterType=t.type,n.emitterProbability=t.emitProbability,this._particleSystem.addBehavior(n)}else Ko&&console.warn("Could not add SubParticleSystem",t,this)}}};let ht=Lp;Ye([m(Th)],ht.prototype,"colorOverLifetime",2),Ye([m(Lt)],ht.prototype,"main",2),Ye([m(hn)],ht.prototype,"emission",2),Ye([m(Qo)],ht.prototype,"sizeOverLifetime",2),Ye([m(Xe)],ht.prototype,"shape",2),Ye([m(Ce)],ht.prototype,"noise",2),Ye([m(Ue)],ht.prototype,"trails",2),Ye([m(Qe)],ht.prototype,"velocityOverLifetime",2),Ye([m(ct)],ht.prototype,"limitVelocityOverLifetime",2),Ye([m(Yo)],ht.prototype,"inheritVelocity",2),Ye([m(ta)],ht.prototype,"colorBySpeed",2),Ye([m(Bt)],ht.prototype,"textureSheetAnimation",2),Ye([m(ns)],ht.prototype,"rotationOverLifetime",2),Ye([m(Fi)],ht.prototype,"rotationBySpeed",2),Ye([m(ni)],ht.prototype,"sizeBySpeed",2);class Ah{constructor(){a(this,"particleSystem"),a(this,"emitProbability",1),a(this,"properties"),a(this,"type")}_deserialize(t,i){const n=this.particleSystem;if(n instanceof ht)return;let o="";n&&typeof n.guid=="string"&&(o=n.guid,this.particleSystem=P.findByGuid(o,i)),Ko&&!(this.particleSystem instanceof ht)&&console.warn("Could not find particle system for sub emitter",o,i,this)}}function h1(s,t){if(t.set(1,1,1),s.gameObject.parent&&s.localspace)switch(s.main.scalingMode){case H0.Local:t=Je(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 i="ParticleSystem scale mode "+H0[s.main.scalingMode]+" is not supported";F()&&xe(i),console.warn(i,s.name,s)}t=Je(s.gameObject,t);break}return t}class Hl extends A{constructor(){super(...arguments),a(this,"_didAssignPlayerColor",!1),a(this,"tryAssignColor",()=>{const t=P.getComponentInParent(this.gameObject,Di);if(t&&t.owner)return this._didAssignPlayerColor=!0,this.assignUserColor(t.owner),!0;const i=P.getComponentInParent(this.gameObject,Tt);return i!=null&&i.connectionId?(this._didAssignPlayerColor=!0,this.assignUserColor(i.connectionId),!0):!1})}onEnable(){this.context.connection.beginListen(ie.JoinedRoom,this.tryAssignColor),this._didAssignPlayerColor||this.startCoroutine(this.waitForConnection())}onDisable(){this.context.connection.stopListen(ie.JoinedRoom,this.tryAssignColor)}*waitForConnection(){for(;!this.destroyed&&this.activeAndEnabled&&(yield V_(.2),!this.tryAssignColor()););}assignUserColor(t){const i=Hl.hashCode(t),n=Hl.colorFromHashCode(i);if(this.gameObject.type==="Mesh"){const o=this.gameObject;this.assignColor(n,t,o)}else if(this.gameObject.children)for(const o of this.gameObject.children){const r=o;r.material&&r.material.color&&this.assignColor(n,t,r)}}assignColor(t,i,n){let o=n.material;o&&(o._playerMaterial!==i&&(o=o.clone(),o._playerMaterial=i,n.material=o),o.color=t)}static hashCode(t){var i=0,n,o;if(t.length===0)return i;for(n=0;n<t.length;n++)o=t.charCodeAt(n),i=(i<<5)-i+o,i|=0;return i}static colorFromHashCode(t){const i=(t&16711680)>>16,n=(t&65280)>>8,o=t&255;return new re(i/255,n/255,o/255)}}const QE=O("debugpost");let K0=null;function YE(s){K0=s}function d1(s){let t=s.gameObject;for(;t;){for(const i of ou(t))if(i.isPostProcessingManager===!0)return i;t=t.parent}return null}function KE(s){let t=d1(s);if(!t)if(K0){QE&&console.warn("Adding postprocessing manager to the scene.");const i=s.scene;t=Mi(i,K0)}else F()&&console.warn("No post processing manager found");return t}var ZE=Object.defineProperty,JE=Object.getOwnPropertyDescriptor,u1=(s,t,i,n)=>{for(var o=n>1?void 0:n?JE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&ZE(t,i,o),o};const eA=O("debugpost");class N{constructor(t){a(this,"isVolumeParameter",!0),a(this,"_isInitialized",!1),a(this,"_active",!0),a(this,"_value"),a(this,"_valueRaw"),a(this,"_defaultValue"),a(this,"valueProcessor"),a(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 i=t?this._valueRaw:this._defaultValue;this.processValue(i,!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,i){if(t==null||!i&&this.testIfValueChanged(t)===!1)return;const n=this._value;eA&&typeof n=="number"&&typeof t=="number"&&(n?.toFixed(4),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,n,this)}testIfValueChanged(t){return this._valueRaw!==t}}u1([m()],N.prototype,"overrideState",1),u1([m()],N.prototype,"value",1);class tA extends Zi{constructor(){super([N])}onSerialize(t,i){}onDeserialize(t,i){const n=i.target,o=i.path;let r;if(n&&o&&(r=n[o]),(typeof r!="object"||typeof r=="object"&&r.isVolumeParameter!==!0)&&(r=new N),typeof t=="object"&&"value"in t){const l=t.value;r.initialize(l),r.overrideState=t.overrideState}else r.value=t;return r}}new tA;var iA=Object.defineProperty,sA=Object.getOwnPropertyDescriptor,nA=(s,t,i,n)=>{for(var o=n>1?void 0:n?sA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&iA(t,i,o),o};const oA=O("debugpost");class dt extends A{constructor(t=void 0){if(super(),a(this,"active",!0),a(this,"_manager",null),a(this,"_result"),a(this,"_postprocessingContext",null),t)for(const i of Object.keys(t)){const n=t[i],o=this[i];o instanceof N?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 t;super.onDisable(),(t=this._manager)==null||t.removeEffect(this),this.active=!1}onEffectEnabled(t){var i;t&&t.isPostProcessingManager===!0?this._manager=t:this._manager||(this._manager=KE(this)),(i=this._manager)==null||i.addEffect(this)}init(){}get postprocessingContext(){return this._postprocessingContext}apply(t){var i;return this._postprocessingContext=t,this._result||(this.initParameters(),this._result=(i=this.onCreateEffect)==null?void 0:i.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){oA&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(t=>t.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const t=Object.keys(this);for(const i of t){const n=this[i];n instanceof N&&n.__init()}}onEditorModification(t){const i=t.propertyName;if(this[i]instanceof N){const n=t.value;return this[i].value=n,!0}}}nA([m()],dt.prototype,"active",2);var rA=Object.defineProperty,aA=Object.getOwnPropertyDescriptor,lA=(s,t,i,n)=>{for(var o=n>1?void 0:n?aA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&rA(t,i,o),o};const cA=O("debugpost"),Z0={};function rs(s,t){Z0[s]=t}function hA(s){return s.__type in Z0?Z0[s.__type]:(cA&&s.__type&&console.warn("Unknown postprocessing type",s.__type,s),dt)}class Ih{constructor(){a(this,"components",[])}init(){var t;(t=this.components)==null||t.forEach(i=>i.init())}addEffect(t){this.components.push(t)}removeEffect(t){const i=this.components.indexOf(t);i>=0&&this.components.splice(i,1)}}lA([$a([s=>hA(s),dt])],Ih.prototype,"components",2);var dA=Object.defineProperty,uA=Object.getOwnPropertyDescriptor,pA=(s,t,i,n)=>{for(var o=n>1?void 0:n?uA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&dA(t,i,o),o};class jh extends dt{constructor(){super(...arguments),a(this,"preset",new N(2))}get typeName(){return"Antialiasing"}onCreateEffect(){const t=new D.POSTPROCESSING.MODULE.SMAAEffect({preset:D.POSTPROCESSING.MODULE.SMAAPreset.HIGH,edgeDetectionMode:D.POSTPROCESSING.MODULE.EdgeDetectionMode.DEPTH});return this.preset.onValueChanged=i=>{t.applyPreset(i)},t}}pA([m(N)],jh.prototype,"preset",2),rs("Antialiasing",jh);var mA=Object.defineProperty,gA=Object.getOwnPropertyDescriptor,J0=(s,t,i,n)=>{for(var o=n>1?void 0:n?gA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&mA(t,i,o),o},ey;const p1=(ey=class extends dt{constructor(){super(...arguments),a(this,"threshold",new N(.9)),a(this,"intensity",new N(1)),a(this,"scatter",new N(.3)),a(this,"selectiveBloom")}get typeName(){return"Bloom"}init(){this.threshold.valueProcessor=s=>s,this.intensity.valueProcessor=s=>s,this.scatter.valueProcessor=s=>s}onCreateEffect(){let s;if(this.selectiveBloom==null&&(this.selectiveBloom=p1.useSelectiveBloom),this.selectiveBloom){const t=s=new D.POSTPROCESSING.MODULE.SelectiveBloomEffect(this.context.scene,this.context.mainCamera,{blendFunction:D.POSTPROCESSING.MODULE.BlendFunction.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,radius:.85,intensity:this.intensity.value});t.inverted=!0}else s=new D.POSTPROCESSING.MODULE.BloomEffect({blendFunction:D.POSTPROCESSING.MODULE.BlendFunction.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,radius:.85,intensity:this.intensity.value});return this.intensity.onValueChanged=t=>{s.intensity=t},this.threshold.onValueChanged=t=>{s.luminanceMaterial.threshold=Math.pow(t,2.2)},this.scatter.onValueChanged=t=>{s.luminancePass.enabled=!0,s.luminanceMaterial.smoothing=t,s.mipmapBlurPass&&(s.mipmapBlurPass.radius=vn.lerp(.1,.9,t))},s}},a(ey,"useSelectiveBloom",!1),ey);let sa=p1;J0([m(N)],sa.prototype,"threshold",2),J0([m(N)],sa.prototype,"intensity",2),J0([m(N)],sa.prototype,"scatter",2),rs("Bloom",sa);var fA=Object.defineProperty,yA=Object.getOwnPropertyDescriptor,vA=(s,t,i,n)=>{for(var o=n>1?void 0:n?yA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&fA(t,i,o),o};class Dh extends dt{constructor(){super(...arguments),a(this,"intensity",new N(0))}get typeName(){return"ChromaticAberration"}onCreateEffect(){const t=new D.POSTPROCESSING.MODULE.ChromaticAberrationEffect;return t.offset=new oe(0,0),t.radialModulation=!0,t.modulationOffset=.15,this.intensity.valueProcessor=i=>i*.02,this.intensity.onValueChanged=i=>{t.offset.x=-i,t.offset.y=i},t}}vA([m(N)],Dh.prototype,"intensity",2),rs("ChromaticAberration",Dh);var bA=Object.defineProperty,_A=Object.getOwnPropertyDescriptor,m1=(s,t,i,n)=>{for(var o=n>1?void 0:n?_A(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&bA(t,i,o),o};const g1=O("debugpost");var Bp=(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))(Bp||{});function ty(s){switch(s){case 0:return fd;case 1:return _m;case 2:return bm;case 3:return gd;case 4:return Yl;default:return Yl}}function wA(s){switch(s){case fd:return 0;case bm:return 2;case gd:return 3;case Yl:return 1;case _m:return 1;default:return 0}}function f1(s){switch(s){case fd:return D.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;case bm:return D.POSTPROCESSING.MODULE.ToneMappingMode.ACES_FILMIC;case gd:return D.POSTPROCESSING.MODULE.ToneMappingMode.AGX;case Yl:return D.POSTPROCESSING.MODULE.ToneMappingMode.NEUTRAL;case _m:return D.POSTPROCESSING.MODULE.ToneMappingMode.REINHARD;default:return D.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR}}const y1=class extends dt{constructor(){super(...arguments),a(this,"mode",new N(void 0)),a(this,"exposure",new N(1))}get typeName(){return"ToneMapping"}setMode(s){const t=Bp[s];return t===void 0?(console.error("Invalid ToneMapping mode",s),this):(this.mode.value=t,this)}get isToneMapping(){return!0}onEffectEnabled(){const s=d1(this);s&&super.onEffectEnabled(s)}onCreateEffect(){if(this.postprocessingContext)for(const i of this.postprocessingContext.components){if(i===this)break;if(i!=this&&i instanceof y1){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=wA(this.context.renderer.toneMapping);this.mode.initialize(i)}const s=ty(this.mode.value),t=new D.POSTPROCESSING.MODULE.ToneMappingEffect({mode:f1(s)});return this.mode.onValueChanged=i=>{const n=ty(i);t.mode=f1(n),g1&&console.log("ToneMapping mode changed to",Bp[i],n,t.mode)},g1&&console.log("Use ToneMapping",Bp[this.mode.value],s,t.mode,"renderer.tonemapping: "+this.context.renderer.toneMapping),this.exposure.onValueChanged=i=>{this.context.renderer.toneMappingExposure=i},t}onBeforeRender(){this.mode.overrideState&&(this.context.renderer.toneMapping=ty(this.mode.value)),this.exposure.overrideState&&(this.context.renderer.toneMappingExposure=this.exposure.value)}};let Jo=y1;m1([m(N)],Jo.prototype,"mode",2),m1([m(N)],Jo.prototype,"exposure",2),rs("Tonemapping",Jo);var xA=Object.defineProperty,SA=Object.getOwnPropertyDescriptor,Fp=(s,t,i,n)=>{for(var o=n>1?void 0:n?SA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&xA(t,i,o),o};class er extends dt{constructor(){super(...arguments),a(this,"postExposure",new N(0)),a(this,"contrast",new N(0)),a(this,"hueShift",new N(0)),a(this,"saturation",new N(0))}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=t=>(t=Math.pow(2,t),t),this.contrast.valueProcessor=t=>{let i=1;return t>0?i=200:t<0&&(i=100),t/i},this.contrast.defaultValue=0,this.hueShift.valueProcessor=t=>Math.PI*t/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=t=>t<0?t/100:t/(100*Math.PI),this.saturation.defaultValue=0}onCreateEffect(){var t,i;const n=[];this.context.renderer.toneMapping!==wa&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=wa);let o=(t=this.postprocessingContext)==null?void 0:t.components.find(c=>c instanceof Jo);o||(o=new Jo,(i=this.postprocessingContext)==null||i.components.push(o)),this.postExposure.onValueChanged=c=>{this.postExposure.overrideState&&(o.exposure.value=c)};const r=new D.POSTPROCESSING.MODULE.BrightnessContrastEffect;this.contrast.onValueChanged=c=>r.contrast=c;const l=new D.POSTPROCESSING.MODULE.HueSaturationEffect;return n.push(r),n.push(l),this.hueShift.onValueChanged=c=>l.hue=c,this.saturation.onValueChanged=c=>l.saturation=c,n}}Fp([m(N)],er.prototype,"postExposure",2),Fp([m(N)],er.prototype,"contrast",2),Fp([m(N)],er.prototype,"hueShift",2),Fp([m(N)],er.prototype,"saturation",2),rs("ColorAdjustments",er);var CA=Object.defineProperty,OA=Object.getOwnPropertyDescriptor,na=(s,t,i,n)=>{for(var o=n>1?void 0:n?OA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&CA(t,i,o),o};const PA=O("debugpost");class As extends dt{constructor(){super(...arguments),a(this,"mode"),a(this,"focusDistance",new N(1)),a(this,"focalLength",new N(.2)),a(this,"aperture",new N(20)),a(this,"gaussianMaxRadius",new N),a(this,"resolutionScale",new N(1*1/window.devicePixelRatio)),a(this,"bokehScale",new N)}get typeName(){return"DepthOfField"}init(){this.focalLength.valueProcessor=i=>{const n=i/300,o=2;return W.lerp(o,.01,n)};const t=20;this.aperture.valueProcessor=i=>{const n=1-i/32;return W.lerp(1,t,n)}}onCreateEffect(){if(this.mode===0){PA&&console.warn("DepthOfField: Mode is set to Off");return}const t=new D.POSTPROCESSING.MODULE.DepthOfFieldEffect(this.context.mainCamera,{worldFocusRange:.2,focalLength:1,bokehScale:20,resolutionScale:this.resolutionScale.value});return this.focusDistance.onValueChanged=i=>{t.cocMaterial.worldFocusDistance=i},this.focalLength.onValueChanged=i=>t.cocMaterial.worldFocusRange=i,this.aperture.onValueChanged=i=>t.bokehScale=i,this.resolutionScale&&(this.resolutionScale.onValueChanged=i=>t.resolution.scale=i),[t]}unapply(){}}na([m()],As.prototype,"mode",2),na([m(N)],As.prototype,"focusDistance",2),na([m(N)],As.prototype,"focalLength",2),na([m(N)],As.prototype,"aperture",2),na([m(N)],As.prototype,"gaussianMaxRadius",2),na([m(N)],As.prototype,"resolutionScale",2),na([m(N)],As.prototype,"bokehScale",2),rs("DepthOfField",As);class Lh extends dt{constructor(t){super(),a(this,"effect"),this.effect=t}get typeName(){return this.effect.constructor.name}onCreateEffect(){return this.effect}}var kA=Object.defineProperty,MA=Object.getOwnPropertyDescriptor,RA=(s,t,i,n)=>{for(var o=n>1?void 0:n?MA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&kA(t,i,o),o};class Bh extends dt{constructor(){super(...arguments),a(this,"granularity",new N(10))}get typeName(){return"PixelationEffect"}onCreateEffect(){const t=new D.POSTPROCESSING.MODULE.PixelationEffect;return this.granularity.onValueChanged=i=>{t.granularity=i},t}}RA([m(N)],Bh.prototype,"granularity",2),rs("PixelationEffect",Bh);var TA=Object.defineProperty,EA=Object.getOwnPropertyDescriptor,Fh=(s,t,i,n)=>{for(var o=n>1?void 0:n?EA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&TA(t,i,o),o};class Gn extends dt{constructor(){super(...arguments),a(this,"intensity",new N(2)),a(this,"falloff",new N(1)),a(this,"samples",new N(9)),a(this,"color",new N(new re(0,0,0))),a(this,"luminanceInfluence",new N(.7)),a(this,"_ssao")}get typeName(){return"ScreenSpaceAmbientOcclusion"}onBeforeRender(){if(this._ssao&&this.context.mainCamera instanceof we){const t=this.context.mainCamera.far-this.context.mainCamera.near;this._ssao.ssaoMaterial.worldDistanceFalloff=t*.01,this._ssao.ssaoMaterial.worldDistanceThreshold=this.context.mainCamera.far}}onCreateEffect(){const t=this.context.mainCamera,i=new D.POSTPROCESSING.MODULE.NormalPass(this.context.scene,t),n=new D.POSTPROCESSING.MODULE.DepthDownsamplingPass({normalBuffer:i.texture,resolutionScale:.5}),o=this._ssao=new D.POSTPROCESSING.MODULE.SSAOEffect(t,i.texture,{normalDepthBuffer:n.texture,worldDistanceThreshold:1,worldDistanceFalloff:1,worldProximityThreshold:.1,worldProximityFalloff:2,intensity:1,blendFunction:D.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 re),o.color.copy(l)},this.luminanceInfluence.onValueChanged=l=>{o.luminanceInfluence=l};const r=new Array;return r.push(i),r.push(n),r.push(o),r}}Fh([m(N)],Gn.prototype,"intensity",2),Fh([m(N)],Gn.prototype,"falloff",2),Fh([m(N)],Gn.prototype,"samples",2),Fh([m(N)],Gn.prototype,"color",2),Fh([m(N)],Gn.prototype,"luminanceInfluence",2),rs("ScreenSpaceAmbientOcclusion",Gn);var AA=Object.defineProperty,IA=Object.getOwnPropertyDescriptor,oa=(s,t,i,n)=>{for(var o=n>1?void 0:n?IA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&AA(t,i,o),o},iy=(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))(iy||{});class Is extends dt{constructor(){super(...arguments),a(this,"gammaCorrection",!0),a(this,"aoRadius",new N(1)),a(this,"falloff",new N(1)),a(this,"intensity",new N(1)),a(this,"color",new N(new re(0,0,0))),a(this,"screenspaceRadius",!1),a(this,"quality",2),a(this,"_ssao")}get typeName(){return"ScreenSpaceAmbientOcclusionN8"}onValidate(){this._ssao&&(this._ssao.setQualityMode(iy[this.quality]),this._ssao.configuration.gammaCorrection=this.gammaCorrection,this._ssao.configuration.screenSpaceRadius=this.screenspaceRadius)}onCreateEffect(){const t=this.context.mainCamera,i=this._ssao=new D.POSTPROCESSING_AO.MODULE.N8AOPostPass(this.context.scene,t,this.context.domWidth,this.context.domHeight),n=iy[this.quality];i.setQualityMode(n),i.configuration.gammaCorrection=this.gammaCorrection,i.configuration.screenSpaceRadius=this.screenspaceRadius,this.intensity.onValueChanged=r=>{i.configuration.intensity=r},this.falloff.onValueChanged=r=>{i.configuration.distanceFalloff=r},this.aoRadius.onValueChanged=r=>{i.configuration.aoRadius=r},this.color.onValueChanged=r=>{i.color||(i.color=new re),i.configuration.color.copy(r)};const o=new Array;return o.push(i),o}}oa([Rt(),m()],Is.prototype,"gammaCorrection",2),oa([m(N)],Is.prototype,"aoRadius",2),oa([m(N)],Is.prototype,"falloff",2),oa([m(N)],Is.prototype,"intensity",2),oa([m(N)],Is.prototype,"color",2),oa([Rt(),m()],Is.prototype,"screenspaceRadius",2),oa([Rt(),m()],Is.prototype,"quality",2),rs("ScreenSpaceAmbientOcclusionN8",Is);var jA=Object.defineProperty,DA=Object.getOwnPropertyDescriptor,v1=(s,t,i,n)=>{for(var o=n>1?void 0:n?DA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&jA(t,i,o),o};class zh extends dt{constructor(){super(...arguments),a(this,"_effect"),a(this,"_amount",1),a(this,"_radius",1)}get typeName(){return"Sharpening"}onCreateEffect(){return this._effect??(this._effect=new(LA())),this.effect}get effect(){return this._effect}set amount(t){this._amount=t,this._effect&&(this._effect.uniforms.get("amount").value=t)}get amount(){return this._effect?this._effect.uniforms.get("amount").value:this._amount}set radius(t){this._radius=t,this._effect&&(this._effect.uniforms.get("radius").value=t)}get radius(){return this._effect?this._effect.uniforms.get("radius").value:this._radius}}v1([m()],zh.prototype,"amount",1),v1([m()],zh.prototype,"radius",1);function LA(){const s=`
|
|
1205
|
+
`)}l&&r.size&&console.log(p);const f=new Set;for(const w of y){w.getPath||console.error("USDZExporter: Animation target object has no getPath method. This is likely a bug",w);let _=w.getPath();_.startsWith("<")&&(_=_.substring(1)),_.endsWith(">")&&(_=_.substring(0,_.length-1)),f.add({path:_,obj:w})}const v=Array.from(f).sort((w,_)=>w.path.length-_.path.length),b=new Array;for(let w=0;w<v.length;w++)for(let _=w+1;_<v.length;_++)if(v[_].path.startsWith(v[w].path)){const C=v[_],R=v[w];b.push({child:C.obj.displayName+" ("+C.path+")",parent:R.obj.displayName+" ("+R.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:r})}for(const p of new Set([...i,...n]))if(Array.isArray(p))for(const g of p)o.add(g.uuid);else o.add(p.uuid);dp&&console.log("All Behavior trigger sources and action targets",i,n,o),this.targetUuids=new Set(o)}onAfterHierarchy(t,i){var n;if((n=this.behaviours)!=null&&n.length){i.beginBlock('def Scope "Behaviors"');for(const o of this.behaviours)o.writeTo(this,t.document,i);i.closeBlock()}}async onAfterSerialize(t){dp&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const i of this.behaviourComponentsCopy)typeof i.afterSerialize=="function"&&(i.afterSerialize.constructor.name==="AsyncFunction"?await i.afterSerialize(this,t):i.afterSerialize(this,t));for(const{clipUrl:i,filesKey:n}of this.audioClipsCopy){if(t.files[n])return;const o=await(await(await fetch(i)).blob()).arrayBuffer(),r=new Uint8Array(o);t.files[n]=r}this.behaviourComponentsCopy.length=0,this.audioClipsCopy.length=0}}var mT=Object.defineProperty,gT=Object.getOwnPropertyDescriptor,$e=(s,t,i,n)=>{for(var o=n>1?void 0:n?gT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&mT(t,i,o),o};const Ux=O("debugusdzbehaviours");function hh(s){s&&(s.getComponentInParent(Xa)||(F()&&console.debug('Raycaster on "'+s.name+'" was automatically added, because no raycaster was found in the parent hierarchy.'),s.addComponent(Ei)))}class qr extends A{constructor(){super(...arguments),a(this,"object"),a(this,"target"),a(this,"duration",1),a(this,"relativeMotion",!1),a(this,"coroutine",null),a(this,"targetPos",new x),a(this,"targetRot",new V),a(this,"targetScale",new x)}start(){hh(this.gameObject)}onPointerClick(t){t.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 t=te(this.object).clone(),i=te(this.target).clone(),n=Oe(this.object).clone(),o=Oe(this.target).clone(),r=Je(this.object).clone(),l=Je(this.target).clone(),c=t.distanceTo(i),h=n.angleTo(o),d=r.distanceTo(l);if(c<.01&&h<.01&&d<.01){ut(this.object,i),Gi(this.object,o),Pa(this.object,l),this.coroutine=null;return}let u=0,p=0;for(;u<1;)u+=this.context.time.deltaTime/this.duration,u>1&&(u=1),p=u<.5?4*u*u*u:1-Math.pow(-2*u+2,3)/2,this.targetPos.lerpVectors(t,i,p),this.targetRot.slerpQuaternions(n,o,p),this.targetScale.lerpVectors(r,l,p),ut(this.object,this.targetPos),Gi(this.object,this.targetRot),Pa(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const t=this.object.position.clone(),i=this.object.quaternion.clone(),n=this.object.scale.clone(),o=this.target.position.clone(),r=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(r),this.targetScale.copy(this.object.scale).multiply(l);let c=0,h=0;for(;c<1;)c+=this.context.time.deltaTime/this.duration,c>1&&(c=1),h=c<.5?4*c*c*c:1-Math.pow(-2*c+2,3)/2,this.object.position.lerpVectors(t,this.targetPos,h),this.object.quaternion.slerpQuaternions(i,this.targetRot,h),this.object.scale.lerpVectors(n,this.targetScale,h),yield;this.coroutine=null}beforeCreateDocument(t){var i;if(this.target&&this.object&&this.gameObject){const n=new Et("Move to "+((i=this.target)==null?void 0:i.name),xt.tapTrigger(this.gameObject),ye.transformAction(this.object,this.target,this.duration,this.relativeMotion?"relative":"absolute"));t.addBehavior(n)}}}$e([m(I)],qr.prototype,"object",2),$e([m(I)],qr.prototype,"target",2),$e([m()],qr.prototype,"duration",2),$e([m()],qr.prototype,"relativeMotion",2);var fl;const ti=(fl=class extends A{constructor(){super(...arguments),a(this,"materialToSwitch"),a(this,"variantMaterial"),a(this,"fadeDuration",0),a(this,"_objectsWithThisMaterial",null),a(this,"selfModel"),a(this,"targetModels")}start(){var s;this._objectsWithThisMaterial=this.objectsWithThisMaterial,hh(this.gameObject),F()&&this._objectsWithThisMaterial.length<=0&&console.warn('ChangeMaterialOnClick: No objects found with material "'+((s=this.materialToSwitch)==null?void 0:s.name)+'"')}onPointerEnter(s){this.context.input.setCursor("pointer")}onPointerExit(s){this.context.input.unsetCursor("pointer")}onPointerClick(s){if(s.use(),!!this.variantMaterial)for(let t=0;t<this.objectsWithThisMaterial.length;t++){const i=this.objectsWithThisMaterial[t];i.material=this.variantMaterial}}get objectsWithThisMaterial(){return this._objectsWithThisMaterial!=null?this._objectsWithThisMaterial:(this._objectsWithThisMaterial=[],this.variantMaterial&&this.materialToSwitch&&this.context.scene.traverse(s=>{if(s instanceof K)if(Array.isArray(s.material)){for(const t of s.material)if(t===this.materialToSwitch){this.objectsWithThisMaterial.push(s);break}}else s.material===this.materialToSwitch?this.objectsWithThisMaterial.push(s):m_(s.material,this.materialToSwitch)&&this.objectsWithThisMaterial.push(s)}),this._objectsWithThisMaterial)}async beforeCreateDocument(s,t){this.targetModels=[],ti._materialTriggersPerId={},ti.variantSwitchIndex=0,this.materialToSwitch&&await it.assignTextureLOD(this.materialToSwitch,0),this.variantMaterial&&await it.assignTextureLOD(this.variantMaterial,0)}createBehaviours(s,t,i){this.objectsWithThisMaterial.find(n=>n.uuid===t.uuid)&&this.targetModels.push(t),this.gameObject.uuid===t.uuid&&(this.selfModel=t,this.materialToSwitch&&(ti._materialTriggersPerId[this.materialToSwitch.uuid]||(ti._materialTriggersPerId[this.materialToSwitch.uuid]=[]),ti._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(s,t){if(!this.materialToSwitch)return;const i=ti._materialTriggersPerId[this.materialToSwitch.uuid];if(i){const n={};for(const o of i){const r=o.createVariants();r&&r.length>0&&(n[o.selfModel.uuid]=r)}for(const o of i){const r=[];for(const l in n)l!==o.selfModel.uuid&&r.push(...n[l]);o.createAndAttachBehaviors(s,n[o.selfModel.uuid],r)}}delete ti._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(s,t,i){const n=[],o=Math.max(0,this.fadeDuration);n.push(ye.fadeAction([...this.targetModels,...i],o,!1)),n.push(ye.fadeAction(t,o,!0)),s.addBehavior(new Et("Select_"+this.selfModel.name,xt.tapTrigger(this.selfModel),ye.parallel(...n))),ti._parallelStartHiddenActions.push(...t),ti._startHiddenBehaviour||(ti._startHiddenBehaviour=new Et("StartHidden_"+this.selfModel.name,xt.sceneStartTrigger(),ye.fadeAction(ti._parallelStartHiddenActions,o,!1)),s.addBehavior(ti._startHiddenBehaviour))}static getMaterialName(s){return Ts(s.name||"Material")+"_"+s.id}createVariants(){if(!this.variantMaterial)return null;const s=[];for(const t of this.targetModels){const i=t.clone();i.name+="_Variant_"+ti.variantSwitchIndex+++"_"+ti.getMaterialName(this.variantMaterial),i.displayName=i.displayName+": Variant with material "+this.variantMaterial.name,i.material=this.variantMaterial,i.geometry=t.geometry,i.transform=t.transform,(!t.parent||!t.parent.isEmpty())&&Zt.createEmptyParent(t),t.parent&&t.parent.add(i),s.push(i)}return s}},a(fl,"_materialTriggersPerId",{}),a(fl,"_startHiddenBehaviour",null),a(fl,"_parallelStartHiddenActions",[]),a(fl,"variantSwitchIndex",0),fl);let yl=ti;$e([m(ke)],yl.prototype,"materialToSwitch",2),$e([m(ke)],yl.prototype,"variantMaterial",2),$e([m()],yl.prototype,"fadeDuration",2);var vl;const qe=(vl=class extends A{constructor(){super(...arguments),a(this,"target"),a(this,"toggleOnClick",!1),a(this,"targetState",!0),a(this,"hideSelf",!0),a(this,"selfModel"),a(this,"selfModelClone"),a(this,"targetModel"),a(this,"toggleModel"),a(this,"stateBeforeCreatingDocument",!1),a(this,"targetStateBeforeCreatingDocument",!1)}start(){hh(this.gameObject)}onPointerClick(s){s.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(s,t,i){t.uuid===this.gameObject.uuid&&(this.selfModel=t,this.selfModelClone=t.clone())}beforeCreateDocument(){this.target&&(this.gameObject[qe.wasVisible]===void 0&&(this.gameObject[qe.wasVisible]=this.gameObject.activeSelf),this.target[qe.wasVisible]===void 0&&(this.target[qe.wasVisible]=this.target.activeSelf),this.stateBeforeCreatingDocument=this.gameObject[qe.wasVisible],this.targetStateBeforeCreatingDocument=this.target[qe.wasVisible],this.gameObject.visible=!0,this.target.visible=!0)}afterCreateDocument(s,t){if(!this.target)return;this.targetModel=t.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())&&Zf.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.deepClone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel);else{if(!this.gameObject[qe.toggleClone]){const c=this.selfModelClone.clone();c.setMatrix(new ne),c.name+="_toggle"+qe.clonedToggleIndex++,i.add(c),this.gameObject[qe.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[qe.toggleClone];if(!this.gameObject[qe.reverseToggleClone]){const c=this.selfModelClone.clone();c.setMatrix(new ne),c.name+="_toggleReverse"+qe.clonedToggleIndex++,i.add(c),this.gameObject[qe.reverseToggleClone]=c}this.toggleModel=this.gameObject[qe.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(ye.fadeAction(n,0,!1)),l.push(ye.fadeAction(this.toggleModel,0,!0)),l.push(ye.fadeAction(this.targetModel,0,o)),s.addBehavior(new Et("Toggle_"+n.name+"_ToggleTo"+(o?"On":"Off"),xt.tapTrigger(n),ye.parallel(...l)));const c=[];c.push(ye.fadeAction(this.toggleModel,0,!1)),c.push(ye.fadeAction(n,0,!0)),c.push(ye.fadeAction(this.targetModel,0,!o)),s.addBehavior(new Et("Toggle_"+n.name+"_ToggleTo"+(o?"Off":"On"),xt.tapTrigger(this.toggleModel),ye.parallel(...c)))}}else{const l=[];this.hideSelf&&l.push(ye.fadeAction(n,0,!1)),l.push(ye.fadeAction(this.targetModel,0,o)),s.addBehavior(new Et("Toggle_"+n.name+"_ToggleTo"+(o?"On":"Off"),xt.tapTrigger(n),l.length>1?ye.parallel(...l):l[0]))}const r=new Array;this.targetStateBeforeCreatingDocument||r.push(this.targetModel),this.stateBeforeCreatingDocument||r.push(i),this.toggleModel&&r.push(this.toggleModel),bl.add(r,s)}}afterSerialize(s,t){this.gameObject[qe.wasVisible]!==void 0&&(this.gameObject.visible=this.gameObject[qe.wasVisible],delete this.gameObject[qe.wasVisible]),this.target&&this.target[qe.wasVisible]!==void 0&&(this.target.visible=this.target[qe.wasVisible],delete this.target[qe.wasVisible]),delete this.gameObject[qe.toggleClone],delete this.gameObject[qe.reverseToggleClone]}},a(vl,"clonedToggleIndex",0),a(vl,"wasVisible",Symbol("usdz_SetActiveOnClick_wasVisible")),a(vl,"toggleClone",Symbol("clone for toggling")),a(vl,"reverseToggleClone",Symbol("clone for reverse toggling")),vl);let Gr=qe;$e([m(I)],Gr.prototype,"target",2),$e([m()],Gr.prototype,"toggleOnClick",2),$e([m()],Gr.prototype,"targetState",2),$e([m()],Gr.prototype,"hideSelf",2);const Do=class extends A{constructor(){super(...arguments),a(this,"wasVisible",!1)}static add(s,t){const i=Array.isArray(s)?s:[s];for(const n of i)Do._fadeObjects.includes(n)||(console.log("adding hide on start",n),Do._fadeObjects.push(n));Do._fadeBehaviour===void 0&&(Do._fadeBehaviour=new Et("HideOnStart",xt.sceneStartTrigger(),ye.fadeAction(Do._fadeObjects,0,!1)),t.addBehavior(Do._fadeBehaviour))}start(){P.setActive(this.gameObject,!1)}createBehaviours(s,t,i){t.uuid===this.gameObject.uuid&&(this.wasVisible||Do.add(t,s))}beforeCreateDocument(){this.wasVisible=P.isActiveSelf(this.gameObject)}};let bl=Do;a(bl,"_fadeBehaviour"),a(bl,"_fadeObjects",[]);class _l extends A{constructor(){super(...arguments),a(this,"target"),a(this,"duration",.5),a(this,"motionType","bounce")}beforeCreateDocument(){}createBehaviours(t,i,n){if(this.target&&i.uuid===this.gameObject.uuid){const o=new Et("emphasize "+this.name,xt.tapTrigger(this.gameObject),ye.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));t.addBehavior(o)}}afterCreateDocument(t,i){}}$e([m()],_l.prototype,"target",2),$e([m()],_l.prototype,"duration",2),$e([m()],_l.prototype,"motionType",2);class Lo extends A{constructor(){super(...arguments),a(this,"target"),a(this,"clip",""),a(this,"toggleOnClick",!1),a(this,"trigger","tap")}start(){hh(this.gameObject)}ensureAudioSource(){if(!this.target){const t=this.gameObject.addComponent(We);t&&(this.target=t,t.spatialBlend=1,t.volume=1,t.loop=!1,t.preload=!0)}}onPointerClick(t){var i;t.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(t,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 r=this.target?this.target.gameObject:this.gameObject;dr.getName(o);const l=this.target?this.target.volume:1,c=this.target&&this.target.spatialBlend==0?"nonSpatial":"spatial";let h=!1;this.gameObject.traverse(g=>{g instanceof K&&g.visible&&(h=!0)}),h=!0;const d=t.addAudioClip(o);let u=ye.playAudioAction(r,d,"play",l,c);this.target&&this.target.loop&&(u=ye.sequence(u).makeLooping());const p=this.name?"_"+this.name:"";if(h&&this.trigger==="tap"){this.toggleOnClick&&(u.multiplePerformOperation="stop");const g=new Et("playAudio"+p,xt.tapTrigger(i),u);t.addBehavior(g)}if(this.target&&this.target.playOnAwake&&this.target.enabled)if(h&&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 Et("playAudioOnStart"+p,xt.sceneStartTrigger(),u);t.addBehavior(g)}}}}$e([m(We)],Lo.prototype,"target",2),$e([m(URL)],Lo.prototype,"clip",2),$e([m()],Lo.prototype,"toggleOnClick",2);var pp;const nn=(pp=class extends A{constructor(){super(...arguments),a(this,"animator"),a(this,"stateName"),a(this,"trigger","tap"),a(this,"animation"),a(this,"selfModel"),a(this,"stateAnimationModel"),a(this,"animationSequence",new Array),a(this,"animationLoopAfterSequence",new Array),a(this,"randomOffsetNormalized",0)}get target(){var s,t;return((s=this.animator)==null?void 0:s.gameObject)||((t=this.animation)==null?void 0:t.gameObject)}start(){hh(this.gameObject)}onPointerClick(s){var t;s.use(),this.target&&this.stateName&&((t=this.animator)==null||t.play(this.stateName,0,0,.1))}createBehaviours(s,t,i){t.uuid===this.gameObject.uuid&&(this.selfModel=t)}afterSerialize(){if(nn.rootsWithExclusivePlayback.size>1){const s='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.';F()&&xe(s),console.warn(s,...nn.rootsWithExclusivePlayback)}nn.animationActions=[],nn.rootsWithExclusivePlayback=new Set}afterCreateDocument(s,t){if(this.animationSequence===void 0&&this.animationLoopAfterSequence===void 0||!this.stateAnimationModel||!this.target)return;const i=t.document,n=t.extensions.find(l=>l instanceof ch);if(!n)return;const o=n.getClipCount(this.target)>1;o&&(F()&&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."),nn.rootsWithExclusivePlayback.add(this.target));const r=this.name?this.name:"";i.traverse(l=>{var c,h;if(l.uuid===((c=this.target)==null?void 0:c.uuid)){const d=nn.getActionForSequences(i,l,this.animationSequence,this.animationLoopAfterSequence,this.randomOffsetNormalized),u=new Et(this.trigger+"_"+r+"_toPlayAnimation_"+this.stateName+"_on_"+((h=this.target)==null?void 0:h.name),this.trigger=="tap"?xt.tapTrigger(this.selfModel):xt.sceneStartTrigger(),d);o&&u.makeExclusive(!0),s.addBehavior(u)}})}static getActionForSequences(s,t,i,n,o){const r=(c,h)=>{let d=nn.animationActions.find(u=>u.affectedObjects==c&&u.start==h.start&&u.duration==h.duration&&u.animationSpeed==h.speed);return d||(d=ye.startAnimationAction(c,h),nn.animationActions.push(d)),d},l=ye.sequence();if(i&&i.length>0)for(const c of i)l.addAction(r(t,c));if(n&&n.length>0){const c=l.actions.length==0?l:ye.sequence();for(const h of n)c.addAction(r(t,h));c.makeLooping(),l!==c&&l.addAction(c)}return o&&o>0&&l.actions.unshift(ye.waitAction(o)),l}static getAndRegisterAnimationSequences(s,t,i){var n,o,r,l,c,h,d,u;if(!t)return;const p=t.getComponent(Mt),g=t.getComponent(Wt);if(!p&&!g)return;if(p&&!i)throw new Error("PlayAnimationOnClick: No stateName specified for animator "+p.name+" on "+t.name);let y=[],f=[];if(g){const M=s.registerAnimation(t,g.clip);M&&(g.loop?f.push(M):y.push(M));let T=0;if(g.minMaxOffsetNormalized){const j=g.minMaxOffsetNormalized.x,L=g.minMaxOffsetNormalized.y;T=(((n=g.clip)==null?void 0:n.duration)||1)*(j+Math.random()*(L-j))}return{animationSequence:y,animationLoopAfterSequence:f,randomTimeOffset:T}}const v=p?.runtimeAnimatorController;let b=v?.findState(i),w=[],_=[];if(v&&b){const M=new Array;M.push(b);let T=!1;for(;M.length<100;){if(!b||b===null||!b.transitions||b.transitions.length===0){(o=b.motion)!=null&&o.isLooping&&(T=!0);break}const j=b.transitions.find(U=>U.conditions.length===0),L=j?v.getState(j.destinationState,0):null;if(L&&M.includes(L)){b=L,T=!0;break}else if(j){if(b=L,!b)break;M.push(b)}else{T=((r=b.motion)==null?void 0:r.isLooping)??!1;break}}if(T&&b){const j=M.indexOf(b);w=M.slice(0,j),_=M.slice(j),Ux&&console.log("found loop from "+i,"states until loop",w,"states looping",_)}else w=M,_=[],Ux&&console.log("found no loop from "+i,"states",w);if(!_.length){const j=w[w.length-1],L=(l=j.motion)==null?void 0:l.clip;if(L){let U;if(s.holdClipMap.has(L))U=s.holdClipMap.get(L);else{const B=j.name+"_hold";U=L.clone(),U.duration=1,U.name=B;const Y=L.duration;U.tracks=L.tracks.map($=>{const E=$.clone();E.times=new Float32Array([0,Y]);const z=$.values.length,H=$.getValueSize(),se=$.values.slice(z-H,z);return E.values=new Float32Array(2*H),E.values.set(se,0),E.values.set(se,H),E}),U.name=B,s.holdClipMap.set(L,U)}if(U){const B={name:U.name,motion:{clip:U,isLooping:!1,name:U.name},speed:1,transitions:[],behaviours:[],hash:j.hash+1};_.push(B)}}}}if(w.length===1&&(!((c=w[0].motion)!=null&&c.clip)||((d=(h=w[0].motion)==null?void 0:h.clip.tracks)==null?void 0:d.length)===0)){y=new Array;const M=s.registerAnimation(t,null);M&&y.push(M);return}if(w=w.filter(M=>{var T,j,L;return((T=M.motion)==null?void 0:T.clip)&&((L=(j=M.motion)==null?void 0:j.clip.tracks)==null?void 0:L.length)>0}),_=_.filter(M=>{var T,j,L;return((T=M.motion)==null?void 0:T.clip)&&((L=(j=M.motion)==null?void 0:j.clip.tracks)==null?void 0:L.length)>0}),w.length===0&&_.length===0){console.warn("No clips found for state "+i+" on "+p?.name+", can't export animation data");return}const C=(M,T)=>{if(!t)return;const j=s.registerAnimation(t,M.motion.clip??null);j?(j.speed=M.speed,T.push(j)):console.warn("Couldn't register animation for state "+M.name+" on "+p?.name)};if(w.length>0){y=new Array;for(const M of w)C(M,y)}if(_.length>0){f=new Array;for(const M of _)C(M,f)}let R=0;if(p&&v&&p.minMaxOffsetNormalized){const M=p.minMaxOffsetNormalized.x,T=p.minMaxOffsetNormalized.y,j=w.length?w[0]:_.length?_[0]:null;R=(((u=j?.motion.clip)==null?void 0:u.duration)||1)*(M+Math.random()*(T-M))}return{animationSequence:y,animationLoopAfterSequence:f,randomTimeOffset:R}}createAnimation(s,t,i){if(!this.target||!this.animator&&!this.animation)return;const n=nn.getAndRegisterAnimationSequences(s,this.target,this.stateName);n&&(this.animationSequence=n.animationSequence,this.animationLoopAfterSequence=n.animationLoopAfterSequence,this.randomOffsetNormalized=n.randomTimeOffset,this.stateAnimationModel=t)}},a(pp,"animationActions",[]),a(pp,"rootsWithExclusivePlayback",new Set),pp);let Xr=nn;$e([m(Mt)],Xr.prototype,"animator",2),$e([m()],Xr.prototype,"stateName",2);class wl extends A{constructor(){super(...arguments),a(this,"target")}getType(){}getDuration(){}}$e([m(I)],wl.prototype,"target",2);class dh extends A{constructor(){super(...arguments),a(this,"target")}}$e([m(wl)],dh.prototype,"target",2);class uh extends wl{constructor(){super(...arguments),a(this,"type",1),a(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}$e([m()],uh.prototype,"type",2),$e([m()],uh.prototype,"duration",2);class d0 extends dh{}class mp{get extensionName(){return"Physics"}onExportObject(t,i,n){const o=P.getComponents(t,ve).filter(h=>h.enabled),r=P.getComponents(t,pi).filter(h=>h.enabled&&!h.isTrigger);let l=o.length>0?o[0]:null;const c=r.length>0?r[0]:null;c&&!l&&(l=new ve,l.isKinematic=!0),l&&i.addEventListener("serialize",(h,d)=>{var u,p,g;if(l){if(h.appendLine(),h.beginBlock('def RealityKitComponent "RigidBody"',"{",!0),l.useGravity||h.appendLine("bool gravityEnabled = 0"),h.appendLine('uniform token info:id = "RealityKit.RigidBody"'),l.isKinematic&&h.appendLine('token motionType = "Kinematic"'),h.beginBlock('def RealityKitStruct "massFrame"',"{",!0),h.appendLine(`float m_mass = ${l.mass}`),h.beginBlock('def RealityKitStruct "m_pose"',"{",!0),h.appendLine(`float3 position = (${l.centerOfMass.x}, ${l.centerOfMass.y}, ${l.centerOfMass.z})`),h.closeBlock("}"),h.closeBlock("}"),r.length>0){const y=r[0];h.beginBlock('def RealityKitStruct "material"',"{",!0);const f=y.sharedMaterial;f&&f.dynamicFriction!==void 0&&h.appendLine(`double dynamicFriction = ${(u=y.sharedMaterial)==null?void 0:u.dynamicFriction}`),f&&f.bounciness!==void 0&&h.appendLine(`double restitution = ${(p=y.sharedMaterial)==null?void 0:p.bounciness}`),f&&f.staticFriction!==void 0&&h.appendLine(`double staticFriction = ${(g=y.sharedMaterial)==null?void 0:g.staticFriction}`),h.closeBlock("}")}h.closeBlock("}")}}),c&&(i.addEventListener("serialize",(h,d)=>{var u;h.beginBlock('def RealityKitComponent "Collider"',"{",!0),h.appendLine("uint group = 1"),h.appendLine('uniform token info:id = "RealityKit.Collider"'),h.appendLine("uint mask = 4294967295");const p=c.isTrigger?"Trigger":"Default";if(h.appendLine(`token type = "${p}"`),h.beginBlock('def RealityKitStruct "Shape"',"{",!0),c instanceof tl){const g=c;h.appendLine('token shapeType = "Sphere"'),h.appendLine(`float radius = ${g.radius}`)}else if(c instanceof il){const g=c;h.appendLine('token shapeType = "Box"'),h.appendLine(`float3 extent = (${g.size.x}, ${g.size.y}, ${g.size.z})`)}else if(c instanceof In){const g=c;h.appendLine('token shapeType = "Capsule"'),h.appendLine(`float radius = ${g.radius}`),h.appendLine(`float height = ${g.height}`)}else if(c instanceof Ao&&(u=c.sharedMesh)!=null&&u.geometry){const g=c.sharedMesh.geometry;g.boundingBox||g.computeBoundingBox();const y=c.sharedMesh.geometry.boundingBox;y&&(h.appendLine('token shapeType = "Box"'),h.appendLine(`float3 extent = (${y.max.x-y.min.x}, ${y.max.y-y.min.y}, ${y.max.z-y.min.z})`),console.log("[USDZ] Only Box, Sphere, and Capsule colliders are supported in visionOS/iOS. MeshCollider will be exported as Box",c))}else console.warn("[USDZ] Only Box, Sphere, and Capsule colliders are supported in visionOS/iOS. Ignoring collider:",c);h.beginBlock('def RealityKitStruct "pose"',"{",!0),h.closeBlock("}"),h.closeBlock("}"),h.closeBlock("}")}),r.length>1&&console.log("WARNING: Multiple colliders detected. visionOS / iOS can only support objects with a single collider, only exporting the first collider: ",c))}}class u0{get extensionName(){return"DocumentExtension"}onAfterBuildDocument(t){}}var fT=Object.defineProperty,yT=Object.getOwnPropertyDescriptor,ph=(s,t,i,n)=>{for(var o=n>1?void 0:n?yT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&fT(t,i,o),o};const p0=O("debugui"),m0=O("debuguilayout");class g0{constructor(){a(this,"width"),a(this,"height")}}class f0{constructor(){a(this,"x"),a(this,"y"),a(this,"width"),a(this,"height")}}const Es=new x,mh=new ne,gp=new V,Nx=class extends ls{constructor(){super(...arguments),a(this,"_anchoredPosition"),a(this,"sizeDelta",new oe(100,100)),a(this,"pivot",new oe(.5,.5)),a(this,"anchorMin",new oe(0,0)),a(this,"anchorMax",new oe(1,1)),a(this,"minWidth"),a(this,"minHeight"),a(this,"lastMatrix"),a(this,"rectBlock"),a(this,"_transformNeedsUpdate",!1),a(this,"_initialPosition"),a(this,"_parentRectTransform"),a(this,"_lastUpdateFrame",-1),a(this,"_lastAnchoring"),a(this,"_createdBlocks",[]),a(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 oe),this._anchoredPosition}set anchoredPosition(s){this._anchoredPosition=s}get width(){let s=this.sizeDelta.x;if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const t=this._parentRectTransform.width,i=this.anchorMax.x-this.anchorMin.x;s=t*i,s+=this.sizeDelta.x}return this.minWidth!==void 0&&s<this.minWidth?this.minWidth:s}get height(){let s=this.sizeDelta.y;if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const t=this._parentRectTransform.height,i=this.anchorMax.y-this.anchorMin.y;s=t*i,s+=this.sizeDelta.y}return this.minHeight!==void 0&&s<this.minHeight?this.minHeight:s}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new oe),this.lastMatrix=new ne,this.rectBlock=new I,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,Ya(this,"_anchoredPosition",()=>{this.markDirty()}),Ya(this,"sizeDelta",()=>{this.markDirty()}),Ya(this,"pivot",()=>{this.markDirty()}),Ya(this,"anchorMin",()=>{this.markDirty()}),Ya(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var s;super.onEnable(),this.rectBlock||(this.rectBlock=new I),this.lastMatrix||(this.lastMatrix=new ne),this._lastAnchoring||(this._lastAnchoring=new oe),this._initialPosition||(this._initialPosition=new x),this._anchoredPosition||(this._anchoredPosition=new oe),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(s=this.canvas)==null||s.registerTransform(this)}onDisable(){var s;super.onDisable(),this.removeShadowComponent(),(s=this.canvas)==null||s.unregisterTransform(this)}onParentRectTransformChanged(s){this._transformNeedsUpdate||this.onApplyTransform(m0?`${s.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(m0&&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(s){var t;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const i=this.shadowComponent;if(!i)return;this.gameObject.parent?this._parentRectTransform=P.getComponentInParent(this.gameObject.parent,Nx):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,m0&&console.warn("RectTransform \u2192 ApplyTransform",this.name+" because "+s),this.isRoot()?this.Root.screenspace||(i.rotation.y=Math.PI):(i.matrix.identity(),i.matrixAutoUpdate=!1,Es.set(0,0,0),this.applyPivot(Es),i.matrix.setPosition(Es.x,Es.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(gp.copy(this.gameObject.quaternion),gp.x*=-1,gp.z*=-1,mh.makeRotationFromQuaternion(gp),i.matrix.premultiply(mh)),Es.set(0,0,0),this.applyAnchoring(Es),(t=this.canvas)!=null&&t.screenspace?Es.z+=.1:Es.z+=.01,mh.identity(),mh.setPosition(Es.x,Es.y,Es.z),i.matrix.premultiply(mh),i.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const n=!0;for(const o of ou(this.gameObject,ls,n,1)){if(o===this||!o.activeAndEnabled)continue;const r=o;r.onParentRectTransformChanged&&r.onParentRectTransformChanged(this)}}applyAnchoring(s){this._lastAnchoring||(this._lastAnchoring=new oe);const t=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=t.x,this.gameObject.position.y+=t.y,this._lastAnchoring.copy(this._anchoredPosition),s.x+=this._initialPosition.x-this.gameObject.position.x,s.y+=this._initialPosition.y-this.gameObject.position.y,s.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,s.y+=n;let r=0;const l=1-this.anchorMax.x-this.anchorMin.x;r-=i.width*.5*l,s.x+=r}}applyPivot(s){if(this.pivot&&!this.isRoot()){const t=this.pivot.x-.5;s.x-=t*this.sizeDelta.x*this.gameObject.scale.x;const i=this.pivot.y-.5;s.y-=i*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const s={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(s),s}ensureValidSize(s,t=1e-4){return s.width<=0&&(s.width=t),s.height<=0&&(s.height=1e-4),s}createNewBlock(s){s={...this.getBasicOptions(),...s},p0&&console.log(this.name,s);const t=new yv(s);return this._createdBlocks.push(t),t}createNewText(s){p0&&console.log(s),s={...this.getBasicOptions(),...s},p0&&console.log(this.name,s);const t=new fv(s);return this._createdTextBlocks.push(t),t}};let Ht=Nx;ph([m(oe)],Ht.prototype,"anchoredPosition",1),ph([m(oe)],Ht.prototype,"sizeDelta",2),ph([m(oe)],Ht.prototype,"pivot",2),ph([m(oe)],Ht.prototype,"anchorMin",2),ph([m(oe)],Ht.prototype,"anchorMax",2);var vT=Object.defineProperty,bT=Object.getOwnPropertyDescriptor,Wx=(s,t,i,n)=>{for(var o=n>1?void 0:n?bT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&vT(t,i,o),o};class xl extends A{constructor(){super(...arguments),a(this,"effectColor"),a(this,"effectDistance")}}Wx([m(Se)],xl.prototype,"effectColor",2),Wx([m(oe)],xl.prototype,"effectDistance",2);var _T=Object.defineProperty,wT=Object.getOwnPropertyDescriptor,Vx=(s,t,i,n)=>{for(var o=n>1?void 0:n?wT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&_T(t,i,o),o};const fp={backgroundColor:new re(1,1,1),backgroundOpacity:1,borderColor:new re(1,1,1),borderOpacity:1};var y0;const gh=(y0=class extends ls{constructor(){super(...arguments),a(this,"_alphaFactor",1),a(this,"sRGBColor",new re(1,0,1)),a(this,"raycastTarget",!0),a(this,"uiObject",null),a(this,"_color",null),a(this,"_rect",null),a(this,"_stateManager",null),a(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new Se(1,1,1,1)),this._color}set color(s){(!this._color||this._color.r!==s.r||this._color.g!==s.g||this._color.b!==s.b||this._color.alpha!==s.alpha)&&(this._color||(this._color=new Se(1,1,1,1)),this._color.copy(s),this.onColorChanged())}setAlphaFactor(s){this._alphaFactor=s,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(this.sRGBColor.copy(this._color),this.sRGBColor.convertLinearToSRGB(),fp.backgroundColor=this.sRGBColor,fp.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(fp,this._alphaFactor),this.uiObject.set(fp),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=P.getComponent(this.gameObject,Ht)),!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 s;(s=this.uiObject)==null||s.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(s){return super.__internalNewInstanceCreated(s),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone()),this}setState(s){this.makePanel(),this.uiObject&&(this.uiObject.setState(s),this==null||this.markDirty())}setupState(s){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new cO(this.uiObject)),this.uiObject.setupState(s.state,s.attributes))}setOptions(s){this.makePanel(),this.uiObject&&this.uiObject.set(s)}awake(){super.awake(),this.makePanel(),Ya(this,"_color",()=>vM(this,this.onColorChanged))}onEnable(){var s;super.onEnable(),this.uiObject&&((s=this.rectTransform.shadowComponent)==null||s.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 s=.015,t={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:s};this.onBeforeCreate(t),this.applyEffects(t),this.onCreate(t),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated(),this.onColorChanged()}onBeforeCreate(s){}onCreate(s){this.uiObject=this.rectTransform.createNewBlock(s),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(s,t=1){var i;const n=(i=this.gameObject)==null?void 0:i.getComponent(xl);n&&(n.effectDistance&&(s.borderWidth=Math.max(Math.abs(n.effectDistance.x),Math.abs(n.effectDistance.y))),n.effectColor&&(s.borderColor=n.effectColor,s.borderOpacity=n.effectColor.alpha*t))}async setTexture(s){if(this.setOptions({backgroundOpacity:0}),s){if(gh.textureCache.has(s))s=gh.textureCache.get(s);else if(!s.isRenderTargetTexture){const t=s.clone();t.colorSpace=mr,gh.textureCache.set(s,t),s=t}this.setOptions({backgroundImage:s,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"}),it.assignTextureLOD(s,0).then(t=>{t instanceof De&&(s&&gh.textureCache.set(s,t),this.setOptions({backgroundImage:t}),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)}},a(y0,"textureCache",new Map),y0);let Qr=gh;Vx([m(Se)],Qr.prototype,"color",1),Vx([m()],Qr.prototype,"raycastTarget",2);class fh extends Qr{constructor(){super(...arguments),a(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var xT=Object.defineProperty,ST=Object.getOwnPropertyDescriptor,Wn=(s,t,i,n)=>{for(var o=n>1?void 0:n?ST(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&xT(t,i,o),o};const Yr=O("debugtext");var gt=(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))(gt||{}),Hx=(s=>(s[s.Normal=0]="Normal",s[s.Bold=1]="Bold",s[s.Italic=2]="Italic",s[s.BoldAndItalic=3]="BoldAndItalic",s))(Hx||{});class $t extends Qr{constructor(){super(...arguments),a(this,"alignment",0),a(this,"verticalOverflow",0),a(this,"horizontalOverflow",0),a(this,"lineSpacing",1),a(this,"supportRichText",!1),a(this,"font"),a(this,"fontStyle",0),a(this,"sRGBTextColor",new re(1,0,1)),a(this,"_text",""),a(this,"_fontSize",12),a(this,"_textMeshUi",null),a(this,"_didHandleTextRenderOnTop",!1)}setAlphaFactor(t){var i;super.setAlphaFactor(t),(i=this.uiObject)==null||i.set({fontOpacity:this.color.alpha*this.alphaFactor}),this.markDirty()}get text(){return this._text}set text(t){t!==this._text&&(this._text=t,this.feedText(this.text,this.supportRichText),this.markDirty())}set_text(t){this.text=t}get fontSize(){return this._fontSize}set fontSize(t){var i;this._fontSize=t,(i=this.uiObject)==null||i.set({fontSize:t})}onColorChanged(){var t;this.sRGBTextColor.copy(this.color),this.sRGBTextColor.convertLinearToSRGB(),(t=this.uiObject)==null||t.set({color:this.sRGBTextColor,fontOpacity:this.color.alpha})}onParentRectTransformChanged(){super.onParentRectTransformChanged(),this.uiObject&&this.updateOverflow()}onBeforeCanvasRender(t){this.updateOverflow()}updateOverflow(){var t;const i=(t=this.uiObject)==null?void 0:t._overflow;i&&(i._needsUpdate=!0)}onCreate(t){Yr&&console.log(this),this.horizontalOverflow==1&&(t.whiteSpace="pre"),this.verticalOverflow==0&&(this.context.renderer.localClippingEnabled=!0,t.overflow="hidden"),this.horizontalOverflow==1&&this.verticalOverflow==0,t.lineHeight=this.lineSpacing,delete t.backgroundOpacity,delete t.backgroundColor,Yr&&(t.backgroundColor=16750848,t.backgroundOpacity=.5);const i=this.rectTransform;t={...t,...this.getTextOpts()},this.getAlignment(t),Yr&&(t.backgroundColor=Math.random()*16777215,t.backgroundOpacity=.1),this.uiObject=i.createNewText(t),this.feedText(this.text,this.supportRichText)}onAfterAddedToScene(){super.onAfterAddedToScene(),this.handleTextRenderOnTop()}getTextOpts(){const t=this.fontSize,i={color:this.color,fontOpacity:this.color.alpha,fontSize:t,fontKerning:"normal"};return this.setFont(i,this.fontStyle),i}onEnable(){var t;super.onEnable(),this._didHandleTextRenderOnTop=!1,this.uiObject&&this.uiObject.addAfterUpdate(()=>{this.setShadowComponentOwner(this.uiObject),this.markDirty()}),setTimeout(()=>this.markDirty(),10),(t=this.canvas)==null||t.registerEventReceiver(this)}onDisable(){var t;super.onDisable(),(t=this.canvas)==null||t.unregisterEventReceiver(this)}getAlignment(t){switch(t.flexDirection="column",this.alignment){case 0:case 3:case 6:t.textAlign="left";break;case 1:case 4:case 7:t.textAlign="center";break;case 2:case 5:case 8:t.textAlign="right";break}switch(this.alignment){default:case 0:case 1:case 2:t.alignItems="start";break;case 3:case 4:case 5:t.alignItems="center";break;case 6:case 7:case 8:t.alignItems="end";break}return t}feedText(t,i){var n,o,r;if(Yr&&console.log("feedText",this.uiObject,t,i),!!this.uiObject)if(this._textMeshUi||(this._textMeshUi=[]),this.uiObject.children.length=0,!i||t.length===0)this.uiObject.textContent=t;else{let l=this.getNextTag(t);if(l){if(l.startIndex>0){for(let d=this.uiObject.children.length-1;d>=0;d--){const u=this.uiObject.children[d];u.isUI&&(this.uiObject.remove(u),u.clear())}const h=new Pm({textContent:t.substring(0,l.startIndex),color:"inherit"});this.uiObject.add(h)}}else{this.uiObject.textContent="",this.setOptions({textContent:t});return}const c=[];for(;l;){const h=this.getNextTag(t,l.endIndex),d={fontFamily:(n=this.uiObject)==null?void 0:n.get("fontFamily"),color:"inherit",textContent:""};if(h){d.textContent=this.getText(t,l,h),this.handleTag(l,d,c);const u=new Pm(d);(o=this.uiObject)==null||o.add(u)}else{d.textContent=t.substring(l.endIndex),this.handleTag(l,d,c);const u=new Pm(d);(r=this.uiObject)==null||r.add(u)}l=h}}}handleTextRenderOnTop(){this._didHandleTextRenderOnTop||(this._didHandleTextRenderOnTop=!0,this.startCoroutine(this.renderOnTopCoroutine()))}*renderOnTopCoroutine(){if(!this.canvas)return;const t=[],i=this.canvas,n={renderOnTop:i.renderOnTop,depthWrite:i.depthWrite,doubleSided:i.doubleSided};for(;;){let o=!1;if(this._textMeshUi)for(let r=0;r<this._textMeshUi.length;r++){if(t[r]===!0)continue;o=!0;const l=this._textMeshUi[r];l.textContent&&(Lu(l,n),t[r]=!0)}if(!o)break;yield}}handleTag(t,i,n){if(!t.isEndTag){if(t.type.includes("color")){const o=new v0(t,{color:i.color});if(n.push(o),t.type.length>6){const r=parseInt("0x"+t.type.substring(7));i.color=r}else i.color=new re(1,1,1)}else if(t.type=="b"){this.setFont(i,1);const o=new v0(t,{fontWeight:700});n.push(o)}else if(t.type=="i"){this.setFont(i,2);const o=new v0(t,{fontStyle:"italic"});n.push(o)}}}getText(t,i,n){return t.substring(i.endIndex,n.startIndex)}getNextTag(t,i=0){const n=t.indexOf("<",i),o=t.indexOf(">",n);if(n>=0&&o>=0){const r=t.substring(n+1,o);return{type:r,startIndex:n,endIndex:o+1,isEndTag:r.startsWith("/")}}return null}setFont(t,i){if(!this.font)return;const n=this.font,o=this.getFamilyNameWithCorrectSuffix(n,i);Yr&&console.log("Selected font family:"+o);let r=vv.getFontFamily(o);switch(r||(r=vv.addFontFamily(o)),t.fontFamily=r,i){default:case 0:t.fontWeight=400,t.fontStyle="normal";break;case 1:t.fontWeight=700,t.fontStyle="normal";break;case 2:t.fontWeight=400,t.fontStyle="italic";break;case 3:t.fontStyle="italic",t.fontWeight=400}let l=r.getVariant(t.fontWeight,t.fontStyle);if(!l){let c=o;c!=null&&c.endsWith("-msdf.json")||(c+="-msdf.json");let h=o;h!=null&&h.endsWith(".png")||(h+=".png"),l=r.addVariant(t.fontWeight,t.fontStyle,c,h),l?.addEventListener("ready",()=>{this.markDirty()})}}getFamilyNameWithCorrectSuffix(t,i){var n;const o=t.lastIndexOf("-");if(o<0)return t;const r=(n=t.substring(o+1))==null?void 0:n.toLowerCase();if(CT.includes(r))return Yr&&console.warn("Unsupported font style: "+r),t;const l=t.lastIndexOf("/");let c=t;l>=0&&(c=c.substring(l+1));const h=c[0]===c[0].toUpperCase(),d=t.substring(0,o);switch(Yr&&console.log("Select font: ",t,Hx[i],c,h,d),i){case 0:return h?d+"-Regular":d+"-regular";case 1:return h?d+"-Bold":d+"-bold";case 2:return h?d+"-Italic":d+"-italic";case 3:return h?d+"-BoldItalic":d+"-bolditalic";default:return t}}}Wn([m()],$t.prototype,"alignment",2),Wn([m()],$t.prototype,"verticalOverflow",2),Wn([m()],$t.prototype,"horizontalOverflow",2),Wn([m()],$t.prototype,"lineSpacing",2),Wn([m()],$t.prototype,"supportRichText",2),Wn([m(URL)],$t.prototype,"font",2),Wn([m()],$t.prototype,"fontStyle",2),Wn([m()],$t.prototype,"text",1),Wn([m()],$t.prototype,"fontSize",1);class v0{constructor(t,i){a(this,"tag"),a(this,"previousValues"),this.tag=t,this.previousValues=i}}const CT=["medium","mediumitalic","black","blackitalic","thin","thinitalic","extrabold","light","lightitalic","semibold"];class Bo{constructor(t){a(this,"id"),a(this,"content",""),a(this,"font",[]),a(this,"pointSize",144),a(this,"width"),a(this,"height"),a(this,"depth"),a(this,"wrapMode"),a(this,"horizontalAlignment"),a(this,"verticalAlignment"),a(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,i){var n;i.beginBlock(`def Preliminary_Text "${this.id}"`,"(",!1),i.appendLine('prepend apiSchemas = ["MaterialBindingAPI"]'),i.closeBlock(")"),i.beginBlock(),this.content&&i.appendLine(`string content = "${this.content}"`),(!this.font||this.font.length<=0)&&(this.font||(this.font=[]),(n=this.font)==null||n.push("sans-serif"));const o=this.font.map(r=>`"${r}"`).join(", ");i.appendLine(`string[] font = [ ${o} ]`),i.appendLine(`double pointSize = ${this.pointSize}`),typeof this.width=="number"&&i.appendLine(`double width = ${this.width}`),typeof this.height=="number"&&i.appendLine(`double height = ${this.height}`),typeof this.depth=="number"&&i.appendLine(`double depth = ${this.depth}`),this.wrapMode&&i.appendLine(`token wrapMode = "${this.wrapMode}"`),this.horizontalAlignment&&i.appendLine(`token horizontalAlignment = "${this.horizontalAlignment}"`),this.verticalAlignment&&i.appendLine(`token verticalAlignment = "${this.verticalAlignment}"`),this.material!==void 0&&i.appendLine(`rel material:binding = </StageRoot/Materials/${i0(this.material)}>`),i.closeBlock()}}a(Bo,"global_id",0);class yp{static singleLine(t,i,n){const o=new Bo("text_"+Bo.getId());return o.content=t,i&&(o.pointSize=i),n&&(o.depth=n),o}static multiLine(t,i,n,o,r,l){const c=new Bo("text_"+Bo.getId());return c.content=t,c.width=i,c.height=n,c.horizontalAlignment=o,c.verticalAlignment=r,l!==void 0&&(c.wrapMode=l),c}}const OT=new ne().makeRotationY(Math.PI),PT=new ne().makeScale(-1,1,-1);class yh{get extensionName(){return"text"}exportText(t,i,n){const o=P.getComponent(t,$t);if(!o)return;const r=P.getComponent(t,Ht);let l=100,c=100;r&&(l=r.width,c=r.height);const h=OT.clone();r&&h.premultiply(PT),i.setMatrix(h);const d=o.color.clone();i.material=new li({color:d,emissive:d}),i.addEventListener("serialize",(u,p)=>{let g=o.text;g=g.replace(/\r/g,""),g=g.replace(/\n/g,"\\n");const y=yp.multiLine(g,l,c,"center","bottom","flowing");this.setTextAlignment(y,o.alignment),this.setOverflow(y,o),i.material&&(y.material=i.material),y.pointSize=this.convertToTextSize(o.fontSize),y.depth=.001,y.writeTo(void 0,u)})}convertToTextSize(t){return 1/.0502*144*t}setOverflow(t,i){i.horizontalOverflow?t.wrapMode="singleLine":t.wrapMode="flowing"}setTextAlignment(t,i){switch(i){case gt.LowerLeft:case gt.MiddleLeft:case gt.UpperLeft:t.horizontalAlignment="left";break;case gt.LowerCenter:case gt.MiddleCenter:case gt.UpperCenter:t.horizontalAlignment="center";break;case gt.LowerRight:case gt.MiddleRight:case gt.UpperRight:t.horizontalAlignment="right";break}switch(i){case gt.LowerLeft:case gt.LowerCenter:case gt.LowerRight:t.verticalAlignment="bottom";break;case gt.MiddleLeft:case gt.MiddleCenter:case gt.MiddleRight:t.verticalAlignment="middle";break;case gt.UpperLeft:case gt.UpperCenter:case gt.UpperRight:t.verticalAlignment="top";break}}}var kT=Object.defineProperty,MT=Object.getOwnPropertyDescriptor,lt=(s,t,i,n)=>{for(var o=n>1?void 0:n?MT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&kT(t,i,o),o};const $x=O("debuguilayout");class Fo{constructor(){a(this,"left",0),a(this,"right",0),a(this,"top",0),a(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}lt([m()],Fo.prototype,"left",2),lt([m()],Fo.prototype,"right",2),lt([m()],Fo.prototype,"top",2),lt([m()],Fo.prototype,"bottom",2);class ji extends A{constructor(){super(...arguments),a(this,"_rectTransform",null),a(this,"_needsUpdate",!1),a(this,"childAlignment",0),a(this,"reverseArrangement",!1),a(this,"spacing",0),a(this,"padding"),a(this,"minWidth",0),a(this,"minHeight",0),a(this,"flexibleHeight",0),a(this,"flexibleWidth",0),a(this,"preferredHeight",0),a(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(t){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&($x&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){$x&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(Ht);const t=this.gameObject.getComponentInParent(At);t&&t.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const t=this.gameObject.getComponentInParent(At);t&&t.unregisterLayoutGroup(this)}set m_Spacing(t){t!==this.spacing&&(this._needsUpdate=!0,this.spacing=t)}get m_Spacing(){return this.spacing}}lt([m()],ji.prototype,"childAlignment",2),lt([m()],ji.prototype,"reverseArrangement",2),lt([m()],ji.prototype,"spacing",2),lt([m(Fo)],ji.prototype,"padding",2),lt([m()],ji.prototype,"minWidth",2),lt([m()],ji.prototype,"minHeight",2),lt([m()],ji.prototype,"flexibleHeight",2),lt([m()],ji.prototype,"flexibleWidth",2),lt([m()],ji.prototype,"preferredHeight",2),lt([m()],ji.prototype,"preferredWidth",2);class zo extends ji{constructor(){super(...arguments),a(this,"childControlHeight",!0),a(this,"childControlWidth",!0),a(this,"childForceExpandHeight",!1),a(this,"childForceExpandWidth",!1),a(this,"childScaleHeight",!1),a(this,"childScaleWidth",!1)}onCalculateLayout(t){var i;const n=this.primaryAxis,o=t.width;let r=o;const l=t.height;let c=l;r-=this.padding.horizontal,c-=this.padding.vertical,n==="x"?this.padding.horizontal:this.padding.vertical;const h=n==="x",d=h?"y":"x",u=h?this.childControlWidth:this.childControlHeight,p=h?this.childControlHeight:this.childControlWidth,g=h?this.childForceExpandWidth:this.childForceExpandHeight,y=h?this.childForceExpandHeight:this.childForceExpandWidth,f=h?c:r,v=h?o:l,b=.5*(h?this.childAlignment%3:Math.floor(this.childAlignment/3));let w=0;h?w+=this.padding.left:w+=this.padding.top;let _=0,C=0;for(let L=0;L<this.gameObject.children.length;L++){const U=this.gameObject.children[L],B=P.getComponent(U,Ht);B!=null&&B.activeAndEnabled&&(C+=1,h?_+=B.width:_+=B.height)}let R=0;const M=this.spacing*(C-1);if(g||u){let L=0;h?L=r-=M:L=c-=M,C>0&&(R=L/C)}let T=0;T+=this.padding.left,T-=this.padding.right,b!==0&&(w=v-_,w*=b,w-=M*b,h?(w-=this.padding.right*b,w+=this.padding.left*(1-b),w<this.padding.left&&(w=this.padding.left)):(w-=this.padding.bottom*b,w+=this.padding.top*(1-b),w<this.padding.top&&(w=this.padding.top)));let j=1;for(let L=0;L<this.gameObject.children.length;L++){const U=this.gameObject.children[L],B=P.getComponent(U,Ht);if(B!=null&&B.activeAndEnabled){(i=B.pivot)==null||i.set(.5,.5),B.anchorMin.set(0,1),B.anchorMax.set(0,1);const Y=o*.5+T*.5;B.anchoredPosition.x!==Y&&(B.anchoredPosition.x=Y);const $=l*-.5;B.anchoredPosition.y!==$&&(B.anchoredPosition.y=$),y&&p&&B.sizeDelta[d]!==f&&(B.sizeDelta[d]=f),g&&u&&B.sizeDelta[n]!==R&&(B.sizeDelta[n]=R);const E=h?B.width:B.height,z=E*.5;if(w+=z,g){const se=R*j-R*.5;se>w&&(w=se-R*.5+E+this.padding.left,w-=z)}let H=w;n==="y"&&(H=-H),B.anchoredPosition[n]!==H&&(B.anchoredPosition[n]=H),w+=z,w+=this.spacing,j+=1}}}}lt([m()],zo.prototype,"childControlHeight",2),lt([m()],zo.prototype,"childControlWidth",2),lt([m()],zo.prototype,"childForceExpandHeight",2),lt([m()],zo.prototype,"childForceExpandWidth",2),lt([m()],zo.prototype,"childScaleHeight",2),lt([m()],zo.prototype,"childScaleWidth",2);class b0 extends zo{get primaryAxis(){return"y"}}class _0 extends zo{get primaryAxis(){return"x"}}class w0 extends ji{onCalculateLayout(){}}var RT=Object.defineProperty,TT=Object.getOwnPropertyDescriptor,on=(s,t,i,n)=>{for(var o=n>1?void 0:n?TT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&RT(t,i,o),o},qx=(s=>(s[s.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",s[s.ScreenSpaceCamera=1]="ScreenSpaceCamera",s[s.WorldSpace=2]="WorldSpace",s[s.Undefined=-1]="Undefined",s))(qx||{});const x0=O("debuguilayout"),Gx=class extends Vc{constructor(){super(...arguments),a(this,"_renderOnTop"),a(this,"_depthWrite",!1),a(this,"_doubleSided",!0),a(this,"_castShadows",!1),a(this,"_receiveShadows",!1),a(this,"_renderMode",-1),a(this,"_rootCanvas"),a(this,"_scaleFactor",1),a(this,"worldCamera"),a(this,"planeDistance",-1),a(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this)),a(this,"previousParent",null),a(this,"_lastMatrixWorld",null),a(this,"_rectTransforms",[]),a(this,"_layoutGroups",new Map),a(this,"_receivers",[]),a(this,"onBeforeRenderRoutine",()=>{var s,t,i,n;if(this.previousParent=this.gameObject.parent,((s=this.context.xr)!=null&&s.isVR||(t=this.context.xr)!=null&&t.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(),ai.ensureUpdateMeshUI(bv,this.context))}),a(this,"onAfterRenderRoutine",()=>{var s,t,i,n,o;if(((s=this.context.xr)!=null&&s.isVR||(t=this.context.xr)!=null&&t.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?.add(this.gameObject)}else this.previousParent.add(this.gameObject);const r=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(),ai.ensureUpdateMeshUI(bv,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=r,this.context.renderer.autoClearColor=l,this.previousParent.add(this.gameObject)}(o=this._lastMatrixWorld)==null||o.copy(this.gameObject.matrixWorld)}),a(this,"_updateRenderSettingsRoutine"),a(this,"_activeRenderMode",-1),a(this,"_lastWidth",-1),a(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(s){s!==this._renderOnTop&&(this._renderOnTop=s,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(s){this._depthWrite!==s&&(this._depthWrite=s,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(s){this._doubleSided!==s&&(this._doubleSided=s,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(s){this._castShadows!==s&&(this._castShadows=s,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(s){this._receiveShadows!==s&&(this._receiveShadows=s,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(s){this._renderMode!==s&&(this._renderMode=s,this.onRenderSettingsChanged())}set rootCanvas(s){this._rootCanvas instanceof Gx||(this._rootCanvas=s)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(s){this._scaleFactor=s}awake(){var s;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,x0&&console.log("Canvas.Awake()",((s=this.previousParent)==null?void 0:s.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new ne,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 s=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);s!==-1&&this.context.pre_render_callbacks.splice(s,1);const t=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);t!==-1&&this.context.post_render_callbacks.splice(t,1)}registerTransform(s){this._rectTransforms.push(s)}unregisterTransform(s){const t=this._rectTransforms.indexOf(s);t!==-1&&this._rectTransforms.splice(t,1)}registerLayoutGroup(s){const t=s.gameObject;this._layoutGroups.set(t,s)}unregisterLayoutGroup(s){const t=s.gameObject;this._layoutGroups.delete(t)}registerEventReceiver(s){this._receivers.push(s)}unregisterEventReceiver(s){const t=this._receivers.indexOf(s);t!==-1&&this._receivers.splice(t,1)}async onEnterXR(s){this.screenspace?(s.xr.isVR||s.xr.isPassThrough)&&(this.gameObject.visible=!1):(this.gameObject.visible=!1,await ec(1).then(()=>{this.gameObject.visible=!0}))}onLeaveXR(s){this.screenspace&&(s.xr.isVR||s.xr.isPassThrough)&&(this.gameObject.visible=!0)}invokeBeforeRenderEvents(){var s;for(const t of this._receivers)(s=t.onBeforeCanvasRender)==null||s.call(t,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new ne);const s=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);x0&&s&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const t=!1;for(const i of this._rectTransforms){s&&i.markDirty();let n=this._layoutGroups.get(i.gameObject);i.isDirty&&!n&&(n=i.gameObject.getComponentInParent(ji)),(i.isDirty||n!=null&&n.isDirty)&&(x0&&!t&&console.log("CANVAS UPDATE ### "+i.name+" ##################################### "+this.context.time.frame),n?.updateLayout(),i.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),Me.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),Lu(this.shadowComponent,this);for(const s of P.getComponentsInChildren(this.gameObject,ls))Lu(s.shadowComponent,this)}}onUpdateRenderMode(s=!1){if(!s&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let t=this.context.mainCameraComponent,i=10;switch(t&&t.nearClipPlane>0&&t.farClipPlane>0&&(i=W.lerp(t.nearClipPlane,t.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(t=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,!t)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(Ht);let r=!1;o.sizeDelta.x!==this.context.domWidth&&(r=!0),o.sizeDelta.y!==this.context.domHeight&&(r=!0);const l=t.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,r&&(o.sizeDelta.x=this.context.domWidth,o.sizeDelta.y=this.context.domHeight,o?.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let At=Gx;on([m()],At.prototype,"renderOnTop",1),on([m()],At.prototype,"depthWrite",1),on([m()],At.prototype,"doubleSided",1),on([m()],At.prototype,"castShadows",1),on([m()],At.prototype,"receiveShadows",1),on([m()],At.prototype,"renderMode",1),on([m(At)],At.prototype,"rootCanvas",1),on([m()],At.prototype,"scaleFactor",1),on([m(Pe)],At.prototype,"worldCamera",2),on([m()],At.prototype,"planeDistance",2);var ET=Object.defineProperty,AT=Object.getOwnPropertyDescriptor,S0=(s,t,i,n)=>{for(var o=n>1?void 0:n?AT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&ET(t,i,o),o};class Uo extends A{constructor(){super(...arguments),a(this,"_alpha",1),a(this,"interactable",!0),a(this,"blocksRaycasts",!0),a(this,"_isDirty",!1),a(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(t){t!==this._alpha&&(this._alpha=t,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),Me.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){this._buffer.length=0;for(const t of P.getComponentsInChildren(this.gameObject,ls,this._buffer)){const i=t;i.setAlphaFactor&&i.setAlphaFactor(this._alpha)}}}S0([m()],Uo.prototype,"alpha",1),S0([m()],Uo.prototype,"interactable",2),S0([m()],Uo.prototype,"blocksRaycasts",2);class vp{get extensionName(){return"tmui"}onExportObject(t,i,n){const o=P.getComponent(t,At);if(o&&o.enabled&&o.renderMode===qx.WorldSpace){const r=new yh,l=P.getComponent(t,Ht),c=P.getComponent(t,Uo),h=new Array;if(l){if(!P.isActiveSelf(t)){const p=P.isActiveSelf(t);P.setActive(t,!0),l.onEnable(),l.updateTransform(),h.push(()=>{l.onDisable(),P.setActive(t,p)})}t.traverse(p=>{if(!P.isActiveInHierarchy(p)){const g=P.isActiveSelf(p);P.setActive(p,!0);const y=P.getComponent(p,ls);y&&(y.onEnable(),h.push(()=>{y.onDisable()}));const f=P.getComponent(p,Ht);f&&(f.onEnable(),f.updateTransform(),f.onApplyTransform(),h.push(()=>{f.onDisable()}));const v=P.getComponent(p,$t);v&&(v.onEnable(),h.push(()=>{v.onDisable()})),h.push(()=>{P.setActive(p,g)})}}),l.width,l.height;const d=Zt.createEmpty(),u=l.shadowComponent;if(i.add(d),u){const p=u.matrix;d.setMatrix(p);const g=new Map,y=new Map;g.set(u,d),y.set(u,c?c.alpha:1),u.traverse(f=>{if(f===u)return;const v=Zt.createEmpty();v.setMatrix(f.matrix);const b=f.parent,w=!!b&&typeof b.textContent=="string"&&b.textContent.length>0;let _=y.get(b)||1;const C=P.getComponent(f,Uo);if(C&&(_*=C.alpha),f instanceof K&&w){const M=f[ts];M?r.exportText(M.gameObject,v,n):console.error("Error when exporting UI: shadow component owner not found. This is likely a bug.",f)}if(f instanceof K&&!w){const M=f.geometry.clone();M.scale(1,1,-1),this.flipWindingOrder(M),v.geometry=M;const T=new re,j=f.material.opacity;T.copy(f.material.color),v.material=new Re({color:T,opacity:j*_,map:f.material.map,transparent:!0})}g.set(f,v),y.set(f,_);const R=g.get(b);if(!R){console.error("Error when exporting UI: shadow component parent not found!",f,f.parent);return}R.add(v)})}}for(const d of h)d()}}flipWindingOrder(t){const i=t.index.array;for(let n=0,o=i.length/3;n<o;n++){const r=i[n*3];i[n*3]=i[n*3+2],i[n*3+2]=r}t.index.needsUpdate=!0}}const Xx=class{constructor(){a(this,"_quicklookButton"),a(this,"_arButton"),a(this,"_vrButton"),a(this,"_sendToQuestButton")}static create(){return new Xx}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 Tn.getOrCreate().createQRCode()}createQuicklookButton(){if(this._quicklookButton)return this._quicklookButton;const s=document.createElement("button");this._quicklookButton=s,s.dataset.needle="quicklook-button";const t=X.supportsQuickLookAR();s.innerText="View in AR",s.prepend(kt("view_in_ar"));let i=!1,n=null;return s.addEventListener("click",()=>{n=Zd(Ge),n||(i=!0,n=new Ge),i&&(n.objectToExport=ee.Current.scene),n?(s.classList.add("this-mode-is-requested"),n.exportAndOpen().then(()=>{s.classList.remove("this-mode-is-requested")}).catch(o=>{s.classList.remove("this-mode-is-requested"),console.error(o)})):console.warn("No USDZExporter component found in the scene")}),this.hideElementDuringXRSession(s),s}createARButton(s){var t;if(this._arButton)return this._arButton;const i="immersive-ar",n=document.createElement("button");return this._arButton=n,n.classList.add("webxr-button"),n.dataset.needle="webxr-ar-button",n.innerText="Enter AR",n.prepend(kt("view_in_ar")),n.title="Click to start an AR session",n.addEventListener("click",()=>J.start(i,s)),this.updateSessionSupported(n,i),this.listenToXRSessionState(n,i),this.hideElementDuringXRSession(n),this.isSecureConnection||(n.disabled=!0,n.title="WebXR requires a secure connection (HTTPS)"),X.isMozillaXR()||(t=navigator.xr)==null||t.addEventListener("devicechange",()=>this.updateSessionSupported(n,i)),n}createVRButton(s){var t;if(this._vrButton)return this._vrButton;const i="immersive-vr",n=document.createElement("button");return this._vrButton=n,n.classList.add("webxr-button"),n.dataset.needle="webxr-vr-button",n.innerText="Enter VR",n.prepend(kt("panorama_photosphere")),n.title="Click to start a VR session",n.addEventListener("click",()=>J.start(i,s)),this.updateSessionSupported(n,i),this.listenToXRSessionState(n,i),this.hideElementDuringXRSession(n),this.isSecureConnection||(n.disabled=!0,n.title="WebXR requires a secure connection (HTTPS)"),X.isMozillaXR()||(t=navigator.xr)==null||t.addEventListener("devicechange",()=>this.updateSessionSupported(n,i)),n}createSendToQuestButton(){var s;if(this._sendToQuestButton)return this._sendToQuestButton;const t="https://oculus.com/open_url/?url=",i=document.createElement("button");return this._sendToQuestButton=i,i.dataset.needle="webxr-sendtoquest-button",i.innerText="Open on Quest",i.prepend(kt("share_windows")),i.title="Click to send this page to the Oculus Browser on your Quest",i.addEventListener("click",()=>{const n=encodeURIComponent(window.location.href),o=t+n;window.open(o)==null&&Le("This page doesn't allow popups. Please paste "+o+" into your browser.")}),this.listenToXRSessionState(i),this.hideElementDuringXRSession(i),X.isMozillaXR()||(s=navigator.xr)==null||s.addEventListener("devicechange",()=>{var n;(n=navigator.xr)!=null&&n.isSessionSupported("immersive-vr")?i.style.display="none":i.style.display=""}),i}createQRCode(){return Tn.getOrCreate().createQRCode()}updateSessionSupported(s,t){if(!("xr"in navigator)){s.style.display="none";return}J.isSessionSupported(t).then(i=>{s.style.display=i?"":"none",F()&&!i&&console.log('[WebXR] "'+t+'" is not supported on this device \u2013 make sure your server runs using HTTPS and you have a device connected that supports '+t)})}hideElementDuringXRSession(s){Ad(t=>{s["previous-display"]=s.style.display,s.style.display="none"}),ng(t=>{s["previous-display"]!=null&&(s.style.display=s["previous-display"])})}listenToXRSessionState(s,t){t&&(J.onSessionRequestStart(i=>{i.mode===t?s.classList.add("this-mode-is-requested"):(s["was-disabled"]=s.disabled,s.disabled=!0,s.classList.add("other-mode-is-requested"))}),J.onSessionRequestEnd(i=>{s.classList.remove("this-mode-is-requested"),s.classList.remove("other-mode-is-requested"),s.disabled=s["was-disabled"]}))}};let Kr=Xx;a(Kr,"_instance");var IT=Object.defineProperty,jT=Object.getOwnPropertyDescriptor,St=(s,t,i,n)=>{for(var o=n>1?void 0:n?jT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&IT(t,i,o),o};const bp=O("debugspriterenderer"),DT=O("wireframe"),C0=class{static getOrCreateGeometry(s){if(s.__cached_geometry)return s.__cached_geometry;if(s.guid&&C0.cache[s.guid])return bp&&console.log("Take cached geometry for sprite",s.guid),C0.cache[s.guid];const t=new bn;s.__cached_geometry=t;const i=new Float32Array(s.triangles.length*3),n=new Float32Array(s.triangles.length*2);for(let o=0;o<s.triangles.length;o+=1){const r=s.triangles[o];i[o*3]=-s.vertices[r].x,i[o*3+1]=s.vertices[r].y,i[o*3+2]=0;const l=s.uv[r];n[o*2]=l.x,n[o*2+1]=1-l.y}return t.setAttribute("position",new yt(i,3)),t.setAttribute("uv",new yt(n,2)),s.guid&&(this.cache[s.guid]=t),bp&&console.log("Built sprite geometry",s,t),t}};let vh=C0;a(vh,"cache",{});class LT{constructor(){a(this,"x"),a(this,"y")}}function Qx(s){s&&(s.colorSpace!=gs&&(s.colorSpace=gs,s.needsUpdate=!0),s.minFilter==md&&s.magFilter==md&&(s.anisotropy=1,s.needsUpdate=!0))}let rn=class{constructor(s){a(this,"guid"),a(this,"texture"),a(this,"triangles"),a(this,"uv"),a(this,"vertices"),a(this,"__cached_geometry"),a(this,"_mesh"),a(this,"_material"),s&&(this.texture=s,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 K(vh.getOrCreateGeometry(this),this.material)),this._mesh}get material(){return this._material||(this.texture&&Qx(this.texture),this._material=new Re({map:this.texture,color:16777215,side:xi,transparent:!0})),this._material}getGeometry(){return vh.getOrCreateGeometry(this)}};St([m()],rn.prototype,"guid",2),St([m(De)],rn.prototype,"texture",2),St([$a()],rn.prototype,"triangles",2),St([$a()],rn.prototype,"uv",2),St([$a()],rn.prototype,"vertices",2);const O0=Symbol("spriteOwner");class No{constructor(){a(this,"sprites")}}St([m(rn)],No.prototype,"sprites",2);const Yx=class{constructor(){a(this,"spriteSheet"),a(this,"index",0)}static create(){const s=new Yx;return s.spriteSheet=new No,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 No,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 i=this.spriteSheet.sprites[t],n=i?.texture;if(n&&(Qx(n),!i.__hasLoadedProgressive)){i.__hasLoadedProgressive=!0;const o=n;it.assignTextureLOD(n,0).then(r=>{r instanceof De&&(i.texture=r,s?.map===o&&(s.map=r,s.needsUpdate=!0))})}}};let Vn=Yx;St([m(No)],Vn.prototype,"spriteSheet",2),St([m()],Vn.prototype,"index",2);class fi extends A{constructor(){super(...arguments),a(this,"drawMode",0),a(this,"size",{x:1,y:1}),a(this,"color"),a(this,"sharedMaterial"),a(this,"transparent",!0),a(this,"cutoutThreshold",0),a(this,"castShadows",!1),a(this,"renderOrder",0),a(this,"toneMapped",!0),a(this,"_spriteSheet"),a(this,"_currentSprite")}set texture(t){var i;if(!this._spriteSheet)return;const n=(i=this._spriteSheet.spriteSheet)==null?void 0:i.sprites[this.spriteIndex];n&&(n.texture=t,this.updateSprite())}addSprite(t,i=!1){var n,o;if(this._spriteSheet||(this._spriteSheet=Vn.create()),!this._spriteSheet.spriteSheet)return-1;(n=this._spriteSheet.spriteSheet)==null||n.sprites.push(t);const r=((o=this._spriteSheet.spriteSheet)==null?void 0:o.sprites.length)-1;return i&&(this.spriteIndex=r),r}get sprite(){return this._spriteSheet}set sprite(t){if(t!==this._spriteSheet)if(typeof t=="number"){const i=Math.floor(t);this.spriteIndex=i;return}else t instanceof rn?(this._spriteSheet||(this._spriteSheet=Vn.create()),this._spriteSheet.sprite!=t&&(this._spriteSheet.sprite=t,this.updateSprite())):t!=this._spriteSheet&&(this._spriteSheet=t,this.updateSprite())}set spriteIndex(t){this._spriteSheet&&t!==this.spriteIndex&&(this._spriteSheet.index=t,this.updateSprite())}get spriteIndex(){var t;return((t=this._spriteSheet)==null?void 0:t.index)??0}get spriteFrames(){var t,i;return((i=(t=this._spriteSheet)==null?void 0:t.spriteSheet)==null?void 0:i.sprites.length)??0}awake(){this._currentSprite=void 0,this._spriteSheet||(this._spriteSheet=new Vn,this._spriteSheet.spriteSheet=new No),bp&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(t=!1){var i;if(!this.__didAwake&&!t)return!1;const n=this._spriteSheet;if(!((i=n?.spriteSheet)!=null&&i.sprites))return console.warn("SpriteRenderer has no data or spritesheet assigned..."),!1;const o=n.spriteSheet.sprites[this.spriteIndex];if(!o)return bp&&console.warn("Sprite not found",this.spriteIndex,n.spriteSheet.sprites),!1;if(this._currentSprite)this._currentSprite.geometry=vh.getOrCreateGeometry(o),this._currentSprite.material.map=o.texture;else{const r=new Re({color:16777215,side:xi});if(DT&&(r.wireframe=!0),this.color&&(r.color||(r.color=new re),r.color.copy(this.color),r.opacity=this.color.alpha),r.transparent=!0,r.toneMapped=this.toneMapped,o.texture&&!r.wireframe){let l=o.texture;l[O0]!==void 0&&l[O0]!==this&&this.spriteFrames>1&&(l=o.texture=l.clone()),l[O0]=this,r.map=l}this.sharedMaterial=r,this._currentSprite=new K(vh.getOrCreateGeometry(o),r),this._currentSprite.renderOrder=Math.round(this.renderOrder),it.assignTextureLOD(r,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,n?.update(this.sharedMaterial),!0}}St([m()],fi.prototype,"drawMode",2),St([m(LT)],fi.prototype,"size",2),St([m(Se)],fi.prototype,"color",2),St([m(ke)],fi.prototype,"sharedMaterial",2),St([m()],fi.prototype,"transparent",2),St([m()],fi.prototype,"cutoutThreshold",2),St([m()],fi.prototype,"castShadows",2),St([m()],fi.prototype,"renderOrder",2),St([m()],fi.prototype,"toneMapped",2),St([m(Vn)],fi.prototype,"sprite",1);const Kx=O("debugwebxr"),BT=new ne().makeRotationY(Math.PI);class Hn extends A{constructor(){super(...arguments),a(this,"_arScale",1),a(this,"invertForward",!1),a(this,"customReticle"),a(this,"arTouchTransform",!0),a(this,"autoPlace",!1),a(this,"autoCenter",!1),a(this,"useXRAnchor",!1),a(this,"_isPlacing",!0),a(this,"_startOffset",new ne),a(this,"_createdPlacementObject",null),a(this,"_reparentedComponents",[]),a(this,"_placementScene",new qi),a(this,"_reticle",[]),a(this,"_hits",[]),a(this,"_placementStartTime",-1),a(this,"_rigPlacementMatrix"),a(this,"_anchor",null),a(this,"userInput"),a(this,"onPlaceScene",t=>{var i;if(this._isPlacing==!1||t!=null&&t.used)return;let n=this._reticle[0];if(!n){console.warn("No reticle to place...");return}if(!n.visible&&!this.autoPlace){console.warn("Reticle is not visible (can not place)");return}if((i=J.active)!=null&&i.isTrackingImages){console.warn("Scene Placement is disabled while images are being tracked");return}let o=this._hits[0];if(t&&t.origin instanceof og){const r=this._reticle[t.origin.index];r&&(n=r,o=this._hits[t.origin.index])}if(t&&(t.stopImmediatePropagation(),t.stopPropagation(),t.use()),this._isPlacing=!1,this.context.input.removeEventListener("pointerup",this.onPlaceScene),this.onRevertSceneChanges(),n.position.copy(n.lastPos),n.quaternion.copy(n.lastQuat),this.onApplyPose(n),this.useXRAnchor&&this.onCreateAnchor(J.active,o),this.context.xr)for(const r of this.context.xr.controllers)r.cancelHitTestSource()}),a(this,"upVec",new x(0,1,0)),a(this,"lookPoint",new x),a(this,"worldUpVec",new x(0,1,0))}static onPlaced(t){const i="placed";return this._eventListeners[i]||(this._eventListeners[i]=[]),this._eventListeners[i].push(t),()=>{const n=this._eventListeners[i].indexOf(t);n>=0&&this._eventListeners[i].splice(n,1)}}get arScale(){return this._arScale}set arScale(t){t!==this._arScale&&(this._arScale=t,this.onScaleChanged())}onEnable(){var t;(t=this.customReticle)==null||t.preload()}supportsXR(t){return t==="immersive-ar"}onEnterXR(t){Kx&&console.log("ENTER WEBXR: SessionRoot start..."),this._anchor=null,this.gameObject.updateMatrixWorld(),this._startOffset.copy(this.gameObject.matrixWorld);const i=new I;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=ci(this._placementScene.children),o=n.getCenter(new x),r=n.getSize(new x),l=new ne;l.makeTranslation(o.x,o.y-r.y*.5,o.z),this._startOffset.multiply(l)}this._reparentedComponents.length=0,this._reparentedComponents.push({comp:this,originalObject:this.gameObject}),P.addComponent(i,this);for(const n of this._reticle)Ri(n);this._reticle.length=0,this._isPlacing=!0,this.context.input.addEventListener("pointerup",this.onPlaceScene,{queue:Oi.Early})}onLeaveXR(){this.context.input.removeEventListener("pointerup",this.onPlaceScene,{queue:Oi.Early}),this.onRevertSceneChanges(),this._anchor=null,this._rigPlacementMatrix=void 0}onUpdateXR(t){var i,n,o,r;if(t.xr.isTrackingImages){for(const l of this._reticle)l.visible=!1;return}if(this._isPlacing){const l=(i=t.xr.rig)==null?void 0:i.gameObject;l&&l.parent!==this.context.scene&&this.context.scene.add(l);let c=!1;if(t.xr.isPassThrough&&t.xr.controllers.length>0&&!this.autoPlace)for(const h of t.xr.controllers){const d=h.getHitTest();d&&(c=!0,this.updateReticleAndHits(t.xr,h.index,d,t.xr.rigScale))}if(!c){const h=t.xr.getHitTest();h&&this.updateReticleAndHits(t.xr,0,h,t.xr.rigScale)}}else{if(this._anchor&&t.xr.referenceSpace){const l=t.xr.frame.getPose(this._anchor.anchorSpace,t.xr.referenceSpace);if(l&&this.context.time.frame%20===0){const c=t.xr.convertSpace(l.transform),h=this._reticle[0];h&&(h.position.copy(c.position),h.quaternion.copy(c.quaternion),this.onApplyPose(h))}}if(this.arTouchTransform?(this.userInput||(this.userInput=new _p(this.context)),(n=this.userInput)==null||n.enable()):(o=this.userInput)==null||o.disable(),this.arTouchTransform&&(r=this.userInput)!=null&&r.hasChanged){if(t.xr.rig){const l=t.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(t,i,n,o){this._hits[i]=n.hit;let r=this._reticle[i];if(!r){if(this.customReticle)if(this.customReticle.asset)r=Ua(this.customReticle.asset);else{this.customReticle.loadAssetAsync();return}else r=new K(new aC(.07,.09,32).rotateX(-Math.PI/2),new Re({side:xi,depthTest:!1,depthWrite:!1,transparent:!0,opacity:1,color:15658734})),r.name="AR Placement Reticle";if(Kx){const l=new wi(1);l.position.y+=.01,r.add(l)}this._reticle[i]=r,r.matrixAutoUpdate=!1,r.visible=!1}if(r.lastPos=r.lastPos||n.position.clone(),r.lastQuat=r.lastQuat||n.quaternion.clone(),r.position.copy(r.lastPos.lerp(n.position,this.context.time.deltaTime/.1)),r.lastPos.copy(r.position),r.quaternion.copy(r.lastQuat.slerp(n.quaternion,this.context.time.deltaTime/.05)),r.lastQuat.copy(r.quaternion),r.scale.set(o,o,o),this.customReticle&&this.applyViewBasedTransform(r),r.updateMatrix(),r.visible=!0,r.parent!==this.context.scene&&this.context.scene.add(r),this._placementStartTime<0&&(this._placementStartTime=this.context.time.realtimeSinceStartup),this.autoPlace)if(this.upVec.set(0,1,0).applyQuaternion(r.quaternion),this.upVec.dot(G(0,1,0))>.9){let l=r["autoplace:timer"]||0;l>=1?(r.visible=!1,this.onPlaceScene(null)):(l+=this.context.time.deltaTime,r["autoplace:timer"]=l)}else r["autoplace:timer"]=0}onScaleChanged(){}onRevertSceneChanges(){var t;for(const i of this._reticle)i&&(i.visible=!1,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)}(t=this._createdPlacementObject)==null||t.removeFromParent();for(const i of this._reparentedComponents)P.addComponent(i.originalObject,i.comp)}async onCreateAnchor(t,i){if(i.createAnchor===void 0){console.warn("Hit does not support creating an anchor",i),F()&&xe("Hit does not support creating an anchor");return}else{const n=await i.createAnchor(t.viewerPose.transform);t.running&&n&&(this._anchor=n)}}applyViewBasedTransform(t){const i=this.context.mainCamera,n=t,o=i.worldPosition,r=n.worldPosition;this.upVec.set(0,1,0).applyQuaternion(t.quaternion);const l=i.worldPosition;l&&t.position.clone().sub(l).angleTo(this.upVec)<Math.PI/2&&this.upVec.negate();const c=this.upVec.angleTo(this.worldUpVec)*180/Math.PI,h=30;c>h&&c<180-h||c<-h&&c>-180+h?(this.lookPoint.copy(t.position).add(this.upVec),this.lookPoint.y=t.position.y,t.lookAt(this.lookPoint)):(o.y=r.y,t.lookAt(o))}onApplyPose(t){var i,n,o,r;const l=(n=(i=J.active)==null?void 0:i.rig)==null?void 0:n.gameObject;if(!l){console.warn("No rig object to place");return}(o=J.active)!=null&&o.rigScale;const c=l.parent||this.context.scene;this._rigPlacementMatrix?(r=this._rigPlacementMatrix)==null||r.decompose(l.position,l.quaternion,l.scale):this._rigPlacementMatrix=l.matrix.clone(),this.applyViewBasedTransform(t),t.updateMatrix(),this.context.scene.add(t),t.attach(l),t.removeFromParent(),l.scale.set(this.arScale,this.arScale,this.arScale),l.position.multiplyScalar(this.arScale),l.updateMatrix(),this.invertForward&&l.matrix.premultiply(BT),l.matrix.premultiply(this._startOffset),l.matrix.decompose(l.position,l.quaternion,l.scale),c.add(l)}}a(Hn,"_eventListeners",{});const P0=class{constructor(s){a(this,"oneFingerDrag",!0),a(this,"twoFingerRotate",!0),a(this,"twoFingerScale",!0),a(this,"factor",1),a(this,"context"),a(this,"offset"),a(this,"plane"),a(this,"_scale",1),a(this,"_hasChanged",!1),a(this,"_enabled",!1),a(this,"currentlyUsedPointerIds",new Set),a(this,"currentlyUnusedPointerIds",new Set),a(this,"onPointerDownEarly",t=>{this.isActive&&t.stopPropagation()}),a(this,"onPointerDownLate",t=>{t.used?this.currentlyUsedPointerIds.add(t.pointerId):this.currentlyUsedPointerIds.size<=0&&this.currentlyUnusedPointerIds.add(t.pointerId)}),a(this,"onPointerUpEarly",t=>{this.currentlyUsedPointerIds.delete(t.pointerId),this.currentlyUnusedPointerIds.delete(t.pointerId)}),a(this,"prev",new Map),a(this,"_didMultitouch",!1),a(this,"touchStart",t=>{if(!t.defaultPrevented)for(let i=0;i<t.changedTouches.length;i++){const n=t.changedTouches[i],o=X.isAndroidDevice()&&n.clientY<window.innerHeight*.1;this.prev.has(n.identifier)||this.prev.set(n.identifier,{ignore:o,x:0,z:0,screenx:0,screeny:0});const r=this.prev.get(n.identifier);if(r){const l=this.getPositionOnPlane(n.clientX,n.clientY);r.x=l.x,r.z=l.z,r.screenx=n.clientX,r.screeny=n.clientY}}}),a(this,"touchEnd",t=>{t.touches.length<=0&&(this._didMultitouch=!1);for(let i=0;i<t.changedTouches.length;i++){const n=t.changedTouches[i];this.prev.delete(n.identifier)}}),a(this,"touchMove",t=>{if(!t.defaultPrevented&&this.isActive){if(t.touches.length===1){if(this._didMultitouch)return;const i=t.touches[0],n=this.prev.get(i.identifier);if(!n||n.ignore)return;const o=this.getPositionOnPlane(i.clientX,i.clientY),r=o.x-n.x,l=o.z-n.z;if(r===0&&l===0)return;this.oneFingerDrag&&this.addMovement(r,l),n.x=o.x,n.z=o.z,n.screenx=i.clientX,n.screeny=i.clientY;return}else if(t.touches.length===2){this._didMultitouch=!0;const i=t.touches[0],n=t.touches[1],o=this.prev.get(i.identifier),r=this.prev.get(n.identifier);if(!o||!r)return;if(this.twoFingerRotate){const l=Math.atan2(i.clientY-n.clientY,i.clientX-n.clientX),c=Math.atan2(o.screeny-r.screeny,o.screenx-r.screenx),h=l-c;Math.abs(h)>.001&&this.addRotation(h)}if(this.twoFingerScale){const l=i.clientX-n.clientX,c=i.clientY-n.clientY,h=Math.sqrt(l*l+c*c),d=o.screenx-r.screenx,u=o.screeny-r.screeny,p=Math.sqrt(d*d+u*u),g=h-p;Math.abs(g)>2&&this.addScale(g)}o.screenx=i.clientX,o.screeny=i.clientY,r.screenx=n.clientX,r.screeny=n.clientY}}}),a(this,"_raycaster",new ud),a(this,"_intersection",new x),a(this,"_screenPos",new x),a(this,"_tempMatrix",new ne),this.context=s,this.offset=new ne,this.plane=new pr,this.plane.setFromNormalAndCoplanarPoint(P0.up,P0.zero)}reset(){this._scale=1,this.offset.identity()}get hasChanged(){return this._hasChanged}applyMatrixTo(s,t){this._hasChanged=!1,t?(this.offset.invert(),s.premultiply(this.offset)):s.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:Oi.Early}),this.context.input.addEventListener("pointerdown",this.onPointerDownLate,{queue:Oi.Late}),this.context.input.addEventListener("pointerup",this.onPointerUpEarly,{queue:Oi.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:Oi.Early}),this.context.input.removeEventListener("pointerdown",this.onPointerDownLate,{queue:Oi.Late}),this.context.input.removeEventListener("pointerup",this.onPointerUpEarly,{queue:Oi.Early}),window.removeEventListener("touchstart",this.touchStart),window.removeEventListener("touchmove",this.touchMove),window.removeEventListener("touchend",this.touchEnd))}getPositionOnPlane(s,t){const i=this.context.mainCamera;return this._screenPos.x=s/window.innerWidth*2-1,this._screenPos.y=-(t/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(s,t){s/=this._scale,t/=this._scale,s*=this.factor,t*=this.factor,this.offset.elements[12]+=s,this.offset.elements[14]+=t,(s!==0||t!==0)&&(this._hasChanged=!0)}addScale(s){s/=window.innerWidth,s*=-1,this._scale*=1+s,this._tempMatrix.makeScale(1-s,1-s,1-s),this.offset.premultiply(this._tempMatrix),s!==0&&(this._hasChanged=!0)}addRotation(s){s*=-1,this._tempMatrix.makeRotationY(s),this.offset.premultiply(this._tempMatrix),s!==0&&(this._hasChanged=!0)}};let _p=P0;a(_p,"up",new x(0,1,0)),a(_p,"zero",new x(0,0,0)),a(_p,"one",new x(1,1,1));const Wo=O("debugautosync"),k0=Symbol("syncerId");class FT{constructor(){a(this,"_syncers",{})}getOrCreateSyncer(t){if(!t.guid)return null;if(this._syncers[t.guid])return this._syncers[t.guid];const i=new zT(t);return i[k0]=t.guid,this._syncers[i[k0]]=i,i}removeSyncer(t){delete this._syncers[t[k0]]}}const M0=new FT;class zT{constructor(t){a(this,"comp"),a(this,"hasChanges",!1),a(this,"changedProperties",{}),a(this,"_isReceiving",!1),a(this,"_isInit",!1),a(this,"onHandleSending",()=>{if(!this.hasChanges)return;this.hasChanges=!1;const i=this.comp.context.connection;if(!i||!i.isConnected||!i.isInRoom){for(const n in this.changedProperties)delete this.changedProperties[n];return}for(const n in this.changedProperties){const o=this.changedProperties[n];Wo&&console.log("SEND",this.comp.guid,this.networkingKey),i.send(this.networkingKey,{guid:this.comp.guid,property:n,data:o},ws.Queued),delete this.changedProperties[n]}}),a(this,"onHandleReceiving",i=>{if(Wo&&console.log("SYNCFIELD RECEIVE",this.comp.name,this.comp.guid,i),!!this._isInit&&this.comp&&i.guid===this.comp.guid)try{this._isReceiving=!0,this.comp[i.property]=i.data}catch(n){console.error(n)}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 i=this.comp.context.connection.tryGetState(this.comp.guid);i&&this.onHandleReceiving(i)}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,i){this._isReceiving||(Wo&&console.log("Property changed: "+t,i),this.hasChanges=!0,this.changedProperties[t]=i)}}function UT(s,t){let i=t!==s;return!i&&s&&t&&(Array.isArray(s)&&Array.isArray(t)||typeof s=="object"&&typeof t=="object")&&(i=!0),i}const bh=Symbol("AutoSyncHandler");function NT(s){if(s[bh])return s[bh];const t=M0.getOrCreateSyncer(s);return t?.init(s),s[bh]=t,t}function WT(s){const t=s[bh];t&&(M0.removeSyncer(t),t.destroy(),delete s[bh])}const R0=function(s=null){return function(t,i){var n;let o="";typeof i=="string"?o=i:o=i.name;let r=null,l;typeof s=="string"?l=t[s]:typeof s=="function"&&(l=s),l==null&&(F()||Wo)&&s!=null&&console.warn('syncField: no callback function found for property "'+o+'"','"'+s+'"');const c=t,h=c.__internalAwake;if(typeof h!="function"){(Wo||F())&&console.error('@syncField can currently only used on Needle Engine Components, custom object of type "'+((n=t?.constructor)==null?void 0:n.name)+'" is not supported',t);return}Wo&&console.log(o);const d=Symbol(o);c.__internalAwake=function(){if(this[d]!==void 0)return;this[d]=this[o],r=M0.getOrCreateSyncer(this);const p=Object.getOwnPropertyDescriptor(this,o);if(p?.set===void 0){let g=!1;Object.defineProperty(this,o,{set:function(y){var f;const v=this[d];if(this[d]=y,g){(F()||Wo)&&console.warn("Recursive call detected",o);return}g=!0;try{const b=UT(y,v);Wo&&console.log("SyncField assignment",o,"changed?",b,y,l),b&&l?.call(this,y,v)!==!1&&((f=NT(this))==null||f.notifyChanged(o,y))}finally{g=!1}},get:function(){return this[d]},configurable:!0,enumerable:!0})}r?.init(this),h.call(this)};const u=c.__internalDestroy;c.__internalDestroy=function(){WT(this),u.call(this)}}};var VT=Object.defineProperty,HT=Object.getOwnPropertyDescriptor,wp=(s,t,i,n)=>{for(var o=n>1?void 0:n?HT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&VT(t,i,o),o};const ii=O("debugplayersync"),Zx=class extends A{constructor(){super(...arguments),a(this,"autoSync",!0),a(this,"asset"),a(this,"onPlayerSpawned"),a(this,"_localInstance"),a(this,"onJoinedRoom",()=>{ii&&console.log("PlayerSync.joinedRoom. autoSync is set to "+this.autoSync),this.autoSync&&this.getInstance()}),a(this,"destroyInstance",()=>{var s;(s=this._localInstance)==null||s.then(t=>{ii&&console.log("PlayerSync.destroyInstance",t),Sc(t,this.context.connection,!0,{saveInRoom:!1})}),this._localInstance=void 0})}static async setupFrom(s,t){const i=ae.getOrCreateFromUrl(s);if(!i.asset){const r=await i.loadAssetAsync();r&&P.getOrAddComponent(r,Di)}const n=new Zx;n._internalInit(t),n.asset=i;const o=new I;return o.guid=s,P.addComponent(o,n),n}awake(){this.watchTabVisible(),this.onPlayerSpawned||(this.onPlayerSpawned=new _e)}onEnable(){this.context.connection.beginListen(ie.RoomStateSent,this.onJoinedRoom),this.context.connection.beginListen(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ie.LeftRoom,this.destroyInstance),this.context.connection.isInRoom&&this.onJoinedRoom()}onDisable(){this.context.connection.stopListen(ie.RoomStateSent,this.onJoinedRoom),this.context.connection.stopListen(ie.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ie.LeftRoom,this.destroyInstance)}async getInstance(){var s,t,i,n,o,r;if(this._localInstance)return this._localInstance;if(ii&&console.log("PlayerSync.createInstance",(s=this.asset)==null?void 0:s.url),!((t=this.asset)!=null&&t.asset)&&!((i=this.asset)!=null&&i.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=(n=this.asset)==null?void 0:n.instantiateSynced({parent:this.gameObject,deleteOnDisconnect:!0},!0);const l=await this._localInstance;if(l){const c=P.getComponentsInChildren(l,Di);if(ii&&console.log(`PlayerSync.createInstance: found ${c?.length} PlayerState components. Owner: ${this.context.connection.connectionId}`),c!=null&&c.length){for(const h of c)h.owner=this.context.connection.connectionId;(o=this.onPlayerSpawned)==null||o.invoke(l)}else this._localInstance=void 0,console.error("<strong>Failed finding PlayerState on "+((r=this.asset)==null?void 0:r.url)+"</strong>: please make sure the asset has a PlayerState component!"),P.destroySynced(l)}else this._localInstance=void 0,console.warn("PlayerSync: failed instantiating asset!");return this._localInstance}watchTabVisible(){window.addEventListener("visibilitychange",s=>{if(document.visibilityState==="visible")for(let t=Di.all.length-1;t>=0;t--){const i=Di.all[t];(!i.owner||!this.context.connection.userIsInRoom(i.owner))&&i.doDestroy()}})}};let Sl=Zx;wp([m()],Sl.prototype,"autoSync",2),wp([m(ae)],Sl.prototype,"asset",2),wp([m(_e)],Sl.prototype,"onPlayerSpawned",2);var Jx=(s=>(s.OwnerChanged="ownerChanged",s))(Jx||{}),_h;const It=(_h=class extends A{constructor(){super(...arguments),a(this,"onOwnerChangeEvent",new _e),a(this,"onFirstOwnerChangeEvent",new _e),a(this,"hasOwner",!1),a(this,"owner"),a(this,"dontDestroy",!1),a(this,"onUserLeftRoom",s=>{if(s.userId===this.owner){ii&&console.log("PLAYERSYNC LEFT",this.owner),this.doDestroy();return}})}static get all(){return It._all}static get local(){return It._local}static getFor(s){if(s instanceof I)return P.getComponentInParent(s,It);if(s instanceof A)return P.getComponentInParent(s.gameObject,It)}static isLocalPlayer(s){const t=It.getFor(s);return t?.isLocalPlayer??!1}static addEventListener(s,t){return this._callbacks[s]||(this._callbacks[s]=[]),this._callbacks[s].push(t),t}static removeEventListener(s,t){if(!this._callbacks[s])return;const i=this._callbacks[s].indexOf(t);i>=0&&this._callbacks[s].splice(i,1)}static dispatchEvent(s,t){if(this._callbacks[s])for(const i of this._callbacks[s])i(t)}get isLocalPlayer(){return this.owner===this.context.connection.connectionId}onOwnerChange(s,t){var i,n;ii&&console.log(`PlayerSync.onOwnerChange: ${t} \u2192 ${s} (me: ${this.context.connection.connectionId})`);const o=It._local.indexOf(this);o>=0&&It._local.splice(o,1);const r={playerState:this,oldValue:t,newValue:s};if(this.hasOwner||(this.hasOwner=!0,(i=this.onFirstOwnerChangeEvent)==null||i.invoke(r)),(n=this.onOwnerChangeEvent)==null||n.invoke(r),this.owner===this.context.connection.connectionId){It._local.push(this);const c=new CustomEvent("local-owner-changed",{detail:r});this.dispatchEvent(c)}const l=new CustomEvent("owner-changed",{detail:r});this.dispatchEvent(l),It.dispatchEvent("ownerChanged",l)}awake(){It.all.push(this),ii&&console.log("Registered new PlayerState",this.guid,It.all.length-1,It.all),this.context.connection.beginListen(ie.UserLeftRoom,this.onUserLeftRoom)}async start(){ii&&console.log("PLAYERSTATE.START, owner: "+this.owner,this.context.connection.usersInRoom([])),this.owner?(this.context.connection.isInRoom||await ys(300),this.context.connection.userIsInRoom(this.owner)==!1&&(ii&&console.log(`PlayerSync.start \u2192 doDestroy "${this.name}" because user "${this.owner}" is not in room anymore...`,"Currently in room:",...this.context.connection.usersInRoom()),this.doDestroy())):this.owner||(ii&&console.warn("PlayerState.start \u2192 owner is undefined!",this.name),setTimeout(()=>{!this.destroyed&&!this.owner?this.dontDestroy?ii&&console.warn("PlayerState.start \u2192 owner is still undefined but dontDestroy is set to true",this.name):(ii&&console.warn(`PlayerState.start \u2192 owner is still undefined: destroying "${this.name}" instance now`),this.doDestroy()):ii&&console.log("PlayerState.start \u2192 owner is assigned",this.owner)},2e3))}doDestroy(){ii&&console.log("PlayerSync.doDestroy \u2192 syncDestroy",this.name),Sc(this.gameObject,this.context.connection,!0,{saveInRoom:!1})}onDestroy(){if(ii&&console.warn("PlayerState.onDestroy",this.owner),this.context.connection.stopListen(ie.UserLeftRoom,this.onUserLeftRoom),It.all.splice(It.all.indexOf(this),1),this.isLocalPlayer){const s=It._local.indexOf(this);s>=0&&It._local.splice(s,1)}}},a(_h,"_all",[]),a(_h,"_local",[]),a(_h,"_callbacks",{}),_h);let Di=It;wp([R0(Di.prototype.onOwnerChange)],Di.prototype,"owner",2);var $T=Object.defineProperty,qT=Object.getOwnPropertyDescriptor,Cl=(s,t,i,n)=>{for(var o=n>1?void 0:n?qT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&$T(t,i,o),o};class an extends A{constructor(){super(...arguments),a(this,"position","bottom"),a(this,"showNeedleLogo",!0),a(this,"showSpatialMenu"),a(this,"createFullscreenButton"),a(this,"createMuteButton"),a(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&&(X.isMobileDevice()||this.context.menu.showQRCodeButton(!0))}}Cl([m()],an.prototype,"position",2),Cl([m()],an.prototype,"showNeedleLogo",2),Cl([m()],an.prototype,"showSpatialMenu",2),Cl([m()],an.prototype,"createFullscreenButton",2),Cl([m()],an.prototype,"createMuteButton",2),Cl([m()],an.prototype,"createQRCodeButton",2);var GT=Object.defineProperty,XT=Object.getOwnPropertyDescriptor,T0=(s,t,i,n)=>{for(var o=n>1?void 0:n?XT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&>(t,i,o),o};const wh=O("debugwebxr"),e1=new V().setFromAxisAngle(new x(0,1,0),Math.PI);class Vo extends A{constructor(){super(...arguments),a(this,"head"),a(this,"leftHand"),a(this,"rightHand"),a(this,"_leftHandMeshes"),a(this,"_rightHandMeshes"),a(this,"_syncTransforms")}async onEnterXR(t){if(!this.activeAndEnabled)return;wh&&console.warn("AVATAR ENTER XR",this.guid,this.sourceId,this,this.activeAndEnabled),this._syncTransforms&&(this._syncTransforms.length=0),await this.prepareAvatar();const i=Di.getFor(this);if(i!=null&&i.owner){const n=this.gameObject.addComponent(Tt);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(t){const i=this.gameObject.getComponent(Tt);i&&i.destroy()}onUpdateXR(t){var i,n;if(!this.activeAndEnabled)return;const o=Di.isLocalPlayer(this);if(!o)return;const r=t.xr;if(r.rig&&r.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),r.rig.gameObject.add(this.gameObject)),this._syncTransforms&&o)for(const u of this._syncTransforms)u.fastMode=!0,u.isOwned()||u.requestOwnership();if(this.head&&this.context.mainCamera){const u=this.head.asset;if(u.position.copy(this.context.mainCamera.position),u.position.x*=-1,u.position.z*=-1,u.quaternion.copy(this.context.mainCamera.quaternion),u.quaternion.x*=-1,this.context.time.frameCount%10===0&&this.head.asset){const p=P.getComponentsInChildren(this.head.asset,Ai);for(const g of p)g.enabled=!1,g.gameObject.visible=!1}}const l=t.xr.leftController,c=(i=this.leftHand)==null?void 0:i.asset;l&&c?(c.position.copy(l.gripPosition),c.quaternion.copy(l.gripQuaternion),c.quaternion.multiply(e1),c.visible=l.isTracking,this.updateHandVisibility(l,c,this._leftHandMeshes)):c&&c.visible&&(c.visible=!1);const h=t.xr.rightController,d=(n=this.rightHand)==null?void 0:n.asset;h&&d?(d.position.copy(h.gripPosition),d.quaternion.copy(h.gripQuaternion),d.quaternion.multiply(e1),d.visible=h.isTracking,this.updateHandVisibility(h,d,this._rightHandMeshes)):d&&d.visible&&(d.visible=!1)}onBeforeRender(){this.context.xr&&this.context.time.frame%10===0&&this.updateRemoteAvatarVisibility()}updateHandVisibility(t,i,n){if(n){const o=t.model&&t.model.visible&&t.model!==i;n.forEach(r=>{Mn(r,!o)})}}updateRemoteAvatarVisibility(){var t,i,n;if(this.context.connection.isConnected){const o=Di.getFor(this);if(o&&o.isLocalPlayer==!1){const r=J.getXRSync(this.context);if(r&&r.hasState(o.owner)){this.tryFindAvatarObjectsIfMissing();const l=(t=this.leftHand)==null?void 0:t.asset;l&&(l.visible=r?.isTracking(o.owner,"left")??!1);const c=(i=this.rightHand)==null?void 0:i.asset;c&&(c.visible=r?.isTracking(o.owner,"right")??!1)}if((n=this.head)!=null&&n.asset){const l=P.getComponentsInChildren(this.head.asset,Ai);for(const c of l)c.enabled=!1,c.gameObject.visible=!0}}}}tryFindAvatarObjectsIfMissing(){if(!this.head||!this.leftHand||!this.rightHand){const t={head:this.head,leftHand:this.leftHand,rightHand:this.rightHand};Nb.tryFindAvatarObjects(this.gameObject,this.sourceId||"",t),t.head&&(this.head=t.head),t.leftHand&&(this.leftHand=t.leftHand),t.rightHand&&(this.rightHand=t.rightHand)}}async prepareAvatar(){var t,i;if(this.tryFindAvatarObjectsIfMissing(),this.head)this.head instanceof I&&(this.head=new ae("",this.sourceId,this.head));else{const n=new I;n.name="Head";const o=mo.createPrimitive(wr.Cube);n.add(o),this.gameObject.add(n),this.head=new ae("",this.sourceId,n),wh&&console.log("Create head",n)}if(this.rightHand)this.rightHand instanceof I&&(this.rightHand=new ae("",this.sourceId,this.rightHand));else{const n=new I;n.name="Right Hand",this.gameObject.add(n),this.rightHand=new ae("",this.sourceId,n),wh&&console.log("Create right hand",n)}if(this.leftHand)this.leftHand instanceof I&&(this.leftHand=new ae("",this.sourceId,this.leftHand));else{const n=new I;n.name="Left Hand",this.gameObject.add(n),this.leftHand=new ae("",this.sourceId,n),wh&&console.log("Create left hand",n)}await this.loadAvatarObjects(this.head,this.leftHand,this.rightHand),this._leftHandMeshes=[],(t=this.leftHand.asset)==null||t.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)}),Di.isLocalPlayer(this.gameObject)&&(this._syncTransforms=P.getComponentsInChildren(this.gameObject,qs))}async loadAvatarObjects(t,i,n){const o=t.loadAssetAsync(),r=i.loadAssetAsync(),l=n.loadAssetAsync(),c=new Array;o&&c.push(o),r&&c.push(r),l&&c.push(l);const h=await wd(c);wh&&console.log("Avatar loaded results:",h)}}T0([m(ae)],Vo.prototype,"head",2),T0([m(ae)],Vo.prototype,"leftHand",2),T0([m(ae)],Vo.prototype,"rightHand",2);var QT=Object.defineProperty,YT=Object.getOwnPropertyDescriptor,xp=(s,t,i,n)=>{for(var o=n>1?void 0:n?YT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&QT(t,i,o),o};const $n=O("debugwebxr"),Ho=new Array;class ln extends A{constructor(){super(...arguments),a(this,"createControllerModel",!0),a(this,"createHandModel",!0),a(this,"customLeftHand"),a(this,"customRightHand"),a(this,"_models",new Array)}supportsXR(t){return t==="immersive-vr"||t==="immersive-ar"}async onXRControllerAdded(t){var i;if(!(t.xr.isVR||t.xr.isPassThrough))return;const{controller:n}=t;if($n&&console.warn("Add Controller Model for",n.side,n.index),this.createControllerModel||this.createHandModel){if(n.hand){if(this.createHandModel){const o=await this.loadHandModel(this,n);if(!o||!n.connected||!n.isHand){o!=null&&o.handObject&&za(o.handObject,!1),(i=o?.handObject)==null||i.destroy();return}this._models.push({controller:n,model:o.handObject,handmesh:o.handmesh}),this._models.sort((r,l)=>r.controller.index-l.controller.index),this.scene.add(o.handObject),n.model=o.handObject}}else if(this.createControllerModel){const o=await n.getModelUrl();if(o){const r=await this.loadModel(n,o);if(!r||!n.connected||n.isHand)return;this._models.push({controller:n,model:r}),this._models.sort((l,c)=>l.controller.index-c.controller.index),this.scene.add(r),r.traverse(l=>{l.layers.set(2),l.matrixAutoUpdate=!1,l.updateMatrix()}),n.model=r}else n.targetRayMode!=="transient-pointer"&&console.warn("XRControllerModel: no model found for "+n.side)}}}onXRControllerRemoved(t){console.debug("XR Controller Removed",t.controller.side,t.controller.index);const i=this._models.findIndex(o=>o.controller===t.controller),n=this._models[i];n&&(this._models.splice(i,1),n.model&&(za(n.model,!1),n.model.destroy(),n.model=void 0))}onBeforeXR(t,i){this.createHandModel&&(this.customLeftHand||this.customRightHand)&&(i.optionalFeatures=i.optionalFeatures||[],i.optionalFeatures.includes("hand-tracking")||i.optionalFeatures.push("hand-tracking"))}onLeaveXR(t){for(const i of this._models)i&&(i.model&&(za(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(J.active&&($n&&(Ho[0]=Date.now()),this.updateRendering(J.active),$n)){const t=Date.now()-Ho[0];Ho.push(t),Ho.length>=30&&(Ho[0]=0,Ho.reduce((i,n)=>i+n,0)/Ho.length,Ho.length=0)}}updateRendering(t){var i,n,o,r,l;for(let c=0;c<this._models.length;c++){const h=this._models[c];if(!h)continue;const d=h.controller;if(!d.connected){$n&&console.warn("XRControllerModel.onUpdateXR: controller is not connected anymore",d.side,d.hand);continue}if(h.model&&!h.handmesh)h.model.matrixAutoUpdate=!1,h.model.matrix.copy(d.gripMatrix),h.model.visible=d.isTracking,(i=t.rig)==null||i.gameObject.add(h.model);else if(d.inputSource.hand&&h.handmesh){const u=t.referenceSpace,p=this.context.renderer.xr.getHand(d.index);if(u&&t.frame.getJointPose){for(const g of d.inputSource.hand.values()){const y=p.joints[g.jointName];if(y){const f=d.getHandJointPose(g);if(f){const v=f.transform.position,b=f.transform.orientation;y.position.copy(v),y.quaternion.copy(b),y.matrixAutoUpdate=!1}y.visible=f!=null}}h.model&&(h.model.visible=d.isTracking,h.model.visible&&h.model.parent!==((n=t.rig)==null?void 0:n.gameObject)&&((o=t.rig)==null||o.gameObject.add(h.model))),(r=h.model)!=null&&r.visible&&((l=h.handmesh)==null||l.updateMesh(),h.model.matrixAutoUpdate=!1,h.model.matrix.identity(),h.model.applyMatrix4(Ra))}}}}async loadModel(t,i){var n;if(!t.connected)return console.warn("XRControllerModel.onXRControllerAdded: controller is not connected anymore",t.side),null;const o=await ae.getOrCreate("",i).instantiate();return za(o),(n=J.active)!=null&&n.isPassThrough&&o.traverseVisible(r=>{this.makeOccluder(r)}),o}async loadHandModel(t,i){const n=this.context,o=n.renderer.xr.getHand(i.index);o||($n?q.DrawLabel(i.rayWorldPosition,"No hand found for index "+i.index,.05,5):console.warn("No hand found for index "+i.index));const r=new gr;Su(r,n),await Zu(r,n,this.sourceId??"");const l=Ku(r);let c="";const h=i.side==="left"?this.customLeftHand:this.customRightHand;h?(c=h.url.split(".").slice(0,-1).join("."),r.setPath("")):(c=i.inputSource.handedness==="left"?"left":"right",r.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/"));const d=new I;za(d);const u=new UC(d,o,r.path,c,r,p=>{var g;const y=l.gltf;((g=y?.scene.children)==null?void 0:g.length)===0&&(y.scene.children[0]=p),fs().createBuiltinComponents(t.context,t.sourceId||c,l.gltf,null,l),p.traverse(f=>{var v;f.layers.set(2),(v=J.active)!=null&&v.isPassThrough&&!h&&this.makeOccluder(f),f instanceof K&&it.assignMeshLOD(f,0)}),i.connected||($n&&q.DrawLabel(i.rayWorldPosition,"Hand is loaded but not connected anymore",.05,5),p.removeFromParent())});if($n&&d.add(new wi(.5)),i.inputSource.hand){$n&&console.log(i.inputSource.hand);for(const p of i.inputSource.hand.values())if(o.joints[p.jointName]===void 0){const g=new oo;g.matrixAutoUpdate=!1,g.visible=!0,o.joints[p.jointName]=g,o.add(g)}}else $n&&q.DrawLabel(i.rayWorldPosition,"No inputSource.hand found for index "+i.index,.05,5);return{handObject:d,handmesh:u}}makeOccluder(t){if(t instanceof K){let i=t.material;i instanceof ke&&(i=t.material=i.clone(),i.depthWrite=!0,i.depthTest=!0,i.colorWrite=!1,t.receiveShadow=!1,t.renderOrder=-100)}}}a(ln,"factory",new zC),xp([m()],ln.prototype,"createControllerModel",2),xp([m()],ln.prototype,"createHandModel",2),xp([m(ae)],ln.prototype,"customLeftHand",2),xp([m(ae)],ln.prototype,"customRightHand",2);class Sp extends A{}var KT=Object.defineProperty,ZT=Object.getOwnPropertyDescriptor,$o=(s,t,i,n)=>{for(var o=n>1?void 0:n?ZT(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&KT(t,i,o),o};const E0=O("debugwebxr");class Li extends A{constructor(){super(...arguments),a(this,"movementSpeed",1.5),a(this,"rotationStep",30),a(this,"useTeleport",!0),a(this,"usePinchToTeleport",!0),a(this,"useTeleportTarget",!1),a(this,"useTeleportFade",!1),a(this,"showRays",!0),a(this,"showHits",!0),a(this,"isXRMovementHandler",!0),a(this,"xrSessionMode","immersive-vr"),a(this,"_didApplyRotation",!1),a(this,"_didTeleport",!1),a(this,"_teleportBuffer",new Array),a(this,"_plane",null),a(this,"_lines",[]),a(this,"_hitDiscs",[]),a(this,"_hitDistances",[]),a(this,"_lastHitDistances",[]),a(this,"hitPointRaycastFilter",t=>t.type==="SkinnedMesh"?"continue in children":!0)}onUpdateXR(t){const i=t.xr.rig;if(!(i!=null&&i.gameObject)||t.xr.isPassThrough)return;const n=t.xr.leftController,o=t.xr.rightController;n&&this.onHandleMovement(n,i.gameObject),o&&(this.onHandleRotation(o,i.gameObject),this.useTeleport&&this.onHandleTeleport(o,i.gameObject))}onLeaveXR(t){for(const i of this._lines)i.removeFromParent();for(const i of this._hitDiscs)i?.removeFromParent()}onBeforeRender(){var t;(t=this.context.xr)!=null&&t.running&&(this.showRays&&this.renderRays(this.context.xr),this.showHits&&this.renderHits(this.context.xr))}onHandleMovement(t,i){const n=t.getStick("xr-standard-thumbstick");if(n.x!=0||n.y!=0){const o=G(n.x,0,n.y);o.multiplyScalar(this.context.time.deltaTimeUnscaled*this.movementSpeed);const r=Je(i);o.multiplyScalar(r.x),o.applyQuaternion(t.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(t,i){if(t._isMxInk)return;const n=t.getStick("xr-standard-thumbstick").x;if(this._didApplyRotation)Math.abs(n)<.3&&(this._didApplyRotation=!1);else if(Math.abs(n)>.5){this._didApplyRotation=!0;const o=n>0?1:-1,r=te(this.context.mainCamera).clone();i.rotateY(o*W.toRadians(this.rotationStep));const l=te(this.context.mainCamera).clone().sub(r);l.y=0,i.position.sub(l)}}onHandleTeleport(t,i){var n,o,r,l,c;let h=0;if(t.hand&&this.usePinchToTeleport&&t.isTeleportGesture){const d=t.getPointerId("primary");if(d!=null&&this.context.input.getIsPointerIdInUse(d))return;const u=t.getGesture("pinch");u&&(h=u.value)}else h=(n=t.getStick("xr-standard-thumbstick"))==null?void 0:n.y;if(this._didTeleport)h>=0&&h<.4?this._didTeleport=!1:h<0&&h>-.4&&(this._didTeleport=!1);else if(h>.8){this._didTeleport=!0;const d=this.context.physics.raycastFromRay(t.ray)[0];if(d&&d.object instanceof Sa){const p=(o=d.normal)==null?void 0:o.dot(G(0,1,0));if(p!==void 0&&p<.4)return}let u=d?.point;if(!u&&!this.useTeleportTarget){this._plane||(this._plane=new pr(new x(0,1,0),0));const p=i.worldPosition;this._plane.setFromNormalAndCoplanarPoint(new x(0,1,0),p);const g=t.ray;u=p.clone(),this._plane.intersectLine(new lC(g.origin,G(g.direction).multiplyScalar(1e4).add(g.origin)),u),u.distanceTo(p)>i.scale.x*10&&(u=null)}if(u){if(this.useTeleportTarget&&!P.getComponentInParent(d.object,Sp))return;const p=u.clone();if(E0&&q.DrawSphere(u,.025,16711680,5),(r=this.context.mainCamera)==null?void 0:r.position){const g=(l=this.context.xr)==null?void 0:l.getUserOffsetInRig();g&&(g.y=0,p.sub(g),E0&&q.DrawWireSphere(g.add(p),.025,65280,5))}this._teleportBuffer.push(i.matrix.clone()),this._teleportBuffer.length>10&&this._teleportBuffer.shift(),this.useTeleportFade?(c=t.xr.fadeTransition())==null||c.then(()=>{i.worldPosition=p}):i.worldPosition=p}}else if(h<-.8&&(this._didTeleport=!0,this._teleportBuffer.length>0)){const d=this._teleportBuffer.pop();d&&d.decompose(i.position,i.quaternion,i.scale)}}renderRays(t){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<t.controllers.length;n++){const o=t.controllers[n];let r=this._lines[n];if(!o.connected||!o.isTracking||!o.ray||o.targetRayMode==="transient-pointer"||!o.hasSelectEvent){r&&(r.visible=!1);continue}r||(r=this.createRayLineObject(),r.scale.z=.5,this._lines[n]=r),o.updateRayWorldPosition(),o.updateRayWorldQuaternion();const l=o.rayWorldPosition,c=o.rayWorldQuaternion;r.position.copy(l),r.quaternion.copy(c);const h=t.rigScale,d=this.usePinchToTeleport&&o.isTeleportGesture,u=this._lastHitDistances[n],p=this._hitDistances[n]!=null,g=u??h;r.scale.set(h,h,g),r.visible=!0,r.layers.disableAll(),r.layers.enable(2);let y=r.material.opacity;d?y=1:this.showHits&&g<t.rigScale*.5?y=0:(i=o.getButton("primary"))!=null&&i.pressed?y=.5:y=p?.2:.1,r.material.opacity=W.lerp(r.material.opacity,y,this.context.time.deltaTimeUnscaled/.1),r.parent!==this.context.scene&&this.context.scene.add(r)}}renderHits(t){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<t.controllers.length;n++){const o=t.controllers[n];if(!o.connected||!o.isTracking||!o.ray||!o.hasSelectEvent)continue;let r=this._hitDiscs[n],l=!0;const c=o.getPointerId("primary");c!=null&&this.context.input.getIsPointerIdInUse(c)&&(r&&(r.visible=!1),this._hitDistances[n]=null,this._lastHitDistances[n]=0,l=!1);const h=this.context.time.smoothedFps>=59?1:10;if((this.context.time.frame+o.index)%h!==0&&(l=!1),!l){const p=this._hitDiscs[n];p&&p.visible&&p.hit&&this.updateHitPointerPosition(o,p,p.hit.distance);continue}const d=this.context.physics.raycastFromRay(o.ray,{testObject:this.hitPointRaycastFilter,precise:!1});let u=d.find(p=>this.usePinchToTeleport&&o.isTeleportGesture?!0:this.isObjectWithInteractiveComponent(p.object));if(u||(u=d[0]),r&&(r.controller=o,r.hit=u),this._hitDistances[n]=u?.distance||null,u){this._lastHitDistances[n]=u.distance;const p=t.rigScale??1;E0&&(q.DrawWireSphere(u.point,.025*p,16711680),q.DrawLabel(G(0,.2,0).add(u.point),u.object.name,.02,0)),r||(r=this.createHitPointObject(),this._hitDiscs[n]=r),r.hit=u,r.visible=u.distance>p*.05;let g=.01*(p+u.distance);const y=(i=o.getButton("primary"))==null?void 0:i.pressed;y&&(g*=1.1),r.scale.set(g,g,g),r.layers.set(2);let f=r.material.opacity;if(y?f=1:f=u.distance<.15*p?.2:.6,r.material.opacity=W.lerp(r.material.opacity,f,this.context.time.deltaTimeUnscaled/.1),r.visible){if(u.normal){this.updateHitPointerPosition(o,r,u.distance);const v=u.normal.applyQuaternion(Oe(u.object));r.quaternion.setFromUnitVectors(JT,v)}else this.updateHitPointerPosition(o,r,u.distance);r.parent!==this.context.scene&&this.context.scene.add(r)}}else this._hitDiscs[n]&&(this._hitDiscs[n].visible=!1)}}isObjectWithInteractiveComponent(t,i=0){return Tu(t)||t.isUI===!0?!0:t.isScene?!1:t.parent?this.isObjectWithInteractiveComponent(t.parent,i+1):!1}updateHitPointerPosition(t,i,n){const o=G(t.rayWorldPosition);o.add(G(0,0,n-.01).applyQuaternion(t.rayWorldQuaternion)),i.position.lerp(o,this.context.time.deltaTimeUnscaled/.05)}createHitPointObject(){const t=new K(new hd(.3,6,6),new Re({color:15658734,opacity:.7,transparent:!0,depthTest:!1,depthWrite:!1,side:xi}));return t.layers.disableAll(),t.layers.enable(2),t}createRayLineObject(){const t=new NC;t.layers.disableAll(),t.layers.enable(2);const i=new WC;t.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 r=new VC({color:16777215,vertexColors:!0,worldUnits:!0,linewidth:.004,transparent:!0,depthWrite:!1,blending:iv,dashed:!1});return t.material=r,t}}$o([m()],Li.prototype,"movementSpeed",2),$o([m()],Li.prototype,"rotationStep",2),$o([m()],Li.prototype,"useTeleport",2),$o([m()],Li.prototype,"usePinchToTeleport",2),$o([m()],Li.prototype,"useTeleportTarget",2),$o([m()],Li.prototype,"useTeleportFade",2),$o([m()],Li.prototype,"showRays",2),$o([m()],Li.prototype,"showHits",2);const JT=new x(0,1,0);var eE=Object.defineProperty,tE=Object.getOwnPropertyDescriptor,Ct=(s,t,i,n)=>{for(var o=n>1?void 0:n?tE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&eE(t,i,o),o};const xh=O("debugwebxr"),iE=O("debugusdz");var A0;const Ol=(A0=class extends A{constructor(){super(...arguments),a(this,"createVRButton",!0),a(this,"createARButton",!0),a(this,"createSendToQuestButton",!0),a(this,"createQRCode",!0),a(this,"useDefaultControls",!0),a(this,"showControllerModels",!0),a(this,"showHandModels",!0),a(this,"usePlacementReticle",!0),a(this,"customARPlacementReticle"),a(this,"usePlacementAdjustment",!0),a(this,"arScale",1),a(this,"useXRAnchor",!1),a(this,"autoPlace",!1),a(this,"autoCenter",!1),a(this,"useQuicklookExport",!1),a(this,"useDepthSensing",!1),a(this,"useSpatialGrab",!0),a(this,"defaultAvatar"),a(this,"_playerSync"),a(this,"_createdComponentsInSession",[]),a(this,"_usdzExporter"),a(this,"_exitXRMenuButton"),a(this,"_previousXRState",0),a(this,"_spatialGrabRaycaster"),a(this,"onAvatarSpawned",s=>{xh&&console.log("WebXR.onAvatarSpawned",s),P.getComponentInChildren(s,Vo)??(e=P.addComponent(s,Vo))}),a(this,"_buttonFactory"),a(this,"_buttons",[])}awake(){J.getXRSync(this.context)}onEnable(){var s,t;window.location.protocol!=="https:"&&xe('<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&&(P.findObjectOfType(Ge)||(xh&&console.log("WebXR: Adding USDZExporter"),this._usdzExporter=P.addComponent(this.gameObject,Ge),this._usdzExporter.objectToExport=this.context.scene,this._usdzExporter.autoExportAnimations=!0,this._usdzExporter.autoExportAudioSources=!0)),this.handleCreatingHTML(),this.handleOfferSession(),this.defaultAvatar===!0&&(xh&&console.warn("WebXR: No default avatar set, using static default avatar"),this.defaultAvatar=new ae("https://cdn.needle.tools/static/avatars/DefaultAvatar.glb")),this.defaultAvatar&&(this._playerSync=this.gameObject.getOrAddComponent(Sl),this._playerSync.autoSync=!1),this._playerSync&&typeof this.defaultAvatar!="boolean"&&(this._playerSync.asset=this.defaultAvatar,(s=this._playerSync.onPlayerSpawned)==null||s.removeEventListener(this.onAvatarSpawned),(t=this._playerSync.onPlayerSpawned)==null||t.addEventListener(this.onAvatarSpawned))}onDisable(){var s;(s=this._usdzExporter)==null||s.destroy(),this.removeButtons()}async handleOfferSession(){return this.createVRButton&&await J.isVRSupported()&&this.createVRButton?J.offerSession("immersive-vr","default",this.context):this.createARButton&&await J.isARSupported()&&this.createARButton?J.offerSession("immersive-ar","default",this.context):!1}get session(){return J.active??null}get sessionMode(){return J.activeMode??null}async enterVR(s){return J.start("immersive-vr",s,this.context)}async enterAR(s){return J.start("immersive-ar",s,this.context)}exitXR(){J.stop()}get isActiveWebXR(){return!Ol.activeWebXRComponent||Ol.activeWebXRComponent===this}onBeforeXR(s,t){var i;if(!this.isActiveWebXR){console.warn(`WebXR: another WebXR component is already active (${(i=Ol.activeWebXRComponent)==null?void 0:i.name}). This is ignored: ${this.name}`);return}Ol.activeWebXRComponent=this,s=="immersive-ar"&&this.useDepthSensing&&(t.optionalFeatures=t.optionalFeatures||[],t.optionalFeatures.push("depth-sensing"))}async onEnterXR(s){if(!this.isActiveWebXR)return;xh&&console.log("WebXR onEnterXR"),this._previousXRState=Kt.Global.Mask;const t=s.xr.isVR;if(Kt.Global.Set(t?Zs.VR:Zs.AR),s.xr.isAR){let i=P.findObjectOfType(Hn);if(!i)if(this.usePlacementReticle){const n=new I;for(const o of this.context.scene.children)n.add(o);this.context.scene.add(n),i=P.addComponent(n,Hn),this._createdComponentsInSession.push(i)}else(xh||F())&&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=P.findObjectOfType(Qa)??void 0,this._spatialGrabRaycaster||(this._spatialGrabRaycaster=this.gameObject.addComponent(Qa))),this.createLocalAvatar(s.xr),s.xr.isScreenBasedAR||(this._exitXRMenuButton=this.context.menu.appendChild({label:"Quit XR",onClick:()=>this.exitXR(),icon:"exit_to_app",priority:2e4}))}onUpdateXR(s){this.isActiveWebXR&&this._spatialGrabRaycaster&&(this._spatialGrabRaycaster.enabled=this.useSpatialGrab)}onLeaveXR(s){var t,i;if((t=this._exitXRMenuButton)==null||t.remove(),!!this.isActiveWebXR){Kt.Global.Set(this._previousXRState),(i=this._playerSync)==null||i.destroyInstance();for(const n of this._createdComponentsInSession)n.destroy();this._createdComponentsInSession.length=0,this.handleOfferSession(),ec(1).then(()=>Ol.activeWebXRComponent=null)}}setDefaultMovementEnabled(s){let t=this.gameObject.getComponent(Li);return!t&&s&&(t=this.gameObject.addComponent(Li),this._createdComponentsInSession.push(t)),t&&(t.enabled=s),t}setDefaultControllerRenderingEnabled(s){let t=this.gameObject.getComponent(ln);return!t&&s&&(t=this.gameObject.addComponent(ln),this._createdComponentsInSession.push(t),t.createControllerModel=this.showControllerModels,t.createHandModel==this.showHandModels),t&&(t.enabled=s),t}async createLocalAvatar(s){this._playerSync&&s.running&&typeof this.defaultAvatar!="boolean"&&(this._playerSync.asset=this.defaultAvatar,await this._playerSync.getInstance())}getButtonsContainer(){return this.getButtonsFactory()}getButtonsFactory(){return this._buttonFactory||(this._buttonFactory=Kr.getOrCreate()),this._buttonFactory}handleCreatingHTML(){if(this.createARButton||this.createVRButton||this.useQuicklookExport){if((X.isiOS()&&X.isSafari()||iE)&&this.useQuicklookExport){const s=P.findObjectOfType(Ge);if(!s||s&&s.allowCreateQuicklookButton){const t=this.getButtonsFactory().createQuicklookButton();this.addButton(t,50)}}if(this.createARButton){const s=this.getButtonsFactory().createARButton();this.addButton(s,50)}if(this.createVRButton){const s=this.getButtonsFactory().createVRButton();this.addButton(s,50)}}if(this.createSendToQuestButton&&!X.isQuest()&&J.isVRSupported().then(s=>{if(!s){const t=this.getButtonsFactory().createSendToQuestButton();this.addButton(t,50)}}),this.createQRCode){const s=Zd(an);if(s&&s.createQRCodeButton===!1)F()&&console.warn("WebXR: QRCode button is disabled in the Needle Menu component");else if(!X.isMobileDevice()){const t=Tn.getOrCreate().createQRCode();this.addButton(t,50)}}}addButton(s,t){this._buttons.push(s),s.setAttribute("priority",t.toString()),this.context.menu.appendChild(s)}removeButtons(){for(const s of this._buttons)s.remove();this._buttons.length=0}},a(A0,"activeWebXRComponent",null),A0);let tt=Ol;Ct([m()],tt.prototype,"createVRButton",2),Ct([m()],tt.prototype,"createARButton",2),Ct([m()],tt.prototype,"createSendToQuestButton",2),Ct([m()],tt.prototype,"createQRCode",2),Ct([m()],tt.prototype,"useDefaultControls",2),Ct([m()],tt.prototype,"showControllerModels",2),Ct([m()],tt.prototype,"showHandModels",2),Ct([m()],tt.prototype,"usePlacementReticle",2),Ct([m(ae)],tt.prototype,"customARPlacementReticle",2),Ct([m()],tt.prototype,"usePlacementAdjustment",2),Ct([m()],tt.prototype,"arScale",2),Ct([m()],tt.prototype,"useXRAnchor",2),Ct([m()],tt.prototype,"autoPlace",2),Ct([m()],tt.prototype,"autoCenter",2),Ct([m()],tt.prototype,"useQuicklookExport",2),Ct([m()],tt.prototype,"useDepthSensing",2),Ct([m()],tt.prototype,"useSpatialGrab",2),Ct([m(ae)],tt.prototype,"defaultAvatar",2);const Sh=O("debugusdz");function sE(s,t){var i;const n=[],o=P.getComponentsInChildren(s,Mt),r=P.getComponentsInChildren(s,Wt),l=new Array,c=new Array;if(t.injectImplicitBehaviours)for(const h of o){if(!h||!h.runtimeAnimatorController||!h.enabled)continue;const d=h.runtimeAnimatorController.activeState;if(!d||!d.motion||!d.motion.clip||((i=d.motion.clip.tracks)==null?void 0:i.length)<1||l.includes(h))continue;const u=new Xr;u.animator=h,u.stateName=d.name,u.trigger="start",u.name="PlayAnimationOnClick_implicitAtStart_"+u.stateName;const p=new I;P.addComponent(p,u),c.push(p),l.push(h),s.add(p)}else for(const h of o){if(!h||!h.runtimeAnimatorController||!h.enabled)continue;Sh&&console.log(h);const d=[];for(const u of h.runtimeAnimatorController.enumerateActions()){Sh&&console.log(u);const p=u.getClip();d.includes(p)||d.push(p)}n.push({root:h.gameObject,clips:d})}if(t.injectImplicitBehaviours)for(const h of r){if(!h||!h.clip||!h.enabled||!h.playAutomatically||l.includes(h))continue;const d=new Xr;d.animation=h,d.stateName=h.clip.name,d.trigger="start",d.name="PlayAnimationOnClick_implicitAtStart_"+d.stateName;const u=new I;P.addComponent(u,d),c.push(u),l.push(h),s.add(u)}else for(const h of r){Sh&&console.log(h);const d=[];for(const u of h.animations)d.includes(u)||d.push(u);n.push({root:h.gameObject,clips:d})}Sh&&n?.length>0&&console.log("USDZ Animation Clips without behaviours",n);for(const h of n)for(const d of h.clips)t.registerAnimation(h.root,d);return c}function nE(s,t){const i=P.getComponentsInChildren(s,We),n=P.getComponentsInChildren(s,Lo),o=new Array,r=new Array;Sh&&console.log({audioSources:i,playAudioOnClicks:n});for(const l of n){if(!l.target)continue;const c=i.indexOf(l.target);c>-1&&i.splice(c,1)}for(const l of i){if(!l||!l.clip||l.volume<=0||o.includes(l))continue;const c=new Lo;c.target=l,c.name="PlayAudioOnClick_implicitAtStart_",c.trigger="start";const h=new I;P.addComponent(h,c),console.log("implicit PlayAudioOnStart",h,c),r.push(h),o.push(l),s.add(h)}return r}function oE(s){return new Et("DisableAtStart",xt.sceneStartTrigger(),ye.fadeAction(s,0,!1))}function t1(s,t){const i=s.domElement.shadowRoot.querySelector("link[rel='ar']");if(i)return i;const n=document.createElement("div");n.classList.add("menu"),n.classList.add("quicklook-menu"),n.style.display="none",n.style.visibility="hidden";const o=document.createElement("button");o.id="open-in-ar",t?(o.innerText="View in AR",o.title="View this scene in AR. The scene will be exported to USDZ and opened with Apple's QuickLook."):(o.innerText="View in AR",o.title="Download this scene for AR. Open the downloaded USDZ file to view it in AR using Apple's QuickLook."),n.appendChild(o);const r=document.createElement("a");r.id="needle-usdz-link",r.style.display="none",r.rel="ar",r.href="",r.target="_blank",n.appendChild(r);const l=document.createElement("img");return l.id="button",r.appendChild(l),s.domElement.shadowRoot.appendChild(n),r}var rE=Object.defineProperty,aE=Object.getOwnPropertyDescriptor,jt=(s,t,i,n)=>{for(var o=n>1?void 0:n?aE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&rE(t,i,o),o};const Bi=O("debugusdz"),lE=O("debugusdzpruning");class qo{constructor(){a(this,"callToAction"),a(this,"checkoutTitle"),a(this,"checkoutSubtitle"),a(this,"callToActionURL")}}jt([m()],qo.prototype,"callToAction",2),jt([m()],qo.prototype,"checkoutTitle",2),jt([m()],qo.prototype,"checkoutSubtitle",2),jt([m()],qo.prototype,"callToActionURL",2);var Cp;const I0=(Cp=class extends A{constructor(){super(...arguments),a(this,"objectToExport"),a(this,"autoExportAnimations",!0),a(this,"autoExportAudioSources",!0),a(this,"exportFileName"),a(this,"customUsdzFile"),a(this,"customBranding"),a(this,"anchoringType","plane"),a(this,"maxTextureSize",2048),a(this,"planeAnchoringAlignment","horizontal"),a(this,"interactive",!0),a(this,"physics",!0),a(this,"allowCreateQuicklookButton",!0),a(this,"quickLookCompatible",!0),a(this,"extensions",[]),a(this,"link"),a(this,"button"),a(this,"onClickedOpenInARElement",s=>{s.preventDefault(),this.exportAndOpen()}),a(this,"_currentExportTasks",new Map),a(this,"_previousTimeScale",1),a(this,"lastCallback"),a(this,"_rootSessionRootWasAppliedTo",null),a(this,"_rootPositionBeforeExport",new x),a(this,"_rootRotationBeforeExport",new V),a(this,"_rootScaleBeforeExport",new x)}start(){var s,t,i;Bi&&(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),!((t=(s=this.objectToExport)==null?void 0:s.children)!=null&&t.length)&&!((i=this.objectToExport)!=null&&i.isMesh)&&(this.objectToExport=this.context.scene)}onEnable(){var s;const t=X.supportsQuickLookAR(),i=X.isiOS()||X.isiPad();!this.button&&(Bi||t||i)&&(this.allowCreateQuicklookButton&&(this.button=this.createQuicklookButton()),this.lastCallback=this.quicklookCallback.bind(this),this.link=t1(this.context,t),this.link.addEventListener("message",this.lastCallback)),Bi&&Le("USDZ Exporter enabled: "+this.name),(s=document.getElementById("open-in-ar"))==null||s.addEventListener("click",this.onClickedOpenInARElement),fc.registerExporter(this)}onDisable(){var s,t,i;(s=this.button)==null||s.remove(),(t=this.link)==null||t.removeEventListener("message",this.lastCallback),Bi&&Le("USDZ Exporter disabled: "+this.name),(i=document.getElementById("open-in-ar"))==null||i.removeEventListener("click",this.onClickedOpenInARElement),fc.unregisterExporter(this)}async exportAsync(){return this.exportAndOpen()}async exportAndOpen(){var s;let t=this.exportFileName??((s=this.objectToExport)==null?void 0:s.name)??this.name;if(t+="-"+yx(),bo()||(t!==""&&(t+="-"),t+="MadeWithNeedle"),this.link||(this.link=t1(this.context,X.supportsQuickLookAR())),this.customUsdzFile)return Bi&&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 i=await this.export(this.objectToExport);return i?(Bi&&console.log("USDZ generation done. Downloading as "+t),this.openInQuickLook(i,t),i):(console.error("USDZ generation failed. Please report a bug",this),null)}async export(s){if(!s)return console.warn("No object to export"),null;const t=this._currentExportTasks.get(s);if(t)return t;const i=this.internalExport(s);return i instanceof Promise?(this._currentExportTasks.set(s,i),i.then(n=>(this._currentExportTasks.delete(s),n)).catch(n=>(this._currentExportTasks.delete(s),console.error("Error during USDZ export \u2013 please report a bug!",n),null))):i}async internalExport(s){ce.start("export-usdz",{onProgress:C=>{this.dispatchEvent(new CustomEvent("export-progress",{detail:{progress:C}}))}}),ce.report("export-usdz",{message:"Starting export",totalSteps:40,currentStep:0}),ce.report("export-usdz",{message:"Load progressive textures",autoStep:5}),ce.start("export-usdz-textures","export-usdz");const t=P.getComponentsInChildren(s,fi);for(const C of t)C&&C.enabled&&C.updateSprite(!0);const i=P.getComponentsInChildren(s,et),n=new Array;let o=0;for(const C of i){for(const R of C.sharedMeshes)if(R){const M=it.assignMeshLOD(R,0);M instanceof Promise&&n.push(new Promise((T,j)=>{M.then(()=>{o++,ce.report("export-usdz-textures",{message:"Loaded progressive mesh",currentStep:o,totalSteps:n.length}),T()}).catch(L=>j(L))}))}for(const R of C.sharedMaterials)if(R){const M=it.assignTextureLOD(R,0);M instanceof Promise&&n.push(new Promise((T,j)=>{M.then(()=>{o++,ce.report("export-usdz-textures",{message:"Loaded progressive texture",currentStep:o,totalSteps:n.length}),T()}).catch(L=>j(L))}))}}Bi&&Le("Progressive Loading: "+n.length),await Promise.all(n),Bi&&Le("Progressive Loading: done"),ce.end("export-usdz-textures");const r=Kt.Global.Mask;Kt.Global.Set(Zs.AR);const l=new xx,c=new ch(this.quickLookCompatible);let h;const d=[];this.interactive&&(d.push(new up),d.push(new dr),globalThis.true&&P.getComponentsInChildren(s,ve).length>0&&(this.physics?(h=new mp,d.push(h)):F()&&console.warn("USDZExporter: Physics export is disabled, but there are active Rigidbody components in the scene. They will not be exported.")),d.push(new yh),d.push(new vp));const u=[c,...d,...this.extensions],p={self:this,exporter:l,extensions:u,object:s};ce.report("export-usdz","Invoking before-export"),this.dispatchEvent(new CustomEvent("before-export",{detail:p})),this.applyWebARSessionRoot(),this._previousTimeScale=this.context.time.timeScale,this.context.time.timeScale=0,ce.report("export-usdz","auto export animations and audio sources");const g=new Array;this.autoExportAnimations&&g.push(...sE(s,c)),u.find(C=>C.extensionName==="Audio")&&this.autoExportAudioSources&&g.push(...nE(s)),l.debug=Bi,l.pruneUnusedNodes=!lE;const y=Hr.instance.objs.map(C=>C.batchedMesh);l.keepObject=C=>{let R=!0;const M=P.getComponent(C,et);return M&&!M.enabled&&(R=!1),R&&y.includes(C)&&(R=!1),R&&P.getComponentInParent(C,ks)&&(R=!1),R&&P.getComponentInParent(C,Hs)&&(R=!1),Bi&&!R&&console.log("USDZExporter: Discarding object",C),R},l.beforeWritingDocument=()=>{if(F()&&c&&h){const C=c.animatedRoots;for(const R of C){const M=P.getComponentsInChildren(R,ve).filter(j=>j.enabled),T=P.getComponents(R,pi).filter(j=>j.enabled&&!j.isTrigger);(M.length>0||T.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 f=new Array;this.objectToExport&&this.quickLookCompatible&&this.interactive&&this.objectToExport.traverse(C=>{C.visible||f.push(C)});const v=u.find(C=>C.extensionName==="Behaviour");this.interactive&&v&&f.length>0&&v.addBehavior(oE(f));let b=!0;this.quickLookCompatible&&!this.interactive&&(b=!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"),ce.report("export-usdz","Invoking exporter.parse");const w=await l.parse(this.objectToExport,{ar:{anchoring:{type:this.anchoringType},planeAnchoring:{alignment:this.planeAnchoringAlignment}},extensions:u,quickLookCompatible:this.quickLookCompatible,maxTextureSize:this.maxTextureSize,exportInvisible:b}),_=new Blob([w],{type:"model/vnd.usdz+zip"});this.revertWebARSessionRoot(),this.context.time.timeScale=this._previousTimeScale,ce.report("export-usdz","Invoking after-export"),this.dispatchEvent(new CustomEvent("after-export",{detail:p}));for(const C of g)P.destroy(C);return Kt.Global.Set(r),ce.end("export-usdz"),_}openInQuickLook(s,t){const i=s instanceof Blob?URL.createObjectURL(s):s,n=this.buildQuicklookOverlay();Bi&&console.log("QuickLook Overlay",n);const o=n.callToAction?encodeURIComponent(n.callToAction):"",r=n.checkoutTitle?encodeURIComponent(n.checkoutTitle):"",l=n.checkoutSubtitle?encodeURIComponent(n.checkoutSubtitle):"";this.link.href=i+`#callToAction=${o}&checkoutTitle=${r}&checkoutSubtitle=${l}&callToActionURL=${n.callToActionURL}`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=t+".usdz",this.link.click()}download(s,t){I0.save(s,t)}static save(s,t){const i=document.createElement("a");i.style.display="none",document.body.appendChild(i),typeof s=="string"?i.href=s:i.href=URL.createObjectURL(s),i.download=t,i.click(),i.remove()}quicklookCallback(s){if(s?.data=="_apple_ar_quicklook_button_tapped"){Bi&&xe("Quicklook closed via call to action button");var t=new CustomEvent("quicklook-button-tapped",{detail:this});if(this.dispatchEvent(t),!t.defaultPrevented){const i=new URLSearchParams(this.link.href);if(i){const n=i.get("callToActionURL");Bi&&Le("Quicklook url: "+n),n&&(bo()?globalThis.open(n,"_blank"):console.warn("Quicklook closed: custom redirects require a Needle Engine Pro license: https://needle.tools/pricing",n))}}}}buildQuicklookOverlay(){var s,t,i,n,o,r;const l={};return this.customBranding&&Object.assign(l,this.customBranding),bo()||(console.log("Custom Quicklook banner text requires pro license: https://needle.tools/pricing"),l.callToAction="Close",l.checkoutTitle="\u{1F335} Made with Needle",l.checkoutSubtitle="_"),(((s=l.callToAction)==null?void 0:s.length)||((t=l.checkoutTitle)==null?void 0:t.length)||((i=l.checkoutSubtitle)==null?void 0:i.length))&&((n=l.callToAction)!=null&&n.length||(l.callToAction="\0"),(o=l.checkoutTitle)!=null&&o.length||(l.checkoutTitle="\0"),(r=l.checkoutSubtitle)!=null&&r.length||(l.checkoutSubtitle="\0")),this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:l})),l}getARScaleAndTarget(){if(!this.objectToExport)return{scale:1,_invertForward:!1,target:this.gameObject,sessionRoot:null};const s=P.findObjectOfType(tt);let t=P.getComponentInParent(this.objectToExport,Hn);t||(t=P.getComponentInChildren(this.objectToExport,Hn));let i=1,n=!1;const o=this.objectToExport;return s?i=s.arScale:t&&(i=t.arScale,n=t.invertForward),{scale:1/i,_invertForward:n,target:o,sessionRoot:t?.gameObject??null}}applyWebARSessionRoot(){if(!this.objectToExport)return;const{scale:s,_invertForward:t,target:i,sessionRoot:n}=this.getARScaleAndTarget(),o=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(s),t&&i.quaternion.multiply(I0.invertForwardQuaternion),i.updateMatrix(),i.updateMatrixWorld(!0),n&&o&&i.matrix.premultiply(o)}revertWebARSessionRoot(){if(!this.objectToExport||!this._rootSessionRootWasAppliedTo)return;const s=this._rootSessionRootWasAppliedTo;s.position.copy(this._rootPositionBeforeExport),s.quaternion.copy(this._rootRotationBeforeExport),s.scale.copy(this._rootScaleBeforeExport),s.updateMatrix(),s.updateMatrixWorld(!0),this._rootSessionRootWasAppliedTo=null}createQuicklookButton(){const s=Kr.getOrCreate().createQuicklookButton();return s.parentNode||this.context.menu.appendChild(s),s}},a(Cp,"invertForwardMatrix",new ne().makeRotationY(Math.PI)),a(Cp,"invertForwardQuaternion",new V().setFromEuler(new Ut(0,Math.PI,0))),Cp);let Ge=I0;jt([m(I)],Ge.prototype,"objectToExport",2),jt([m()],Ge.prototype,"autoExportAnimations",2),jt([m()],Ge.prototype,"autoExportAudioSources",2),jt([m()],Ge.prototype,"exportFileName",2),jt([m(URL)],Ge.prototype,"customUsdzFile",2),jt([m(qo)],Ge.prototype,"customBranding",2),jt([m()],Ge.prototype,"anchoringType",2),jt([m()],Ge.prototype,"maxTextureSize",2),jt([m()],Ge.prototype,"planeAnchoringAlignment",2),jt([m()],Ge.prototype,"interactive",2),jt([m()],Ge.prototype,"physics",2),jt([m()],Ge.prototype,"allowCreateQuicklookButton",2),jt([m()],Ge.prototype,"quickLookCompatible",2);var cE=Object.defineProperty,hE=Object.getOwnPropertyDescriptor,j0=(s,t,i,n)=>{for(var o=n>1?void 0:n?hE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&cE(t,i,o),o};class Pl extends A{constructor(){super(...arguments),a(this,"_fog")}get fog(){return this._fog||(this._fog=new $y(0,0,50)),this._fog}get mode(){return 1}set near(t){this.fog.near=t}get near(){return this.fog.near}set far(t){this.fog.far=t}get far(){return this.fog.far}set color(t){this.fog.color.copy(t)}get color(){return this.fog.color}onEnable(){this.scene.fog=this.fog}onDisable(){this.scene.fog===this._fog&&(this.scene.fog=null)}}j0([m()],Pl.prototype,"near",1),j0([m()],Pl.prototype,"far",1),j0([m(re)],Pl.prototype,"color",1);var dE=Object.defineProperty,uE=Object.getOwnPropertyDescriptor,D0=(s,t,i,n)=>{for(var o=n>1?void 0:n?uE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&dE(t,i,o),o};class Zr extends A{constructor(){super(...arguments),a(this,"objectBounds",!1),a(this,"color"),a(this,"isGizmo",!0),a(this,"_gizmoObject",null),a(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!Cc||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new cC(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=_g(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),Me.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){for(var t;this._boxHelper;)(t=this._boxHelper)==null||t.update(),yield}}D0([m()],Zr.prototype,"objectBounds",2),D0([m(re)],Zr.prototype,"color",2),D0([m()],Zr.prototype,"isGizmo",2);var pE=Object.defineProperty,mE=Object.getOwnPropertyDescriptor,L0=(s,t,i,n)=>{for(var o=n>1?void 0:n?mE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&pE(t,i,o),o};class kl extends A{constructor(){super(...arguments),a(this,"isGizmo",!1),a(this,"color0"),a(this,"color1"),a(this,"gridHelper"),a(this,"size"),a(this,"divisions"),a(this,"offset")}onEnable(){if(this.isGizmo&&!Cc)return;const t=this.size,i=this.divisions;this.gridHelper||(this.gridHelper=new cm(t,i,this.color0??new re(.4,.4,.4),this.color1??new re(.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)}}L0([m()],kl.prototype,"isGizmo",2),L0([m(re)],kl.prototype,"color0",2),L0([m(re)],kl.prototype,"color1",2);var gE=Object.defineProperty,fE=Object.getOwnPropertyDescriptor,B0=(s,t,i,n)=>{for(var o=n>1?void 0:n?fE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&gE(t,i,o),o};class F0 extends A{constructor(){super(...arguments),a(this,"connectedBody"),a(this,"_rigidBody",null)}get rigidBody(){return this._rigidBody}onEnable(){this._rigidBody||(this._rigidBody=this.gameObject.getComponent(ve)),this.rigidBody&&this.connectedBody&&this.startCoroutine(this.create())}*create(){yield,this.rigidBody&&this.connectedBody&&this.activeAndEnabled&&this.createJoint(this.rigidBody,this.connectedBody)}}B0([m(ve)],F0.prototype,"connectedBody",2);class z0 extends F0{createJoint(t,i){var n;(n=this.context.physics.engine)==null||n.addFixedJoint(t,i)}}class Ch extends F0{constructor(){super(...arguments),a(this,"anchor"),a(this,"axis")}createJoint(t,i){var n;this.axis&&this.anchor&&((n=this.context.physics.engine)==null||n.addHingeJoint(t,i,this.anchor,this.axis))}}B0([m(x)],Ch.prototype,"anchor",2),B0([m(x)],Ch.prototype,"axis",2);var yE=Object.defineProperty,vE=Object.getOwnPropertyDescriptor,cn=(s,t,i,n)=>{for(var o=n>1?void 0:n?vE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&yE(t,i,o),o};function U0(s){return s*Math.PI/180}const i1=300,Go=O("debuglights");class yi extends A{constructor(){super(...arguments),a(this,"type",0),a(this,"range",1),a(this,"spotAngle",1),a(this,"innerSpotAngle",1),a(this,"_color",new re(16777215)),a(this,"_shadowNearPlane",.1),a(this,"_shadowBias",0),a(this,"_shadowNormalBias",0),a(this,"_overrideShadowBiasSettings",!1),a(this,"_shadows",1),a(this,"lightmapBakeType",4),a(this,"_intensity",-1),a(this,"_shadowDistance"),a(this,"shadowWidth"),a(this,"shadowHeight"),a(this,"_shadowResolution"),a(this,"light"),a(this,"_webXRStartedListener"),a(this,"_webXREndedListener"),a(this,"_webARRoot")}set color(t){this._color=t,this.light!==void 0&&(this.light.color=t)}get color(){return this.light?this.light.color:this._color}set shadowNearPlane(t){var i,n;if(t!==this._shadowNearPlane&&(this._shadowNearPlane=t,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.camera)!==void 0)){const o=this.light.shadow.camera;o.near=t}}get shadowNearPlane(){return this._shadowNearPlane}set shadowBias(t){var i,n;t!==this._shadowBias&&(this._shadowBias=t,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.bias)!==void 0&&(this.light.shadow.bias=t,this.light.shadow.needsUpdate=!0))}get shadowBias(){return this._shadowBias}set shadowNormalBias(t){var i,n;t!==this._shadowNormalBias&&(this._shadowNormalBias=t,((n=(i=this.light)==null?void 0:i.shadow)==null?void 0:n.normalBias)!==void 0&&(this.light.shadow.normalBias=t,this.light.shadow.needsUpdate=!0))}get shadowNormalBias(){return this._shadowNormalBias}set shadows(t){this._shadows=t,this.light&&(this.light.castShadow=t!==0,this.updateShadowSoftHard())}get shadows(){return this._shadows}set intensity(t){var i;if(this._intensity=t,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=t*n}Go&&console.log("Set light intensity to "+this._intensity,t,this)}get intensity(){return this._intensity}get shadowDistance(){const t=this.light;return t!=null&&t.shadow?t.shadow.camera.far:-1}set shadowDistance(t){this._shadowDistance=t;const i=this.light;if(i!=null&&i.shadow){const n=i.shadow.camera;n.far=t,n.updateProjectionMatrix()}}get shadowResolution(){const t=this.light;return t!=null&&t.shadow?t.shadow.mapSize.x:-1}set shadowResolution(t){if(t===this._shadowResolution)return;this._shadowResolution=t;const i=this.light;i!=null&&i.shadow&&(i.shadow.mapSize.set(t,t),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(t){return this.light?this.type===1?this.light.getWorldPosition(t).multiplyScalar(1):this.light.getWorldPosition(t):t}awake(){this.color=new re(this.color??16777215),Go&&console.log(this.name,this)}onEnable(){Go&&console.log("ENABLE LIGHT",this.name),this.createLight(),!this.isBaked&&(this.light&&(this.light.visible=!0,this.light.intensity=this._intensity,Go&&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(),Me.LateUpdate))}onDisable(){Go&&console.log("DISABLE LIGHT",this.name),this.light&&(this.selfIsLight?this.light.intensity=0:this.light.visible=!1)}onEnterXR(t){this._webARRoot=P.getComponentInParent(this.gameObject,Hn)??void 0}onLeaveXR(t){}createLight(){const t=this.selfIsLight;if(t&&!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 hm(this.color,this.intensity*Math.PI);if(i.position.set(0,0,-i1*.5).applyQuaternion(this.gameObject.quaternion),this.gameObject.add(i.target),yr(i.target,0,0,0),this.light=i,this.gameObject.position.set(0,0,0),this.gameObject.rotation.set(0,0,0),Go){const l=new dC(this.light,.2,this.color);this.context.scene.add(l)}break;case 0:const n=new hC(this.color,this.intensity*Math.PI,this.range,U0(this.spotAngle/2),1-U0(this.innerSpotAngle/2)/U0(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 r=new qy(this.color,this.intensity*Math.PI,this.range);this.light=r;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),Go&&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=i1*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,Go&&this.context.scene.add(new uC(i))}this.isBaked?this.light.removeFromParent():t||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(t){t.add(t.target),t.target.position.set(0,0,-1)}}a(yi,"allowChangingRendererShadowMapType",!0),cn([m()],yi.prototype,"type",2),cn([m(re)],yi.prototype,"color",1),cn([m()],yi.prototype,"shadowNearPlane",1),cn([m()],yi.prototype,"shadowBias",1),cn([m()],yi.prototype,"shadowNormalBias",1),cn([m()],yi.prototype,"shadows",1),cn([m()],yi.prototype,"lightmapBakeType",2),cn([m()],yi.prototype,"intensity",1),cn([m()],yi.prototype,"shadowDistance",1),cn([m()],yi.prototype,"shadowResolution",1),new x(0,0,0);var bE=Object.defineProperty,_E=Object.getOwnPropertyDescriptor,Oh=(s,t,i,n)=>{for(var o=n>1?void 0:n?_E(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&bE(t,i,o),o};const N0=O("debuglods"),wE=O("nolods");class Jr{constructor(){a(this,"screenRelativeTransitionHeight"),a(this,"distance"),a(this,"renderers")}}Oh([m()],Jr.prototype,"screenRelativeTransitionHeight",2),Oh([m()],Jr.prototype,"distance",2),Oh([m(et)],Jr.prototype,"renderers",2);class xE{constructor(t){a(this,"model"),this.model=t}get renderers(){return this.model.renderers}}class Ph extends A{constructor(){super(...arguments),a(this,"fadeMode",0),a(this,"localReferencePoint"),a(this,"lodCount",0),a(this,"size",0),a(this,"animateCrossFading",!1),a(this,"lodModels"),a(this,"_lods",[]),a(this,"_settings",[]),a(this,"_lodsHandler"),a(this,"_distanceFactor",1)}start(){if(N0&&console.log("LODGROUP",this.name,this.lodModels,this),!wE&&!this._lodsHandler&&this.gameObject&&this.lodModels&&Array.isArray(this.lodModels)){const t=[];for(const n of this.lodModels){const o=new xE(n);this._lods.push(o);for(const r of o.renderers)t.includes(r)||t.push(r)}this._lodsHandler=new Array;for(let n=0;n<t.length;n++){const o=new pC;this._lodsHandler.push(o),this.gameObject.add(o)}const i=new I;i.name="Cull "+this.name;for(let n=0;n<t.length;n++){const o=t[n],r=this._lodsHandler[n],l=o.gameObject;N0&&console.log(n,l.name);for(const c of this._lods){const h=c.model.distance;let d=null;if(c.renderers.includes(o)?d=l:d=i,d.type==="Group"){console.warn(`LODGroup ${this.name}: Group or MultiMaterial object's are not supported as LOD object: ${d.name}`);continue}N0&&console.log("LEVEL",d.name,h),r.autoUpdate=!1,this.onAddLodLevel(r,d,c.model.distance)}}}}onAfterRender(){if(!this.gameObject||!this._lodsHandler)return;const t=this.context.mainCamera;if(t)for(const i of this._lodsHandler){i.update(t);const n=i.getCurrentLevel(),o=i.levels[n];i.layers.mask=o.object.layers.mask}}onAddLodLevel(t,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}t.addLevel(i,n*this._distanceFactor,.01);const o={lod:t,levelIndex:t.levels.length-1,distance:n};this._settings.push(o)}distanceFactor(t){if(t!==this._distanceFactor){this._distanceFactor=t;for(const i of this._settings){const n=i.lod.levels[i.levelIndex];n.distance=i.distance*t}}}}Oh([m(x)],Ph.prototype,"localReferencePoint",2),Oh([m(Jr)],Ph.prototype,"lodModels",2);var SE=Object.defineProperty,CE=Object.getOwnPropertyDescriptor,OE=(s,t,i,n)=>{for(var o=n>1?void 0:n?CE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&SE(t,i,o),o};const Op=O("debugnestedgltf");class Pp extends A{constructor(){super(...arguments),a(this,"filePath"),a(this,"loadAssetInParent",!0),a(this,"_isLoadingOrDoneLoading",!1)}listenToProgress(t){var i;(i=this.filePath)==null||i.beginListenDownload(t)}preload(){var t;(t=this.filePath)==null||t.preload()}async start(){var t,i,n,o,r;if(this._isLoadingOrDoneLoading)return;Op&&console.log(this,this.guid);const l=this.gameObject.parent;if(l){this._isLoadingOrDoneLoading=!0;const c=new Ls;c.idProvider=new zt(this.hash(this.guid)),c.parent=this.loadAssetInParent!==!1?l:this.gameObject,this.gameObject.updateMatrix();const h=this.gameObject.matrix;Op&&console.log("Load nested:",((t=this.filePath)==null?void 0:t.url)??this.filePath,this.gameObject.position);const d=await((n=(i=this.filePath)==null?void 0:i.instantiate)==null?void 0:n.call(this.filePath,c));Op&&console.log("Nested loaded:",((o=this.filePath)==null?void 0:o.url)??this.filePath,d),d&&this.loadAssetInParent!==!1&&(d.matrixAutoUpdate=!1,d.matrix.identity(),d.applyMatrix4(h),d.matrixAutoUpdate=!0,d.layers.disableAll(),d.layers.set(this.layer),this.dispatchEvent(new CustomEvent("loaded",{detail:{instance:d,assetReference:this.filePath}}))),Op&&console.log("Nested loading done:",((r=this.filePath)==null?void 0:r.url)??this.filePath,d)}}onDestroy(){var t;(t=this.filePath)==null||t.unload()}hash(t){let i=0;for(let n=0;n<t.length;n++)i=t.charCodeAt(n)+((i<<5)-i);return i}}OE([m(ae)],Pp.prototype,"filePath",2);var PE=Object.defineProperty,kE=Object.getOwnPropertyDescriptor,W0=(s,t,i,n)=>{for(var o=n>1?void 0:n?kE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&PE(t,i,o),o};const ME=O("debugnet"),V0=class extends A{constructor(){super(...arguments),a(this,"url",null),a(this,"urlParameterName",null),a(this,"localhost",null)}awake(){ME&&console.log(this),this.context.connection.registerProvider(this)}getWebsocketUrl(){let s=this.url?V0.GetUrl(this.url,this.localhost):null;if(this.urlParameterName){const i=O(this.urlParameterName);i&&typeof i=="string"&&(s=i)}if(!s)return null;const t=new RegExp("(((https?)|(?<socket_prefix>wss?))://)?(www.)?(?<url>.+)","gm").exec(s);return t!=null&&t.groups?t?.groups.socket_prefix?s:"wss://"+t?.groups.url:null}static GetUrl(s,t){let i=s;const n=V0.IsLocalNetwork()&&t;if(n&&(i=t),s!=null&&s.startsWith("/")){const o=n?i:window.location.origin;o!=null&&o.endsWith("/")&&s.startsWith("/")&&(s=s.substring(1)),i=o+s}return i}static IsLocalNetwork(s=window.location.hostname){return Gt(s)}};let Ml=V0;W0([m()],Ml.prototype,"url",2),W0([m()],Ml.prototype,"urlParameterName",2),W0([m()],Ml.prototype,"localhost",2);var RE=Object.defineProperty,TE=Object.getOwnPropertyDescriptor,kp=(s,t,i,n)=>{for(var o=n>1?void 0:n?TE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&RE(t,i,o),o};class ea extends A{constructor(){super(...arguments),a(this,"referenceSpace"),a(this,"from"),a(this,"affectPosition",!1),a(this,"affectRotation",!1),a(this,"alignLookDirection",!1),a(this,"levelLookDirection",!1),a(this,"levelPosition",!1),a(this,"positionOffset",new x(0,0,0)),a(this,"rotationOffset",new x(0,0,0)),a(this,"offset",new x(0,0,0))}update(){if(!this.from)return;var t=te(this.from),i=Oe(this.from);this.offset.copy(this.positionOffset);const n=this.offset.length();if(this.referenceSpace&&this.offset.transformDirection(this.referenceSpace.matrixWorld).multiplyScalar(n),t.add(this.offset),this.levelPosition&&this.referenceSpace){const c=new pr(this.gameObject.up,0),h=te(this.referenceSpace);c.setFromNormalAndCoplanarPoint(this.gameObject.up,h);const d=new x(0,0,0);c.projectPoint(t,d),t.copy(d)}this.affectPosition&&ut(this.gameObject,t);const o=new Ut(this.rotationOffset.x,this.rotationOffset.y,this.rotationOffset.z),r=new V().setFromEuler(o);this.affectRotation&&Gi(this.gameObject,i.multiply(r));const l=new x;this.from.getWorldDirection(l).multiplyScalar(50),this.levelLookDirection&&(l.y=0),this.alignLookDirection&&this.gameObject.lookAt(l)}}kp([m(P)],ea.prototype,"referenceSpace",2),kp([m(P)],ea.prototype,"from",2),kp([m(x)],ea.prototype,"positionOffset",2),kp([m(x)],ea.prototype,"rotationOffset",2);var EE=Object.defineProperty,AE=Object.getOwnPropertyDescriptor,k=(s,t,i,n)=>{for(var o=n>1?void 0:n?AE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&EE(t,i,o),o};const Mp=O("debugparticles");var qn=(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))(qn||{});class Xo{constructor(){a(this,"alphaKeys",[]),a(this,"colorKeys",[])}get duration(){return 1}evaluate(t,i){let n,o=0,r=null,l=0;for(let c=0;c<this.alphaKeys.length;c++){const h=this.alphaKeys[c];(h.time<t||!n)&&(n=h,o=c)}for(let c=0;c<this.colorKeys.length;c++){const h=this.colorKeys[c];(h.time<t||!r)&&(r=h,l=c)}if(r)if(l+1<this.colorKeys.length){const c=this.colorKeys[l+1],h=W.remap(t,r.time,c.time,0,1);i.r=W.lerp(r.color.r,c.color.r,h),i.g=W.lerp(r.color.g,c.color.g,h),i.b=W.lerp(r.color.b,c.color.b,h)}else i.r=r.color.r,i.g=r.color.g,i.b=r.color.b;if(n)if(o+1<this.alphaKeys.length){const c=this.alphaKeys[o+1],h=W.remap(t,n.time,c.time,0,1);i.alpha=W.lerp(n.alpha,c.alpha,h)}else i.alpha=n.alpha;return i}}k([m()],Xo.prototype,"alphaKeys",2),k([m()],Xo.prototype,"colorKeys",2);var kh=(s=>(s[s.Local=0]="Local",s[s.World=1]="World",s[s.Custom=2]="Custom",s))(kh||{}),Rp=(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))(Rp||{});const Mh=class{constructor(){a(this,"mode","Constant"),a(this,"constant"),a(this,"constantMin"),a(this,"constantMax"),a(this,"curve"),a(this,"curveMin"),a(this,"curveMax"),a(this,"curveMultiplier")}static constant(s){const t=new Mh;return t.setConstant(s),t}static betweenTwoConstants(s,t){const i=new Mh;return i.setMinMaxConstant(s,t),i}static curve(s,t=1){const i=new Mh;return i.setCurve(s,t),i}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 s,t,i;const n=new Mh;return n.mode=this.mode,n.constant=this.constant,n.constantMin=this.constantMin,n.constantMax=this.constantMax,n.curve=(s=this.curve)==null?void 0:s.clone(),n.curveMin=(t=this.curveMin)==null?void 0:t.clone(),n.curveMax=(i=this.curveMax)==null?void 0:i.clone(),n.curveMultiplier=this.curveMultiplier,n}evaluate(s,t){const i=t===void 0?Math.random():t;switch(this.mode){case 0:case"Constant":return this.constant;case 1:case"Curve":return s=W.clamp01(s),this.curve.evaluate(s)*this.curveMultiplier;case 2:case"TwoCurves":const n=s*this.curveMin.duration,o=s*this.curveMax.duration;return W.lerp(this.curveMin.evaluate(n),this.curveMax.evaluate(o),i%1)*this.curveMultiplier;case 3:case"TwoConstants":return W.lerp(this.constantMin,this.constantMax,i%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 i=0;i<s.keys.length;i++){const n=s.keys[i];n.value>t&&(t=n.value)}return t}};let Q=Mh;k([m()],Q.prototype,"mode",2),k([m()],Q.prototype,"constant",2),k([m()],Q.prototype,"constantMin",2),k([m()],Q.prototype,"constantMax",2),k([m(Lr)],Q.prototype,"curve",2),k([m(Lr)],Q.prototype,"curveMin",2),k([m(Lr)],Q.prototype,"curveMax",2),k([m()],Q.prototype,"curveMultiplier",2);var Tp;const Dt=(Tp=class{constructor(){a(this,"mode",0),a(this,"color"),a(this,"colorMin"),a(this,"colorMax"),a(this,"gradient"),a(this,"gradientMin"),a(this,"gradientMax")}static constant(s){const t=new Dt;return t.constant(s),t}static betweenTwoColors(s,t){const i=new Dt;return i.betweenTwoColors(s,t),i}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 i=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,Dt._temp),Dt._temp;case 2:case"TwoColors":return Dt._temp.lerpColors(this.colorMin,this.colorMax,i);case 3:case"TwoGradients":return this.gradientMin.evaluate(s,Dt._temp),this.gradientMax.evaluate(s,Dt._temp2),Dt._temp.lerp(Dt._temp2,i);case 4:case"RandomColor":const n=Math.random();return this.gradientMin.evaluate(s,Dt._temp),this.gradientMax.evaluate(s,Dt._temp2),Dt._temp.lerp(Dt._temp2,n)}return Dt._temp.set(16777215),Dt._temp.alpha=1,Dt._temp}},a(Tp,"_temp",new Se(0,0,0,1)),a(Tp,"_temp2",new Se(0,0,0,1)),Tp);let si=Dt;k([m()],si.prototype,"mode",2),k([m(Se)],si.prototype,"color",2),k([m(Se)],si.prototype,"colorMin",2),k([m(Se)],si.prototype,"colorMax",2),k([m(Xo)],si.prototype,"gradient",2),k([m(Xo)],si.prototype,"gradientMin",2),k([m(Xo)],si.prototype,"gradientMax",2);var H0=(s=>(s[s.Hierarchy=0]="Hierarchy",s[s.Local=1]="Local",s[s.Shape=2]="Shape",s))(H0||{});class Lt{constructor(){a(this,"cullingMode"),a(this,"duration"),a(this,"emitterVelocityMode"),a(this,"flipRotation"),a(this,"gravityModifier"),a(this,"gravityModifierMultiplier"),a(this,"loop"),a(this,"maxParticles"),a(this,"playOnAwake"),a(this,"prewarm"),a(this,"ringBufferLoopRange"),a(this,"ringBufferMode"),a(this,"scalingMode"),a(this,"simulationSpace"),a(this,"simulationSpeed"),a(this,"startColor"),a(this,"startDelay"),a(this,"startDelayMultiplier"),a(this,"startLifetime"),a(this,"startLifetimeMultiplier"),a(this,"startRotation"),a(this,"startRotationMultiplier"),a(this,"startRotation3D"),a(this,"startRotationX"),a(this,"startRotationXMultiplier"),a(this,"startRotationY"),a(this,"startRotationYMultiplier"),a(this,"startRotationZ"),a(this,"startRotationZMultiplier"),a(this,"startSize"),a(this,"startSize3D"),a(this,"startSizeMultiplier"),a(this,"startSizeX"),a(this,"startSizeXMultiplier"),a(this,"startSizeY"),a(this,"startSizeYMultiplier"),a(this,"startSizeZ"),a(this,"startSizeZMultiplier"),a(this,"startSpeed"),a(this,"startSpeedMultiplier"),a(this,"stopAction"),a(this,"useUnscaledTime")}}k([m(Q)],Lt.prototype,"gravityModifier",2),k([m(si)],Lt.prototype,"startColor",2),k([m(Q)],Lt.prototype,"startDelay",2),k([m(Q)],Lt.prototype,"startLifetime",2),k([m(Q)],Lt.prototype,"startRotation",2),k([m(Q)],Lt.prototype,"startRotationX",2),k([m(Q)],Lt.prototype,"startRotationY",2),k([m(Q)],Lt.prototype,"startRotationZ",2),k([m(Q)],Lt.prototype,"startSize",2),k([m(Q)],Lt.prototype,"startSizeX",2),k([m(Q)],Lt.prototype,"startSizeY",2),k([m(Q)],Lt.prototype,"startSizeZ",2),k([m(Q)],Lt.prototype,"startSpeed",2);class Rh{constructor(){a(this,"cycleCount"),a(this,"maxCount"),a(this,"minCount"),a(this,"probability"),a(this,"repeatInterval"),a(this,"time"),a(this,"count"),a(this,"_performed",0)}reset(){this._performed=0}run(t){if(t<=this.time)return 0;let i=0;if(this.cycleCount===0||this._performed<this.cycleCount){const n=this.time+this.repeatInterval*this._performed;if(t>=n&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:i=this.count.constant;break;case 3:i=W.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:i=this.count.curve.evaluate(Math.random());break;case 2:const o=Math.random();i=W.lerp(this.count.curveMin.evaluate(o),this.count.curveMax.evaluate(o),Math.random());break}}return i}}class hn{constructor(){a(this,"enabled"),a(this,"bursts"),a(this,"rateOverTime"),a(this,"rateOverTimeMultiplier"),a(this,"rateOverDistance"),a(this,"rateOverDistanceMultiplier"),a(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(i=>i.reset())}getBurst(){let t=0;if(this.burstCount>0)for(let i=0;i<this.burstCount;i++){const n=this.bursts[i];this.system.main.loop&&n.time>=this.system.time&&n.reset(),t+=Math.round(n.run(this.system.time))}return t}}k([m()],hn.prototype,"enabled",2),k([m()],hn.prototype,"bursts",2),k([m(Q)],hn.prototype,"rateOverTime",2),k([m()],hn.prototype,"rateOverTimeMultiplier",2),k([m(Q)],hn.prototype,"rateOverDistance",2),k([m()],hn.prototype,"rateOverDistanceMultiplier",2);class Th{constructor(){a(this,"enabled"),a(this,"color")}}k([m(si)],Th.prototype,"color",2);class Qo{constructor(){a(this,"enabled"),a(this,"separateAxes"),a(this,"size"),a(this,"sizeMultiplier"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier"),a(this,"_time",0),a(this,"_temp",new x)}evaluate(t,i,n){if(i||(i=this._temp),!this.enabled)return i.x=i.y=i.z=1,i;if(this.separateAxes)i.x=this.x.evaluate(t,n)*this.xMultiplier,i.y=this.y.evaluate(t,n)*this.yMultiplier,i.z=this.z.evaluate(t,n)*this.zMultiplier;else{const o=this.size.evaluate(t,n)*this.sizeMultiplier;i.x=o}return i}}k([m(Q)],Qo.prototype,"size",2),k([m(Q)],Qo.prototype,"x",2),k([m(Q)],Qo.prototype,"y",2),k([m(Q)],Qo.prototype,"z",2);var Ep;const Eh=(Ep=class{constructor(){a(this,"shapeType",5),a(this,"enabled",!0),a(this,"alignToDirection",!1),a(this,"angle",0),a(this,"arc",360),a(this,"arcSpread"),a(this,"arcSpeedMultiplier"),a(this,"arcMode"),a(this,"boxThickness"),a(this,"position"),a(this,"rotation"),a(this,"_rotation",new Ut),a(this,"scale"),a(this,"radius"),a(this,"radiusThickness"),a(this,"sphericalDirectionAmount"),a(this,"randomDirectionAmount"),a(this,"randomPositionAmount"),a(this,"meshShapeType"),a(this,"meshRenderer"),a(this,"_meshObj"),a(this,"_meshGeometry"),a(this,"system"),a(this,"_space"),a(this,"_worldSpaceMatrix",new ne),a(this,"_worldSpaceMatrixInverse",new ne),a(this,"_vector",new x(0,0,0)),a(this,"_temp",new x(0,0,0)),a(this,"_triangle",new mC),a(this,"_dir",new x),a(this,"_loopTime",0),a(this,"_loopDirection",1),Mp&&console.log(this)}get type(){return Rp[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 Eh}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,i,n){this.system=s,this._space=i,i===1&&(this._worldSpaceMatrix.copy(n.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=W.toRadians(this.rotation.x),this._rotation.y=W.toRadians(this.rotation.y),this._rotation.z=W.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),i=this._space===1;i&&t.applyQuaternion(this.system.worldQuaternion);let n=this.radius;if(i&&(n*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:Mp&&q.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,n,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,n,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,n,this.radiusThickness,this.arc,this._vector);break;case 13:const o=this.meshRenderer;o?.destroyed==!1&&this.setMesh(o);const r=s.mesh=this._meshObj,l=s.mesh_geometry=this._meshGeometry;if(r&&l)switch(this.meshShapeType){case 0:{const c=l.getAttribute("position"),h=Math.floor(Math.random()*c.count);this._vector.fromBufferAttribute(c,h),this._vector.applyMatrix4(r.matrixWorld),s.mesh_normal=h}break;case 1:break;case 2:{const c=l.index;if(c){let h=Math.random(),d=Math.random();h+d>1&&(h=1-h,d=1-d);const u=Math.floor(Math.random()*(c.count/3));let p=u*3,g=u*3+1,y=u*3+2;p=c.getX(p),g=c.getX(g),y=c.getX(y);const f=l.getAttribute("position");this._triangle.a.fromBufferAttribute(f,p),this._triangle.b.fromBufferAttribute(f,g),this._triangle.c.fromBufferAttribute(f,y),this._vector.set(0,0,0).addScaledVector(this._triangle.a,h).addScaledVector(this._triangle.b,d).addScaledVector(this._triangle.c,1-(h+d)),this._vector.applyMatrix4(r.matrixWorld),s.mesh_normal=u}}break}break;default:this._vector.set(0,0,0),F()&&!globalThis.__particlesystem_shapetype_unsupported&&(console.warn("ParticleSystem ShapeType is not supported:",Rp[this.shapeType]),globalThis.__particlesystem_shapetype_unsupported=!0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),i&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),Mp&&q.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(s,t){var i;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 n=t.x,o=t.y,r=t.z;this._dir.set(n,o,r),(i=this.system)!=null&&i.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;case 13:const l=s.mesh,c=s.mesh_geometry;if(l&&c)switch(this.meshShapeType){case 0:{const h=c.getAttribute("normal"),d=s.mesh_normal;this._dir.fromBufferAttribute(h,d)}break;case 1:break;case 2:{const h=c.index;if(h){const d=s.mesh_normal,u=h.getX(d*3),p=h.getX(d*3+1),g=h.getX(d*3+2),y=c.getAttribute("position"),f=G(),v=G(),b=G();f.fromBufferAttribute(y,u),v.fromBufferAttribute(y,p),b.fromBufferAttribute(y,g),f.sub(v),b.sub(v),f.cross(b),this._dir.copy(f).multiplyScalar(-1);const w=Oe(l);this._dir.applyQuaternion(w)}}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),Mp&&(q.DrawSphere(t,.01,8925952,.5,!0),q.DrawDirection(t,this._dir,8925952,.5,!0)),this._dir}randomizePosition(s,t){if(t<=0)return;const i=Eh._tempVec;i.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),i.x*=t*this.scale.x,i.y*=t*this.scale.y,i.z*=t*this.scale.z,s.add(i)}randomizeDirection(s,t){if(t===0)return;const i=Eh._randomQuat,n=Eh._tempVec;n.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),i.setFromAxisAngle(n,t*Math.random()*Math.PI),s.applyQuaternion(i)}spherizeDirection(s,t){if(t===0)return;const i=Math.random()*Math.PI*2,n=Math.acos(1-Math.random()*2),o=Math.sin(n)*Math.cos(i),r=Math.sin(n)*Math.sin(i),l=Math.cos(n),c=new x(o,r,l);s.lerp(c,t)}randomSpherePoint(s,t,i,n,o){const r=Math.random(),l=Math.random(),c=2*Math.PI*r*(n/360),h=Math.acos(2*l-1),d=W.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*t,u=s.x+this.scale.x*(-d*Math.sin(h)*Math.cos(c)),p=s.y+this.scale.y*(d*Math.sin(h)*Math.sin(c)),g=s.z+this.scale.z*(d*Math.cos(h));o.x=u,o.y=p,o.z=g}randomCirclePoint(s,t,i,n,o){const r=Math.random(),l=2*Math.PI*r*(n/360),c=W.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*t,h=s.x+this.scale.x*c*Math.cos(l),d=s.y+this.scale.y*c*Math.sin(l),u=s.z;o.x=h,o.y=d,o.z=u}randomConePoint(s,t,i,n,o,r,l){let c=0,h=0;switch(r){case 0:c=Math.random(),h=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:c=.5,h=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let d=2*Math.PI*c*(o/360);switch(r){case 2:case 1:d+=Math.PI+.5,d+=this._loopTime*Math.PI*2,d%=W.toRadians(o);break}const u=Math.acos(2*h-1),p=W.lerp(1,1-Math.pow(1-Math.random(),Math.PI),n)*i,g=s.x+-p*Math.sin(u)*Math.cos(d),y=s.y+p*Math.sin(u)*Math.sin(d),f=s.z;l.x=g*this.scale.x,l.y=y*this.scale.y,l.z=f*this.scale.z}},a(Ep,"_randomQuat",new V),a(Ep,"_tempVec",new x),Ep);let Xe=Eh;k([m()],Xe.prototype,"shapeType",2),k([m()],Xe.prototype,"enabled",2),k([m()],Xe.prototype,"alignToDirection",2),k([m()],Xe.prototype,"angle",2),k([m()],Xe.prototype,"arc",2),k([m()],Xe.prototype,"arcSpread",2),k([m()],Xe.prototype,"arcSpeedMultiplier",2),k([m()],Xe.prototype,"arcMode",2),k([m(x)],Xe.prototype,"boxThickness",2),k([m(x)],Xe.prototype,"position",2),k([m(x)],Xe.prototype,"rotation",2),k([m(x)],Xe.prototype,"scale",2),k([m()],Xe.prototype,"radius",2),k([m()],Xe.prototype,"radiusThickness",2),k([m()],Xe.prototype,"sphericalDirectionAmount",2),k([m()],Xe.prototype,"randomDirectionAmount",2),k([m()],Xe.prototype,"randomPositionAmount",2),k([m()],Xe.prototype,"meshShapeType",2),k([m(rh)],Xe.prototype,"meshRenderer",2);class Ce{constructor(){a(this,"damping"),a(this,"enabled"),a(this,"frequency"),a(this,"octaveCount"),a(this,"octaveMultiplier"),a(this,"octaveScale"),a(this,"positionAmount"),a(this,"quality"),a(this,"remap"),a(this,"remapEnabled"),a(this,"remapMultiplier"),a(this,"remapX"),a(this,"remapXMultiplier"),a(this,"remapY"),a(this,"remapYMultiplier"),a(this,"remapZ"),a(this,"remapZMultiplier"),a(this,"scrollSpeedMultiplier"),a(this,"separateAxes"),a(this,"strengthMultiplier"),a(this,"strengthX"),a(this,"strengthXMultiplier"),a(this,"strengthY"),a(this,"strengthYMultiplier"),a(this,"strengthZ"),a(this,"strengthZMultiplier"),a(this,"_noise"),a(this,"_time",0),a(this,"_temp",new x)}update(t){this._time+=t.time.deltaTime*this.scrollSpeedMultiplier}apply(t,i,n,o,r,l){if(!this.enabled)return;this._noise||(this._noise=JC(()=>0));const c=this._temp.set(i.x,i.y,i.z).multiplyScalar(this.frequency),h=this._noise(c.x,c.y,c.z,this._time),d=this._noise(c.x,c.y,c.z,this._time+1e3*this.frequency),u=this._noise(c.x,c.y,c.z,this._time+2e3*this.frequency);this._temp.set(h,d,u).normalize();const p=r/l;let g=this.positionAmount.evaluate(p);this.separateAxes?(this._temp.x*=g*this.strengthXMultiplier,this._temp.y*=g*this.strengthYMultiplier,this._temp.z*=g*this.strengthZMultiplier):(this.strengthX&&(g*=this.strengthX.evaluate(p)*1.5),this._temp.multiplyScalar(g)),n.x+=this._temp.x,n.y+=this._temp.y,n.z+=this._temp.z}}k([m()],Ce.prototype,"damping",2),k([m()],Ce.prototype,"enabled",2),k([m()],Ce.prototype,"frequency",2),k([m()],Ce.prototype,"octaveCount",2),k([m()],Ce.prototype,"octaveMultiplier",2),k([m()],Ce.prototype,"octaveScale",2),k([m(Q)],Ce.prototype,"positionAmount",2),k([m()],Ce.prototype,"quality",2),k([m(Q)],Ce.prototype,"remap",2),k([m()],Ce.prototype,"remapEnabled",2),k([m()],Ce.prototype,"remapMultiplier",2),k([m(Q)],Ce.prototype,"remapX",2),k([m()],Ce.prototype,"remapXMultiplier",2),k([m(Q)],Ce.prototype,"remapY",2),k([m()],Ce.prototype,"remapYMultiplier",2),k([m(Q)],Ce.prototype,"remapZ",2),k([m()],Ce.prototype,"remapZMultiplier",2),k([m()],Ce.prototype,"scrollSpeedMultiplier",2),k([m()],Ce.prototype,"separateAxes",2),k([m()],Ce.prototype,"strengthMultiplier",2),k([m(Q)],Ce.prototype,"strengthX",2),k([m()],Ce.prototype,"strengthXMultiplier",2),k([m(Q)],Ce.prototype,"strengthY",2),k([m()],Ce.prototype,"strengthYMultiplier",2),k([m(Q)],Ce.prototype,"strengthZ",2),k([m()],Ce.prototype,"strengthZMultiplier",2);class Ue{constructor(){a(this,"enabled"),a(this,"attachRibbonToTransform",!1),a(this,"colorOverLifetime"),a(this,"colorOverTrail"),a(this,"dieWithParticles",!0),a(this,"inheritParticleColor",!0),a(this,"lifetime"),a(this,"lifetimeMultiplier"),a(this,"minVertexDistance",.2),a(this,"mode",0),a(this,"ratio",1),a(this,"ribbonCount",1),a(this,"shadowBias",0),a(this,"sizeAffectsLifetime",!1),a(this,"sizeAffectsWidth",!1),a(this,"splitSubEmitterRibbons",!1),a(this,"textureMode",0),a(this,"widthOverTrail"),a(this,"widthOverTrailMultiplier"),a(this,"worldSpace",!1)}getWidth(t,i,n,o){const r=this.widthOverTrail.evaluate(n,o);return t*=r,t}getColor(t,i,n){const o=this.colorOverTrail.evaluate(n),r=this.colorOverLifetime.evaluate(i);t.x*=o.r*r.r,t.y*=o.g*r.g,t.z*=o.b*r.b,"alpha"in o&&"alpha"in r&&(t.w*=o.alpha*r.alpha)}}k([m()],Ue.prototype,"enabled",2),k([m()],Ue.prototype,"attachRibbonToTransform",2),k([m(si)],Ue.prototype,"colorOverLifetime",2),k([m(si)],Ue.prototype,"colorOverTrail",2),k([m()],Ue.prototype,"dieWithParticles",2),k([m()],Ue.prototype,"inheritParticleColor",2),k([m(Q)],Ue.prototype,"lifetime",2),k([m()],Ue.prototype,"lifetimeMultiplier",2),k([m()],Ue.prototype,"minVertexDistance",2),k([m()],Ue.prototype,"mode",2),k([m()],Ue.prototype,"ratio",2),k([m()],Ue.prototype,"ribbonCount",2),k([m()],Ue.prototype,"shadowBias",2),k([m()],Ue.prototype,"sizeAffectsLifetime",2),k([m()],Ue.prototype,"sizeAffectsWidth",2),k([m()],Ue.prototype,"splitSubEmitterRibbons",2),k([m()],Ue.prototype,"textureMode",2),k([m(Q)],Ue.prototype,"widthOverTrail",2),k([m()],Ue.prototype,"widthOverTrailMultiplier",2),k([m()],Ue.prototype,"worldSpace",2);class Qe{constructor(){a(this,"enabled"),a(this,"space",0),a(this,"orbitalX"),a(this,"orbitalY"),a(this,"orbitalZ"),a(this,"orbitalXMultiplier"),a(this,"orbitalYMultiplier"),a(this,"orbitalZMultiplier"),a(this,"orbitalOffsetX"),a(this,"orbitalOffsetY"),a(this,"orbitalOffsetZ"),a(this,"speedModifier"),a(this,"speedModifierMultiplier"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier"),a(this,"_system"),a(this,"_temp",new x),a(this,"_temp2",new x),a(this,"_temp3",new x),a(this,"_hasOrbital",!1),a(this,"_index",0),a(this,"_orbitalMatrix",new ne)}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,i,n,o,r,l,c){var h;if(!this.enabled)return;const d=l/c,u=this.speedModifier.evaluate(d)*this.speedModifierMultiplier,p=this.x.evaluate(d),g=this.y.evaluate(d),y=this.z.evaluate(d);if(this._temp.set(-p,g,y),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((h=this._system)==null?void 0:h.worldPos)){const f=this._temp2.set(n.x,n.y,n.z),v=this.orbitalXMultiplier,b=this.orbitalYMultiplier,w=this.orbitalZMultiplier,_=u*Math.PI*2*10,C=Math.cos(_*v),R=Math.sin(_*v),M=Math.cos(_*b),T=Math.sin(_*b),j=Math.cos(_*w),L=Math.sin(_*w),U=f.x*(M*j)+f.y*(M*L)+f.z*-T,B=f.x*(R*T*j-C*L)+f.y*(R*T*L+C*j)+f.z*(R*M),Y=f.x*(C*T*j+R*L)+f.y*(C*T*L-R*j)+f.z*(C*M),$=this._temp3.set(f.x-U,f.y-B,f.z-Y);$.normalize(),$.multiplyScalar(.2/r*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),o.x+=$.x,o.y+=$.y,o.z+=$.z}o.x+=this._temp.x,o.y+=this._temp.y,o.z+=this._temp.z,o.x*=u,o.y*=u,o.z*=u}}k([m()],Qe.prototype,"enabled",2),k([m()],Qe.prototype,"space",2),k([m(Q)],Qe.prototype,"orbitalX",2),k([m(Q)],Qe.prototype,"orbitalY",2),k([m(Q)],Qe.prototype,"orbitalZ",2),k([m()],Qe.prototype,"orbitalXMultiplier",2),k([m()],Qe.prototype,"orbitalYMultiplier",2),k([m()],Qe.prototype,"orbitalZMultiplier",2),k([m()],Qe.prototype,"orbitalOffsetX",2),k([m()],Qe.prototype,"orbitalOffsetY",2),k([m()],Qe.prototype,"orbitalOffsetZ",2),k([m(Q)],Qe.prototype,"speedModifier",2),k([m()],Qe.prototype,"speedModifierMultiplier",2),k([m(Q)],Qe.prototype,"x",2),k([m()],Qe.prototype,"xMultiplier",2),k([m(Q)],Qe.prototype,"y",2),k([m()],Qe.prototype,"yMultiplier",2),k([m(Q)],Qe.prototype,"z",2),k([m()],Qe.prototype,"zMultiplier",2);class Bt{constructor(){a(this,"animation"),a(this,"enabled"),a(this,"cycleCount"),a(this,"frameOverTime"),a(this,"frameOverTimeMultiplier"),a(this,"numTilesX"),a(this,"numTilesY"),a(this,"startFrame"),a(this,"startFrameMultiplier"),a(this,"rowMode"),a(this,"rowIndex"),a(this,"spriteCount"),a(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 i=this.numTilesX*this.numTilesY;t=t*this.cycleCount;let n=this.frameOverTime.evaluate(t%1);return n*=this.frameOverTimeMultiplier,n*=i,n=n%i,n=Math.floor(n),n}}k([m()],Bt.prototype,"animation",2),k([m()],Bt.prototype,"enabled",2),k([m()],Bt.prototype,"cycleCount",2),k([m(Q)],Bt.prototype,"frameOverTime",2),k([m()],Bt.prototype,"frameOverTimeMultiplier",2),k([m()],Bt.prototype,"numTilesX",2),k([m()],Bt.prototype,"numTilesY",2),k([m(Q)],Bt.prototype,"startFrame",2),k([m()],Bt.prototype,"startFrameMultiplier",2),k([m()],Bt.prototype,"rowMode",2),k([m()],Bt.prototype,"rowIndex",2),k([m()],Bt.prototype,"spriteCount",2),k([m()],Bt.prototype,"timeMode",2);class ns{constructor(){a(this,"enabled"),a(this,"separateAxes"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier")}evaluate(t,i){return this.enabled?this.separateAxes?0:this.z.evaluate(t,i)*-1:0}}k([m()],ns.prototype,"enabled",2),k([m()],ns.prototype,"separateAxes",2),k([m(Q)],ns.prototype,"x",2),k([m()],ns.prototype,"xMultiplier",2),k([m(Q)],ns.prototype,"y",2),k([m()],ns.prototype,"yMultiplier",2),k([m(Q)],ns.prototype,"z",2),k([m()],ns.prototype,"zMultiplier",2);class Fi{constructor(){a(this,"enabled"),a(this,"range"),a(this,"separateAxes"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier")}evaluate(t,i){if(!this.enabled)return 0;if(!this.separateAxes){const n=W.lerp(this.range.x,this.range.y,i);return this.z.evaluate(n)*-1}return 0}}k([m()],Fi.prototype,"enabled",2),k([m()],Fi.prototype,"range",2),k([m()],Fi.prototype,"separateAxes",2),k([m(Q)],Fi.prototype,"x",2),k([m()],Fi.prototype,"xMultiplier",2),k([m(Q)],Fi.prototype,"y",2),k([m()],Fi.prototype,"yMultiplier",2),k([m(Q)],Fi.prototype,"z",2),k([m()],Fi.prototype,"zMultiplier",2);class ct{constructor(){a(this,"enabled"),a(this,"dampen"),a(this,"drag"),a(this,"dragMultiplier"),a(this,"limit"),a(this,"limitMultiplier"),a(this,"separateAxes"),a(this,"limitX"),a(this,"limitXMultiplier"),a(this,"limitY"),a(this,"limitYMultiplier"),a(this,"limitZ"),a(this,"limitZMultiplier"),a(this,"multiplyDragByParticleSize",!1),a(this,"multiplyDragByParticleVelocity",!1),a(this,"space"),a(this,"_temp",new x),a(this,"_temp2",new x)}apply(t,i,n,o,r,l,c){if(this.enabled){const h=this.limit.evaluate(r)*this.limitMultiplier;if(i.length()>h){this._temp.copy(i).normalize().multiplyScalar(h);const d=this.dampen*.5;i.x=W.lerp(i.x,this._temp.x,d),i.y=W.lerp(i.y,this._temp.y,d),i.z=W.lerp(i.z,this._temp.z,d),n.x=W.lerp(n.x,this._temp.x,d),n.y=W.lerp(n.y,this._temp.y,d),n.z=W.lerp(n.z,this._temp.z,d)}}}}k([m()],ct.prototype,"enabled",2),k([m()],ct.prototype,"dampen",2),k([m(Q)],ct.prototype,"drag",2),k([m()],ct.prototype,"dragMultiplier",2),k([m(Q)],ct.prototype,"limit",2),k([m()],ct.prototype,"limitMultiplier",2),k([m()],ct.prototype,"separateAxes",2),k([m(Q)],ct.prototype,"limitX",2),k([m()],ct.prototype,"limitXMultiplier",2),k([m(Q)],ct.prototype,"limitY",2),k([m()],ct.prototype,"limitYMultiplier",2),k([m(Q)],ct.prototype,"limitZ",2),k([m()],ct.prototype,"limitZMultiplier",2),k([m()],ct.prototype,"multiplyDragByParticleSize",2),k([m()],ct.prototype,"multiplyDragByParticleVelocity",2),k([m()],ct.prototype,"space",2);const s1=class{constructor(){a(this,"enabled"),a(this,"curve"),a(this,"curveMultiplier"),a(this,"mode"),a(this,"system"),a(this,"_temp",new x),a(this,"_firstUpdate",!0),a(this,"_frames",0)}clone(){var s;const t=new s1;return t.enabled=this.enabled,t.curve=(s=this.curve)==null?void 0:s.clone(),t.curveMultiplier=this.curveMultiplier,t.mode=this.mode,t}get _lastWorldPosition(){return this.system._iv_lastWorldPosition||(this.system._iv_lastWorldPosition=new x),this.system._iv_lastWorldPosition}get _velocity(){return this.system._iv_velocity||(this.system._iv_velocity=new x),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,i){if(this.enabled&&this.system&&this.system.worldspace!==!1&&this.mode===1){const n=this.curve.evaluate(t,i);this._temp.copy(this._velocity).multiplyScalar(n),s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z}}};let Yo=s1;k([m()],Yo.prototype,"enabled",2),k([m(Q)],Yo.prototype,"curve",2),k([m()],Yo.prototype,"curveMultiplier",2),k([m()],Yo.prototype,"mode",2);class ni{constructor(){a(this,"enabled"),a(this,"range"),a(this,"separateAxes"),a(this,"size"),a(this,"sizeMultiplier"),a(this,"x"),a(this,"xMultiplier"),a(this,"y"),a(this,"yMultiplier"),a(this,"z"),a(this,"zMultiplier")}evaluate(t,i,n,o){const r=t.length(),l=W.remap(r,this.range.x,this.range.y,0,1),c=this.size.evaluate(l,n);return o.x*=c,o.y*=c,o.z*=c,o}}k([m()],ni.prototype,"enabled",2),k([m(oe)],ni.prototype,"range",2),k([m()],ni.prototype,"separateAxes",2),k([m(Q)],ni.prototype,"size",2),k([m()],ni.prototype,"sizeMultiplier",2),k([m(Q)],ni.prototype,"x",2),k([m()],ni.prototype,"xMultiplier",2),k([m(Q)],ni.prototype,"y",2),k([m()],ni.prototype,"yMultiplier",2),k([m(Q)],ni.prototype,"z",2),k([m()],ni.prototype,"zMultiplier",2);class ta{constructor(){a(this,"enabled"),a(this,"range"),a(this,"color")}evaluate(t,i,n){const o=t.length(),r=W.remap(o,this.range.x,this.range.y,0,1),l=this.color.evaluate(r,i);n.x*=l.r,n.y*=l.g,n.z*=l.b,"alpha"in l&&(n.w*=l.alpha)}}k([m()],ta.prototype,"enabled",2),k([m(oe)],ta.prototype,"range",2),k([m(si)],ta.prototype,"color",2),new x(1,1,1),new x(0,0,1);class Ap{constructor(t,i,n,o){a(this,"type","NeedleParticleSubEmitter"),a(this,"emitterType"),a(this,"emitterProbability"),a(this,"q_",new V),a(this,"v_",new x),a(this,"v2_",new x),a(this,"_emitterMatrix",new Om),a(this,"_circularBuffer"),this.system=t,this.particleSystem=i,this.subSystem=n,this.subParticleSystem=o,this.subParticleSystem&&this.subParticleSystem&&(this.subParticleSystem.onlyUsedByOther=!0);const r=1e3;this._circularBuffer=new Si(()=>new Om,r)}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===$0.Birth&&this.run(t)}update(t,i){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 i=this.system.deltaTime;if(this.emitterType===$0.Death){let o=t.life;if(t[Rl]!==void 0&&(o=t[Rl]),!(t.age+i*1.2>=o))return;const r=this.subSystem.main.maxParticles-this.subSystem.currentParticles;t.emissionState.waitEmiting=r}const n=new Om;n.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||n.multiplyMatrices(this._emitterMatrix,n),this.subParticleSystem.emit(i,t.emissionState,n)}}var IE=Object.defineProperty,jE=Object.getOwnPropertyDescriptor,Ye=(s,t,i,n)=>{for(var o=n>1?void 0:n?jE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&IE(t,i,o),o};const Ko=O("debugparticles"),DE=O("noprogressive"),LE=O("debugprogressive");var $0=(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))($0||{});class os extends A{constructor(){super(...arguments),a(this,"renderMode"),a(this,"particleMaterial"),a(this,"trailMaterial"),a(this,"particleMesh"),a(this,"maxParticleSize"),a(this,"minParticleSize"),a(this,"velocityScale"),a(this,"cameraVelocityScale"),a(this,"lengthScale")}start(){if(this.maxParticleSize!==.5&&this.minParticleSize!==0&&F()){const t=`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(t)}}get transparent(){var t;return((t=this.particleMaterial)==null?void 0:t.transparent)??!1}getMaterial(t=!1){let i=t===!0&&this.trailMaterial?this.trailMaterial:this.particleMaterial;if(i){if(i.type==="MeshStandardMaterial"){Ko&&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=mr,i.map.premultiplyAlpha=!1);const n=new Re;n.copy(i),t?this.trailMaterial=n:this.particleMaterial=n}i.map&&(i.map.colorSpace=mr,i.map.premultiplyAlpha=!1),t&&i.side===lo&&(i=i.clone(),i.side=ym,t?this.trailMaterial=i:this.particleMaterial=i)}return i&&!DE&&i._didRequestTextureLOD===void 0&&(i._didRequestTextureLOD=0,LE&&console.log("Load material LOD",i.name),it.assignTextureLOD(i,0)),i}getMesh(t){let i=null;if(!i&&(this.particleMesh instanceof K&&(i=this.particleMesh.geometry),i===null)){i=new Fs(1,1);const n=i.attributes.uv;for(let o=0;o<n.count;o++)n.setX(o,1-n.getX(o))}return new K(i,this.getMaterial())}}Ye([m()],os.prototype,"renderMode",2),Ye([m(ke)],os.prototype,"particleMaterial",2),Ye([m(ke)],os.prototype,"trailMaterial",2),Ye([m()],os.prototype,"maxParticleSize",2),Ye([m()],os.prototype,"minParticleSize",2),Ye([m()],os.prototype,"velocityScale",2),Ye([m()],os.prototype,"cameraVelocityScale",2),Ye([m()],os.prototype,"lengthScale",2);class Ip{constructor(t,i=1){a(this,"_curve"),a(this,"_factor"),a(this,"type","function"),this._curve=t,this._factor=i}startGen(t){}genValue(t,i){return this._curve.evaluate(i,Math.random())*this._factor}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}}class q0{constructor(t){a(this,"type","value"),a(this,"system"),this.system=t}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}startGen(t){}}class BE extends q0{genValue(){return this.system.textureSheetAnimation.getStartIndex()}}class FE extends q0{constructor(){super(...arguments),a(this,"_lastPosition",new x),a(this,"_lastDistance",0)}update(){const t=te(this.system.gameObject);this._lastDistance=this._lastPosition.distanceTo(t),this._lastPosition.copy(t)}genValue(){if(!this.system.isPlaying||!this.system.emission.enabled||this.system.currentParticles>=this.system.maxParticles)return 0;let t=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 r=this._lastDistance/this.system.deltaTime*o;Number.isFinite(r)||(r=0),t+=r}const i=this.system.emission.getBurst();i>0&&(t+=i/this.system.deltaTime);const n=this.system.maxParticles-this.system.currentParticles;return W.clamp(t,0,n/this.system.deltaTime)}}class zE extends q0{genValue(){return this.system.isPlaying,0}}class Zo{constructor(t){a(this,"system"),a(this,"type"),this.type=Object.getPrototypeOf(this).constructor.name||"ParticleSystemBaseBehaviour",t&&(this.system=t)}get context(){return this.system.context}initialize(t){}update(t,i){}frameUpdate(t){}toJSON(){throw new Error("Method not implemented.")}clone(){throw new Error("Method not implemented.")}reset(){}}class UE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleTextureSheet")}update(t,i){const n=this.system.textureSheetAnimation;if(n.enabled){const o=t.age/t.life,r=n.evaluate(o);r!==void 0&&(t.uvTile=r)}}}const n1=Symbol("particleRotation");class NE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleRotation")}initialize(t){t[n1]=Math.random()}update(t,i){if(t.rotation===void 0)return;const n=t.age/t.life;if(typeof t.rotation=="number"&&(this.system.rotationOverLifetime.enabled?t.rotation+=this.system.rotationOverLifetime.evaluate(n,t[n1])*i:this.system.renderer.renderMode===qn.Billboard&&(t.rotation=Math.PI),this.system.rotationBySpeed.enabled)){const o=t.velocity.length();t.rotation+=this.system.rotationBySpeed.evaluate(n,o)*i}}}const o1=Symbol("sizeLerpFactor"),WE=new x;class VE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleSize"),a(this,"_minSize",0),a(this,"_maxSize",1)}initialize(t){t[o1]=Math.random(),this._minSize=this.system.renderer.minParticleSize,this._maxSize=this.system.renderer.maxParticleSize}update(t,i){const n=t.age/t.life;let o=1;this.system.sizeOverLifetime.enabled&&(o*=this.system.sizeOverLifetime.evaluate(n,void 0,t[o1]).x);let r=1;this.system.renderer.renderMode!==qn.Mesh&&(r=this.system.worldScale.x/this.system.cameraScale);const l=G(t.startSize).multiplyScalar(o*r);if(t.size.set(l.x,l.y,l.z),this.system.localspace){const c=h1(this.system,WE);t.size.x*=c.x,t.size.y*=c.y,t.size.z*=c.z}}}const Rl=Symbol("particleLife"),G0=Symbol("trailLifetime"),r1=Symbol("trailStartLength"),X0=Symbol("trailWidthRandom");class HE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleTrail")}initialize(t){t instanceof gv&&(t[Rl]=t.life,this.system.trails.enabled&&this.system.trails.dieWithParticles===!1&&(t[G0]=this.system.trails.lifetime.evaluate(Math.random(),Math.random()),t.life+=t[G0]),t[r1]=t.length,t[X0]=Math.random())}update(t){var i;if((i=this.system.trails)!=null&&i.enabled&&t instanceof gv){const n=t,o=t.age/t[Rl],r=t.previous.values(),l=t.previous.length;for(let c=0;c<l;c++){const h=r.next().value,d=1-c/(l-1),u=t.size;if(u.x<=0&&!this.system.trails.sizeAffectsWidth){const p=20*this.system.trails.widthOverTrail.evaluate(.5,n[X0]);u.x=p,u.y=p,u.z=p}h.size=this.system.trails.getWidth(u.x,o,d,n[X0]),h.color.copy(t.color),this.system.trails.getColor(h.color,o,d)}if(t.age>t[Rl]){t.velocity.set(0,0,0);const c=(t.age-t[Rl])/t[G0];n.length=W.lerp(t[r1],0,c)}}}}const jp=Symbol("startVelocity"),a1=Symbol("gravityModifier"),Q0=Symbol("gravitySpeed"),Dp=Symbol("velocity lerp factor"),Y0=new x;class $E extends Zo{constructor(){super(...arguments),a(this,"type","NeedleVelocity"),a(this,"_gravityDirection",new x)}initialize(t){var i,n;const o=this.system.main.simulationSpeed;t.startSpeed=this.system.main.startSpeed.evaluate(Math.random(),Math.random());const r=this.system.shape.getDirection(t,t.position);t.velocity.x=r.x*t.startSpeed,t.velocity.y=r.y*t.startSpeed,t.velocity.z=r.z*t.startSpeed,(i=this.system.inheritVelocity)!=null&&i.enabled&&this.system.inheritVelocity.applyInitial(t.velocity),t[jp]?t[jp].copy(t.velocity):t[jp]=t.velocity.clone();const l=this.system.main.gravityModifier.evaluate(Math.random(),Math.random());t[a1]=l*o,t[Q0]=l*o*.5,t[Dp]=Math.random(),(n=this.system.velocityOverLifetime)==null||n.init(t),this._gravityDirection.set(0,-1,0),this.system.main.simulationSpace===kh.Local&&this._gravityDirection.applyQuaternion(this.system.worldQuaternionInverted).normalize()}update(t,i){var n;const o=t[jp],r=t[a1];if(r!==0){const g=r*t[Q0];Y0.copy(this._gravityDirection).multiplyScalar(g),t[Q0]+=i*.05,o.add(Y0)}t.velocity.copy(o);const l=t.age/t.life;(n=this.system.inheritVelocity)!=null&&n.enabled&&this.system.inheritVelocity.applyCurrent(t.velocity,l,t[Dp]);const c=this.system.noise;c.enabled&&c.apply(0,t.position,t.velocity,i,t.age,t.life);const h=this.system.sizeBySpeed;h!=null&&h.enabled&&(t.size=h.evaluate(t.velocity,l,t[Dp],t.size));const d=this.system.colorBySpeed;d!=null&&d.enabled&&d.evaluate(t.velocity,t[Dp],t.color);const u=this.system.velocityOverLifetime;u.enabled&&u.apply(t,0,t.position,t.velocity,i,t.age,t.life);const p=this.system.limitVelocityOverLifetime;if(p.enabled&&p.apply(t.position,o,t.velocity,t.size,l,i,1),this.system.worldspace){const g=this.system.worldScale;t.velocity.x*=g.x,t.velocity.y*=g.y,t.velocity.z*=g.z}}}const l1=Symbol("colorLerpFactor"),c1=new Se(1,1,1,1),ia=new Se(1,1,1,1);class qE extends Zo{constructor(){super(...arguments),a(this,"type","NeedleColor")}initialize(t){}_init(t){const i=this.system.renderer.particleMaterial;ia.copy(this.system.main.startColor.evaluate(Math.random())),i!=null&&i.color&&(c1.copy(i.color),ia.multiply(c1)),ia.convertLinearToSRGB(),t.startColor.set(ia.r,ia.g,ia.b,ia.alpha),t.color.copy(t.startColor),t[l1]=Math.random()}update(t,i){if(t.age===0&&this._init(t),this.system.colorOverLifetime.enabled){const n=t.age/t.life,o=this.system.colorOverLifetime.color.evaluate(n,t[l1]);t.color.set(o.r,o.g,o.b,"alpha"in o?o.alpha:1).multiply(t.startColor)}else t.color.copy(t.startColor)}}class GE{constructor(t){a(this,"system"),a(this,"emission"),a(this,"autoDestroy"),a(this,"startLength"),a(this,"emissionBursts"),a(this,"onlyUsedByOther"),a(this,"behaviors",[]),a(this,"rendererEmitterSettings",{startLength:new nO(220),followLocalOrigin:!1}),a(this,"flatWhiteTexture"),a(this,"clonedTexture",{original:void 0,clone:void 0}),this.system=t,this.emission=new FE(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 Ip(this.system.main.startLifetime)}get startSpeed(){return new Ip(this.system.main.startSpeed)}get startRotation(){return new Ip(this.system.main.startRotation)}get startSize(){return new Ip(this.system.main.startSize)}get startColor(){return new iO(new sO(1,1,1,1))}get emissionOverTime(){return this.emission}get emissionOverDistance(){return new zE(this.system)}get instancingGeometry(){return this.system.renderer.getMesh(this.system.renderer.renderMode).geometry}get renderMode(){if(this.system.trails.enabled===!0)return xn.Trail;switch(this.system.renderer.renderMode){case qn.Billboard:return xn.BillBoard;case qn.Stretch:return xn.StretchedBillBoard;case qn.HorizontalBillboard:return xn.HorizontalBillBoard;case qn.VerticalBillboard:return xn.VerticalBillBoard;case qn.Mesh:return xn.Mesh}return xn.BillBoard}get speedFactor(){var t;let i=this.system.main.simulationSpeed;return((t=this.system.renderer)==null?void 0:t.renderMode)===qn.Stretch&&(i*=this.system.renderer.velocityScale??1),i}get texture(){const t=this.material;if(t&&t.map){const i=t.map;if(this.clonedTexture.original!==i||!this.clonedTexture.clone){const n=i.clone();n.premultiplyAlpha=!1,n.colorSpace=mr,this.clonedTexture.original=i,this.clonedTexture.clone=n}return this.clonedTexture.clone}return this.flatWhiteTexture||(this.flatWhiteTexture=Kg(new Se(1,1,1,1),1)),this.flatWhiteTexture}get startTileIndex(){return new BE(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)??gC}get transparent(){return this.system.renderer.transparent}get worldSpace(){return this.system.main.simulationSpace===kh.World}}class XE{constructor(){a(this,"burstParticleIndex",0),a(this,"burstParticleCount",0),a(this,"isBursting",!1),a(this,"travelDistance",0),a(this,"previousWorldPos"),a(this,"burstIndex",0),a(this,"burstWaveIndex",0),a(this,"time",0),a(this,"waitEmiting",0)}}const Lp=class extends A{constructor(){super(...arguments),a(this,"_state"),a(this,"colorOverLifetime"),a(this,"main"),a(this,"emission"),a(this,"sizeOverLifetime"),a(this,"shape"),a(this,"noise"),a(this,"trails"),a(this,"velocityOverLifetime"),a(this,"limitVelocityOverLifetime"),a(this,"inheritVelocity"),a(this,"colorBySpeed"),a(this,"textureSheetAnimation"),a(this,"rotationOverLifetime"),a(this,"rotationBySpeed"),a(this,"sizeBySpeed"),a(this,"_cameraScale",1),a(this,"__worldQuaternion",new V),a(this,"_worldQuaternionInverted",new V),a(this,"_worldScale",new x),a(this,"_worldPositionFrame",-1),a(this,"_worldPos",new x),a(this,"_renderer"),a(this,"_batchSystem"),a(this,"_particleSystem"),a(this,"_interface"),a(this,"_container"),a(this,"_time",0),a(this,"_isPlaying",!0),a(this,"_isUsedAsSubsystem",!1),a(this,"_didPreWarm",!1),a(this,"_bursts"),a(this,"_subEmitterSystems"),a(this,"_lastBatchesCount",-1)}play(s=!1){var t;s&&P.foreachComponent(this.gameObject,i=>{i instanceof Lp&&i!==this&&i.play(!1)},!0),this._isPlaying=!0,this._particleSystem&&(this._particleSystem.emissionState.time=0,this._particleSystem.emitEnded=!1),(t=this.emission)==null||t.reset()}pause(s=!0){s&&P.foreachComponent(this.gameObject,t=>{t instanceof Lp&&t!==this&&t.pause(!1)},!0),this._isPlaying=!1}stop(s=!0,t=!1){s&&P.foreachComponent(this.gameObject,i=>{i instanceof Lp&&i!==this&&i.stop(!1,t)},!0),this._isPlaying=!1,this._time=0,t&&this.reset()}reset(){var s;this._time=0,this._particleSystem&&(this._particleSystem.particleNum=0,this._particleSystem.emissionState.time=0,this._particleSystem.emitEnded=!1,(s=this.emission)==null||s.reset())}emit(s){if(this._particleSystem){this.onUpdate(),s=Math.min(s,this.maxParticles-this.currentParticles),this._state||(this._state=new XE),this._state.waitEmiting=s,this._state.time=0;const t=this._particleSystem.emitEnded;this._particleSystem.emitEnded=!1,this._particleSystem.emit(this.deltaTime,this._state,this._particleSystem.emitter.matrixWorld),this._particleSystem.emitEnded=t}}get playOnAwake(){return this.main.playOnAwake}set playOnAwake(s){this.main.playOnAwake=s}get renderer(){return this._renderer}get isPlaying(){return this._isPlaying}get currentParticles(){var s;return((s=this._particleSystem)==null?void 0:s.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===kh.World}get localspace(){return this.main.simulationSpace===kh.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,te(this.gameObject,this._worldPos)),this._worldPos}get matrixWorld(){return this._container.matrixWorld}get isSubsystem(){return this._isUsedAsSubsystem}addBehaviour(s){return this._particleSystem?(s instanceof Zo&&(s.system=this),(F()||Ko)&&console.debug("Add custom ParticleSystem Behaviour",s),this._particleSystem.addBehavior(s),!0):!1}removeBehaviour(s){if(!this._particleSystem)return!1;const t=this._particleSystem.behaviors,i=t.indexOf(s);return i!==-1&&((F()||Ko)&&console.debug("Remove custom ParticleSystem Behaviour",i,s),t.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(s){for(let t=0;t<s.length;t++){const i=s[t];if(!(i instanceof Rh)){const n=new Rh;La(n,i),s[t]=n}}this._bursts=s}set subEmitterSystems(s){for(let t=0;t<s.length;t++){const i=s[t];if(!(i instanceof Ah)){const n=new Ah;La(n,i),s[t]=n}}Ko&&s.length>0&&console.log("SubEmitters: ",s,this),this._subEmitterSystems=s}onAfterDeserialize(s){if(this._subEmitterSystems&&Array.isArray(this._subEmitterSystems))for(const t of this._subEmitterSystems)t._deserialize(this.context,this.gameObject)}awake(){if(this._worldPositionFrame=-1,this._renderer=this.gameObject.getComponent(os),!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 I,this._container.matrixAutoUpdate=!1,this.context.scene.add(this._container),this._batchSystem=new eO,this._batchSystem.name=this.gameObject.name,this._container.add(this._batchSystem),this._interface=new GE(this),this._particleSystem=new tO(this._interface),this._particleSystem.addBehavior(new VE(this)),this._particleSystem.addBehavior(new qE(this)),this._particleSystem.addBehavior(new UE(this)),this._particleSystem.addBehavior(new NE(this)),this._particleSystem.addBehavior(new $E(this)),this._particleSystem.addBehavior(new HE(this)),this._batchSystem.addSystem(this._particleSystem);const s=this._particleSystem.emitter;this.context.scene.add(s),this.inheritVelocity.system&&this.inheritVelocity.system!==this&&(this.inheritVelocity=this.inheritVelocity.clone()),this.inheritVelocity.awake(this),Ko&&(console.log(this),this.gameObject.add(new wi(1)))}start(){this.addSubParticleSystems(),this.updateLayers(),this.renderer.particleMesh instanceof K&&this._interface.renderMode==xn.Mesh&&it.assignMeshLOD(this.renderer.particleMesh,0).then(s=>{s&&this.particleSystem&&this._interface.renderMode==xn.Mesh&&(this.particleSystem.instancingGeometry=s)})}onDestroy(){var s,t,i,n;(s=this._container)==null||s.removeFromParent(),(t=this._batchSystem)==null||t.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 s;this.main&&(this._didPreWarm===!1&&((s=this.main)==null?void 0:s.prewarm)===!0&&(this._didPreWarm=!0,this.preWarm()),this.onUpdate(),this.onSimulate(this.deltaTime))}preWarm(){var s;if(!((s=this.emission)!=null&&s.enabled)||this.emission.rateOverTime.getMax()<=0)return;const t=1/60,i=this.main.duration,n=this.main.startLifetime.getMax(),o=1e3,r=Math.min(Math.max(i,n)/Math.max(.01,this.main.simulationSpeed),o),l=Math.ceil(r/t),c=Date.now();Ko&&console.log(`Particles ${this.name} - Prewarm for ${l} frames (${r} sec). Duration: ${i}, Lifetime: ${n}`);for(let h=0;h<l&&!(this.currentParticles>=this.maxParticles);h++){const d=Date.now()-c;if(d>2e3){console.warn(`Particles ${this.name} - Prewarm took too long. Aborting: ${d}`);break}this.onUpdate(),this.onSimulate(t)}}onSimulate(s){if(this._batchSystem){let t=this.context.time.frameCount%60===0;this._lastBatchesCount!==this._batchSystem.batches.length&&(this._lastBatchesCount=this._batchSystem.batches.length,t=!0),t&&this.updateLayers(),this._batchSystem.update(s)}this._time+=s,this._time>this.duration&&(this._time=0)}updateLayers(){if(this._batchSystem)for(let s=0;s<this._batchSystem.batches.length;s++){const t=this._batchSystem.batches[s];t.layers.disableAll();const i=this.layer;t.layers.mask=1<<i}}onUpdate(){var s,t;if(this._bursts&&(this.emission.bursts=this._bursts,delete this._bursts),!this._isPlaying)return;const i=this.context.mainCamera;if(i){const r=Je(i);this._cameraScale=r.x}const n=!this.worldspace,o=this.gameObject;if(Oe(o,this.__worldQuaternion),this._worldQuaternionInverted.copy(this.__worldQuaternion).invert(),Je(this.gameObject,this._worldScale),n&&this._container&&(s=this.gameObject)!=null&&s.parent){const r=h1(this,Y0);this._container.matrix.makeScale(r.x,r.y,r.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),(t=this.inheritVelocity)==null||t.update(this.context),this.velocityOverLifetime.update(this)}addSubParticleSystems(){var s;if(this._subEmitterSystems&&this._particleSystem)for(const t of this._subEmitterSystems){t.particleSystem&&(t.particleSystem.__internalAwake?t.particleSystem.__internalAwake():F()&&console.warn("SubParticleSystem serialization issue(?)",t.particleSystem,t));const i=(s=t.particleSystem)==null?void 0:s._particleSystem;if(i){t.particleSystem._isUsedAsSubsystem=!0;const n=new Ap(this,this._particleSystem,t.particleSystem,i);n.emitterType=t.type,n.emitterProbability=t.emitProbability,this._particleSystem.addBehavior(n)}else Ko&&console.warn("Could not add SubParticleSystem",t,this)}}};let ht=Lp;Ye([m(Th)],ht.prototype,"colorOverLifetime",2),Ye([m(Lt)],ht.prototype,"main",2),Ye([m(hn)],ht.prototype,"emission",2),Ye([m(Qo)],ht.prototype,"sizeOverLifetime",2),Ye([m(Xe)],ht.prototype,"shape",2),Ye([m(Ce)],ht.prototype,"noise",2),Ye([m(Ue)],ht.prototype,"trails",2),Ye([m(Qe)],ht.prototype,"velocityOverLifetime",2),Ye([m(ct)],ht.prototype,"limitVelocityOverLifetime",2),Ye([m(Yo)],ht.prototype,"inheritVelocity",2),Ye([m(ta)],ht.prototype,"colorBySpeed",2),Ye([m(Bt)],ht.prototype,"textureSheetAnimation",2),Ye([m(ns)],ht.prototype,"rotationOverLifetime",2),Ye([m(Fi)],ht.prototype,"rotationBySpeed",2),Ye([m(ni)],ht.prototype,"sizeBySpeed",2);class Ah{constructor(){a(this,"particleSystem"),a(this,"emitProbability",1),a(this,"properties"),a(this,"type")}_deserialize(t,i){const n=this.particleSystem;if(n instanceof ht)return;let o="";n&&typeof n.guid=="string"&&(o=n.guid,this.particleSystem=P.findByGuid(o,i)),Ko&&!(this.particleSystem instanceof ht)&&console.warn("Could not find particle system for sub emitter",o,i,this)}}function h1(s,t){if(t.set(1,1,1),s.gameObject.parent&&s.localspace)switch(s.main.scalingMode){case H0.Local:t=Je(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 i="ParticleSystem scale mode "+H0[s.main.scalingMode]+" is not supported";F()&&xe(i),console.warn(i,s.name,s)}t=Je(s.gameObject,t);break}return t}class Hl extends A{constructor(){super(...arguments),a(this,"_didAssignPlayerColor",!1),a(this,"tryAssignColor",()=>{const t=P.getComponentInParent(this.gameObject,Di);if(t&&t.owner)return this._didAssignPlayerColor=!0,this.assignUserColor(t.owner),!0;const i=P.getComponentInParent(this.gameObject,Tt);return i!=null&&i.connectionId?(this._didAssignPlayerColor=!0,this.assignUserColor(i.connectionId),!0):!1})}onEnable(){this.context.connection.beginListen(ie.JoinedRoom,this.tryAssignColor),this._didAssignPlayerColor||this.startCoroutine(this.waitForConnection())}onDisable(){this.context.connection.stopListen(ie.JoinedRoom,this.tryAssignColor)}*waitForConnection(){for(;!this.destroyed&&this.activeAndEnabled&&(yield V_(.2),!this.tryAssignColor()););}assignUserColor(t){const i=Hl.hashCode(t),n=Hl.colorFromHashCode(i);if(this.gameObject.type==="Mesh"){const o=this.gameObject;this.assignColor(n,t,o)}else if(this.gameObject.children)for(const o of this.gameObject.children){const r=o;r.material&&r.material.color&&this.assignColor(n,t,r)}}assignColor(t,i,n){let o=n.material;o&&(o._playerMaterial!==i&&(o=o.clone(),o._playerMaterial=i,n.material=o),o.color=t)}static hashCode(t){var i=0,n,o;if(t.length===0)return i;for(n=0;n<t.length;n++)o=t.charCodeAt(n),i=(i<<5)-i+o,i|=0;return i}static colorFromHashCode(t){const i=(t&16711680)>>16,n=(t&65280)>>8,o=t&255;return new re(i/255,n/255,o/255)}}const QE=O("debugpost");let K0=null;function YE(s){K0=s}function d1(s){let t=s.gameObject;for(;t;){for(const i of ou(t))if(i.isPostProcessingManager===!0)return i;t=t.parent}return null}function KE(s){let t=d1(s);if(!t)if(K0){QE&&console.warn("Adding postprocessing manager to the scene.");const i=s.scene;t=Mi(i,K0)}else F()&&console.warn("No post processing manager found");return t}var ZE=Object.defineProperty,JE=Object.getOwnPropertyDescriptor,u1=(s,t,i,n)=>{for(var o=n>1?void 0:n?JE(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&ZE(t,i,o),o};const eA=O("debugpost");class N{constructor(t){a(this,"isVolumeParameter",!0),a(this,"_isInitialized",!1),a(this,"_active",!0),a(this,"_value"),a(this,"_valueRaw"),a(this,"_defaultValue"),a(this,"valueProcessor"),a(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 i=t?this._valueRaw:this._defaultValue;this.processValue(i,!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,i){if(t==null||!i&&this.testIfValueChanged(t)===!1)return;const n=this._value;eA&&typeof n=="number"&&typeof t=="number"&&(n?.toFixed(4),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,n,this)}testIfValueChanged(t){return this._valueRaw!==t}}u1([m()],N.prototype,"overrideState",1),u1([m()],N.prototype,"value",1);class tA extends Zi{constructor(){super([N])}onSerialize(t,i){}onDeserialize(t,i){const n=i.target,o=i.path;let r;if(n&&o&&(r=n[o]),(typeof r!="object"||typeof r=="object"&&r.isVolumeParameter!==!0)&&(r=new N),typeof t=="object"&&"value"in t){const l=t.value;r.initialize(l),r.overrideState=t.overrideState}else r.value=t;return r}}new tA;var iA=Object.defineProperty,sA=Object.getOwnPropertyDescriptor,nA=(s,t,i,n)=>{for(var o=n>1?void 0:n?sA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&iA(t,i,o),o};const oA=O("debugpost");class dt extends A{constructor(t=void 0){if(super(),a(this,"active",!0),a(this,"_manager",null),a(this,"_result"),a(this,"_postprocessingContext",null),t)for(const i of Object.keys(t)){const n=t[i],o=this[i];o instanceof N?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 t;super.onDisable(),(t=this._manager)==null||t.removeEffect(this),this.active=!1}onEffectEnabled(t){var i;t&&t.isPostProcessingManager===!0?this._manager=t:this._manager||(this._manager=KE(this)),(i=this._manager)==null||i.addEffect(this)}init(){}get postprocessingContext(){return this._postprocessingContext}apply(t){var i;return this._postprocessingContext=t,this._result||(this.initParameters(),this._result=(i=this.onCreateEffect)==null?void 0:i.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){oA&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(t=>t.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const t=Object.keys(this);for(const i of t){const n=this[i];n instanceof N&&n.__init()}}onEditorModification(t){const i=t.propertyName;if(this[i]instanceof N){const n=t.value;return this[i].value=n,!0}}}nA([m()],dt.prototype,"active",2);var rA=Object.defineProperty,aA=Object.getOwnPropertyDescriptor,lA=(s,t,i,n)=>{for(var o=n>1?void 0:n?aA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&rA(t,i,o),o};const cA=O("debugpost"),Z0={};function rs(s,t){Z0[s]=t}function hA(s){return s.__type in Z0?Z0[s.__type]:(cA&&s.__type&&console.warn("Unknown postprocessing type",s.__type,s),dt)}class Ih{constructor(){a(this,"components",[])}init(){var t;(t=this.components)==null||t.forEach(i=>i.init())}addEffect(t){this.components.push(t)}removeEffect(t){const i=this.components.indexOf(t);i>=0&&this.components.splice(i,1)}}lA([$a([s=>hA(s),dt])],Ih.prototype,"components",2);var dA=Object.defineProperty,uA=Object.getOwnPropertyDescriptor,pA=(s,t,i,n)=>{for(var o=n>1?void 0:n?uA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&dA(t,i,o),o};class jh extends dt{constructor(){super(...arguments),a(this,"preset",new N(2))}get typeName(){return"Antialiasing"}onCreateEffect(){const t=new D.POSTPROCESSING.MODULE.SMAAEffect({preset:D.POSTPROCESSING.MODULE.SMAAPreset.HIGH,edgeDetectionMode:D.POSTPROCESSING.MODULE.EdgeDetectionMode.DEPTH});return this.preset.onValueChanged=i=>{t.applyPreset(i)},t}}pA([m(N)],jh.prototype,"preset",2),rs("Antialiasing",jh);var mA=Object.defineProperty,gA=Object.getOwnPropertyDescriptor,J0=(s,t,i,n)=>{for(var o=n>1?void 0:n?gA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&mA(t,i,o),o},ey;const p1=(ey=class extends dt{constructor(){super(...arguments),a(this,"threshold",new N(.9)),a(this,"intensity",new N(1)),a(this,"scatter",new N(.3)),a(this,"selectiveBloom")}get typeName(){return"Bloom"}init(){this.threshold.valueProcessor=s=>s,this.intensity.valueProcessor=s=>s,this.scatter.valueProcessor=s=>s}onCreateEffect(){let s;if(this.selectiveBloom==null&&(this.selectiveBloom=p1.useSelectiveBloom),this.selectiveBloom){const t=s=new D.POSTPROCESSING.MODULE.SelectiveBloomEffect(this.context.scene,this.context.mainCamera,{blendFunction:D.POSTPROCESSING.MODULE.BlendFunction.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,radius:.85,intensity:this.intensity.value});t.inverted=!0}else s=new D.POSTPROCESSING.MODULE.BloomEffect({blendFunction:D.POSTPROCESSING.MODULE.BlendFunction.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,radius:.85,intensity:this.intensity.value});return this.intensity.onValueChanged=t=>{s.intensity=t},this.threshold.onValueChanged=t=>{s.luminanceMaterial.threshold=Math.pow(t,2.2)},this.scatter.onValueChanged=t=>{s.luminancePass.enabled=!0,s.luminanceMaterial.smoothing=t,s.mipmapBlurPass&&(s.mipmapBlurPass.radius=vn.lerp(.1,.9,t))},s}},a(ey,"useSelectiveBloom",!1),ey);let sa=p1;J0([m(N)],sa.prototype,"threshold",2),J0([m(N)],sa.prototype,"intensity",2),J0([m(N)],sa.prototype,"scatter",2),rs("Bloom",sa);var fA=Object.defineProperty,yA=Object.getOwnPropertyDescriptor,vA=(s,t,i,n)=>{for(var o=n>1?void 0:n?yA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&fA(t,i,o),o};class Dh extends dt{constructor(){super(...arguments),a(this,"intensity",new N(0))}get typeName(){return"ChromaticAberration"}onCreateEffect(){const t=new D.POSTPROCESSING.MODULE.ChromaticAberrationEffect;return t.offset=new oe(0,0),t.radialModulation=!0,t.modulationOffset=.15,this.intensity.valueProcessor=i=>i*.02,this.intensity.onValueChanged=i=>{t.offset.x=-i,t.offset.y=i},t}}vA([m(N)],Dh.prototype,"intensity",2),rs("ChromaticAberration",Dh);var bA=Object.defineProperty,_A=Object.getOwnPropertyDescriptor,m1=(s,t,i,n)=>{for(var o=n>1?void 0:n?_A(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&bA(t,i,o),o};const g1=O("debugpost");var Bp=(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))(Bp||{});function ty(s){switch(s){case 0:return fd;case 1:return _m;case 2:return bm;case 3:return gd;case 4:return Yl;default:return Yl}}function wA(s){switch(s){case fd:return 0;case bm:return 2;case gd:return 3;case Yl:return 1;case _m:return 1;default:return 0}}function f1(s){switch(s){case fd:return D.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR;case bm:return D.POSTPROCESSING.MODULE.ToneMappingMode.ACES_FILMIC;case gd:return D.POSTPROCESSING.MODULE.ToneMappingMode.AGX;case Yl:return D.POSTPROCESSING.MODULE.ToneMappingMode.NEUTRAL;case _m:return D.POSTPROCESSING.MODULE.ToneMappingMode.REINHARD;default:return D.POSTPROCESSING.MODULE.ToneMappingMode.LINEAR}}const y1=class extends dt{constructor(){super(...arguments),a(this,"mode",new N(void 0)),a(this,"exposure",new N(1))}get typeName(){return"ToneMapping"}setMode(s){const t=Bp[s];return t===void 0?(console.error("Invalid ToneMapping mode",s),this):(this.mode.value=t,this)}get isToneMapping(){return!0}onEffectEnabled(){const s=d1(this);s&&super.onEffectEnabled(s)}onCreateEffect(){if(this.postprocessingContext)for(const i of this.postprocessingContext.components){if(i===this)break;if(i!=this&&i instanceof y1){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=wA(this.context.renderer.toneMapping);this.mode.initialize(i)}const s=ty(this.mode.value),t=new D.POSTPROCESSING.MODULE.ToneMappingEffect({mode:f1(s)});return this.mode.onValueChanged=i=>{const n=ty(i);t.mode=f1(n),g1&&console.log("ToneMapping mode changed to",Bp[i],n,t.mode)},g1&&console.log("Use ToneMapping",Bp[this.mode.value],s,t.mode,"renderer.tonemapping: "+this.context.renderer.toneMapping),this.exposure.onValueChanged=i=>{this.context.renderer.toneMappingExposure=i},t}onBeforeRender(){this.mode.overrideState&&(this.context.renderer.toneMapping=ty(this.mode.value)),this.exposure.overrideState&&(this.context.renderer.toneMappingExposure=this.exposure.value)}};let Jo=y1;m1([m(N)],Jo.prototype,"mode",2),m1([m(N)],Jo.prototype,"exposure",2),rs("Tonemapping",Jo);var xA=Object.defineProperty,SA=Object.getOwnPropertyDescriptor,Fp=(s,t,i,n)=>{for(var o=n>1?void 0:n?SA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&xA(t,i,o),o};class er extends dt{constructor(){super(...arguments),a(this,"postExposure",new N(0)),a(this,"contrast",new N(0)),a(this,"hueShift",new N(0)),a(this,"saturation",new N(0))}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=t=>(t=Math.pow(2,t),t),this.contrast.valueProcessor=t=>{let i=1;return t>0?i=200:t<0&&(i=100),t/i},this.contrast.defaultValue=0,this.hueShift.valueProcessor=t=>Math.PI*t/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=t=>t<0?t/100:t/(100*Math.PI),this.saturation.defaultValue=0}onCreateEffect(){var t,i;const n=[];this.context.renderer.toneMapping!==wa&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=wa);let o=(t=this.postprocessingContext)==null?void 0:t.components.find(c=>c instanceof Jo);o||(o=new Jo,(i=this.postprocessingContext)==null||i.components.push(o)),this.postExposure.onValueChanged=c=>{this.postExposure.overrideState&&(o.exposure.value=c)};const r=new D.POSTPROCESSING.MODULE.BrightnessContrastEffect;this.contrast.onValueChanged=c=>r.contrast=c;const l=new D.POSTPROCESSING.MODULE.HueSaturationEffect;return n.push(r),n.push(l),this.hueShift.onValueChanged=c=>l.hue=c,this.saturation.onValueChanged=c=>l.saturation=c,n}}Fp([m(N)],er.prototype,"postExposure",2),Fp([m(N)],er.prototype,"contrast",2),Fp([m(N)],er.prototype,"hueShift",2),Fp([m(N)],er.prototype,"saturation",2),rs("ColorAdjustments",er);var CA=Object.defineProperty,OA=Object.getOwnPropertyDescriptor,na=(s,t,i,n)=>{for(var o=n>1?void 0:n?OA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&CA(t,i,o),o};const PA=O("debugpost");class As extends dt{constructor(){super(...arguments),a(this,"mode"),a(this,"focusDistance",new N(1)),a(this,"focalLength",new N(.2)),a(this,"aperture",new N(20)),a(this,"gaussianMaxRadius",new N),a(this,"resolutionScale",new N(1*1/window.devicePixelRatio)),a(this,"bokehScale",new N)}get typeName(){return"DepthOfField"}init(){this.focalLength.valueProcessor=i=>{const n=i/300,o=2;return W.lerp(o,.01,n)};const t=20;this.aperture.valueProcessor=i=>{const n=1-i/32;return W.lerp(1,t,n)}}onCreateEffect(){if(this.mode===0){PA&&console.warn("DepthOfField: Mode is set to Off");return}const t=new D.POSTPROCESSING.MODULE.DepthOfFieldEffect(this.context.mainCamera,{worldFocusRange:.2,focalLength:1,bokehScale:20,resolutionScale:this.resolutionScale.value});return this.focusDistance.onValueChanged=i=>{t.cocMaterial.worldFocusDistance=i},this.focalLength.onValueChanged=i=>t.cocMaterial.worldFocusRange=i,this.aperture.onValueChanged=i=>t.bokehScale=i,this.resolutionScale&&(this.resolutionScale.onValueChanged=i=>t.resolution.scale=i),[t]}unapply(){}}na([m()],As.prototype,"mode",2),na([m(N)],As.prototype,"focusDistance",2),na([m(N)],As.prototype,"focalLength",2),na([m(N)],As.prototype,"aperture",2),na([m(N)],As.prototype,"gaussianMaxRadius",2),na([m(N)],As.prototype,"resolutionScale",2),na([m(N)],As.prototype,"bokehScale",2),rs("DepthOfField",As);class Lh extends dt{constructor(t){super(),a(this,"effect"),this.effect=t}get typeName(){return this.effect.constructor.name}onCreateEffect(){return this.effect}}var kA=Object.defineProperty,MA=Object.getOwnPropertyDescriptor,RA=(s,t,i,n)=>{for(var o=n>1?void 0:n?MA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&kA(t,i,o),o};class Bh extends dt{constructor(){super(...arguments),a(this,"granularity",new N(10))}get typeName(){return"PixelationEffect"}onCreateEffect(){const t=new D.POSTPROCESSING.MODULE.PixelationEffect;return this.granularity.onValueChanged=i=>{t.granularity=i},t}}RA([m(N)],Bh.prototype,"granularity",2),rs("PixelationEffect",Bh);var TA=Object.defineProperty,EA=Object.getOwnPropertyDescriptor,Fh=(s,t,i,n)=>{for(var o=n>1?void 0:n?EA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&TA(t,i,o),o};class Gn extends dt{constructor(){super(...arguments),a(this,"intensity",new N(2)),a(this,"falloff",new N(1)),a(this,"samples",new N(9)),a(this,"color",new N(new re(0,0,0))),a(this,"luminanceInfluence",new N(.7)),a(this,"_ssao")}get typeName(){return"ScreenSpaceAmbientOcclusion"}onBeforeRender(){if(this._ssao&&this.context.mainCamera instanceof we){const t=this.context.mainCamera.far-this.context.mainCamera.near;this._ssao.ssaoMaterial.worldDistanceFalloff=t*.01,this._ssao.ssaoMaterial.worldDistanceThreshold=this.context.mainCamera.far}}onCreateEffect(){const t=this.context.mainCamera,i=new D.POSTPROCESSING.MODULE.NormalPass(this.context.scene,t),n=new D.POSTPROCESSING.MODULE.DepthDownsamplingPass({normalBuffer:i.texture,resolutionScale:.5}),o=this._ssao=new D.POSTPROCESSING.MODULE.SSAOEffect(t,i.texture,{normalDepthBuffer:n.texture,worldDistanceThreshold:1,worldDistanceFalloff:1,worldProximityThreshold:.1,worldProximityFalloff:2,intensity:1,blendFunction:D.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 re),o.color.copy(l)},this.luminanceInfluence.onValueChanged=l=>{o.luminanceInfluence=l};const r=new Array;return r.push(i),r.push(n),r.push(o),r}}Fh([m(N)],Gn.prototype,"intensity",2),Fh([m(N)],Gn.prototype,"falloff",2),Fh([m(N)],Gn.prototype,"samples",2),Fh([m(N)],Gn.prototype,"color",2),Fh([m(N)],Gn.prototype,"luminanceInfluence",2),rs("ScreenSpaceAmbientOcclusion",Gn);var AA=Object.defineProperty,IA=Object.getOwnPropertyDescriptor,oa=(s,t,i,n)=>{for(var o=n>1?void 0:n?IA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&AA(t,i,o),o},iy=(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))(iy||{});class Is extends dt{constructor(){super(...arguments),a(this,"gammaCorrection",!0),a(this,"aoRadius",new N(1)),a(this,"falloff",new N(1)),a(this,"intensity",new N(1)),a(this,"color",new N(new re(0,0,0))),a(this,"screenspaceRadius",!1),a(this,"quality",2),a(this,"_ssao")}get typeName(){return"ScreenSpaceAmbientOcclusionN8"}onValidate(){this._ssao&&(this._ssao.setQualityMode(iy[this.quality]),this._ssao.configuration.gammaCorrection=this.gammaCorrection,this._ssao.configuration.screenSpaceRadius=this.screenspaceRadius)}onCreateEffect(){const t=this.context.mainCamera,i=this._ssao=new D.POSTPROCESSING_AO.MODULE.N8AOPostPass(this.context.scene,t,this.context.domWidth,this.context.domHeight),n=iy[this.quality];i.setQualityMode(n),i.configuration.gammaCorrection=this.gammaCorrection,i.configuration.screenSpaceRadius=this.screenspaceRadius,this.intensity.onValueChanged=r=>{i.configuration.intensity=r},this.falloff.onValueChanged=r=>{i.configuration.distanceFalloff=r},this.aoRadius.onValueChanged=r=>{i.configuration.aoRadius=r},this.color.onValueChanged=r=>{i.color||(i.color=new re),i.configuration.color.copy(r)};const o=new Array;return o.push(i),o}}oa([Rt(),m()],Is.prototype,"gammaCorrection",2),oa([m(N)],Is.prototype,"aoRadius",2),oa([m(N)],Is.prototype,"falloff",2),oa([m(N)],Is.prototype,"intensity",2),oa([m(N)],Is.prototype,"color",2),oa([Rt(),m()],Is.prototype,"screenspaceRadius",2),oa([Rt(),m()],Is.prototype,"quality",2),rs("ScreenSpaceAmbientOcclusionN8",Is);var jA=Object.defineProperty,DA=Object.getOwnPropertyDescriptor,v1=(s,t,i,n)=>{for(var o=n>1?void 0:n?DA(t,i):t,r=s.length-1,l;r>=0;r--)(l=s[r])&&(o=(n?l(t,i,o):l(o))||o);return n&&o&&jA(t,i,o),o};class zh extends dt{constructor(){super(...arguments),a(this,"_effect"),a(this,"_amount",1),a(this,"_radius",1)}get typeName(){return"Sharpening"}onCreateEffect(){return this._effect??(this._effect=new(LA())),this.effect}get effect(){return this._effect}set amount(t){this._amount=t,this._effect&&(this._effect.uniforms.get("amount").value=t)}get amount(){return this._effect?this._effect.uniforms.get("amount").value:this._amount}set radius(t){this._radius=t,this._effect&&(this._effect.uniforms.get("radius").value=t)}get radius(){return this._effect?this._effect.uniforms.get("radius").value:this._radius}}v1([m()],zh.prototype,"amount",1),v1([m()],zh.prototype,"radius",1);function LA(){const s=`
|
|
1206
1206
|
void mainSupport() {
|
|
1207
1207
|
vUv = uv;
|
|
1208
1208
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|