@needle-tools/engine 4.3.2-beta โ†’ 4.3.2-beta.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.
@@ -130,7 +130,7 @@ Open this page to get the console: `+t.toString())}const s=exports.DeviceUtiliti
130
130
  #__vconsole .vc-mask {
131
131
  overflow: hidden;
132
132
  }
133
- `,gi==null||gi.prepend(i),s===!0&&Fm()<=0&&cv(),console.log("๐ŸŒต Debug console has loaded")}},t.onerror=()=>{console.warn("๐ŸŒต Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),bl=!1,Ht=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function wS(){if(!globalThis.VConsole)return;const s=new VConsole.VConsolePlugin("needle-console","๐ŸŒต Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+s._id+" iframe");return s.on("renderTab",function(e){const i=globalThis["needle:codegen_files"];if(!i||i.length===0)return;let n=globalThis["needle:codegen_files"][0];const o=n.indexOf("?");o>-1&&(n=n.substring(0,o));const l=location.protocol+"//"+location.host+location.pathname+"/"+n,c=encodeURIComponent(l);s.fullUrl="https://viewer.needle.tools?inspect&file="+c;var d='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';e(d)}),s.on("show",function(){const e=t();e&&e.src!==s.fullUrl&&(e.src=s.fullUrl)}),s.on("hide",function(){const e=t();e&&(e.src="")}),s.on("addTopBar",function(e){var i=new Array;i.push({name:"Open in new window โ†—",onClick:function(n){window.open(s.fullUrl,"_blank"),Ht==null||Ht.hide()}}),i.push({name:"Reload",onClick:function(n){const o=t();o&&(o.src=s.fullUrl)}}),i.push({name:"Fullscreen",onClick:function(n){const o=t();o.requestFullscreen?o.requestFullscreen():o.webkitRequestFullscreen instanceof Function&&o.webkitRequestFullscreen()}}),e(i)}),s}function xS(){const s=document.querySelector("#__vconsole .vc-switch");return s||null}function SS(){const s=document.querySelector("#__vconsole");return s||null}const uv=S("debugdefines");_o('if(!globalThis[""4.3.2-beta""]) globalThis[""4.3.2-beta""] = "0.0.0";');_o('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');_o('if(!globalThis[""Fri Mar 14 2025 15:04:23 GMT+0100 (Central European Standard Time)""]) globalThis[""Fri Mar 14 2025 15:04:23 GMT+0100 (Central European Standard Time)""] = "unknown";');_o('if(!globalThis[""npk_0b7230d0d7c94c5ef23003726b2e2ccfc5ec0f20d26de8f0bda29e63698f9006""]) globalThis[""npk_0b7230d0d7c94c5ef23003726b2e2ccfc5ec0f20d26de8f0bda29e63698f9006""] = "unknown";');_o('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.3.2-beta";');_o('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');_o('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Fri Mar 14 2025 15:04:23 GMT+0100 (Central European Standard Time)";');_o('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_0b7230d0d7c94c5ef23003726b2e2ccfc5ec0f20d26de8f0bda29e63698f9006";');const cn="4.3.2-beta",Mu="undefined",Xm="Fri Mar 14 2025 15:04:23 GMT+0100 (Central European Standard Time)";uv&&console.log(`Engine version: ${cn} (generator: ${Mu})
133
+ `,gi==null||gi.prepend(i),s===!0&&Fm()<=0&&cv(),console.log("๐ŸŒต Debug console has loaded")}},t.onerror=()=>{console.warn("๐ŸŒต Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),bl=!1,Ht=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function wS(){if(!globalThis.VConsole)return;const s=new VConsole.VConsolePlugin("needle-console","๐ŸŒต Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+s._id+" iframe");return s.on("renderTab",function(e){const i=globalThis["needle:codegen_files"];if(!i||i.length===0)return;let n=globalThis["needle:codegen_files"][0];const o=n.indexOf("?");o>-1&&(n=n.substring(0,o));const l=location.protocol+"//"+location.host+location.pathname+"/"+n,c=encodeURIComponent(l);s.fullUrl="https://viewer.needle.tools?inspect&file="+c;var d='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';e(d)}),s.on("show",function(){const e=t();e&&e.src!==s.fullUrl&&(e.src=s.fullUrl)}),s.on("hide",function(){const e=t();e&&(e.src="")}),s.on("addTopBar",function(e){var i=new Array;i.push({name:"Open in new window โ†—",onClick:function(n){window.open(s.fullUrl,"_blank"),Ht==null||Ht.hide()}}),i.push({name:"Reload",onClick:function(n){const o=t();o&&(o.src=s.fullUrl)}}),i.push({name:"Fullscreen",onClick:function(n){const o=t();o.requestFullscreen?o.requestFullscreen():o.webkitRequestFullscreen instanceof Function&&o.webkitRequestFullscreen()}}),e(i)}),s}function xS(){const s=document.querySelector("#__vconsole .vc-switch");return s||null}function SS(){const s=document.querySelector("#__vconsole");return s||null}const uv=S("debugdefines");_o('if(!globalThis[""4.3.2-beta.1""]) globalThis[""4.3.2-beta.1""] = "0.0.0";');_o('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');_o('if(!globalThis[""Mon Mar 17 2025 15:56:01 GMT+0100 (Central European Standard Time)""]) globalThis[""Mon Mar 17 2025 15:56:01 GMT+0100 (Central European Standard Time)""] = "unknown";');_o('if(!globalThis[""npk_0b7230d0d7c94c5ef23003726b2e2ccfc5ec0f20d26de8f0bda29e63698f9006""]) globalThis[""npk_0b7230d0d7c94c5ef23003726b2e2ccfc5ec0f20d26de8f0bda29e63698f9006""] = "unknown";');_o('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.3.2-beta.1";');_o('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');_o('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Mar 17 2025 15:56:01 GMT+0100 (Central European Standard Time)";');_o('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_0b7230d0d7c94c5ef23003726b2e2ccfc5ec0f20d26de8f0bda29e63698f9006";');const cn="4.3.2-beta.1",Mu="undefined",Xm="Mon Mar 17 2025 15:56:01 GMT+0100 (Central European Standard Time)";uv&&console.log(`Engine version: ${cn} (generator: ${Mu})
134
134
  Project built at ${Xm}`);const tc="npk_0b7230d0d7c94c5ef23003726b2e2ccfc5ec0f20d26de8f0bda29e63698f9006",xs="needle_isActiveInHierarchy",Go="builtin_components",ic="needle_editor_guid";function _o(s){try{(0,eval)(s)}catch(t){uv&&console.error(t)}}const CS='<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>',PS=btoa(CS),OS="data:image/svg+xml;base64,"+PS,MS=OS,RS=`<?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(RS);const kS='<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>',TS=btoa(kS),ES="data:image/svg+xml;charset=utf-8;base64,"+TS,AS=ES,DS=S("debugpatch");function Ru(s,t,e,i){const n=DS===t;if(!e&&!i)return;const o=t+"___needle";IS(s,t,e,i);const a=Object.getOwnPropertyDescriptor(s,t),l=s[t];n&&console.log("Patch",s.constructor.name,t,a,l),a?(n&&console.log("Apply patch with existing descriptor",s.constructor.name,t,a),typeof a.value=="function"&&(s[t]=q_(a.value,s,t))):(n&&console.log("Create patch with new property",s.constructor.name,t,a),Object.defineProperty(s,t,{set:function(c){if(typeof c=="function")this[o]=q_(c,s,t);else{const d=this[o];fv(s,t,this,d,c),this[o]=c,pv(s,t,this,d,c)}},get:function(){const c=this[o];return typeof c=="function"&&c[o]?c[o]:c}}))}function LS(s,t,e){const i=Qm(s,t);if(i)for(let n=i.length-1;n>=0;n--){const o=i[n];o.prefix===e&&(o.prefix=null),o.postfix===e&&(o.postfix=null),!o.prefix&&!o.postfix&&i.splice(n,1)}}const G_=Symbol("Needle:Patches:WrappedFunction");function q_(s,t,e){if(s[G_])return s;const i=function(...n){fv(t,e,this,...n);const o=s.apply(this,n);return pv(t,e,this,o,...n),o};return i[G_]=!0,i}const wd="Needle:Patches";function Yp(){return globalThis[wd]||(globalThis[wd]=new WeakMap),globalThis[wd]}function Qm(s,t){const e=Yp().get(s);return e?e.get(t):null}function IS(s,t,e,i){let n=Yp().get(s);n||(n=new Map,Yp().set(s,n));let o=n.get(t);o||(o=[],n.set(t,o)),o.push({prefix:e,postfix:i})}function fv(s,t,e,...i){var o;if(!e)return;const n=Qm(s,t);if(n)for(const a of n)(o=a.prefix)==null||o.call(e,...i)}function pv(s,t,e,i,...n){var a;if(!e)return;const o=Qm(s,t);if(o)for(const l of o)(a=l.postfix)==null||a.call(e,i,...n)}const ja=[];function ku(s){ja.indexOf(s)===-1&&ja.push(s)}function jS(s){const t=ja.indexOf(s);t!==-1&&ja.splice(t,1)}const Ba=[];function Ym(s){Ba.indexOf(s)===-1&&Ba.push(s)}function BS(s){const t=Ba.indexOf(s);t!==-1&&Ba.splice(t,1)}function mv(s){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:s}));for(let t=0;t<ja.length;t++)ja[t](s)}function gv(s){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:s}));for(let t=0;t<Ba.length;t++)Ba[t](s)}const Je=S("debuginput");var Tu=(s=>(s.Mouse="mouse",s.Touch="touch",s.Controller="controller",s.Hand="hand",s))(Tu||{}),Te=(s=>(s.PointerDown="pointerdown",s.PointerUp="pointerup",s.PointerMove="pointermove",s.KeyDown="keydown",s.KeyUp="keyup",s.KeyPressed="keypress",s))(Te||{});class cs extends PointerEvent{constructor(e,i,n){super(e,n);r(this,"clientZ");r(this,"deviceIndex");r(this,"origin");r(this,"source");r(this,"mode");r(this,"_ray");r(this,"space");r(this,"isClick",!1);r(this,"isDoubleClick",!1);r(this,"_used",!1);r(this,"_pointerid");r(this,"_pointerType");r(this,"_type");r(this,"metadata",{});r(this,"intersections",new Array);r(this,"_immediatePropagationStopped",!1);r(this,"_propagationStopped",!1);this.clientZ=n.clientZ,this._pointerid=n.pointerId,this._pointerType=n.pointerType,this._type=e,this.deviceIndex=n.deviceIndex,this.origin=n.origin,this.source=i,this.mode=n.mode,this._ray=n.ray,this.space=n.device}get isSpatial(){return this.mode!="screen"}get ray(){return this._ray||(this._ray=new h.Ray(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(e){this._ray=e}get hasRay(){return this._ray!==void 0}get used(){return this._used}use(){this._used=!0}get pointerId(){return this._pointerid}get pointerType(){return this._pointerType}get type(){return this._type}get immediatePropagationStopped(){return this._immediatePropagationStopped}get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){var e;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}stopPropagation(){var e;this._propagationStopped=!0,super.stopPropagation(),(e=this.source)==null||e.stopPropagation(),Je&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class Bl extends KeyboardEvent{constructor(e,i,n){super(e,n);r(this,"source");this.source=i}stopImmediatePropagation(){var e;super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}}class FS{constructor(t){r(this,"key");r(this,"keyType");r(this,"source");this.key=t.key,this.keyType=t.type,this.source=t}}var ni=(s=>(s[s.Early=-100]="Early",s[s.Default=0]="Default",s[s.Late=100]="Late",s))(ni||{});class _v{constructor(t){r(this,"_eventListeners",{});r(this,"_doubleClickTimeThreshold",.2);r(this,"_longPressTimeThreshold",1);r(this,"_setCursorTypes",[]);r(this,"context");r(this,"_pointerDown",[!1]);r(this,"_pointerUp",[!1]);r(this,"_pointerClick",[!1]);r(this,"_pointerDoubleClick",[!1]);r(this,"_pointerPressed",[!1]);r(this,"_pointerPositions",[new h.Vector2]);r(this,"_pointerPositionsLastFrame",[new h.Vector2]);r(this,"_pointerPositionsDelta",[new h.Vector2]);r(this,"_pointerPositionsRC",[new h.Vector2]);r(this,"_pointerPositionDown",[new h.Vector3]);r(this,"_pointerDownTime",[]);r(this,"_pointerUpTime",[]);r(this,"_pointerUpTimestamp",[]);r(this,"_pointerIds",[]);r(this,"_pointerTypes",[""]);r(this,"_mouseWheelChanged",[!1]);r(this,"_mouseWheelDeltaY",[0]);r(this,"_pointerEvent",[]);r(this,"_pointerEventsPressed",[]);r(this,"_pointerSpace",[]);r(this,"_pressedStack",new Map);r(this,"_htmlEventSource");r(this,"onLostFocus",()=>{for(const t in this.keysPressed)this.keysPressed[t].pressed=!1});r(this,"_receivedPointerMoveEventsThisFrame",new Array);r(this,"onEndOfFrame",()=>{this._receivedPointerMoveEventsThisFrame.length=0;for(let t=0;t<this._pointerUp.length;t++)this._pointerUp[t]=!1;for(let t=0;t<this._pointerDown.length;t++)this._pointerDown[t]=!1;for(let t=0;t<this._pointerClick.length;t++)this._pointerClick[t]=!1;for(let t=0;t<this._pointerDoubleClick.length;t++)this._pointerDoubleClick[t]=!1;for(const t of this._pointerPositionsDelta)t.set(0,0);for(let t=0;t<this._mouseWheelChanged.length;t++)this._mouseWheelChanged[t]=!1;for(let t=0;t<this._mouseWheelDeltaY.length;t++)this._mouseWheelDeltaY[t]=0});r(this,"onContextMenu",t=>{this.canReceiveInput(t)!==!1&&t instanceof PointerEvent&&t.pointerType});r(this,"keysPressed",{});r(this,"onKeyDown",t=>{if(Je&&console.log(`key down ${t.code}, ${this.context.application.hasFocus}`,t),!this.context.application.hasFocus)return;const e=this.keysPressed[t.code];if(e&&e.pressed)return;this.keysPressed[t.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:t.key,code:t.code};const i=new Bl("keydown",t,t);this.onDispatchEvent(i)});r(this,"onKeyPressed",t=>{if(!this.context.application.hasFocus)return;const e=this.keysPressed[t.code];if(!e)return;e.pressed=!0,e.frame=this.context.time.frameCount+1;const i=new Bl("keypress",t,t);this.onDispatchEvent(i)});r(this,"onKeyUp",t=>{if(!this.context.application.hasFocus)return;const e=this.keysPressed[t.code];if(!e)return;e.pressed=!1,e.frame=this.context.time.frameCount+1;const i=new Bl("keyup",t,t);this.onDispatchEvent(i)});r(this,"onWheelWindow",t=>{document.pointerLockElement&&this.onMouseWheel(t)});r(this,"onMouseWheel",t=>{if(this.canReceiveInput(t)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const e=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=e+t.deltaY});r(this,"onPointerDown",t=>{if(this.context.isInAR||this.canReceiveInput(t)===!1)return;t.target instanceof HTMLElement&&t.target.setPointerCapture(t.pointerId);const e=this.getPointerId(t);Je&&Ee(`pointer down #${e}, identifier:${t.pointerId}`);const i=this.getAndUpdateSpatialObjectForScreenPosition(e,t.clientX,t.clientY),n=new cs("pointerdown",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:e,button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:i,pressure:t.pressure});this.onDown(n)});r(this,"onPointerMove",t=>{if(this.context.isInAR||this._receivedPointerMoveEventsThisFrame.includes(t.pointerId))return;this._receivedPointerMoveEventsThisFrame.push(t.pointerId);let e=t.button;t.pointerType==="mouse"&&(e=this.getFirstPressedButtonForPointer(0)??0);const i=this.getPointerId(t,e);e===-1&&(e=i);const n=this.getAndUpdateSpatialObjectForScreenPosition(i,t.clientX,t.clientY),o=new cs("pointermove",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:i,button:e,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:n,pressure:t.pressure});this.onMove(o)});r(this,"onPointerCancel",t=>{this.context.isInAR||(Je&&console.log("Pointer cancel",t),this.onPointerUp(t))});r(this,"onPointerUp",t=>{if(this.context.isInAR)return;t.target instanceof HTMLElement&&t.target.releasePointerCapture(t.pointerId);const e=this.getPointerId(t),i=new cs("pointerup",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:e,button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:this.getAndUpdateSpatialObjectForScreenPosition(e,t.clientX,t.clientY),pressure:t.pressure});this.onUp(i),this._pointerIds[e]=-1,Je&&console.log("ID="+e,"PointerId="+t.pointerId,"ALL:",[...this._pointerIds])});r(this,"onTouchStart",t=>{if(this.context.isInAR)for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e],n=this.getPointerIndex(i.identifier),o=this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),a=new cs("pointerdown",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:0,clientX:i.clientX,clientY:i.clientY,pointerType:"touch",buttonName:"unknown",device:o,pressure:i.force});this.onDown(a)}});r(this,"onTouchMove",t=>{if(this.context.isInAR)for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e],n=this.getPointerIndex(i.identifier),o=this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),a=new cs("pointermove",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:0,clientX:i.clientX,clientY:i.clientY,pointerType:"touch",buttonName:"unknown",device:o,pressure:i.force});this.onMove(a)}});r(this,"onTouchEnd",t=>{if(this.context.isInAR)for(let e=0;e<t.changedTouches.length;e++){const i=t.changedTouches[e],n=this.getPointerIndex(i.identifier),o=new cs("pointerup",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:0,clientX:i.clientX,clientY:i.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),pressure:i.force});this.onUp(o),this._pointerIds[n]=-1}});r(this,"tempNearPlaneVector",new h.Vector3);r(this,"tempFarPlaneVector",new h.Vector3);r(this,"tempLookMatrix",new h.Matrix4);this.context=t,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(t,e,i){if(this._eventListeners[t]||(this._eventListeners[t]=[]),!e||typeof e!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}i?i={...i}:i={};let n=0;(i==null?void 0:i.queue)!=null&&(n=i.queue);const o=this._eventListeners[t],a=o.find(l=>l.priority===n);a?a.listeners.push({callback:e,options:i}):(o.push({priority:n,listeners:[{callback:e,options:i}]}),o.sort((l,c)=>l.priority-c.priority))}removeEventListener(t,e,i){if(!this._eventListeners[t]||!e)return;const n=this._eventListeners[t];if((i==null?void 0:i.queue)!=null){const o=n.find(l=>l.priority===i.queue);if(!o)return;const a=o.listeners.findIndex(l=>l.callback===e);a>=0&&o.listeners.splice(a,1)}else for(const o of n){const a=o.listeners.findIndex(l=>l.callback===e);a>=0&&o.listeners.splice(a,1)}}dispatchEvent(t){var i,n,o,a;let e=!1;if(t instanceof Bl){const l=this._eventListeners[t.type];if(l)for(const c of l)for(let d=0;d<c.listeners.length;d++){const u=c.listeners[d];if((n=(i=u.options)==null?void 0:i.signal)!=null&&n.aborted){c.listeners.splice(d,1),d--;continue}u.options.once&&(c.listeners.splice(d,1),d--),u.callback(t)}}if(t instanceof cs){const l=this._eventListeners[t.type];if(l)for(const c of l){if(e)break;for(let d=0;d<c.listeners.length;d++){const u=c.listeners[d];if((a=(o=u.options)==null?void 0:o.signal)!=null&&a.aborted){c.listeners.splice(d,1),d--;continue}if(t.immediatePropagationStopped){e=!0,Je&&console.log("immediatePropagationStopped",t.type);break}else t.propagationStopped&&(e=!0,Je&&console.log("propagationStopped",t.type));u.options.once&&(c.listeners.splice(d,1),d--),u.callback(t)}}}}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}get click(){return this._pointerClick[0]}get doubleClick(){return this._pointerDoubleClick[0]}setCursorPointer(){this.setCursor("pointer")}setCursorNormal(){this.unsetCursor("pointer")}setCursor(t){this._setCursorTypes.push(t),this._setCursorTypes.length>10&&this._setCursorTypes.shift(),this.updateCursor()}unsetCursor(t){for(let e=this._setCursorTypes.length-1;e>=0;e--)if(this._setCursorTypes[e]===t){this._setCursorTypes.splice(e,1),this.updateCursor();break}}updateCursor(){var t;((t=this._setCursorTypes)==null?void 0:t.length)==0?this.context.domElement.style.cursor="default":this.context.domElement.style.cursor=this._setCursorTypes[this._setCursorTypes.length-1]}getIsPointerIdInUse(t){for(const e of this._pointerEventsPressed)if(e.pointerId===t&&e.used)return!0;return!1}getPointerPressedCount(){let t=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&t++;return t}getPointerPosition(t){return t>=this._pointerPositions.length?null:this._pointerPositions[t]}getPointerPositionLastFrame(t){return t>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[t]}getPointerPositionDelta(t){return t>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[t]}getPointerPositionRC(t){return t>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[t]}getPointerDown(t){return t>=this._pointerDown.length?!1:this._pointerDown[t]}getPointerUp(t){return t>=this._pointerUp.length?!1:this._pointerUp[t]}getPointerPressed(t){return t>=this._pointerPressed.length?!1:this._pointerPressed[t]}getPointerClicked(t){return t>=this._pointerClick.length?!1:this._pointerClick[t]}getPointerDoubleClicked(t){return t>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[t]}getPointerDownTime(t){return t>=this._pointerDownTime.length?-1:this._pointerDownTime[t]}getPointerUpTime(t){return t>=this._pointerUpTime.length?-1:this._pointerUpTime[t]}getPointerLongPress(t){return t>=this._pointerDownTime.length?!1:this.getPointerPressed(t)&&this.context.time.time-this._pointerDownTime[t]>this._longPressTimeThreshold}getIsMouse(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="mouse"}getIsTouch(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="touch"}getTouchesPressedCount(){let t=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&this.getIsTouch(e)&&t++;return t}getMouseWheelChanged(t=0){return t>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[t]}getMouseWheelDeltaY(t=0){return t>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[t]}getPointerEvent(t){if(!(t>=this._pointerEvent.length))return this._pointerEvent[t]??void 0}*foreachPointerId(t){for(let e=0;e<this._pointerTypes.length;e++)if(this._pointerIsActive(e)){if(t!==void 0){const i=this._pointerTypes[e];if(Array.isArray(t)){let n=!1;for(const o of t)if(i===o){n=!0;break}if(!n)continue}else if(t!==i)continue}yield e}}*foreachTouchId(){for(let t=0;t<this._pointerTypes.length;t++)this._pointerTypes[t]==="touch"&&this._pointerIsActive[t]&&(yield t)}_pointerIsActive(t){return t<0?!1:this._pointerPressed[t]||this._pointerDown[t]||this._pointerUp[t]}onDownButton(t,e){let i=this._pressedStack.get(t);i||(i=[],this._pressedStack.set(t,i)),i.push(e)}onReleaseButton(t,e){const i=this._pressedStack.get(t);if(!i)return;const n=i.indexOf(e);n>=0&&i.splice(n,1)}getFirstPressedButtonForPointer(t){const e=this._pressedStack.get(t);if(e)return e[0]}getLatestPressedButtonForPointer(t){const e=this._pressedStack.get(t);if(e)return e[e.length-1]}getKeyDown(){for(const t in this.keysPressed){const e=this.keysPressed[t];if(e.startFrame===this.context.time.frameCount)return e.key}return null}getKeyPressed(){for(const t in this.keysPressed){const e=this.keysPressed[t];if(e.pressed)return e.key}return null}isKeyDown(t){var i;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(t);if(e!==null){for(const n of e)if(this.isKeyDown(n))return!0;return!1}return((i=this.keysPressed[t])==null?void 0:i.startFrame)===this.context.time.frameCount&&this.keysPressed[t].pressed}isKeyUp(t){var i;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(t);if(e!==null){for(const n of e)if(this.isKeyUp(n))return!0;return!1}return((i=this.keysPressed[t])==null?void 0:i.frame)===this.context.time.frameCount&&!this.keysPressed[t].pressed}isKeyPressed(t){var i;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(t);if(e!==null){for(const n of e)if(this.isKeyPressed(n))return!0;return!1}return(i=this.keysPressed[t])==null?void 0:i.pressed}getCodeForCommonKeyName(t){if(t.length===1){if(t>="0"&&t<="9")return["Digit"+t];if(t>="a"&&t<="z")return["Key"+t.toUpperCase()];if(t==" ")return["Space"]}switch(t){case"shift":case"Shift":return["ShiftLeft","ShiftRight"];case"control":case"Control":return["ControlLeft","ControlRight"];case"alt":case"Alt":return["AltLeft","AltRight"]}return null}createInputEvent(t){switch(t.type){case"pointerdown":Je&&Ee("Create Pointer down"),this.onDownButton(t.deviceIndex,t.button),this.onDown(t);break;case"pointermove":Je&&Ee("Create Pointer move"),this.onMove(t);break;case"pointerup":Je&&Ee("Create Pointer up"),this.onUp(t),this.onReleaseButton(t.deviceIndex,t.button);break}}convertScreenspaceToRaycastSpace(t){return t.x=(t.x-this.context.domX)/this.context.domWidth*2-1,t.y=-((t.y-this.context.domY)/this.context.domHeight)*2+1,t}bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){var t,e;window.removeEventListener("contextmenu",this.onContextMenu),(t=this._htmlEventSource)==null||t.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),window.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("touchend",this.onTouchEnd),(e=this._htmlEventSource)==null||e.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const t=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);t>=0&&this.context.post_render_callbacks.splice(t,1),this.unbindEvents()}canReceiveInput(t){var e;return t.target===((e=this.context.renderer)==null?void 0:e.domElement)||t.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&t.target===document.body&&exports.DeviceUtilities.isMozillaXR()?!0:(Je&&console.warn("CanReceiveInput:False for",t.target),!1)}getPointerId(t,e){return t.pointerType==="mouse"?0+(e??t.button):this.getPointerIndex(t.pointerId)}getButtonName(t){const e=t.button;if(t.pointerType==="mouse")switch(e){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(t,e,i){let n=this._pointerSpace[t];n||(n=new h.Object3D,this._pointerSpace[t]=n),this._pointerSpace[t]=n;const o=this.context.mainCamera;if(o){const a=this.tempNearPlaneVector.set(e,i,-1);this.convertScreenspaceToRaycastSpace(a);const l=this.tempFarPlaneVector.set(a.x,a.y,1);a.unproject(o),l.unproject(o);const c=o.worldUp||$(0,1,0).applyQuaternion(ye(o));this.tempLookMatrix.lookAt(l,a,c),n.position.set(a.x,a.y,a.z),n.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return n}isInRect(t){if(this.context.isInXR)return!0;const e=this.context.domElement.getBoundingClientRect(),i=t.clientX,n=t.clientY,o=i>=e.x&&i<=e.right&&n>=e.y&&n<=e.bottom;return Je&&!o&&console.log("Not in rect",e,i,n),o}onDown(t){const e=t.pointerId;if(this.getPointerPressed(e)&&console.warn(`Received pointerDown for pointerId that is already pressed: ${e}`,Je?t:""),Je&&console.log(t.pointerType,"DOWN",e),!!this.isInRect(t)){for(this.setPointerState(e,this._pointerPressed,!0),this.setPointerState(e,this._pointerDown,!0),this.setPointerStateT(e,this._pointerEvent,t.source);e>=this._pointerTypes.length;)this._pointerTypes.push(t.pointerType);for(this._pointerTypes[e]=t.pointerType;e>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new h.Vector3);for(this._pointerPositionDown[e].set(t.clientX,t.clientY,t.clientZ??0);e>=this._pointerPositions.length;)this._pointerPositions.push(new h.Vector2);this._pointerPositions[e].set(t.clientX,t.clientY),e>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[e]=this.context.time.realtimeSinceStartup,this.updatePointerPosition(t),this._pointerEventsPressed.push(t),this.onDispatchEvent(t)}}onMove(t){const e=t.pointerId,i=this.getPointerPressed(e);i===!1&&!this.isInRect(t)||t.pointerType==="touch"&&!i||(this.updatePointerPosition(t),this.setPointerStateT(e,this._pointerEvent,t.source),this.onDispatchEvent(t))}onUp(t){const e=t.pointerId;if(!this.getPointerPressed(e)){Je&&console.log(t.pointerType,"UP",e,"was not down");return}Je&&console.log(t.pointerType,"UP",e),this.setPointerState(e,this._pointerPressed,!1),this.setPointerStateT(e,this._pointerEvent,t.source),this.setPointerState(e,this._pointerUp,!0),this.updatePointerPosition(t);for(let c=this._pointerEventsPressed.length-1;c>=0;c--)if(this._pointerEventsPressed[c].pointerId===e){this._pointerEventsPressed.splice(c,1);break}if(!this._pointerPositionDown[e]){Je&&me("Received pointer up event without matching down event for button: "+e),console.warn("Received pointer up event without matching down event for button: "+e);return}const n=this._pointerUpTime[e],o=this._pointerDownTime[e],a=this.context.time.realtimeSinceStartup,l=a-o;if(e>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),this._pointerUpTime[e]=a,l<1){let c=t.clientX-this._pointerPositionDown[e].x,d=t.clientY-this._pointerPositionDown[e].y,u=0;if(t.isSpatial&&t.clientZ!=null&&(u=t.clientZ-this._pointerPositionDown[e].z,c*=200,d*=200,u*=200),Math.abs(c)<5&&Math.abs(d)<5&&Math.abs(u)<5){this.setPointerState(e,this._pointerClick,!0),t.isClick=!0;const f=a-n;Je&&console.log("CLICK",e,c,d,u,f),f<this._doubleClickTimeThreshold&&f>0&&(this.setPointerState(e,this._pointerDoubleClick,!0),t.isDoubleClick=!0)}}this.onDispatchEvent(t)}updatePointerPosition(t){const e=t.pointerId;for(;e>=this._pointerPositions.length;)this._pointerPositions.push(new h.Vector2);for(;e>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new h.Vector2);for(;e>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new h.Vector2);const i=this._pointerPositionsLastFrame[e];i.copy(this._pointerPositions[e]);const n=this._pointerPositionsDelta[e];let o=t.clientX-i.x,a=t.clientY-i.y;if(t.source instanceof MouseEvent||t.source instanceof TouchEvent){const u=t.source;o===0&&u.movementX!==0&&(o=u.movementX||0),a===0&&u.movementY!==0&&(a=u.movementY||0)}n.x+=o,n.y+=a,this._pointerPositions[e].x=t.clientX,this._pointerPositions[e].y=t.clientY;const l=t.clientX,c=t.clientY;for(;e>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new h.Vector2);const d=this._pointerPositionsRC[e];d.set(l,c),this.convertScreenspaceToRaycastSpace(d)}getPointerIndex(t){let e=-1;for(let i=0;i<this._pointerIds.length;i++){if(this._pointerIds[i]===t)return i;e===-1&&this._pointerIds[i]===-1&&(e=i)}return e!==-1?(this._pointerIds[e]=t,e):(Je&&console.log("PUSH pointerId:",t),this._pointerIds.push(t),this._pointerIds.length-1)}setPointerState(t,e,i){e[t]=i}setPointerStateT(t,e,i){return e[t]=i,i}onDispatchEvent(t){const e=Q.Current;try{Q.Current=this.context,this.dispatchEvent(t)}finally{Q.Current=e}}}const Ca=new h.Matrix4().makeRotationY(Math.PI),Bi=new h.Quaternion().setFromAxisAngle(new h.Vector3(0,1,0),Math.PI),US=S("debugwebxr");class zS{constructor(){r(this,"priority",-1e5);r(this,"gameObject");if(this.gameObject=new h.Object3D,this.gameObject.name="Implicit XR Rig",US){const t=ng(16733661);t.position.y+=.5,this.gameObject.add(t)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const Jn=S("debugwebxr"),zh=S("debugcustomgesture"),NS="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",VS="generic-trigger",$S=new h.Quaternion().setFromEuler(new h.Euler(h.MathUtils.degToRad(0),h.MathUtils.degToRad(-90),h.MathUtils.degToRad(-90))),WS=new h.Vector3(.04,-.04,0);class Km{constructor(t,e,i){r(this,"xr");r(this,"inputSource");r(this,"index",0);r(this,"emitEvents",!0);r(this,"_connected",!0);r(this,"_isTracking",!1);r(this,"__gamepad");r(this,"__hand");r(this,"__side");r(this,"_hitTestSource");r(this,"_hasSelectEvent",!1);r(this,"_isMxInk",!1);r(this,"_isMetaQuestTouchController",!1);r(this,"_handJointPoses",new Map);r(this,"_gripMatrix",new h.Matrix4);r(this,"_gripPosition",new h.Vector3);r(this,"_gripQuaternion",new h.Quaternion);r(this,"_linearVelocity",new h.Vector3);r(this,"_rayPositionRaw",new h.Vector3);r(this,"_rayRotationRaw",new h.Quaternion);r(this,"_rayMatrix",new h.Matrix4);r(this,"_rayPosition",new h.Vector3);r(this,"_rayQuaternion",new h.Quaternion);r(this,"_gripWorldPosition",new h.Vector3);r(this,"_gripWorldQuaternion",new h.Quaternion);r(this,"_rayWorldPosition",new h.Vector3);r(this,"_rayWorldQuaternion",new h.Quaternion);r(this,"_pinchPosition",new h.Vector3);r(this,"_ray");r(this,"_hand_wristDotUp");r(this,"_object");r(this,"_gripSpaceObject");r(this,"_raySpaceObject");r(this,"model",null);r(this,"_debugAxesHelper",new h.AxesHelper(.15));r(this,"_debugGripAxesHelper",new h.AxesHelper(.07));r(this,"_debugRayAxesHelper",new h.AxesHelper(.07));r(this,"_hitTestSourcePromise",null);r(this,"onPointerHits",t=>{});r(this,"_needleGamepadButtons",{});r(this,"_buttonMap",new Map);r(this,"_motioncontroller");r(this,"_layout");r(this,"getMotionController");r(this,"emitPointerDownEvent",!0);r(this,"emitPointerUpEvent",!0);r(this,"emitPointerMoveEvent",!0);r(this,"pointerMoveDistanceThreshold",.03);r(this,"pointerMoveAngleThreshold",.05);r(this,"_selectButtonIndex");r(this,"_squeezeButtonIndex");r(this,"onSelectStart",t=>{var n,o,a,l;if(!this.emitPointerDownEvent||this.inputSource!==t.inputSource)return;this.onUpdateFrame(t.frame),this._hasSelectEvent=!0;const e=(n=this._layout)==null?void 0:n.selectComponentId,i=(l=(a=(o=this._layout)==null?void 0:o.components[e])==null?void 0:a.gamepadIndices)==null?void 0:l.button;i!==void 0&&(this._selectButtonIndex=i),!zh&&(Jn&&N.DrawDirection(this.rayWorldPosition,$(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(Te.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,t))});r(this,"onSelectEnd",t=>{this.emitPointerUpEvent&&(zh||this.inputSource===t.inputSource&&this.emitPointerEvent(Te.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,t))});r(this,"onSequeezeStart",t=>{var e,i,n;this.emitPointerDownEvent&&this.inputSource===t.inputSource&&(this._squeezeButtonIndex=(n=(i=(e=this._layout)==null?void 0:e.components["xr-standard-squeeze"])==null?void 0:i.gamepadIndices)==null?void 0:n.button,this._squeezeButtonIndex!==void 0&&(Jn&&N.DrawDirection(this.rayWorldPosition,$(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(Te.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,t)))});r(this,"onSequeezeEnd",t=>{this.emitPointerUpEvent&&this.inputSource===t.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(Te.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,t)});r(this,"states",{});r(this,"_didMoveLastFrame",!1);r(this,"_lastPointerMovePosition",new h.Vector3);r(this,"_lastPointerMoveQuaternion",new h.Quaternion);r(this,"pointerInit");this.xr=t,this.inputSource=e,this.index=i,this._object=new h.Object3D,this._object.name=`NeedleXRController_${i}`,Jn&&(this._object.add(this._debugAxesHelper),this._gripSpaceObject=new h.Object3D,this._raySpaceObject=new h.Object3D,this._gripSpaceObject.name=`NeedleXRController_${i}_gripSpace`,this._raySpaceObject.name=`NeedleXRController_${i}_raySpace`,this._gripSpaceObject.add(this._debugGripAxesHelper),this._raySpaceObject.add(this._debugRayAxesHelper),this.xr.context.scene.add(this._gripSpaceObject),this.xr.context.scene.add(this._raySpaceObject)),this.xr.context.scene.add(this._object),this._ray=new h.Ray,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents()}get context(){return this.xr.context}get connected(){return this._connected}get isTracking(){return this._isTracking}get gamepad(){return this.__gamepad??(this.__gamepad=this.inputSource.gamepad)}get isHand(){return this.hand!=null}get hand(){return this.__hand??(this.__hand=this.inputSource.hand)}get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.__side??(this.__side=this.inputSource.handedness)}get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get isStylus(){return this._isMxInk}getHitTestSource(){return this._hitTestSource||this._requestHitTestSource(),this._hitTestSource}get hasHitTestSource(){return this._hitTestSource}cancelHitTestSource(){this._hitTestSource&&(this._hitTestSource.cancel(),this._hitTestSource=void 0)}get hasSelectEvent(){return this._hasSelectEvent}getHitTest(){return this.xr.getHitTest(this)}getHandJointPose(t,e){var n;if(e=e||this.xr.frame,!this.hand||!(e!=null&&e.getJointPose)||!this.xr.referenceSpace)return null;let i=(n=this._handJointPoses)==null?void 0:n.get(t);return i||(i=e.getJointPose(t,this.xr.referenceSpace),i&&this._handJointPoses.set(t,i),i)}get gripPosition(){return $(this._gripPosition)}get gripQuaternion(){return rn(this._gripQuaternion)}get gripMatrix(){return this._gripMatrix}get gripLinearVelocity(){return $(this._linearVelocity).applyQuaternion(Bi)}get rayPosition(){return $(this._rayPosition)}get rayQuaternion(){return rn(this._rayQuaternion)}get gripWorldPosition(){return $(this._gripWorldPosition)}get gripWorldQuaternion(){return rn(this._gripWorldQuaternion)}get rayWorldPosition(){return $(this._rayWorldPosition)}updateRayWorldPosition(){var e;const t=(e=this.xr.context.mainCamera)==null?void 0:e.parent;this._rayWorldPosition.copy(this._rayPositionRaw),t&&this._rayWorldPosition.applyMatrix4(t.matrixWorld)}get rayWorldQuaternion(){return rn(this._rayWorldQuaternion)}get pinchPosition(){return $(this._pinchPosition)}updateRayWorldQuaternion(){var i;const t=(i=this.xr.context.mainCamera)==null?void 0:i.parent,e=t?ye(t):void 0;this._rayWorldQuaternion.copy(this._rayRotationRaw).multiply(Bi),e&&this._rayWorldQuaternion.premultiply(e)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy($(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get handWristDotUp(){var e;if(this._hand_wristDotUp!==void 0)return this._hand_wristDotUp;const t=(e=this.handObject)==null?void 0:e.joints.wrist;if(t){const i=$(0,1,0).applyQuaternion(t.quaternion),n=$(0,1,0).dot(i);return this._hand_wristDotUp=n}}get isHandUpsideDown(){return this.handWristDotUp!==void 0?this.handWristDotUp<-.7:!1}get isTeleportGesture(){var t;return this.isHandUpsideDown&&((t=this.getGesture("pinch"))==null?void 0:t.isDown)}get object(){return this._object}async getModelUrl(){var t;return(t=this.getMotionController)==null?void 0:t.then(e=>(e==null?void 0:e.assetUrl)||null)}_requestHitTestSource(){var t;return this._hitTestSourcePromise?this._hitTestSourcePromise:this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&this.xr.session.requestHitTestSourceForTransientInput?this._hitTestSourcePromise=((t=this.xr.session.requestHitTestSourceForTransientInput({profile:this.inputSource.profiles[0],offsetRay:new XRRay}))==null?void 0:t.then(e=>(this._hitTestSourcePromise=null,this.connected?this._hitTestSource=e:(e.cancel(),null))))??null:null}onUpdate(t){performance.mark("NeedleXRController onUpdate start"),this.onUpdateFrame(t),this.updateInputEvents(),this.onUpdateMove(),performance.mark("NeedleXRController onUpdate end"),performance.measure("NeedleXRController onUpdate","NeedleXRController onUpdate start","NeedleXRController onUpdate end")}onRenderDebug(){var o;N.DrawSphere(this.rayWorldPosition,.003),N.DrawDirection(this.rayWorldPosition,$(0,0,10).applyQuaternion(this.rayWorldQuaternion));const e=(this.inputSource.gripSpace?this.gripWorldPosition:this.object.worldPosition).sub(this.object.worldForward.multiplyScalar(.1)),i=this.inputSource.profiles.join(`
135
135
  `);let n=`Controller[${this.index}] (${this.inputSource.targetRayMode}, ${this.side})
136
136
  C:${this.connected?"x":"-"} T:${this.isTracking?"x":"-"} Hand:${this.inputSource.hand?"x":"-"} Pen: ${this._isMxInk?"x":"-"}`;if(this.inputSource.hand&&(n+=`
@@ -152,7 +152,7 @@ See https://engine.needle.tools/docs/scripting.html#special-lifecycle-hooks for
152
152
  `+Jt):console.debug("โŠž Connected to networking backend",Jt),n(!0),this.onSendQueued(an.OnConnection)}).onClose(f=>{this._connectingToWebsocketPromise=null,this.connected=!1,this._isInRoom=!1,n(!1);let m="Websocket connection closed...";Jt!=null&&Jt.includes("/socket")||(m+=' Do you perhaps mean to connect to "/socket"?'),console.error(m)}).onError(f=>{console.error("โŠ  Websocket connection failed..."),n(!1)}).onRetry(()=>{console.log("โ†’ Retry connecting to networking websocket")}).build();c.addEventListener(o.WebsocketEvent.message,(f,m)=>{this.onMessage(f,m)})})}onMessage(t,e){const i=e.data;try{if(typeof i!="string"){i.size&&this.handleIncomingBinaryMessage(i);return}const n=JSON.parse(i);if(Array.isArray(n))for(const o of n)this.handleIncomingStringMessage(o);else this.handleIncomingStringMessage(n);return}catch(n){ei&&i==="pong"?console.log("<<",i):B()&&console.error("Failed to parse message",n)}}async handleIncomingBinaryMessage(t){Mf&&console.log("<< bin",this.context.time.frame);const e=await t.arrayBuffer();var i=new Uint8Array(e);const n=new oe.ByteBuffer(i),o=n.getBufferIdentifier(),a=this._listenersBinary[o],l=bv(n),c=vv(l);if(c&&typeof c=="string"&&(this._state[c]=l),!a)return;const d=l??n;for(const u of a)u(d)}handleIncomingStringMessage(t){var n,o;if(ei&&console.log("<<",t.key??t),t.key)switch(t.key){case"connection-start-info":if(t.data){const c=t.data;c&&(console.assert(c.id!==void 0&&c.id!==null&&c.id.length>0,"server did not send connection id",c.id),console.debug("Your id is: "+c.id,this.context.alias??""),this._connectionId=c.id)}else console.warn("Expected connection id in "+t.key);break;case"joined-room":if(ei&&console.log(t),t){this._isInRoom=!0;const c=t;this._currentRoomName=c.room,this._currentRoomViewId=c.viewId,this._currentRoomAllowEditing=c.allowEditing??!0,this._currentInRoom.length=0,this._currentInRoom.push(...c.inRoom),(Mf||B())&&console.debug("Joined Needle Engine Room: "+c.room);const d=new URL(window.location.href);d.searchParams.has("room")&&d.searchParams.delete("room"),d.searchParams.set("view",this._currentRoomViewId),console.debug(`Room view id: ${this._currentRoomViewId}
153
153
  ${d.href}`)}this.onSendQueued(an.OnRoomJoin);break;case"left-room":t.room===this.currentRoomName&&(this._isInRoom=!1,this._currentRoomName=null,this._currentInRoom.length=0);break;case"user-joined-room":if(t.data){const c=t.data;this._currentInRoom.push(c.userId),ei&&console.log(c.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(t.data){const c=t.data,d=this._currentInRoom.indexOf(c.userId);d>=0&&(ei&&console.log(c.userId+" left","now in room:",this._currentInRoom),this._currentInRoom.splice(d,1)),c.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":ei&&console.log("RECEIVED all-room-state-deleted"),this._state={};break;case"ping":case"pong":const l=(n=t.data)==null?void 0:n.time;l&&(this._currentDelay=this.context.time.time-l),ei&&console.log("Current latency: "+this._currentDelay.toFixed(4)+" sec","Clients in room: "+((o=this._currentInRoom)==null?void 0:o.length));break}const e=t.data;e&&(this._state[e.guid]=e);let i=this._listeners[t.key];if(i){i=[...i];for(const a of i)try{a(t.data)}catch(l){console.error('Error invoking callback for "'+t.key+'"',l)}}}toMessage(t,e){return{key:t,data:e}}sendWithWebsocket(t,e,i=an.OnRoomJoin){if(!this._ws){const o=this._waitingForSocket[i]||[];o.push(()=>this.sendWithWebsocket(t,e,i)),this._waitingForSocket[i]=o;return}const n=JSON.stringify(this.toMessage(t,e));ei&&console.log(">>",t),this._ws.send(n)}onSendQueued(t){const e=this._waitingForSocket[t];if(e){for(const i of e)i();e.length=0}}}const nc=S("debugwebxr");class Rf{constructor(t,e){r(this,"controllerStates",[]);r(this,"userId");r(this,"context");r(this,"userStateEvtName");r(this,"onReceivedControllerState",t=>{nc&&console.log(`XRSync: Received change for ${this.userId}: ${t.type} ${t.handedness}; tracked=${t.isTracking}`);let e=!1;for(let i=0;i<this.controllerStates.length;i++)if(this.controllerStates[i].index===t.index){this.controllerStates[i]=t,e=!0;break}e||this.controllerStates.push(t)});this.userId=t,this.context=e,this.userStateEvtName="xr-sync-user-state-"+t,this.context.connection.beginListen(this.userStateEvtName,this.onReceivedControllerState)}dispose(){this.context.connection.stopListen(this.userStateEvtName,this.onReceivedControllerState)}update(t){if(this.context.connection.isConnected!=!1){for(let e=this.controllerStates.length-1;e>=0;e--){const i=this.controllerStates[e];let n=!1;for(let o=0;o<t.controllers.length;o++)t.controllers[o].index===i.index&&(n=!0);n||(nc&&console.log(`XRSync: ${i.type} ${i.handedness} removed`,i.index),this.controllerStates.splice(e,1),this.sendControllerRemoved(i))}for(const e of t.controllers)this.updateControllerStates(e)}}onExitXR(t){for(const e of this.controllerStates)this.sendControllerRemoved(e);this.controllerStates.length=0}sendControllerRemoved(t){t.isTracking=!1,t.guid="",this.context.connection.send(this.userStateEvtName,t),this.context.connection.sendDeleteRemoteState(t.guid)}updateControllerStates(t){const e=this.controllerStates.find(i=>i.index===t.index);if(e){let i=!1;i||(i=e.isTracking!=t.isTracking),i&&(e.isTracking=t.isTracking,this.context.connection.send(this.userStateEvtName,e))}else{const i={guid:this.userId+"-"+t.index,isTracking:t.isTracking,handedness:t.side,index:t.index,type:t.hand?"hand":"controller"};this.controllerStates.push(i),this.context.connection.send(this.userStateEvtName,i),nc&&console.log(`XRSync: ${i.type} ${i.handedness} added`,i.index)}}}class Ov{constructor(t){r(this,"context");r(this,"onJoinedRoom",()=>{if(this.context.connection.connectionId){this._states.has(this.context.connection.connectionId)||(nc&&console.log("XRSync: Local user joined room",this.context.connection.connectionId),this._states.set(this.context.connection.connectionId,new Rf(this.context.connection.connectionId,this.context)));for(const t of this.context.connection.usersInRoom())this._states.has(t)||this._states.set(t,new Rf(t,this.context))}});r(this,"onLeftRoom",()=>{if(this.context.connection.connectionId&&!this._states.has(this.context.connection.connectionId)){const t=this._states.get(this.context.connection.connectionId);t==null||t.dispose(),this._states.delete(this.context.connection.connectionId)}});r(this,"onOtherUserJoinedRoom",t=>{const e=t.userId;this._states.has(e)||(nc&&console.log("XRSync: Remote user joined room",e),this._states.set(e,new Rf(e,this.context)))});r(this,"onOtherUserLeftRoom",t=>{const e=t.userId;if(!this._states.has(e)){const i=this._states.get(e);i==null||i.dispose(),this._states.delete(e)}});r(this,"_states",new Map);this.context=t,this.context.connection.beginListen(J.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(J.LeftRoom,this.onLeftRoom),this.context.connection.beginListen(J.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.beginListen(J.UserLeftRoom,this.onOtherUserLeftRoom)}hasState(t){return t?this._states.has(t):!1}isTracking(t,e){if(!t)return;const i=this._states.get(t);if(!i)return;const n=i.controllerStates.find(o=>o.handedness===e);return(n==null?void 0:n.isTracking)||!1}getDeviceType(t,e){if(!t)return;const i=this._states.get(t);if(!i)return;const n=i.controllerStates.find(o=>o.handedness===e);return(n==null?void 0:n.type)||"unknown"}destroy(){this.context.connection.stopListen(J.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(J.LeftRoom,this.onLeftRoom),this.context.connection.stopListen(J.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.stopListen(J.UserLeftRoom,this.onOtherUserLeftRoom)}onUpdate(t){if(this.context.connection.isConnected&&this.context.connection.connectionId){const e=this._states.get(this.context.connection.connectionId);e==null||e.update(t)}}onExitXR(t){if(this.context.connection.isConnected&&this.context.connection.connectionId){const e=this._states.get(this.context.connection.connectionId);e==null||e.onExitXR(t)}}}class ty{constructor(){r(this,"_fadeToColorQuad");r(this,"_fadeToColorMaterial");r(this,"_requestedFadeValue",0);r(this,"_transitionPromise",null);r(this,"_transitionResolve",null);this._fadeToColorMaterial=new h.MeshBasicMaterial({color:0,transparent:!0,depthTest:!1,fog:!1,side:h.DoubleSide}),this._fadeToColorQuad=new h.Mesh(new h.PlaneGeometry(10,10),this._fadeToColorMaterial)}dispose(){this._fadeToColorQuad.geometry.dispose(),this._fadeToColorMaterial.dispose()}update(t,e){const i=this._fadeToColorQuad,n=this._fadeToColorMaterial;i.parent!==t&&n.opacity>0?t.add(i):n.opacity===0&&i.removeFromParent(),i.layers.set(2),i.material=this._fadeToColorMaterial,i.position.z=-1,i.renderOrder=1/0;const o=this._requestedFadeValue;n.opacity=z.lerp(n.opacity,o,e/.03),Math.abs(n.opacity-o)<=.01&&this._transitionResolve&&(this._transitionResolve(),this._transitionResolve=null,this._transitionPromise=null,this._requestedFadeValue=0)}remove(){this._fadeToColorQuad.removeFromParent()}fadeTransition(){if(this._transitionPromise)return this._transitionPromise;this._requestedFadeValue=1;const t=new Promise(e=>{this._transitionResolve=e});return this._transitionPromise=t,t}}var mr=(s=>(s[s.Quad=0]="Quad",s[s.Cube=1]="Cube",s[s.Sphere=2]="Sphere",s[s.RoundedCube=10]="RoundedCube",s))(mr||{}),Uc,Zp;class bo{static createText(t,e){let i=null;const n=(e==null?void 0:e.font)||JS((e==null?void 0:e.familyFamily)||null);n instanceof Y.Font?i=Fo(this,Uc,Zp).call(this,t,n,e):i==null&&(i=new h.BufferGeometry);const o=(e==null?void 0:e.color)||16777215,a=new h.Mesh(i,(e==null?void 0:e.material)??new h.MeshStandardMaterial({color:o}));return this.applyDefaultObjectOptions(a,e),n instanceof Promise?n.then(l=>{a.geometry=Fo(this,Uc,Zp).call(this,t,l,e),e!=null&&e.onGeometry&&e.onGeometry(a)}):e!=null&&e.onGeometry&&e.onGeometry(a),a}static createOccluder(t){const e=new h.MeshBasicMaterial({colorWrite:!1,depthWrite:!0,side:h.DoubleSide});return this.createPrimitive(t,{material:e})}static createPrimitive(t,e){let i;const n=(e==null?void 0:e.color)||16777215;switch(t){case"Quad":case 0:{const o=new h.PlaneGeometry(1,1,1,1),a=(e==null?void 0:e.material)??new h.MeshStandardMaterial({color:n});e!=null&&e.texture&&"map"in a&&(a.map=e.texture),i=new h.Mesh(o,a),i.name="Quad"}break;case"Cube":case 1:{const o=new h.BoxGeometry(1,1,1),a=(e==null?void 0:e.material)??new h.MeshStandardMaterial({color:n});e!=null&&e.texture&&"map"in a&&(a.map=e.texture),i=new h.Mesh(o,a),i.name="Cube"}break;case 10:case"RoundedCube":{const o=ZS(1,1,1,.1,2),a=(e==null?void 0:e.material)??new h.MeshStandardMaterial({color:n});e!=null&&e.texture&&"map"in a&&(a.map=e.texture),i=new h.Mesh(o,a),i.name="RoundedCube"}break;case"Sphere":case 2:{const o=new h.SphereGeometry(.5,16,16),a=(e==null?void 0:e.material)??new h.MeshStandardMaterial({color:n});e!=null&&e.texture&&"map"in a&&(a.map=e.texture),i=new h.Mesh(o,a),i.name="Sphere"}break;case"ShaderBall":i=new h.Group,i.name="ShaderBall",eC(i,e);break}return this.applyDefaultObjectOptions(i,e),i}static createSprite(t){const i=new h.SpriteMaterial({color:16777215});t!=null&&t.texture&&"map"in i&&(i.map=t.texture);const n=new h.Sprite(i);return this.applyDefaultObjectOptions(n,t),n}static applyDefaultObjectOptions(t,e){t.receiveShadow=!0,t.castShadow=!0,e!=null&&e.name&&(t.name=e.name),e!=null&&e.position&&(Array.isArray(e.position)?t.position.set(e.position[0],e.position[1],e.position[2]):t.position.set(e.position.x,e.position.y,e.position.z)),e!=null&&e.rotation&&(Array.isArray(e.rotation)?t.rotation.set(e.rotation[0],e.rotation[1],e.rotation[2]):t.rotation.set(e.rotation.x,e.rotation.y,e.rotation.z)),e!=null&&e.scale&&(typeof e.scale=="number"?t.scale.set(e.scale,e.scale,e.scale):t.scale.set(e.scale.x,e.scale.y,e.scale.z)),(e==null?void 0:e.receiveShadow)!=null&&(t.receiveShadow=e.receiveShadow),(e==null?void 0:e.castShadow)!=null&&(t.castShadow=e.castShadow),e!=null&&e.parent&&e.parent.add(t)}}Uc=new WeakSet,Zp=function(t,e,i){const n=(i==null?void 0:i.depth)||.1;return new Y.TextGeometry(t,{font:e,size:1,depth:n,height:n,bevelEnabled:(i==null?void 0:i.bevel)||!1,bevelThickness:.01,bevelOffset:.01,bevelSize:.01})},di(bo,Uc);function ZS(s,t,e,i,n){const o=new h.Shape,a=1e-5,l=i-a;o.absarc(a,a,a,-Math.PI/2,-Math.PI,!0),o.absarc(a,t-l*2,a,Math.PI,Math.PI/2,!0),o.absarc(s-l*2,t-l*2,a,Math.PI/2,0,!0),o.absarc(s-l*2,a,a,0,-Math.PI/2,!0);const c=new h.ExtrudeGeometry(o,{bevelEnabled:!0,bevelSegments:n*2,steps:1,bevelSize:l,bevelThickness:i,curveSegments:n});return c.scale(1,1,1-i),c.center(),c.computeVertexNormals(),c}const Vh=new Map;function JS(s){let t="";switch(s){default:case"OpenSans":t="https://cdn.needle.tools/static/fonts/facetype/Open Sans_Regular_ascii.json";break;case"Helvetiker":t="https://raw.githubusercontent.com/mrdoob/three.js/master/examples/fonts/helvetiker_regular.typeface.json";break}if(Vh.has(t)){const n=Vh.get(t);if(n)return n}const e=new Y.FontLoader,i=new Promise((n,o)=>{e.load(t,a=>{Vh.set(t,a),n(a)},void 0,o)});return Vh.set(t,i),i}let kf=!1,Tf=null;function eC(s,t){if(Tf===null){const e="https://cdn.needle.tools/static/models/shaderball.glb",i=new Y.GLTFLoader,n=re.createLoaders(null);i.setDRACOLoader(n.dracoLoader),i.setKTX2Loader(n.ktx2Loader),kf=!0,Tf=i.loadAsync(e).then(o=>{const a=o.scene;return a.position.y-=.5,a}).catch(o=>(console.warn("Failed to load shaderball mesh: "+o.message),ny())).finally(()=>{kf=!1})}if(kf){const e=ny();e.name="ShaderBall-Placeholder";const i=e.children[0];(i==null?void 0:i.type)==="Mesh"&&iy(i,t),s.add(e)}Tf.then(e=>{s.children.forEach(o=>{o.name==="ShaderBall-Placeholder"&&s.remove(o)});const i=e.clone(),n=i.children[0];(n==null?void 0:n.type)==="Mesh"&&iy(n,t),s.add(i)})}function iy(s,t){var i;if((t==null?void 0:t.color)||(t==null?void 0:t.material)||(t==null?void 0:t.texture)){const n=(t==null?void 0:t.material)??((i=s.material)==null?void 0:i.clone())??new h.MeshStandardMaterial;t.color&&"color"in n&&n.color instanceof h.Color&&n.color.set(t.color),t!=null&&t.texture&&"map"in n&&(n.map=t.texture),s.material=n}}function ny(){return new h.Group().add(bo.createPrimitive("Sphere",{material:new h.MeshBasicMaterial({transparent:!0,opacity:.1})}))}const C_=class{constructor(t,e,i){r(this,"_session");r(this,"_mode");r(this,"_init");r(this,"_renderer");r(this,"_camera");r(this,"_scene");r(this,"onEnd",()=>{var t;(t=this._session)==null||t.removeEventListener("end",this.onEnd),this._renderer.setAnimationLoop(null),this._renderer.dispose(),this._scene.clear()});r(this,"_lastTime",0);r(this,"onFrame",(t,e)=>{const i=t-this._lastTime;this.update(t,i),this._camera.parent!==this._scene&&this._scene.add(this._camera),this._renderer.render(this._scene,this._camera)});r(this,"_objects",[]);this._mode=t,this._init=e,this._session=i,this._session.addEventListener("end",this.onEnd),this._renderer=new h.WebGLRenderer({alpha:!0}),this._renderer.setAnimationLoop(this.onFrame),this._renderer.xr.setSession(i),this._renderer.xr.enabled=!0,this._camera=new h.PerspectiveCamera,this._scene=new h.Scene,this._scene.fog=new h.Fog(4473924,10,250),this._scene.add(this._camera),this.setupScene()}static get active(){return this._active}static async start(t,e){if(this._active)return console.error("Cannot start a new XR session while one is already active"),null;if(this._requestInFlight)return console.error("Cannot start a new XR session while a request is already in flight"),null;if("xr"in navigator&&navigator.xr){if(!e)return console.error("XRSessionInit must be provided"),null;this._requestInFlight=!0;const i=await navigator.xr.requestSession(t,e);return i.addEventListener("end",()=>{this._active=null}),this._requestInFlight?(this._requestInFlight=!1,this._active=new C_(t,e,i),this._active):(i.end(),null)}return null}static async handoff(){return this._active?this._active.handoff():null}static async stop(){this._requestInFlight=!1,this._active&&(await this._active.end(),await fn(100)),this._active=null}get isAR(){return this._mode==="immersive-ar"}end(){return this._session?this._session.end():Promise.resolve()}async handoff(){if(!this._session)throw new Error("Cannot handoff a session that has already ended");const t={session:this._session,mode:this._mode,init:this._init};return await this.onBeforeHandoff(),this.onEnd(),this._session=null,t}async onBeforeHandoff(){await fn(1e3),this._scene.clear()}setupScene(){this._scene.background=new h.Color(0),this._scene.add(new h.GridHelper(5,10,1118481,1118481));const t=new h.DirectionalLight(16777215,1);t.position.set(0,20,0),t.castShadow=!1,this._scene.add(t);const e=new h.DirectionalLight(16777215,1);e.position.set(0,-1,0),e.castShadow=!1,this._scene.add(e);const i=new h.PointLight(16777215,1,100,1);i.position.set(0,2,0),i.castShadow=!1,i.distance=200,this._scene.add(i);const n=50;for(let o=0;o<100;o++){const a=new h.MeshStandardMaterial({color:2236962,metalness:1,roughness:.8});this.isAR&&(a.emissive=new h.Color(Math.random(),Math.random(),Math.random()),a.emissiveIntensity=Math.random());const l=z.random(0,1)>.5?mr.Sphere:mr.Cube,c=bo.createPrimitive(l,{material:a});c.position.x=z.random(-n,n),c.position.y=z.random(-2,n),c.position.z=z.random(-n,n),c.rotation.x=z.random(0,Math.PI*2),c.rotation.y=z.random(0,Math.PI*2),c.rotation.z=z.random(0,Math.PI*2),c.scale.multiplyScalar(.5+Math.random()*10);const d=c.position.distanceTo(this._camera.position)-c.scale.x;d<1&&c.position.multiplyScalar(1+1/d),this._objects.push(c),this._scene.add(c)}}update(t,e){const i=t*4e-4;for(let n=0;n<this._objects.length;n++){const o=this._objects[n];o.position.y+=Math.sin(i+n*.5)*.005,o.rotateY(.002)}}};let Zs=C_;r(Zs,"_active",null),r(Zs,"_requestInFlight",!1);var Pc;(s=>{const t=[];function e(){if(!(t!=null&&t.length))return!1;for(const o of t)o.exportAndOpen();return!0}s.exportAndOpen=e;function i(o){t.push(o)}s.registerExporter=i;function n(o){if(!t)return;const a=t.indexOf(o);a>=0&&t.splice(a,1)}s.unregisterExporter=n})(Pc||(Pc={}));const sy="NeedleXRSession onStart",oy="NeedleXRSession onEnd",rt=S("debugwebxr"),ry=S("stats");let Ef=0;function tC(s){let t=null;const e=s;return e.getAROverlayContainer?t=e.getAROverlayContainer():t=s,t}iC();async function iC(){var s;if(S("debugasap")){let t=globalThis["needle:XRSession"];if(t instanceof Promise){delete globalThis["needle:XRSession"],ce.addContextCreatedCallback(async e=>{if(!t)return;nr(!0);const i=await t;if(i){const n=q.getDefaultSessionInit("immersive-vr");q.setSession("immersive-vr",i,n,e.context)}else console.error("NeedleXRSession: ASAP session was rejected");t=void 0});return}}if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent)){console.warn("WebXRViewer does not support addEventListener");return}(s=navigator.xr)==null||s.addEventListener("sessiongranted",async()=>{nr(!0),console.log("Received Session Granted..."),await fn(100);const t=sessionStorage.getItem("needle_xr_session_mode"),e=sessionStorage.getItem("needle_xr_session_init")??null,i=e?JSON.parse(e):null;let n=null;if(Mv()&&(await Zs.start(t||"immersive-vr",i||q.getDefaultSessionInit("immersive-vr")),await oC(),n=await Zs.handoff()),n)q.setSession(n.mode,n.session,n.init,Q.Current);else if(t&&e){console.log("Session Granted: Restore last session");const o=JSON.parse(e);q.start(t,o).catch(a=>console.warn(a))}else q.start("immersive-vr").catch(o=>console.warn("Session Granted failed:",o))},{once:!0})}}function nC(s,t){sessionStorage.setItem("needle_xr_session_mode",s),sessionStorage.setItem("needle_xr_session_init",JSON.stringify(t))}function sC(){sessionStorage.removeItem("needle_xr_session_mode"),sessionStorage.removeItem("needle_xr_session_init")}const ig=new Set;ce.registerCallback(de.ContextCreationStart,async s=>{ig.add(s.context)});ce.registerCallback(de.ContextCreated,async s=>{ig.delete(s.context)});function Mv(){return ig.size>0}function oC(){return new Promise(s=>{const t=Date.now(),e=setInterval(()=>{(!Mv()||Date.now()-t>6e4)&&(clearInterval(e),s())},100)})}exports.DeviceUtilities.isDesktop()&&B()&&window.addEventListener("keydown",s=>{(s.key==="x"||s.key==="Escape")&&q.active&&q.stop()});const hs=class{constructor(t,e,i,n){r(this,"context");r(this,"session");r(this,"mode");r(this,"controllers",[]);r(this,"_rigScale",1);r(this,"_lastRigScaleUpdate",-1);r(this,"_rigs",[]);r(this,"_viewerHitTestSource",null);r(this,"_defaultRig");r(this,"_xr_scripts");r(this,"_xr_update_scripts",[]);r(this,"_inactive_scripts",[]);r(this,"_controllerAdded");r(this,"_controllerRemoved");r(this,"_originalCameraWorldPosition");r(this,"_originalCameraWorldRotation");r(this,"_originalCameraWorldScale");r(this,"_originalCameraParent");r(this,"_mainCamera",null);r(this,"onRendererSessionSet",()=>{var t;this.running&&(this.context.renderer.xr.enabled=!0,this.context.renderer.xr.updateCamera(this.context.mainCamera),(t=this.context.mainCameraComponent)==null||t.applyClearFlags())});r(this,"onInputSourceAdded",t=>{if(t.targetRayMode==="screen")return;let e=0;for(let n=0;n<this.session.inputSources.length;n++)if(this.session.inputSources[n]===t){e=n;break}if(this.controllers.find(n=>n.inputSource===t)){console.debug("Controller already exists for input source",e);return}else if(this._newControllers.find(n=>n.inputSource===t)){console.debug("Controller already registered for input source",e);return}const i=new Km(this,t,e);this._newControllers.push(i)});r(this,"_ended",!1);r(this,"_newControllers",[]);r(this,"onEnd",t=>{var o,a,l;if(this._ended)return;this._ended=!0,console.debug("XR Session ended"),sC(),this.onAfterRender(),this.revertCustomForward(),this._didStart=!1,this._previousCameraParent=null,yo(this.onBefore,ve.LateUpdate);const e=this.context.pre_render_callbacks.indexOf(this.onBeforeRender);e>=0&&this.context.pre_render_callbacks.splice(e,1);const i=this.context.post_render_callbacks.indexOf(this.onAfterRender);i>=0&&this.context.post_render_callbacks.splice(i,1),this.context.xr=null,this.context.renderer.xr.enabled=!1,this.context.pre_update_oneshot_callbacks.push(()=>{var c,d;(c=this.context.mainCameraComponent)==null||c.applyClearFlags(),(d=this.context.mainCameraComponent)==null||d.applyClippingPlane()}),gv({session:this});for(const c of hs._xrEndListeners)c({xr:this});const n=[...this.controllers];for(let c=0;c<n.length;c++)this.disconnectInputSource(n[c].inputSource);this._newControllers.length=0,this.controllers.length=0;for(const c of this._xr_scripts)(o=c==null?void 0:c.onLeaveXR)==null||o.call(c,{xr:this});(a=this.sync)==null||a.onExitXR(this),this.context.mainCamera&&((l=this._originalCameraParent)==null||l.add(this.context.mainCamera),this._originalCameraWorldPosition&&nt(this.context.mainCamera,this._originalCameraWorldPosition),this._originalCameraWorldRotation&&Hi(this.context.mainCamera,this._originalCameraWorldRotation),this._originalCameraWorldScale&&Ia(this.context.mainCamera,this._originalCameraWorldScale)),this.context.requestSizeUpdate(),this._defaultRig.gameObject.removeFromParent(),nr(!1),performance.mark(oy),performance.measure("NeedleXRSession",sy,oy)});r(this,"_didStart",!1);r(this,"onBefore",t=>{var n,o,a,l,c,d,u,f;const e=t.xrFrame;if(!e)return;performance.mark("NeedleXRSession onBefore start"),this.context.xr=this,this.context.mainCameraComponent&&this.context.mainCameraComponent!==this._mainCamera&&(this._mainCamera=this.context.mainCameraComponent),((n=this.rig)==null?void 0:n.isActive)==!1&&(rt&&console.warn("Latest rig is not active - trying to activate a different rig",this.rig),this.updateActiveXRRig()),this.rig&&((o=this._mainCamera)!=null&&o.gameObject)&&((l=(a=this._mainCamera)==null?void 0:a.gameObject)==null?void 0:l.parent)!==this.rig.gameObject&&this.rig.gameObject.add((c=this._mainCamera)==null?void 0:c.gameObject),this.internalUpdateState(),this.applyCustomForward();const i={xr:this};if(this._didStart){if(this.context.new_scripts_xr.length>0){const m=[...this.context.new_scripts_xr];for(let g=0;g<m.length;g++){const _=this.context.new_scripts_xr[g];if(!_||_.destroyed||((d=_.supportsXR)==null?void 0:d.call(_,this.mode))==!1){this.context.new_scripts_xr.splice(g,1);continue}if(!_.activeAndEnabled){this.context.new_scripts_xr.splice(g,1),this.markInactive(_);continue}if(this.addScript(_)){this.invokeCallback_EnterXR(_);for(const y of this.controllers)this.invokeCallback_ControllerAdded(_,y)}}}}else{if(this._didStart=!0,this.mode==="immersive-vr"){const g=ri(this.context.scene.children);if(g){const _=g.getSize($());if(_.length()>0){const y=this._defaultRig.gameObject;y.position.set(g.min.x+_.x*.5,g.min.y,g.max.z+_.z*.5+1.5);const b=g.getCenter($());b.y=y.position.y,y.lookAt(b)}}}mv({session:this});for(const g of hs._xrStartListeners)g(i);const m=[...this._xr_scripts];rt&&console.log("NeedleXRSession start, handle scripts:",m);for(const g of m){if(g.destroyed){this._script_to_remove.push(g);continue}if(!g.activeAndEnabled){this.markInactive(g);continue}this.invokeCallback_EnterXR(g);for(const _ of this.controllers)this.invokeCallback_ControllerAdded(g,_)}}this.syncCameraCullingMask();for(const m of this.controllers)m.onUpdate(e);if(this._newControllers.length>0){const m=[...this._newControllers];this._newControllers.length=0;for(const g of m){if(!g.connected){console.warn("New controller is not connected",g);continue}this.controllers.push(g);for(const _ of this._xr_scripts){if(_.destroyed){this._script_to_remove.push(_);continue}_.activeAndEnabled!==!1&&this.invokeCallback_ControllerAdded(_,g)}}this.controllers.sort((g,_)=>g.index-_.index)}rt&&this.context.time.frame%30===0&&this.controllers.length<=0&&this.session.inputSources.length>0&&(nr(!0),console.error("XRControllers are not added but inputSources are present")),performance.mark("NeedleXRSession update scripts start");for(const m of this._xr_update_scripts){if(m.destroyed===!0){this._script_to_remove.push(m);continue}if(m.activeAndEnabled===!1){this.markInactive(m);continue}m.onUpdateXR&&m.onUpdateXR(i)}if(performance.mark("NeedleXRSession update scripts end"),performance.measure("NeedleXRSession update scripts","NeedleXRSession update scripts start","NeedleXRSession update scripts end"),this.handleInactiveScripts(),this._script_to_remove.length>0){const m=[...new Set(this._script_to_remove)];this._script_to_remove.length=0;for(const g of m)!g.destroyed&&this.running&&((u=g.onLeaveXR)==null||u.call(g,i)),this.removeScript(g)}(f=this.sync)==null||f.onUpdate(this),this.onRenderDebug(),performance.mark("NeedleXRSession onBefore end"),performance.measure("NE XR frame","NeedleXRSession onBefore start","NeedleXRSession onBefore end")});r(this,"onBeforeRender",()=>{this.context.mainCamera&&this.updateFade(this.context.mainCamera)});r(this,"onAfterRender",()=>{if(this.onUpdateFade_PostRender(),exports.DeviceUtilities.isDesktop()||!this._renderOnceOnDevice){const t=this.context.renderer;if(t.xr.isPresenting&&this.context.mainCamera){this._renderOnceOnDevice=!0;const e=t.xr.enabled,i=t.getRenderTarget(),n=this.context.scene.background;t.xr.enabled=!1,t.setRenderTarget(null),this.isPassThrough&&(this.context.scene.background=null),this.context.composer?this.context.composer.render(this.context.time.deltaTime):t.render(this.context.scene,this.context.mainCamera),t.xr.enabled=e,t.setRenderTarget(i),this.context.scene.background=n}}});r(this,"_script_to_remove",[]);r(this,"_camera");r(this,"_cameraRenderParent",new h.Object3D().rotateY(Math.PI));r(this,"_previousCameraParent");r(this,"_customforward",!0);r(this,"originalCameraNearPlane");r(this,"_viewerPose");r(this,"_transformOrientation",new h.Quaternion);r(this,"_transformPosition",new h.Vector3);r(this,"_transition");var o,a;performance.mark(sy),nC(t,n.init),this.session=e,this.mode=t,this.context=i,(rt||S("console"))&&nr(!0),this._xr_scripts=[...n.scripts],this._xr_update_scripts=this._xr_scripts.filter(l=>typeof l.onUpdateXR=="function"),this._controllerAdded=n.controller_added,this._controllerRemoved=n.controller_removed,Os(this.onBefore,ve.LateUpdate),this.context.pre_render_callbacks.push(this.onBeforeRender),this.context.post_render_callbacks.push(this.onAfterRender),((o=n.init.optionalFeatures)!=null&&o.includes("hit-test")||(a=n.init.requiredFeatures)!=null&&a.includes("hit-test"))&&e.requestReferenceSpace("viewer").then(l=>{var c,d;return(d=(c=e.requestHitTestSource)==null?void 0:c.call(e,{space:l}))==null?void 0:d.then(u=>this._viewerHitTestSource=u).catch(u=>console.error(u))}).catch(l=>console.error(l)),this.context.mainCamera&&(this._originalCameraWorldPosition=Z(this.context.mainCamera,new h.Vector3),this._originalCameraWorldRotation=ye(this.context.mainCamera,new h.Quaternion),this._originalCameraWorldScale=Ne(this.context.mainCamera,new h.Vector3),this._originalCameraParent=this.context.mainCamera.parent),this._defaultRig=new zS,this.context.scene.add(this._defaultRig.gameObject),this.addRig(this._defaultRig);for(let l=0;l<e.inputSources.length;l++){const c=e.inputSources[l];if(!c.handedness){console.warn("Input source in xr session has no handedness - ignoring",l);continue}this.onInputSourceAdded(c)}this.session.addEventListener("end",this.onEnd),this.session.addEventListener("inputsourceschange",l=>{for(const c of l.removed)this.disconnectInputSource(c);for(const c of l.added)this.onInputSourceAdded(c)}),this.context.xr=this,this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet),"controllerAutoUpdate"in this.context.renderer.xr?(console.debug("Disabling three.js controllerAutoUpdate"),this.context.renderer.xr.controllerAutoUpdate=!1):rt&&console.warn("controllerAutoUpdate is not available in three.js - cannot disable it")}static getXRSync(t){return this._sync||(this._sync=new Ov(t)),this._sync}static get currentSessionRequest(){return this._currentSessionRequestMode}static get active(){return this._activeSession}static get activeMode(){var t;return((t=this._activeSession)==null?void 0:t.mode)??null}static get xrSystem(){return"xr"in navigator?navigator.xr:void 0}static isXRSupported(){return Promise.all([this.isVRSupported(),this.isARSupported()]).then(t=>t.some(e=>e)).catch(()=>!1)}static isVRSupported(){return this.isSessionSupported("immersive-vr")}static isARSupported(){return this.isSessionSupported("immersive-ar")}static isSessionSupported(t){var e;return((e=this.xrSystem)==null?void 0:e.isSessionSupported(t).catch(i=>(rt&&console.error(i),!1)))??Promise.resolve(!1)}static onSessionRequestStart(t){this._sessionRequestStartListeners.push(t)}static offSessionRequestStart(t){const e=this._sessionRequestStartListeners.indexOf(t);e>=0&&this._sessionRequestStartListeners.splice(e,1)}static onSessionRequestEnd(t){this._sessionRequestEndListeners.push(t)}static offSessionRequestEnd(t){const e=this._sessionRequestEndListeners.indexOf(t);e>=0&&this._sessionRequestEndListeners.splice(e,1)}static onXRSessionStart(t){this._xrStartListeners.push(t)}static offXRSessionStart(t){const e=this._xrStartListeners.indexOf(t);e>=0&&this._xrStartListeners.splice(e,1)}static onXRSessionEnd(t){this._xrEndListeners.push(t)}static offXRSessionEnd(t){const e=this._xrEndListeners.indexOf(t);e>=0&&this._xrEndListeners.splice(e,1)}static onControllerAdded(t){this._controllerAddedListeners.push(t)}static offControllerAdded(t){const e=this._controllerAddedListeners.indexOf(t);e>=0&&this._controllerAddedListeners.splice(e,1)}static onControllerRemoved(t){this._controllerRemovedListeners.push(t)}static offControllerRemoved(t){const e=this._controllerRemovedListeners.indexOf(t);e>=0&&this._controllerRemovedListeners.splice(e,1)}static offerSession(t,e,i){return"xr"in navigator&&navigator.xr&&"offerSession"in navigator.xr?(typeof navigator.xr.offerSession=="function"&&(console.log("WebXR offerSession is available - requesting mode: "+t),e=="default"&&(e=this.getDefaultSessionInit(t)),navigator.xr.offerSession(t,{...e}).then(n=>hs.setSession(t,n,e,i)).catch(n=>{console.log("XRSession offer rejected (perhaps because another call to offerSession was made or a call to requestSession was made)")})),!0):!1}static getDefaultSessionInit(t){switch(t){case"immersive-ar":const e=["anchors","local-floor","layers","dom-overlay","hit-test","unbounded"];return exports.DeviceUtilities.isVisionOS()||e.push("hand-tracking"),{optionalFeatures:e};case"immersive-vr":const i=["local-floor","bounded-floor","high-fixed-foveation-level","layers"];return exports.DeviceUtilities.isVisionOS()||i.push("hand-tracking"),{optionalFeatures:i};default:return console.warn("No default session init for mode",t),{}}}static async start(t,e,i){var l,c,d,u;if(exports.DeviceUtilities.isiOS()){if(t==="ar")if(await this.isARSupported())t="immersive-ar";else return Pc.exportAndOpen(),null}else t=="ar"&&(t="immersive-ar");if(B()&&S("debugxrpreroom"))return console.warn("Debug: Starting temporary XR session"),await Zs.start(t,e||hs.getDefaultSessionInit(t)),null;if(this._currentSessionRequest)return console.warn("A XRSession is already being requested"),(rt||B())&&me("A XRSession is already being requested"),this._currentSessionRequest.then(()=>this._activeSession);if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;if(i||(i=Q.Current),i||(i=ce.All[0]),!i)throw new Error("No Needle Engine Context found");switch(performance.mark("NeedleXRSession start"),e||(e={}),t){case"immersive-ar":{if(await((l=this.xrSystem)==null?void 0:l.isSessionSupported("immersive-ar"))!==!0)return console.error(t+" is not supported by this browser."),null;const m=this.getDefaultSessionInit(t),g=tC(i.domElement);g&&!exports.DeviceUtilities.isQuest()&&(m.domOverlay={root:g},m.optionalFeatures.push("dom-overlay")),e={...m,...e}}break;case"immersive-vr":{if(await((c=this.xrSystem)==null?void 0:c.isSessionSupported("immersive-vr"))!==!0)return console.error(t+" is not supported by this browser."),null;e={...this.getDefaultSessionInit(t),...e}}break;default:console.warn("No default session init for mode",t);break}e.optionalFeatures??(e.optionalFeatures=[]),e.requiredFeatures??(e.requiredFeatures=[]),await Zs.stop();const n=t=="immersive-ar"?i.scripts_immersive_ar:i.scripts_immersive_vr;rt?console.log(`%cRequesting ${t} session`,"font-weight:bold;",e,n):console.log(`%cRequesting ${t} session`,"font-weight:bold;");for(const f of n)f.onBeforeXR&&f.onBeforeXR(t,e);for(const f of this._sessionRequestStartListeners)f({mode:t,init:e});rt&&Ee("Requesting "+t+" session ("+Date.now()+")"),this._currentSessionRequest=(d=navigator.xr)==null?void 0:d.requestSession(t,e),this._currentSessionRequestMode=t;const o=await((u=this._currentSessionRequest)==null?void 0:u.catch(f=>{console.error(f,"Code: "+f.code),f.code===9&&me("Make sure your device has the required permissions (e.g. camera access)"),console.log("If the specified XR configuration is not supported (e.g. entering AR doesnt work) - make sure you access the website on a secure connection (HTTPS) and your device has the required permissions (e.g. camera access)"),location.protocol==="http:"&&me("XR requires a secure connection (HTTPS)")}));this._currentSessionRequest=void 0,this._currentSessionRequestMode=null;for(const f of this._sessionRequestEndListeners)f({mode:t,init:e,newSession:o||null});if(!o)return console.warn("XR Session request was rejected"),null;const a=this.setSession(t,o,e,i);return performance.mark("NeedleXRSession end"),performance.measure("NeedleXRSession Startup","NeedleXRSession start","NeedleXRSession end"),a}static setSession(t,e,i,n){if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;const o=t=="immersive-ar"?n.scripts_immersive_ar:n.scripts_immersive_vr;return this._activeSession=new hs(t,e,n,{scripts:o,controller_added:this._controllerAddedListeners,controller_removed:this._controllerRemovedListeners,init:i}),e.addEventListener("end",this.onEnd),rt?console.log(`%cStarted ${t} session`,"font-weight:bold;",o):console.log(`%cStarted ${t} session`,"font-weight:bold;"),this._activeSession}static stop(){var t;(t=this._activeSession)==null||t.end()}get sync(){return hs._sync}get running(){return!this._ended&&this.session!=null}get interactionMode(){return this.session.interactionMode}get visibilityState(){return this.session.visibilityState}get isVisibleBlurred(){return this.session.visibilityState==="visible-blurred"}get isSystemKeyboardSupported(){return this.session.isSystemKeyboardSupported}get environmentBlendMode(){return this.session.environmentBlendMode}get frame(){return this.context.xrFrame}get leftController(){return this.controllers.find(t=>t.side==="left")}get rightController(){return this.controllers.find(t=>t.side==="right")}getController(t){return typeof t=="number"?this.controllers[t]||null:this.controllers.find(e=>e.side===t)||null}get isPassThrough(){return!!(this.environmentBlendMode!=="opaque"&&this.interactionMode==="world-space"||this.mode==="immersive-ar"&&this.environmentBlendMode!=="opaque"&&this.controllers.some(t=>t.inputSource.targetRayMode==="tracked-pointer")||B()&&exports.DeviceUtilities.isDesktop()&&this.mode==="immersive-ar")}get isAR(){return this.mode==="immersive-ar"}get isVR(){return this.mode==="immersive-vr"}get isScreenBasedAR(){return this.isAR&&!this.isPassThrough}get posePosition(){return this._transformPosition}get poseOrientation(){return this._transformOrientation}get referenceSpace(){return this.context.renderer.xr.getReferenceSpace()}get viewerPose(){return this._viewerPose}get isTrackingImages(){if(this.frame&&"getImageTrackingResults"in this.frame&&typeof this.frame.getImageTrackingResults=="function")try{const t=this.frame.getImageTrackingResults();for(const e of t)if(e.trackingState==="tracked")return!0}catch{return!1}return!1}get rig(){const t=this._rigs[0]??null;return t!=null&&t.gameObject&&gr(t.gameObject)||(t==null?void 0:t.isActive)===!1?(this.updateActiveXRRig(),this._rigs[0]??null):t}get rigScale(){return this._rigs[0]?(this._lastRigScaleUpdate!==this.context.time.frame&&(this._lastRigScaleUpdate=this.context.time.frame,this._rigScale=this._rigs[0].gameObject.worldScale.x),this._rigScale):1}addRig(t){this._rigs.indexOf(t)>=0||(t.priority===void 0&&(t.priority=0),this._rigs.push(t),this.updateActiveXRRig())}removeRig(t){const e=this._rigs.indexOf(t);e!==-1&&(this._rigs.splice(e,1),this.updateActiveXRRig())}setRigActive(t){const e=this._rigs.indexOf(t),i=this._rigs[0];this._rigs.splice(e,1),this._rigs.unshift(t),t.priority=(i==null?void 0:i.priority)??0,this.updateActiveXRRig()}getUserOffsetInRig(){var i;const t=(i=this.context.mainCamera)==null?void 0:i.position;if(!t||!this.rig)return $(0,0,0);const e=$(t);return e.x*=-1,e.z*=-1,e.applyQuaternion(rn(this.rig.gameObject.quaternion)),e}updateActiveXRRig(){const t=this._rigs[0]??null;this._defaultRig.gameObject.parent!==this.context.scene&&this.context.scene.add(this._defaultRig.gameObject),this._defaultRig.gameObject.visible=!0,this._rigs.includes(this._defaultRig)||this._rigs.push(this._defaultRig);let e=this._rigs[0];e&&e.priority===void 0&&(e.priority=0);for(let i=1;i<this._rigs.length;i++){const n=this._rigs[i];if(n.isActive){if(gr(n.gameObject)){this._rigs.splice(i,1),i--;continue}(!e||e.isActive===!1||n.priority!==void 0&&n.priority>e.priority)&&(e=n)}}if(t!==e){const i=this._rigs.indexOf(e);i>=0&&this._rigs.splice(i,1),this._rigs.unshift(e)}rt&&(t===e?console.log("Updated Active XR Rig:",e,"prev:",t):console.log("Updated Active XRRig:",e," (the same as before)"))}getHitTest(t){if(t)return this.getControllerHitTest(t);if(!this._viewerHitTestSource)return null;const e=this._viewerHitTestSource,i=this.frame.getHitTestResults(e);if(i.length>0){const n=i[0];return this.convertHitTestResult(n)}return null}getControllerHitTest(t){const e=t.getHitTestSource();if(!e)return null;const i=this.frame.getHitTestResultsForTransientInput(e);for(const n of i)if(n.inputSource===t.inputSource)for(const o of n.results)return this.convertHitTestResult(o);return null}convertHitTestResult(t){const e=this.context.renderer.xr.getReferenceSpace(),i=e&&t.getPose(e);if(i){const n=$(i.transform.position),o=rn(i.transform.orientation),a=this.context.mainCamera;if((a==null?void 0:a.parent)!==this._cameraRenderParent&&n.applyMatrix4(Ca),a!=null&&a.parent){n.applyMatrix4(a.parent.matrixWorld),o.multiply(Bi);const l=ye(a.parent);l.premultiply(Bi),o.premultiply(l)}return{hit:t,position:n,quaternion:o}}return null}convertSpace(t){const e=$(t.position);e.applyMatrix4(Ca);const i=rn(t.orientation);return i.premultiply(Bi),{position:e,quaternion:i}}disconnectInputSource(t){const e=(i,n,o)=>{if(i.inputSource===t){rt&&console.log("Disconnecting controller",i.index),this.controllers.splice(o,1),this.invokeControllerEvent(i,this._controllerRemoved,"removed");const a={xr:this,controller:i,change:"removed"};for(const l of this._xr_scripts)l.onXRControllerRemoved&&l.onXRControllerRemoved(a);i.onDisconnected()}};for(let i=this.controllers.length-1;i>=0;i--){const n=this.controllers[i];e(n,this.controllers,i)}for(let i=this._newControllers.length-1;i>=0;i--){const n=this._newControllers[i];e(n,this._newControllers,i)}}end(){this._ended||this.session.end().catch(t=>console.warn(t))}onRenderDebug(){if(rt)for(const t of this.controllers)t.onRenderDebug();if((rt||ry)&&this.rig&&(Ef++,Ef>=20)){const t=this.rig.gameObject.worldPosition,e=this.rig.gameObject.worldForward;t.add(e.multiplyScalar(1.5));const i=this.rig.gameObject.worldUp;t.add(i.multiplyScalar(2.5));let n="";if(n+=`${this.context.time.smoothedFps.toFixed(0)} FPS`,n+=`, calls: ${this.context.renderer.info.render.calls}, tris: ${this.context.renderer.info.render.triangles.toLocaleString()}`,rt||ry)for(const o of this.controllers)n+=`
154
154
  ${o.hand?"hand":"ctrl"} ${o.inputSource.handedness}[${o.index}] con:${o.connected} tr:${o.isTracking} hts:${o.hasHitTestSource?"yes":"no"}`;Ef=0,N.DrawLabel(t,n,void 0,1/60*20)}}addScript(t){return this._xr_scripts.includes(t)?!1:(rt&&console.log("Register new XRScript",t),this._xr_scripts.push(t),typeof t.onUpdateXR=="function"&&this._xr_update_scripts.push(t),!0)}markInactive(t){if(!(this._inactive_scripts.indexOf(t)>=0)){this.removeScript(t,!1),this._inactive_scripts.push(t);for(const e of this.controllers)this.invokeCallback_ControllerRemoved(t,e);this.invokeCallback_LeaveXR(t)}}handleInactiveScripts(){if(this._inactive_scripts.length>0)for(let t=this._inactive_scripts.length-1;t>=0;t--){const e=this._inactive_scripts[t];if(e.activeAndEnabled){this._inactive_scripts.splice(t,1),this.addScript(e),this.invokeCallback_EnterXR(e);for(const i of this.controllers)this.invokeCallback_ControllerAdded(e,i)}}}removeScript(t,e=!0){rt&&console.log("Remove XRScript",t);const i=this._xr_scripts.indexOf(t);i>=0&&this._xr_scripts.splice(i,1);const n=this._xr_update_scripts.indexOf(t);if(n>=0&&this._xr_update_scripts.splice(n,1),e){const o=this._inactive_scripts.indexOf(t);o>=0&&this._inactive_scripts.splice(o,1)}}invokeCallback_EnterXR(t){t.onEnterXR&&t.onEnterXR({xr:this})}invokeCallback_ControllerAdded(t,e){t.onXRControllerAdded&&t.onXRControllerAdded({xr:this,controller:e,change:"added"})}invokeCallback_ControllerRemoved(t,e){t.onXRControllerRemoved&&t.onXRControllerRemoved({xr:this,controller:e,change:"removed"})}invokeCallback_LeaveXR(t){t.onLeaveXR&&!t.destroyed&&t.onLeaveXR({xr:this})}syncCameraCullingMask(){var i;const t=this.context.xrCamera,e=(i=this.context.mainCameraComponent)==null?void 0:i.cullingMask;if(t&&e!==void 0){for(const n of t.cameras)n.layers.mask=e;t.layers.mask=e}else if(t){for(const n of t.cameras)n.layers.enableAll();t.layers.enableAll()}}invokeControllerEvent(t,e,i){for(let n=e.length-1;n>=0;n--){const o=e[n];if(o)try{o({xr:this,controller:t,change:i})}catch(a){console.error(a)}}}applyCustomForward(){var t;if(this.context.mainCamera&&this._customforward){this._camera=this.context.mainCamera,this._camera.parent!==this._cameraRenderParent&&(this._previousCameraParent=this._camera.parent,(t=this._previousCameraParent)==null||t.add(this._cameraRenderParent)),this._cameraRenderParent.name="XR Camera Render Parent",this._cameraRenderParent.add(this._camera);let e=.02;if(this.rig){const i=Ne(this.rig.gameObject);e*=i.x}this._camera instanceof h.PerspectiveCamera&&this._camera.near>e&&(this.originalCameraNearPlane=this._camera.near,this._camera.near=e)}}revertCustomForward(){this._camera&&this._previousCameraParent&&this._previousCameraParent.add(this._camera),this._previousCameraParent=null,this._camera instanceof h.PerspectiveCamera&&this.originalCameraNearPlane!=null&&(this._camera.near=this.originalCameraNearPlane)}internalUpdateState(){const t=this.context.renderer.xr.getReferenceSpace();if(!t){this._viewerPose=void 0;return}if(this._viewerPose=this.frame.getViewerPose(t),this._viewerPose){const e=this._viewerPose.transform;this._transformPosition.set(e.position.x,e.position.y,e.position.z),this._transformOrientation.set(e.orientation.x,e.orientation.y,e.orientation.z,e.orientation.w)}}get transition(){return this._transition||(this._transition=new ty),this._transition}fadeTransition(){return this._transition||(this._transition=new ty),this._transition.fadeTransition()}updateFade(t){this._transition&&t instanceof h.PerspectiveCamera&&this._transition.update(t,this.context.time.deltaTime)}onUpdateFade_PostRender(){var t;(t=this._transition)==null||t.remove()}};let q=hs;r(q,"_sync",null),r(q,"_currentSessionRequestMode",null),r(q,"_currentSessionRequest"),r(q,"_activeSession"),r(q,"_sessionRequestStartListeners",[]),r(q,"_sessionRequestEndListeners",[]),r(q,"_xrStartListeners",[]),r(q,"_xrEndListeners",[]),r(q,"_controllerAddedListeners",[]),r(q,"_controllerRemovedListeners",[]),r(q,"onEnd",()=>{rt&&console.log("XR Session ended"),hs._activeSession=null});const Af=S("debugwebxr");class Rv{static tryFindAvatarObjects(t,e,i){if(i.head&&i.leftHand&&i.rightHand)return;const n=t.name.toLocaleLowerCase();!i.head&&n.includes("head")&&(Af&&console.log("FOUND AVATAR HEAD",t.name),i.head=new ee("",e,t)),n.includes("hand")&&(!i.leftHand&&n.includes("left")&&(Af&&console.log("FOUND AVATAR LEFT HAND",t.name),i.leftHand=new ee("",e,t)),!i.rightHand&&n.includes("right")&&(Af&&console.log("FOUND AVATAR RIGHT HAND",t.name),i.rightHand=new ee("",e,t)));for(let o=0;o<t.children.length;o++){if(i.head&&i.leftHand&&i.rightHand)return;const a=t.children[o];this.tryFindAvatarObjects(a,e,i)}}}const kt=new h.Vector3,ay=new h.Vector3,ly=new h.Quaternion,rC=S("debuggizmos"),Ji=8947848,Df=32,ji=class{constructor(){}static isGizmo(t){return t[Jp]!==void 0}static DrawLabel(t,e,i=.05,n=0,o,a,l){var u;if(!ji.enabled)return null;o||(o=Ji);const c=((u=q.active)==null?void 0:u.rigScale)??1,d=Se.getTextLabel(n,e,i*c,o,a);return l instanceof h.Object3D&&l.add(d),d.position.x=t.x,d.position.y=t.y,d.position.z=t.z,d}static DrawRay(t,e,i=Ji,n=0,o=!0){if(!ji.enabled)return;const a=Se.getLine(n),l=a.geometry.getAttribute("position");l.setXYZ(0,t.x,t.y,t.z),kt.set(e.x,e.y,e.z).multiplyScalar(999999999),l.setXYZ(1,t.x+kt.x,t.y+kt.y,t.z+kt.z),l.needsUpdate=!0,a.material.color.set(i),a.material.depthTest=o,a.material.depthWrite=!1}static DrawDirection(t,e,i=Ji,n=0,o=!0,a=1){if(!ji.enabled)return;const l=Se.getLine(n),c=l.geometry.getAttribute("position");c.setXYZ(0,t.x,t.y,t.z),e.w!==void 0?(kt.set(0,0,-a),ly.set(e.x,e.y,e.z,e.w),kt.applyQuaternion(ly)):(kt.set(e.x,e.y,e.z),kt.multiplyScalar(a)),c.setXYZ(1,t.x+kt.x,t.y+kt.y,t.z+kt.z),c.needsUpdate=!0,l.material.color.set(i),l.material.depthTest=o,l.material.depthWrite=!1}static DrawLine(t,e,i=Ji,n=0,o=!0){if(!ji.enabled)return;const a=Se.getLine(n),l=a.geometry.getAttribute("position");l.setXYZ(0,t.x,t.y,t.z),l.setXYZ(1,e.x,e.y,e.z),l.needsUpdate=!0,a.material.color.set(i),a.material.depthTest=o,a.material.depthWrite=!1,a.material.fog=!1}static DrawCircle(t,e,i,n=Ji,o=0,a=!0){if(!ji.enabled)return;const l=Se.getCircle(o);l.position.set(t.x,t.y,t.z),l.scale.set(i,i,i),l.quaternion.setFromUnitVectors(this._up,kt.set(e.x,e.y,e.z).normalize()),l.material.color.set(n),l.material.depthTest=a,l.material.depthWrite=!1,l.material.fog=!1}static DrawWireSphere(t,e,i=Ji,n=0,o=!0){if(!ji.enabled)return;const a=Se.getSphere(e,n,!0);pr(a,t.x,t.y,t.z),a.material.color.set(i),a.material.depthTest=o,a.material.depthWrite=!1,a.material.fog=!1}static DrawSphere(t,e,i=Ji,n=0,o=!0){if(!ji.enabled)return;const a=Se.getSphere(e,n,!1);pr(a,t.x,t.y,t.z),a.material.color.set(i),a.material.depthTest=o,a.material.depthWrite=!1}static DrawWireBox(t,e,i=Ji,n=0,o=!0){if(!ji.enabled)return;const a=Se.getBox(n);a.position.set(t.x,t.y,t.z),a.scale.set(e.x,e.y,e.z),a.material.color.set(i),a.material.depthTest=o,a.material.wireframe=!0,a.material.depthWrite=!1,a.material.fog=!1}static DrawWireBox3(t,e=Ji,i=0,n=!0){if(!ji.enabled)return;const o=Se.getBox(i);o.position.copy(t.getCenter(kt)),o.scale.copy(t.getSize(kt)),o.material.color.set(e),o.material.depthTest=n,o.material.wireframe=!0,o.material.depthWrite=!1,o.material.fog=!1}static DrawArrow(t,e,i=Ji,n=0,o=!0,a=!1){if(!ji.enabled)return;const l=Se.getArrowHead(n);l.position.set(e.x,e.y,e.z),l.quaternion.setFromUnitVectors(this._up.set(0,1,0),kt.set(e.x,e.y,e.z).sub(ay.set(t.x,t.y,t.z)).normalize());const d=kt.set(e.x,e.y,e.z).sub(ay.set(t.x,t.y,t.z)).length()*.1;l.scale.set(d,d,d),l.material.color.set(i),l.material.depthTest=o,l.material.wireframe=a,this.DrawLine(t,e,i,n,o)}static DrawWireMesh(t){const e=Se.getMesh(t.duration??0);"mesh"in t?(e.geometry=t.mesh.geometry,e.matrix.copy(t.mesh.matrixWorld)):(e.geometry=t.geometry,e.matrix.copy(t.matrix)),e.matrixAutoUpdate=!1,e.matrixWorldAutoUpdate=!1,e.material.color.set(t.color??Ji),e.material.depthTest=t.depthTest??!0,e.material.wireframe=!0}static setVisible(t){for(const e of Se.timedObjectsBuffer)e.visible=t}};let N=ji;r(N,"enabled",!0),r(N,"_up",new h.Vector3(0,1,0));const aC=new h.BoxGeometry(1,1,1);function ng(s=null){const t=new h.Color(s??14540253),e=new h.EdgesGeometry(aC);return new h.LineSegments(e,new h.LineBasicMaterial({color:t}))}const Jp=Symbol("GizmoCache");class Se{static ensureFont(){let t=ie.__webpack_exports__default.FontLibrary.getFontFamily(this.familyName);if(!t){t=ie.__webpack_exports__default.FontLibrary.addFontFamily(this.familyName);const e=t.addVariant("normal","normal","https://uploads.needle.tools/include/font-msdf.json","https://uploads.needle.tools/include/font.png");e==null||e.addEventListener("ready",()=>{ie.__webpack_exports__default.update()})}}static getTextLabel(t,e,i,n,o){this.ensureFont();let a=this.textLabelCache.pop(),l=1;o&&typeof o=="string"&&(o==null?void 0:o.length)>=8&&o.startsWith("#")?(l=parseInt(o.substring(7),16)/255,o=o.substring(0,7),rC&&console.log(o,l)):typeof o=="object"&&o.a!==void 0&&(l=o.a);const c={boxSizing:"border-box",fontFamily:this.familyName,width:"auto",fontSize:i,color:n,lineHeight:1,backgroundColor:o??void 0,backgroundOpacity:l,textContent:e,borderRadius:.5*i,padding:.8*i,whiteSpace:"pre",offset:.05*i};if(a)a.set(c);else{a=new ie.__webpack_exports__Text(c);const d=this,u=a;u.setText=function(f){this.set({textContent:f}),d.tmuiNeedsUpdate=!0}}return this.tmuiNeedsUpdate=!0,this.registerTimedObject(Q.Current,a,t,this.textLabelCache),a}static getBox(t){let e=this.boxesCache.pop();if(!e){const i=new h.BoxGeometry(1,1,1);e=new h.Mesh(i)}return this.registerTimedObject(Q.Current,e,t,this.boxesCache),e}static getLine(t){let e=this.linesCache.pop();if(!e){e=new h.Line;let i=e.geometry.getAttribute("position");i||(i=new h.BufferAttribute(new Float32Array(2*3),3),e.geometry.setAttribute("position",i))}return e.frustumCulled=!1,this.registerTimedObject(Q.Current,e,t,this.linesCache),e}static getCircle(t){let e=this.circlesCache.pop();if(!e){e=new h.Line;let i=e.geometry.getAttribute("position");if(!i){i=new h.BufferAttribute(new Float32Array(Df*3),3),e.geometry.setAttribute("position",i);const n=$(0,1,0),o=$(0,0,1),a=$(o);a.cross(n).normalize();const l=$(a),c=Math.PI*2/(Df-1);for(let d=0;d<Df+1;d++){const u=c*d;n.copy(l).multiplyScalar(Math.cos(u)*1),a.copy(o).multiplyScalar(Math.sin(u)*1);const f=n.add(a);i.setXYZ(d,f.x,f.y,f.z)}}}return e.frustumCulled=!1,this.registerTimedObject(Q.Current,e,t,this.circlesCache),e}static getSphere(t,e,i){let n=this.spheresCache.pop();return n||(n=new h.Mesh(new h.SphereGeometry(1,8,8))),n.scale.set(t,t,t),n.material.wireframe=i,this.registerTimedObject(Q.Current,n,e,this.spheresCache),n}static getArrowHead(t){let e=this.arrowHeadsCache.pop();return e||(e=new h.Mesh(new h.CylinderGeometry(0,.5,1,8))),this.registerTimedObject(Q.Current,e,t,this.arrowHeadsCache),e}static getMesh(t){let e=this.mesh.pop();return e||(e=new h.Mesh,e.material=new h.MeshBasicMaterial),this.registerTimedObject(Q.Current,e,t,this.mesh),e}static registerTimedObject(t,e,i,n){if(!t){console.error("No Needle Engine context available. Did you call a Gizmos function in global scope?");return}const o=this.contextBeforeRenderCallbacks.get(t),a=this.contextPostRenderCallbacks.get(t);if(o){if(t.pre_render_callbacks[t.pre_render_callbacks.length-1]!==o){const l=t.pre_render_callbacks.indexOf(o);l>=0&&t.pre_render_callbacks.splice(l,1),t.pre_render_callbacks.push(o)}}else{const l=()=>{this.onBeforeRender(t,this.timedObjectsBuffer)};this.contextBeforeRenderCallbacks.set(t,l),t.pre_render_callbacks.push(l)}if(a){if(t.post_render_callbacks[t.post_render_callbacks.length-1]!==a){const l=t.post_render_callbacks.indexOf(a);l>=0&&t.post_render_callbacks.splice(l,1),t.post_render_callbacks.push(a)}}else{const l=()=>{this.onPostRender(t,this.timedObjectsBuffer,this.timesBuffer)};this.contextPostRenderCallbacks.set(t,l),t.post_render_callbacks.push(l)}e.traverse(l=>{l.layers.disableAll(),l.layers.enable(2)}),e.renderOrder=999999,e[Jp]=n,e.castShadow=!1,e.receiveShadow=!1,e.isGizmo=!0,this.timedObjectsBuffer.push(e),this.timesBuffer.push(Q.Current.time.realtimeSinceStartup+i),t.scene.add(e)}static onBeforeRender(t,e){this.tmuiNeedsUpdate&&(this.tmuiNeedsUpdate=!1,ie.__webpack_exports__default.update());for(let i=0;i<e.length;i++){const n=e[i];if(t.mainCamera&&n instanceof ie.__webpack_exports__default.MeshUIBaseElement){if(gr(n))continue;const o=t.isInVR,a=!1,l=!o;Gc(n,t.mainCamera,a,l)}}}static onPostRender(t,e,i){const n=t.time.realtimeSinceStartup;for(let o=e.length-1;o>=0;o--){const a=e[o];n>=i[o]-1e-6&&(e.splice(o,1),i.splice(o,1),a.removeFromParent(),gr(a)!=!0&&a[Jp].push(a))}}}r(Se,"familyName","needle-gizmos"),r(Se,"linesCache",[]),r(Se,"circlesCache",[]),r(Se,"spheresCache",[]),r(Se,"boxesCache",[]),r(Se,"arrowHeadsCache",[]),r(Se,"mesh",[]),r(Se,"textLabelCache",[]),r(Se,"timedObjectsBuffer",new Array),r(Se,"timesBuffer",new Array),r(Se,"contextPostRenderCallbacks",new Map),r(Se,"contextBeforeRenderCallbacks",new Map),r(Se,"tmuiNeedsUpdate",!1);const _i=S("debugphysics"),cy=new h.Layers;class Nn{constructor(){r(this,"ray");r(this,"cam");r(this,"screenPoint");r(this,"raycaster");r(this,"results");r(this,"targets");r(this,"recursive",!0);r(this,"minDistance");r(this,"maxDistance");r(this,"lineThreshold");r(this,"layerMask");r(this,"ignore");r(this,"testObject");r(this,"useAcceleratedRaycast")}screenPointFromOffset(t,e){this.screenPoint===void 0&&(this.screenPoint=new h.Vector2),this.screenPoint.x=t/window.innerWidth*2-1,this.screenPoint.y=-(e/window.innerHeight)*2+1}setLayer(t){cy.set(t),this.layerMask=cy}setMask(t){this.layerMask||(this.layerMask=new h.Layers);const e=this.layerMask;e?e.mask=t:this.layerMask=t}}r(Nn,"AllLayers",4294967295);class sg{constructor(t,e,i){r(this,"distance");r(this,"point");r(this,"object");this.object=t,this.distance=e,this.point=i}}const mu=class{constructor(t){r(this,"context");r(this,"engine");r(this,"raycaster",new h.Raycaster);r(this,"defaultRaycastOptions",new Nn);r(this,"targetBuffer",new Array(1));r(this,"defaultThresholds",{Mesh:{},Line:{threshold:-1},LOD:{},Points:{threshold:0},Sprite:{}});r(this,"sphereResults",new Array);r(this,"sphereMask",new h.Layers);r(this,"sphere",new h.Sphere);r(this,"tempBoundingBox",new h.Box3);this.context=t}static get raycasting(){return this._raycasting>0}raycastPhysicsFast(t,e=void 0,i=1/0,n=!0){var o;return((o=this.context.physics.engine)==null?void 0:o.raycast(t,e,{maxDistance:i,solid:n}))??null}raycastPhysicsFastAndGetNormal(t,e=void 0,i=1/0,n=!0){var o;return((o=this.context.physics.engine)==null?void 0:o.raycastAndGetNormal(t,e,{maxDistance:i,solid:n}))??null}sphereOverlapPhysics(t,e){var i;return((i=this.context.physics.engine)==null?void 0:i.sphereOverlap(t,e))??null}sphereOverlap(t,e,i=!0,n=!1,o=null){if(this.sphereResults.length=0,!this.context.scene)return this.sphereResults;const a=this.sphereMask;a.enableAll(),a.disable(2);for(const l of this.context.scene.children)this.intersectSphere(l,t,e,a,this.sphereResults,i,n,o);return this.sphereResults.sort((l,c)=>l.distance-c.distance)}raycastFromRay(t,e=null){const i=e??this.defaultRaycastOptions;i.ray=t;const n=this.raycast(i);return i===this.defaultRaycastOptions&&(i.ray=void 0),n}raycast(t=null){_i&&performance.mark("raycast.start"),t||(t=this.defaultRaycastOptions);const e=t.screenPoint??this.context.input.mousePositionRC,i=t.raycaster??this.raycaster;if(i.near=t.minDistance??0,i.far=t.maxDistance??1/0,i.params=this.defaultThresholds,t.lineThreshold===void 0&&(t.lineThreshold=-1),i.params.Line={threshold:t.lineThreshold},t.ray)i.ray.copy(t.ray);else{const l=t.cam??this.context.mainCamera;if(!l)return _i&&console.error("Can not perform raycast - no main camera found"),this.defaultRaycastOptions.results&&(this.defaultRaycastOptions.results.length=0),this.defaultRaycastOptions.results??[];const c=this.context.xrCamera;this.context.isInXR&&c instanceof h.ArrayCamera&&c.cameras.length>0?i.setFromCamera(e,c.cameras[0]):i.setFromCamera(e,l)}let n=t.targets;n||(n=this.targetBuffer,n.length=1,n[0]=this.context.scene);let o=t.results;this.defaultRaycastOptions.results&&(this.defaultRaycastOptions.results.length=0),o||(this.defaultRaycastOptions.results||(this.defaultRaycastOptions.results=new Array),o=this.defaultRaycastOptions.results),t.layerMask!==void 0?t.layerMask instanceof h.Layers?i.layers.mask=t.layerMask.mask:i.layers.mask=t.layerMask:(i.layers.enableAll(),i.layers.disable(2)),_i&&console.time("raycast"),o.length=0,mu._raycasting++,this.intersect(this.raycaster,n,o,t),o.sort((l,c)=>l.distance-c.distance);const a=t.ignore;return a!==void 0&&a.length>0&&(o=o.filter(l=>!a.includes(l.object))),mu._raycasting--,_i&&(console.timeEnd("raycast"),console.warn("#"+this.context.time.frame+", hits:",o!=null&&o.length?[...o]:"nothing"),performance.mark("raycast.end"),performance.measure("raycast","raycast.start","raycast.end")),o}intersect(t,e,i,n){var o,a,l;for(const c of e){if(!c||c.visible===!1||N.isGizmo(c)||n.lineThreshold!==void 0&&n.lineThreshold<0&&c instanceof h.Line)continue;let d=!0;const u=c,f=u.geometry;if(n.testObject){const m=(o=n.testObject)==null?void 0:o.call(n,c);if(m===!1)continue;m==="continue in children"&&(d=!1)}if(d&&(f&&hy(f)||(d=!1)),d){const m=re.getRaycastMesh(c);m&&(u.geometry=m);const g=i.length;let _=!0;if(n.precise===!1&&(_=!1),_||(_=((l=(a=f.getAttribute("position"))==null?void 0:a.array)==null?void 0:l.length)<64),u instanceof Y.GroundedSkybox&&(_=!1),!_&&cC(u,t,i)||(n.useAcceleratedRaycast!==!1?Wd.runMeshBVHRaycast(t,u,i,this.context):t.intersectObject(u,!1,i)),_i&&i.length!=g){const y=i[i.length-1],b=m?8969557:7798784;N.DrawWireSphere(y.point,.1,b,1,!1),N.DrawWireMesh({mesh:c,depthTest:!1,duration:.2,color:b})}u.geometry=f}n.recursive!==!1&&this.intersect(t,c.children,i,n)}return i}intersectSphere(t,e,i,n,o,a,l,c){let d=t&&t.isMesh&&t.layers.test(n)&&!N.isGizmo(t);d&&(d=t.visible),d&&(d=!(t instanceof h.Line)),d&&(d=!(t instanceof Y.GroundedSkybox));const u=t,f=u.geometry;if(d&&c){const m=c(t);if(m===!1)return;m==="continue in children"&&(d=!1)}if(f&&hy(f)||(d=!1),d){if(l){const m=this.sphere;m.center.copy(e),m.radius=i;const g=o.length;if(Wd.runMeshBVHRaycast(this.sphere,u,o,this.context),g!=o.length&&!a)return}else if(f.boundingBox||f.computeBoundingBox(),f.boundingBox){u.matrixWorldNeedsUpdate&&u.updateWorldMatrix(!1,!1);const m=this.tempBoundingBox.copy(f.boundingBox).applyMatrix4(u.matrixWorld),g=this.sphere;if(g.center.copy(e),g.radius=i,g.intersectsBox(m)){const _=Z(t),y=_.distanceTo(g.center),b=new sg(t,y,_);if(o.push(b),!a)return}}}if(t.children)for(const m of t.children){const g=o.length;if(this.intersectSphere(m,e,i,n,o,a,l,c),g!=o.length&&!a)return}}};let Oa=mu;r(Oa,"_raycasting",0);function hy(s){return!(s.index&&s.index.array.length<3)}const Uo=new h.Sphere,$h=new h.Plane,lC=new h.Matrix3;function cC(s,t,e){const i=s._computeIntersections;if(!i)return!1;let n=s["_computeIntersections:Needle"];return n||(n=s["_computeIntersections:Needle"]=function(o,a,l){const c=this,d=c.geometry.boundingSphere;if(d){if(c instanceof Y.GroundedSkybox){$h.setFromNormalAndCoplanarPoint($(0,1,0),$(0,-c.position.y,0)),$h.applyMatrix4(c.matrixWorld,lC);const f=o.ray.intersectPlane($h,$());if(f){Uo.copy(d),Uo.applyMatrix4(c.matrixWorld);const g=$(f).sub(o.ray.origin).length(),_=Uo.radius*.5;g<_&&a.push({distance:g,point:f,object:c,normal:$h.normal.clone()})}return}Uo.copy(d),Uo.applyMatrix4(c.matrixWorld);const u=o.ray.intersectSphere(Uo,$());if(u){const f=$(u).sub(o.ray.origin),m=f.length();if(m>Uo.radius){const g=f.clone().normalize();a.push({distance:m,point:u,object:c,normal:g})}}}}),s._computeIntersections=n,t.intersectObject(s,!1,e),s._computeIntersections=i,!0}var Wd;(s=>{function t(v,x,O,k){var R,A,I;if(!x.geometry||!x.geometry.hasAttribute("position"))return!1;const M=x.geometry;if(x!=null&&x.isSkinnedMesh){const E=x,j=E.bvhNeedsUpdate;if(!E.staticGenerator)l(),o&&(E.staticGenerator=new o(x),E.staticGenerator.applyWorldTransforms=!1,E.staticGeometry=E.staticGenerator.generate(),M.boundsTree=a==null?void 0:a.call(E.staticGeometry),E.staticGeometryLastUpdate=performance.now()+Math.random()*200,E.autoUpdateMeshBVH===void 0&&(E.autoUpdateMeshBVH=!1));else if(M.boundsTree&&(E.autoUpdateMeshBVH===!0||j===!0)){const F=performance.now(),X=F-E.staticGeometryLastUpdate;(j||X>100)&&(E.bvhNeedsUpdate=!1,E.staticGeometryLastUpdate=F,(R=E.staticGenerator)==null||R.generate(E.staticGeometry),M.boundsTree.refit())}}else if(!M.boundsTree){d||b();let E=!0;if((k.xr||M[g]===!1||(A=M.getAttribute("position"))!=null&&A.isInterleavedBufferAttribute||M.index&&((I=M.index)!=null&&I.isInterleavedBufferAttribute))&&(E=!1),E&&f){if(M[m]===void 0){let j=null;if(y.length>0){const F=y.shift();F&&!F.running&&(j=F)}if(!j&&_.length<3&&(j=new f,_.push(j)),j!=null&&!j.running){const F=x.name;_i&&console.log("<<<< worker start",F,j),M[m]="queued",performance.mark("bvh.create.start");const X=M.clone();try{j.generate(X).then(T=>{M[m]="done",M.boundsTree=T}).catch(T=>{M[m]="failed - "+(T==null?void 0:T.message),M[g]=!1,_i&&console.error("Failed to generate mesh bvh on worker",T)}).finally(()=>{_i&&console.log(">>>>> worker done",F,{hasBoundsTre:M.boundsTree!=null}),y.push(j),X.dispose(),performance.mark("bvh.create.end"),performance.measure("bvh.create (worker)","bvh.create.start","bvh.create.end")})}catch(T){console.error("Failed to generate mesh bvh on worker",T)}}else _i&&console.warn("No worker available")}}else(!u||!E)&&(l(),n&&(performance.mark("bvh.create.start"),M.boundsTree=new n(M),performance.mark("bvh.create.end"),performance.measure("bvh.create","bvh.create.start","bvh.create.end")))}if(v instanceof h.Raycaster){const E=v,j=x.raycast;M.boundsTree?(l(),i&&(x.acceleratedRaycast||(x.acceleratedRaycast=i.bind(x),_i&&console.debug(`Physics: bind acceleratedRaycast fn to "${x.name}"`)),x.raycast=x.acceleratedRaycast)):_i&&console.warn("No bounds tree found for mesh",x.name,{workerTask:M[m],hasAcceleratedRaycast:i!=null});const F=E.firstHitOnly;return E.firstHitOnly=!1,E.intersectObject(x,!1,O),E.firstHitOnly=F,x.raycast=j,!0}else if(v instanceof h.Sphere){const E=M.boundsTree;if(E){const j=v;if(c.copy(x.matrixWorld).invert(),j.applyMatrix4(c),E.intersectsSphere(j)){const X=Z(x),T=X.distanceTo(j.center),L=new sg(x,T,X);O.push(L)}}return!0}return!1}s.runMeshBVHRaycast=t;let e=!1,i=null,n=null,o=null,a=null;function l(){e||(e=!0,Promise.resolve().then(()=>require("./vendor.light.umd.cjs")).then(v=>v.index$1).then(v=>{i=v.acceleratedRaycast,n=v.MeshBVH,o=v.StaticGeometryGenerator,a=v.computeBoundsTree}).catch(v=>{(_i||B())&&console.error("Failed to load BVH library...",v.message)}))}const c=new h.Matrix4;let d=!1,u=!1,f=null;const m=Symbol("Needle:MeshBVH-Worker"),g=Symbol("Needle:MeshBVH-CanUseWorker"),_=[],y=[];function b(){d=!0,u=!0,Promise.resolve().then(()=>QE).then(v=>{f=v.GenerateMeshBVHWorker}).catch(v=>{(_i||B())&&console.warn("Failed to setup mesh bvh worker")}).finally(()=>{u=!1})}})(Wd||(Wd={}));const dy=Symbol("gltf-loader-internal-usage-tracker"),hC=S("debugusers"),mc=class{constructor(t){r(this,"parser");r(this,"_getDependency");r(this,"_loadingId");r(this,"_loadedObjects",new Set);this.parser=t,this._getDependency=this.parser.getDependency,this._loadingId=Date.now().toString()}get name(){return"NEEDLE_internal_usage_tracker"}static isLoading(t){return mc._loadingProcesses>0}beforeRoot(){mc._loadingProcesses++;const t=this,e=this._getDependency;return this.parser.getDependency=function(i,n){const o=e.call(this,i,n);return o.then(a=>(a&&(t._loadedObjects.add(a),a[dy]=t._loadingId),a)),o},null}afterRoot(t){mc._loadingProcesses--,this.parser.getDependency=this._getDependency;for(const e of this._loadedObjects)delete e[dy],e instanceof h.Object3D&&(e.parent||e instanceof h.Mesh&&setTimeout(()=>{hC&&console.warn("> GLTF LOADER: Mesh not used in scene!",e),e.material=null,e.geometry=null},1e3));return null}};let sc=mc;r(sc,"_loadingProcesses",0);class kv{constructor(){window.addEventListener("unhandledrejection",t=>{var i;if(t.defaultPrevented)return;const e=(i=t==null?void 0:t.reason)==null?void 0:i.path;if(e){const n=e[0];n&&n.tagName==="IMG"&&(console.warn(`Could not load image:
155
- `+n.src),t.preventDefault())}})}}const Eu=S("trackresources");function Tv(){return Eu==="dispose"}let Sr=!0;Eu===0&&(Sr=!1);function dC(s){Sr=s}function Ev(){return Sr}const Av=Symbol("disposable");function og(s,t){s&&(s[Av]=t,sr&&console.warn("Set disposable",t,s))}const Dv=Symbol("disposed");function uC(s){return s[Dv]===!0}function xe(s){var t;if(s){if(s[Av]===!1){sr&&console.warn("Object is marked as not disposable",s);return}if(s[Dv]=!0,s instanceof h.Scene)xe(s.environment),xe(s.background),xe(s.customDepthMaterial),xe(s.customDistanceMaterial);else if(s instanceof h.SkinnedMesh)xe(s.geometry),xe(s.material),xe(s.skeleton),xe(s.bindMatrix),xe(s.bindMatrixInverse),xe(s.customDepthMaterial),xe(s.customDistanceMaterial),s.geometry=null,s.material=null,s.visible=!1;else if(s instanceof h.Mesh)xe(s.geometry),xe(s.material),xe(s.customDepthMaterial),xe(s.customDistanceMaterial),s.geometry=null,s.material=null,s.visible=!1;else if(s instanceof h.BufferGeometry){Xr(s);for(const e of Object.keys(s.attributes)){const i=s.attributes[e];xe(i)}}else if(s instanceof h.BufferAttribute||s instanceof h.InterleavedBufferAttribute)sr&&console.warn("BufferAttribute dispose not supported",s.count);else if(s instanceof Array)for(const e of s)e instanceof h.Material&&xe(e);else if(s instanceof h.Material){Xr(s);for(const i of Object.keys(s)){const n=s[i];n instanceof h.Texture&&(xe(n),s[i]=null)}const e=s.uniforms;if(e)for(const i of Object.keys(e)){const n=e[i];n instanceof h.Texture?(xe(n),e[i]=null):n instanceof h.Uniform$1&&(xe(n.value),n.value=null)}}else s instanceof h.Texture?(Xr(s),Xr(s.source),((t=s.source)==null?void 0:t.data)instanceof ImageBitmap&&Xr(s.source.data)):s instanceof h.Skeleton?(Xr(s.boneTexture),s.boneTexture=null):s instanceof h.Bone||!(s instanceof h.Object3D)&&sr&&console.warn("Unknown object type",s)}}function Xr(s){s&&((sr||Tv()||Eu)&&console.warn("๐Ÿงจ FREE",s),s instanceof ImageBitmap?s.close():s instanceof h.Source?s.data=null:s.dispose())}function Lv(s){(s instanceof h.Mesh||s instanceof h.SkinnedMesh)&&(s.material=null,s.geometry=null)}const fC=new Set;function rg(s,t,e=null,i){if(i||(i=fC,i.clear()),!s)return i;const n=s[Oc];if(n)for(const o of n)i.has(o)||(e==null?void 0:e.call(null,o))!==!1&&(i.add(o),t&&rg(o,!0,e,i));return i}function pC(s){return s[Ul]}const sr=S("debugresourceusers")||S("debugmemory"),Oc=Symbol("needle-resource-users"),Ul=Symbol("needle-resource-users-count");function It(s,t){Ru(s,t,function(e,i){Sr&&!Oa.raycasting&&(Hd(Oc,this,e,!1),Hd(Oc,this,i,!0))})}Sr&&(It(h.Mesh.prototype,"material"),It(h.Mesh.prototype,"geometry"),It(h.Material.prototype,"map"),It(h.Material.prototype,"bumpMap"),It(h.Material.prototype,"alphaMap"),It(h.Material.prototype,"normalMap"),It(h.Material.prototype,"displacementMap"),It(h.Material.prototype,"roughnessMap"),It(h.Material.prototype,"metalnessMap"),It(h.Material.prototype,"emissiveMap"),It(h.Material.prototype,"specularMap"),It(h.Material.prototype,"envMap"),It(h.Material.prototype,"lightMap"),It(h.Material.prototype,"aoMap"),It(h.Material.prototype,"gradientMap"));function mC(s){if(Sr===!1)return;const t=s[Oc];if(t)for(const e of t)Hd(Oc,e,s,!1)}Sr&&Ru(h.Material.prototype,"dispose",function(){mC(this)});let em=0;function Hd(s,t,e,i){if(em>0)return;if(Array.isArray(e)){for(const o of e)Hd(s,t,o,i);return}if(!e)return;let n=e[s];if(n||(n=new Set),i){if(t&&!n.has(t)){n.add(t);let o=e[Ul]||0;o+=1,e[Ul]=o,sr&&console.warn(`๐ŸŸข Added user of "${e.type}"`,t,e,o,"users:",n)}}else if(t&&n.has(t)){n.delete(t);let o=e[Ul]||0;o>0&&(o-=1,e[Ul]=o),sr&&console.warn(`๐Ÿ”ด Removed user of "${e.type}"`,t,e,o,"users:",n),o<=0&&(sc.isLoading(e)||(Eu&&console.warn(`๐Ÿ”ด Removed all user of "${e.type}"`,e),Tv()&&xe(e)))}e[s]=n}try{Ru(h.WebGLRenderer.prototype,"render",function(){em++},function(){em--})}catch(s){console.warn("Could not wrap WebGLRenderer.render",s)}const uy=S("debugcomponentevents");class Yc{static addComponentLifecylceEventListener(t,e){this.eventListeners.has(t)&&this.eventListeners.set(t,[]);let i=this.eventListeners.get(t);i||(i=[]),i.push(e),this.eventListeners.set(t,i),uy&&console.log("Added event listener for "+t,this.eventListeners)}static removeComponentLifecylceEventListener(t,e){const i=this.eventListeners.get(t);if(!i)return;const n=i.indexOf(e);n<0||i.splice(n,1)}static dispatchComponentLifecycleEvent(t,e){const i=this.eventListeners.get(t);if(uy&&console.log("Dispatching event "+t,i),!!i)for(const n of i)n(e)}}r(Yc,"eventListeners",new Map);const Mc=Symbol("NEEDLE_NEED_UPDATE_INSTANCE"),Iv=Symbol("isUsingInstancing"),jv=Symbol("instancingRenderer"),zl=Symbol("instancingAutoUpdateBounds");class Wi{static isUsingInstancing(t){return t[Iv]===!0}static getRenderer(t){return t[jv]||null}setAutoUpdateBounds(t,e){const i=Wi.getRenderer(t);i&&(i[zl]=e)}static markDirty(t,e=!0){if(t&&(this.isUsingInstancing(t)&&(t[Mc]=!0,t.matrixWorldNeedsUpdate=!0),e))for(const i of t.children)Wi.markDirty(i,!0)}}function Ma(s,t){try{t?s(t):s()}catch(e){return console.error(e),!1}return!0}const tm=S("debugnewscripts"),gC=S("debughierarchy"),Re=[];function _C(){return Re.length>0}function Gd(s){if(!(s.new_scripts.length<=0)){if(tm&&console.log("Register new components",s.new_scripts.length,[...s.new_scripts],s.alias?"element: "+s.alias:s.hash,s),s.new_scripts_pre_setup_callbacks.length>0){for(const t of s.new_scripts_pre_setup_callbacks)t&&t();s.new_scripts_pre_setup_callbacks.length=0}Re.length=0,s.new_scripts.length>0&&Re.push(...s.new_scripts),s.new_scripts.length=0;for(let t=0;t<Re.length;t++)try{const e=Re[t];if(e.isComponent!==!0){(B()||tm)&&console.error(`Registered script is not a Needle Engine component.
155
+ `+n.src),t.preventDefault())}})}}const Eu=S("trackresources");function Tv(){return Eu==="dispose"}let Sr=!0;Eu===0&&(Sr=!1);function dC(s){Sr=s}function Ev(){return Sr}const Av=Symbol("disposable");function og(s,t){s&&(s[Av]=t,sr&&console.warn("Set disposable",t,s))}const Dv=Symbol("disposed");function uC(s){return s[Dv]===!0}function xe(s){var t;if(s){if(s[Av]===!1){sr&&console.warn("Object is marked as not disposable",s);return}if(s[Dv]=!0,s instanceof h.Scene)xe(s.environment),xe(s.background),xe(s.customDepthMaterial),xe(s.customDistanceMaterial);else if(s instanceof h.SkinnedMesh)xe(s.geometry),xe(s.material),xe(s.skeleton),xe(s.bindMatrix),xe(s.bindMatrixInverse),xe(s.customDepthMaterial),xe(s.customDistanceMaterial),s.geometry=null,s.material=null,s.visible=!1;else if(s instanceof h.Mesh)xe(s.geometry),xe(s.material),xe(s.customDepthMaterial),xe(s.customDistanceMaterial),s.geometry=null,s.material=null,s.visible=!1;else if(s instanceof h.BufferGeometry){Xr(s);for(const e of Object.keys(s.attributes)){const i=s.attributes[e];xe(i)}}else if(s instanceof h.BufferAttribute||s instanceof h.InterleavedBufferAttribute)sr&&console.warn("BufferAttribute dispose not supported",s.count);else if(s instanceof Array)for(const e of s)e instanceof h.Material&&xe(e);else if(s instanceof h.Material){Xr(s);for(const i of Object.keys(s)){const n=s[i];n instanceof h.Texture&&(xe(n),s[i]=null)}const e=s.uniforms;if(e)for(const i of Object.keys(e)){const n=e[i];n instanceof h.Texture?(xe(n),e[i]=null):n instanceof h.Uniform$1&&(xe(n.value),n.value=null)}}else s instanceof h.Texture?(Xr(s),Xr(s.source),((t=s.source)==null?void 0:t.data)instanceof ImageBitmap&&Xr(s.source.data)):s instanceof h.Skeleton?(Xr(s.boneTexture),s.boneTexture=null):s instanceof h.Bone||!(s instanceof h.Object3D)&&sr&&console.warn("Unknown object type",s)}}function Xr(s){s&&((sr||Tv()||Eu)&&console.warn("๐Ÿงจ FREE",s),s instanceof ImageBitmap?s.close():s instanceof h.Source?s.data=null:s.dispose())}function Lv(s){(s instanceof h.Mesh||s instanceof h.SkinnedMesh)&&(s.material=null,s.geometry=null)}const fC=new Set;function rg(s,t,e=null,i){if(i||(i=fC,i.clear()),!s)return i;const n=s[Oc];if(n)for(const o of n)i.has(o)||(e==null?void 0:e.call(null,o))!==!1&&(i.add(o),t&&rg(o,!0,e,i));return i}function pC(s){return s[Ul]}const sr=S("debugresourceusers")||S("debugmemory"),Oc=Symbol("needle-resource-users"),Ul=Symbol("needle-resource-users-count");function It(s,t){Ru(s,t,function(e,i){Sr&&!Oa.raycasting&&(Hd(Oc,this,e,!1),Hd(Oc,this,i,!0))})}Sr&&(It(h.Mesh.prototype,"material"),It(h.Mesh.prototype,"geometry"),It(h.Material.prototype,"map"),It(h.Material.prototype,"bumpMap"),It(h.Material.prototype,"alphaMap"),It(h.Material.prototype,"normalMap"),It(h.Material.prototype,"displacementMap"),It(h.Material.prototype,"roughnessMap"),It(h.Material.prototype,"metalnessMap"),It(h.Material.prototype,"emissiveMap"),It(h.Material.prototype,"specularMap"),It(h.Material.prototype,"envMap"),It(h.Material.prototype,"lightMap"),It(h.Material.prototype,"aoMap"),It(h.Material.prototype,"gradientMap"));function mC(s){if(Sr===!1)return;const t=s[Oc];if(t)for(const e of t)Hd(Oc,e,s,!1)}Sr&&Ru(h.Material.prototype,"dispose",function(){mC(this)});let em=0;function Hd(s,t,e,i){if(em>0)return;if(Array.isArray(e)){for(const o of e)Hd(s,t,o,i);return}if(!e)return;let n=e[s];if(n||(n=new Set),i){if(t&&!n.has(t)){n.add(t);let o=e[Ul]||0;o+=1,e[Ul]=o,sr&&console.warn(`๐ŸŸข Added user of "${e.type}"`,t,e,o,"users:",n)}}else if(t&&n.has(t)){n.delete(t);let o=e[Ul]||0;o>0&&(o-=1,e[Ul]=o),sr&&console.warn(`๐Ÿ”ด Removed user of "${e.type}"`,t,e,o,"users:",n),o<=0&&(sc.isLoading(e)||(Eu&&console.warn(`๐Ÿ”ด Removed all user of "${e.type}"`,e),Tv()&&xe(e)))}e[s]=n}try{Ru(h.WebGLRenderer.prototype,"render",function(){em++},function(){em--})}catch(s){console.warn("Could not wrap WebGLRenderer.render",s)}const uy=S("debugcomponentevents");class Yc{static addComponentLifecylceEventListener(t,e){this.eventListeners.has(t)&&this.eventListeners.set(t,[]);let i=this.eventListeners.get(t);i||(i=[]),i.push(e),this.eventListeners.set(t,i),uy&&console.log("Added event listener for "+t,this.eventListeners)}static removeComponentLifecylceEventListener(t,e){const i=this.eventListeners.get(t);if(!i)return;const n=i.indexOf(e);n<0||i.splice(n,1)}static dispatchComponentLifecycleEvent(t,e){const i=this.eventListeners.get(t);if(uy&&console.log("Dispatching event "+t,i),!!i)for(const n of i)n(e)}}r(Yc,"eventListeners",new Map);const Mc=Symbol("NEEDLE_NEED_UPDATE_INSTANCE"),Iv=Symbol("isUsingInstancing"),jv=Symbol("instancingRenderer"),zl=Symbol("instancingAutoUpdateBounds");class Wi{static isUsingInstancing(t){return t[Iv]===!0}static getRenderer(t){return t[jv]||null}setAutoUpdateBounds(t,e){const i=Wi.getRenderer(t);i&&(i[zl]=e)}static markDirty(t,e=!0){if(t&&(this.isUsingInstancing(t)&&(t[Mc]=!0,t.matrixWorldNeedsUpdate=!0),e))for(const i of t.children)Wi.markDirty(i,!0)}}function Ma(s,t){try{t?s(t):s()}catch(e){return console.error(e),!1}return!0}const tm=S("debugnewscripts"),gC=S("debughierarchy"),Re=[];function _C(){return Re.length>0}function Gd(s){if(tm&&console.log("Register new components",s.new_scripts.length,[...s.new_scripts],s.alias?"element: "+s.alias:s.hash,s),s.new_scripts_pre_setup_callbacks.length>0){for(const t of s.new_scripts_pre_setup_callbacks)t&&t();s.new_scripts_pre_setup_callbacks.length=0}if(!(s.new_scripts.length<=0)){Re.length=0,s.new_scripts.length>0&&Re.push(...s.new_scripts),s.new_scripts.length=0;for(let t=0;t<Re.length;t++)try{const e=Re[t];if(e.isComponent!==!0){(B()||tm)&&console.error(`Registered script is not a Needle Engine component.
156
156
  The script will be ignored. Please make sure your component extends "Behaviour" imported from "@needle-tools/engine"
157
157
  `,e),Re.splice(t,1),t--;continue}if(e.destroyed)continue;if(!e.gameObject){console.warn(`Component can not be initialized: no GameObject assigned.
158
158
  Did you add and remove a component in the same frame?`),Re.splice(t,1),t--;continue}e.context=s,oc(e.gameObject),ag(e,s)}catch(e){console.error(e),ps(Re[t],s),Re.splice(t,1),t--}for(let t=0;t<Re.length;t++)try{const e=Re[t];if(e.destroyed){ps(Re[t],s),Re.splice(t,1),t--;continue}if(e.registering)try{e.registering()}catch(i){console.error(i)}e.__internalAwake!==void 0&&(e.gameObject||console.error("Calling awake for a component without a GameObject",e,e.gameObject),oc(e.gameObject),e.activeAndEnabled&&Ma(e.__internalAwake.bind(e)))}catch(e){console.error(e),ps(Re[t],s),Re.splice(t,1),t--}for(let t=0;t<Re.length;t++)try{const e=Re[t];if(e.destroyed||e.enabled===!1||(oc(e.gameObject),e.activeAndEnabled===!1))continue;e.__internalEnable!==void 0&&(e.enabled=!0,Ma(e.__internalEnable.bind(e)))}catch(e){console.error(e),ps(Re[t],s),Re.splice(t,1),t--}for(let t=0;t<Re.length;t++)try{const e=Re[t];if(e.destroyed||!e.gameObject)continue;s.new_script_start.push(e)}catch(e){console.error(e),ps(Re[t],s),Re.splice(t,1),t--}Re.length=0;for(const t of s.new_scripts_post_setup_callbacks)t&&t();s.new_scripts_post_setup_callbacks.length=0}}function yC(s){s&&(s.__internalDisable(!0),ps(s,s.context))}function Bv(s,t){for(let e=0;e<s.new_script_start.length;e++)try{const i=s.new_script_start[e];if(t!==void 0&&i.gameObject!==t||i.destroyed||i.activeAndEnabled===!1)continue;Ma(i.__internalAwake.bind(i)),i.enabled&&(Ma(i.__internalEnable.bind(i)),Ma(i.__internalStart.bind(i)),s.new_script_start.splice(e,1),e--)}catch(i){console.error(i),ps(s.new_script_start[e],s),s.new_script_start.splice(e,1),e--}}function ag(s,t){t.scripts.indexOf(s)===-1&&(t.scripts.push(s),s.earlyUpdate&&t.scripts_earlyUpdate.push(s),s.update&&t.scripts_update.push(s),s.lateUpdate&&t.scripts_lateUpdate.push(s),s.onBeforeRender&&t.scripts_onBeforeRender.push(s),s.onAfterRender&&t.scripts_onAfterRender.push(s),s.onPausedChanged&&t.scripts_pausedChanged.push(s),Lf(s,null)&&t.new_scripts_xr.push(s),Lf(s,"immersive-vr")&&t.scripts_immersive_vr.push(s),Lf(s,"immersive-ar")&&t.scripts_immersive_ar.push(s))}function ps(s,t){Di(s,t.new_scripts),Di(s,t.new_script_start),Di(s,t.scripts),Di(s,t.scripts_earlyUpdate),Di(s,t.scripts_update),Di(s,t.scripts_lateUpdate),Di(s,t.scripts_onBeforeRender),Di(s,t.scripts_onAfterRender),Di(s,t.scripts_pausedChanged),Di(s,t.new_scripts_xr),Di(s,t.scripts_immersive_vr),Di(s,t.scripts_immersive_ar),t.stopAllCoroutinesFrom(s)}function Di(s,t){const e=t.indexOf(s);e>=0&&t.splice(e,1)}function Lf(s,t){var e;if(s){const i=s;if(i.onBeforeXR||i.onEnterXR||i.onUpdateXR||i.onLeaveXR||i.onXRControllerAdded||i.onXRControllerRemoved)return!(t!=null&&((e=i.supportsXR)==null?void 0:e.call(i,t))===!1)}return!1}function xd(s){if(s||(s=ce.Current.scene),!s){console.trace("Invalid call - no current context.");return}const t=$a(s);Fv(s,t,!0)||(tm||B()?console.error(`Error updating hierarchy