@needle-tools/engine 4.5.0 → 4.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/{needle-engine.bundle-8e64768b.js → needle-engine.bundle-99bb72c3.js} +7 -7
  2. package/dist/{needle-engine.bundle-4e21a0eb.min.js → needle-engine.bundle-ac883b5a.min.js} +2 -2
  3. package/dist/{needle-engine.bundle-0293e87a.light.js → needle-engine.bundle-adcbea18.light.js} +7 -7
  4. package/dist/{needle-engine.bundle-1679a09a.light.min.js → needle-engine.bundle-b57b2055.light.min.js} +2 -2
  5. package/dist/{needle-engine.bundle-2f187b48.light.umd.cjs → needle-engine.bundle-bcb5a31b.light.umd.cjs} +4 -4
  6. package/dist/{needle-engine.bundle-4366d297.umd.cjs → needle-engine.bundle-caf79082.umd.cjs} +4 -4
  7. package/dist/needle-engine.js +2 -2
  8. package/dist/needle-engine.light.js +2 -2
  9. package/dist/needle-engine.light.min.js +1 -1
  10. package/dist/needle-engine.light.umd.cjs +1 -1
  11. package/dist/needle-engine.min.js +1 -1
  12. package/dist/needle-engine.umd.cjs +1 -1
  13. package/lib/engine/engine_loaders.callbacks.d.ts +1 -0
  14. package/lib/engine/engine_loaders.callbacks.js +1 -0
  15. package/lib/engine/engine_loaders.callbacks.js.map +1 -1
  16. package/lib/engine/engine_utils_format.js +2 -2
  17. package/lib/engine/engine_utils_format.js.map +1 -1
  18. package/package.json +1 -1
  19. package/plugins/vite/build-pipeline.js +22 -6
  20. package/src/engine/engine_loaders.callbacks.ts +1 -0
  21. package/src/engine/engine_utils_format.ts +2 -2
  22. package/lib/engine/engine.d.ts +0 -4
  23. package/lib/engine/engine.js +0 -12
  24. package/lib/engine/engine.js.map +0 -1
  25. package/lib/engine/engine_element.d.ts +0 -113
  26. package/lib/engine/engine_element.js +0 -833
  27. package/lib/engine/engine_element.js.map +0 -1
  28. package/lib/engine/engine_element_attributes.d.ts +0 -72
  29. package/lib/engine/engine_element_attributes.js +0 -2
  30. package/lib/engine/engine_element_attributes.js.map +0 -1
  31. package/lib/engine/engine_element_extras.d.ts +0 -6
  32. package/lib/engine/engine_element_extras.js +0 -14
  33. package/lib/engine/engine_element_extras.js.map +0 -1
  34. package/lib/engine/engine_element_loading.d.ts +0 -44
  35. package/lib/engine/engine_element_loading.js +0 -350
  36. package/lib/engine/engine_element_loading.js.map +0 -1
  37. package/lib/engine/engine_element_overlay.d.ts +0 -21
  38. package/lib/engine/engine_element_overlay.js +0 -167
  39. package/lib/engine/engine_element_overlay.js.map +0 -1
  40. package/lib/engine/engine_scenetools.d.ts +0 -50
  41. package/lib/engine/engine_scenetools.js +0 -322
  42. package/lib/engine/engine_scenetools.js.map +0 -1
  43. package/lib/engine/engine_web_api.d.ts +0 -12
  44. package/lib/engine/engine_web_api.js +0 -113
  45. package/lib/engine/engine_web_api.js.map +0 -1
  46. package/lib/engine-components/FlyControls.d.ts +0 -10
  47. package/lib/engine-components/FlyControls.js +0 -29
  48. package/lib/engine-components/FlyControls.js.map +0 -1
@@ -1792,15 +1792,15 @@ function TC() {
1792
1792
  return s || null;
1793
1793
  }
1794
1794
  const z0 = x("debugdefines");
1795
- Ro('if(!globalThis[""4.5.0""]) globalThis[""4.5.0""] = "0.0.0";');
1795
+ Ro('if(!globalThis[""4.5.2""]) globalThis[""4.5.2""] = "0.0.0";');
1796
1796
  Ro('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');
1797
- Ro('if(!globalThis[""Wed May 21 2025 11:58:56 GMT+0200 (Central European Summer Time)""]) globalThis[""Wed May 21 2025 11:58:56 GMT+0200 (Central European Summer Time)""] = "unknown";');
1797
+ Ro('if(!globalThis[""Fri May 30 2025 15:56:24 GMT+0200 (Central European Summer Time)""]) globalThis[""Fri May 30 2025 15:56:24 GMT+0200 (Central European Summer Time)""] = "unknown";');
1798
1798
  Ro('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";');
1799
- Ro('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.5.0";');
1799
+ Ro('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.5.2";');
1800
1800
  Ro('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');
1801
- Ro('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Wed May 21 2025 11:58:56 GMT+0200 (Central European Summer Time)";');
1801
+ Ro('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Fri May 30 2025 15:56:24 GMT+0200 (Central European Summer Time)";');
1802
1802
  Ro('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');
1803
- const Vn = "4.5.0", bg = "undefined", U0 = "Wed May 21 2025 11:58:56 GMT+0200 (Central European Summer Time)";
1803
+ const Vn = "4.5.2", bg = "undefined", U0 = "Fri May 30 2025 15:56:24 GMT+0200 (Central European Summer Time)";
1804
1804
  z0 && console.log(`Engine version: ${Vn} (generator: ${bg})
1805
1805
  Project built at ${U0}`);
1806
1806
  const md = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9", _o = "needle_isActiveInHierarchy", sa = "builtin_components", gd = "needle_editor_guid";
@@ -40709,7 +40709,7 @@ async function gI(s, t) {
40709
40709
  var o;
40710
40710
  const { useExtension: e = !0 } = t;
40711
40711
  if (e) {
40712
- const a = s, l = new URL(a, globalThis.location.origin);
40712
+ const a = s, l = new URL(a, globalThis.location.href);
40713
40713
  let c = null;
40714
40714
  const h = l.searchParams.get("filetype");
40715
40715
  switch (h && (c = h.toUpperCase()), c != null && c.length || (c = (o = l.pathname.split(".").pop()) == null ? void 0 : o.toUpperCase()), Cc && console.warn(`[Needle Engine] Try to use file extension to determine type: '${c}'`), c) {
@@ -40733,7 +40733,7 @@ async function gI(s, t) {
40733
40733
  }
40734
40734
  const i = s;
40735
40735
  if (!s.startsWith("blob:")) {
40736
- const a = new URL(s);
40736
+ const a = new URL(s, globalThis.location.href);
40737
40737
  a.searchParams.append("range", "true"), s = a.toString();
40738
40738
  }
40739
40739
  const n = await fetch(s, {
@@ -130,7 +130,7 @@ Open this page to get the console: `+t.toString())}const n=Q.isMobileDevice()||Q
130
130
  #__vconsole .vc-mask {
131
131
  overflow: hidden;
132
132
  }
133
- `,Gi?.prepend(s),n===!0&&Em()<=0&&nb(),console.log("\u{1F335} Debug console has loaded")}},t.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),oc=!1,ri=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function CP(){if(!globalThis.VConsole)return;const n=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+n._id+" iframe");return n.on("renderTab",function(i){const s=globalThis["needle:codegen_files"];if(!s||s.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);n.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';i(h)}),n.on("show",function(){const i=t();i&&i.src!==n.fullUrl&&(i.src=n.fullUrl)}),n.on("hide",function(){const i=t();i&&(i.src="")}),n.on("addTopBar",function(i){var s=new Array;s.push({name:"Open in new window \u2197",onClick:function(o){window.open(n.fullUrl,"_blank"),ri?.hide()}}),s.push({name:"Reload",onClick:function(o){const r=t();r&&(r.src=n.fullUrl)}}),s.push({name:"Fullscreen",onClick:function(o){const r=t();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),i(s)}),n}function OP(){return document.querySelector("#__vconsole .vc-switch")||null}function PP(){return document.querySelector("#__vconsole")||null}const ab=C("debugdefines");go('if(!globalThis[""4.5.0""]) globalThis[""4.5.0""] = "0.0.0";'),go('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),go('if(!globalThis[""Wed May 21 2025 11:58:56 GMT+0200 (Central European Summer Time)""]) globalThis[""Wed May 21 2025 11:58:56 GMT+0200 (Central European Summer Time)""] = "unknown";'),go('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";'),go('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.5.0";'),go('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),go('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Wed May 21 2025 11:58:56 GMT+0200 (Central European Summer Time)";'),go('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');const bn="4.5.0",kd="undefined",Ym="Wed May 21 2025 11:58:56 GMT+0200 (Central European Summer Time)";ab&&console.log(`Engine version: ${bn} (generator: ${kd})
133
+ `,Gi?.prepend(s),n===!0&&Em()<=0&&nb(),console.log("\u{1F335} Debug console has loaded")}},t.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),oc=!1,ri=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function CP(){if(!globalThis.VConsole)return;const n=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+n._id+" iframe");return n.on("renderTab",function(i){const s=globalThis["needle:codegen_files"];if(!s||s.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);n.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';i(h)}),n.on("show",function(){const i=t();i&&i.src!==n.fullUrl&&(i.src=n.fullUrl)}),n.on("hide",function(){const i=t();i&&(i.src="")}),n.on("addTopBar",function(i){var s=new Array;s.push({name:"Open in new window \u2197",onClick:function(o){window.open(n.fullUrl,"_blank"),ri?.hide()}}),s.push({name:"Reload",onClick:function(o){const r=t();r&&(r.src=n.fullUrl)}}),s.push({name:"Fullscreen",onClick:function(o){const r=t();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),i(s)}),n}function OP(){return document.querySelector("#__vconsole .vc-switch")||null}function PP(){return document.querySelector("#__vconsole")||null}const ab=C("debugdefines");go('if(!globalThis[""4.5.2""]) globalThis[""4.5.2""] = "0.0.0";'),go('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),go('if(!globalThis[""Fri May 30 2025 15:56:24 GMT+0200 (Central European Summer Time)""]) globalThis[""Fri May 30 2025 15:56:24 GMT+0200 (Central European Summer Time)""] = "unknown";'),go('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";'),go('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.5.2";'),go('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),go('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Fri May 30 2025 15:56:24 GMT+0200 (Central European Summer Time)";'),go('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');const bn="4.5.2",kd="undefined",Ym="Fri May 30 2025 15:56:24 GMT+0200 (Central European Summer Time)";ab&&console.log(`Engine version: ${bn} (generator: ${kd})
134
134
  Project built at ${Ym}`);const ac="npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9",Os="needle_isActiveInHierarchy",pr="builtin_components",lc="needle_editor_guid";function go(n){try{(0,eval)(n)}catch(t){ab&&console.error(t)}}let lb,cb=null;function _n(){return lb}function Km(n){if(n==null){console.warn("Oh no: someone tried registering a non-existend gltf-loader. When you see this log it might mean that needle-engine is being imported multiple times. Please check your project setup.");return}cb!==n&&(cb=n,lb=new n)}const ki=Symbol("shadowDomOwner"),kP=C("debugpatch");function Md(n,t,i,s){const o=kP===t;if(!i&&!s)return;const r=t+"___needle";RP(n,t,i,s);const l=Object.getOwnPropertyDescriptor(n,t),c=n[t];o&&console.log("Patch",n.constructor.name,t,l,c),l?(o&&console.log("Apply patch with existing descriptor",n.constructor.name,t,l),typeof l.value=="function"&&(n[t]=db(l.value,n,t))):(o&&console.log("Create patch with new property",n.constructor.name,t,l),Object.defineProperty(n,t,{set:function(h){if(typeof h=="function")this[r]=db(h,n,t);else{const d=this[r];ub(n,t,this,d,h),this[r]=h,pb(n,t,this,d,h)}},get:function(){const h=this[r];return typeof h=="function"&&h[r]?h[r]:h}}))}function MP(n,t,i){const s=Jm(n,t);if(s)for(let o=s.length-1;o>=0;o--){const r=s[o];r.prefix===i&&(r.prefix=null),r.postfix===i&&(r.postfix=null),!r.prefix&&!r.postfix&&s.splice(o,1)}}const hb=Symbol("Needle:Patches:WrappedFunction");function db(n,t,i){if(n[hb])return n;const s=function(...o){ub(t,i,this,...o);const r=n.apply(this,o);return pb(t,i,this,r,...o),r};return s[hb]=!0,s}const Rd="Needle:Patches";function Zm(){return globalThis[Rd]||(globalThis[Rd]=new WeakMap),globalThis[Rd]}function Jm(n,t){const i=Zm().get(n);return i?i.get(t):null}function RP(n,t,i,s){let o=Zm().get(n);o||(o=new Map,Zm().set(n,o));let r=o.get(t);r||(r=[],o.set(t,r)),r.push({prefix:i,postfix:s})}function ub(n,t,i,...s){var o;if(!i)return;const r=Jm(n,t);if(r)for(const l of r)(o=l.prefix)==null||o.call(i,...s)}function pb(n,t,i,s,...o){var r;if(!i)return;const l=Jm(n,t);if(l)for(const c of l)(r=c.postfix)==null||r.call(i,s,...o)}const xa=[];function Td(n){xa.indexOf(n)===-1&&xa.push(n)}function TP(n){const t=xa.indexOf(n);t!==-1&&xa.splice(t,1)}const Sa=[];function eg(n){Sa.indexOf(n)===-1&&Sa.push(n)}function EP(n){const t=Sa.indexOf(n);t!==-1&&Sa.splice(t,1)}function mb(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:n}));for(let t=0;t<xa.length;t++)xa[t](n)}function gb(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:n}));for(let t=0;t<Sa.length;t++)Sa[t](n)}const ut=C("debuginput");var Ed=(n=>(n.Mouse="mouse",n.Touch="touch",n.Controller="controller",n.Hand="hand",n))(Ed||{}),Fe=(n=>(n.PointerDown="pointerdown",n.PointerUp="pointerup",n.PointerMove="pointermove",n.KeyDown="keydown",n.KeyUp="keyup",n.KeyPressed="keypress",n))(Fe||{});class Ps extends PointerEvent{constructor(t,i,s){super(t,s),a(this,"clientZ"),a(this,"deviceIndex"),a(this,"origin"),a(this,"source"),a(this,"mode"),a(this,"_ray"),a(this,"space"),a(this,"isClick",!1),a(this,"isDoubleClick",!1),a(this,"_used",!1),a(this,"_pointerid"),a(this,"_pointerType"),a(this,"_type"),a(this,"metadata",{}),a(this,"intersections",new Array),a(this,"_immediatePropagationStopped",!1),a(this,"_propagationStopped",!1),this.clientZ=s.clientZ,this._pointerid=s.pointerId,this._pointerType=s.pointerType,this._type=t,this.deviceIndex=s.deviceIndex,this.origin=s.origin,this.source=i,this.mode=s.mode,this._ray=s.ray,this.space=s.device}get isSpatial(){return this.mode!="screen"}get ray(){return this._ray||(this._ray=new lo(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(t){this._ray=t}get hasRay(){return this._ray!==void 0}get used(){return this._used}use(){this._used=!0}get pointerId(){return this._pointerid}get pointerType(){return this._pointerType}get type(){return this._type}get immediatePropagationStopped(){return this._immediatePropagationStopped}get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){var t;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(t=this.source)==null||t.stopImmediatePropagation()}stopPropagation(){var t;this._propagationStopped=!0,super.stopPropagation(),(t=this.source)==null||t.stopPropagation(),ut&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class cc extends KeyboardEvent{constructor(t,i,s){super(t,s),a(this,"source"),this.source=i}stopImmediatePropagation(){var t;super.stopImmediatePropagation(),(t=this.source)==null||t.stopImmediatePropagation()}}class AP{constructor(t){a(this,"key"),a(this,"keyType"),a(this,"source"),this.key=t.key,this.keyType=t.type,this.source=t}}var ai=(n=>(n[n.Early=-100]="Early",n[n.Default=0]="Default",n[n.Late=100]="Late",n))(ai||{});class fb{constructor(t){a(this,"_eventListeners",{}),a(this,"_doubleClickTimeThreshold",.2),a(this,"_longPressTimeThreshold",1),a(this,"_setCursorTypes",[]),a(this,"context"),a(this,"_pointerDown",[!1]),a(this,"_pointerUp",[!1]),a(this,"_pointerClick",[!1]),a(this,"_pointerDoubleClick",[!1]),a(this,"_pointerPressed",[!1]),a(this,"_pointerPositions",[new re]),a(this,"_pointerPositionsLastFrame",[new re]),a(this,"_pointerPositionsDelta",[new re]),a(this,"_pointerPositionsRC",[new re]),a(this,"_pointerPositionDown",[new x]),a(this,"_pointerDownTime",[]),a(this,"_pointerUpTime",[]),a(this,"_pointerUpTimestamp",[]),a(this,"_pointerIds",[]),a(this,"_pointerTypes",[""]),a(this,"_mouseWheelChanged",[!1]),a(this,"_mouseWheelDeltaY",[0]),a(this,"_pointerEvent",[]),a(this,"_pointerEventsPressed",[]),a(this,"_pointerSpace",[]),a(this,"_pressedStack",new Map),a(this,"_htmlEventSource"),a(this,"onLostFocus",()=>{for(const i in this.keysPressed)this.keysPressed[i].pressed=!1}),a(this,"_receivedPointerMoveEventsThisFrame",new Array),a(this,"onEndOfFrame",()=>{this._receivedPointerMoveEventsThisFrame.length=0;for(let i=0;i<this._pointerUp.length;i++)this._pointerUp[i]=!1;for(let i=0;i<this._pointerDown.length;i++)this._pointerDown[i]=!1;for(let i=0;i<this._pointerClick.length;i++)this._pointerClick[i]=!1;for(let i=0;i<this._pointerDoubleClick.length;i++)this._pointerDoubleClick[i]=!1;for(const i of this._pointerPositionsDelta)i.set(0,0);for(let i=0;i<this._mouseWheelChanged.length;i++)this._mouseWheelChanged[i]=!1;for(let i=0;i<this._mouseWheelDeltaY.length;i++)this._mouseWheelDeltaY[i]=0}),a(this,"onContextMenu",i=>{this.canReceiveInput(i)!==!1&&i instanceof PointerEvent&&i.pointerType}),a(this,"keysPressed",{}),a(this,"onKeyDown",i=>{if(ut&&console.log(`key down ${i.code}, ${this.context.application.hasFocus}`,i),!this.context.application.hasFocus)return;const s=this.keysPressed[i.code];if(s&&s.pressed)return;this.keysPressed[i.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:i.key,code:i.code};const o=new cc("keydown",i,i);this.onDispatchEvent(o)}),a(this,"onKeyPressed",i=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[i.code];if(!s)return;s.pressed=!0,s.frame=this.context.time.frameCount+1;const o=new cc("keypress",i,i);this.onDispatchEvent(o)}),a(this,"onKeyUp",i=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[i.code];if(!s)return;s.pressed=!1,s.frame=this.context.time.frameCount+1;const o=new cc("keyup",i,i);this.onDispatchEvent(o)}),a(this,"onWheelWindow",i=>{document.pointerLockElement&&this.onMouseWheel(i)}),a(this,"onMouseWheel",i=>{if(this.canReceiveInput(i)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const s=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=s+i.deltaY}),a(this,"onPointerDown",i=>{if(this.context.isInAR||this.canReceiveInput(i)===!1)return;i.target instanceof HTMLElement&&i.target.setPointerCapture(i.pointerId);const s=this.getPointerId(i);ut&&Be(`pointer down #${s}, identifier:${i.pointerId}`);const o=this.getAndUpdateSpatialObjectForScreenPosition(s,i.clientX,i.clientY),r=new Ps("pointerdown",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:i.button,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:o,pressure:i.pressure});this.onDown(r)}),a(this,"onPointerMove",i=>{if(this.context.isInAR||this._receivedPointerMoveEventsThisFrame.includes(i.pointerId))return;this._receivedPointerMoveEventsThisFrame.push(i.pointerId);let s=i.button;i.pointerType==="mouse"&&(s=this.getFirstPressedButtonForPointer(0)??0);const o=this.getPointerId(i,s);s===-1&&(s=o);const r=this.getAndUpdateSpatialObjectForScreenPosition(o,i.clientX,i.clientY),l=new Ps("pointermove",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:o,button:s,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:r,pressure:i.pressure});this.onMove(l)}),a(this,"onPointerCancel",i=>{this.context.isInAR||(ut&&console.log("Pointer cancel",i),this.onPointerUp(i))}),a(this,"onPointerUp",i=>{if(this.context.isInAR)return;i.target instanceof HTMLElement&&i.target.releasePointerCapture(i.pointerId);const s=this.getPointerId(i),o=new Ps("pointerup",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:i.button,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:this.getAndUpdateSpatialObjectForScreenPosition(s,i.clientX,i.clientY),pressure:i.pressure});this.onUp(o),this._pointerIds[s]=-1,ut&&console.log("ID="+s,"PointerId="+i.pointerId,"ALL:",[...this._pointerIds])}),a(this,"onTouchStart",i=>{if(this.context.isInAR)for(let s=0;s<i.changedTouches.length;s++){const o=i.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new Ps("pointerdown",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onDown(c)}}),a(this,"onTouchMove",i=>{if(this.context.isInAR)for(let s=0;s<i.changedTouches.length;s++){const o=i.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new Ps("pointermove",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onMove(c)}}),a(this,"onTouchEnd",i=>{if(this.context.isInAR)for(let s=0;s<i.changedTouches.length;s++){const o=i.changedTouches[s],r=this.getPointerIndex(o.identifier),l=new Ps("pointerup",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),pressure:o.force});this.onUp(l),this._pointerIds[r]=-1}}),a(this,"tempNearPlaneVector",new x),a(this,"tempFarPlaneVector",new x),a(this,"tempLookMatrix",new se),this.context=t,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(t,i,s){if(this._eventListeners[t]||(this._eventListeners[t]=[]),!i||typeof i!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}s?s={...s}:s={};let o=0;s?.queue!=null&&(o=s.queue);const r=this._eventListeners[t],l=r.find(c=>c.priority===o);l?l.listeners.push({callback:i,options:s}):(r.push({priority:o,listeners:[{callback:i,options:s}]}),r.sort((c,h)=>c.priority-h.priority))}removeEventListener(t,i,s){if(!this._eventListeners[t]||!i)return;const o=this._eventListeners[t];if(s?.queue!=null){const r=o.find(c=>c.priority===s.queue);if(!r)return;const l=r.listeners.findIndex(c=>c.callback===i);l>=0&&r.listeners.splice(l,1)}else for(const r of o){const l=r.listeners.findIndex(c=>c.callback===i);l>=0&&r.listeners.splice(l,1)}}dispatchEvent(t){var i,s,o,r;let l=!1;if(t instanceof cc){const c=this._eventListeners[t.type];if(c)for(const h of c)for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((s=(i=u.options)==null?void 0:i.signal)!=null&&s.aborted){h.listeners.splice(d,1),d--;continue}u.options.once&&(h.listeners.splice(d,1),d--),u.callback(t)}}if(t instanceof Ps){const c=this._eventListeners[t.type];if(c)for(const h of c){if(l)break;for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((r=(o=u.options)==null?void 0:o.signal)!=null&&r.aborted){h.listeners.splice(d,1),d--;continue}if(t.immediatePropagationStopped){l=!0,ut&&console.log("immediatePropagationStopped",t.type);break}else t.propagationStopped&&(l=!0,ut&&console.log("propagationStopped",t.type));u.options.once&&(h.listeners.splice(d,1),d--),u.callback(t)}}}}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}get click(){return this._pointerClick[0]}get doubleClick(){return this._pointerDoubleClick[0]}getGamepad(t=0){return typeof navigator<"u"&&"getGamepads"in navigator&&navigator.getGamepads()[t]||null}setCursorPointer(){this.setCursor("pointer")}setCursorNormal(){this.unsetCursor("pointer")}setCursor(t){this._setCursorTypes.push(t),this._setCursorTypes.length>10&&this._setCursorTypes.shift(),this.updateCursor()}unsetCursor(t){for(let i=this._setCursorTypes.length-1;i>=0;i--)if(this._setCursorTypes[i]===t){this._setCursorTypes.splice(i,1),this.updateCursor();break}}updateCursor(){var t;((t=this._setCursorTypes)==null?void 0:t.length)==0?this.context.domElement.style.cursor="default":this.context.domElement.style.cursor=this._setCursorTypes[this._setCursorTypes.length-1]}getIsPointerIdInUse(t){for(const i of this._pointerEventsPressed)if(i.pointerId===t&&i.used)return!0;return!1}getPointerPressedCount(){let t=0;for(let i=0;i<this._pointerPressed.length;i++)this._pointerPressed[i]&&t++;return t}getPointerPosition(t){return t>=this._pointerPositions.length?null:this._pointerPositions[t]}getPointerPositionLastFrame(t){return t>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[t]}getPointerPositionDelta(t){return t>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[t]}getPointerPositionRC(t){return t>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[t]}getPointerDown(t){return t>=this._pointerDown.length?!1:this._pointerDown[t]}getPointerUp(t){return t>=this._pointerUp.length?!1:this._pointerUp[t]}getPointerPressed(t){return t>=this._pointerPressed.length?!1:this._pointerPressed[t]}getPointerClicked(t){return t>=this._pointerClick.length?!1:this._pointerClick[t]}getPointerDoubleClicked(t){return t>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[t]}getPointerDownTime(t){return t>=this._pointerDownTime.length?-1:this._pointerDownTime[t]}getPointerUpTime(t){return t>=this._pointerUpTime.length?-1:this._pointerUpTime[t]}getPointerLongPress(t){return t>=this._pointerDownTime.length?!1:this.getPointerPressed(t)&&this.context.time.time-this._pointerDownTime[t]>this._longPressTimeThreshold}getIsMouse(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="mouse"}getIsTouch(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="touch"}getTouchesPressedCount(){let t=0;for(let i=0;i<this._pointerPressed.length;i++)this._pointerPressed[i]&&this.getIsTouch(i)&&t++;return t}getMouseWheelChanged(t=0){return t>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[t]}getMouseWheelDeltaY(t=0){return t>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[t]}getPointerEvent(t){if(!(t>=this._pointerEvent.length))return this._pointerEvent[t]??void 0}*foreachPointerId(t){for(let i=0;i<this._pointerTypes.length;i++)if(this._pointerIsActive(i)){if(t!==void 0){const s=this._pointerTypes[i];if(Array.isArray(t)){let o=!1;for(const r of t)if(s===r){o=!0;break}if(!o)continue}else if(t!==s)continue}yield i}}*foreachTouchId(){for(let t=0;t<this._pointerTypes.length;t++)this._pointerTypes[t]==="touch"&&this._pointerIsActive[t]&&(yield t)}_pointerIsActive(t){return t<0?!1:this._pointerPressed[t]||this._pointerDown[t]||this._pointerUp[t]}onDownButton(t,i){let s=this._pressedStack.get(t);s||(s=[],this._pressedStack.set(t,s)),s.push(i)}onReleaseButton(t,i){const s=this._pressedStack.get(t);if(!s)return;const o=s.indexOf(i);o>=0&&s.splice(o,1)}getFirstPressedButtonForPointer(t){const i=this._pressedStack.get(t);if(i)return i[0]}getLatestPressedButtonForPointer(t){const i=this._pressedStack.get(t);if(i)return i[i.length-1]}getKeyDown(t){if(t!==void 0)return this.isKeyDown(t);for(const i in this.keysPressed){const s=this.keysPressed[i];if(s.startFrame===this.context.time.frameCount)return s.key}return null}getKeyPressed(t){if(t!==void 0)return this.isKeyPressed(t);for(const i in this.keysPressed){const s=this.keysPressed[i];if(s.pressed)return s.key}return null}getKeyUp(t){if(t!==void 0)return this.isKeyUp(t);for(const i in this.keysPressed){const s=this.keysPressed[i];return s.pressed===!1&&s.frame===this.context.time.frameCount}return null}isKeyDown(t){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(t);if(i!==null){for(const o of i)if(this.isKeyDown(o))return!0;return!1}const s=this.keysPressed[t];return s?s.startFrame===this.context.time.frameCount&&s.pressed:!1}isKeyUp(t){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(t);if(i!==null){for(const o of i)if(this.isKeyUp(o))return!0;return!1}const s=this.keysPressed[t];return s?s.frame===this.context.time.frameCount&&s.pressed===!1:!1}isKeyPressed(t){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(t);if(i!==null){for(const o of i)if(this.isKeyPressed(o))return!0;return!1}const s=this.keysPressed[t];return s&&s.pressed||!1}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":ut&&Be("Create Pointer down"),this.onDownButton(t.deviceIndex,t.button),this.onDown(t);break;case"pointermove":ut&&Be("Create Pointer move"),this.onMove(t);break;case"pointerup":ut&&Be("Create Pointer up"),this.onUp(t),this.onReleaseButton(t.deviceIndex,t.button);break}}convertScreenspaceToRaycastSpace(t){return t.x=(t.x-this.context.domX)/this.context.domWidth*2-1,t.y=-((t.y-this.context.domY)/this.context.domHeight)*2+1,t}bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){var t,i;window.removeEventListener("contextmenu",this.onContextMenu),(t=this._htmlEventSource)==null||t.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),window.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("touchend",this.onTouchEnd),(i=this._htmlEventSource)==null||i.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const t=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);t>=0&&this.context.post_render_callbacks.splice(t,1),this.unbindEvents()}canReceiveInput(t){var i;return t.target===((i=this.context.renderer)==null?void 0:i.domElement)||t.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&t.target===document.body&&Q.isMozillaXR()?!0:(ut&&console.warn("CanReceiveInput:False for",t.target),!1)}getPointerId(t,i){return t.pointerType==="mouse"?0+(i??t.button):this.getPointerIndex(t.pointerId)}getButtonName(t){const i=t.button;if(t.pointerType==="mouse")switch(i){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(t,i,s){let o=this._pointerSpace[t];o||(o=new E,this._pointerSpace[t]=o),this._pointerSpace[t]=o;const r=this.context.mainCamera;if(r){const l=this.tempNearPlaneVector.set(i,s,-1);this.convertScreenspaceToRaycastSpace(l);const c=this.tempFarPlaneVector.set(l.x,l.y,1);l.unproject(r),c.unproject(r);const h=r.worldUp||q(0,1,0).applyQuaternion(Ce(r));this.tempLookMatrix.lookAt(c,l,h),o.position.set(l.x,l.y,l.z),o.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return o}isInRect(t){if(this.context.isInXR)return!0;const i=this.context.domElement.getBoundingClientRect(),s=t.clientX,o=t.clientY,r=s>=i.x&&s<=i.right&&o>=i.y&&o<=i.bottom;return ut&&!r&&console.log("Not in rect",i,s,o),r}onDown(t){const i=t.pointerId;if(this.getPointerPressed(i)&&console.warn(`Received pointerDown for pointerId that is already pressed: ${i}`,ut?t:""),ut&&console.log(t.pointerType,"DOWN",i),!!this.isInRect(t)){for(this.setPointerState(i,this._pointerPressed,!0),this.setPointerState(i,this._pointerDown,!0),this.setPointerStateT(i,this._pointerEvent,t.source);i>=this._pointerTypes.length;)this._pointerTypes.push(t.pointerType);for(this._pointerTypes[i]=t.pointerType;i>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new x);for(this._pointerPositionDown[i].set(t.clientX,t.clientY,t.clientZ??0);i>=this._pointerPositions.length;)this._pointerPositions.push(new re);this._pointerPositions[i].set(t.clientX,t.clientY),i>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[i]=this.context.time.realtimeSinceStartup,this.updatePointerPosition(t),this._pointerEventsPressed.push(t),this.onDispatchEvent(t)}}onMove(t){const i=t.pointerId,s=this.getPointerPressed(i);s===!1&&!this.isInRect(t)||t.pointerType==="touch"&&!s||(this.updatePointerPosition(t),this.setPointerStateT(i,this._pointerEvent,t.source),this.onDispatchEvent(t))}onUp(t){const i=t.pointerId;if(!this.getPointerPressed(i)){ut&&console.log(t.pointerType,"UP",i,"was not down");return}ut&&console.log(t.pointerType,"UP",i),this.setPointerState(i,this._pointerPressed,!1),this.setPointerStateT(i,this._pointerEvent,t.source),this.setPointerState(i,this._pointerUp,!0),this.updatePointerPosition(t);for(let c=this._pointerEventsPressed.length-1;c>=0;c--)if(this._pointerEventsPressed[c].pointerId===i){this._pointerEventsPressed.splice(c,1);break}if(!this._pointerPositionDown[i]){ut&&_e("Received pointer up event without matching down event for button: "+i),console.warn("Received pointer up event without matching down event for button: "+i);return}const s=this._pointerUpTime[i],o=this._pointerDownTime[i],r=this.context.time.realtimeSinceStartup,l=r-o;if(i>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),this._pointerUpTime[i]=r,l<1){let c=t.clientX-this._pointerPositionDown[i].x,h=t.clientY-this._pointerPositionDown[i].y,d=0;if(t.isSpatial&&t.clientZ!=null&&(d=t.clientZ-this._pointerPositionDown[i].z,c*=200,h*=200,d*=200),Math.abs(c)<5&&Math.abs(h)<5&&Math.abs(d)<5){this.setPointerState(i,this._pointerClick,!0),t.isClick=!0;const u=r-s;ut&&console.log("CLICK",i,c,h,d,u),u<this._doubleClickTimeThreshold&&u>0&&(this.setPointerState(i,this._pointerDoubleClick,!0),t.isDoubleClick=!0)}}this.onDispatchEvent(t)}updatePointerPosition(t){const i=t.pointerId;for(;i>=this._pointerPositions.length;)this._pointerPositions.push(new re);for(;i>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new re);for(;i>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new re);const s=this._pointerPositionsLastFrame[i];s.copy(this._pointerPositions[i]);const o=this._pointerPositionsDelta[i];let r=t.clientX-s.x,l=t.clientY-s.y;if(t.source instanceof MouseEvent||t.source instanceof TouchEvent){const u=t.source;r===0&&u.movementX!==0&&(r=u.movementX||0),l===0&&u.movementY!==0&&(l=u.movementY||0)}o.x+=r,o.y+=l,this._pointerPositions[i].x=t.clientX,this._pointerPositions[i].y=t.clientY;const c=t.clientX,h=t.clientY;for(;i>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new re);const d=this._pointerPositionsRC[i];d.set(c,h),this.convertScreenspaceToRaycastSpace(d)}getPointerIndex(t){let i=-1;for(let s=0;s<this._pointerIds.length;s++){if(this._pointerIds[s]===t)return s;i===-1&&this._pointerIds[s]===-1&&(i=s)}return i!==-1?(this._pointerIds[i]=t,i):(ut&&console.log("PUSH pointerId:",t),this._pointerIds.push(t),this._pointerIds.length-1)}setPointerState(t,i,s){i[t]=s}setPointerStateT(t,i,s){return i[t]=s,s}onDispatchEvent(t){const i=ee.Current;try{ee.Current=this.context,this.dispatchEvent(t)}finally{ee.Current=i}}}const Ca=new se().makeRotationY(Math.PI),qi=new V().setFromAxisAngle(new x(0,1,0),Math.PI),IP=C("debugwebxr");class jP{constructor(){if(a(this,"priority",-1e5),a(this,"gameObject"),this.gameObject=new E,this.gameObject.name="Implicit XR Rig",IP){const t=fg(16733661);t.position.y+=.5,this.gameObject.add(t)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const ks=C("debugwebxr"),Ad=C("debugcustomgesture"),LP="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",DP="generic-trigger",BP=new V().setFromEuler(new zt(ys.degToRad(0),ys.degToRad(-90),ys.degToRad(-90))),FP=new x(.04,-.04,0);class tg{constructor(t,i,s){a(this,"xr"),a(this,"inputSource"),a(this,"index",0),a(this,"emitEvents",!0),a(this,"_connected",!0),a(this,"_isTracking",!1),a(this,"__gamepad"),a(this,"__hand"),a(this,"__side"),a(this,"_hitTestSource"),a(this,"_hasSelectEvent",!1),a(this,"_isMxInk",!1),a(this,"_isMetaQuestTouchController",!1),a(this,"_handJointPoses",new Map),a(this,"_gripMatrix",new se),a(this,"_gripPosition",new x),a(this,"_gripQuaternion",new V),a(this,"_linearVelocity",new x),a(this,"_rayPositionRaw",new x),a(this,"_rayRotationRaw",new V),a(this,"_rayMatrix",new se),a(this,"_rayPosition",new x),a(this,"_rayQuaternion",new V),a(this,"_gripWorldPosition",new x),a(this,"_gripWorldQuaternion",new V),a(this,"_rayWorldPosition",new x),a(this,"_rayWorldQuaternion",new V),a(this,"_pinchPosition",new x),a(this,"_ray"),a(this,"_hand_wristDotUp"),a(this,"_object"),a(this,"_gripSpaceObject"),a(this,"_raySpaceObject"),a(this,"model",null),a(this,"_debugAxesHelper",new Si(.15)),a(this,"_debugGripAxesHelper",new Si(.07)),a(this,"_debugRayAxesHelper",new Si(.07)),a(this,"_hitTestSourcePromise",null),a(this,"onPointerHits",o=>{}),a(this,"_needleGamepadButtons",{}),a(this,"_buttonMap",new Map),a(this,"_motioncontroller"),a(this,"_layout"),a(this,"getMotionController"),a(this,"emitPointerDownEvent",!0),a(this,"emitPointerUpEvent",!0),a(this,"emitPointerMoveEvent",!0),a(this,"pointerMoveDistanceThreshold",.03),a(this,"pointerMoveAngleThreshold",.05),a(this,"_selectButtonIndex"),a(this,"_squeezeButtonIndex"),a(this,"onSelectStart",o=>{var r,l,c,h;if(!this.emitPointerDownEvent||this.inputSource!==o.inputSource)return;this.onUpdateFrame(o.frame),this._hasSelectEvent=!0;const d=(r=this._layout)==null?void 0:r.selectComponentId,u=(h=(c=(l=this._layout)==null?void 0:l.components[d])==null?void 0:c.gamepadIndices)==null?void 0:h.button;u!==void 0&&(this._selectButtonIndex=u),!Ad&&(ks&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(Fe.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSelectEnd",o=>{this.emitPointerUpEvent&&(Ad||this.inputSource===o.inputSource&&this.emitPointerEvent(Fe.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSequeezeStart",o=>{var r,l,c;this.emitPointerDownEvent&&this.inputSource===o.inputSource&&(this._squeezeButtonIndex=(c=(l=(r=this._layout)==null?void 0:r.components["xr-standard-squeeze"])==null?void 0:l.gamepadIndices)==null?void 0:c.button,this._squeezeButtonIndex!==void 0&&(ks&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(Fe.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)))}),a(this,"onSequeezeEnd",o=>{this.emitPointerUpEvent&&this.inputSource===o.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(Fe.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)}),a(this,"states",{}),a(this,"_didMoveLastFrame",!1),a(this,"_lastPointerMovePosition",new x),a(this,"_lastPointerMoveQuaternion",new V),a(this,"pointerInit"),this.xr=t,this.inputSource=i,this.index=s,this._object=new E,this._object.name=`NeedleXRController_${s}`,ks&&(this._object.add(this._debugAxesHelper),this._gripSpaceObject=new E,this._raySpaceObject=new E,this._gripSpaceObject.name=`NeedleXRController_${s}_gripSpace`,this._raySpaceObject.name=`NeedleXRController_${s}_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 lo,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents()}get context(){return this.xr.context}get connected(){return this._connected}get isTracking(){return this._isTracking}get gamepad(){return this.__gamepad??(this.__gamepad=this.inputSource.gamepad)}get isHand(){return this.hand!=null}get hand(){return this.__hand??(this.__hand=this.inputSource.hand)}get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.__side??(this.__side=this.inputSource.handedness)}get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get isStylus(){return this._isMxInk}getHitTestSource(){return this._hitTestSource||this._requestHitTestSource(),this._hitTestSource}get hasHitTestSource(){return this._hitTestSource}cancelHitTestSource(){this._hitTestSource&&(this._hitTestSource.cancel(),this._hitTestSource=void 0)}get hasSelectEvent(){return this._hasSelectEvent}getHitTest(){return this.xr.getHitTest(this)}getHandJointPose(t,i){var s;if(i=i||this.xr.frame,!this.hand||!(i!=null&&i.getJointPose)||!this.xr.referenceSpace)return null;let o=(s=this._handJointPoses)==null?void 0:s.get(t);return o||(o=i.getJointPose(t,this.xr.referenceSpace),o&&this._handJointPoses.set(t,o),o)}get gripPosition(){return q(this._gripPosition)}get gripQuaternion(){return yn(this._gripQuaternion)}get gripMatrix(){return this._gripMatrix}get gripLinearVelocity(){return q(this._linearVelocity).applyQuaternion(qi)}get rayPosition(){return q(this._rayPosition)}get rayQuaternion(){return yn(this._rayQuaternion)}get gripWorldPosition(){return q(this._gripWorldPosition)}get gripWorldQuaternion(){return yn(this._gripWorldQuaternion)}get rayWorldPosition(){return q(this._rayWorldPosition)}updateRayWorldPosition(){var t;const i=(t=this.xr.context.mainCamera)==null?void 0:t.parent;this._rayWorldPosition.copy(this._rayPositionRaw),i&&this._rayWorldPosition.applyMatrix4(i.matrixWorld)}get rayWorldQuaternion(){return yn(this._rayWorldQuaternion)}get pinchPosition(){return q(this._pinchPosition)}updateRayWorldQuaternion(){var t;const i=(t=this.xr.context.mainCamera)==null?void 0:t.parent,s=i?Ce(i):void 0;this._rayWorldQuaternion.copy(this._rayRotationRaw).multiply(qi),s&&this._rayWorldQuaternion.premultiply(s)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(q(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get handWristDotUp(){var t;if(this._hand_wristDotUp!==void 0)return this._hand_wristDotUp;const i=(t=this.handObject)==null?void 0:t.joints.wrist;if(i){const s=q(0,1,0).applyQuaternion(i.quaternion),o=q(0,1,0).dot(s);return this._hand_wristDotUp=o}}get isHandUpsideDown(){return this.handWristDotUp!==void 0?this.handWristDotUp<-.7:!1}get isTeleportGesture(){var t;return this.isHandUpsideDown&&((t=this.getGesture("pinch"))==null?void 0:t.isDown)}get object(){return this._object}async getModelUrl(){var t;return(t=this.getMotionController)==null?void 0:t.then(i=>i?.assetUrl||null)}_requestHitTestSource(){var t;return this._hitTestSourcePromise?this._hitTestSourcePromise:this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&this.xr.session.requestHitTestSourceForTransientInput?this._hitTestSourcePromise=((t=this.xr.session.requestHitTestSourceForTransientInput({profile:this.inputSource.profiles[0],offsetRay:new XRRay}))==null?void 0:t.then(i=>(this._hitTestSourcePromise=null,this.connected?this._hitTestSource=i:(i.cancel(),null))))??null:null}onUpdate(t){this.onUpdateFrame(t),this.updateInputEvents(),this.onUpdateMove()}onRenderDebug(){var t;$.DrawSphere(this.rayWorldPosition,.003),$.DrawDirection(this.rayWorldPosition,q(0,0,10).applyQuaternion(this.rayWorldQuaternion));const i=(this.inputSource.gripSpace?this.gripWorldPosition:this.object.worldPosition).sub(this.object.worldForward.multiplyScalar(.1)),s=this.inputSource.profiles.join(`
135
135
  `);let o=`Controller[${this.index}] (${this.inputSource.targetRayMode}, ${this.side})
136
136
  C:${this.connected?"x":"-"} T:${this.isTracking?"x":"-"} Hand:${this.inputSource.hand?"x":"-"} Pen: ${this._isMxInk?"x":"-"}`;if(this.inputSource.hand&&(o+=`
@@ -1399,7 +1399,7 @@ void main() {
1399
1399
  ${p}
1400
1400
 
1401
1401
  This could mean you forgot to add a npmdef to your ExportInfo
1402
- <a href="https://engine.needle.tools/docs/project_structure.html#creating-and-installing-a-npmdef" target="_blank">documentation</a>`,Pi.Warn)}}if(t.children)for(const u of t.children)await ky(n,u,i)}function Ej(n,t){const{instance:i,compData:s,obj:o}=n;t.object=o,t.target=i,Yd(i,s,t),Xh&&console.debug("add "+s.name,s,i)}const zl=[],Jp=[];var My;(n=>{function t(s,o){const r={name:o?.name,priority:o?.priority??0,callback:s};return zl.push(r),zl.sort((l,c)=>l.priority===c.priority?0:l.priority>c.priority?-1:1),()=>{const l=zl.indexOf(r);l>=0&&zl.splice(l,1)}}n.onCreateCustomModelLoader=t;function i(s){return Jp.push(s),()=>{const o=Jp.indexOf(s);o>=0&&Jp.splice(o,1)}}n.onDetermineModelMimetype=i})(My||(My={}));const Yh=C("debugfileformat");async function $1(n,t){var i;const{useExtension:s=!0}=t;if(s){const l=n,c=new URL(l,globalThis.location.origin);let h=null;const d=c.searchParams.get("filetype");switch(d&&(h=d.toUpperCase()),h!=null&&h.length||(h=(i=c.pathname.split(".").pop())==null?void 0:i.toUpperCase()),Yh&&console.warn(`[Needle Engine] Try to use file extension to determine type: '${h}'`),h){case"GLTF":return"model/gltf+json";case"VRM":return"model/vrm";case"GLB":return"model/gltf-binary";case"FBX":return"model/fbx";case"USD":return"model/vnd.usd+zip";case"USDA":return"model/vnd.usda+zip";case"USDZ":return"model/vnd.usdz+zip";case"OBJ":return"model/obj"}}const o=n;if(!n.startsWith("blob:")){const l=new URL(n);l.searchParams.append("range","true"),n=l.toString()}const r=await fetch(n,{method:"GET",headers:{range:"bytes=0-32"}}).catch(l=>null);if(r!=null&&r.ok){const l=await r.arrayBuffer(),c=G1(o,l,r);return Yh&&console.log("[Needle Engine] Determined file type from header: "+c),c}return"unknown"}function G1(n,t,i){if(t.byteLength<4)return"unknown";const s=new Uint8Array(t);if(Yh&&console.warn(`[Needle Engine] Trying to determine file type from binary data
1402
+ <a href="https://engine.needle.tools/docs/project_structure.html#creating-and-installing-a-npmdef" target="_blank">documentation</a>`,Pi.Warn)}}if(t.children)for(const u of t.children)await ky(n,u,i)}function Ej(n,t){const{instance:i,compData:s,obj:o}=n;t.object=o,t.target=i,Yd(i,s,t),Xh&&console.debug("add "+s.name,s,i)}const zl=[],Jp=[];var My;(n=>{function t(s,o){const r={name:o?.name,priority:o?.priority??0,callback:s};return zl.push(r),zl.sort((l,c)=>l.priority===c.priority?0:l.priority>c.priority?-1:1),()=>{const l=zl.indexOf(r);l>=0&&zl.splice(l,1)}}n.onCreateCustomModelLoader=t;function i(s){return Jp.push(s),()=>{const o=Jp.indexOf(s);o>=0&&Jp.splice(o,1)}}n.onDetermineModelMimetype=i})(My||(My={}));const Yh=C("debugfileformat");async function $1(n,t){var i;const{useExtension:s=!0}=t;if(s){const l=n,c=new URL(l,globalThis.location.href);let h=null;const d=c.searchParams.get("filetype");switch(d&&(h=d.toUpperCase()),h!=null&&h.length||(h=(i=c.pathname.split(".").pop())==null?void 0:i.toUpperCase()),Yh&&console.warn(`[Needle Engine] Try to use file extension to determine type: '${h}'`),h){case"GLTF":return"model/gltf+json";case"VRM":return"model/vrm";case"GLB":return"model/gltf-binary";case"FBX":return"model/fbx";case"USD":return"model/vnd.usd+zip";case"USDA":return"model/vnd.usda+zip";case"USDZ":return"model/vnd.usdz+zip";case"OBJ":return"model/obj"}}const o=n;if(!n.startsWith("blob:")){const l=new URL(n,globalThis.location.href);l.searchParams.append("range","true"),n=l.toString()}const r=await fetch(n,{method:"GET",headers:{range:"bytes=0-32"}}).catch(l=>null);if(r!=null&&r.ok){const l=await r.arrayBuffer(),c=G1(o,l,r);return Yh&&console.log("[Needle Engine] Determined file type from header: "+c),c}return"unknown"}function G1(n,t,i){if(t.byteLength<4)return"unknown";const s=new Uint8Array(t);if(Yh&&console.warn(`[Needle Engine] Trying to determine file type from binary data
1403
1403
  `,'"'+new TextDecoder().decode(t)+`"
1404
1404
  `,s),s[0]==103&&s[1]==108&&s[2]==84&&s[3]==70&&s[4]==10)return console.debug("GLTF detected"),"model/gltf+json";if(s[0]==103&&s[1]==108&&s[2]==84&&s[3]==70&&s[4]==98)return console.debug("GLB detected"),"model/gltf-binary";if(s[0]==80&&s[1]==75&&s[2]==3&&s[3]==4)return console.debug("USDZ detected"),"model/vnd.usdz+zip";if(s[0]==80&&s[1]==88&&s[2]==82&&s[3]==45&&s[4]==85&&s[5]==83&&s[6]==68&&s[7]==67)return console.debug("Binary USD detected"),"model/vnd.usd";if(s[0]==35&&s[1]==117&&s[2]==115&&s[3]==100&&s[4]==97)return console.debug("ASCII USD detected"),"model/vnd.usda";if(s[0]==75&&s[1]==97&&s[2]==121&&s[3]==100&&s[4]==97&&s[5]==114&&s[6]==97&&s[7]==32)return console.debug("Binary FBX detected"),"model/fbx";if(s[0]==59&&s[1]==32&&s[2]==70&&s[3]==66&&s[4]==88&&s[5]==32)return console.debug("ASCII FBX detected"),"model/fbx";if(s[0]==35&&s[1]==32&&s[2]==66&&s[3]==108&&s[4]==101&&s[5]==110&&s[6]==100&&s[7]==101&&s[8]==114&&s[9]==32||s[0]==35&&s[1]==32&&s[2]==65&&s[3]==108&&s[4]==105&&s[5]==97&&s[6]==115&&s[7]==32&&s[8]==79&&s[9]==66&&s[10]==74)return console.debug("OBJ detected"),"model/obj";if(i.headers.has("content-type")){const o=i.headers.get("content-type");switch(console.debug("Content-Type: "+o),o){case"model/gltf+json":case"model/gltf-binary":case"model/vrm":case"model/vnd.usdz+zip":case"model/vnd.usd+zip":case"model/vnd.usd":case"model/vnd.usda+zip":case"model/vnd.usda":case"model/vnd.usdc":case"model/fbx":case"model/vnd.autodesk.fbx":case"model/obj":return o}}if(s[0]==118&&s[1]==32||s[0]==102&&s[1]==32)return console.debug("OBJ detected (the file has no header and starts with vertex or face)"),"obj";if(s[0]==35&&s[1]==32&&s[2]==70&&s[3]==105&&s[4]==108&&s[5]==101&&s[6]==32&&s[7]==101&&s[8]==120&&s[9]==112&&s[10]==111&&s[11]==114&&s[12]==116&&s[13]==101&&s[14]==100&&s[15]==32&&s[16]==98&&s[17]==121&&s[18]==32&&s[19]==90&&s[20]==66&&s[21]==114&&s[22]==117&&s[23]==115&&s[24]==104)return console.debug("OBJ detected (exported by ZBrush)"),"obj";if(s[0]==109&&s[1]==116&&s[2]==108&&s[3]==108&&s[4]==105&&s[5]==98)return console.debug("OBJ detected (mtllib)"),"obj";for(const o of Jp){const r=o({url:n,response:i,contentType:i.headers.get("content-type"),bytes:s});if(r)return Yh&&console.debug(`Mimetype callback returned: ${r}`),r}if(B()||Yh){const o=new TextDecoder().decode(t.slice(0,Math.min(t.byteLength,32)));console.warn(`Could not determine file type.
1405
1405
 
@@ -1792,15 +1792,15 @@ function TC() {
1792
1792
  return s || null;
1793
1793
  }
1794
1794
  const z0 = x("debugdefines");
1795
- Ro('if(!globalThis[""4.5.0""]) globalThis[""4.5.0""] = "0.0.0";');
1795
+ Ro('if(!globalThis[""4.5.2""]) globalThis[""4.5.2""] = "0.0.0";');
1796
1796
  Ro('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');
1797
- Ro('if(!globalThis[""Wed May 21 2025 11:59:15 GMT+0200 (Central European Summer Time)""]) globalThis[""Wed May 21 2025 11:59:15 GMT+0200 (Central European Summer Time)""] = "unknown";');
1797
+ Ro('if(!globalThis[""Fri May 30 2025 15:56:44 GMT+0200 (Central European Summer Time)""]) globalThis[""Fri May 30 2025 15:56:44 GMT+0200 (Central European Summer Time)""] = "unknown";');
1798
1798
  Ro('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";');
1799
- Ro('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.5.0";');
1799
+ Ro('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.5.2";');
1800
1800
  Ro('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');
1801
- Ro('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Wed May 21 2025 11:59:15 GMT+0200 (Central European Summer Time)";');
1801
+ Ro('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Fri May 30 2025 15:56:44 GMT+0200 (Central European Summer Time)";');
1802
1802
  Ro('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');
1803
- const Vn = "4.5.0", bg = "undefined", U0 = "Wed May 21 2025 11:59:15 GMT+0200 (Central European Summer Time)";
1803
+ const Vn = "4.5.2", bg = "undefined", U0 = "Fri May 30 2025 15:56:44 GMT+0200 (Central European Summer Time)";
1804
1804
  z0 && console.log(`Engine version: ${Vn} (generator: ${bg})
1805
1805
  Project built at ${U0}`);
1806
1806
  const md = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9", _o = "needle_isActiveInHierarchy", sa = "builtin_components", gd = "needle_editor_guid";
@@ -40709,7 +40709,7 @@ async function gI(s, t) {
40709
40709
  var o;
40710
40710
  const { useExtension: e = !0 } = t;
40711
40711
  if (e) {
40712
- const a = s, l = new URL(a, globalThis.location.origin);
40712
+ const a = s, l = new URL(a, globalThis.location.href);
40713
40713
  let c = null;
40714
40714
  const h = l.searchParams.get("filetype");
40715
40715
  switch (h && (c = h.toUpperCase()), c != null && c.length || (c = (o = l.pathname.split(".").pop()) == null ? void 0 : o.toUpperCase()), Cc && console.warn(`[Needle Engine] Try to use file extension to determine type: '${c}'`), c) {
@@ -40733,7 +40733,7 @@ async function gI(s, t) {
40733
40733
  }
40734
40734
  const i = s;
40735
40735
  if (!s.startsWith("blob:")) {
40736
- const a = new URL(s);
40736
+ const a = new URL(s, globalThis.location.href);
40737
40737
  a.searchParams.append("range", "true"), s = a.toString();
40738
40738
  }
40739
40739
  const n = await fetch(s, {
@@ -130,7 +130,7 @@ Open this page to get the console: `+t.toString())}const n=Q.isMobileDevice()||Q
130
130
  #__vconsole .vc-mask {
131
131
  overflow: hidden;
132
132
  }
133
- `,Gi?.prepend(s),n===!0&&Em()<=0&&nb(),console.log("\u{1F335} Debug console has loaded")}},t.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),sc=!1,ri=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function CP(){if(!globalThis.VConsole)return;const n=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+n._id+" iframe");return n.on("renderTab",function(i){const s=globalThis["needle:codegen_files"];if(!s||s.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);n.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';i(h)}),n.on("show",function(){const i=t();i&&i.src!==n.fullUrl&&(i.src=n.fullUrl)}),n.on("hide",function(){const i=t();i&&(i.src="")}),n.on("addTopBar",function(i){var s=new Array;s.push({name:"Open in new window \u2197",onClick:function(o){window.open(n.fullUrl,"_blank"),ri?.hide()}}),s.push({name:"Reload",onClick:function(o){const r=t();r&&(r.src=n.fullUrl)}}),s.push({name:"Fullscreen",onClick:function(o){const r=t();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),i(s)}),n}function OP(){return document.querySelector("#__vconsole .vc-switch")||null}function PP(){return document.querySelector("#__vconsole")||null}const ab=C("debugdefines");fo('if(!globalThis[""4.5.0""]) globalThis[""4.5.0""] = "0.0.0";'),fo('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),fo('if(!globalThis[""Wed May 21 2025 11:59:15 GMT+0200 (Central European Summer Time)""]) globalThis[""Wed May 21 2025 11:59:15 GMT+0200 (Central European Summer Time)""] = "unknown";'),fo('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";'),fo('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.5.0";'),fo('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),fo('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Wed May 21 2025 11:59:15 GMT+0200 (Central European Summer Time)";'),fo('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');const bn="4.5.0",kd="undefined",Ym="Wed May 21 2025 11:59:15 GMT+0200 (Central European Summer Time)";ab&&console.log(`Engine version: ${bn} (generator: ${kd})
133
+ `,Gi?.prepend(s),n===!0&&Em()<=0&&nb(),console.log("\u{1F335} Debug console has loaded")}},t.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),sc=!1,ri=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function CP(){if(!globalThis.VConsole)return;const n=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+n._id+" iframe");return n.on("renderTab",function(i){const s=globalThis["needle:codegen_files"];if(!s||s.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);n.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';i(h)}),n.on("show",function(){const i=t();i&&i.src!==n.fullUrl&&(i.src=n.fullUrl)}),n.on("hide",function(){const i=t();i&&(i.src="")}),n.on("addTopBar",function(i){var s=new Array;s.push({name:"Open in new window \u2197",onClick:function(o){window.open(n.fullUrl,"_blank"),ri?.hide()}}),s.push({name:"Reload",onClick:function(o){const r=t();r&&(r.src=n.fullUrl)}}),s.push({name:"Fullscreen",onClick:function(o){const r=t();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),i(s)}),n}function OP(){return document.querySelector("#__vconsole .vc-switch")||null}function PP(){return document.querySelector("#__vconsole")||null}const ab=C("debugdefines");fo('if(!globalThis[""4.5.2""]) globalThis[""4.5.2""] = "0.0.0";'),fo('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),fo('if(!globalThis[""Fri May 30 2025 15:56:44 GMT+0200 (Central European Summer Time)""]) globalThis[""Fri May 30 2025 15:56:44 GMT+0200 (Central European Summer Time)""] = "unknown";'),fo('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";'),fo('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.5.2";'),fo('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),fo('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Fri May 30 2025 15:56:44 GMT+0200 (Central European Summer Time)";'),fo('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');const bn="4.5.2",kd="undefined",Ym="Fri May 30 2025 15:56:44 GMT+0200 (Central European Summer Time)";ab&&console.log(`Engine version: ${bn} (generator: ${kd})
134
134
  Project built at ${Ym}`);const rc="npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9",Os="needle_isActiveInHierarchy",pr="builtin_components",ac="needle_editor_guid";function fo(n){try{(0,eval)(n)}catch(t){ab&&console.error(t)}}let lb,cb=null;function _n(){return lb}function Km(n){if(n==null){console.warn("Oh no: someone tried registering a non-existend gltf-loader. When you see this log it might mean that needle-engine is being imported multiple times. Please check your project setup.");return}cb!==n&&(cb=n,lb=new n)}const ki=Symbol("shadowDomOwner"),kP=C("debugpatch");function Md(n,t,i,s){const o=kP===t;if(!i&&!s)return;const r=t+"___needle";RP(n,t,i,s);const l=Object.getOwnPropertyDescriptor(n,t),c=n[t];o&&console.log("Patch",n.constructor.name,t,l,c),l?(o&&console.log("Apply patch with existing descriptor",n.constructor.name,t,l),typeof l.value=="function"&&(n[t]=db(l.value,n,t))):(o&&console.log("Create patch with new property",n.constructor.name,t,l),Object.defineProperty(n,t,{set:function(h){if(typeof h=="function")this[r]=db(h,n,t);else{const d=this[r];ub(n,t,this,d,h),this[r]=h,pb(n,t,this,d,h)}},get:function(){const h=this[r];return typeof h=="function"&&h[r]?h[r]:h}}))}function MP(n,t,i){const s=Jm(n,t);if(s)for(let o=s.length-1;o>=0;o--){const r=s[o];r.prefix===i&&(r.prefix=null),r.postfix===i&&(r.postfix=null),!r.prefix&&!r.postfix&&s.splice(o,1)}}const hb=Symbol("Needle:Patches:WrappedFunction");function db(n,t,i){if(n[hb])return n;const s=function(...o){ub(t,i,this,...o);const r=n.apply(this,o);return pb(t,i,this,r,...o),r};return s[hb]=!0,s}const Rd="Needle:Patches";function Zm(){return globalThis[Rd]||(globalThis[Rd]=new WeakMap),globalThis[Rd]}function Jm(n,t){const i=Zm().get(n);return i?i.get(t):null}function RP(n,t,i,s){let o=Zm().get(n);o||(o=new Map,Zm().set(n,o));let r=o.get(t);r||(r=[],o.set(t,r)),r.push({prefix:i,postfix:s})}function ub(n,t,i,...s){var o;if(!i)return;const r=Jm(n,t);if(r)for(const l of r)(o=l.prefix)==null||o.call(i,...s)}function pb(n,t,i,s,...o){var r;if(!i)return;const l=Jm(n,t);if(l)for(const c of l)(r=c.postfix)==null||r.call(i,s,...o)}const xa=[];function Td(n){xa.indexOf(n)===-1&&xa.push(n)}function TP(n){const t=xa.indexOf(n);t!==-1&&xa.splice(t,1)}const Sa=[];function eg(n){Sa.indexOf(n)===-1&&Sa.push(n)}function EP(n){const t=Sa.indexOf(n);t!==-1&&Sa.splice(t,1)}function mb(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:n}));for(let t=0;t<xa.length;t++)xa[t](n)}function gb(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:n}));for(let t=0;t<Sa.length;t++)Sa[t](n)}const dt=C("debuginput");var Ed=(n=>(n.Mouse="mouse",n.Touch="touch",n.Controller="controller",n.Hand="hand",n))(Ed||{}),Fe=(n=>(n.PointerDown="pointerdown",n.PointerUp="pointerup",n.PointerMove="pointermove",n.KeyDown="keydown",n.KeyUp="keyup",n.KeyPressed="keypress",n))(Fe||{});class Ps extends PointerEvent{constructor(t,i,s){super(t,s),a(this,"clientZ"),a(this,"deviceIndex"),a(this,"origin"),a(this,"source"),a(this,"mode"),a(this,"_ray"),a(this,"space"),a(this,"isClick",!1),a(this,"isDoubleClick",!1),a(this,"_used",!1),a(this,"_pointerid"),a(this,"_pointerType"),a(this,"_type"),a(this,"metadata",{}),a(this,"intersections",new Array),a(this,"_immediatePropagationStopped",!1),a(this,"_propagationStopped",!1),this.clientZ=s.clientZ,this._pointerid=s.pointerId,this._pointerType=s.pointerType,this._type=t,this.deviceIndex=s.deviceIndex,this.origin=s.origin,this.source=i,this.mode=s.mode,this._ray=s.ray,this.space=s.device}get isSpatial(){return this.mode!="screen"}get ray(){return this._ray||(this._ray=new co(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(t){this._ray=t}get hasRay(){return this._ray!==void 0}get used(){return this._used}use(){this._used=!0}get pointerId(){return this._pointerid}get pointerType(){return this._pointerType}get type(){return this._type}get immediatePropagationStopped(){return this._immediatePropagationStopped}get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){var t;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(t=this.source)==null||t.stopImmediatePropagation()}stopPropagation(){var t;this._propagationStopped=!0,super.stopPropagation(),(t=this.source)==null||t.stopPropagation(),dt&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class lc extends KeyboardEvent{constructor(t,i,s){super(t,s),a(this,"source"),this.source=i}stopImmediatePropagation(){var t;super.stopImmediatePropagation(),(t=this.source)==null||t.stopImmediatePropagation()}}class AP{constructor(t){a(this,"key"),a(this,"keyType"),a(this,"source"),this.key=t.key,this.keyType=t.type,this.source=t}}var ai=(n=>(n[n.Early=-100]="Early",n[n.Default=0]="Default",n[n.Late=100]="Late",n))(ai||{});class fb{constructor(t){a(this,"_eventListeners",{}),a(this,"_doubleClickTimeThreshold",.2),a(this,"_longPressTimeThreshold",1),a(this,"_setCursorTypes",[]),a(this,"context"),a(this,"_pointerDown",[!1]),a(this,"_pointerUp",[!1]),a(this,"_pointerClick",[!1]),a(this,"_pointerDoubleClick",[!1]),a(this,"_pointerPressed",[!1]),a(this,"_pointerPositions",[new re]),a(this,"_pointerPositionsLastFrame",[new re]),a(this,"_pointerPositionsDelta",[new re]),a(this,"_pointerPositionsRC",[new re]),a(this,"_pointerPositionDown",[new x]),a(this,"_pointerDownTime",[]),a(this,"_pointerUpTime",[]),a(this,"_pointerUpTimestamp",[]),a(this,"_pointerIds",[]),a(this,"_pointerTypes",[""]),a(this,"_mouseWheelChanged",[!1]),a(this,"_mouseWheelDeltaY",[0]),a(this,"_pointerEvent",[]),a(this,"_pointerEventsPressed",[]),a(this,"_pointerSpace",[]),a(this,"_pressedStack",new Map),a(this,"_htmlEventSource"),a(this,"onLostFocus",()=>{for(const i in this.keysPressed)this.keysPressed[i].pressed=!1}),a(this,"_receivedPointerMoveEventsThisFrame",new Array),a(this,"onEndOfFrame",()=>{this._receivedPointerMoveEventsThisFrame.length=0;for(let i=0;i<this._pointerUp.length;i++)this._pointerUp[i]=!1;for(let i=0;i<this._pointerDown.length;i++)this._pointerDown[i]=!1;for(let i=0;i<this._pointerClick.length;i++)this._pointerClick[i]=!1;for(let i=0;i<this._pointerDoubleClick.length;i++)this._pointerDoubleClick[i]=!1;for(const i of this._pointerPositionsDelta)i.set(0,0);for(let i=0;i<this._mouseWheelChanged.length;i++)this._mouseWheelChanged[i]=!1;for(let i=0;i<this._mouseWheelDeltaY.length;i++)this._mouseWheelDeltaY[i]=0}),a(this,"onContextMenu",i=>{this.canReceiveInput(i)!==!1&&i instanceof PointerEvent&&i.pointerType}),a(this,"keysPressed",{}),a(this,"onKeyDown",i=>{if(dt&&console.log(`key down ${i.code}, ${this.context.application.hasFocus}`,i),!this.context.application.hasFocus)return;const s=this.keysPressed[i.code];if(s&&s.pressed)return;this.keysPressed[i.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:i.key,code:i.code};const o=new lc("keydown",i,i);this.onDispatchEvent(o)}),a(this,"onKeyPressed",i=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[i.code];if(!s)return;s.pressed=!0,s.frame=this.context.time.frameCount+1;const o=new lc("keypress",i,i);this.onDispatchEvent(o)}),a(this,"onKeyUp",i=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[i.code];if(!s)return;s.pressed=!1,s.frame=this.context.time.frameCount+1;const o=new lc("keyup",i,i);this.onDispatchEvent(o)}),a(this,"onWheelWindow",i=>{document.pointerLockElement&&this.onMouseWheel(i)}),a(this,"onMouseWheel",i=>{if(this.canReceiveInput(i)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const s=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=s+i.deltaY}),a(this,"onPointerDown",i=>{if(this.context.isInAR||this.canReceiveInput(i)===!1)return;i.target instanceof HTMLElement&&i.target.setPointerCapture(i.pointerId);const s=this.getPointerId(i);dt&&Be(`pointer down #${s}, identifier:${i.pointerId}`);const o=this.getAndUpdateSpatialObjectForScreenPosition(s,i.clientX,i.clientY),r=new Ps("pointerdown",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:i.button,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:o,pressure:i.pressure});this.onDown(r)}),a(this,"onPointerMove",i=>{if(this.context.isInAR||this._receivedPointerMoveEventsThisFrame.includes(i.pointerId))return;this._receivedPointerMoveEventsThisFrame.push(i.pointerId);let s=i.button;i.pointerType==="mouse"&&(s=this.getFirstPressedButtonForPointer(0)??0);const o=this.getPointerId(i,s);s===-1&&(s=o);const r=this.getAndUpdateSpatialObjectForScreenPosition(o,i.clientX,i.clientY),l=new Ps("pointermove",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:o,button:s,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:r,pressure:i.pressure});this.onMove(l)}),a(this,"onPointerCancel",i=>{this.context.isInAR||(dt&&console.log("Pointer cancel",i),this.onPointerUp(i))}),a(this,"onPointerUp",i=>{if(this.context.isInAR)return;i.target instanceof HTMLElement&&i.target.releasePointerCapture(i.pointerId);const s=this.getPointerId(i),o=new Ps("pointerup",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:i.button,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:this.getAndUpdateSpatialObjectForScreenPosition(s,i.clientX,i.clientY),pressure:i.pressure});this.onUp(o),this._pointerIds[s]=-1,dt&&console.log("ID="+s,"PointerId="+i.pointerId,"ALL:",[...this._pointerIds])}),a(this,"onTouchStart",i=>{if(this.context.isInAR)for(let s=0;s<i.changedTouches.length;s++){const o=i.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new Ps("pointerdown",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onDown(c)}}),a(this,"onTouchMove",i=>{if(this.context.isInAR)for(let s=0;s<i.changedTouches.length;s++){const o=i.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new Ps("pointermove",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onMove(c)}}),a(this,"onTouchEnd",i=>{if(this.context.isInAR)for(let s=0;s<i.changedTouches.length;s++){const o=i.changedTouches[s],r=this.getPointerIndex(o.identifier),l=new Ps("pointerup",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),pressure:o.force});this.onUp(l),this._pointerIds[r]=-1}}),a(this,"tempNearPlaneVector",new x),a(this,"tempFarPlaneVector",new x),a(this,"tempLookMatrix",new se),this.context=t,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(t,i,s){if(this._eventListeners[t]||(this._eventListeners[t]=[]),!i||typeof i!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}s?s={...s}:s={};let o=0;s?.queue!=null&&(o=s.queue);const r=this._eventListeners[t],l=r.find(c=>c.priority===o);l?l.listeners.push({callback:i,options:s}):(r.push({priority:o,listeners:[{callback:i,options:s}]}),r.sort((c,h)=>c.priority-h.priority))}removeEventListener(t,i,s){if(!this._eventListeners[t]||!i)return;const o=this._eventListeners[t];if(s?.queue!=null){const r=o.find(c=>c.priority===s.queue);if(!r)return;const l=r.listeners.findIndex(c=>c.callback===i);l>=0&&r.listeners.splice(l,1)}else for(const r of o){const l=r.listeners.findIndex(c=>c.callback===i);l>=0&&r.listeners.splice(l,1)}}dispatchEvent(t){var i,s,o,r;let l=!1;if(t instanceof lc){const c=this._eventListeners[t.type];if(c)for(const h of c)for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((s=(i=u.options)==null?void 0:i.signal)!=null&&s.aborted){h.listeners.splice(d,1),d--;continue}u.options.once&&(h.listeners.splice(d,1),d--),u.callback(t)}}if(t instanceof Ps){const c=this._eventListeners[t.type];if(c)for(const h of c){if(l)break;for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((r=(o=u.options)==null?void 0:o.signal)!=null&&r.aborted){h.listeners.splice(d,1),d--;continue}if(t.immediatePropagationStopped){l=!0,dt&&console.log("immediatePropagationStopped",t.type);break}else t.propagationStopped&&(l=!0,dt&&console.log("propagationStopped",t.type));u.options.once&&(h.listeners.splice(d,1),d--),u.callback(t)}}}}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}get click(){return this._pointerClick[0]}get doubleClick(){return this._pointerDoubleClick[0]}getGamepad(t=0){return typeof navigator<"u"&&"getGamepads"in navigator&&navigator.getGamepads()[t]||null}setCursorPointer(){this.setCursor("pointer")}setCursorNormal(){this.unsetCursor("pointer")}setCursor(t){this._setCursorTypes.push(t),this._setCursorTypes.length>10&&this._setCursorTypes.shift(),this.updateCursor()}unsetCursor(t){for(let i=this._setCursorTypes.length-1;i>=0;i--)if(this._setCursorTypes[i]===t){this._setCursorTypes.splice(i,1),this.updateCursor();break}}updateCursor(){var t;((t=this._setCursorTypes)==null?void 0:t.length)==0?this.context.domElement.style.cursor="default":this.context.domElement.style.cursor=this._setCursorTypes[this._setCursorTypes.length-1]}getIsPointerIdInUse(t){for(const i of this._pointerEventsPressed)if(i.pointerId===t&&i.used)return!0;return!1}getPointerPressedCount(){let t=0;for(let i=0;i<this._pointerPressed.length;i++)this._pointerPressed[i]&&t++;return t}getPointerPosition(t){return t>=this._pointerPositions.length?null:this._pointerPositions[t]}getPointerPositionLastFrame(t){return t>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[t]}getPointerPositionDelta(t){return t>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[t]}getPointerPositionRC(t){return t>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[t]}getPointerDown(t){return t>=this._pointerDown.length?!1:this._pointerDown[t]}getPointerUp(t){return t>=this._pointerUp.length?!1:this._pointerUp[t]}getPointerPressed(t){return t>=this._pointerPressed.length?!1:this._pointerPressed[t]}getPointerClicked(t){return t>=this._pointerClick.length?!1:this._pointerClick[t]}getPointerDoubleClicked(t){return t>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[t]}getPointerDownTime(t){return t>=this._pointerDownTime.length?-1:this._pointerDownTime[t]}getPointerUpTime(t){return t>=this._pointerUpTime.length?-1:this._pointerUpTime[t]}getPointerLongPress(t){return t>=this._pointerDownTime.length?!1:this.getPointerPressed(t)&&this.context.time.time-this._pointerDownTime[t]>this._longPressTimeThreshold}getIsMouse(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="mouse"}getIsTouch(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="touch"}getTouchesPressedCount(){let t=0;for(let i=0;i<this._pointerPressed.length;i++)this._pointerPressed[i]&&this.getIsTouch(i)&&t++;return t}getMouseWheelChanged(t=0){return t>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[t]}getMouseWheelDeltaY(t=0){return t>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[t]}getPointerEvent(t){if(!(t>=this._pointerEvent.length))return this._pointerEvent[t]??void 0}*foreachPointerId(t){for(let i=0;i<this._pointerTypes.length;i++)if(this._pointerIsActive(i)){if(t!==void 0){const s=this._pointerTypes[i];if(Array.isArray(t)){let o=!1;for(const r of t)if(s===r){o=!0;break}if(!o)continue}else if(t!==s)continue}yield i}}*foreachTouchId(){for(let t=0;t<this._pointerTypes.length;t++)this._pointerTypes[t]==="touch"&&this._pointerIsActive[t]&&(yield t)}_pointerIsActive(t){return t<0?!1:this._pointerPressed[t]||this._pointerDown[t]||this._pointerUp[t]}onDownButton(t,i){let s=this._pressedStack.get(t);s||(s=[],this._pressedStack.set(t,s)),s.push(i)}onReleaseButton(t,i){const s=this._pressedStack.get(t);if(!s)return;const o=s.indexOf(i);o>=0&&s.splice(o,1)}getFirstPressedButtonForPointer(t){const i=this._pressedStack.get(t);if(i)return i[0]}getLatestPressedButtonForPointer(t){const i=this._pressedStack.get(t);if(i)return i[i.length-1]}getKeyDown(t){if(t!==void 0)return this.isKeyDown(t);for(const i in this.keysPressed){const s=this.keysPressed[i];if(s.startFrame===this.context.time.frameCount)return s.key}return null}getKeyPressed(t){if(t!==void 0)return this.isKeyPressed(t);for(const i in this.keysPressed){const s=this.keysPressed[i];if(s.pressed)return s.key}return null}getKeyUp(t){if(t!==void 0)return this.isKeyUp(t);for(const i in this.keysPressed){const s=this.keysPressed[i];return s.pressed===!1&&s.frame===this.context.time.frameCount}return null}isKeyDown(t){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(t);if(i!==null){for(const o of i)if(this.isKeyDown(o))return!0;return!1}const s=this.keysPressed[t];return s?s.startFrame===this.context.time.frameCount&&s.pressed:!1}isKeyUp(t){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(t);if(i!==null){for(const o of i)if(this.isKeyUp(o))return!0;return!1}const s=this.keysPressed[t];return s?s.frame===this.context.time.frameCount&&s.pressed===!1:!1}isKeyPressed(t){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(t);if(i!==null){for(const o of i)if(this.isKeyPressed(o))return!0;return!1}const s=this.keysPressed[t];return s&&s.pressed||!1}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":dt&&Be("Create Pointer down"),this.onDownButton(t.deviceIndex,t.button),this.onDown(t);break;case"pointermove":dt&&Be("Create Pointer move"),this.onMove(t);break;case"pointerup":dt&&Be("Create Pointer up"),this.onUp(t),this.onReleaseButton(t.deviceIndex,t.button);break}}convertScreenspaceToRaycastSpace(t){return t.x=(t.x-this.context.domX)/this.context.domWidth*2-1,t.y=-((t.y-this.context.domY)/this.context.domHeight)*2+1,t}bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){var t,i;window.removeEventListener("contextmenu",this.onContextMenu),(t=this._htmlEventSource)==null||t.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),window.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("touchend",this.onTouchEnd),(i=this._htmlEventSource)==null||i.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const t=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);t>=0&&this.context.post_render_callbacks.splice(t,1),this.unbindEvents()}canReceiveInput(t){var i;return t.target===((i=this.context.renderer)==null?void 0:i.domElement)||t.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&t.target===document.body&&Q.isMozillaXR()?!0:(dt&&console.warn("CanReceiveInput:False for",t.target),!1)}getPointerId(t,i){return t.pointerType==="mouse"?0+(i??t.button):this.getPointerIndex(t.pointerId)}getButtonName(t){const i=t.button;if(t.pointerType==="mouse")switch(i){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(t,i,s){let o=this._pointerSpace[t];o||(o=new E,this._pointerSpace[t]=o),this._pointerSpace[t]=o;const r=this.context.mainCamera;if(r){const l=this.tempNearPlaneVector.set(i,s,-1);this.convertScreenspaceToRaycastSpace(l);const c=this.tempFarPlaneVector.set(l.x,l.y,1);l.unproject(r),c.unproject(r);const h=r.worldUp||q(0,1,0).applyQuaternion(Ce(r));this.tempLookMatrix.lookAt(c,l,h),o.position.set(l.x,l.y,l.z),o.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return o}isInRect(t){if(this.context.isInXR)return!0;const i=this.context.domElement.getBoundingClientRect(),s=t.clientX,o=t.clientY,r=s>=i.x&&s<=i.right&&o>=i.y&&o<=i.bottom;return dt&&!r&&console.log("Not in rect",i,s,o),r}onDown(t){const i=t.pointerId;if(this.getPointerPressed(i)&&console.warn(`Received pointerDown for pointerId that is already pressed: ${i}`,dt?t:""),dt&&console.log(t.pointerType,"DOWN",i),!!this.isInRect(t)){for(this.setPointerState(i,this._pointerPressed,!0),this.setPointerState(i,this._pointerDown,!0),this.setPointerStateT(i,this._pointerEvent,t.source);i>=this._pointerTypes.length;)this._pointerTypes.push(t.pointerType);for(this._pointerTypes[i]=t.pointerType;i>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new x);for(this._pointerPositionDown[i].set(t.clientX,t.clientY,t.clientZ??0);i>=this._pointerPositions.length;)this._pointerPositions.push(new re);this._pointerPositions[i].set(t.clientX,t.clientY),i>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[i]=this.context.time.realtimeSinceStartup,this.updatePointerPosition(t),this._pointerEventsPressed.push(t),this.onDispatchEvent(t)}}onMove(t){const i=t.pointerId,s=this.getPointerPressed(i);s===!1&&!this.isInRect(t)||t.pointerType==="touch"&&!s||(this.updatePointerPosition(t),this.setPointerStateT(i,this._pointerEvent,t.source),this.onDispatchEvent(t))}onUp(t){const i=t.pointerId;if(!this.getPointerPressed(i)){dt&&console.log(t.pointerType,"UP",i,"was not down");return}dt&&console.log(t.pointerType,"UP",i),this.setPointerState(i,this._pointerPressed,!1),this.setPointerStateT(i,this._pointerEvent,t.source),this.setPointerState(i,this._pointerUp,!0),this.updatePointerPosition(t);for(let c=this._pointerEventsPressed.length-1;c>=0;c--)if(this._pointerEventsPressed[c].pointerId===i){this._pointerEventsPressed.splice(c,1);break}if(!this._pointerPositionDown[i]){dt&&_e("Received pointer up event without matching down event for button: "+i),console.warn("Received pointer up event without matching down event for button: "+i);return}const s=this._pointerUpTime[i],o=this._pointerDownTime[i],r=this.context.time.realtimeSinceStartup,l=r-o;if(i>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),this._pointerUpTime[i]=r,l<1){let c=t.clientX-this._pointerPositionDown[i].x,h=t.clientY-this._pointerPositionDown[i].y,d=0;if(t.isSpatial&&t.clientZ!=null&&(d=t.clientZ-this._pointerPositionDown[i].z,c*=200,h*=200,d*=200),Math.abs(c)<5&&Math.abs(h)<5&&Math.abs(d)<5){this.setPointerState(i,this._pointerClick,!0),t.isClick=!0;const u=r-s;dt&&console.log("CLICK",i,c,h,d,u),u<this._doubleClickTimeThreshold&&u>0&&(this.setPointerState(i,this._pointerDoubleClick,!0),t.isDoubleClick=!0)}}this.onDispatchEvent(t)}updatePointerPosition(t){const i=t.pointerId;for(;i>=this._pointerPositions.length;)this._pointerPositions.push(new re);for(;i>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new re);for(;i>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new re);const s=this._pointerPositionsLastFrame[i];s.copy(this._pointerPositions[i]);const o=this._pointerPositionsDelta[i];let r=t.clientX-s.x,l=t.clientY-s.y;if(t.source instanceof MouseEvent||t.source instanceof TouchEvent){const u=t.source;r===0&&u.movementX!==0&&(r=u.movementX||0),l===0&&u.movementY!==0&&(l=u.movementY||0)}o.x+=r,o.y+=l,this._pointerPositions[i].x=t.clientX,this._pointerPositions[i].y=t.clientY;const c=t.clientX,h=t.clientY;for(;i>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new re);const d=this._pointerPositionsRC[i];d.set(c,h),this.convertScreenspaceToRaycastSpace(d)}getPointerIndex(t){let i=-1;for(let s=0;s<this._pointerIds.length;s++){if(this._pointerIds[s]===t)return s;i===-1&&this._pointerIds[s]===-1&&(i=s)}return i!==-1?(this._pointerIds[i]=t,i):(dt&&console.log("PUSH pointerId:",t),this._pointerIds.push(t),this._pointerIds.length-1)}setPointerState(t,i,s){i[t]=s}setPointerStateT(t,i,s){return i[t]=s,s}onDispatchEvent(t){const i=ee.Current;try{ee.Current=this.context,this.dispatchEvent(t)}finally{ee.Current=i}}}const Ca=new se().makeRotationY(Math.PI),qi=new V().setFromAxisAngle(new x(0,1,0),Math.PI),IP=C("debugwebxr");class jP{constructor(){if(a(this,"priority",-1e5),a(this,"gameObject"),this.gameObject=new E,this.gameObject.name="Implicit XR Rig",IP){const t=fg(16733661);t.position.y+=.5,this.gameObject.add(t)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const ks=C("debugwebxr"),Ad=C("debugcustomgesture"),LP="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",DP="generic-trigger",BP=new V().setFromEuler(new zt(ys.degToRad(0),ys.degToRad(-90),ys.degToRad(-90))),FP=new x(.04,-.04,0);class tg{constructor(t,i,s){a(this,"xr"),a(this,"inputSource"),a(this,"index",0),a(this,"emitEvents",!0),a(this,"_connected",!0),a(this,"_isTracking",!1),a(this,"__gamepad"),a(this,"__hand"),a(this,"__side"),a(this,"_hitTestSource"),a(this,"_hasSelectEvent",!1),a(this,"_isMxInk",!1),a(this,"_isMetaQuestTouchController",!1),a(this,"_handJointPoses",new Map),a(this,"_gripMatrix",new se),a(this,"_gripPosition",new x),a(this,"_gripQuaternion",new V),a(this,"_linearVelocity",new x),a(this,"_rayPositionRaw",new x),a(this,"_rayRotationRaw",new V),a(this,"_rayMatrix",new se),a(this,"_rayPosition",new x),a(this,"_rayQuaternion",new V),a(this,"_gripWorldPosition",new x),a(this,"_gripWorldQuaternion",new V),a(this,"_rayWorldPosition",new x),a(this,"_rayWorldQuaternion",new V),a(this,"_pinchPosition",new x),a(this,"_ray"),a(this,"_hand_wristDotUp"),a(this,"_object"),a(this,"_gripSpaceObject"),a(this,"_raySpaceObject"),a(this,"model",null),a(this,"_debugAxesHelper",new Si(.15)),a(this,"_debugGripAxesHelper",new Si(.07)),a(this,"_debugRayAxesHelper",new Si(.07)),a(this,"_hitTestSourcePromise",null),a(this,"onPointerHits",o=>{}),a(this,"_needleGamepadButtons",{}),a(this,"_buttonMap",new Map),a(this,"_motioncontroller"),a(this,"_layout"),a(this,"getMotionController"),a(this,"emitPointerDownEvent",!0),a(this,"emitPointerUpEvent",!0),a(this,"emitPointerMoveEvent",!0),a(this,"pointerMoveDistanceThreshold",.03),a(this,"pointerMoveAngleThreshold",.05),a(this,"_selectButtonIndex"),a(this,"_squeezeButtonIndex"),a(this,"onSelectStart",o=>{var r,l,c,h;if(!this.emitPointerDownEvent||this.inputSource!==o.inputSource)return;this.onUpdateFrame(o.frame),this._hasSelectEvent=!0;const d=(r=this._layout)==null?void 0:r.selectComponentId,u=(h=(c=(l=this._layout)==null?void 0:l.components[d])==null?void 0:c.gamepadIndices)==null?void 0:h.button;u!==void 0&&(this._selectButtonIndex=u),!Ad&&(ks&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(Fe.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSelectEnd",o=>{this.emitPointerUpEvent&&(Ad||this.inputSource===o.inputSource&&this.emitPointerEvent(Fe.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSequeezeStart",o=>{var r,l,c;this.emitPointerDownEvent&&this.inputSource===o.inputSource&&(this._squeezeButtonIndex=(c=(l=(r=this._layout)==null?void 0:r.components["xr-standard-squeeze"])==null?void 0:l.gamepadIndices)==null?void 0:c.button,this._squeezeButtonIndex!==void 0&&(ks&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(Fe.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)))}),a(this,"onSequeezeEnd",o=>{this.emitPointerUpEvent&&this.inputSource===o.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(Fe.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)}),a(this,"states",{}),a(this,"_didMoveLastFrame",!1),a(this,"_lastPointerMovePosition",new x),a(this,"_lastPointerMoveQuaternion",new V),a(this,"pointerInit"),this.xr=t,this.inputSource=i,this.index=s,this._object=new E,this._object.name=`NeedleXRController_${s}`,ks&&(this._object.add(this._debugAxesHelper),this._gripSpaceObject=new E,this._raySpaceObject=new E,this._gripSpaceObject.name=`NeedleXRController_${s}_gripSpace`,this._raySpaceObject.name=`NeedleXRController_${s}_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 co,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents()}get context(){return this.xr.context}get connected(){return this._connected}get isTracking(){return this._isTracking}get gamepad(){return this.__gamepad??(this.__gamepad=this.inputSource.gamepad)}get isHand(){return this.hand!=null}get hand(){return this.__hand??(this.__hand=this.inputSource.hand)}get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.__side??(this.__side=this.inputSource.handedness)}get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get isStylus(){return this._isMxInk}getHitTestSource(){return this._hitTestSource||this._requestHitTestSource(),this._hitTestSource}get hasHitTestSource(){return this._hitTestSource}cancelHitTestSource(){this._hitTestSource&&(this._hitTestSource.cancel(),this._hitTestSource=void 0)}get hasSelectEvent(){return this._hasSelectEvent}getHitTest(){return this.xr.getHitTest(this)}getHandJointPose(t,i){var s;if(i=i||this.xr.frame,!this.hand||!(i!=null&&i.getJointPose)||!this.xr.referenceSpace)return null;let o=(s=this._handJointPoses)==null?void 0:s.get(t);return o||(o=i.getJointPose(t,this.xr.referenceSpace),o&&this._handJointPoses.set(t,o),o)}get gripPosition(){return q(this._gripPosition)}get gripQuaternion(){return yn(this._gripQuaternion)}get gripMatrix(){return this._gripMatrix}get gripLinearVelocity(){return q(this._linearVelocity).applyQuaternion(qi)}get rayPosition(){return q(this._rayPosition)}get rayQuaternion(){return yn(this._rayQuaternion)}get gripWorldPosition(){return q(this._gripWorldPosition)}get gripWorldQuaternion(){return yn(this._gripWorldQuaternion)}get rayWorldPosition(){return q(this._rayWorldPosition)}updateRayWorldPosition(){var t;const i=(t=this.xr.context.mainCamera)==null?void 0:t.parent;this._rayWorldPosition.copy(this._rayPositionRaw),i&&this._rayWorldPosition.applyMatrix4(i.matrixWorld)}get rayWorldQuaternion(){return yn(this._rayWorldQuaternion)}get pinchPosition(){return q(this._pinchPosition)}updateRayWorldQuaternion(){var t;const i=(t=this.xr.context.mainCamera)==null?void 0:t.parent,s=i?Ce(i):void 0;this._rayWorldQuaternion.copy(this._rayRotationRaw).multiply(qi),s&&this._rayWorldQuaternion.premultiply(s)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(q(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get handWristDotUp(){var t;if(this._hand_wristDotUp!==void 0)return this._hand_wristDotUp;const i=(t=this.handObject)==null?void 0:t.joints.wrist;if(i){const s=q(0,1,0).applyQuaternion(i.quaternion),o=q(0,1,0).dot(s);return this._hand_wristDotUp=o}}get isHandUpsideDown(){return this.handWristDotUp!==void 0?this.handWristDotUp<-.7:!1}get isTeleportGesture(){var t;return this.isHandUpsideDown&&((t=this.getGesture("pinch"))==null?void 0:t.isDown)}get object(){return this._object}async getModelUrl(){var t;return(t=this.getMotionController)==null?void 0:t.then(i=>i?.assetUrl||null)}_requestHitTestSource(){var t;return this._hitTestSourcePromise?this._hitTestSourcePromise:this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&this.xr.session.requestHitTestSourceForTransientInput?this._hitTestSourcePromise=((t=this.xr.session.requestHitTestSourceForTransientInput({profile:this.inputSource.profiles[0],offsetRay:new XRRay}))==null?void 0:t.then(i=>(this._hitTestSourcePromise=null,this.connected?this._hitTestSource=i:(i.cancel(),null))))??null:null}onUpdate(t){this.onUpdateFrame(t),this.updateInputEvents(),this.onUpdateMove()}onRenderDebug(){var t;$.DrawSphere(this.rayWorldPosition,.003),$.DrawDirection(this.rayWorldPosition,q(0,0,10).applyQuaternion(this.rayWorldQuaternion));const i=(this.inputSource.gripSpace?this.gripWorldPosition:this.object.worldPosition).sub(this.object.worldForward.multiplyScalar(.1)),s=this.inputSource.profiles.join(`
135
135
  `);let o=`Controller[${this.index}] (${this.inputSource.targetRayMode}, ${this.side})
136
136
  C:${this.connected?"x":"-"} T:${this.isTracking?"x":"-"} Hand:${this.inputSource.hand?"x":"-"} Pen: ${this._isMxInk?"x":"-"}`;if(this.inputSource.hand&&(o+=`
@@ -1399,7 +1399,7 @@ void main() {
1399
1399
  ${p}
1400
1400
 
1401
1401
  This could mean you forgot to add a npmdef to your ExportInfo
1402
- <a href="https://engine.needle.tools/docs/project_structure.html#creating-and-installing-a-npmdef" target="_blank">documentation</a>`,Pi.Warn)}}if(t.children)for(const u of t.children)await ky(n,u,i)}function Ej(n,t){const{instance:i,compData:s,obj:o}=n;t.object=o,t.target=i,Yd(i,s,t),qh&&console.debug("add "+s.name,s,i)}const zl=[],Jp=[];var My;(n=>{function t(s,o){const r={name:o?.name,priority:o?.priority??0,callback:s};return zl.push(r),zl.sort((l,c)=>l.priority===c.priority?0:l.priority>c.priority?-1:1),()=>{const l=zl.indexOf(r);l>=0&&zl.splice(l,1)}}n.onCreateCustomModelLoader=t;function i(s){return Jp.push(s),()=>{const o=Jp.indexOf(s);o>=0&&Jp.splice(o,1)}}n.onDetermineModelMimetype=i})(My||(My={}));const Qh=C("debugfileformat");async function $1(n,t){var i;const{useExtension:s=!0}=t;if(s){const l=n,c=new URL(l,globalThis.location.origin);let h=null;const d=c.searchParams.get("filetype");switch(d&&(h=d.toUpperCase()),h!=null&&h.length||(h=(i=c.pathname.split(".").pop())==null?void 0:i.toUpperCase()),Qh&&console.warn(`[Needle Engine] Try to use file extension to determine type: '${h}'`),h){case"GLTF":return"model/gltf+json";case"VRM":return"model/vrm";case"GLB":return"model/gltf-binary";case"FBX":return"model/fbx";case"USD":return"model/vnd.usd+zip";case"USDA":return"model/vnd.usda+zip";case"USDZ":return"model/vnd.usdz+zip";case"OBJ":return"model/obj"}}const o=n;if(!n.startsWith("blob:")){const l=new URL(n);l.searchParams.append("range","true"),n=l.toString()}const r=await fetch(n,{method:"GET",headers:{range:"bytes=0-32"}}).catch(l=>null);if(r!=null&&r.ok){const l=await r.arrayBuffer(),c=G1(o,l,r);return Qh&&console.log("[Needle Engine] Determined file type from header: "+c),c}return"unknown"}function G1(n,t,i){if(t.byteLength<4)return"unknown";const s=new Uint8Array(t);if(Qh&&console.warn(`[Needle Engine] Trying to determine file type from binary data
1402
+ <a href="https://engine.needle.tools/docs/project_structure.html#creating-and-installing-a-npmdef" target="_blank">documentation</a>`,Pi.Warn)}}if(t.children)for(const u of t.children)await ky(n,u,i)}function Ej(n,t){const{instance:i,compData:s,obj:o}=n;t.object=o,t.target=i,Yd(i,s,t),qh&&console.debug("add "+s.name,s,i)}const zl=[],Jp=[];var My;(n=>{function t(s,o){const r={name:o?.name,priority:o?.priority??0,callback:s};return zl.push(r),zl.sort((l,c)=>l.priority===c.priority?0:l.priority>c.priority?-1:1),()=>{const l=zl.indexOf(r);l>=0&&zl.splice(l,1)}}n.onCreateCustomModelLoader=t;function i(s){return Jp.push(s),()=>{const o=Jp.indexOf(s);o>=0&&Jp.splice(o,1)}}n.onDetermineModelMimetype=i})(My||(My={}));const Qh=C("debugfileformat");async function $1(n,t){var i;const{useExtension:s=!0}=t;if(s){const l=n,c=new URL(l,globalThis.location.href);let h=null;const d=c.searchParams.get("filetype");switch(d&&(h=d.toUpperCase()),h!=null&&h.length||(h=(i=c.pathname.split(".").pop())==null?void 0:i.toUpperCase()),Qh&&console.warn(`[Needle Engine] Try to use file extension to determine type: '${h}'`),h){case"GLTF":return"model/gltf+json";case"VRM":return"model/vrm";case"GLB":return"model/gltf-binary";case"FBX":return"model/fbx";case"USD":return"model/vnd.usd+zip";case"USDA":return"model/vnd.usda+zip";case"USDZ":return"model/vnd.usdz+zip";case"OBJ":return"model/obj"}}const o=n;if(!n.startsWith("blob:")){const l=new URL(n,globalThis.location.href);l.searchParams.append("range","true"),n=l.toString()}const r=await fetch(n,{method:"GET",headers:{range:"bytes=0-32"}}).catch(l=>null);if(r!=null&&r.ok){const l=await r.arrayBuffer(),c=G1(o,l,r);return Qh&&console.log("[Needle Engine] Determined file type from header: "+c),c}return"unknown"}function G1(n,t,i){if(t.byteLength<4)return"unknown";const s=new Uint8Array(t);if(Qh&&console.warn(`[Needle Engine] Trying to determine file type from binary data
1403
1403
  `,'"'+new TextDecoder().decode(t)+`"
1404
1404
  `,s),s[0]==103&&s[1]==108&&s[2]==84&&s[3]==70&&s[4]==10)return console.debug("GLTF detected"),"model/gltf+json";if(s[0]==103&&s[1]==108&&s[2]==84&&s[3]==70&&s[4]==98)return console.debug("GLB detected"),"model/gltf-binary";if(s[0]==80&&s[1]==75&&s[2]==3&&s[3]==4)return console.debug("USDZ detected"),"model/vnd.usdz+zip";if(s[0]==80&&s[1]==88&&s[2]==82&&s[3]==45&&s[4]==85&&s[5]==83&&s[6]==68&&s[7]==67)return console.debug("Binary USD detected"),"model/vnd.usd";if(s[0]==35&&s[1]==117&&s[2]==115&&s[3]==100&&s[4]==97)return console.debug("ASCII USD detected"),"model/vnd.usda";if(s[0]==75&&s[1]==97&&s[2]==121&&s[3]==100&&s[4]==97&&s[5]==114&&s[6]==97&&s[7]==32)return console.debug("Binary FBX detected"),"model/fbx";if(s[0]==59&&s[1]==32&&s[2]==70&&s[3]==66&&s[4]==88&&s[5]==32)return console.debug("ASCII FBX detected"),"model/fbx";if(s[0]==35&&s[1]==32&&s[2]==66&&s[3]==108&&s[4]==101&&s[5]==110&&s[6]==100&&s[7]==101&&s[8]==114&&s[9]==32||s[0]==35&&s[1]==32&&s[2]==65&&s[3]==108&&s[4]==105&&s[5]==97&&s[6]==115&&s[7]==32&&s[8]==79&&s[9]==66&&s[10]==74)return console.debug("OBJ detected"),"model/obj";if(i.headers.has("content-type")){const o=i.headers.get("content-type");switch(console.debug("Content-Type: "+o),o){case"model/gltf+json":case"model/gltf-binary":case"model/vrm":case"model/vnd.usdz+zip":case"model/vnd.usd+zip":case"model/vnd.usd":case"model/vnd.usda+zip":case"model/vnd.usda":case"model/vnd.usdc":case"model/fbx":case"model/vnd.autodesk.fbx":case"model/obj":return o}}if(s[0]==118&&s[1]==32||s[0]==102&&s[1]==32)return console.debug("OBJ detected (the file has no header and starts with vertex or face)"),"obj";if(s[0]==35&&s[1]==32&&s[2]==70&&s[3]==105&&s[4]==108&&s[5]==101&&s[6]==32&&s[7]==101&&s[8]==120&&s[9]==112&&s[10]==111&&s[11]==114&&s[12]==116&&s[13]==101&&s[14]==100&&s[15]==32&&s[16]==98&&s[17]==121&&s[18]==32&&s[19]==90&&s[20]==66&&s[21]==114&&s[22]==117&&s[23]==115&&s[24]==104)return console.debug("OBJ detected (exported by ZBrush)"),"obj";if(s[0]==109&&s[1]==116&&s[2]==108&&s[3]==108&&s[4]==105&&s[5]==98)return console.debug("OBJ detected (mtllib)"),"obj";for(const o of Jp){const r=o({url:n,response:i,contentType:i.headers.get("content-type"),bytes:s});if(r)return Qh&&console.debug(`Mimetype callback returned: ${r}`),r}if(B()||Qh){const o=new TextDecoder().decode(t.slice(0,Math.min(t.byteLength,32)));console.warn(`Could not determine file type.
1405
1405