@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in
134 lines (125 loc) • 1.24 MB
JavaScript
"use strict";var px=Object.defineProperty;var mx=(s,t,e)=>t in s?px(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var r=(s,t,e)=>(mx(s,typeof t!="symbol"?t+"":t,e),e),uf=(s,t,e)=>{if(!t.has(s))throw TypeError("Cannot "+e)};var ce=(s,t,e)=>(uf(s,t,"read from private field"),e?e.call(s):t.get(s)),Ei=(s,t,e)=>{if(t.has(s))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(s):t.set(s,e)},Ki=(s,t,e,i)=>(uf(s,t,"write to private field"),i?i.call(s,e):t.set(s,e),e);var ml=(s,t,e)=>(uf(s,t,"access private method"),e);const h=require("./three.light.umd.cjs"),ae=require("./gltf-progressive.light.umd.cjs"),Y=require("./three-examples.light.umd.cjs"),re=require("./vendor.light.umd.cjs"),ne=require("./three-mesh-ui.light.umd.cjs");var _a=typeof document<"u"?document.currentScript:null;let kb,M_=null;function dn(){return kb}function Om(s){if(s==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}M_!==s&&(M_=s,kb=new s)}const ff=new Map;function Gt(s=(t=>(t=globalThis.location)==null?void 0:t.hostname)()){if(ff.has(s))return ff.get(s);const e=/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|localhost/.test(s);return ff.set(s,e),e===!0}function Eb(){return window.location.hostname.includes("glitch.me")}const R_=typeof window!==void 0?window.location.search.includes("debugcontext"):!1;var de=(s=>(s.ContextRegistered="ContextRegistered",s.ContextCreationStart="ContextCreationStart",s.ContextCreated="ContextCreated",s.ContextFirstFrameRendered="ContextFirstFrameRendered",s.ContextDestroying="ContextDestroying",s.ContextDestroyed="ContextDestroyed",s.MissingCamera="MissingCamera",s.ContextClearing="ContextClearing",s.ContextCleared="ContextCleared",s))(de||{});class he{static get Current(){return globalThis["NeedleEngine.Context.Current"]}static set Current(t){globalThis["NeedleEngine.Context.Current"]=t}static get All(){return this.Registered}static register(t){this.Registered.indexOf(t)===-1&&(R_&&console.warn("Registering context"),this.Registered.push(t),this.dispatchCallback("ContextRegistered",t))}static unregister(t){const e=this.Registered.indexOf(t);e!==-1&&(R_&&console.warn("Unregistering context"),this.Registered.splice(e,1))}static registerCallback(t,e){this._callbacks[t]||(this._callbacks[t]=[]),this._callbacks[t].push(e)}static unregisterCallback(t,e){if(!this._callbacks[t])return;const i=this._callbacks[t].indexOf(e);i!==-1&&this._callbacks[t].splice(i,1)}static dispatchCallback(t,e,i){if(!this._callbacks[t])return!0;const n={event:t,context:e};if(i)for(const a in i)n[a]=i[a];const o=new Array;return this._callbacks[t].forEach(a=>{const l=a(n);l instanceof Promise&&o.push(l)}),Promise.all(o)}static addContextCreatedCallback(t){this.registerCallback("ContextCreated",t)}static addContextDestroyedCallback(t){this.registerCallback("ContextDestroyed",t)}}r(he,"Registered",[]),r(he,"_callbacks",{});const Tb=()=>s=>s;function gx(s){return Tb()(s)}function _x(){return!!x("debug")}class xi{constructor(t,e){r(this,"_factory");r(this,"_cache",[]);r(this,"_maxSize");r(this,"_index",0);this._factory=t,this._maxSize=e}get(){const t=this._index%this._maxSize;return this._index++,this._cache.length<=t&&(this._cache[t]=this._factory()),this._cache[t]}}let Bo=!1;const Dp=new Array;typeof window<"u"&&setTimeout(()=>{if(Bo){const s={},t=new URL(window.location.href),e=new URL(t);e.searchParams.append("console","");const i=e.toString().replace(/=$|=(?=&)/g,"");for(const o of Dp){const a=new URL(t);a.searchParams.append(o,""),s[o]=a.toString().replace(/=$|=(?=&)/g,"")}console.log(`🌵 ?help: Debug Options for Needle Engine.
Append any of these parameters to the URL to enable specific debug options.
Example: ${i} will show an onscreen console window.`);const n=Bo===!0?"":` (containing "${Bo}")`;console.group("Available URL parameters:"+n);for(const o of Object.keys(s).sort())typeof Bo=="string"&&!o.toLowerCase().includes(Bo.toLowerCase())||(console.groupCollapsed(o),console.log("Reload with this flag enabled:"),console.log(s[o]),console.groupEnd());console.groupEnd()}},100);function Fc(){var s;return new URLSearchParams((s=globalThis.location)==null?void 0:s.search)}function x(s){Bo&&!Dp.includes(s)&&Dp.push(s);const t=Fc();if(t.has(s)){const e=t.get(s);if(e){const i=Number(e);return isNaN(i)?e:i}else return!0}return!1}Bo=x("help");function yx(s,t){const e=Fc();e.has(s)?e.set(s,t):e.append(s,t),document.location.search=e.toString()}function xc(s,t,e=!0){const i=Fc();i.has(s)?t===null?i.delete(s):i.set(s,t):t!==null&&i.append(s,t),e?Ab(s,i):Mm(s,i)}function Lp(s,t,e){s.has(t)?s.set(t,e.toString()):s.append(t,e.toString())}function Ab(s,t,e){window.history.pushState(e,s,"?"+t.toString())}function Mm(s,t,e){window.history.replaceState(e,s,"?"+t.toString())}function bx(s){for(var t="",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",i=e.length,n=0;n<s;n++)t+=e.charAt(Math.floor(Math.random()*i));return t}function vx(s,t){return Math.floor(Math.random()*(t-s+1))+s}const k_=["smol","tiny","giant","interesting","smart","bright","dull","extreme","beautiful","pretty","dark","epic","salty","silly","funny","lame","lazy","loud","lucky","mad","mean","mighty","mysterious","nasty","odd","old","powerful","quiet","rapid","scary","shiny","shy","silly","smooth","sour","spicy","stupid","sweet","tasty","terrible","ugly","unusual","vast","wet","wild","witty","wrong","zany","zealous","zippy","zombie","zorro"],E_=["cat","dog","mouse","pig","cow","horse","sheep","chicken","duck","goat","panda","tiger","lion","elephant","monkey","bird","fish","snake","frog","turtle","hamster","penguin","kangaroo","whale","dolphin","crocodile","snail","ant","bee","beetle","butterfly","dragon","eagle","fish","giraffe","lizard","panda","penguin","rabbit","snake","spider","tiger","zebra"];function Db(){const s=k_[Math.floor(Math.random()*k_.length)],t=E_[Math.floor(Math.random()*E_.length)];return s+"_"+t}function Lb(s){return s=s.replace(/[^a-z0-9áéÃóúñü \.,_-]/gim,""),s.trim()}function ka(s,t,e=!0,i=!1){var n;if(t==null)return null;if(t.userData&&t.userData.guid===s)return t;if(t.guid==s)return t;if(i&&(n=t.userData)!=null&&n.components){for(const o of t.userData.components)if(o.guid===s)return o}if(e){if(t.scenes)for(const o in t.scenes){const a=t.scenes[o],l=ka(s,a,e,i);if(l)return l}if(t.children)for(const o in t.children){const a=t.children[o],l=ka(s,a,e,i);if(l)return l}}}function Uc(s,t){if(s!=null&&typeof s=="object"){let e;Array.isArray(s)?e=[]:(e=Object.create(s),Object.assign(e,s));for(const i of Object.keys(s)){const n=s[i];t&&!t(s,i,n)?e[i]=n:(n==null?void 0:n.clone)!==void 0&&typeof n.clone=="function"?e[i]=n.clone():e[i]=Uc(n,t)}return e}return s}function un(s){return new Promise((t,e)=>{setTimeout(t,s)})}function zc(s,t){if(s<=0)return Promise.resolve();if(t||(t=he.Current),!t)return Promise.reject("No context");const e=t.time.frameCount+s;return new Promise((i,n)=>{if(!t)return n("No context");const o=()=>{t.time.frameCount>=e&&(t.pre_update_callbacks.splice(t.pre_update_callbacks.indexOf(o),1),i())};t.pre_update_callbacks.push(o)})}const Eh=x("debugresolveurl"),Ib="rel:";function wx(s,t){return mo(s,t)}function mo(s,t){if(t===void 0)return Eh&&console.warn("getPath: uri is undefined, returning uri",t),t;if(t.startsWith("./"))return t;if(t.startsWith("http"))return Eh&&console.warn("getPath: uri is absolute, returning uri",t),t;if(s===void 0)return Eh&&console.warn("getPath: source is undefined, returning uri",t),t;t.startsWith(Ib)&&(t=t.substring(4));const e=s.lastIndexOf("/");if(e>=0){const i=s.substring(0,e+1);for(;i.endsWith("/")&&t.startsWith("/");)t=t.substring(1);const n=i+t;return Eh&&console.log("source:",s,`changed uri
from`,t,`
to `,n,`
basePath: `+i),n}return t}class xx{constructor(t,e){r(this,"writeCallbacks",[]);r(this,"_applied",!1);r(this,"_object");r(this,"_prop");r(this,"_wrapperProp");this._object=t,this._prop=e,this._wrapperProp=Symbol("$"+e),this.apply()}subscribeWrite(t){this.writeCallbacks.push(t)}unsubscribeWrite(t){const e=this.writeCallbacks.indexOf(t);e!==-1&&this.writeCallbacks.splice(e,1)}apply(){if(this._applied||!this._object)return;const t=this._object,e=this._prop;if(t[e]===void 0)return;this._applied=!0,t[this._wrapperProp]!==void 0&&console.warn("Watcher is being applied to an object that already has a wrapper property. This is not (yet) supported");const i=t[e];t[this._wrapperProp]=i,Object.defineProperty(t,e,{get:()=>t[this._wrapperProp],set:a=>{t[this._wrapperProp]=a;for(const l of this.writeCallbacks)l(a,this._prop)}})}revoke(){if(!this._applied||!this._object)return;this._applied=!1;const t=this._object,e=this._prop;Reflect.deleteProperty(t,e);const i=t[this._wrapperProp];t[e]=i,Reflect.deleteProperty(t,this._wrapperProp)}dispose(){this.revoke(),this.writeCallbacks.length=0,this._object=null}}class fs{constructor(t,e){r(this,"_watches",[]);if(Array.isArray(e))for(const i of e)this._watches.push(new fs(t,i));else this._watches.push(new xx(t,e))}subscribeWrite(t){for(const e of this._watches)e.subscribeWrite(t)}unsubscribeWrite(t){for(const e of this._watches)e.unsubscribeWrite(t)}apply(){for(const t of this._watches)t.apply()}revoke(){for(const t of this._watches)t.revoke()}dispose(){for(const t of this._watches)t.dispose();this._watches.length=0}}const ea=Symbol("needle:watches");function vu(s,t){if(!s[ea])if(s instanceof h.Vector2)s[ea]=new fs(s,["x","y"]);else if(s instanceof h.Vector3)s[ea]=new fs(s,["x","y","z"]);else if(s instanceof h.Vector4||s instanceof h.Quaternion)s[ea]=new fs(s,["x","y","z","w"]);else return!1;return s[ea].subscribeWrite(t),!0}function Rm(s,t){if(!s)return;const e=s[ea];e&&e.unsubscribeWrite(t)}exports.DeviceUtilities=void 0;(s=>{let t;function e(){if(t!==void 0)return t;const L=window.navigator.userAgent,V=/Windows|MacOS|Mac OS/.test(L),H=/Windows NT/.test(L)&&/Edg/.test(L)&&!/Win64/.test(L);return t=V&&!H&&!w()}s.isDesktop=e;let i;function n(){return i!==void 0?i:typeof window.orientation<"u"||navigator.userAgent.indexOf("IEMobile")!==-1?i=!0:i=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent)}s.isMobileDevice=n;function o(){return l()}s.isIPad=o;let a;function l(){return a!==void 0?a:a=/iPad/.test(navigator.userAgent)}s.isiPad=l;let c;function d(){return c!==void 0?c:c=/Android/.test(navigator.userAgent)}s.isAndroidDevice=d;let u;function f(){return u!==void 0?u:u=/WebXRViewer\//i.test(navigator.userAgent)}s.isMozillaXR=f;let m;function g(){if(m!==void 0)return m;if(navigator.userAgentData)return m=navigator.userAgentData.platform==="macOS";{const L=navigator.userAgent.toLowerCase();return m=L.includes("mac os x")||L.includes("macintosh")}}s.isMacOS=g;let _;function y(){return _!==void 0?_:_=g()&&"xr"in navigator}s.isVisionOS=y;let b;const v=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"];function w(){return b!==void 0?b:b=v.includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}s.isiOS=w;let P;function k(){return P!==void 0||(P=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),P}s.isSafari=k;let O;function M(){return O!==void 0?O:O=navigator.userAgent.includes("OculusBrowser")}s.isQuest=M;let A;function I(){return A!==void 0||(A=document.createElement("a").relList.supports("ar")),A}s.supportsQuickLookAR=I;async function T(){try{return(await navigator.permissions.query({name:"microphone"})).state!=="denied"}catch(L){return console.error("Error querying `microphone` permissions.",L),!1}}s.microphonePermissionsGranted=T;let j;function F(){if(j!==void 0)return j;const L=navigator.userAgent.match(/iPhone OS (\d+_\d+)/);if(L&&(j=L[1].replace("_",".")),!j){const V=navigator.userAgent.match(/(?:\(Macintosh;|iPhone;|iPad;).*Version\/(\d+\.\d+)/);V&&(j=V[1])}return j||(j=null),j}s.getiOSVersion=F;let X;function E(){if(X!==void 0)return X;const L=navigator.userAgent.match(/(?:CriOS|Chrome)\/(\d+\.\d+\.\d+\.\d+)/);return L?X=L[1].replace("_","."):X=null,X}s.getChromeVersion=E})(exports.DeviceUtilities||(exports.DeviceUtilities={}));function Sx(){return exports.DeviceUtilities.isDesktop()}function Cx(){return exports.DeviceUtilities.isMobileDevice()}function Px(){return exports.DeviceUtilities.isiPad()}function Ox(){return exports.DeviceUtilities.isiPad()}function Mx(){return exports.DeviceUtilities.isAndroidDevice()}function Rx(){return exports.DeviceUtilities.isMozillaXR()}function kx(){return exports.DeviceUtilities.isMacOS()}function Ex(){return exports.DeviceUtilities.isiOS()}function Tx(){return exports.DeviceUtilities.isSafari()}function Ax(){return exports.DeviceUtilities.isQuest()}async function Dx(){return exports.DeviceUtilities.microphonePermissionsGranted()}const Lx=/ip=(?<ip>.+?)\n/s;async function Ix(){const t=await(await fetch("https://www.cloudflare.com/cdn-cgi/trace")).text(),e=Lx.exec(t);return e?e[1]:null}async function jx(){const s=await fetch("https://api.db-ip.com/v2/free/self").catch(()=>null);return s?(await s.json()).ipAddress:void 0}async function Bx(){const s=await fetch("https://api.db-ip.com/v2/free/self").catch(()=>null);return s?await s.json():void 0}const Xs=new WeakMap;function jb(s,t,e){if(!Xs.get(s)){const n=new MutationObserver(o=>{Fx(s,o)});Xs.set(s,{observer:n,attributeChangedListeners:new Map}),n.observe(s,{attributes:!0})}const i=Xs.get(s).attributeChangedListeners;i.has(t)||i.set(t,[]),i.get(t).push(e)}function Bb(s,t,e){if(!Xs.get(s))return;const i=Xs.get(s).attributeChangedListeners;if(!i.has(t))return;const n=i.get(t),o=n.indexOf(e);if(o!==-1&&(n.splice(o,1),n.length<=0)){i.delete(t);const a=Xs.get(s);a==null||a.observer.disconnect(),Xs.delete(s)}}function Fx(s,t){const e=Xs.get(s).attributeChangedListeners;for(const i of t)if(i.type==="attributes"){const n=i.attributeName,o=s.getAttribute(n);if(e.has(n))for(const a of e.get(n))a(o)}}class Ip{constructor(t){r(this,"reason");this.reason=t}}async function km(s){const t=await Promise.allSettled(s).catch(n=>[new Ip(n.message)]);let e=!1;const i=t.map(n=>"value"in n?n.value:(e=!0,new Ip(n.reason)));return{anyFailed:e,results:i}}async function Fb(s){if(!globalThis.QRCode){const i="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js";let n=document.head.querySelector(`script[src="${i}"]`);n||(n=document.createElement("script"),n.src=i,document.head.appendChild(n)),await new Promise((o,a)=>{n.addEventListener("load",()=>{o(!0)})})}const t=globalThis.QRCode,e=s.domElement??document.createElement("div");return new t(e,{width:s.width??256,height:s.height??256,colorDark:"#000000",colorLight:"#ffffff",correctLevel:t.CorrectLevel.M,...s}),e}const Ub=x("debugdebug");let Sc=!1;(x("noerrors")||x("nooverlaymessages"))&&(Sc=!0);const pf="needle_engine_global_error_container";var bi=(s=>(s[s.Log=0]="Log",s[s.Warn=1]="Warn",s[s.Error=2]="Error",s))(bi||{});function Em(){return $b}const jp=new Array;function Ux(s){jp.push(s)}let mf=!1;function zx(...s){if(!mf){mf=!0;try{for(let t=0;t<jp.length;t++)jp[t](...s)}catch(t){console.error(t)}mf=!1}}const zb=console.error,Nb=function(...s){zb.apply(console,s),$x(s),Tn(2,s),Bp(...s)};function Vb(s){Sc=!s,s?console.error=Nb:console.error=zb}function Nx(s){return Vb(s)}function Vx(){Sc||(Ub&&console.warn("Patch console",window.location.hostname),console.error=Nb,window.addEventListener("error",s=>{if(!s)return;const t=s.error;if(t===void 0){Gt()&&console.warn("Received unknown error",s,s.target);return}Tn(2,t,s.filename,s.lineno),Bp(s)},!0),window.addEventListener("unhandledrejection",s=>{Sc||s&&(s.reason?Tn(2,s.reason.message,s.reason.stack):Tn(2,"unhandled rejection"),Bp(s))}))}let $b=0;function Bp(...s){$b+=1,zx(...s)}function $x(s){if(Array.isArray(s))for(let t=0;t<s.length;t++){const e=s[t];typeof e=="string"&&e.startsWith("THREE.PropertyBinding: Trying to update node for track:")&&(s[t]="Some animated objects couldn't be found: see console for details")}}function Tn(s,t,e,i){if(Sc)return;const n=he.Current,o=(n==null?void 0:n.domElement)??document.querySelector("needle-engine");if(o){if(Array.isArray(t)){let a="";for(let l=0;l<t.length;l++){let c=t[l];c instanceof Error&&(c=c.message),typeof c!="object"&&(l>0&&(a+=" "),a+=c)}t=a}!t||t.length<=0||Wx(s,o,t)}}const Zl=new Map;function Wx(s,t,e){if(e==null)return;const i=qx(t);if(i.childElementCount>=20){const l=i.lastElementChild;T_(l)}e.length>400&&(e=e.substring(0,400)+"...");const n=e;if(Zl.has(n))return;const o=Xx(s,e);i.prepend(o);const a=()=>{Zl.delete(n),T_(o)};Zl.set(n,a),setTimeout(a,1e4)}function Hx(){Ub&&console.log("Clearing messages");for(const s of Zl.values())s==null||s.call(s);Zl.clear()}const Gx=`
@import url('https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap');
div[data-needle_engine_debug_overlay] {
font-family: 'Roboto Flex', sans-serif;
font-weight: 400;
font-size: 16px;
}
div[data-needle_engine_debug_overlay] strong {
font-weight: 700;
}
div[data-needle_engine_debug_overlay] a {
color: white;
text-decoration: none;
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}
div[data-needle_engine_debug_overlay] a:hover {
text-decoration: none;
border: none;
}
div[data-needle_engine_debug_overlay] .log strong {
color: rgba(200,200,200,.9);
}
div[data-needle_engine_debug_overlay] .warn strong {
color: rgba(255,255,230, 1);
}
div[data-needle_engine_debug_overlay] .error strong {
color: rgba(255,100,120, 1);
}
`;function qx(s){globalThis[pf]||(globalThis[pf]=new Map);const t=globalThis[pf];if(t.has(s))return t.get(s);{const e=document.createElement("div");t.set(s,e),e.setAttribute("data-needle_engine_debug_overlay",""),e.classList.add("debug-container"),e.style.cssText=`
position: absolute;
top: 0;
right: 5px;
padding-top: 0px;
max-width: 70%;
max-height: calc(100% - 5px);
z-index: 9999999999;
pointer-events: scroll;
display: flex;
align-items: end;
flex-direction: column;
color: white;
overflow: auto;
word-break: break-word;
`,s.shadowRoot?s.shadowRoot.appendChild(e):s.appendChild(e);const i=document.createElement("style");return i.innerHTML=Gx,e.appendChild(i),e}}const Wb=Symbol("logtype"),Td=new Map;function T_(s){s.remove();const t=s[Wb],e=Td.get(t)??[];e.push(s),Td.set(t,e)}function Xx(s,t){if(Td.has(s)){const i=Td.get(s);if(i.length>0){const n=i.pop();return n.innerHTML=t,n}}const e=document.createElement("div");switch(e.setAttribute("data-id","__needle_engine_debug_overlay"),e.style.marginRight="5px",e.style.padding=".5em",e.style.backgroundColor="rgba(0,0,0,.9)",e.style.marginTop="5px",e.style.marginBottom="3px",e.style.borderRadius="8px",e.style.pointerEvents="all",e.style.userSelect="text",e.style.maxWidth="250px",e.style.whiteSpace="pre-wrap",e.style["backdrop-filter"]="blur(10px)",e.style["-webkit-backdrop-filter"]="blur(10px)",e.style.backgroundColor="rgba(20,20,20,.8)",e.style.boxShadow="inset 0 0 80px rgba(0,0,0,.2), 0 0 5px rgba(0,0,0,.2)",e.style.border="1px solid rgba(160,160,160,.2)",e[Wb]=s,s){case 0:e.classList.add("log"),e.style.color="rgba(200,200,200,.7)",e.style.backgroundColor="rgba(40,40,40,.7)";break;case 1:e.classList.add("warn"),e.style.color="rgb(255, 255, 150)",e.style.backgroundColor="rgba(50,50,20,.8)";break;case 2:e.classList.add("error"),e.style.color="rgb(255, 50, 50",e.style.backgroundColor="rgba(50,20,20,.8)";break}return e.title="Open the browser console (F12) for more information",e.innerHTML=t,e}class Qx{constructor(){r(this,"Rad2Deg",180/Math.PI);r(this,"Deg2Rad",Math.PI/180);r(this,"Epsilon",1e-5)}random(t,e){return Array.isArray(t)?t.length<=0?null:t[Math.floor(Math.random()*t.length)]:t!==void 0&&e!==void 0?Math.random()*(e-t)+t:Math.random()}randomVector3(t,e=0,i=1){t.x=this.random(e,i),t.y=this.random(e,i),t.z=this.random(e,i)}clamp(t,e,i){return t<e?e:t>i?i:t}clamp01(t){return this.clamp(t,0,1)}lerp(t,e,i){return i=i<0?0:i,i=i>1?1:i,t+(e-t)*i}inverseLerp(t,e,i){return(i-t)/(e-t)}remap(t,e,i,n,o){return n+(o-n)*(t-e)/(i-e)}moveTowards(t,e,i){return t+=i,(i<0&&t<e||i>0&&t>e)&&(t=e),t}toDegrees(t){return t*180/Math.PI}toRadians(t){return t*Math.PI/180}tan(t){return Math.tan(t)}gammaToLinear(t){return Math.pow(t,2.2)}linearToGamma(t){return Math.pow(t,1/2.2)}approximately(t,e,i=Number.EPSILON){for(const n of Yx){const o=t[n],a=e[n];if(o===void 0||a===void 0)break;if(Math.abs(o-a)>i)return!1}return!0}easeInOutCubic(t){return t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2}}const Yx=["x","y","z","w"],z=new Qx;class A_{constructor(t){r(this,"y");r(this,"s");r(this,"alpha",0);this.setAlpha(t),this.y=null,this.s=null}setAlpha(t){if(t<=0||t>1)throw new Error;this.alpha=t}filter(t,e){e&&this.setAlpha(e);let i;return this.y?i=this.alpha*t+(1-this.alpha)*this.s:i=t,this.y=t,this.s=i,i}lastValue(){return this.y}reset(t){this.y=t,this.s=t}}class hd{constructor(t,e=1,i=0,n=1){r(this,"freq");r(this,"minCutOff");r(this,"beta");r(this,"dCutOff");r(this,"x");r(this,"dx");r(this,"lasttime");if(t<=0||e<=0||n<=0)throw new Error;this.freq=t,this.minCutOff=e,this.beta=i,this.dCutOff=n,this.x=new A_(this.alpha(this.minCutOff)),this.dx=new A_(this.alpha(this.dCutOff)),this.lasttime=null}alpha(t){const e=1/this.freq;return 1/(1+1/(2*Math.PI*t)/e)}filter(t,e=null){this.lasttime&&e&&(this.freq=1/(e-this.lasttime)),this.lasttime=e;const i=this.x.lastValue(),n=i?(t-i)*this.freq:0,o=this.dx.filter(n,this.alpha(this.dCutOff)),a=this.minCutOff+this.beta*Math.abs(o);return this.x.filter(t,this.alpha(a))}reset(t){t!=null&&this.x.reset(t),this.x.alpha=this.alpha(this.minCutOff),this.dx.alpha=this.alpha(this.dCutOff),this.lasttime=null}}class Tm{constructor(t,e=1,i=0,n=1){r(this,"x");r(this,"y");r(this,"z");this.x=new hd(t,e,i,n),this.y=new hd(t,e,i,n),this.z=new hd(t,e,i,n)}filter(t,e,i=null){e.x=this.x.filter(t.x,i),e.y=this.y.filter(t.y,i),e.z=this.z.filter(t.z,i)}reset(t){this.x.reset(t==null?void 0:t.x),this.y.reset(t==null?void 0:t.y),this.z.reset(t==null?void 0:t.z)}}const dd="needle:cameraController";function Hb(s){return s[dd]}function Fp(s,t,e){e?s[dd]=t:s[dd]===t&&(s[dd]=null)}const Up="needle:autofit";function Gb(s){return s[Up]===void 0?!0:s[Up]!==!1}function Ad(s,t){s[Up]=t}function Kx(s,t,e){const i=s.length(),n=t.length(),o=z.lerp(i,n,e);return s.lerp(t,e).normalize().multiplyScalar(o)}const gf=new h.Quaternion,qb=new h.Quaternion().setFromAxisAngle(new h.Vector3(0,1,0),Math.PI);function Zx(s,t){s.lookAt(t),s.quaternion.multiply(qb)}function Nc(s,t,e=!0,i=!1){if(s===t)return;gf.copy(s.quaternion);const n=Z(t),o=Z(s);if(i){if(Wi(s,_e(t)),e){const a=o.y,l=o.sub(Qb(s));l.y=a,s.lookAt(l),s.quaternion.multiply(qb)}Number.isNaN(s.quaternion.x)&&s.quaternion.copy(gf);return}e&&(n.y=o.y),s.lookAt(n),Number.isNaN(s.quaternion.x)&&s.quaternion.copy(gf)}function Jx(s,t,e,i=1){if(e){const n=$(0,0,0),o=t.x/window.innerWidth*2-1,a=-(t.y/window.innerHeight)*2+1;n.set(o,a,0),n.unproject(e);const l=e.worldPosition,c=s.worldPosition.distanceTo(l),d=n.sub(l);d.multiplyScalar(i*3.6*c);const u=e.worldPosition.add(d);return s.lookAt(u),u}return null}const eS=new xi(()=>new h.Vector3,100);function $(s,t,e){const i=eS.get();return i.set(0,0,0),s instanceof h.Vector3?i.copy(s):Array.isArray(s)?i.set(s[0],s[1],s[2]):s instanceof DOMPointReadOnly?i.set(s.x,s.y,s.z):typeof s=="number"?(i.x=s,i.y=t!==void 0?t:i.x,i.z=e!==void 0?e:i.x):typeof s=="object"&&(i.x=s.x,i.y=s.y,i.z=s.z),i}const tS=new xi(()=>new h.Color,30);function Xb(s){const t=tS.get();return s?t.copy(s):t.set(0,0,0),t}const iS=new xi(()=>new h.Quaternion,100);function on(s){const t=iS.get();return t.identity(),s instanceof h.Quaternion?t.copy(s):s instanceof DOMPointReadOnly&&t.set(s.x,s.y,s.z,s.w),t}const Am=new xi(()=>new h.Vector3,100),D_=Symbol("lastMatrixWorldUpdateKey");function Z(s,t=null,e=!0){const i=t??Am.get();return s?s.parent?(e&&s.updateWorldMatrix(!0,!1),s.matrixWorldNeedsUpdate&&s[D_]!==Date.now()&&(s[D_]=Date.now(),s.updateMatrixWorld()),i.setFromMatrixPosition(s.matrixWorld),i):i.copy(s.position):i.set(0,0,0)}function it(s,t){if(!s)return s;const e=Am.get();return t!==e&&e.copy(t),((s==null?void 0:s.parent)??s).worldToLocal(e),s.position.set(e.x,e.y,e.z),s}function ar(s,t,e,i){const n=Am.get();return n.set(t,e,i),it(s,n),s}const Dd=new xi(()=>new h.Quaternion,100),Yo=new h.Quaternion,_f=new h.Quaternion;function _e(s,t=null){if(!s)return Dd.get().identity();const e=t??Dd.get();return s.parent?(s.getWorldQuaternion(e),e):e.copy(s.quaternion)}function Wi(s,t){if(!s)return;t!==Yo&&Yo.copy(t);const e=Yo,i=s==null?void 0:s.parent;i==null||i.getWorldQuaternion(_f),_f.invert();const n=_f.multiply(e);s.quaternion.set(n.x,n.y,n.z,n.w)}function Dm(s,t,e,i,n){Yo.set(t,e,i,n),Wi(s,Yo)}const nS=new xi(()=>new h.Vector3,100),sS=new h.Vector3;function Ue(s,t=null){return t||(t=nS.get()),s?s.parent?(s.getWorldScale(t),t):t.copy(s.scale):t.set(0,0,0)}function Ea(s,t){if(!s)return;if(!s.parent){s.scale.copy(t);return}const e=sS;s.parent.getWorldScale(e),s.scale.copy(t),s.scale.divide(e)}const oS=new h.Vector3,L_=new h.Quaternion;function rS(s){return _e(s,L_),oS.set(0,0,1).applyQuaternion(L_)}const aS=new xi(()=>new h.Vector3,100),I_=new h.Quaternion;function Qb(s,t){return t||(t=aS.get().set(0,0,1)),_e(s,I_),t.applyQuaternion(I_)}const j_=new h.Euler,B_=new h.Euler,lS=new h.Vector3;function Lm(s){const t=Dd.get();return s.getWorldQuaternion(t),B_.setFromQuaternion(t),B_}function Im(s,t){const e=Dd.get();Wi(s,e.setFromEuler(t))}function Vc(s){const t=Lm(s),e=lS;return e.set(t.x,t.y,t.z),e.x=z.toDegrees(e.x),e.y=z.toDegrees(e.y),e.z=z.toDegrees(e.z),e}function jm(s,t){$c(s,t.x,t.y,t.z,!0)}function $c(s,t,e,i,n=!0){n&&(t=z.toRadians(t),e=z.toRadians(e),i=z.toRadians(i)),j_.set(t,e,i),Yo.setFromEuler(j_),Wi(s,Yo)}function Ld(s,t=!0){s&&(t?function e(i){console.groupCollapsed((i.name?i.name:"(no name : "+i.type+")")+" %o",i),i.children.forEach(e),console.groupEnd()}(s):s.traverse(function(e){for(var i="|___",n=e;n.parent!==null;)i=" "+i,n=n.parent;console.log(i+e.name+" <"+e.type+">")}))}function cS(s){let t=(s==null?void 0:s.name)||"";if(!s)return t;let e=s.parent;for(;e;)t=e.name+"/"+t,e=e.parent;return t}function Yb(s){if(s){const t=s;return t.blendMode!==void 0&&t.clampWhenFinished!==void 0&&t.enabled!==void 0&&t.fadeIn!==void 0&&t.getClip!==void 0}return!1}class ji{static createBlitMaterial(t){return new h.ShaderMaterial({uniforms:{map:new h.Uniform$1(null)},vertexShader:this.vertex,fragmentShader:t})}static copyTexture(t,e){this.blitMaterial||(this.blitMaterial=new h.ShaderMaterial({uniforms:{map:new h.Uniform$1(null)},vertexShader:this.vertex,fragmentShader:this.fragment}));const i=e||this.blitMaterial;i.uniforms.map.value=t,i.needsUpdate=!0,i.uniformsNeedUpdate=!0;const n=i.vertexShader;i.vertexShader=this.vertex,this.mesh||(this.mesh=new h.Mesh(this.planeGeometry,this.blitMaterial));const o=this.mesh;o.material=i,o.frustumCulled=!1,this.scene.children.length=0,this.scene.add(o),this.renderer||(this.renderer=new h.WebGLRenderer({antialias:!1})),this.renderer.setSize(t.image.width,t.image.height),this.renderer.clear(),this.renderer.render(this.scene,this.perspectiveCam);const a=new h.Texture(this.renderer.domElement);return a.name="Copy",a.needsUpdate=!0,i.vertexShader=n,a}static textureToCanvas(t,e=!1){if(!t)return null;(e===!0||t.isCompressedTexture===!0)&&(t=Kb(t));const i=t.image;if(dS(i)){const n=document.createElement("canvas");n.width=i.width,n.height=i.height;const o=n.getContext("2d");return o?(o.drawImage(i,0,0,i.width,i.height,0,0,n.width,n.height),n):(console.error("Failed getting canvas 2d context"),null)}return null}}r(ji,"planeGeometry",new h.PlaneGeometry(2,2,1,1)),r(ji,"renderer"),r(ji,"perspectiveCam",new h.PerspectiveCamera),r(ji,"scene",new h.Scene),r(ji,"vertex",`
varying vec2 vUv;
void main(){
vUv = uv;
gl_Position = vec4(position.xy * 1.0,0.,.999999);
}`),r(ji,"fragment",`
uniform sampler2D map;
varying vec2 vUv;
void main(){
vec2 uv = vUv;
uv.y = 1.0 - uv.y;
gl_FragColor = texture2D( map, uv);
// gl_FragColor = vec4(uv.xy, 0, 1);
}`),r(ji,"blitMaterial"),r(ji,"mesh");function Kb(s){return ji.copyTexture(s)}function hS(s,t=!1){return ji.textureToCanvas(s,t)}function dS(s){return typeof HTMLImageElement<"u"&&s instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&s instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&s instanceof OffscreenCanvas||typeof ImageBitmap<"u"&&s instanceof ImageBitmap}function uS(s){const t=s.type;return t==="Mesh"||t==="SkinnedMesh"}function Bm(s,t){t?s["needle:rendercustomshadow"]=!0:s["needle:rendercustomshadow"]=!1}function Zb(s){if(s){if(s["needle:rendercustomshadow"]===!0)return!0;if(s["needle:rendercustomshadow"]==null)return!0}return!1}function si(s,t=void 0,e=void 0,i=void 0){const n=i||new h.Box3;n.makeEmpty();const o=[];function a(c){let d=!0;if(c.visible&&Gb(c)!==!1&&!(c.type==="TransformControlsGizmo"||c.type==="TransformControlsPlane")){if(c instanceof h.Box3Helper&&(d=!1),c instanceof h.GridHelper&&(d=!1),c instanceof Y.GroundedSkybox&&(d=!1),c.isGizmo===!0&&(d=!1),c.material instanceof h.ShadowMaterial&&(d=!1),uS(c)||(d=!1),e&&c.layers.test(e)===!1&&(d=!1),d){if(t&&Array.isArray(t)&&(t!=null&&t.includes(c)))return;if(typeof t=="function"&&t(c)===!0)return}if(c.isUI!==!0){if(d){const u=c.children;c.children=o;const f=c.position,m=c.scale;if(Number.isNaN(f.x)||Number.isNaN(f.y)||Number.isNaN(f.z)){console.warn(`Object "${c.name}" has NaN values in position or scale.... will ignore it`,f,m);return}n.expandByObject(c,!0),c.children=u}for(const u of c.children)a(u)}}}let l=!1;Array.isArray(s)||(s=[s]);for(const c of s)c&&(l=!0,c.updateMatrixWorld(),a(c));return l||console.warn("No objects to fit camera to..."),n}function Jb(s,t,e){const i=si([s],e==null?void 0:e.ignore),n=new h.Vector3;i.getSize(n);const o=new h.Vector3;i.getCenter(o);const a=new h.Vector3;t.getSize(a);const l=new h.Vector3;t.getCenter(l);const c=new h.Vector3;c.set(a.x/n.x,a.y/n.y,a.z/n.z);const d=Math.min(c.x,c.y,c.z),u=(e==null?void 0:e.scale)!==!1;if(u&&Ea(s,Ue(s).multiplyScalar(d)),(e==null?void 0:e.position)!==!1){const f=new h.Vector3;i.getCenter(f),f.y=i.min.y;const m=new h.Vector3;t.getCenter(m),m.y=t.min.y;const g=m.clone().sub(f);u&&g.multiplyScalar(d),it(s,Z(s).add(g))}return{boundsBefore:i,scale:c}}function e0(s,t){const e=si([s]),i=new h.Vector3;e.getCenter(i),i.y=e.min.y;const n=t.clone().sub(i),o=Z(s);return it(s,o.add(n)),{offset:n,bounds:e}}function Fm(s,t,e,i){if(Array.isArray(t)){let a=!0;for(let l=0;l<t.length;l++)Fm(s,t[l],l,t)||(a=!1);return a}if(t.type==="MeshStandardMaterial"||t.type==="MeshBasicMaterial")return!1;if(t["material:fbx"]!=null)return!0;const n=new h.MeshStandardMaterial;n["material:fbx"]=t;const o=t;return o&&(o.map?n.color.set(1,1,1):n.color.copyLinearToSRGB(o.color),n.emissive.copyLinearToSRGB(o.emissive),n.emissiveIntensity=o.emissiveIntensity,n.opacity=o.opacity,n.displacementScale=o.displacementScale,n.transparent=o.transparent,n.bumpMap=o.bumpMap,n.aoMap=o.aoMap,n.map=o.map,n.displacementMap=o.displacementMap,n.emissiveMap=o.emissiveMap,n.normalMap=o.normalMap,n.envMap=o.envMap,n.alphaMap=o.alphaMap,n.metalness=o.reflectivity,n.vertexColors=o.vertexColors,o.shininess&&(n.roughness=1-Math.sqrt(o.shininess)/10),n.needsUpdate=!0),e===void 0?s.material=n:i[e]=n,!0}let Th=!1;Ux((...s)=>{var t;B()&&((t=he.Current)!=null&&t.isInXR)&&(Ko(!0),t0("error",...s))});function Ko(s){if(s){if(Th)return;Th=!0,pS()}else{if(!Th)return;Th=!1,mS()}}const Jl={log:void 0,warn:void 0,error:void 0};class fS{constructor(){r(this,"familyName","needle-xr");r(this,"root",null);r(this,"context",null);r(this,"defaultFontSize",.06);r(this,"targetObject",new h.Object3D);r(this,"userForwardViewPoint",new h.Vector3);r(this,"oneEuroFilter",new Tm(90,.8));r(this,"_lastElementRemoveTime",0);r(this,"onBeforeRender",()=>{var e,i;const t=(e=this.context)==null?void 0:e.mainCamera;if(this.context&&t instanceof h.PerspectiveCamera){const n=this.getRoot();Number.isNaN(n.position.x)&&n.position.set(0,0,0),Number.isNaN(n.quaternion.x)&&n.quaternion.set(0,0,0,1),this.context.scene.add(this.targetObject);const o=((i=this.context.xr)==null?void 0:i.rigScale)??1,a=3.5*o,l=t.worldForward;l.y=0,l.normalize().multiplyScalar(a),this.userForwardViewPoint.copy(t.worldPosition).sub(l),this.targetObject.position.distanceTo(this.userForwardViewPoint)>2*o&&(this.targetObject.position.copy(this.userForwardViewPoint),Nc(this.targetObject,t,!0,!0),this.targetObject.rotateY(Math.PI)),this.oneEuroFilter.filter(this.targetObject.position,n.position,this.context.time.time);const d=this.context.time.deltaTime;if(n.quaternion.slerp(this.targetObject.quaternion,d*5),n.scale.setScalar(o),this.targetObject.removeFromParent(),this.context.scene.add(n),this.context.time.time-this._lastElementRemoveTime>.1){this._lastElementRemoveTime=this.context.time.time;const u=Date.now();for(let f=0;f<this._activeTexts.length;f++){const m=this._activeTexts[f];if(m instanceof ne.__webpack_exports__default.Text&&u-m._activatedTime>2e4){m.removeFromParent(),this._textBuffer.push(m),this._activeTexts.splice(f,1);break}}}}});r(this,"textOptions",{fontSize:this.defaultFontSize,fontFamily:this.familyName,padding:.03,margin:.005,color:0,backgroundColor:16777215,backgroundOpacity:.4,borderRadius:.03,offset:.025});r(this,"_textBuffer",[]);r(this,"_activeTexts",[]);this.ensureFont()}onEnable(){this.context=he.Current||he.All[0],this.context.pre_render_callbacks.push(this.onBeforeRender)}onDisable(){var t,e,i;(e=this.context)==null||e.pre_render_callbacks.splice((t=this.context)==null?void 0:t.pre_render_callbacks.indexOf(this.onBeforeRender),1),(i=this.root)==null||i.removeFromParent()}addLog(t,e){const i=this.getRoot(),n=this.getText();let o=16777215,a=0;switch(t){case"log":o=16777215,a=0;break;case"warn":o=16772761,a=4465152;break;case"error":o=16755370,a=7798784;break}e.length>1e3&&(e=e.substring(0,1e3)+"...");const l=new Date().toISOString().split("T")[1].split(".")[0];n.textContent="["+l+"] "+e,n.visible=!0,n._activatedTime=Date.now(),i.add(n),this._activeTexts.push(n),this.context&&this.context.scene.add(i),n.set({backgroundColor:o,color:a}),ne.__webpack_exports__default.update()}ensureFont(){let t=ne.__webpack_exports__default.FontLibrary.getFontFamily(this.familyName);if(!t){t=ne.__webpack_exports__default.FontLibrary.addFontFamily(this.familyName);const e=t.addVariant("normal","normal","./include/needle/arial-msdf.json","./include/needle/arial.png");e==null||e.addEventListener("ready",()=>{ne.__webpack_exports__default.update()})}}getText(){const t=this.getRoot();if(this._textBuffer.length>0){const i=this._textBuffer.pop();return i.visible=!0,setTimeout(()=>this.disableDepthTestRecursive(i),100),i}if(t.children.length>20&&this._activeTexts.length>0)return this._activeTexts.shift();const e=new ne.__webpack_exports__default.Text(this.textOptions);return setTimeout(()=>this.disableDepthTestRecursive(e),500),setTimeout(()=>this.disableDepthTestRecursive(e),1500),e}disableDepthTestRecursive(t,e=0){for(let n=0;n<t.children.length;n++){const o=t.children[n];o instanceof h.Object3D&&this.disableDepthTestRecursive(o,e+1)}t.renderOrder=10*e,t.layers.set(2);const i=t.material;i&&(i.depthWrite=!1,i.depthTest=!1,i.transparent=!0),e===0&&ne.__webpack_exports__default.update()}getRoot(){if(this.root)return this.root;const t=this.defaultFontSize,e={boxSizing:"border-box",fontFamily:this.familyName,width:"2.6",fontSize:t,color:0,lineHeight:1,backgroundColor:16777215,backgroundOpacity:0,whiteSpace:"pre-wrap",flexDirection:"column-reverse"};return this.root=new ne.__webpack_exports__default.Block(e),this.root}}let $t=null;function pS(){$t||($t=new fS),$t.onEnable();for(const s in Jl){Jl[s]=console[s];let t=!1;console[s]=function(){var e;if((e=Jl[s])==null||e.apply(console,arguments),!t)try{t=!0,t0(s,...arguments)}finally{t=!1}}}}function mS(){$t==null||$t.onDisable();for(const s in Jl)console[s]=Jl[s]}const gl=new Map;function t0(s,...t){try{switch(gl.clear(),s){case"log":$t==null||$t.addLog("log",e());break;case"warn":$t==null||$t.addLog("warn",e());break;case"error":$t==null||$t.addLog("error",e());break}}catch(o){console.error("Error in spatial console",o)}finally{gl.clear()}function e(){let o="";for(let a=0;a<t.length;a++){const l=t[a];o+=i(l),a<t.length-1&&(o+=", ")}return o}function i(o,a=0){if(typeof o=="string")return'"'+o+'"';if(typeof o=="number"){if(o%1!==0){const c=o.toFixed(5),d=c.indexOf(".");let u=c.length-1;for(;u>d&&c[u]==="0";)u--;return c.substring(0,u+1)}return o.toString()}else if(Array.isArray(o)){let l="[";for(let c=0;c<o.length;c++){const d=o[c];l+=i(d,a+1),c<o.length-1&&(l+=", ")}return l+="]",l}else{if(o===null)return"null";if(o===void 0)return"undefined";if(typeof o=="function")return o.name+"()"}if(o instanceof h.Vector2)return`(${i(o.x)}, ${i(o.y)})`;if(o instanceof h.Vector3)return`(${i(o.x)}, ${i(o.y)}, ${i(o.z)})`;if(o instanceof h.Vector4)return`(${i(o.x)}, ${i(o.y)}, ${i(o.z)}, ${i(o.w)})`;if(o instanceof h.Quaternion)return`(${i(o.x)}, ${i(o.y)}, ${i(o.z)}, ${i(o.w)})`;if(o instanceof h.Material||o instanceof h.Texture)return o.name;if(o instanceof h.Matrix3)return`[${o.elements.join(", ")}]`;if(o instanceof h.Matrix4)return`[${o.elements.join(", ")}]`;if(o instanceof h.Layers)return o.mask.toString();if(typeof o=="object"){if(gl.has(o))return"*";let l=`{
`;l+=n(a);const c=Object.keys(o);let d="";for(let u=0;u<c.length;u++){const f=c[u],m=o[f];if(gl.has(m)){d+="";continue}gl.set(m,!0),d+=f+":"+i(m,a+1),u<c.length-1&&(d+=", "),d.length>=60&&(d+=`
`,d+=n(a),l+=d,d="")}return l+=d,l+=`
}`,l}return o}function n(o){let a="";for(let l=0;l<o;l++)a+=" ";return a}}const gS=x("nodevlogs");function Te(s,t=bi.Log){Tn(t,s)}function pe(s){Te(s,bi.Warn)}function Wc(s){Te(s,bi.Error)}let zp,yf;function B(){if(gS)return!1;if(zp!==void 0)return zp;if(yf!==void 0)return yf;let s=Gt();return s||(s=window.location.hostname.endsWith(".local-credentialless.webcontainer.io")),yf=s,s}function _S(s){zp=s}let Wt,mi=null,An=null,_l=!1,F_=null;const i0="terminal",Il=x("console"),yS=x("noerrors")||x("noconsole")||window.crossOriginIsolated;Il&&Um();if(!yS&&(Il||Gt())){if(Gt()&&!Il){const t=new URL(window.location.href);t.searchParams.set("console","1"),console.log('🌵 Tip: You can add the "?console" query parameter to the url to show the debug console (on mobile it will automatically open in the bottom right corner when your get errors during development. In VR a spatial console will appear.)',`
Open this page to get the console: `+t.toString())}const s=exports.DeviceUtilities.isMobileDevice()||exports.DeviceUtilities.isQuest()&&B();if((s||Il)&&(Vx(),s0(),o0(!0),s)){const t=document.querySelector("needle-engine");t==null||t.addEventListener("enter-ar",()=>{(Il||Wt||Em()>0)&&x("noerrors")}),t==null||t.addEventListener("exit-ar",()=>{xS()})}}const Np=Symbol("consoleParent");function Um(){if(Wt){Wt.showSwitch();return}o0()}function n0(){Wt&&(Wt.hide(),Wt.hideSwitch())}function s0(){F_||(F_=setInterval(bS,500))}let U_=0;function bS(){const s=Em(),t=s!==U_;U_=s,t&&vS()}function vS(){Um(),An&&(An.setAttribute("error","true"),An.innerText="🤬")}function wS(){An&&(An.removeAttribute("error"),An.innerText=i0)}function xS(){mi&&mi[Np]&&mi[Np].appendChild(mi)}function o0(s=!1){if(Wt!==void 0||_l)return;_l=!0;const t=document.createElement("script");t.onload=()=>{if(!globalThis.VConsole){console.warn("🌵 Debug console failed to load."),_l=!1,Wt=null;return}_l=!1,s0(),Wt=new VConsole({pluginOrder:["default","needle-console"]});const e=globalThis["needle:codegen_files"];if(e&&e.length>0&&Wt.addPlugin(SS()),mi=PS(),mi&&(mi[Np]=mi.parentElement,mi.style.position="absolute",mi.style.zIndex=Number.MAX_SAFE_INTEGER.toString()),Wt.setSwitchPosition(20,30),An=CS(),An){An.innerText=i0,An.addEventListener("click",wS);const i=document.createElement("style"),n=40;i.innerHTML=`
#__vconsole .vc-switch {
border: 1px solid rgba(255, 255, 255, .1);
border-radius: 50%;
width: ${n}px;
height: ${n}px;
padding: 0;
line-height: ${n}px;
font-size: ${n*.4}px;
text-align: center;
background: #ffffff5c;
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
user-select: none;
pointer-events: auto;
transition: transform .2s ease-in-out;
box-shadow: 0px 7px 0.5rem 0px rgb(0 0 0 / 6%), inset 0px 0px 1.3rem rgba(0,0,0,.05);
font-family: 'Material Symbols Outlined';
color: black;
font-size: 2.3em;
font-weight: 100;
}
#__vconsole .vc-switch:hover {
cursor: pointer;
transform: scale(1.1);
transition: transform .1s ease-in-out, background .1s linear;
background: rgba(245, 245, 245, .8);
outline: rgba(0, 0, 0, .05) 1px solid;
}
#__vconsole .vc-switch[error] {
background: rgba(255,0,0,.2);
animation: vconsole-notify 1s ease-in-out;
line-height: 35px;
}
@keyframes vconsole-notify {
from {
transform: scale(1, 1);
}
10% {
transform: scale(1.3, 1.3);
}
70% {
transform: scale(1.4, 1.4);
}
to {
transform: scale(1, 1);
}
}
#__vconsole .vc-panel {
font-family: monospace;
font-size: 11px;
}
#__vconsole .vc-plugin-box.vc-actived {
height: 100%;
}
#__vconsole .vc-mask {
overflow: hidden;
}
`,mi==null||mi.prepend(i),s===!0&&Em()<=0&&n0(),console.log("🌵 Debug console has loaded")}},t.onerror=()=>{console.warn("🌵 Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),_l=!1,Wt=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function SS(){if(!globalThis.VConsole)return;const s=new VConsole.VConsolePlugin("needle-console","🌵 Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+s._id+" iframe");return s.on("renderTab",function(e){const i=globalThis["needle:codegen_files"];if(!i||i.length===0)return;let n=globalThis["needle:codegen_files"][0];const o=n.indexOf("?");o>-1&&(n=n.substring(0,o));const l=location.protocol+"//"+location.host+location.pathname+"/"+n,c=encodeURIComponent(l);s.fullUrl="https://viewer.needle.tools?inspect&file="+c;var d='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';e(d)}),s.on("show",function(){const e=t();e&&e.src!==s.fullUrl&&(e.src=s.fullUrl)}),s.on("hide",function(){const e=t();e&&(e.src="")}),s.on("addTopBar",function(e){var i=new Array;i.push({name:"Open in new window ↗",onClick:function(n){window.open(s.fullUrl,"_blank"),Wt==null||Wt.hide()}}),i.push({name:"Reload",onClick:function(n){const o=t();o&&(o.src=s.fullUrl)}}),i.push({name:"Fullscreen",onClick:function(n){const o=t();o.requestFullscreen?o.requestFullscreen():o.webkitRequestFullscreen instanceof Function&&o.webkitRequestFullscreen()}}),e(i)}),s}function CS(){const s=document.querySelector("#__vconsole .vc-switch");return s||null}function PS(){const s=document.querySelector("#__vconsole");return s||null}const r0=x("debugdefines");go('if(!globalThis[""4.4.0-beta.5""]) globalThis[""4.4.0-beta.5""] = "0.0.0";');go('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');go('if(!globalThis[""Tue Apr 08 2025 18:43:13 GMT+0200 (Central European Summer Time)""]) globalThis[""Tue Apr 08 2025 18:43:13 GMT+0200 (Central European Summer Time)""] = "unknown";');go('if(!globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""]) globalThis[""npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9""] = "unknown";');go('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.4.0-beta.5";');go('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');go('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Tue Apr 08 2025 18:43:13 GMT+0200 (Central European Summer Time)";');go('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9";');const ln="4.4.0-beta.5",wu="undefined",zm="Tue Apr 08 2025 18:43:13 GMT+0200 (Central European Summer Time)";r0&&console.log(`Engine version: ${ln} (generator: ${wu})
Project built at ${zm}`);const ec="npk_74222a9fbd1b42572cdd3bf7f639eeb17a07d07f40a6185fac5f722e8fd34df9",ps="needle_isActiveInHierarchy",Fo="builtin_components",tc="needle_editor_guid";function go(s){try{(0,eval)(s)}catch(t){r0&&console.error(t)}}const OS='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 160 187.74"><defs><linearGradient id="a" x1="89.64" y1="184.81" x2="90.48" y2="21.85" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#62d399"/><stop offset=".51" stop-color="#acd842"/><stop offset=".9" stop-color="#d7db0a"/></linearGradient><linearGradient id="b" x1="69.68" y1="178.9" x2="68.08" y2="16.77" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#0ba398"/><stop offset=".5" stop-color="#4ca352"/><stop offset="1" stop-color="#76a30a"/></linearGradient><linearGradient id="c" x1="36.6" y1="152.17" x2="34.7" y2="84.19" gradientUnits="userSpaceOnUse"><stop offset=".19" stop-color="#36a382"/><stop offset=".54" stop-color="#49a459"/><stop offset="1" stop-color="#76a30b"/></linearGradient><linearGradient id="d" x1="15.82" y1="153.24" x2="18" y2="90.86" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#267880"/><stop offset=".51" stop-color="#457a5c"/><stop offset="1" stop-color="#717516"/></linearGradient><linearGradient id="e" x1="135.08" y1="135.43" x2="148.93" y2="63.47" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#b0d939"/><stop offset="1" stop-color="#eadb04"/></linearGradient><linearGradient id="f" x1="-4163.25" y1="2285.12" x2="-4160.81" y2="2215.34" gradientTransform="rotate(20 4088.49 13316.712)" gradientUnits="userSpaceOnUse"><stop offset=".17" stop-color="#74af52"/><stop offset=".48" stop-color="#99be32"/><stop offset="1" stop-color="#c0c40a"/></linearGradient><symbol id="g" viewBox="0 0 160 187.74"><path style="fill:url(#a)" d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75z"/><path style="fill:url(#b)" d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98z"/><path style="fill:url(#c)" d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z"/><path style="fill:url(#d)" d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04z"/><path style="fill:#9c3" d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5z"/><path style="fill:url(#e)" d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59z"/><path style="fill:url(#f)" d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z"/><path style="fill:#ffe113" d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1z"/><path style="fill:#f3e600" d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75z"/></symbol></defs><use width="160" height="187.74" xlink:href="#g"/></svg>',MS=btoa(OS),RS="data:image/svg+xml;base64,"+MS,kS=RS,ES=`<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'> <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" version="1.1" viewBox="0 0 1014 282" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m665.95 132.73v44.88l-10.56-8.4c-0.8-0.64-1.2-1.44-1.2-2.4v-32.4c0-6.48-4.12-9.72-12.36-9.72-2.16 0-4.18 0.4-6.06 1.2s-3.54 1.8-4.98 3-2.56 2.5-3.36 3.9-1.2 2.7-1.2 3.9v40.92l-10.68-8.4c-0.72-0.64-1.08-1.44-1.08-2.4v-53.76l10.92 8.52c0.32 0.24 0.56 0.44 0.72 0.6s0.36 0.32 0.6 0.48c0.96-1.2 2.14-2.28 3.54-3.24s2.92-1.76 4.56-2.4 3.34-1.14 5.1-1.5 3.44-0.54 5.04-0.54c1.44 0 2.92 0.04 4.44 0.12s2.84 0.28 3.96 0.6c4.56 1.12 7.8 3.12 9.72 6s2.88 6.56 2.88 11.04z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m732.38 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m795.93 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.9