@needle-tools/engine 3.5.9-alpha → 3.5.9-alpha.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.
@@ -4970,7 +4970,7 @@ void main() {
4970
4970
  `,r=function(d,p,f){p=p||1024;let g=d.pos,m=-1,v=0,A="",b=String.fromCharCode.apply(null,new Uint16Array(d.subarray(g,g+128)));for(;0>(m=b.indexOf(s))&&v<p&&g<d.byteLength;)A+=b,v+=b.length,g+=128,b+=String.fromCharCode.apply(null,new Uint16Array(d.subarray(g,g+128)));return-1<m?(f!==!1&&(d.pos+=v+m+1),A+b.slice(0,m)):!1},n=function(d){const p=/^#\?(\S+)/,f=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,g=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,m=/^\s*FORMAT=(\S+)\s*$/,v=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,A={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let b,y;if(d.pos>=d.byteLength||!(b=r(d)))return t(1,"no header found");if(!(y=b.match(p)))return t(3,"bad initial token");for(A.valid|=1,A.programtype=y[1],A.string+=b+`
4971
4971
  `;b=r(d),b!==!1;){if(A.string+=b+`
4972
4972
  `,b.charAt(0)==="#"){A.comments+=b+`
4973
- `;continue}if((y=b.match(f))&&(A.gamma=parseFloat(y[1])),(y=b.match(g))&&(A.exposure=parseFloat(y[1])),(y=b.match(m))&&(A.valid|=2,A.format=y[1]),(y=b.match(v))&&(A.valid|=4,A.height=parseInt(y[1],10),A.width=parseInt(y[2],10)),A.valid&2&&A.valid&4)break}return A.valid&2?A.valid&4?A:t(3,"missing image size specifier"):t(3,"missing format specifier")},o=function(d,p,f){const g=p;if(g<8||g>32767||d[0]!==2||d[1]!==2||d[2]&128)return new Uint8Array(d);if(g!==(d[2]<<8|d[3]))return t(3,"wrong scanline width");const m=new Uint8Array(4*p*f);if(!m.length)return t(4,"unable to allocate buffer space");let v=0,A=0;const b=4*g,y=new Uint8Array(4),_=new Uint8Array(b);let w=f;for(;w>0&&A<d.byteLength;){if(A+4>d.byteLength)return t(1);if(y[0]=d[A++],y[1]=d[A++],y[2]=d[A++],y[3]=d[A++],y[0]!=2||y[1]!=2||(y[2]<<8|y[3])!=g)return t(3,"bad rgbe scanline format");let E=0,P;for(;E<b&&A<d.byteLength;){P=d[A++];const R=P>128;if(R&&(P-=128),P===0||E+P>b)return t(3,"bad scanline data");if(R){const T=d[A++];for(let z=0;z<P;z++)_[E++]=T}else _.set(d.subarray(A,A+P),E),E+=P,A+=P}const C=g;for(let R=0;R<C;R++){let T=0;m[v]=_[R+T],T+=g,m[v+1]=_[R+T],T+=g,m[v+2]=_[R+T],T+=g,m[v+3]=_[R+T],v+=4}w--}return m},a=function(d,p,f,g){const m=d[p+3],v=Math.pow(2,m-128)/255;f[g+0]=d[p+0]*v,f[g+1]=d[p+1]*v,f[g+2]=d[p+2]*v,f[g+3]=1},l=function(d,p,f,g){const m=d[p+3],v=Math.pow(2,m-128)/255;f[g+0]=Oh.toHalfFloat(Math.min(d[p+0]*v,65504)),f[g+1]=Oh.toHalfFloat(Math.min(d[p+1]*v,65504)),f[g+2]=Oh.toHalfFloat(Math.min(d[p+2]*v,65504)),f[g+3]=Oh.toHalfFloat(1)},c=new Uint8Array(e);c.pos=0;const u=n(c);if(u!==-1){const d=u.width,p=u.height,f=o(c.subarray(c.pos),d,p);if(f!==-1){let g,m,v;switch(this.type){case is:v=f.length/4;const A=new Float32Array(v*4);for(let y=0;y<v;y++)a(f,y*4,A,y*4);g=A,m=is;break;case ms:v=f.length/4;const b=new Uint16Array(v*4);for(let y=0;y<v;y++)l(f,y*4,b,y*4);g=b,m=ms;break;default:console.error("THREE.RGBELoader: unsupported type: ",this.type);break}return{width:d,height:p,data:g,header:u.string,gamma:u.gamma,exposure:u.exposure,type:m}}}return null}setDataType(e){return this.type=e,this}load(e,t,s,r){function n(o,a){switch(o.type){case is:case ms:o.encoding=Gi,o.minFilter=Qt,o.magFilter=Qt,o.generateMipmaps=!1,o.flipY=!0;break}t&&t(o,a)}return super.load(e,n,s,r)}}const tU=oe("debugautosync"),GM=Symbol("syncerId");class Yse{constructor(){h(this,"_syncers",{})}getOrCreateSyncer(e){if(!e.guid)return null;if(this._syncers[e.guid])return this._syncers[e.guid];const t=new Jse(e);return t[GM]=e.guid,this._syncers[t[GM]]=t,t}removeSyncer(e){delete this._syncers[e[GM]]}}const HM=new Yse;class Jse{constructor(e){h(this,"comp"),h(this,"hasChanges",!1),h(this,"changedProperties",{}),h(this,"data",{}),h(this,"_boundEvent"),h(this,"_handleReceivingMethod"),h(this,"_isReceiving",!1),h(this,"_isInit",!1),this.comp=e}get networkingKey(){return this.comp.constructor.name}init(e){if(this._isInit)return;this._isInit=!0,this.comp=e,this._boundEvent=this.onHandleSending.bind(this),this.comp.context.post_render_callbacks.push(this._boundEvent),this._handleReceivingMethod=this.onHandleReceiving.bind(this),this.comp.context.connection.beginListen(this.networkingKey,this._handleReceivingMethod);const t=this.comp.context.connection.tryGetState(this.comp.guid);t&&this.onHandleReceiving(t)}destroy(){this._isInit&&(this._boundEvent&&this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this._boundEvent),1),this._handleReceivingMethod&&this.comp.context.connection.stopListen(this.networkingKey,this._handleReceivingMethod),this.comp=null,this._isInit=!1)}notifyChanged(e,t){this._isReceiving||(this.hasChanges=!0,this.changedProperties[e]=t)}onHandleSending(){if(!this.hasChanges)return;this.hasChanges=!1;const e=this.comp.context.connection;if(!e||!e.isConnected){for(const t in this.changedProperties)delete this.changedProperties[t];return}for(const t in this.data)delete this.data[t];this.data.guid=this.comp.guid;for(const t in this.changedProperties){const s=this.changedProperties[t];delete this.changedProperties[t],this.data[t]=s}e.send(this.networkingKey,this.data)}onHandleReceiving(e){if(!this._isInit||!this.comp)return;const t=e.guid;if(!(t&&t!==this.comp.guid)){tU&&console.log("RECEIVED",this.comp.name,this.comp.guid,e);try{this._isReceiving=!0;for(const s in e){if(s==="guid")continue;const r=e[s];this.comp[s]=r}}catch(s){console.error(s)}finally{this._isReceiving=!1}}}}function Kse(i,e){let t=e!==i;if(!t&&i&&e){if(Array.isArray(i)&&Array.isArray(e))t=!0;else if(typeof i=="object"&&typeof e=="object"){for(const s of Object.keys(i))if(i[s]!==e[s]){t=!0;break}}}return t}const Jm=Symbol("AutoSyncHandler");function Zse(i){if(i[Jm])return i[Jm];const e=HM.getOrCreateSyncer(i);return e?.init(i),i[Jm]=e,e}function $se(i){const e=i[Jm];e&&(HM.removeSyncer(e),e.destroy(),delete i[Jm])}const VM=function(i){return function(e,t){let s=null,r;typeof i=="string"?r=e[i]:typeof i=="function"&&(r=i);const n=e,o=n.__internalAwake;tU&&console.log(t);const a=Symbol(t);n.__internalAwake=function(){if(this[a]!==void 0)return;this[a]=this[t],o.call(this),s=HM.getOrCreateSyncer(this);const c=Object.getOwnPropertyDescriptor(this,t);c?.set===void 0&&Object.defineProperty(this,t,{set:function(u){var d;const p=this[a];this[a]=u,Kse(u,p)&&r?.call(this,u,p)!==!1&&((d=Zse(this))==null||d.notifyChanged(t,u))},get:function(){return this[a]},configurable:!0,enumerable:!0}),s?.init(this)};const l=n.__internalDestroy;n.__internalDestroy=function(){$se(this),l.call(this)}}};var ere=Object.defineProperty,tre=Object.getOwnPropertyDescriptor,g_=(i,e,t,s)=>{for(var r=s>1?void 0:s?tre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&ere(e,t,r),r};const Km=oe("debugskybox");class _u extends Ee{constructor(){super(...arguments),h(this,"url"),h(this,"allowDrop",!0),h(this,"background",!0),h(this,"environment",!0),h(this,"_loader"),h(this,"_prevUrl"),h(this,"_prevLoadedEnvironment"),h(this,"_prevEnvironment",null),h(this,"_prevBackground",null),h(this,"dragOverEvent"),h(this,"dropEvent")}onEnable(){this.setSkybox(this.url),this.registerDropEvents()}onDisable(){var e;this.context.scene.environment===this._prevLoadedEnvironment&&(this.context.scene.environment=this._prevEnvironment,Ei.backgroundShouldBeTransparent(this.context)||(this.context.scene.background=this._prevBackground),this._prevLoadedEnvironment=void 0),this.unregisterDropEvents(),(e=this.context.mainCameraComponent)==null||e.applyClearFlags()}async setSkybox(e){var t;if(!e)return;if(!(e!=null&&e.endsWith(".hdr"))&&!e.endsWith(".exr")&&!e.endsWith(".jpg")&&!e.endsWith(".png")&&!e.endsWith(".jpeg")&&console.warn("Potentially invalid skybox url",this.url,"on",this.name),Km&&console.log("Remote skybox url?: "+e),this._prevUrl===e&&this._prevLoadedEnvironment){this.applySkybox();return}else(t=this._prevLoadedEnvironment)==null||t.dispose(),this._prevLoadedEnvironment=void 0;this._prevUrl=e;const s=e.endsWith(".exr"),r=e.endsWith(".hdr");s?this._loader instanceof fS||(this._loader=new fS):r?this._loader instanceof eU||(this._loader=new eU):this._loader instanceof tc||(this._loader=new tc),Km&&console.log("Loading skybox: "+e);const n=await this._loader.loadAsync(e);if(!n||!this.enabled)return;this.url=e;const o=e.lastIndexOf("/");n.name=e.substring(o>=0?o+1:0),this._loader instanceof tc&&(n.encoding=yt),this._prevLoadedEnvironment=n,this.applySkybox()}applySkybox(){var e;const t=this._prevLoadedEnvironment;t&&(t.mapping=Lu,t.needsUpdate=!0,this.context.scene.background!==t&&(this._prevBackground=this.context.scene.background),this.context.scene.environment!==t&&(this._prevEnvironment=this.context.scene.environment),Km&&console.log("Set remote skybox",this.url),this.environment&&(this.context.scene.environment=t),this.background&&!Ei.backgroundShouldBeTransparent(this.context)&&(this.context.scene.background=t),((e=this.context.mainCameraComponent)==null?void 0:e.backgroundBlurriness)!==void 0&&(this.context.scene.backgroundBlurriness=this.context.mainCameraComponent.backgroundBlurriness))}registerDropEvents(){this.dragOverEvent||(this.dragOverEvent=e=>{if(this.allowDrop&&e.dataTransfer)for(const t of e.dataTransfer.types)t==="text/uri-list"&&e.preventDefault()},this.dropEvent=e=>{var t,s,r,n;if(this.allowDrop&&(e.preventDefault(),!!e.dataTransfer)){for(const o of e.dataTransfer.types)if(o==="text/uri-list"){const a=e.dataTransfer.getData(o);Km&&console.log(o,a);let l=(s=(t=new RegExp(/polyhaven.com\/asset_img\/.+?\/(?<name>.+)\.png/).exec(a))==null?void 0:t.groups)==null?void 0:s.name;if(l||(l=(n=(r=new RegExp(/polyhaven\.com\/a\/(?<name>.+)/).exec(a))==null?void 0:r.groups)==null?void 0:n.name),Km&&console.log(l),l){const c="https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/"+l+"_1k.exr";this.setSkybox(c)}else console.warn("Could not resolve skybox name from dropped url",a)}}},this.context.domElement.addEventListener("dragover",this.dragOverEvent),this.context.domElement.addEventListener("drop",this.dropEvent))}unregisterDropEvents(){this.dragOverEvent&&(this.context.domElement.removeEventListener("dragover",this.dragOverEvent),this.context.domElement.removeEventListener("drop",this.dropEvent))}}g_([VM("setSkybox"),x(URL)],_u.prototype,"url",2),g_([x()],_u.prototype,"allowDrop",2),g_([x()],_u.prototype,"background",2),g_([x()],_u.prototype,"environment",2);var ire=Object.defineProperty,sre=Object.getOwnPropertyDescriptor,fa=(i,e,t,s)=>{for(var r=s>1?void 0:s?sre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&ire(e,t,r),r};const Ml=oe("debugsceneswitcher"),Zm="scene";ts.registerCallback($r.ContextRegistered,async i=>{Promise.resolve().then(()=>qne).then(e=>{const t=e.NeedleEngineHTMLElement;Ml&&console.log("SceneSwitcher: registering scene attribute",t.observedAttributes),t.observedAttributes.includes(Zm)||t.observedAttributes.push(Zm)})});const Kc=Promise.resolve(!1);class mn extends Ee{constructor(){super(...arguments),h(this,"scenes"),h(this,"queryParameterName","scene"),h(this,"clamp",!0),h(this,"useHistory",!0),h(this,"useKeyboard",!0),h(this,"useSwipe",!0),h(this,"useSceneLighting",!0),h(this,"preloadNext",1),h(this,"preloadPrevious",1),h(this,"preloadConcurrent",2),h(this,"_currentIndex",-1),h(this,"_currentScene"),h(this,"_engineElementOverserver"),h(this,"_preloadScheduler"),h(this,"onPopState",async e=>{if(!this.useHistory)return;let t=this.useHistory;try{this.useHistory=!1;let s=!1;if(this.queryParameterName&&(s=await this.tryLoadFromQueryParam()),!s){const r=e.state;if(r!==null&&r.startsWith(this.guid)){const n=r.substr(this.guid.length+2);console.log(n),await this.trySelectSceneFromValue(n)}}}finally{this.useHistory=t}}),h(this,"normalizedSwipeThresholdX",.1),h(this,"_didSwipe",!1),h(this,"onPointerMove",e=>{if(!this._didSwipe&&e.button===0&&e.pointerType==="touch"&&this.context.input.getPointerPressedCount()===1){const t=this.context.input.getPointerPositionDelta(e.button);if(t){const s=t.x/this.context.domWidth;s>=this.normalizedSwipeThresholdX?(this._didSwipe=!0,this.selectPrev()):s<=-this.normalizedSwipeThresholdX&&(this._didSwipe=!0,this.selectNext())}}}),h(this,"onPointerUp",e=>{e.button===0&&(this._didSwipe=!1)}),h(this,"onKeyDown",e=>{if(!this.useKeyboard||!this.scenes)return;const t=e.key.toLowerCase();if(!t)return;const s=parseInt(t)-1;if(s>=0){this.trySelectSceneFromValue(s);return}switch(t){case"arrowright":case"d":this.selectNext();break;case"arrowleft":case"a":this.selectPrev();break}})}get currentIndex(){return this._currentIndex}awake(){Ml&&console.log("SceneSwitcher",this)}async start(){if(this._currentIndex===-1&&!await this.tryLoadFromQueryParam()){const e=this.context.domElement.getAttribute(Zm);try{(e===null||!await this.trySelectSceneFromValue(e))&&this._currentIndex===-1&&this.select(0)}finally{}}}onEnable(){globalThis.addEventListener("popstate",this.onPopState),this.context.input.addEventListener(Uo.KeyDown,this.onKeyDown),this.context.input.addEventListener(Uo.PointerMove,this.onPointerMove),this.context.input.addEventListener(Uo.PointerUp,this.onPointerUp),this._engineElementOverserver||(this._engineElementOverserver=new MutationObserver(e=>{for(const t of e)if(t.type==="attributes"&&t.attributeName===Zm){const s=this.context.domElement.getAttribute(Zm);s!==null&&this.trySelectSceneFromValue(s)}})),this._engineElementOverserver.observe(this.context.domElement,{attributes:!0}),this._preloadScheduler||(this._preloadScheduler=new rre(this)),this._preloadScheduler.maxLoadAhead=this.preloadNext,this._preloadScheduler.maxLoadBehind=this.preloadPrevious,this._preloadScheduler.maxConcurrent=this.preloadConcurrent,this._preloadScheduler.begin()}onDisable(){var e;globalThis.removeEventListener("popstate",this.onPopState),this.context.input.removeEventListener(Uo.KeyDown,this.onKeyDown),this.context.input.removeEventListener(Uo.PointerMove,this.onPointerMove),this.context.input.removeEventListener(Uo.PointerUp,this.onPointerUp),(e=this._preloadScheduler)==null||e.stop()}selectNext(){return this.select(this._currentIndex+1)}selectPrev(){return this.select(this._currentIndex-1)}select(e){var t,s;if(Ml&&console.log("select",e),typeof e=="object"&&console.warn('Switching to "'+e+'" might not work. Please either use an index or a AssetReference (not a scene reference)'),typeof e=="string"){const n=(t=this.scenes)==null?void 0:t.find(o=>o.uri===e);if(!n){const o=lr.getOrCreate(this.sourceId??"",e,this.context);return this.switchScene(o)}if(n)e=this.scenes.indexOf(n);else return Kc}if(!((s=this.scenes)!=null&&s.length))return Kc;if(e<0){if(this.clamp)return Kc;e=this.scenes.length-1}else if(e>=this.scenes.length){if(this.clamp)return Kc;e=0}const r=this.scenes[e];return this.switchScene(r)}async switchScene(e){var t,s;if(e===this._currentScene)return!0;this._currentScene&&this._currentScene.unload();const r=this._currentIndex=((t=this.scenes)==null?void 0:t.indexOf(e))??-1;this._currentScene=e;try{const n=new CustomEvent("loadscene-start",{detail:{scene:e,switcher:this,index:r}});this.dispatchEvent(n),await e.loadAssetAsync();const o=new CustomEvent("loadscene-finished",{detail:{scene:e,switcher:this,index:r}});if(this.dispatchEvent(o),o.defaultPrevented)return Ml&&console.warn("Adding loaded scene prevented:",e,o),!1;if(!e.asset)return Ml&&console.warn("Failed loading scene:",e),!1;if(this._currentIndex===r){if($.add(e.asset,this.gameObject),this.useSceneLighting&&this.context.sceneLighting.enable(e),this.useHistory&&r>=0)if((s=this.queryParameterName)!=null&&s.length)NI(this.queryParameterName,r.toString(),this.useHistory);else{const a=history.state,l=this.guid+"::"+r;a!==l&&history.pushState(l,"unused",location.href)}return!0}}catch(n){console.error(n)}return!1}preload(e){if(e>=0&&e<this.scenes.length){const t=this.scenes[e];if(t instanceof lr)return t.preload()}return Kc}tryLoadFromQueryParam(){var e;if(!((e=this.queryParameterName)!=null&&e.length))return Kc;const t=oe(this.queryParameterName);return typeof t=="boolean"?Kc:this.trySelectSceneFromValue(t)}trySelectSceneFromValue(e){if(typeof e=="string"){const t=parseInt(e);if(t>=0&&t<this.scenes.length)return this.select(t);for(let s=0;s<this.scenes.length;s++)if(this.scenes[s].uri.toLowerCase().includes(e))return this.select(s)}else if(typeof e=="number"&&e>=0&&e<this.scenes.length)return this.select(e);return gr()&&console.warn('Can not find scene: "'+e+'"',this),Kc}}fa([x(lr)],mn.prototype,"scenes",2),fa([x()],mn.prototype,"queryParameterName",2),fa([x()],mn.prototype,"clamp",2),fa([x()],mn.prototype,"useHistory",2),fa([x()],mn.prototype,"useKeyboard",2),fa([x()],mn.prototype,"useSwipe",2),fa([x()],mn.prototype,"useSceneLighting",2),fa([x()],mn.prototype,"preloadNext",2),fa([x()],mn.prototype,"preloadPrevious",2),fa([x()],mn.prototype,"preloadConcurrent",2);class rre{constructor(e,t=1,s=1,r=2){h(this,"maxLoadAhead"),h(this,"maxLoadBehind"),h(this,"maxConcurrent"),h(this,"_isRunning",!1),h(this,"_switcher"),h(this,"_loadTasks",[]),h(this,"_maxConcurrentLoads",1),this._switcher=e,this.maxLoadAhead=t,this.maxLoadBehind=s,this.maxConcurrent=r}begin(){if(this._isRunning)return;Ml&&console.log("Preload begin"),this._isRunning=!0;let e=-1,t,s;const r=this._switcher.scenes;let n=setInterval(()=>{if(this.allLoaded()&&(Ml&&console.log("All scenes loaded"),this.stop()),!this._isRunning){clearInterval(n);return}if(this.canLoadNewScene()===!1)return;e!==this._switcher.currentIndex&&(e=this._switcher.currentIndex,s=0,t=0);const o=s%2===0;o&&(t+=1),s+=1;const a=o?this.maxLoadAhead:this.maxLoadBehind;if(t>a)return;let l=o?e+t:e-t;if(l<0||l<0||l>=r.length)return;const c=r[l];new nre(l,c,this._loadTasks)},200)}stop(){this._isRunning=!1}canLoadNewScene(){return this._loadTasks.length<this._maxConcurrentLoads}allLoaded(){for(const e of this._switcher.scenes)if(e?.isLoaded()===!1)return!1;return!0}}class nre{constructor(e,t,s){h(this,"index"),h(this,"asset"),h(this,"tasks"),this.index=e,this.asset=t,this.tasks=s,s.push(this),this.awaitLoading()}async awaitLoading(){this.asset.isLoaded()||(Ml&&console.log("Preload start: "+this.asset.uri,this.index),await this.asset.preload(),Ml&&console.log("Preload finished: "+this.asset.uri,this.index));const e=this.tasks.indexOf(this);e>=0&&this.tasks.splice(e,1)}}function ore(){return new Promise((i,e)=>{let t=()=>{t!=null&&(document.removeEventListener("pointerdown",t),document.removeEventListener("click",t),document.removeEventListener("dragstart",t),document.removeEventListener("touchstart",t),i())};document.addEventListener("pointerdown",t),document.addEventListener("click",t),document.addEventListener("dragstart",t),document.addEventListener("touchstart",t)})}async function are(i){await ore(),i()}var iU=(i=>(i[i.Quad=0]="Quad",i))(iU||{});class lre{static createPrimitive(e,t){let s;switch(e){case 0:const r=new Os(1,1,1,1),n=t?.material??new di({color:16777215});s=new ye(r,n)}return t!=null&&t.name&&(s.name=t.name),s}}var cre=Object.defineProperty,hre=Object.getOwnPropertyDescriptor,Yn=(i,e,t,s)=>{for(var r=s>1?void 0:s?hre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&cre(e,t,r),r};const ga=oe("debugvideo");var sU=(i=>(i[i.CameraFarPlane=0]="CameraFarPlane",i[i.CameraNearPlane=1]="CameraNearPlane",i[i.RenderTexture=2]="RenderTexture",i[i.MaterialOverride=3]="MaterialOverride",i))(sU||{});class Js extends Ee{constructor(){super(),h(this,"renderer",null),h(this,"playOnAwake",!0),h(this,"aspectMode",0),h(this,"clip",null),h(this,"renderMode"),h(this,"targetMaterialProperty"),h(this,"targetMaterialRenderer"),h(this,"targetTexture"),h(this,"time",0),h(this,"_playbackSpeed",1),h(this,"_isLooping",!1),h(this,"_muted",!1),h(this,"_audioOutputMode",2),h(this,"playInBackground",!0),h(this,"_crossOrigin","anonymous"),h(this,"source"),h(this,"url",null),h(this,"_videoElement",null),h(this,"_videoTexture",null),h(this,"_videoMaterial",null),h(this,"_isPlaying",!1),h(this,"wasPlaying",!1),h(this,"visibilityChanged",e=>{switch(document.visibilityState){case"hidden":this.playInBackground||(this.wasPlaying=this._isPlaying,this.pause());break;case"visible":this.wasPlaying&&!this._isPlaying&&this.play();break}}),h(this,"_receivedInput",!1),h(this,"_overlay",null),h(this,"_targetObjects"),h(this,"_updateAspectRoutineId",-1),are(()=>{this._receivedInput=!0,this.updateVideoElementSettings()}),this._targetObjects=[],oe("videoscreenspace")&&window.addEventListener("keydown",e=>{e.key==="f"&&(this.screenspace=!this.screenspace)})}get playbackSpeed(){var e;return((e=this._videoElement)==null?void 0:e.playbackRate)??this._playbackSpeed}set playbackSpeed(e){this._playbackSpeed=e,this._videoElement&&(this._videoElement.playbackRate=e)}get isLooping(){var e;return((e=this._videoElement)==null?void 0:e.loop)??this._isLooping}set isLooping(e){this._isLooping=e,this._videoElement&&(this._videoElement.loop=e)}get currentTime(){var e;return((e=this._videoElement)==null?void 0:e.currentTime)??this.time}set currentTime(e){this._videoElement?this._videoElement.currentTime=e:this.time=e}get isPlaying(){const e=this._videoElement;return!!(e&&(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>e.HAVE_CURRENT_DATA||e.srcObject&&e.srcObject.active))}get crossOrigin(){var e;return((e=this._videoElement)==null?void 0:e.crossOrigin)??this._crossOrigin}set crossOrigin(e){this._crossOrigin=e,this._videoElement&&(e!==null?this._videoElement.setAttribute("crossorigin",e):this._videoElement.removeAttribute("crossorigin"))}get videoMaterial(){return this._videoMaterial}get videoTexture(){return this._videoTexture}get videoElement(){return this._videoElement}get muted(){var e;return((e=this._videoElement)==null?void 0:e.muted)??this._muted}set muted(e){this._muted=e,this._videoElement&&(this._videoElement.muted=e)}set audioOutputMode(e){e!==this._audioOutputMode&&(e===1&&Rn()&&console.warn("VideoAudioOutputMode.AudioSource is not yet implemented"),this._audioOutputMode=e,this.updateVideoElementSettings())}get audioOutputMode(){return this._audioOutputMode}setVideo(e){this.clip=e,this.source=0,this._videoElement?(this._videoElement.srcObject=e,this._isPlaying&&this.play(),this.updateAspect()):this.create(!0)}setClipURL(e){this.url!==e&&(this.url=e,this.source=1,ga&&console.log("set url",e),this._videoElement?(this._videoElement.src=e,this._isPlaying&&(this.stop(),this.play())):this.create(!0))}onEnable(){var e,t;window.addEventListener("visibilitychange",this.visibilityChanged),this.playOnAwake===!0&&this.create(!0),this.screenspace?(e=this._overlay)==null||e.start():(t=this._overlay)==null||t.stop()}onDisable(){window.removeEventListener("visibilitychange",this.visibilityChanged),this.pause()}onDestroy(){var e;this._videoElement&&((e=this._videoElement.parentElement)==null||e.removeChild(this._videoElement),this._videoElement=null),this._videoTexture&&(this._videoTexture.dispose(),this._videoTexture=null)}play(){var e,t;this._videoElement||this.create(!1),this._videoElement&&(this._isPlaying&&!((e=this._videoElement)!=null&&e.ended)&&!((t=this._videoElement)!=null&&t.paused)||(this._isPlaying=!0,this._receivedInput||(this._videoElement.muted=!0),this.updateVideoElementSettings(),this._videoElement.currentTime=this.time,this._videoElement.play().catch(s=>{var r;console.log(s),ga&&console.error("Error playing video",s,"CODE="+s.code,(r=this.videoElement)==null?void 0:r.src,this),setTimeout(()=>{this._isPlaying&&!this.destroyed&&this.activeAndEnabled&&this.play()},1e3)}),ga&&console.log("play",this._videoElement,this.time)))}stop(){this._isPlaying=!1,this.time=0,this._videoElement&&(this._videoElement.currentTime=0,this._videoElement.pause(),ga&&console.log("STOP",this))}pause(){var e,t;this.time=((e=this._videoElement)==null?void 0:e.currentTime)??0,this._isPlaying=!1,(t=this._videoElement)==null||t.pause(),ga&&console.log("PAUSE",this,this.currentTime)}create(e){var t;let s;switch(this.source){case 0:s=this.clip;break;case 1:s=this.url;break}s&&(this._videoElement||(ga&&console.warn("Create VideoElement",this),this._videoElement=this.createVideoElement(),(t=this.context.domElement)==null||t.prepend(this._videoElement),this.updateVideoElementStyles()),typeof s=="string"?(ga&&console.log("Set Video src",s),this._videoElement.src=s):(ga&&console.log("Set Video srcObject",s),this._videoElement.srcObject=s),this._videoTexture||(this._videoTexture=new iP(this._videoElement)),this._videoTexture.flipY=!1,this._videoTexture.encoding=yt,this.handleBeginPlaying(e),ga&&console.log(this,e))}updateAspect(){this.aspectMode!==0&&this.startCoroutine(this.updateAspectImpl())}get screenspace(){var e;return((e=this._overlay)==null?void 0:e.enabled)??!1}set screenspace(e){var t;if(e){if(!this._videoTexture)return;this._overlay||(this._overlay=new ure(this.context)),this._overlay.add(this._videoTexture)}else(t=this._overlay)==null||t.remove(this._videoTexture);this._overlay&&(this._overlay.enabled=e)}createVideoElement(){const e=document.createElement("video");return this._crossOrigin&&e.setAttribute("crossorigin",this._crossOrigin),ga&&console.log("created video element",e),e}handleBeginPlaying(e){var t,s;if(!this.enabled||!this._videoElement)return;this._targetObjects.length=0;let r=this.gameObject;switch(this.renderMode){case 3:r=(t=this.targetMaterialRenderer)==null?void 0:t.gameObject,r||(r=(s=$.getComponent(this.gameObject,Ui))==null?void 0:s.gameObject);break;case 2:console.error("VideoPlayer renderTexture not implemented yet. Please use material override instead");return}if(!r){console.error("Missing target for video material renderer",this.name,sU[this.renderMode],this);return}const n=r.material;if(n)if(this._targetObjects.push(r),n!==this._videoMaterial&&(this._videoMaterial=n.clone(),r.material=this._videoMaterial),!this.targetMaterialProperty)this._videoMaterial.map=this._videoTexture;else switch(this.targetMaterialProperty){default:this._videoMaterial.map=this._videoTexture;break}else{console.warn("Can not play video, no material found, this might be a multimaterial case which is not supported yet");return}this.updateVideoElementSettings(),this.updateVideoElementStyles(),e&&this.play()}updateVideoElementSettings(){if(!this._videoElement)return;this._videoElement.loop=this._isLooping,this._videoElement.currentTime=this.currentTime,this._videoElement.playbackRate=this._playbackSpeed,this._videoElement.playsInline=!0;let e=!this._receivedInput||this.audioOutputMode===0;!e&&this._muted&&(e=!0),this._videoElement.muted=e,this.playOnAwake&&(this._videoElement.autoplay=!0)}updateVideoElementStyles(){this._videoElement&&(this._videoElement.style.userSelect="none",this._videoElement.style.visibility="hidden",this._videoElement.style.display="none",this.updateAspect())}*updateAspectImpl(){const e=++this._updateAspectRoutineId,t=void 0,s=this.clip;for(;e===this._updateAspectRoutineId&&this.aspectMode!==0&&this.clip&&s===this.clip&&this._isPlaying;){if(!s||typeof s=="string")return;let r;for(const n of s.getVideoTracks()){const o=n.getSettings();if(o&&o.width&&o.height){r=o.width/o.height;break}else r=this.context.renderer.domElement.clientWidth/this.context.renderer.domElement.clientHeight}if(r===void 0){for(let n=0;n<10;n++)yield;if(!this.isPlaying)break;continue}if(t===r){yield;continue}for(const n of this._targetObjects){let o=1;if(n.parent){const a=Us(n.parent);o=a.x/a.y}switch(this.aspectMode){case 1:n.scale.y=1/r*n.scale.x*o;break;case 2:n.scale.x=r*n.scale.y*o;break}}for(let n=0;n<3;n++)yield}}}Yn([x(Me)],Js.prototype,"renderer",2),Yn([x()],Js.prototype,"playOnAwake",2),Yn([x()],Js.prototype,"aspectMode",2),Yn([x(URL)],Js.prototype,"clip",2),Yn([x()],Js.prototype,"renderMode",2),Yn([x()],Js.prototype,"targetMaterialProperty",2),Yn([x(Ui)],Js.prototype,"targetMaterialRenderer",2),Yn([x(Ut)],Js.prototype,"targetTexture",2),Yn([x()],Js.prototype,"time",2),Yn([x()],Js.prototype,"playbackSpeed",1),Yn([x()],Js.prototype,"isLooping",1),Yn([x()],Js.prototype,"audioOutputMode",1);class ure{constructor(e){h(this,"context"),h(this,"_videos",[]),h(this,"_screenspaceModeQuad"),h(this,"_isInScreenspaceMode",!1),h(this,"_input"),this.context=e,this._input=new dre(this)}get enabled(){return this._isInScreenspaceMode}set enabled(e){e?this.start():this.stop()}add(e){this._videos.indexOf(e)===-1&&this._videos.push(e)}remove(e){if(!e)return;const t=this._videos.indexOf(e);t>=0&&this._videos.splice(t,1)}start(){var e;if(this._isInScreenspaceMode||this._videos.length<0)return;const t=this._videos[this._videos.length-1];if(!t)return;if(this._isInScreenspaceMode=!0,!this._screenspaceModeQuad){if(this._screenspaceModeQuad=lre.createPrimitive(iU.Quad,{material:new pre(t)}),!this._screenspaceModeQuad)return;this._screenspaceModeQuad.geometry.scale(2,2,2)}const s=this._screenspaceModeQuad;this.context.scene.add(s),this.updateScreenspaceMaterialUniforms();const r=s.material;r?.reset(),(e=this._input)==null||e.enable(r)}stop(){var e;this._isInScreenspaceMode=!1,this._screenspaceModeQuad&&((e=this._input)==null||e.disable(),this._screenspaceModeQuad.removeFromParent())}updateScreenspaceMaterialUniforms(){var e;const t=(e=this._screenspaceModeQuad)==null?void 0:e.material;t&&(t.screenAspect=this.context.domElement.clientWidth/this.context.domElement.clientHeight)}}class dre{constructor(e){h(this,"_onResizeScreenFn"),h(this,"_onKeyUpFn"),h(this,"_onMouseWheelFn"),h(this,"context"),h(this,"overlay"),h(this,"_material"),h(this,"_isPinching",!1),h(this,"_lastPinch",0),this.overlay=e,this.context=e.context}enable(e){this._material=e,window.addEventListener("resize",this._onResizeScreenFn=()=>{this.overlay.updateScreenspaceMaterialUniforms()}),window.addEventListener("keyup",this._onKeyUpFn=r=>{r.key==="Escape"&&this.overlay.stop()}),window.addEventListener("wheel",this._onMouseWheelFn=r=>{this.overlay.enabled&&(e.zoom+=r.deltaY*5e-4,r.preventDefault())},{passive:!1});const t=new W;window.addEventListener("mousemove",r=>{if(this.overlay.enabled&&this.context.input.getPointerPressed(0)){const n=new W(r.movementX,r.movementY);n.x/=this.context.domElement.clientWidth,n.y/=this.context.domElement.clientHeight,t.set(n.x,n.y),t.multiplyScalar(e.zoom/-this.context.time.deltaTime*.01),e.offset=e.offset.add(t)}}),window.addEventListener("pointermove",r=>{this.overlay.enabled&&this.context.input.getPointerPressed(0)&&this.context.input.getTouchesPressedCount()===1&&(t.set(r.movementX,r.movementY),t.multiplyScalar(e.zoom*-this.context.time.deltaTime*.05),e.offset=e.offset.add(t))});let s=0;window.addEventListener("touchstart",r=>{if(r.touches.length<2){this.context.time.time-s<.3&&this.overlay.stop(),s=this.context.time.time;return}this._isPinching=!0,this._lastPinch=0}),window.addEventListener("touchmove",r=>{if(!this._isPinching||!this._material)return;const n=r.touches[0],o=r.touches[1],a=n.clientX-o.clientX,l=n.clientY-o.clientY,c=Math.sqrt(a*a+l*l);if(this._lastPinch!==0){const u=c-this._lastPinch;this._material.zoom-=u*.004}this._lastPinch=c}),window.addEventListener("touchend",()=>{this._isPinching=!1})}disable(){this._onResizeScreenFn&&(window.removeEventListener("resize",this._onResizeScreenFn),this._onResizeScreenFn=void 0),this._onKeyUpFn&&(window.removeEventListener("keyup",this._onKeyUpFn),this._onKeyUpFn=void 0),this._onMouseWheelFn&&(window.removeEventListener("wheel",this._onMouseWheelFn),this._onMouseWheelFn=void 0)}}class pre extends Vt{constructor(e){super(),h(this,"_offset",new W),this.uniforms={map:{value:e},screenAspect:{value:1},offsetScale:{value:new it(0,0,1,1)}},this.vertexShader=`
4973
+ `;continue}if((y=b.match(f))&&(A.gamma=parseFloat(y[1])),(y=b.match(g))&&(A.exposure=parseFloat(y[1])),(y=b.match(m))&&(A.valid|=2,A.format=y[1]),(y=b.match(v))&&(A.valid|=4,A.height=parseInt(y[1],10),A.width=parseInt(y[2],10)),A.valid&2&&A.valid&4)break}return A.valid&2?A.valid&4?A:t(3,"missing image size specifier"):t(3,"missing format specifier")},o=function(d,p,f){const g=p;if(g<8||g>32767||d[0]!==2||d[1]!==2||d[2]&128)return new Uint8Array(d);if(g!==(d[2]<<8|d[3]))return t(3,"wrong scanline width");const m=new Uint8Array(4*p*f);if(!m.length)return t(4,"unable to allocate buffer space");let v=0,A=0;const b=4*g,y=new Uint8Array(4),_=new Uint8Array(b);let w=f;for(;w>0&&A<d.byteLength;){if(A+4>d.byteLength)return t(1);if(y[0]=d[A++],y[1]=d[A++],y[2]=d[A++],y[3]=d[A++],y[0]!=2||y[1]!=2||(y[2]<<8|y[3])!=g)return t(3,"bad rgbe scanline format");let E=0,P;for(;E<b&&A<d.byteLength;){P=d[A++];const R=P>128;if(R&&(P-=128),P===0||E+P>b)return t(3,"bad scanline data");if(R){const T=d[A++];for(let z=0;z<P;z++)_[E++]=T}else _.set(d.subarray(A,A+P),E),E+=P,A+=P}const C=g;for(let R=0;R<C;R++){let T=0;m[v]=_[R+T],T+=g,m[v+1]=_[R+T],T+=g,m[v+2]=_[R+T],T+=g,m[v+3]=_[R+T],v+=4}w--}return m},a=function(d,p,f,g){const m=d[p+3],v=Math.pow(2,m-128)/255;f[g+0]=d[p+0]*v,f[g+1]=d[p+1]*v,f[g+2]=d[p+2]*v,f[g+3]=1},l=function(d,p,f,g){const m=d[p+3],v=Math.pow(2,m-128)/255;f[g+0]=Oh.toHalfFloat(Math.min(d[p+0]*v,65504)),f[g+1]=Oh.toHalfFloat(Math.min(d[p+1]*v,65504)),f[g+2]=Oh.toHalfFloat(Math.min(d[p+2]*v,65504)),f[g+3]=Oh.toHalfFloat(1)},c=new Uint8Array(e);c.pos=0;const u=n(c);if(u!==-1){const d=u.width,p=u.height,f=o(c.subarray(c.pos),d,p);if(f!==-1){let g,m,v;switch(this.type){case is:v=f.length/4;const A=new Float32Array(v*4);for(let y=0;y<v;y++)a(f,y*4,A,y*4);g=A,m=is;break;case ms:v=f.length/4;const b=new Uint16Array(v*4);for(let y=0;y<v;y++)l(f,y*4,b,y*4);g=b,m=ms;break;default:console.error("THREE.RGBELoader: unsupported type: ",this.type);break}return{width:d,height:p,data:g,header:u.string,gamma:u.gamma,exposure:u.exposure,type:m}}}return null}setDataType(e){return this.type=e,this}load(e,t,s,r){function n(o,a){switch(o.type){case is:case ms:o.encoding=Gi,o.minFilter=Qt,o.magFilter=Qt,o.generateMipmaps=!1,o.flipY=!0;break}t&&t(o,a)}return super.load(e,n,s,r)}}const tU=oe("debugautosync"),GM=Symbol("syncerId");class Yse{constructor(){h(this,"_syncers",{})}getOrCreateSyncer(e){if(!e.guid)return null;if(this._syncers[e.guid])return this._syncers[e.guid];const t=new Jse(e);return t[GM]=e.guid,this._syncers[t[GM]]=t,t}removeSyncer(e){delete this._syncers[e[GM]]}}const HM=new Yse;class Jse{constructor(e){h(this,"comp"),h(this,"hasChanges",!1),h(this,"changedProperties",{}),h(this,"data",{}),h(this,"_boundEvent"),h(this,"_handleReceivingMethod"),h(this,"_isReceiving",!1),h(this,"_isInit",!1),this.comp=e}get networkingKey(){return this.comp.constructor.name}init(e){if(this._isInit)return;this._isInit=!0,this.comp=e,this._boundEvent=this.onHandleSending.bind(this),this.comp.context.post_render_callbacks.push(this._boundEvent),this._handleReceivingMethod=this.onHandleReceiving.bind(this),this.comp.context.connection.beginListen(this.networkingKey,this._handleReceivingMethod);const t=this.comp.context.connection.tryGetState(this.comp.guid);t&&this.onHandleReceiving(t)}destroy(){this._isInit&&(this._boundEvent&&this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this._boundEvent),1),this._handleReceivingMethod&&this.comp.context.connection.stopListen(this.networkingKey,this._handleReceivingMethod),this.comp=null,this._isInit=!1)}notifyChanged(e,t){this._isReceiving||(this.hasChanges=!0,this.changedProperties[e]=t)}onHandleSending(){if(!this.hasChanges)return;this.hasChanges=!1;const e=this.comp.context.connection;if(!e||!e.isConnected){for(const t in this.changedProperties)delete this.changedProperties[t];return}for(const t in this.data)delete this.data[t];this.data.guid=this.comp.guid;for(const t in this.changedProperties){const s=this.changedProperties[t];delete this.changedProperties[t],this.data[t]=s}e.send(this.networkingKey,this.data)}onHandleReceiving(e){if(!this._isInit||!this.comp)return;const t=e.guid;if(!(t&&t!==this.comp.guid)){tU&&console.log("RECEIVED",this.comp.name,this.comp.guid,e);try{this._isReceiving=!0;for(const s in e){if(s==="guid")continue;const r=e[s];this.comp[s]=r}}catch(s){console.error(s)}finally{this._isReceiving=!1}}}}function Kse(i,e){let t=e!==i;if(!t&&i&&e){if(Array.isArray(i)&&Array.isArray(e))t=!0;else if(typeof i=="object"&&typeof e=="object"){for(const s of Object.keys(i))if(i[s]!==e[s]){t=!0;break}}}return t}const Jm=Symbol("AutoSyncHandler");function Zse(i){if(i[Jm])return i[Jm];const e=HM.getOrCreateSyncer(i);return e?.init(i),i[Jm]=e,e}function $se(i){const e=i[Jm];e&&(HM.removeSyncer(e),e.destroy(),delete i[Jm])}const VM=function(i){return function(e,t){let s=null,r;typeof i=="string"?r=e[i]:typeof i=="function"&&(r=i);const n=e,o=n.__internalAwake;tU&&console.log(t);const a=Symbol(t);n.__internalAwake=function(){if(this[a]!==void 0)return;this[a]=this[t],o.call(this),s=HM.getOrCreateSyncer(this);const c=Object.getOwnPropertyDescriptor(this,t);c?.set===void 0&&Object.defineProperty(this,t,{set:function(u){var d;const p=this[a];this[a]=u,Kse(u,p)&&r?.call(this,u,p)!==!1&&((d=Zse(this))==null||d.notifyChanged(t,u))},get:function(){return this[a]},configurable:!0,enumerable:!0}),s?.init(this)};const l=n.__internalDestroy;n.__internalDestroy=function(){$se(this),l.call(this)}}};var ere=Object.defineProperty,tre=Object.getOwnPropertyDescriptor,g_=(i,e,t,s)=>{for(var r=s>1?void 0:s?tre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&ere(e,t,r),r};const Km=oe("debugskybox");class _u extends Ee{constructor(){super(...arguments),h(this,"url"),h(this,"allowDrop",!0),h(this,"background",!0),h(this,"environment",!0),h(this,"_loader"),h(this,"_prevUrl"),h(this,"_prevLoadedEnvironment"),h(this,"_prevEnvironment",null),h(this,"_prevBackground",null),h(this,"dragOverEvent"),h(this,"dropEvent")}onEnable(){this.setSkybox(this.url),this.registerDropEvents()}onDisable(){var e;this.context.scene.environment===this._prevLoadedEnvironment&&(this.context.scene.environment=this._prevEnvironment,Ei.backgroundShouldBeTransparent(this.context)||(this.context.scene.background=this._prevBackground),this._prevLoadedEnvironment=void 0),this.unregisterDropEvents(),(e=this.context.mainCameraComponent)==null||e.applyClearFlags()}async setSkybox(e){var t;if(!e)return;if(!(e!=null&&e.endsWith(".hdr"))&&!e.endsWith(".exr")&&!e.endsWith(".jpg")&&!e.endsWith(".png")&&!e.endsWith(".jpeg")&&console.warn("Potentially invalid skybox url",this.url,"on",this.name),Km&&console.log("Remote skybox url?: "+e),this._prevUrl===e&&this._prevLoadedEnvironment){this.applySkybox();return}else(t=this._prevLoadedEnvironment)==null||t.dispose(),this._prevLoadedEnvironment=void 0;this._prevUrl=e;const s=e.endsWith(".exr"),r=e.endsWith(".hdr");s?this._loader instanceof fS||(this._loader=new fS):r?this._loader instanceof eU||(this._loader=new eU):this._loader instanceof tc||(this._loader=new tc),Km&&console.log("Loading skybox: "+e);const n=await this._loader.loadAsync(e);if(!n||!this.enabled)return;this.url=e;const o=e.lastIndexOf("/");n.name=e.substring(o>=0?o+1:0),this._loader instanceof tc&&(n.encoding=yt),this._prevLoadedEnvironment=n,this.applySkybox()}applySkybox(){var e;const t=this._prevLoadedEnvironment;t&&(t.mapping=Lu,t.needsUpdate=!0,this.context.scene.background!==t&&(this._prevBackground=this.context.scene.background),this.context.scene.environment!==t&&(this._prevEnvironment=this.context.scene.environment),Km&&console.log("Set remote skybox",this.url),this.environment&&(this.context.scene.environment=t),this.background&&!Ei.backgroundShouldBeTransparent(this.context)&&(this.context.scene.background=t),((e=this.context.mainCameraComponent)==null?void 0:e.backgroundBlurriness)!==void 0&&(this.context.scene.backgroundBlurriness=this.context.mainCameraComponent.backgroundBlurriness))}registerDropEvents(){this.dragOverEvent||(this.dragOverEvent=e=>{if(this.allowDrop&&e.dataTransfer)for(const t of e.dataTransfer.types)t==="text/uri-list"&&e.preventDefault()},this.dropEvent=e=>{var t,s,r,n;if(this.allowDrop&&(e.preventDefault(),!!e.dataTransfer)){for(const o of e.dataTransfer.types)if(o==="text/uri-list"){const a=e.dataTransfer.getData(o);Km&&console.log(o,a);let l=(s=(t=new RegExp(/polyhaven.com\/asset_img\/.+?\/(?<name>.+)\.png/).exec(a))==null?void 0:t.groups)==null?void 0:s.name;if(l||(l=(n=(r=new RegExp(/polyhaven\.com\/a\/(?<name>.+)/).exec(a))==null?void 0:r.groups)==null?void 0:n.name),Km&&console.log(l),l){const c="https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/"+l+"_1k.exr";this.setSkybox(c)}else console.warn("Could not resolve skybox name from dropped url",a)}}},this.context.domElement.addEventListener("dragover",this.dragOverEvent),this.context.domElement.addEventListener("drop",this.dropEvent))}unregisterDropEvents(){this.dragOverEvent&&(this.context.domElement.removeEventListener("dragover",this.dragOverEvent),this.context.domElement.removeEventListener("drop",this.dropEvent))}}g_([VM("setSkybox"),x(URL)],_u.prototype,"url",2),g_([x()],_u.prototype,"allowDrop",2),g_([x()],_u.prototype,"background",2),g_([x()],_u.prototype,"environment",2);var ire=Object.defineProperty,sre=Object.getOwnPropertyDescriptor,fa=(i,e,t,s)=>{for(var r=s>1?void 0:s?sre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&ire(e,t,r),r};const Ml=oe("debugsceneswitcher"),Zm="scene";ts.registerCallback($r.ContextRegistered,async i=>{Promise.resolve().then(()=>Xne).then(e=>{const t=e.NeedleEngineHTMLElement;Ml&&console.log("SceneSwitcher: registering scene attribute",t.observedAttributes),t.observedAttributes.includes(Zm)||t.observedAttributes.push(Zm)})});const Kc=Promise.resolve(!1);class mn extends Ee{constructor(){super(...arguments),h(this,"scenes"),h(this,"queryParameterName","scene"),h(this,"clamp",!0),h(this,"useHistory",!0),h(this,"useKeyboard",!0),h(this,"useSwipe",!0),h(this,"useSceneLighting",!0),h(this,"preloadNext",1),h(this,"preloadPrevious",1),h(this,"preloadConcurrent",2),h(this,"_currentIndex",-1),h(this,"_currentScene"),h(this,"_engineElementOverserver"),h(this,"_preloadScheduler"),h(this,"onPopState",async e=>{if(!this.useHistory)return;let t=this.useHistory;try{this.useHistory=!1;let s=!1;if(this.queryParameterName&&(s=await this.tryLoadFromQueryParam()),!s){const r=e.state;if(r!==null&&r.startsWith(this.guid)){const n=r.substr(this.guid.length+2);console.log(n),await this.trySelectSceneFromValue(n)}}}finally{this.useHistory=t}}),h(this,"normalizedSwipeThresholdX",.1),h(this,"_didSwipe",!1),h(this,"onPointerMove",e=>{if(!this._didSwipe&&e.button===0&&e.pointerType==="touch"&&this.context.input.getPointerPressedCount()===1){const t=this.context.input.getPointerPositionDelta(e.button);if(t){const s=t.x/this.context.domWidth;s>=this.normalizedSwipeThresholdX?(this._didSwipe=!0,this.selectPrev()):s<=-this.normalizedSwipeThresholdX&&(this._didSwipe=!0,this.selectNext())}}}),h(this,"onPointerUp",e=>{e.button===0&&(this._didSwipe=!1)}),h(this,"onKeyDown",e=>{if(!this.useKeyboard||!this.scenes)return;const t=e.key.toLowerCase();if(!t)return;const s=parseInt(t)-1;if(s>=0){this.trySelectSceneFromValue(s);return}switch(t){case"arrowright":case"d":this.selectNext();break;case"arrowleft":case"a":this.selectPrev();break}})}get currentIndex(){return this._currentIndex}awake(){Ml&&console.log("SceneSwitcher",this)}async start(){if(this._currentIndex===-1&&!await this.tryLoadFromQueryParam()){const e=this.context.domElement.getAttribute(Zm);try{(e===null||!await this.trySelectSceneFromValue(e))&&this._currentIndex===-1&&this.select(0)}finally{}}}onEnable(){globalThis.addEventListener("popstate",this.onPopState),this.context.input.addEventListener(Uo.KeyDown,this.onKeyDown),this.context.input.addEventListener(Uo.PointerMove,this.onPointerMove),this.context.input.addEventListener(Uo.PointerUp,this.onPointerUp),this._engineElementOverserver||(this._engineElementOverserver=new MutationObserver(e=>{for(const t of e)if(t.type==="attributes"&&t.attributeName===Zm){const s=this.context.domElement.getAttribute(Zm);s!==null&&this.trySelectSceneFromValue(s)}})),this._engineElementOverserver.observe(this.context.domElement,{attributes:!0}),this._preloadScheduler||(this._preloadScheduler=new rre(this)),this._preloadScheduler.maxLoadAhead=this.preloadNext,this._preloadScheduler.maxLoadBehind=this.preloadPrevious,this._preloadScheduler.maxConcurrent=this.preloadConcurrent,this._preloadScheduler.begin()}onDisable(){var e;globalThis.removeEventListener("popstate",this.onPopState),this.context.input.removeEventListener(Uo.KeyDown,this.onKeyDown),this.context.input.removeEventListener(Uo.PointerMove,this.onPointerMove),this.context.input.removeEventListener(Uo.PointerUp,this.onPointerUp),(e=this._preloadScheduler)==null||e.stop()}selectNext(){return this.select(this._currentIndex+1)}selectPrev(){return this.select(this._currentIndex-1)}select(e){var t,s;if(Ml&&console.log("select",e),typeof e=="object"&&console.warn('Switching to "'+e+'" might not work. Please either use an index or a AssetReference (not a scene reference)'),typeof e=="string"){const n=(t=this.scenes)==null?void 0:t.find(o=>o.uri===e);if(!n){const o=lr.getOrCreate(this.sourceId??"",e,this.context);return this.switchScene(o)}if(n)e=this.scenes.indexOf(n);else return Kc}if(!((s=this.scenes)!=null&&s.length))return Kc;if(e<0){if(this.clamp)return Kc;e=this.scenes.length-1}else if(e>=this.scenes.length){if(this.clamp)return Kc;e=0}const r=this.scenes[e];return this.switchScene(r)}async switchScene(e){var t,s;if(e===this._currentScene)return!0;this._currentScene&&this._currentScene.unload();const r=this._currentIndex=((t=this.scenes)==null?void 0:t.indexOf(e))??-1;this._currentScene=e;try{const n=new CustomEvent("loadscene-start",{detail:{scene:e,switcher:this,index:r}});this.dispatchEvent(n),await e.loadAssetAsync();const o=new CustomEvent("loadscene-finished",{detail:{scene:e,switcher:this,index:r}});if(this.dispatchEvent(o),o.defaultPrevented)return Ml&&console.warn("Adding loaded scene prevented:",e,o),!1;if(!e.asset)return Ml&&console.warn("Failed loading scene:",e),!1;if(this._currentIndex===r){if($.add(e.asset,this.gameObject),this.useSceneLighting&&this.context.sceneLighting.enable(e),this.useHistory&&r>=0)if((s=this.queryParameterName)!=null&&s.length)NI(this.queryParameterName,r.toString(),this.useHistory);else{const a=history.state,l=this.guid+"::"+r;a!==l&&history.pushState(l,"unused",location.href)}return!0}}catch(n){console.error(n)}return!1}preload(e){if(e>=0&&e<this.scenes.length){const t=this.scenes[e];if(t instanceof lr)return t.preload()}return Kc}tryLoadFromQueryParam(){var e;if(!((e=this.queryParameterName)!=null&&e.length))return Kc;const t=oe(this.queryParameterName);return typeof t=="boolean"?Kc:this.trySelectSceneFromValue(t)}trySelectSceneFromValue(e){if(typeof e=="string"){const t=parseInt(e);if(t>=0&&t<this.scenes.length)return this.select(t);for(let s=0;s<this.scenes.length;s++)if(this.scenes[s].uri.toLowerCase().includes(e))return this.select(s)}else if(typeof e=="number"&&e>=0&&e<this.scenes.length)return this.select(e);return gr()&&console.warn('Can not find scene: "'+e+'"',this),Kc}}fa([x(lr)],mn.prototype,"scenes",2),fa([x()],mn.prototype,"queryParameterName",2),fa([x()],mn.prototype,"clamp",2),fa([x()],mn.prototype,"useHistory",2),fa([x()],mn.prototype,"useKeyboard",2),fa([x()],mn.prototype,"useSwipe",2),fa([x()],mn.prototype,"useSceneLighting",2),fa([x()],mn.prototype,"preloadNext",2),fa([x()],mn.prototype,"preloadPrevious",2),fa([x()],mn.prototype,"preloadConcurrent",2);class rre{constructor(e,t=1,s=1,r=2){h(this,"maxLoadAhead"),h(this,"maxLoadBehind"),h(this,"maxConcurrent"),h(this,"_isRunning",!1),h(this,"_switcher"),h(this,"_loadTasks",[]),h(this,"_maxConcurrentLoads",1),this._switcher=e,this.maxLoadAhead=t,this.maxLoadBehind=s,this.maxConcurrent=r}begin(){if(this._isRunning)return;Ml&&console.log("Preload begin"),this._isRunning=!0;let e=-1,t,s;const r=this._switcher.scenes;let n=setInterval(()=>{if(this.allLoaded()&&(Ml&&console.log("All scenes loaded"),this.stop()),!this._isRunning){clearInterval(n);return}if(this.canLoadNewScene()===!1)return;e!==this._switcher.currentIndex&&(e=this._switcher.currentIndex,s=0,t=0);const o=s%2===0;o&&(t+=1),s+=1;const a=o?this.maxLoadAhead:this.maxLoadBehind;if(t>a)return;let l=o?e+t:e-t;if(l<0||l<0||l>=r.length)return;const c=r[l];new nre(l,c,this._loadTasks)},200)}stop(){this._isRunning=!1}canLoadNewScene(){return this._loadTasks.length<this._maxConcurrentLoads}allLoaded(){for(const e of this._switcher.scenes)if(e?.isLoaded()===!1)return!1;return!0}}class nre{constructor(e,t,s){h(this,"index"),h(this,"asset"),h(this,"tasks"),this.index=e,this.asset=t,this.tasks=s,s.push(this),this.awaitLoading()}async awaitLoading(){this.asset.isLoaded()||(Ml&&console.log("Preload start: "+this.asset.uri,this.index),await this.asset.preload(),Ml&&console.log("Preload finished: "+this.asset.uri,this.index));const e=this.tasks.indexOf(this);e>=0&&this.tasks.splice(e,1)}}function ore(){return new Promise((i,e)=>{let t=()=>{t!=null&&(document.removeEventListener("pointerdown",t),document.removeEventListener("click",t),document.removeEventListener("dragstart",t),document.removeEventListener("touchstart",t),i())};document.addEventListener("pointerdown",t),document.addEventListener("click",t),document.addEventListener("dragstart",t),document.addEventListener("touchstart",t)})}async function are(i){await ore(),i()}var iU=(i=>(i[i.Quad=0]="Quad",i))(iU||{});class lre{static createPrimitive(e,t){let s;switch(e){case 0:const r=new Os(1,1,1,1),n=t?.material??new di({color:16777215});s=new ye(r,n)}return t!=null&&t.name&&(s.name=t.name),s}}var cre=Object.defineProperty,hre=Object.getOwnPropertyDescriptor,Yn=(i,e,t,s)=>{for(var r=s>1?void 0:s?hre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&cre(e,t,r),r};const ga=oe("debugvideo");var sU=(i=>(i[i.CameraFarPlane=0]="CameraFarPlane",i[i.CameraNearPlane=1]="CameraNearPlane",i[i.RenderTexture=2]="RenderTexture",i[i.MaterialOverride=3]="MaterialOverride",i))(sU||{});class Js extends Ee{constructor(){super(),h(this,"renderer",null),h(this,"playOnAwake",!0),h(this,"aspectMode",0),h(this,"clip",null),h(this,"renderMode"),h(this,"targetMaterialProperty"),h(this,"targetMaterialRenderer"),h(this,"targetTexture"),h(this,"time",0),h(this,"_playbackSpeed",1),h(this,"_isLooping",!1),h(this,"_muted",!1),h(this,"_audioOutputMode",2),h(this,"playInBackground",!0),h(this,"_crossOrigin","anonymous"),h(this,"source"),h(this,"url",null),h(this,"_videoElement",null),h(this,"_videoTexture",null),h(this,"_videoMaterial",null),h(this,"_isPlaying",!1),h(this,"wasPlaying",!1),h(this,"visibilityChanged",e=>{switch(document.visibilityState){case"hidden":this.playInBackground||(this.wasPlaying=this._isPlaying,this.pause());break;case"visible":this.wasPlaying&&!this._isPlaying&&this.play();break}}),h(this,"_receivedInput",!1),h(this,"_overlay",null),h(this,"_targetObjects"),h(this,"_updateAspectRoutineId",-1),are(()=>{this._receivedInput=!0,this.updateVideoElementSettings()}),this._targetObjects=[],oe("videoscreenspace")&&window.addEventListener("keydown",e=>{e.key==="f"&&(this.screenspace=!this.screenspace)})}get playbackSpeed(){var e;return((e=this._videoElement)==null?void 0:e.playbackRate)??this._playbackSpeed}set playbackSpeed(e){this._playbackSpeed=e,this._videoElement&&(this._videoElement.playbackRate=e)}get isLooping(){var e;return((e=this._videoElement)==null?void 0:e.loop)??this._isLooping}set isLooping(e){this._isLooping=e,this._videoElement&&(this._videoElement.loop=e)}get currentTime(){var e;return((e=this._videoElement)==null?void 0:e.currentTime)??this.time}set currentTime(e){this._videoElement?this._videoElement.currentTime=e:this.time=e}get isPlaying(){const e=this._videoElement;return!!(e&&(e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>e.HAVE_CURRENT_DATA||e.srcObject&&e.srcObject.active))}get crossOrigin(){var e;return((e=this._videoElement)==null?void 0:e.crossOrigin)??this._crossOrigin}set crossOrigin(e){this._crossOrigin=e,this._videoElement&&(e!==null?this._videoElement.setAttribute("crossorigin",e):this._videoElement.removeAttribute("crossorigin"))}get videoMaterial(){return this._videoMaterial}get videoTexture(){return this._videoTexture}get videoElement(){return this._videoElement}get muted(){var e;return((e=this._videoElement)==null?void 0:e.muted)??this._muted}set muted(e){this._muted=e,this._videoElement&&(this._videoElement.muted=e)}set audioOutputMode(e){e!==this._audioOutputMode&&(e===1&&Rn()&&console.warn("VideoAudioOutputMode.AudioSource is not yet implemented"),this._audioOutputMode=e,this.updateVideoElementSettings())}get audioOutputMode(){return this._audioOutputMode}setVideo(e){this.clip=e,this.source=0,this._videoElement?(this._videoElement.srcObject=e,this._isPlaying&&this.play(),this.updateAspect()):this.create(!0)}setClipURL(e){this.url!==e&&(this.url=e,this.source=1,ga&&console.log("set url",e),this._videoElement?(this._videoElement.src=e,this._isPlaying&&(this.stop(),this.play())):this.create(!0))}onEnable(){var e,t;window.addEventListener("visibilitychange",this.visibilityChanged),this.playOnAwake===!0&&this.create(!0),this.screenspace?(e=this._overlay)==null||e.start():(t=this._overlay)==null||t.stop()}onDisable(){window.removeEventListener("visibilitychange",this.visibilityChanged),this.pause()}onDestroy(){var e;this._videoElement&&((e=this._videoElement.parentElement)==null||e.removeChild(this._videoElement),this._videoElement=null),this._videoTexture&&(this._videoTexture.dispose(),this._videoTexture=null)}play(){var e,t;this._videoElement||this.create(!1),this._videoElement&&(this._isPlaying&&!((e=this._videoElement)!=null&&e.ended)&&!((t=this._videoElement)!=null&&t.paused)||(this._isPlaying=!0,this._receivedInput||(this._videoElement.muted=!0),this.updateVideoElementSettings(),this._videoElement.currentTime=this.time,this._videoElement.play().catch(s=>{var r;console.log(s),ga&&console.error("Error playing video",s,"CODE="+s.code,(r=this.videoElement)==null?void 0:r.src,this),setTimeout(()=>{this._isPlaying&&!this.destroyed&&this.activeAndEnabled&&this.play()},1e3)}),ga&&console.log("play",this._videoElement,this.time)))}stop(){this._isPlaying=!1,this.time=0,this._videoElement&&(this._videoElement.currentTime=0,this._videoElement.pause(),ga&&console.log("STOP",this))}pause(){var e,t;this.time=((e=this._videoElement)==null?void 0:e.currentTime)??0,this._isPlaying=!1,(t=this._videoElement)==null||t.pause(),ga&&console.log("PAUSE",this,this.currentTime)}create(e){var t;let s;switch(this.source){case 0:s=this.clip;break;case 1:s=this.url;break}s&&(this._videoElement||(ga&&console.warn("Create VideoElement",this),this._videoElement=this.createVideoElement(),(t=this.context.domElement)==null||t.prepend(this._videoElement),this.updateVideoElementStyles()),typeof s=="string"?(ga&&console.log("Set Video src",s),this._videoElement.src=s):(ga&&console.log("Set Video srcObject",s),this._videoElement.srcObject=s),this._videoTexture||(this._videoTexture=new iP(this._videoElement)),this._videoTexture.flipY=!1,this._videoTexture.encoding=yt,this.handleBeginPlaying(e),ga&&console.log(this,e))}updateAspect(){this.aspectMode!==0&&this.startCoroutine(this.updateAspectImpl())}get screenspace(){var e;return((e=this._overlay)==null?void 0:e.enabled)??!1}set screenspace(e){var t;if(e){if(!this._videoTexture)return;this._overlay||(this._overlay=new ure(this.context)),this._overlay.add(this._videoTexture)}else(t=this._overlay)==null||t.remove(this._videoTexture);this._overlay&&(this._overlay.enabled=e)}createVideoElement(){const e=document.createElement("video");return this._crossOrigin&&e.setAttribute("crossorigin",this._crossOrigin),ga&&console.log("created video element",e),e}handleBeginPlaying(e){var t,s;if(!this.enabled||!this._videoElement)return;this._targetObjects.length=0;let r=this.gameObject;switch(this.renderMode){case 3:r=(t=this.targetMaterialRenderer)==null?void 0:t.gameObject,r||(r=(s=$.getComponent(this.gameObject,Ui))==null?void 0:s.gameObject);break;case 2:console.error("VideoPlayer renderTexture not implemented yet. Please use material override instead");return}if(!r){console.error("Missing target for video material renderer",this.name,sU[this.renderMode],this);return}const n=r.material;if(n)if(this._targetObjects.push(r),n!==this._videoMaterial&&(this._videoMaterial=n.clone(),r.material=this._videoMaterial),!this.targetMaterialProperty)this._videoMaterial.map=this._videoTexture;else switch(this.targetMaterialProperty){default:this._videoMaterial.map=this._videoTexture;break}else{console.warn("Can not play video, no material found, this might be a multimaterial case which is not supported yet");return}this.updateVideoElementSettings(),this.updateVideoElementStyles(),e&&this.play()}updateVideoElementSettings(){if(!this._videoElement)return;this._videoElement.loop=this._isLooping,this._videoElement.currentTime=this.currentTime,this._videoElement.playbackRate=this._playbackSpeed,this._videoElement.playsInline=!0;let e=!this._receivedInput||this.audioOutputMode===0;!e&&this._muted&&(e=!0),this._videoElement.muted=e,this.playOnAwake&&(this._videoElement.autoplay=!0)}updateVideoElementStyles(){this._videoElement&&(this._videoElement.style.userSelect="none",this._videoElement.style.visibility="hidden",this._videoElement.style.display="none",this.updateAspect())}*updateAspectImpl(){const e=++this._updateAspectRoutineId,t=void 0,s=this.clip;for(;e===this._updateAspectRoutineId&&this.aspectMode!==0&&this.clip&&s===this.clip&&this._isPlaying;){if(!s||typeof s=="string")return;let r;for(const n of s.getVideoTracks()){const o=n.getSettings();if(o&&o.width&&o.height){r=o.width/o.height;break}else r=this.context.renderer.domElement.clientWidth/this.context.renderer.domElement.clientHeight}if(r===void 0){for(let n=0;n<10;n++)yield;if(!this.isPlaying)break;continue}if(t===r){yield;continue}for(const n of this._targetObjects){let o=1;if(n.parent){const a=Us(n.parent);o=a.x/a.y}switch(this.aspectMode){case 1:n.scale.y=1/r*n.scale.x*o;break;case 2:n.scale.x=r*n.scale.y*o;break}}for(let n=0;n<3;n++)yield}}}Yn([x(Me)],Js.prototype,"renderer",2),Yn([x()],Js.prototype,"playOnAwake",2),Yn([x()],Js.prototype,"aspectMode",2),Yn([x(URL)],Js.prototype,"clip",2),Yn([x()],Js.prototype,"renderMode",2),Yn([x()],Js.prototype,"targetMaterialProperty",2),Yn([x(Ui)],Js.prototype,"targetMaterialRenderer",2),Yn([x(Ut)],Js.prototype,"targetTexture",2),Yn([x()],Js.prototype,"time",2),Yn([x()],Js.prototype,"playbackSpeed",1),Yn([x()],Js.prototype,"isLooping",1),Yn([x()],Js.prototype,"audioOutputMode",1);class ure{constructor(e){h(this,"context"),h(this,"_videos",[]),h(this,"_screenspaceModeQuad"),h(this,"_isInScreenspaceMode",!1),h(this,"_input"),this.context=e,this._input=new dre(this)}get enabled(){return this._isInScreenspaceMode}set enabled(e){e?this.start():this.stop()}add(e){this._videos.indexOf(e)===-1&&this._videos.push(e)}remove(e){if(!e)return;const t=this._videos.indexOf(e);t>=0&&this._videos.splice(t,1)}start(){var e;if(this._isInScreenspaceMode||this._videos.length<0)return;const t=this._videos[this._videos.length-1];if(!t)return;if(this._isInScreenspaceMode=!0,!this._screenspaceModeQuad){if(this._screenspaceModeQuad=lre.createPrimitive(iU.Quad,{material:new pre(t)}),!this._screenspaceModeQuad)return;this._screenspaceModeQuad.geometry.scale(2,2,2)}const s=this._screenspaceModeQuad;this.context.scene.add(s),this.updateScreenspaceMaterialUniforms();const r=s.material;r?.reset(),(e=this._input)==null||e.enable(r)}stop(){var e;this._isInScreenspaceMode=!1,this._screenspaceModeQuad&&((e=this._input)==null||e.disable(),this._screenspaceModeQuad.removeFromParent())}updateScreenspaceMaterialUniforms(){var e;const t=(e=this._screenspaceModeQuad)==null?void 0:e.material;t&&(t.screenAspect=this.context.domElement.clientWidth/this.context.domElement.clientHeight)}}class dre{constructor(e){h(this,"_onResizeScreenFn"),h(this,"_onKeyUpFn"),h(this,"_onMouseWheelFn"),h(this,"context"),h(this,"overlay"),h(this,"_material"),h(this,"_isPinching",!1),h(this,"_lastPinch",0),this.overlay=e,this.context=e.context}enable(e){this._material=e,window.addEventListener("resize",this._onResizeScreenFn=()=>{this.overlay.updateScreenspaceMaterialUniforms()}),window.addEventListener("keyup",this._onKeyUpFn=r=>{r.key==="Escape"&&this.overlay.stop()}),window.addEventListener("wheel",this._onMouseWheelFn=r=>{this.overlay.enabled&&(e.zoom+=r.deltaY*5e-4,r.preventDefault())},{passive:!1});const t=new W;window.addEventListener("mousemove",r=>{if(this.overlay.enabled&&this.context.input.getPointerPressed(0)){const n=new W(r.movementX,r.movementY);n.x/=this.context.domElement.clientWidth,n.y/=this.context.domElement.clientHeight,t.set(n.x,n.y),t.multiplyScalar(e.zoom/-this.context.time.deltaTime*.01),e.offset=e.offset.add(t)}}),window.addEventListener("pointermove",r=>{this.overlay.enabled&&this.context.input.getPointerPressed(0)&&this.context.input.getTouchesPressedCount()===1&&(t.set(r.movementX,r.movementY),t.multiplyScalar(e.zoom*-this.context.time.deltaTime*.05),e.offset=e.offset.add(t))});let s=0;window.addEventListener("touchstart",r=>{if(r.touches.length<2){this.context.time.time-s<.3&&this.overlay.stop(),s=this.context.time.time;return}this._isPinching=!0,this._lastPinch=0}),window.addEventListener("touchmove",r=>{if(!this._isPinching||!this._material)return;const n=r.touches[0],o=r.touches[1],a=n.clientX-o.clientX,l=n.clientY-o.clientY,c=Math.sqrt(a*a+l*l);if(this._lastPinch!==0){const u=c-this._lastPinch;this._material.zoom-=u*.004}this._lastPinch=c}),window.addEventListener("touchend",()=>{this._isPinching=!1})}disable(){this._onResizeScreenFn&&(window.removeEventListener("resize",this._onResizeScreenFn),this._onResizeScreenFn=void 0),this._onKeyUpFn&&(window.removeEventListener("keyup",this._onKeyUpFn),this._onKeyUpFn=void 0),this._onMouseWheelFn&&(window.removeEventListener("wheel",this._onMouseWheelFn),this._onMouseWheelFn=void 0)}}class pre extends Vt{constructor(e){super(),h(this,"_offset",new W),this.uniforms={map:{value:e},screenAspect:{value:1},offsetScale:{value:new it(0,0,1,1)}},this.vertexShader=`
4974
4974
  uniform sampler2D map;
4975
4975
  uniform float screenAspect;
4976
4976
  uniform vec4 offsetScale;
@@ -5049,9 +5049,9 @@ void main() {
5049
5049
  #include <encodings_fragment>
5050
5050
 
5051
5051
  }
5052
- `;function wne(i){const e="vec4("+i.r.toFixed(3)+","+i.g.toFixed(3)+","+i.b.toFixed(3)+","+i.a.toFixed(3)+")";console.log(e);const t=new ye(new Os(2,2),new Vt({name:"BackgroundMaterial",uniforms:pw.clone(rn.background.uniforms),vertexShader:rn.background.vertexShader,fragmentShader:xne.replace("<backgroundTint>",e),side:bi,depthTest:!1,depthWrite:!1,fog:!1}));return t.geometry.deleteAttribute("normal"),Object.defineProperty(t.material,"map",{get:function(){return this.threeTexture}}),t.renderOrder=-1e4,t.layers.disableAll(),t.layers.enable(2),t.frustumCulled=!1,t.setTexture=function(s){t.material.uniforms.t2D.value=s},t}var Cne=Object.defineProperty,Sne=Object.getOwnPropertyDescriptor,Wp=(i,e,t,s)=>{for(var r=s>1?void 0:s?Sne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Cne(e,t,r),r};const Ene=oe("debugimagetracking"),P_=class{constructor(i,e,t,s,r,n){h(this,"measuredSize"),h(this,"state"),h(this,"_position"),h(this,"_rotation"),h(this,"_trackingComponent"),h(this,"_trackedImage"),h(this,"_bitmap"),h(this,"_pose"),this._trackingComponent=i,this._trackedImage=e,this._bitmap=t,this.measuredSize=s,this.state=r,this._pose=n}get url(){return this._trackedImage.image??""}get widthInMeters(){return this._trackedImage.widthInMeters??void 0}get bitmap(){return this._bitmap}get model(){return this._trackedImage}getPosition(i){return this.ensureTransformData(),i.copy(this._position),i}getQuaternion(i){return this.ensureTransformData(),i.copy(this._rotation),i}applyToObject(i,e=void 0){this.ensureTransformData();const t=i.position.distanceToSquared(this._position)>.05||i.quaternion.angleTo(this._rotation)>.05;e===void 0||e>=1||t?(i.position.copy(this._position),i.quaternion.copy(this._rotation)):(e=Math.max(0,Math.min(1,e)),i.position.lerp(this._position,e),i.quaternion.slerp(this._rotation,e)),i.quaternion.multiply(P_.y180)}ensureTransformData(){if(!this._position){this._position=P_._positionBuffer.get(),this._rotation=P_._rotationBuffer.get();const i=this._pose.transform;this._position.set(i.position.x,i.position.y,i.position.z),this._rotation.set(i.orientation.x,i.orientation.y,i.orientation.z,i.orientation.w)}}};let Mu=P_;h(Mu,"y180",new we().setFromAxisAngle(new S(0,1,0),Math.PI)),h(Mu,"_positionBuffer",new Bo(()=>new S,20)),h(Mu,"_rotationBuffer",new Bo(()=>new we,20));class Rl{constructor(){h(this,"image"),h(this,"widthInMeters"),h(this,"object"),h(this,"createObjectInstance",!1),h(this,"imageDoesNotMove",!1)}}Wp([x(URL)],Rl.prototype,"image",2),Wp([x()],Rl.prototype,"widthInMeters",2),Wp([x(lr)],Rl.prototype,"object",2),Wp([x()],Rl.prototype,"createObjectInstance",2),Wp([x()],Rl.prototype,"imageDoesNotMove",2);class Mne{constructor(e,t,s){h(this,"filename"),h(this,"widthInMeters"),h(this,"imageData"),this.filename=e,this.imageData=t,this.widthInMeters=s}get extensionName(){return"image-tracking"}onAfterHierarchy(e,t){t.beginBlock('def Preliminary_ReferenceImage "AnchoringReferenceImage"'),t.appendLine("uniform asset image = @tracker/"+this.filename+"@"),t.appendLine("uniform double physicalWidth = "+(this.widthInMeters*100).toFixed(8)),t.closeBlock()}onAfterSerialize(e){e.files["tracker/"+this.filename]=this.imageData}}var hI;const pv=(hI=class extends Ee{constructor(){super(...arguments),h(this,"trackedImages"),h(this,"trackedImageIndexMap",new Map),h(this,"xr",null),h(this,"onModifyAROptions",i=>{var e;const t=i.detail,s=t.optionalFeatures||[];s.includes("image-tracking")||s.push("image-tracking"),t.optionalFeatures=s,t.trackedImages=[];for(const r of this.trackedImages)if((e=r.image)!=null&&e.length&&r.widthInMeters>0){const n=pv._imageElements.get(r.image);n&&(this.trackedImageIndexMap.set(t.trackedImages.length,r),t.trackedImages.push({image:n,widthInMeters:r.widthInMeters}))}}),h(this,"imageToObjectMap",new Map),h(this,"onImageTrackingUpdate",i=>{const e=i.detail;for(const[t,s]of this.imageToObjectMap){if(!s.object||!t)continue;let r=!1;for(const n of e)if(n.model===t){r=!0;break}r||$.setActive(s.object,!1)}for(const t of e){const s=t.model;if(!s.object)continue;let r=this.imageToObjectMap.get(s);if(r===void 0)r={object:null,frames:0},this.imageToObjectMap.set(s,r),s.object.loadAssetAsync().then(n=>{s.createObjectInstance&&(n=$.instantiate(n)),n&&(r.object=n,this.xr&&this.xr.Rig.add(n),t.applyToObject(n),n.activeSelf||$.setActive(n,!0))});else{if(r.frames++,s.imageDoesNotMove&&r.frames>10||!r.object)continue;this.xr&&this.xr.Rig.add(r.object),t.applyToObject(r.object),r.object.activeSelf||$.setActive(r.object,!0)}}}),h(this,"onXRStarted",i=>{for(const e of this.imageToObjectMap.values())e.frames=0}),h(this,"onXRUpdate",i=>{const e=i.frame;if(e){if(e.session&&!("getImageTrackingResults"in e)){ho('Image tracking is currently not supported on this device. On Chrome for Android, you can enable the <a href="chrome://flags/#webxr-incubations">chrome://flags/#webxr-incubations</a> flag.');return}if(e.session&&typeof e.getImageTrackingResults=="function"){const t=e.getImageTrackingResults();if(t.length){const s=this.context.renderer.xr.getReferenceSpace();if(s){const r=[];for(const n of t){const o=n.index,a=this.trackedImageIndexMap.get(o);if(a){const l=e.getPose(n.imageSpace,s),c=n.trackingState,u=new Mu(this,a,n.image,n.measuredSize,c,l);r.push(u)}else Ene&&console.warn("No tracked image for index",o)}if(r.length>0)try{this.dispatchEvent(new CustomEvent("image-tracking",{detail:r}))}catch(n){console.error(n)}}}}}})}awake(){for(const i of this.trackedImages)if(i.image&&!pv._imageElements.has(i.image)){const e=i.image;pv._imageElements.set(e,null);const t=document.createElement("img");t.src=e,t.addEventListener("load",async()=>{const s=await createImageBitmap(t);pv._imageElements.set(e,s);const r=await RL(s);if(r){const n=await(await new Promise(a=>r.toBlob(a,"image/png",1))).arrayBuffer(),o=$.findObjectOfType(Xn);o&&(o.extensions.push(new Mne("marker.png",new Uint8Array(n),this.trackedImages[0].widthInMeters)),o.anchoringType="image")}})}}onEnable(){this.xr=$.findObjectOfType(wt),wt.addEventListener(_i.ModifyAROptions,this.onModifyAROptions),wt.addEventListener(_i.XRStarted,this.onXRStarted),wt.addEventListener(_i.XRUpdate,this.onXRUpdate),this.addEventListener("image-tracking",this.onImageTrackingUpdate)}onDisable(){wt.removeEventListener(_i.ModifyAROptions,this.onModifyAROptions),wt.removeEventListener(_i.XRStarted,this.onXRStarted),wt.removeEventListener(_i.XRUpdate,this.onXRUpdate),this.removeEventListener("image-tracking",this.onImageTrackingUpdate)}},h(hI,"_imageElements",new Map),hI);let B_=pv;Wp([x(Rl)],B_.prototype,"trackedImages",2);var Ine=Object.defineProperty,Tne=Object.getOwnPropertyDescriptor,Rne=(i,e,t,s)=>{for(var r=s>1?void 0:s?Tne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Ine(e,t,r),r};const yU=oe("debugplanetracking");class k_ extends Ee{constructor(){super(...arguments),h(this,"planeTemplate"),h(this,"onModifyAROptions",e=>{const t=e.detail,s=t.optionalFeatures||[];s.includes("plane-detection")||s.push("plane-detection"),t.optionalFeatures=s}),h(this,"onXRUpdate",e=>{this.processPlanes(e.rig,e.frame)}),h(this,"_planeId",1),h(this,"_allPlanes",new Map)}get trackedPlanes(){return this._allPlanes.values()}onEnable(){wt.addEventListener(_i.XRUpdate,this.onXRUpdate),wt.addEventListener("modify-ar-options",this.onModifyAROptions)}onDisable(){wt.removeEventListener(_i.XRUpdate,this.onXRUpdate),wt.removeEventListener("modify-ar-options",this.onModifyAROptions)}processPlanes(e,t){const s=this.context.renderer;if(!e||t.detectedPlanes===void 0)return;const r=s.xr.getReferenceSpace();if(r){for(const n of this._allPlanes.keys())if(!t.detectedPlanes.has(n)){const o=this._allPlanes.get(n);this._allPlanes.delete(n),yU&&console.log("Plane no longer tracked, id="+o.id),o.mesh&&e?.remove(o.mesh);const a=new CustomEvent("plane-tracking",{detail:{type:"plane-removed",context:o}});this.dispatchEvent(a)}for(const n of t.detectedPlanes){const o=t.getPose(n.planeSpace,r);let a;if(this._allPlanes.has(n)){const l=this._allPlanes.get(n);if(a=l.mesh,l.timestamp<n.lastChangedTime){if(l.timestamp=n.lastChangedTime,l.mesh){const u=this.createGeometry(n.polygon);if(l.mesh instanceof ye)l.mesh.geometry.dispose(),l.mesh.geometry=u;else if(l.mesh instanceof En)for(const d of l.mesh.children)d instanceof ye&&(d.geometry.dispose(),d.geometry=u);l.collider&&(l.collider.sharedMesh=l.mesh,l.collider.convex=!0,l.collider.onDisable(),l.collider.onEnable())}const c=new CustomEvent("plane-tracking",{detail:{type:"plane-updated",context:l}});this.dispatchEvent(c)}}else if(this.planeTemplate||(this.planeTemplate=new ye),this.planeTemplate){const l=$.instantiate(this.planeTemplate);a=l,l instanceof ye&&(go(l.geometry),l.geometry=this.createGeometry(n.polygon));const c=l.getComponent(Mm);c&&(c.sharedMesh=l,c.convex=!0,c.onDisable(),c.onEnable()),l.matrixAutoUpdate=!1,l.matrixWorldNeedsUpdate=!0,e.add(l);const u={id:this._planeId++,xrPlane:n,timestamp:n.lastChangedTime,mesh:l,collider:c};this._allPlanes.set(n,u),yU&&console.log("New plane detected, id="+u.id);try{const d=new CustomEvent("plane-tracking",{detail:{type:"plane-added",context:u}});this.dispatchEvent(d)}catch(d){console.error(d)}}a&&(o?(a.visible=!0,a.matrix.fromArray(o.transform.matrix)):a.visible=!1)}}}createGeometry(e){const t=new At,s=[],r=[];e.forEach(p=>{s.push(p.x,p.y,p.z),r.push(p.x,p.z)});const n=new S(s[0],s[1],s[2]),o=new S(s[3],s[4],s[5]),a=new S(s[6],s[7],s[8]),l=new S,c=new S;l.subVectors(o,n),c.subVectors(a,n),l.cross(c),l.normalize();const u=[];for(let p=0;p<s.length/3;p++)u.push(l.x,l.y,l.z);const d=[];for(let p=2;p<e.length;++p)d.push(0,p-1,p);return t.setAttribute("position",new rt(new Float32Array(s),3)),t.setAttribute("uv",new rt(new Float32Array(r),2)),t.setAttribute("normal",new rt(new Float32Array(u),3)),t.setIndex(d),t}}Rne([x(Me)],k_.prototype,"planeTemplate",2);class D_{constructor(){h(this,"guid"),h(this,"dontSave",!0),h(this,"userId"),h(this,"point",{x:0,y:0,z:0}),h(this,"source",{x:0,y:0,z:0}),h(this,"target")}update(e,t,s,r=void 0){this.userId=e.connection.connectionId,this.point.x=t.x,this.point.y=t.y,this.point.z=t.z,this.source.x=s.x,this.source.y=s.y,this.source.z=s.z,this.target=r}}class uI extends Ee{constructor(){super(...arguments),h(this,"prefab",null),h(this,"_grabModels",[]),h(this,"_grabModelsUpdateTime",[]),h(this,"_addOrUpdateSub",null),h(this,"_endSub",null),h(this,"_freeSub",null),h(this,"_instances",{}),h(this,"temp",new S)}awake(){this.prefab&&(this.prefab.visible=!1)}onEnable(){this._addOrUpdateSub=this.context.connection.beginListen("xr-grab-visual-start-or-update",this.onRemoteGrabStartOrUpdate.bind(this)),this._endSub=this.context.connection.beginListen("xr-grab-visual-end",this.onRemoteGrabEnd.bind(this)),this._freeSub=ra.AddEventListener(Ab.WillFree,this.onAttachedObjectFree.bind(this))}onDisable(){this.context.connection.stopListen("xr-grab-visual-start-or-update",this._addOrUpdateSub),this.context.connection.stopListen("xr-grab-visual-end",this._endSub),ra.RemoveEventListener(Ab.WillFree,this._freeSub)}addOrUpdateGrab(e){this.context.connection.send("xr-grab-visual-start-or-update",e,Ur.Queued)}endGrab(e){this.context.connection.send("xr-grab-visual-end",e,Ur.Queued)}onRemoteGrabStartOrUpdate(e){if(!this.prefab)return;const t=this._instances[e.guid];if(!t){const s=$.instantiate(this.prefab);if(s.visible=!0,this._instances[e.guid]={instance:s,model:e},e.userId){const r=$.getComponentsInChildren(s,Pu);if(r?.length>0)for(const n of r)n.assignUserColor(e.userId)}return}t.model=e}onRemoteGrabEnd(e){if(!e)return;const t=e.guid;this._instances[t]&&($.destroy(this._instances[t].instance),delete this._instances[t])}onAttachedObjectFree(e){if(this._grabModels.length<=0)return;const t=this._grabModels[0];this.updateModel(t,e),this.endGrab(t)}onBeforeRender(){if(this.updateRendering(),!!this.prefab&&(this.prefab.visible=!1,this.context.time.frameCount%10===0))for(let e=0;e<ra.Current.length;e++){const t=ra.Current[e];if(!t.controller||!t.selected)continue;this._grabModels.length<=e&&(this._grabModels.push(new D_),this._grabModelsUpdateTime.push(0)),this._grabModelsUpdateTime[e]=this.context.time.time;const s=this._grabModels[e];this.updateModel(s,t),this.addOrUpdateGrab(s)}}updateModel(e,t){if(!t.controller||!t.selected)return;e.guid=t.grabUUID;const s=t.selected.guid;e.update(this.context,t.grabPoint,t.controller.worldPosition,s)}updateRendering(){const e=this.context.time.deltaTime/.5;for(const t in this._instances){const{instance:s,model:r}=this._instances[t];if(!s||!r)continue;const{point:n}=r,o=xt(s);this.temp.set(n.x,n.y,n.z),o.lerp(this.temp,e),rs(s,o)}}}class dI{}const Pne=Object.freeze(Object.defineProperty({__proto__:null,ActionBuilder:ni,ActionCollection:kS,ActionModel:xo,AlignmentConstraint:Hg,Animation:yo,AnimationCurve:Jh,AnimationExtension:Hy,AnimationTrackHandler:Mb,Animator:jr,AnimatorController:Ru,Antialiasing:wm,AttachedObject:ra,AudioExtension:Tb,AudioListener:gp,AudioSource:os,AudioTrackHandler:bm,AvatarBlink_Simple:ru,AvatarEyeLook_Rotation:Ap,AvatarLoader:Yy,AvatarMarker:hr,AvatarModel:Xy,Avatar_Brain_LookAt:Yg,Avatar_MouthShapes:Cm,Avatar_MustacheShake:NE,Avatar_POI:Rr,AxesHelper:yp,BaseUIComponent:Ro,BasicIKConstraint:QE,BehaviorExtension:Pb,BehaviorModel:Ir,Behaviour:Ee,Bloom:nu,BoxCollider:Em,BoxGizmo:eu,BoxHelperComponent:Jo,Button:xl,CallInfo:qh,Camera:Ei,Canvas:dr,CanvasGroup:Cp,CapsuleCollider:zc,ChangeMaterialOnClick:Rm,ChangeTransformOnClick:cu,CharacterController:hu,CharacterControllerInput:Cl,ChromaticAberration:km,Collider:oa,ColorAdjustments:Hc,ColorBySpeedModule:uu,ColorOverLifetimeModule:Om,Component:fc,ControlTrackHandler:Ib,CustomBranding:Yc,Deletable:lM,DeleteBox:Xb,DepthOfField:Io,DeviceFlag:Yb,DocumentExtension:cM,DragControls:Pp,DropListener:Fm,Duplicatable:fu,EmissionModule:ha,EmphasizeOnClick:Mp,EventList:Gr,EventListEvent:Dy,EventSystem:Hn,EventTrigger:Zb,FieldWithDefault:CS,FixedJoint:yM,FlyControls:bM,Fog:kp,GltfExport:Ol,GltfExportBox:MM,Gradient:Vc,Graphic:au,GraphicRaycaster:PE,GridHelper:Op,GridLayoutGroup:$E,GroundProjectedEnv:gu,GroupActionModel:Mc,HideOnStart:sM,HingeJoint:Nm,HorizontalLayoutGroup:ZE,Image:xp,InheritVelocityModule:qc,InputField:vu,Interactable:tp,LODGroup:Qm,LODModel:Au,Light:Yr,LimitVelocityOverLifetimeModule:us,LogStats:RM,LookAt:yu,LookAtConstraint:Wg,MainModule:Ws,MaskableGraphic:Tm,MeshCollider:Mm,MeshRenderer:Fy,MinMaxCurve:tt,MinMaxGradient:Xr,NestedGltf:s_,Networking:pu,NoiseModule:hi,ObjectRaycaster:iu,OffsetConstraint:bu,OpenURL:Np,OrbitControls:Nc,Outline:_p,Padding:jc,ParticleBurst:Dm,ParticleSubEmitter:d_,ParticleSystem:$i,ParticleSystemRenderer:El,PixelationEffect:Ym,PlayAnimationOnClick:Gc,PlayAudioOnClick:Ip,PlayableDirector:vm,PlayerColor:Pu,PointerEventData:tu,PostProcessingHandler:f_,PreliminaryAction:Rp,PreliminaryTrigger:Pm,RGBAColor:vi,RawImage:Fb,Raycaster:fp,Rect:XE,RectTransform:ur,ReflectionProbe:Xd,RegisteredAnimationInfo:Qy,RemoteSkybox:_u,Renderer:Ui,RendererLightmap:Qg,Rigidbody:Di,RotationBySpeedModule:fn,RotationOverLifetimeModule:Wn,SceneSwitcher:mn,ScreenCapture:$m,ScreenSpaceAmbientOcclusion:Il,SetActiveOnClick:Ep,ShadowCatcher:iv,ShapeModule:Ki,SignalAsset:gm,SignalReceiver:vp,SignalReceiverEvent:mp,SignalTrackHandler:_m,Size:qE,SizeBySpeedModule:kr,SizeOverLifetimeModule:Wc,SkinnedMeshRenderer:SS,SmoothFollow:Zc,SpatialHtml:XM,SpatialTrigger:nv,SpatialTriggerReceiver:ma,SpectatorCamera:b_,SphereCollider:Sm,Sprite:Tl,SpriteData:Hp,SpriteRenderer:xu,SpriteSheet:ov,SubEmitterSystem:Xm,SyncedCamera:x_,SyncedRoom:$c,SyncedTransform:Oc,TapGestureTrigger:nM,TeleportTarget:vb,TestRunner:rI,TestSimulateUserData:nI,Text:Dr,TextBuilder:Wb,TextExtension:qb,TextureSheetAnimationModule:qs,TiltShiftEffect:va,ToneMapping:lv,TrailModule:Ii,TransformData:Gy,TransformGizmo:Su,TriggerBuilder:Hr,TriggerModel:Yh,UIRaycastUtils:cp,UIRootComponent:om,USDZExporter:Xn,USDZText:Xc,UsageMarker:ip,VRUserState:Al,VariantAction:BS,VelocityOverLifetimeModule:Oi,VerticalLayoutGroup:KE,VideoPlayer:Js,Vignette:Eu,VisibilityAction:Bm,Voip:kl,Volume:I_,VolumeParameter:Dt,VolumeProfile:xm,WebAR:um,WebARCameraBackground:R_,WebARSessionRoot:Pc,WebXR:wt,WebXRAvatar:kc,WebXRController:cs,WebXRImageTracking:B_,WebXRImageTrackingModel:Rl,WebXRPlaneTracking:k_,WebXRSync:cm,WebXRTrackedImage:Mu,XRFlag:Tr,XRGrabModel:D_,XRGrabRendering:uI,XRRig:yb,XRState:Zo,__Ignore:dI},Symbol.toStringTag,{value:"Module"}));var Bne=Object.defineProperty,kne=Object.getOwnPropertyDescriptor,bU=(i,e,t,s)=>{for(var r=s>1?void 0:s?kne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Bne(e,t,r),r};const O_=oe("debugplayersync");class pI extends Ee{constructor(){super(...arguments),h(this,"asset"),h(this,"joinedRoomFunction")}awake(){this.watchTabVisible(),this.joinedRoomFunction=this.onUserJoined.bind(this)}onEnable(){this.context.connection.beginListen(Fi.JoinedRoom,this.joinedRoomFunction)}onDisable(){this.context.connection.stopListen(Fi.JoinedRoom,this.joinedRoomFunction)}async onUserJoined(e){var t,s;O_&&console.log("PlayerSync.onUserJoined",e);const r=await((t=this.asset)==null?void 0:t.instantiateSynced({parent:this.gameObject},!0));if(r){let n=$.getComponent(r,qp);n?n.owner=this.context.connection.connectionId:(console.error("<strong>Failed finding PlayerState on "+((s=this.asset)==null?void 0:s.uri)+"</strong>: please make sure the asset has a PlayerState component!"),$.destroySynced(r))}else console.warn("PlayerSync: failed instantiating asset!")}watchTabVisible(){window.addEventListener("visibilitychange",e=>{if(document.visibilityState==="visible")for(let t=qp.all.length-1;t>=0;t--){const s=qp.all[t];(!s.owner||!this.context.connection.userIsInRoom(s.owner))&&s.doDestroy()}})}}bU([x(lr)],pI.prototype,"asset",2);var _U=(i=>(i.OwnerChanged="ownerChanged",i))(_U||{}),fv;const Ks=(fv=class extends Ee{constructor(){super(...arguments),h(this,"owner")}static get all(){return Ks._all}static get local(){return Ks._local}static isLocalPlayer(i){if(i instanceof Me){const e=$.getComponentInParent(i,Ks);return e?.isLocalPlayer??!1}else if(i instanceof fc){const e=$.getComponentInParent(i.gameObject,Ks);return e?.isLocalPlayer??!1}return!1}static addEventListener(i,e){return this._callbacks[i]||(this._callbacks[i]=[]),this._callbacks[i].push(e),e}static removeEventListener(i,e){if(!this._callbacks[i])return;const t=this._callbacks[i].indexOf(e);t>=0&&this._callbacks[i].splice(t,1)}static dispatchEvent(i,e){if(this._callbacks[i])for(const t of this._callbacks[i])t(e)}get isLocalPlayer(){return this.owner===this.context.connection.connectionId}onOwnerChange(i,e){O_&&console.log("PlayerSync.onOwnerChange",this,"newOwner",i,"oldOwner",e);const t=Ks._local.indexOf(this);t>=0&&Ks._local.splice(t,1);const s={playerState:this,oldValue:e,newValue:i};if(this.owner===this.context.connection.connectionId){Ks._local.push(this);const n=new CustomEvent("local-owner-changed",{detail:s});this.dispatchEvent(n),Ks.dispatchEvent("ownerChanged",n)}const r=new CustomEvent("owner-changed",{detail:s});this.dispatchEvent(r),Ks.dispatchEvent("ownerChanged",r)}awake(){Ks.all.push(this),O_&&console.log("Registered new PlayerState",this,Ks.all.length-1,Ks.all),this.context.connection.beginListen(Fi.UserLeftRoom,i=>{if(i.userId===this.owner){this.doDestroy();return}})}start(){if(this.owner&&!this.context.connection.userIsInRoom(this.owner)){this.doDestroy();return}}doDestroy(){O_&&console.log("PlayerSync.doDestroy \u2192 syncDestroy",this),q0(this.gameObject,this.context.connection)}onDestroy(){if(Ks.all.splice(Ks.all.indexOf(this),1),this.isLocalPlayer){const i=Ks._local.indexOf(this);i>=0&&Ks._local.splice(i,1)}}},h(fv,"_all",[]),h(fv,"_local",[]),h(fv,"_callbacks",{}),fv);let qp=Ks;bU([VM("onOwnerChange")],qp.prototype,"owner",2);class Dne extends Ee{constructor(){super(...arguments),h(this,"toggleKey","KeyP")}update(){this.context.input.isKeyDown(this.toggleKey)&&this.context.domElement.classList.toggle("presentation-mode")}}Q.add("__Ignore",dI),Q.add("ActionBuilder",ni),Q.add("ActionCollection",kS),Q.add("ActionModel",xo),Q.add("AlignmentConstraint",Hg),Q.add("Animation",yo),Q.add("AnimationCurve",Jh),Q.add("AnimationExtension",Hy),Q.add("AnimationTrackHandler",Mb),Q.add("Animator",jr),Q.add("AnimatorController",Ru),Q.add("Antialiasing",wm),Q.add("AttachedObject",ra),Q.add("AudioExtension",Tb),Q.add("AudioListener",gp),Q.add("AudioSource",os),Q.add("AudioTrackHandler",bm),Q.add("Avatar_Brain_LookAt",Yg),Q.add("Avatar_MouthShapes",Cm),Q.add("Avatar_MustacheShake",NE),Q.add("Avatar_POI",Rr),Q.add("AvatarBlink_Simple",ru),Q.add("AvatarEyeLook_Rotation",Ap),Q.add("AvatarLoader",Yy),Q.add("AvatarMarker",hr),Q.add("AvatarModel",Xy),Q.add("AxesHelper",yp),Q.add("BaseUIComponent",Ro),Q.add("BasicIKConstraint",QE),Q.add("BehaviorExtension",Pb),Q.add("BehaviorModel",Ir),Q.add("Behaviour",Ee),Q.add("Bloom",nu),Q.add("BoxCollider",Em),Q.add("BoxGizmo",eu),Q.add("BoxHelperComponent",Jo),Q.add("Button",xl),Q.add("CallInfo",qh),Q.add("Camera",Ei),Q.add("Canvas",dr),Q.add("CanvasGroup",Cp),Q.add("CapsuleCollider",zc),Q.add("ChangeMaterialOnClick",Rm),Q.add("ChangeTransformOnClick",cu),Q.add("CharacterController",hu),Q.add("CharacterControllerInput",Cl),Q.add("ChromaticAberration",km),Q.add("Collider",oa),Q.add("ColorAdjustments",Hc),Q.add("ColorBySpeedModule",uu),Q.add("ColorOverLifetimeModule",Om),Q.add("Component",fc),Q.add("ControlTrackHandler",Ib),Q.add("CustomBranding",Yc),Q.add("Deletable",lM),Q.add("DeleteBox",Xb),Q.add("DepthOfField",Io),Q.add("DeviceFlag",Yb),Q.add("DocumentExtension",cM),Q.add("DragControls",Pp),Q.add("DropListener",Fm),Q.add("Duplicatable",fu),Q.add("EmissionModule",ha),Q.add("EmphasizeOnClick",Mp),Q.add("EventList",Gr),Q.add("EventListEvent",Dy),Q.add("EventSystem",Hn),Q.add("EventTrigger",Zb),Q.add("FieldWithDefault",CS),Q.add("FixedJoint",yM),Q.add("FlyControls",bM),Q.add("Fog",kp),Q.add("GltfExport",Ol),Q.add("GltfExportBox",MM),Q.add("Gradient",Vc),Q.add("Graphic",au),Q.add("GraphicRaycaster",PE),Q.add("GridHelper",Op),Q.add("GridLayoutGroup",$E),Q.add("GroundProjectedEnv",gu),Q.add("GroupActionModel",Mc),Q.add("HideOnStart",sM),Q.add("HingeJoint",Nm),Q.add("HorizontalLayoutGroup",ZE),Q.add("Image",xp),Q.add("InheritVelocityModule",qc),Q.add("InputField",vu),Q.add("Interactable",tp),Q.add("Light",Yr),Q.add("LimitVelocityOverLifetimeModule",us),Q.add("LODGroup",Qm),Q.add("LODModel",Au),Q.add("LogStats",RM),Q.add("LookAt",yu),Q.add("LookAtConstraint",Wg),Q.add("MainModule",Ws),Q.add("MaskableGraphic",Tm),Q.add("MeshCollider",Mm),Q.add("MeshRenderer",Fy),Q.add("MinMaxCurve",tt),Q.add("MinMaxGradient",Xr),Q.add("NestedGltf",s_),Q.add("Networking",pu),Q.add("NoiseModule",hi),Q.add("ObjectRaycaster",iu),Q.add("OffsetConstraint",bu),Q.add("OpenURL",Np),Q.add("OrbitControls",Nc),Q.add("Outline",_p),Q.add("Padding",jc),Q.add("ParticleBurst",Dm),Q.add("ParticleSubEmitter",d_),Q.add("ParticleSystem",$i),Q.add("ParticleSystemRenderer",El),Q.add("PixelationEffect",Ym),Q.add("PlayableDirector",vm),Q.add("PlayAnimationOnClick",Gc),Q.add("PlayAudioOnClick",Ip),Q.add("PlayerColor",Pu),Q.add("PlayerState",qp),Q.add("PlayerSync",pI),Q.add("PointerEventData",tu),Q.add("PostProcessingHandler",f_),Q.add("PreliminaryAction",Rp),Q.add("PreliminaryTrigger",Pm),Q.add("PresentationMode",Dne),Q.add("RawImage",Fb),Q.add("Raycaster",fp),Q.add("Rect",XE),Q.add("RectTransform",ur),Q.add("ReflectionProbe",Xd),Q.add("RegisteredAnimationInfo",Qy),Q.add("RemoteSkybox",_u),Q.add("Renderer",Ui),Q.add("RendererLightmap",Qg),Q.add("RGBAColor",vi),Q.add("Rigidbody",Di),Q.add("RotationBySpeedModule",fn),Q.add("RotationOverLifetimeModule",Wn),Q.add("SceneSwitcher",mn),Q.add("ScreenCapture",$m),Q.add("ScreenSpaceAmbientOcclusion",Il),Q.add("SetActiveOnClick",Ep),Q.add("ShadowCatcher",iv),Q.add("ShapeModule",Ki),Q.add("SignalAsset",gm),Q.add("SignalReceiver",vp),Q.add("SignalReceiverEvent",mp),Q.add("SignalTrackHandler",_m),Q.add("Size",qE),Q.add("SizeBySpeedModule",kr),Q.add("SizeOverLifetimeModule",Wc),Q.add("SkinnedMeshRenderer",SS),Q.add("SmoothFollow",Zc),Q.add("SpatialHtml",XM),Q.add("SpatialTrigger",nv),Q.add("SpatialTriggerReceiver",ma),Q.add("SpectatorCamera",b_),Q.add("SphereCollider",Sm),Q.add("Sprite",Tl),Q.add("SpriteData",Hp),Q.add("SpriteRenderer",xu),Q.add("SpriteSheet",ov),Q.add("SubEmitterSystem",Xm),Q.add("SyncedCamera",x_),Q.add("SyncedRoom",$c),Q.add("SyncedTransform",Oc),Q.add("TapGestureTrigger",nM),Q.add("TeleportTarget",vb),Q.add("TestRunner",rI),Q.add("TestSimulateUserData",nI),Q.add("Text",Dr),Q.add("TextBuilder",Wb),Q.add("TextExtension",qb),Q.add("TextureSheetAnimationModule",qs),Q.add("TiltShiftEffect",va),Q.add("ToneMapping",lv),Q.add("TrailModule",Ii),Q.add("TransformData",Gy),Q.add("TransformGizmo",Su),Q.add("TriggerBuilder",Hr),Q.add("TriggerModel",Yh),Q.add("UIRaycastUtils",cp),Q.add("UIRootComponent",om),Q.add("UsageMarker",ip),Q.add("USDZExporter",Xn),Q.add("USDZText",Xc),Q.add("VariantAction",BS),Q.add("VelocityOverLifetimeModule",Oi),Q.add("VerticalLayoutGroup",KE),Q.add("VideoPlayer",Js),Q.add("Vignette",Eu),Q.add("VisibilityAction",Bm),Q.add("Voip",kl),Q.add("Volume",I_),Q.add("VolumeParameter",Dt),Q.add("VolumeProfile",xm),Q.add("VRUserState",Al),Q.add("WebAR",um),Q.add("WebARCameraBackground",R_),Q.add("WebARSessionRoot",Pc),Q.add("WebXR",wt),Q.add("WebXRAvatar",kc),Q.add("WebXRController",cs),Q.add("WebXRImageTracking",B_),Q.add("WebXRImageTrackingModel",Rl),Q.add("WebXRPlaneTracking",k_),Q.add("WebXRSync",cm),Q.add("WebXRTrackedImage",Mu),Q.add("XRFlag",Tr),Q.add("XRGrabModel",D_),Q.add("XRGrabRendering",uI),Q.add("XRRig",yb),Q.add("XRState",Zo);const xU=rr,One=oe("debugtypestore");One&&console.log(Q);function Lne(i,e){const t=fB(i,e);return t!==void 0?t:null}const Fne=new m6,fI=Symbol("deserialize-queue");async function Nne(i,e,t,s=null,r){if(!t)return;let n=s;typeof n=="number"&&(n=new Lr(s));const o=e.indexOf("?");e=o===-1?e:e.substring(0,o);const a=new pB(t.scene);a.gltfId=e,a.context=i,a.gltf=t,a.nodeToObject=r?.nodeToObjectMap,a.implementationInformation=Fne;let l=i[fI];if(l||(l=i[fI]=[]),t.scenes)for(const c of t.scenes)await mI(a,c,l);if(t.children)for(const c of t.children)await mI(a,c,l);i.new_scripts_pre_setup_callbacks.push(()=>{const c=i[fI];if(c){for(const u of c)Une(u,a);c.length=0}if(n){const u={};gI(t,n,u);for(const d of t.scenes)gI(d,n,u)}})}function gI(i,e,t){if(e===null||!i)return;const s=i.guid;if(i.guid=e.generateUUID(),s&&s!=="invalid"&&(t[s]=i.guid),i&&i.userData&&i.userData.components)for(const r of i.userData.components){if(r===null)continue;const n=r.guid;r.guid=e.generateUUID(),n&&n!=="invalid"&&(t[n]=r.guid),r.resolveGuids&&r.resolveGuids(t)}if(i.children)for(const r of i.children)gI(r,e,t)}const gv=[];async function mI(i,e,t,s){if(!e)return;const r=e.userData;if(r){const n=r.builtin_components;if(n&&n.length>0)for(const o of n)try{if(o===null)continue;const a=Q.get(o.name);if(a!=null){const l=new a;l.sourceId=i.gltfId,Lh(l,o,i.implementationInformation),"guid"in o&&(l[pf]=o.guid),lc(e,l,!1),t.push({instance:l,compData:o,obj:e})}else xU&&console.debug("unknown component: "+o.name),gv.includes(o.name)||gv.push(o.name)}catch(a){console.error(o.name+" - "+a.message,a)}if(gv.length>0){const o=gv.join(", ");console.warn("unknown components: "+o),gv.length=0,gr()&&Ns(`<strong>Unknown components in scene</strong>:
5052
+ `;function wne(i){const e="vec4("+i.r.toFixed(3)+","+i.g.toFixed(3)+","+i.b.toFixed(3)+","+i.a.toFixed(3)+")";console.log(e);const t=new ye(new Os(2,2),new Vt({name:"BackgroundMaterial",uniforms:pw.clone(rn.background.uniforms),vertexShader:rn.background.vertexShader,fragmentShader:xne.replace("<backgroundTint>",e),side:bi,depthTest:!1,depthWrite:!1,fog:!1}));return t.geometry.deleteAttribute("normal"),Object.defineProperty(t.material,"map",{get:function(){return this.threeTexture}}),t.renderOrder=-1e4,t.layers.disableAll(),t.layers.enable(2),t.frustumCulled=!1,t.setTexture=function(s){t.material.uniforms.t2D.value=s},t}var Cne=Object.defineProperty,Sne=Object.getOwnPropertyDescriptor,Wp=(i,e,t,s)=>{for(var r=s>1?void 0:s?Sne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Cne(e,t,r),r};const Ene=oe("debugimagetracking"),P_=class{constructor(i,e,t,s,r,n){h(this,"measuredSize"),h(this,"state"),h(this,"_position"),h(this,"_rotation"),h(this,"_trackingComponent"),h(this,"_trackedImage"),h(this,"_bitmap"),h(this,"_pose"),this._trackingComponent=i,this._trackedImage=e,this._bitmap=t,this.measuredSize=s,this.state=r,this._pose=n}get url(){return this._trackedImage.image??""}get widthInMeters(){return this._trackedImage.widthInMeters??void 0}get bitmap(){return this._bitmap}get model(){return this._trackedImage}getPosition(i){return this.ensureTransformData(),i.copy(this._position),i}getQuaternion(i){return this.ensureTransformData(),i.copy(this._rotation),i}applyToObject(i,e=void 0){this.ensureTransformData();const t=i.position.distanceToSquared(this._position)>.05||i.quaternion.angleTo(this._rotation)>.05;e===void 0||e>=1||t?(i.position.copy(this._position),i.quaternion.copy(this._rotation)):(e=Math.max(0,Math.min(1,e)),i.position.lerp(this._position,e),i.quaternion.slerp(this._rotation,e)),i.quaternion.multiply(P_.y180)}ensureTransformData(){if(!this._position){this._position=P_._positionBuffer.get(),this._rotation=P_._rotationBuffer.get();const i=this._pose.transform;this._position.set(i.position.x,i.position.y,i.position.z),this._rotation.set(i.orientation.x,i.orientation.y,i.orientation.z,i.orientation.w)}}};let Mu=P_;h(Mu,"y180",new we().setFromAxisAngle(new S(0,1,0),Math.PI)),h(Mu,"_positionBuffer",new Bo(()=>new S,20)),h(Mu,"_rotationBuffer",new Bo(()=>new we,20));class Rl{constructor(){h(this,"image"),h(this,"widthInMeters"),h(this,"object"),h(this,"createObjectInstance",!1),h(this,"imageDoesNotMove",!1)}}Wp([x(URL)],Rl.prototype,"image",2),Wp([x()],Rl.prototype,"widthInMeters",2),Wp([x(lr)],Rl.prototype,"object",2),Wp([x()],Rl.prototype,"createObjectInstance",2),Wp([x()],Rl.prototype,"imageDoesNotMove",2);class Mne{constructor(e,t,s){h(this,"filename"),h(this,"widthInMeters"),h(this,"imageData"),this.filename=e,this.imageData=t,this.widthInMeters=s}get extensionName(){return"image-tracking"}onAfterHierarchy(e,t){t.beginBlock('def Preliminary_ReferenceImage "AnchoringReferenceImage"'),t.appendLine("uniform asset image = @tracker/"+this.filename+"@"),t.appendLine("uniform double physicalWidth = "+(this.widthInMeters*100).toFixed(8)),t.closeBlock()}onAfterSerialize(e){e.files["tracker/"+this.filename]=this.imageData}}var hI;const pv=(hI=class extends Ee{constructor(){super(...arguments),h(this,"trackedImages"),h(this,"trackedImageIndexMap",new Map),h(this,"xr",null),h(this,"onModifyAROptions",i=>{var e;const t=i.detail,s=t.optionalFeatures||[];s.includes("image-tracking")||s.push("image-tracking"),t.optionalFeatures=s,t.trackedImages=[];for(const r of this.trackedImages)if((e=r.image)!=null&&e.length&&r.widthInMeters>0){const n=pv._imageElements.get(r.image);n&&(this.trackedImageIndexMap.set(t.trackedImages.length,r),t.trackedImages.push({image:n,widthInMeters:r.widthInMeters}))}}),h(this,"imageToObjectMap",new Map),h(this,"onImageTrackingUpdate",i=>{const e=i.detail;for(const[t,s]of this.imageToObjectMap){if(!s.object||!t)continue;let r=!1;for(const n of e)if(n.model===t){r=!0;break}r||$.setActive(s.object,!1)}for(const t of e){const s=t.model;if(!s.object)continue;let r=this.imageToObjectMap.get(s);if(r===void 0)r={object:null,frames:0},this.imageToObjectMap.set(s,r),s.object.loadAssetAsync().then(n=>{s.createObjectInstance&&(n=$.instantiate(n)),n&&(r.object=n,this.xr&&this.xr.Rig.add(n),t.applyToObject(n),n.activeSelf||$.setActive(n,!0))});else{if(r.frames++,s.imageDoesNotMove&&r.frames>10||!r.object)continue;this.xr&&this.xr.Rig.add(r.object),t.applyToObject(r.object),r.object.activeSelf||$.setActive(r.object,!0)}}}),h(this,"onXRStarted",i=>{for(const e of this.imageToObjectMap.values())e.frames=0}),h(this,"onXRUpdate",i=>{const e=i.frame;if(e){if(e.session&&!("getImageTrackingResults"in e)){ho('Image tracking is currently not supported on this device. On Chrome for Android, you can enable the <a href="chrome://flags/#webxr-incubations">chrome://flags/#webxr-incubations</a> flag.');return}if(e.session&&typeof e.getImageTrackingResults=="function"){const t=e.getImageTrackingResults();if(t.length){const s=this.context.renderer.xr.getReferenceSpace();if(s){const r=[];for(const n of t){const o=n.index,a=this.trackedImageIndexMap.get(o);if(a){const l=e.getPose(n.imageSpace,s),c=n.trackingState,u=new Mu(this,a,n.image,n.measuredSize,c,l);r.push(u)}else Ene&&console.warn("No tracked image for index",o)}if(r.length>0)try{this.dispatchEvent(new CustomEvent("image-tracking",{detail:r}))}catch(n){console.error(n)}}}}}})}awake(){for(const i of this.trackedImages)if(i.image&&!pv._imageElements.has(i.image)){const e=i.image;pv._imageElements.set(e,null);const t=document.createElement("img");t.src=e,t.addEventListener("load",async()=>{const s=await createImageBitmap(t);pv._imageElements.set(e,s);const r=await RL(s);if(r){const n=await(await new Promise(a=>r.toBlob(a,"image/png",1))).arrayBuffer(),o=$.findObjectOfType(Xn);o&&(o.extensions.push(new Mne("marker.png",new Uint8Array(n),this.trackedImages[0].widthInMeters)),o.anchoringType="image")}})}}onEnable(){this.xr=$.findObjectOfType(wt),wt.addEventListener(_i.ModifyAROptions,this.onModifyAROptions),wt.addEventListener(_i.XRStarted,this.onXRStarted),wt.addEventListener(_i.XRUpdate,this.onXRUpdate),this.addEventListener("image-tracking",this.onImageTrackingUpdate)}onDisable(){wt.removeEventListener(_i.ModifyAROptions,this.onModifyAROptions),wt.removeEventListener(_i.XRStarted,this.onXRStarted),wt.removeEventListener(_i.XRUpdate,this.onXRUpdate),this.removeEventListener("image-tracking",this.onImageTrackingUpdate)}},h(hI,"_imageElements",new Map),hI);let B_=pv;Wp([x(Rl)],B_.prototype,"trackedImages",2);var Ine=Object.defineProperty,Tne=Object.getOwnPropertyDescriptor,Rne=(i,e,t,s)=>{for(var r=s>1?void 0:s?Tne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Ine(e,t,r),r};const yU=oe("debugplanetracking");class k_ extends Ee{constructor(){super(...arguments),h(this,"planeTemplate"),h(this,"onModifyAROptions",e=>{const t=e.detail,s=t.optionalFeatures||[];s.includes("plane-detection")||s.push("plane-detection"),t.optionalFeatures=s}),h(this,"onXRUpdate",e=>{this.processPlanes(e.rig,e.frame)}),h(this,"_planeId",1),h(this,"_allPlanes",new Map)}get trackedPlanes(){return this._allPlanes.values()}onEnable(){wt.addEventListener(_i.XRUpdate,this.onXRUpdate),wt.addEventListener("modify-ar-options",this.onModifyAROptions)}onDisable(){wt.removeEventListener(_i.XRUpdate,this.onXRUpdate),wt.removeEventListener("modify-ar-options",this.onModifyAROptions)}processPlanes(e,t){const s=this.context.renderer;if(!e||t.detectedPlanes===void 0)return;const r=s.xr.getReferenceSpace();if(r){for(const n of this._allPlanes.keys())if(!t.detectedPlanes.has(n)){const o=this._allPlanes.get(n);this._allPlanes.delete(n),yU&&console.log("Plane no longer tracked, id="+o.id),o.mesh&&e?.remove(o.mesh);const a=new CustomEvent("plane-tracking",{detail:{type:"plane-removed",context:o}});this.dispatchEvent(a)}for(const n of t.detectedPlanes){const o=t.getPose(n.planeSpace,r);let a;if(this._allPlanes.has(n)){const l=this._allPlanes.get(n);if(a=l.mesh,l.timestamp<n.lastChangedTime){if(l.timestamp=n.lastChangedTime,l.mesh){const u=this.createGeometry(n.polygon);if(l.mesh instanceof ye)l.mesh.geometry.dispose(),l.mesh.geometry=u;else if(l.mesh instanceof En)for(const d of l.mesh.children)d instanceof ye&&(d.geometry.dispose(),d.geometry=u);l.collider&&(l.collider.sharedMesh=l.mesh,l.collider.convex=!0,l.collider.onDisable(),l.collider.onEnable())}const c=new CustomEvent("plane-tracking",{detail:{type:"plane-updated",context:l}});this.dispatchEvent(c)}}else if(this.planeTemplate||(this.planeTemplate=new ye),this.planeTemplate){const l=$.instantiate(this.planeTemplate);a=l,l instanceof ye&&(go(l.geometry),l.geometry=this.createGeometry(n.polygon));const c=l.getComponent(Mm);c&&(c.sharedMesh=l,c.convex=!0,c.onDisable(),c.onEnable()),l.matrixAutoUpdate=!1,l.matrixWorldNeedsUpdate=!0,e.add(l);const u={id:this._planeId++,xrPlane:n,timestamp:n.lastChangedTime,mesh:l,collider:c};this._allPlanes.set(n,u),yU&&console.log("New plane detected, id="+u.id);try{const d=new CustomEvent("plane-tracking",{detail:{type:"plane-added",context:u}});this.dispatchEvent(d)}catch(d){console.error(d)}}a&&(o?(a.visible=!0,a.matrix.fromArray(o.transform.matrix)):a.visible=!1)}}}createGeometry(e){const t=new At,s=[],r=[];e.forEach(p=>{s.push(p.x,p.y,p.z),r.push(p.x,p.z)});const n=new S(s[0],s[1],s[2]),o=new S(s[3],s[4],s[5]),a=new S(s[6],s[7],s[8]),l=new S,c=new S;l.subVectors(o,n),c.subVectors(a,n),l.cross(c),l.normalize();const u=[];for(let p=0;p<s.length/3;p++)u.push(l.x,l.y,l.z);const d=[];for(let p=2;p<e.length;++p)d.push(0,p-1,p);return t.setAttribute("position",new rt(new Float32Array(s),3)),t.setAttribute("uv",new rt(new Float32Array(r),2)),t.setAttribute("normal",new rt(new Float32Array(u),3)),t.setIndex(d),t}}Rne([x(Me)],k_.prototype,"planeTemplate",2);class D_{constructor(){h(this,"guid"),h(this,"dontSave",!0),h(this,"userId"),h(this,"point",{x:0,y:0,z:0}),h(this,"source",{x:0,y:0,z:0}),h(this,"target")}update(e,t,s,r=void 0){this.userId=e.connection.connectionId,this.point.x=t.x,this.point.y=t.y,this.point.z=t.z,this.source.x=s.x,this.source.y=s.y,this.source.z=s.z,this.target=r}}class uI extends Ee{constructor(){super(...arguments),h(this,"prefab",null),h(this,"_grabModels",[]),h(this,"_grabModelsUpdateTime",[]),h(this,"_addOrUpdateSub",null),h(this,"_endSub",null),h(this,"_freeSub",null),h(this,"_instances",{}),h(this,"temp",new S)}awake(){this.prefab&&(this.prefab.visible=!1)}onEnable(){this._addOrUpdateSub=this.context.connection.beginListen("xr-grab-visual-start-or-update",this.onRemoteGrabStartOrUpdate.bind(this)),this._endSub=this.context.connection.beginListen("xr-grab-visual-end",this.onRemoteGrabEnd.bind(this)),this._freeSub=ra.AddEventListener(Ab.WillFree,this.onAttachedObjectFree.bind(this))}onDisable(){this.context.connection.stopListen("xr-grab-visual-start-or-update",this._addOrUpdateSub),this.context.connection.stopListen("xr-grab-visual-end",this._endSub),ra.RemoveEventListener(Ab.WillFree,this._freeSub)}addOrUpdateGrab(e){this.context.connection.send("xr-grab-visual-start-or-update",e,Ur.Queued)}endGrab(e){this.context.connection.send("xr-grab-visual-end",e,Ur.Queued)}onRemoteGrabStartOrUpdate(e){if(!this.prefab)return;const t=this._instances[e.guid];if(!t){const s=$.instantiate(this.prefab);if(s.visible=!0,this._instances[e.guid]={instance:s,model:e},e.userId){const r=$.getComponentsInChildren(s,Pu);if(r?.length>0)for(const n of r)n.assignUserColor(e.userId)}return}t.model=e}onRemoteGrabEnd(e){if(!e)return;const t=e.guid;this._instances[t]&&($.destroy(this._instances[t].instance),delete this._instances[t])}onAttachedObjectFree(e){if(this._grabModels.length<=0)return;const t=this._grabModels[0];this.updateModel(t,e),this.endGrab(t)}onBeforeRender(){if(this.updateRendering(),!!this.prefab&&(this.prefab.visible=!1,this.context.time.frameCount%10===0))for(let e=0;e<ra.Current.length;e++){const t=ra.Current[e];if(!t.controller||!t.selected)continue;this._grabModels.length<=e&&(this._grabModels.push(new D_),this._grabModelsUpdateTime.push(0)),this._grabModelsUpdateTime[e]=this.context.time.time;const s=this._grabModels[e];this.updateModel(s,t),this.addOrUpdateGrab(s)}}updateModel(e,t){if(!t.controller||!t.selected)return;e.guid=t.grabUUID;const s=t.selected.guid;e.update(this.context,t.grabPoint,t.controller.worldPosition,s)}updateRendering(){const e=this.context.time.deltaTime/.5;for(const t in this._instances){const{instance:s,model:r}=this._instances[t];if(!s||!r)continue;const{point:n}=r,o=xt(s);this.temp.set(n.x,n.y,n.z),o.lerp(this.temp,e),rs(s,o)}}}class dI{}const Pne=Object.freeze(Object.defineProperty({__proto__:null,ActionBuilder:ni,ActionCollection:kS,ActionModel:xo,AlignmentConstraint:Hg,Animation:yo,AnimationCurve:Jh,AnimationExtension:Hy,AnimationTrackHandler:Mb,Animator:jr,AnimatorController:Ru,Antialiasing:wm,AttachedObject:ra,AudioExtension:Tb,AudioListener:gp,AudioSource:os,AudioTrackHandler:bm,AvatarBlink_Simple:ru,AvatarEyeLook_Rotation:Ap,AvatarLoader:Yy,AvatarMarker:hr,AvatarModel:Xy,Avatar_Brain_LookAt:Yg,Avatar_MouthShapes:Cm,Avatar_MustacheShake:NE,Avatar_POI:Rr,AxesHelper:yp,BaseUIComponent:Ro,BasicIKConstraint:QE,BehaviorExtension:Pb,BehaviorModel:Ir,Behaviour:Ee,Bloom:nu,BoxCollider:Em,BoxGizmo:eu,BoxHelperComponent:Jo,Button:xl,CallInfo:qh,Camera:Ei,Canvas:dr,CanvasGroup:Cp,CapsuleCollider:zc,ChangeMaterialOnClick:Rm,ChangeTransformOnClick:cu,CharacterController:hu,CharacterControllerInput:Cl,ChromaticAberration:km,Collider:oa,ColorAdjustments:Hc,ColorBySpeedModule:uu,ColorOverLifetimeModule:Om,Component:fc,ControlTrackHandler:Ib,CustomBranding:Yc,Deletable:lM,DeleteBox:Xb,DepthOfField:Io,DeviceFlag:Yb,DocumentExtension:cM,DragControls:Pp,DropListener:Fm,Duplicatable:fu,EmissionModule:ha,EmphasizeOnClick:Mp,EventList:Gr,EventListEvent:Dy,EventSystem:Hn,EventTrigger:Zb,FieldWithDefault:CS,FixedJoint:yM,FlyControls:bM,Fog:kp,GltfExport:Ol,GltfExportBox:MM,Gradient:Vc,Graphic:au,GraphicRaycaster:PE,GridHelper:Op,GridLayoutGroup:$E,GroundProjectedEnv:gu,GroupActionModel:Mc,HideOnStart:sM,HingeJoint:Nm,HorizontalLayoutGroup:ZE,Image:xp,InheritVelocityModule:qc,InputField:vu,Interactable:tp,LODGroup:Qm,LODModel:Au,Light:Yr,LimitVelocityOverLifetimeModule:us,LogStats:RM,LookAt:yu,LookAtConstraint:Wg,MainModule:Ws,MaskableGraphic:Tm,MeshCollider:Mm,MeshRenderer:Fy,MinMaxCurve:tt,MinMaxGradient:Xr,NestedGltf:s_,Networking:pu,NoiseModule:hi,ObjectRaycaster:iu,OffsetConstraint:bu,OpenURL:Np,OrbitControls:Nc,Outline:_p,Padding:jc,ParticleBurst:Dm,ParticleSubEmitter:d_,ParticleSystem:$i,ParticleSystemRenderer:El,PixelationEffect:Ym,PlayAnimationOnClick:Gc,PlayAudioOnClick:Ip,PlayableDirector:vm,PlayerColor:Pu,PointerEventData:tu,PostProcessingHandler:f_,PreliminaryAction:Rp,PreliminaryTrigger:Pm,RGBAColor:vi,RawImage:Fb,Raycaster:fp,Rect:XE,RectTransform:ur,ReflectionProbe:Xd,RegisteredAnimationInfo:Qy,RemoteSkybox:_u,Renderer:Ui,RendererLightmap:Qg,Rigidbody:Di,RotationBySpeedModule:fn,RotationOverLifetimeModule:Wn,SceneSwitcher:mn,ScreenCapture:$m,ScreenSpaceAmbientOcclusion:Il,SetActiveOnClick:Ep,ShadowCatcher:iv,ShapeModule:Ki,SignalAsset:gm,SignalReceiver:vp,SignalReceiverEvent:mp,SignalTrackHandler:_m,Size:qE,SizeBySpeedModule:kr,SizeOverLifetimeModule:Wc,SkinnedMeshRenderer:SS,SmoothFollow:Zc,SpatialHtml:XM,SpatialTrigger:nv,SpatialTriggerReceiver:ma,SpectatorCamera:b_,SphereCollider:Sm,Sprite:Tl,SpriteData:Hp,SpriteRenderer:xu,SpriteSheet:ov,SubEmitterSystem:Xm,SyncedCamera:x_,SyncedRoom:$c,SyncedTransform:Oc,TapGestureTrigger:nM,TeleportTarget:vb,TestRunner:rI,TestSimulateUserData:nI,Text:Dr,TextBuilder:Wb,TextExtension:qb,TextureSheetAnimationModule:qs,TiltShiftEffect:va,ToneMapping:lv,TrailModule:Ii,TransformData:Gy,TransformGizmo:Su,TriggerBuilder:Hr,TriggerModel:Yh,UIRaycastUtils:cp,UIRootComponent:om,USDZExporter:Xn,USDZText:Xc,UsageMarker:ip,VRUserState:Al,VariantAction:BS,VelocityOverLifetimeModule:Oi,VerticalLayoutGroup:KE,VideoPlayer:Js,Vignette:Eu,VisibilityAction:Bm,Voip:kl,Volume:I_,VolumeParameter:Dt,VolumeProfile:xm,WebAR:um,WebARCameraBackground:R_,WebARSessionRoot:Pc,WebXR:wt,WebXRAvatar:kc,WebXRController:cs,WebXRImageTracking:B_,WebXRImageTrackingModel:Rl,WebXRPlaneTracking:k_,WebXRSync:cm,WebXRTrackedImage:Mu,XRFlag:Tr,XRGrabModel:D_,XRGrabRendering:uI,XRRig:yb,XRState:Zo,__Ignore:dI},Symbol.toStringTag,{value:"Module"}));var Bne=Object.defineProperty,kne=Object.getOwnPropertyDescriptor,bU=(i,e,t,s)=>{for(var r=s>1?void 0:s?kne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Bne(e,t,r),r};const O_=oe("debugplayersync");class pI extends Ee{constructor(){super(...arguments),h(this,"asset"),h(this,"joinedRoomFunction")}awake(){this.watchTabVisible(),this.joinedRoomFunction=this.onUserJoined.bind(this)}onEnable(){this.context.connection.beginListen(Fi.JoinedRoom,this.joinedRoomFunction)}onDisable(){this.context.connection.stopListen(Fi.JoinedRoom,this.joinedRoomFunction)}async onUserJoined(e){var t,s;O_&&console.log("PlayerSync.onUserJoined",e);const r=await((t=this.asset)==null?void 0:t.instantiateSynced({parent:this.gameObject},!0));if(r){let n=$.getComponent(r,qp);n?n.owner=this.context.connection.connectionId:(console.error("<strong>Failed finding PlayerState on "+((s=this.asset)==null?void 0:s.uri)+"</strong>: please make sure the asset has a PlayerState component!"),$.destroySynced(r))}else console.warn("PlayerSync: failed instantiating asset!")}watchTabVisible(){window.addEventListener("visibilitychange",e=>{if(document.visibilityState==="visible")for(let t=qp.all.length-1;t>=0;t--){const s=qp.all[t];(!s.owner||!this.context.connection.userIsInRoom(s.owner))&&s.doDestroy()}})}}bU([x(lr)],pI.prototype,"asset",2);var _U=(i=>(i.OwnerChanged="ownerChanged",i))(_U||{}),fv;const Ks=(fv=class extends Ee{constructor(){super(...arguments),h(this,"owner")}static get all(){return Ks._all}static get local(){return Ks._local}static isLocalPlayer(i){if(i instanceof Me){const e=$.getComponentInParent(i,Ks);return e?.isLocalPlayer??!1}else if(i instanceof fc){const e=$.getComponentInParent(i.gameObject,Ks);return e?.isLocalPlayer??!1}return!1}static addEventListener(i,e){return this._callbacks[i]||(this._callbacks[i]=[]),this._callbacks[i].push(e),e}static removeEventListener(i,e){if(!this._callbacks[i])return;const t=this._callbacks[i].indexOf(e);t>=0&&this._callbacks[i].splice(t,1)}static dispatchEvent(i,e){if(this._callbacks[i])for(const t of this._callbacks[i])t(e)}get isLocalPlayer(){return this.owner===this.context.connection.connectionId}onOwnerChange(i,e){O_&&console.log("PlayerSync.onOwnerChange",this,"newOwner",i,"oldOwner",e);const t=Ks._local.indexOf(this);t>=0&&Ks._local.splice(t,1);const s={playerState:this,oldValue:e,newValue:i};if(this.owner===this.context.connection.connectionId){Ks._local.push(this);const n=new CustomEvent("local-owner-changed",{detail:s});this.dispatchEvent(n),Ks.dispatchEvent("ownerChanged",n)}const r=new CustomEvent("owner-changed",{detail:s});this.dispatchEvent(r),Ks.dispatchEvent("ownerChanged",r)}awake(){Ks.all.push(this),O_&&console.log("Registered new PlayerState",this,Ks.all.length-1,Ks.all),this.context.connection.beginListen(Fi.UserLeftRoom,i=>{if(i.userId===this.owner){this.doDestroy();return}})}start(){if(this.owner&&!this.context.connection.userIsInRoom(this.owner)){this.doDestroy();return}}doDestroy(){O_&&console.log("PlayerSync.doDestroy \u2192 syncDestroy",this),q0(this.gameObject,this.context.connection)}onDestroy(){if(Ks.all.splice(Ks.all.indexOf(this),1),this.isLocalPlayer){const i=Ks._local.indexOf(this);i>=0&&Ks._local.splice(i,1)}}},h(fv,"_all",[]),h(fv,"_local",[]),h(fv,"_callbacks",{}),fv);let qp=Ks;bU([VM("onOwnerChange")],qp.prototype,"owner",2);class Dne extends Ee{constructor(){super(...arguments),h(this,"toggleKey","KeyP")}update(){this.context.input.isKeyDown(this.toggleKey)&&this.context.domElement.classList.toggle("presentation-mode")}}Q.add("__Ignore",dI),Q.add("ActionBuilder",ni),Q.add("ActionCollection",kS),Q.add("ActionModel",xo),Q.add("AlignmentConstraint",Hg),Q.add("Animation",yo),Q.add("AnimationCurve",Jh),Q.add("AnimationExtension",Hy),Q.add("AnimationTrackHandler",Mb),Q.add("Animator",jr),Q.add("AnimatorController",Ru),Q.add("Antialiasing",wm),Q.add("AttachedObject",ra),Q.add("AudioExtension",Tb),Q.add("AudioListener",gp),Q.add("AudioSource",os),Q.add("AudioTrackHandler",bm),Q.add("Avatar_Brain_LookAt",Yg),Q.add("Avatar_MouthShapes",Cm),Q.add("Avatar_MustacheShake",NE),Q.add("Avatar_POI",Rr),Q.add("AvatarBlink_Simple",ru),Q.add("AvatarEyeLook_Rotation",Ap),Q.add("AvatarLoader",Yy),Q.add("AvatarMarker",hr),Q.add("AvatarModel",Xy),Q.add("AxesHelper",yp),Q.add("BaseUIComponent",Ro),Q.add("BasicIKConstraint",QE),Q.add("BehaviorExtension",Pb),Q.add("BehaviorModel",Ir),Q.add("Behaviour",Ee),Q.add("Bloom",nu),Q.add("BoxCollider",Em),Q.add("BoxGizmo",eu),Q.add("BoxHelperComponent",Jo),Q.add("Button",xl),Q.add("CallInfo",qh),Q.add("Camera",Ei),Q.add("Canvas",dr),Q.add("CanvasGroup",Cp),Q.add("CapsuleCollider",zc),Q.add("ChangeMaterialOnClick",Rm),Q.add("ChangeTransformOnClick",cu),Q.add("CharacterController",hu),Q.add("CharacterControllerInput",Cl),Q.add("ChromaticAberration",km),Q.add("Collider",oa),Q.add("ColorAdjustments",Hc),Q.add("ColorBySpeedModule",uu),Q.add("ColorOverLifetimeModule",Om),Q.add("Component",fc),Q.add("ControlTrackHandler",Ib),Q.add("CustomBranding",Yc),Q.add("Deletable",lM),Q.add("DeleteBox",Xb),Q.add("DepthOfField",Io),Q.add("DeviceFlag",Yb),Q.add("DocumentExtension",cM),Q.add("DragControls",Pp),Q.add("DropListener",Fm),Q.add("Duplicatable",fu),Q.add("EmissionModule",ha),Q.add("EmphasizeOnClick",Mp),Q.add("EventList",Gr),Q.add("EventListEvent",Dy),Q.add("EventSystem",Hn),Q.add("EventTrigger",Zb),Q.add("FieldWithDefault",CS),Q.add("FixedJoint",yM),Q.add("FlyControls",bM),Q.add("Fog",kp),Q.add("GltfExport",Ol),Q.add("GltfExportBox",MM),Q.add("Gradient",Vc),Q.add("Graphic",au),Q.add("GraphicRaycaster",PE),Q.add("GridHelper",Op),Q.add("GridLayoutGroup",$E),Q.add("GroundProjectedEnv",gu),Q.add("GroupActionModel",Mc),Q.add("HideOnStart",sM),Q.add("HingeJoint",Nm),Q.add("HorizontalLayoutGroup",ZE),Q.add("Image",xp),Q.add("InheritVelocityModule",qc),Q.add("InputField",vu),Q.add("Interactable",tp),Q.add("Light",Yr),Q.add("LimitVelocityOverLifetimeModule",us),Q.add("LODGroup",Qm),Q.add("LODModel",Au),Q.add("LogStats",RM),Q.add("LookAt",yu),Q.add("LookAtConstraint",Wg),Q.add("MainModule",Ws),Q.add("MaskableGraphic",Tm),Q.add("MeshCollider",Mm),Q.add("MeshRenderer",Fy),Q.add("MinMaxCurve",tt),Q.add("MinMaxGradient",Xr),Q.add("NestedGltf",s_),Q.add("Networking",pu),Q.add("NoiseModule",hi),Q.add("ObjectRaycaster",iu),Q.add("OffsetConstraint",bu),Q.add("OpenURL",Np),Q.add("OrbitControls",Nc),Q.add("Outline",_p),Q.add("Padding",jc),Q.add("ParticleBurst",Dm),Q.add("ParticleSubEmitter",d_),Q.add("ParticleSystem",$i),Q.add("ParticleSystemRenderer",El),Q.add("PixelationEffect",Ym),Q.add("PlayableDirector",vm),Q.add("PlayAnimationOnClick",Gc),Q.add("PlayAudioOnClick",Ip),Q.add("PlayerColor",Pu),Q.add("PlayerState",qp),Q.add("PlayerSync",pI),Q.add("PointerEventData",tu),Q.add("PostProcessingHandler",f_),Q.add("PreliminaryAction",Rp),Q.add("PreliminaryTrigger",Pm),Q.add("PresentationMode",Dne),Q.add("RawImage",Fb),Q.add("Raycaster",fp),Q.add("Rect",XE),Q.add("RectTransform",ur),Q.add("ReflectionProbe",Xd),Q.add("RegisteredAnimationInfo",Qy),Q.add("RemoteSkybox",_u),Q.add("Renderer",Ui),Q.add("RendererLightmap",Qg),Q.add("RGBAColor",vi),Q.add("Rigidbody",Di),Q.add("RotationBySpeedModule",fn),Q.add("RotationOverLifetimeModule",Wn),Q.add("SceneSwitcher",mn),Q.add("ScreenCapture",$m),Q.add("ScreenSpaceAmbientOcclusion",Il),Q.add("SetActiveOnClick",Ep),Q.add("ShadowCatcher",iv),Q.add("ShapeModule",Ki),Q.add("SignalAsset",gm),Q.add("SignalReceiver",vp),Q.add("SignalReceiverEvent",mp),Q.add("SignalTrackHandler",_m),Q.add("Size",qE),Q.add("SizeBySpeedModule",kr),Q.add("SizeOverLifetimeModule",Wc),Q.add("SkinnedMeshRenderer",SS),Q.add("SmoothFollow",Zc),Q.add("SpatialHtml",XM),Q.add("SpatialTrigger",nv),Q.add("SpatialTriggerReceiver",ma),Q.add("SpectatorCamera",b_),Q.add("SphereCollider",Sm),Q.add("Sprite",Tl),Q.add("SpriteData",Hp),Q.add("SpriteRenderer",xu),Q.add("SpriteSheet",ov),Q.add("SubEmitterSystem",Xm),Q.add("SyncedCamera",x_),Q.add("SyncedRoom",$c),Q.add("SyncedTransform",Oc),Q.add("TapGestureTrigger",nM),Q.add("TeleportTarget",vb),Q.add("TestRunner",rI),Q.add("TestSimulateUserData",nI),Q.add("Text",Dr),Q.add("TextBuilder",Wb),Q.add("TextExtension",qb),Q.add("TextureSheetAnimationModule",qs),Q.add("TiltShiftEffect",va),Q.add("ToneMapping",lv),Q.add("TrailModule",Ii),Q.add("TransformData",Gy),Q.add("TransformGizmo",Su),Q.add("TriggerBuilder",Hr),Q.add("TriggerModel",Yh),Q.add("UIRaycastUtils",cp),Q.add("UIRootComponent",om),Q.add("UsageMarker",ip),Q.add("USDZExporter",Xn),Q.add("USDZText",Xc),Q.add("VariantAction",BS),Q.add("VelocityOverLifetimeModule",Oi),Q.add("VerticalLayoutGroup",KE),Q.add("VideoPlayer",Js),Q.add("Vignette",Eu),Q.add("VisibilityAction",Bm),Q.add("Voip",kl),Q.add("Volume",I_),Q.add("VolumeParameter",Dt),Q.add("VolumeProfile",xm),Q.add("VRUserState",Al),Q.add("WebAR",um),Q.add("WebARCameraBackground",R_),Q.add("WebARSessionRoot",Pc),Q.add("WebXR",wt),Q.add("WebXRAvatar",kc),Q.add("WebXRController",cs),Q.add("WebXRImageTracking",B_),Q.add("WebXRImageTrackingModel",Rl),Q.add("WebXRPlaneTracking",k_),Q.add("WebXRSync",cm),Q.add("WebXRTrackedImage",Mu),Q.add("XRFlag",Tr),Q.add("XRGrabModel",D_),Q.add("XRGrabRendering",uI),Q.add("XRRig",yb),Q.add("XRState",Zo);const xU=rr,One=oe("debugtypestore");One&&console.log(Q);function Lne(i,e){const t=fB(i,e);return t!==void 0?t:null}const Fne=new m6,fI=Symbol("deserialize-queue");async function Nne(i,e,t,s=null,r){if(!t)return;let n=s;typeof n=="number"&&(n=new Lr(s));const o=e.indexOf("?");e=o===-1?e:e.substring(0,o);const a=new pB(t.scene);a.gltfId=e,a.context=i,a.gltf=t,a.nodeToObject=r?.nodeToObjectMap,a.implementationInformation=Fne;let l=i[fI];if(l||(l=i[fI]=[]),t.scenes)for(const c of t.scenes)await mI(a,c,l);if(t.children)for(const c of t.children)await mI(a,c,l);i.new_scripts_pre_setup_callbacks.push(()=>{const c=i[fI];if(c){for(const u of c)Une(u,a);c.length=0}if(n){const u={};gI(t,n,u);for(const d of t.scenes)gI(d,n,u)}})}function gI(i,e,t){if(e===null||!i)return;const s=i.guid;if(i.guid=e.generateUUID(),s&&s!=="invalid"&&(t[s]=i.guid),i&&i.userData&&i.userData.components)for(const r of i.userData.components){if(r===null)continue;const n=r.guid;r.guid=e.generateUUID(),n&&n!=="invalid"&&(t[n]=r.guid),r.resolveGuids&&r.resolveGuids(t)}if(i.children)for(const r of i.children)gI(r,e,t)}const gv=[];async function mI(i,e,t,s){if(!e)return;const r=e.userData;if(r){const n=r.builtin_components;if(n&&n.length>0)for(const o of n)try{if(o===null)continue;const a=Q.get(o.name);if(a!=null){const l=new a;l.sourceId=i.gltfId,Lh(l,o,i.implementationInformation),"guid"in o&&(l[pf]=o.guid),lc(e,l,!1),t.push({instance:l,compData:o,obj:e}),l.isCamera&&i.context&&i.context.mainCamera===null&&l.tag==="MainCamera"&&i.context.setCurrentCamera(l)}else xU&&console.debug("unknown component: "+o.name),gv.includes(o.name)||gv.push(o.name)}catch(a){console.error(o.name+" - "+a.message,a)}if(gv.length>0){const o=gv.join(", ");console.warn("unknown components: "+o),gv.length=0,gr()&&Ns(`<strong>Unknown components in scene</strong>:
5053
5053
 
5054
5054
  ${o}
5055
5055
 
5056
5056
  This could mean you forgot to add a npmdef to your ExportInfo
5057
- <a href="https://engine.needle.tools/docs/project_structure.html#creating-and-installing-a-npmdef" target="_blank">documentation</a>`,ko.Warn)}}if(e.children)for(const n of e.children)await mI(i,n,t)}function Une(i,e){const{instance:t,compData:s,obj:r}=i;e.object=r,e.target=t,y0(t,s,e),xU&&console.debug("add "+s.name,s,t)}class vI{createBuiltinComponents(e,t,s,r,n){return Nne(e,t,s,r,n)}writeBuiltinComponentData(e,t){return Lne(e,t)}parseSync(e,t,s,r){return SU(e,t,s,r)}loadSync(e,t,s,r,n){return EU(e,t,s,r,n)}}AC(vI);const zne=oe("printGltf");var wU=(i=>(i[i.BeforeLoad=0]="BeforeLoad",i[i.AfterLoaded=1]="AfterLoaded",i[i.FinishedSetup=10]="FinishedSetup",i))(wU||{});class Iu{constructor(e,t,s,r){h(this,"context"),h(this,"loader"),h(this,"path"),h(this,"gltf"),this.context=e,this.path=t,this.loader=s,this.gltf=r}}const th={};function jne(i,e){th[i]=th[i]||[],th[i].push(e)}function Qne(i,e){if(th[i]){const t=th[i].indexOf(e);t>=0&&th[i].splice(t,1)}}function Xp(i,e){if(th[i])for(const t of th[i])t(e)}async function CU(i,e,t,s,r){zne&&console.warn("glTF",e,t),await vo().createBuiltinComponents(i,e,t,s,r)}function AI(i,e){const t=new Pd;return oL(t,e,i),t}function SU(i,e,t,s){typeof t!="string"&&console.warn("Parse gltf binary without path, this might lead to errors in resolving extensions. Please provide the source path of the gltf/glb file",t,typeof t);const r=AI(t,i),n=xS(r);return new Promise((o,a)=>{try{Tg(r,i),Xp(0,new Iu(i,t,r)),r.parse(e,t,async l=>{Xp(1,new Iu(i,t,r,l)),await CU(i,t,l,s,n),Xp(10,new Iu(i,t,r,l)),j2(l.scene,i),o(l)},l=>{console.error("failed loading "+t,l),o(void 0)})}catch(l){console.error(l),a(l)}})}function EU(i,e,t,s,r){const n=AI(e,i),o=xS(n);return new Promise((a,l)=>{try{Tg(n,i),Xp(0,new Iu(i,e,n)),n.load(e,async c=>{Xp(1,new Iu(i,e,n,c)),await CU(i,t,c,s,o),Xp(10,new Iu(i,e,n,c)),j2(c.scene,i),a(c)},c=>{r?.call(n,c)},c=>{console.error("failed loading "+e,c),a(void 0)})}catch(c){console.error(c),l(c)}})}function Gne(i,e,t,s=!1){e&&e.animations&&e.animations.length>0&&t.push(()=>{MU(e,s)})}function MU(i,e=!1){if(!i||!i.animations||!i.scene||!e&&!wd(i.scene,yo))return;for(let s=0;s<i.animations.length;s++){const r=i.animations[s];if(!(!r.tracks||r.tracks.length<=0))for(const n in r.tracks){const o=r.tracks[n],a=o.__objectName??o.name.substring(0,o.name.indexOf(".")),l=i.scene.getObjectByName(a);if(!l)continue;let c=t(l);if(!c)if(e)c=lc(i.scene,new yo);else{console.warn("Failed finding animator for",o.name,a);continue}const u=c.animations=c.animations||[];r.name_animator=c.name,u.indexOf(r)<0&&u.push(r)}}function t(s){var r;if(!s)return;const n=(r=s.userData)==null?void 0:r.components;if(n&&n.length>0)for(let o=0;o<n.length;o++){const a=n[o];if(a instanceof jr||a instanceof yo)return s}return t(s.parent)}}function IU(i,e,t=!0){if(e.userData&&e.userData.name===i)return e;if(e.children&&e.children.length>0)for(let s=0;s<e.children.length;s++){const r=e.children[s],n=IU(i,r,t);if(n)return n}}function Hne(i,e=null){const t=e??_t.Current.scripts;for(const s in t){const r=t[s];if(r&&r.guid===i)return r}return null}AC(vI);const Kn=oe("debugwebcomponent"),TU="needle-engine",RU="vr",PU="desktop",Vne=[Qh,RU,PU],mv="ar-session-active",vv="desktop-session-active";class yI extends HTMLElement{constructor(){super(),h(this,"gameObject",$),h(this,"GameObject",$),h(this,"_context"),h(this,"_overlay_ar"),h(this,"_loadingProgress01",0),h(this,"_loadingView"),h(this,"_previousSrc",null),h(this,"_isCurrentlySettingsSourceAttribute",!1),h(this,"onReady",()=>{var e;return(e=this._loadingView)==null?void 0:e.onLoadingFinished()}),this._overlay_ar=new Uq,this._context=new _t({domElement:this}),this.addEventListener("ready",this.onReady)}get loadingProgress01(){return this._loadingProgress01}get loadingFinished(){return this.loadingProgress01>.999}get cameraControls(){const e=this.getAttribute("camera-controls");return!(e===null||e==="False"||e==="false"||e==="0")}getContext(){return new Promise((e,t)=>{if(this._context&&this.loadingFinished)e(this._context);else{const s=()=>{this.removeEventListener("loadfinished",s),this._context&&this.loadingFinished&&e(this._context)};this.addEventListener("loadfinished",s)}})}get context(){return this._context}get Context(){return this._context}async connectedCallback(){Kn&&(console.log("<needle-engine> connected"),console.dir(this)),this.onSetupDesktop();const e=this.getAttribute("src")??globalThis["needle:codegen_files"];e&&e.length>0&&await this.onLoad(e,!0),this.onSetupDesktop()}disconnectedCallback(){var e;(e=this._context)==null||e.onDestroy()}static get observedAttributes(){return["hash","src","camera-controls","loadstart","progress","loadfinished","dracoDecoderPath","dracoDecoderType","ktx2DecoderPath"]}attributeChangedCallback(e,t,s){switch(e){case"src":Kn&&console.log("src changed to type:",typeof s,', from "',t,'" to "',s),this.onLoad(s,!1);break;case"hash":this._context&&(this._context.hash=s);break;case"loadstart":case"progress":case"loadfinished":typeof s=="string"&&s.length>0&&(Kn&&console.log(e+" attribute changed",s),this.registerEventFromAttribute(e,s));break;case"dracoDecoderPath":Kn&&console.log("dracoDecoderPath",s),YD(s);break;case"dracoDecoderType":s==="wasm"||s==="js"?(Kn&&console.log("dracoDecoderType",s),JD(s)):console.error("Invalid dracoDecoderType",s,"expected js or wasm");break;case"ktx2DecoderPath":Kn&&console.log("ktx2DecoderPath",s),KD(s);break}}async onLoad(e,t){var s,r;if(this._isCurrentlySettingsSourceAttribute||e===this._previousSrc)return;if(!e||!e.length){console.error("Needle Engine: No source specified",e);return}if(!this._context){console.error("Needle Engine: Context not initialized");return}this._previousSrc=e,this._isCurrentlySettingsSourceAttribute=!0,this.setAttribute("src",e?.toString()),this._isCurrentlySettingsSourceAttribute=!1;const n=this.getAttribute("alias");this.classList.add("loading"),Kn&&console.log("Needle Engine: Begin loading",n??"");const o=!0,a=this.dispatchEvent(new CustomEvent("loadstart",{detail:{context:this._context,alias:n},cancelable:o}));!this._loadingView&&a&&(this._loadingView=new EC(this)),a&&((s=this._loadingView)==null||s.onLoadingBegin("begin load")),this.onBeforeBeginLoading(),Kn&&console.log(e);let l;Array.isArray(e)?l=e:e.startsWith("[")&&e.endsWith("]")?l=JSON.parse(e):e.includes(",")?l=e.split(","):l=[e];let c=null;if(l?.length>0&&(c=async d=>{let p=0;d.hash&&(p=Number.parseInt(d.hash)??0);const f=vo();for(let g=0;g<l.length;g++){const m=l[g];if(!m.includes(".glb")&&!m.includes(".gltf")){const w=`Needle Engine: found suspicious src "${m}"`;console.warn(w),gr()&&ho(w)}const v=Wne(m),A={name:v,progress:null,index:g,count:l.length},b={detail:{context:d,name:v,progress:A.progress,index:g,count:l.length,totalProgress01:this._loadingProgress01}},y=await f.loadSync(d,m,m,p,w=>{var E;A.progress=w,this._loadingProgress01=CC(A),a&&((E=this._loadingView)==null||E.onLoadingUpdate(A)),b.detail.progress=w,b.detail.totalProgress01=this._loadingProgress01,this.dispatchEvent(new CustomEvent("progress",b))}),_=y?.scene;_&&$.add(_,d.scene,d)}t||yg(d)}),!c){console.error("Needle Engine: No files to load",e);return}const u=this.getAttribute("hash");u!=null&&(this._context.hash=u),this._context.alias=n,this._context.isCreated?await c(this._context):await this._context.onCreate(c),this._loadingProgress01=1,a&&((r=this._loadingView)==null||r.onLoadingUpdate(1,"creating scene")),this.classList.remove("loading"),this.classList.add("loading-finished"),Kn&&console.log("Needle Engine: finished loading",n??""),this.dispatchEvent(new CustomEvent("loadfinished",{detail:{context:this._context,src:n??e}}))}registerEventFromAttribute(e,t){if(typeof t=="string"&&t.length>0){const s=(0,eval)(t);typeof s=="function"&&this.addEventListener(e,r=>s?.call(globalThis,this._context,r))}}getAROverlayContainer(){return this._overlay_ar.findOrCreateARContainer(this)}getVROverlayContainer(){for(let e=0;e<this.children.length;e++){const t=this.children[e];if(t.classList.contains("vr"))return t}return null}onEnterAR(e,t){var s;this.onSetupAR(),this._overlay_ar.onBegin(this._context,t,e),this.dispatchEvent(new CustomEvent("enter-ar",{detail:{session:e,context:this._context,htmlContainer:(s=this._overlay_ar)==null?void 0:s.ARContainer}}))}onExitAR(e){var t;this._overlay_ar.onEnd(this._context),this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-ar",{detail:{session:e,context:this._context,htmlContainer:(t=this._overlay_ar)==null?void 0:t.ARContainer}}))}onEnterVR(e){this.onSetupVR(),this.dispatchEvent(new CustomEvent("enter-vr",{detail:{session:e,context:this._context}}))}onExitVR(e){this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-vr",{detail:{session:e,context:this._context}}))}onSetupAR(){this.classList.add(mv),this.classList.remove(vv);const e=this.getAROverlayContainer();e&&(e.classList.add(mv),e.classList.remove(vv)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,Qh))}onSetupVR(){this.classList.remove(mv),this.classList.remove(vv),this.foreachHtmlElement(e=>this.setupElementsForMode(e,RU))}onSetupDesktop(){this.classList.remove(mv),this.classList.add(vv);const e=this.getAROverlayContainer();e&&(e.classList.remove(mv),e.classList.add(vv)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,PU))}setupElementsForMode(e,t,s=null){var r;if(!(e===((r=this._context)==null?void 0:r.renderer.domElement)||e.id==="VRButton"||e.id==="ARButton"))if(e.style.position="absolute",e.classList.contains(t))e.style.visibility="visible",e.style.display==="none"&&(e.style.display="block");else for(const n of Vne)e.classList.contains(n)&&(e.style.visibility="hidden",e.style.display="none")}foreachHtmlElement(e){for(let t=0;t<this.children.length;t++){const s=this.children[t];s.style&&e(s)}}onBeforeBeginLoading(){const e=this.getAttribute("dracoDecoderPath");e&&(Kn&&console.log("using custom draco decoder path",e),YD(e));const t=this.getAttribute("dracoDecoderType");t&&(Kn&&console.log("using custom draco decoder type",t),JD(t));const s=this.getAttribute("ktx2DecoderPath");s&&(Kn&&console.log("using custom ktx2 decoder path",s),KD(s))}}window.customElements.get(TU)||window.customElements.define(TU,yI);function Wne(i){const e=i.split("/");let t=e[e.length-1],s=t.indexOf("?");return s>0&&(t=t.substring(0,s)),decodeURIComponent(t)}const qne=Object.freeze(Object.defineProperty({__proto__:null,NeedleEngineHTMLElement:yI},Symbol.toStringTag,{value:"Module"}));ts.registerCallback($r.MissingCamera,i=>{const e=i.context.scene,t="unknown",s=new Me;e.add(s);const r=new Ei,n=lc(s,r,!0);return n.sourceId=t,n.clearFlags=2,n.backgroundColor=new vi(.5,.5,.5,1),s.position.x=-2,s.position.y=2,s.position.z=2,n}),ts.registerCallback($r.ContextCreated,i=>{if(!i.context.mainCamera)return;const e=i.context.domElement;if(e?.cameraControls===!0){const t=fee(i.context.mainCamera);if(t?.isCameraController===!0)return;const s=i.context.mainCameraComponent,r=s?.gameObject;if(r){const n=lc(r,new Nc,!1);n.sourceId="unknown"}else console.warn("Missing camera object, can not add orbit controls")}});const bI=oe("debughotreload");let Av=!1;const yv=new Map;function Xne(){return Av}function Yne(i){var e;if(Av)return;const t=i.constructor.name;yv.has(t)?(e=yv.get(t))==null||e.push(i):yv.set(t,[i])}function Jne(i){if(Av)return;const e=i.constructor.name,t=yv.get(e);if(!t)return;const s=t.indexOf(i);s!==-1&&t.splice(s,1)}let BU=!1;function Kne(){if(bI||BU)return;BU=!0;const i=console.error;console.error=(...e)=>{if(e.length){const t=e[0];if(typeof t=="string"&&t.includes("[hmr] Failed to reload ")){console.log("[Needle Engine] Hot reloading failed"),window.location.reload();return}}i.apply(console,e)}}function Zne(i){bI&&console.log("Hot Reload - apply changes"),Kne();for(const e of Object.keys(i))try{Av=!0;const t=Q.get(e);if(!t)continue;const s=i[e],r=yv.get(s.name);let n="[Needle Engine] Updating type: "+e,o=r?.length??-1;o>0?n+=" x"+o:n+=" - no instances",console.log(n);const a=Object.getOwnPropertyNames(t.prototype),l=Object.getOwnPropertyDescriptors(s.prototype);for(const c in l)l[c].writable&&(t.prototype[c]=i[e].prototype[c]);for(const c of a)l[c]||delete t.prototype[c];if(r){const c=new s,u=Object.getOwnPropertyDescriptors(c);for(const d of r){const p=d,f=p.isComponent===!0,g=f?p.activeAndEnabled:!0,m=f?p.context:void 0;try{if(f&&Ka(p,m),f&&g&&(p.enabled=!1),d.onBeforeHotReloadFields&&d.onBeforeHotReloadFields()===!1)continue;for(const v in u)if(u[v].writable){if(d[v]===void 0)d[v]=c[v];else if(typeof d[v]=="function"&&!d[v].prototype){const A=d[v],b=A.name,y="bound ";if(b===y)continue;const _=A.name.substring(y.length),w=s.prototype[_];w&&(d[v]=w.bind(d))}}d.onAfterHotReloadFields&&d.onAfterHotReloadFields()}finally{f&&tC(p,m),f&&g&&(p.enabled=!0)}}}}catch(t){if(bI)console.error(t);else return!1}finally{Av=!1,Ra(ko.Log,"Script changes applied (HMR)")}return!0}const $ne=Symbol("object"),kU=new Bo(()=>new S,20);class DU{constructor(e,t,s,r,n){h(this,"_point"),h(this,"_normal"),h(this,"distance"),h(this,"impulse"),h(this,"friction"),this._point=e,this.distance=t,this._normal=s,this.impulse=r,this.friction=n}get point(){return kU.get().set(this._point.x,this._point.y,this._point.z)}get normal(){return kU.get().set(this._normal.x,this._normal.y,this._normal.z)}}class OU{constructor(e,t,s){h(this,"contacts"),h(this,"me"),h(this,"_collider"),h(this,"_gameObject"),this.me=e,this._collider=t,this._gameObject=t.gameObject,this.contacts=s}get collider(){return this._collider}get gameObject(){return this._gameObject}get rigidBody(){var e;return(e=this.collider)==null?void 0:e.attachedRigidbody}}class LU{constructor(e,t){h(this,"object"),h(this,"collider"),this.object=e,this.collider=t}}let Le;const bv=new Array(32).fill(void 0);bv.push(void 0,null,!0,!1);let FU;bv.length;function NU(){return FU.byteLength,FU}const eoe=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});function gt(i,e){if(!(i instanceof e))throw new Error(`expected instance of ${e.name}`);return i.ptr}eoe.decode();let UU,zU,_v=32;function jU(i){if(_v==1)throw new Error("out of js stack");return bv[--_v]=i,_v}function toe(){return UU.byteLength,UU}function ioe(){return zU.byteLength,zU}let yn=0;function Tu(i,e){const t=e(4*i.length);return toe().set(i,t/4),yn=i.length,t}function L_(i,e){const t=e(4*i.length);return ioe().set(i,t/4),yn=i.length,t}class H_{static __wrap(e){const t=Object.create(H_.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_raweventqueue_free(e)}constructor(e){const t=Le.raweventqueue_new(e);return H_.__wrap(t)}drainCollisionEvents(e){try{Le.raweventqueue_drainCollisionEvents(this.ptr,jU(e))}finally{bv[_v++]=void 0}}drainContactForceEvents(e){try{Le.raweventqueue_drainContactForceEvents(this.ptr,jU(e))}finally{bv[_v++]=void 0}}clear(){Le.raweventqueue_clear(this.ptr)}}class Ma{static __wrap(e){const t=Object.create(Ma.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawgenericjoint_free(e)}static spherical(e,t){gt(e,ot),gt(t,ot);const s=Le.rawgenericjoint_spherical(e.ptr,t.ptr);return Ma.__wrap(s)}static prismatic(e,t,s,r,n,o){gt(e,ot),gt(t,ot),gt(s,ot);const a=Le.rawgenericjoint_prismatic(e.ptr,t.ptr,s.ptr,r,n,o);return a===0?void 0:Ma.__wrap(a)}static fixed(e,t,s,r){gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,Ls);const n=Le.rawgenericjoint_fixed(e.ptr,t.ptr,s.ptr,r.ptr);return Ma.__wrap(n)}static revolute(e,t,s){gt(e,ot),gt(t,ot),gt(s,ot);const r=Le.rawgenericjoint_revolute(e.ptr,t.ptr,s.ptr);return r===0?void 0:Ma.__wrap(r)}}class PI{static __wrap(e){const t=Object.create(PI.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawpointprojection_free(e)}point(){const e=Le.rawpointprojection_point(this.ptr);return ot.__wrap(e)}isInside(){return Le.rawpointprojection_isInside(this.ptr)!==0}}class BI{static __wrap(e){const t=Object.create(BI.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawrayintersection_free(e)}normal(){const e=Le.rawrayintersection_normal(this.ptr);return ot.__wrap(e)}toi(){return Le.rawintegrationparameters_dt(this.ptr)}featureType(){return Le.rawrayintersection_featureType(this.ptr)>>>0}featureId(){try{const s=Le.__wbindgen_add_to_stack_pointer(-16);Le.rawrayintersection_featureId(s,this.ptr);var e=NU()[s/4+0],t=NU()[s/4+1];return e===0?void 0:t>>>0}finally{Le.__wbindgen_add_to_stack_pointer(16)}}}class Ls{static __wrap(e){const t=Object.create(Ls.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawrotation_free(e)}constructor(e,t,s,r){const n=Le.rawrotation_new(e,t,s,r);return Ls.__wrap(n)}static identity(){const e=Le.rawrotation_identity();return Ls.__wrap(e)}get x(){return Le.rawintegrationparameters_dt(this.ptr)}get y(){return Le.rawrotation_y(this.ptr)}get z(){return Le.rawintegrationparameters_erp(this.ptr)}get w(){return Le.rawrotation_w(this.ptr)}}class Ot{static __wrap(e){const t=Object.create(Ot.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawshape_free(e)}static cuboid(e,t,s){const r=Le.rawshape_cuboid(e,t,s);return Ot.__wrap(r)}static roundCuboid(e,t,s,r){const n=Le.rawshape_roundCuboid(e,t,s,r);return Ot.__wrap(n)}static ball(e){const t=Le.rawshape_ball(e);return Ot.__wrap(t)}static capsule(e,t){const s=Le.rawshape_capsule(e,t);return Ot.__wrap(s)}static cylinder(e,t){const s=Le.rawshape_cylinder(e,t);return Ot.__wrap(s)}static roundCylinder(e,t,s){const r=Le.rawshape_roundCylinder(e,t,s);return Ot.__wrap(r)}static cone(e,t){const s=Le.rawshape_cone(e,t);return Ot.__wrap(s)}static roundCone(e,t,s){const r=Le.rawshape_roundCone(e,t,s);return Ot.__wrap(r)}static polyline(e,t){const s=Tu(e,Le.__wbindgen_malloc),r=yn,n=L_(t,Le.__wbindgen_malloc),o=yn,a=Le.rawshape_polyline(s,r,n,o);return Ot.__wrap(a)}static trimesh(e,t){const s=Tu(e,Le.__wbindgen_malloc),r=yn,n=L_(t,Le.__wbindgen_malloc),o=yn,a=Le.rawshape_trimesh(s,r,n,o);return Ot.__wrap(a)}static heightfield(e,t,s,r){const n=Tu(s,Le.__wbindgen_malloc),o=yn;gt(r,ot);const a=Le.rawshape_heightfield(e,t,n,o,r.ptr);return Ot.__wrap(a)}static segment(e,t){gt(e,ot),gt(t,ot);const s=Le.rawshape_segment(e.ptr,t.ptr);return Ot.__wrap(s)}static triangle(e,t,s){gt(e,ot),gt(t,ot),gt(s,ot);const r=Le.rawshape_triangle(e.ptr,t.ptr,s.ptr);return Ot.__wrap(r)}static roundTriangle(e,t,s,r){gt(e,ot),gt(t,ot),gt(s,ot);const n=Le.rawshape_roundTriangle(e.ptr,t.ptr,s.ptr,r);return Ot.__wrap(n)}static convexHull(e){const t=Tu(e,Le.__wbindgen_malloc),s=yn,r=Le.rawshape_convexHull(t,s);return r===0?void 0:Ot.__wrap(r)}static roundConvexHull(e,t){const s=Tu(e,Le.__wbindgen_malloc),r=yn,n=Le.rawshape_roundConvexHull(s,r,t);return n===0?void 0:Ot.__wrap(n)}static convexMesh(e,t){const s=Tu(e,Le.__wbindgen_malloc),r=yn,n=L_(t,Le.__wbindgen_malloc),o=yn,a=Le.rawshape_convexMesh(s,r,n,o);return a===0?void 0:Ot.__wrap(a)}static roundConvexMesh(e,t,s){const r=Tu(e,Le.__wbindgen_malloc),n=yn,o=L_(t,Le.__wbindgen_malloc),a=yn,l=Le.rawshape_roundConvexMesh(r,n,o,a,s);return l===0?void 0:Ot.__wrap(l)}castShape(e,t,s,r,n,o,a,l){gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,Ot),gt(n,ot),gt(o,Ls),gt(a,ot);const c=Le.rawshape_castShape(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n.ptr,o.ptr,a.ptr,l);return c===0?void 0:DI.__wrap(c)}intersectsShape(e,t,s,r,n){return gt(e,ot),gt(t,Ls),gt(s,Ot),gt(r,ot),gt(n,Ls),Le.rawshape_intersectsShape(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n.ptr)!==0}contactShape(e,t,s,r,n,o){gt(e,ot),gt(t,Ls),gt(s,Ot),gt(r,ot),gt(n,Ls);const a=Le.rawshape_contactShape(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n.ptr,o);return a===0?void 0:kI.__wrap(a)}containsPoint(e,t,s){return gt(e,ot),gt(t,Ls),gt(s,ot),Le.rawshape_containsPoint(this.ptr,e.ptr,t.ptr,s.ptr)!==0}projectPoint(e,t,s,r){gt(e,ot),gt(t,Ls),gt(s,ot);const n=Le.rawshape_projectPoint(this.ptr,e.ptr,t.ptr,s.ptr,r);return PI.__wrap(n)}intersectsRay(e,t,s,r,n){return gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,ot),Le.rawshape_intersectsRay(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n)!==0}castRay(e,t,s,r,n,o){return gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,ot),Le.rawshape_castRay(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n,o)}castRayAndGetNormal(e,t,s,r,n,o){gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,ot);const a=Le.rawshape_castRayAndGetNormal(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n,o);return a===0?void 0:BI.__wrap(a)}}class kI{static __wrap(e){const t=Object.create(kI.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawshapecontact_free(e)}distance(){return Le.rawshapecontact_distance(this.ptr)}point1(){const e=Le.rawpointprojection_point(this.ptr);return ot.__wrap(e)}point2(){const e=Le.rawshapecontact_point2(this.ptr);return ot.__wrap(e)}normal1(){const e=Le.rawshapecontact_normal1(this.ptr);return ot.__wrap(e)}normal2(){const e=Le.rawshapecontact_normal2(this.ptr);return ot.__wrap(e)}}class DI{static __wrap(e){const t=Object.create(DI.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawshapetoi_free(e)}toi(){return Le.rawintegrationparameters_dt(this.ptr)}witness1(){const e=Le.rawrayintersection_normal(this.ptr);return ot.__wrap(e)}witness2(){const e=Le.rawshapetoi_witness2(this.ptr);return ot.__wrap(e)}normal1(){const e=Le.rawshapetoi_normal1(this.ptr);return ot.__wrap(e)}normal2(){const e=Le.rawshapetoi_normal2(this.ptr);return ot.__wrap(e)}}class ot{static __wrap(e){const t=Object.create(ot.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawvector_free(e)}static zero(){const e=Le.rawvector_zero();return ot.__wrap(e)}constructor(e,t,s){const r=Le.rawvector_new(e,t,s);return ot.__wrap(r)}get x(){return Le.rawintegrationparameters_dt(this.ptr)}set x(e){Le.rawintegrationparameters_set_dt(this.ptr,e)}get y(){return Le.rawrotation_y(this.ptr)}set y(e){Le.rawvector_set_y(this.ptr,e)}get z(){return Le.rawintegrationparameters_erp(this.ptr)}set z(e){Le.rawintegrationparameters_set_erp(this.ptr,e)}xyz(){const e=Le.rawvector_xyz(this.ptr);return ot.__wrap(e)}yxz(){const e=Le.rawvector_yxz(this.ptr);return ot.__wrap(e)}zxy(){const e=Le.rawvector_zxy(this.ptr);return ot.__wrap(e)}xzy(){const e=Le.rawvector_xzy(this.ptr);return ot.__wrap(e)}yzx(){const e=Le.rawvector_yzx(this.ptr);return ot.__wrap(e)}zyx(){const e=Le.rawvector_zyx(this.ptr);return ot.__wrap(e)}}class soe{constructor(e,t,s){this.x=e,this.y=t,this.z=s}}class Ue{static new(e,t,s){return new soe(e,t,s)}static intoRaw(e){return new ot(e.x,e.y,e.z)}static zeros(){return Ue.new(0,0,0)}static fromRaw(e){if(!e)return null;let t=Ue.new(e.x,e.y,e.z);return e.free(),t}static copy(e,t){e.x=t.x,e.y=t.y,e.z=t.z}}class QU{constructor(e,t,s,r){this.x=e,this.y=t,this.z=s,this.w=r}}class ji{static identity(){return new QU(0,0,0,1)}static fromRaw(e){if(!e)return null;let t=new QU(e.x,e.y,e.z,e.w);return e.free(),t}static intoRaw(e){return new Ls(e.x,e.y,e.z,e.w)}static copy(e,t){e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w}}var xv,ya,GU,Zn,_I,$t,F_,Yp,xI,wI,HU,VU;(function(i){i[i.Dynamic=0]="Dynamic",i[i.Fixed=1]="Fixed",i[i.KinematicPositionBased=2]="KinematicPositionBased",i[i.KinematicVelocityBased=3]="KinematicVelocityBased"})(xv||(xv={})),function(i){i[i.Revolute=0]="Revolute",i[i.Fixed=1]="Fixed",i[i.Prismatic=2]="Prismatic",i[i.Spherical=3]="Spherical"}(ya||(ya={})),function(i){i[i.AccelerationBased=0]="AccelerationBased",i[i.ForceBased=1]="ForceBased"}(GU||(GU={}));class of{constructor(){}static fixed(e,t,s,r){let n=new of;return n.anchor1=e,n.anchor2=s,n.frame1=t,n.frame2=r,n.jointType=ya.Fixed,n}static spherical(e,t){let s=new of;return s.anchor1=e,s.anchor2=t,s.jointType=ya.Spherical,s}static prismatic(e,t,s){let r=new of;return r.anchor1=e,r.anchor2=t,r.axis=s,r.jointType=ya.Prismatic,r}static revolute(e,t,s){let r=new of;return r.anchor1=e,r.anchor2=t,r.axis=s,r.jointType=ya.Revolute,r}intoRaw(){let e,t,s=Ue.intoRaw(this.anchor1),r=Ue.intoRaw(this.anchor2),n=!1,o=0,a=0;switch(this.jointType){case ya.Fixed:let l=ji.intoRaw(this.frame1),c=ji.intoRaw(this.frame2);t=Ma.fixed(s,l,r,c),l.free(),c.free();break;case ya.Prismatic:e=Ue.intoRaw(this.axis),this.limitsEnabled&&(n=!0,o=this.limits[0],a=this.limits[1]),t=Ma.prismatic(s,r,e,n,o,a),e.free();break;case ya.Spherical:t=Ma.spherical(s,r);break;case ya.Revolute:e=Ue.intoRaw(this.axis),t=Ma.revolute(s,r,e),e.free()}return s.free(),r.free(),t}}(function(i){i[i.Average=0]="Average",i[i.Min=1]="Min",i[i.Multiply=2]="Multiply",i[i.Max=3]="Max"})(Zn||(Zn={}));class Dv{constructor(e,t,s,r,n){this.distance=e,this.point1=t,this.point2=s,this.normal1=r,this.normal2=n}static fromRaw(e){if(!e)return null;const t=new Dv(e.distance(),Ue.fromRaw(e.point1()),Ue.fromRaw(e.point2()),Ue.fromRaw(e.normal1()),Ue.fromRaw(e.normal2()));return e.free(),t}}(function(i){i[i.Vertex=0]="Vertex",i[i.Edge=1]="Edge",i[i.Face=2]="Face",i[i.Unknown=3]="Unknown"})(_I||(_I={}));class V_{constructor(e,t){this.point=e,this.isInside=t}static fromRaw(e){if(!e)return null;const t=new V_(Ue.fromRaw(e.point()),e.isInside());return e.free(),t}}class roe{constructor(e,t){this.origin=e,this.dir=t}pointAt(e){return{x:this.origin.x+this.dir.x*e,y:this.origin.y+this.dir.y*e,z:this.origin.z+this.dir.z*e}}}class W_{constructor(e,t,s,r){this.featureType=_I.Unknown,this.featureId=void 0,this.toi=e,this.normal=t,r!==void 0&&(this.featureId=r),s!==void 0&&(this.featureType=s)}static fromRaw(e){if(!e)return null;const t=new W_(e.toi(),Ue.fromRaw(e.normal()),e.featureType(),e.featureId());return e.free(),t}}class Ov{constructor(e,t,s,r,n){this.toi=e,this.witness1=t,this.witness2=s,this.normal1=r,this.normal2=n}static fromRaw(e,t){if(!t)return null;const s=new Ov(t.toi(),Ue.fromRaw(t.witness1()),Ue.fromRaw(t.witness2()),Ue.fromRaw(t.normal1()),Ue.fromRaw(t.normal2()));return t.free(),s}}class OI extends Ov{constructor(e,t,s,r,n,o){super(t,s,r,n,o),this.collider=e}static fromRaw(e,t){if(!t)return null;const s=new OI(e.get(t.colliderHandle()),t.toi(),Ue.fromRaw(t.witness1()),Ue.fromRaw(t.witness2()),Ue.fromRaw(t.normal1()),Ue.fromRaw(t.normal2()));return t.free(),s}}class Zs{static fromRaw(e,t){const s=e.coShapeType(t);let r,n,o,a,l,c;switch(s){case $t.Ball:return new CI(e.coRadius(t));case $t.Cuboid:return r=e.coHalfExtents(t),new WU(r.x,r.y,r.z);case $t.RoundCuboid:return r=e.coHalfExtents(t),n=e.coRoundRadius(t),new qU(r.x,r.y,r.z,n);case $t.Capsule:return l=e.coHalfHeight(t),c=e.coRadius(t),new XU(l,c);case $t.Segment:return o=e.coVertices(t),new YU(Ue.new(o[0],o[1],o[2]),Ue.new(o[3],o[4],o[5]));case $t.Polyline:return o=e.coVertices(t),a=e.coIndices(t),new ZU(o,a);case $t.Triangle:return o=e.coVertices(t),new JU(Ue.new(o[0],o[1],o[2]),Ue.new(o[3],o[4],o[5]),Ue.new(o[6],o[7],o[8]));case $t.RoundTriangle:return o=e.coVertices(t),n=e.coRoundRadius(t),new KU(Ue.new(o[0],o[1],o[2]),Ue.new(o[3],o[4],o[5]),Ue.new(o[6],o[7],o[8]),n);case $t.TriMesh:return o=e.coVertices(t),a=e.coIndices(t),new $U(o,a);case $t.HeightField:const u=e.coHeightfieldScale(t),d=e.coHeightfieldHeights(t),p=e.coHeightfieldNRows(t),f=e.coHeightfieldNCols(t);return new ez(p,f,d,u);case $t.ConvexPolyhedron:return o=e.coVertices(t),a=e.coIndices(t),new SI(o,a);case $t.RoundConvexPolyhedron:return o=e.coVertices(t),a=e.coIndices(t),n=e.coRoundRadius(t),new EI(o,a,n);case $t.Cylinder:return l=e.coHalfHeight(t),c=e.coRadius(t),new tz(l,c);case $t.RoundCylinder:return l=e.coHalfHeight(t),c=e.coRadius(t),n=e.coRoundRadius(t),new iz(l,c,n);case $t.Cone:return l=e.coHalfHeight(t),c=e.coRadius(t),new sz(l,c);case $t.RoundCone:return l=e.coHalfHeight(t),c=e.coRadius(t),n=e.coRoundRadius(t),new rz(l,c,n);default:throw new Error("unknown shape type: "+s)}}castShape(e,t,s,r,n,o,a,l){let c=Ue.intoRaw(e),u=ji.intoRaw(t),d=Ue.intoRaw(s),p=Ue.intoRaw(n),f=ji.intoRaw(o),g=Ue.intoRaw(a),m=this.intoRaw(),v=r.intoRaw(),A=Ov.fromRaw(null,m.castShape(c,u,d,v,p,f,g,l));return c.free(),u.free(),d.free(),p.free(),f.free(),g.free(),m.free(),v.free(),A}intersectsShape(e,t,s,r,n){let o=Ue.intoRaw(e),a=ji.intoRaw(t),l=Ue.intoRaw(r),c=ji.intoRaw(n),u=this.intoRaw(),d=s.intoRaw(),p=u.intersectsShape(o,a,d,l,c);return o.free(),a.free(),l.free(),c.free(),u.free(),d.free(),p}contactShape(e,t,s,r,n,o){let a=Ue.intoRaw(e),l=ji.intoRaw(t),c=Ue.intoRaw(r),u=ji.intoRaw(n),d=this.intoRaw(),p=s.intoRaw(),f=Dv.fromRaw(d.contactShape(a,l,p,c,u,o));return a.free(),l.free(),c.free(),u.free(),d.free(),p.free(),f}containsPoint(e,t,s){let r=Ue.intoRaw(e),n=ji.intoRaw(t),o=Ue.intoRaw(s),a=this.intoRaw(),l=a.containsPoint(r,n,o);return r.free(),n.free(),o.free(),a.free(),l}projectPoint(e,t,s,r){let n=Ue.intoRaw(e),o=ji.intoRaw(t),a=Ue.intoRaw(s),l=this.intoRaw(),c=V_.fromRaw(l.projectPoint(n,o,a,r));return n.free(),o.free(),a.free(),l.free(),c}intersectsRay(e,t,s,r){let n=Ue.intoRaw(t),o=ji.intoRaw(s),a=Ue.intoRaw(e.origin),l=Ue.intoRaw(e.dir),c=this.intoRaw(),u=c.intersectsRay(n,o,a,l,r);return n.free(),o.free(),a.free(),l.free(),c.free(),u}castRay(e,t,s,r,n){let o=Ue.intoRaw(t),a=ji.intoRaw(s),l=Ue.intoRaw(e.origin),c=Ue.intoRaw(e.dir),u=this.intoRaw(),d=u.castRay(o,a,l,c,r,n);return o.free(),a.free(),l.free(),c.free(),u.free(),d}castRayAndGetNormal(e,t,s,r,n){let o=Ue.intoRaw(t),a=ji.intoRaw(s),l=Ue.intoRaw(e.origin),c=Ue.intoRaw(e.dir),u=this.intoRaw(),d=W_.fromRaw(u.castRayAndGetNormal(o,a,l,c,r,n));return o.free(),a.free(),l.free(),c.free(),u.free(),d}}(function(i){i[i.Ball=0]="Ball",i[i.Cuboid=1]="Cuboid",i[i.Capsule=2]="Capsule",i[i.Segment=3]="Segment",i[i.Polyline=4]="Polyline",i[i.Triangle=5]="Triangle",i[i.TriMesh=6]="TriMesh",i[i.HeightField=7]="HeightField",i[i.ConvexPolyhedron=9]="ConvexPolyhedron",i[i.Cylinder=10]="Cylinder",i[i.Cone=11]="Cone",i[i.RoundCuboid=12]="RoundCuboid",i[i.RoundTriangle=13]="RoundTriangle",i[i.RoundCylinder=14]="RoundCylinder",i[i.RoundCone=15]="RoundCone",i[i.RoundConvexPolyhedron=16]="RoundConvexPolyhedron"})($t||($t={}));class CI extends Zs{constructor(e){super(),this.type=$t.Ball,this.radius=e}intoRaw(){return Ot.ball(this.radius)}}class WU extends Zs{constructor(e,t,s){super(),this.type=$t.Cuboid,this.halfExtents=Ue.new(e,t,s)}intoRaw(){return Ot.cuboid(this.halfExtents.x,this.halfExtents.y,this.halfExtents.z)}}class qU extends Zs{constructor(e,t,s,r){super(),this.type=$t.RoundCuboid,this.halfExtents=Ue.new(e,t,s),this.borderRadius=r}intoRaw(){return Ot.roundCuboid(this.halfExtents.x,this.halfExtents.y,this.halfExtents.z,this.borderRadius)}}class XU extends Zs{constructor(e,t){super(),this.type=$t.Capsule,this.halfHeight=e,this.radius=t}intoRaw(){return Ot.capsule(this.halfHeight,this.radius)}}class YU extends Zs{constructor(e,t){super(),this.type=$t.Segment,this.a=e,this.b=t}intoRaw(){let e=Ue.intoRaw(this.a),t=Ue.intoRaw(this.b),s=Ot.segment(e,t);return e.free(),t.free(),s}}class JU extends Zs{constructor(e,t,s){super(),this.type=$t.Triangle,this.a=e,this.b=t,this.c=s}intoRaw(){let e=Ue.intoRaw(this.a),t=Ue.intoRaw(this.b),s=Ue.intoRaw(this.c),r=Ot.triangle(e,t,s);return e.free(),t.free(),s.free(),r}}class KU extends Zs{constructor(e,t,s,r){super(),this.type=$t.RoundTriangle,this.a=e,this.b=t,this.c=s,this.borderRadius=r}intoRaw(){let e=Ue.intoRaw(this.a),t=Ue.intoRaw(this.b),s=Ue.intoRaw(this.c),r=Ot.roundTriangle(e,t,s,this.borderRadius);return e.free(),t.free(),s.free(),r}}class ZU extends Zs{constructor(e,t){super(),this.type=$t.Polyline,this.vertices=e,this.indices=t??new Uint32Array(0)}intoRaw(){return Ot.polyline(this.vertices,this.indices)}}class $U extends Zs{constructor(e,t){super(),this.type=$t.TriMesh,this.vertices=e,this.indices=t}intoRaw(){return Ot.trimesh(this.vertices,this.indices)}}class SI extends Zs{constructor(e,t){super(),this.type=$t.ConvexPolyhedron,this.vertices=e,this.indices=t}intoRaw(){return this.indices?Ot.convexMesh(this.vertices,this.indices):Ot.convexHull(this.vertices)}}class EI extends Zs{constructor(e,t,s){super(),this.type=$t.RoundConvexPolyhedron,this.vertices=e,this.indices=t,this.borderRadius=s}intoRaw(){return this.indices?Ot.roundConvexMesh(this.vertices,this.indices,this.borderRadius):Ot.roundConvexHull(this.vertices,this.borderRadius)}}class ez extends Zs{constructor(e,t,s,r){super(),this.type=$t.HeightField,this.nrows=e,this.ncols=t,this.heights=s,this.scale=r}intoRaw(){let e=Ue.intoRaw(this.scale),t=Ot.heightfield(this.nrows,this.ncols,this.heights,e);return e.free(),t}}class tz extends Zs{constructor(e,t){super(),this.type=$t.Cylinder,this.halfHeight=e,this.radius=t}intoRaw(){return Ot.cylinder(this.halfHeight,this.radius)}}class iz extends Zs{constructor(e,t,s){super(),this.type=$t.RoundCylinder,this.borderRadius=s,this.halfHeight=e,this.radius=t}intoRaw(){return Ot.roundCylinder(this.halfHeight,this.radius,this.borderRadius)}}class sz extends Zs{constructor(e,t){super(),this.type=$t.Cone,this.halfHeight=e,this.radius=t}intoRaw(){return Ot.cone(this.halfHeight,this.radius)}}class rz extends Zs{constructor(e,t,s){super(),this.type=$t.RoundCone,this.halfHeight=e,this.radius=t,this.borderRadius=s}intoRaw(){return Ot.roundCone(this.halfHeight,this.radius,this.borderRadius)}}(function(i){i[i.DYNAMIC_DYNAMIC=1]="DYNAMIC_DYNAMIC",i[i.DYNAMIC_KINEMATIC=12]="DYNAMIC_KINEMATIC",i[i.DYNAMIC_FIXED=2]="DYNAMIC_FIXED",i[i.KINEMATIC_KINEMATIC=52224]="KINEMATIC_KINEMATIC",i[i.KINEMATIC_FIXED=8704]="KINEMATIC_FIXED",i[i.FIXED_FIXED=32]="FIXED_FIXED",i[i.DEFAULT=15]="DEFAULT",i[i.ALL=60943]="ALL"})(F_||(F_={}));class noe{constructor(e,t,s,r){this.colliderSet=e,this.handle=t,this._parent=s,this._shape=r}finalizeDeserialization(e){this.handle!=null&&(this._parent=e.get(this.colliderSet.raw.coParent(this.handle)))}ensureShapeIsCached(){this._shape||(this._shape=Zs.fromRaw(this.colliderSet.raw,this.handle))}get shape(){return this.ensureShapeIsCached(),this._shape}isValid(){return this.colliderSet.raw.contains(this.handle)}translation(){return Ue.fromRaw(this.colliderSet.raw.coTranslation(this.handle))}rotation(){return ji.fromRaw(this.colliderSet.raw.coRotation(this.handle))}isSensor(){return this.colliderSet.raw.coIsSensor(this.handle)}setSensor(e){this.colliderSet.raw.coSetSensor(this.handle,e)}setShape(e){let t=e.intoRaw();this.colliderSet.raw.coSetShape(this.handle,t),t.free(),this._shape=e}setRestitution(e){this.colliderSet.raw.coSetRestitution(this.handle,e)}setFriction(e){this.colliderSet.raw.coSetFriction(this.handle,e)}frictionCombineRule(){return this.colliderSet.raw.coFrictionCombineRule(this.handle)}setFrictionCombineRule(e){this.colliderSet.raw.coSetFrictionCombineRule(this.handle,e)}restitutionCombineRule(){return this.colliderSet.raw.coRestitutionCombineRule(this.handle)}setRestitutionCombineRule(e){this.colliderSet.raw.coSetRestitutionCombineRule(this.handle,e)}setCollisionGroups(e){this.colliderSet.raw.coSetCollisionGroups(this.handle,e)}setSolverGroups(e){this.colliderSet.raw.coSetSolverGroups(this.handle,e)}activeHooks(){return this.colliderSet.raw.coActiveHooks(this.handle)}setActiveHooks(e){this.colliderSet.raw.coSetActiveHooks(this.handle,e)}activeEvents(){return this.colliderSet.raw.coActiveEvents(this.handle)}setActiveEvents(e){this.colliderSet.raw.coSetActiveEvents(this.handle,e)}activeCollisionTypes(){return this.colliderSet.raw.coActiveCollisionTypes(this.handle)}setContactForceEventThreshold(e){return this.colliderSet.raw.coSetContactForceEventThreshold(this.handle,e)}contactForceEventThreshold(){return this.colliderSet.raw.coContactForceEventThreshold(this.handle)}setActiveCollisionTypes(e){this.colliderSet.raw.coSetActiveCollisionTypes(this.handle,e)}setDensity(e){this.colliderSet.raw.coSetDensity(this.handle,e)}setMass(e){this.colliderSet.raw.coSetMass(this.handle,e)}setMassProperties(e,t,s,r){let n=Ue.intoRaw(t),o=Ue.intoRaw(s),a=ji.intoRaw(r);this.colliderSet.raw.coSetMassProperties(this.handle,e,n,o,a),n.free(),o.free(),a.free()}setTranslation(e){this.colliderSet.raw.coSetTranslation(this.handle,e.x,e.y,e.z)}setTranslationWrtParent(e){this.colliderSet.raw.coSetTranslationWrtParent(this.handle,e.x,e.y,e.z)}setRotation(e){this.colliderSet.raw.coSetRotation(this.handle,e.x,e.y,e.z,e.w)}setRotationWrtParent(e){this.colliderSet.raw.coSetRotationWrtParent(this.handle,e.x,e.y,e.z,e.w)}shapeType(){return this.colliderSet.raw.coShapeType(this.handle)}halfExtents(){return Ue.fromRaw(this.colliderSet.raw.coHalfExtents(this.handle))}radius(){return this.colliderSet.raw.coRadius(this.handle)}roundRadius(){return this.colliderSet.raw.coRoundRadius(this.handle)}halfHeight(){return this.colliderSet.raw.coHalfHeight(this.handle)}vertices(){return this.colliderSet.raw.coVertices(this.handle)}indices(){return this.colliderSet.raw.coIndices(this.handle)}heightfieldHeights(){return this.colliderSet.raw.coHeightfieldHeights(this.handle)}heightfieldScale(){let e=this.colliderSet.raw.coHeightfieldScale(this.handle);return Ue.fromRaw(e)}heightfieldNRows(){return this.colliderSet.raw.coHeightfieldNRows(this.handle)}heightfieldNCols(){return this.colliderSet.raw.coHeightfieldNCols(this.handle)}parent(){return this._parent}friction(){return this.colliderSet.raw.coFriction(this.handle)}restitution(){return this.colliderSet.raw.coRestitution(this.handle)}density(){return this.colliderSet.raw.coDensity(this.handle)}mass(){return this.colliderSet.raw.coMass(this.handle)}volume(){return this.colliderSet.raw.coVolume(this.handle)}collisionGroups(){return this.colliderSet.raw.coCollisionGroups(this.handle)}solverGroups(){return this.colliderSet.raw.coSolverGroups(this.handle)}containsPoint(e){let t=Ue.intoRaw(e),s=this.colliderSet.raw.coContainsPoint(this.handle,t);return t.free(),s}projectPoint(e,t){let s=Ue.intoRaw(e),r=V_.fromRaw(this.colliderSet.raw.coProjectPoint(this.handle,s,t));return s.free(),r}intersectsRay(e,t){let s=Ue.intoRaw(e.origin),r=Ue.intoRaw(e.dir),n=this.colliderSet.raw.coIntersectsRay(this.handle,s,r,t);return s.free(),r.free(),n}castShape(e,t,s,r,n,o){let a=Ue.intoRaw(e),l=Ue.intoRaw(s),c=ji.intoRaw(r),u=Ue.intoRaw(n),d=t.intoRaw(),p=Ov.fromRaw(this.colliderSet,this.colliderSet.raw.coCastShape(this.handle,a,d,l,c,u,o));return a.free(),l.free(),c.free(),u.free(),d.free(),p}castCollider(e,t,s,r){let n=Ue.intoRaw(e),o=Ue.intoRaw(s),a=OI.fromRaw(this.colliderSet,this.colliderSet.raw.coCastCollider(this.handle,n,t.handle,o,r));return n.free(),o.free(),a}intersectsShape(e,t,s){let r=Ue.intoRaw(t),n=ji.intoRaw(s),o=e.intoRaw(),a=this.colliderSet.raw.coIntersectsShape(this.handle,o,r,n);return r.free(),n.free(),o.free(),a}contactShape(e,t,s,r){let n=Ue.intoRaw(t),o=ji.intoRaw(s),a=e.intoRaw(),l=Dv.fromRaw(this.colliderSet.raw.coContactShape(this.handle,a,n,o,r));return n.free(),o.free(),a.free(),l}contactCollider(e,t){return Dv.fromRaw(this.colliderSet.raw.coContactCollider(this.handle,e.handle,t))}castRay(e,t,s){let r=Ue.intoRaw(e.origin),n=Ue.intoRaw(e.dir),o=this.colliderSet.raw.coCastRay(this.handle,r,n,t,s);return r.free(),n.free(),o}castRayAndGetNormal(e,t,s){let r=Ue.intoRaw(e.origin),n=Ue.intoRaw(e.dir),o=W_.fromRaw(this.colliderSet.raw.coCastRayAndGetNormal(this.handle,r,n,t,s));return r.free(),n.free(),o}}(function(i){i[i.Density=0]="Density",i[i.Mass=1]="Mass",i[i.MassProps=2]="MassProps"})(Yp||(Yp={}));class Ri{constructor(e){this.shape=e,this.massPropsMode=Yp.Density,this.density=1,this.friction=.5,this.restitution=0,this.rotation=ji.identity(),this.translation=Ue.zeros(),this.isSensor=!1,this.collisionGroups=4294967295,this.solverGroups=4294967295,this.frictionCombineRule=Zn.Average,this.restitutionCombineRule=Zn.Average,this.activeCollisionTypes=F_.DEFAULT,this.activeEvents=0,this.activeHooks=0,this.mass=0,this.centerOfMass=Ue.zeros(),this.contactForceEventThreshold=0,this.principalAngularInertia=Ue.zeros(),this.angularInertiaLocalFrame=ji.identity()}static ball(e){const t=new CI(e);return new Ri(t)}static capsule(e,t){const s=new XU(e,t);return new Ri(s)}static segment(e,t){const s=new YU(e,t);return new Ri(s)}static triangle(e,t,s){const r=new JU(e,t,s);return new Ri(r)}static roundTriangle(e,t,s,r){const n=new KU(e,t,s,r);return new Ri(n)}static polyline(e,t){const s=new ZU(e,t);return new Ri(s)}static trimesh(e,t){const s=new $U(e,t);return new Ri(s)}static cuboid(e,t,s){const r=new WU(e,t,s);return new Ri(r)}static roundCuboid(e,t,s,r){const n=new qU(e,t,s,r);return new Ri(n)}static heightfield(e,t,s,r){const n=new ez(e,t,s,r);return new Ri(n)}static cylinder(e,t){const s=new tz(e,t);return new Ri(s)}static roundCylinder(e,t,s){const r=new iz(e,t,s);return new Ri(r)}static cone(e,t){const s=new sz(e,t);return new Ri(s)}static roundCone(e,t,s){const r=new rz(e,t,s);return new Ri(r)}static convexHull(e){const t=new SI(e,null);return new Ri(t)}static convexMesh(e,t){const s=new SI(e,t);return new Ri(s)}static roundConvexHull(e,t){const s=new EI(e,null,t);return new Ri(s)}static roundConvexMesh(e,t,s){const r=new EI(e,t,s);return new Ri(r)}setTranslation(e,t,s){if(typeof e!="number"||typeof t!="number"||typeof s!="number")throw TypeError("The translation components must be numbers.");return this.translation={x:e,y:t,z:s},this}setRotation(e){return ji.copy(this.rotation,e),this}setSensor(e){return this.isSensor=e,this}setDensity(e){return this.massPropsMode=Yp.Density,this.density=e,this}setMass(e){return this.massPropsMode=Yp.Mass,this.mass=e,this}setMassProperties(e,t,s,r){return this.massPropsMode=Yp.MassProps,this.mass=e,Ue.copy(this.centerOfMass,t),Ue.copy(this.principalAngularInertia,s),ji.copy(this.angularInertiaLocalFrame,r),this}setRestitution(e){return this.restitution=e,this}setFriction(e){return this.friction=e,this}setFrictionCombineRule(e){return this.frictionCombineRule=e,this}setRestitutionCombineRule(e){return this.restitutionCombineRule=e,this}setCollisionGroups(e){return this.collisionGroups=e,this}setSolverGroups(e){return this.solverGroups=e,this}setActiveHooks(e){return this.activeHooks=e,this}setActiveEvents(e){return this.activeEvents=e,this}setActiveCollisionTypes(e){return this.activeCollisionTypes=e,this}setContactForceEventThreshold(e){return this.contactForceEventThreshold=e,this}}(function(i){i[i.EXCLUDE_FIXED=1]="EXCLUDE_FIXED",i[i.EXCLUDE_KINEMATIC=2]="EXCLUDE_KINEMATIC",i[i.EXCLUDE_DYNAMIC=4]="EXCLUDE_DYNAMIC",i[i.EXCLUDE_SENSORS=8]="EXCLUDE_SENSORS",i[i.EXCLUDE_SOLIDS=16]="EXCLUDE_SOLIDS",i[i.ONLY_DYNAMIC=3]="ONLY_DYNAMIC",i[i.ONLY_KINEMATIC=5]="ONLY_KINEMATIC",i[i.ONLY_FIXED=6]="ONLY_FIXED"})(xI||(xI={})),function(i){i[i.COLLISION_EVENTS=1]="COLLISION_EVENTS",i[i.CONTACT_FORCE_EVENTS=2]="CONTACT_FORCE_EVENTS"}(wI||(wI={}));class ooe{free(){this.raw.free(),this.raw=void 0}collider1(){return this.raw.collider1()}collider2(){return this.raw.collider2()}totalForce(){return Ue.fromRaw(this.raw.total_force())}totalForceMagnitude(){return this.raw.total_force_magnitude()}maxForceDirection(){return Ue.fromRaw(this.raw.max_force_direction())}maxForceMagnitude(){return this.raw.max_force_magnitude()}}class aoe{constructor(e,t){this.raw=t||new H_(e)}free(){this.raw.free(),this.raw=void 0}drainCollisionEvents(e){this.raw.drainCollisionEvents(e)}drainContactForceEvents(e){let t=new ooe;this.raw.drainContactForceEvents(s=>{t.raw=s,e(t),t.free()})}clear(){this.raw.clear()}}(function(i){i[i.FILTER_CONTACT_PAIRS=1]="FILTER_CONTACT_PAIRS",i[i.FILTER_INTERSECTION_PAIRS=2]="FILTER_INTERSECTION_PAIRS"})(HU||(HU={})),function(i){i[i.EMPTY=0]="EMPTY",i[i.COMPUTE_IMPULSE=1]="COMPUTE_IMPULSE"}(VU||(VU={}));for(var goe={byteLength:function(i){var e=nz(i),t=e[0],s=e[1];return 3*(t+s)/4-s},toByteArray:function(i){var e,t,s=nz(i),r=s[0],n=s[1],o=new loe(function(c,u,d){return 3*(u+d)/4-d}(0,r,n)),a=0,l=n>0?r-4:r;for(t=0;t<l;t+=4)e=$n[i.charCodeAt(t)]<<18|$n[i.charCodeAt(t+1)]<<12|$n[i.charCodeAt(t+2)]<<6|$n[i.charCodeAt(t+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=255&e;return n===2&&(e=$n[i.charCodeAt(t)]<<2|$n[i.charCodeAt(t+1)]>>4,o[a++]=255&e),n===1&&(e=$n[i.charCodeAt(t)]<<10|$n[i.charCodeAt(t+1)]<<4|$n[i.charCodeAt(t+2)]>>2,o[a++]=e>>8&255,o[a++]=255&e),o},fromByteArray:function(i){for(var e,t=i.length,s=t%3,r=[],n=16383,o=0,a=t-s;o<a;o+=n)r.push(hoe(i,o,o+n>a?a:o+n));return s===1?(e=i[t-1],r.push(ba[e>>2]+ba[e<<4&63]+"==")):s===2&&(e=(i[t-2]<<8)+i[t-1],r.push(ba[e>>10]+ba[e>>4&63]+ba[e<<2&63]+"=")),r.join("")}},ba=[],$n=[],loe=typeof Uint8Array<"u"?Uint8Array:Array,MI="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Jp=0,coe=MI.length;Jp<coe;++Jp)ba[Jp]=MI[Jp],$n[MI.charCodeAt(Jp)]=Jp;function nz(i){var e=i.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=i.indexOf("=");return t===-1&&(t=e),[t,t===e?0:4-t%4]}function hoe(i,e,t){for(var s,r,n=[],o=e;o<t;o+=3)s=(i[o]<<16&16711680)+(i[o+1]<<8&65280)+(255&i[o+2]),n.push(ba[(r=s)>>18&63]+ba[r>>12&63]+ba[r>>6&63]+ba[63&r]);return n.join("")}$n["-".charCodeAt(0)]=62,$n["_".charCodeAt(0)]=63;const _a=oe("debugphysics"),II=oe("debugphysicscolliders"),TI=oe("debugcollisions"),uoe=oe("showcolliders"),To=Symbol("needle component"),eo=Symbol("physics body"),doe=Symbol("rigidbody");let Kp;const N_=class{constructor(){h(this,"context"),h(this,"_initializePromise"),h(this,"_isInitialized",!1),h(this,"rapierRay",new roe({x:0,y:0,z:0},{x:0,y:0,z:1})),h(this,"raycastVectorsBuffer",new Bo(()=>new S,10)),h(this,"rapierSphere",null),h(this,"rapierColliderArray",[]),h(this,"rapierIdentityRotation",{x:0,y:0,z:0,w:1}),h(this,"rapierForwardVector",{x:0,y:0,z:1}),h(this,"enabled",!1),h(this,"_tempPosition",new S),h(this,"_tempQuaternion",new we),h(this,"_tempScale",new S),h(this,"_tempMatrix",new je),h(this,"_isUpdatingPhysicsWorld",!1),h(this,"world"),h(this,"_hasCreatedWorld",!1),h(this,"eventQueue"),h(this,"collisionHandler"),h(this,"objects",[]),h(this,"bodies",[]),h(this,"_meshCache",new Map),h(this,"_gravity",{x:0,y:-9.81,z:0}),h(this,"lines")}removeBody(i){var e,t;this.validate();const s=i[eo];if(i[eo]=null,s&&this.world){const r=this.objects.findIndex(n=>n===i);if(r>=0){const n=this.bodies[r];if(this.bodies.splice(r,1),this.objects.splice(r,1),n instanceof noe){const o=n;(e=this.world)==null||e.removeCollider(o,!0);const a=o.parent();a&&a.numColliders()<=0&&((t=this.world)==null||t.removeRigidBody(a))}}}}updateBody(i,e,t){if(this.validate(),!!this.enabled&&!(i.destroyed||!i.gameObject)&&!(!e&&!t))if(i.isCollider===!0)console.warn("TODO: implement updating collider position");else{const s=i,r=s[eo];r&&this.syncPhysicsBody(s.gameObject,r,e,t)}}updateProperties(i){this.validate();const e=i[eo];e&&this.internalUpdateProperties(i,e)}addForce(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.addForce(e,t)}addImpulse(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.applyImpulse(e,t)}getLinearVelocity(i){this.validate();const e=this.internal_getRigidbody(i);return e?e.linvel():null}getAngularVelocity(i){this.validate();const e=this.internal_getRigidbody(i);return e?e.angvel():null}resetForces(i,e){this.validate();const t=this.internal_getRigidbody(i);t?.resetForces(e)}resetTorques(i,e){this.validate();const t=this.internal_getRigidbody(i);t?.resetTorques(e)}applyImpulse(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.applyImpulse(e,t)}wakeup(i){this.validate();const e=this.internal_getRigidbody(i);e?.wakeUp()}setAngularVelocity(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.setAngvel(e,t)}setLinearVelocity(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.setLinvel(e,t)}async initialize(i){return this.context=i,this._initializePromise||(this._initializePromise=this.internalInitialization()),this._initializePromise}async internalInitialization(){return"env"in import.meta&&{}.VITE_NEEDLE_USE_RAPIER,!1}validate(){this._isInitialized||_a&&console.warn("Physics engine is not initialized")}raycast(i,e=void 0,t=1/0,s=!0){var r;const n=this.getPhysicsRay(this.rapierRay,i,e);if(!n)return null;const o=(r=this.world)==null?void 0:r.castRay(n,t,s,void 0,void 0,void 0,void 0,a=>{var l;return!((l=a[To])!=null&&l.gameObject.layers.isEnabled(2))});if(o){const a=n.pointAt(o.toi),l=this.raycastVectorsBuffer.get();return l.set(a.x,a.y,a.z),{point:l,collider:o.collider[To]}}return null}raycastAndGetNormal(i,e=void 0,t=1/0,s=!0){var r;const n=this.getPhysicsRay(this.rapierRay,i,e);if(!n)return null;const o=(r=this.world)==null?void 0:r.castRayAndGetNormal(n,t,s,void 0,void 0,void 0,void 0,a=>{var l;return!((l=a[To])!=null&&l.gameObject.layers.isEnabled(2))});if(o){const a=n.pointAt(o.toi),l=o.normal,c=this.raycastVectorsBuffer.get(),u=this.raycastVectorsBuffer.get();return c.set(a.x,a.y,a.z),u.set(l.x,l.y,l.z),{point:c,normal:u,collider:o.collider[To]}}return null}getPhysicsRay(i,e,t=void 0){var s,r;const n=(s=this.context)==null?void 0:s.mainCamera;if(e.z===void 0){if(!n)return console.error("Can not perform raycast from 2d point - no main camera found"),null;const l=this.raycastVectorsBuffer.get();l.x=e.x,l.y=e.y,l.z=0,(l.x>1||l.y>1||l.y<-1||l.x<-1)&&((r=this.context)==null||r.input.convertScreenspaceToRaycastSpace(l)),l.unproject(n),e=l}const o=e;i.origin.x=o.x,i.origin.y=o.y,i.origin.z=o.z;const a=this.raycastVectorsBuffer.get();if(t)a.set(t.x,t.y,t.z);else{if(!n)return console.error("Can not perform raycast - no camera found"),null;a.set(i.origin.x,i.origin.y,i.origin.z);const l=xt(n);a.sub(l)}return a.normalize(),i.dir.x=a.x,i.dir.y=a.y,i.dir.z=a.z,i}sphereOverlap(i,e){return this.rapierColliderArray.length=0,this.world?(this.rapierSphere||(this.rapierSphere=new CI(e)),this.rapierSphere.radius=e,this.world.intersectionsWithShape(i,this.rapierIdentityRotation,this.rapierSphere,t=>{const s=t[To],r=new LU(s.gameObject,s);return this.rapierColliderArray.push(r),!0},xI.EXCLUDE_SENSORS,void 0,void 0,void 0,t=>t[To].gameObject.layers.isEnabled(2)==!1),this.rapierColliderArray):this.rapierColliderArray}get isUpdating(){return this._isUpdatingPhysicsWorld}get gravity(){var i;return((i=this.world)==null?void 0:i.gravity)??this._gravity}set gravity(i){this.world?this.world.gravity=i:this._gravity=i}clearCaches(){this._meshCache.clear()}async addBoxCollider(i,e,t){if(this._isInitialized||await this.initialize(i.context),!i.activeAndEnabled)return;if(!this.enabled){_a&&console.warn("Physics are disabled");return}const s=i.gameObject,r=Us(s,this._tempPosition).multiply(t);r.multiplyScalar(.5),r.x<0&&(r.x=Math.abs(r.x)),r.y<0&&(r.y=Math.abs(r.y)),r.z<0&&(r.z=Math.abs(r.z)),r.x==0&&(r.x=1e-7),r.y==0&&(r.y=1e-7),r.z==0&&(r.z=1e-7);const n=Ri.cuboid(r.x,r.y,r.z);this.createCollider(i,n,e)}async addSphereCollider(i,e,t){if(this._isInitialized||await this.initialize(i.context),!i.activeAndEnabled)return;if(!this.enabled){_a&&console.warn("Physics are disabled");return}const s=i.gameObject,r=Us(s,this._tempPosition).multiplyScalar(t);r.x=Math.abs(r.x);const n=Ri.ball(r.x);this.createCollider(i,n,e)}async addCapsuleCollider(i,e,t,s){if(this._isInitialized||await this.initialize(i.context),!i.activeAndEnabled)return;if(!this.enabled){_a&&console.warn("Physics are disabled");return}const r=i.gameObject,n=Us(r,this._tempPosition);n.x=Math.abs(n.x),n.y=Math.abs(n.y);const o=Ri.capsule(t*.5*n.y-s,s*n.x);this.createCollider(i,o,e)}async addMeshCollider(i,e,t,s){var r;if(this._isInitialized||await this.initialize(i.context),!i.activeAndEnabled)return;if(!this.enabled){_a&&console.warn("Physics are disabled");return}const n=e.geometry;if(!n){_a&&console.warn("Missing mesh geometry",e.name);return}let o=n.getAttribute("position").array;const a=(r=n.index)==null?void 0:r.array;if(Math.abs(s.x-1)>1e-4||Math.abs(s.y-1)>1e-4||Math.abs(s.z-1)>1e-4){const c=n.uuid+"_"+s.x+"_"+s.y+"_"+s.z+"_"+t;if(this._meshCache.has(c))o=this._meshCache.get(c);else{console.warn("Your model is using scaled mesh colliders which is not optimal for performance",e.name,Object.assign({},s),e);const u=new Float32Array(o.length);for(let d=0;d<o.length;d+=3)u[d]=o[d]*s.x,u[d+1]=o[d+1]*s.y,u[d+2]=o[d+2]*s.z;o=u,this._meshCache.set(c,u)}}const l=t?Ri.convexMesh(o):Ri.trimesh(o,a);l&&this.createCollider(i,l).setMassProperties(1,{x:0,y:0,z:0},{x:0,y:0,z:0},{x:0,y:0,z:0,w:1})}createCollider(i,e,t){if(!this.world)throw new Error("Physics world not initialized");const s=this._tempMatrix,{rigidBody:r,useExplicitMassProperties:n}=this.getRigidbody(i,this._tempMatrix);s.decompose(this._tempPosition,this._tempQuaternion,this._tempScale),Us(i.gameObject,this._tempScale),t&&(t.multiply(this._tempScale),this._tempPosition.x-=t.x,this._tempPosition.y+=t.y,this._tempPosition.z+=t.z),e.setTranslation(this._tempPosition.x,this._tempPosition.y,this._tempPosition.z),e.setRotation(this._tempQuaternion),e.setSensor(i.isTrigger);const o=i.sharedMaterial;if(o){switch(e.setRestitution(o.bounciness),o.bounceCombine){case ea.Average:e.setRestitutionCombineRule(Zn.Average);break;case ea.Maximum:e.setRestitutionCombineRule(Zn.Max);break;case ea.Minimum:e.setRestitutionCombineRule(Zn.Min);break;case ea.Multiply:e.setRestitutionCombineRule(Zn.Multiply);break}switch(e.setFriction(o.dynamicFriction),o.frictionCombine){case ea.Average:e.setFrictionCombineRule(Zn.Average);break;case ea.Maximum:e.setFrictionCombineRule(Zn.Max);break;case ea.Minimum:e.setFrictionCombineRule(Zn.Min);break;case ea.Multiply:e.setFrictionCombineRule(Zn.Multiply);break}}const a=this.world.createCollider(e,r);return a[To]=i,i[eo]=a,a.setActiveEvents(wI.COLLISION_EVENTS),a.setActiveCollisionTypes(F_.ALL),this.objects.push(i),this.bodies.push(a),a}getRigidbody(i,e){if(!this.world)throw new Error("Physics world not initialized");let t=null,s=!1;if(i.attachedRigidbody){const r=i.attachedRigidbody;if(t=r[eo],s=!0,!t){const n=r.isKinematic&&!II;_a&&console.log("Create rigidbody",n);const o=n?Kp.RigidBodyDesc.kinematicPositionBased():Kp.RigidBodyDesc.dynamic(),a=xt(i.attachedRigidbody.gameObject);o.setTranslation(a.x,a.y,a.z),o.setRotation(xs(i.attachedRigidbody.gameObject)),t=this.world.createRigidBody(o),this.bodies.push(t),this.objects.push(r)}t[To]=r,r[eo]=t,this.internalUpdateProperties(r,t),this.getRigidbodyRelativeMatrix(i.gameObject,r.gameObject,e)}else{const r=Kp.RigidBodyDesc.kinematicPositionBased(),n=xt(i.gameObject);r.setTranslation(n.x,n.y,n.z),r.setRotation(xs(i.gameObject)),t=this.world.createRigidBody(r),e.identity(),t[To]=null}return i[doe]=t,{rigidBody:t,useExplicitMassProperties:s}}internal_getRigidbody(i){return i[eo]}internalUpdateProperties(i,e){e.enableCcd(i.collisionDetectionMode!==Ky.Discrete),e.setLinearDamping(i.drag),e.setAngularDamping(i.angularDrag),e.setGravityScale(i.useGravity?i.gravityScale:0,!0),e.setEnabledRotations(!i.lockRotationX,!i.lockRotationY,!i.lockRotationZ,!0),e.setEnabledTranslations(!i.lockPositionX,!i.lockPositionY,!i.lockPositionZ,!0),i.isKinematic?e.setBodyType(Kp.RigidBodyType.KinematicPositionBased):e.setBodyType(Kp.RigidBodyType.Dynamic)}step(i){this.world&&this.enabled&&(this._isUpdatingPhysicsWorld=!0,this.eventQueue||(this.eventQueue=new aoe(!1)),i&&(this.world.timestep=Je.lerp(this.world.timestep,i,.8)),this.world.step(this.eventQueue),this._isUpdatingPhysicsWorld=!1,this.updateDebugRendering(this.world))}updateDebugRendering(i){var e;if(_a||II||uoe){if(!this.lines){const s=new Vi({color:2258688}),r=new At;this.lines=new on(r,s),(e=this.context)==null||e.scene.add(this.lines)}const t=i.debugRender();this.lines.geometry.setAttribute("position",new rt(t.vertices,3)),this.lines.geometry.setAttribute("color",new rt(t.colors,4))}}postStep(){this.world&&this.enabled&&(this._isUpdatingPhysicsWorld=!0,this.syncObjects(),this._isUpdatingPhysicsWorld=!1,this.eventQueue&&!this.collisionHandler&&(this.collisionHandler=new poe(this.world,this.eventQueue)),this.collisionHandler&&(this.collisionHandler.handleCollisionEvents(),this.collisionHandler.update()))}syncObjects(){if(!II)for(let i=0;i<this.bodies.length;i++){const e=this.objects[i],t=this.bodies[i],s=e;if(s?.isCollider===!0&&!s.attachedRigidbody){const a=t.parent();a&&this.syncPhysicsBody(e.gameObject,a,!0,!0);continue}const r=t.translation(),n=t.rotation(),o=e.center;if(o&&o.isVector3){this._tempQuaternion.set(n.x,n.y,n.z,n.w);const a=this._tempPosition.copy(o).applyQuaternion(this._tempQuaternion),l=Us(e.gameObject);a.multiply(l),r.x-=a.x,r.y-=a.y,r.z-=a.z}Ad(e.gameObject,r.x,r.y,r.z),bB(e.gameObject,n.x,n.y,n.z,n.w)}}syncPhysicsBody(i,e,t,s){const r=xt(i,this._tempPosition),n=xs(i,this._tempQuaternion);switch(e.bodyType()){case xv.Fixed:case xv.KinematicPositionBased:case xv.KinematicVelocityBased:t&&e.setNextKinematicTranslation(r),s&&e.setNextKinematicRotation(n);break;default:t&&e.setTranslation(r,!1),s&&e.setRotation(n,!1);break}e.wakeUp()}getRigidbodyRelativeMatrix(i,e,t,s){if(s===void 0&&(s=N_._matricesBuffer,s.length=0),i===e){const r=Us(i,this._tempPosition);t.makeScale(r.x,r.y,r.z);for(let n=s.length-1;n>=0;n--)t.multiply(s[n]);return t}return s.push(i.matrix),i.parent&&this.getRigidbodyRelativeMatrix(i.parent,e,t,s),t}addFixedJoint(i,e){if(!this.world){console.error("Physics world not initialized");return}const t=i[eo],s=e[eo];this.calculateJointRelativeMatrices(i.gameObject,e.gameObject,this._tempMatrix),this._tempMatrix.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);const r=of.fixed(N_.centerConnectionPos,N_.centerConnectionRot,this._tempPosition,this._tempQuaternion),n=this.world.createImpulseJoint(r,t,s,!0);_a&&console.log("ADD FIXED JOINT",n)}addHingeJoint(i,e,t,s){if(!this.world){console.error("Physics world not initialized");return}const r=i[eo],n=e[eo];this.calculateJointRelativeMatrices(i.gameObject,e.gameObject,this._tempMatrix),this._tempMatrix.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);let o=Kp.JointData.revolute(t,this._tempPosition,s),a=this.world.createImpulseJoint(o,r,n,!0);_a&&console.log("ADD HINGE JOINT",a)}calculateJointRelativeMatrices(i,e,t){i.updateWorldMatrix(!0,!1),e.updateWorldMatrix(!0,!1);const s=i.matrixWorld,r=e.matrixWorld;s.elements[0]=1,s.elements[5]=1,s.elements[10]=1,r.elements[0]=1,r.elements[5]=1,r.elements[10]=1,t.copy(r).premultiply(s.invert()).invert()}};let wv=N_;h(wv,"_didLoadPhysicsEngine",!1),h(wv,"_matricesBuffer",[]),h(wv,"centerConnectionPos",{x:0,y:0,z:0}),h(wv,"centerConnectionRot",{x:0,y:0,z:0,w:1});class poe{constructor(e,t){h(this,"world"),h(this,"eventQueue"),h(this,"activeCollisions",[]),h(this,"activeCollisionsStay",[]),h(this,"activeTriggers",[]),this.world=e,this.eventQueue=t}handleCollisionEvents(){this.eventQueue&&this.world&&this.eventQueue.drainCollisionEvents((e,t,s)=>{const r=this.world.getCollider(e),n=this.world.getCollider(t),o=r[To],a=n[To];TI&&console.log("EVT",o.name,a.name,s,r,n),o&&a&&(s?(this.onCollisionStarted(o,r,a,n),this.onCollisionStarted(a,n,o,r)):(this.onCollisionEnded(o,a),this.onCollisionEnded(a,o)))})}update(){this.onHandleCollisionStay()}onCollisionStarted(e,t,s,r){let n=null;if(e.isTrigger||s.isTrigger)zh(e.gameObject,o=>{o.onTriggerEnter&&!o.destroyed&&o.onTriggerEnter(s),this.activeTriggers.push({collider:e,component:o,otherCollider:s})});else{const o=e.gameObject;this.world.contactPair(t,r,(a,l)=>{zh(o,c=>{var u;if(c.destroyed)return;const d=c.onCollisionEnter||c.onCollisionStay||c.onCollisionExit;if(d||TI){if(!n){const p=[],f=a.normal();for(let g=0;g<a.numSolverContacts();g++){const m=a.solverContactPoint(g),v=a.contactImpulse(g);if(m){const A=a.contactDist(g),b=a.solverContactFriction(g),y=new DU(m,A,f,v,b);p.push(y),TI&&Yo.DrawDirection(m,f,16711680,3,!0)}}n=new OU(o,s,p)}if(d){const p={collider:e,component:c,collision:n};this.activeCollisions.push(p),c.onCollisionStay&&this.activeCollisionsStay.push(p),(u=c.onCollisionEnter)==null||u.call(c,n)}}})})}}onHandleCollisionStay(){for(const e of this.activeCollisionsStay){const t=e.component;if(!t.destroyed&&t.activeAndEnabled&&t.onCollisionStay){const s=e.collision;t.onCollisionStay(s)}}for(const e of this.activeTriggers){const t=e.component;if(!t.destroyed&&t.activeAndEnabled&&t.onTriggerStay){const s=e.otherCollider;t.onTriggerStay(s)}}}onCollisionEnded(e,t){if(!(e.destroyed||t.destroyed)){for(let s=0;s<this.activeCollisions.length;s++){const r=this.activeCollisions[s],n=r.collider;if(n.destroyed){this.activeCollisions.splice(s,1),s--;continue}if(n===e&&r.collision.collider===t){const o=r.component;if(this.activeCollisions.splice(s,1),s--,o.activeAndEnabled&&o.onCollisionExit){const a=r.collision;o.onCollisionExit(a)}}}for(let s=0;s<this.activeCollisionsStay.length;s++){const r=this.activeCollisionsStay[s],n=r.collider;if(n.destroyed){this.activeCollisionsStay.splice(s,1),s--;continue}if(n===e&&r.collision.collider===t){const o=r.component;if(this.activeCollisionsStay.splice(s,1),s--,o.activeAndEnabled&&o.onCollisionExit){const a=r.collision;o.onCollisionExit(a)}}}for(let s=0;s<this.activeTriggers.length;s++){const r=this.activeTriggers[s],n=r.collider;if(n.destroyed){this.activeTriggers.splice(s,1),s--;continue}if(n===e&&r.otherCollider===t){const o=r.component;if(this.activeTriggers.splice(s,1),s--,o.activeAndEnabled&&o.onTriggerExit){const a=r.otherCollider;o.onTriggerExit(a)}}}}}}Object.defineProperty(Xt.prototype,"fov",{get:function(){return this._fov},set:function(i){const e=i!==this._fov;this._fov=i,e&&this.view!==void 0&&this.updateProjectionMatrix()}}),Object.defineProperty(Xt.prototype,"near",{get:function(){return this._near},set:function(i){const e=i!==this._near;this._near=i,e&&this.view!==void 0&&this.updateProjectionMatrix()}}),Object.defineProperty(Xt.prototype,"far",{get:function(){return this._far},set:function(i){const e=i!==this._far;this._far=i,e&&this.view!==void 0&&this.updateProjectionMatrix()}});function foe(i,e,t,s="image/webp",r){if(!r&&(r=i.mainCamera,!r))return console.error("No camera found"),null;const n=i.renderer.domElement.width,o=i.renderer.domElement.height;try{const a=i.renderer.domElement;return i.renderer.setSize(e,t),r instanceof Xt&&i.updateAspect(r,e,t),i.renderNow(),a.toDataURL(s)}finally{i.renderer.setSize(n,o),i.updateSize()}return null}Cz();const U_={Context:_t};globalThis.Needle!==void 0&&console.warn("Needle Engine is already imported"),globalThis.Needle=U_;function oz(i){for(const e in i)U_[e]=i[e]}oz(zq),oz(Pne),U_.$meta={version:ox,generator:$I};for(const i of Object.getOwnPropertyNames($))switch(i){case"prototype":case"constructor":case"length":case"name":continue;default:U_[i]=$[i];break}globalThis.THREE?console.warn("Threejs is already imported"):globalThis.THREE=e6;export{$ne as $physicsKey,ni as ActionBuilder,kS as ActionCollection,xo as ActionModel,xD as Addressables,Hg as AlignmentConstraint,Id as AmbientMode,yo as Animation,Jh as AnimationCurve,Hy as AnimationExtension,Mb as AnimationTrackHandler,jr as Animator,vc as AnimatorConditionMode,Ru as AnimatorController,zC as AnimatorControllerParameterType,my as AnimatorStateInfo,wm as Antialiasing,ED as Application,fy as ApplicationEvents,C2 as AssetDatabase,lr as AssetReference,ra as AttachedObject,Ab as AttachedObjectEvents,Tb as AudioExtension,gp as AudioListener,os as AudioSource,bm as AudioTrackHandler,ru as AvatarBlink_Simple,Ap as AvatarEyeLook_Rotation,Yy as AvatarLoader,hr as AvatarMarker,Xy as AvatarModel,Yg as Avatar_Brain_LookAt,Cm as Avatar_MouthShapes,NE as Avatar_MustacheShake,Rr as Avatar_POI,sp as Axes,yp as AxesHelper,Ro as BaseUIComponent,QE as BasicIKConstraint,Pb as BehaviorExtension,Ir as BehaviorModel,Ee as Behaviour,nu as Bloom,Em as BoxCollider,eu as BoxGizmo,Jo as BoxHelperComponent,xl as Button,qh as CallInfo,Ei as Camera,dr as Canvas,Cp as CanvasGroup,zc as CapsuleCollider,Rm as ChangeMaterialOnClick,cu as ChangeTransformOnClick,hu as CharacterController,Cl as CharacterControllerInput,km as ChromaticAberration,Bo as CircularBuffer,zF as ClearFlags,Uc as ClipExtrapolation,oa as Collider,OU as Collision,Ky as CollisionDetectionMode,Hc as ColorAdjustments,uu as ColorBySpeedModule,Om as ColorOverLifetimeModule,fc as Component,lg as ComponentEvents,cg as ComponentLifecycleEvents,e2 as ConnectionEvents,DU as ContactPoint,_t as Context,Fq as ContextArgs,$r as ContextEvent,ts as ContextRegistry,Ib as ControlTrackHandler,vl as ControllerEvents,hp as ControllerType,Yc as CustomBranding,bo as CustomShader,py as DefaultReflectionMode,lM as Deletable,Xb as DeleteBox,Io as DepthOfField,Yb as DeviceFlag,cM as DocumentExtension,Pp as DragControls,Fm as DropListener,fu as Duplicatable,By as EXTENSION_NAME,ha as EmissionModule,Mp as EmphasizeOnClick,EC as EngineLoadingView,Gr as EventList,Dy as EventListEvent,Hn as EventSystem,Zb as EventTrigger,CS as FieldWithDefault,sN as FileSpawnModel,iN as File_Event,yM as FixedJoint,bM as FlyControls,kp as Fog,cn as FrameEvent,$ as GameObject,Yo as Gizmos,Ol as GltfExport,MM as GltfExportBox,Iu as GltfLoadEvent,wU as GltfLoadEventType,Vc as Gradient,au as Graphic,PE as GraphicRaycaster,uo as Graphics,Op as GridHelper,$E as GridLayoutGroup,gu as GroundProjectedEnv,Mc as GroupActionModel,T2 as HideFlags,sM as HideOnStart,Nm as HingeJoint,ZE as HorizontalLayoutGroup,Q8 as HostData,xp as Image,dy as ImageReference,wD as ImageReferenceSerializer,qc as InheritVelocityModule,AB as Input,Uo as InputEvents,vu as InputField,Kr as InstancingUtil,n2 as InstantiateEvent,Lr as InstantiateIdProvider,Qo as InstantiateOptions,tp as Interactable,I8 as JoinedRoomResponse,b0 as KeyEventArgs,Qm as LODGroup,Au as LODModel,T8 as LeftRoomResponse,Yr as Light,SD as LightData,us as LimitVelocityOverLifetimeModule,Jq as LoadingElementOptions,RM as LogStats,ko as LogType,yu as LookAt,Wg as LookAtConstraint,Ws as MainModule,OE as MarkerType,Tm as MaskableGraphic,Je as Mathf,Mm as MeshCollider,Fy as MeshRenderer,tt as MinMaxCurve,Xr as MinMaxGradient,$I as NEEDLE_ENGINE_GENERATOR,ox as NEEDLE_ENGINE_VERSION,al as NEEDLE_progressive,yI as NeedleEngineHTMLElement,vI as NeedleGltfLoader,Z0 as NeedlePatchesKey,s_ as NestedGltf,i2 as NetworkConnection,pu as Networking,hi as NoiseModule,iu as ObjectRaycaster,bu as OffsetConstraint,Np as OpenURL,Nc as OrbitControls,_p as Outline,t2 as OwnershipEvent,V0 as OwnershipModel,jc as Padding,Dm as ParticleBurst,d_ as ParticleSubEmitter,$i as ParticleSystem,El as ParticleSystemRenderer,PB as Physics,ea as PhysicsMaterialCombine,Ym as PixelationEffect,Gc as PlayAnimationOnClick,Ip as PlayAudioOnClick,vm as PlayableDirector,Pu as PlayerColor,qp as PlayerState,_U as PlayerStateEvent,pI as PlayerSync,TD as PlayerView,RD as PlayerViewManager,tu as PointerEventData,vB as PointerType,Br as PostProcessingEffect,f_ as PostProcessingHandler,Rp as PreliminaryAction,Pm as PreliminaryTrigger,rL as ProgressiveLoadingInfo,vi as RGBAColor,wv as RapierPhysics,Fb as RawImage,po as RaycastOptions,fp as Raycaster,XE as Rect,ur as RectTransform,Xd as ReflectionProbe,Qy as RegisteredAnimationInfo,_u as RemoteSkybox,qd as RenderTexture,cL as RenderTextureSerializer,Ui as Renderer,CD as RendererData,Qg as RendererLightmap,Di as Rigidbody,Ji as RigidbodyConstraints,Fi as RoomEvents,fn as RotationBySpeedModule,Wn as RotationOverLifetimeModule,Py as SceneLightSettings,mn as SceneSwitcher,$m as ScreenCapture,Il as ScreenSpaceAmbientOcclusion,Ur as SendQueue,Ep as SetActiveOnClick,iv as ShadowCatcher,Ki as ShapeModule,gm as SignalAsset,vp as SignalReceiver,mp as SignalReceiverEvent,_m as SignalTrackHandler,qE as Size,kr as SizeBySpeedModule,Wc as SizeOverLifetimeModule,SS as SkinnedMeshRenderer,Zc as SmoothFollow,XM as SpatialHtml,nv as SpatialTrigger,ma as SpatialTriggerReceiver,b_ as SpectatorCamera,Sm as SphereCollider,RB as SphereIntersection,LU as SphereOverlapResult,Tl as Sprite,Hp as SpriteData,xu as SpriteRenderer,ov as SpriteSheet,h7 as StateMachineBehaviour,Xm as SubEmitterSystem,x_ as SyncedCamera,$c as SyncedRoom,Oc as SyncedTransform,nM as TapGestureTrigger,vb as TeleportTarget,rI as TestRunner,nI as TestSimulateUserData,Dr as Text,Wb as TextBuilder,qb as TextExtension,qs as TextureSheetAnimationModule,va as TiltShiftEffect,kB as Time,lv as ToneMapping,Am as TrackHandler,un as TrackType,Ii as TrailModule,Gy as TransformData,Su as TransformGizmo,Hr as TriggerBuilder,Yh as TriggerModel,Q as TypeStore,cp as UIRaycastUtils,om as UIRootComponent,Ko as USDObject,Xn as USDZExporter,Xc as USDZText,gC as Upload_Result,hL as UriSerializer,ip as UsageMarker,R8 as UserJoinedOrLeftRoomModel,Al as VRUserState,BS as VariantAction,Oi as VelocityOverLifetimeModule,KE as VerticalLayoutGroup,Js as VideoPlayer,Ho as ViewDevice,Eu as Vignette,Bm as VisibilityAction,kl as Voip,I_ as Volume,Dt as VolumeParameter,xm as VolumeProfile,Xse as WaitForFrames,$N as WaitForSeconds,$p as Watch,um as WebAR,R_ as WebARCameraBackground,Pc as WebARSessionRoot,wt as WebXR,kc as WebXRAvatar,cs as WebXRController,_i as WebXREvent,B_ as WebXRImageTracking,Rl as WebXRImageTrackingModel,k_ as WebXRPlaneTracking,cm as WebXRSync,Mu as WebXRTrackedImage,Tr as XRFlag,D_ as XRGrabModel,uI as XRGrabRendering,yb as XRRig,Sg as XRSessionMode,Zo as XRState,as as XRStateFlag,dI as __Ignore,M2 as __internalNotifyObjectDestroyed,Pa as activeInHierarchyFieldName,xX as addCustomExtension,uM as addFile,rN as addFileFromUrl,jne as addGltfLoadEventListener,lc as addNewComponent,Z8 as addPatch,J0 as apply,Zne as applyChanges,l2 as beginListenDestroy,nN as beginListenFileSpawn,c2 as beginListenInstantiate,Lq as build_scene_functions,oh as builtinComponentKeyName,CC as calculateProgress01,MX as colorSerializer,Oy as componentSerializer,IB as copyTexture,AI as createGLTFLoader,ZD as createMotion,xr as debugNet,ag as debugOwner,jv as deepClone,uf as delay,y0 as deserializeObject,cc as destroy,m2 as destroyComponentInstance,FF as detectARSupport,NF as detectVRSupport,go as disposeObjectResources,yD as download,vC as download_file,pf as editorGuidKeyName,QM as effectsOrder,BX as eventListSerializer,MU as findAnimations,Gne as findAnimationsLate,vg as findByGuid,y2 as findObjectOfType,b2 as findObjectsOfType,Z1 as findUsers,zh as foreachComponent,eC as foreachComponentEnumerator,T6 as forward,X0 as generateSeed,xd as getComponent,wd as getComponentInChildren,dg as getComponentInParent,hg as getComponents,ug as getComponentsInChildren,Y0 as getComponentsInParent,_z as getIp,xz as getIpAndLocation,bz as getIpCloudflare,vo as getLoader,J1 as getOrAddComponent,oe as getParam,gz as getPath,cf as getUrlParams,nW as getUserCount,P6 as getWorldDirection,SB as getWorldEuler,xt as getWorldPosition,xs as getWorldQuaternion,E1 as getWorldRotation,Us as getWorldScale,gc as hasProLicense,mC as hash,Ag as instantiate,R2 as isActiveInHierarchy,Cd as isActiveSelf,MB as isAnimationAction,dz as isDebugMode,$1 as isDestroyed,Rn as isDevEnvironment,WI as isHostedOnGlitch,Xne as isHotReloading,gr as isLocalNetwork,nh as isMobileDevice,tx as isMozillaXR,Az as isQuest,Ta as isSafari,E2 as isUsageTrackingEnabled,ty as isUsingInstancing,df as isiOS,EU as loadSync,w0 as logHierarchy,S6 as lookAtInverse,fz as makeId,GI as makeIdFromRandomWords,P2 as markAsInstancedRendered,K1 as moveComponentInstance,uz as nameof,zv as nameofFactory,lL as objectSerializer,SU as parseSync,tJ as prefix,UI as pushState,zI as randomNumber,Yne as register,gy as registerComponent,xS as registerComponentExtension,oL as registerExtensions,AC as registerLoader,u2 as registerPrefabProvider,VI as relativePathPrefix,Y1 as removeComponent,wX as removeCustomExtension,Qne as removeGltfLoadEventListener,$8 as removePatch,Ll as resolveUrl,HI as sanitizeString,foe as screenshot,a2 as sendDestroyed,x as serializable,fB as serializeObject,Rd as serializeable,mg as setActive,k2 as setDestroyed,hf as setOrAddParamsToUrl,pz as setParam,NI as setParamWithoutReload,ex as setState,sW as setUsageTrackingEnabled,EB as setWorldEuler,rs as setWorldPosition,Ad as setWorldPositionXYZ,Fr as setWorldQuaternion,bB as setWorldQuaternionXYZW,k6 as setWorldRotation,x0 as setWorldRotationXYZ,S1 as setWorldScale,Ns as showBalloonMessage,ho as showBalloonWarning,m1 as showDebugConsole,yB as slerp,q0 as syncDestroy,VM as syncField,q1 as syncInstantiate,D6 as textureToCanvas,Bu as tryFindObject,IU as tryFindObjectByName,Hne as tryFindScript,Jne as unregister,AD as upload_file,ta as validate};
5057
+ <a href="https://engine.needle.tools/docs/project_structure.html#creating-and-installing-a-npmdef" target="_blank">documentation</a>`,ko.Warn)}}if(e.children)for(const n of e.children)await mI(i,n,t)}function Une(i,e){const{instance:t,compData:s,obj:r}=i;e.object=r,e.target=t,y0(t,s,e),xU&&console.debug("add "+s.name,s,t)}class vI{createBuiltinComponents(e,t,s,r,n){return Nne(e,t,s,r,n)}writeBuiltinComponentData(e,t){return Lne(e,t)}parseSync(e,t,s,r){return SU(e,t,s,r)}loadSync(e,t,s,r,n){return EU(e,t,s,r,n)}}AC(vI);const zne=oe("printGltf");var wU=(i=>(i[i.BeforeLoad=0]="BeforeLoad",i[i.AfterLoaded=1]="AfterLoaded",i[i.FinishedSetup=10]="FinishedSetup",i))(wU||{});class Iu{constructor(e,t,s,r){h(this,"context"),h(this,"loader"),h(this,"path"),h(this,"gltf"),this.context=e,this.path=t,this.loader=s,this.gltf=r}}const th={};function jne(i,e){th[i]=th[i]||[],th[i].push(e)}function Qne(i,e){if(th[i]){const t=th[i].indexOf(e);t>=0&&th[i].splice(t,1)}}function Xp(i,e){if(th[i])for(const t of th[i])t(e)}async function CU(i,e,t,s,r){zne&&console.warn("glTF",e,t),await vo().createBuiltinComponents(i,e,t,s,r)}function AI(i,e){const t=new Pd;return oL(t,e,i),t}function SU(i,e,t,s){typeof t!="string"&&console.warn("Parse gltf binary without path, this might lead to errors in resolving extensions. Please provide the source path of the gltf/glb file",t,typeof t);const r=AI(t,i),n=xS(r);return new Promise((o,a)=>{try{Tg(r,i),Xp(0,new Iu(i,t,r)),r.parse(e,t,async l=>{Xp(1,new Iu(i,t,r,l)),await CU(i,t,l,s,n),Xp(10,new Iu(i,t,r,l)),j2(l.scene,i),o(l)},l=>{console.error("failed loading "+t,l),o(void 0)})}catch(l){console.error(l),a(l)}})}function EU(i,e,t,s,r){const n=AI(e,i),o=xS(n);return new Promise((a,l)=>{try{Tg(n,i),Xp(0,new Iu(i,e,n)),n.load(e,async c=>{Xp(1,new Iu(i,e,n,c)),await CU(i,t,c,s,o),Xp(10,new Iu(i,e,n,c)),j2(c.scene,i),a(c)},c=>{r?.call(n,c)},c=>{console.error("failed loading "+e,c),a(void 0)})}catch(c){console.error(c),l(c)}})}function Gne(i,e,t,s=!1){e&&e.animations&&e.animations.length>0&&t.push(()=>{MU(e,s)})}function MU(i,e=!1){if(!i||!i.animations||!i.scene||!e&&!wd(i.scene,yo))return;for(let s=0;s<i.animations.length;s++){const r=i.animations[s];if(!(!r.tracks||r.tracks.length<=0))for(const n in r.tracks){const o=r.tracks[n],a=o.__objectName??o.name.substring(0,o.name.indexOf(".")),l=i.scene.getObjectByName(a);if(!l)continue;let c=t(l);if(!c)if(e)c=lc(i.scene,new yo);else{console.warn("Failed finding animator for",o.name,a);continue}const u=c.animations=c.animations||[];r.name_animator=c.name,u.indexOf(r)<0&&u.push(r)}}function t(s){var r;if(!s)return;const n=(r=s.userData)==null?void 0:r.components;if(n&&n.length>0)for(let o=0;o<n.length;o++){const a=n[o];if(a instanceof jr||a instanceof yo)return s}return t(s.parent)}}function IU(i,e,t=!0){if(e.userData&&e.userData.name===i)return e;if(e.children&&e.children.length>0)for(let s=0;s<e.children.length;s++){const r=e.children[s],n=IU(i,r,t);if(n)return n}}function Hne(i,e=null){const t=e??_t.Current.scripts;for(const s in t){const r=t[s];if(r&&r.guid===i)return r}return null}AC(vI);const Kn=oe("debugwebcomponent"),TU="needle-engine",RU="vr",PU="desktop",Vne=[Qh,RU,PU],mv="ar-session-active",vv="desktop-session-active",Wne=["hash","src","camera-controls","loadstart","progress","loadfinished","dracoDecoderPath","dracoDecoderType","ktx2DecoderPath"];class yI extends HTMLElement{constructor(){super(),h(this,"gameObject",$),h(this,"GameObject",$),h(this,"_context"),h(this,"_overlay_ar"),h(this,"_loadingProgress01",0),h(this,"_loadingView"),h(this,"_previousSrc",null),h(this,"_isCurrentlySettingsSourceAttribute",!1),h(this,"onReady",()=>{var e;return(e=this._loadingView)==null?void 0:e.onLoadingFinished()}),this._overlay_ar=new Uq,this._context=new _t({domElement:this}),this.addEventListener("ready",this.onReady)}static get observedAttributes(){return Wne}get loadingProgress01(){return this._loadingProgress01}get loadingFinished(){return this.loadingProgress01>.999}get cameraControls(){const e=this.getAttribute("camera-controls");return!(e===null||e==="False"||e==="false"||e==="0")}getContext(){return new Promise((e,t)=>{if(this._context&&this.loadingFinished)e(this._context);else{const s=()=>{this.removeEventListener("loadfinished",s),this._context&&this.loadingFinished&&e(this._context)};this.addEventListener("loadfinished",s)}})}get context(){return this._context}get Context(){return this._context}async connectedCallback(){Kn&&(console.log("<needle-engine> connected"),console.dir(this)),this.onSetupDesktop();const e=this.getAttribute("src")??globalThis["needle:codegen_files"];e&&e.length>0&&await this.onLoad(e,!0),this.onSetupDesktop()}disconnectedCallback(){var e;(e=this._context)==null||e.onDestroy()}attributeChangedCallback(e,t,s){switch(e){case"src":Kn&&console.log("src changed to type:",typeof s,', from "',t,'" to "',s),this.onLoad(s,!1);break;case"hash":this._context&&(this._context.hash=s);break;case"loadstart":case"progress":case"loadfinished":typeof s=="string"&&s.length>0&&(Kn&&console.log(e+" attribute changed",s),this.registerEventFromAttribute(e,s));break;case"dracoDecoderPath":Kn&&console.log("dracoDecoderPath",s),YD(s);break;case"dracoDecoderType":s==="wasm"||s==="js"?(Kn&&console.log("dracoDecoderType",s),JD(s)):console.error("Invalid dracoDecoderType",s,"expected js or wasm");break;case"ktx2DecoderPath":Kn&&console.log("ktx2DecoderPath",s),KD(s);break}}async onLoad(e,t){var s,r;if(this._isCurrentlySettingsSourceAttribute||e===this._previousSrc)return;if(!e||!e.length){console.error("Needle Engine: No source specified",e);return}if(!this._context){console.error("Needle Engine: Context not initialized");return}this._previousSrc=e,this._isCurrentlySettingsSourceAttribute=!0,this.setAttribute("src",e?.toString()),this._isCurrentlySettingsSourceAttribute=!1;const n=this.getAttribute("alias");this.classList.add("loading"),Kn&&console.log("Needle Engine: Begin loading",n??"");const o=!0,a=this.dispatchEvent(new CustomEvent("loadstart",{detail:{context:this._context,alias:n},cancelable:o}));!this._loadingView&&a&&(this._loadingView=new EC(this)),a&&((s=this._loadingView)==null||s.onLoadingBegin("begin load")),this.onBeforeBeginLoading(),Kn&&console.log(e);let l;Array.isArray(e)?l=e:e.startsWith("[")&&e.endsWith("]")?l=JSON.parse(e):e.includes(",")?l=e.split(","):l=[e];let c=null;if(l?.length>0&&(c=async d=>{let p=0;d.hash&&(p=Number.parseInt(d.hash)??0);const f=vo();for(let g=0;g<l.length;g++){const m=l[g];if(!m.includes(".glb")&&!m.includes(".gltf")){const w=`Needle Engine: found suspicious src "${m}"`;console.warn(w),gr()&&ho(w)}const v=qne(m),A={name:v,progress:null,index:g,count:l.length},b={detail:{context:d,name:v,progress:A.progress,index:g,count:l.length,totalProgress01:this._loadingProgress01}},y=await f.loadSync(d,m,m,p,w=>{var E;A.progress=w,this._loadingProgress01=CC(A),a&&((E=this._loadingView)==null||E.onLoadingUpdate(A)),b.detail.progress=w,b.detail.totalProgress01=this._loadingProgress01,this.dispatchEvent(new CustomEvent("progress",b))}),_=y?.scene;_&&$.add(_,d.scene,d)}t||yg(d)}),!c){console.error("Needle Engine: No files to load",e);return}const u=this.getAttribute("hash");u!=null&&(this._context.hash=u),this._context.alias=n,this._context.isCreated?await c(this._context):await this._context.onCreate(c),this._loadingProgress01=1,a&&((r=this._loadingView)==null||r.onLoadingUpdate(1,"creating scene")),this.classList.remove("loading"),this.classList.add("loading-finished"),Kn&&console.log("Needle Engine: finished loading",n??""),this.dispatchEvent(new CustomEvent("loadfinished",{detail:{context:this._context,src:n??e}}))}registerEventFromAttribute(e,t){if(typeof t=="string"&&t.length>0){const s=(0,eval)(t);typeof s=="function"&&this.addEventListener(e,r=>s?.call(globalThis,this._context,r))}}getAROverlayContainer(){return this._overlay_ar.findOrCreateARContainer(this)}getVROverlayContainer(){for(let e=0;e<this.children.length;e++){const t=this.children[e];if(t.classList.contains("vr"))return t}return null}onEnterAR(e,t){var s;this.onSetupAR(),this._overlay_ar.onBegin(this._context,t,e),this.dispatchEvent(new CustomEvent("enter-ar",{detail:{session:e,context:this._context,htmlContainer:(s=this._overlay_ar)==null?void 0:s.ARContainer}}))}onExitAR(e){var t;this._overlay_ar.onEnd(this._context),this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-ar",{detail:{session:e,context:this._context,htmlContainer:(t=this._overlay_ar)==null?void 0:t.ARContainer}}))}onEnterVR(e){this.onSetupVR(),this.dispatchEvent(new CustomEvent("enter-vr",{detail:{session:e,context:this._context}}))}onExitVR(e){this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-vr",{detail:{session:e,context:this._context}}))}onSetupAR(){this.classList.add(mv),this.classList.remove(vv);const e=this.getAROverlayContainer();e&&(e.classList.add(mv),e.classList.remove(vv)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,Qh))}onSetupVR(){this.classList.remove(mv),this.classList.remove(vv),this.foreachHtmlElement(e=>this.setupElementsForMode(e,RU))}onSetupDesktop(){this.classList.remove(mv),this.classList.add(vv);const e=this.getAROverlayContainer();e&&(e.classList.remove(mv),e.classList.add(vv)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,PU))}setupElementsForMode(e,t,s=null){var r;if(!(e===((r=this._context)==null?void 0:r.renderer.domElement)||e.id==="VRButton"||e.id==="ARButton"))if(e.style.position="absolute",e.classList.contains(t))e.style.visibility="visible",e.style.display==="none"&&(e.style.display="block");else for(const n of Vne)e.classList.contains(n)&&(e.style.visibility="hidden",e.style.display="none")}foreachHtmlElement(e){for(let t=0;t<this.children.length;t++){const s=this.children[t];s.style&&e(s)}}onBeforeBeginLoading(){const e=this.getAttribute("dracoDecoderPath");e&&(Kn&&console.log("using custom draco decoder path",e),YD(e));const t=this.getAttribute("dracoDecoderType");t&&(Kn&&console.log("using custom draco decoder type",t),JD(t));const s=this.getAttribute("ktx2DecoderPath");s&&(Kn&&console.log("using custom ktx2 decoder path",s),KD(s))}}window.customElements.get(TU)||window.customElements.define(TU,yI);function qne(i){const e=i.split("/");let t=e[e.length-1],s=t.indexOf("?");return s>0&&(t=t.substring(0,s)),decodeURIComponent(t)}const Xne=Object.freeze(Object.defineProperty({__proto__:null,NeedleEngineHTMLElement:yI},Symbol.toStringTag,{value:"Module"}));ts.registerCallback($r.MissingCamera,i=>{const e=i.context.scene,t="unknown",s=new Me;e.add(s);const r=new Ei,n=lc(s,r,!0);return n.sourceId=t,n.clearFlags=2,n.backgroundColor=new vi(.5,.5,.5,1),s.position.x=-2,s.position.y=2,s.position.z=2,n}),ts.registerCallback($r.ContextCreated,i=>{if(!i.context.mainCamera)return;const e=i.context.domElement;if(e?.cameraControls===!0){const t=fee(i.context.mainCamera);if(t?.isCameraController===!0)return;const s=i.context.mainCameraComponent,r=s?.gameObject;if(r){const n=lc(r,new Nc,!1);n.sourceId="unknown"}else console.warn("Missing camera object, can not add orbit controls")}});const bI=oe("debughotreload");let Av=!1;const yv=new Map;function Yne(){return Av}function Jne(i){var e;if(Av)return;const t=i.constructor.name;yv.has(t)?(e=yv.get(t))==null||e.push(i):yv.set(t,[i])}function Kne(i){if(Av)return;const e=i.constructor.name,t=yv.get(e);if(!t)return;const s=t.indexOf(i);s!==-1&&t.splice(s,1)}let BU=!1;function Zne(){if(bI||BU)return;BU=!0;const i=console.error;console.error=(...e)=>{if(e.length){const t=e[0];if(typeof t=="string"&&t.includes("[hmr] Failed to reload ")){console.log("[Needle Engine] Hot reloading failed"),window.location.reload();return}}i.apply(console,e)}}function $ne(i){bI&&console.log("Hot Reload - apply changes"),Zne();for(const e of Object.keys(i))try{Av=!0;const t=Q.get(e);if(!t)continue;const s=i[e],r=yv.get(s.name);let n="[Needle Engine] Updating type: "+e,o=r?.length??-1;o>0?n+=" x"+o:n+=" - no instances",console.log(n);const a=Object.getOwnPropertyNames(t.prototype),l=Object.getOwnPropertyDescriptors(s.prototype);for(const c in l)l[c].writable&&(t.prototype[c]=i[e].prototype[c]);for(const c of a)l[c]||delete t.prototype[c];if(r){const c=new s,u=Object.getOwnPropertyDescriptors(c);for(const d of r){const p=d,f=p.isComponent===!0,g=f?p.activeAndEnabled:!0,m=f?p.context:void 0;try{if(f&&Ka(p,m),f&&g&&(p.enabled=!1),d.onBeforeHotReloadFields&&d.onBeforeHotReloadFields()===!1)continue;for(const v in u)if(u[v].writable){if(d[v]===void 0)d[v]=c[v];else if(typeof d[v]=="function"&&!d[v].prototype){const A=d[v],b=A.name,y="bound ";if(b===y)continue;const _=A.name.substring(y.length),w=s.prototype[_];w&&(d[v]=w.bind(d))}}d.onAfterHotReloadFields&&d.onAfterHotReloadFields()}finally{f&&tC(p,m),f&&g&&(p.enabled=!0)}}}}catch(t){if(bI)console.error(t);else return!1}finally{Av=!1,Ra(ko.Log,"Script changes applied (HMR)")}return!0}const eoe=Symbol("object"),kU=new Bo(()=>new S,20);class DU{constructor(e,t,s,r,n){h(this,"_point"),h(this,"_normal"),h(this,"distance"),h(this,"impulse"),h(this,"friction"),this._point=e,this.distance=t,this._normal=s,this.impulse=r,this.friction=n}get point(){return kU.get().set(this._point.x,this._point.y,this._point.z)}get normal(){return kU.get().set(this._normal.x,this._normal.y,this._normal.z)}}class OU{constructor(e,t,s){h(this,"contacts"),h(this,"me"),h(this,"_collider"),h(this,"_gameObject"),this.me=e,this._collider=t,this._gameObject=t.gameObject,this.contacts=s}get collider(){return this._collider}get gameObject(){return this._gameObject}get rigidBody(){var e;return(e=this.collider)==null?void 0:e.attachedRigidbody}}class LU{constructor(e,t){h(this,"object"),h(this,"collider"),this.object=e,this.collider=t}}let Le;const bv=new Array(32).fill(void 0);bv.push(void 0,null,!0,!1);let FU;bv.length;function NU(){return FU.byteLength,FU}const toe=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});function gt(i,e){if(!(i instanceof e))throw new Error(`expected instance of ${e.name}`);return i.ptr}toe.decode();let UU,zU,_v=32;function jU(i){if(_v==1)throw new Error("out of js stack");return bv[--_v]=i,_v}function ioe(){return UU.byteLength,UU}function soe(){return zU.byteLength,zU}let yn=0;function Tu(i,e){const t=e(4*i.length);return ioe().set(i,t/4),yn=i.length,t}function L_(i,e){const t=e(4*i.length);return soe().set(i,t/4),yn=i.length,t}class H_{static __wrap(e){const t=Object.create(H_.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_raweventqueue_free(e)}constructor(e){const t=Le.raweventqueue_new(e);return H_.__wrap(t)}drainCollisionEvents(e){try{Le.raweventqueue_drainCollisionEvents(this.ptr,jU(e))}finally{bv[_v++]=void 0}}drainContactForceEvents(e){try{Le.raweventqueue_drainContactForceEvents(this.ptr,jU(e))}finally{bv[_v++]=void 0}}clear(){Le.raweventqueue_clear(this.ptr)}}class Ma{static __wrap(e){const t=Object.create(Ma.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawgenericjoint_free(e)}static spherical(e,t){gt(e,ot),gt(t,ot);const s=Le.rawgenericjoint_spherical(e.ptr,t.ptr);return Ma.__wrap(s)}static prismatic(e,t,s,r,n,o){gt(e,ot),gt(t,ot),gt(s,ot);const a=Le.rawgenericjoint_prismatic(e.ptr,t.ptr,s.ptr,r,n,o);return a===0?void 0:Ma.__wrap(a)}static fixed(e,t,s,r){gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,Ls);const n=Le.rawgenericjoint_fixed(e.ptr,t.ptr,s.ptr,r.ptr);return Ma.__wrap(n)}static revolute(e,t,s){gt(e,ot),gt(t,ot),gt(s,ot);const r=Le.rawgenericjoint_revolute(e.ptr,t.ptr,s.ptr);return r===0?void 0:Ma.__wrap(r)}}class PI{static __wrap(e){const t=Object.create(PI.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawpointprojection_free(e)}point(){const e=Le.rawpointprojection_point(this.ptr);return ot.__wrap(e)}isInside(){return Le.rawpointprojection_isInside(this.ptr)!==0}}class BI{static __wrap(e){const t=Object.create(BI.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawrayintersection_free(e)}normal(){const e=Le.rawrayintersection_normal(this.ptr);return ot.__wrap(e)}toi(){return Le.rawintegrationparameters_dt(this.ptr)}featureType(){return Le.rawrayintersection_featureType(this.ptr)>>>0}featureId(){try{const s=Le.__wbindgen_add_to_stack_pointer(-16);Le.rawrayintersection_featureId(s,this.ptr);var e=NU()[s/4+0],t=NU()[s/4+1];return e===0?void 0:t>>>0}finally{Le.__wbindgen_add_to_stack_pointer(16)}}}class Ls{static __wrap(e){const t=Object.create(Ls.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawrotation_free(e)}constructor(e,t,s,r){const n=Le.rawrotation_new(e,t,s,r);return Ls.__wrap(n)}static identity(){const e=Le.rawrotation_identity();return Ls.__wrap(e)}get x(){return Le.rawintegrationparameters_dt(this.ptr)}get y(){return Le.rawrotation_y(this.ptr)}get z(){return Le.rawintegrationparameters_erp(this.ptr)}get w(){return Le.rawrotation_w(this.ptr)}}class Ot{static __wrap(e){const t=Object.create(Ot.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawshape_free(e)}static cuboid(e,t,s){const r=Le.rawshape_cuboid(e,t,s);return Ot.__wrap(r)}static roundCuboid(e,t,s,r){const n=Le.rawshape_roundCuboid(e,t,s,r);return Ot.__wrap(n)}static ball(e){const t=Le.rawshape_ball(e);return Ot.__wrap(t)}static capsule(e,t){const s=Le.rawshape_capsule(e,t);return Ot.__wrap(s)}static cylinder(e,t){const s=Le.rawshape_cylinder(e,t);return Ot.__wrap(s)}static roundCylinder(e,t,s){const r=Le.rawshape_roundCylinder(e,t,s);return Ot.__wrap(r)}static cone(e,t){const s=Le.rawshape_cone(e,t);return Ot.__wrap(s)}static roundCone(e,t,s){const r=Le.rawshape_roundCone(e,t,s);return Ot.__wrap(r)}static polyline(e,t){const s=Tu(e,Le.__wbindgen_malloc),r=yn,n=L_(t,Le.__wbindgen_malloc),o=yn,a=Le.rawshape_polyline(s,r,n,o);return Ot.__wrap(a)}static trimesh(e,t){const s=Tu(e,Le.__wbindgen_malloc),r=yn,n=L_(t,Le.__wbindgen_malloc),o=yn,a=Le.rawshape_trimesh(s,r,n,o);return Ot.__wrap(a)}static heightfield(e,t,s,r){const n=Tu(s,Le.__wbindgen_malloc),o=yn;gt(r,ot);const a=Le.rawshape_heightfield(e,t,n,o,r.ptr);return Ot.__wrap(a)}static segment(e,t){gt(e,ot),gt(t,ot);const s=Le.rawshape_segment(e.ptr,t.ptr);return Ot.__wrap(s)}static triangle(e,t,s){gt(e,ot),gt(t,ot),gt(s,ot);const r=Le.rawshape_triangle(e.ptr,t.ptr,s.ptr);return Ot.__wrap(r)}static roundTriangle(e,t,s,r){gt(e,ot),gt(t,ot),gt(s,ot);const n=Le.rawshape_roundTriangle(e.ptr,t.ptr,s.ptr,r);return Ot.__wrap(n)}static convexHull(e){const t=Tu(e,Le.__wbindgen_malloc),s=yn,r=Le.rawshape_convexHull(t,s);return r===0?void 0:Ot.__wrap(r)}static roundConvexHull(e,t){const s=Tu(e,Le.__wbindgen_malloc),r=yn,n=Le.rawshape_roundConvexHull(s,r,t);return n===0?void 0:Ot.__wrap(n)}static convexMesh(e,t){const s=Tu(e,Le.__wbindgen_malloc),r=yn,n=L_(t,Le.__wbindgen_malloc),o=yn,a=Le.rawshape_convexMesh(s,r,n,o);return a===0?void 0:Ot.__wrap(a)}static roundConvexMesh(e,t,s){const r=Tu(e,Le.__wbindgen_malloc),n=yn,o=L_(t,Le.__wbindgen_malloc),a=yn,l=Le.rawshape_roundConvexMesh(r,n,o,a,s);return l===0?void 0:Ot.__wrap(l)}castShape(e,t,s,r,n,o,a,l){gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,Ot),gt(n,ot),gt(o,Ls),gt(a,ot);const c=Le.rawshape_castShape(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n.ptr,o.ptr,a.ptr,l);return c===0?void 0:DI.__wrap(c)}intersectsShape(e,t,s,r,n){return gt(e,ot),gt(t,Ls),gt(s,Ot),gt(r,ot),gt(n,Ls),Le.rawshape_intersectsShape(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n.ptr)!==0}contactShape(e,t,s,r,n,o){gt(e,ot),gt(t,Ls),gt(s,Ot),gt(r,ot),gt(n,Ls);const a=Le.rawshape_contactShape(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n.ptr,o);return a===0?void 0:kI.__wrap(a)}containsPoint(e,t,s){return gt(e,ot),gt(t,Ls),gt(s,ot),Le.rawshape_containsPoint(this.ptr,e.ptr,t.ptr,s.ptr)!==0}projectPoint(e,t,s,r){gt(e,ot),gt(t,Ls),gt(s,ot);const n=Le.rawshape_projectPoint(this.ptr,e.ptr,t.ptr,s.ptr,r);return PI.__wrap(n)}intersectsRay(e,t,s,r,n){return gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,ot),Le.rawshape_intersectsRay(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n)!==0}castRay(e,t,s,r,n,o){return gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,ot),Le.rawshape_castRay(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n,o)}castRayAndGetNormal(e,t,s,r,n,o){gt(e,ot),gt(t,Ls),gt(s,ot),gt(r,ot);const a=Le.rawshape_castRayAndGetNormal(this.ptr,e.ptr,t.ptr,s.ptr,r.ptr,n,o);return a===0?void 0:BI.__wrap(a)}}class kI{static __wrap(e){const t=Object.create(kI.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawshapecontact_free(e)}distance(){return Le.rawshapecontact_distance(this.ptr)}point1(){const e=Le.rawpointprojection_point(this.ptr);return ot.__wrap(e)}point2(){const e=Le.rawshapecontact_point2(this.ptr);return ot.__wrap(e)}normal1(){const e=Le.rawshapecontact_normal1(this.ptr);return ot.__wrap(e)}normal2(){const e=Le.rawshapecontact_normal2(this.ptr);return ot.__wrap(e)}}class DI{static __wrap(e){const t=Object.create(DI.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawshapetoi_free(e)}toi(){return Le.rawintegrationparameters_dt(this.ptr)}witness1(){const e=Le.rawrayintersection_normal(this.ptr);return ot.__wrap(e)}witness2(){const e=Le.rawshapetoi_witness2(this.ptr);return ot.__wrap(e)}normal1(){const e=Le.rawshapetoi_normal1(this.ptr);return ot.__wrap(e)}normal2(){const e=Le.rawshapetoi_normal2(this.ptr);return ot.__wrap(e)}}class ot{static __wrap(e){const t=Object.create(ot.prototype);return t.ptr=e,t}__destroy_into_raw(){const e=this.ptr;return this.ptr=0,e}free(){const e=this.__destroy_into_raw();Le.__wbg_rawvector_free(e)}static zero(){const e=Le.rawvector_zero();return ot.__wrap(e)}constructor(e,t,s){const r=Le.rawvector_new(e,t,s);return ot.__wrap(r)}get x(){return Le.rawintegrationparameters_dt(this.ptr)}set x(e){Le.rawintegrationparameters_set_dt(this.ptr,e)}get y(){return Le.rawrotation_y(this.ptr)}set y(e){Le.rawvector_set_y(this.ptr,e)}get z(){return Le.rawintegrationparameters_erp(this.ptr)}set z(e){Le.rawintegrationparameters_set_erp(this.ptr,e)}xyz(){const e=Le.rawvector_xyz(this.ptr);return ot.__wrap(e)}yxz(){const e=Le.rawvector_yxz(this.ptr);return ot.__wrap(e)}zxy(){const e=Le.rawvector_zxy(this.ptr);return ot.__wrap(e)}xzy(){const e=Le.rawvector_xzy(this.ptr);return ot.__wrap(e)}yzx(){const e=Le.rawvector_yzx(this.ptr);return ot.__wrap(e)}zyx(){const e=Le.rawvector_zyx(this.ptr);return ot.__wrap(e)}}class roe{constructor(e,t,s){this.x=e,this.y=t,this.z=s}}class Ue{static new(e,t,s){return new roe(e,t,s)}static intoRaw(e){return new ot(e.x,e.y,e.z)}static zeros(){return Ue.new(0,0,0)}static fromRaw(e){if(!e)return null;let t=Ue.new(e.x,e.y,e.z);return e.free(),t}static copy(e,t){e.x=t.x,e.y=t.y,e.z=t.z}}class QU{constructor(e,t,s,r){this.x=e,this.y=t,this.z=s,this.w=r}}class ji{static identity(){return new QU(0,0,0,1)}static fromRaw(e){if(!e)return null;let t=new QU(e.x,e.y,e.z,e.w);return e.free(),t}static intoRaw(e){return new Ls(e.x,e.y,e.z,e.w)}static copy(e,t){e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w}}var xv,ya,GU,Zn,_I,$t,F_,Yp,xI,wI,HU,VU;(function(i){i[i.Dynamic=0]="Dynamic",i[i.Fixed=1]="Fixed",i[i.KinematicPositionBased=2]="KinematicPositionBased",i[i.KinematicVelocityBased=3]="KinematicVelocityBased"})(xv||(xv={})),function(i){i[i.Revolute=0]="Revolute",i[i.Fixed=1]="Fixed",i[i.Prismatic=2]="Prismatic",i[i.Spherical=3]="Spherical"}(ya||(ya={})),function(i){i[i.AccelerationBased=0]="AccelerationBased",i[i.ForceBased=1]="ForceBased"}(GU||(GU={}));class of{constructor(){}static fixed(e,t,s,r){let n=new of;return n.anchor1=e,n.anchor2=s,n.frame1=t,n.frame2=r,n.jointType=ya.Fixed,n}static spherical(e,t){let s=new of;return s.anchor1=e,s.anchor2=t,s.jointType=ya.Spherical,s}static prismatic(e,t,s){let r=new of;return r.anchor1=e,r.anchor2=t,r.axis=s,r.jointType=ya.Prismatic,r}static revolute(e,t,s){let r=new of;return r.anchor1=e,r.anchor2=t,r.axis=s,r.jointType=ya.Revolute,r}intoRaw(){let e,t,s=Ue.intoRaw(this.anchor1),r=Ue.intoRaw(this.anchor2),n=!1,o=0,a=0;switch(this.jointType){case ya.Fixed:let l=ji.intoRaw(this.frame1),c=ji.intoRaw(this.frame2);t=Ma.fixed(s,l,r,c),l.free(),c.free();break;case ya.Prismatic:e=Ue.intoRaw(this.axis),this.limitsEnabled&&(n=!0,o=this.limits[0],a=this.limits[1]),t=Ma.prismatic(s,r,e,n,o,a),e.free();break;case ya.Spherical:t=Ma.spherical(s,r);break;case ya.Revolute:e=Ue.intoRaw(this.axis),t=Ma.revolute(s,r,e),e.free()}return s.free(),r.free(),t}}(function(i){i[i.Average=0]="Average",i[i.Min=1]="Min",i[i.Multiply=2]="Multiply",i[i.Max=3]="Max"})(Zn||(Zn={}));class Dv{constructor(e,t,s,r,n){this.distance=e,this.point1=t,this.point2=s,this.normal1=r,this.normal2=n}static fromRaw(e){if(!e)return null;const t=new Dv(e.distance(),Ue.fromRaw(e.point1()),Ue.fromRaw(e.point2()),Ue.fromRaw(e.normal1()),Ue.fromRaw(e.normal2()));return e.free(),t}}(function(i){i[i.Vertex=0]="Vertex",i[i.Edge=1]="Edge",i[i.Face=2]="Face",i[i.Unknown=3]="Unknown"})(_I||(_I={}));class V_{constructor(e,t){this.point=e,this.isInside=t}static fromRaw(e){if(!e)return null;const t=new V_(Ue.fromRaw(e.point()),e.isInside());return e.free(),t}}class noe{constructor(e,t){this.origin=e,this.dir=t}pointAt(e){return{x:this.origin.x+this.dir.x*e,y:this.origin.y+this.dir.y*e,z:this.origin.z+this.dir.z*e}}}class W_{constructor(e,t,s,r){this.featureType=_I.Unknown,this.featureId=void 0,this.toi=e,this.normal=t,r!==void 0&&(this.featureId=r),s!==void 0&&(this.featureType=s)}static fromRaw(e){if(!e)return null;const t=new W_(e.toi(),Ue.fromRaw(e.normal()),e.featureType(),e.featureId());return e.free(),t}}class Ov{constructor(e,t,s,r,n){this.toi=e,this.witness1=t,this.witness2=s,this.normal1=r,this.normal2=n}static fromRaw(e,t){if(!t)return null;const s=new Ov(t.toi(),Ue.fromRaw(t.witness1()),Ue.fromRaw(t.witness2()),Ue.fromRaw(t.normal1()),Ue.fromRaw(t.normal2()));return t.free(),s}}class OI extends Ov{constructor(e,t,s,r,n,o){super(t,s,r,n,o),this.collider=e}static fromRaw(e,t){if(!t)return null;const s=new OI(e.get(t.colliderHandle()),t.toi(),Ue.fromRaw(t.witness1()),Ue.fromRaw(t.witness2()),Ue.fromRaw(t.normal1()),Ue.fromRaw(t.normal2()));return t.free(),s}}class Zs{static fromRaw(e,t){const s=e.coShapeType(t);let r,n,o,a,l,c;switch(s){case $t.Ball:return new CI(e.coRadius(t));case $t.Cuboid:return r=e.coHalfExtents(t),new WU(r.x,r.y,r.z);case $t.RoundCuboid:return r=e.coHalfExtents(t),n=e.coRoundRadius(t),new qU(r.x,r.y,r.z,n);case $t.Capsule:return l=e.coHalfHeight(t),c=e.coRadius(t),new XU(l,c);case $t.Segment:return o=e.coVertices(t),new YU(Ue.new(o[0],o[1],o[2]),Ue.new(o[3],o[4],o[5]));case $t.Polyline:return o=e.coVertices(t),a=e.coIndices(t),new ZU(o,a);case $t.Triangle:return o=e.coVertices(t),new JU(Ue.new(o[0],o[1],o[2]),Ue.new(o[3],o[4],o[5]),Ue.new(o[6],o[7],o[8]));case $t.RoundTriangle:return o=e.coVertices(t),n=e.coRoundRadius(t),new KU(Ue.new(o[0],o[1],o[2]),Ue.new(o[3],o[4],o[5]),Ue.new(o[6],o[7],o[8]),n);case $t.TriMesh:return o=e.coVertices(t),a=e.coIndices(t),new $U(o,a);case $t.HeightField:const u=e.coHeightfieldScale(t),d=e.coHeightfieldHeights(t),p=e.coHeightfieldNRows(t),f=e.coHeightfieldNCols(t);return new ez(p,f,d,u);case $t.ConvexPolyhedron:return o=e.coVertices(t),a=e.coIndices(t),new SI(o,a);case $t.RoundConvexPolyhedron:return o=e.coVertices(t),a=e.coIndices(t),n=e.coRoundRadius(t),new EI(o,a,n);case $t.Cylinder:return l=e.coHalfHeight(t),c=e.coRadius(t),new tz(l,c);case $t.RoundCylinder:return l=e.coHalfHeight(t),c=e.coRadius(t),n=e.coRoundRadius(t),new iz(l,c,n);case $t.Cone:return l=e.coHalfHeight(t),c=e.coRadius(t),new sz(l,c);case $t.RoundCone:return l=e.coHalfHeight(t),c=e.coRadius(t),n=e.coRoundRadius(t),new rz(l,c,n);default:throw new Error("unknown shape type: "+s)}}castShape(e,t,s,r,n,o,a,l){let c=Ue.intoRaw(e),u=ji.intoRaw(t),d=Ue.intoRaw(s),p=Ue.intoRaw(n),f=ji.intoRaw(o),g=Ue.intoRaw(a),m=this.intoRaw(),v=r.intoRaw(),A=Ov.fromRaw(null,m.castShape(c,u,d,v,p,f,g,l));return c.free(),u.free(),d.free(),p.free(),f.free(),g.free(),m.free(),v.free(),A}intersectsShape(e,t,s,r,n){let o=Ue.intoRaw(e),a=ji.intoRaw(t),l=Ue.intoRaw(r),c=ji.intoRaw(n),u=this.intoRaw(),d=s.intoRaw(),p=u.intersectsShape(o,a,d,l,c);return o.free(),a.free(),l.free(),c.free(),u.free(),d.free(),p}contactShape(e,t,s,r,n,o){let a=Ue.intoRaw(e),l=ji.intoRaw(t),c=Ue.intoRaw(r),u=ji.intoRaw(n),d=this.intoRaw(),p=s.intoRaw(),f=Dv.fromRaw(d.contactShape(a,l,p,c,u,o));return a.free(),l.free(),c.free(),u.free(),d.free(),p.free(),f}containsPoint(e,t,s){let r=Ue.intoRaw(e),n=ji.intoRaw(t),o=Ue.intoRaw(s),a=this.intoRaw(),l=a.containsPoint(r,n,o);return r.free(),n.free(),o.free(),a.free(),l}projectPoint(e,t,s,r){let n=Ue.intoRaw(e),o=ji.intoRaw(t),a=Ue.intoRaw(s),l=this.intoRaw(),c=V_.fromRaw(l.projectPoint(n,o,a,r));return n.free(),o.free(),a.free(),l.free(),c}intersectsRay(e,t,s,r){let n=Ue.intoRaw(t),o=ji.intoRaw(s),a=Ue.intoRaw(e.origin),l=Ue.intoRaw(e.dir),c=this.intoRaw(),u=c.intersectsRay(n,o,a,l,r);return n.free(),o.free(),a.free(),l.free(),c.free(),u}castRay(e,t,s,r,n){let o=Ue.intoRaw(t),a=ji.intoRaw(s),l=Ue.intoRaw(e.origin),c=Ue.intoRaw(e.dir),u=this.intoRaw(),d=u.castRay(o,a,l,c,r,n);return o.free(),a.free(),l.free(),c.free(),u.free(),d}castRayAndGetNormal(e,t,s,r,n){let o=Ue.intoRaw(t),a=ji.intoRaw(s),l=Ue.intoRaw(e.origin),c=Ue.intoRaw(e.dir),u=this.intoRaw(),d=W_.fromRaw(u.castRayAndGetNormal(o,a,l,c,r,n));return o.free(),a.free(),l.free(),c.free(),u.free(),d}}(function(i){i[i.Ball=0]="Ball",i[i.Cuboid=1]="Cuboid",i[i.Capsule=2]="Capsule",i[i.Segment=3]="Segment",i[i.Polyline=4]="Polyline",i[i.Triangle=5]="Triangle",i[i.TriMesh=6]="TriMesh",i[i.HeightField=7]="HeightField",i[i.ConvexPolyhedron=9]="ConvexPolyhedron",i[i.Cylinder=10]="Cylinder",i[i.Cone=11]="Cone",i[i.RoundCuboid=12]="RoundCuboid",i[i.RoundTriangle=13]="RoundTriangle",i[i.RoundCylinder=14]="RoundCylinder",i[i.RoundCone=15]="RoundCone",i[i.RoundConvexPolyhedron=16]="RoundConvexPolyhedron"})($t||($t={}));class CI extends Zs{constructor(e){super(),this.type=$t.Ball,this.radius=e}intoRaw(){return Ot.ball(this.radius)}}class WU extends Zs{constructor(e,t,s){super(),this.type=$t.Cuboid,this.halfExtents=Ue.new(e,t,s)}intoRaw(){return Ot.cuboid(this.halfExtents.x,this.halfExtents.y,this.halfExtents.z)}}class qU extends Zs{constructor(e,t,s,r){super(),this.type=$t.RoundCuboid,this.halfExtents=Ue.new(e,t,s),this.borderRadius=r}intoRaw(){return Ot.roundCuboid(this.halfExtents.x,this.halfExtents.y,this.halfExtents.z,this.borderRadius)}}class XU extends Zs{constructor(e,t){super(),this.type=$t.Capsule,this.halfHeight=e,this.radius=t}intoRaw(){return Ot.capsule(this.halfHeight,this.radius)}}class YU extends Zs{constructor(e,t){super(),this.type=$t.Segment,this.a=e,this.b=t}intoRaw(){let e=Ue.intoRaw(this.a),t=Ue.intoRaw(this.b),s=Ot.segment(e,t);return e.free(),t.free(),s}}class JU extends Zs{constructor(e,t,s){super(),this.type=$t.Triangle,this.a=e,this.b=t,this.c=s}intoRaw(){let e=Ue.intoRaw(this.a),t=Ue.intoRaw(this.b),s=Ue.intoRaw(this.c),r=Ot.triangle(e,t,s);return e.free(),t.free(),s.free(),r}}class KU extends Zs{constructor(e,t,s,r){super(),this.type=$t.RoundTriangle,this.a=e,this.b=t,this.c=s,this.borderRadius=r}intoRaw(){let e=Ue.intoRaw(this.a),t=Ue.intoRaw(this.b),s=Ue.intoRaw(this.c),r=Ot.roundTriangle(e,t,s,this.borderRadius);return e.free(),t.free(),s.free(),r}}class ZU extends Zs{constructor(e,t){super(),this.type=$t.Polyline,this.vertices=e,this.indices=t??new Uint32Array(0)}intoRaw(){return Ot.polyline(this.vertices,this.indices)}}class $U extends Zs{constructor(e,t){super(),this.type=$t.TriMesh,this.vertices=e,this.indices=t}intoRaw(){return Ot.trimesh(this.vertices,this.indices)}}class SI extends Zs{constructor(e,t){super(),this.type=$t.ConvexPolyhedron,this.vertices=e,this.indices=t}intoRaw(){return this.indices?Ot.convexMesh(this.vertices,this.indices):Ot.convexHull(this.vertices)}}class EI extends Zs{constructor(e,t,s){super(),this.type=$t.RoundConvexPolyhedron,this.vertices=e,this.indices=t,this.borderRadius=s}intoRaw(){return this.indices?Ot.roundConvexMesh(this.vertices,this.indices,this.borderRadius):Ot.roundConvexHull(this.vertices,this.borderRadius)}}class ez extends Zs{constructor(e,t,s,r){super(),this.type=$t.HeightField,this.nrows=e,this.ncols=t,this.heights=s,this.scale=r}intoRaw(){let e=Ue.intoRaw(this.scale),t=Ot.heightfield(this.nrows,this.ncols,this.heights,e);return e.free(),t}}class tz extends Zs{constructor(e,t){super(),this.type=$t.Cylinder,this.halfHeight=e,this.radius=t}intoRaw(){return Ot.cylinder(this.halfHeight,this.radius)}}class iz extends Zs{constructor(e,t,s){super(),this.type=$t.RoundCylinder,this.borderRadius=s,this.halfHeight=e,this.radius=t}intoRaw(){return Ot.roundCylinder(this.halfHeight,this.radius,this.borderRadius)}}class sz extends Zs{constructor(e,t){super(),this.type=$t.Cone,this.halfHeight=e,this.radius=t}intoRaw(){return Ot.cone(this.halfHeight,this.radius)}}class rz extends Zs{constructor(e,t,s){super(),this.type=$t.RoundCone,this.halfHeight=e,this.radius=t,this.borderRadius=s}intoRaw(){return Ot.roundCone(this.halfHeight,this.radius,this.borderRadius)}}(function(i){i[i.DYNAMIC_DYNAMIC=1]="DYNAMIC_DYNAMIC",i[i.DYNAMIC_KINEMATIC=12]="DYNAMIC_KINEMATIC",i[i.DYNAMIC_FIXED=2]="DYNAMIC_FIXED",i[i.KINEMATIC_KINEMATIC=52224]="KINEMATIC_KINEMATIC",i[i.KINEMATIC_FIXED=8704]="KINEMATIC_FIXED",i[i.FIXED_FIXED=32]="FIXED_FIXED",i[i.DEFAULT=15]="DEFAULT",i[i.ALL=60943]="ALL"})(F_||(F_={}));class ooe{constructor(e,t,s,r){this.colliderSet=e,this.handle=t,this._parent=s,this._shape=r}finalizeDeserialization(e){this.handle!=null&&(this._parent=e.get(this.colliderSet.raw.coParent(this.handle)))}ensureShapeIsCached(){this._shape||(this._shape=Zs.fromRaw(this.colliderSet.raw,this.handle))}get shape(){return this.ensureShapeIsCached(),this._shape}isValid(){return this.colliderSet.raw.contains(this.handle)}translation(){return Ue.fromRaw(this.colliderSet.raw.coTranslation(this.handle))}rotation(){return ji.fromRaw(this.colliderSet.raw.coRotation(this.handle))}isSensor(){return this.colliderSet.raw.coIsSensor(this.handle)}setSensor(e){this.colliderSet.raw.coSetSensor(this.handle,e)}setShape(e){let t=e.intoRaw();this.colliderSet.raw.coSetShape(this.handle,t),t.free(),this._shape=e}setRestitution(e){this.colliderSet.raw.coSetRestitution(this.handle,e)}setFriction(e){this.colliderSet.raw.coSetFriction(this.handle,e)}frictionCombineRule(){return this.colliderSet.raw.coFrictionCombineRule(this.handle)}setFrictionCombineRule(e){this.colliderSet.raw.coSetFrictionCombineRule(this.handle,e)}restitutionCombineRule(){return this.colliderSet.raw.coRestitutionCombineRule(this.handle)}setRestitutionCombineRule(e){this.colliderSet.raw.coSetRestitutionCombineRule(this.handle,e)}setCollisionGroups(e){this.colliderSet.raw.coSetCollisionGroups(this.handle,e)}setSolverGroups(e){this.colliderSet.raw.coSetSolverGroups(this.handle,e)}activeHooks(){return this.colliderSet.raw.coActiveHooks(this.handle)}setActiveHooks(e){this.colliderSet.raw.coSetActiveHooks(this.handle,e)}activeEvents(){return this.colliderSet.raw.coActiveEvents(this.handle)}setActiveEvents(e){this.colliderSet.raw.coSetActiveEvents(this.handle,e)}activeCollisionTypes(){return this.colliderSet.raw.coActiveCollisionTypes(this.handle)}setContactForceEventThreshold(e){return this.colliderSet.raw.coSetContactForceEventThreshold(this.handle,e)}contactForceEventThreshold(){return this.colliderSet.raw.coContactForceEventThreshold(this.handle)}setActiveCollisionTypes(e){this.colliderSet.raw.coSetActiveCollisionTypes(this.handle,e)}setDensity(e){this.colliderSet.raw.coSetDensity(this.handle,e)}setMass(e){this.colliderSet.raw.coSetMass(this.handle,e)}setMassProperties(e,t,s,r){let n=Ue.intoRaw(t),o=Ue.intoRaw(s),a=ji.intoRaw(r);this.colliderSet.raw.coSetMassProperties(this.handle,e,n,o,a),n.free(),o.free(),a.free()}setTranslation(e){this.colliderSet.raw.coSetTranslation(this.handle,e.x,e.y,e.z)}setTranslationWrtParent(e){this.colliderSet.raw.coSetTranslationWrtParent(this.handle,e.x,e.y,e.z)}setRotation(e){this.colliderSet.raw.coSetRotation(this.handle,e.x,e.y,e.z,e.w)}setRotationWrtParent(e){this.colliderSet.raw.coSetRotationWrtParent(this.handle,e.x,e.y,e.z,e.w)}shapeType(){return this.colliderSet.raw.coShapeType(this.handle)}halfExtents(){return Ue.fromRaw(this.colliderSet.raw.coHalfExtents(this.handle))}radius(){return this.colliderSet.raw.coRadius(this.handle)}roundRadius(){return this.colliderSet.raw.coRoundRadius(this.handle)}halfHeight(){return this.colliderSet.raw.coHalfHeight(this.handle)}vertices(){return this.colliderSet.raw.coVertices(this.handle)}indices(){return this.colliderSet.raw.coIndices(this.handle)}heightfieldHeights(){return this.colliderSet.raw.coHeightfieldHeights(this.handle)}heightfieldScale(){let e=this.colliderSet.raw.coHeightfieldScale(this.handle);return Ue.fromRaw(e)}heightfieldNRows(){return this.colliderSet.raw.coHeightfieldNRows(this.handle)}heightfieldNCols(){return this.colliderSet.raw.coHeightfieldNCols(this.handle)}parent(){return this._parent}friction(){return this.colliderSet.raw.coFriction(this.handle)}restitution(){return this.colliderSet.raw.coRestitution(this.handle)}density(){return this.colliderSet.raw.coDensity(this.handle)}mass(){return this.colliderSet.raw.coMass(this.handle)}volume(){return this.colliderSet.raw.coVolume(this.handle)}collisionGroups(){return this.colliderSet.raw.coCollisionGroups(this.handle)}solverGroups(){return this.colliderSet.raw.coSolverGroups(this.handle)}containsPoint(e){let t=Ue.intoRaw(e),s=this.colliderSet.raw.coContainsPoint(this.handle,t);return t.free(),s}projectPoint(e,t){let s=Ue.intoRaw(e),r=V_.fromRaw(this.colliderSet.raw.coProjectPoint(this.handle,s,t));return s.free(),r}intersectsRay(e,t){let s=Ue.intoRaw(e.origin),r=Ue.intoRaw(e.dir),n=this.colliderSet.raw.coIntersectsRay(this.handle,s,r,t);return s.free(),r.free(),n}castShape(e,t,s,r,n,o){let a=Ue.intoRaw(e),l=Ue.intoRaw(s),c=ji.intoRaw(r),u=Ue.intoRaw(n),d=t.intoRaw(),p=Ov.fromRaw(this.colliderSet,this.colliderSet.raw.coCastShape(this.handle,a,d,l,c,u,o));return a.free(),l.free(),c.free(),u.free(),d.free(),p}castCollider(e,t,s,r){let n=Ue.intoRaw(e),o=Ue.intoRaw(s),a=OI.fromRaw(this.colliderSet,this.colliderSet.raw.coCastCollider(this.handle,n,t.handle,o,r));return n.free(),o.free(),a}intersectsShape(e,t,s){let r=Ue.intoRaw(t),n=ji.intoRaw(s),o=e.intoRaw(),a=this.colliderSet.raw.coIntersectsShape(this.handle,o,r,n);return r.free(),n.free(),o.free(),a}contactShape(e,t,s,r){let n=Ue.intoRaw(t),o=ji.intoRaw(s),a=e.intoRaw(),l=Dv.fromRaw(this.colliderSet.raw.coContactShape(this.handle,a,n,o,r));return n.free(),o.free(),a.free(),l}contactCollider(e,t){return Dv.fromRaw(this.colliderSet.raw.coContactCollider(this.handle,e.handle,t))}castRay(e,t,s){let r=Ue.intoRaw(e.origin),n=Ue.intoRaw(e.dir),o=this.colliderSet.raw.coCastRay(this.handle,r,n,t,s);return r.free(),n.free(),o}castRayAndGetNormal(e,t,s){let r=Ue.intoRaw(e.origin),n=Ue.intoRaw(e.dir),o=W_.fromRaw(this.colliderSet.raw.coCastRayAndGetNormal(this.handle,r,n,t,s));return r.free(),n.free(),o}}(function(i){i[i.Density=0]="Density",i[i.Mass=1]="Mass",i[i.MassProps=2]="MassProps"})(Yp||(Yp={}));class Ri{constructor(e){this.shape=e,this.massPropsMode=Yp.Density,this.density=1,this.friction=.5,this.restitution=0,this.rotation=ji.identity(),this.translation=Ue.zeros(),this.isSensor=!1,this.collisionGroups=4294967295,this.solverGroups=4294967295,this.frictionCombineRule=Zn.Average,this.restitutionCombineRule=Zn.Average,this.activeCollisionTypes=F_.DEFAULT,this.activeEvents=0,this.activeHooks=0,this.mass=0,this.centerOfMass=Ue.zeros(),this.contactForceEventThreshold=0,this.principalAngularInertia=Ue.zeros(),this.angularInertiaLocalFrame=ji.identity()}static ball(e){const t=new CI(e);return new Ri(t)}static capsule(e,t){const s=new XU(e,t);return new Ri(s)}static segment(e,t){const s=new YU(e,t);return new Ri(s)}static triangle(e,t,s){const r=new JU(e,t,s);return new Ri(r)}static roundTriangle(e,t,s,r){const n=new KU(e,t,s,r);return new Ri(n)}static polyline(e,t){const s=new ZU(e,t);return new Ri(s)}static trimesh(e,t){const s=new $U(e,t);return new Ri(s)}static cuboid(e,t,s){const r=new WU(e,t,s);return new Ri(r)}static roundCuboid(e,t,s,r){const n=new qU(e,t,s,r);return new Ri(n)}static heightfield(e,t,s,r){const n=new ez(e,t,s,r);return new Ri(n)}static cylinder(e,t){const s=new tz(e,t);return new Ri(s)}static roundCylinder(e,t,s){const r=new iz(e,t,s);return new Ri(r)}static cone(e,t){const s=new sz(e,t);return new Ri(s)}static roundCone(e,t,s){const r=new rz(e,t,s);return new Ri(r)}static convexHull(e){const t=new SI(e,null);return new Ri(t)}static convexMesh(e,t){const s=new SI(e,t);return new Ri(s)}static roundConvexHull(e,t){const s=new EI(e,null,t);return new Ri(s)}static roundConvexMesh(e,t,s){const r=new EI(e,t,s);return new Ri(r)}setTranslation(e,t,s){if(typeof e!="number"||typeof t!="number"||typeof s!="number")throw TypeError("The translation components must be numbers.");return this.translation={x:e,y:t,z:s},this}setRotation(e){return ji.copy(this.rotation,e),this}setSensor(e){return this.isSensor=e,this}setDensity(e){return this.massPropsMode=Yp.Density,this.density=e,this}setMass(e){return this.massPropsMode=Yp.Mass,this.mass=e,this}setMassProperties(e,t,s,r){return this.massPropsMode=Yp.MassProps,this.mass=e,Ue.copy(this.centerOfMass,t),Ue.copy(this.principalAngularInertia,s),ji.copy(this.angularInertiaLocalFrame,r),this}setRestitution(e){return this.restitution=e,this}setFriction(e){return this.friction=e,this}setFrictionCombineRule(e){return this.frictionCombineRule=e,this}setRestitutionCombineRule(e){return this.restitutionCombineRule=e,this}setCollisionGroups(e){return this.collisionGroups=e,this}setSolverGroups(e){return this.solverGroups=e,this}setActiveHooks(e){return this.activeHooks=e,this}setActiveEvents(e){return this.activeEvents=e,this}setActiveCollisionTypes(e){return this.activeCollisionTypes=e,this}setContactForceEventThreshold(e){return this.contactForceEventThreshold=e,this}}(function(i){i[i.EXCLUDE_FIXED=1]="EXCLUDE_FIXED",i[i.EXCLUDE_KINEMATIC=2]="EXCLUDE_KINEMATIC",i[i.EXCLUDE_DYNAMIC=4]="EXCLUDE_DYNAMIC",i[i.EXCLUDE_SENSORS=8]="EXCLUDE_SENSORS",i[i.EXCLUDE_SOLIDS=16]="EXCLUDE_SOLIDS",i[i.ONLY_DYNAMIC=3]="ONLY_DYNAMIC",i[i.ONLY_KINEMATIC=5]="ONLY_KINEMATIC",i[i.ONLY_FIXED=6]="ONLY_FIXED"})(xI||(xI={})),function(i){i[i.COLLISION_EVENTS=1]="COLLISION_EVENTS",i[i.CONTACT_FORCE_EVENTS=2]="CONTACT_FORCE_EVENTS"}(wI||(wI={}));class aoe{free(){this.raw.free(),this.raw=void 0}collider1(){return this.raw.collider1()}collider2(){return this.raw.collider2()}totalForce(){return Ue.fromRaw(this.raw.total_force())}totalForceMagnitude(){return this.raw.total_force_magnitude()}maxForceDirection(){return Ue.fromRaw(this.raw.max_force_direction())}maxForceMagnitude(){return this.raw.max_force_magnitude()}}class loe{constructor(e,t){this.raw=t||new H_(e)}free(){this.raw.free(),this.raw=void 0}drainCollisionEvents(e){this.raw.drainCollisionEvents(e)}drainContactForceEvents(e){let t=new aoe;this.raw.drainContactForceEvents(s=>{t.raw=s,e(t),t.free()})}clear(){this.raw.clear()}}(function(i){i[i.FILTER_CONTACT_PAIRS=1]="FILTER_CONTACT_PAIRS",i[i.FILTER_INTERSECTION_PAIRS=2]="FILTER_INTERSECTION_PAIRS"})(HU||(HU={})),function(i){i[i.EMPTY=0]="EMPTY",i[i.COMPUTE_IMPULSE=1]="COMPUTE_IMPULSE"}(VU||(VU={}));for(var moe={byteLength:function(i){var e=nz(i),t=e[0],s=e[1];return 3*(t+s)/4-s},toByteArray:function(i){var e,t,s=nz(i),r=s[0],n=s[1],o=new coe(function(c,u,d){return 3*(u+d)/4-d}(0,r,n)),a=0,l=n>0?r-4:r;for(t=0;t<l;t+=4)e=$n[i.charCodeAt(t)]<<18|$n[i.charCodeAt(t+1)]<<12|$n[i.charCodeAt(t+2)]<<6|$n[i.charCodeAt(t+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=255&e;return n===2&&(e=$n[i.charCodeAt(t)]<<2|$n[i.charCodeAt(t+1)]>>4,o[a++]=255&e),n===1&&(e=$n[i.charCodeAt(t)]<<10|$n[i.charCodeAt(t+1)]<<4|$n[i.charCodeAt(t+2)]>>2,o[a++]=e>>8&255,o[a++]=255&e),o},fromByteArray:function(i){for(var e,t=i.length,s=t%3,r=[],n=16383,o=0,a=t-s;o<a;o+=n)r.push(uoe(i,o,o+n>a?a:o+n));return s===1?(e=i[t-1],r.push(ba[e>>2]+ba[e<<4&63]+"==")):s===2&&(e=(i[t-2]<<8)+i[t-1],r.push(ba[e>>10]+ba[e>>4&63]+ba[e<<2&63]+"=")),r.join("")}},ba=[],$n=[],coe=typeof Uint8Array<"u"?Uint8Array:Array,MI="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Jp=0,hoe=MI.length;Jp<hoe;++Jp)ba[Jp]=MI[Jp],$n[MI.charCodeAt(Jp)]=Jp;function nz(i){var e=i.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=i.indexOf("=");return t===-1&&(t=e),[t,t===e?0:4-t%4]}function uoe(i,e,t){for(var s,r,n=[],o=e;o<t;o+=3)s=(i[o]<<16&16711680)+(i[o+1]<<8&65280)+(255&i[o+2]),n.push(ba[(r=s)>>18&63]+ba[r>>12&63]+ba[r>>6&63]+ba[63&r]);return n.join("")}$n["-".charCodeAt(0)]=62,$n["_".charCodeAt(0)]=63;const _a=oe("debugphysics"),II=oe("debugphysicscolliders"),TI=oe("debugcollisions"),doe=oe("showcolliders"),To=Symbol("needle component"),eo=Symbol("physics body"),poe=Symbol("rigidbody");let Kp;const N_=class{constructor(){h(this,"context"),h(this,"_initializePromise"),h(this,"_isInitialized",!1),h(this,"rapierRay",new noe({x:0,y:0,z:0},{x:0,y:0,z:1})),h(this,"raycastVectorsBuffer",new Bo(()=>new S,10)),h(this,"rapierSphere",null),h(this,"rapierColliderArray",[]),h(this,"rapierIdentityRotation",{x:0,y:0,z:0,w:1}),h(this,"rapierForwardVector",{x:0,y:0,z:1}),h(this,"enabled",!1),h(this,"_tempPosition",new S),h(this,"_tempQuaternion",new we),h(this,"_tempScale",new S),h(this,"_tempMatrix",new je),h(this,"_isUpdatingPhysicsWorld",!1),h(this,"world"),h(this,"_hasCreatedWorld",!1),h(this,"eventQueue"),h(this,"collisionHandler"),h(this,"objects",[]),h(this,"bodies",[]),h(this,"_meshCache",new Map),h(this,"_gravity",{x:0,y:-9.81,z:0}),h(this,"lines")}removeBody(i){var e,t;this.validate();const s=i[eo];if(i[eo]=null,s&&this.world){const r=this.objects.findIndex(n=>n===i);if(r>=0){const n=this.bodies[r];if(this.bodies.splice(r,1),this.objects.splice(r,1),n instanceof ooe){const o=n;(e=this.world)==null||e.removeCollider(o,!0);const a=o.parent();a&&a.numColliders()<=0&&((t=this.world)==null||t.removeRigidBody(a))}}}}updateBody(i,e,t){if(this.validate(),!!this.enabled&&!(i.destroyed||!i.gameObject)&&!(!e&&!t))if(i.isCollider===!0)console.warn("TODO: implement updating collider position");else{const s=i,r=s[eo];r&&this.syncPhysicsBody(s.gameObject,r,e,t)}}updateProperties(i){this.validate();const e=i[eo];e&&this.internalUpdateProperties(i,e)}addForce(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.addForce(e,t)}addImpulse(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.applyImpulse(e,t)}getLinearVelocity(i){this.validate();const e=this.internal_getRigidbody(i);return e?e.linvel():null}getAngularVelocity(i){this.validate();const e=this.internal_getRigidbody(i);return e?e.angvel():null}resetForces(i,e){this.validate();const t=this.internal_getRigidbody(i);t?.resetForces(e)}resetTorques(i,e){this.validate();const t=this.internal_getRigidbody(i);t?.resetTorques(e)}applyImpulse(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.applyImpulse(e,t)}wakeup(i){this.validate();const e=this.internal_getRigidbody(i);e?.wakeUp()}setAngularVelocity(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.setAngvel(e,t)}setLinearVelocity(i,e,t){this.validate();const s=this.internal_getRigidbody(i);s?.setLinvel(e,t)}async initialize(i){return this.context=i,this._initializePromise||(this._initializePromise=this.internalInitialization()),this._initializePromise}async internalInitialization(){return"env"in import.meta&&{}.VITE_NEEDLE_USE_RAPIER,!1}validate(){this._isInitialized||_a&&console.warn("Physics engine is not initialized")}raycast(i,e=void 0,t=1/0,s=!0){var r;const n=this.getPhysicsRay(this.rapierRay,i,e);if(!n)return null;const o=(r=this.world)==null?void 0:r.castRay(n,t,s,void 0,void 0,void 0,void 0,a=>{var l;return!((l=a[To])!=null&&l.gameObject.layers.isEnabled(2))});if(o){const a=n.pointAt(o.toi),l=this.raycastVectorsBuffer.get();return l.set(a.x,a.y,a.z),{point:l,collider:o.collider[To]}}return null}raycastAndGetNormal(i,e=void 0,t=1/0,s=!0){var r;const n=this.getPhysicsRay(this.rapierRay,i,e);if(!n)return null;const o=(r=this.world)==null?void 0:r.castRayAndGetNormal(n,t,s,void 0,void 0,void 0,void 0,a=>{var l;return!((l=a[To])!=null&&l.gameObject.layers.isEnabled(2))});if(o){const a=n.pointAt(o.toi),l=o.normal,c=this.raycastVectorsBuffer.get(),u=this.raycastVectorsBuffer.get();return c.set(a.x,a.y,a.z),u.set(l.x,l.y,l.z),{point:c,normal:u,collider:o.collider[To]}}return null}getPhysicsRay(i,e,t=void 0){var s,r;const n=(s=this.context)==null?void 0:s.mainCamera;if(e.z===void 0){if(!n)return console.error("Can not perform raycast from 2d point - no main camera found"),null;const l=this.raycastVectorsBuffer.get();l.x=e.x,l.y=e.y,l.z=0,(l.x>1||l.y>1||l.y<-1||l.x<-1)&&((r=this.context)==null||r.input.convertScreenspaceToRaycastSpace(l)),l.unproject(n),e=l}const o=e;i.origin.x=o.x,i.origin.y=o.y,i.origin.z=o.z;const a=this.raycastVectorsBuffer.get();if(t)a.set(t.x,t.y,t.z);else{if(!n)return console.error("Can not perform raycast - no camera found"),null;a.set(i.origin.x,i.origin.y,i.origin.z);const l=xt(n);a.sub(l)}return a.normalize(),i.dir.x=a.x,i.dir.y=a.y,i.dir.z=a.z,i}sphereOverlap(i,e){return this.rapierColliderArray.length=0,this.world?(this.rapierSphere||(this.rapierSphere=new CI(e)),this.rapierSphere.radius=e,this.world.intersectionsWithShape(i,this.rapierIdentityRotation,this.rapierSphere,t=>{const s=t[To],r=new LU(s.gameObject,s);return this.rapierColliderArray.push(r),!0},xI.EXCLUDE_SENSORS,void 0,void 0,void 0,t=>t[To].gameObject.layers.isEnabled(2)==!1),this.rapierColliderArray):this.rapierColliderArray}get isUpdating(){return this._isUpdatingPhysicsWorld}get gravity(){var i;return((i=this.world)==null?void 0:i.gravity)??this._gravity}set gravity(i){this.world?this.world.gravity=i:this._gravity=i}clearCaches(){this._meshCache.clear()}async addBoxCollider(i,e,t){if(this._isInitialized||await this.initialize(i.context),!i.activeAndEnabled)return;if(!this.enabled){_a&&console.warn("Physics are disabled");return}const s=i.gameObject,r=Us(s,this._tempPosition).multiply(t);r.multiplyScalar(.5),r.x<0&&(r.x=Math.abs(r.x)),r.y<0&&(r.y=Math.abs(r.y)),r.z<0&&(r.z=Math.abs(r.z)),r.x==0&&(r.x=1e-7),r.y==0&&(r.y=1e-7),r.z==0&&(r.z=1e-7);const n=Ri.cuboid(r.x,r.y,r.z);this.createCollider(i,n,e)}async addSphereCollider(i,e,t){if(this._isInitialized||await this.initialize(i.context),!i.activeAndEnabled)return;if(!this.enabled){_a&&console.warn("Physics are disabled");return}const s=i.gameObject,r=Us(s,this._tempPosition).multiplyScalar(t);r.x=Math.abs(r.x);const n=Ri.ball(r.x);this.createCollider(i,n,e)}async addCapsuleCollider(i,e,t,s){if(this._isInitialized||await this.initialize(i.context),!i.activeAndEnabled)return;if(!this.enabled){_a&&console.warn("Physics are disabled");return}const r=i.gameObject,n=Us(r,this._tempPosition);n.x=Math.abs(n.x),n.y=Math.abs(n.y);const o=Ri.capsule(t*.5*n.y-s,s*n.x);this.createCollider(i,o,e)}async addMeshCollider(i,e,t,s){var r;if(this._isInitialized||await this.initialize(i.context),!i.activeAndEnabled)return;if(!this.enabled){_a&&console.warn("Physics are disabled");return}const n=e.geometry;if(!n){_a&&console.warn("Missing mesh geometry",e.name);return}let o=n.getAttribute("position").array;const a=(r=n.index)==null?void 0:r.array;if(Math.abs(s.x-1)>1e-4||Math.abs(s.y-1)>1e-4||Math.abs(s.z-1)>1e-4){const c=n.uuid+"_"+s.x+"_"+s.y+"_"+s.z+"_"+t;if(this._meshCache.has(c))o=this._meshCache.get(c);else{console.warn("Your model is using scaled mesh colliders which is not optimal for performance",e.name,Object.assign({},s),e);const u=new Float32Array(o.length);for(let d=0;d<o.length;d+=3)u[d]=o[d]*s.x,u[d+1]=o[d+1]*s.y,u[d+2]=o[d+2]*s.z;o=u,this._meshCache.set(c,u)}}const l=t?Ri.convexMesh(o):Ri.trimesh(o,a);l&&this.createCollider(i,l).setMassProperties(1,{x:0,y:0,z:0},{x:0,y:0,z:0},{x:0,y:0,z:0,w:1})}createCollider(i,e,t){if(!this.world)throw new Error("Physics world not initialized");const s=this._tempMatrix,{rigidBody:r,useExplicitMassProperties:n}=this.getRigidbody(i,this._tempMatrix);s.decompose(this._tempPosition,this._tempQuaternion,this._tempScale),Us(i.gameObject,this._tempScale),t&&(t.multiply(this._tempScale),this._tempPosition.x-=t.x,this._tempPosition.y+=t.y,this._tempPosition.z+=t.z),e.setTranslation(this._tempPosition.x,this._tempPosition.y,this._tempPosition.z),e.setRotation(this._tempQuaternion),e.setSensor(i.isTrigger);const o=i.sharedMaterial;if(o){switch(e.setRestitution(o.bounciness),o.bounceCombine){case ea.Average:e.setRestitutionCombineRule(Zn.Average);break;case ea.Maximum:e.setRestitutionCombineRule(Zn.Max);break;case ea.Minimum:e.setRestitutionCombineRule(Zn.Min);break;case ea.Multiply:e.setRestitutionCombineRule(Zn.Multiply);break}switch(e.setFriction(o.dynamicFriction),o.frictionCombine){case ea.Average:e.setFrictionCombineRule(Zn.Average);break;case ea.Maximum:e.setFrictionCombineRule(Zn.Max);break;case ea.Minimum:e.setFrictionCombineRule(Zn.Min);break;case ea.Multiply:e.setFrictionCombineRule(Zn.Multiply);break}}const a=this.world.createCollider(e,r);return a[To]=i,i[eo]=a,a.setActiveEvents(wI.COLLISION_EVENTS),a.setActiveCollisionTypes(F_.ALL),this.objects.push(i),this.bodies.push(a),a}getRigidbody(i,e){if(!this.world)throw new Error("Physics world not initialized");let t=null,s=!1;if(i.attachedRigidbody){const r=i.attachedRigidbody;if(t=r[eo],s=!0,!t){const n=r.isKinematic&&!II;_a&&console.log("Create rigidbody",n);const o=n?Kp.RigidBodyDesc.kinematicPositionBased():Kp.RigidBodyDesc.dynamic(),a=xt(i.attachedRigidbody.gameObject);o.setTranslation(a.x,a.y,a.z),o.setRotation(xs(i.attachedRigidbody.gameObject)),t=this.world.createRigidBody(o),this.bodies.push(t),this.objects.push(r)}t[To]=r,r[eo]=t,this.internalUpdateProperties(r,t),this.getRigidbodyRelativeMatrix(i.gameObject,r.gameObject,e)}else{const r=Kp.RigidBodyDesc.kinematicPositionBased(),n=xt(i.gameObject);r.setTranslation(n.x,n.y,n.z),r.setRotation(xs(i.gameObject)),t=this.world.createRigidBody(r),e.identity(),t[To]=null}return i[poe]=t,{rigidBody:t,useExplicitMassProperties:s}}internal_getRigidbody(i){return i[eo]}internalUpdateProperties(i,e){e.enableCcd(i.collisionDetectionMode!==Ky.Discrete),e.setLinearDamping(i.drag),e.setAngularDamping(i.angularDrag),e.setGravityScale(i.useGravity?i.gravityScale:0,!0),e.setEnabledRotations(!i.lockRotationX,!i.lockRotationY,!i.lockRotationZ,!0),e.setEnabledTranslations(!i.lockPositionX,!i.lockPositionY,!i.lockPositionZ,!0),i.isKinematic?e.setBodyType(Kp.RigidBodyType.KinematicPositionBased):e.setBodyType(Kp.RigidBodyType.Dynamic)}step(i){this.world&&this.enabled&&(this._isUpdatingPhysicsWorld=!0,this.eventQueue||(this.eventQueue=new loe(!1)),i&&(this.world.timestep=Je.lerp(this.world.timestep,i,.8)),this.world.step(this.eventQueue),this._isUpdatingPhysicsWorld=!1,this.updateDebugRendering(this.world))}updateDebugRendering(i){var e;if(_a||II||doe){if(!this.lines){const s=new Vi({color:2258688}),r=new At;this.lines=new on(r,s),(e=this.context)==null||e.scene.add(this.lines)}const t=i.debugRender();this.lines.geometry.setAttribute("position",new rt(t.vertices,3)),this.lines.geometry.setAttribute("color",new rt(t.colors,4))}}postStep(){this.world&&this.enabled&&(this._isUpdatingPhysicsWorld=!0,this.syncObjects(),this._isUpdatingPhysicsWorld=!1,this.eventQueue&&!this.collisionHandler&&(this.collisionHandler=new foe(this.world,this.eventQueue)),this.collisionHandler&&(this.collisionHandler.handleCollisionEvents(),this.collisionHandler.update()))}syncObjects(){if(!II)for(let i=0;i<this.bodies.length;i++){const e=this.objects[i],t=this.bodies[i],s=e;if(s?.isCollider===!0&&!s.attachedRigidbody){const a=t.parent();a&&this.syncPhysicsBody(e.gameObject,a,!0,!0);continue}const r=t.translation(),n=t.rotation(),o=e.center;if(o&&o.isVector3){this._tempQuaternion.set(n.x,n.y,n.z,n.w);const a=this._tempPosition.copy(o).applyQuaternion(this._tempQuaternion),l=Us(e.gameObject);a.multiply(l),r.x-=a.x,r.y-=a.y,r.z-=a.z}Ad(e.gameObject,r.x,r.y,r.z),bB(e.gameObject,n.x,n.y,n.z,n.w)}}syncPhysicsBody(i,e,t,s){const r=xt(i,this._tempPosition),n=xs(i,this._tempQuaternion);switch(e.bodyType()){case xv.Fixed:case xv.KinematicPositionBased:case xv.KinematicVelocityBased:t&&e.setNextKinematicTranslation(r),s&&e.setNextKinematicRotation(n);break;default:t&&e.setTranslation(r,!1),s&&e.setRotation(n,!1);break}e.wakeUp()}getRigidbodyRelativeMatrix(i,e,t,s){if(s===void 0&&(s=N_._matricesBuffer,s.length=0),i===e){const r=Us(i,this._tempPosition);t.makeScale(r.x,r.y,r.z);for(let n=s.length-1;n>=0;n--)t.multiply(s[n]);return t}return s.push(i.matrix),i.parent&&this.getRigidbodyRelativeMatrix(i.parent,e,t,s),t}addFixedJoint(i,e){if(!this.world){console.error("Physics world not initialized");return}const t=i[eo],s=e[eo];this.calculateJointRelativeMatrices(i.gameObject,e.gameObject,this._tempMatrix),this._tempMatrix.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);const r=of.fixed(N_.centerConnectionPos,N_.centerConnectionRot,this._tempPosition,this._tempQuaternion),n=this.world.createImpulseJoint(r,t,s,!0);_a&&console.log("ADD FIXED JOINT",n)}addHingeJoint(i,e,t,s){if(!this.world){console.error("Physics world not initialized");return}const r=i[eo],n=e[eo];this.calculateJointRelativeMatrices(i.gameObject,e.gameObject,this._tempMatrix),this._tempMatrix.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);let o=Kp.JointData.revolute(t,this._tempPosition,s),a=this.world.createImpulseJoint(o,r,n,!0);_a&&console.log("ADD HINGE JOINT",a)}calculateJointRelativeMatrices(i,e,t){i.updateWorldMatrix(!0,!1),e.updateWorldMatrix(!0,!1);const s=i.matrixWorld,r=e.matrixWorld;s.elements[0]=1,s.elements[5]=1,s.elements[10]=1,r.elements[0]=1,r.elements[5]=1,r.elements[10]=1,t.copy(r).premultiply(s.invert()).invert()}};let wv=N_;h(wv,"_didLoadPhysicsEngine",!1),h(wv,"_matricesBuffer",[]),h(wv,"centerConnectionPos",{x:0,y:0,z:0}),h(wv,"centerConnectionRot",{x:0,y:0,z:0,w:1});class foe{constructor(e,t){h(this,"world"),h(this,"eventQueue"),h(this,"activeCollisions",[]),h(this,"activeCollisionsStay",[]),h(this,"activeTriggers",[]),this.world=e,this.eventQueue=t}handleCollisionEvents(){this.eventQueue&&this.world&&this.eventQueue.drainCollisionEvents((e,t,s)=>{const r=this.world.getCollider(e),n=this.world.getCollider(t),o=r[To],a=n[To];TI&&console.log("EVT",o.name,a.name,s,r,n),o&&a&&(s?(this.onCollisionStarted(o,r,a,n),this.onCollisionStarted(a,n,o,r)):(this.onCollisionEnded(o,a),this.onCollisionEnded(a,o)))})}update(){this.onHandleCollisionStay()}onCollisionStarted(e,t,s,r){let n=null;if(e.isTrigger||s.isTrigger)zh(e.gameObject,o=>{o.onTriggerEnter&&!o.destroyed&&o.onTriggerEnter(s),this.activeTriggers.push({collider:e,component:o,otherCollider:s})});else{const o=e.gameObject;this.world.contactPair(t,r,(a,l)=>{zh(o,c=>{var u;if(c.destroyed)return;const d=c.onCollisionEnter||c.onCollisionStay||c.onCollisionExit;if(d||TI){if(!n){const p=[],f=a.normal();for(let g=0;g<a.numSolverContacts();g++){const m=a.solverContactPoint(g),v=a.contactImpulse(g);if(m){const A=a.contactDist(g),b=a.solverContactFriction(g),y=new DU(m,A,f,v,b);p.push(y),TI&&Yo.DrawDirection(m,f,16711680,3,!0)}}n=new OU(o,s,p)}if(d){const p={collider:e,component:c,collision:n};this.activeCollisions.push(p),c.onCollisionStay&&this.activeCollisionsStay.push(p),(u=c.onCollisionEnter)==null||u.call(c,n)}}})})}}onHandleCollisionStay(){for(const e of this.activeCollisionsStay){const t=e.component;if(!t.destroyed&&t.activeAndEnabled&&t.onCollisionStay){const s=e.collision;t.onCollisionStay(s)}}for(const e of this.activeTriggers){const t=e.component;if(!t.destroyed&&t.activeAndEnabled&&t.onTriggerStay){const s=e.otherCollider;t.onTriggerStay(s)}}}onCollisionEnded(e,t){if(!(e.destroyed||t.destroyed)){for(let s=0;s<this.activeCollisions.length;s++){const r=this.activeCollisions[s],n=r.collider;if(n.destroyed){this.activeCollisions.splice(s,1),s--;continue}if(n===e&&r.collision.collider===t){const o=r.component;if(this.activeCollisions.splice(s,1),s--,o.activeAndEnabled&&o.onCollisionExit){const a=r.collision;o.onCollisionExit(a)}}}for(let s=0;s<this.activeCollisionsStay.length;s++){const r=this.activeCollisionsStay[s],n=r.collider;if(n.destroyed){this.activeCollisionsStay.splice(s,1),s--;continue}if(n===e&&r.collision.collider===t){const o=r.component;if(this.activeCollisionsStay.splice(s,1),s--,o.activeAndEnabled&&o.onCollisionExit){const a=r.collision;o.onCollisionExit(a)}}}for(let s=0;s<this.activeTriggers.length;s++){const r=this.activeTriggers[s],n=r.collider;if(n.destroyed){this.activeTriggers.splice(s,1),s--;continue}if(n===e&&r.otherCollider===t){const o=r.component;if(this.activeTriggers.splice(s,1),s--,o.activeAndEnabled&&o.onTriggerExit){const a=r.otherCollider;o.onTriggerExit(a)}}}}}}Object.defineProperty(Xt.prototype,"fov",{get:function(){return this._fov},set:function(i){const e=i!==this._fov;this._fov=i,e&&this.view!==void 0&&this.updateProjectionMatrix()}}),Object.defineProperty(Xt.prototype,"near",{get:function(){return this._near},set:function(i){const e=i!==this._near;this._near=i,e&&this.view!==void 0&&this.updateProjectionMatrix()}}),Object.defineProperty(Xt.prototype,"far",{get:function(){return this._far},set:function(i){const e=i!==this._far;this._far=i,e&&this.view!==void 0&&this.updateProjectionMatrix()}});function goe(i,e,t,s="image/webp",r){if(!r&&(r=i.mainCamera,!r))return console.error("No camera found"),null;const n=i.renderer.domElement.width,o=i.renderer.domElement.height;try{const a=i.renderer.domElement;return i.renderer.setSize(e,t),r instanceof Xt&&i.updateAspect(r,e,t),i.renderNow(),a.toDataURL(s)}finally{i.renderer.setSize(n,o),i.updateSize()}return null}Cz();const U_={Context:_t};globalThis.Needle!==void 0&&console.warn("Needle Engine is already imported"),globalThis.Needle=U_;function oz(i){for(const e in i)U_[e]=i[e]}oz(zq),oz(Pne),U_.$meta={version:ox,generator:$I};for(const i of Object.getOwnPropertyNames($))switch(i){case"prototype":case"constructor":case"length":case"name":continue;default:U_[i]=$[i];break}globalThis.THREE?console.warn("Threejs is already imported"):globalThis.THREE=e6;export{eoe as $physicsKey,ni as ActionBuilder,kS as ActionCollection,xo as ActionModel,xD as Addressables,Hg as AlignmentConstraint,Id as AmbientMode,yo as Animation,Jh as AnimationCurve,Hy as AnimationExtension,Mb as AnimationTrackHandler,jr as Animator,vc as AnimatorConditionMode,Ru as AnimatorController,zC as AnimatorControllerParameterType,my as AnimatorStateInfo,wm as Antialiasing,ED as Application,fy as ApplicationEvents,C2 as AssetDatabase,lr as AssetReference,ra as AttachedObject,Ab as AttachedObjectEvents,Tb as AudioExtension,gp as AudioListener,os as AudioSource,bm as AudioTrackHandler,ru as AvatarBlink_Simple,Ap as AvatarEyeLook_Rotation,Yy as AvatarLoader,hr as AvatarMarker,Xy as AvatarModel,Yg as Avatar_Brain_LookAt,Cm as Avatar_MouthShapes,NE as Avatar_MustacheShake,Rr as Avatar_POI,sp as Axes,yp as AxesHelper,Ro as BaseUIComponent,QE as BasicIKConstraint,Pb as BehaviorExtension,Ir as BehaviorModel,Ee as Behaviour,nu as Bloom,Em as BoxCollider,eu as BoxGizmo,Jo as BoxHelperComponent,xl as Button,qh as CallInfo,Ei as Camera,dr as Canvas,Cp as CanvasGroup,zc as CapsuleCollider,Rm as ChangeMaterialOnClick,cu as ChangeTransformOnClick,hu as CharacterController,Cl as CharacterControllerInput,km as ChromaticAberration,Bo as CircularBuffer,zF as ClearFlags,Uc as ClipExtrapolation,oa as Collider,OU as Collision,Ky as CollisionDetectionMode,Hc as ColorAdjustments,uu as ColorBySpeedModule,Om as ColorOverLifetimeModule,fc as Component,lg as ComponentEvents,cg as ComponentLifecycleEvents,e2 as ConnectionEvents,DU as ContactPoint,_t as Context,Fq as ContextArgs,$r as ContextEvent,ts as ContextRegistry,Ib as ControlTrackHandler,vl as ControllerEvents,hp as ControllerType,Yc as CustomBranding,bo as CustomShader,py as DefaultReflectionMode,lM as Deletable,Xb as DeleteBox,Io as DepthOfField,Yb as DeviceFlag,cM as DocumentExtension,Pp as DragControls,Fm as DropListener,fu as Duplicatable,By as EXTENSION_NAME,ha as EmissionModule,Mp as EmphasizeOnClick,EC as EngineLoadingView,Gr as EventList,Dy as EventListEvent,Hn as EventSystem,Zb as EventTrigger,CS as FieldWithDefault,sN as FileSpawnModel,iN as File_Event,yM as FixedJoint,bM as FlyControls,kp as Fog,cn as FrameEvent,$ as GameObject,Yo as Gizmos,Ol as GltfExport,MM as GltfExportBox,Iu as GltfLoadEvent,wU as GltfLoadEventType,Vc as Gradient,au as Graphic,PE as GraphicRaycaster,uo as Graphics,Op as GridHelper,$E as GridLayoutGroup,gu as GroundProjectedEnv,Mc as GroupActionModel,T2 as HideFlags,sM as HideOnStart,Nm as HingeJoint,ZE as HorizontalLayoutGroup,Q8 as HostData,xp as Image,dy as ImageReference,wD as ImageReferenceSerializer,qc as InheritVelocityModule,AB as Input,Uo as InputEvents,vu as InputField,Kr as InstancingUtil,n2 as InstantiateEvent,Lr as InstantiateIdProvider,Qo as InstantiateOptions,tp as Interactable,I8 as JoinedRoomResponse,b0 as KeyEventArgs,Qm as LODGroup,Au as LODModel,T8 as LeftRoomResponse,Yr as Light,SD as LightData,us as LimitVelocityOverLifetimeModule,Jq as LoadingElementOptions,RM as LogStats,ko as LogType,yu as LookAt,Wg as LookAtConstraint,Ws as MainModule,OE as MarkerType,Tm as MaskableGraphic,Je as Mathf,Mm as MeshCollider,Fy as MeshRenderer,tt as MinMaxCurve,Xr as MinMaxGradient,$I as NEEDLE_ENGINE_GENERATOR,ox as NEEDLE_ENGINE_VERSION,al as NEEDLE_progressive,yI as NeedleEngineHTMLElement,vI as NeedleGltfLoader,Z0 as NeedlePatchesKey,s_ as NestedGltf,i2 as NetworkConnection,pu as Networking,hi as NoiseModule,iu as ObjectRaycaster,bu as OffsetConstraint,Np as OpenURL,Nc as OrbitControls,_p as Outline,t2 as OwnershipEvent,V0 as OwnershipModel,jc as Padding,Dm as ParticleBurst,d_ as ParticleSubEmitter,$i as ParticleSystem,El as ParticleSystemRenderer,PB as Physics,ea as PhysicsMaterialCombine,Ym as PixelationEffect,Gc as PlayAnimationOnClick,Ip as PlayAudioOnClick,vm as PlayableDirector,Pu as PlayerColor,qp as PlayerState,_U as PlayerStateEvent,pI as PlayerSync,TD as PlayerView,RD as PlayerViewManager,tu as PointerEventData,vB as PointerType,Br as PostProcessingEffect,f_ as PostProcessingHandler,Rp as PreliminaryAction,Pm as PreliminaryTrigger,rL as ProgressiveLoadingInfo,vi as RGBAColor,wv as RapierPhysics,Fb as RawImage,po as RaycastOptions,fp as Raycaster,XE as Rect,ur as RectTransform,Xd as ReflectionProbe,Qy as RegisteredAnimationInfo,_u as RemoteSkybox,qd as RenderTexture,cL as RenderTextureSerializer,Ui as Renderer,CD as RendererData,Qg as RendererLightmap,Di as Rigidbody,Ji as RigidbodyConstraints,Fi as RoomEvents,fn as RotationBySpeedModule,Wn as RotationOverLifetimeModule,Py as SceneLightSettings,mn as SceneSwitcher,$m as ScreenCapture,Il as ScreenSpaceAmbientOcclusion,Ur as SendQueue,Ep as SetActiveOnClick,iv as ShadowCatcher,Ki as ShapeModule,gm as SignalAsset,vp as SignalReceiver,mp as SignalReceiverEvent,_m as SignalTrackHandler,qE as Size,kr as SizeBySpeedModule,Wc as SizeOverLifetimeModule,SS as SkinnedMeshRenderer,Zc as SmoothFollow,XM as SpatialHtml,nv as SpatialTrigger,ma as SpatialTriggerReceiver,b_ as SpectatorCamera,Sm as SphereCollider,RB as SphereIntersection,LU as SphereOverlapResult,Tl as Sprite,Hp as SpriteData,xu as SpriteRenderer,ov as SpriteSheet,h7 as StateMachineBehaviour,Xm as SubEmitterSystem,x_ as SyncedCamera,$c as SyncedRoom,Oc as SyncedTransform,nM as TapGestureTrigger,vb as TeleportTarget,rI as TestRunner,nI as TestSimulateUserData,Dr as Text,Wb as TextBuilder,qb as TextExtension,qs as TextureSheetAnimationModule,va as TiltShiftEffect,kB as Time,lv as ToneMapping,Am as TrackHandler,un as TrackType,Ii as TrailModule,Gy as TransformData,Su as TransformGizmo,Hr as TriggerBuilder,Yh as TriggerModel,Q as TypeStore,cp as UIRaycastUtils,om as UIRootComponent,Ko as USDObject,Xn as USDZExporter,Xc as USDZText,gC as Upload_Result,hL as UriSerializer,ip as UsageMarker,R8 as UserJoinedOrLeftRoomModel,Al as VRUserState,BS as VariantAction,Oi as VelocityOverLifetimeModule,KE as VerticalLayoutGroup,Js as VideoPlayer,Ho as ViewDevice,Eu as Vignette,Bm as VisibilityAction,kl as Voip,I_ as Volume,Dt as VolumeParameter,xm as VolumeProfile,Xse as WaitForFrames,$N as WaitForSeconds,$p as Watch,um as WebAR,R_ as WebARCameraBackground,Pc as WebARSessionRoot,wt as WebXR,kc as WebXRAvatar,cs as WebXRController,_i as WebXREvent,B_ as WebXRImageTracking,Rl as WebXRImageTrackingModel,k_ as WebXRPlaneTracking,cm as WebXRSync,Mu as WebXRTrackedImage,Tr as XRFlag,D_ as XRGrabModel,uI as XRGrabRendering,yb as XRRig,Sg as XRSessionMode,Zo as XRState,as as XRStateFlag,dI as __Ignore,M2 as __internalNotifyObjectDestroyed,Pa as activeInHierarchyFieldName,xX as addCustomExtension,uM as addFile,rN as addFileFromUrl,jne as addGltfLoadEventListener,lc as addNewComponent,Z8 as addPatch,J0 as apply,$ne as applyChanges,l2 as beginListenDestroy,nN as beginListenFileSpawn,c2 as beginListenInstantiate,Lq as build_scene_functions,oh as builtinComponentKeyName,CC as calculateProgress01,MX as colorSerializer,Oy as componentSerializer,IB as copyTexture,AI as createGLTFLoader,ZD as createMotion,xr as debugNet,ag as debugOwner,jv as deepClone,uf as delay,y0 as deserializeObject,cc as destroy,m2 as destroyComponentInstance,FF as detectARSupport,NF as detectVRSupport,go as disposeObjectResources,yD as download,vC as download_file,pf as editorGuidKeyName,QM as effectsOrder,BX as eventListSerializer,MU as findAnimations,Gne as findAnimationsLate,vg as findByGuid,y2 as findObjectOfType,b2 as findObjectsOfType,Z1 as findUsers,zh as foreachComponent,eC as foreachComponentEnumerator,T6 as forward,X0 as generateSeed,xd as getComponent,wd as getComponentInChildren,dg as getComponentInParent,hg as getComponents,ug as getComponentsInChildren,Y0 as getComponentsInParent,_z as getIp,xz as getIpAndLocation,bz as getIpCloudflare,vo as getLoader,J1 as getOrAddComponent,oe as getParam,gz as getPath,cf as getUrlParams,nW as getUserCount,P6 as getWorldDirection,SB as getWorldEuler,xt as getWorldPosition,xs as getWorldQuaternion,E1 as getWorldRotation,Us as getWorldScale,gc as hasProLicense,mC as hash,Ag as instantiate,R2 as isActiveInHierarchy,Cd as isActiveSelf,MB as isAnimationAction,dz as isDebugMode,$1 as isDestroyed,Rn as isDevEnvironment,WI as isHostedOnGlitch,Yne as isHotReloading,gr as isLocalNetwork,nh as isMobileDevice,tx as isMozillaXR,Az as isQuest,Ta as isSafari,E2 as isUsageTrackingEnabled,ty as isUsingInstancing,df as isiOS,EU as loadSync,w0 as logHierarchy,S6 as lookAtInverse,fz as makeId,GI as makeIdFromRandomWords,P2 as markAsInstancedRendered,K1 as moveComponentInstance,uz as nameof,zv as nameofFactory,lL as objectSerializer,SU as parseSync,tJ as prefix,UI as pushState,zI as randomNumber,Jne as register,gy as registerComponent,xS as registerComponentExtension,oL as registerExtensions,AC as registerLoader,u2 as registerPrefabProvider,VI as relativePathPrefix,Y1 as removeComponent,wX as removeCustomExtension,Qne as removeGltfLoadEventListener,$8 as removePatch,Ll as resolveUrl,HI as sanitizeString,goe as screenshot,a2 as sendDestroyed,x as serializable,fB as serializeObject,Rd as serializeable,mg as setActive,k2 as setDestroyed,hf as setOrAddParamsToUrl,pz as setParam,NI as setParamWithoutReload,ex as setState,sW as setUsageTrackingEnabled,EB as setWorldEuler,rs as setWorldPosition,Ad as setWorldPositionXYZ,Fr as setWorldQuaternion,bB as setWorldQuaternionXYZW,k6 as setWorldRotation,x0 as setWorldRotationXYZ,S1 as setWorldScale,Ns as showBalloonMessage,ho as showBalloonWarning,m1 as showDebugConsole,yB as slerp,q0 as syncDestroy,VM as syncField,q1 as syncInstantiate,D6 as textureToCanvas,Bu as tryFindObject,IU as tryFindObjectByName,Hne as tryFindScript,Kne as unregister,AD as upload_file,ta as validate};