@needle-tools/engine 4.5.0-alpha.2 → 4.5.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/dist/{needle-engine.bundle-53f80c62.js → needle-engine.bundle-1b8f44f4.js} +218 -198
- package/dist/{needle-engine.bundle-15b19b2c.light.min.js → needle-engine.bundle-56f095f1.light.min.js} +3 -3
- package/dist/{needle-engine.bundle-f3c8cffc.light.umd.cjs → needle-engine.bundle-9fe9a394.light.umd.cjs} +5 -5
- package/dist/{needle-engine.bundle-2024e2b3.min.js → needle-engine.bundle-baacde19.min.js} +3 -3
- package/dist/{needle-engine.bundle-1526f05b.light.js → needle-engine.bundle-d710d96f.light.js} +26 -6
- package/dist/{needle-engine.bundle-a52706c5.umd.cjs → needle-engine.bundle-ef2b8438.umd.cjs} +5 -5
- package/dist/needle-engine.js +2 -2
- package/dist/needle-engine.light.js +2 -2
- package/dist/needle-engine.light.min.js +1 -1
- package/dist/needle-engine.light.umd.cjs +1 -1
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/engine_context_registry.d.ts +2 -2
- package/lib/engine/engine_context_registry.js +2 -2
- package/lib/engine/engine_context_registry.js.map +1 -1
- package/lib/engine-components/ContactShadows.d.ts +12 -0
- package/lib/engine-components/ContactShadows.js +23 -0
- package/lib/engine-components/ContactShadows.js.map +1 -1
- package/lib/engine-components/webxr/controllers/XRControllerModel.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_context_registry.ts +2 -2
- package/src/engine-components/ContactShadows.ts +24 -0
- package/src/engine-components/webxr/controllers/XRControllerModel.ts +0 -2
|
@@ -130,7 +130,7 @@ Open this page to get the console: `+t.toString())}const n=Q.isMobileDevice()||Q
|
|
|
130
130
|
#__vconsole .vc-mask {
|
|
131
131
|
overflow: hidden;
|
|
132
132
|
}
|
|
133
|
-
`,Gi?.prepend(s),n===!0&&Em()<=0&&nb(),console.log("\u{1F335} Debug console has loaded")}},t.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),nc=!1,ri=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function CP(){if(!globalThis.VConsole)return;const n=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+n._id+" iframe");return n.on("renderTab",function(i){const s=globalThis["needle:codegen_files"];if(!s||s.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);n.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';i(h)}),n.on("show",function(){const i=t();i&&i.src!==n.fullUrl&&(i.src=n.fullUrl)}),n.on("hide",function(){const i=t();i&&(i.src="")}),n.on("addTopBar",function(i){var s=new Array;s.push({name:"Open in new window \u2197",onClick:function(o){window.open(n.fullUrl,"_blank"),ri?.hide()}}),s.push({name:"Reload",onClick:function(o){const r=t();r&&(r.src=n.fullUrl)}}),s.push({name:"Fullscreen",onClick:function(o){const r=t();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),i(s)}),n}function OP(){return document.querySelector("#__vconsole .vc-switch")||null}function PP(){return document.querySelector("#__vconsole")||null}const ab=C("debugdefines");fo('if(!globalThis[""4.5.0-alpha.
|
|
133
|
+
`,Gi?.prepend(s),n===!0&&Em()<=0&&nb(),console.log("\u{1F335} Debug console has loaded")}},t.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),nc=!1,ri=null},t.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(t)}function CP(){if(!globalThis.VConsole)return;const n=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),t=()=>document.querySelector("#__vc_plug_"+n._id+" iframe");return n.on("renderTab",function(i){const s=globalThis["needle:codegen_files"];if(!s||s.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);n.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';i(h)}),n.on("show",function(){const i=t();i&&i.src!==n.fullUrl&&(i.src=n.fullUrl)}),n.on("hide",function(){const i=t();i&&(i.src="")}),n.on("addTopBar",function(i){var s=new Array;s.push({name:"Open in new window \u2197",onClick:function(o){window.open(n.fullUrl,"_blank"),ri?.hide()}}),s.push({name:"Reload",onClick:function(o){const r=t();r&&(r.src=n.fullUrl)}}),s.push({name:"Fullscreen",onClick:function(o){const r=t();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),i(s)}),n}function OP(){return document.querySelector("#__vconsole .vc-switch")||null}function PP(){return document.querySelector("#__vconsole")||null}const ab=C("debugdefines");fo('if(!globalThis[""4.5.0-alpha.3""]) globalThis[""4.5.0-alpha.3""] = "0.0.0";'),fo('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),fo('if(!globalThis[""Mon May 12 2025 21:25:04 GMT+0700 (Indochina Time)""]) globalThis[""Mon May 12 2025 21:25:04 GMT+0700 (Indochina Time)""] = "unknown";'),fo('if(!globalThis[""npk_ad8e492e31253a2800d563522e42a7311d0d7b766ac4ec1f64d3b425f06eacbd""]) globalThis[""npk_ad8e492e31253a2800d563522e42a7311d0d7b766ac4ec1f64d3b425f06eacbd""] = "unknown";'),fo('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.5.0-alpha.3";'),fo('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),fo('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon May 12 2025 21:25:04 GMT+0700 (Indochina Time)";'),fo('globalThis["__NEEDLE_PUBLIC_KEY__"] = "npk_ad8e492e31253a2800d563522e42a7311d0d7b766ac4ec1f64d3b425f06eacbd";');const bn="4.5.0-alpha.3",Pd="undefined",Ym="Mon May 12 2025 21:25:04 GMT+0700 (Indochina Time)";ab&&console.log(`Engine version: ${bn} (generator: ${Pd})
|
|
134
134
|
Project built at ${Ym}`);const oc="npk_ad8e492e31253a2800d563522e42a7311d0d7b766ac4ec1f64d3b425f06eacbd",Os="needle_isActiveInHierarchy",pr="builtin_components",rc="needle_editor_guid";function fo(n){try{(0,eval)(n)}catch(t){ab&&console.error(t)}}let lb,cb=null;function _n(){return lb}function Km(n){if(n==null){console.warn("Oh no: someone tried registering a non-existend gltf-loader. When you see this log it might mean that needle-engine is being imported multiple times. Please check your project setup.");return}cb!==n&&(cb=n,lb=new n)}const ki=Symbol("shadowDomOwner"),kP=C("debugpatch");function kd(n,t,i,s){const o=kP===t;if(!i&&!s)return;const r=t+"___needle";RP(n,t,i,s);const l=Object.getOwnPropertyDescriptor(n,t),c=n[t];o&&console.log("Patch",n.constructor.name,t,l,c),l?(o&&console.log("Apply patch with existing descriptor",n.constructor.name,t,l),typeof l.value=="function"&&(n[t]=db(l.value,n,t))):(o&&console.log("Create patch with new property",n.constructor.name,t,l),Object.defineProperty(n,t,{set:function(h){if(typeof h=="function")this[r]=db(h,n,t);else{const d=this[r];ub(n,t,this,d,h),this[r]=h,pb(n,t,this,d,h)}},get:function(){const h=this[r];return typeof h=="function"&&h[r]?h[r]:h}}))}function MP(n,t,i){const s=Jm(n,t);if(s)for(let o=s.length-1;o>=0;o--){const r=s[o];r.prefix===i&&(r.prefix=null),r.postfix===i&&(r.postfix=null),!r.prefix&&!r.postfix&&s.splice(o,1)}}const hb=Symbol("Needle:Patches:WrappedFunction");function db(n,t,i){if(n[hb])return n;const s=function(...o){ub(t,i,this,...o);const r=n.apply(this,o);return pb(t,i,this,r,...o),r};return s[hb]=!0,s}const Md="Needle:Patches";function Zm(){return globalThis[Md]||(globalThis[Md]=new WeakMap),globalThis[Md]}function Jm(n,t){const i=Zm().get(n);return i?i.get(t):null}function RP(n,t,i,s){let o=Zm().get(n);o||(o=new Map,Zm().set(n,o));let r=o.get(t);r||(r=[],o.set(t,r)),r.push({prefix:i,postfix:s})}function ub(n,t,i,...s){var o;if(!i)return;const r=Jm(n,t);if(r)for(const l of r)(o=l.prefix)==null||o.call(i,...s)}function pb(n,t,i,s,...o){var r;if(!i)return;const l=Jm(n,t);if(l)for(const c of l)(r=c.postfix)==null||r.call(i,s,...o)}const xa=[];function Rd(n){xa.indexOf(n)===-1&&xa.push(n)}function TP(n){const t=xa.indexOf(n);t!==-1&&xa.splice(t,1)}const Sa=[];function eg(n){Sa.indexOf(n)===-1&&Sa.push(n)}function EP(n){const t=Sa.indexOf(n);t!==-1&&Sa.splice(t,1)}function mb(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:n}));for(let t=0;t<xa.length;t++)xa[t](n)}function gb(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:n}));for(let t=0;t<Sa.length;t++)Sa[t](n)}const dt=C("debuginput");var Td=(n=>(n.Mouse="mouse",n.Touch="touch",n.Controller="controller",n.Hand="hand",n))(Td||{}),Fe=(n=>(n.PointerDown="pointerdown",n.PointerUp="pointerup",n.PointerMove="pointermove",n.KeyDown="keydown",n.KeyUp="keyup",n.KeyPressed="keypress",n))(Fe||{});class Ps extends PointerEvent{constructor(t,i,s){super(t,s),a(this,"clientZ"),a(this,"deviceIndex"),a(this,"origin"),a(this,"source"),a(this,"mode"),a(this,"_ray"),a(this,"space"),a(this,"isClick",!1),a(this,"isDoubleClick",!1),a(this,"_used",!1),a(this,"_pointerid"),a(this,"_pointerType"),a(this,"_type"),a(this,"metadata",{}),a(this,"intersections",new Array),a(this,"_immediatePropagationStopped",!1),a(this,"_propagationStopped",!1),this.clientZ=s.clientZ,this._pointerid=s.pointerId,this._pointerType=s.pointerType,this._type=t,this.deviceIndex=s.deviceIndex,this.origin=s.origin,this.source=i,this.mode=s.mode,this._ray=s.ray,this.space=s.device}get isSpatial(){return this.mode!="screen"}get ray(){return this._ray||(this._ray=new co(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(t){this._ray=t}get hasRay(){return this._ray!==void 0}get used(){return this._used}use(){this._used=!0}get pointerId(){return this._pointerid}get pointerType(){return this._pointerType}get type(){return this._type}get immediatePropagationStopped(){return this._immediatePropagationStopped}get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){var t;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(t=this.source)==null||t.stopImmediatePropagation()}stopPropagation(){var t;this._propagationStopped=!0,super.stopPropagation(),(t=this.source)==null||t.stopPropagation(),dt&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class ac extends KeyboardEvent{constructor(t,i,s){super(t,s),a(this,"source"),this.source=i}stopImmediatePropagation(){var t;super.stopImmediatePropagation(),(t=this.source)==null||t.stopImmediatePropagation()}}class AP{constructor(t){a(this,"key"),a(this,"keyType"),a(this,"source"),this.key=t.key,this.keyType=t.type,this.source=t}}var ai=(n=>(n[n.Early=-100]="Early",n[n.Default=0]="Default",n[n.Late=100]="Late",n))(ai||{});class fb{constructor(t){a(this,"_eventListeners",{}),a(this,"_doubleClickTimeThreshold",.2),a(this,"_longPressTimeThreshold",1),a(this,"_setCursorTypes",[]),a(this,"context"),a(this,"_pointerDown",[!1]),a(this,"_pointerUp",[!1]),a(this,"_pointerClick",[!1]),a(this,"_pointerDoubleClick",[!1]),a(this,"_pointerPressed",[!1]),a(this,"_pointerPositions",[new re]),a(this,"_pointerPositionsLastFrame",[new re]),a(this,"_pointerPositionsDelta",[new re]),a(this,"_pointerPositionsRC",[new re]),a(this,"_pointerPositionDown",[new x]),a(this,"_pointerDownTime",[]),a(this,"_pointerUpTime",[]),a(this,"_pointerUpTimestamp",[]),a(this,"_pointerIds",[]),a(this,"_pointerTypes",[""]),a(this,"_mouseWheelChanged",[!1]),a(this,"_mouseWheelDeltaY",[0]),a(this,"_pointerEvent",[]),a(this,"_pointerEventsPressed",[]),a(this,"_pointerSpace",[]),a(this,"_pressedStack",new Map),a(this,"_htmlEventSource"),a(this,"onLostFocus",()=>{for(const i in this.keysPressed)this.keysPressed[i].pressed=!1}),a(this,"_receivedPointerMoveEventsThisFrame",new Array),a(this,"onEndOfFrame",()=>{this._receivedPointerMoveEventsThisFrame.length=0;for(let i=0;i<this._pointerUp.length;i++)this._pointerUp[i]=!1;for(let i=0;i<this._pointerDown.length;i++)this._pointerDown[i]=!1;for(let i=0;i<this._pointerClick.length;i++)this._pointerClick[i]=!1;for(let i=0;i<this._pointerDoubleClick.length;i++)this._pointerDoubleClick[i]=!1;for(const i of this._pointerPositionsDelta)i.set(0,0);for(let i=0;i<this._mouseWheelChanged.length;i++)this._mouseWheelChanged[i]=!1;for(let i=0;i<this._mouseWheelDeltaY.length;i++)this._mouseWheelDeltaY[i]=0}),a(this,"onContextMenu",i=>{this.canReceiveInput(i)!==!1&&i instanceof PointerEvent&&i.pointerType}),a(this,"keysPressed",{}),a(this,"onKeyDown",i=>{if(dt&&console.log(`key down ${i.code}, ${this.context.application.hasFocus}`,i),!this.context.application.hasFocus)return;const s=this.keysPressed[i.code];if(s&&s.pressed)return;this.keysPressed[i.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:i.key,code:i.code};const o=new ac("keydown",i,i);this.onDispatchEvent(o)}),a(this,"onKeyPressed",i=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[i.code];if(!s)return;s.pressed=!0,s.frame=this.context.time.frameCount+1;const o=new ac("keypress",i,i);this.onDispatchEvent(o)}),a(this,"onKeyUp",i=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[i.code];if(!s)return;s.pressed=!1,s.frame=this.context.time.frameCount+1;const o=new ac("keyup",i,i);this.onDispatchEvent(o)}),a(this,"onWheelWindow",i=>{document.pointerLockElement&&this.onMouseWheel(i)}),a(this,"onMouseWheel",i=>{if(this.canReceiveInput(i)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const s=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=s+i.deltaY}),a(this,"onPointerDown",i=>{if(this.context.isInAR||this.canReceiveInput(i)===!1)return;i.target instanceof HTMLElement&&i.target.setPointerCapture(i.pointerId);const s=this.getPointerId(i);dt&&Be(`pointer down #${s}, identifier:${i.pointerId}`);const o=this.getAndUpdateSpatialObjectForScreenPosition(s,i.clientX,i.clientY),r=new Ps("pointerdown",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:i.button,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:o,pressure:i.pressure});this.onDown(r)}),a(this,"onPointerMove",i=>{if(this.context.isInAR||this._receivedPointerMoveEventsThisFrame.includes(i.pointerId))return;this._receivedPointerMoveEventsThisFrame.push(i.pointerId);let s=i.button;i.pointerType==="mouse"&&(s=this.getFirstPressedButtonForPointer(0)??0);const o=this.getPointerId(i,s);s===-1&&(s=o);const r=this.getAndUpdateSpatialObjectForScreenPosition(o,i.clientX,i.clientY),l=new Ps("pointermove",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:o,button:s,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:r,pressure:i.pressure});this.onMove(l)}),a(this,"onPointerCancel",i=>{this.context.isInAR||(dt&&console.log("Pointer cancel",i),this.onPointerUp(i))}),a(this,"onPointerUp",i=>{if(this.context.isInAR)return;i.target instanceof HTMLElement&&i.target.releasePointerCapture(i.pointerId);const s=this.getPointerId(i),o=new Ps("pointerup",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:i.button,clientX:i.clientX,clientY:i.clientY,pointerType:i.pointerType,buttonName:this.getButtonName(i),device:this.getAndUpdateSpatialObjectForScreenPosition(s,i.clientX,i.clientY),pressure:i.pressure});this.onUp(o),this._pointerIds[s]=-1,dt&&console.log("ID="+s,"PointerId="+i.pointerId,"ALL:",[...this._pointerIds])}),a(this,"onTouchStart",i=>{if(this.context.isInAR)for(let s=0;s<i.changedTouches.length;s++){const o=i.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new Ps("pointerdown",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onDown(c)}}),a(this,"onTouchMove",i=>{if(this.context.isInAR)for(let s=0;s<i.changedTouches.length;s++){const o=i.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new Ps("pointermove",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onMove(c)}}),a(this,"onTouchEnd",i=>{if(this.context.isInAR)for(let s=0;s<i.changedTouches.length;s++){const o=i.changedTouches[s],r=this.getPointerIndex(o.identifier),l=new Ps("pointerup",i,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),pressure:o.force});this.onUp(l),this._pointerIds[r]=-1}}),a(this,"tempNearPlaneVector",new x),a(this,"tempFarPlaneVector",new x),a(this,"tempLookMatrix",new se),this.context=t,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(t,i,s){if(this._eventListeners[t]||(this._eventListeners[t]=[]),!i||typeof i!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}s?s={...s}:s={};let o=0;s?.queue!=null&&(o=s.queue);const r=this._eventListeners[t],l=r.find(c=>c.priority===o);l?l.listeners.push({callback:i,options:s}):(r.push({priority:o,listeners:[{callback:i,options:s}]}),r.sort((c,h)=>c.priority-h.priority))}removeEventListener(t,i,s){if(!this._eventListeners[t]||!i)return;const o=this._eventListeners[t];if(s?.queue!=null){const r=o.find(c=>c.priority===s.queue);if(!r)return;const l=r.listeners.findIndex(c=>c.callback===i);l>=0&&r.listeners.splice(l,1)}else for(const r of o){const l=r.listeners.findIndex(c=>c.callback===i);l>=0&&r.listeners.splice(l,1)}}dispatchEvent(t){var i,s,o,r;let l=!1;if(t instanceof ac){const c=this._eventListeners[t.type];if(c)for(const h of c)for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((s=(i=u.options)==null?void 0:i.signal)!=null&&s.aborted){h.listeners.splice(d,1),d--;continue}u.options.once&&(h.listeners.splice(d,1),d--),u.callback(t)}}if(t instanceof Ps){const c=this._eventListeners[t.type];if(c)for(const h of c){if(l)break;for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((r=(o=u.options)==null?void 0:o.signal)!=null&&r.aborted){h.listeners.splice(d,1),d--;continue}if(t.immediatePropagationStopped){l=!0,dt&&console.log("immediatePropagationStopped",t.type);break}else t.propagationStopped&&(l=!0,dt&&console.log("propagationStopped",t.type));u.options.once&&(h.listeners.splice(d,1),d--),u.callback(t)}}}}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}get click(){return this._pointerClick[0]}get doubleClick(){return this._pointerDoubleClick[0]}getGamepad(t=0){return typeof navigator<"u"&&"getGamepads"in navigator&&navigator.getGamepads()[t]||null}setCursorPointer(){this.setCursor("pointer")}setCursorNormal(){this.unsetCursor("pointer")}setCursor(t){this._setCursorTypes.push(t),this._setCursorTypes.length>10&&this._setCursorTypes.shift(),this.updateCursor()}unsetCursor(t){for(let i=this._setCursorTypes.length-1;i>=0;i--)if(this._setCursorTypes[i]===t){this._setCursorTypes.splice(i,1),this.updateCursor();break}}updateCursor(){var t;((t=this._setCursorTypes)==null?void 0:t.length)==0?this.context.domElement.style.cursor="default":this.context.domElement.style.cursor=this._setCursorTypes[this._setCursorTypes.length-1]}getIsPointerIdInUse(t){for(const i of this._pointerEventsPressed)if(i.pointerId===t&&i.used)return!0;return!1}getPointerPressedCount(){let t=0;for(let i=0;i<this._pointerPressed.length;i++)this._pointerPressed[i]&&t++;return t}getPointerPosition(t){return t>=this._pointerPositions.length?null:this._pointerPositions[t]}getPointerPositionLastFrame(t){return t>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[t]}getPointerPositionDelta(t){return t>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[t]}getPointerPositionRC(t){return t>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[t]}getPointerDown(t){return t>=this._pointerDown.length?!1:this._pointerDown[t]}getPointerUp(t){return t>=this._pointerUp.length?!1:this._pointerUp[t]}getPointerPressed(t){return t>=this._pointerPressed.length?!1:this._pointerPressed[t]}getPointerClicked(t){return t>=this._pointerClick.length?!1:this._pointerClick[t]}getPointerDoubleClicked(t){return t>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[t]}getPointerDownTime(t){return t>=this._pointerDownTime.length?-1:this._pointerDownTime[t]}getPointerUpTime(t){return t>=this._pointerUpTime.length?-1:this._pointerUpTime[t]}getPointerLongPress(t){return t>=this._pointerDownTime.length?!1:this.getPointerPressed(t)&&this.context.time.time-this._pointerDownTime[t]>this._longPressTimeThreshold}getIsMouse(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="mouse"}getIsTouch(t){return t<0||t>=this._pointerTypes.length?!1:this._pointerTypes[t]==="touch"}getTouchesPressedCount(){let t=0;for(let i=0;i<this._pointerPressed.length;i++)this._pointerPressed[i]&&this.getIsTouch(i)&&t++;return t}getMouseWheelChanged(t=0){return t>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[t]}getMouseWheelDeltaY(t=0){return t>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[t]}getPointerEvent(t){if(!(t>=this._pointerEvent.length))return this._pointerEvent[t]??void 0}*foreachPointerId(t){for(let i=0;i<this._pointerTypes.length;i++)if(this._pointerIsActive(i)){if(t!==void 0){const s=this._pointerTypes[i];if(Array.isArray(t)){let o=!1;for(const r of t)if(s===r){o=!0;break}if(!o)continue}else if(t!==s)continue}yield i}}*foreachTouchId(){for(let t=0;t<this._pointerTypes.length;t++)this._pointerTypes[t]==="touch"&&this._pointerIsActive[t]&&(yield t)}_pointerIsActive(t){return t<0?!1:this._pointerPressed[t]||this._pointerDown[t]||this._pointerUp[t]}onDownButton(t,i){let s=this._pressedStack.get(t);s||(s=[],this._pressedStack.set(t,s)),s.push(i)}onReleaseButton(t,i){const s=this._pressedStack.get(t);if(!s)return;const o=s.indexOf(i);o>=0&&s.splice(o,1)}getFirstPressedButtonForPointer(t){const i=this._pressedStack.get(t);if(i)return i[0]}getLatestPressedButtonForPointer(t){const i=this._pressedStack.get(t);if(i)return i[i.length-1]}getKeyDown(t){if(t!==void 0)return this.isKeyDown(t);for(const i in this.keysPressed){const s=this.keysPressed[i];if(s.startFrame===this.context.time.frameCount)return s.key}return null}getKeyPressed(t){if(t!==void 0)return this.isKeyPressed(t);for(const i in this.keysPressed){const s=this.keysPressed[i];if(s.pressed)return s.key}return null}getKeyUp(t){if(t!==void 0)return this.isKeyUp(t);for(const i in this.keysPressed){const s=this.keysPressed[i];return s.pressed===!1&&s.frame===this.context.time.frameCount}return null}isKeyDown(t){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(t);if(i!==null){for(const o of i)if(this.isKeyDown(o))return!0;return!1}const s=this.keysPressed[t];return s?s.startFrame===this.context.time.frameCount&&s.pressed:!1}isKeyUp(t){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(t);if(i!==null){for(const o of i)if(this.isKeyUp(o))return!0;return!1}const s=this.keysPressed[t];return s?s.frame===this.context.time.frameCount&&s.pressed===!1:!1}isKeyPressed(t){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(t);if(i!==null){for(const o of i)if(this.isKeyPressed(o))return!0;return!1}const s=this.keysPressed[t];return s&&s.pressed||!1}getCodeForCommonKeyName(t){if(t.length===1){if(t>="0"&&t<="9")return["Digit"+t];if(t>="a"&&t<="z")return["Key"+t.toUpperCase()];if(t==" ")return["Space"]}switch(t){case"shift":case"Shift":return["ShiftLeft","ShiftRight"];case"control":case"Control":return["ControlLeft","ControlRight"];case"alt":case"Alt":return["AltLeft","AltRight"]}return null}createInputEvent(t){switch(t.type){case"pointerdown":dt&&Be("Create Pointer down"),this.onDownButton(t.deviceIndex,t.button),this.onDown(t);break;case"pointermove":dt&&Be("Create Pointer move"),this.onMove(t);break;case"pointerup":dt&&Be("Create Pointer up"),this.onUp(t),this.onReleaseButton(t.deviceIndex,t.button);break}}convertScreenspaceToRaycastSpace(t){return t.x=(t.x-this.context.domX)/this.context.domWidth*2-1,t.y=-((t.y-this.context.domY)/this.context.domHeight)*2+1,t}bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){var t,i;window.removeEventListener("contextmenu",this.onContextMenu),(t=this._htmlEventSource)==null||t.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),window.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("touchend",this.onTouchEnd),(i=this._htmlEventSource)==null||i.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const t=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);t>=0&&this.context.post_render_callbacks.splice(t,1),this.unbindEvents()}canReceiveInput(t){var i;return t.target===((i=this.context.renderer)==null?void 0:i.domElement)||t.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&t.target===document.body&&Q.isMozillaXR()?!0:(dt&&console.warn("CanReceiveInput:False for",t.target),!1)}getPointerId(t,i){return t.pointerType==="mouse"?0+(i??t.button):this.getPointerIndex(t.pointerId)}getButtonName(t){const i=t.button;if(t.pointerType==="mouse")switch(i){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(t,i,s){let o=this._pointerSpace[t];o||(o=new A,this._pointerSpace[t]=o),this._pointerSpace[t]=o;const r=this.context.mainCamera;if(r){const l=this.tempNearPlaneVector.set(i,s,-1);this.convertScreenspaceToRaycastSpace(l);const c=this.tempFarPlaneVector.set(l.x,l.y,1);l.unproject(r),c.unproject(r);const h=r.worldUp||q(0,1,0).applyQuaternion(Ce(r));this.tempLookMatrix.lookAt(c,l,h),o.position.set(l.x,l.y,l.z),o.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return o}isInRect(t){if(this.context.isInXR)return!0;const i=this.context.domElement.getBoundingClientRect(),s=t.clientX,o=t.clientY,r=s>=i.x&&s<=i.right&&o>=i.y&&o<=i.bottom;return dt&&!r&&console.log("Not in rect",i,s,o),r}onDown(t){const i=t.pointerId;if(this.getPointerPressed(i)&&console.warn(`Received pointerDown for pointerId that is already pressed: ${i}`,dt?t:""),dt&&console.log(t.pointerType,"DOWN",i),!!this.isInRect(t)){for(this.setPointerState(i,this._pointerPressed,!0),this.setPointerState(i,this._pointerDown,!0),this.setPointerStateT(i,this._pointerEvent,t.source);i>=this._pointerTypes.length;)this._pointerTypes.push(t.pointerType);for(this._pointerTypes[i]=t.pointerType;i>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new x);for(this._pointerPositionDown[i].set(t.clientX,t.clientY,t.clientZ??0);i>=this._pointerPositions.length;)this._pointerPositions.push(new re);this._pointerPositions[i].set(t.clientX,t.clientY),i>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[i]=this.context.time.realtimeSinceStartup,this.updatePointerPosition(t),this._pointerEventsPressed.push(t),this.onDispatchEvent(t)}}onMove(t){const i=t.pointerId,s=this.getPointerPressed(i);s===!1&&!this.isInRect(t)||t.pointerType==="touch"&&!s||(this.updatePointerPosition(t),this.setPointerStateT(i,this._pointerEvent,t.source),this.onDispatchEvent(t))}onUp(t){const i=t.pointerId;if(!this.getPointerPressed(i)){dt&&console.log(t.pointerType,"UP",i,"was not down");return}dt&&console.log(t.pointerType,"UP",i),this.setPointerState(i,this._pointerPressed,!1),this.setPointerStateT(i,this._pointerEvent,t.source),this.setPointerState(i,this._pointerUp,!0),this.updatePointerPosition(t);for(let c=this._pointerEventsPressed.length-1;c>=0;c--)if(this._pointerEventsPressed[c].pointerId===i){this._pointerEventsPressed.splice(c,1);break}if(!this._pointerPositionDown[i]){dt&&_e("Received pointer up event without matching down event for button: "+i),console.warn("Received pointer up event without matching down event for button: "+i);return}const s=this._pointerUpTime[i],o=this._pointerDownTime[i],r=this.context.time.realtimeSinceStartup,l=r-o;if(i>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),this._pointerUpTime[i]=r,l<1){let c=t.clientX-this._pointerPositionDown[i].x,h=t.clientY-this._pointerPositionDown[i].y,d=0;if(t.isSpatial&&t.clientZ!=null&&(d=t.clientZ-this._pointerPositionDown[i].z,c*=200,h*=200,d*=200),Math.abs(c)<5&&Math.abs(h)<5&&Math.abs(d)<5){this.setPointerState(i,this._pointerClick,!0),t.isClick=!0;const u=r-s;dt&&console.log("CLICK",i,c,h,d,u),u<this._doubleClickTimeThreshold&&u>0&&(this.setPointerState(i,this._pointerDoubleClick,!0),t.isDoubleClick=!0)}}this.onDispatchEvent(t)}updatePointerPosition(t){const i=t.pointerId;for(;i>=this._pointerPositions.length;)this._pointerPositions.push(new re);for(;i>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new re);for(;i>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new re);const s=this._pointerPositionsLastFrame[i];s.copy(this._pointerPositions[i]);const o=this._pointerPositionsDelta[i];let r=t.clientX-s.x,l=t.clientY-s.y;if(t.source instanceof MouseEvent||t.source instanceof TouchEvent){const u=t.source;r===0&&u.movementX!==0&&(r=u.movementX||0),l===0&&u.movementY!==0&&(l=u.movementY||0)}o.x+=r,o.y+=l,this._pointerPositions[i].x=t.clientX,this._pointerPositions[i].y=t.clientY;const c=t.clientX,h=t.clientY;for(;i>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new re);const d=this._pointerPositionsRC[i];d.set(c,h),this.convertScreenspaceToRaycastSpace(d)}getPointerIndex(t){let i=-1;for(let s=0;s<this._pointerIds.length;s++){if(this._pointerIds[s]===t)return s;i===-1&&this._pointerIds[s]===-1&&(i=s)}return i!==-1?(this._pointerIds[i]=t,i):(dt&&console.log("PUSH pointerId:",t),this._pointerIds.push(t),this._pointerIds.length-1)}setPointerState(t,i,s){i[t]=s}setPointerStateT(t,i,s){return i[t]=s,s}onDispatchEvent(t){const i=ee.Current;try{ee.Current=this.context,this.dispatchEvent(t)}finally{ee.Current=i}}}const Ca=new se().makeRotationY(Math.PI),qi=new V().setFromAxisAngle(new x(0,1,0),Math.PI),IP=C("debugwebxr");class jP{constructor(){if(a(this,"priority",-1e5),a(this,"gameObject"),this.gameObject=new A,this.gameObject.name="Implicit XR Rig",IP){const t=fg(16733661);t.position.y+=.5,this.gameObject.add(t)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const ks=C("debugwebxr"),Ed=C("debugcustomgesture"),LP="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",DP="generic-trigger",BP=new V().setFromEuler(new zt(ys.degToRad(0),ys.degToRad(-90),ys.degToRad(-90))),FP=new x(.04,-.04,0);class tg{constructor(t,i,s){a(this,"xr"),a(this,"inputSource"),a(this,"index",0),a(this,"emitEvents",!0),a(this,"_connected",!0),a(this,"_isTracking",!1),a(this,"__gamepad"),a(this,"__hand"),a(this,"__side"),a(this,"_hitTestSource"),a(this,"_hasSelectEvent",!1),a(this,"_isMxInk",!1),a(this,"_isMetaQuestTouchController",!1),a(this,"_handJointPoses",new Map),a(this,"_gripMatrix",new se),a(this,"_gripPosition",new x),a(this,"_gripQuaternion",new V),a(this,"_linearVelocity",new x),a(this,"_rayPositionRaw",new x),a(this,"_rayRotationRaw",new V),a(this,"_rayMatrix",new se),a(this,"_rayPosition",new x),a(this,"_rayQuaternion",new V),a(this,"_gripWorldPosition",new x),a(this,"_gripWorldQuaternion",new V),a(this,"_rayWorldPosition",new x),a(this,"_rayWorldQuaternion",new V),a(this,"_pinchPosition",new x),a(this,"_ray"),a(this,"_hand_wristDotUp"),a(this,"_object"),a(this,"_gripSpaceObject"),a(this,"_raySpaceObject"),a(this,"model",null),a(this,"_debugAxesHelper",new Si(.15)),a(this,"_debugGripAxesHelper",new Si(.07)),a(this,"_debugRayAxesHelper",new Si(.07)),a(this,"_hitTestSourcePromise",null),a(this,"onPointerHits",o=>{}),a(this,"_needleGamepadButtons",{}),a(this,"_buttonMap",new Map),a(this,"_motioncontroller"),a(this,"_layout"),a(this,"getMotionController"),a(this,"emitPointerDownEvent",!0),a(this,"emitPointerUpEvent",!0),a(this,"emitPointerMoveEvent",!0),a(this,"pointerMoveDistanceThreshold",.03),a(this,"pointerMoveAngleThreshold",.05),a(this,"_selectButtonIndex"),a(this,"_squeezeButtonIndex"),a(this,"onSelectStart",o=>{var r,l,c,h;if(!this.emitPointerDownEvent||this.inputSource!==o.inputSource)return;this.onUpdateFrame(o.frame),this._hasSelectEvent=!0;const d=(r=this._layout)==null?void 0:r.selectComponentId,u=(h=(c=(l=this._layout)==null?void 0:l.components[d])==null?void 0:c.gamepadIndices)==null?void 0:h.button;u!==void 0&&(this._selectButtonIndex=u),!Ed&&(ks&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(Fe.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSelectEnd",o=>{this.emitPointerUpEvent&&(Ed||this.inputSource===o.inputSource&&this.emitPointerEvent(Fe.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSequeezeStart",o=>{var r,l,c;this.emitPointerDownEvent&&this.inputSource===o.inputSource&&(this._squeezeButtonIndex=(c=(l=(r=this._layout)==null?void 0:r.components["xr-standard-squeeze"])==null?void 0:l.gamepadIndices)==null?void 0:c.button,this._squeezeButtonIndex!==void 0&&(ks&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(Fe.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)))}),a(this,"onSequeezeEnd",o=>{this.emitPointerUpEvent&&this.inputSource===o.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(Fe.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)}),a(this,"states",{}),a(this,"_didMoveLastFrame",!1),a(this,"_lastPointerMovePosition",new x),a(this,"_lastPointerMoveQuaternion",new V),a(this,"pointerInit"),this.xr=t,this.inputSource=i,this.index=s,this._object=new A,this._object.name=`NeedleXRController_${s}`,ks&&(this._object.add(this._debugAxesHelper),this._gripSpaceObject=new A,this._raySpaceObject=new A,this._gripSpaceObject.name=`NeedleXRController_${s}_gripSpace`,this._raySpaceObject.name=`NeedleXRController_${s}_raySpace`,this._gripSpaceObject.add(this._debugGripAxesHelper),this._raySpaceObject.add(this._debugRayAxesHelper),this.xr.context.scene.add(this._gripSpaceObject),this.xr.context.scene.add(this._raySpaceObject)),this.xr.context.scene.add(this._object),this._ray=new co,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents()}get context(){return this.xr.context}get connected(){return this._connected}get isTracking(){return this._isTracking}get gamepad(){return this.__gamepad??(this.__gamepad=this.inputSource.gamepad)}get isHand(){return this.hand!=null}get hand(){return this.__hand??(this.__hand=this.inputSource.hand)}get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.__side??(this.__side=this.inputSource.handedness)}get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get isStylus(){return this._isMxInk}getHitTestSource(){return this._hitTestSource||this._requestHitTestSource(),this._hitTestSource}get hasHitTestSource(){return this._hitTestSource}cancelHitTestSource(){this._hitTestSource&&(this._hitTestSource.cancel(),this._hitTestSource=void 0)}get hasSelectEvent(){return this._hasSelectEvent}getHitTest(){return this.xr.getHitTest(this)}getHandJointPose(t,i){var s;if(i=i||this.xr.frame,!this.hand||!(i!=null&&i.getJointPose)||!this.xr.referenceSpace)return null;let o=(s=this._handJointPoses)==null?void 0:s.get(t);return o||(o=i.getJointPose(t,this.xr.referenceSpace),o&&this._handJointPoses.set(t,o),o)}get gripPosition(){return q(this._gripPosition)}get gripQuaternion(){return yn(this._gripQuaternion)}get gripMatrix(){return this._gripMatrix}get gripLinearVelocity(){return q(this._linearVelocity).applyQuaternion(qi)}get rayPosition(){return q(this._rayPosition)}get rayQuaternion(){return yn(this._rayQuaternion)}get gripWorldPosition(){return q(this._gripWorldPosition)}get gripWorldQuaternion(){return yn(this._gripWorldQuaternion)}get rayWorldPosition(){return q(this._rayWorldPosition)}updateRayWorldPosition(){var t;const i=(t=this.xr.context.mainCamera)==null?void 0:t.parent;this._rayWorldPosition.copy(this._rayPositionRaw),i&&this._rayWorldPosition.applyMatrix4(i.matrixWorld)}get rayWorldQuaternion(){return yn(this._rayWorldQuaternion)}get pinchPosition(){return q(this._pinchPosition)}updateRayWorldQuaternion(){var t;const i=(t=this.xr.context.mainCamera)==null?void 0:t.parent,s=i?Ce(i):void 0;this._rayWorldQuaternion.copy(this._rayRotationRaw).multiply(qi),s&&this._rayWorldQuaternion.premultiply(s)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(q(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get handWristDotUp(){var t;if(this._hand_wristDotUp!==void 0)return this._hand_wristDotUp;const i=(t=this.handObject)==null?void 0:t.joints.wrist;if(i){const s=q(0,1,0).applyQuaternion(i.quaternion),o=q(0,1,0).dot(s);return this._hand_wristDotUp=o}}get isHandUpsideDown(){return this.handWristDotUp!==void 0?this.handWristDotUp<-.7:!1}get isTeleportGesture(){var t;return this.isHandUpsideDown&&((t=this.getGesture("pinch"))==null?void 0:t.isDown)}get object(){return this._object}async getModelUrl(){var t;return(t=this.getMotionController)==null?void 0:t.then(i=>i?.assetUrl||null)}_requestHitTestSource(){var t;return this._hitTestSourcePromise?this._hitTestSourcePromise:this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&this.xr.session.requestHitTestSourceForTransientInput?this._hitTestSourcePromise=((t=this.xr.session.requestHitTestSourceForTransientInput({profile:this.inputSource.profiles[0],offsetRay:new XRRay}))==null?void 0:t.then(i=>(this._hitTestSourcePromise=null,this.connected?this._hitTestSource=i:(i.cancel(),null))))??null:null}onUpdate(t){this.onUpdateFrame(t),this.updateInputEvents(),this.onUpdateMove()}onRenderDebug(){var t;$.DrawSphere(this.rayWorldPosition,.003),$.DrawDirection(this.rayWorldPosition,q(0,0,10).applyQuaternion(this.rayWorldQuaternion));const i=(this.inputSource.gripSpace?this.gripWorldPosition:this.object.worldPosition).sub(this.object.worldForward.multiplyScalar(.1)),s=this.inputSource.profiles.join(`
|
|
135
135
|
`);let o=`Controller[${this.index}] (${this.inputSource.targetRayMode}, ${this.side})
|
|
136
136
|
C:${this.connected?"x":"-"} T:${this.isTracking?"x":"-"} Hand:${this.inputSource.hand?"x":"-"} Pen: ${this._isMxInk?"x":"-"}`;if(this.inputSource.hand&&(o+=`
|
|
@@ -929,10 +929,10 @@ Using the assigned clip instead:`,this.clip),n=this.clip);let o=!this.sound||n&&
|
|
|
929
929
|
Audio:`,r.getAudioTracks(),`
|
|
930
930
|
Video:`,r.getVideoTracks()),this._stream=r,s==="incoming"){const l=new Uw(t,r,this);this.dispatchEvent(l)}}),i.on("close",()=>{this.dispatchEvent(new bf(t,s))})}get stream(){return this._stream}close(){this._isDisposed||(this._isDisposed=!0,this.call.close(),Jn(this._stream))}get isOpen(){var t;return((t=this.call.peerConnection)==null?void 0:t.connectionState)==="connected"}get isOpening(){var t;return((t=this.call.peerConnection)==null?void 0:t.connectionState)==="connecting"}get isClosed(){return!this.isOpen||this._isDisposed}}function Ww(n){return n=n.replace("a=fmtp:111 minptime=10;useinbandfec=1","a=fmtp:111 ptime=5;useinbandfec=1;stereo=1;maxplaybackrate=48000;maxaveragebitrat=128000;sprop-stereo=1"),n}const Nc=class extends pm{constructor(n,t){super(),a(this,"updateCalls",()=>{var i;for(let s=this._incomingCalls.length-1;s>=0;s--){const o=this._incomingCalls[s];o.isClosed&&!o.isOpening&&this._incomingCalls.splice(s,1)}for(let s=this._outgoingCalls.length-1;s>=0;s--){const o=this._outgoingCalls[s];let r=!1;o.isClosed&&!o.isOpening&&((i=o.stream)!=null&&i.active?st&&console.warn("!!! Stream is still active, don't remove call",o.userId,"Your id: "+this.context.connection.connectionId):(st&&console.warn("!!! Remove closed call",o.userId),r=!0)),this.context.connection.userIsInRoom(o.userId)===!1&&(st&&console.warn("!!! User is not in room anymore, remove call",o.userId),r=!0),r&&(o.close(),this._outgoingCalls.splice(s,1))}}),a(this,"id"),a(this,"context"),a(this,"_incomingCalls",[]),a(this,"_outgoingCalls",[]),a(this,"_peer"),a(this,"_enabled",!1),a(this,"_enabledPeer",!1),a(this,"onConnectRoomFn",this.onConnectRoom.bind(this)),a(this,"onPeerConnect",i=>{if(st&&console.log("PEER opened as",i),i===null){console.error("Peer connection failed",i);return}this.context.connection.send("peer-user-connected",new jM(this,i))}),a(this,"onPeerClose",()=>{st&&console.log("PEER closed"),this.updateCalls()}),a(this,"onPeerDisconnected",()=>{st&&console.log("PEER disconnected"),this.updateCalls()}),a(this,"onPeerError",i=>{st&&console.error("PEER error",i)}),a(this,"onPeerReceivingCall",i=>{i.answer(void 0,{sdpTransform:s=>Ww(s)}),this.registerCall(i,"incoming",null)}),this.context=n,this.id=t,this.setupPeer(),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia}static getOrCreate(n,t){if(Nc.instances.has(t))return Nc.instances.get(t);const i=new Nc(n,t);return Nc.instances.set(t,i),i}getMyPeerId(){if(this.context.connection.connectionId)return this.getPeerIdFromUserId(this.context.connection.connectionId)}getPeerIdFromUserId(n){return this.id+"-"+n}getUserIdFromPeerId(n){return n.substring(this.id.length+1)}makeCall(n,t){var i;if(!(t!=null&&t.id)){st?console.warn("Can not make a call: mediastream has no id or is undefined"):console.debug("Can not make a call: mediastream has no id or is undefined");return}const s={metadata:{userId:this.context.connection.connectionId,streamId:t.id},sdpTransform:r=>Ww(r)},o=(i=this._peer)==null?void 0:i.call(n,t,s);if(o){const r=this.registerCall(o,"outgoing",t);return st&&console.warn(`\u{1F4DE} CALL ${n}`,`
|
|
931
931
|
Outgoing:`,this._outgoingCalls,`
|
|
932
|
-
Incoming:`,this._incomingCalls),r}else st&&console.error("Failed to make call",n,t,this._peer)}closeAll(){for(const n of this._incomingCalls)n.close();for(const n of this._outgoingCalls)n.close();this.updateCalls()}get peer(){return this._peer}get incomingCalls(){return this._incomingCalls}enable(){this._enabled||(this._enabled=!0,this.context.connection.beginListen(ne.JoinedRoom,this.onConnectRoomFn),this.subscribePeerEvents())}disable(){this._enabled&&(this._enabled=!1,this.context.connection.stopListen(ne.JoinedRoom,this.onConnectRoomFn),this.unsubscribePeerEvents())}onConnectRoom(){this.setupPeer()}setupPeer(){if(this.context.connection.connectionId&&!this._enabledPeer){if(this._enabledPeer=!0,!this._peer){const n=this.getMyPeerId();n?this._peer=Pb(n):console.error("Failed to setup peerjs because we dont have a connection id",this.context.connection.connectionId)}this._enabled&&this.subscribePeerEvents()}}subscribePeerEvents(){this._peer&&(this._peer.on("open",this.onPeerConnect),this._peer.on("close",this.onPeerClose),this._peer.on("call",this.onPeerReceivingCall),this._peer.on("disconnected",this.onPeerDisconnected),this._peer.on("error",this.onPeerError))}unsubscribePeerEvents(){this._peer&&(this._peer.off("open",this.onPeerConnect),this._peer.off("close",this.onPeerClose),this._peer.off("call",this.onPeerReceivingCall),this._peer.off("disconnected",this.onPeerDisconnected),this._peer.off("error",this.onPeerError))}registerCall(n,t,i){const s=n.metadata;(!s||!s.userId)&&console.error("Missing call metadata",n);const o=s.userId;t==="incoming"&&st?console.warn("\u2190 Receive call from",n.metadata,n.connectionId):st&&console.warn("\u2192 Make call to",n.metadata);const r=t==="incoming"?this._incomingCalls:this._outgoingCalls,l=new LM(o,n,t,i);return r.push(l),n.on("error",c=>{console.error("Call error",c)}),n.on("close",()=>{st&&console.log("Call ended",n.metadata);const c=r.indexOf(l);c!==-1&&r.splice(c,1),l.close(),this.dispatchEvent(new bf(o,t))}),l.addEventListener("call-ended",c=>{this.dispatchEvent(c)}),t==="incoming"&&(l.addEventListener("receive-stream",c=>{this.dispatchEvent(c)}),n.on("stream",()=>{st&&console.log("Received stream for call",n.metadata);let c=0;const h=setInterval(()=>{const d=c===0;!l.isOpen&&d&&(st&&console.warn("Close call because stream is not active",n.metadata),c+=1,clearInterval(h),l.close())},2e3)})),l}};let Wc=Nc;a(Wc,"instances",new Map);class sd extends pm{constructor(t,i){if(super(),a(this,"context"),a(this,"peer"),a(this,"_sendingStreams",new Map),a(this,"debug",!1),a(this,"_enabled",!1),a(this,"_tickIntervalId"),a(this,"tick",()=>{this.updateSendingCalls()}),a(this,"onJoinedRoom",s=>{this._sendingStreams.size>0&&(this.debug&&console.warn(`${s!=null&&s.userId?`User ${s.userId}`:"You"} joined room`,s,this._sendingStreams.size),this.updateSendingCalls())}),a(this,"onLeftRoom",s=>{this.debug&&console.warn(`${s?.userId||"You"} left room`,s),this.stopCallsToUsersThatAreNotInTheRoomAnymore(),this.peer.closeAll()}),a(this,"onCallStreamReceived",s=>{this.debug&&console.log("Call with "+s.userId+" started"),this.dispatchEvent({type:"receive-stream",target:this,stream:s.stream,userId:s.userId}),this.debug&&this.debugLogCurrentState()}),a(this,"onCallEnded",s=>{this.debug&&console.log("Call with "+s.userId+" ended"),this.dispatchEvent(s),this.debug&&this.debugLogCurrentState()}),a(this,"onUserConnected",s=>{if(this.peer.id===s.guid){this.debug&&console.log("PEER USER CONNECTED",s.guid,s,this._sendingStreams.size);const o=this._sendingStreams.keys().next().value;this.peer.makeCall(s.peerId,o)}else st&&console.log("Unknown user connected",s.guid,s.peerId)}),a(this,"onUserLeft",s=>{this.debug&&console.log("User left room: "+s.userId),this.stopCallsToUsersThatAreNotInTheRoomAnymore()}),Dw(t)){const s=t;t=s.context,i=Wc.getOrCreate(s.context,s.guid)}else typeof i=="string"&&(i=Wc.getOrCreate(t,i));if(t){if(!(t instanceof ee))throw new Error("Failed to create NetworkedStreams because context is not an instance of Context")}else throw new Error("Failed to create NetworkedStreams because context is undefined");if(!i)throw new Error("Failed to create NetworkedStreams because peer is undefined");this.context=t,this.peer=i,st&&(this.debug=!0)}static create(t,i){const s=Wc.getOrCreate(t.context,i||t.context.connection.connectionId||t.guid);return new sd(t.context,s)}startSendingStream(t){this._sendingStreams.has(t)?console.warn("Received start sending stream with stream that is already being sent"):(this._sendingStreams.set(t,[]),this.updateSendingCalls())}stopSendingStream(t){if(t){const i=this._sendingStreams.get(t);if(i){for(const s of i)s.close();i.length=0}this._sendingStreams.delete(t),i&&this.debug&&this.debugLogCurrentState()}this.updateSendingCalls()}get enabled(){return this._enabled}enable(){this._enabled||(this._enabled=!0,this.peer.enable(),this.peer.addEventListener("receive-stream",this.onCallStreamReceived),this.peer.addEventListener("call-ended",this.onCallEnded),this.context.connection.beginListen("peer-user-connected",this.onUserConnected),this.context.connection.beginListen(ne.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ne.UserJoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ne.UserLeftRoom,this.onUserLeft),this.context.connection.beginListen(ne.LeftRoom,this.onLeftRoom),this._tickIntervalId=setInterval(this.tick,5e3))}disable(){this._enabled&&(this._enabled=!1,this.peer.disable(),this.peer.removeEventListener("receive-stream",this.onCallStreamReceived),this.peer.removeEventListener("call-ended",this.onCallEnded),this.context.connection.stopListen("peer-user-connected",this.onUserConnected),this.context.connection.stopListen(ne.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ne.UserJoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ne.UserLeftRoom,this.onUserLeft),this.context.connection.stopListen(ne.LeftRoom,this.onLeftRoom),this._tickIntervalId!=null&&(clearInterval(this._tickIntervalId),this._tickIntervalId=void 0))}updateSendingCalls(){const t=this.context.connection.connectionId;for(const i of this._sendingStreams.keys()){const s=this._sendingStreams.get(i)||[];for(const o of this.context.connection.usersInRoom()){if(o===t)continue;const r=this.peer.getPeerIdFromUserId(o);if(s.find(l=>{var c;return l.peerId===r&&l.direction==="outgoing"&&!l.isClosed&&((c=l.stream)==null?void 0:c.active)}))st&&console.debug("Already have a call with user "+o+" / peer "+r);else{const l=this.peer.makeCall(r,i);l&&s.push(l)}}this._sendingStreams.set(i,s)}this.stopCallsToUsersThatAreNotInTheRoomAnymore()}stopCallsToUsersThatAreNotInTheRoomAnymore(){for(const t of this._sendingStreams.keys()){const i=this._sendingStreams.get(t);if(i)for(let s=i.length-1;s>=0;s--){const o=i[s];this.context.connection.userIsInRoom(o.userId)?st&&(this.context.connection.connectionId===o.userId?console.warn(`You are still in the room [${s}] ${o.userId}`):console.log(`User is still in room [${s}] ${o.userId}`)):(st&&console.log(`Remove call ${[s]} to user that is not in room anymore ${o.userId}`),o.close(),i.splice(s,1))}}this.peer.updateCalls(),this.debug&&this.debugLogCurrentState()}debugLogCurrentState(){console.warn(`You (${this.context.connection.connectionId}) are currently sending ${this._sendingStreams.size} and receiving ${this.peer.incomingCalls.length} calls (${this.peer.incomingCalls.map(t=>t.userId).join(", ")})`,this.peer.incomingCalls)}}function Jn(n){if(n&&n instanceof MediaStream)for(const t of n.getTracks())t.stop()}var DM=Object.defineProperty,BM=Object.getOwnPropertyDescriptor,_f=(n,t,i,s)=>{for(var o=s>1?void 0:s?BM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&DM(t,i,o),o};const FM="noVoip",zM=C("debugvoip");class Io extends I{constructor(){super(...arguments),a(this,"autoConnect",!0),a(this,"runInBackground",!0),a(this,"createMenuButton",!0),a(this,"debug",!1),a(this,"_net"),a(this,"_menubutton"),a(this,"_allowSending",!0),a(this,"_outputStream",null),a(this,"onJoinedRoom",async()=>{this.debug&&console.log("VOIP: Joined room"),await fn(300),this.autoConnect&&!this.isSending&&this._allowSending&&this.connect()}),a(this,"onLeftRoom",()=>{this.debug&&console.log("VOIP: Left room"),this.disconnect();for(const t of this._incomingStreams.values())Jn(t.srcObject);this._incomingStreams.clear()}),a(this,"_incomingStreams",new Map),a(this,"onReceiveStream",t=>{const i=t.target.userId,s=t.stream;let o=this._incomingStreams.get(i);o||(o=new Audio,this._incomingStreams.set(i,o)),o.srcObject=s,o.setAttribute("autoplay","true"),Wn.registerWaitForInteraction(()=>{o?.play().catch(r=>{console.error("VOIP: Failed to play audio",r)})})}),a(this,"onStreamEnded",t=>{const i=this._incomingStreams.get(t.userId);Jn(i?.srcObject),this._incomingStreams.delete(t.userId)}),a(this,"onEnabledChanged",()=>{for(const t of this._incomingStreams){const i=t[1];i.muted=!this.enabled}}),a(this,"onVisibilityChanged",()=>{if(this.runInBackground)return;const t=document.visibilityState!=="visible";this.setMuted(t);for(const i of this._incomingStreams){const s=i[1];s.muted=t}})}awake(){zM&&(this.debug=!0),this.debug&&(console.log("VOIP debugging: press 'v' to toggle mute or 'c' to toggle connect/disconnect"),window.addEventListener("keydown",async t=>{switch(t.key.toLowerCase()){case"v":console.log("MUTE?",!this.isMuted),this.setMuted(!this.isMuted);break;case"c":this.isSending?this.disconnect():this.connect();break}}),window.addEventListener("blur",()=>{console.log("VOIP: MUTE ON BLUR"),this.setMuted(!0)}),window.addEventListener("focus",()=>{console.log("VOIP: UNMUTE ON FOCUS"),this.setMuted(!1)}))}onEnable(){this._net||(this._net=sd.create(this)),this.debug&&(this._net.debug=!0),this._net.addEventListener(Zn.StreamReceived,this.onReceiveStream),this._net.addEventListener(Zn.StreamEnded,this.onStreamEnded),this._net.enable(),this.autoConnect&&this.context.connection.isConnected&&this.connect(),this.context.connection.beginListen(ne.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ne.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.addEventListener("visibilitychange",this.onVisibilityChanged)}onDisable(){var t;this._net&&(this._net.stopSendingStream(this._outputStream),this._net.removeEventListener(Zn.StreamReceived,this.onReceiveStream),this._net.removeEventListener(Zn.StreamEnded,this.onStreamEnded),(t=this._net)==null||t.disable()),this.context.connection.stopListen(ne.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ne.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.removeEventListener("visibilitychange",this.onVisibilityChanged)}onDestroy(){var t;(t=this._menubutton)==null||t.remove(),this._menubutton=void 0}get isSending(){return this._outputStream!=null&&this._outputStream.active}async connect(t){var i,s;if(!this._net)return console.error("Cannot connect to voice chat - NetworkedStreams not initialized. Make sure the component is enabled before calling this method."),!1;if(this.context.connection.isConnected){if(!await Q.microphonePermissionsGranted())return console.error("Cannot connect to voice chat - microphone permissions not granted"),this.updateButton(),!1}else return console.error("Cannot connect to voice chat - not connected to server"),this.updateButton(),!1;return this._allowSending=!0,(i=this._net)==null||i.stopSendingStream(this._outputStream),Jn(this._outputStream),this._outputStream=await this.getAudioStream(t),this._outputStream?(this.debug&&console.log("VOIP: Got audio stream"),(s=this._net)==null||s.startSendingStream(this._outputStream),this.updateButton(),!0):(this.updateButton(),await Q.microphonePermissionsGranted()?console.error("VOIP: Could not get audio stream - please make sure to connect an audio device and grant microphone permissions"):ic("Microphone permissions not granted: Please grant microphone permissions to use voice chat"),(this.debug||B())&&console.log("VOIP: Failed to get audio stream"),!1)}disconnect(t){var i;t!=null&&t.remember&&(this._allowSending=!1),(i=this._net)==null||i.stopSendingStream(this._outputStream),Jn(this._outputStream),this._outputStream=null,this.updateButton()}setMuted(t){var i;const s=(i=this._outputStream)==null?void 0:i.getAudioTracks();if(s)for(const o of s)o.enabled=!t}get isMuted(){var t;if(this._outputStream===null)return!1;const i=(t=this._outputStream)==null?void 0:t.getAudioTracks();if(i){for(const s of i)if(!s.enabled)return!0}return!1}async updateButton(){var t;if(this.createMenuButton){if(this._menubutton||(this._menubutton=document.createElement("button"),this._menubutton.addEventListener("click",()=>{this.isSending?this.disconnect({remember:!0}):this.connect(),Q.microphonePermissionsGranted().then(i=>{i||_e("<strong>Microphone permissions not granted</strong>. Please allow your browser to use the microphone to be able to talk. Click on the button on the left side of your browser's address bar to allow microphone permissions.")})})),this._menubutton){this.context.menu.appendChild(this._menubutton),this.activeAndEnabled?this._menubutton.style.display="":this._menubutton.style.display="none",this._menubutton.title=this.isSending?"Click to disable your microphone":"Click to enable your microphone";let i=(this.isSending,""),s=this.isSending?"mic":"mic_off";await Q.microphonePermissionsGranted()||(i="No Permission",s="mic_off",this._menubutton.title="Microphone permissions not granted. Please allow your browser to use the microphone to be able to talk. This can usually be done in the addressbar of the webpage."),this._menubutton.innerText=i,this._menubutton.prepend(Pt(s)),this.context.connection.isConnected==!1?this._menubutton.setAttribute("disabled",""):this._menubutton.removeAttribute("disabled")}}else this.activeAndEnabled||(t=this._menubutton)==null||t.remove()}getFrequency(t){return this.unsupported_getfrequency||(this.unsupported_getfrequency=!0,B()&&_e("VOIP: getFrequency is currently not supported"),console.warn("VOIP: getFrequency is currently not supported")),null}async getAudioStream(t){if(!navigator.mediaDevices.getUserMedia)return console.error("No getDisplayMedia support"),null;const i=async o=>await navigator.mediaDevices.getUserMedia({audio:o??!0,video:!1}).catch(r=>(console.warn("VOIP failed getting audio stream",r),null)),s=await i(t);if(!s)return null;if(Q.isiOS()&&t?.deviceId===void 0){const o=(await navigator.mediaDevices.enumerateDevices()).find(r=>(r.kind==="audioinput"||r.kind==="audiooutput")&&!r.label.includes("iPhone"));if(o){const r=Object.assign({},t);return r.deviceId=o.deviceId,await i(r)}}return s}}_f([m()],Io.prototype,"autoConnect",2),_f([m()],Io.prototype,"runInBackground",2),_f([m()],Io.prototype,"createMenuButton",2);var UM=Object.defineProperty,NM=Object.getOwnPropertyDescriptor,Vw=(n,t,i,s)=>{for(var o=s>1?void 0:s?NM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&UM(t,i,o),o};const WM=C("debugmouth");class Vc extends I{constructor(){super(...arguments),a(this,"idle",[]),a(this,"talking",[]),a(this,"marker",null),a(this,"voip",null),a(this,"lastMouthChangeTime",0),a(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=O.findObjectOfType(Io,this.context),this.marker||(this.marker=O.getComponentInParent(this.gameObject,Tt))},3e3)}update(){var t;if(!this.voip||this.context.time.frameCount%10!==0)return;let i=((t=this.marker)==null?void 0:t.connectionId)??null;if(!i){WM&&(i=null);return}const s=this.voip.getFrequency(i)??0;this.updateLips(s)}updateLips(t){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&t>30){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,i)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,i)}}}setMouthShapeActive(t,i){if(t){t!=this.idle?this.idle.map(s=>s.visible=!1):this.talking.map(s=>s.visible=!1);for(let s=0;s<t.length;s++){const o=t[s];o&&(o.visible=s===i)}}}}Vw([m(A)],Vc.prototype,"idle",2),Vw([m(A)],Vc.prototype,"talking",2);class wf extends I{constructor(){super(...arguments),a(this,"voip",null),a(this,"marker",null),a(this,"_startPosition",null)}awake(){this.voip=O.findObjectOfType(Io,this.context),this.marker=O.getComponentInParent(this.gameObject,Tt)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const t=this.marker.connectionId,i=this.voip.getFrequency(t);if(i==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const s=i/100;this.gameObject.position.y=this._startPosition.y+s*.07}}var VM=Object.defineProperty,HM=Object.getOwnPropertyDescriptor,$M=(n,t,i,s)=>{for(var o=s>1?void 0:s?HM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&VM(t,i,o),o};const $a=C("debugxrflags"),Hw=C("disablexrflags");Hw&&console.warn("XRFlags are disabled");var es=(n=>(n[n.Never=0]="Never",n[n.Browser=1]="Browser",n[n.AR=2]="AR",n[n.VR=4]="VR",n[n.FirstPerson=8]="FirstPerson",n[n.ThirdPerson=16]="ThirdPerson",n[n.All=4294967295]="All",n))(es||{});const $w=class{constructor(){a(this,"Mask",17)}Has(n){return(this.Mask&n)!==0}Set(n){$a&&console.warn("Set XR flag state to",n),this.Mask=n,ji.Apply()}Enable(n){this.Mask|=n,ji.Apply()}Disable(n){this.Mask&=~n,ji.Apply()}Toggle(n){this.Mask^=n,ji.Apply()}EnableAll(){this.Mask=-1,ji.Apply()}DisableAll(){this.Mask=0,ji.Apply()}};let ci=$w;a(ci,"Global",new $w);var Hc;const Bs=(Hc=class extends I{constructor(){super(...arguments),a(this,"visibleIn")}static Apply(){for(const n of this.registry)n.UpdateVisible(ci.Global)}awake(){Bs.registry.push(this)}onEnable(){Bs.firstApply?this.UpdateVisible(ci.Global):(Bs.firstApply=!0,Bs.Apply())}onDestroy(){const n=Bs.registry.indexOf(this);n>=0&&Bs.registry.splice(n,1)}get isOn(){return this.gameObject.visible}UpdateVisible(n=null){if(Hw)return;let t;const i=n;if(i&&typeof i=="number"&&(console.assert(typeof i=="number","XRFlag.UpdateVisible: state must be a number",i),$a&&console.log(i),Bs.buffer.Mask=i,n=Bs.buffer),n instanceof ci?($a&&console.warn(this.name,"use passed in mask",n.Mask,this.visibleIn),t=n.Has(this.visibleIn)):($a&&console.log(this.name,"use global mask"),ci.Global.Has(this.visibleIn)),t!==void 0)if(t)$a&&console.log(this.name,"is visible",this.gameObject.uuid),O.setActive(this.gameObject,!0);else{if($a&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},a(Hc,"registry",[]),a(Hc,"firstApply"),a(Hc,"buffer",new ci),Hc);let ji=Bs;$M([m()],ji.prototype,"visibleIn",2);var GM=Object.defineProperty,qM=Object.getOwnPropertyDescriptor,Lu=(n,t,i,s)=>{for(var o=s>1?void 0:s?qM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&GM(t,i,o),o};class Tr extends I{constructor(){super(...arguments),a(this,"eyes",[]),a(this,"lastBlinkTime",0),a(this,"blinkLength",0),a(this,"eyesOpen",!0),a(this,"state",null)}awake(){this.state=O.getComponentInParent(this.gameObject,ji)}update(){if(!(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)&&this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const t of this.eyes)t&&(t.visible=this.eyesOpen)}}}Lu([m(A)],Tr.prototype,"eyes",2),Lu([m()],Tr.prototype,"lastBlinkTime",2),Lu([m()],Tr.prototype,"blinkLength",2),Lu([m()],Tr.prototype,"eyesOpen",2);var XM=Object.defineProperty,QM=Object.getOwnPropertyDescriptor,xf=(n,t,i,s)=>{for(var o=s>1?void 0:s?QM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&XM(t,i,o),o},Sf;const Gw=(Sf=class extends I{constructor(){super(...arguments),a(this,"head",null),a(this,"eyes",null),a(this,"target",null),a(this,"brain",null),a(this,"vec",new x),a(this,"currentTargetPoint",new x)}awake(){this.brain||(this.brain=O.getComponentInParent(this.gameObject,Uc)),this.brain||(this.brain=O.addComponent(this.gameObject,Uc)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const n=this.target;if(n&&this.head){const t=this.eyes;if(t){const i=te(n);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const s=te(this.head),o=this.vec.copy(this.currentTargetPoint).sub(s).normalize();if(o.length()<.1)return;const r=Gw.forward;if(r.set(0,0,1),r.applyQuaternion(Ce(this.head)),r.dot(o)>.45)for(let l=0;l<t.length;l++)t[l].lookAt(this.currentTargetPoint)}}}},a(Sf,"forward",new x(0,0,1)),Sf);let Ga=Gw;xf([m(A)],Ga.prototype,"head",2),xf([m(A)],Ga.prototype,"eyes",2),xf([m(A)],Ga.prototype,"target",2);var YM=Object.defineProperty,KM=Object.getOwnPropertyDescriptor,Cf=(n,t,i,s)=>{for(var o=s>1?void 0:s?KM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&YM(t,i,o),o};class qa extends I{constructor(){super(...arguments),a(this,"length",1),a(this,"depthTest",!0),a(this,"isGizmo",!1),a(this,"_axes",null)}onEnable(){if(this.isGizmo&&!vc)return;this._axes||(this._axes=new Si(this.length)),this._axes.layers.disableAll(),this._axes.layers.set(this.layer),this.gameObject.add(this._axes);const t=this._axes.material;t&&t.depthTest!==void 0&&(t.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}Cf([m()],qa.prototype,"length",2),Cf([m()],qa.prototype,"depthTest",2),Cf([m()],qa.prototype,"isGizmo",2);class Of extends I{constructor(){super(...arguments),a(this,"from"),a(this,"to"),a(this,"hint"),a(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const t=te(this.to).clone(),i=te(this.from).clone(),s=t.distanceTo(i),o=t.clone();o.sub(i);const r=i.clone();r.add(t),r.multiplyScalar(.5);const l=te(this.hint).clone();l.sub(r);const c=new x;c.crossVectors(l,o),c.crossVectors(o,c),c.normalize();const h=s*.5,d=Math.max(this.desiredDistance,h),u=Math.sqrt(d*d-h*h),p=c.clone();p.multiplyScalar(u),p.add(r),ht(this.gameObject,p);const g=r.clone();g.sub(c),this.gameObject.lookAt(g)}}const ZM=C("gizmos"),JM=C("debugboxhelper"),ts=class extends I{constructor(){super(...arguments),a(this,"box",null),a(this,"_lastMatrixUpdateFrame",-1),a(this,"_helper",null),a(this,"_color",null)}isInBox(n){var t;if(!n)return;if(this.box||(this.box=new xi),oi([n],void 0,void 0,ts.testBox),ts.testBox.isEmpty()){const s=te(n,ts._position);ts.testBox.setFromCenterAndSize(s,ts._emptyObjectSize)}this.updateBox();const i=(t=this.box)==null?void 0:t.intersectsBox(ts.testBox);return i&&JM&&$.DrawWireBox3(ts.testBox,16711680,5),i}intersects(n){return n?this.updateBox(!1).intersectsBox(n):!1}updateBox(n=!1){if(this.box||(this.box=new xi),n||this.context.time.frameCount!=this._lastMatrixUpdateFrame){const t=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;const i=t,s=te(this.gameObject,ts._position,i),o=Ye(this.gameObject,ts._size);this.box.setFromCenterAndSize(s,o)}return this.box}awake(){this._helper=null,this._color=null,this.box=null}showHelper(n=null,t=!1){var i;if(!(!ZM&&!t)){if(this._helper){n&&((i=this._color)==null||i.set(n)),this.gameObject.add(this._helper);return}this._helper=fg(n),this.gameObject.add(this._helper)}}};let Ji=ts;a(Ji,"testBox",new xi),a(Ji,"_position",new x),a(Ji,"_size",new x(.01,.01,.01)),a(Ji,"_emptyObjectSize",new x(.01,.01,.01));var eR=Object.defineProperty,tR=Object.getOwnPropertyDescriptor,hi=(n,t,i,s)=>{for(var o=s>1?void 0:s?tR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&eR(t,i,o),o};class di extends I{constructor(){super(...arguments),a(this,"attachedRigidbody",null),a(this,"isTrigger",!1),a(this,"sharedMaterial"),a(this,"membership",[0]),a(this,"filter"),a(this,"updateProperties",()=>{var t;(t=this.context.physics.engine)==null||t.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}onDisable(){var t;(t=this.context.physics.engine)==null||t.removeBody(this)}get body(){var t;return(t=this.context.physics.engine)==null?void 0:t.getBody(this)}updatePhysicsMaterial(){var t;(t=this.context.physics.engine)==null||t.updatePhysicsMaterial(this)}}hi([m(ve)],di.prototype,"attachedRigidbody",2),hi([m()],di.prototype,"isTrigger",2),hi([m()],di.prototype,"sharedMaterial",2),hi([m()],di.prototype,"membership",2),hi([m()],di.prototype,"filter",2);class Xa extends di{constructor(){super(...arguments),a(this,"radius",.5),a(this,"center",new x(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addSphereCollider(this),yd(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),km(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}hi([Mt(),m()],Xa.prototype,"radius",2),hi([m(x)],Xa.prototype,"center",2);const qw=class extends di{constructor(){super(...arguments),a(this,"size",new x(1,1,1)),a(this,"center",new x(0,0,0))}static add(n,t){const i=Ti(n,qw);return i.autoFit(),t?.rigidbody===!0&&Ti(n,ve,{isKinematic:!1}),i}onEnable(){var n;super.onEnable(),(n=this.context.physics.engine)==null||n.addBoxCollider(this,this.size),yd(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),km(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}autoFit(n){const t=this.gameObject,i=t.position.clone(),s=t.quaternion.clone(),o=t.scale.clone(),r=t.parent;t.position.set(0,0,0),t.quaternion.set(0,0,0,1),t.scale.set(1,1,1),t.parent=null,t.updateMatrix();const l=oi([t]);t.position.copy(i),t.quaternion.copy(s),t.scale.copy(o),t.parent=r,n?.debug===!0&&$.DrawWireBox3(l,16768256,20),this.size=l.getSize(new x)||new x(1,1,1),this.center=l.getCenter(new x)||new x(0,0,0),this.size.length()<=0&&this.size.set(.01,.01,.01)}};let Qa=qw;hi([Mt(),m(x)],Qa.prototype,"size",2),hi([m(x)],Qa.prototype,"center",2);class jo extends di{constructor(){super(...arguments),a(this,"sharedMesh"),a(this,"convex",!1)}onEnable(){var t,i,s;if(super.onEnable(),!this.context.physics.engine)return;(t=this.sharedMesh)!=null&&t.isMesh||(this.gameObject instanceof X||this.gameObject instanceof ho)&&(this.sharedMesh=this.gameObject);const o=0;if((i=this.sharedMesh)!=null&&i.isMesh)this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex),it.assignMeshLOD(this.sharedMesh,o).then(r=>{r&&this.activeAndEnabled&&this.context.physics.engine&&this.sharedMesh&&(this.context.physics.engine.removeBody(this),this.sharedMesh.geometry=r,this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex))});else{const r=this.sharedMesh;if(r!=null&&r.isGroup){console.warn(`MeshCollider mesh is a group "${((s=this.sharedMesh)==null?void 0:s.name)||this.gameObject.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);const l=new Array;for(const c in r.children){const h=r.children[c];h.isMesh&&(this.context.physics.engine.addMeshCollider(this,h,this.convex),l.push(it.assignMeshLOD(h,o)))}Promise.all(l).then(c=>{var h,d;if(c.some(p=>p)==!1)return;(h=this.context.physics.engine)==null||h.removeBody(this);const u=new X;for(const p of c)p&&this.activeAndEnabled&&(u.geometry=p,(d=this.context.physics.engine)==null||d.addMeshCollider(this,u,this.convex))})}else(B()||C("showcolliders"))&&console.warn(`[MeshCollider] A MeshCollider mesh is assigned to an unknown object on "${this.gameObject.name}", but it's neither a Mesh nor a Group. Please double check that you attached the collider component to the right object and report a bug otherwise!`,this)}}}hi([m(X)],jo.prototype,"sharedMesh",2),hi([m()],jo.prototype,"convex",2);class Fs extends di{constructor(){super(...arguments),a(this,"center",new x(0,0,0)),a(this,"radius",.5),a(this,"height",2)}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addCapsuleCollider(this,this.height,this.radius)}}hi([m(x)],Fs.prototype,"center",2),hi([m()],Fs.prototype,"radius",2),hi([m()],Fs.prototype,"height",2);var iR=Object.defineProperty,nR=Object.getOwnPropertyDescriptor,zs=(n,t,i,s)=>{for(var o=s>1?void 0:s?nR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&iR(t,i,o),o};const Xw=C("debugcharactercontroller");class Er extends I{constructor(){super(...arguments),a(this,"center",new x(0,0,0)),a(this,"radius",.5),a(this,"height",2),a(this,"_rigidbody",null),a(this,"_activeGroundCollisions"),a(this,"_contactVelocity",new x)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(ve),this._rigidbody||(this._rigidbody=this.gameObject.addComponent(ve)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const t=this.rigidbody;let i=this.gameObject.getComponent(Fs);i||(i=this.gameObject.addComponent(Fs)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height;const s=new x(0,0,1),o=new x(1,0,0),r=new x(0,1,0),l=this.gameObject.getWorldDirection(new x);l.y=0;const c=o.dot(l)<0?-1:1,h=s.angleTo(l)*c;this.gameObject.setRotationFromAxisAngle(r,h),t.lockRotationX=!0,t.lockRotationY=!0,t.lockRotationZ=!0}move(t){this.gameObject.position.add(t)}onCollisionEnter(t){(t.contacts.length==0||t.contacts.some(i=>i.normal.y>.2))&&(this._activeGroundCollisions.add(t),Xw&&console.log(`Collision(${this._activeGroundCollisions.size}): ${t.contacts.map(i=>i.normal.y.toFixed(2)).join(", ")} - ${this.isGrounded}`))}onCollisionExit(t){this._activeGroundCollisions.delete(t),Xw&&console.log(`Collision(${this._activeGroundCollisions.size}) - ${this.isGrounded}`)}get isGrounded(){return this._activeGroundCollisions.size>0}get contactVelocity(){var t;this._contactVelocity.set(0,0,0);for(const i of this._activeGroundCollisions){const s=(t=this.context.physics.engine)==null?void 0:t.getLinearVelocity(i.collider);s&&(this._contactVelocity.x+=s.x,this._contactVelocity.y+=s.y,this._contactVelocity.z+=s.z)}return this._contactVelocity}}zs([m(x)],Er.prototype,"center",2),zs([m()],Er.prototype,"radius",2),zs([m()],Er.prototype,"height",2);class Us extends I{constructor(){super(...arguments),a(this,"controller"),a(this,"movementSpeed",2),a(this,"rotationSpeed",2),a(this,"jumpForce",1),a(this,"doubleJumpForce",2),a(this,"animator"),a(this,"lookForward",!0),a(this,"lookInput",new re(0,0)),a(this,"moveInput",new re(0,0)),a(this,"jumpInput",!1),a(this,"_currentSpeed",new x(0,0,0)),a(this,"_currentAngularSpeed",new x(0,0,0)),a(this,"_temp",new x(0,0,0)),a(this,"_jumpCount",0),a(this,"_currentRotation"),a(this,"_raycastOptions",new Hn)}awake(){this._currentRotation=new V}update(){const t=this.context.input;t.isKeyPressed("KeyW")?this.moveInput.y+=1:t.isKeyPressed("KeyS")&&(this.moveInput.y-=1),t.isKeyPressed("KeyD")?this.lookInput.x+=1:t.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=t.isKeyDown("Space"))}move(t){this.moveInput.add(t)}look(t){this.lookInput.add(t)}jump(){this.jumpInput=!0}onBeforeRender(){this.handleInput(this.moveInput,this.lookInput,this.jumpInput),this.lookInput.set(0,0),this.moveInput.set(0,0),this.jumpInput=!1}handleInput(t,i,s){var o,r,l,c,h,d,u,p,g,f,y;if((o=this.controller)!=null&&o.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((r=this.animator)==null||r.setBool("doubleJump",!1))),this._currentSpeed.z+=t.y*this.movementSpeed*this.context.time.deltaTime,(l=this.animator)==null||l.setBool("running",t.length()>.01),(h=this.animator)==null||h.setBool("jumping",((c=this.controller)==null?void 0:c.isGrounded)===!0&&s),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp),this._currentAngularSpeed.y+=W.toRadians(-i.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const b=this.context.mainCameraComponent.forward;b.y=0,b.normalize(),this._currentRotation.setFromUnitVectors(new x(0,0,1),b),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&s&&this.jumpForce>0){let b=(d=this.controller)==null?void 0:d.isGrounded;if(this.doubleJumpForce>0&&!((u=this.controller)!=null&&u.isGrounded)&&this._jumpCount===1&&(b=!0,(p=this.animator)==null||p.setBool("doubleJump",!0)),b){this._jumpCount+=1;const v=this.controller.rigidbody,w=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;v.applyImpulse(new x(0,1,0).multiplyScalar(w))}}if(this.controller){const b=(g=this.controller)==null?void 0:g.rigidbody.getVelocity().y;if(b<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new co),this._raycastOptions.ray.origin.copy(te(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const v=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const w=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(v),(w.length&&w[0].distance>2||b<-10)&&((f=this.animator)==null||f.setBool("falling",!0))}else(y=this.animator)==null||y.setBool("falling",!1)}}}zs([m(Er)],Us.prototype,"controller",2),zs([m()],Us.prototype,"movementSpeed",2),zs([m()],Us.prototype,"rotationSpeed",2),zs([m()],Us.prototype,"jumpForce",2),zs([m()],Us.prototype,"doubleJumpForce",2),zs([m(kt)],Us.prototype,"animator",2);var sR=Object.defineProperty,oR=Object.getOwnPropertyDescriptor,Ya=(n,t,i,s)=>{for(var o=s>1?void 0:s?oR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&sR(t,i,o),o};const $c=C("debugcontactshadows");Ow(n=>{const t=n.domElement.getAttribute("contactshadows")||n.domElement.getAttribute("contact-shadows");if(t!=null&&t!="0"&&t!="false"){console.debug("Auto-creating ContactShadows because of `contactshadows` attribute");const i=Pn.auto(n),s=parseFloat(t);isNaN(s)||(i.opacity=s,i.darkness=s)}});var Pf;const Gc=(Pf=class extends I{constructor(){super(...arguments),a(this,"autoFit",!1),a(this,"darkness",.5),a(this,"opacity",.5),a(this,"blur",4),a(this,"occludeBelowGround",!1),a(this,"backfaceShadows",!0),a(this,"minSize"),a(this,"shadowsRoot",new A),a(this,"shadowCamera"),a(this,"shadowGroup",new ho),a(this,"renderTarget"),a(this,"renderTargetBlur"),a(this,"plane"),a(this,"occluderMesh"),a(this,"blurPlane"),a(this,"depthMaterial"),a(this,"horizontalBlurMaterial"),a(this,"verticalBlurMaterial"),a(this,"textureSize",512)}static auto(n){if(n||(n=ee.Current),!n)throw new Error("No context provided and no current context set.");let t=this._instances.get(n);if(!t||t.destroyed){const i=new A;t=Ti(i,Gc,{autoFit:!1,occludeBelowGround:!1}),this._instances.set(n,t)}return n.scene.add(t.gameObject),t.fitShadows(),t}fitShadows(){$c&&console.warn("Fitting shadows to scene"),wd(this.shadowsRoot,!1);const n=oi(this.context.scene.children,[this.shadowsRoot]),t=Math.max(1,this.blur/32),i=n.max.x-n.min.x,s=n.max.z-n.min.z;n.expandByVector(new x(t*i,0,t*s)),$c&&$.DrawWireBox3(n,16776960,60),this.gameObject.parent&&n.applyMatrix4(this.gameObject.parent.matrixWorld.clone().invert());const o=n.min,r=Math.max(1e-5,(n.max.y-o.y)*.002);n.max.y+=r,this.shadowsRoot.position.set((o.x+n.max.x)/2,o.y-r,(o.z+n.max.z)/2),this.shadowsRoot.scale.set(n.max.x-o.x,n.max.y-o.y,n.max.z-o.z),this.applyMinSize(),this.shadowsRoot.matrixWorldNeedsUpdate=!0,$c&&console.log("Fitted shadows to scene",this.shadowsRoot.scale.clone())}awake(){Gc._instances.set(this.context,this),this.shadowsRoot.hideFlags=ju.DontExport,wd(this.shadowsRoot,!1)}start(){$c&&console.log("Create ContactShadows on "+this.gameObject.name,this),this.gameObject.add(this.shadowsRoot),this.shadowsRoot.add(this.shadowGroup),this.renderTarget=new xs(this.textureSize,this.textureSize),this.renderTarget.texture.generateMipmaps=!1,this.renderTargetBlur=new xs(this.textureSize,this.textureSize),this.renderTargetBlur.texture.generateMipmaps=!1;const n=new Fn(1,1).rotateX(Math.PI/2);this.gameObject instanceof X&&(console.warn("ContactShadows can not be added to a Mesh. Please add it to a Group or an empty Object"),Ts(this.gameObject,!1));const t=new Re({map:this.renderTarget.texture,opacity:this.opacity,color:0,transparent:!0,depthWrite:!1,side:po});this.plane=new X(n,t),this.plane.scale.y=-1,this.plane.layers.set(2),this.shadowsRoot.add(this.plane),this.plane&&(this.plane.renderOrder=1),this.occluderMesh=new X(this.plane.geometry,new Re({depthWrite:!0,stencilWrite:!0,colorWrite:!1,side:dd})).translateY(-1e-4),this.occluderMesh.renderOrder=-100,this.occluderMesh.layers.set(2),this.shadowsRoot.add(this.occluderMesh),this.blurPlane=new X(n),this.blurPlane.visible=!1,this.shadowGroup.add(this.blurPlane);const i=0,s=1;this.shadowCamera=new dm(-1/2,1/2,1/2,-1/2,i,s),this.shadowCamera.layers.enableAll(),this.shadowCamera.rotation.x=Math.PI/2,this.shadowGroup.add(this.shadowCamera),this.depthMaterial=new zS,this.depthMaterial.userData.darkness={value:this.darkness},this.depthMaterial.blending=US,this.depthMaterial.blendEquation=NS,this.depthMaterial.onBeforeCompile=o=>{this.depthMaterial&&(o.uniforms.darkness=this.depthMaterial.userData.darkness,o.fragmentShader=`
|
|
932
|
+
Incoming:`,this._incomingCalls),r}else st&&console.error("Failed to make call",n,t,this._peer)}closeAll(){for(const n of this._incomingCalls)n.close();for(const n of this._outgoingCalls)n.close();this.updateCalls()}get peer(){return this._peer}get incomingCalls(){return this._incomingCalls}enable(){this._enabled||(this._enabled=!0,this.context.connection.beginListen(ne.JoinedRoom,this.onConnectRoomFn),this.subscribePeerEvents())}disable(){this._enabled&&(this._enabled=!1,this.context.connection.stopListen(ne.JoinedRoom,this.onConnectRoomFn),this.unsubscribePeerEvents())}onConnectRoom(){this.setupPeer()}setupPeer(){if(this.context.connection.connectionId&&!this._enabledPeer){if(this._enabledPeer=!0,!this._peer){const n=this.getMyPeerId();n?this._peer=Pb(n):console.error("Failed to setup peerjs because we dont have a connection id",this.context.connection.connectionId)}this._enabled&&this.subscribePeerEvents()}}subscribePeerEvents(){this._peer&&(this._peer.on("open",this.onPeerConnect),this._peer.on("close",this.onPeerClose),this._peer.on("call",this.onPeerReceivingCall),this._peer.on("disconnected",this.onPeerDisconnected),this._peer.on("error",this.onPeerError))}unsubscribePeerEvents(){this._peer&&(this._peer.off("open",this.onPeerConnect),this._peer.off("close",this.onPeerClose),this._peer.off("call",this.onPeerReceivingCall),this._peer.off("disconnected",this.onPeerDisconnected),this._peer.off("error",this.onPeerError))}registerCall(n,t,i){const s=n.metadata;(!s||!s.userId)&&console.error("Missing call metadata",n);const o=s.userId;t==="incoming"&&st?console.warn("\u2190 Receive call from",n.metadata,n.connectionId):st&&console.warn("\u2192 Make call to",n.metadata);const r=t==="incoming"?this._incomingCalls:this._outgoingCalls,l=new LM(o,n,t,i);return r.push(l),n.on("error",c=>{console.error("Call error",c)}),n.on("close",()=>{st&&console.log("Call ended",n.metadata);const c=r.indexOf(l);c!==-1&&r.splice(c,1),l.close(),this.dispatchEvent(new bf(o,t))}),l.addEventListener("call-ended",c=>{this.dispatchEvent(c)}),t==="incoming"&&(l.addEventListener("receive-stream",c=>{this.dispatchEvent(c)}),n.on("stream",()=>{st&&console.log("Received stream for call",n.metadata);let c=0;const h=setInterval(()=>{const d=c===0;!l.isOpen&&d&&(st&&console.warn("Close call because stream is not active",n.metadata),c+=1,clearInterval(h),l.close())},2e3)})),l}};let Wc=Nc;a(Wc,"instances",new Map);class sd extends pm{constructor(t,i){if(super(),a(this,"context"),a(this,"peer"),a(this,"_sendingStreams",new Map),a(this,"debug",!1),a(this,"_enabled",!1),a(this,"_tickIntervalId"),a(this,"tick",()=>{this.updateSendingCalls()}),a(this,"onJoinedRoom",s=>{this._sendingStreams.size>0&&(this.debug&&console.warn(`${s!=null&&s.userId?`User ${s.userId}`:"You"} joined room`,s,this._sendingStreams.size),this.updateSendingCalls())}),a(this,"onLeftRoom",s=>{this.debug&&console.warn(`${s?.userId||"You"} left room`,s),this.stopCallsToUsersThatAreNotInTheRoomAnymore(),this.peer.closeAll()}),a(this,"onCallStreamReceived",s=>{this.debug&&console.log("Call with "+s.userId+" started"),this.dispatchEvent({type:"receive-stream",target:this,stream:s.stream,userId:s.userId}),this.debug&&this.debugLogCurrentState()}),a(this,"onCallEnded",s=>{this.debug&&console.log("Call with "+s.userId+" ended"),this.dispatchEvent(s),this.debug&&this.debugLogCurrentState()}),a(this,"onUserConnected",s=>{if(this.peer.id===s.guid){this.debug&&console.log("PEER USER CONNECTED",s.guid,s,this._sendingStreams.size);const o=this._sendingStreams.keys().next().value;this.peer.makeCall(s.peerId,o)}else st&&console.log("Unknown user connected",s.guid,s.peerId)}),a(this,"onUserLeft",s=>{this.debug&&console.log("User left room: "+s.userId),this.stopCallsToUsersThatAreNotInTheRoomAnymore()}),Dw(t)){const s=t;t=s.context,i=Wc.getOrCreate(s.context,s.guid)}else typeof i=="string"&&(i=Wc.getOrCreate(t,i));if(t){if(!(t instanceof ee))throw new Error("Failed to create NetworkedStreams because context is not an instance of Context")}else throw new Error("Failed to create NetworkedStreams because context is undefined");if(!i)throw new Error("Failed to create NetworkedStreams because peer is undefined");this.context=t,this.peer=i,st&&(this.debug=!0)}static create(t,i){const s=Wc.getOrCreate(t.context,i||t.context.connection.connectionId||t.guid);return new sd(t.context,s)}startSendingStream(t){this._sendingStreams.has(t)?console.warn("Received start sending stream with stream that is already being sent"):(this._sendingStreams.set(t,[]),this.updateSendingCalls())}stopSendingStream(t){if(t){const i=this._sendingStreams.get(t);if(i){for(const s of i)s.close();i.length=0}this._sendingStreams.delete(t),i&&this.debug&&this.debugLogCurrentState()}this.updateSendingCalls()}get enabled(){return this._enabled}enable(){this._enabled||(this._enabled=!0,this.peer.enable(),this.peer.addEventListener("receive-stream",this.onCallStreamReceived),this.peer.addEventListener("call-ended",this.onCallEnded),this.context.connection.beginListen("peer-user-connected",this.onUserConnected),this.context.connection.beginListen(ne.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ne.UserJoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ne.UserLeftRoom,this.onUserLeft),this.context.connection.beginListen(ne.LeftRoom,this.onLeftRoom),this._tickIntervalId=setInterval(this.tick,5e3))}disable(){this._enabled&&(this._enabled=!1,this.peer.disable(),this.peer.removeEventListener("receive-stream",this.onCallStreamReceived),this.peer.removeEventListener("call-ended",this.onCallEnded),this.context.connection.stopListen("peer-user-connected",this.onUserConnected),this.context.connection.stopListen(ne.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ne.UserJoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ne.UserLeftRoom,this.onUserLeft),this.context.connection.stopListen(ne.LeftRoom,this.onLeftRoom),this._tickIntervalId!=null&&(clearInterval(this._tickIntervalId),this._tickIntervalId=void 0))}updateSendingCalls(){const t=this.context.connection.connectionId;for(const i of this._sendingStreams.keys()){const s=this._sendingStreams.get(i)||[];for(const o of this.context.connection.usersInRoom()){if(o===t)continue;const r=this.peer.getPeerIdFromUserId(o);if(s.find(l=>{var c;return l.peerId===r&&l.direction==="outgoing"&&!l.isClosed&&((c=l.stream)==null?void 0:c.active)}))st&&console.debug("Already have a call with user "+o+" / peer "+r);else{const l=this.peer.makeCall(r,i);l&&s.push(l)}}this._sendingStreams.set(i,s)}this.stopCallsToUsersThatAreNotInTheRoomAnymore()}stopCallsToUsersThatAreNotInTheRoomAnymore(){for(const t of this._sendingStreams.keys()){const i=this._sendingStreams.get(t);if(i)for(let s=i.length-1;s>=0;s--){const o=i[s];this.context.connection.userIsInRoom(o.userId)?st&&(this.context.connection.connectionId===o.userId?console.warn(`You are still in the room [${s}] ${o.userId}`):console.log(`User is still in room [${s}] ${o.userId}`)):(st&&console.log(`Remove call ${[s]} to user that is not in room anymore ${o.userId}`),o.close(),i.splice(s,1))}}this.peer.updateCalls(),this.debug&&this.debugLogCurrentState()}debugLogCurrentState(){console.warn(`You (${this.context.connection.connectionId}) are currently sending ${this._sendingStreams.size} and receiving ${this.peer.incomingCalls.length} calls (${this.peer.incomingCalls.map(t=>t.userId).join(", ")})`,this.peer.incomingCalls)}}function Jn(n){if(n&&n instanceof MediaStream)for(const t of n.getTracks())t.stop()}var DM=Object.defineProperty,BM=Object.getOwnPropertyDescriptor,_f=(n,t,i,s)=>{for(var o=s>1?void 0:s?BM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&DM(t,i,o),o};const FM="noVoip",zM=C("debugvoip");class Io extends I{constructor(){super(...arguments),a(this,"autoConnect",!0),a(this,"runInBackground",!0),a(this,"createMenuButton",!0),a(this,"debug",!1),a(this,"_net"),a(this,"_menubutton"),a(this,"_allowSending",!0),a(this,"_outputStream",null),a(this,"onJoinedRoom",async()=>{this.debug&&console.log("VOIP: Joined room"),await fn(300),this.autoConnect&&!this.isSending&&this._allowSending&&this.connect()}),a(this,"onLeftRoom",()=>{this.debug&&console.log("VOIP: Left room"),this.disconnect();for(const t of this._incomingStreams.values())Jn(t.srcObject);this._incomingStreams.clear()}),a(this,"_incomingStreams",new Map),a(this,"onReceiveStream",t=>{const i=t.target.userId,s=t.stream;let o=this._incomingStreams.get(i);o||(o=new Audio,this._incomingStreams.set(i,o)),o.srcObject=s,o.setAttribute("autoplay","true"),Wn.registerWaitForInteraction(()=>{o?.play().catch(r=>{console.error("VOIP: Failed to play audio",r)})})}),a(this,"onStreamEnded",t=>{const i=this._incomingStreams.get(t.userId);Jn(i?.srcObject),this._incomingStreams.delete(t.userId)}),a(this,"onEnabledChanged",()=>{for(const t of this._incomingStreams){const i=t[1];i.muted=!this.enabled}}),a(this,"onVisibilityChanged",()=>{if(this.runInBackground)return;const t=document.visibilityState!=="visible";this.setMuted(t);for(const i of this._incomingStreams){const s=i[1];s.muted=t}})}awake(){zM&&(this.debug=!0),this.debug&&(console.log("VOIP debugging: press 'v' to toggle mute or 'c' to toggle connect/disconnect"),window.addEventListener("keydown",async t=>{switch(t.key.toLowerCase()){case"v":console.log("MUTE?",!this.isMuted),this.setMuted(!this.isMuted);break;case"c":this.isSending?this.disconnect():this.connect();break}}),window.addEventListener("blur",()=>{console.log("VOIP: MUTE ON BLUR"),this.setMuted(!0)}),window.addEventListener("focus",()=>{console.log("VOIP: UNMUTE ON FOCUS"),this.setMuted(!1)}))}onEnable(){this._net||(this._net=sd.create(this)),this.debug&&(this._net.debug=!0),this._net.addEventListener(Zn.StreamReceived,this.onReceiveStream),this._net.addEventListener(Zn.StreamEnded,this.onStreamEnded),this._net.enable(),this.autoConnect&&this.context.connection.isConnected&&this.connect(),this.context.connection.beginListen(ne.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ne.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.addEventListener("visibilitychange",this.onVisibilityChanged)}onDisable(){var t;this._net&&(this._net.stopSendingStream(this._outputStream),this._net.removeEventListener(Zn.StreamReceived,this.onReceiveStream),this._net.removeEventListener(Zn.StreamEnded,this.onStreamEnded),(t=this._net)==null||t.disable()),this.context.connection.stopListen(ne.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ne.LeftRoom,this.onLeftRoom),this.onEnabledChanged(),this.updateButton(),window.removeEventListener("visibilitychange",this.onVisibilityChanged)}onDestroy(){var t;(t=this._menubutton)==null||t.remove(),this._menubutton=void 0}get isSending(){return this._outputStream!=null&&this._outputStream.active}async connect(t){var i,s;if(!this._net)return console.error("Cannot connect to voice chat - NetworkedStreams not initialized. Make sure the component is enabled before calling this method."),!1;if(this.context.connection.isConnected){if(!await Q.microphonePermissionsGranted())return console.error("Cannot connect to voice chat - microphone permissions not granted"),this.updateButton(),!1}else return console.error("Cannot connect to voice chat - not connected to server"),this.updateButton(),!1;return this._allowSending=!0,(i=this._net)==null||i.stopSendingStream(this._outputStream),Jn(this._outputStream),this._outputStream=await this.getAudioStream(t),this._outputStream?(this.debug&&console.log("VOIP: Got audio stream"),(s=this._net)==null||s.startSendingStream(this._outputStream),this.updateButton(),!0):(this.updateButton(),await Q.microphonePermissionsGranted()?console.error("VOIP: Could not get audio stream - please make sure to connect an audio device and grant microphone permissions"):ic("Microphone permissions not granted: Please grant microphone permissions to use voice chat"),(this.debug||B())&&console.log("VOIP: Failed to get audio stream"),!1)}disconnect(t){var i;t!=null&&t.remember&&(this._allowSending=!1),(i=this._net)==null||i.stopSendingStream(this._outputStream),Jn(this._outputStream),this._outputStream=null,this.updateButton()}setMuted(t){var i;const s=(i=this._outputStream)==null?void 0:i.getAudioTracks();if(s)for(const o of s)o.enabled=!t}get isMuted(){var t;if(this._outputStream===null)return!1;const i=(t=this._outputStream)==null?void 0:t.getAudioTracks();if(i){for(const s of i)if(!s.enabled)return!0}return!1}async updateButton(){var t;if(this.createMenuButton){if(this._menubutton||(this._menubutton=document.createElement("button"),this._menubutton.addEventListener("click",()=>{this.isSending?this.disconnect({remember:!0}):this.connect(),Q.microphonePermissionsGranted().then(i=>{i||_e("<strong>Microphone permissions not granted</strong>. Please allow your browser to use the microphone to be able to talk. Click on the button on the left side of your browser's address bar to allow microphone permissions.")})})),this._menubutton){this.context.menu.appendChild(this._menubutton),this.activeAndEnabled?this._menubutton.style.display="":this._menubutton.style.display="none",this._menubutton.title=this.isSending?"Click to disable your microphone":"Click to enable your microphone";let i=(this.isSending,""),s=this.isSending?"mic":"mic_off";await Q.microphonePermissionsGranted()||(i="No Permission",s="mic_off",this._menubutton.title="Microphone permissions not granted. Please allow your browser to use the microphone to be able to talk. This can usually be done in the addressbar of the webpage."),this._menubutton.innerText=i,this._menubutton.prepend(Pt(s)),this.context.connection.isConnected==!1?this._menubutton.setAttribute("disabled",""):this._menubutton.removeAttribute("disabled")}}else this.activeAndEnabled||(t=this._menubutton)==null||t.remove()}getFrequency(t){return this.unsupported_getfrequency||(this.unsupported_getfrequency=!0,B()&&_e("VOIP: getFrequency is currently not supported"),console.warn("VOIP: getFrequency is currently not supported")),null}async getAudioStream(t){if(!navigator.mediaDevices.getUserMedia)return console.error("No getDisplayMedia support"),null;const i=async o=>await navigator.mediaDevices.getUserMedia({audio:o??!0,video:!1}).catch(r=>(console.warn("VOIP failed getting audio stream",r),null)),s=await i(t);if(!s)return null;if(Q.isiOS()&&t?.deviceId===void 0){const o=(await navigator.mediaDevices.enumerateDevices()).find(r=>(r.kind==="audioinput"||r.kind==="audiooutput")&&!r.label.includes("iPhone"));if(o){const r=Object.assign({},t);return r.deviceId=o.deviceId,await i(r)}}return s}}_f([m()],Io.prototype,"autoConnect",2),_f([m()],Io.prototype,"runInBackground",2),_f([m()],Io.prototype,"createMenuButton",2);var UM=Object.defineProperty,NM=Object.getOwnPropertyDescriptor,Vw=(n,t,i,s)=>{for(var o=s>1?void 0:s?NM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&UM(t,i,o),o};const WM=C("debugmouth");class Vc extends I{constructor(){super(...arguments),a(this,"idle",[]),a(this,"talking",[]),a(this,"marker",null),a(this,"voip",null),a(this,"lastMouthChangeTime",0),a(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=O.findObjectOfType(Io,this.context),this.marker||(this.marker=O.getComponentInParent(this.gameObject,Tt))},3e3)}update(){var t;if(!this.voip||this.context.time.frameCount%10!==0)return;let i=((t=this.marker)==null?void 0:t.connectionId)??null;if(!i){WM&&(i=null);return}const s=this.voip.getFrequency(i)??0;this.updateLips(s)}updateLips(t){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&t>30){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,i)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,i)}}}setMouthShapeActive(t,i){if(t){t!=this.idle?this.idle.map(s=>s.visible=!1):this.talking.map(s=>s.visible=!1);for(let s=0;s<t.length;s++){const o=t[s];o&&(o.visible=s===i)}}}}Vw([m(A)],Vc.prototype,"idle",2),Vw([m(A)],Vc.prototype,"talking",2);class wf extends I{constructor(){super(...arguments),a(this,"voip",null),a(this,"marker",null),a(this,"_startPosition",null)}awake(){this.voip=O.findObjectOfType(Io,this.context),this.marker=O.getComponentInParent(this.gameObject,Tt)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const t=this.marker.connectionId,i=this.voip.getFrequency(t);if(i==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const s=i/100;this.gameObject.position.y=this._startPosition.y+s*.07}}var VM=Object.defineProperty,HM=Object.getOwnPropertyDescriptor,$M=(n,t,i,s)=>{for(var o=s>1?void 0:s?HM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&VM(t,i,o),o};const $a=C("debugxrflags"),Hw=C("disablexrflags");Hw&&console.warn("XRFlags are disabled");var es=(n=>(n[n.Never=0]="Never",n[n.Browser=1]="Browser",n[n.AR=2]="AR",n[n.VR=4]="VR",n[n.FirstPerson=8]="FirstPerson",n[n.ThirdPerson=16]="ThirdPerson",n[n.All=4294967295]="All",n))(es||{});const $w=class{constructor(){a(this,"Mask",17)}Has(n){return(this.Mask&n)!==0}Set(n){$a&&console.warn("Set XR flag state to",n),this.Mask=n,ji.Apply()}Enable(n){this.Mask|=n,ji.Apply()}Disable(n){this.Mask&=~n,ji.Apply()}Toggle(n){this.Mask^=n,ji.Apply()}EnableAll(){this.Mask=-1,ji.Apply()}DisableAll(){this.Mask=0,ji.Apply()}};let ci=$w;a(ci,"Global",new $w);var Hc;const Bs=(Hc=class extends I{constructor(){super(...arguments),a(this,"visibleIn")}static Apply(){for(const n of this.registry)n.UpdateVisible(ci.Global)}awake(){Bs.registry.push(this)}onEnable(){Bs.firstApply?this.UpdateVisible(ci.Global):(Bs.firstApply=!0,Bs.Apply())}onDestroy(){const n=Bs.registry.indexOf(this);n>=0&&Bs.registry.splice(n,1)}get isOn(){return this.gameObject.visible}UpdateVisible(n=null){if(Hw)return;let t;const i=n;if(i&&typeof i=="number"&&(console.assert(typeof i=="number","XRFlag.UpdateVisible: state must be a number",i),$a&&console.log(i),Bs.buffer.Mask=i,n=Bs.buffer),n instanceof ci?($a&&console.warn(this.name,"use passed in mask",n.Mask,this.visibleIn),t=n.Has(this.visibleIn)):($a&&console.log(this.name,"use global mask"),ci.Global.Has(this.visibleIn)),t!==void 0)if(t)$a&&console.log(this.name,"is visible",this.gameObject.uuid),O.setActive(this.gameObject,!0);else{if($a&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},a(Hc,"registry",[]),a(Hc,"firstApply"),a(Hc,"buffer",new ci),Hc);let ji=Bs;$M([m()],ji.prototype,"visibleIn",2);var GM=Object.defineProperty,qM=Object.getOwnPropertyDescriptor,Lu=(n,t,i,s)=>{for(var o=s>1?void 0:s?qM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&GM(t,i,o),o};class Tr extends I{constructor(){super(...arguments),a(this,"eyes",[]),a(this,"lastBlinkTime",0),a(this,"blinkLength",0),a(this,"eyesOpen",!0),a(this,"state",null)}awake(){this.state=O.getComponentInParent(this.gameObject,ji)}update(){if(!(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)&&this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const t of this.eyes)t&&(t.visible=this.eyesOpen)}}}Lu([m(A)],Tr.prototype,"eyes",2),Lu([m()],Tr.prototype,"lastBlinkTime",2),Lu([m()],Tr.prototype,"blinkLength",2),Lu([m()],Tr.prototype,"eyesOpen",2);var XM=Object.defineProperty,QM=Object.getOwnPropertyDescriptor,xf=(n,t,i,s)=>{for(var o=s>1?void 0:s?QM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&XM(t,i,o),o},Sf;const Gw=(Sf=class extends I{constructor(){super(...arguments),a(this,"head",null),a(this,"eyes",null),a(this,"target",null),a(this,"brain",null),a(this,"vec",new x),a(this,"currentTargetPoint",new x)}awake(){this.brain||(this.brain=O.getComponentInParent(this.gameObject,Uc)),this.brain||(this.brain=O.addComponent(this.gameObject,Uc)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const n=this.target;if(n&&this.head){const t=this.eyes;if(t){const i=te(n);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const s=te(this.head),o=this.vec.copy(this.currentTargetPoint).sub(s).normalize();if(o.length()<.1)return;const r=Gw.forward;if(r.set(0,0,1),r.applyQuaternion(Ce(this.head)),r.dot(o)>.45)for(let l=0;l<t.length;l++)t[l].lookAt(this.currentTargetPoint)}}}},a(Sf,"forward",new x(0,0,1)),Sf);let Ga=Gw;xf([m(A)],Ga.prototype,"head",2),xf([m(A)],Ga.prototype,"eyes",2),xf([m(A)],Ga.prototype,"target",2);var YM=Object.defineProperty,KM=Object.getOwnPropertyDescriptor,Cf=(n,t,i,s)=>{for(var o=s>1?void 0:s?KM(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&YM(t,i,o),o};class qa extends I{constructor(){super(...arguments),a(this,"length",1),a(this,"depthTest",!0),a(this,"isGizmo",!1),a(this,"_axes",null)}onEnable(){if(this.isGizmo&&!vc)return;this._axes||(this._axes=new Si(this.length)),this._axes.layers.disableAll(),this._axes.layers.set(this.layer),this.gameObject.add(this._axes);const t=this._axes.material;t&&t.depthTest!==void 0&&(t.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}Cf([m()],qa.prototype,"length",2),Cf([m()],qa.prototype,"depthTest",2),Cf([m()],qa.prototype,"isGizmo",2);class Of extends I{constructor(){super(...arguments),a(this,"from"),a(this,"to"),a(this,"hint"),a(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const t=te(this.to).clone(),i=te(this.from).clone(),s=t.distanceTo(i),o=t.clone();o.sub(i);const r=i.clone();r.add(t),r.multiplyScalar(.5);const l=te(this.hint).clone();l.sub(r);const c=new x;c.crossVectors(l,o),c.crossVectors(o,c),c.normalize();const h=s*.5,d=Math.max(this.desiredDistance,h),u=Math.sqrt(d*d-h*h),p=c.clone();p.multiplyScalar(u),p.add(r),ht(this.gameObject,p);const g=r.clone();g.sub(c),this.gameObject.lookAt(g)}}const ZM=C("gizmos"),JM=C("debugboxhelper"),ts=class extends I{constructor(){super(...arguments),a(this,"box",null),a(this,"_lastMatrixUpdateFrame",-1),a(this,"_helper",null),a(this,"_color",null)}isInBox(n){var t;if(!n)return;if(this.box||(this.box=new xi),oi([n],void 0,void 0,ts.testBox),ts.testBox.isEmpty()){const s=te(n,ts._position);ts.testBox.setFromCenterAndSize(s,ts._emptyObjectSize)}this.updateBox();const i=(t=this.box)==null?void 0:t.intersectsBox(ts.testBox);return i&&JM&&$.DrawWireBox3(ts.testBox,16711680,5),i}intersects(n){return n?this.updateBox(!1).intersectsBox(n):!1}updateBox(n=!1){if(this.box||(this.box=new xi),n||this.context.time.frameCount!=this._lastMatrixUpdateFrame){const t=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;const i=t,s=te(this.gameObject,ts._position,i),o=Ye(this.gameObject,ts._size);this.box.setFromCenterAndSize(s,o)}return this.box}awake(){this._helper=null,this._color=null,this.box=null}showHelper(n=null,t=!1){var i;if(!(!ZM&&!t)){if(this._helper){n&&((i=this._color)==null||i.set(n)),this.gameObject.add(this._helper);return}this._helper=fg(n),this.gameObject.add(this._helper)}}};let Ji=ts;a(Ji,"testBox",new xi),a(Ji,"_position",new x),a(Ji,"_size",new x(.01,.01,.01)),a(Ji,"_emptyObjectSize",new x(.01,.01,.01));var eR=Object.defineProperty,tR=Object.getOwnPropertyDescriptor,hi=(n,t,i,s)=>{for(var o=s>1?void 0:s?tR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&eR(t,i,o),o};class di extends I{constructor(){super(...arguments),a(this,"attachedRigidbody",null),a(this,"isTrigger",!1),a(this,"sharedMaterial"),a(this,"membership",[0]),a(this,"filter"),a(this,"updateProperties",()=>{var t;(t=this.context.physics.engine)==null||t.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(ve))}onDisable(){var t;(t=this.context.physics.engine)==null||t.removeBody(this)}get body(){var t;return(t=this.context.physics.engine)==null?void 0:t.getBody(this)}updatePhysicsMaterial(){var t;(t=this.context.physics.engine)==null||t.updatePhysicsMaterial(this)}}hi([m(ve)],di.prototype,"attachedRigidbody",2),hi([m()],di.prototype,"isTrigger",2),hi([m()],di.prototype,"sharedMaterial",2),hi([m()],di.prototype,"membership",2),hi([m()],di.prototype,"filter",2);class Xa extends di{constructor(){super(...arguments),a(this,"radius",.5),a(this,"center",new x(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addSphereCollider(this),yd(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),km(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}hi([Mt(),m()],Xa.prototype,"radius",2),hi([m(x)],Xa.prototype,"center",2);const qw=class extends di{constructor(){super(...arguments),a(this,"size",new x(1,1,1)),a(this,"center",new x(0,0,0))}static add(n,t){const i=Ti(n,qw);return i.autoFit(),t?.rigidbody===!0&&Ti(n,ve,{isKinematic:!1}),i}onEnable(){var n;super.onEnable(),(n=this.context.physics.engine)==null||n.addBoxCollider(this,this.size),yd(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),km(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}autoFit(n){const t=this.gameObject,i=t.position.clone(),s=t.quaternion.clone(),o=t.scale.clone(),r=t.parent;t.position.set(0,0,0),t.quaternion.set(0,0,0,1),t.scale.set(1,1,1),t.parent=null,t.updateMatrix();const l=oi([t]);t.position.copy(i),t.quaternion.copy(s),t.scale.copy(o),t.parent=r,n?.debug===!0&&$.DrawWireBox3(l,16768256,20),this.size=l.getSize(new x)||new x(1,1,1),this.center=l.getCenter(new x)||new x(0,0,0),this.size.length()<=0&&this.size.set(.01,.01,.01)}};let Qa=qw;hi([Mt(),m(x)],Qa.prototype,"size",2),hi([m(x)],Qa.prototype,"center",2);class jo extends di{constructor(){super(...arguments),a(this,"sharedMesh"),a(this,"convex",!1)}onEnable(){var t,i,s;if(super.onEnable(),!this.context.physics.engine)return;(t=this.sharedMesh)!=null&&t.isMesh||(this.gameObject instanceof X||this.gameObject instanceof ho)&&(this.sharedMesh=this.gameObject);const o=0;if((i=this.sharedMesh)!=null&&i.isMesh)this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex),it.assignMeshLOD(this.sharedMesh,o).then(r=>{r&&this.activeAndEnabled&&this.context.physics.engine&&this.sharedMesh&&(this.context.physics.engine.removeBody(this),this.sharedMesh.geometry=r,this.context.physics.engine.addMeshCollider(this,this.sharedMesh,this.convex))});else{const r=this.sharedMesh;if(r!=null&&r.isGroup){console.warn(`MeshCollider mesh is a group "${((s=this.sharedMesh)==null?void 0:s.name)||this.gameObject.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);const l=new Array;for(const c in r.children){const h=r.children[c];h.isMesh&&(this.context.physics.engine.addMeshCollider(this,h,this.convex),l.push(it.assignMeshLOD(h,o)))}Promise.all(l).then(c=>{var h,d;if(c.some(p=>p)==!1)return;(h=this.context.physics.engine)==null||h.removeBody(this);const u=new X;for(const p of c)p&&this.activeAndEnabled&&(u.geometry=p,(d=this.context.physics.engine)==null||d.addMeshCollider(this,u,this.convex))})}else(B()||C("showcolliders"))&&console.warn(`[MeshCollider] A MeshCollider mesh is assigned to an unknown object on "${this.gameObject.name}", but it's neither a Mesh nor a Group. Please double check that you attached the collider component to the right object and report a bug otherwise!`,this)}}}hi([m(X)],jo.prototype,"sharedMesh",2),hi([m()],jo.prototype,"convex",2);class Fs extends di{constructor(){super(...arguments),a(this,"center",new x(0,0,0)),a(this,"radius",.5),a(this,"height",2)}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addCapsuleCollider(this,this.height,this.radius)}}hi([m(x)],Fs.prototype,"center",2),hi([m()],Fs.prototype,"radius",2),hi([m()],Fs.prototype,"height",2);var iR=Object.defineProperty,nR=Object.getOwnPropertyDescriptor,zs=(n,t,i,s)=>{for(var o=s>1?void 0:s?nR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&iR(t,i,o),o};const Xw=C("debugcharactercontroller");class Er extends I{constructor(){super(...arguments),a(this,"center",new x(0,0,0)),a(this,"radius",.5),a(this,"height",2),a(this,"_rigidbody",null),a(this,"_activeGroundCollisions"),a(this,"_contactVelocity",new x)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(ve),this._rigidbody||(this._rigidbody=this.gameObject.addComponent(ve)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const t=this.rigidbody;let i=this.gameObject.getComponent(Fs);i||(i=this.gameObject.addComponent(Fs)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height;const s=new x(0,0,1),o=new x(1,0,0),r=new x(0,1,0),l=this.gameObject.getWorldDirection(new x);l.y=0;const c=o.dot(l)<0?-1:1,h=s.angleTo(l)*c;this.gameObject.setRotationFromAxisAngle(r,h),t.lockRotationX=!0,t.lockRotationY=!0,t.lockRotationZ=!0}move(t){this.gameObject.position.add(t)}onCollisionEnter(t){(t.contacts.length==0||t.contacts.some(i=>i.normal.y>.2))&&(this._activeGroundCollisions.add(t),Xw&&console.log(`Collision(${this._activeGroundCollisions.size}): ${t.contacts.map(i=>i.normal.y.toFixed(2)).join(", ")} - ${this.isGrounded}`))}onCollisionExit(t){this._activeGroundCollisions.delete(t),Xw&&console.log(`Collision(${this._activeGroundCollisions.size}) - ${this.isGrounded}`)}get isGrounded(){return this._activeGroundCollisions.size>0}get contactVelocity(){var t;this._contactVelocity.set(0,0,0);for(const i of this._activeGroundCollisions){const s=(t=this.context.physics.engine)==null?void 0:t.getLinearVelocity(i.collider);s&&(this._contactVelocity.x+=s.x,this._contactVelocity.y+=s.y,this._contactVelocity.z+=s.z)}return this._contactVelocity}}zs([m(x)],Er.prototype,"center",2),zs([m()],Er.prototype,"radius",2),zs([m()],Er.prototype,"height",2);class Us extends I{constructor(){super(...arguments),a(this,"controller"),a(this,"movementSpeed",2),a(this,"rotationSpeed",2),a(this,"jumpForce",1),a(this,"doubleJumpForce",2),a(this,"animator"),a(this,"lookForward",!0),a(this,"lookInput",new re(0,0)),a(this,"moveInput",new re(0,0)),a(this,"jumpInput",!1),a(this,"_currentSpeed",new x(0,0,0)),a(this,"_currentAngularSpeed",new x(0,0,0)),a(this,"_temp",new x(0,0,0)),a(this,"_jumpCount",0),a(this,"_currentRotation"),a(this,"_raycastOptions",new Hn)}awake(){this._currentRotation=new V}update(){const t=this.context.input;t.isKeyPressed("KeyW")?this.moveInput.y+=1:t.isKeyPressed("KeyS")&&(this.moveInput.y-=1),t.isKeyPressed("KeyD")?this.lookInput.x+=1:t.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=t.isKeyDown("Space"))}move(t){this.moveInput.add(t)}look(t){this.lookInput.add(t)}jump(){this.jumpInput=!0}onBeforeRender(){this.handleInput(this.moveInput,this.lookInput,this.jumpInput),this.lookInput.set(0,0),this.moveInput.set(0,0),this.jumpInput=!1}handleInput(t,i,s){var o,r,l,c,h,d,u,p,g,f,y;if((o=this.controller)!=null&&o.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((r=this.animator)==null||r.setBool("doubleJump",!1))),this._currentSpeed.z+=t.y*this.movementSpeed*this.context.time.deltaTime,(l=this.animator)==null||l.setBool("running",t.length()>.01),(h=this.animator)==null||h.setBool("jumping",((c=this.controller)==null?void 0:c.isGrounded)===!0&&s),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp),this._currentAngularSpeed.y+=W.toRadians(-i.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const b=this.context.mainCameraComponent.forward;b.y=0,b.normalize(),this._currentRotation.setFromUnitVectors(new x(0,0,1),b),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&s&&this.jumpForce>0){let b=(d=this.controller)==null?void 0:d.isGrounded;if(this.doubleJumpForce>0&&!((u=this.controller)!=null&&u.isGrounded)&&this._jumpCount===1&&(b=!0,(p=this.animator)==null||p.setBool("doubleJump",!0)),b){this._jumpCount+=1;const v=this.controller.rigidbody,w=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;v.applyImpulse(new x(0,1,0).multiplyScalar(w))}}if(this.controller){const b=(g=this.controller)==null?void 0:g.rigidbody.getVelocity().y;if(b<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new co),this._raycastOptions.ray.origin.copy(te(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const v=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const w=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(v),(w.length&&w[0].distance>2||b<-10)&&((f=this.animator)==null||f.setBool("falling",!0))}else(y=this.animator)==null||y.setBool("falling",!1)}}}zs([m(Er)],Us.prototype,"controller",2),zs([m()],Us.prototype,"movementSpeed",2),zs([m()],Us.prototype,"rotationSpeed",2),zs([m()],Us.prototype,"jumpForce",2),zs([m()],Us.prototype,"doubleJumpForce",2),zs([m(kt)],Us.prototype,"animator",2);var sR=Object.defineProperty,oR=Object.getOwnPropertyDescriptor,Ya=(n,t,i,s)=>{for(var o=s>1?void 0:s?oR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&sR(t,i,o),o};const $c=C("debugcontactshadows");Ow(n=>{const t=n.domElement.getAttribute("contactshadows")||n.domElement.getAttribute("contact-shadows");if(t!=null&&t!="0"&&t!="false"){console.debug("Auto-creating ContactShadows because of `contactshadows` attribute");const i=Pn.auto(n),s=parseFloat(t);isNaN(s)||(i.opacity=s,i.darkness=s)}});var Pf;const Gc=(Pf=class extends I{constructor(){super(...arguments),a(this,"autoFit",!1),a(this,"darkness",.5),a(this,"opacity",.5),a(this,"blur",4),a(this,"occludeBelowGround",!1),a(this,"backfaceShadows",!0),a(this,"minSize"),a(this,"manualUpdate",!1),a(this,"_needsUpdate",!1),a(this,"shadowsRoot",new A),a(this,"shadowCamera"),a(this,"shadowGroup",new ho),a(this,"renderTarget"),a(this,"renderTargetBlur"),a(this,"plane"),a(this,"occluderMesh"),a(this,"blurPlane"),a(this,"depthMaterial"),a(this,"horizontalBlurMaterial"),a(this,"verticalBlurMaterial"),a(this,"textureSize",512)}static auto(n){if(n||(n=ee.Current),!n)throw new Error("No context provided and no current context set.");let t=this._instances.get(n);if(!t||t.destroyed){const i=new A;t=Ti(i,Gc,{autoFit:!1,occludeBelowGround:!1}),this._instances.set(n,t)}return n.scene.add(t.gameObject),t.fitShadows(),t}set needsUpdate(n){this._needsUpdate=n}get needsUpdate(){return this._needsUpdate}fitShadows(){$c&&console.warn("Fitting shadows to scene"),wd(this.shadowsRoot,!1);const n=oi(this.context.scene.children,[this.shadowsRoot]),t=Math.max(1,this.blur/32),i=n.max.x-n.min.x,s=n.max.z-n.min.z;n.expandByVector(new x(t*i,0,t*s)),$c&&$.DrawWireBox3(n,16776960,60),this.gameObject.parent&&n.applyMatrix4(this.gameObject.parent.matrixWorld.clone().invert());const o=n.min,r=Math.max(1e-5,(n.max.y-o.y)*.002);n.max.y+=r,this.shadowsRoot.position.set((o.x+n.max.x)/2,o.y-r,(o.z+n.max.z)/2),this.shadowsRoot.scale.set(n.max.x-o.x,n.max.y-o.y,n.max.z-o.z),this.applyMinSize(),this.shadowsRoot.matrixWorldNeedsUpdate=!0,$c&&console.log("Fitted shadows to scene",this.shadowsRoot.scale.clone())}awake(){Gc._instances.set(this.context,this),this.shadowsRoot.hideFlags=ju.DontExport,wd(this.shadowsRoot,!1)}start(){$c&&console.log("Create ContactShadows on "+this.gameObject.name,this),this.gameObject.add(this.shadowsRoot),this.shadowsRoot.add(this.shadowGroup),this.renderTarget=new xs(this.textureSize,this.textureSize),this.renderTarget.texture.generateMipmaps=!1,this.renderTargetBlur=new xs(this.textureSize,this.textureSize),this.renderTargetBlur.texture.generateMipmaps=!1;const n=new Fn(1,1).rotateX(Math.PI/2);this.gameObject instanceof X&&(console.warn("ContactShadows can not be added to a Mesh. Please add it to a Group or an empty Object"),Ts(this.gameObject,!1));const t=new Re({map:this.renderTarget.texture,opacity:this.opacity,color:0,transparent:!0,depthWrite:!1,side:po});this.plane=new X(n,t),this.plane.scale.y=-1,this.plane.layers.set(2),this.shadowsRoot.add(this.plane),this.plane&&(this.plane.renderOrder=1),this.occluderMesh=new X(this.plane.geometry,new Re({depthWrite:!0,stencilWrite:!0,colorWrite:!1,side:dd})).translateY(-1e-4),this.occluderMesh.renderOrder=-100,this.occluderMesh.layers.set(2),this.shadowsRoot.add(this.occluderMesh),this.blurPlane=new X(n),this.blurPlane.visible=!1,this.shadowGroup.add(this.blurPlane);const i=0,s=1;this.shadowCamera=new dm(-1/2,1/2,1/2,-1/2,i,s),this.shadowCamera.layers.enableAll(),this.shadowCamera.rotation.x=Math.PI/2,this.shadowGroup.add(this.shadowCamera),this.depthMaterial=new zS,this.depthMaterial.userData.darkness={value:this.darkness},this.depthMaterial.blending=US,this.depthMaterial.blendEquation=NS,this.depthMaterial.onBeforeCompile=o=>{this.depthMaterial&&(o.uniforms.darkness=this.depthMaterial.userData.darkness,o.fragmentShader=`
|
|
933
933
|
uniform float darkness;
|
|
934
934
|
${o.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 1.0 ), ( 1.0 - fragCoordZ ) * darkness * opacity * (gl_FrontFacing ? 1.0 : 0.66) );")}
|
|
935
|
-
`)},this.depthMaterial.depthTest=!1,this.depthMaterial.depthWrite=!1,this.horizontalBlurMaterial=new gn(HC),this.horizontalBlurMaterial.depthTest=!1,this.verticalBlurMaterial=new gn($C),this.verticalBlurMaterial.depthTest=!1,this.shadowGroup.visible=!1,this.autoFit?this.fitShadows():this.applyMinSize()}onDestroy(){var n,t,i,s,o,r,l,c;Gc._instances.get(this.context)===this&&Gc._instances.delete(this.context),(n=this.renderTarget)==null||n.dispose(),(t=this.renderTargetBlur)==null||t.dispose(),(i=this.depthMaterial)==null||i.dispose(),(s=this.horizontalBlurMaterial)==null||s.dispose(),(o=this.verticalBlurMaterial)==null||o.dispose(),(r=this.blurPlane)==null||r.geometry.dispose(),(l=this.plane)==null||l.geometry.dispose(),(c=this.occluderMesh)==null||c.geometry.dispose()}onBeforeRender(n){if(!this.renderTarget||!this.renderTargetBlur||!this.depthMaterial||!this.shadowCamera||!this.blurPlane||!this.shadowGroup||!this.plane||!this.horizontalBlurMaterial||!this.verticalBlurMaterial){$c&&console.error("ContactShadows: not initialized yet");return}const t=this.context.scene,i=this.context.renderer,s=i.getRenderTarget();this.shadowGroup.visible=!0,this.occluderMesh&&(this.occluderMesh.visible=!1);const o=this.plane.visible;this.plane.visible=!1,this.gameObject instanceof X&&Ts(this.gameObject,!1);const r=t.background;t.background=null,t.overrideMaterial=this.depthMaterial,this.backfaceShadows?this.depthMaterial.side=Ci:this.depthMaterial.side=po;const l=i.getClearAlpha();i.setClearAlpha(0);const c=i.xr.enabled;i.xr.enabled=!1;const h=this.context.scene.matrixWorldAutoUpdate;this.context.scene.matrixWorldAutoUpdate=!1;const d=i.renderLists.get(t,0),u=d.transparent;Qw.length=0,d.transparent=Qw,kf.length=0;for(const g of d.opaque){if(!g.object.visible)continue;const f=g.material;let y=g.material.colorWrite==!1||f.wireframe===!0||Kv(g.object)===!1;!y&&g.material.isLineMaterial&&(y=!0),!y&&g.material.isPointsMaterial&&(y=!0),y&&(kf.push(g.object),g.object["needle:visible"]=g.object.visible,g.object.visible=!1)}i.setRenderTarget(this.renderTarget),i.clear(),i.render(t,this.shadowCamera),d.transparent=u;for(const g of kf)g["needle:visible"]!=null&&(g.visible=g["needle:visible"]);t.overrideMaterial=null;const p=Math.max(this.blur,.05);this.blurShadow(p*2),this.blurShadow(p*.5),this.shadowGroup.visible=!1,this.occluderMesh&&(this.occluderMesh.visible=this.occludeBelowGround),this.plane.visible=o,i.setRenderTarget(s),i.setClearAlpha(l),t.background=r,i.xr.enabled=c,this.context.scene.matrixWorldAutoUpdate=h}blurShadow(n){if(!this.blurPlane||!this.shadowCamera||!this.renderTarget||!this.renderTargetBlur||!this.horizontalBlurMaterial||!this.verticalBlurMaterial)return;this.blurPlane.visible=!0;const t=this.shadowsRoot.worldScale,i=(t.x+t.z)/2,s=t.z/i,o=t.x/i;this.blurPlane.material=this.horizontalBlurMaterial,this.blurPlane.material.uniforms.tDiffuse.value=this.renderTarget.texture,this.horizontalBlurMaterial.uniforms.h.value=n*1/this.textureSize*s;const r=this.context.renderer,l=r.getRenderTarget();r.setRenderTarget(this.renderTargetBlur),r.render(this.blurPlane,this.shadowCamera),this.blurPlane.material=this.verticalBlurMaterial,this.blurPlane.material.uniforms.tDiffuse.value=this.renderTargetBlur.texture,this.verticalBlurMaterial.uniforms.v.value=n*1/this.textureSize*o,r.setRenderTarget(this.renderTarget),r.render(this.blurPlane,this.shadowCamera),this.blurPlane.visible=!1,r.setRenderTarget(l)}applyMinSize(){this.minSize&&this.shadowsRoot.scale.set(Math.max(this.minSize.x||0,this.shadowsRoot.scale.x),Math.max(this.minSize.y||0,this.shadowsRoot.scale.y),Math.max(this.minSize.z||0,this.shadowsRoot.scale.z))}},a(Pf,"_instances",new Map),Pf);let Pn=Gc;Ya([m()],Pn.prototype,"autoFit",2),Ya([m()],Pn.prototype,"darkness",2),Ya([m()],Pn.prototype,"opacity",2),Ya([m()],Pn.prototype,"blur",2),Ya([m()],Pn.prototype,"occludeBelowGround",2),Ya([m()],Pn.prototype,"backfaceShadows",2);const Qw=[],kf=new Array,rR=C("logstats");class Mf extends I{onEnable(){console.log(this),rR&&this.startCoroutine(this.run(),Me.OnAfterRender)}*run(){for(;this.enabled;){const t=this.context.renderer.info;console.log(t.memory,t.render,t.programs),yield}}}class qc extends I{constructor(){super(...arguments),a(this,"isUsed",!0),a(this,"usedBy",null)}}class Rf extends I{}const Yw=C("debugdeletable"),Du=class extends Ji{onEnable(){Du._instances.push(this)}onDisable(){const n=Du._instances.indexOf(this);n>=0&&Du._instances.splice(n,1)}};let Xc=Du;a(Xc,"_instances",[]);class Tf extends I{update(){for(const t of Xc._instances){const i=this.gameObject;if(t.isInBox(i)===!0){const s=O.getComponentInParent(this.gameObject,qc);if(s)Yw&&console.warn("DeleteBox: Not deleting object with usage marker",this.guid,s);else{if(Yw)try{if(t.box){const o=t.box,r=Ji.testBox;$.DrawWireBox3(o,16711680,5),$.DrawWireBox3(r,255,5),console.log("DeleteBox: Destroying",this.gameObject,{deleteBoxArea:o,deletedObjectArea:r})}else console.log("DeleteBox: Destroying",this.gameObject)}catch{}yc(this.gameObject,this.context.connection)}}}}}var aR=Object.defineProperty,lR=Object.getOwnPropertyDescriptor,cR=(n,t,i,s)=>{for(var o=s>1?void 0:s?lR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&aR(t,i,o),o};class Bu extends I{constructor(){super(...arguments),a(this,"visibleOn")}onEnable(){this.apply()}apply(){this.test()||O.setActive(this.gameObject,!1)}test(){return this.visibleOn<0?!0:Q.isMobileDevice()?(this.visibleOn&2)!==0:(this.visibleOn&1)!==0}}cR([m()],Bu.prototype,"visibleOn",2);var hR=Object.defineProperty,dR=Object.getOwnPropertyDescriptor,Ar=(n,t,i,s)=>{for(var o=s>1?void 0:s?dR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&hR(t,i,o),o};const is=C("debugdrag"),Ef=[];var Af=(n=>(n[n.XZPlane=0]="XZPlane",n[n.Attached=1]="Attached",n[n.HitNormal=2]="HitNormal",n[n.DynamicViewAngle=3]="DynamicViewAngle",n[n.SnapToSurfaces=4]="SnapToSurfaces",n[n.None=5]="None",n))(Af||{}),Qc;const en=(Qc=class extends I{constructor(){super(...arguments),a(this,"dragMode",3),a(this,"snapGridResolution",0),a(this,"keepRotation",!0),a(this,"xrDragMode",1),a(this,"xrKeepRotation",!1),a(this,"xrDistanceDragFactor",1),a(this,"showGizmo",!1),a(this,"_rigidbody",null),a(this,"_targetObject",null),a(this,"_dragHelper",null),a(this,"_draggingRigidbodies",[]),a(this,"_potentialDragStartEvt",null),a(this,"_dragHandlers",new Map),a(this,"_totalMovement",new x),a(this,"_marker",null),a(this,"_isDragging",!1),a(this,"_didDrag",!1)}static get HasAnySelected(){return this._active>0}static get CurrentlySelected(){Ef.length=0;for(const n of this._instances)n._isDragging&&Ef.push(n);return Ef}get draggedObject(){return this._targetObject}setTargetObject(n){var t,i;this._targetObject=n;for(const o of this._dragHandlers.values())o.setTargetObject(n);const s="_rigidbody-was-kinematic";((t=this._rigidbody)==null?void 0:t[s])===!1&&(this._rigidbody.isKinematic=!1,this._rigidbody[s]=void 0),this._rigidbody=null,n&&(this._rigidbody=O.getComponentInChildren(n,ve),((i=this._rigidbody)==null?void 0:i.isKinematic)===!1&&(this._rigidbody.isKinematic=!0,this._rigidbody[s]=!1))}awake(){this._potentialDragStartEvt=null,this._dragHandlers=new Map,this._totalMovement=new x,this._marker=null,this._isDragging=!1,this._didDrag=!1,this._dragHelper=null,this._draggingRigidbodies=[]}start(){this.gameObject.getComponentInParent(Ii)||this.gameObject.addComponent(Ii)}onEnable(){en._instances.push(this)}onDisable(){en._instances=en._instances.filter(n=>n!==this)}allowEdit(n=null){return this.context.connection.allowEditing}onPointerEnter(n){if(!this.allowEdit(this.gameObject)||n.mode!=="screen"||(n.event.mode==="tracked-pointer"||n.event.mode==="transient-pointer"?this.xrDragMode:this.dragMode)===5)return;const t=O.getComponentInParent(n.object,en);!t||t!==this||(en.lastHovered=n.object,this.context.domElement.style.cursor="pointer")}onPointerMove(n){(this._isDragging||this._potentialDragStartEvt!==null)&&n.use()}onPointerExit(n){this.allowEdit(this.gameObject)&&n.mode==="screen"&&en.lastHovered===n.object&&(this.context.domElement.style.cursor="auto")}onPointerDown(n){if(!(!this.allowEdit(this.gameObject)||n.used||(n.mode==="tracked-pointer"||n.mode==="transient-pointer"?this.xrDragMode:this.dragMode)===5)&&(en.lastHovered=n.object,n.button===0)){this._dragHandlers.size===0&&(this._didDrag=!1,this._totalMovement.set(0,0,0),this._potentialDragStartEvt=n),this._targetObject||this.setTargetObject(this.gameObject),en._active+=1;const t=new If(this,this._targetObject);if(this._dragHandlers.set(n.event.space,t),t.onDragStart(n),this._dragHandlers.size===2){const i=this._dragHandlers.values(),s=i.next().value,o=i.next().value;if(s instanceof If&&o instanceof If){const r=new uR(this,this._targetObject,s,o);this._dragHandlers.set(this.gameObject,r),r.onDragStart(n)}else console.error("Attempting to construct a MultiTouchDragHandler with invalid DragPointerHandlers. This is likely a bug.",{a:s,b:o})}n.use()}}onPointerUp(n){if(is&&$.DrawLabel(n.point??this.gameObject.worldPosition,"POINTERUP:"+n.pointerId+", "+n.button,.03,3),!this.allowEdit(this.gameObject)||n.button!==0)return;this._potentialDragStartEvt=null;const t=this._dragHandlers.get(n.event.space),i=this._dragHandlers.get(this.gameObject);i&&(i.handlerA===t||i.handlerB===t)&&(this._dragHandlers.delete(this.gameObject),i.onDragEnd(n)),t&&(en._active>0&&(en._active-=1),this.setTargetObject(null),t.onDragEnd&&t.onDragEnd(n),this._dragHandlers.delete(n.event.space),this._dragHandlers.size===0&&this.onLastDragEnd(n),n.use())}update(){for(const n of this._dragHandlers.values())n.collectMovementInfo&&n.collectMovementInfo(),n.getTotalMovement&&this._totalMovement.add(n.getTotalMovement());if(this._potentialDragStartEvt){if(!this._didDrag)if(this._totalMovement.length()>3e-4)this._didDrag=!0;else return;const n=this._potentialDragStartEvt;this._potentialDragStartEvt=null,this.onFirstDragStart(n)}for(const n of this._dragHandlers.values())n.onDragUpdate&&n.onDragUpdate(this._dragHandlers.size);this._dragHelper&&this._dragHelper.hasSelected&&this.onAnyDragUpdate()}onFirstDragStart(n){if(!n||!n.object)return;const t=O.getComponentInParent(n.object,en);if(!t||t!==this&&t._isDragging)return;const i=this._targetObject||this.gameObject;if(!i)return;this._isDragging=!0;const s=O.getComponentInChildren(i,Yn);is&&console.log("DRAG START",s,i),s&&(s.fastMode=!0,s?.requestOwnership()),this._marker=O.addComponent(i,qc),this._draggingRigidbodies.length=0;const o=O.getComponentsInChildren(i,ve);o&&this._draggingRigidbodies.push(...o)}onAnyDragUpdate(){if(!this._dragHelper)return;this._dragHelper.showGizmo=this.showGizmo,this._dragHelper.onUpdate(this.context);for(const t of this._draggingRigidbodies)t.wakeUp(),t.resetVelocities(),t.resetForcesAndTorques();const n=this._targetObject||this.gameObject;ln.markDirty(n)}onLastDragEnd(n){if(!this||!this._isDragging)return;this._isDragging=!1;for(const i of this._draggingRigidbodies)i.setVelocity(i.smoothedVelocity);if(this._draggingRigidbodies.length=0,this._targetObject=null,n!=null&&n.object){const i=O.getComponentInChildren(n.object,Yn);i&&(i.fastMode=!1)}if(this._marker&&this._marker.destroy(),!this._dragHelper)return;const t=this._dragHelper.selected;is&&console.log("DRAG END",t,t?.visible),this._dragHelper.setSelected(null,this.context)}},a(Qc,"_active",0),a(Qc,"_instances",[]),a(Qc,"lastHovered"),Qc);let ui=en;Ar([m()],ui.prototype,"dragMode",2),Ar([m()],ui.prototype,"snapGridResolution",2),Ar([m()],ui.prototype,"keepRotation",2),Ar([m()],ui.prototype,"xrDragMode",2),Ar([m()],ui.prototype,"xrKeepRotation",2),Ar([m()],ui.prototype,"xrDistanceDragFactor",2),Ar([m()],ui.prototype,"showGizmo",2);class uR{constructor(t,i,s,o){a(this,"handlerA"),a(this,"handlerB"),a(this,"context"),a(this,"settings"),a(this,"gameObject"),a(this,"_handlerAAttachmentPoint",new x),a(this,"_handlerBAttachmentPoint",new x),a(this,"_followObject"),a(this,"_manipulatorObject"),a(this,"_deviceMode"),a(this,"_followObjectStartWorldQuaternion",new V),a(this,"_manipulatorPosOffset",new x),a(this,"_manipulatorRotOffset",new V),a(this,"_manipulatorScaleOffset",new x),a(this,"_tempVec1",new x),a(this,"_tempVec2",new x),a(this,"_tempVec3",new x),a(this,"tempLookMatrix",new se),a(this,"_initialScale",new x),a(this,"_initialDistance",0);var r,l;this.context=t.context,this.settings=t,this.gameObject=i,this.handlerA=s,this.handlerB=o,this._followObject=new A,this._manipulatorObject=new A,this.context.scene.add(this._manipulatorObject);const c=(l=(r=J.active)==null?void 0:r.rig)==null?void 0:l.gameObject;if(!this.handlerA||!this.handlerB||!this.handlerA.hitPointInLocalSpace||!this.handlerB.hitPointInLocalSpace){console.error("Invalid: MultiTouchDragHandler needs two valid DragPointerHandlers with hitPointInLocalSpace set.");return}if(this._tempVec1.copy(this.handlerA.hitPointInLocalSpace),this._tempVec2.copy(this.handlerB.hitPointInLocalSpace),this.gameObject.localToWorld(this._tempVec1),this.gameObject.localToWorld(this._tempVec2),c&&(c.worldToLocal(this._tempVec1),c.worldToLocal(this._tempVec2)),this._initialDistance=this._tempVec1.distanceTo(this._tempVec2),this._initialDistance<.02?(is&&console.log("Finding alternative drag attachment points since initial distance is too low: "+this._initialDistance.toFixed(2)),this.handlerA.followObject.parent.getWorldPosition(this._tempVec1),this.handlerB.followObject.parent.getWorldPosition(this._tempVec2),this._handlerAAttachmentPoint.copy(this._tempVec1),this._handlerBAttachmentPoint.copy(this._tempVec2),this.gameObject.worldToLocal(this._handlerAAttachmentPoint),this.gameObject.worldToLocal(this._handlerBAttachmentPoint),this._initialDistance=this._tempVec1.distanceTo(this._tempVec2),this._initialDistance<.001&&(console.warn("Not supported right now \u2013 controller drag points for multitouch are too close!"),this._initialDistance=1)):(this._handlerAAttachmentPoint.copy(this.handlerA.hitPointInLocalSpace),this._handlerBAttachmentPoint.copy(this.handlerB.hitPointInLocalSpace)),this._tempVec3.lerpVectors(this._tempVec1,this._tempVec2,.5),this._initialScale.copy(i.scale),is){this._followObject.add(new Si(2)),this._manipulatorObject.add(new Si(5));const h=d=>`${d.x.toFixed(2)}, ${d.y.toFixed(2)}, ${d.z.toFixed(2)}`;$.DrawLine(this._tempVec1,this._tempVec2,65535,0,!1),$.DrawLabel(this._tempVec3,"A:B "+this._initialDistance.toFixed(2)+`
|
|
935
|
+
`)},this.depthMaterial.depthTest=!1,this.depthMaterial.depthWrite=!1,this.horizontalBlurMaterial=new gn(HC),this.horizontalBlurMaterial.depthTest=!1,this.verticalBlurMaterial=new gn($C),this.verticalBlurMaterial.depthTest=!1,this.shadowGroup.visible=!1,this.autoFit?this.fitShadows():this.applyMinSize()}onEnable(){this._needsUpdate=!0}onDestroy(){var n,t,i,s,o,r,l,c;Gc._instances.get(this.context)===this&&Gc._instances.delete(this.context),(n=this.renderTarget)==null||n.dispose(),(t=this.renderTargetBlur)==null||t.dispose(),(i=this.depthMaterial)==null||i.dispose(),(s=this.horizontalBlurMaterial)==null||s.dispose(),(o=this.verticalBlurMaterial)==null||o.dispose(),(r=this.blurPlane)==null||r.geometry.dispose(),(l=this.plane)==null||l.geometry.dispose(),(c=this.occluderMesh)==null||c.geometry.dispose()}onBeforeRender(n){if(this.manualUpdate&&!this._needsUpdate)return;if(this._needsUpdate=!1,!this.renderTarget||!this.renderTargetBlur||!this.depthMaterial||!this.shadowCamera||!this.blurPlane||!this.shadowGroup||!this.plane||!this.horizontalBlurMaterial||!this.verticalBlurMaterial){$c&&console.error("ContactShadows: not initialized yet");return}const t=this.context.scene,i=this.context.renderer,s=i.getRenderTarget();this.shadowGroup.visible=!0,this.occluderMesh&&(this.occluderMesh.visible=!1);const o=this.plane.visible;this.plane.visible=!1,this.gameObject instanceof X&&Ts(this.gameObject,!1);const r=t.background;t.background=null,t.overrideMaterial=this.depthMaterial,this.backfaceShadows?this.depthMaterial.side=Ci:this.depthMaterial.side=po;const l=i.getClearAlpha();i.setClearAlpha(0);const c=i.xr.enabled;i.xr.enabled=!1;const h=this.context.scene.matrixWorldAutoUpdate;this.context.scene.matrixWorldAutoUpdate=!1;const d=i.renderLists.get(t,0),u=d.transparent;Qw.length=0,d.transparent=Qw,kf.length=0;for(const g of d.opaque){if(!g.object.visible)continue;const f=g.material;let y=g.material.colorWrite==!1||f.wireframe===!0||Kv(g.object)===!1;!y&&g.material.isLineMaterial&&(y=!0),!y&&g.material.isPointsMaterial&&(y=!0),y&&(kf.push(g.object),g.object["needle:visible"]=g.object.visible,g.object.visible=!1)}i.setRenderTarget(this.renderTarget),i.clear(),i.render(t,this.shadowCamera),d.transparent=u;for(const g of kf)g["needle:visible"]!=null&&(g.visible=g["needle:visible"]);t.overrideMaterial=null;const p=Math.max(this.blur,.05);this.blurShadow(p*2),this.blurShadow(p*.5),this.shadowGroup.visible=!1,this.occluderMesh&&(this.occluderMesh.visible=this.occludeBelowGround),this.plane.visible=o,i.setRenderTarget(s),i.setClearAlpha(l),t.background=r,i.xr.enabled=c,this.context.scene.matrixWorldAutoUpdate=h}blurShadow(n){if(!this.blurPlane||!this.shadowCamera||!this.renderTarget||!this.renderTargetBlur||!this.horizontalBlurMaterial||!this.verticalBlurMaterial)return;this.blurPlane.visible=!0;const t=this.shadowsRoot.worldScale,i=(t.x+t.z)/2,s=t.z/i,o=t.x/i;this.blurPlane.material=this.horizontalBlurMaterial,this.blurPlane.material.uniforms.tDiffuse.value=this.renderTarget.texture,this.horizontalBlurMaterial.uniforms.h.value=n*1/this.textureSize*s;const r=this.context.renderer,l=r.getRenderTarget();r.setRenderTarget(this.renderTargetBlur),r.render(this.blurPlane,this.shadowCamera),this.blurPlane.material=this.verticalBlurMaterial,this.blurPlane.material.uniforms.tDiffuse.value=this.renderTargetBlur.texture,this.verticalBlurMaterial.uniforms.v.value=n*1/this.textureSize*o,r.setRenderTarget(this.renderTarget),r.render(this.blurPlane,this.shadowCamera),this.blurPlane.visible=!1,r.setRenderTarget(l)}applyMinSize(){this.minSize&&this.shadowsRoot.scale.set(Math.max(this.minSize.x||0,this.shadowsRoot.scale.x),Math.max(this.minSize.y||0,this.shadowsRoot.scale.y),Math.max(this.minSize.z||0,this.shadowsRoot.scale.z))}},a(Pf,"_instances",new Map),Pf);let Pn=Gc;Ya([m()],Pn.prototype,"autoFit",2),Ya([m()],Pn.prototype,"darkness",2),Ya([m()],Pn.prototype,"opacity",2),Ya([m()],Pn.prototype,"blur",2),Ya([m()],Pn.prototype,"occludeBelowGround",2),Ya([m()],Pn.prototype,"backfaceShadows",2);const Qw=[],kf=new Array,rR=C("logstats");class Mf extends I{onEnable(){console.log(this),rR&&this.startCoroutine(this.run(),Me.OnAfterRender)}*run(){for(;this.enabled;){const t=this.context.renderer.info;console.log(t.memory,t.render,t.programs),yield}}}class qc extends I{constructor(){super(...arguments),a(this,"isUsed",!0),a(this,"usedBy",null)}}class Rf extends I{}const Yw=C("debugdeletable"),Du=class extends Ji{onEnable(){Du._instances.push(this)}onDisable(){const n=Du._instances.indexOf(this);n>=0&&Du._instances.splice(n,1)}};let Xc=Du;a(Xc,"_instances",[]);class Tf extends I{update(){for(const t of Xc._instances){const i=this.gameObject;if(t.isInBox(i)===!0){const s=O.getComponentInParent(this.gameObject,qc);if(s)Yw&&console.warn("DeleteBox: Not deleting object with usage marker",this.guid,s);else{if(Yw)try{if(t.box){const o=t.box,r=Ji.testBox;$.DrawWireBox3(o,16711680,5),$.DrawWireBox3(r,255,5),console.log("DeleteBox: Destroying",this.gameObject,{deleteBoxArea:o,deletedObjectArea:r})}else console.log("DeleteBox: Destroying",this.gameObject)}catch{}yc(this.gameObject,this.context.connection)}}}}}var aR=Object.defineProperty,lR=Object.getOwnPropertyDescriptor,cR=(n,t,i,s)=>{for(var o=s>1?void 0:s?lR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&aR(t,i,o),o};class Bu extends I{constructor(){super(...arguments),a(this,"visibleOn")}onEnable(){this.apply()}apply(){this.test()||O.setActive(this.gameObject,!1)}test(){return this.visibleOn<0?!0:Q.isMobileDevice()?(this.visibleOn&2)!==0:(this.visibleOn&1)!==0}}cR([m()],Bu.prototype,"visibleOn",2);var hR=Object.defineProperty,dR=Object.getOwnPropertyDescriptor,Ar=(n,t,i,s)=>{for(var o=s>1?void 0:s?dR(t,i):t,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(t,i,o):l(o))||o);return s&&o&&hR(t,i,o),o};const is=C("debugdrag"),Ef=[];var Af=(n=>(n[n.XZPlane=0]="XZPlane",n[n.Attached=1]="Attached",n[n.HitNormal=2]="HitNormal",n[n.DynamicViewAngle=3]="DynamicViewAngle",n[n.SnapToSurfaces=4]="SnapToSurfaces",n[n.None=5]="None",n))(Af||{}),Qc;const en=(Qc=class extends I{constructor(){super(...arguments),a(this,"dragMode",3),a(this,"snapGridResolution",0),a(this,"keepRotation",!0),a(this,"xrDragMode",1),a(this,"xrKeepRotation",!1),a(this,"xrDistanceDragFactor",1),a(this,"showGizmo",!1),a(this,"_rigidbody",null),a(this,"_targetObject",null),a(this,"_dragHelper",null),a(this,"_draggingRigidbodies",[]),a(this,"_potentialDragStartEvt",null),a(this,"_dragHandlers",new Map),a(this,"_totalMovement",new x),a(this,"_marker",null),a(this,"_isDragging",!1),a(this,"_didDrag",!1)}static get HasAnySelected(){return this._active>0}static get CurrentlySelected(){Ef.length=0;for(const n of this._instances)n._isDragging&&Ef.push(n);return Ef}get draggedObject(){return this._targetObject}setTargetObject(n){var t,i;this._targetObject=n;for(const o of this._dragHandlers.values())o.setTargetObject(n);const s="_rigidbody-was-kinematic";((t=this._rigidbody)==null?void 0:t[s])===!1&&(this._rigidbody.isKinematic=!1,this._rigidbody[s]=void 0),this._rigidbody=null,n&&(this._rigidbody=O.getComponentInChildren(n,ve),((i=this._rigidbody)==null?void 0:i.isKinematic)===!1&&(this._rigidbody.isKinematic=!0,this._rigidbody[s]=!1))}awake(){this._potentialDragStartEvt=null,this._dragHandlers=new Map,this._totalMovement=new x,this._marker=null,this._isDragging=!1,this._didDrag=!1,this._dragHelper=null,this._draggingRigidbodies=[]}start(){this.gameObject.getComponentInParent(Ii)||this.gameObject.addComponent(Ii)}onEnable(){en._instances.push(this)}onDisable(){en._instances=en._instances.filter(n=>n!==this)}allowEdit(n=null){return this.context.connection.allowEditing}onPointerEnter(n){if(!this.allowEdit(this.gameObject)||n.mode!=="screen"||(n.event.mode==="tracked-pointer"||n.event.mode==="transient-pointer"?this.xrDragMode:this.dragMode)===5)return;const t=O.getComponentInParent(n.object,en);!t||t!==this||(en.lastHovered=n.object,this.context.domElement.style.cursor="pointer")}onPointerMove(n){(this._isDragging||this._potentialDragStartEvt!==null)&&n.use()}onPointerExit(n){this.allowEdit(this.gameObject)&&n.mode==="screen"&&en.lastHovered===n.object&&(this.context.domElement.style.cursor="auto")}onPointerDown(n){if(!(!this.allowEdit(this.gameObject)||n.used||(n.mode==="tracked-pointer"||n.mode==="transient-pointer"?this.xrDragMode:this.dragMode)===5)&&(en.lastHovered=n.object,n.button===0)){this._dragHandlers.size===0&&(this._didDrag=!1,this._totalMovement.set(0,0,0),this._potentialDragStartEvt=n),this._targetObject||this.setTargetObject(this.gameObject),en._active+=1;const t=new If(this,this._targetObject);if(this._dragHandlers.set(n.event.space,t),t.onDragStart(n),this._dragHandlers.size===2){const i=this._dragHandlers.values(),s=i.next().value,o=i.next().value;if(s instanceof If&&o instanceof If){const r=new uR(this,this._targetObject,s,o);this._dragHandlers.set(this.gameObject,r),r.onDragStart(n)}else console.error("Attempting to construct a MultiTouchDragHandler with invalid DragPointerHandlers. This is likely a bug.",{a:s,b:o})}n.use()}}onPointerUp(n){if(is&&$.DrawLabel(n.point??this.gameObject.worldPosition,"POINTERUP:"+n.pointerId+", "+n.button,.03,3),!this.allowEdit(this.gameObject)||n.button!==0)return;this._potentialDragStartEvt=null;const t=this._dragHandlers.get(n.event.space),i=this._dragHandlers.get(this.gameObject);i&&(i.handlerA===t||i.handlerB===t)&&(this._dragHandlers.delete(this.gameObject),i.onDragEnd(n)),t&&(en._active>0&&(en._active-=1),this.setTargetObject(null),t.onDragEnd&&t.onDragEnd(n),this._dragHandlers.delete(n.event.space),this._dragHandlers.size===0&&this.onLastDragEnd(n),n.use())}update(){for(const n of this._dragHandlers.values())n.collectMovementInfo&&n.collectMovementInfo(),n.getTotalMovement&&this._totalMovement.add(n.getTotalMovement());if(this._potentialDragStartEvt){if(!this._didDrag)if(this._totalMovement.length()>3e-4)this._didDrag=!0;else return;const n=this._potentialDragStartEvt;this._potentialDragStartEvt=null,this.onFirstDragStart(n)}for(const n of this._dragHandlers.values())n.onDragUpdate&&n.onDragUpdate(this._dragHandlers.size);this._dragHelper&&this._dragHelper.hasSelected&&this.onAnyDragUpdate()}onFirstDragStart(n){if(!n||!n.object)return;const t=O.getComponentInParent(n.object,en);if(!t||t!==this&&t._isDragging)return;const i=this._targetObject||this.gameObject;if(!i)return;this._isDragging=!0;const s=O.getComponentInChildren(i,Yn);is&&console.log("DRAG START",s,i),s&&(s.fastMode=!0,s?.requestOwnership()),this._marker=O.addComponent(i,qc),this._draggingRigidbodies.length=0;const o=O.getComponentsInChildren(i,ve);o&&this._draggingRigidbodies.push(...o)}onAnyDragUpdate(){if(!this._dragHelper)return;this._dragHelper.showGizmo=this.showGizmo,this._dragHelper.onUpdate(this.context);for(const t of this._draggingRigidbodies)t.wakeUp(),t.resetVelocities(),t.resetForcesAndTorques();const n=this._targetObject||this.gameObject;ln.markDirty(n)}onLastDragEnd(n){if(!this||!this._isDragging)return;this._isDragging=!1;for(const i of this._draggingRigidbodies)i.setVelocity(i.smoothedVelocity);if(this._draggingRigidbodies.length=0,this._targetObject=null,n!=null&&n.object){const i=O.getComponentInChildren(n.object,Yn);i&&(i.fastMode=!1)}if(this._marker&&this._marker.destroy(),!this._dragHelper)return;const t=this._dragHelper.selected;is&&console.log("DRAG END",t,t?.visible),this._dragHelper.setSelected(null,this.context)}},a(Qc,"_active",0),a(Qc,"_instances",[]),a(Qc,"lastHovered"),Qc);let ui=en;Ar([m()],ui.prototype,"dragMode",2),Ar([m()],ui.prototype,"snapGridResolution",2),Ar([m()],ui.prototype,"keepRotation",2),Ar([m()],ui.prototype,"xrDragMode",2),Ar([m()],ui.prototype,"xrKeepRotation",2),Ar([m()],ui.prototype,"xrDistanceDragFactor",2),Ar([m()],ui.prototype,"showGizmo",2);class uR{constructor(t,i,s,o){a(this,"handlerA"),a(this,"handlerB"),a(this,"context"),a(this,"settings"),a(this,"gameObject"),a(this,"_handlerAAttachmentPoint",new x),a(this,"_handlerBAttachmentPoint",new x),a(this,"_followObject"),a(this,"_manipulatorObject"),a(this,"_deviceMode"),a(this,"_followObjectStartWorldQuaternion",new V),a(this,"_manipulatorPosOffset",new x),a(this,"_manipulatorRotOffset",new V),a(this,"_manipulatorScaleOffset",new x),a(this,"_tempVec1",new x),a(this,"_tempVec2",new x),a(this,"_tempVec3",new x),a(this,"tempLookMatrix",new se),a(this,"_initialScale",new x),a(this,"_initialDistance",0);var r,l;this.context=t.context,this.settings=t,this.gameObject=i,this.handlerA=s,this.handlerB=o,this._followObject=new A,this._manipulatorObject=new A,this.context.scene.add(this._manipulatorObject);const c=(l=(r=J.active)==null?void 0:r.rig)==null?void 0:l.gameObject;if(!this.handlerA||!this.handlerB||!this.handlerA.hitPointInLocalSpace||!this.handlerB.hitPointInLocalSpace){console.error("Invalid: MultiTouchDragHandler needs two valid DragPointerHandlers with hitPointInLocalSpace set.");return}if(this._tempVec1.copy(this.handlerA.hitPointInLocalSpace),this._tempVec2.copy(this.handlerB.hitPointInLocalSpace),this.gameObject.localToWorld(this._tempVec1),this.gameObject.localToWorld(this._tempVec2),c&&(c.worldToLocal(this._tempVec1),c.worldToLocal(this._tempVec2)),this._initialDistance=this._tempVec1.distanceTo(this._tempVec2),this._initialDistance<.02?(is&&console.log("Finding alternative drag attachment points since initial distance is too low: "+this._initialDistance.toFixed(2)),this.handlerA.followObject.parent.getWorldPosition(this._tempVec1),this.handlerB.followObject.parent.getWorldPosition(this._tempVec2),this._handlerAAttachmentPoint.copy(this._tempVec1),this._handlerBAttachmentPoint.copy(this._tempVec2),this.gameObject.worldToLocal(this._handlerAAttachmentPoint),this.gameObject.worldToLocal(this._handlerBAttachmentPoint),this._initialDistance=this._tempVec1.distanceTo(this._tempVec2),this._initialDistance<.001&&(console.warn("Not supported right now \u2013 controller drag points for multitouch are too close!"),this._initialDistance=1)):(this._handlerAAttachmentPoint.copy(this.handlerA.hitPointInLocalSpace),this._handlerBAttachmentPoint.copy(this.handlerB.hitPointInLocalSpace)),this._tempVec3.lerpVectors(this._tempVec1,this._tempVec2,.5),this._initialScale.copy(i.scale),is){this._followObject.add(new Si(2)),this._manipulatorObject.add(new Si(5));const h=d=>`${d.x.toFixed(2)}, ${d.y.toFixed(2)}, ${d.z.toFixed(2)}`;$.DrawLine(this._tempVec1,this._tempVec2,65535,0,!1),$.DrawLabel(this._tempVec3,"A:B "+this._initialDistance.toFixed(2)+`
|
|
936
936
|
`+h(this._tempVec1)+`
|
|
937
937
|
`+h(this._tempVec2),.03,5)}}onDragStart(t){this.gameObject.add(this._followObject),this._followObject.matrixAutoUpdate=!1,this._followObject.matrix.identity(),this._deviceMode=t.mode,this._followObjectStartWorldQuaternion.copy(this._followObject.worldQuaternion),this.alignManipulator(),this._manipulatorObject.attach(this._followObject),this._manipulatorPosOffset.copy(this._followObject.position),this._manipulatorRotOffset.copy(this._followObject.quaternion),this._manipulatorScaleOffset.copy(this._followObject.scale)}onDragEnd(t){if(!this.handlerA||!this.handlerB){console.error("onDragEnd called on MultiTouchDragHandler without valid handlers. This is likely a bug.");return}this.handlerA.recenter(),this.handlerB.recenter(),this._manipulatorObject.removeFromParent(),this._followObject.removeFromParent(),this._manipulatorObject.destroy(),this._followObject.destroy()}alignManipulator(){if(!this.handlerA||!this.handlerB){console.error("alignManipulator called on MultiTouchDragHandler without valid handlers. This is likely a bug.",this);return}if(!this.handlerA.followObject||!this.handlerB.followObject){console.error("alignManipulator called on MultiTouchDragHandler without valid follow objects. This is likely a bug.",this.handlerA,this.handlerB);return}this._tempVec1.copy(this._handlerAAttachmentPoint),this._tempVec2.copy(this._handlerBAttachmentPoint),this.handlerA.followObject.localToWorld(this._tempVec1),this.handlerB.followObject.localToWorld(this._tempVec2),this._tempVec3.lerpVectors(this._tempVec1,this._tempVec2,.5),this._manipulatorObject.position.copy(this._tempVec3);const t=this.context.mainCamera;this.tempLookMatrix.lookAt(this._tempVec3,this._tempVec2,t.worldUp),this._manipulatorObject.quaternion.setFromRotationMatrix(this.tempLookMatrix);const i=this._tempVec1.distanceTo(this._tempVec2);this._manipulatorObject.scale.copy(this._initialScale).multiplyScalar(i/this._initialDistance),this._manipulatorObject.updateMatrix(),this._manipulatorObject.updateMatrixWorld(!0),is&&($.DrawLabel(this._tempVec3.clone().add(new x(0,.2,0)),"A:B "+i.toFixed(2),.03),$.DrawLine(this._tempVec1,this._tempVec2,65280,0,!1))}onDragUpdate(){this.alignManipulator();const t=30,i=1;this._followObject.position.copy(this._manipulatorPosOffset),this._followObject.quaternion.copy(this._manipulatorRotOffset),this._followObject.scale.copy(this._manipulatorScaleOffset);const s=this.gameObject,o=this._followObject;if(!s){console.error("MultiTouchDragHandler has no dragged object. This is likely a bug.");return}o.updateMatrix(),o.updateMatrixWorld(!0);const r=this._deviceMode==="tracked-pointer"||this._deviceMode==="transient-pointer"?this.settings.xrKeepRotation:this.settings.keepRotation;if(this.settings.snapGridResolution>0){const u=this._followObject.worldPosition,p=this.settings.snapGridResolution;u.x=Math.round(u.x/p)*p,u.y=Math.round(u.y/p)*p,u.z=Math.round(u.z/p)*p,this._followObject.worldPosition=u,this._followObject.updateMatrix()}r&&(this._followObject.worldQuaternion=this._followObjectStartWorldQuaternion,this._followObject.updateMatrix());const l=W.clamp01(this.context.time.deltaTime*t*i),c=s.worldPosition;c.lerp(o.worldPosition,l),s.worldPosition=c;const h=s.worldQuaternion;h.slerp(o.worldQuaternion,l),s.worldQuaternion=h;const d=s.worldScale;d.lerp(o.worldScale,l),s.worldScale=d}setTargetObject(t){this.gameObject=t}}class If{constructor(t,i){a(this,"context"),a(this,"gameObject"),a(this,"settings"),a(this,"_lastRig"),a(this,"_followObject"),a(this,"_totalMovement",new x),a(this,"_totalMovementAlongRayDirection",0),a(this,"_grabStartDistance",0),a(this,"_deviceMode"),a(this,"_followObjectStartPosition",new x),a(this,"_followObjectStartQuaternion",new V),a(this,"_followObjectStartWorldQuaternion",new V),a(this,"_lastDragPosRigSpace"),a(this,"_tempVec",new x),a(this,"_tempMat",new se),a(this,"_hitPointInLocalSpace",new x),a(this,"_hitNormalInLocalSpace",new x),a(this,"_bottomCenter",new x),a(this,"_backCenter",new x),a(this,"_backBottomCenter",new x),a(this,"_bounds",new xi),a(this,"_dragPlane",new lr(new x(0,1,0))),a(this,"_draggedOverObject",null),a(this,"_draggedOverObjectLastSetUp",null),a(this,"_draggedOverObjectLastNormal",new x),a(this,"_draggedOverObjectDuration",0),a(this,"_hasLastSurfaceHitPoint",!1),a(this,"_lastSurfaceHitPoint",new x),this.settings=t,this.context=t.context,this.gameObject=i,this._followObject=new A}getTotalMovement(){return this._totalMovement}get followObject(){return this._followObject}get hitPointInLocalSpace(){return this._hitPointInLocalSpace}setTargetObject(t){this.gameObject=t}recenter(){var t,i;if(!this._followObject.parent){console.warn("Error: space follow object doesn't have parent but recenter() is called. This is likely a bug");return}if(!this.gameObject){console.warn("Error: space follow object doesn't have a gameObject");return}const s=this._followObject.parent;this.gameObject.add(this._followObject),this._followObject.matrixAutoUpdate=!1,this._followObject.position.set(0,0,0),this._followObject.quaternion.set(0,0,0,1),this._followObject.scale.set(1,1,1),this._followObject.updateMatrix(),this._followObject.updateMatrixWorld(!0),s.attach(this._followObject),this._followObjectStartPosition.copy(this._followObject.position),this._followObjectStartQuaternion.copy(this._followObject.quaternion),this._followObjectStartWorldQuaternion.copy(this._followObject.worldQuaternion),this._followObject.updateMatrix(),this._followObject.updateMatrixWorld(!0);const o=this._hitPointInLocalSpace.clone();this.gameObject.localToWorld(o),this._grabStartDistance=o.distanceTo(s.worldPosition);const r=(i=(t=J.active)==null?void 0:t.rig)==null?void 0:i.gameObject,l=r?.worldScale.x||1;this._grabStartDistance/=l,this._totalMovementAlongRayDirection=0,this._lastDragPosRigSpace=void 0,is&&($.DrawLine(o,s.worldPosition,65280,.5,!1),$.DrawLabel(s.worldPosition.add(new x(0,.1,0)),this._grabStartDistance.toFixed(2),.03,.5))}onDragStart(t){if(!this.gameObject){console.warn("Error: space follow object doesn't have a gameObject");return}if(t.event.space.add(this._followObject),this._lastDragPosRigSpace=void 0,t.point&&t.normal)this._hitPointInLocalSpace.copy(t.point),this.gameObject.worldToLocal(this._hitPointInLocalSpace),this._hitNormalInLocalSpace.copy(t.normal);else if(t){const f=t.event.space,y=f.worldPosition;this.gameObject.worldToLocal(y),this._hitPointInLocalSpace.copy(y);const b=f.worldUp;this._tempMat.copy(this.gameObject.matrixWorld).invert(),b.transformDirection(this._tempMat),this._hitNormalInLocalSpace.copy(b)}this.recenter(),this._totalMovement.set(0,0,0),this._deviceMode=t.mode;const i=this._followObject.parent.worldForward,s=this._deviceMode==="tracked-pointer"||this._deviceMode==="transient-pointer"?this.settings.xrDragMode:this.settings.dragMode,o=this._hitPointInLocalSpace.clone();switch(this.gameObject.localToWorld(o),s){case 0:const f=new x(0,1,0);this.gameObject.parent&&f.transformDirection(this.gameObject.parent.matrixWorld.clone().invert()),this._dragPlane.setFromNormalAndCoplanarPoint(f,o);break;case 2:const y=this._hitNormalInLocalSpace.clone();y.transformDirection(this.gameObject.matrixWorld),this._dragPlane.setFromNormalAndCoplanarPoint(y,o);break;case 1:this._dragPlane.setFromNormalAndCoplanarPoint(i,o);break;case 3:this.setPlaneViewAligned(o,!0);break;case 4:this.setPlaneViewAligned(o,!1);break}const r=this.gameObject.parent,l=this.gameObject.position.clone(),c=this.gameObject.quaternion.clone(),h=this.gameObject.scale.clone(),d=this.gameObject.matrixWorld.clone();r&&r.remove(this.gameObject),this.gameObject.position.set(0,0,0),this.gameObject.quaternion.set(0,0,0,1),this.gameObject.scale.set(1,1,1);const u=oi([this.gameObject]);u.expandByPoint(this.gameObject.worldPosition);const p=new x;u.getCenter(p);const g=new x;u.getSize(g),this._bottomCenter.copy(p.clone().add(new x(0,-g.y/2,0))),this._backCenter.copy(p.clone().add(new x(0,0,g.z/2))),this._backBottomCenter.copy(p.clone().add(new x(0,-g.y/2,g.z/2))),this._bounds.copy(u),r&&r.add(this.gameObject),this.gameObject.position.copy(l),this.gameObject.quaternion.copy(c),this.gameObject.scale.copy(h),this.gameObject.matrixWorld.copy(d),this._draggedOverObject=null,this._draggedOverObjectLastSetUp=null,this._draggedOverObjectLastNormal.set(0,1,0),this._draggedOverObjectDuration=0}collectMovementInfo(){var t,i;if(!this._followObject.parent)return;const s=this._followObject.parent;this._followObject.updateMatrix();const o=s.worldPosition,r=(i=(t=J.active)==null?void 0:t.rig)==null?void 0:i.gameObject;r&&r.worldToLocal(o),(this._lastDragPosRigSpace===void 0||r!=this._lastRig)&&(this._lastDragPosRigSpace=o.clone(),this._lastRig=r),this._tempVec.copy(o).sub(this._lastDragPosRigSpace);const l=s.worldForward;if(r&&(this._tempMat.copy(r.matrixWorld).invert(),l.transformDirection(this._tempMat)),this._totalMovementAlongRayDirection+=l.dot(this._tempVec),this._tempVec.x=Math.abs(this._tempVec.x),this._tempVec.y=Math.abs(this._tempVec.y),this._tempVec.z=Math.abs(this._tempVec.z),this._totalMovement.add(this._tempVec),this._lastDragPosRigSpace.copy(o),is){let c=o;r&&(c=c.clone(),c.transformDirection(r.matrixWorld)),$.DrawRay(c,l,255)}}onDragUpdate(t){if(t>1)return;const i=this.gameObject;if(!i||!this._followObject){console.warn("Warning: DragPointerHandler doesn't have a dragged object. This is likely a bug.");return}const s=this._followObject.parent;if(!s){console.warn("Warning: DragPointerHandler doesn't have a drag source. This is likely a bug.");return}this._followObject.updateMatrix();const o=s.worldPosition,r=s.worldForward,l=this._deviceMode==="tracked-pointer"||this._deviceMode==="transient-pointer",c=l?this.settings.xrKeepRotation:this.settings.keepRotation,h=l?this.settings.xrDragMode:this.settings.dragMode;if(h===5)return;const d=10;c&&(this._followObject.worldQuaternion=this._followObjectStartWorldQuaternion),this._followObject.updateMatrix(),this._followObject.updateMatrixWorld(!0);let u=1,p=2;if(l&&this._grabStartDistance>.5){const _=1+this._totalMovementAlongRayDirection*(2*this.settings.xrDistanceDragFactor);u=Math.max(0,_),u=u*u*u}else this._grabStartDistance<=.5&&(p=3);this._followObject.position.copy(this._followObjectStartPosition),c||this._followObject.quaternion.copy(this._followObjectStartQuaternion),this._followObject.position.multiplyScalar(u),this._followObject.updateMatrix();const g=this._hasLastSurfaceHitPoint;this._hasLastSurfaceHitPoint=!1;const f=new co(o,r);if(h==4){const _=this.context.physics.raycastFromRay(f,{testObject:S=>S!==this.followObject&&S!==s&&S!==i});if(_.length>0){const S=_[0];if(this._draggedOverObject===S.object?this._draggedOverObjectDuration+=this.context.time.deltaTime:(this._draggedOverObject=S.object,this._draggedOverObjectDuration=0),S.face){this._hasLastSurfaceHitPoint=!0,this._lastSurfaceHitPoint.copy(S.point);const R=.15,M=this._draggedOverObjectDuration>=R,T=.001,L=this._totalMovement.length()>=T,D=q(S.normal||S.face.normal).applyQuaternion(S.object.worldQuaternion);if((M||L)&&(this._draggedOverObjectLastSetUp!==this._draggedOverObject||this._draggedOverObjectLastNormal.dot(D)<.999999||this.context.time.frame%60===0)){this._draggedOverObjectLastSetUp=this._draggedOverObject,this._draggedOverObjectLastNormal.copy(S.face.normal);const U=q(),F=q();this._bounds.getCenter(U),this._bounds.getSize(F),U.sub(F.multiplyScalar(.5).multiply(D)),this._hitPointInLocalSpace.copy(U),this._hitNormalInLocalSpace.copy(S.face.normal),this._bounds.getCenter(U),this._bounds.getSize(F),U.add(F.multiplyScalar(.5).multiply(S.face.normal));const Y=q(this._hitPointInLocalSpace).add(U);this._followObject.localToWorld(Y);const G=S.point;this._dragPlane.setFromNormalAndCoplanarPoint(D,G)}else if(!(M||L))return}}else g&&this.gameObject&&this.setPlaneViewAligned(this.gameObject.worldPosition,!1)}if(h!==1&&f.intersectPlane(this._dragPlane,this._tempVec)){this._followObject.worldPosition=this._tempVec,this._followObject.updateMatrix(),this._followObject.updateMatrixWorld(!0);const _=q(this._hitPointInLocalSpace);this._followObject.localToWorld(_),is&&$.DrawLine(_,this._tempVec,65535,0,!1),this._followObject.worldPosition=this._tempVec.multiplyScalar(2).sub(_),this._followObject.updateMatrix(),this._followObject.updateMatrix()}if(this.settings.snapGridResolution>0){const _=this._followObject.worldPosition,S=this.settings.snapGridResolution;_.x=Math.round(_.x/S)*S,_.y=Math.round(_.y/S)*S,_.z=Math.round(_.z/S)*S,this._followObject.worldPosition=_,this._followObject.updateMatrix()}c&&(this._followObject.worldQuaternion=this._followObjectStartWorldQuaternion,this._followObject.updateMatrix());const y=W.clamp01(this.context.time.deltaTime*d*p),b=W.clamp01(this.context.time.deltaTime*d*.5*p),v=i.worldPosition;v.lerp(this._followObject.worldPosition,y),i.worldPosition=v;const w=i.worldQuaternion;if(w.slerp(this._followObject.worldQuaternion,b),i.worldQuaternion=w,is){const _=this._hitPointInLocalSpace.clone();i.localToWorld(_),$.DrawSphere(_,.02,16711680);const S=this._hitNormalInLocalSpace.clone();S.applyQuaternion(w),$.DrawRay(_,S,16711680),$.DrawLabel(v.add(new x(0,.25,0)),`Distance: ${this._totalMovement.length().toFixed(2)}
|
|
938
938
|
|