@needle-tools/engine 3.10.1-beta → 3.10.2-beta
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 +4 -0
- package/dist/needle-engine.js +65 -52
- package/dist/needle-engine.light.js +65 -52
- package/dist/needle-engine.light.min.js +8 -8
- package/dist/needle-engine.light.umd.cjs +8 -8
- package/dist/needle-engine.min.js +8 -8
- package/dist/needle-engine.umd.cjs +105 -105
- package/lib/engine/engine_input.js +2 -2
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +1 -0
- package/lib/engine-components/Renderer.js +1 -1
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RendererLightmap.d.ts +2 -2
- package/lib/engine-components/RendererLightmap.js +11 -16
- package/lib/engine-components/RendererLightmap.js.map +1 -1
- package/lib/engine-components/webxr/WebXRController.d.ts +5 -1
- package/lib/engine-components/webxr/WebXRController.js +90 -74
- package/lib/engine-components/webxr/WebXRController.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_input.ts +2 -2
- package/src/engine-components/Renderer.ts +1 -1
- package/src/engine-components/RendererLightmap.ts +13 -17
- package/src/engine-components/webxr/WebXRController.ts +104 -83
|
@@ -3666,7 +3666,7 @@ Please change to:
|
|
|
3666
3666
|
${o}? : AssetReference;
|
|
3667
3667
|
|
|
3668
3668
|
in script ${g}.ts
|
|
3669
|
-
<a href="https://docs.needle.tools/serializable" target="_blank">documentation</a>`),console.warn(g,o,t[o],t);continue}}}}function yz(t,A){for(const e of Object.keys(A)){const i=A[e];if(typeof i=="object"&&i!==null&&i!==void 0){const g=t[e];if(!g){vC&&console.log(e,"is undefined on",t);continue}for(const I of Object.keys(i))if(g[I]===void 0&&Kv(i[I])&&!Kv(g)){const o=Sz(g,I);if(o&&(o?.writable===void 0||o?.writable===!1)&&o.set===void 0){vC&&console.warn('Property is not writable "'+I+'"',g,o,i[I],g[I]);continue}g[I]=i[I]}}}}function Sz(t,A){for(;t;){const e=Object.getOwnPropertyDescriptor(t,A);if(e)return e;t=Object.getPrototypeOf(t)}}function Kv(t){switch(typeof t){case"number":case"string":case"boolean":return!0}return!1}function bk(t,A,e,i,g){let I=typeof A=="function"&&A.prototype===void 0,o=A;if(I)try{if(o=A?.call(A,g),I=!1,o==null)return}catch(n){console.error("Error in callback",n,t)}if(e.type=o,!I&&g instanceof o)return g;if(g&&typeof g=="object"&&lz(g)){if(g.__concreteInstance)return g.__concreteInstance;const n=g;if(!n.$serializedTypes&&o.prototype.$serializedTypes&&(n.$serializedTypes=o.prototype.$serializedTypes),n.$serializedTypes&&QD(n,t,e),g&&o!==void 0)try{const B=new o;Rg&&console.log("Create concrete instance for persistent asset",g,"instance:",B),Pr(B,g),g.__concreteInstance=B,g=B}catch(B){console.error("Error creating instance or creating values on instance",B,g,o)}return g}if(i||(i={serializer:rD.getSerializerForConstructor(o)}),Array.isArray(t)){const n=[];for(let B=0;B<t.length;B++){const Q=t[B],E=bk(Q,A,e,i,Q);n.push(E)}return n}const s=i.serializer;if(s)return s.onDeserialize(t,e);let C;if(t&&(t.isMaterial||t.isTexture||t.isObject3D))C=t;else{if(t===void 0)return;if(t===null&&(o===Ue||o===_e||o===fA||o===PI))return null;C=new o(...fz(t))}const a=C;return a.$serializedTypes&&QD(a,t,e),C}function fz(t){if(BD.length=0,typeof t=="object"&&t!==null&&t!==void 0)for(const A of Object.keys(t))BD.push(t[A]);return BD}const Lk=Symbol("assigned component properties");function Pr(t,A,e){var i;if(A==null||t==null)return;t[Lk]=!0;const g=((i=t.constructor)==null?void 0:i.name)??"unknown";e?.registerDefinedKeys(g,t);for(const I of Object.keys(A)){const o=mz(t,I);typeof o?.value!="function"&&(!o||o.writable===!0||o?.set!==void 0)&&(t[I]=A[I])}delete t[Lk]}function mz(t,A){let e;do e=Object.getOwnPropertyDescriptor(t,A);while(!e&&(t=Object.getPrototypeOf(t)));return e}const wo=oA("debuginput");class ED{constructor(A){r(this,"key"),r(this,"keyType"),r(this,"source"),this.key=A.key,this.keyType=A.type,this.source=A}}var bs=(t=>(t.PointerDown="pointerdown",t.PointerUp="pointerup",t.PointerMove="pointermove",t.KeyDown="keydown",t.KeyUp="keyup",t.KeyPressed="keypress",t))(bs||{}),Jv=(t=>(t.Mouse="mouse",t.Touch="touch",t))(Jv||{});class qv extends EventTarget{constructor(A){super(),r(this,"_doubleClickTimeThreshold",.2),r(this,"_longPressTimeThreshold",1),r(this,"_specialCursorTrigger",0),r(this,"context"),r(this,"_pointerDown",[!1]),r(this,"_pointerUp",[!1]),r(this,"_pointerClick",[!1]),r(this,"_pointerDoubleClick",[!1]),r(this,"_pointerPressed",[!1]),r(this,"_pointerPositions",[new Z]),r(this,"_pointerPositionsLastFrame",[new Z]),r(this,"_pointerPositionsDelta",[new Z]),r(this,"_pointerPositionsRC",[new Z]),r(this,"_pointerPositionDown",[new Z]),r(this,"_pointerDownTime",[]),r(this,"_pointerUpTime",[]),r(this,"_pointerUpTimestamp",[]),r(this,"_pointerIds",[]),r(this,"_pointerTypes",[""]),r(this,"_mouseWheelChanged",[!1]),r(this,"_mouseWheelDeltaY",[0]),r(this,"_pointerEvent",[]),r(this,"_pointerUsed",[]),r(this,"onLostFocus",()=>{for(const e in this.keysPressed)this.keysPressed[e].pressed=!1}),r(this,"onEndOfFrame",()=>{for(let e=0;e<this._pointerUp.length;e++)this._pointerUp[e]=!1;for(let e=0;e<this._pointerDown.length;e++)this._pointerDown[e]=!1;for(let e=0;e<this._pointerClick.length;e++)this._pointerClick[e]=!1;for(let e=0;e<this._pointerDoubleClick.length;e++)this._pointerDoubleClick[e]=!1;for(const e of this._pointerPositionsDelta)e.set(0,0);for(let e=0;e<this._mouseWheelChanged.length;e++)this._mouseWheelChanged[e]=!1;for(let e=0;e<this._mouseWheelDeltaY.length;e++)this._mouseWheelDeltaY[e]=0}),r(this,"keysPressed",{}),r(this,"onKeyDown",e=>{if(!this.context.application.hasFocus)return;const i=this.keysPressed[e.code];i&&i.pressed||(this.keysPressed[e.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:e.key,code:e.code},this.onDispatchEvent("keydown",new ED(e)))}),r(this,"onKeyPressed",e=>{if(!this.context.application.hasFocus)return;const i=this.keysPressed[e.code];i&&(i.pressed=!0,i.frame=this.context.time.frameCount+1,this.onDispatchEvent("keypress",new ED(e)))}),r(this,"onKeyUp",e=>{if(!this.context.application.hasFocus)return;const i=this.keysPressed[e.code];i&&(i.pressed=!1,i.frame=this.context.time.frameCount+1,this.onDispatchEvent("keyup",new ED(e)))}),r(this,"onMouseWheel",e=>{if(this.canReceiveInput(e)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const i=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=i+e.deltaY}),r(this,"onTouchStart",e=>{if(!(e.changedTouches.length<=0)&&this.canReceiveInput(e)!==!1)for(let i=0;i<e.changedTouches.length;i++){const g=e.changedTouches[i],I=this.getPointerIndex(g.identifier);wo&&di(`touch start #${I}, identifier:${g.identifier}`);const o={button:I,clientX:g.clientX,clientY:g.clientY,pointerType:"touch",source:e};this.onDown(o)}}),r(this,"onTouchMove",e=>{if(!(e.changedTouches.length<=0))for(let i=0;i<e.changedTouches.length;i++){const g=e.changedTouches[i],I={button:this.getPointerIndex(g.identifier),clientX:g.clientX,clientY:g.clientY,pointerType:"touch",source:e};this.onMove(I)}}),r(this,"onTouchUp",e=>{if(!(e.changedTouches.length<=0))for(let i=0;i<e.changedTouches.length;i++){const g=e.changedTouches[i],I=this.getPointerIndex(g.identifier);if(!this.isNewEvent(e.timeStamp,I,this._pointerUpTimestamp))continue;wo&&di(`touch up #${I}, identifier:${g.identifier}`);const o={button:I,clientX:g.clientX,clientY:g.clientY,pointerType:"touch",source:e};this.onUp(o)}}),r(this,"onMouseDown",e=>{if(e.defaultPrevented||this.canReceiveInput(e)===!1)return;let i=e.button;this.onDown({button:i,clientX:e.clientX,clientY:e.clientY,pointerType:"mouse",source:e})}),r(this,"onMouseMove",e=>{if(e.defaultPrevented)return;const i={button:e.button,clientX:e.clientX,clientY:e.clientY,pointerType:"mouse",source:e,movementX:e.movementX,movementY:e.movementY};this.onMove(i)}),r(this,"onMouseUp",e=>{if(e.defaultPrevented)return;let i=e.button;this.isNewEvent(e.timeStamp,i,this._pointerUpTimestamp)&&this.onUp({button:i,clientX:e.clientX,clientY:e.clientY,pointerType:"mouse",source:e})}),this.context=A,this.context.post_render_callbacks.push(this.onEndOfFrame),window.addEventListener("touchstart",this.onTouchStart,!1),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchUp,!1),window.addEventListener("mousedown",this.onMouseDown,!1),window.addEventListener("mousemove",this.onMouseMove,!1),window.addEventListener("mouseup",this.onMouseUp,!1),window.addEventListener("wheel",this.onMouseWheel,{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)}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)}setCursorPointer(){this._specialCursorTrigger+=1,this.context.domElement.style.cursor="pointer"}setCursorNormal(){this._specialCursorTrigger-=1,this._specialCursorTrigger=Math.max(0,this._specialCursorTrigger),this._specialCursorTrigger===0&&(this.context.domElement.style.cursor="default")}setPointerUsed(A,e=!0){if(A>=this._pointerUsed.length){if(A>=this._pointerIds.length)return;for(;this._pointerUsed.length<=A;)this._pointerUsed.push(!1)}this._pointerUsed[A]=e}getPointerUsed(A){return A>=this._pointerUsed.length?!1:this._pointerUsed[A]}getPointerPressedCount(){let A=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&A++;return A}getPointerPosition(A){return A>=this._pointerPositions.length?null:this._pointerPositions[A]}getPointerPositionLastFrame(A){return A>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[A]}getPointerPositionDelta(A){return A>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[A]}getPointerPositionRC(A){return A>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[A]}getPointerDown(A){return A>=this._pointerDown.length?!1:this._pointerDown[A]}getPointerUp(A){return A>=this._pointerUp.length?!1:this._pointerUp[A]}getPointerPressed(A){return A>=this._pointerPressed.length?!1:this._pointerPressed[A]}getPointerClicked(A){return A>=this._pointerClick.length?!1:this._pointerClick[A]}getPointerDoubleClicked(A){return A>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[A]}getPointerDownTime(A){return A>=this._pointerDownTime.length?-1:this._pointerDownTime[A]}getPointerUpTime(A){return A>=this._pointerUpTime.length?-1:this._pointerUpTime[A]}getPointerLongPress(A){return A>=this._pointerDownTime.length?!1:this.getPointerPressed(A)&&this.context.time.time-this._pointerDownTime[A]>this._longPressTimeThreshold}getIsMouse(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="mouse"}getIsTouch(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="touch"}getTouchesPressedCount(){let A=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&this.getIsTouch(e)&&A++;return A}getMouseWheelChanged(A=0){return A>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[A]}getMouseWheelDeltaY(A=0){return A>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[A]}getPointerEvent(A){if(!(A>=this._pointerEvent.length))return this._pointerEvent[A]??void 0}*foreachPointerId(A){for(let e=0;e<this._pointerTypes.length;e++)if(this._pointerIsActive(e)){if(A!==void 0){const i=this._pointerTypes[e];if(Array.isArray(A)){let g=!1;for(const I of A)if(i===I){g=!0;break}if(!g)continue}else if(A!==i)continue}yield e}}*foreachTouchId(){for(let A=0;A<this._pointerTypes.length;A++)this._pointerTypes[A]==="touch"&&this._pointerIsActive[A]&&(yield A)}_pointerIsActive(A){return A<0?!1:this._pointerPressed[A]||this._pointerDown[A]||this._pointerUp[A]}getKeyDown(){for(const A in this.keysPressed){const e=this.keysPressed[A];if(e.startFrame===this.context.time.frameCount)return e.key}return null}getKeyPressed(){for(const A in this.keysPressed){const e=this.keysPressed[A];if(e.pressed)return e.key}return null}isKeyDown(A){var e;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(A);if(i!==null){for(const g of i)if(this.isKeyDown(g))return!0;return!1}return((e=this.keysPressed[A])==null?void 0:e.startFrame)===this.context.time.frameCount&&this.keysPressed[A].pressed}isKeyUp(A){var e;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(A);if(i!==null){for(const g of i)if(this.isKeyUp(g))return!0;return!1}return((e=this.keysPressed[A])==null?void 0:e.frame)===this.context.time.frameCount&&!this.keysPressed[A].pressed}isKeyPressed(A){var e;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(A);if(i!==null){for(const g of i)if(this.isKeyPressed(g))return!0;return!1}return(e=this.keysPressed[A])==null?void 0:e.pressed}getCodeForCommonKeyName(A){if(A.length===1){if(A>="0"&&A<="9")return["Digit"+A];if(A>="a"&&A<="z")return["Key"+A.toUpperCase()];if(A==" ")return["Space"]}switch(A){case"Shift":return["ShiftLeft","ShiftRight"];case"Control":return["ControlLeft","ControlRight"];case"Alt":return["AltLeft","AltRight"]}return null}createPointerDown(A){wo&&di("Create Pointer down"),this.onDown(A)}createPointerMove(A){wo&&di("Create Pointer move"),this.onMove(A)}createPointerUp(A){wo&&di("Create Pointer up"),this.onUp(A)}convertScreenspaceToRaycastSpace(A){A.x=(A.x-this.context.domX)/this.context.domWidth*2-1,A.y=-((A.y-this.context.domY)/this.context.domHeight)*2+1}dispose(){const A=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);A>=0&&this.context.post_render_callbacks.splice(A,1),window.removeEventListener("touchstart",this.onTouchStart,!1),window.removeEventListener("touchmove",this.onTouchMove,!1),window.removeEventListener("touchend",this.onTouchUp,!1),window.removeEventListener("mousedown",this.onMouseDown,!1),window.removeEventListener("mousemove",this.onMouseMove,!1),window.removeEventListener("mouseup",this.onMouseUp,!1),window.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}canReceiveInput(A){return A.target===this.context.renderer.domElement||A.target===this.context.domElement}isNewEvent(A,e,i){for(;i.length<=e;)i.push(-1);return A===i[e]?!1:(i[e]=A,!0)}isInRect(A){if(this.context.isInXR)return!0;const e=this.context.domElement.getBoundingClientRect(),i=A.clientX,g=A.clientY,I=i>=e.x&&i<=e.right&&g>=e.y&&g<=e.bottom;return wo&&!I&&console.log("Not in rect",e,i,g),I}onDown(A){var e;if(wo&&console.log(A.pointerType,"DOWN",A.button),!!this.isInRect(A)){if(A.pointerType==="mouse"){const i=this._pointerUpTimestamp[A.button];if(i>0&&((e=A.source)==null?void 0:e.timeStamp)!==void 0){const g=i-A.source.timeStamp;if(g<30&&g>0){wo&&console.log("Ignoring mouse.down for touch.up");return}}}for(this.setPointerState(A.button,this._pointerPressed,!0),this.setPointerState(A.button,this._pointerDown,!0),this.setPointerStateT(A.button,this._pointerEvent,A.source);A.button>=this._pointerTypes.length;)this._pointerTypes.push(A.pointerType);for(this._pointerTypes[A.button]=A.pointerType;A.button>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new Z);for(this._pointerPositionDown[A.button].set(A.clientX,A.clientY);A.button>=this._pointerPositions.length;)this._pointerPositions.push(new Z);this._pointerPositions[A.button].set(A.clientX,A.clientY),A.button>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[A.button]=this.context.time.time,this.updatePointerPosition(A),this.onDispatchEvent("pointerdown",A)}}onMove(A){const e=this.getPointerPressed(A.button);e===!1&&!this.isInRect(A)||A.pointerType==="touch"&&!e||(wo&&console.log(A.pointerType,"MOVE",A.button),this.updatePointerPosition(A),this.setPointerStateT(A.button,this._pointerEvent,A.source),this.onDispatchEvent("pointermove",A))}onUp(A){var e;if(((e=this._pointerIds)==null?void 0:e.length)>=A.button&&(this._pointerIds[A.button]=-1),!this._pointerPressed[A.button]){wo&&console.log(A.pointerType,"UP",A.button,"was not down");return}for(wo&&console.log(A.pointerType,"UP",A.button),this.setPointerState(A.button,this._pointerPressed,!1),this.setPointerStateT(A.button,this._pointerEvent,A.source),this.setPointerState(A.button,this._pointerUp,!0);A.button>=this._pointerUsed.length;)this._pointerUsed.push(!1);if(this.setPointerState(A.button,this._pointerUsed,!1),this.updatePointerPosition(A),!this._pointerPositionDown[A.button]){wo&&Do("Received pointer up event without matching down event for button: "+A.button),console.warn("Received pointer up event without matching down event for button: "+A.button);return}const i=A.clientX-this._pointerPositionDown[A.button].x,g=A.clientY-this._pointerPositionDown[A.button].y;if(A.button>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(i)<5&&Math.abs(g)<5){this.setPointerState(A.button,this._pointerClick,!0);const I=this._pointerUpTime[A.button],o=this.context.time.time-I;o<this._doubleClickTimeThreshold&&o>0&&this.setPointerState(A.button,this._pointerDoubleClick,!0)}this._pointerUpTime[A.button]=this.context.time.time,this.onDispatchEvent("pointerup",A)}updatePointerPosition(A){for(;A.button>=this._pointerPositions.length;)this._pointerPositions.push(new Z);for(;A.button>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new Z);for(;A.button>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new Z);const e=this._pointerPositionsLastFrame[A.button];e.copy(this._pointerPositions[A.button]);const i=this._pointerPositionsDelta[A.button],g=A.clientX-e.x,I=A.clientY-e.y;i.x+=g,i.y+=I,this._pointerPositions[A.button].x=A.clientX,this._pointerPositions[A.button].y=A.clientY;const o=A.clientX,s=A.clientY;for(;A.button>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new Z);const C=this._pointerPositionsRC[A.button];C.set(o,s),this.convertScreenspaceToRaycastSpace(C)}getPointerIndex(A){const e=this._pointerIds;let i=-1;for(let g=0;g<e.length;g++){if(e[g]===A)return g;i===-1&&e[g]===-1&&(i=g)}return i!==-1?(e[i]=A,i):(e.push(A),e.length-1)}setPointerState(A,e,i){for(;e.length<=A;)e.push(!1);e[A]=i}setPointerStateT(A,e,i){for(;e.length<=A;)e.push(null);e[A]=i}onDispatchEvent(A,e){const i=be.Current;try{be.Current=this.context;const g=new Event(A);Pr(g,e),this.dispatchEvent(g)}finally{be.Current=i}}}class kz{constructor(){r(this,"Rad2Deg",180/Math.PI),r(this,"Deg2Rad",Math.PI/180),r(this,"Epsilon",1e-5)}random(){return Math.random()}clamp(A,e,i){return A<e?e:A>i?i:A}clamp01(A){return this.clamp(A,0,1)}lerp(A,e,i){return i=i<0?0:i,i=i>1?1:i,A+(e-A)*i}inverseLerp(A,e,i){return(i-A)/(e-A)}remap(A,e,i,g,I){return g+(I-g)*(A-e)/(i-e)}moveTowards(A,e,i){return A+=i,(i<0&&A<e||i>0&&A>e)&&(A=e),A}toDegrees(A){return A*180/Math.PI}toRadians(A){return A*Math.PI/180}tan(A){return Math.tan(A)}gammaToLinear(A){return Math.pow(A,2.2)}linearToGamma(A){return Math.pow(A,1/2.2)}}const te=new kz;function vv(t,A,e){const i=t.length(),g=A.length(),I=te.lerp(i,g,e);return t.lerp(A,e).normalize().multiplyScalar(I)}const Gz=new xA().setFromAxisAngle(new S(0,1,0),Math.PI);function Mz(t,A){t.lookAt(A),t.quaternion.multiply(Gz)}const xk=new Rs(()=>new S,100);function ue(t,A=null,e=!0){const i=A??xk.get();return t?t.parent?(e&&t.updateWorldMatrix(!0,!1),t.matrixWorldNeedsUpdate&&t.updateMatrixWorld(),i.setFromMatrixPosition(t.matrixWorld),i):i.copy(t.position):i.set(0,0,0)}function Ci(t,A){if(!t)return;const e=xk.get();A!==e&&e.copy(A),(t?.parent??t).worldToLocal(e),t.position.set(e.x,e.y,e.z)}function HQ(t,A,e,i){const g=xk.get();g.set(A,e,i),Ci(t,g)}const hD=new Rs(()=>new xA,100),jr=new xA,Tk=new xA;function Ti(t,A=null){if(!t)return hD.get().identity();const e=A??hD.get();return t.parent?(t.getWorldQuaternion(e),e):e.copy(t.quaternion)}function pI(t,A){if(!t)return;A!==jr&&jr.copy(A);const e=jr,i=t?.parent;i?.getWorldQuaternion(Tk),Tk.invert();const g=Tk.multiply(e);t.quaternion.set(g.x,g.y,g.z,g.w)}function bv(t,A,e,i,g){jr.set(A,e,i,g),pI(t,jr)}const Rz=new Rs(()=>new S,100),Uz=new S;function Cg(t,A=null){return A||(A=Rz.get()),t?t.parent?(t.getWorldScale(A),A):A.copy(t.scale):A.set(0,0,0)}function Yk(t,A){if(!t)return;if(!t.parent){t.scale.copy(A);return}const e=Uz;t.parent.getWorldScale(e),t.scale.copy(A),t.scale.divide(e)}const Fz=new S,Lv=new xA;function Nz(t){return Ti(t,Lv),Fz.set(0,0,1).applyQuaternion(Lv)}const Kz=new Rs(()=>new S,100),xv=new xA;function Jz(t,A){return A||(A=Kz.get().set(0,0,1)),Ti(t,xv),A.applyQuaternion(xv)}const Tv=new og,Yv=new og,qz=new S;function Hv(t){const A=hD.get();return t.getWorldQuaternion(A),Yv.setFromQuaternion(A),Yv}function Ov(t,A){const e=hD.get();pI(t,e.setFromEuler(A))}function cD(t){const A=Hv(t),e=qz;return e.set(A.x,A.y,A.z),e.x=te.toDegrees(e.x),e.y=te.toDegrees(e.y),e.z=te.toDegrees(e.z),e}function _v(t,A){lD(t,A.x,A.y,A.z,!0)}function lD(t,A,e,i,g=!0){g&&(A=te.toRadians(A),e=te.toRadians(e),i=te.toRadians(i)),Tv.set(A,e,i),jr.setFromEuler(Tv),pI(t,jr)}function dD(t,A=!0){t&&(A?function e(i){console.groupCollapsed((i.name?i.name:"(no name : "+i.type+")")+" %o",i),i.children.forEach(e),console.groupEnd()}(t):t.traverse(function(e){for(var i="|___",g=e;g.parent!==null;)i=" "+i,g=g.parent;console.log(i+e.name+" <"+e.type+">")}))}function Pv(t){if(t){const A=t;return A.blendMode!==void 0&&A.clampWhenFinished!==void 0&&A.enabled!==void 0&&A.fadeIn!==void 0&&A.getClip!==void 0}return!1}const Rc=class{static createBlitMaterial(t){return new Je({uniforms:{map:new FA(null)},vertexShader:this.vertex,fragmentShader:t})}static copyTexture(t,A){const e=A??this.blipMaterial;e.uniforms.map.value=t,e.needsUpdate=!0,e.uniformsNeedUpdate=!0;const i=this.mesh;i.material=e,i.frustumCulled=!1,this.scene.children.length=0,this.scene.add(i),this.renderer.setSize(t.image.width,t.image.height),this.renderer.clear(),this.renderer.render(this.scene,this.perspectiveCam);const g=new _e(this.renderer.domElement);return g.name="Copy",g.needsUpdate=!0,g}static textureToCanvas(t,A){if(!t)return null;(A===!0||t.isCompressedTexture===!0)&&(t=jv(t));const e=t.image;if(bz(e)){const i=document.createElement("canvas");i.width=e.width,i.height=e.height;const g=i.getContext("2d");return g?(g.drawImage(e,0,0,e.width,e.height,0,0,i.width,i.height),i):(console.error("Failed getting canvas 2d context"),null)}return null}};let As=Rc;r(As,"planeGeometry",new YI(2,2,1,1)),r(As,"renderer",new kQ({antialias:!1})),r(As,"perspectiveCam",new ze),r(As,"scene",new dI),r(As,"vertex",`
|
|
3669
|
+
<a href="https://docs.needle.tools/serializable" target="_blank">documentation</a>`),console.warn(g,o,t[o],t);continue}}}}function yz(t,A){for(const e of Object.keys(A)){const i=A[e];if(typeof i=="object"&&i!==null&&i!==void 0){const g=t[e];if(!g){vC&&console.log(e,"is undefined on",t);continue}for(const I of Object.keys(i))if(g[I]===void 0&&Kv(i[I])&&!Kv(g)){const o=Sz(g,I);if(o&&(o?.writable===void 0||o?.writable===!1)&&o.set===void 0){vC&&console.warn('Property is not writable "'+I+'"',g,o,i[I],g[I]);continue}g[I]=i[I]}}}}function Sz(t,A){for(;t;){const e=Object.getOwnPropertyDescriptor(t,A);if(e)return e;t=Object.getPrototypeOf(t)}}function Kv(t){switch(typeof t){case"number":case"string":case"boolean":return!0}return!1}function bk(t,A,e,i,g){let I=typeof A=="function"&&A.prototype===void 0,o=A;if(I)try{if(o=A?.call(A,g),I=!1,o==null)return}catch(n){console.error("Error in callback",n,t)}if(e.type=o,!I&&g instanceof o)return g;if(g&&typeof g=="object"&&lz(g)){if(g.__concreteInstance)return g.__concreteInstance;const n=g;if(!n.$serializedTypes&&o.prototype.$serializedTypes&&(n.$serializedTypes=o.prototype.$serializedTypes),n.$serializedTypes&&QD(n,t,e),g&&o!==void 0)try{const B=new o;Rg&&console.log("Create concrete instance for persistent asset",g,"instance:",B),Pr(B,g),g.__concreteInstance=B,g=B}catch(B){console.error("Error creating instance or creating values on instance",B,g,o)}return g}if(i||(i={serializer:rD.getSerializerForConstructor(o)}),Array.isArray(t)){const n=[];for(let B=0;B<t.length;B++){const Q=t[B],E=bk(Q,A,e,i,Q);n.push(E)}return n}const s=i.serializer;if(s)return s.onDeserialize(t,e);let C;if(t&&(t.isMaterial||t.isTexture||t.isObject3D))C=t;else{if(t===void 0)return;if(t===null&&(o===Ue||o===_e||o===fA||o===PI))return null;C=new o(...fz(t))}const a=C;return a.$serializedTypes&&QD(a,t,e),C}function fz(t){if(BD.length=0,typeof t=="object"&&t!==null&&t!==void 0)for(const A of Object.keys(t))BD.push(t[A]);return BD}const Lk=Symbol("assigned component properties");function Pr(t,A,e){var i;if(A==null||t==null)return;t[Lk]=!0;const g=((i=t.constructor)==null?void 0:i.name)??"unknown";e?.registerDefinedKeys(g,t);for(const I of Object.keys(A)){const o=mz(t,I);typeof o?.value!="function"&&(!o||o.writable===!0||o?.set!==void 0)&&(t[I]=A[I])}delete t[Lk]}function mz(t,A){let e;do e=Object.getOwnPropertyDescriptor(t,A);while(!e&&(t=Object.getPrototypeOf(t)));return e}const wo=oA("debuginput");class ED{constructor(A){r(this,"key"),r(this,"keyType"),r(this,"source"),this.key=A.key,this.keyType=A.type,this.source=A}}var bs=(t=>(t.PointerDown="pointerdown",t.PointerUp="pointerup",t.PointerMove="pointermove",t.KeyDown="keydown",t.KeyUp="keyup",t.KeyPressed="keypress",t))(bs||{}),Jv=(t=>(t.Mouse="mouse",t.Touch="touch",t))(Jv||{});class qv extends EventTarget{constructor(A){super(),r(this,"_doubleClickTimeThreshold",.2),r(this,"_longPressTimeThreshold",1),r(this,"_specialCursorTrigger",0),r(this,"context"),r(this,"_pointerDown",[!1]),r(this,"_pointerUp",[!1]),r(this,"_pointerClick",[!1]),r(this,"_pointerDoubleClick",[!1]),r(this,"_pointerPressed",[!1]),r(this,"_pointerPositions",[new Z]),r(this,"_pointerPositionsLastFrame",[new Z]),r(this,"_pointerPositionsDelta",[new Z]),r(this,"_pointerPositionsRC",[new Z]),r(this,"_pointerPositionDown",[new Z]),r(this,"_pointerDownTime",[]),r(this,"_pointerUpTime",[]),r(this,"_pointerUpTimestamp",[]),r(this,"_pointerIds",[]),r(this,"_pointerTypes",[""]),r(this,"_mouseWheelChanged",[!1]),r(this,"_mouseWheelDeltaY",[0]),r(this,"_pointerEvent",[]),r(this,"_pointerUsed",[]),r(this,"onLostFocus",()=>{for(const e in this.keysPressed)this.keysPressed[e].pressed=!1}),r(this,"onEndOfFrame",()=>{for(let e=0;e<this._pointerUp.length;e++)this._pointerUp[e]=!1;for(let e=0;e<this._pointerDown.length;e++)this._pointerDown[e]=!1;for(let e=0;e<this._pointerClick.length;e++)this._pointerClick[e]=!1;for(let e=0;e<this._pointerDoubleClick.length;e++)this._pointerDoubleClick[e]=!1;for(const e of this._pointerPositionsDelta)e.set(0,0);for(let e=0;e<this._mouseWheelChanged.length;e++)this._mouseWheelChanged[e]=!1;for(let e=0;e<this._mouseWheelDeltaY.length;e++)this._mouseWheelDeltaY[e]=0}),r(this,"keysPressed",{}),r(this,"onKeyDown",e=>{if(!this.context.application.hasFocus)return;const i=this.keysPressed[e.code];i&&i.pressed||(this.keysPressed[e.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:e.key,code:e.code},this.onDispatchEvent("keydown",new ED(e)))}),r(this,"onKeyPressed",e=>{if(!this.context.application.hasFocus)return;const i=this.keysPressed[e.code];i&&(i.pressed=!0,i.frame=this.context.time.frameCount+1,this.onDispatchEvent("keypress",new ED(e)))}),r(this,"onKeyUp",e=>{if(!this.context.application.hasFocus)return;const i=this.keysPressed[e.code];i&&(i.pressed=!1,i.frame=this.context.time.frameCount+1,this.onDispatchEvent("keyup",new ED(e)))}),r(this,"onMouseWheel",e=>{if(this.canReceiveInput(e)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const i=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=i+e.deltaY}),r(this,"onTouchStart",e=>{if(!(e.changedTouches.length<=0)&&this.canReceiveInput(e)!==!1)for(let i=0;i<e.changedTouches.length;i++){const g=e.changedTouches[i],I=this.getPointerIndex(g.identifier);wo&&di(`touch start #${I}, identifier:${g.identifier}`);const o={button:I,clientX:g.clientX,clientY:g.clientY,pointerType:"touch",source:e};this.onDown(o)}}),r(this,"onTouchMove",e=>{if(!(e.changedTouches.length<=0))for(let i=0;i<e.changedTouches.length;i++){const g=e.changedTouches[i],I={button:this.getPointerIndex(g.identifier),clientX:g.clientX,clientY:g.clientY,pointerType:"touch",source:e};this.onMove(I)}}),r(this,"onTouchUp",e=>{if(!(e.changedTouches.length<=0))for(let i=0;i<e.changedTouches.length;i++){const g=e.changedTouches[i],I=this.getPointerIndex(g.identifier);if(!this.isNewEvent(e.timeStamp,I,this._pointerUpTimestamp))continue;wo&&di(`touch up #${I}, identifier:${g.identifier}`);const o={button:I,clientX:g.clientX,clientY:g.clientY,pointerType:"touch",source:e};this.onUp(o)}}),r(this,"onMouseDown",e=>{if(e.defaultPrevented||this.canReceiveInput(e)===!1)return;let i=e.button;this.onDown({button:i,clientX:e.clientX,clientY:e.clientY,pointerType:"mouse",source:e})}),r(this,"onMouseMove",e=>{if(e.defaultPrevented)return;const i={button:e.button,clientX:e.clientX,clientY:e.clientY,pointerType:"mouse",source:e,movementX:e.movementX,movementY:e.movementY};this.onMove(i)}),r(this,"onMouseUp",e=>{if(e.defaultPrevented)return;let i=e.button;this.isNewEvent(e.timeStamp,i,this._pointerUpTimestamp)&&this.onUp({button:i,clientX:e.clientX,clientY:e.clientY,pointerType:"mouse",source:e})}),this.context=A,this.context.post_render_callbacks.push(this.onEndOfFrame),window.addEventListener("touchstart",this.onTouchStart,!1),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchUp,!1),window.addEventListener("mousedown",this.onMouseDown,!1),window.addEventListener("mousemove",this.onMouseMove,!1),window.addEventListener("mouseup",this.onMouseUp,!1),window.addEventListener("wheel",this.onMouseWheel,{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)}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)}setCursorPointer(){this._specialCursorTrigger+=1,this.context.domElement.style.cursor="pointer"}setCursorNormal(){this._specialCursorTrigger-=1,this._specialCursorTrigger=Math.max(0,this._specialCursorTrigger),this._specialCursorTrigger===0&&(this.context.domElement.style.cursor="default")}setPointerUsed(A,e=!0){if(A>=this._pointerUsed.length){if(A>=this._pointerIds.length)return;for(;this._pointerUsed.length<=A;)this._pointerUsed.push(!1)}this._pointerUsed[A]=e}getPointerUsed(A){return A>=this._pointerUsed.length?!1:this._pointerUsed[A]}getPointerPressedCount(){let A=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&A++;return A}getPointerPosition(A){return A>=this._pointerPositions.length?null:this._pointerPositions[A]}getPointerPositionLastFrame(A){return A>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[A]}getPointerPositionDelta(A){return A>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[A]}getPointerPositionRC(A){return A>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[A]}getPointerDown(A){return A>=this._pointerDown.length?!1:this._pointerDown[A]}getPointerUp(A){return A>=this._pointerUp.length?!1:this._pointerUp[A]}getPointerPressed(A){return A>=this._pointerPressed.length?!1:this._pointerPressed[A]}getPointerClicked(A){return A>=this._pointerClick.length?!1:this._pointerClick[A]}getPointerDoubleClicked(A){return A>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[A]}getPointerDownTime(A){return A>=this._pointerDownTime.length?-1:this._pointerDownTime[A]}getPointerUpTime(A){return A>=this._pointerUpTime.length?-1:this._pointerUpTime[A]}getPointerLongPress(A){return A>=this._pointerDownTime.length?!1:this.getPointerPressed(A)&&this.context.time.time-this._pointerDownTime[A]>this._longPressTimeThreshold}getIsMouse(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="mouse"}getIsTouch(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="touch"}getTouchesPressedCount(){let A=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&this.getIsTouch(e)&&A++;return A}getMouseWheelChanged(A=0){return A>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[A]}getMouseWheelDeltaY(A=0){return A>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[A]}getPointerEvent(A){if(!(A>=this._pointerEvent.length))return this._pointerEvent[A]??void 0}*foreachPointerId(A){for(let e=0;e<this._pointerTypes.length;e++)if(this._pointerIsActive(e)){if(A!==void 0){const i=this._pointerTypes[e];if(Array.isArray(A)){let g=!1;for(const I of A)if(i===I){g=!0;break}if(!g)continue}else if(A!==i)continue}yield e}}*foreachTouchId(){for(let A=0;A<this._pointerTypes.length;A++)this._pointerTypes[A]==="touch"&&this._pointerIsActive[A]&&(yield A)}_pointerIsActive(A){return A<0?!1:this._pointerPressed[A]||this._pointerDown[A]||this._pointerUp[A]}getKeyDown(){for(const A in this.keysPressed){const e=this.keysPressed[A];if(e.startFrame===this.context.time.frameCount)return e.key}return null}getKeyPressed(){for(const A in this.keysPressed){const e=this.keysPressed[A];if(e.pressed)return e.key}return null}isKeyDown(A){var e;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(A);if(i!==null){for(const g of i)if(this.isKeyDown(g))return!0;return!1}return((e=this.keysPressed[A])==null?void 0:e.startFrame)===this.context.time.frameCount&&this.keysPressed[A].pressed}isKeyUp(A){var e;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(A);if(i!==null){for(const g of i)if(this.isKeyUp(g))return!0;return!1}return((e=this.keysPressed[A])==null?void 0:e.frame)===this.context.time.frameCount&&!this.keysPressed[A].pressed}isKeyPressed(A){var e;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const i=this.getCodeForCommonKeyName(A);if(i!==null){for(const g of i)if(this.isKeyPressed(g))return!0;return!1}return(e=this.keysPressed[A])==null?void 0:e.pressed}getCodeForCommonKeyName(A){if(A.length===1){if(A>="0"&&A<="9")return["Digit"+A];if(A>="a"&&A<="z")return["Key"+A.toUpperCase()];if(A==" ")return["Space"]}switch(A){case"Shift":return["ShiftLeft","ShiftRight"];case"Control":return["ControlLeft","ControlRight"];case"Alt":return["AltLeft","AltRight"]}return null}createPointerDown(A){wo&&di("Create Pointer down"),this.onDown(A)}createPointerMove(A){wo&&di("Create Pointer move"),this.onMove(A)}createPointerUp(A){wo&&di("Create Pointer up"),this.onUp(A)}convertScreenspaceToRaycastSpace(A){A.x=(A.x-this.context.domX)/this.context.domWidth*2-1,A.y=-((A.y-this.context.domY)/this.context.domHeight)*2+1}dispose(){const A=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);A>=0&&this.context.post_render_callbacks.splice(A,1),window.removeEventListener("touchstart",this.onTouchStart,!1),window.removeEventListener("touchmove",this.onTouchMove,!1),window.removeEventListener("touchend",this.onTouchUp,!1),window.removeEventListener("mousedown",this.onMouseDown,!1),window.removeEventListener("mousemove",this.onMouseMove,!1),window.removeEventListener("mouseup",this.onMouseUp,!1),window.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}canReceiveInput(A){return A.target===this.context.renderer.domElement||A.target===this.context.domElement}isNewEvent(A,e,i){for(;i.length<=e;)i.push(-1);return A===i[e]?!1:(i[e]=A,!0)}isInRect(A){if(this.context.isInXR)return!0;const e=this.context.domElement.getBoundingClientRect(),i=A.clientX,g=A.clientY,I=i>=e.x&&i<=e.right&&g>=e.y&&g<=e.bottom;return wo&&!I&&console.log("Not in rect",e,i,g),I}onDown(A){var e;if(wo&&console.log(A.pointerType,"DOWN",A.button),!!this.isInRect(A)){if(A.pointerType==="mouse"){const i=this._pointerUpTimestamp[A.button];if(i>0&&((e=A.source)==null?void 0:e.timeStamp)!==void 0){const g=A.source.timeStamp-i;if(g<60&&g>=0){wo&&console.log("Ignoring mouse.down for touch.up");return}}}for(this.setPointerState(A.button,this._pointerPressed,!0),this.setPointerState(A.button,this._pointerDown,!0),this.setPointerStateT(A.button,this._pointerEvent,A.source);A.button>=this._pointerTypes.length;)this._pointerTypes.push(A.pointerType);for(this._pointerTypes[A.button]=A.pointerType;A.button>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new Z);for(this._pointerPositionDown[A.button].set(A.clientX,A.clientY);A.button>=this._pointerPositions.length;)this._pointerPositions.push(new Z);this._pointerPositions[A.button].set(A.clientX,A.clientY),A.button>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[A.button]=this.context.time.time,this.updatePointerPosition(A),this.onDispatchEvent("pointerdown",A)}}onMove(A){const e=this.getPointerPressed(A.button);e===!1&&!this.isInRect(A)||A.pointerType==="touch"&&!e||(wo&&console.log(A.pointerType,"MOVE",A.button),this.updatePointerPosition(A),this.setPointerStateT(A.button,this._pointerEvent,A.source),this.onDispatchEvent("pointermove",A))}onUp(A){var e;if(((e=this._pointerIds)==null?void 0:e.length)>=A.button&&(this._pointerIds[A.button]=-1),!this._pointerPressed[A.button]){wo&&console.log(A.pointerType,"UP",A.button,"was not down");return}for(wo&&console.log(A.pointerType,"UP",A.button),this.setPointerState(A.button,this._pointerPressed,!1),this.setPointerStateT(A.button,this._pointerEvent,A.source),this.setPointerState(A.button,this._pointerUp,!0);A.button>=this._pointerUsed.length;)this._pointerUsed.push(!1);if(this.setPointerState(A.button,this._pointerUsed,!1),this.updatePointerPosition(A),!this._pointerPositionDown[A.button]){wo&&Do("Received pointer up event without matching down event for button: "+A.button),console.warn("Received pointer up event without matching down event for button: "+A.button);return}const i=A.clientX-this._pointerPositionDown[A.button].x,g=A.clientY-this._pointerPositionDown[A.button].y;if(A.button>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(i)<5&&Math.abs(g)<5){this.setPointerState(A.button,this._pointerClick,!0);const I=this._pointerUpTime[A.button],o=this.context.time.time-I;o<this._doubleClickTimeThreshold&&o>0&&this.setPointerState(A.button,this._pointerDoubleClick,!0)}this._pointerUpTime[A.button]=this.context.time.time,this.onDispatchEvent("pointerup",A)}updatePointerPosition(A){for(;A.button>=this._pointerPositions.length;)this._pointerPositions.push(new Z);for(;A.button>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new Z);for(;A.button>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new Z);const e=this._pointerPositionsLastFrame[A.button];e.copy(this._pointerPositions[A.button]);const i=this._pointerPositionsDelta[A.button],g=A.clientX-e.x,I=A.clientY-e.y;i.x+=g,i.y+=I,this._pointerPositions[A.button].x=A.clientX,this._pointerPositions[A.button].y=A.clientY;const o=A.clientX,s=A.clientY;for(;A.button>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new Z);const C=this._pointerPositionsRC[A.button];C.set(o,s),this.convertScreenspaceToRaycastSpace(C)}getPointerIndex(A){const e=this._pointerIds;let i=-1;for(let g=0;g<e.length;g++){if(e[g]===A)return g;i===-1&&e[g]===-1&&(i=g)}return i!==-1?(e[i]=A,i):(e.push(A),e.length-1)}setPointerState(A,e,i){for(;e.length<=A;)e.push(!1);e[A]=i}setPointerStateT(A,e,i){for(;e.length<=A;)e.push(null);e[A]=i}onDispatchEvent(A,e){const i=be.Current;try{be.Current=this.context;const g=new Event(A);Pr(g,e),this.dispatchEvent(g)}finally{be.Current=i}}}class kz{constructor(){r(this,"Rad2Deg",180/Math.PI),r(this,"Deg2Rad",Math.PI/180),r(this,"Epsilon",1e-5)}random(){return Math.random()}clamp(A,e,i){return A<e?e:A>i?i:A}clamp01(A){return this.clamp(A,0,1)}lerp(A,e,i){return i=i<0?0:i,i=i>1?1:i,A+(e-A)*i}inverseLerp(A,e,i){return(i-A)/(e-A)}remap(A,e,i,g,I){return g+(I-g)*(A-e)/(i-e)}moveTowards(A,e,i){return A+=i,(i<0&&A<e||i>0&&A>e)&&(A=e),A}toDegrees(A){return A*180/Math.PI}toRadians(A){return A*Math.PI/180}tan(A){return Math.tan(A)}gammaToLinear(A){return Math.pow(A,2.2)}linearToGamma(A){return Math.pow(A,1/2.2)}}const te=new kz;function vv(t,A,e){const i=t.length(),g=A.length(),I=te.lerp(i,g,e);return t.lerp(A,e).normalize().multiplyScalar(I)}const Gz=new xA().setFromAxisAngle(new S(0,1,0),Math.PI);function Mz(t,A){t.lookAt(A),t.quaternion.multiply(Gz)}const xk=new Rs(()=>new S,100);function ue(t,A=null,e=!0){const i=A??xk.get();return t?t.parent?(e&&t.updateWorldMatrix(!0,!1),t.matrixWorldNeedsUpdate&&t.updateMatrixWorld(),i.setFromMatrixPosition(t.matrixWorld),i):i.copy(t.position):i.set(0,0,0)}function Ci(t,A){if(!t)return;const e=xk.get();A!==e&&e.copy(A),(t?.parent??t).worldToLocal(e),t.position.set(e.x,e.y,e.z)}function HQ(t,A,e,i){const g=xk.get();g.set(A,e,i),Ci(t,g)}const hD=new Rs(()=>new xA,100),jr=new xA,Tk=new xA;function Ti(t,A=null){if(!t)return hD.get().identity();const e=A??hD.get();return t.parent?(t.getWorldQuaternion(e),e):e.copy(t.quaternion)}function pI(t,A){if(!t)return;A!==jr&&jr.copy(A);const e=jr,i=t?.parent;i?.getWorldQuaternion(Tk),Tk.invert();const g=Tk.multiply(e);t.quaternion.set(g.x,g.y,g.z,g.w)}function bv(t,A,e,i,g){jr.set(A,e,i,g),pI(t,jr)}const Rz=new Rs(()=>new S,100),Uz=new S;function Cg(t,A=null){return A||(A=Rz.get()),t?t.parent?(t.getWorldScale(A),A):A.copy(t.scale):A.set(0,0,0)}function Yk(t,A){if(!t)return;if(!t.parent){t.scale.copy(A);return}const e=Uz;t.parent.getWorldScale(e),t.scale.copy(A),t.scale.divide(e)}const Fz=new S,Lv=new xA;function Nz(t){return Ti(t,Lv),Fz.set(0,0,1).applyQuaternion(Lv)}const Kz=new Rs(()=>new S,100),xv=new xA;function Jz(t,A){return A||(A=Kz.get().set(0,0,1)),Ti(t,xv),A.applyQuaternion(xv)}const Tv=new og,Yv=new og,qz=new S;function Hv(t){const A=hD.get();return t.getWorldQuaternion(A),Yv.setFromQuaternion(A),Yv}function Ov(t,A){const e=hD.get();pI(t,e.setFromEuler(A))}function cD(t){const A=Hv(t),e=qz;return e.set(A.x,A.y,A.z),e.x=te.toDegrees(e.x),e.y=te.toDegrees(e.y),e.z=te.toDegrees(e.z),e}function _v(t,A){lD(t,A.x,A.y,A.z,!0)}function lD(t,A,e,i,g=!0){g&&(A=te.toRadians(A),e=te.toRadians(e),i=te.toRadians(i)),Tv.set(A,e,i),jr.setFromEuler(Tv),pI(t,jr)}function dD(t,A=!0){t&&(A?function e(i){console.groupCollapsed((i.name?i.name:"(no name : "+i.type+")")+" %o",i),i.children.forEach(e),console.groupEnd()}(t):t.traverse(function(e){for(var i="|___",g=e;g.parent!==null;)i=" "+i,g=g.parent;console.log(i+e.name+" <"+e.type+">")}))}function Pv(t){if(t){const A=t;return A.blendMode!==void 0&&A.clampWhenFinished!==void 0&&A.enabled!==void 0&&A.fadeIn!==void 0&&A.getClip!==void 0}return!1}const Rc=class{static createBlitMaterial(t){return new Je({uniforms:{map:new FA(null)},vertexShader:this.vertex,fragmentShader:t})}static copyTexture(t,A){const e=A??this.blipMaterial;e.uniforms.map.value=t,e.needsUpdate=!0,e.uniformsNeedUpdate=!0;const i=this.mesh;i.material=e,i.frustumCulled=!1,this.scene.children.length=0,this.scene.add(i),this.renderer.setSize(t.image.width,t.image.height),this.renderer.clear(),this.renderer.render(this.scene,this.perspectiveCam);const g=new _e(this.renderer.domElement);return g.name="Copy",g.needsUpdate=!0,g}static textureToCanvas(t,A){if(!t)return null;(A===!0||t.isCompressedTexture===!0)&&(t=jv(t));const e=t.image;if(bz(e)){const i=document.createElement("canvas");i.width=e.width,i.height=e.height;const g=i.getContext("2d");return g?(g.drawImage(e,0,0,e.width,e.height,0,0,i.width,i.height),i):(console.error("Failed getting canvas 2d context"),null)}return null}};let As=Rc;r(As,"planeGeometry",new YI(2,2,1,1)),r(As,"renderer",new kQ({antialias:!1})),r(As,"perspectiveCam",new ze),r(As,"scene",new dI),r(As,"vertex",`
|
|
3670
3670
|
varying vec2 vUv;
|
|
3671
3671
|
void main(){
|
|
3672
3672
|
vUv = uv;
|
|
@@ -4408,7 +4408,7 @@ Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
|
|
|
4408
4408
|
version 0.6.9
|
|
4409
4409
|
*/var qT=function(t){return URL.createObjectURL(new Blob([t],{type:"text/javascript"}))};try{URL.revokeObjectURL(qT(""))}catch{qT=function(t){return"data:application/javascript;charset=UTF-8,"+encodeURI(t)}}var wi=Uint8Array,zg=Uint16Array,aE=Uint32Array,hw=new wi([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),cw=new wi([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),sM=new wi([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),vT=function(t,A){for(var e=new zg(31),i=0;i<31;++i)e[i]=A+=1<<t[i-1];for(var g=new aE(e[30]),i=1;i<30;++i)for(var I=e[i];I<e[i+1];++I)g[I]=I-e[i]<<5|i;return[e,g]},bT=vT(hw,2),LT=bT[0],CM=bT[1];LT[28]=258,CM[258]=28;for(var xT=vT(cw,0),z6=xT[0],TT=xT[1],aM=new zg(32768),qt=0;qt<32768;++qt){var wn=(qt&43690)>>>1|(qt&21845)<<1;wn=(wn&52428)>>>2|(wn&13107)<<2,wn=(wn&61680)>>>4|(wn&3855)<<4,aM[qt]=((wn&65280)>>>8|(wn&255)<<8)>>>1}for(var Os=function(t,A,e){for(var i=t.length,g=0,I=new zg(A);g<i;++g)++I[t[g]-1];var o=new zg(A);for(g=0;g<A;++g)o[g]=o[g-1]+I[g-1]<<1;var s;if(e){s=new zg(1<<A);var C=15-A;for(g=0;g<i;++g)if(t[g])for(var a=g<<4|t[g],n=A-t[g],B=o[t[g]-1]++<<n,Q=B|(1<<n)-1;B<=Q;++B)s[aM[B]>>>C]=a}else for(s=new zg(i),g=0;g<i;++g)t[g]&&(s[g]=aM[o[t[g]-1]++]>>>15-t[g]);return s},yn=new wi(288),qt=0;qt<144;++qt)yn[qt]=8;for(var qt=144;qt<256;++qt)yn[qt]=9;for(var qt=256;qt<280;++qt)yn[qt]=7;for(var qt=280;qt<288;++qt)yn[qt]=8;for(var rl=new wi(32),qt=0;qt<32;++qt)rl[qt]=5;var Z6=Os(yn,9,0),X6=Os(yn,9,1),$6=Os(rl,5,0),A7=Os(rl,5,1),nM=function(t){for(var A=t[0],e=1;e<t.length;++e)t[e]>A&&(A=t[e]);return A},ss=function(t,A,e){var i=A/8|0;return(t[i]|t[i+1]<<8)>>(A&7)&e},rM=function(t,A){var e=A/8|0;return(t[e]|t[e+1]<<8|t[e+2]<<16)>>(A&7)},BM=function(t){return(t/8|0)+(t&7&&1)},QM=function(t,A,e){(A==null||A<0)&&(A=0),(e==null||e>t.length)&&(e=t.length);var i=new(t instanceof zg?zg:t instanceof aE?aE:wi)(e-A);return i.set(t.subarray(A,e)),i},e7=function(t,A,e){var i=t.length;if(!i||e&&!e.l&&i<5)return A||new wi(0);var g=!A||e,I=!e||e.i;e||(e={}),A||(A=new wi(i*3));var o=function(YA){var ee=A.length;if(YA>ee){var XA=new wi(Math.max(ee*2,YA));XA.set(A),A=XA}},s=e.f||0,C=e.p||0,a=e.b||0,n=e.l,B=e.d,Q=e.m,E=e.n,h=i*8;do{if(!n){e.f=s=ss(t,C,1);var l=ss(t,C+1,3);if(C+=3,l)if(l==1)n=X6,B=A7,Q=9,E=5;else if(l==2){var d=ss(t,C,31)+257,c=ss(t,C+10,15)+4,u=d+ss(t,C+5,31)+1;C+=14;for(var p=new wi(u),D=new wi(19),w=0;w<c;++w)D[sM[w]]=ss(t,C+w*3,7);C+=c*3;for(var m=nM(D),M=(1<<m)-1,F=Os(D,m,1),w=0;w<u;){var k=F[ss(t,C,M)];C+=k&15;var f=k>>>4;if(f<16)p[w++]=f;else{var b=0,O=0;for(f==16?(O=3+ss(t,C,3),C+=2,b=p[w-1]):f==17?(O=3+ss(t,C,7),C+=3):f==18&&(O=11+ss(t,C,127),C+=7);O--;)p[w++]=b}}var L=p.subarray(0,d),T=p.subarray(d);Q=nM(L),E=nM(T),n=Os(L,Q,1),B=Os(T,E,1)}else throw"invalid block type";else{var f=BM(C)+4,W=t[f-4]|t[f-3]<<8,iA=f+W;if(iA>i){if(I)throw"unexpected EOF";break}g&&o(a+W),A.set(t.subarray(f,iA),a),e.b=a+=W,e.p=C=iA*8;continue}if(C>h){if(I)throw"unexpected EOF";break}}g&&o(a+131072);for(var AA=(1<<Q)-1,eA=(1<<E)-1,EA=C;;EA=C){var b=n[rM(t,C)&AA],rA=b>>>4;if(C+=b&15,C>h){if(I)throw"unexpected EOF";break}if(!b)throw"invalid length/literal";if(rA<256)A[a++]=rA;else if(rA==256){EA=C,n=null;break}else{var V=rA-254;if(rA>264){var w=rA-257,sA=hw[w];V=ss(t,C,(1<<sA)-1)+LT[w],C+=sA}var mA=B[rM(t,C)&eA],RA=mA>>>4;if(!mA)throw"invalid distance";C+=mA&15;var T=z6[RA];if(RA>3){var sA=cw[RA];T+=rM(t,C)&(1<<sA)-1,C+=sA}if(C>h){if(I)throw"unexpected EOF";break}g&&o(a+131072);for(var bA=a+V;a<bA;a+=4)A[a]=A[a-T],A[a+1]=A[a+1-T],A[a+2]=A[a+2-T],A[a+3]=A[a+3-T];a=bA}}e.l=n,e.p=EA,e.b=a,n&&(s=1,e.m=Q,e.d=B,e.n=E)}while(!s);return a==A.length?A:QM(A,0,a)},VC=function(t,A,e){e<<=A&7;var i=A/8|0;t[i]|=e,t[i+1]|=e>>>8},Bl=function(t,A,e){e<<=A&7;var i=A/8|0;t[i]|=e,t[i+1]|=e>>>8,t[i+2]|=e>>>16},EM=function(t,A){for(var e=[],i=0;i<t.length;++i)t[i]&&e.push({s:i,f:t[i]});var g=e.length,I=e.slice();if(!g)return[cM,0];if(g==1){var o=new wi(e[0].s+1);return o[e[0].s]=1,[o,1]}e.sort(function(w,m){return w.f-m.f}),e.push({s:-1,f:25001});var s=e[0],C=e[1],a=0,n=1,B=2;for(e[0]={s:-1,f:s.f+C.f,l:s,r:C};n!=g-1;)s=e[e[a].f<e[B].f?a++:B++],C=e[a!=n&&e[a].f<e[B].f?a++:B++],e[n++]={s:-1,f:s.f+C.f,l:s,r:C};for(var Q=I[0].s,i=1;i<g;++i)I[i].s>Q&&(Q=I[i].s);var E=new zg(Q+1),h=hM(e[n-1],E,0);if(h>A){var i=0,l=0,d=h-A,c=1<<d;for(I.sort(function(m,M){return E[M.s]-E[m.s]||m.f-M.f});i<g;++i){var u=I[i].s;if(E[u]>A)l+=c-(1<<h-E[u]),E[u]=A;else break}for(l>>>=d;l>0;){var p=I[i].s;E[p]<A?l-=1<<A-E[p]++-1:++i}for(;i>=0&&l;--i){var D=I[i].s;E[D]==A&&(--E[D],++l)}h=A}return[new wi(E),h]},hM=function(t,A,e){return t.s==-1?Math.max(hM(t.l,A,e+1),hM(t.r,A,e+1)):A[t.s]=e},YT=function(t){for(var A=t.length;A&&!t[--A];);for(var e=new zg(++A),i=0,g=t[0],I=1,o=function(C){e[i++]=C},s=1;s<=A;++s)if(t[s]==g&&s!=A)++I;else{if(!g&&I>2){for(;I>138;I-=138)o(32754);I>2&&(o(I>10?I-11<<5|28690:I-3<<5|12305),I=0)}else if(I>3){for(o(g),--I;I>6;I-=6)o(8304);I>2&&(o(I-3<<5|8208),I=0)}for(;I--;)o(g);I=1,g=t[s]}return[e.subarray(0,i),A]},Ql=function(t,A){for(var e=0,i=0;i<A.length;++i)e+=t[i]*A[i];return e},lw=function(t,A,e){var i=e.length,g=BM(A+2);t[g]=i&255,t[g+1]=i>>>8,t[g+2]=t[g]^255,t[g+3]=t[g+1]^255;for(var I=0;I<i;++I)t[g+I+4]=e[I];return(g+4+i)*8},HT=function(t,A,e,i,g,I,o,s,C,a,n){VC(A,n++,e),++g[256];for(var B=EM(g,15),Q=B[0],E=B[1],h=EM(I,15),l=h[0],d=h[1],c=YT(Q),u=c[0],p=c[1],D=YT(l),w=D[0],m=D[1],M=new zg(19),F=0;F<u.length;++F)M[u[F]&31]++;for(var F=0;F<w.length;++F)M[w[F]&31]++;for(var k=EM(M,7),f=k[0],b=k[1],O=19;O>4&&!f[sM[O-1]];--O);var L=a+5<<3,T=Ql(g,yn)+Ql(I,rl)+o,W=Ql(g,Q)+Ql(I,l)+o+14+3*O+Ql(M,f)+(2*M[16]+3*M[17]+7*M[18]);if(L<=T&&L<=W)return lw(A,n,t.subarray(C,C+a));var iA,AA,eA,EA;if(VC(A,n,1+(W<T)),n+=2,W<T){iA=Os(Q,E,0),AA=Q,eA=Os(l,d,0),EA=l;var rA=Os(f,b,0);VC(A,n,p-257),VC(A,n+5,m-1),VC(A,n+10,O-4),n+=14;for(var F=0;F<O;++F)VC(A,n+3*F,f[sM[F]]);n+=3*O;for(var V=[u,w],sA=0;sA<2;++sA)for(var mA=V[sA],F=0;F<mA.length;++F){var RA=mA[F]&31;VC(A,n,rA[RA]),n+=f[RA],RA>15&&(VC(A,n,mA[F]>>>5&127),n+=mA[F]>>>12)}}else iA=Z6,AA=yn,eA=$6,EA=rl;for(var F=0;F<s;++F)if(i[F]>255){var RA=i[F]>>>18&31;Bl(A,n,iA[RA+257]),n+=AA[RA+257],RA>7&&(VC(A,n,i[F]>>>23&31),n+=hw[RA]);var bA=i[F]&31;Bl(A,n,eA[bA]),n+=EA[bA],bA>3&&(Bl(A,n,i[F]>>>5&8191),n+=cw[bA])}else Bl(A,n,iA[i[F]]),n+=AA[i[F]];return Bl(A,n,iA[256]),n+AA[256]},t7=new aE([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),cM=new wi(0),i7=function(t,A,e,i,g,I){var o=t.length,s=new wi(i+o+5*(1+Math.ceil(o/7e3))+g),C=s.subarray(i,s.length-g),a=0;if(!A||o<8)for(var n=0;n<=o;n+=65535){var B=n+65535;B<o?a=lw(C,a,t.subarray(n,B)):(C[n]=I,a=lw(C,a,t.subarray(n,o)))}else{for(var Q=t7[A-1],E=Q>>>13,h=Q&8191,l=(1<<e)-1,d=new zg(32768),c=new zg(l+1),u=Math.ceil(e/3),p=2*u,D=function(yA){return(t[yA]^t[yA+1]<<u^t[yA+2]<<p)&l},w=new aE(25e3),m=new zg(288),M=new zg(32),F=0,k=0,n=0,f=0,b=0,O=0;n<o;++n){var L=D(n),T=n&32767,W=c[L];if(d[T]=W,c[L]=T,b<=n){var iA=o-n;if((F>7e3||f>24576)&&iA>423){a=HT(t,C,0,w,m,M,k,f,O,n-O,a),f=F=k=0,O=n;for(var AA=0;AA<286;++AA)m[AA]=0;for(var AA=0;AA<30;++AA)M[AA]=0}var eA=2,EA=0,rA=h,V=T-W&32767;if(iA>2&&L==D(n-V))for(var sA=Math.min(E,iA)-1,mA=Math.min(32767,n),RA=Math.min(258,iA);V<=mA&&--rA&&T!=W;){if(t[n+eA]==t[n+eA-V]){for(var bA=0;bA<RA&&t[n+bA]==t[n+bA-V];++bA);if(bA>eA){if(eA=bA,EA=V,bA>sA)break;for(var YA=Math.min(V,bA-2),ee=0,AA=0;AA<YA;++AA){var XA=n-V+AA+32768&32767,VA=d[XA],we=XA-VA+32768&32767;we>ee&&(ee=we,W=XA)}}}T=W,W=d[T],V+=T-W+32768&32767}if(EA){w[f++]=268435456|CM[eA]<<18|TT[EA];var lA=CM[eA]&31,_=TT[EA]&31;k+=hw[lA]+cw[_],++m[257+lA],++M[_],b=n+eA,++F}else w[f++]=t[n],++m[t[n]]}}a=HT(t,C,I,w,m,M,k,f,O,n-O,a),!I&&a&7&&(a=lw(C,a+1,cM))}return QM(s,0,i+BM(a)+g)},g7=function(){for(var t=new aE(256),A=0;A<256;++A){for(var e=A,i=9;--i;)e=(e&1&&3988292384)^e>>>1;t[A]=e}return t}(),I7=function(){var t=-1;return{p:function(A){for(var e=t,i=0;i<A.length;++i)e=g7[e&255^A[i]]^e>>>8;t=e},d:function(){return~t}}},o7=function(t,A,e,i,g){return i7(t,A.level==null?6:A.level,A.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(t.length)))*1.5):12+A.mem,e,i,!g)},OT=function(t,A){var e={};for(var i in t)e[i]=t[i];for(var i in A)e[i]=A[i];return e},Qg=function(t,A,e){for(;e;++A)t[A]=e,e>>>=8},s7=function(t){if((t[0]&15)!=8||t[0]>>>4>7||(t[0]<<8|t[1])%31)throw"invalid zlib data";if(t[1]&32)throw"invalid zlib data: preset dictionaries not supported"};function C7(t,A){return o7(t,A||{},0,0)}function dw(t,A){return e7((s7(t),t.subarray(2,-4)),A)}var _T=function(t,A,e,i){for(var g in t){var I=t[g],o=A+g;I instanceof wi?e[o]=[I,i]:Array.isArray(I)?e[o]=[I[0],OT(i,I[1])]:_T(I,o+"/",e,i)}},PT=typeof TextEncoder<"u"&&new TextEncoder,a7=typeof TextDecoder<"u"&&new TextDecoder,n7=0;try{a7.decode(cM,{stream:!0}),n7=1}catch{}function pw(t,A){if(A){for(var e=new wi(t.length),i=0;i<t.length;++i)e[i]=t.charCodeAt(i);return e}if(PT)return PT.encode(t);for(var g=t.length,I=new wi(t.length+(t.length>>1)),o=0,s=function(B){I[o++]=B},i=0;i<g;++i){if(o+5>I.length){var C=new wi(o+8+(g-i<<1));C.set(I),I=C}var a=t.charCodeAt(i);a<128||A?s(a):a<2048?(s(192|a>>6),s(128|a&63)):a>55295&&a<57344?(a=65536+(a&1047552)|t.charCodeAt(++i)&1023,s(240|a>>18),s(128|a>>12&63),s(128|a>>6&63),s(128|a&63)):(s(224|a>>12),s(128|a>>6&63),s(128|a&63))}return QM(I,0,o)}var lM=function(t){var A=0;if(t)for(var e in t){var i=t[e].length;if(i>65535)throw"extra field too long";A+=i+4}return A},jT=function(t,A,e,i,g,I,o,s){var C=i.length,a=e.extra,n=s&&s.length,B=lM(a);Qg(t,A,o!=null?33639248:67324752),A+=4,o!=null&&(t[A++]=20,t[A++]=e.os),t[A]=20,A+=2,t[A++]=e.flag<<1|(I==null&&8),t[A++]=g&&8,t[A++]=e.compression&255,t[A++]=e.compression>>8;var Q=new Date(e.mtime==null?Date.now():e.mtime),E=Q.getFullYear()-1980;if(E<0||E>119)throw"date not in range 1980-2099";if(Qg(t,A,E<<25|Q.getMonth()+1<<21|Q.getDate()<<16|Q.getHours()<<11|Q.getMinutes()<<5|Q.getSeconds()>>>1),A+=4,I!=null&&(Qg(t,A,e.crc),Qg(t,A+4,I),Qg(t,A+8,e.size)),Qg(t,A+12,C),Qg(t,A+14,B),A+=16,o!=null&&(Qg(t,A,n),Qg(t,A+6,e.attrs),Qg(t,A+10,o),A+=14),t.set(i,A),A+=C,B)for(var h in a){var l=a[h],d=l.length;Qg(t,A,+h),Qg(t,A+2,d),t.set(l,A+4),A+=4+d}return n&&(t.set(s,A),A+=n),A},r7=function(t,A,e,i,g){Qg(t,A,101010256),Qg(t,A+8,e),Qg(t,A+10,e),Qg(t,A+12,i),Qg(t,A+16,g)};function B7(t,A){A||(A={});var e={},i=[];_T(t,"",e,A);var g=0,I=0;for(var o in e){var s=e[o],C=s[0],a=s[1],n=a.level==0?0:8,B=pw(o),Q=B.length,E=a.comment,h=E&&pw(E),l=h&&h.length,d=lM(a.extra);if(Q>65535)throw"filename too long";var c=n?C7(C,a):C,u=c.length,p=I7();p.p(C),i.push(OT(a,{size:C.length,crc:p.d(),c,f:B,m:h,u:Q!=o.length||h&&E.length!=l,o:g,compression:n})),g+=30+Q+d+u,I+=76+2*(Q+d)+(l||0)+u}for(var D=new wi(I+22),w=g,m=I-g,M=0;M<i.length;++M){var B=i[M];jT(D,B.o,B,B.f,B.u,B.c.length);var F=30+B.f.length+lM(B.extra);D.set(B.c,B.o+F),jT(D,g,B,B.f,B.u,B.c.length,B.o,B.m),g+=16+F+(B.m?B.m.length:0)}return r7(D,g,i.length,m,w),D}class dM extends Ek{constructor(A){super(A),this.type=ci}parse(A){const e=Math.pow(2.7182818,2.2);function i(G,K){let U=0;for(let x=0;x<65536;++x)(x==0||G[x>>3]&1<<(x&7))&&(K[U++]=x);const H=U-1;for(;U<65536;)K[U++]=0;return H}function g(G){for(let K=0;K<16384;K++)G[K]={},G[K].len=0,G[K].lit=0,G[K].p=null}const I={l:0,c:0,lc:0};function o(G,K,U,H,x){for(;U<G;)K=K<<8|_(H,x),U+=8;U-=G,I.l=K>>U&(1<<G)-1,I.c=K,I.lc=U}const s=new Array(59);function C(G){for(let U=0;U<=58;++U)s[U]=0;for(let U=0;U<65537;++U)s[G[U]]+=1;let K=0;for(let U=58;U>0;--U){const H=K+s[U]>>1;s[U]=K,K=H}for(let U=0;U<65537;++U){const H=G[U];H>0&&(G[U]=H|s[H]++<<6)}}function a(G,K,U,H,x,j){const gA=K;let MA=0,qA=0;for(;H<=x;H++){if(gA.value-K.value>U)return!1;o(6,MA,qA,G,gA);const kA=I.l;if(MA=I.c,qA=I.lc,j[H]=kA,kA==63){if(gA.value-K.value>U)throw new Error("Something wrong with hufUnpackEncTable");o(8,MA,qA,G,gA);let TA=I.l+6;if(MA=I.c,qA=I.lc,H+TA>x+1)throw new Error("Something wrong with hufUnpackEncTable");for(;TA--;)j[H++]=0;H--}else if(kA>=59){let TA=kA-59+2;if(H+TA>x+1)throw new Error("Something wrong with hufUnpackEncTable");for(;TA--;)j[H++]=0;H--}}C(j)}function n(G){return G&63}function B(G){return G>>6}function Q(G,K,U,H){for(;K<=U;K++){const x=B(G[K]),j=n(G[K]);if(x>>j)throw new Error("Invalid table entry");if(j>14){const gA=H[x>>j-14];if(gA.len)throw new Error("Invalid table entry");if(gA.lit++,gA.p){const MA=gA.p;gA.p=new Array(gA.lit);for(let qA=0;qA<gA.lit-1;++qA)gA.p[qA]=MA[qA]}else gA.p=new Array(1);gA.p[gA.lit-1]=K}else if(j){let gA=0;for(let MA=1<<14-j;MA>0;MA--){const qA=H[(x<<14-j)+gA];if(qA.len||qA.p)throw new Error("Invalid table entry");qA.len=j,qA.lit=K,gA++}}}return!0}const E={c:0,lc:0};function h(G,K,U,H){G=G<<8|_(U,H),K+=8,E.c=G,E.lc=K}const l={c:0,lc:0};function d(G,K,U,H,x,j,gA,MA,qA){if(G==K){H<8&&(h(U,H,x,j),U=E.c,H=E.lc),H-=8;let kA=U>>H;if(kA=new Uint8Array([kA])[0],MA.value+kA>qA)return!1;const TA=gA[MA.value-1];for(;kA-- >0;)gA[MA.value++]=TA}else if(MA.value<qA)gA[MA.value++]=G;else return!1;l.c=U,l.lc=H}function c(G){return G&65535}function u(G){const K=c(G);return K>32767?K-65536:K}const p={a:0,b:0};function D(G,K){const U=u(G),H=u(K),x=U+(H&1)+(H>>1),j=x,gA=x-H;p.a=j,p.b=gA}function w(G,K){const U=c(G),H=c(K),x=U-(H>>1)&65535,j=H+x-32768&65535;p.a=j,p.b=x}function m(G,K,U,H,x,j,gA){const MA=gA<16384,qA=U>x?x:U;let kA=1,TA,_A;for(;kA<=qA;)kA<<=1;for(kA>>=1,TA=kA,kA>>=1;kA>=1;){_A=0;const $A=_A+j*(x-TA),Ce=j*kA,Fe=j*TA,ne=H*kA,Qe=H*TA;let Ke,Mt,mt,fg;for(;_A<=$A;_A+=Fe){let wt=_A;const et=_A+H*(U-TA);for(;wt<=et;wt+=Qe){const ti=wt+ne,q=wt+Ce,IA=q+ne;MA?(D(G[wt+K],G[q+K]),Ke=p.a,mt=p.b,D(G[ti+K],G[IA+K]),Mt=p.a,fg=p.b,D(Ke,Mt),G[wt+K]=p.a,G[ti+K]=p.b,D(mt,fg),G[q+K]=p.a,G[IA+K]=p.b):(w(G[wt+K],G[q+K]),Ke=p.a,mt=p.b,w(G[ti+K],G[IA+K]),Mt=p.a,fg=p.b,w(Ke,Mt),G[wt+K]=p.a,G[ti+K]=p.b,w(mt,fg),G[q+K]=p.a,G[IA+K]=p.b)}if(U&kA){const ti=wt+Ce;MA?D(G[wt+K],G[ti+K]):w(G[wt+K],G[ti+K]),Ke=p.a,G[ti+K]=p.b,G[wt+K]=Ke}}if(x&kA){let wt=_A;const et=_A+H*(U-TA);for(;wt<=et;wt+=Qe){const ti=wt+ne;MA?D(G[wt+K],G[ti+K]):w(G[wt+K],G[ti+K]),Ke=p.a,G[ti+K]=p.b,G[wt+K]=Ke}}TA=kA,kA>>=1}return _A}function M(G,K,U,H,x,j,gA,MA,qA){let kA=0,TA=0;const _A=gA,$A=Math.trunc(H.value+(x+7)/8);for(;H.value<$A;)for(h(kA,TA,U,H),kA=E.c,TA=E.lc;TA>=14;){const Fe=kA>>TA-14&16383,ne=K[Fe];if(ne.len)TA-=ne.len,d(ne.lit,j,kA,TA,U,H,MA,qA,_A),kA=l.c,TA=l.lc;else{if(!ne.p)throw new Error("hufDecode issues");let Qe;for(Qe=0;Qe<ne.lit;Qe++){const Ke=n(G[ne.p[Qe]]);for(;TA<Ke&&H.value<$A;)h(kA,TA,U,H),kA=E.c,TA=E.lc;if(TA>=Ke&&B(G[ne.p[Qe]])==(kA>>TA-Ke&(1<<Ke)-1)){TA-=Ke,d(ne.p[Qe],j,kA,TA,U,H,MA,qA,_A),kA=l.c,TA=l.lc;break}}if(Qe==ne.lit)throw new Error("hufDecode issues")}}const Ce=8-x&7;for(kA>>=Ce,TA-=Ce;TA>0;){const Fe=K[kA<<14-TA&16383];if(Fe.len)TA-=Fe.len,d(Fe.lit,j,kA,TA,U,H,MA,qA,_A),kA=l.c,TA=l.lc;else throw new Error("hufDecode issues")}return!0}function F(G,K,U,H,x,j){const gA={value:0},MA=U.value,qA=lA(K,U),kA=lA(K,U);U.value+=4;const TA=lA(K,U);if(U.value+=4,qA<0||qA>=65537||kA<0||kA>=65537)throw new Error("Something wrong with HUF_ENCSIZE");const _A=new Array(65537),$A=new Array(16384);g($A);const Ce=H-(U.value-MA);if(a(G,U,Ce,qA,kA,_A),TA>8*(H-(U.value-MA)))throw new Error("Something wrong with hufUncompress");Q(_A,qA,kA,$A),M(_A,$A,G,U,TA,kA,j,x,gA)}function k(G,K,U){for(let H=0;H<U;++H)K[H]=G[K[H]]}function f(G){for(let K=1;K<G.length;K++){const U=G[K-1]+G[K]-128;G[K]=U}}function b(G,K){let U=0,H=Math.floor((G.length+1)/2),x=0;const j=G.length-1;for(;!(x>j||(K[x++]=G[U++],x>j));)K[x++]=G[H++]}function O(G){let K=G.byteLength;const U=new Array;let H=0;const x=new DataView(G);for(;K>0;){const j=x.getInt8(H++);if(j<0){const gA=-j;K-=gA+1;for(let MA=0;MA<gA;MA++)U.push(x.getUint8(H++))}else{const gA=j;K-=2;const MA=x.getUint8(H++);for(let qA=0;qA<gA+1;qA++)U.push(MA)}}return U}function L(G,K,U,H,x,j){let gA=new DataView(j.buffer);const MA=U[G.idx[0]].width,qA=U[G.idx[0]].height,kA=3,TA=Math.floor(MA/8),_A=Math.ceil(MA/8),$A=Math.ceil(qA/8),Ce=MA-(_A-1)*8,Fe=qA-($A-1)*8,ne={value:0},Qe=new Array(kA),Ke=new Array(kA),Mt=new Array(kA),mt=new Array(kA),fg=new Array(kA);for(let et=0;et<kA;++et)fg[et]=K[G.idx[et]],Qe[et]=et<1?0:Qe[et-1]+_A*$A,Ke[et]=new Float32Array(64),Mt[et]=new Uint16Array(64),mt[et]=new Uint16Array(_A*64);for(let et=0;et<$A;++et){let ti=8;et==$A-1&&(ti=Fe);let q=8;for(let aA=0;aA<_A;++aA){aA==_A-1&&(q=Ce);for(let X=0;X<kA;++X)Mt[X].fill(0),Mt[X][0]=x[Qe[X]++],T(ne,H,Mt[X]),W(Mt[X],Ke[X]),iA(Ke[X]);AA(Ke);for(let X=0;X<kA;++X)eA(Ke[X],mt[X],aA*64)}let IA=0;for(let aA=0;aA<kA;++aA){const X=U[G.idx[aA]].type;for(let dA=8*et;dA<8*et+ti;++dA){IA=fg[aA][dA];for(let PA=0;PA<TA;++PA){const Be=PA*64+(dA&7)*8;gA.setUint16(IA+0*2*X,mt[aA][Be+0],!0),gA.setUint16(IA+1*2*X,mt[aA][Be+1],!0),gA.setUint16(IA+2*2*X,mt[aA][Be+2],!0),gA.setUint16(IA+3*2*X,mt[aA][Be+3],!0),gA.setUint16(IA+4*2*X,mt[aA][Be+4],!0),gA.setUint16(IA+5*2*X,mt[aA][Be+5],!0),gA.setUint16(IA+6*2*X,mt[aA][Be+6],!0),gA.setUint16(IA+7*2*X,mt[aA][Be+7],!0),IA+=8*2*X}}if(TA!=_A)for(let dA=8*et;dA<8*et+ti;++dA){const PA=fg[aA][dA]+8*TA*2*X,Be=TA*64+(dA&7)*8;for(let ye=0;ye<q;++ye)gA.setUint16(PA+ye*2*X,mt[aA][Be+ye],!0)}}}const wt=new Uint16Array(MA);gA=new DataView(j.buffer);for(let et=0;et<kA;++et){U[G.idx[et]].decoded=!0;const ti=U[G.idx[et]].type;if(U[et].type==2)for(let q=0;q<qA;++q){const IA=fg[et][q];for(let aA=0;aA<MA;++aA)wt[aA]=gA.getUint16(IA+aA*2*ti,!0);for(let aA=0;aA<MA;++aA)gA.setFloat32(IA+aA*2*ti,pA(wt[aA]),!0)}}}function T(G,K,U){let H,x=1;for(;x<64;)H=K[G.value],H==65280?x=64:H>>8==255?x+=H&255:(U[x]=H,x++),G.value++}function W(G,K){K[0]=pA(G[0]),K[1]=pA(G[1]),K[2]=pA(G[5]),K[3]=pA(G[6]),K[4]=pA(G[14]),K[5]=pA(G[15]),K[6]=pA(G[27]),K[7]=pA(G[28]),K[8]=pA(G[2]),K[9]=pA(G[4]),K[10]=pA(G[7]),K[11]=pA(G[13]),K[12]=pA(G[16]),K[13]=pA(G[26]),K[14]=pA(G[29]),K[15]=pA(G[42]),K[16]=pA(G[3]),K[17]=pA(G[8]),K[18]=pA(G[12]),K[19]=pA(G[17]),K[20]=pA(G[25]),K[21]=pA(G[30]),K[22]=pA(G[41]),K[23]=pA(G[43]),K[24]=pA(G[9]),K[25]=pA(G[11]),K[26]=pA(G[18]),K[27]=pA(G[24]),K[28]=pA(G[31]),K[29]=pA(G[40]),K[30]=pA(G[44]),K[31]=pA(G[53]),K[32]=pA(G[10]),K[33]=pA(G[19]),K[34]=pA(G[23]),K[35]=pA(G[32]),K[36]=pA(G[39]),K[37]=pA(G[45]),K[38]=pA(G[52]),K[39]=pA(G[54]),K[40]=pA(G[20]),K[41]=pA(G[22]),K[42]=pA(G[33]),K[43]=pA(G[38]),K[44]=pA(G[46]),K[45]=pA(G[51]),K[46]=pA(G[55]),K[47]=pA(G[60]),K[48]=pA(G[21]),K[49]=pA(G[34]),K[50]=pA(G[37]),K[51]=pA(G[47]),K[52]=pA(G[50]),K[53]=pA(G[56]),K[54]=pA(G[59]),K[55]=pA(G[61]),K[56]=pA(G[35]),K[57]=pA(G[36]),K[58]=pA(G[48]),K[59]=pA(G[49]),K[60]=pA(G[57]),K[61]=pA(G[58]),K[62]=pA(G[62]),K[63]=pA(G[63])}function iA(G){const K=.5*Math.cos(.7853975),U=.5*Math.cos(3.14159/16),H=.5*Math.cos(3.14159/8),x=.5*Math.cos(3*3.14159/16),j=.5*Math.cos(5*3.14159/16),gA=.5*Math.cos(3*3.14159/8),MA=.5*Math.cos(7*3.14159/16),qA=new Array(4),kA=new Array(4),TA=new Array(4),_A=new Array(4);for(let $A=0;$A<8;++$A){const Ce=$A*8;qA[0]=H*G[Ce+2],qA[1]=gA*G[Ce+2],qA[2]=H*G[Ce+6],qA[3]=gA*G[Ce+6],kA[0]=U*G[Ce+1]+x*G[Ce+3]+j*G[Ce+5]+MA*G[Ce+7],kA[1]=x*G[Ce+1]-MA*G[Ce+3]-U*G[Ce+5]-j*G[Ce+7],kA[2]=j*G[Ce+1]-U*G[Ce+3]+MA*G[Ce+5]+x*G[Ce+7],kA[3]=MA*G[Ce+1]-j*G[Ce+3]+x*G[Ce+5]-U*G[Ce+7],TA[0]=K*(G[Ce+0]+G[Ce+4]),TA[3]=K*(G[Ce+0]-G[Ce+4]),TA[1]=qA[0]+qA[3],TA[2]=qA[1]-qA[2],_A[0]=TA[0]+TA[1],_A[1]=TA[3]+TA[2],_A[2]=TA[3]-TA[2],_A[3]=TA[0]-TA[1],G[Ce+0]=_A[0]+kA[0],G[Ce+1]=_A[1]+kA[1],G[Ce+2]=_A[2]+kA[2],G[Ce+3]=_A[3]+kA[3],G[Ce+4]=_A[3]-kA[3],G[Ce+5]=_A[2]-kA[2],G[Ce+6]=_A[1]-kA[1],G[Ce+7]=_A[0]-kA[0]}for(let $A=0;$A<8;++$A)qA[0]=H*G[16+$A],qA[1]=gA*G[16+$A],qA[2]=H*G[48+$A],qA[3]=gA*G[48+$A],kA[0]=U*G[8+$A]+x*G[24+$A]+j*G[40+$A]+MA*G[56+$A],kA[1]=x*G[8+$A]-MA*G[24+$A]-U*G[40+$A]-j*G[56+$A],kA[2]=j*G[8+$A]-U*G[24+$A]+MA*G[40+$A]+x*G[56+$A],kA[3]=MA*G[8+$A]-j*G[24+$A]+x*G[40+$A]-U*G[56+$A],TA[0]=K*(G[$A]+G[32+$A]),TA[3]=K*(G[$A]-G[32+$A]),TA[1]=qA[0]+qA[3],TA[2]=qA[1]-qA[2],_A[0]=TA[0]+TA[1],_A[1]=TA[3]+TA[2],_A[2]=TA[3]-TA[2],_A[3]=TA[0]-TA[1],G[0+$A]=_A[0]+kA[0],G[8+$A]=_A[1]+kA[1],G[16+$A]=_A[2]+kA[2],G[24+$A]=_A[3]+kA[3],G[32+$A]=_A[3]-kA[3],G[40+$A]=_A[2]-kA[2],G[48+$A]=_A[1]-kA[1],G[56+$A]=_A[0]-kA[0]}function AA(G){for(let K=0;K<64;++K){const U=G[0][K],H=G[1][K],x=G[2][K];G[0][K]=U+1.5747*x,G[1][K]=U-.1873*H-.4682*x,G[2][K]=U+1.8556*H}}function eA(G,K,U){for(let H=0;H<64;++H)K[U+H]=Mr.toHalfFloat(EA(G[H]))}function EA(G){return G<=1?Math.sign(G)*Math.pow(Math.abs(G),2.2):Math.sign(G)*Math.pow(e,Math.abs(G)-1)}function rA(G){return new DataView(G.array.buffer,G.offset.value,G.size)}function V(G){const K=G.viewer.buffer.slice(G.offset.value,G.offset.value+G.size),U=new Uint8Array(O(K)),H=new Uint8Array(U.length);return f(U),b(U,H),new DataView(H.buffer)}function sA(G){const K=G.array.slice(G.offset.value,G.offset.value+G.size),U=dw(K),H=new Uint8Array(U.length);return f(U),b(U,H),new DataView(H.buffer)}function mA(G){const K=G.viewer,U={value:G.offset.value},H=new Uint16Array(G.width*G.scanlineBlockSize*(G.channels*G.type)),x=new Uint8Array(8192);let j=0;const gA=new Array(G.channels);for(let Fe=0;Fe<G.channels;Fe++)gA[Fe]={},gA[Fe].start=j,gA[Fe].end=gA[Fe].start,gA[Fe].nx=G.width,gA[Fe].ny=G.lines,gA[Fe].size=G.type,j+=gA[Fe].nx*gA[Fe].ny*gA[Fe].size;const MA=ZA(K,U),qA=ZA(K,U);if(qA>=8192)throw new Error("Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(MA<=qA)for(let Fe=0;Fe<qA-MA+1;Fe++)x[Fe+MA]=LA(K,U);const kA=new Uint16Array(65536),TA=i(x,kA),_A=lA(K,U);F(G.array,K,U,_A,H,j);for(let Fe=0;Fe<G.channels;++Fe){const ne=gA[Fe];for(let Qe=0;Qe<gA[Fe].size;++Qe)m(H,ne.start+Qe,ne.nx,ne.size,ne.ny,ne.nx*ne.size,TA)}k(kA,H,j);let $A=0;const Ce=new Uint8Array(H.buffer.byteLength);for(let Fe=0;Fe<G.lines;Fe++)for(let ne=0;ne<G.channels;ne++){const Qe=gA[ne],Ke=Qe.nx*Qe.size,Mt=new Uint8Array(H.buffer,Qe.end*2,Ke*2);Ce.set(Mt,$A),$A+=Ke*2,Qe.end+=Ke}return new DataView(Ce.buffer)}function RA(G){const K=G.array.slice(G.offset.value,G.offset.value+G.size),U=dw(K),H=G.lines*G.channels*G.width,x=G.type==1?new Uint16Array(H):new Uint32Array(H);let j=0,gA=0;const MA=new Array(4);for(let qA=0;qA<G.lines;qA++)for(let kA=0;kA<G.channels;kA++){let TA=0;switch(G.type){case 1:MA[0]=j,MA[1]=MA[0]+G.width,j=MA[1]+G.width;for(let _A=0;_A<G.width;++_A){const $A=U[MA[0]++]<<8|U[MA[1]++];TA+=$A,x[gA]=TA,gA++}break;case 2:MA[0]=j,MA[1]=MA[0]+G.width,MA[2]=MA[1]+G.width,j=MA[2]+G.width;for(let _A=0;_A<G.width;++_A){const $A=U[MA[0]++]<<24|U[MA[1]++]<<16|U[MA[2]++]<<8;TA+=$A,x[gA]=TA,gA++}break}}return new DataView(x.buffer)}function bA(G){const K=G.viewer,U={value:G.offset.value},H=new Uint8Array(G.width*G.lines*(G.channels*G.type*2)),x={version:yA(K,U),unknownUncompressedSize:yA(K,U),unknownCompressedSize:yA(K,U),acCompressedSize:yA(K,U),dcCompressedSize:yA(K,U),rleCompressedSize:yA(K,U),rleUncompressedSize:yA(K,U),rleRawSize:yA(K,U),totalAcUncompressedCount:yA(K,U),totalDcUncompressedCount:yA(K,U),acCompression:yA(K,U)};if(x.version<2)throw new Error("EXRLoader.parse: "+zA.compression+" version "+x.version+" is unsupported");const j=new Array;let gA=ZA(K,U)-2;for(;gA>0;){const ne=YA(K.buffer,U),Qe=LA(K,U),Ke=Qe>>2&3,Mt=(Qe>>4)-1,mt=new Int8Array([Mt])[0],fg=LA(K,U);j.push({name:ne,index:mt,type:fg,compression:Ke}),gA-=ne.length+3}const MA=zA.channels,qA=new Array(G.channels);for(let ne=0;ne<G.channels;++ne){const Qe=qA[ne]={},Ke=MA[ne];Qe.name=Ke.name,Qe.compression=0,Qe.decoded=!1,Qe.type=Ke.pixelType,Qe.pLinear=Ke.pLinear,Qe.width=G.width,Qe.height=G.lines}const kA={idx:new Array(3)};for(let ne=0;ne<G.channels;++ne){const Qe=qA[ne];for(let Ke=0;Ke<j.length;++Ke){const Mt=j[Ke];Qe.name==Mt.name&&(Qe.compression=Mt.compression,Mt.index>=0&&(kA.idx[Mt.index]=ne),Qe.offset=ne)}}let TA,_A,$A;if(x.acCompressedSize>0)switch(x.acCompression){case 0:TA=new Uint16Array(x.totalAcUncompressedCount),F(G.array,K,U,x.acCompressedSize,TA,x.totalAcUncompressedCount);break;case 1:const ne=G.array.slice(U.value,U.value+x.totalAcUncompressedCount),Qe=dw(ne);TA=new Uint16Array(Qe.buffer),U.value+=x.totalAcUncompressedCount;break}if(x.dcCompressedSize>0){const ne={array:G.array,offset:U,size:x.dcCompressedSize};_A=new Uint16Array(sA(ne).buffer),U.value+=x.dcCompressedSize}if(x.rleRawSize>0){const ne=G.array.slice(U.value,U.value+x.rleCompressedSize),Qe=dw(ne);$A=O(Qe.buffer),U.value+=x.rleCompressedSize}let Ce=0;const Fe=new Array(qA.length);for(let ne=0;ne<Fe.length;++ne)Fe[ne]=new Array;for(let ne=0;ne<G.lines;++ne)for(let Qe=0;Qe<qA.length;++Qe)Fe[Qe].push(Ce),Ce+=qA[Qe].width*G.type*2;L(kA,Fe,qA,TA,_A,H);for(let ne=0;ne<qA.length;++ne){const Qe=qA[ne];if(!Qe.decoded)switch(Qe.compression){case 2:let Ke=0,Mt=0;for(let mt=0;mt<G.lines;++mt){let fg=Fe[ne][Ke];for(let wt=0;wt<Qe.width;++wt){for(let et=0;et<2*Qe.type;++et)H[fg++]=$A[Mt+et*Qe.width*Qe.height];Mt++}Ke++}break;case 1:default:throw new Error("EXRLoader.parse: unsupported channel compression")}}return new DataView(H.buffer)}function YA(G,K){const U=new Uint8Array(G);let H=0;for(;U[K.value+H]!=0;)H+=1;const x=new TextDecoder().decode(U.slice(K.value,K.value+H));return K.value=K.value+H+1,x}function ee(G,K,U){const H=new TextDecoder().decode(new Uint8Array(G).slice(K.value,K.value+U));return K.value=K.value+U,H}function XA(G,K){const U=we(G,K),H=lA(G,K);return[U,H]}function VA(G,K){const U=lA(G,K),H=lA(G,K);return[U,H]}function we(G,K){const U=G.getInt32(K.value,!0);return K.value=K.value+4,U}function lA(G,K){const U=G.getUint32(K.value,!0);return K.value=K.value+4,U}function _(G,K){const U=G[K.value];return K.value=K.value+1,U}function LA(G,K){const U=G.getUint8(K.value);return K.value=K.value+1,U}const yA=function(G,K){let U;return"getBigInt64"in DataView.prototype?U=Number(G.getBigInt64(K.value,!0)):U=G.getUint32(K.value+4,!0)+Number(G.getUint32(K.value,!0)<<32),K.value+=8,U};function uA(G,K){const U=G.getFloat32(K.value,!0);return K.value+=4,U}function HA(G,K){return Mr.toHalfFloat(uA(G,K))}function pA(G){const K=(G&31744)>>10,U=G&1023;return(G>>15?-1:1)*(K?K===31?U?NaN:1/0:Math.pow(2,K-15)*(1+U/1024):6103515625e-14*(U/1024))}function ZA(G,K){const U=G.getUint16(K.value,!0);return K.value+=2,U}function ge(G,K){return pA(ZA(G,K))}function re(G,K,U,H){const x=U.value,j=[];for(;U.value<x+H-1;){const gA=YA(K,U),MA=we(G,U),qA=LA(G,U);U.value+=3;const kA=we(G,U),TA=we(G,U);j.push({name:gA,pixelType:MA,pLinear:qA,xSampling:kA,ySampling:TA})}return U.value+=1,j}function Ve(G,K){const U=uA(G,K),H=uA(G,K),x=uA(G,K),j=uA(G,K),gA=uA(G,K),MA=uA(G,K),qA=uA(G,K),kA=uA(G,K);return{redX:U,redY:H,greenX:x,greenY:j,blueX:gA,blueY:MA,whiteX:qA,whiteY:kA}}function It(G,K){const U=["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"],H=LA(G,K);return U[H]}function v(G,K){const U=lA(G,K),H=lA(G,K),x=lA(G,K),j=lA(G,K);return{xMin:U,yMin:H,xMax:x,yMax:j}}function J(G,K){const U=["INCREASING_Y"],H=LA(G,K);return U[H]}function QA(G,K){const U=uA(G,K),H=uA(G,K);return[U,H]}function NA(G,K){const U=uA(G,K),H=uA(G,K),x=uA(G,K);return[U,H,x]}function KA(G,K,U,H,x){if(H==="string"||H==="stringvector"||H==="iccProfile")return ee(K,U,x);if(H==="chlist")return re(G,K,U,x);if(H==="chromaticities")return Ve(G,U);if(H==="compression")return It(G,U);if(H==="box2i")return v(G,U);if(H==="lineOrder")return J(G,U);if(H==="float")return uA(G,U);if(H==="v2f")return QA(G,U);if(H==="v3f")return NA(G,U);if(H==="int")return we(G,U);if(H==="rational")return XA(G,U);if(H==="timecode")return VA(G,U);if(H==="preview")return U.value+=x,"skipped";U.value+=x}function Y(G,K,U){const H={};if(G.getUint32(0,!0)!=20000630)throw new Error("THREE.EXRLoader: provided file doesn't appear to be in OpenEXR format.");H.version=G.getUint8(4);const x=G.getUint8(5);H.spec={singleTile:!!(x&2),longName:!!(x&4),deepFormat:!!(x&8),multiPart:!!(x&16)},U.value=8;let j=!0;for(;j;){const gA=YA(K,U);if(gA==0)j=!1;else{const MA=YA(K,U),qA=lA(G,U),kA=KA(G,K,U,MA,qA);kA===void 0?console.warn(`EXRLoader.parse: skipped unknown header attribute type '${MA}'.`):H[gA]=kA}}if(x&-5)throw console.error("EXRHeader:",H),new Error("THREE.EXRLoader: provided file is currently unsupported.");return H}function DA(G,K,U,H,x){const j={size:0,viewer:K,array:U,offset:H,width:G.dataWindow.xMax-G.dataWindow.xMin+1,height:G.dataWindow.yMax-G.dataWindow.yMin+1,channels:G.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:G.channels[0].pixelType,uncompress:null,getter:null,format:null,colorSpace:zi};switch(G.compression){case"NO_COMPRESSION":j.lines=1,j.uncompress=rA;break;case"RLE_COMPRESSION":j.lines=1,j.uncompress=V;break;case"ZIPS_COMPRESSION":j.lines=1,j.uncompress=sA;break;case"ZIP_COMPRESSION":j.lines=16,j.uncompress=sA;break;case"PIZ_COMPRESSION":j.lines=32,j.uncompress=mA;break;case"PXR24_COMPRESSION":j.lines=16,j.uncompress=RA;break;case"DWAA_COMPRESSION":j.lines=32,j.uncompress=bA;break;case"DWAB_COMPRESSION":j.lines=256,j.uncompress=bA;break;default:throw new Error("EXRLoader.parse: "+G.compression+" is unsupported")}if(j.scanlineBlockSize=j.lines,j.type==1)switch(x){case zt:j.getter=ge,j.inputSize=2;break;case ci:j.getter=ZA,j.inputSize=2;break}else if(j.type==2)switch(x){case zt:j.getter=uA,j.inputSize=4;break;case ci:j.getter=HA,j.inputSize=4}else throw new Error("EXRLoader.parse: unsupported pixelType "+j.type+" for "+G.compression+".");j.blockCount=(G.dataWindow.yMax+1)/j.scanlineBlockSize;for(let MA=0;MA<j.blockCount;MA++)yA(K,H);j.outputChannels=j.channels==3?4:j.channels;const gA=j.width*j.height*j.outputChannels;switch(x){case zt:j.byteArray=new Float32Array(gA),j.channels<j.outputChannels&&j.byteArray.fill(1,0,gA);break;case ci:j.byteArray=new Uint16Array(gA),j.channels<j.outputChannels&&j.byteArray.fill(15360,0,gA);break;default:console.error("THREE.EXRLoader: unsupported type: ",x);break}return j.bytesPerLine=j.width*j.inputSize*j.channels,j.outputChannels==4?(j.format=Ft,j.colorSpace=zi):(j.format=mC,j.colorSpace=cI),j}const GA=new DataView(A),hA=new Uint8Array(A),jA={value:0},zA=Y(GA,A,jA),SA=DA(zA,GA,hA,jA,this.type),ie={value:0},Ae={R:0,G:1,B:2,A:3,Y:0};for(let G=0;G<SA.height/SA.scanlineBlockSize;G++){const K=lA(GA,jA);SA.size=lA(GA,jA),SA.lines=K+SA.scanlineBlockSize>SA.height?SA.height-K:SA.scanlineBlockSize;const U=SA.size<SA.lines*SA.bytesPerLine?SA.uncompress(SA):rA(SA);jA.value+=SA.size;for(let H=0;H<SA.scanlineBlockSize;H++){const x=H+G*SA.scanlineBlockSize;if(x>=SA.height)break;for(let j=0;j<SA.channels;j++){const gA=Ae[zA.channels[j].name];for(let MA=0;MA<SA.width;MA++){ie.value=(H*(SA.channels*SA.width)+j*SA.width+MA)*SA.inputSize;const qA=(SA.height-1-x)*(SA.width*SA.outputChannels)+MA*SA.outputChannels+gA;SA.byteArray[qA]=SA.getter(U,ie)}}}}return{header:zA,width:SA.width,height:SA.height,data:SA.byteArray,format:SA.format,colorSpace:SA.colorSpace,type:this.type}}setDataType(A){return this.type=A,this}load(A,e,i,g){function I(o,s){o.colorSpace=s.colorSpace,o.minFilter=Re,o.magFilter=Re,o.generateMipmaps=!1,o.flipY=!1,e&&e(o,s)}return super.load(A,I,i,g)}}const pM=oA("debugexr");class Q7{constructor(A){r(this,"parser"),r(this,"name"),this.parser=A,this.name="EXT_texture_exr",pM&&console.log(A)}loadTexture(A){const e=this.name,i=this.parser,g=i.json.textures[A];if(pM&&console.log("EXT_texture_exr.loadTexture",A,g),!g.extensions||!g.extensions[e])return null;const I=g.extensions[e],o=new dM(i.options.manager);return pM&&console.log("EXT_texture_exr.loadTexture",I,o),i.loadTextureImage(A,I.source,o)}}window.addEventListener("unhandledrejection",t=>{});const WT="NEEDLE_gameobject_data";class E7{constructor(A){r(this,"parser"),this.parser=A}get name(){return WT}afterRoot(A){const e=[];for(let i=0;i<this.parser.json.nodes.length;i++){const g=this.parser.json.nodes[i];if(g&&g.extensions){const I=g.extensions[WT];if(I){const o=this.findAndApplyExtensionData(i,I);e.push(o)}}}return Promise.all(e).then(()=>{})}async findAndApplyExtensionData(A,e){const i=await this.parser.getDependency("node",A);i&&this.applyExtensionData(i,e)}applyExtensionData(A,e){e.layers===void 0&&(e.layers=0),A.userData.layer=e.layers,A.layers.disableAll(),A.layers.set(e.layers),A.userData.tag=e.tag??"none",A.userData.hideFlags=e.hideFlags??0,A.userData.static=e.static??!1,A.visible=e.activeSelf??!0,A.guid=e.guid}}const VT="NEEDLE_lighting_settings",iB=oA("debugenvlight");class h7{constructor(A,e,i){r(this,"parser"),r(this,"sourceId"),r(this,"context"),this.parser=A,this.sourceId=e,this.context=i}get name(){return VT}afterRoot(A){const e=this.parser.json.extensions;if(e){const i=e[VT];if(i){iB&&console.log('Loaded "'+this.name+'", src: "'+this.sourceId+'"',i);let g;if(A.scene.children.length===1){const I=A.scene.children[0];g=tA.addNewComponent(I,uw,!1)}else{const I=new vA;I.name="LightSettings "+this.sourceId,A.scene.add(I),g=tA.addNewComponent(I,uw,!1)}g.sourceId=this.sourceId,g.ambientIntensity=i.ambientIntensity,g.ambientLight=new wA().fromArray(i.ambientLight),Array.isArray(i.ambientTrilight)&&(g.ambientTrilight=i.ambientTrilight.map(I=>new wA().fromArray(I))),g.ambientMode=i.ambientMode,g.environmentReflectionSource=i.environmentReflectionSource}}return null}}Rt.registerCallback(mg.ContextCreated,t=>{const A=t.context,e=tA.findObjectOfType(uw,A);e!=null&&e.sourceId&&(e.enabled=!0)});class uw extends UA{constructor(){super(...arguments),r(this,"ambientMode",AE.Skybox),r(this,"ambientLight"),r(this,"ambientTrilight"),r(this,"ambientIntensity",1),r(this,"environmentReflectionSource",rw.Skybox),r(this,"_hasReflection",!1),r(this,"_ambientLightObj"),r(this,"_hemisphereLightObj"),r(this,"_lightProbeObj")}awake(){var A;if(this.sourceId){const i=this.environmentReflectionSource===rw.Skybox?cn.Skybox:cn.Reflection,g=this.context.lightmaps.tryGet(this.sourceId,i,0);this._hasReflection=g!=null,g&&this.context.sceneLighting.internalRegisterReflection(this.sourceId,g)}this.enabled=!1,this.context.sceneLighting.internalRegisterSceneLightSettings(this),iB&&window.addEventListener("keydown",i=>{if(!this.destroyed)switch(i.key){case"l":this.enabled=!this.enabled;break}});const e=(A=this.gameObject.userData)==null?void 0:A.components;if(e){const i=e.indexOf(this);e.splice(i,1),e.push(this)}}onDestroy(){this.context.sceneLighting.internalUnregisterSceneLightSettings(this)}calculateIntensityFactor(A){const e=Math.max(A.r,A.g,A.b);return 2.2*te.lerp(0,1.33,e)}onEnable(){if(iB&&console.warn("\u{1F4A1}\u{1F7E1} >>> Enable lighting",this.sourceId,this.enabled,this),this.ambientMode==AE.Flat){if(this.ambientLight&&!this._ambientLightObj){const A=this.calculateIntensityFactor(this.ambientLight);this._ambientLightObj=new pk(this.ambientLight,this.ambientIntensity*A),iB&&console.log("Created ambient light",this.sourceId,this._ambientLightObj,this.ambientIntensity,A)}this._ambientLightObj&&this.gameObject.add(this._ambientLightObj),this._lightProbeObj&&this._lightProbeObj.removeFromParent()}else if(this.ambientMode===AE.Trilight){if(this.ambientTrilight){const A=this.ambientTrilight[0],e=this.ambientTrilight[this.ambientTrilight.length-1],i=this.calculateIntensityFactor(e);this._hemisphereLightObj=new hk(e,A,this.ambientIntensity*i),this.gameObject.add(this._hemisphereLightObj),iB&&console.log("Created hemisphere ambient light",this.sourceId,this._hemisphereLightObj,this.ambientIntensity,i)}}else this._ambientLightObj&&this._ambientLightObj.removeFromParent(),this._hemisphereLightObj&&this._hemisphereLightObj.removeFromParent(),this._lightProbeObj?this.enabled&&this.destroyed&&this._lightProbeObj&&this.gameObject.add(this._lightProbeObj):this.sourceId&&this.context.sceneLighting.internalGetSceneLightingData(this.sourceId).then(A=>{A&&(this._lightProbeObj=A.lightProbe,this.enabled&&!this.destroyed&&this._lightProbeObj&&(iB&&console.log("Add",this.sourceId,A),this.gameObject.add(this._lightProbeObj)))});this.sourceId&&this.context.sceneLighting.internalEnableReflection(this.sourceId)}onDisable(){iB&&console.warn("\u{1F4A1}\u26AB <<< Disable lighting:",this.sourceId,this),this._lightProbeObj&&this._lightProbeObj.removeFromParent(),this._ambientLightObj&&this._ambientLightObj.removeFromParent(),this._hemisphereLightObj&&this._hemisphereLightObj.removeFromParent(),this.sourceId&&this.context.sceneLighting.internalDisableReflection(this.sourceId)}}const uM=oA("debugstencil");function c7(t,A){return(t&1<<A.layer)!=0}const l7=Symbol("stencils"),nE=class{constructor(t,A){r(this,"parser"),r(this,"source"),this.parser=t,this.source=A}static applyStencil(t){if(!t)return;const A=t.sourceId;if(uM&&console.log(A,nE.stencils),!A)return;const e=nE.stencils[A];if(e)for(let i=e.length-1;i>=0;i--){const g=e[i];if(c7(g.layer,t)){uM&&console.log(g),setTimeout(()=>{Yg()&&XD(t.gameObject)&&(Do("Stencil not supported on instanced objects"),console.warn("Stencil not supported on instanced objects",t))},500);for(let I=0;I<t.sharedMaterials.length;I++){let o=t.sharedMaterials[I];o&&(o=o.clone(),o[l7]=!0,o.stencilWrite=!0,o.stencilWriteMask=255,o.stencilFuncMask=255,o.stencilRef=g.value,o.stencilFunc=g.compareFunc,o.stencilZPass=g.passOp,o.stencilFail=g.failOp,o.stencilZFail=g.zFailOp,t.sharedMaterials[I]=o)}t.gameObject.renderOrder=g.event*1e3+g.index*50;break}}}afterRoot(t){const A=this.parser.json.extensions;if(A){const e=A[p7];if(e){uM&&console.log(e);const i=e.stencil;if(i&&Array.isArray(i))for(const g of i){const I={...g};I.compareFunc=d7(I.compareFunc),I.passOp=wM(I.passOp),I.failOp=wM(I.failOp),I.zFailOp=wM(I.zFailOp),nE.stencils[this.source]||(nE.stencils[this.source]=[]),nE.stencils[this.source].push(I)}}}return null}};let DM=nE;r(DM,"stencils",{});function wM(t){switch(t){case 0:return ec;case 1:return vK;case 2:return bK;case 3:return LK;case 4:return xK;case 6:return TK;case 7:return YK;case 5:return HK}return 0}function d7(t){switch(t){case 1:return Im;case 2:return OK;case 3:return _K;case 4:return PK;case 5:return jK;case 6:return WK;case 7:return VK;case 8:return om}return Im}const p7="NEEDLE_render_objects",Dw="NEEDLE_progressive",Yi=oA("debugprogressive"),yM=Symbol("needle-progressive-texture"),SM=new Map;let fM=!1;Yi&&window.addEventListener("keyup",t=>{t.key==="p"&&(SM.forEach((A,e)=>{Object.entries(A).forEach(([i,g])=>{fM?e[i]=g.lod0:e[i]=g.original,e.needsUpdate=!0})}),fM=!fM)});const ww=class{constructor(t,A,e){r(this,"parser"),r(this,"sourceId"),r(this,"context"),this.parser=t,this.sourceId=A,this.context=e}static assignTextureLOD(t,A,e,i=0){if(!e)return Promise.resolve(null);const g=[];for(let I of Object.keys(e)){const o=e[I];if(o!=null&&o.isTexture){const s=this.assignTextureLODForSlot(t,A,e,i,I,o);g.push(s)}}if(e instanceof Pu)for(let I of Object.keys(e.uniforms)){const o=e.uniforms[I].value;if(o!=null&&o.isTexture){const s=this.assignTextureLODForSlot(t,A,e,i,I,o);g.push(s)}}return g}static assignTextureLODForSlot(t,A,e,i,g,I){return I?.isTexture!==!0?Promise.resolve(null):(Yi&&console.log(`-----------
|
|
4410
4410
|
`,"FIND",e.name,g,I?.name,I?.userData,I,e),ww.getOrLoadTexture(t,A,e,g,I,i).then(o=>{if(o?.isTexture===!0){if(Yi&&console.log("Assign LOD",e.name,g,o.name,o.guid,e,"Prev:",I,"Now:",o,`
|
|
4411
|
-
--------------`),e[g]=o,o.needsUpdate=!0,e.needsUpdate=!0,Yi){let s=SM.get(e);s||(s={},SM.set(e,s));let C=s[g];C||(C=s[g]={original:I,lod0:o}),C.lod0=o}return o}return null}))}get name(){return Dw}afterRoot(t){var A;return Yi&&console.log("AFTER",this.sourceId,t),(A=this.parser.json.textures)==null||A.forEach((e,i)=>{if(e!=null&&e.extensions){const g=e?.extensions[Dw];g&&this.parser.getDependency("texture",i).then(I=>{Yi&&console.log("> Progressive: register",I.name,I.uuid,g),I.source&&(I.source[yM]=g),ww.cache.set(I.uuid,g)})}}),null}static async getOrLoadTexture(t,A,e,i,g,I){const o=g.uuid;let s;if(g.source&&g.source[yM]&&(s=g.source[yM]),s||(s=ww.cache.get(o)),s){Yi&&console.log(o,s.uri,s.guid);const C=Ya(A,s.uri);if(C.endsWith(".glb")||C.endsWith(".gltf")){if(!s.guid)return console.warn("missing pointer for glb/gltf texture",s),null;const a=C+"_"+s.guid;if(this.resolved[a]){let B=this.resolved[a];if(B.image&&B.image.data)return Yi&&console.log("Texture has already been loaded: "+a,e.name,i,g.name,B),B=this.copySettings(g,B),B;B&&Yi&&console.log("Texture has been disposed, will load again: "+a,e.name,i,g.name,B)}const n=this.onProgressiveLoadStart(t,A,C,e,i);try{if(this.currentlyLoading[a]!==void 0){Yi&&console.log("Already loading:",e.name+"."+i,a);let E=await this.currentlyLoading[a];return E&&(E=this.copySettings(g,E)),E}const B=s,Q=new Promise(async(E,h)=>{var l;const d=new oE;al(d,t),Yi&&console.log("Load "+C,e.name,i,B.guid),Yi&&await Hh(Math.random()*1e3);const c=await d.loadAsync(C),u=c.parser;Yi&&console.log("Loading finished "+C,e.name,i,B.guid);let p=-1,D=!1;if(!((l=c.parser.json)!=null&&l.textures))return Yi&&console.warn("No textures in glTF "+C+" - may be a bug",e.name,i,B.guid),E(null);for(const m of c.parser.json.textures)if(p++,m!=null&&m.extensions){const M=m?.extensions[Dw];if(M!=null&&M.guid&&M.guid===B.guid){D=!0;break}}if(!D)return E(null);let w=await u.getDependency("texture",p);w=this.copySettings(g,w),w&&(w.guid=B.guid),this.resolved[a]=w,Yi&&console.log(e.name,i,'change "'+g.name+'" \u2192 "'+w.name+'"',C,p,w,e,a),E(w)});return this.currentlyLoading[a]=Q,await Q}finally{delete this.currentlyLoading[a],this.onProgressiveLoadEnd(n)}}else{const a=this.onProgressiveLoadStart(t,A,C,e,i);try{Yi&&console.log("Load texture from uri: "+C);const n=await new sn().loadAsync(C);return n?(n.guid=s.guid,n.flipY=!1,n.needsUpdate=!0,n.encoding=g.encoding,Yi&&console.log(s,n)):Yi&&console.warn("failed loading",C),n}finally{this.onProgressiveLoadEnd(a)}}}else Yi&&console.warn("unknown texture",g.name,g.uuid,g);return null}static copySettings(t,A){const e=t.clone(),i=A.source,g=A.mipmaps;return e.copy(t),e.source=i,e.mipmaps=g,e}static beginListenStart(t,A){this._progressiveEventListeners.has(t)||this._progressiveEventListeners.set(t,new ZT),this._progressiveEventListeners.get(t).start.push(A)}static stopListenStart(t,A){if(!this._progressiveEventListeners.has(t))return;const e=this._progressiveEventListeners.get(t).start,i=e.indexOf(A);i>=0&&e.splice(i,1)}static beginListenEnd(t,A){this._progressiveEventListeners.has(t)||this._progressiveEventListeners.set(t,new ZT),this._progressiveEventListeners.get(t).end.push(A)}static stopListenEnd(t,A){if(!this._progressiveEventListeners.has(t))return;const e=this._progressiveEventListeners.get(t).end,i=e.indexOf(A);i>=0&&e.splice(i,1)}static onProgressiveLoadStart(t,A,e,i,g){this._currentProgressiveLoadingInfo.has(t)||this._currentProgressiveLoadingInfo.set(t,[]);const I=new zT(t,A,e,i,g),o=this._currentProgressiveLoadingInfo.get(t),s=this._progressiveEventListeners.get(t);return s&&s.onStart(I),o.push(I),I}static onProgressiveLoadEnd(t){if(!t)return;const A=t.context;if(!this._currentProgressiveLoadingInfo.has(A))return;const e=this._currentProgressiveLoadingInfo.get(A),i=e.indexOf(t);if(i<0)return;e.splice(i,1);const g=this._progressiveEventListeners.get(A);g&&g.onEnd(t)}};let Cs=ww;r(Cs,"cache",new Map),r(Cs,"resolved",{}),r(Cs,"currentlyLoading",{}),r(Cs,"_progressiveEventListeners",new Map),r(Cs,"_currentProgressiveLoadingInfo",new Map);class zT{constructor(A,e,i,g,I){r(this,"context"),r(this,"source"),r(this,"uri"),r(this,"material"),r(this,"slot"),this.context=A,this.source=e,this.uri=i,this.material=g,this.slot=I}}class ZT{constructor(){r(this,"start",[]),r(this,"end",[])}onStart(A){for(const e of this.start)e(A)}onEnd(A){for(const e of this.end)e(A)}}let yw;Promise.resolve().then(()=>_rA).then(t=>(yw=t.GLTFAnimationPointerExtension,yw)).catch(t=>{console.warn("Failed to import GLTFLoaderAnimationPointer. Please use @needle-tools/three for full KHR_animation support",t)});const El=new Array;function u7(t){El.includes(t)||El.push(t)}function D7(t){const A=El.indexOf(t);A>=0&&El.splice(A,1)}function mM(t){const A=new JT;return t.register(e=>(A.parser=e,A)),A}class w7{resolvePath(A){return A.includes("/extensions/builtin_components/")?A.replace("/extensions/builtin_components/","/userData/components/"):A.includes("extensions/builtin_components/")?A.replace("extensions/builtin_components/","/userData/components/"):A}}function XT(t,A,e){const i=e.lastIndexOf("?");i>=0&&(e=e.substring(0,i)),t.register(g=>new E7(g)),t.register(g=>new dz(g)),t.register(g=>new U9(g,A.lightmaps,e)),t.register(g=>new h7(g,e,A)),t.register(g=>new P6(g,e)),t.register(g=>new DM(g,e)),t.register(g=>new Cs(g,e,A)),t.register(g=>new Q7(g)),jL()&&t.register(g=>new OL(g));for(const g of El)t.register(I=>new g(I));t.register(g=>{if(yw){const I=new yw(g);return I.setAnimationPointerResolver.bind(I)(new w7),I}})}const kM=oA("debuglightmaps");class hl{constructor(A,e){r(this,"lightmapIndex",-1),r(this,"lightmapScaleOffset",new ce(1,1,0,0)),r(this,"context"),r(this,"gameObject"),r(this,"lightmapTexture",null),r(this,"lightmapScaleOffsetUniform",{value:new ce(1,1,0,0)}),r(this,"lightmapUniform",{value:null}),r(this,"onBeforeCompile",(i,g)=>{kM&&console.log("Lightmaps, before compile"),i.lightMapUv="uv1",this.lightmapScaleOffsetUniform.value=this.lightmapScaleOffset,this.lightmapUniform.value=this.lightmapTexture,i.uniforms.
|
|
4411
|
+
--------------`),e[g]=o,o.needsUpdate=!0,e.needsUpdate=!0,Yi){let s=SM.get(e);s||(s={},SM.set(e,s));let C=s[g];C||(C=s[g]={original:I,lod0:o}),C.lod0=o}return o}return null}))}get name(){return Dw}afterRoot(t){var A;return Yi&&console.log("AFTER",this.sourceId,t),(A=this.parser.json.textures)==null||A.forEach((e,i)=>{if(e!=null&&e.extensions){const g=e?.extensions[Dw];g&&this.parser.getDependency("texture",i).then(I=>{Yi&&console.log("> Progressive: register",I.name,I.uuid,g),I.source&&(I.source[yM]=g),ww.cache.set(I.uuid,g)})}}),null}static async getOrLoadTexture(t,A,e,i,g,I){const o=g.uuid;let s;if(g.source&&g.source[yM]&&(s=g.source[yM]),s||(s=ww.cache.get(o)),s){Yi&&console.log(o,s.uri,s.guid);const C=Ya(A,s.uri);if(C.endsWith(".glb")||C.endsWith(".gltf")){if(!s.guid)return console.warn("missing pointer for glb/gltf texture",s),null;const a=C+"_"+s.guid;if(this.resolved[a]){let B=this.resolved[a];if(B.image&&B.image.data)return Yi&&console.log("Texture has already been loaded: "+a,e.name,i,g.name,B),B=this.copySettings(g,B),B;B&&Yi&&console.log("Texture has been disposed, will load again: "+a,e.name,i,g.name,B)}const n=this.onProgressiveLoadStart(t,A,C,e,i);try{if(this.currentlyLoading[a]!==void 0){Yi&&console.log("Already loading:",e.name+"."+i,a);let E=await this.currentlyLoading[a];return E&&(E=this.copySettings(g,E)),E}const B=s,Q=new Promise(async(E,h)=>{var l;const d=new oE;al(d,t),Yi&&console.log("Load "+C,e.name,i,B.guid),Yi&&await Hh(Math.random()*1e3);const c=await d.loadAsync(C),u=c.parser;Yi&&console.log("Loading finished "+C,e.name,i,B.guid);let p=-1,D=!1;if(!((l=c.parser.json)!=null&&l.textures))return Yi&&console.warn("No textures in glTF "+C+" - may be a bug",e.name,i,B.guid),E(null);for(const m of c.parser.json.textures)if(p++,m!=null&&m.extensions){const M=m?.extensions[Dw];if(M!=null&&M.guid&&M.guid===B.guid){D=!0;break}}if(!D)return E(null);let w=await u.getDependency("texture",p);w=this.copySettings(g,w),w&&(w.guid=B.guid),this.resolved[a]=w,Yi&&console.log(e.name,i,'change "'+g.name+'" \u2192 "'+w.name+'"',C,p,w,e,a),E(w)});return this.currentlyLoading[a]=Q,await Q}finally{delete this.currentlyLoading[a],this.onProgressiveLoadEnd(n)}}else{const a=this.onProgressiveLoadStart(t,A,C,e,i);try{Yi&&console.log("Load texture from uri: "+C);const n=await new sn().loadAsync(C);return n?(n.guid=s.guid,n.flipY=!1,n.needsUpdate=!0,n.encoding=g.encoding,Yi&&console.log(s,n)):Yi&&console.warn("failed loading",C),n}finally{this.onProgressiveLoadEnd(a)}}}else Yi&&console.warn("unknown texture",g.name,g.uuid,g);return null}static copySettings(t,A){const e=t.clone(),i=A.source,g=A.mipmaps;return e.copy(t),e.source=i,e.mipmaps=g,e}static beginListenStart(t,A){this._progressiveEventListeners.has(t)||this._progressiveEventListeners.set(t,new ZT),this._progressiveEventListeners.get(t).start.push(A)}static stopListenStart(t,A){if(!this._progressiveEventListeners.has(t))return;const e=this._progressiveEventListeners.get(t).start,i=e.indexOf(A);i>=0&&e.splice(i,1)}static beginListenEnd(t,A){this._progressiveEventListeners.has(t)||this._progressiveEventListeners.set(t,new ZT),this._progressiveEventListeners.get(t).end.push(A)}static stopListenEnd(t,A){if(!this._progressiveEventListeners.has(t))return;const e=this._progressiveEventListeners.get(t).end,i=e.indexOf(A);i>=0&&e.splice(i,1)}static onProgressiveLoadStart(t,A,e,i,g){this._currentProgressiveLoadingInfo.has(t)||this._currentProgressiveLoadingInfo.set(t,[]);const I=new zT(t,A,e,i,g),o=this._currentProgressiveLoadingInfo.get(t),s=this._progressiveEventListeners.get(t);return s&&s.onStart(I),o.push(I),I}static onProgressiveLoadEnd(t){if(!t)return;const A=t.context;if(!this._currentProgressiveLoadingInfo.has(A))return;const e=this._currentProgressiveLoadingInfo.get(A),i=e.indexOf(t);if(i<0)return;e.splice(i,1);const g=this._progressiveEventListeners.get(A);g&&g.onEnd(t)}};let Cs=ww;r(Cs,"cache",new Map),r(Cs,"resolved",{}),r(Cs,"currentlyLoading",{}),r(Cs,"_progressiveEventListeners",new Map),r(Cs,"_currentProgressiveLoadingInfo",new Map);class zT{constructor(A,e,i,g,I){r(this,"context"),r(this,"source"),r(this,"uri"),r(this,"material"),r(this,"slot"),this.context=A,this.source=e,this.uri=i,this.material=g,this.slot=I}}class ZT{constructor(){r(this,"start",[]),r(this,"end",[])}onStart(A){for(const e of this.start)e(A)}onEnd(A){for(const e of this.end)e(A)}}let yw;Promise.resolve().then(()=>_rA).then(t=>(yw=t.GLTFAnimationPointerExtension,yw)).catch(t=>{console.warn("Failed to import GLTFLoaderAnimationPointer. Please use @needle-tools/three for full KHR_animation support",t)});const El=new Array;function u7(t){El.includes(t)||El.push(t)}function D7(t){const A=El.indexOf(t);A>=0&&El.splice(A,1)}function mM(t){const A=new JT;return t.register(e=>(A.parser=e,A)),A}class w7{resolvePath(A){return A.includes("/extensions/builtin_components/")?A.replace("/extensions/builtin_components/","/userData/components/"):A.includes("extensions/builtin_components/")?A.replace("extensions/builtin_components/","/userData/components/"):A}}function XT(t,A,e){const i=e.lastIndexOf("?");i>=0&&(e=e.substring(0,i)),t.register(g=>new E7(g)),t.register(g=>new dz(g)),t.register(g=>new U9(g,A.lightmaps,e)),t.register(g=>new h7(g,e,A)),t.register(g=>new P6(g,e)),t.register(g=>new DM(g,e)),t.register(g=>new Cs(g,e,A)),t.register(g=>new Q7(g)),jL()&&t.register(g=>new OL(g));for(const g of El)t.register(I=>new g(I));t.register(g=>{if(yw){const I=new yw(g);return I.setAnimationPointerResolver.bind(I)(new w7),I}})}const kM=oA("debuglightmaps");class hl{constructor(A,e){r(this,"lightmapIndex",-1),r(this,"lightmapScaleOffset",new ce(1,1,0,0)),r(this,"context"),r(this,"gameObject"),r(this,"lightmapTexture",null),r(this,"lightmapScaleOffsetUniform",{value:new ce(1,1,0,0)}),r(this,"lightmapUniform",{value:null}),r(this,"onBeforeCompile",(i,g)=>{kM&&console.log("Lightmaps, before compile",i),i.lightMapUv="uv1",this.lightmapScaleOffsetUniform.value=this.lightmapScaleOffset,this.lightmapUniform.value=this.lightmapTexture,i.uniforms.lightmapScaleOffset=this.lightmapScaleOffsetUniform}),this.gameObject=A,this.context=e}get lightmap(){return this.lightmapTexture}set lightmap(A){A!==this.lightmapTexture&&(this.lightmapTexture=A,this.applyLightmap())}init(A,e,i){console.assert(this.gameObject!==void 0&&this.gameObject!==null,"Missing gameobject",this),this.lightmapIndex=A,!(this.lightmapIndex<0)&&(this.lightmapScaleOffset=e,this.lightmapTexture=i,kM&&this.setLightmapDebugMaterial(),this.applyLightmap())}updateLightmapUniforms(A){const e=A.uniforms;e&&e.lightmap&&(this.lightmapScaleOffsetUniform.value=this.lightmapScaleOffset,e.lightmapScaleOffset=this.lightmapScaleOffsetUniform)}applyLightmap(){if(this.gameObject.type==="Object3D"){kM&&console.warn("Can not add lightmap. Is this object missing a renderer?",this.gameObject.name);return}if(this.gameObject.type==="Group"){console.warn("Lightmap on multimaterial object is not supported yet... please open a feature request on https://github.com/needle-tools/needle-engine-support if your project requires it");return}console.assert(this.gameObject.type==="Mesh","Lightmap only works on meshes",this);const A=this.gameObject;if(A.geometry.getAttribute("uv1")||A.geometry.setAttribute("uv1",A.geometry.getAttribute("uv")),Array.isArray(this.gameObject.material)){const e=this.gameObject.material;for(let i=0;i<e.length;i++){const g=e[i].clone();e[i]=g,g.onBeforeCompile=this.onBeforeCompile}}else{const e=this.gameObject.material.clone();this.gameObject.material=e,this.gameObject.material.onBeforeCompile=this.onBeforeCompile}if(this.lightmapIndex>=0&&this.lightmapTexture){const e=this.gameObject.material;e&&(e.lightMap=this.lightmapTexture,e.needsUpdate=!0)}}setLightmapDebugMaterial(){this.gameObject.material=new Je({vertexShader:`
|
|
4412
4412
|
varying vec2 vUv1;
|
|
4413
4413
|
void main()
|
|
4414
4414
|
{
|
|
@@ -4416,7 +4416,7 @@ version 0.6.9
|
|
|
4416
4416
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
4417
4417
|
}
|
|
4418
4418
|
`,fragmentShader:`
|
|
4419
|
-
uniform sampler2D
|
|
4419
|
+
uniform sampler2D lightMap;
|
|
4420
4420
|
uniform float lightMapIntensity;
|
|
4421
4421
|
uniform vec4 lightmapScaleOffset;
|
|
4422
4422
|
varying vec2 vUv1;
|
|
@@ -4429,11 +4429,11 @@ version 0.6.9
|
|
|
4429
4429
|
void main() {
|
|
4430
4430
|
vec2 lUv = vUv1.xy * lightmapScaleOffset.xy + vec2(lightmapScaleOffset.z, (1. - (lightmapScaleOffset.y + lightmapScaleOffset.w)));
|
|
4431
4431
|
|
|
4432
|
-
vec4 lightMapTexel = texture2D(
|
|
4432
|
+
vec4 lightMapTexel = texture2D( lightMap, lUv);
|
|
4433
4433
|
// The range of RGBM lightmaps goes from 0 to 34.49 (5^2.2) in linear space, and from 0 to 5 in gamma space.
|
|
4434
|
-
//lightMapTexel.rgb *= lightMapTexel.a * 8.; // no idea where that "8" comes from... heuristically derived
|
|
4435
|
-
//lightMapTexel.a = 1.;
|
|
4436
|
-
//lightMapTexel = conv_sRGBToLinear(lightMapTexel);
|
|
4434
|
+
// lightMapTexel.rgb *= lightMapTexel.a * 8.; // no idea where that "8" comes from... heuristically derived
|
|
4435
|
+
// lightMapTexel.a = 1.;
|
|
4436
|
+
// lightMapTexel = conv_sRGBToLinear(lightMapTexel);
|
|
4437
4437
|
// lightMapTexel.rgb = vec3(1.);
|
|
4438
4438
|
|
|
4439
4439
|
// gl_FragColor = vec4(vUv1.xy, 0, 1);
|
|
@@ -5006,7 +5006,7 @@ void main() {
|
|
|
5006
5006
|
`){super("lineBreak",A,!0),this._newLineBreakability=null}update(A,e){this._needsProcess=!0}process(A){const e=A._whiteSpace._newLineBreakability;if(A._inlines._value)for(let i=0;i<A._inlines._value.length;i++){const g=A._inlines._value[i],I=g.char;let o=null;I!==void 0&&(e!=="nowrap"&&(this._value.includes(I)||I.match(/\s/g))&&(o="possible"),I.match(/\n/g)&&(o=e)),g.lineBreak=o}}get value(){return this._value}}class C2 extends lt{constructor(){super("layouter",null,!1),this._value=null}update(A,e){this._value=A._parent.find(i=>i.isUI&&i.isText),this._needsProcess=!0}process(A){this._value&&(this._value._layouter._needsProcess=!0)}}class yiA extends kl{constructor(A){super("backgroundColor",A,!1),this._allowsInherit=!1,this._input=0}computeOutputValue(A){this._input==="inherit"?this._value.set(this.getInheritedInput(A)):this._value.set(this._input)}}class a2 extends iH{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class n2 extends gH{constructor(){super()}computeOutputValue(A){this._value=ZM(this.getInheritedInput(A))}}class r2 extends rH{constructor(){super("fontFamily","inherit",!0),this._input="inherit",this._needsUpdate=!0,this._allowsInherit=!1}computeOutputValue(A){let e=this._inheritedInput;if(e==="inherit"&&(e=this.getInheritedInput(A)),e instanceof Zw)this._value=e,A._font._needsUpdate=!0;else if(typeof e=="string"){const i=sB.getFontFamily(e);i?(this._value=i,A._font._needsUpdate=!0):console.warn(`(.style) fontFamily, the font '${e}' is not registered. Aborted.`)}else console.warn("(.style) fontFamily requires a registered fontFamily instance, or the id of a registered fontFamily."),console.warn("If you want to set a specific font, please use .font property instead.")}get value(){return this._value}}class KR extends QH{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited,this._whiteSpacedContent="",this._stringCollapser=this.emptyStrategyLogic,this._inlineCollapser=this.emptyStrategyLogic,this._inlineWrapper=this.emptyStrategyLogic}_computeFromInherited(A){switch(super._computeFromInherited(A),this._newLineBreakability=SiA(this._value),this._value){case"nowrap":case"normal":this._stringCollapser=fiA;break;case"pre-line":this._stringCollapser=Q2;break;default:this._stringCollapser=miA}switch(this._value){case"pre-line":case"nowrap":case"normal":this._inlineCollapser=UiA;break;case"pre-wrap":this._inlineCollapser=RiA;break;default:this._inlineCollapser=FiA}switch(this._value){case"pre-line":case"pre-wrap":case"normal":this._inlineWrapper=kiA;break;case"pre":this._inlineWrapper=GiA;break;default:this._inlineWrapper=MiA}this._needsProcess=!0}process(A){A.isInline&&!A.isInlineBlock&&(this._whiteSpacedContent=this._stringCollapser(A._textContent._value),A._glyphs._needsProcess=!0)}}const B2={" ":" ","\n":`
|
|
5007
5007
|
`,"\r":"\r"," ":" "},SiA=function(t){switch(t){case"pre":case"pre-wrap":case"pre-line":return"mandatory"}return null};function fiA(t){return Q2(t.replace(/\n/g," "))}function Q2(t){return t.replace(/[ ]{2,}/g," ")}function miA(t){return t}function kiA(t,A,e,i){const g=t[A];if(g.lineBreak==="mandatory"||e+g.xadvance+g.xoffset+g.kerning>i.INNER_WIDTH)return!0;const I=c2(t,A,i);return NiA(t[A-1],e,I,i)}function GiA(t,A,e,i){return t[A].lineBreak==="mandatory"}function MiA(){return!1}function RiA(t){if(!t[0])return 0;const A=t[0],e=t[t.length-1];return A.char&&A.char===`
|
|
5008
5008
|
`&&t.length>1&&h2([A],t[1]),e.char&&e.char===`
|
|
5009
|
-
`&&t.length>1&&E2([e],t[t.length-2]),A.offsetX}function UiA(t){if(!t[0])return 0;let A=[],e;for(let i=0;i<t.length;i++){const g=t[i];if(g.char&&B2[g.char]&&t.length>i){A.push(g),e=t[i+1];continue}break}h2(A,e),A=[],e=null;for(let i=t.length-1;i>0;i--){const g=t[i];if(g.char&&B2[g.char]&&i>0){A.push(g),e=t[i-1];continue}break}return E2(A,e),t[0].offsetX}function FiA(t){return t[0]?t[0].offsetX:0}function E2(t,A){if(A)for(let e=0;e<t.length;e++){const i=t[e];i.fontFactor=0,i.offsetX=A.offsetX+A.cumulativeWidth,i.cumulativeWidth=0}}function h2(t,A){if(A)for(let e=0;e<t.length;e++){const i=t[e];i.fontFactor=0,i.offsetX=A.offsetX,i.cumulativeWidth=0}}function c2(t,A,e,i){if(i=i||0,!t[A])return i;const g=t[A];return g.lineBreak?i+g.xadvance:c2(t,A+1,e,i+g.xadvance+g.xoffset+g.kerning+e.LETTERSPACING)}function NiA(t,A,e,i){return!t||!t.char||A+e<i.INNER_WIDTH?!1:i.BREAKON.indexOf(t.char)>-1}class l2 extends EH{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._fontSize._needsProcess=!0,A._layouter._needsProcess=!0}}class d2 extends Lt{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(A){this._value=this._inheritedInput,A._font._fontVariant&&(A._bounds._needsProcess=!0,A._layouter._needsProcess=!0)}process(A){if(!A._font._fontVariant||!A._font._fontVariant.isReady)return;const e=this._value/A._font._fontVariant.typographic.size,i=A._inlines._value;for(let g=0;g<i.length;g++){const I=i[g];I.resetOffsets(),I.fontSize=this._value,I.fontFactor=e}}get value(){return this._value}}class p2 extends hH{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(A,e){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(A)),A._layouter._needsUpdate=!0}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class KiA extends p2{constructor(){super(),this._value="inherit"}}class JiA extends $w{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._parent._value._layouter._needsProcess=!1}process(A){if(this._value!=="none"){const e=A._whiteSpace._whiteSpacedContent,i=A._inlines._value;for(let g=1;g<i.length;g++){const I=e[g-1]+e[g];i[g].kerning=A._font._fontVariant.getKerningAmount(I)}}}}class u2 extends lt{constructor(){super("children",null,!1),this._uis=[]}update(A,e){}process(A){}_compute(A){}dispose(){}}function qiA(t,A=!1){const e=t[0].index!==null,i=new Set(Object.keys(t[0].attributes)),g=new Set(Object.keys(t[0].morphAttributes)),I={},o={},s=t[0].morphTargetsRelative,C=new OA.BufferGeometry;let a=0;for(let n=0;n<t.length;++n){const B=t[n];let Q=0;if(e!==(B.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const E in B.attributes){if(!i.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+'. All geometries must have compatible attributes; make sure "'+E+'" attribute exists among all geometries, or in none of them.'),null;I[E]===void 0&&(I[E]=[]),I[E].push(B.attributes[E]),Q++}if(Q!==i.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". Make sure all geometries have the same number of attributes."),null;if(s!==B.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const E in B.morphAttributes){if(!g.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". .morphAttributes must be consistent throughout all geometries."),null;o[E]===void 0&&(o[E]=[]),o[E].push(B.morphAttributes[E])}if(C.userData.mergedUserData=C.userData.mergedUserData||[],C.userData.mergedUserData.push(B.userData),A){let E;if(e)E=B.index.count;else if(B.attributes.position!==void 0)E=B.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". The geometry must have either an index or a position attribute"),null;C.addGroup(a,E,n),a+=E}}if(e){let n=0;const B=[];for(let Q=0;Q<t.length;++Q){const E=t[Q].index;for(let h=0;h<E.count;++h)B.push(E.getX(h)+n);n+=t[Q].attributes.position.count}C.setIndex(B)}for(const n in I){const B=D2(I[n]);if(!B)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+n+" attribute."),null;C.setAttribute(n,B)}for(const n in o){const B=o[n][0].length;if(B===0)break;C.morphAttributes=C.morphAttributes||{},C.morphAttributes[n]=[];for(let Q=0;Q<B;++Q){const E=[];for(let l=0;l<o[n].length;++l)E.push(o[n][l][Q]);const h=D2(E);if(!h)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+n+" morphAttribute."),null;C.morphAttributes[n].push(h)}}return C}function D2(t){let A,e,i,g=0;for(let s=0;s<t.length;++s){const C=t[s];if(C.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(A===void 0&&(A=C.array.constructor),A!==C.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=C.itemSize),e!==C.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(i===void 0&&(i=C.normalized),i!==C.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;g+=C.array.length}const I=new A(g);let o=0;for(let s=0;s<t.length;++s)I.set(t[s].array,o),o+=t[s].array.length;return new OA.BufferAttribute(I,e,i)}class viA extends lt{constructor(){super("renderer")}render(A){if(!A._inlines._value||!A._inlines._value.length)return;const e=A._inlines._value.map(g=>A._font._fontVariant.getGeometricGlyph(g,A).translate(g.offsetX,g.offsetY,0)),i=qiA(e);A.setFontMesh(new OA.Mesh(i,A.fontMaterial)),A._fontMesh.renderOrder=1/0}}class biA extends AR{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(A){this._value=this._inheritedInput,A._layouter._needsProcess=!0}}class bh extends Kl{constructor(A={}){const e={};bh.definePropertiesValues(e,A),super(e,A),r(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0}),bh.init(this)}add(A){const e=[];for(let i=0;i<arguments.length;i++){const g=arguments[i];!g.isUI||g.isInline?(e.push(g),g.position.z=.005):console.warn("Block element can only contain Box elements.",g)}return super.add(...e)}set textContent(A){this._textContent.value=A}get textContent(){return this._textContent._value}set invertAlpha(A){this._invertAlpha.value=A}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(A,e){A.children||(A.children=u2),A.textContent||(A.textContent=piA),A.glyphs||(A.glyphs=DiA),A.inlines||(A.inlines=uiA),A.layouter||(A.layouter=C2),A.renderer||(A.renderer=viA),A.fontFamily||(A.fontFamily=r2),A.fontWeight||(A.fontWeight=n2),A.fontStyle||(A.fontStyle=a2),A.fontSize||(A.fontSize=d2),A.color||(A.color=wiA),A.backgroundColor||(A.backgroundColor=yiA),A.lineBreak||(A.lineBreak=s2),A.letterSpacing||(A.letterSpacing=l2),A.whiteSpace||(A.whiteSpace=KR),A.segments||(A.segments=KiA),A.textAlign||(A.textAlign=biA),A.fontKerning||(A.fontKerning=JiA)}static init(A){Object.defineProperties(A,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class LiA extends tH{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}update(A,e){this._needsUpdate=!1;for(let i=A.children.length-1;i>=0;i--){const g=A.children[i];g.isUI&&(A.remove(g),g.clear())}A._children._uis=[],this._value&&A.add(new bh({name:"anonymousInline",textContent:this._value}))}}class xiA extends Array{constructor(...A){super(...A),this.width=0,this.height=0}}class TiA extends lt{constructor(){super("layouter",null,!1),this._value=null}update(A,e){}process(A){let e=A._width._value;A._width._auto?e=1/0:e=A._bounds._innerWidth;const i=A._lineHeight._value,g=new xiA(new o2);let I=0;A._children._inlines.forEach(B=>{if(!B._inlines.value)return;this._resetInlines(B);const Q=B._fontSize._value,E=B._letterSpacing._value*Q,h=B._whiteSpace._value,l=B._lineBreak._value,d={WHITESPACE:h,LETTERSPACING:E,BREAKON:l,INNER_WIDTH:e},c=B._whiteSpace._inlineWrapper;I+=B._margin._value.w+B._padding._value.w,B._inlines.value.forEach((u,p,D)=>{const w=g[g.length-1];if(c(D,p,I,d)){if(g.push(new o2(u)),u.offsetX=u.xoffset,u.width===0){I=0;return}u.cumulativeWidth=u.xadvance+E,I=u.cumulativeWidth;return}g[g.length-1].push(u),u.offsetX=I+u.xoffset+u.kerning,u.cumulativeWidth=u.xadvance+u.kerning+E,I+=u.cumulativeWidth,w.length-1===1&&w[w.length-2].width===0&&(u.offsetX-=u.xoffset,I-=u.xoffset)}),I+=B._margin._value.y+B._padding._value.y});const o=A._whiteSpace._inlineCollapser;let s=0,C=0,a=0;g.forEach((B,Q)=>{const E=o(B);let h=0,l=0;if(B.forEach(d=>{h=Math.max(h,d.lineHeight),l=Math.max(l,d.lineBase),d.offsetX-=E}),B.lineHeight=h,B.lineBase=l,Q===0?a=-(h*i-h)*.5:a-=g[Q-1].lineHeight*i,B.y=a,B.x=0,B.forEach(d=>{d.offsetY=a-d.anchor,d.lineHeight<B.lineHeight&&(d.offsetY-=B.lineBase-d.lineBase)}),C+=B.lineHeight*i,B.width=0,B[0]){const d=B[B.length-1];B.width=d.offsetX+d.cumulativeWidth+d.paddingRight+d.marginRight+B[0].offsetX,s=Math.max(s,B.width)}}),g.height=C,g.width=s,this._value=g,e===1/0&&A._bounds.setChildrenWidth(A,g.width),A._height._auto&&A._bounds.setChildrenHeight(A,g.height);const n=A._parent._value;n&&(n._autoSize._needsProcess=!0,n._flexDirection._needsProcess=!0),A._inlineJustificator._needsProcess=!0,A._textAlign._needsProcess=!0,A._overflow._needsUpdate=!0}_resetInlines(A){A._fontSize.process(A)}}class YiA extends AR{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput,this._needsProcess=!0}process(A){HiA(A),A._renderer._needsRender=!0}}function HiA(t){const A=t._layouter._value,e=t._textAlign._value,i=t._bounds._innerWidth;for(let g=0;g<A.length;g++){const I=A[g],o=OiA(t,I,g===A.length-1),s=t._padding._value,C=t._borderWidth._value,a=(-s.w+s.y)/2+(-C.w+C.y)/2;I.x+=o;for(let n=0;n<I.length;n++)I[n].offsetX+=o-a}if(e.indexOf("justify")===0)for(let g=0;g<A.length;g++){const I=A[g];if(e.indexOf("-")!==-1&&g===A.length-1)return;const o=i-I.width;if(o<=0)return;let s=0;for(let B=1;B<I.length-1;B++)s+=I[B].char===" "?1:0;const C=o/s;let a=1;e==="justify-right"&&(I.reverse(),a=-1);let n=0;for(let B=1;B<=I.length-1;B++){const Q=I[B];Q.offsetX+=n*a,n+=Q.char===" "?C:0}e==="justify-right"&&I.reverse()}}function OiA(t,A,e){switch(t._textAlign._value){case"justify-left":case"justify":case"left":return-t._bounds._innerWidth/2;case"justify-right":case"right":return-A.width+t._bounds._innerWidth/2;case"center":return-A.width/2;case"justify-center":return e?-A.width/2:-t._bounds._innerWidth/2;default:console.warn(`textAlign: '${t._textAlign._value}' is not valid`)}}class _iA extends eR{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput}}class PiA extends BH{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class jiA extends $w{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A)}}class WiA extends t2{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class ViA extends lt{constructor(){super("children",null,!1),r(this,"_sortOrder",(A,e)=>A._order._value<e._order._value?-1:A._order._value>e._order._value?1:this._uis.indexOf(A)<this._uis.indexOf(e)?-1:1),this._uis=[],this._inlines=[],this._boxes=[]}update(A,e){this._compute(A),this._needsProcess=!0}process(A){this._compute(A),A._overflow._needsRender=!0}_compute(A){this._uis=A.children.filter(e=>e.visible&&e.isUI),this._inlines=this._uis.filter(e=>e.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class ziA extends lt{constructor(){super("autosize")}process(A){if(A._layouter._value&&A._layouter._value.length){const e=A._layouter._value,i=A._padding._value,g=A._borderWidth._value;A._width._auto&&A._bounds.setOffsetWidth(A,e.width+i.w+i.y+g.w+g.y),A._height._auto&&A._bounds.setOffsetHeight(A,e.height+i.x+i.z+g.x+g.z)}}}class ZiA extends I2{constructor(){super("renderer"),this._needsUpdate=!1}render(A){super.render(A);for(const e of A._children._inlines)e._renderer.render(e);A.performAfterUpdate()}}class yp extends Dp{constructor(A={},e={}){yp.definePropertiesValues(e,A),super(e,A),yp.init(this)}add(A){const e=[];let i=!1;for(let g=0;g<arguments.length;g++){const I=arguments[g];!I.isUI||I.isInline?(I.isInline&&(i=!0),e.push(I)):console.warn("Block element can only contain Box elements.",I)}return e.length>0&&super.add(...e),i&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(A){this._textContent.value=A}get textContent(){return super.textContent}set invertAlpha(A){this._invertAlpha.value=A}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(A,e){A.flexDirection=_iA,A.justifyContent=tR,A.alignItems=$M,A.bounds=WiA,A.autoSize=ziA,A.renderer=ZiA,A.children||(A.children=ViA),A.textContent||(A.textContent=LiA),A.layouter||(A.layouter=TiA),A.lineHeight||(A.lineHeight=PiA),A.textAlign||(A.textAlign=YiA),A.whiteSpace||(A.whiteSpace=KR),A.fontKerning||(A.fontKerning=jiA),A.segments||(A.segments=p2),e.width||(e.width="100%"),e.fontSide||(e.fontSide=0)}static init(A){Object.defineProperties(A,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class XiA extends lt{constructor(){super("inlines",null,!1),this._value=[]}process(A){this._value[0].paddingLeft=A._padding._value.w,this._value[0].marginLeft=A._margin._value.w;const e=this._value.length-1;this._value[e].paddingRight=A._padding._value.y,this._value[e].marginRight=A._margin._value.y}}class $iA extends lt{constructor(){super("renderer")}render(A){A._backgroundMesh||A.setBackgroundMesh(new g2(A)),A._backgroundMesh.position.x=A._inlines._value[0].offsetX+A._inlines._value[0].width/2,A._backgroundMesh.position.y=A._inlines._value[0].offsetY+A._inlines._value[0].lineBase/2,A._bounds.render(A)}}class AgA extends lt{constructor(){super("bounds",null,!1),this._size=new OA.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(A,e){this.output(e),this._needsProcess=!0}process(A){this._offsetWidth=this._innerWidth=A._inlines._value[0].width,this._offsetHeight=this._innerHeight=A._inlines._value[0].height,this._needsRender=!0,A._borderWidth._needsRender=!0,A._borderRadius._needsRender=!0}render(A){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(A){A.size=this._size}}class Sp extends Kl{constructor(A={}){const e={};Sp.definePropertiesValues(e,A),super(e,A),Sp.init(this)}clear(){for(const A of this._inlines._value)A.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new OA.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(A){const e=[];for(let i=0;i<arguments.length;i++){const g=arguments[i];g.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",g):(e.push(g),g.position.z=.005)}return super.add(...e)}static definePropertiesValues(A,e){A.children||(A.children=u2),A.bounds||(A.bounds=AgA),A.inlines||(A.inlines=XiA),A.layouter||(A.layouter=C2),A.renderer||(A.renderer=$iA),A.fontFamily||(A.fontFamily=r2),A.fontWeight||(A.fontWeight=n2),A.fontStyle||(A.fontStyle=a2),A.fontSize||(A.fontSize=d2),A.backgroundColor||(A.backgroundColor=$Y),A.lineBreak||(A.lineBreak=s2),A.letterSpacing||(A.letterSpacing=l2),A.whiteSpace||(A.whiteSpace=KR),A.fontKerning||(A.fontKerning=$w),e.backgroundSize||(e.backgroundSize="cover"),e.width||(e.width="100%"),e.height||(e.height="100%"),e.boxSizing||(e.boxSizing="border-box")}static init(A){Object.defineProperties(A,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),A._inlines._value=[new egA(A)],A.backgroundMaterial=new e2,A._renderer.render(A)}}class egA extends sH{constructor(A){super(),this._uiElement=A}get xadvance(){const A=this._uiElement._padding._value,e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.w+A.y+e.value}get width(){const A=this._uiElement._width;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get height(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get anchor(){return this.height}get lineHeight(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get lineBase(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}clear(){this._uiElement=null}}class w2{constructor(A){this._subject=A}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const y2=()=>Cy.update(),S2={BaseProperty:lt,Block:wp,Text:yp,Inline:bh,InlineBlock:Sp,MeshUIBaseElement:Kl,FontLibrary:sB,update:y2,MSDFFontMaterialUtils:Oo,ShaderChunkUI:A2,Behavior:w2,FontVariant:ml};typeof global<"u"&&(global.ThreeMeshUI=S2);const tgA=S2;var igA=fi.w8,f2=fi.cg,JR=fi.gO,ggA=fi.wb,qR=fi.zV,IgA=fi.HS,ogA=fi.Ec,ny=fi.gF,sgA=fi.ol,CgA=fi.pz,agA=fi.tx,ngA=fi.hj,rgA=fi.FV,BgA=fi.sV,m2=fi.xv,QgA=fi.mx,EgA=fi.gE,hgA=fi.ZP,k2=fi.Vx;const vR=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:igA,Behavior:f2,Block:JR,DefaultValues:ggA,FontLibrary:qR,FontVariant:IgA,InheritableProperty:ogA,Inline:ny,InlineBlock:sgA,InlineGlyph:CgA,MSDFFontMaterialUtils:agA,MaterialTransformers:ngA,MeshUIBaseElement:rgA,ShaderChunkUI:BgA,Text:m2,TypographicFont:QgA,TypographicGlyph:EgA,default:hgA,update:k2},Symbol.toStringTag,{value:"Module"})),cgA=oA("debugshadowcomponents");JR.prototype.interactable={get(){return this.interactive},set(t){this.interactable=t}};const $s=Symbol("shadowDomOwner");class fs extends UA{constructor(){super(...arguments),r(this,"shadowComponent",null),r(this,"_controlsChildLayout",!0),r(this,"_root"),r(this,"_parentComponent")}isRoot(){var A;return((A=this.Root)==null?void 0:A.gameObject)===this.gameObject}get canvas(){const A=this.Root;return A!=null&&A.isCanvas?A:null}markDirty(){ZI.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(A){this._controlsChildLayout=A,this.shadowComponent&&(this.shadowComponent.autoLayout=A)}get Root(){return this._root===void 0&&(this._root=tA.getComponentInParent(this.gameObject,Jl)),this._root}get Canvas(){return this.canvas}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this.shadowComponent=null,this._root=void 0,this._parentComponent=void 0}onEnable(){super.onEnable()}addShadowComponent(A,e){var i;this.removeShadowComponent();const g=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=tA.getComponentInParent(g,fs),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}A.name=this.name+" ("+(this.constructor.name??"UI")+")",A.autoLayout=this._parentComponent.controlsChildLayout,A[$s]=this,this.setShadowComponentOwner(A);let I=!1;if(((i=this.Root)==null?void 0:i.gameObject)===this.gameObject)this.gameObject.add(A);else{let o=this._parentComponent.shadowComponent;o&&(o?.add(A),I=!0)}this.shadowComponent=A,e&&e.shadowComponent&&this.shadowComponent&&e.shadowComponent.add(this.shadowComponent),Mc&&A.add(new YQ(.5)),this.onAfterAddedToScene(),I&&k2(),cgA&&console.log(this.shadowComponent)}set(A){}setShadowComponentOwner(A){if(A&&(A[$s]===void 0||A[$s]===this)&&(A[$s]=this,A.children))for(const e of A.children)this.setShadowComponentOwner(e)}traverseOwnedShadowComponents(A,e,i){if(A&&A[$s]===e){i(A);for(const g of A.children)this.traverseOwnedShadowComponents(g,e,i)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(A){this.shadowComponent&&(this.shadowComponent.interactable=A)}}class Jl extends fs{awake(){super.awake()}}class ME{static getObject(A){const e=A[$s];return e&&(e.isComponent===!0?A=e.gameObject:A=e),A}static isInteractable(A,e){if(e&&(e.canvasGroup=void 0,e.graphic=void 0),A==null||!A.visible||(A=this.getObject(A),!A.visible))return!1;const i=this.tryFindCanvasGroup(A);if(i?.isCanvasGroup===!0&&(e&&(e.canvasGroup=i),i.blocksRaycasts===!1||i.interactable===!1))return!1;const g=Xr(A,I=>{if(I.isGraphic===!0)return I},!1);return e&&g?.isGraphic===!0&&(e.graphic=g),!(g?.raycastTarget===!1||g?.layer===2)}static tryFindCanvasGroup(A){if(!A)return null;const e=Xr(A,i=>{const g=i;if(g.blocksRaycasts!==void 0&&g.interactable!==void 0)return g},!1);return e!==void 0?e:this.tryFindCanvasGroup(A.parent)}}const ql=oA("debugwebxrcontroller");var RE=(t=>(t[t.PhysicalDevice=0]="PhysicalDevice",t[t.Touch=1]="Touch",t))(RE||{}),sa=(t=>(t.SelectStart="select-start",t.SelectEnd="select-end",t.Update="update",t))(sa||{});class ry extends UA{}const Eg=class extends UA{constructor(){super(...arguments),r(this,"webXR"),r(this,"index",-1),r(this,"controllerModel"),r(this,"controller"),r(this,"controllerGrip"),r(this,"hand"),r(this,"handPointerModel"),r(this,"grabbed",null),r(this,"input",null),r(this,"type",0),r(this,"showRaycastLine",!0),r(this,"_wristQuaternion",null),r(this,"movementVector",new S),r(this,"worldRot",new xA),r(this,"joystick",new Z),r(this,"didRotate",!1),r(this,"didTeleport",!1),r(this,"didChangeScale",!1),r(this,"lastHit",null),r(this,"raycastLine",null),r(this,"_raycastHitPoint",null),r(this,"_connnectedCallback",null),r(this,"_disconnectedCallback",null),r(this,"_selectStartEvt",null),r(this,"_selectEndEvt",null),r(this,"_selectionPressed",!1),r(this,"_selectionPressedLastFrame",!1),r(this,"_selectionStartTime",0),r(this,"_selectionEndTime",0),r(this,"_useSmoothing",!0),r(this,"_isConnected",!1),r(this,"rayRotation",new xA),r(this,"_pinchStartTime"),r(this,"selectStartCallback",null),r(this,"lastSelectStartObject",null),r(this,"_didNotEndSelection",!1),r(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const t=new oi(this.geometry),A=t.material;return A.color=this.raycastColor,t.layers.set(2),t.name="line",t.scale.z=1,t}static CreateRaycastHitPoint(){const t=new Yo(.5,22,22),A=new Et({color:this.raycastColor}),e=new fA(t,A);return e.visible=!1,e.layers.set(2),e}static Create(t,A,e,i){const g=e?tA.addNewComponent(e,Eg,!1):new Eg;g.webXR=t,g.index=A,g.type=i;const I=t.context;g.controller=I.renderer.xr.getController(A),g.controllerGrip=I.renderer.xr.getControllerGrip(A),g.controllerModel=this.Factory.createControllerModel(g.controller),g.controllerGrip.add(g.controllerModel),g.hand=I.renderer.xr.getHand(A);const o=new oE;al(o,I),g.webXR.handModelPath&&g.webXR.handModelPath!==""?o.setPath(Ya(t.sourceId,g.webXR.handModelPath)):o.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const s=new L$(g.hand,o);return g.hand.add(s),g.hand.traverse(C=>C.layers.set(2)),g.handPointerModel=new P$(g.hand,g.controller),g.controller.addEventListener("connected",C=>{g.setControllerLayers(g.controllerModel,2),g.setControllerLayers(g.controllerGrip,2),g.setControllerLayers(g.hand,2),setTimeout(()=>{g.setControllerLayers(g.controllerModel,2),g.setControllerLayers(g.controllerGrip,2),g.setControllerLayers(g.hand,2)},1e3)}),g.hand.addEventListener("connected",C=>{var a;if(C.data.hand){t.Rig&&t.Rig.add(g.hand),g.type=0,g.handPointerModel.traverse(B=>B.layers.set(2)),(a=g.handPointerModel.pointerObject)==null||a.traverse(B=>B.layers.set(2));const n=g.hand.joints;if(n)for(const B of Object.keys(n)){const Q=n[B];Q.parent||g.hand.add(Q)}}}),g}static addEventListener(t,A){const e=this.eventSubs[t]??[];e.push(A),this.eventSubs[t]=e}static removeEventListener(t,A){if(!A)return;const e=this.eventSubs[t]??[],i=e.indexOf(A);i>=0&&e.splice(i,1),this.eventSubs[t]=e}get isUsingHands(){var t;return((t=this.input)==null?void 0:t.hand)!=null}get wrist(){if(!this.hand)return null;const t=this.hand.joints;return t?t.wrist:null}getWristQuaternion(){const t=this.wrist;return t?(this._wristQuaternion||(this._wristQuaternion=new xA),Ti(t).multiply(this._wristQuaternion.setFromEuler(new og(-Math.PI/4,0,0)))):null}get selectionDown(){return this._selectionPressed&&!this._selectionPressedLastFrame}get selectionUp(){return!this._selectionPressed&&this._selectionPressedLastFrame}get selectionPressed(){return this._selectionPressed}get selectionClick(){return this._selectionEndTime-this._selectionStartTime<.3}get raycastHitPoint(){return this._raycastHitPoint}get useSmoothing(){return this._useSmoothing}awake(){if(!this.controller){console.warn("Missing Controller!!!",this);return}this._connnectedCallback=this.onSourceConnected.bind(this),this._disconnectedCallback=this.onSourceDisconnected.bind(this),this._selectStartEvt=this.onSelectStart.bind(this),this._selectEndEvt=this.onSelectEnd.bind(this),this.type===1&&(this.controllerGrip.addEventListener("connected",this._connnectedCallback),this.controllerGrip.addEventListener("disconnected",this._disconnectedCallback),this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt))}onDestroy(){var t,A,e;this.type===1&&(this.controllerGrip.removeEventListener("connected",this._connnectedCallback),this.controllerGrip.removeEventListener("disconnected",this._disconnectedCallback),this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),(t=this.hand)==null||t.clear(),(A=this.controllerGrip)==null||A.clear(),(e=this.controller)==null||e.clear()}onEnable(){var t,A,e,i,g;this.hand&&(this.hand.name="Hand"),this.controllerGrip&&(this.controllerGrip.name="ControllerGrip"),this.controller&&(this.controller.name="Controller"),this.raycastLine&&(this.raycastLine.name="RaycastLine;"),this.webXR.Controllers.indexOf(this)<0&&this.webXR.Controllers.push(this),this.raycastLine||(this.raycastLine=Eg.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=Eg.CreateRaycastHitPoint()),(t=this.webXR.Rig)==null||t.add(this.hand),(A=this.webXR.Rig)==null||A.add(this.controllerGrip),(e=this.webXR.Rig)==null||e.add(this.controller),(i=this.webXR.Rig)==null||i.add(this.raycastLine),(g=this.raycastLine)==null||g.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),ql&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var t,A,e,i,g;(t=this.hand)==null||t.removeFromParent(),(A=this.controllerGrip)==null||A.removeFromParent(),(e=this.controller)==null||e.removeFromParent(),(i=this.raycastLine)==null||i.removeFromParent(),(g=this._raycastHitPoint)==null||g.removeFromParent();const I=this.webXR.Controllers.indexOf(this);I>=0&&this.webXR.Controllers.splice(I,1)}onSourceConnected(t){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,t);return}this._isConnected=!0,this.input=t.data,this.type===1&&(this.onSelectStart(),this.createPointerEvent("down"))}onSourceDisconnected(t){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",t);return}this._isConnected=!1,this.type===1&&(this.onSelectEnd(),this.createPointerEvent("up")),this.input=null}createPointerEvent(t){switch(t){case"down":this.context.input.createPointerDown({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break;case"move":break;case"up":this.context.input.createPointerUp({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break}}update(){this.context.time.frameCount%60===0&&(this.setControllerLayers(this.controller,2),this.setControllerLayers(this.controllerGrip,2),this.setControllerLayers(this.hand,2));const t=Eg.eventSubs.update;if(t&&t.length>0)for(const i of t)i(this);let A=1;this.type===0?A=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(A=this.context.time.deltaTime/.3),this.rayRotation.slerp(Ti(this.controller),this.useSmoothing?A:1);const e=ue(this.controller);if(this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine){const i=this.showRaycastLine&&this.type!==1;if(this.type===1)this.raycastLine.visible=!1;else if(this.isUsingHands){this.raycastLine.visible=!this.grabbed&&i,Ci(this.raycastLine,e);const g=this.hand.joints;if(g&&g.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const I=this.getWristQuaternion();I&&this.rayRotation.copy(I)}pI(this.raycastLine,this.rayRotation)}else this.raycastLine.visible=i,pI(this.raycastLine,this.rayRotation),Ci(this.raycastLine,e)}this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(t){var A,e;if(this.lastHit=null,!t||t.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=t.inputSources[this.index]),!this.input)return;const i=this.webXR.Rig;if(!i)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const g=(e=(A=this.input)==null?void 0:A.gamepad)==null?void 0:e.buttons;switch(this.input.handedness){case"left":const I=3*Eg.MovementSpeedFactor,o=2,s=te.clamp01(this.joystick.length()*2),C=this.joystick.x>0?1:-1;let a=Math.pow(this.joystick.x,o);a*=C,a*=s;const n=this.joystick.y>0?1:-1;let B=Math.pow(this.joystick.y,o);B*=n,a*=s,i.getWorldQuaternion(this.worldRot),this.movementVector.set(a,0,B),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(I*this.context.time.deltaTime),i.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(i,g);break;case"right":const Q=this.joystick.x,E=Math.abs(Q);if(E<.4)this.didRotate=!1;else if(E>.5&&!this.didRotate){const h=Q>0?-1:1;i.rotateY(te.toRadians(30*h)),this.didRotate=!0}this.runTeleport(i,g);break}}runTeleport(t,A){var e,i,g;let I=-this.joystick.y;if((e=this.hand)!=null&&e.visible&&!this.grabbed){const a=this.handPointerModel.isPinched();a&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),a&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(I=this.handPointerModel.isPinched()?1:0),a||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;let o=I>.5&&this.webXR.IsInVR,s=this.webXR.Rig?((g=(i=this.webXR.Rig)==null?void 0:i.scale)==null?void 0:g.x)<.999:!1,C=null;if(A&&this.input&&!this.input.hand)for(let a=0;a<A.length;a++){const n=A[a];if(a===4)if(n.pressed&&!this.didChangeScale&&this.webXR.IsInVR){this.didChangeScale=!0;const B=this.webXR.Rig;if(B)if(s){s=!1,B.scale.set(1,1,1),C=1,Eg.MovementSpeedFactor=1;const Q=this.context.mainCamera;Eg.PreviousCameraFarDistance&&(Q.far=Eg.PreviousCameraFarDistance)}else{s=!0,o=!0,C=.1,Eg.MovementSpeedFactor=C*2;const Q=this.context.mainCamera;Eg.PreviousCameraFarDistance=Q.far,Q.far/=C}}else n.pressed||(this.didChangeScale=!1)}if(o){if(!this.didTeleport){const a=this.raycast();if(this.didTeleport=!0,a&&a.length>0){const n=a[0];if(s||this.isValidTeleportTarget(n.object)){const B=n.point;Ci(t,B)}}}}else I<.1&&(this.didTeleport=!1);C!==null&&(t.scale.set(C,C,C),t.updateMatrixWorld())}isValidTeleportTarget(t){return tA.getComponentInParent(t,ry)!=null}updateStick(t){var A;!t||!t.gamepad||((A=t.gamepad.axes)==null?void 0:A.length)<4||(this.joystick.x=t.gamepad.axes[2],this.joystick.y=t.gamepad.axes[3])}updateLastHit(){var t;const A=this.raycast(),e=A?A[0]:null;this.lastHit=e;let i=1;if(this.webXR.Rig&&(i/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=i*(((t=this.lastHit)==null?void 0:t.distance)??9999);const g=this.raycastLine.material;e!=null?g.color=Eg.raycastColor:g.color=Eg.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const g=te.clamp(this.lastHit.distance*.01*i,.015,.1);this._raycastHitPoint.scale.set(g,g,g)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return e}onSelectStart(){this.context.connection.allowEditing&&(this.selectStartCallback=()=>this.onHandleSelectStart())}onHandleSelectStart(){this.selectStartCallback=null,this._selectionPressed=!0,this._selectionStartTime=this.context.time.time,this._selectionEndTime=1e3;let t=null,A=!1;if(this.isUsingHands?(t=this.overlap(),t.length<=0?(t=this.raycast(),A=!1):A=!0):t=this.raycast(),ql&&console.log("onHandleSelectStart","close grab? "+A,"intersections",t),t&&t.length>0)for(const e of t){const i=e.object;this.lastSelectStartObject=i;const g={selected:i,grab:i},I=Eg.eventSubs["select-start"];if(I&&I.length>0)for(const o of I)o(this,g);g.grab!==i&&ql&&console.log("Grabbed object changed","original",i,"new",g.grab),g.grab&&(this.grabbed=AC.TryTake(this,g.grab,e,A));break}else{const e=Eg.eventSubs["select-start"],i={selected:null,grab:null};if(e&&e.length>0)for(const g of e)g(this,i)}}onSelectEnd(){var t;if(this.isUsingHands&&this.handPointerModel.pinched){this._didNotEndSelection=!0;return}if(!this._selectionPressed)return;this.selectStartCallback=null,this._selectionPressed=!1,this._selectionEndTime=this.context.time.time;const A={grab:((t=this.grabbed)==null?void 0:t.selected)??this.lastSelectStartObject},e=Eg.eventSubs["select-end"];if(e&&e.length>0)for(const i of e)i(this,A);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(t){return!(!t||tA.isActiveInHierarchy(t)===!1||ME.isInteractable(t)===!1)}setControllerLayers(t,A){var e,i;if(t&&(t.layers.set(A),t.children))for(const g of t.children)((e=this.grabbed)==null?void 0:e.selected)===g||((i=this.grabbed)==null?void 0:i.selectedMesh)===g||this.setControllerLayers(g,A)}getRay(){const t=new Js;return t.origin.copy(ue(this.controller)),t.direction.set(0,0,-1).applyQuaternion(this.rayRotation),t}overlap(){const t=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(ql&&(!this.closeGrabBoundingBoxHelper&&t&&(this.closeGrabBoundingBoxHelper=new CD(t,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&t&&this.closeGrabBoundingBoxHelper.setFromObject(t)),!t)return new Array;const A=ue(t).clone();return this.context.physics.sphereOverlap(A,.02)}raycast(){const t=new es;t.layerMask=new Qo,t.layerMask.enableAll(),t.layerMask.disable(2),t.ray=this.getRay();const A=this.context.physics.raycast(t);for(let e=0;e<A.length;e++){const i=A[e],g=i.object;if(!this.testIsVisible(g)){A.splice(e,1),e--;continue}i.object=ME.getObject(g);break}return A}};let mi=Eg;r(mi,"Factory",new gAA),r(mi,"raycastColor",new wA(.9,.3,.3)),r(mi,"raycastNoHitColor",new wA(.6,.6,.6)),r(mi,"geometry",new pe().setFromPoints([new S(0,0,0),new S(0,0,-1)])),r(mi,"handModels",{}),r(mi,"eventSubs",{}),r(mi,"PreviousCameraFarDistance"),r(mi,"MovementSpeedFactor",1);var By=(t=>(t.WillTake="WillTake",t.DidTake="DidTake",t.WillFree="WillFree",t.DidFree="DidFree",t))(By||{});const kI=class{constructor(){r(this,"sync",null),r(this,"selected",null),r(this,"selectedParent",null),r(this,"selectedMesh",null),r(this,"controller",null),r(this,"grabTime",0),r(this,"grabUUID",""),r(this,"isCloseGrab",!1),r(this,"originalMaterial",null),r(this,"usageMarker",null),r(this,"rigidbodies",null),r(this,"didReparent",!1),r(this,"grabDistance",0),r(this,"interactable",null),r(this,"positionSource",null),r(this,"grabPoint",new S),r(this,"localPositionOffsetToGrab",null),r(this,"localPositionOffsetToGrab_worldSpace",new S),r(this,"localQuaternionToGrab",new xA(0,0,0,1)),r(this,"targetDir",null),r(this,"quaternionLerp",null),r(this,"controllerDir",new S),r(this,"controllerWorldPos",new S),r(this,"lastControllerWorldPos",new S),r(this,"controllerPosDelta",new S),r(this,"totalChangeAlongDirection",0),r(this,"rigPositionLastFrame",new S)}static AddEventListener(t,A){return kI.Events[t]||(kI.Events[t]=[]),kI.Events[t].push(A),A}static RemoveEventListener(t,A){if(!A||!kI.Events[t])return;const e=kI.Events[t].indexOf(A);e>=0&&kI.Events[t].splice(e,1)}static Register(t){this.Current.find(A=>A===t)||this.Current.push(t)}static Remove(t){const A=this.Current.indexOf(t);A>=0&&this.Current.splice(A,1)}static TryTake(t,A,e,i){const g=tA.getComponentInParent(A,DE);if(g)A=g.gameObject;else return ql&&console.warn("Prevented taking object that is not interactable",A),null;let I=A;const o=tA.getComponentInParent(A,Kn);o&&(o.requestOwnership(),I=o.gameObject);for(const C of this.Current)if(C.selected===I)return C.controller===t||(C.free(),C.Take(t,I,A,o,g,e,i)),C;const s=new kI;return s.Take(t,I,A,o,g,e,i),s}Take(t,A,e,i,g,I,o){var s,C;if(console.assert(A!==null,"Expected object to be taken but was",A),t.isUsingHands?this.positionSource=o?t.wrist:t.controller:this.positionSource=t.controller,!this.positionSource)return console.warn("No position source"),this;const a={controller:t,take:A,hit:e,sync:i,interactable:g};(s=kI.Events.WillTake)==null||s.forEach(h=>h(this,a));const n=e;n!=null&&n.material&&(this.originalMaterial=n.material,Array.isArray(n.material)||(n.material=n.material.clone(),n.material&&n.material.emissive&&(n.material.emissive.b=.2))),this.selected=A,this.selectedParent||(this.selectedParent=A.parent),this.selectedMesh=n,this.controller=t,this.interactable=g,this.isCloseGrab=o,this.didReparent=!1,this.sync=i,this.grabTime=t.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=tA.addNewComponent(this.selected,wE),this.rigidbodies=tA.getComponentsInChildren(this.selected,Wt),ue(this.positionSource,this.lastControllerWorldPos);const B=()=>o?this.lastControllerWorldPos.clone():I.point.clone();this.grabDistance=B().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(B());const Q=t.isUsingHands&&o?this.controller.getWristQuaternion().clone():t.rayRotation.clone();Ti(this.selected,this.localQuaternionToGrab).premultiply(Q.invert());const E=this.controller.webXR.Rig;return E&&this.rigPositionLastFrame.copy(ue(E)),iI.Add(t.context,this.selected),kI.Register(this),this.sync&&(this.sync.fastMode=!0),(C=kI.Events.DidTake)==null||C.forEach(h=>h(this,a)),this}free(){var t,A,e,i;if(!this.selected)return;const g={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(t=kI.Events.WillFree)==null||t.forEach(s=>s(this,g)),iI.Remove(this.controller.context,this.selected),kI.Remove(this),this.sync&&(this.sync.fastMode=!1);const I=this.selectedMesh;I&&this.originalMaterial&&I.material&&(I.material=this.originalMaterial);const o=this.selected;if(this.didReparent&&o.parent){const s=this.selectedParent;s?s.attach(o):(A=this.controller)==null||A.context.scene.attach(o)}if((e=this.usageMarker)==null||e.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const s of this.rigidbodies)s.wakeUp(),s.setVelocity(s.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(i=kI.Events.DidFree)==null||i.forEach(s=>s(this,g))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),ue(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const t=this.controller.webXR.Rig;if(t){const A=ue(t),e=this.rigPositionLastFrame.sub(A);this.controllerPosDelta.add(e),this.rigPositionLastFrame.copy(A)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var t;if(this.rigidbodies)for(const A of this.rigidbodies)A.resetVelocities();if(this.sync&&this.controller&&this.controller.context.connection.isInRoom&&this.controller.context.time.time-this.grabTime>3&&this.sync.hasOwnership()===!1&&(console.log("no ownership, will leave",this.sync.guid),this.free()),!(this.interactable&&!this.interactable.canGrab)){if(!this.didReparent&&this.selected&&this.controller){const A=((t=this.controller.webXR.Rig)==null?void 0:t.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let e=1;this.controller.type===0&&(e=Math.max(0,1+this.totalChangeAlongDirection*2/A),e=e*e*e),this.grabDistance/A<.8&&(e=1),this.targetDir||(this.targetDir=new S),this.targetDir.set(0,0,-this.grabDistance*e);const i=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),g=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=g.clone()),this.quaternionLerp.slerp(g,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),pI(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(i),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(ue(this.selected)),i.sub(this.localPositionOffsetToGrab_worldSpace)),Ci(this.selected,i)}if(this.rigidbodies!=null)for(const A of this.rigidbodies)A.wakeUp();JI.markDirty(this.selected,!0)}}};let AC=kI;r(AC,"Events",{}),r(AC,"Current",[]);var lgA=Object.defineProperty,dgA=Object.getOwnPropertyDescriptor,bR=(t,A,e,i)=>{for(var g=i>1?void 0:i?dgA(A,e):A,I=t.length-1,o;I>=0;I--)(o=t[I])&&(g=(i?o(A,e,g):o(g))||g);return i&&g&&lgA(A,e,g),g};class aB extends UA{constructor(){super(...arguments),r(this,"objectBounds",!1),r(this,"color"),r(this,"isGizmo",!0),r(this,"_gizmoObject",null),r(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!Mc||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new CD(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=oY(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),WI.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){for(var A;this._boxHelper;)(A=this._boxHelper)==null||A.update(),yield}}bR([y()],aB.prototype,"objectBounds",2),bR([y(wA)],aB.prototype,"color",2),bR([y()],aB.prototype,"isGizmo",2);const pgA=oA("debugrig");class Qy extends UA{awake(){if(pgA){const A=new vA;A.position.y+=.5,this.gameObject.add(A);const e=A.addNewComponent(aB);e&&(e.isGizmo=!1)}}}class UE{constructor(){r(this,"bb",null),r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}w(){return this.bb.readFloat32(this.bb_pos+12)}static sizeOf(){return 16}static createVec4(A,e,i,g,I){return A.prep(4,16),A.writeFloat32(I),A.writeFloat32(g),A.writeFloat32(i),A.writeFloat32(e),A.offset()}}class xg{constructor(){r(this,"bb",null),r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsVrUserStateBuffer(A,e){return(e||new xg).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsVrUserStateBuffer(A,e){return A.setPosition(A.position()+kD),(e||new xg).__init(A.readInt32(A.position())+A.position(),A)}guid(A){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}time(){const A=this.bb.__offset(this.bb_pos,6);return A?this.bb.readInt64(this.bb_pos+A):this.bb.createLong(0,0)}avatarId(A){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,A):null}position(A){const e=this.bb.__offset(this.bb_pos,10);return e?(A||new zI).__init(this.bb_pos+e,this.bb):null}rotation(A){const e=this.bb.__offset(this.bb_pos,12);return e?(A||new UE).__init(this.bb_pos+e,this.bb):null}scale(){const A=this.bb.__offset(this.bb_pos,14);return A?this.bb.readFloat32(this.bb_pos+A):0}posLeftHand(A){const e=this.bb.__offset(this.bb_pos,16);return e?(A||new zI).__init(this.bb_pos+e,this.bb):null}posRightHand(A){const e=this.bb.__offset(this.bb_pos,18);return e?(A||new zI).__init(this.bb_pos+e,this.bb):null}rotLeftHand(A){const e=this.bb.__offset(this.bb_pos,20);return e?(A||new UE).__init(this.bb_pos+e,this.bb):null}rotRightHand(A){const e=this.bb.__offset(this.bb_pos,22);return e?(A||new UE).__init(this.bb_pos+e,this.bb):null}static startVrUserStateBuffer(A){A.startObject(10)}static addGuid(A,e){A.addFieldOffset(0,e,0)}static addTime(A,e){A.addFieldInt64(1,e,A.createLong(0,0))}static addAvatarId(A,e){A.addFieldOffset(2,e,0)}static addPosition(A,e){A.addFieldStruct(3,e,0)}static addRotation(A,e){A.addFieldStruct(4,e,0)}static addScale(A,e){A.addFieldFloat32(5,e,0)}static addPosLeftHand(A,e){A.addFieldStruct(6,e,0)}static addPosRightHand(A,e){A.addFieldStruct(7,e,0)}static addRotLeftHand(A,e){A.addFieldStruct(8,e,0)}static addRotRightHand(A,e){A.addFieldStruct(9,e,0)}static endVrUserStateBuffer(A){return A.endObject()}static finishVrUserStateBufferBuffer(A,e){A.finish(e)}static finishSizePrefixedVrUserStateBufferBuffer(A,e){A.finish(e,void 0,!0)}}const G2=oA("debugxr"),vl=oA("debugavatar"),LR="VRUS";jk(LR,xg.getRootAsVrUserStateBuffer);function xR(){return new Date().getTime()}function ugA(t){let A=t&4294967295,e=t/Math.pow(2,32)&1048575;return cC.create(A,e)}const Ey=class{constructor(t){r(this,"guid"),r(this,"time"),r(this,"avatarId"),r(this,"position",new S),r(this,"rotation",new ce),r(this,"scale",1),r(this,"posLeftHand",new S),r(this,"posRightHand",new S),r(this,"rotLeftHand",new xA),r(this,"rotRightHand",new xA),this.guid=t}update(t,A,e,i,g){var I,o,s,C,a,n;this.time=xR(),this.avatarId=g,this.position.set(A.x,A.y,A.z),t&&this.position.applyMatrix4(t.matrixWorld);let B=Ey.quat0;const Q=Ey.quat1;B.set(e.x,e.y,e.z,e.w),B=B.multiplyQuaternions(B,Ey.invertRotation),t&&(t.getWorldQuaternion(Q),B.multiplyQuaternions(Q,B)),this.rotation.set(B.x,B.y,B.z,B.w),this.scale=t.scale.x;const E=(I=i.LeftController)==null?void 0:I.controllerGrip;E&&(E.getWorldPosition(this.posLeftHand),E.getWorldQuaternion(this.rotLeftHand));const h=(o=i.RightController)==null?void 0:o.controllerGrip;if(h&&(h.getWorldPosition(this.posRightHand),h.getWorldQuaternion(this.rotRightHand)),(C=(s=i.LeftController)==null?void 0:s.hand)!=null&&C.visible){const l=i.LeftController.wrist;l&&(l.getWorldPosition(this.posLeftHand),l.getWorldQuaternion(this.rotLeftHand))}if((n=(a=i.RightController)==null?void 0:a.hand)!=null&&n.visible){const l=i.RightController.wrist;l&&(l.getWorldPosition(this.posRightHand),l.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(t,A){t.clear();const e=t.createString(this.guid),i=t.createString(this.avatarId);xg.startVrUserStateBuffer(t),xg.addGuid(t,e),xg.addTime(t,ugA(this.time)),xg.addAvatarId(t,i),xg.addPosition(t,zI.createVec3(t,this.position.x,this.position.y,this.position.z)),xg.addRotation(t,UE.createVec4(t,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),xg.addScale(t,this.scale),xg.addPosLeftHand(t,zI.createVec3(t,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),xg.addPosRightHand(t,zI.createVec3(t,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),xg.addRotLeftHand(t,UE.createVec4(t,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),xg.addRotRightHand(t,UE.createVec4(t,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const g=xg.endVrUserStateBuffer(t);t.finish(g,LR);const I=t.asUint8Array();A.sendBinary(I)}setFromBuffer(t,A){if(!t)return;this.guid=t,this.time=A.time().toFloat64();const e=A.avatarId();e&&(this.avatarId=e);const i=A.position();i&&this.position.set(i.x(),i.y(),i.z());const g=A.rotation();g&&this.rotation.set(g.x(),g.y(),g.z(),g.w());const I=A.posLeftHand();I&&this.posLeftHand.set(I.x(),I.y(),I.z());const o=A.posRightHand();o&&this.posRightHand.set(o.x(),o.y(),o.z());const s=A.rotLeftHand();s&&this.rotLeftHand.set(s.x(),s.y(),s.z(),s.w());const C=A.rotRightHand();C&&this.rotRightHand.set(C.x(),C.y(),C.z(),C.w()),this.scale=A.scale()}};let Ca=Ey;r(Ca,"invertRotation",new xA().setFromAxisAngle(new S(0,1,0),Math.PI)),r(Ca,"quat0",new xA),r(Ca,"quat1",new xA);class bl extends UA{constructor(){super(...arguments),r(this,"webXR",null),r(this,"debugAvatarUser",null),r(this,"voip",null),r(this,"tempState",new Ca("")),r(this,"_removeAvatarsList",[]),r(this,"eventSub_ConnectionEvent",null),r(this,"eventSub_WebXRStartEvent",null),r(this,"eventSub_WebXREndEvent",null),r(this,"eventSub_WebXRUpdateEvent",null),r(this,"avatars",{}),r(this,"localAvatar",null),r(this,"k_LocalAvatarNoNetworkingGuid","local"),r(this,"ownership",null),r(this,"xrState",null),r(this,"builder",new Rh(1024))}async awake(){if(this.webXR||(this.webXR=tA.getComponent(this.gameObject,Se)),this.webXR||(this.webXR=tA.findObjectOfType(Se,this.context)),!this.webXR&&(console.log("Missing webxr component"),this.webXR=tA.findObjectOfType(Se,this.context),!this.webXR)){console.error("Could not find webxr component");return}if(this.voip||(this.voip=tA.findObjectOfType(Ka,this.context)),vl){const A="debug-avatar-"+vl,e=new Fn(this.context,A,this.webXR);if(this.debugAvatarUser=e,typeof vl=="string"&&vl.length>0)if(await e.setAvatarOverride(vl)){const i=new Ca(A);i.position.y+=1;const g=.5;i.posLeftHand.y+=g,i.posLeftHand.x+=g,i.posRightHand.y+=g,i.posRightHand.x-=g,e.tryUpdate(i,0)}else e.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=tA.getComponent(this.gameObject,Se),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),Se.addEventListener(kt.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),Se.addEventListener(kt.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Se.addEventListener(kt.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen($t.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",A=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",A=>{const e=A.id!==null&&A.id!==void 0;if(e&&(console.log("webxr user left evt"),e)){const i=this.avatars[A.id];i?.destroy(),this.avatars[A.id]=void 0}}),this.context.connection.beginListenBinary(LR,A=>{const e=A.guid();if(!e)return;const i=A.time().toFloat64(),g=this.tempState;g.setFromBuffer(e,A);const I=this.onTryGetAvatar(e,i);I?.tryUpdate(g,i)}),this.context.connection.beginListen("vr-session-update",A=>{const e=A.guid,i=A.time,g=this.onTryGetAvatar(e,i);g?.tryUpdate(A,i)})}onTryGetAvatar(A,e){if(A===this.context.connection.connectionId)return null;const i=new Date().getTime()-e;if(i>5e3)return G2&&console.log("old data",i,A),null;let g=this.avatars[A];if(g===void 0)try{console.log("create new avatar");const I=new Fn(this.context,A,this.webXR);g=I,this.avatars[A]=I}catch(I){this.avatars[A]=null,console.error(I)}return g}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen($t.JoinedRoom,this.eventSub_ConnectionEvent),Se.removeEventListener(kt.XRStarted,this.eventSub_WebXRStartEvent),Se.removeEventListener(kt.XRUpdate,this.eventSub_WebXRUpdateEvent),Se.removeEventListener(kt.XRStopped,this.eventSub_WebXREndEvent)}update(){const A=xR();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=A),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const e in this.avatars){const i=this.avatars[e];i&&i.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const A=xR();for(const e in this.avatars){const i=this.avatars[e];if(!i){this._removeAvatarsList.push(e);continue}A-i.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),i.destroy(),this.avatars[e]=void 0)}for(const e of this._removeAvatarsList)delete this.avatars[e];this._removeAvatarsList.length=0}buildLocalAvatar(){var A;if(this.localAvatar)return;const e=((A=this.context.connection)==null?void 0:A.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new Fn(this.context,e,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var A,e,i;G2&&console.log("Hey you are connected as "+this.context.connection.connectionId),((A=this.localAvatar)==null?void 0:A.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((e=this.localAvatar)==null||e.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(i=this.ownership)==null||i.freeOwnership(),this.ownership=null)}onXRSessionStart(A){var e,i,g;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((e=this.localAvatar)==null||e.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(i=this.ownership)==null||i.freeOwnership(),this.ownership=null,this.avatars)for(const I in this.avatars)(g=this.avatars[I])==null||g.updateFlags()}onXRSessionEnded(A){var e;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((e=this.localAvatar)==null||e.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(A){this.xrState??(this.xrState=new Ca(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new xD(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:e,xr:i,rig:g}=A,I=e.getViewerPose(i.getReferenceSpace());if(!I)return;const o=I?.transform,s=o.position,C=o.orientation;this.xrState.update(g,s,C,this.webXR,this.getAvatarId()),this.localAvatar&&(this.context.connection.connectionId&&(this.localAvatar.guid=this.context.connection.connectionId),this.localAvatar.tryUpdate(this.xrState,0)),!(this.ownership&&!this.ownership.hasOwnership&&this.context.connection.isConnected&&(this.context.time.frameCount%120===0&&this.ownership.requestOwnership(),!this.ownership.hasOwnership))&&(!this.context.connection.isConnected||!this.context.connection.connectionId||this.xrState.sendAsBuffer(this.builder,this.context.connection))}getAvatarId(){return oA("avatar")??null}}var DgA=Object.defineProperty,wgA=Object.getOwnPropertyDescriptor,FE=(t,A,e,i)=>{for(var g=i>1?void 0:i?wgA(A,e):A,I=t.length-1,o;I>=0;I--)(o=t[I])&&(g=(i?o(A,e,g):o(g))||g);return i&&g&&DgA(A,e,g),g};const TR=oA("debugwebxr");async function M2(){return Rp()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function R2(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let Ll=!1,xl=!1;M2().then(t=>Ll=t),R2().then(t=>xl=t);var kt=(t=>(t.XRStarted="xrStarted",t.XRStopped="xrStopped",t.XRUpdate="xrUpdate",t.RequestVRSession="requestVRSession",t.ModifyAROptions="modify-ar-options",t))(kt||{}),NE;const Oi=(NE=class extends UA{constructor(){super(...arguments),r(this,"enableVR",!0),r(this,"enableAR",!0),r(this,"defaultAvatar"),r(this,"handModelPath",""),r(this,"createVRButton",!0),r(this,"createARButton",!0),r(this,"controllers",[]),r(this,"rig"),r(this,"isInit",!1),r(this,"_requestedAR",!1),r(this,"_requestedVR",!1),r(this,"_isInAR",!1),r(this,"_isInVR",!1),r(this,"_arButton"),r(this,"_vrButton"),r(this,"webAR",null),r(this,"_transformOrientation",new xA),r(this,"_currentHeadPose",null),r(this,"_originalCameraParent",null),r(this,"_originalCameraPosition",new S),r(this,"_originalCameraRotation",new xA),r(this,"_originalXRRigParent",null),r(this,"_originalXRRigPosition",new S),r(this,"_originalXRRigRotation",new xA),r(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(Ll||xl)}static get IsARSupported(){return Ll}static get IsVRSupported(){return xl}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(t,A){return this.events.addEventListener(t,A),A}static removeEventListener(t,A){return this.events.removeEventListener(t,A),A}static dispatchEvent(t,A){this.events.dispatchEvent({type:t,detail:A})}static createVRButton(t,A){Oi.XRSupported?t.__internalAwake():console.warn("WebXR is not supported on this device");const e={optionalFeatures:Oi.OptionalFeatures_VR},i=HM.createButton(t.context.renderer,e);return i.classList.add("webxr-ar-button"),i.classList.add("webxr-button"),this.resetButtonStyles(i),(A?.registerClick??!0)&&i.addEventListener("click",t.onClickedVRButton.bind(t)),i}static createARButton(t,A){var e;t.__internalAwake();const i=(e=t.webAR)==null?void 0:e.getAROverlayContainer(),g={optionalFeatures:[...this.OptionalFeatures_AR]};i?(g.domOverlay={root:i},g.optionalFeatures.push("dom-overlay"),g.optionalFeatures.push("hit-test")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const I=G$.createButton(t.context.renderer,g,this.onModifyAROptions.bind(this));return I.classList.add("webxr-ar-button"),I.classList.add("webxr-button"),Oi.resetButtonStyles(I),(A?.registerClick??!0)&&I.addEventListener("click",t.onClickedARButton.bind(t)),I}static onModifyAROptions(t){Oi.dispatchEvent("modify-ar-options",t)}static resetButtonStyles(t){t&&(t.style.position="",t.style.bottom="",t.style.left="")}endSession(){const t=this.context.renderer.xr.getSession();t&&t.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var t,A;return this.controllers.length>0&&((t=this.controllers[0].input)==null?void 0:t.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((A=this.controllers[1].input)==null?void 0:A.handedness)==="left"?this.controllers[1]:null}get RightController(){var t,A;return this.controllers.length>0&&((t=this.controllers[0].input)==null?void 0:t.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((A=this.controllers[1].input)==null?void 0:A.handedness)==="right"?this.controllers[1]:null}get ARButton(){return this._arButton}get VRButton(){return this._vrButton}get IsInVR(){return this._isInVR}get IsInAR(){return this._isInAR}awake(){if(this.defaultAvatar&&typeof this.defaultAvatar=="string"&&(this.defaultAvatar=Kg.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!tA.findObjectOfType(bl,this.context)){const t=tA.addNewComponent(this.gameObject,bl,!1);t.webXR=this}this.webAR=new Yl(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(Do("WebXR only works on https"),console.warn("WebXR only works on https. https://engine.needle.tools/docs/xr.html"))}onEnable(){if(this.isInit||!this.enableAR&&!this.enableVR)return;this.isInit=!0,this.context.renderer.xr.enabled=!0,Oi.XRSupported;let t,A;const e=document.createElement("div");e.classList.add("webxr-buttons"),e.style.cssText=`
|
|
5009
|
+
`&&t.length>1&&E2([e],t[t.length-2]),A.offsetX}function UiA(t){if(!t[0])return 0;let A=[],e;for(let i=0;i<t.length;i++){const g=t[i];if(g.char&&B2[g.char]&&t.length>i){A.push(g),e=t[i+1];continue}break}h2(A,e),A=[],e=null;for(let i=t.length-1;i>0;i--){const g=t[i];if(g.char&&B2[g.char]&&i>0){A.push(g),e=t[i-1];continue}break}return E2(A,e),t[0].offsetX}function FiA(t){return t[0]?t[0].offsetX:0}function E2(t,A){if(A)for(let e=0;e<t.length;e++){const i=t[e];i.fontFactor=0,i.offsetX=A.offsetX+A.cumulativeWidth,i.cumulativeWidth=0}}function h2(t,A){if(A)for(let e=0;e<t.length;e++){const i=t[e];i.fontFactor=0,i.offsetX=A.offsetX,i.cumulativeWidth=0}}function c2(t,A,e,i){if(i=i||0,!t[A])return i;const g=t[A];return g.lineBreak?i+g.xadvance:c2(t,A+1,e,i+g.xadvance+g.xoffset+g.kerning+e.LETTERSPACING)}function NiA(t,A,e,i){return!t||!t.char||A+e<i.INNER_WIDTH?!1:i.BREAKON.indexOf(t.char)>-1}class l2 extends EH{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._fontSize._needsProcess=!0,A._layouter._needsProcess=!0}}class d2 extends Lt{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(A){this._value=this._inheritedInput,A._font._fontVariant&&(A._bounds._needsProcess=!0,A._layouter._needsProcess=!0)}process(A){if(!A._font._fontVariant||!A._font._fontVariant.isReady)return;const e=this._value/A._font._fontVariant.typographic.size,i=A._inlines._value;for(let g=0;g<i.length;g++){const I=i[g];I.resetOffsets(),I.fontSize=this._value,I.fontFactor=e}}get value(){return this._value}}class p2 extends hH{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(A,e){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(A)),A._layouter._needsUpdate=!0}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class KiA extends p2{constructor(){super(),this._value="inherit"}}class JiA extends $w{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._parent._value._layouter._needsProcess=!1}process(A){if(this._value!=="none"){const e=A._whiteSpace._whiteSpacedContent,i=A._inlines._value;for(let g=1;g<i.length;g++){const I=e[g-1]+e[g];i[g].kerning=A._font._fontVariant.getKerningAmount(I)}}}}class u2 extends lt{constructor(){super("children",null,!1),this._uis=[]}update(A,e){}process(A){}_compute(A){}dispose(){}}function qiA(t,A=!1){const e=t[0].index!==null,i=new Set(Object.keys(t[0].attributes)),g=new Set(Object.keys(t[0].morphAttributes)),I={},o={},s=t[0].morphTargetsRelative,C=new OA.BufferGeometry;let a=0;for(let n=0;n<t.length;++n){const B=t[n];let Q=0;if(e!==(B.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const E in B.attributes){if(!i.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+'. All geometries must have compatible attributes; make sure "'+E+'" attribute exists among all geometries, or in none of them.'),null;I[E]===void 0&&(I[E]=[]),I[E].push(B.attributes[E]),Q++}if(Q!==i.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". Make sure all geometries have the same number of attributes."),null;if(s!==B.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const E in B.morphAttributes){if(!g.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". .morphAttributes must be consistent throughout all geometries."),null;o[E]===void 0&&(o[E]=[]),o[E].push(B.morphAttributes[E])}if(C.userData.mergedUserData=C.userData.mergedUserData||[],C.userData.mergedUserData.push(B.userData),A){let E;if(e)E=B.index.count;else if(B.attributes.position!==void 0)E=B.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+n+". The geometry must have either an index or a position attribute"),null;C.addGroup(a,E,n),a+=E}}if(e){let n=0;const B=[];for(let Q=0;Q<t.length;++Q){const E=t[Q].index;for(let h=0;h<E.count;++h)B.push(E.getX(h)+n);n+=t[Q].attributes.position.count}C.setIndex(B)}for(const n in I){const B=D2(I[n]);if(!B)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+n+" attribute."),null;C.setAttribute(n,B)}for(const n in o){const B=o[n][0].length;if(B===0)break;C.morphAttributes=C.morphAttributes||{},C.morphAttributes[n]=[];for(let Q=0;Q<B;++Q){const E=[];for(let l=0;l<o[n].length;++l)E.push(o[n][l][Q]);const h=D2(E);if(!h)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+n+" morphAttribute."),null;C.morphAttributes[n].push(h)}}return C}function D2(t){let A,e,i,g=0;for(let s=0;s<t.length;++s){const C=t[s];if(C.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(A===void 0&&(A=C.array.constructor),A!==C.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=C.itemSize),e!==C.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(i===void 0&&(i=C.normalized),i!==C.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;g+=C.array.length}const I=new A(g);let o=0;for(let s=0;s<t.length;++s)I.set(t[s].array,o),o+=t[s].array.length;return new OA.BufferAttribute(I,e,i)}class viA extends lt{constructor(){super("renderer")}render(A){if(!A._inlines._value||!A._inlines._value.length)return;const e=A._inlines._value.map(g=>A._font._fontVariant.getGeometricGlyph(g,A).translate(g.offsetX,g.offsetY,0)),i=qiA(e);A.setFontMesh(new OA.Mesh(i,A.fontMaterial)),A._fontMesh.renderOrder=1/0}}class biA extends AR{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(A){this._value=this._inheritedInput,A._layouter._needsProcess=!0}}class bh extends Kl{constructor(A={}){const e={};bh.definePropertiesValues(e,A),super(e,A),r(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0}),bh.init(this)}add(A){const e=[];for(let i=0;i<arguments.length;i++){const g=arguments[i];!g.isUI||g.isInline?(e.push(g),g.position.z=.005):console.warn("Block element can only contain Box elements.",g)}return super.add(...e)}set textContent(A){this._textContent.value=A}get textContent(){return this._textContent._value}set invertAlpha(A){this._invertAlpha.value=A}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(A,e){A.children||(A.children=u2),A.textContent||(A.textContent=piA),A.glyphs||(A.glyphs=DiA),A.inlines||(A.inlines=uiA),A.layouter||(A.layouter=C2),A.renderer||(A.renderer=viA),A.fontFamily||(A.fontFamily=r2),A.fontWeight||(A.fontWeight=n2),A.fontStyle||(A.fontStyle=a2),A.fontSize||(A.fontSize=d2),A.color||(A.color=wiA),A.backgroundColor||(A.backgroundColor=yiA),A.lineBreak||(A.lineBreak=s2),A.letterSpacing||(A.letterSpacing=l2),A.whiteSpace||(A.whiteSpace=KR),A.segments||(A.segments=KiA),A.textAlign||(A.textAlign=biA),A.fontKerning||(A.fontKerning=JiA)}static init(A){Object.defineProperties(A,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class LiA extends tH{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}update(A,e){this._needsUpdate=!1;for(let i=A.children.length-1;i>=0;i--){const g=A.children[i];g.isUI&&(A.remove(g),g.clear())}A._children._uis=[],this._value&&A.add(new bh({name:"anonymousInline",textContent:this._value}))}}class xiA extends Array{constructor(...A){super(...A),this.width=0,this.height=0}}class TiA extends lt{constructor(){super("layouter",null,!1),this._value=null}update(A,e){}process(A){let e=A._width._value;A._width._auto?e=1/0:e=A._bounds._innerWidth;const i=A._lineHeight._value,g=new xiA(new o2);let I=0;A._children._inlines.forEach(B=>{if(!B._inlines.value)return;this._resetInlines(B);const Q=B._fontSize._value,E=B._letterSpacing._value*Q,h=B._whiteSpace._value,l=B._lineBreak._value,d={WHITESPACE:h,LETTERSPACING:E,BREAKON:l,INNER_WIDTH:e},c=B._whiteSpace._inlineWrapper;I+=B._margin._value.w+B._padding._value.w,B._inlines.value.forEach((u,p,D)=>{const w=g[g.length-1];if(c(D,p,I,d)){if(g.push(new o2(u)),u.offsetX=u.xoffset,u.width===0){I=0;return}u.cumulativeWidth=u.xadvance+E,I=u.cumulativeWidth;return}g[g.length-1].push(u),u.offsetX=I+u.xoffset+u.kerning,u.cumulativeWidth=u.xadvance+u.kerning+E,I+=u.cumulativeWidth,w.length-1===1&&w[w.length-2].width===0&&(u.offsetX-=u.xoffset,I-=u.xoffset)}),I+=B._margin._value.y+B._padding._value.y});const o=A._whiteSpace._inlineCollapser;let s=0,C=0,a=0;g.forEach((B,Q)=>{const E=o(B);let h=0,l=0;if(B.forEach(d=>{h=Math.max(h,d.lineHeight),l=Math.max(l,d.lineBase),d.offsetX-=E}),B.lineHeight=h,B.lineBase=l,Q===0?a=-(h*i-h)*.5:a-=g[Q-1].lineHeight*i,B.y=a,B.x=0,B.forEach(d=>{d.offsetY=a-d.anchor,d.lineHeight<B.lineHeight&&(d.offsetY-=B.lineBase-d.lineBase)}),C+=B.lineHeight*i,B.width=0,B[0]){const d=B[B.length-1];B.width=d.offsetX+d.cumulativeWidth+d.paddingRight+d.marginRight+B[0].offsetX,s=Math.max(s,B.width)}}),g.height=C,g.width=s,this._value=g,e===1/0&&A._bounds.setChildrenWidth(A,g.width),A._height._auto&&A._bounds.setChildrenHeight(A,g.height);const n=A._parent._value;n&&(n._autoSize._needsProcess=!0,n._flexDirection._needsProcess=!0),A._inlineJustificator._needsProcess=!0,A._textAlign._needsProcess=!0,A._overflow._needsUpdate=!0}_resetInlines(A){A._fontSize.process(A)}}class YiA extends AR{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput,this._needsProcess=!0}process(A){HiA(A),A._renderer._needsRender=!0}}function HiA(t){const A=t._layouter._value,e=t._textAlign._value,i=t._bounds._innerWidth;for(let g=0;g<A.length;g++){const I=A[g],o=OiA(t,I,g===A.length-1),s=t._padding._value,C=t._borderWidth._value,a=(-s.w+s.y)/2+(-C.w+C.y)/2;I.x+=o;for(let n=0;n<I.length;n++)I[n].offsetX+=o-a}if(e.indexOf("justify")===0)for(let g=0;g<A.length;g++){const I=A[g];if(e.indexOf("-")!==-1&&g===A.length-1)return;const o=i-I.width;if(o<=0)return;let s=0;for(let B=1;B<I.length-1;B++)s+=I[B].char===" "?1:0;const C=o/s;let a=1;e==="justify-right"&&(I.reverse(),a=-1);let n=0;for(let B=1;B<=I.length-1;B++){const Q=I[B];Q.offsetX+=n*a,n+=Q.char===" "?C:0}e==="justify-right"&&I.reverse()}}function OiA(t,A,e){switch(t._textAlign._value){case"justify-left":case"justify":case"left":return-t._bounds._innerWidth/2;case"justify-right":case"right":return-A.width+t._bounds._innerWidth/2;case"center":return-A.width/2;case"justify-center":return e?-A.width/2:-t._bounds._innerWidth/2;default:console.warn(`textAlign: '${t._textAlign._value}' is not valid`)}}class _iA extends eR{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput}}class PiA extends BH{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class jiA extends $w{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A)}}class WiA extends t2{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class ViA extends lt{constructor(){super("children",null,!1),r(this,"_sortOrder",(A,e)=>A._order._value<e._order._value?-1:A._order._value>e._order._value?1:this._uis.indexOf(A)<this._uis.indexOf(e)?-1:1),this._uis=[],this._inlines=[],this._boxes=[]}update(A,e){this._compute(A),this._needsProcess=!0}process(A){this._compute(A),A._overflow._needsRender=!0}_compute(A){this._uis=A.children.filter(e=>e.visible&&e.isUI),this._inlines=this._uis.filter(e=>e.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class ziA extends lt{constructor(){super("autosize")}process(A){if(A._layouter._value&&A._layouter._value.length){const e=A._layouter._value,i=A._padding._value,g=A._borderWidth._value;A._width._auto&&A._bounds.setOffsetWidth(A,e.width+i.w+i.y+g.w+g.y),A._height._auto&&A._bounds.setOffsetHeight(A,e.height+i.x+i.z+g.x+g.z)}}}class ZiA extends I2{constructor(){super("renderer"),this._needsUpdate=!1}render(A){super.render(A);for(const e of A._children._inlines)e._renderer.render(e);A.performAfterUpdate()}}class yp extends Dp{constructor(A={},e={}){yp.definePropertiesValues(e,A),super(e,A),yp.init(this)}add(A){const e=[];let i=!1;for(let g=0;g<arguments.length;g++){const I=arguments[g];!I.isUI||I.isInline?(I.isInline&&(i=!0),e.push(I)):console.warn("Block element can only contain Box elements.",I)}return e.length>0&&super.add(...e),i&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(A){this._textContent.value=A}get textContent(){return super.textContent}set invertAlpha(A){this._invertAlpha.value=A}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(A,e){A.flexDirection=_iA,A.justifyContent=tR,A.alignItems=$M,A.bounds=WiA,A.autoSize=ziA,A.renderer=ZiA,A.children||(A.children=ViA),A.textContent||(A.textContent=LiA),A.layouter||(A.layouter=TiA),A.lineHeight||(A.lineHeight=PiA),A.textAlign||(A.textAlign=YiA),A.whiteSpace||(A.whiteSpace=KR),A.fontKerning||(A.fontKerning=jiA),A.segments||(A.segments=p2),e.width||(e.width="100%"),e.fontSide||(e.fontSide=0)}static init(A){Object.defineProperties(A,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class XiA extends lt{constructor(){super("inlines",null,!1),this._value=[]}process(A){this._value[0].paddingLeft=A._padding._value.w,this._value[0].marginLeft=A._margin._value.w;const e=this._value.length-1;this._value[e].paddingRight=A._padding._value.y,this._value[e].marginRight=A._margin._value.y}}class $iA extends lt{constructor(){super("renderer")}render(A){A._backgroundMesh||A.setBackgroundMesh(new g2(A)),A._backgroundMesh.position.x=A._inlines._value[0].offsetX+A._inlines._value[0].width/2,A._backgroundMesh.position.y=A._inlines._value[0].offsetY+A._inlines._value[0].lineBase/2,A._bounds.render(A)}}class AgA extends lt{constructor(){super("bounds",null,!1),this._size=new OA.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(A,e){this.output(e),this._needsProcess=!0}process(A){this._offsetWidth=this._innerWidth=A._inlines._value[0].width,this._offsetHeight=this._innerHeight=A._inlines._value[0].height,this._needsRender=!0,A._borderWidth._needsRender=!0,A._borderRadius._needsRender=!0}render(A){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(A){A.size=this._size}}class Sp extends Kl{constructor(A={}){const e={};Sp.definePropertiesValues(e,A),super(e,A),Sp.init(this)}clear(){for(const A of this._inlines._value)A.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new OA.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(A){const e=[];for(let i=0;i<arguments.length;i++){const g=arguments[i];g.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",g):(e.push(g),g.position.z=.005)}return super.add(...e)}static definePropertiesValues(A,e){A.children||(A.children=u2),A.bounds||(A.bounds=AgA),A.inlines||(A.inlines=XiA),A.layouter||(A.layouter=C2),A.renderer||(A.renderer=$iA),A.fontFamily||(A.fontFamily=r2),A.fontWeight||(A.fontWeight=n2),A.fontStyle||(A.fontStyle=a2),A.fontSize||(A.fontSize=d2),A.backgroundColor||(A.backgroundColor=$Y),A.lineBreak||(A.lineBreak=s2),A.letterSpacing||(A.letterSpacing=l2),A.whiteSpace||(A.whiteSpace=KR),A.fontKerning||(A.fontKerning=$w),e.backgroundSize||(e.backgroundSize="cover"),e.width||(e.width="100%"),e.height||(e.height="100%"),e.boxSizing||(e.boxSizing="border-box")}static init(A){Object.defineProperties(A,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),A._inlines._value=[new egA(A)],A.backgroundMaterial=new e2,A._renderer.render(A)}}class egA extends sH{constructor(A){super(),this._uiElement=A}get xadvance(){const A=this._uiElement._padding._value,e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.w+A.y+e.value}get width(){const A=this._uiElement._width;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get height(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get anchor(){return this.height}get lineHeight(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get lineBase(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}clear(){this._uiElement=null}}class w2{constructor(A){this._subject=A}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const y2=()=>Cy.update(),S2={BaseProperty:lt,Block:wp,Text:yp,Inline:bh,InlineBlock:Sp,MeshUIBaseElement:Kl,FontLibrary:sB,update:y2,MSDFFontMaterialUtils:Oo,ShaderChunkUI:A2,Behavior:w2,FontVariant:ml};typeof global<"u"&&(global.ThreeMeshUI=S2);const tgA=S2;var igA=fi.w8,f2=fi.cg,JR=fi.gO,ggA=fi.wb,qR=fi.zV,IgA=fi.HS,ogA=fi.Ec,ny=fi.gF,sgA=fi.ol,CgA=fi.pz,agA=fi.tx,ngA=fi.hj,rgA=fi.FV,BgA=fi.sV,m2=fi.xv,QgA=fi.mx,EgA=fi.gE,hgA=fi.ZP,k2=fi.Vx;const vR=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:igA,Behavior:f2,Block:JR,DefaultValues:ggA,FontLibrary:qR,FontVariant:IgA,InheritableProperty:ogA,Inline:ny,InlineBlock:sgA,InlineGlyph:CgA,MSDFFontMaterialUtils:agA,MaterialTransformers:ngA,MeshUIBaseElement:rgA,ShaderChunkUI:BgA,Text:m2,TypographicFont:QgA,TypographicGlyph:EgA,default:hgA,update:k2},Symbol.toStringTag,{value:"Module"})),cgA=oA("debugshadowcomponents");JR.prototype.interactable={get(){return this.interactive},set(t){this.interactable=t}};const $s=Symbol("shadowDomOwner");class fs extends UA{constructor(){super(...arguments),r(this,"shadowComponent",null),r(this,"_controlsChildLayout",!0),r(this,"_root"),r(this,"_parentComponent")}isRoot(){var A;return((A=this.Root)==null?void 0:A.gameObject)===this.gameObject}get canvas(){const A=this.Root;return A!=null&&A.isCanvas?A:null}markDirty(){ZI.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(A){this._controlsChildLayout=A,this.shadowComponent&&(this.shadowComponent.autoLayout=A)}get Root(){return this._root===void 0&&(this._root=tA.getComponentInParent(this.gameObject,Jl)),this._root}get Canvas(){return this.canvas}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this.shadowComponent=null,this._root=void 0,this._parentComponent=void 0}onEnable(){super.onEnable()}addShadowComponent(A,e){var i;this.removeShadowComponent();const g=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=tA.getComponentInParent(g,fs),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}A.name=this.name+" ("+(this.constructor.name??"UI")+")",A.autoLayout=this._parentComponent.controlsChildLayout,A[$s]=this,this.setShadowComponentOwner(A);let I=!1;if(((i=this.Root)==null?void 0:i.gameObject)===this.gameObject)this.gameObject.add(A);else{let o=this._parentComponent.shadowComponent;o&&(o?.add(A),I=!0)}this.shadowComponent=A,e&&e.shadowComponent&&this.shadowComponent&&e.shadowComponent.add(this.shadowComponent),Mc&&A.add(new YQ(.5)),this.onAfterAddedToScene(),I&&k2(),cgA&&console.log(this.shadowComponent)}set(A){}setShadowComponentOwner(A){if(A&&(A[$s]===void 0||A[$s]===this)&&(A[$s]=this,A.children))for(const e of A.children)this.setShadowComponentOwner(e)}traverseOwnedShadowComponents(A,e,i){if(A&&A[$s]===e){i(A);for(const g of A.children)this.traverseOwnedShadowComponents(g,e,i)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(A){this.shadowComponent&&(this.shadowComponent.interactable=A)}}class Jl extends fs{awake(){super.awake()}}class ME{static getObject(A){const e=A[$s];return e&&(e.isComponent===!0?A=e.gameObject:A=e),A}static isInteractable(A,e){if(e&&(e.canvasGroup=void 0,e.graphic=void 0),A==null||!A.visible||(A=this.getObject(A),!A.visible))return!1;const i=this.tryFindCanvasGroup(A);if(i?.isCanvasGroup===!0&&(e&&(e.canvasGroup=i),i.blocksRaycasts===!1||i.interactable===!1))return!1;const g=Xr(A,I=>{if(I.isGraphic===!0)return I},!1);return e&&g?.isGraphic===!0&&(e.graphic=g),!(g?.raycastTarget===!1||g?.layer===2)}static tryFindCanvasGroup(A){if(!A)return null;const e=Xr(A,i=>{const g=i;if(g.blocksRaycasts!==void 0&&g.interactable!==void 0)return g},!1);return e!==void 0?e:this.tryFindCanvasGroup(A.parent)}}const ql=oA("debugwebxrcontroller");var RE=(t=>(t[t.PhysicalDevice=0]="PhysicalDevice",t[t.Touch=1]="Touch",t))(RE||{}),sa=(t=>(t.SelectStart="select-start",t.SelectEnd="select-end",t.Update="update",t))(sa||{});class ry extends UA{}const Eg=class extends UA{constructor(){super(...arguments),r(this,"webXR"),r(this,"index",-1),r(this,"controllerModel"),r(this,"controller"),r(this,"controllerGrip"),r(this,"hand"),r(this,"handPointerModel"),r(this,"grabbed",null),r(this,"input",null),r(this,"type",0),r(this,"showRaycastLine",!0),r(this,"_wristQuaternion",null),r(this,"movementVector",new S),r(this,"worldRot",new xA),r(this,"joystick",new Z),r(this,"didRotate",!1),r(this,"didTeleport",!1),r(this,"didChangeScale",!1),r(this,"lastHit",null),r(this,"raycastLine",null),r(this,"_raycastHitPoint",null),r(this,"_connnectedCallback",null),r(this,"_disconnectedCallback",null),r(this,"_selectStartEvt",null),r(this,"_selectEndEvt",null),r(this,"_selectionPressed",!1),r(this,"_selectionPressedLastFrame",!1),r(this,"_selectionStartTime",0),r(this,"_selectionEndTime",0),r(this,"_useSmoothing",!0),r(this,"_isConnected",!1),r(this,"rayRotation",new xA),r(this,"_pinchStartTime"),r(this,"selectStartCallback",null),r(this,"lastSelectStartObject",null),r(this,"_didNotEndSelection",!1),r(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const t=new oi(this.geometry),A=t.material;return A.color=this.raycastColor,t.layers.set(2),t.name="line",t.scale.z=1,t}static CreateRaycastHitPoint(){const t=new Yo(.5,22,22),A=new Et({color:this.raycastColor}),e=new fA(t,A);return e.visible=!1,e.layers.set(2),e}static Create(t,A,e,i){const g=e?tA.addNewComponent(e,Eg,!1):new Eg;g.webXR=t,g.index=A,g.type=i;const I=t.context;g.controller=I.renderer.xr.getController(A),g.controllerGrip=I.renderer.xr.getControllerGrip(A),g.controllerModel=this.Factory.createControllerModel(g.controller),g.controllerGrip.add(g.controllerModel),g.hand=I.renderer.xr.getHand(A);const o=new oE;al(o,I),g.webXR.handModelPath&&g.webXR.handModelPath!==""?o.setPath(Ya(t.sourceId,g.webXR.handModelPath)):o.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const s=new L$(g.hand,o);return g.hand.add(s),g.hand.traverse(C=>C.layers.set(2)),g.handPointerModel=new P$(g.hand,g.controller),g.controller.addEventListener("connected",C=>{g.setControllerLayers(g.controllerModel,2),g.setControllerLayers(g.controllerGrip,2),g.setControllerLayers(g.hand,2),setTimeout(()=>{g.setControllerLayers(g.controllerModel,2),g.setControllerLayers(g.controllerGrip,2),g.setControllerLayers(g.hand,2)},1e3)}),g.hand.addEventListener("connected",C=>{var a;if(C.data.hand){t.Rig&&t.Rig.add(g.hand),g.type=0,g.handPointerModel.traverse(B=>B.layers.set(2)),(a=g.handPointerModel.pointerObject)==null||a.traverse(B=>B.layers.set(2));const n=g.hand.joints;if(n)for(const B of Object.keys(n)){const Q=n[B];Q.parent||g.hand.add(Q)}}}),g}static addEventListener(t,A){const e=this.eventSubs[t]??[];e.push(A),this.eventSubs[t]=e}static removeEventListener(t,A){if(!A)return;const e=this.eventSubs[t]??[],i=e.indexOf(A);i>=0&&e.splice(i,1),this.eventSubs[t]=e}get isUsingHands(){var t;return((t=this.input)==null?void 0:t.hand)!=null}get wrist(){if(!this.hand)return null;const t=this.hand.joints;return t?t.wrist:null}getWristQuaternion(){const t=this.wrist;return t?(this._wristQuaternion||(this._wristQuaternion=new xA),Ti(t).multiply(this._wristQuaternion.setFromEuler(new og(-Math.PI/4,0,0)))):null}get selectionDown(){return this._selectionPressed&&!this._selectionPressedLastFrame}get selectionUp(){return!this._selectionPressed&&this._selectionPressedLastFrame}get selectionPressed(){return this._selectionPressed}get selectionClick(){return this._selectionEndTime-this._selectionStartTime<.3}get raycastHitPoint(){return this._raycastHitPoint}get useSmoothing(){return this._useSmoothing}awake(){if(!this.controller){console.warn("Missing Controller!!!",this);return}this._connnectedCallback=this.onSourceConnected.bind(this),this._disconnectedCallback=this.onSourceDisconnected.bind(this),this._selectStartEvt=this.onSelectStart.bind(this),this._selectEndEvt=this.onSelectEnd.bind(this),this.type===1&&(this.controllerGrip.addEventListener("connected",this._connnectedCallback),this.controllerGrip.addEventListener("disconnected",this._disconnectedCallback),this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt))}onDestroy(){var t,A,e;this.type===1&&(this.controllerGrip.removeEventListener("connected",this._connnectedCallback),this.controllerGrip.removeEventListener("disconnected",this._disconnectedCallback),this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),(t=this.hand)==null||t.clear(),(A=this.controllerGrip)==null||A.clear(),(e=this.controller)==null||e.clear()}onEnable(){var t,A,e,i,g;this.hand&&(this.hand.name="Hand"),this.controllerGrip&&(this.controllerGrip.name="ControllerGrip"),this.controller&&(this.controller.name="Controller"),this.raycastLine&&(this.raycastLine.name="RaycastLine;"),this.webXR.Controllers.indexOf(this)<0&&this.webXR.Controllers.push(this),this.raycastLine||(this.raycastLine=Eg.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=Eg.CreateRaycastHitPoint()),(t=this.webXR.Rig)==null||t.add(this.hand),(A=this.webXR.Rig)==null||A.add(this.controllerGrip),(e=this.webXR.Rig)==null||e.add(this.controller),(i=this.webXR.Rig)==null||i.add(this.raycastLine),(g=this.raycastLine)==null||g.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),ql&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var t,A,e,i,g;(t=this.hand)==null||t.removeFromParent(),(A=this.controllerGrip)==null||A.removeFromParent(),(e=this.controller)==null||e.removeFromParent(),(i=this.raycastLine)==null||i.removeFromParent(),(g=this._raycastHitPoint)==null||g.removeFromParent();const I=this.webXR.Controllers.indexOf(this);I>=0&&this.webXR.Controllers.splice(I,1)}onSourceConnected(t){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,t);return}this._isConnected=!0,this.input=t.data,this.type===1&&(this.onSelectStart(),this.createPointerEvent("down"))}onSourceDisconnected(t){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",t);return}this._isConnected=!1,this.type===1&&(this.onSelectEnd(),this.createPointerEvent("up")),this.input=null}createPointerEvent(t){switch(t){case"down":this.context.input.createPointerDown({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break;case"move":break;case"up":this.context.input.createPointerUp({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break}}raycastUpdate(t,A){const e=this.showRaycastLine&&this.type!==1;if(this.type===1)t.visible=!1;else if(this.isUsingHands){t.visible=!this.grabbed&&e,Ci(t,A);const i=this.hand.joints;if(i&&i.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const g=this.getWristQuaternion();g&&this.rayRotation.copy(g)}pI(t,this.rayRotation)}else t.visible=e,pI(t,this.rayRotation),Ci(t,A)}update(){this.context.time.frameCount%60===0&&(this.setControllerLayers(this.controller,2),this.setControllerLayers(this.controllerGrip,2),this.setControllerLayers(this.hand,2));const t=Eg.eventSubs.update;if(t&&t.length>0)for(const i of t)i(this);let A=1;this.type===0?A=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(A=this.context.time.deltaTime/.3),this.rayRotation.slerp(Ti(this.controller),this.useSmoothing?A:1);const e=ue(this.controller);this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine&&this.raycastUpdate(this.raycastLine,e),this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(t){var A,e;if(this.lastHit=null,!t||t.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=t.inputSources[this.index]),!this.input)return;const i=this.webXR.Rig;if(!i)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const g=(e=(A=this.input)==null?void 0:A.gamepad)==null?void 0:e.buttons;switch(this.input.handedness){case"left":this.movementUpdate(i,g);break;case"right":this.rotationUpdate(i,g);break}}movementUpdate(t,A){const e=3*Eg.MovementSpeedFactor,i=2,g=te.clamp01(this.joystick.length()*2),I=this.joystick.x>0?1:-1;let o=Math.pow(this.joystick.x,i);o*=I,o*=g;const s=this.joystick.y>0?1:-1;let C=Math.pow(this.joystick.y,i);C*=s,o*=g,t.getWorldQuaternion(this.worldRot),this.movementVector.set(o,0,C),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(e*this.context.time.deltaTime),t.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(t,A)}rotationUpdate(t,A){const e=this.joystick.x,i=Math.abs(e);if(i<.4)this.didRotate=!1;else if(i>.5&&!this.didRotate){const g=e>0?-1:1;t.rotateY(te.toRadians(30*g)),this.didRotate=!0}this.runTeleport(t,A)}runTeleport(t,A){var e,i,g;let I=-this.joystick.y;if((e=this.hand)!=null&&e.visible&&!this.grabbed){const a=this.handPointerModel.isPinched();a&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),a&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(I=this.handPointerModel.isPinched()?1:0),a||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;let o=I>.5&&this.webXR.IsInVR,s=this.webXR.Rig?((g=(i=this.webXR.Rig)==null?void 0:i.scale)==null?void 0:g.x)<.999:!1,C=null;if(A&&this.input&&!this.input.hand)for(let a=0;a<A.length;a++){const n=A[a];if(a===4)if(n.pressed&&!this.didChangeScale&&this.webXR.IsInVR){this.didChangeScale=!0;const B=this.webXR.Rig;if(B){let Q=this.switchScale(B,o,s,C);o=Q.doTeleport,s=Q.isInMiniatureMode,C=Q.newRigScale}}else n.pressed||(this.didChangeScale=!1)}if(o){if(!this.didTeleport){const a=this.raycast();if(this.didTeleport=!0,a&&a.length>0){const n=a[0];if(s||this.isValidTeleportTarget(n.object)){const B=n.point;Ci(t,B)}}}}else I<.1&&(this.didTeleport=!1);C!==null&&(t.scale.set(C,C,C),t.updateMatrixWorld())}isValidTeleportTarget(t){return tA.getComponentInParent(t,ry)!=null}switchScale(t,A,e,i){if(e){e=!1,t.scale.set(1,1,1),i=1,Eg.MovementSpeedFactor=1;const g=this.context.mainCamera;Eg.PreviousCameraFarDistance&&(g.far=Eg.PreviousCameraFarDistance)}else{e=!0,A=!0,i=.1,Eg.MovementSpeedFactor=i*2;const g=this.context.mainCamera;Eg.PreviousCameraFarDistance=g.far,g.far/=i}return{doTeleport:A,isInMiniatureMode:e,newRigScale:i}}updateStick(t){var A;!t||!t.gamepad||((A=t.gamepad.axes)==null?void 0:A.length)<4||(this.joystick.x=t.gamepad.axes[2],this.joystick.y=t.gamepad.axes[3])}updateLastHit(){var t;const A=this.raycast(),e=A?A[0]:null;this.lastHit=e;let i=1;if(this.webXR.Rig&&(i/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=i*(((t=this.lastHit)==null?void 0:t.distance)??9999);const g=this.raycastLine.material;e!=null?g.color=Eg.raycastColor:g.color=Eg.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const g=te.clamp(this.lastHit.distance*.01*i,.015,.1);this._raycastHitPoint.scale.set(g,g,g)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return e}onSelectStart(){this.context.connection.allowEditing&&(this.selectStartCallback=()=>this.onHandleSelectStart())}onHandleSelectStart(){this.selectStartCallback=null,this._selectionPressed=!0,this._selectionStartTime=this.context.time.time,this._selectionEndTime=1e3;let t=null,A=!1;if(this.isUsingHands?(t=this.overlap(),t.length<=0?(t=this.raycast(),A=!1):A=!0):t=this.raycast(),ql&&console.log("onHandleSelectStart","close grab? "+A,"intersections",t),t&&t.length>0)for(const e of t){const i=e.object;this.lastSelectStartObject=i;const g={selected:i,grab:i},I=Eg.eventSubs["select-start"];if(I&&I.length>0)for(const o of I)o(this,g);g.grab!==i&&ql&&console.log("Grabbed object changed","original",i,"new",g.grab),g.grab&&(this.grabbed=AC.TryTake(this,g.grab,e,A));break}else{const e=Eg.eventSubs["select-start"],i={selected:null,grab:null};if(e&&e.length>0)for(const g of e)g(this,i)}}onSelectEnd(){var t;if(this.isUsingHands&&this.handPointerModel.pinched){this._didNotEndSelection=!0;return}if(!this._selectionPressed)return;this.selectStartCallback=null,this._selectionPressed=!1,this._selectionEndTime=this.context.time.time;const A={grab:((t=this.grabbed)==null?void 0:t.selected)??this.lastSelectStartObject},e=Eg.eventSubs["select-end"];if(e&&e.length>0)for(const i of e)i(this,A);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(t){return!(!t||tA.isActiveInHierarchy(t)===!1||ME.isInteractable(t)===!1)}setControllerLayers(t,A){var e,i;if(t&&(t.layers.set(A),t.children))for(const g of t.children)((e=this.grabbed)==null?void 0:e.selected)===g||((i=this.grabbed)==null?void 0:i.selectedMesh)===g||this.setControllerLayers(g,A)}getRay(){const t=new Js;return t.origin.copy(ue(this.controller)),t.direction.set(0,0,-1).applyQuaternion(this.rayRotation),t}overlap(){const t=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(ql&&(!this.closeGrabBoundingBoxHelper&&t&&(this.closeGrabBoundingBoxHelper=new CD(t,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&t&&this.closeGrabBoundingBoxHelper.setFromObject(t)),!t)return new Array;const A=ue(t).clone();return this.context.physics.sphereOverlap(A,.02)}raycast(){const t=new es;t.layerMask=new Qo,t.layerMask.enableAll(),t.layerMask.disable(2),t.ray=this.getRay();const A=this.context.physics.raycast(t);for(let e=0;e<A.length;e++){const i=A[e],g=i.object;if(!this.testIsVisible(g)){A.splice(e,1),e--;continue}i.object=ME.getObject(g);break}return A}};let mi=Eg;r(mi,"Factory",new gAA),r(mi,"raycastColor",new wA(.9,.3,.3)),r(mi,"raycastNoHitColor",new wA(.6,.6,.6)),r(mi,"geometry",new pe().setFromPoints([new S(0,0,0),new S(0,0,-1)])),r(mi,"handModels",{}),r(mi,"eventSubs",{}),r(mi,"PreviousCameraFarDistance"),r(mi,"MovementSpeedFactor",1);var By=(t=>(t.WillTake="WillTake",t.DidTake="DidTake",t.WillFree="WillFree",t.DidFree="DidFree",t))(By||{});const kI=class{constructor(){r(this,"sync",null),r(this,"selected",null),r(this,"selectedParent",null),r(this,"selectedMesh",null),r(this,"controller",null),r(this,"grabTime",0),r(this,"grabUUID",""),r(this,"isCloseGrab",!1),r(this,"originalMaterial",null),r(this,"usageMarker",null),r(this,"rigidbodies",null),r(this,"didReparent",!1),r(this,"grabDistance",0),r(this,"interactable",null),r(this,"positionSource",null),r(this,"grabPoint",new S),r(this,"localPositionOffsetToGrab",null),r(this,"localPositionOffsetToGrab_worldSpace",new S),r(this,"localQuaternionToGrab",new xA(0,0,0,1)),r(this,"targetDir",null),r(this,"quaternionLerp",null),r(this,"controllerDir",new S),r(this,"controllerWorldPos",new S),r(this,"lastControllerWorldPos",new S),r(this,"controllerPosDelta",new S),r(this,"totalChangeAlongDirection",0),r(this,"rigPositionLastFrame",new S)}static AddEventListener(t,A){return kI.Events[t]||(kI.Events[t]=[]),kI.Events[t].push(A),A}static RemoveEventListener(t,A){if(!A||!kI.Events[t])return;const e=kI.Events[t].indexOf(A);e>=0&&kI.Events[t].splice(e,1)}static Register(t){this.Current.find(A=>A===t)||this.Current.push(t)}static Remove(t){const A=this.Current.indexOf(t);A>=0&&this.Current.splice(A,1)}static TryTake(t,A,e,i){const g=tA.getComponentInParent(A,DE);if(g)A=g.gameObject;else return ql&&console.warn("Prevented taking object that is not interactable",A),null;let I=A;const o=tA.getComponentInParent(A,Kn);o&&(o.requestOwnership(),I=o.gameObject);for(const C of this.Current)if(C.selected===I)return C.controller===t||(C.free(),C.Take(t,I,A,o,g,e,i)),C;const s=new kI;return s.Take(t,I,A,o,g,e,i),s}Take(t,A,e,i,g,I,o){var s,C;if(console.assert(A!==null,"Expected object to be taken but was",A),t.isUsingHands?this.positionSource=o?t.wrist:t.controller:this.positionSource=t.controller,!this.positionSource)return console.warn("No position source"),this;const a={controller:t,take:A,hit:e,sync:i,interactable:g};(s=kI.Events.WillTake)==null||s.forEach(h=>h(this,a));const n=e;n!=null&&n.material&&(this.originalMaterial=n.material,Array.isArray(n.material)||(n.material=n.material.clone(),n.material&&n.material.emissive&&(n.material.emissive.b=.2))),this.selected=A,this.selectedParent||(this.selectedParent=A.parent),this.selectedMesh=n,this.controller=t,this.interactable=g,this.isCloseGrab=o,this.didReparent=!1,this.sync=i,this.grabTime=t.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=tA.addNewComponent(this.selected,wE),this.rigidbodies=tA.getComponentsInChildren(this.selected,Wt),ue(this.positionSource,this.lastControllerWorldPos);const B=()=>o?this.lastControllerWorldPos.clone():I.point.clone();this.grabDistance=B().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(B());const Q=t.isUsingHands&&o?this.controller.getWristQuaternion().clone():t.rayRotation.clone();Ti(this.selected,this.localQuaternionToGrab).premultiply(Q.invert());const E=this.controller.webXR.Rig;return E&&this.rigPositionLastFrame.copy(ue(E)),iI.Add(t.context,this.selected),kI.Register(this),this.sync&&(this.sync.fastMode=!0),(C=kI.Events.DidTake)==null||C.forEach(h=>h(this,a)),this}free(){var t,A,e,i;if(!this.selected)return;const g={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(t=kI.Events.WillFree)==null||t.forEach(s=>s(this,g)),iI.Remove(this.controller.context,this.selected),kI.Remove(this),this.sync&&(this.sync.fastMode=!1);const I=this.selectedMesh;I&&this.originalMaterial&&I.material&&(I.material=this.originalMaterial);const o=this.selected;if(this.didReparent&&o.parent){const s=this.selectedParent;s?s.attach(o):(A=this.controller)==null||A.context.scene.attach(o)}if((e=this.usageMarker)==null||e.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const s of this.rigidbodies)s.wakeUp(),s.setVelocity(s.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(i=kI.Events.DidFree)==null||i.forEach(s=>s(this,g))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),ue(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const t=this.controller.webXR.Rig;if(t){const A=ue(t),e=this.rigPositionLastFrame.sub(A);this.controllerPosDelta.add(e),this.rigPositionLastFrame.copy(A)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var t;if(this.rigidbodies)for(const A of this.rigidbodies)A.resetVelocities();if(this.sync&&this.controller&&this.controller.context.connection.isInRoom&&this.controller.context.time.time-this.grabTime>3&&this.sync.hasOwnership()===!1&&(console.log("no ownership, will leave",this.sync.guid),this.free()),!(this.interactable&&!this.interactable.canGrab)){if(!this.didReparent&&this.selected&&this.controller){const A=((t=this.controller.webXR.Rig)==null?void 0:t.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let e=1;this.controller.type===0&&(e=Math.max(0,1+this.totalChangeAlongDirection*2/A),e=e*e*e),this.grabDistance/A<.8&&(e=1),this.targetDir||(this.targetDir=new S),this.targetDir.set(0,0,-this.grabDistance*e);const i=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),g=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=g.clone()),this.quaternionLerp.slerp(g,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),pI(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(i),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(ue(this.selected)),i.sub(this.localPositionOffsetToGrab_worldSpace)),Ci(this.selected,i)}if(this.rigidbodies!=null)for(const A of this.rigidbodies)A.wakeUp();JI.markDirty(this.selected,!0)}}};let AC=kI;r(AC,"Events",{}),r(AC,"Current",[]);var lgA=Object.defineProperty,dgA=Object.getOwnPropertyDescriptor,bR=(t,A,e,i)=>{for(var g=i>1?void 0:i?dgA(A,e):A,I=t.length-1,o;I>=0;I--)(o=t[I])&&(g=(i?o(A,e,g):o(g))||g);return i&&g&&lgA(A,e,g),g};class aB extends UA{constructor(){super(...arguments),r(this,"objectBounds",!1),r(this,"color"),r(this,"isGizmo",!0),r(this,"_gizmoObject",null),r(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!Mc||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new CD(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=oY(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),WI.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){for(var A;this._boxHelper;)(A=this._boxHelper)==null||A.update(),yield}}bR([y()],aB.prototype,"objectBounds",2),bR([y(wA)],aB.prototype,"color",2),bR([y()],aB.prototype,"isGizmo",2);const pgA=oA("debugrig");class Qy extends UA{awake(){if(pgA){const A=new vA;A.position.y+=.5,this.gameObject.add(A);const e=A.addNewComponent(aB);e&&(e.isGizmo=!1)}}}class UE{constructor(){r(this,"bb",null),r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}w(){return this.bb.readFloat32(this.bb_pos+12)}static sizeOf(){return 16}static createVec4(A,e,i,g,I){return A.prep(4,16),A.writeFloat32(I),A.writeFloat32(g),A.writeFloat32(i),A.writeFloat32(e),A.offset()}}class xg{constructor(){r(this,"bb",null),r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsVrUserStateBuffer(A,e){return(e||new xg).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsVrUserStateBuffer(A,e){return A.setPosition(A.position()+kD),(e||new xg).__init(A.readInt32(A.position())+A.position(),A)}guid(A){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}time(){const A=this.bb.__offset(this.bb_pos,6);return A?this.bb.readInt64(this.bb_pos+A):this.bb.createLong(0,0)}avatarId(A){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,A):null}position(A){const e=this.bb.__offset(this.bb_pos,10);return e?(A||new zI).__init(this.bb_pos+e,this.bb):null}rotation(A){const e=this.bb.__offset(this.bb_pos,12);return e?(A||new UE).__init(this.bb_pos+e,this.bb):null}scale(){const A=this.bb.__offset(this.bb_pos,14);return A?this.bb.readFloat32(this.bb_pos+A):0}posLeftHand(A){const e=this.bb.__offset(this.bb_pos,16);return e?(A||new zI).__init(this.bb_pos+e,this.bb):null}posRightHand(A){const e=this.bb.__offset(this.bb_pos,18);return e?(A||new zI).__init(this.bb_pos+e,this.bb):null}rotLeftHand(A){const e=this.bb.__offset(this.bb_pos,20);return e?(A||new UE).__init(this.bb_pos+e,this.bb):null}rotRightHand(A){const e=this.bb.__offset(this.bb_pos,22);return e?(A||new UE).__init(this.bb_pos+e,this.bb):null}static startVrUserStateBuffer(A){A.startObject(10)}static addGuid(A,e){A.addFieldOffset(0,e,0)}static addTime(A,e){A.addFieldInt64(1,e,A.createLong(0,0))}static addAvatarId(A,e){A.addFieldOffset(2,e,0)}static addPosition(A,e){A.addFieldStruct(3,e,0)}static addRotation(A,e){A.addFieldStruct(4,e,0)}static addScale(A,e){A.addFieldFloat32(5,e,0)}static addPosLeftHand(A,e){A.addFieldStruct(6,e,0)}static addPosRightHand(A,e){A.addFieldStruct(7,e,0)}static addRotLeftHand(A,e){A.addFieldStruct(8,e,0)}static addRotRightHand(A,e){A.addFieldStruct(9,e,0)}static endVrUserStateBuffer(A){return A.endObject()}static finishVrUserStateBufferBuffer(A,e){A.finish(e)}static finishSizePrefixedVrUserStateBufferBuffer(A,e){A.finish(e,void 0,!0)}}const G2=oA("debugxr"),vl=oA("debugavatar"),LR="VRUS";jk(LR,xg.getRootAsVrUserStateBuffer);function xR(){return new Date().getTime()}function ugA(t){let A=t&4294967295,e=t/Math.pow(2,32)&1048575;return cC.create(A,e)}const Ey=class{constructor(t){r(this,"guid"),r(this,"time"),r(this,"avatarId"),r(this,"position",new S),r(this,"rotation",new ce),r(this,"scale",1),r(this,"posLeftHand",new S),r(this,"posRightHand",new S),r(this,"rotLeftHand",new xA),r(this,"rotRightHand",new xA),this.guid=t}update(t,A,e,i,g){var I,o,s,C,a,n;this.time=xR(),this.avatarId=g,this.position.set(A.x,A.y,A.z),t&&this.position.applyMatrix4(t.matrixWorld);let B=Ey.quat0;const Q=Ey.quat1;B.set(e.x,e.y,e.z,e.w),B=B.multiplyQuaternions(B,Ey.invertRotation),t&&(t.getWorldQuaternion(Q),B.multiplyQuaternions(Q,B)),this.rotation.set(B.x,B.y,B.z,B.w),this.scale=t.scale.x;const E=(I=i.LeftController)==null?void 0:I.controllerGrip;E&&(E.getWorldPosition(this.posLeftHand),E.getWorldQuaternion(this.rotLeftHand));const h=(o=i.RightController)==null?void 0:o.controllerGrip;if(h&&(h.getWorldPosition(this.posRightHand),h.getWorldQuaternion(this.rotRightHand)),(C=(s=i.LeftController)==null?void 0:s.hand)!=null&&C.visible){const l=i.LeftController.wrist;l&&(l.getWorldPosition(this.posLeftHand),l.getWorldQuaternion(this.rotLeftHand))}if((n=(a=i.RightController)==null?void 0:a.hand)!=null&&n.visible){const l=i.RightController.wrist;l&&(l.getWorldPosition(this.posRightHand),l.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(t,A){t.clear();const e=t.createString(this.guid),i=t.createString(this.avatarId);xg.startVrUserStateBuffer(t),xg.addGuid(t,e),xg.addTime(t,ugA(this.time)),xg.addAvatarId(t,i),xg.addPosition(t,zI.createVec3(t,this.position.x,this.position.y,this.position.z)),xg.addRotation(t,UE.createVec4(t,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),xg.addScale(t,this.scale),xg.addPosLeftHand(t,zI.createVec3(t,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),xg.addPosRightHand(t,zI.createVec3(t,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),xg.addRotLeftHand(t,UE.createVec4(t,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),xg.addRotRightHand(t,UE.createVec4(t,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const g=xg.endVrUserStateBuffer(t);t.finish(g,LR);const I=t.asUint8Array();A.sendBinary(I)}setFromBuffer(t,A){if(!t)return;this.guid=t,this.time=A.time().toFloat64();const e=A.avatarId();e&&(this.avatarId=e);const i=A.position();i&&this.position.set(i.x(),i.y(),i.z());const g=A.rotation();g&&this.rotation.set(g.x(),g.y(),g.z(),g.w());const I=A.posLeftHand();I&&this.posLeftHand.set(I.x(),I.y(),I.z());const o=A.posRightHand();o&&this.posRightHand.set(o.x(),o.y(),o.z());const s=A.rotLeftHand();s&&this.rotLeftHand.set(s.x(),s.y(),s.z(),s.w());const C=A.rotRightHand();C&&this.rotRightHand.set(C.x(),C.y(),C.z(),C.w()),this.scale=A.scale()}};let Ca=Ey;r(Ca,"invertRotation",new xA().setFromAxisAngle(new S(0,1,0),Math.PI)),r(Ca,"quat0",new xA),r(Ca,"quat1",new xA);class bl extends UA{constructor(){super(...arguments),r(this,"webXR",null),r(this,"debugAvatarUser",null),r(this,"voip",null),r(this,"tempState",new Ca("")),r(this,"_removeAvatarsList",[]),r(this,"eventSub_ConnectionEvent",null),r(this,"eventSub_WebXRStartEvent",null),r(this,"eventSub_WebXREndEvent",null),r(this,"eventSub_WebXRUpdateEvent",null),r(this,"avatars",{}),r(this,"localAvatar",null),r(this,"k_LocalAvatarNoNetworkingGuid","local"),r(this,"ownership",null),r(this,"xrState",null),r(this,"builder",new Rh(1024))}async awake(){if(this.webXR||(this.webXR=tA.getComponent(this.gameObject,Se)),this.webXR||(this.webXR=tA.findObjectOfType(Se,this.context)),!this.webXR&&(console.log("Missing webxr component"),this.webXR=tA.findObjectOfType(Se,this.context),!this.webXR)){console.error("Could not find webxr component");return}if(this.voip||(this.voip=tA.findObjectOfType(Ka,this.context)),vl){const A="debug-avatar-"+vl,e=new Fn(this.context,A,this.webXR);if(this.debugAvatarUser=e,typeof vl=="string"&&vl.length>0)if(await e.setAvatarOverride(vl)){const i=new Ca(A);i.position.y+=1;const g=.5;i.posLeftHand.y+=g,i.posLeftHand.x+=g,i.posRightHand.y+=g,i.posRightHand.x-=g,e.tryUpdate(i,0)}else e.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=tA.getComponent(this.gameObject,Se),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),Se.addEventListener(kt.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),Se.addEventListener(kt.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Se.addEventListener(kt.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen($t.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",A=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",A=>{const e=A.id!==null&&A.id!==void 0;if(e&&(console.log("webxr user left evt"),e)){const i=this.avatars[A.id];i?.destroy(),this.avatars[A.id]=void 0}}),this.context.connection.beginListenBinary(LR,A=>{const e=A.guid();if(!e)return;const i=A.time().toFloat64(),g=this.tempState;g.setFromBuffer(e,A);const I=this.onTryGetAvatar(e,i);I?.tryUpdate(g,i)}),this.context.connection.beginListen("vr-session-update",A=>{const e=A.guid,i=A.time,g=this.onTryGetAvatar(e,i);g?.tryUpdate(A,i)})}onTryGetAvatar(A,e){if(A===this.context.connection.connectionId)return null;const i=new Date().getTime()-e;if(i>5e3)return G2&&console.log("old data",i,A),null;let g=this.avatars[A];if(g===void 0)try{console.log("create new avatar");const I=new Fn(this.context,A,this.webXR);g=I,this.avatars[A]=I}catch(I){this.avatars[A]=null,console.error(I)}return g}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen($t.JoinedRoom,this.eventSub_ConnectionEvent),Se.removeEventListener(kt.XRStarted,this.eventSub_WebXRStartEvent),Se.removeEventListener(kt.XRUpdate,this.eventSub_WebXRUpdateEvent),Se.removeEventListener(kt.XRStopped,this.eventSub_WebXREndEvent)}update(){const A=xR();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=A),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const e in this.avatars){const i=this.avatars[e];i&&i.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const A=xR();for(const e in this.avatars){const i=this.avatars[e];if(!i){this._removeAvatarsList.push(e);continue}A-i.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),i.destroy(),this.avatars[e]=void 0)}for(const e of this._removeAvatarsList)delete this.avatars[e];this._removeAvatarsList.length=0}buildLocalAvatar(){var A;if(this.localAvatar)return;const e=((A=this.context.connection)==null?void 0:A.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new Fn(this.context,e,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var A,e,i;G2&&console.log("Hey you are connected as "+this.context.connection.connectionId),((A=this.localAvatar)==null?void 0:A.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((e=this.localAvatar)==null||e.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(i=this.ownership)==null||i.freeOwnership(),this.ownership=null)}onXRSessionStart(A){var e,i,g;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((e=this.localAvatar)==null||e.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(i=this.ownership)==null||i.freeOwnership(),this.ownership=null,this.avatars)for(const I in this.avatars)(g=this.avatars[I])==null||g.updateFlags()}onXRSessionEnded(A){var e;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((e=this.localAvatar)==null||e.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(A){this.xrState??(this.xrState=new Ca(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new xD(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:e,xr:i,rig:g}=A,I=e.getViewerPose(i.getReferenceSpace());if(!I)return;const o=I?.transform,s=o.position,C=o.orientation;this.xrState.update(g,s,C,this.webXR,this.getAvatarId()),this.localAvatar&&(this.context.connection.connectionId&&(this.localAvatar.guid=this.context.connection.connectionId),this.localAvatar.tryUpdate(this.xrState,0)),!(this.ownership&&!this.ownership.hasOwnership&&this.context.connection.isConnected&&(this.context.time.frameCount%120===0&&this.ownership.requestOwnership(),!this.ownership.hasOwnership))&&(!this.context.connection.isConnected||!this.context.connection.connectionId||this.xrState.sendAsBuffer(this.builder,this.context.connection))}getAvatarId(){return oA("avatar")??null}}var DgA=Object.defineProperty,wgA=Object.getOwnPropertyDescriptor,FE=(t,A,e,i)=>{for(var g=i>1?void 0:i?wgA(A,e):A,I=t.length-1,o;I>=0;I--)(o=t[I])&&(g=(i?o(A,e,g):o(g))||g);return i&&g&&DgA(A,e,g),g};const TR=oA("debugwebxr");async function M2(){return Rp()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function R2(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let Ll=!1,xl=!1;M2().then(t=>Ll=t),R2().then(t=>xl=t);var kt=(t=>(t.XRStarted="xrStarted",t.XRStopped="xrStopped",t.XRUpdate="xrUpdate",t.RequestVRSession="requestVRSession",t.ModifyAROptions="modify-ar-options",t))(kt||{}),NE;const Oi=(NE=class extends UA{constructor(){super(...arguments),r(this,"enableVR",!0),r(this,"enableAR",!0),r(this,"defaultAvatar"),r(this,"handModelPath",""),r(this,"createVRButton",!0),r(this,"createARButton",!0),r(this,"controllers",[]),r(this,"rig"),r(this,"isInit",!1),r(this,"_requestedAR",!1),r(this,"_requestedVR",!1),r(this,"_isInAR",!1),r(this,"_isInVR",!1),r(this,"_arButton"),r(this,"_vrButton"),r(this,"webAR",null),r(this,"_transformOrientation",new xA),r(this,"_currentHeadPose",null),r(this,"_originalCameraParent",null),r(this,"_originalCameraPosition",new S),r(this,"_originalCameraRotation",new xA),r(this,"_originalXRRigParent",null),r(this,"_originalXRRigPosition",new S),r(this,"_originalXRRigRotation",new xA),r(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(Ll||xl)}static get IsARSupported(){return Ll}static get IsVRSupported(){return xl}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(t,A){return this.events.addEventListener(t,A),A}static removeEventListener(t,A){return this.events.removeEventListener(t,A),A}static dispatchEvent(t,A){this.events.dispatchEvent({type:t,detail:A})}static createVRButton(t,A){Oi.XRSupported?t.__internalAwake():console.warn("WebXR is not supported on this device");const e={optionalFeatures:Oi.OptionalFeatures_VR},i=HM.createButton(t.context.renderer,e);return i.classList.add("webxr-ar-button"),i.classList.add("webxr-button"),this.resetButtonStyles(i),(A?.registerClick??!0)&&i.addEventListener("click",t.onClickedVRButton.bind(t)),i}static createARButton(t,A){var e;t.__internalAwake();const i=(e=t.webAR)==null?void 0:e.getAROverlayContainer(),g={optionalFeatures:[...this.OptionalFeatures_AR]};i?(g.domOverlay={root:i},g.optionalFeatures.push("dom-overlay"),g.optionalFeatures.push("hit-test")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const I=G$.createButton(t.context.renderer,g,this.onModifyAROptions.bind(this));return I.classList.add("webxr-ar-button"),I.classList.add("webxr-button"),Oi.resetButtonStyles(I),(A?.registerClick??!0)&&I.addEventListener("click",t.onClickedARButton.bind(t)),I}static onModifyAROptions(t){Oi.dispatchEvent("modify-ar-options",t)}static resetButtonStyles(t){t&&(t.style.position="",t.style.bottom="",t.style.left="")}endSession(){const t=this.context.renderer.xr.getSession();t&&t.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var t,A;return this.controllers.length>0&&((t=this.controllers[0].input)==null?void 0:t.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((A=this.controllers[1].input)==null?void 0:A.handedness)==="left"?this.controllers[1]:null}get RightController(){var t,A;return this.controllers.length>0&&((t=this.controllers[0].input)==null?void 0:t.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((A=this.controllers[1].input)==null?void 0:A.handedness)==="right"?this.controllers[1]:null}get ARButton(){return this._arButton}get VRButton(){return this._vrButton}get IsInVR(){return this._isInVR}get IsInAR(){return this._isInAR}awake(){if(this.defaultAvatar&&typeof this.defaultAvatar=="string"&&(this.defaultAvatar=Kg.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!tA.findObjectOfType(bl,this.context)){const t=tA.addNewComponent(this.gameObject,bl,!1);t.webXR=this}this.webAR=new Yl(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(Do("WebXR only works on https"),console.warn("WebXR only works on https. https://engine.needle.tools/docs/xr.html"))}onEnable(){if(this.isInit||!this.enableAR&&!this.enableVR)return;this.isInit=!0,this.context.renderer.xr.enabled=!0,Oi.XRSupported;let t,A;const e=document.createElement("div");e.classList.add("webxr-buttons"),e.style.cssText=`
|
|
5010
5010
|
position: fixed;
|
|
5011
5011
|
bottom: 21px;
|
|
5012
5012
|
left: 50%;
|