@needle-tools/engine 3.21.1-alpha.1 → 3.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/needle-engine.js +19 -14
- package/dist/needle-engine.light.js +19 -14
- package/dist/needle-engine.light.min.js +3 -3
- package/dist/needle-engine.light.umd.cjs +3 -3
- package/dist/needle-engine.min.js +3 -3
- package/dist/needle-engine.umd.cjs +3 -3
- package/lib/engine-components/EventList.d.ts +2 -1
- package/lib/engine-components/EventList.js +5 -1
- package/lib/engine-components/EventList.js.map +1 -1
- package/lib/engine-components/ui/Button.js +4 -2
- package/lib/engine-components/ui/Button.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.js +1 -3
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/package.json +1 -1
- package/src/engine-components/EventList.ts +5 -1
- package/src/engine-components/ui/Button.ts +5 -3
- package/src/engine-components/ui/EventSystem.ts +1 -2
|
@@ -4489,7 +4489,7 @@ Texture:`,i),this.setLightmapDebugMaterial()),this.applyLightmap())}updateLightm
|
|
|
4489
4489
|
gl_FragColor = lightMapTexel;
|
|
4490
4490
|
gl_FragColor.a = 1.;
|
|
4491
4491
|
}
|
|
4492
|
-
`,defines:{USE_LIGHTMAP:""}})}}const lp=function(n){return x(n)},x=function(n){if(n===void 0&&(n=null),!Array.isArray(n))n=LD(n);else for(let e=0;e<n.length;e++){const t=n[e];n[e]=LD(t)}return function(e,t){typeof t!="string"&&(t=t.name),Object.getOwnPropertyDescriptor(e,"$serializedTypes")||(e.$serializedTypes={});const i=e.$serializedTypes=e.$serializedTypes||{};i[t]=n}};function LD(n){var e,t;switch((t=(e=n==null?void 0:n.prototype)==null?void 0:e.constructor)==null?void 0:t.name){case"Number":case"String":case"Boolean":return null}return n}class bi extends _e{constructor(t,i,s,r){super(t,i,s);h(this,"alpha",1);this.alpha=r}get isRGBAColor(){return!0}set a(t){this.alpha=t}get a(){return this.alpha}clone(){const t=super.clone();return t.alpha=this.alpha,t}copy(t){return super.copy(t),"alpha"in t&&typeof t.alpha=="number"?this.alpha=t.alpha:typeof t.a=="number"&&(this.alpha=t.a),this}lerp(t,i){const s=t;return s.alpha&&(this.alpha=tt.lerp(this.alpha,s.alpha,i)),super.lerp(t,i)}lerpColors(t,i,s){const r=t,o=i;return r.alpha&&o.alpha&&(this.alpha=tt.lerp(r.alpha,o.alpha,s)),super.lerpColors(t,i,s)}multiply(t){const i=t;return i.alpha&&(this.alpha=this.alpha*i.alpha),super.multiply(t)}fromArray(t,i=0){return this.alpha=t[i+3],super.fromArray(t,i)}}class Wf{constructor(e,t){h(this,"method");h(this,"enabled");this.method=e,this.enabled=t!==void 0?t:!0}invoke(...e){if(this.enabled!==!1){if(!this.method){console.warn("No function. Please check you assigned a method to invoke on export",this);return}this.method(...e)}}}const Q7=n=>/^[A-Z]*$/.test(n);class ix extends Event{constructor(){super(...arguments);h(this,"args")}}class us{constructor(e){h(this,"target");h(this,"key");h(this,"_isInvoking",!1);h(this,"methods",[]);this.methods=e??[]}setEventTarget(e,t){if(this.key=e,this.target=t,this.key!==void 0){let i="",s=!1;for(const r of this.key)s&&Q7(r)&&(i+="-"),s=!0,i+=r.toLowerCase();this.key=i}}invoke(...e){if(this._isInvoking)
|
|
4492
|
+
`,defines:{USE_LIGHTMAP:""}})}}const lp=function(n){return x(n)},x=function(n){if(n===void 0&&(n=null),!Array.isArray(n))n=LD(n);else for(let e=0;e<n.length;e++){const t=n[e];n[e]=LD(t)}return function(e,t){typeof t!="string"&&(t=t.name),Object.getOwnPropertyDescriptor(e,"$serializedTypes")||(e.$serializedTypes={});const i=e.$serializedTypes=e.$serializedTypes||{};i[t]=n}};function LD(n){var e,t;switch((t=(e=n==null?void 0:n.prototype)==null?void 0:e.constructor)==null?void 0:t.name){case"Number":case"String":case"Boolean":return null}return n}class bi extends _e{constructor(t,i,s,r){super(t,i,s);h(this,"alpha",1);this.alpha=r}get isRGBAColor(){return!0}set a(t){this.alpha=t}get a(){return this.alpha}clone(){const t=super.clone();return t.alpha=this.alpha,t}copy(t){return super.copy(t),"alpha"in t&&typeof t.alpha=="number"?this.alpha=t.alpha:typeof t.a=="number"&&(this.alpha=t.a),this}lerp(t,i){const s=t;return s.alpha&&(this.alpha=tt.lerp(this.alpha,s.alpha,i)),super.lerp(t,i)}lerpColors(t,i,s){const r=t,o=i;return r.alpha&&o.alpha&&(this.alpha=tt.lerp(r.alpha,o.alpha,s)),super.lerpColors(t,i,s)}multiply(t){const i=t;return i.alpha&&(this.alpha=this.alpha*i.alpha),super.multiply(t)}fromArray(t,i=0){return this.alpha=t[i+3],super.fromArray(t,i)}}class Wf{constructor(e,t){h(this,"method");h(this,"enabled");this.method=e,this.enabled=t!==void 0?t:!0}invoke(...e){if(this.enabled!==!1){if(!this.method){console.warn("No function. Please check you assigned a method to invoke on export",this);return}this.method(...e)}}}const Q7=n=>/^[A-Z]*$/.test(n);class ix extends Event{constructor(){super(...arguments);h(this,"args")}}class us{constructor(e){h(this,"target");h(this,"key");h(this,"_isInvoking",!1);h(this,"methods",[]);this.methods=e??[]}setEventTarget(e,t){if(this.key=e,this.target=t,this.key!==void 0){let i="",s=!1;for(const r of this.key)s&&Q7(r)&&(i+="-"),s=!0,i+=r.toLowerCase();this.key=i}}get listenerCount(){var e;return((e=this.methods)==null?void 0:e.length)??0}invoke(...e){var t;if(this._isInvoking)return console.warn("Circular event invocation detected. Please check your event listeners for circular references.",this),!1;if(((t=this.methods)==null?void 0:t.length)<=0)return!1;this._isInvoking=!0;try{for(const i of this.methods)i.invoke(...e);if(typeof this.target=="object"&&typeof this.key=="string"){const i=this.target.dispatchEvent;if(typeof i=="function"){const s=new ix(this.key);s.args=e,i.call(this.target,s)}}}finally{this._isInvoking=!1}return!0}addEventListener(e){return this.methods.push(new Wf(e,!0)),e}removeEventListener(e){if(e)for(let t=this.methods.length-1;t>=0;t--)this.methods[t].method===e&&(this.methods[t].enabled=!1,this.methods.splice(t,1))}removeAllEventListeners(){this.methods.length=0}}const FD=Symbol("previous-visibility"),pf=class extends ai{render(e,t,i){if(i instanceof lT)this._unsupported_effectcomposer_warning||(console.warn("RenderTexture.render() does not yet support EffectComposer"),this._unsupported_effectcomposer_warning=!0);else{this.onBeforeRender();const s=i.getRenderTarget(),r=i.xr.enabled;i.xr.enabled=!1,i.setRenderTarget(this),i.clear(!0,!0,!0),i.render(e,t),i.setRenderTarget(s),i.xr.enabled=r,this.onAfterRender()}}onBeforeRender(){pf._userSet.clear();const e=iT(this.texture,!0,null,pf._userSet);for(const t of e)t instanceof ye&&(t[FD]=t.visible,t.visible=!1)}onAfterRender(){for(const e of pf._userSet)e instanceof ye&&(e.visible=e[FD]);pf._userSet.clear()}};let Jl=pf;h(Jl,"_userSet",new Set);class W7 extends mh{constructor(){super([_e,bi])}onDeserialize(e){if(e!=null)return e.a!==void 0?new bi(e.r,e.g,e.b,e.a):e.alpha!==void 0?new bi(e.r,e.g,e.b,e.alpha):new _e(e.r,e.g,e.b)}onSerialize(e){if(e!=null)return e.a!==void 0?{r:e.r,g:e.g,b:e.b,a:e.a}:{r:e.r,g:e.g,b:e.b}}}const j7=new W7;class X7 extends mh{constructor(){super(Te)}onSerialize(e,t){if(t.objectToNode!==void 0&&e.uuid){const i=t.objectToNode[e.uuid];return Rs&&console.log(i,e.name,e.uuid),{node:i}}}onDeserialize(e,t){var i,s,r;if(typeof e=="string"){(e.endsWith(".glb")||e.endsWith(".gltf"))&&(ci()&&Ls("Detected wrong usage of @serializable with Object3D or GameObject. Instead you should use AssetReference here! Please see the console for details."),console.warn(`Wrong usage of @serializable detected:
|
|
4493
4493
|
|
|
4494
4494
|
It looks like you used @serializable(Object3D) or @serializable(GameObject) for a prefab or scene reference named "`+t.path+'" in your script "'+((s=(i=t.target)==null?void 0:i.constructor)==null?void 0:s.name)+`".
|
|
4495
4495
|
To fix this replace it with @serializable(AssetReference). Make sure to replace the type with AssetReference too.
|
|
@@ -5069,7 +5069,7 @@ void main() {
|
|
|
5069
5069
|
`){super("lineBreak",e,!0),this._newLineBreakability=null}update(e,t){this._needsProcess=!0}process(e){const t=e._whiteSpace._newLineBreakability;if(e._inlines._value)for(let i=0;i<e._inlines._value.length;i++){const s=e._inlines._value[i],r=s.char;let o=null;r!==void 0&&(t!=="nowrap"&&(this._value.includes(r)||r.match(/\s/g))&&(o="possible"),r.match(/\n/g)&&(o=t)),s.lineBreak=o}}get value(){return this._value}}class vz extends Ai{constructor(){super("layouter",null,!1),this._value=null}update(e,t){this._value=e._parent.find(i=>i.isUI&&i.isText),this._needsProcess=!0}process(e){this._value&&(this._value._layouter._needsProcess=!0)}}class Vee extends Wm{constructor(e){super("backgroundColor",e,!1),this._allowsInherit=!1,this._input=0}computeOutputValue(e){this._input==="inherit"?this._value.set(this.getInheritedInput(e)):this._value.set(this._input)}}class yz extends b3{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class bz extends _3{constructor(){super()}computeOutputValue(e){this._value=DT(this.getInheritedInput(e))}}class _z extends T3{constructor(){super("fontFamily","inherit",!0),this._input="inherit",this._needsUpdate=!0,this._allowsInherit=!1}computeOutputValue(e){let t=this._inheritedInput;if(t==="inherit"&&(t=this.getInheritedInput(e)),t instanceof dx)this._value=t,e._font._needsUpdate=!0;else if(typeof t=="string"){const i=Pu.getFontFamily(t);i?(this._value=i,e._font._needsUpdate=!0):console.warn(`(.style) fontFamily, the font '${t}' 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 oI extends R3{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited,this._whiteSpacedContent="",this._stringCollapser=this.emptyStrategyLogic,this._inlineCollapser=this.emptyStrategyLogic,this._inlineWrapper=this.emptyStrategyLogic}_computeFromInherited(e){switch(super._computeFromInherited(e),this._newLineBreakability=Qee(this._value),this._value){case"nowrap":case"normal":this._stringCollapser=Wee;break;case"pre-line":this._stringCollapser=xz;break;default:this._stringCollapser=jee}switch(this._value){case"pre-line":case"nowrap":case"normal":this._inlineCollapser=Jee;break;case"pre-wrap":this._inlineCollapser=Kee;break;default:this._inlineCollapser=Zee}switch(this._value){case"pre-line":case"pre-wrap":case"normal":this._inlineWrapper=Xee;break;case"pre":this._inlineWrapper=qee;break;default:this._inlineWrapper=Yee}this._needsProcess=!0}process(e){e.isInline&&!e.isInlineBlock&&(this._whiteSpacedContent=this._stringCollapser(e._textContent._value),e._glyphs._needsProcess=!0)}}const gO={" ":" ","\n":`
|
|
5070
5070
|
`,"\r":"\r"," ":" "},Qee=function(n){switch(n){case"pre":case"pre-wrap":case"pre-line":return"mandatory"}return null};function Wee(n){return xz(n.replace(/\n/g," "))}function xz(n){return n.replace(/[ ]{2,}/g," ")}function jee(n){return n}function Xee(n,e,t,i){const s=n[e];if(s.lineBreak==="mandatory"||t+s.xadvance+s.xoffset+s.kerning>i.INNER_WIDTH)return!0;const r=Cz(n,e,i);return $ee(n[e-1],t,r,i)}function qee(n,e,t,i){return n[e].lineBreak==="mandatory"}function Yee(){return!1}function Kee(n){if(!n[0])return 0;const e=n[0],t=n[n.length-1];return e.char&&e.char===`
|
|
5071
5071
|
`&&n.length>1&&Sz([e],n[1]),t.char&&t.char===`
|
|
5072
|
-
`&&n.length>1&&wz([t],n[n.length-2]),e.offsetX}function Jee(n){if(!n[0])return 0;let e=[],t;for(let i=0;i<n.length;i++){const s=n[i];if(s.char&&gO[s.char]&&n.length>i){e.push(s),t=n[i+1];continue}break}Sz(e,t),e=[],t=null;for(let i=n.length-1;i>0;i--){const s=n[i];if(s.char&&gO[s.char]&&i>0){e.push(s),t=n[i-1];continue}break}return wz(e,t),n[0].offsetX}function Zee(n){return n[0]?n[0].offsetX:0}function wz(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX+e.cumulativeWidth,i.cumulativeWidth=0}}function Sz(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX,i.cumulativeWidth=0}}function Cz(n,e,t,i){if(i=i||0,!n[e])return i;const s=n[e];return s.lineBreak?i+s.xadvance:Cz(n,e+1,t,i+s.xadvance+s.xoffset+s.kerning+t.LETTERSPACING)}function $ee(n,e,t,i){return!n||!n.char||e+t<i.INNER_WIDTH?!1:i.BREAKON.indexOf(n.char)>-1}class Ez extends P3{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._fontSize._needsProcess=!0,e._layouter._needsProcess=!0}}class Mz extends Wi{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(e){this._value=this._inheritedInput,e._font._fontVariant&&(e._bounds._needsProcess=!0,e._layouter._needsProcess=!0)}process(e){if(!e._font._fontVariant||!e._font._fontVariant.isReady)return;const t=this._value/e._font._fontVariant.typographic.size,i=e._inlines._value;for(let s=0;s<i.length;s++){const r=i[s];r.resetOffsets(),r.fontSize=this._value,r.fontFactor=t}}get value(){return this._value}}class Tz extends B3{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(e,t){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(e)),e._layouter._needsUpdate=!0}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class ete extends Tz{constructor(){super(),this._value="inherit"}}class tte extends fx{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._parent._value._layouter._needsProcess=!1}process(e){if(this._value!=="none"){const t=e._whiteSpace._whiteSpacedContent,i=e._inlines._value;for(let s=1;s<i.length;s++){const r=t[s-1]+t[s];i[s].kerning=e._font._fontVariant.getKerningAmount(r)}}}}class Iz extends Ai{constructor(){super("children",null,!1),this._uis=[]}update(e,t){}process(e){}_compute(e){}dispose(){}}function ite(n,e=!1){const t=n[0].index!==null,i=new Set(Object.keys(n[0].attributes)),s=new Set(Object.keys(n[0].morphAttributes)),r={},o={},a=n[0].morphTargetsRelative,c=new He.BufferGeometry;let l=0;for(let u=0;u<n.length;++u){const d=n[u];let f=0;if(t!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const p in d.attributes){if(!i.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+'. All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.'),null;r[p]===void 0&&(r[p]=[]),r[p].push(d.attributes[p]),f++}if(f!==i.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const p in d.morphAttributes){if(!s.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". .morphAttributes must be consistent throughout all geometries."),null;o[p]===void 0&&(o[p]=[]),o[p].push(d.morphAttributes[p])}if(c.userData.mergedUserData=c.userData.mergedUserData||[],c.userData.mergedUserData.push(d.userData),e){let p;if(t)p=d.index.count;else if(d.attributes.position!==void 0)p=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". The geometry must have either an index or a position attribute"),null;c.addGroup(l,p,u),l+=p}}if(t){let u=0;const d=[];for(let f=0;f<n.length;++f){const p=n[f].index;for(let g=0;g<p.count;++g)d.push(p.getX(g)+u);u+=n[f].attributes.position.count}c.setIndex(d)}for(const u in r){const d=mO(r[u]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+u+" attribute."),null;c.setAttribute(u,d)}for(const u in o){const d=o[u][0].length;if(d===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[u]=[];for(let f=0;f<d;++f){const p=[];for(let A=0;A<o[u].length;++A)p.push(o[u][A][f]);const g=mO(p);if(!g)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+u+" morphAttribute."),null;c.morphAttributes[u].push(g)}}return c}function mO(n){let e,t,i,s=0;for(let a=0;a<n.length;++a){const c=n[a];if(c.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(e===void 0&&(e=c.array.constructor),e!==c.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(t===void 0&&(t=c.itemSize),t!==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;s+=c.array.length}const r=new e(s);let o=0;for(let a=0;a<n.length;++a)r.set(n[a].array,o),o+=n[a].array.length;return new He.BufferAttribute(r,t,i)}class nte extends Ai{constructor(){super("renderer")}render(e){if(!e._inlines._value||!e._inlines._value.length)return;const t=e._inlines._value.map(s=>e._font._fontVariant.getGeometricGlyph(s,e).translate(s.offsetX,s.offsetY,0)),i=ite(t);e.setFontMesh(new He.Mesh(i,e.fontMaterial)),e._fontMesh.renderOrder=1/0}}class ste extends kT{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(e){this._value=this._inheritedInput,e._layouter._needsProcess=!0}}class qf extends GA{constructor(t={}){const i={};qf.definePropertiesValues(i,t);super(i,t);h(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0});qf.init(this)}add(t){const i=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(i.push(r),r.position.z=.005):console.warn("Block element can only contain Box elements.",r)}return super.add(...i)}set textContent(t){this._textContent.value=t}get textContent(){return this._textContent._value}set invertAlpha(t){this._invertAlpha.value=t}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(t,i){t.children||(t.children=Iz),t.textContent||(t.textContent=Nee),t.glyphs||(t.glyphs=Gee),t.inlines||(t.inlines=zee),t.layouter||(t.layouter=vz),t.renderer||(t.renderer=nte),t.fontFamily||(t.fontFamily=_z),t.fontWeight||(t.fontWeight=bz),t.fontStyle||(t.fontStyle=yz),t.fontSize||(t.fontSize=Mz),t.color||(t.color=Hee),t.backgroundColor||(t.backgroundColor=Vee),t.lineBreak||(t.lineBreak=Az),t.letterSpacing||(t.letterSpacing=Ez),t.whiteSpace||(t.whiteSpace=oI),t.segments||(t.segments=ete),t.textAlign||(t.textAlign=ste),t.fontKerning||(t.fontKerning=tte)}static init(t){Object.defineProperties(t,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class rte extends y3{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}update(e,t){this._needsUpdate=!1;for(let i=e.children.length-1;i>=0;i--){const s=e.children[i];s.isUI&&(e.remove(s),s.clear())}e._children._uis=[],this._value&&e.add(new qf({name:"anonymousInline",textContent:this._value}))}}class ote extends Array{constructor(...e){super(...e),this.width=0,this.height=0}}class ate extends Ai{constructor(){super("layouter",null,!1),this._value=null}update(e,t){}process(e){let t=e._width._value;e._width._auto?t=1/0:t=e._bounds._innerWidth;const i=e._lineHeight._value,s=new ote(new pO);let r=0;e._children._inlines.forEach(d=>{if(!d._inlines.value)return;this._resetInlines(d);const f=d._fontSize._value,p=d._letterSpacing._value*f,g=d._whiteSpace._value,A=d._lineBreak._value,v={WHITESPACE:g,LETTERSPACING:p,BREAKON:A,INNER_WIDTH:t},m=d._whiteSpace._inlineWrapper;r+=d._margin._value.w+d._padding._value.w,d._inlines.value.forEach((b,y,_)=>{const C=s[s.length-1];if(m(_,y,r,v)){if(s.push(new pO(b)),b.offsetX=b.xoffset,b.width===0){r=0;return}b.cumulativeWidth=b.xadvance+p,r=b.cumulativeWidth;return}s[s.length-1].push(b),b.offsetX=r+b.xoffset+b.kerning,b.cumulativeWidth=b.xadvance+b.kerning+p,r+=b.cumulativeWidth,C.length-1===1&&C[C.length-2].width===0&&(b.offsetX-=b.xoffset,r-=b.xoffset)}),r+=d._margin._value.y+d._padding._value.y});const o=e._whiteSpace._inlineCollapser;let a=0,c=0,l=0;s.forEach((d,f)=>{const p=o(d);let g=0,A=0;if(d.forEach(v=>{g=Math.max(g,v.lineHeight),A=Math.max(A,v.lineBase),v.offsetX-=p}),d.lineHeight=g,d.lineBase=A,f===0?l=-(g*i-g)*.5:l-=s[f-1].lineHeight*i,d.y=l,d.x=0,d.forEach(v=>{v.offsetY=l-v.anchor,v.lineHeight<d.lineHeight&&(v.offsetY-=d.lineBase-v.lineBase)}),c+=d.lineHeight*i,d.width=0,d[0]){const v=d[d.length-1];d.width=v.offsetX+v.cumulativeWidth+v.paddingRight+v.marginRight+d[0].offsetX,a=Math.max(a,d.width)}}),s.height=c,s.width=a,this._value=s,t===1/0&&e._bounds.setChildrenWidth(e,s.width),e._height._auto&&e._bounds.setChildrenHeight(e,s.height);const u=e._parent._value;u&&(u._autoSize._needsProcess=!0,u._flexDirection._needsProcess=!0),e._inlineJustificator._needsProcess=!0,e._textAlign._needsProcess=!0,e._overflow._needsUpdate=!0}_resetInlines(e){e._fontSize.process(e)}}class cte extends kT{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput,this._needsProcess=!0}process(e){lte(e),e._renderer._needsRender=!0}}function lte(n){const e=n._layouter._value,t=n._textAlign._value,i=n._bounds._innerWidth;for(let s=0;s<e.length;s++){const r=e[s],o=hte(n,r,s===e.length-1),a=n._padding._value,c=n._borderWidth._value,l=(-a.w+a.y)/2+(-c.w+c.y)/2;r.x+=o;for(let u=0;u<r.length;u++)r[u].offsetX+=o-l}if(t.indexOf("justify")===0)for(let s=0;s<e.length;s++){const r=e[s];if(t.indexOf("-")!==-1&&s===e.length-1)return;const o=i-r.width;if(o<=0)return;let a=0;for(let d=1;d<r.length-1;d++)a+=r[d].char===" "?1:0;const c=o/a;let l=1;t==="justify-right"&&(r.reverse(),l=-1);let u=0;for(let d=1;d<=r.length-1;d++){const f=r[d];f.offsetX+=u*l,u+=f.char===" "?c:0}t==="justify-right"&&r.reverse()}}function hte(n,e,t){switch(n._textAlign._value){case"justify-left":case"justify":case"left":return-n._bounds._innerWidth/2;case"justify-right":case"right":return-e.width+n._bounds._innerWidth/2;case"center":return-e.width/2;case"justify-center":return t?-e.width/2:-n._bounds._innerWidth/2;default:console.warn(`textAlign: '${n._textAlign._value}' is not valid`)}}class ute extends LT{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput}}class dte extends I3{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class fte extends fx{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e)}}class pte extends pz{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class gte extends Ai{constructor(){super("children",null,!1);h(this,"_sortOrder",(t,i)=>t._order._value<i._order._value?-1:t._order._value>i._order._value?1:this._uis.indexOf(t)<this._uis.indexOf(i)?-1:1);this._uis=[],this._inlines=[],this._boxes=[]}update(t,i){this._compute(t),this._needsProcess=!0}process(t){this._compute(t),t._overflow._needsRender=!0}_compute(t){this._uis=t.children.filter(i=>i.visible&&i.isUI),this._inlines=this._uis.filter(i=>i.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class mte extends Ai{constructor(){super("autosize")}process(e){if(e._layouter._value&&e._layouter._value.length){const t=e._layouter._value,i=e._padding._value,s=e._borderWidth._value;e._width._auto&&e._bounds.setOffsetWidth(e,t.width+i.w+i.y+s.w+s.y),e._height._auto&&e._bounds.setOffsetHeight(e,t.height+i.x+i.z+s.x+s.z)}}}class Ate extends mz{constructor(){super("renderer"),this._needsUpdate=!1}render(e){super.render(e);for(const t of e._children._inlines)t._renderer.render(t);e.performAfterUpdate()}}class Km extends qm{constructor(e={},t={}){Km.definePropertiesValues(t,e),super(t,e),Km.init(this)}add(e){const t=[];let i=!1;for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(r.isInline&&(i=!0),t.push(r)):console.warn("Block element can only contain Box elements.",r)}return t.length>0&&super.add(...t),i&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(e){this._textContent.value=e}get textContent(){return super.textContent}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(e,t){e.flexDirection=ute,e.justifyContent=FT,e.alignItems=OT,e.bounds=pte,e.autoSize=mte,e.renderer=Ate,e.children||(e.children=gte),e.textContent||(e.textContent=rte),e.layouter||(e.layouter=ate),e.lineHeight||(e.lineHeight=dte),e.textAlign||(e.textAlign=cte),e.whiteSpace||(e.whiteSpace=oI),e.fontKerning||(e.fontKerning=fte),e.segments||(e.segments=Tz),t.width||(t.width="100%"),t.fontSide||(t.fontSide=0)}static init(e){Object.defineProperties(e,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class vte extends Ai{constructor(){super("inlines",null,!1),this._value=[]}process(e){this._value[0].paddingLeft=e._padding._value.w,this._value[0].marginLeft=e._margin._value.w;const t=this._value.length-1;this._value[t].paddingRight=e._padding._value.y,this._value[t].marginRight=e._margin._value.y}}class yte extends Ai{constructor(){super("renderer")}render(e){e._backgroundMesh||e.setBackgroundMesh(new gz(e)),e._backgroundMesh.position.x=e._inlines._value[0].offsetX+e._inlines._value[0].width/2,e._backgroundMesh.position.y=e._inlines._value[0].offsetY+e._inlines._value[0].lineBase/2,e._bounds.render(e)}}class bte extends Ai{constructor(){super("bounds",null,!1),this._size=new He.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(e,t){this.output(t),this._needsProcess=!0}process(e){this._offsetWidth=this._innerWidth=e._inlines._value[0].width,this._offsetHeight=this._innerHeight=e._inlines._value[0].height,this._needsRender=!0,e._borderWidth._needsRender=!0,e._borderRadius._needsRender=!0}render(e){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(e){e.size=this._size}}class Jm extends GA{constructor(e={}){const t={};Jm.definePropertiesValues(t,e),super(t,e),Jm.init(this)}clear(){for(const e of this._inlines._value)e.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new He.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(e){const t=[];for(let i=0;i<arguments.length;i++){const s=arguments[i];s.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",s):(t.push(s),s.position.z=.005)}return super.add(...t)}static definePropertiesValues(e,t){e.children||(e.children=Iz),e.bounds||(e.bounds=bte),e.inlines||(e.inlines=vte),e.layouter||(e.layouter=vz),e.renderer||(e.renderer=yte),e.fontFamily||(e.fontFamily=_z),e.fontWeight||(e.fontWeight=bz),e.fontStyle||(e.fontStyle=yz),e.fontSize||(e.fontSize=Mz),e.backgroundColor||(e.backgroundColor=m3),e.lineBreak||(e.lineBreak=Az),e.letterSpacing||(e.letterSpacing=Ez),e.whiteSpace||(e.whiteSpace=oI),e.fontKerning||(e.fontKerning=fx),t.backgroundSize||(t.backgroundSize="cover"),t.width||(t.width="100%"),t.height||(t.height="100%"),t.boxSizing||(t.boxSizing="border-box")}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),e._inlines._value=[new _te(e)],e.backgroundMaterial=new fz,e._renderer.render(e)}}class _te extends S3{constructor(e){super(),this._uiElement=e}get xadvance(){const e=this._uiElement._padding._value,t=this._uiElement._width;return t._relative?t._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.w+e.y+t.value}get width(){const e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get height(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get anchor(){return this.height}get lineHeight(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get lineBase(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}clear(){this._uiElement=null}}class Rz{constructor(e){this._subject=e}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 Pz=()=>Cb.update(),Bz={BaseProperty:Ai,Block:Ym,Text:Km,Inline:qf,InlineBlock:Jm,MeshUIBaseElement:GA,FontLibrary:Pu,update:Pz,MSDFFontMaterialUtils:Co,ShaderChunkUI:dz,Behavior:Rz,FontVariant:FA};typeof global<"u"&&(global.ThreeMeshUI=Bz);const xte=Bz;var wte=Rn.w8,Dz=Rn.cg,aI=Rn.gO,Ste=Rn.wb,hM=Rn.zV,Cte=Rn.HS,Ete=Rn.Ec,P0=Rn.gF,Mte=Rn.ol,Tte=Rn.pz,Ite=Rn.tx,Rte=Rn.hj,Pte=Rn.FV,Bte=Rn.sV,Oz=Rn.xv,Dte=Rn.mx,Ote=Rn.gE,kte=Rn.ZP,kz=Rn.Vx;const GS=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:wte,Behavior:Dz,Block:aI,DefaultValues:Ste,FontLibrary:hM,FontVariant:Cte,InheritableProperty:Ete,Inline:P0,InlineBlock:Mte,InlineGlyph:Tte,MSDFFontMaterialUtils:Ite,MaterialTransformers:Rte,MeshUIBaseElement:Pte,ShaderChunkUI:Bte,Text:Oz,TypographicFont:Dte,TypographicGlyph:Ote,default:kte,update:kz},Symbol.toStringTag,{value:"Module"})),Lte=re("debugshadowcomponents");aI.prototype.interactable={get(){return this.interactive},set(n){this.interactable=n}};const Ba=Symbol("shadowDomOwner");class aa extends Ie{constructor(){super(...arguments);h(this,"shadowComponent",null);h(this,"_controlsChildLayout",!0);h(this,"_root");h(this,"_parentComponent")}isRoot(){var t;return((t=this.Root)==null?void 0:t.gameObject)===this.gameObject}get canvas(){const t=this.Root;return t!=null&&t.isCanvas?t:null}markDirty(){$s.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(t){this._controlsChildLayout=t,this.shadowComponent&&(this.shadowComponent.autoLayout=t)}get Root(){return this._root===void 0&&(this._root=ne.getComponentInParent(this.gameObject,HA)),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(t,i){var o;this.removeShadowComponent();const s=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=ne.getComponentInParent(s,aa),!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}t.name=this.name+" ("+(this.constructor.name??"UI")+")",t.autoLayout=this._parentComponent.controlsChildLayout,t[Ba]=this,this.setShadowComponentOwner(t);let r=!1;if(((o=this.Root)==null?void 0:o.gameObject)===this.gameObject)this.gameObject.add(t);else{const a=this._parentComponent.shadowComponent;a&&(a==null||a.add(t),r=!0)}this.shadowComponent=t,i&&i.shadowComponent&&this.shadowComponent&&i.shadowComponent.add(this.shadowComponent),IA&&t.add(new tp(.5)),this.onAfterAddedToScene(),r&&kz(),Lte&&console.log(this.shadowComponent)}set(t){}setShadowComponentOwner(t){if(t&&(t[Ba]===void 0||t[Ba]===this)&&(t[Ba]=this,t.children))for(const i of t.children)this.setShadowComponentOwner(i)}traverseOwnedShadowComponents(t,i,s){if(t&&t[Ba]===i){s(t);for(const r of t.children)this.traverseOwnedShadowComponents(r,i,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(t){this.shadowComponent&&(this.shadowComponent.interactable=t)}}class HA extends aa{awake(){super.awake()}}class Yf{static getObject(e){const t=e[Ba];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const i=this.tryFindCanvasGroup(e);if((i==null?void 0:i.isCanvasGroup)===!0&&(t&&(t.canvasGroup=i),i.blocksRaycasts===!1||i.interactable===!1))return!1;const s=Ru(e,r=>{if(r.isGraphic===!0)return r},!1);return t&&(s==null?void 0:s.isGraphic)===!0&&(t.graphic=s),!((s==null?void 0:s.raycastTarget)===!1||(s==null?void 0:s.layer)===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=Ru(e,i=>{const s=i;if(s.blocksRaycasts!==void 0&&s.interactable!==void 0)return s},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}const Pg=re("debugwebxrcontroller");var Ef=(n=>(n[n.PhysicalDevice=0]="PhysicalDevice",n[n.Touch=1]="Touch",n))(Ef||{}),Cc=(n=>(n.SelectStart="select-start",n.SelectEnd="select-end",n.Update="update",n))(Cc||{});class vx extends Ie{}const Xn=class extends Ie{constructor(){super(...arguments);h(this,"webXR");h(this,"index",-1);h(this,"controllerModel");h(this,"controller");h(this,"controllerGrip");h(this,"hand");h(this,"handPointerModel");h(this,"grabbed",null);h(this,"input",null);h(this,"type",0);h(this,"showRaycastLine",!0);h(this,"_wristQuaternion",null);h(this,"movementVector",new w);h(this,"worldRot",new we);h(this,"joystick",new te);h(this,"didRotate",!1);h(this,"didTeleport",!1);h(this,"didChangeScale",!1);h(this,"lastHit",null);h(this,"raycastLine",null);h(this,"_raycastHitPoint",null);h(this,"_connnectedCallback",null);h(this,"_disconnectedCallback",null);h(this,"_selectStartEvt",null);h(this,"_selectEndEvt",null);h(this,"_selectionPressed",!1);h(this,"_selectionPressedLastFrame",!1);h(this,"_selectionStartTime",0);h(this,"_selectionEndTime",0);h(this,"_useSmoothing",!0);h(this,"_isConnected",!1);h(this,"rayRotation",new we);h(this,"_pinchStartTime");h(this,"selectStartCallback",null);h(this,"lastSelectStartObject",null);h(this,"_didNotEndSelection",!1);h(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const t=new dn(this.geometry),i=t.material;return i.color=this.raycastColor,t.layers.set(2),t.name="line",t.scale.z=1,t}static CreateRaycastHitPoint(){const t=new Lo(.5,22,22),i=new ui({color:this.raycastColor}),s=new ye(t,i);return s.visible=!1,s.layers.set(2),s}static Create(t,i,s,r){const o=s?ne.addNewComponent(s,Xn,!1):new Xn;o.webXR=t,o.index=i,o.type=r;const a=t.context;o.controller=a.renderer.xr.getController(i),o.controllerGrip=a.renderer.xr.getControllerGrip(i),o.controllerModel=this.Factory.createControllerModel(o.controller),o.controllerGrip.add(o.controllerModel),o.hand=a.renderer.xr.getHand(i);const c=new cp;DA(c,a),o.webXR.handModelPath&&o.webXR.handModelPath!==""?c.setPath(al(t.sourceId,o.webXR.handModelPath)):c.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const l=new iJ(o.hand,c);return o.hand.add(l),o.hand.traverse(u=>u.layers.set(2)),o.handPointerModel=new lJ(o.hand,o.controller),o.controller.addEventListener("connected",u=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2),setTimeout(()=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2)},1e3)}),o.hand.addEventListener("connected",u=>{var f;if(u.data.hand){t.Rig&&t.Rig.add(o.hand),o.type=0,o.handPointerModel.traverse(g=>g.layers.set(2)),(f=o.handPointerModel.pointerObject)==null||f.traverse(g=>g.layers.set(2));const p=o.hand.joints;if(p)for(const g of Object.keys(p)){const A=p[g];A.parent||o.hand.add(A)}}}),o}static addEventListener(t,i){const s=this.eventSubs[t]??[];s.push(i),this.eventSubs[t]=s}static removeEventListener(t,i){if(!i)return;const s=this.eventSubs[t]??[],r=s.indexOf(i);r>=0&&s.splice(r,1),this.eventSubs[t]=s}get isUsingHands(){var i;const t=(i=this.input)==null?void 0:i.hand;return t!=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 we),zn(t).multiply(this._wristQuaternion.setFromEuler(new mn(-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("WebXRController: Missing controller object.",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,i,s;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(),(i=this.controllerGrip)==null||i.clear(),(s=this.controller)==null||s.clear()}onEnable(){var t,i,s,r,o;if(!this.webXR){console.warn("No WebXR component assigned to WebXRController.");return}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=Xn.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=Xn.CreateRaycastHitPoint()),(t=this.webXR.Rig)==null||t.add(this.hand),(i=this.webXR.Rig)==null||i.add(this.controllerGrip),(s=this.webXR.Rig)==null||s.add(this.controller),(r=this.webXR.Rig)==null||r.add(this.raycastLine),(o=this.raycastLine)==null||o.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),Pg&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var t,i,s,r,o;if((t=this.hand)==null||t.removeFromParent(),(i=this.controllerGrip)==null||i.removeFromParent(),(s=this.controller)==null||s.removeFromParent(),(r=this.raycastLine)==null||r.removeFromParent(),(o=this._raycastHitPoint)==null||o.removeFromParent(),this.webXR){const a=this.webXR.Controllers.indexOf(this);a>=0&&this.webXR.Controllers.splice(a,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()}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.input=null}createPointerEvent(t){switch(t){case"down":this.context.input.createPointerDown(new wc(Sn.PointerDown,null,{clientX:0,clientY:0,button:this.index,pointerType:zf.Touch}));break;case"move":break;case"up":this.context.input.createPointerUp(new wc(Sn.PointerUp,null,{clientX:0,clientY:0,button:this.index,pointerType:zf.Touch}));break}}raycastUpdate(t,i){const s=this.showRaycastLine&&this.type!==1;if(this.type===1)t.visible=!1;else if(this.isUsingHands){t.visible=!this.grabbed&&s,Mn(t,i);const r=this.hand.joints;if(r&&r.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const a=this.getWristQuaternion();a&&this.rayRotation.copy(a)}Mr(t,this.rayRotation)}else t.visible=s,Mr(t,this.rayRotation),Mn(t,i)}update(){if(!this.webXR)return;this.context.time.frameCount%60===0&&(this.setControllerLayers(this.controller,2),this.setControllerLayers(this.controllerGrip,2),this.setControllerLayers(this.hand,2));const t=Xn.eventSubs.update;if(t&&t.length>0)for(const r of t)r(this);let i=1;this.type===0?i=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(i=this.context.time.deltaTime/.3),this.rayRotation.slerp(zn(this.controller),this.useSmoothing?i:1);const s=Ct(this.controller);this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine&&this.raycastUpdate(this.raycastLine,s),this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(t){var r,o;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 s=(o=(r=this.input)==null?void 0:r.gamepad)==null?void 0:o.buttons;switch(this.input.handedness){case"left":this.movementUpdate(i,s);break;case"right":this.rotationUpdate(i,s);break}}movementUpdate(t,i){const s=3*Xn.MovementSpeedFactor,r=2,o=tt.clamp01(this.joystick.length()*2),a=this.joystick.x>0?1:-1;let c=Math.pow(this.joystick.x,r);c*=a,c*=o;const l=this.joystick.y>0?1:-1;let u=Math.pow(this.joystick.y,r);u*=l,c*=o,t.getWorldQuaternion(this.worldRot),this.movementVector.set(c,0,u),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(s*this.context.time.deltaTime),t.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(t,i)}rotationUpdate(t,i){const s=this.joystick.x,r=Math.abs(s);if(r<.4)this.didRotate=!1;else if(r>.5&&!this.didRotate){const o=s>0?-1:1;t.rotateY(tt.toRadians(30*o)),this.didRotate=!0}this.runTeleport(t,i)}runTeleport(t,i){var u,d;let s=-this.joystick.y;if((u=this.hand)!=null&&u.visible&&!this.grabbed){const f=this.handPointerModel.isPinched();f&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),f&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(s=this.handPointerModel.isPinched()?1:0),f||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;const r=this.webXR.IsInVR,o=this.webXR.Rig;let a=s>.5&&r,c=o?((d=o==null?void 0:o.scale)==null?void 0:d.x)<.999:!1,l=null;if(i&&this.input&&!this.input.hand)for(let f=0;f<i.length;f++){const p=i[f];if(f===4)if(p.pressed&&!this.didChangeScale&&r){this.didChangeScale=!0;const g=o;if(g){const A=this.switchScale(g,a,c,l);a=A.doTeleport,c=A.isInMiniatureMode,l=A.newRigScale}}else p.pressed||(this.didChangeScale=!1)}if(a){if(!this.didTeleport){const f=this.raycast();if(this.didTeleport=!0,f&&f.length>0){const p=f[0];if(c||this.isValidTeleportTarget(p.object)){const g=p.point;Mn(t,g)}}}}else s<.1&&(this.didTeleport=!1);l!==null&&(t.scale.set(l,l,l),t.updateMatrixWorld())}isValidTeleportTarget(t){return ne.getComponentInParent(t,vx)!=null}switchScale(t,i,s,r){if(s){s=!1,t.scale.set(1,1,1),r=1,Xn.MovementSpeedFactor=1;const o=this.context.mainCamera;Xn.PreviousCameraFarDistance&&(o.far=Xn.PreviousCameraFarDistance)}else{s=!0,i=!0,r=.1,Xn.MovementSpeedFactor=r*2;const o=this.context.mainCamera;Xn.PreviousCameraFarDistance=o.far,o.far/=r}return{doTeleport:i,isInMiniatureMode:s,newRigScale:r}}updateStick(t){var i;!t||!t.gamepad||((i=t.gamepad.axes)==null?void 0:i.length)<4||(this.joystick.x=t.gamepad.axes[2],this.joystick.y=t.gamepad.axes[3])}updateLastHit(){var r;const t=this.raycast(),i=t?t[0]:null;this.lastHit=i;let s=1;if(this.webXR.Rig&&(s/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=s*(((r=this.lastHit)==null?void 0:r.distance)??9999);const o=this.raycastLine.material;i!=null?o.color=Xn.raycastColor:o.color=Xn.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const o=tt.clamp(this.lastHit.distance*.01*s,.015,.1);this._raycastHitPoint.scale.set(o,o,o)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return i}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,i=!1;if(this.isUsingHands?(t=this.overlap(),t.length<=0?(t=this.raycast(),i=!1):i=!0):t=this.raycast(),Pg&&console.log("onHandleSelectStart","close grab? "+i,"intersections",t),t&&t.length>0)for(const s of t){const r=s.object;this.lastSelectStartObject=r;const o={selected:r,grab:r},a=Xn.eventSubs["select-start"];if(a&&a.length>0)for(const c of a)c(this,o);o.grab!==r&&Pg&&console.log("Grabbed object changed","original",r,"new",o.grab),o.grab&&(this.grabbed=Io.TryTake(this,o.grab,s,i));break}else{const s=Xn.eventSubs["select-start"],r={selected:null,grab:null};if(s&&s.length>0)for(const o of s)o(this,r)}}onSelectEnd(){var s;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 t={grab:((s=this.grabbed)==null?void 0:s.selected)??this.lastSelectStartObject},i=Xn.eventSubs["select-end"];if(i&&i.length>0)for(const r of i)r(this,t);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(t){return!(!t||ne.isActiveInHierarchy(t)===!1||Yf.isInteractable(t)===!1)}setControllerLayers(t,i){var s,r;if(t&&(t.layers.set(i),t.children))for(const o of t.children)((s=this.grabbed)==null?void 0:s.selected)===o||((r=this.grabbed)==null?void 0:r.selectedMesh)===o||this.setControllerLayers(o,i)}getRay(){const t=new Ya;return t.origin.copy(Ct(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(Pg&&(!this.closeGrabBoundingBoxHelper&&t&&(this.closeGrabBoundingBoxHelper=new P_(t,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&t&&this.closeGrabBoundingBoxHelper.setFromObject(t)),!t)return new Array;const i=Ct(t).clone();return this.context.physics.sphereOverlap(i,.02)}raycast(){const t=new ko;t.layerMask=new Ps,t.layerMask.enableAll(),t.layerMask.disable(2),t.ray=this.getRay();const i=this.context.physics.raycast(t);for(let s=0;s<i.length;s++){const r=i[s],o=r.object;if(!this.testIsVisible(o)){i.splice(s,1),s--;continue}r.object=Yf.getObject(o);break}return i}};let sn=Xn;h(sn,"Factory",new _J),h(sn,"raycastColor",new _e(.9,.3,.3)),h(sn,"raycastNoHitColor",new _e(.6,.6,.6)),h(sn,"geometry",new mt().setFromPoints([new w(0,0,0),new w(0,0,-1)])),h(sn,"handModels",{}),h(sn,"eventSubs",{}),h(sn,"PreviousCameraFarDistance"),h(sn,"MovementSpeedFactor",1);var Mb=(n=>(n.WillTake="WillTake",n.DidTake="DidTake",n.WillFree="WillFree",n.DidFree="DidFree",n))(Mb||{});const Xs=class{constructor(){h(this,"sync",null);h(this,"selected",null);h(this,"selectedParent",null);h(this,"selectedMesh",null);h(this,"controller",null);h(this,"grabTime",0);h(this,"grabUUID","");h(this,"isCloseGrab",!1);h(this,"originalMaterial",null);h(this,"usageMarker",null);h(this,"rigidbodies",null);h(this,"didReparent",!1);h(this,"grabDistance",0);h(this,"interactable",null);h(this,"positionSource",null);h(this,"grabPoint",new w);h(this,"localPositionOffsetToGrab",null);h(this,"localPositionOffsetToGrab_worldSpace",new w);h(this,"localQuaternionToGrab",new we(0,0,0,1));h(this,"targetDir",null);h(this,"quaternionLerp",null);h(this,"controllerDir",new w);h(this,"controllerWorldPos",new w);h(this,"lastControllerWorldPos",new w);h(this,"controllerPosDelta",new w);h(this,"totalChangeAlongDirection",0);h(this,"rigPositionLastFrame",new w)}static AddEventListener(e,t){return Xs.Events[e]||(Xs.Events[e]=[]),Xs.Events[e].push(t),t}static RemoveEventListener(e,t){if(!t||!Xs.Events[e])return;const i=Xs.Events[e].indexOf(t);i>=0&&Xs.Events[e].splice(i,1)}static Register(e){this.Current.find(t=>t===e)||this.Current.push(e)}static Remove(e){const t=this.Current.indexOf(e);t>=0&&this.Current.splice(t,1)}static TryTake(e,t,i,s){const r=ne.getComponentInParent(t,up);if(r)t=r.gameObject;else return Pg&&console.warn("Prevented taking object that is not interactable",t),null;let o=t;const a=ne.getComponentInParent(t,ah);a&&(a.requestOwnership(),o=a.gameObject);for(const l of this.Current)if(l.selected===o)return l.controller===e||(l.free(),l.Take(e,o,t,a,r,i,s)),l;const c=new Xs;return c.Take(e,o,t,a,r,i,s),c}Take(e,t,i,s,r,o,a){var p,g;if(console.assert(t!==null,"Expected object to be taken but was",t),e.isUsingHands?this.positionSource=a?e.wrist:e.controller:this.positionSource=e.controller,!this.positionSource)return console.warn("No position source"),this;const c={controller:e,take:t,hit:i,sync:s,interactable:r};(p=Xs.Events.WillTake)==null||p.forEach(A=>A(this,c));const l=i;l!=null&&l.material&&(this.originalMaterial=l.material,Array.isArray(l.material)||(l.material=l.material.clone(),l.material&&l.material.emissive&&(l.material.emissive.b=.2))),this.selected=t,this.selectedParent||(this.selectedParent=t.parent),this.selectedMesh=l,this.controller=e,this.interactable=r,this.isCloseGrab=a,this.didReparent=!1,this.sync=s,this.grabTime=e.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=ne.addNewComponent(this.selected,dp),this.rigidbodies=ne.getComponentsInChildren(this.selected,Ii),Ct(this.positionSource,this.lastControllerWorldPos);const u=()=>a?this.lastControllerWorldPos.clone():o.point.clone();this.grabDistance=u().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(u());const d=e.isUsingHands&&a?this.controller.getWristQuaternion().clone():e.rayRotation.clone();zn(this.selected,this.localQuaternionToGrab).premultiply(d.invert());const f=this.controller.webXR.Rig;return f&&this.rigPositionLastFrame.copy(Ct(f)),ir.Add(e.context,this.selected),Xs.Register(this),this.sync&&(this.sync.fastMode=!0),(g=Xs.Events.DidTake)==null||g.forEach(A=>A(this,c)),this}free(){var s,r,o,a;if(!this.selected)return;const e={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(s=Xs.Events.WillFree)==null||s.forEach(c=>c(this,e)),ir.Remove(this.controller.context,this.selected),Xs.Remove(this),this.sync&&(this.sync.fastMode=!1);const t=this.selectedMesh;t&&this.originalMaterial&&t.material&&(t.material=this.originalMaterial);const i=this.selected;if(this.didReparent&&i.parent){const c=this.selectedParent;c?c.attach(i):(r=this.controller)==null||r.context.scene.attach(i)}if((o=this.usageMarker)==null||o.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const c of this.rigidbodies)c.wakeUp(),c.setVelocity(c.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(a=Xs.Events.DidFree)==null||a.forEach(c=>c(this,e))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),Ct(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const e=this.controller.webXR.Rig;if(e){const i=Ct(e),s=this.rigPositionLastFrame.sub(i);this.controllerPosDelta.add(s),this.rigPositionLastFrame.copy(i)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var e;if(this.rigidbodies)for(const t of this.rigidbodies)t.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 t=((e=this.controller.webXR.Rig)==null?void 0:e.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let i=1;this.controller.type===0&&(i=Math.max(0,1+this.totalChangeAlongDirection*2/t),i=i*i*i),this.grabDistance/t<.8&&(i=1),this.targetDir||(this.targetDir=new w),this.targetDir.set(0,0,-this.grabDistance*i);const s=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),r=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=r.clone()),this.quaternionLerp.slerp(r,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),Mr(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(s),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(Ct(this.selected)),s.sub(this.localPositionOffsetToGrab_worldSpace)),Mn(this.selected,s)}if(this.rigidbodies!=null)for(const t of this.rigidbodies)t.wakeUp();Sr.markDirty(this.selected,!0)}}};let Io=Xs;h(Io,"Events",{}),h(Io,"Current",[]);class Gc{constructor(e,t){h(this,"used",!1);h(this,"inputSource");h(this,"object");h(this,"pointerId");h(this,"isDown");h(this,"isUp");h(this,"isPressed");h(this,"isClicked");h(this,"input");h(this,"_event");this._event=t,this.input=e}use(){this.used=!0,this.pointerId!==void 0&&this.input.setPointerUsed(this.pointerId)}stopPropagation(){var e;(e=this._event)==null||e.stopImmediatePropagation()}Use(){this.use()}StopPropagation(){var e;(e=this._event)==null||e.stopImmediatePropagation()}get event(){return this._event}clone(){const e=new Gc(this.input,this._event);return Object.assign(e,this),e}}class mp extends Ie{awake(){$s.createIfNoneExists(this.context)}onEnable(){var e;(e=$s.get(this.context))==null||e.register(this)}onDisable(){var e;(e=$s.get(this.context))==null||e.unregister(this)}performRaycast(e=null){return null}}class rl extends mp{constructor(){super(...arguments);h(this,"targets",null);h(this,"raycastHits",[])}start(){this.targets=[this.gameObject]}performRaycast(t=null){return this.targets?(t??(t=new ko),t.targets=this.targets,t.results=this.raycastHits,this.context.physics.raycast(t)):null}}class cI extends rl{}const Kd=re("debugeventsystem");var uM=(n=>(n.BeforeHandleInput="BeforeHandleInput",n.AfterHandleInput="AfterHandleInput",n))(uM||{});const Ea=class extends Ie{constructor(){super();h(this,"raycaster",[]);h(this,"_selectStartFn");h(this,"_selectEndFn");h(this,"_selectUpdateFn");h(this,"_handleEventCycleFn");h(this,"_handleInputFn");h(this,"pressedByID",new Map);h(this,"hoveredByID",new Map);h(this,"_sortedHits",[]);h(this,"_sortingBuffer",[]);h(this,"_noDepthTestingResults",[]);h(this,"out",{});h(this,"currentActiveMeshUIComponents",[]);Ea.systems.push(this)}static createIfNoneExists(t){this.didSearchEventSystem||(this.didSearchEventSystem=!0,Ea.systems.length<=0&&Ea.systems.push(...ne.findObjectsOfType(Ea,t)));for(const s of Ea.systems)if(s.context===t)return;const i=new Te;ne.addNewComponent(i,Ea),t.scene.add(i)}static get systems(){const t=Ft.Current;return this._eventSystemMap.has(t)||this._eventSystemMap.set(t,[]),this._eventSystemMap.get(t)}static get(t){const i=this._eventSystemMap.get(t);return i&&i.length>0?i[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(t,i,s=!1){Ec.update(t,i,s)}static markUIDirty(t){Ec.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.hoveredByID.size>0}onDestroy(){Ea.systems.splice(Ea.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!ne.findObjectOfType(mp,this.context)){const i=ne.addNewComponent(this.context.scene,rl);this.raycaster.push(i),(ci()||Kd)&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found")}}register(t){var i;t&&this.raycaster&&!this.raycaster.includes(t)&&((i=this.raycaster)==null||i.push(t))}unregister(t){var s,r;const i=(s=this.raycaster)==null?void 0:s.indexOf(t);i!==void 0&&i!==-1&&((r=this.raycaster)==null||r.splice(i,1))}onEnable(){const t=new Map;this._selectStartFn??(this._selectStartFn=(s,r)=>{if(!r.grab)return;Ec.resetLastSelected();const o=new Gc(this.context.input);o.inputSource=s,o.pointerId=0,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=!1,t.set(s,r.grab),r.grab&&!this.handleEventOnObject(r.grab,o)&&(r.grab=null)}),this._selectEndFn??(this._selectEndFn=(s,r)=>{var c;if(!r.grab)return;const o=new Gc(this.context.input);o.inputSource=s,o.pointerId=0,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=s.selectionClick,this.handleEventOnObject(r.grab,o);const a=t.get(s);if(t.set(s,null),a)for(const l of this.pressedByID.keys()){const u=this.pressedByID[l];u.obj===a&&u.handler&&((c=u.handler.onPointerUp)==null||c.call(u.handler,o),this.pressedByID.delete(l))}});const i=new ko;this._selectUpdateFn??(this._selectUpdateFn=s=>{i.ray=s.getRay();const r=this.performRaycast(i);if(!r)return;const o=new Gc(this.context.input);o.inputSource=s,this.handleIntersections(r,o)}),sn.addEventListener(Cc.SelectStart,this._selectStartFn),sn.addEventListener(Cc.SelectEnd,this._selectEndFn),sn.addEventListener(Cc.Update,this._selectUpdateFn),this._handleInputFn=this.onPointerEvent.bind(this),this.context.input.addEventListener(Sn.PointerDown,this._handleInputFn),this.context.input.addEventListener(Sn.PointerUp,this._handleInputFn),this.context.input.addEventListener(Sn.PointerMove,this._handleInputFn)}onDisable(){sn.removeEventListener(Cc.SelectStart,this._selectStartFn),sn.removeEventListener(Cc.SelectEnd,this._selectEndFn),sn.removeEventListener(Cc.Update,this._selectUpdateFn),this.context.input.removeEventListener(Sn.PointerDown,this._handleInputFn),this.context.input.removeEventListener(Sn.PointerUp,this._handleInputFn),this.context.input.removeEventListener(Sn.PointerMove,this._handleInputFn)}onBeforeRender(){this.resetMeshUIStates()}onPointerEvent(t){if(t===void 0)return;const i=t.pointerType==zf.Touch?t.button:0,s=new Gc(this.context.input,t);s.inputSource=this.context.input,s.pointerId=i,s.isClicked=this.context.input.getPointerClicked(i),s.isDown=t.type==Sn.PointerDown,s.isUp=t.type==Sn.PointerUp,s.isPressed=this.context.input.getPointerPressed(i),Kd&&s.isClicked&&console.log("CLICK",i);const r=new ko;r.screenPoint=this.context.input.getPointerPositionRC(i);const o=this.performRaycast(r);if(!o)return;Kd&&s.isClicked&&pn("EventSystem: "+s.pointerId+" - "+this.context.time.frame+" - Up:"+s.isUp+", Down:"+s.isDown);const a={sender:this,args:s,hasActiveUI:this.currentActiveMeshUIComponents.length>0};if(this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:a})),!this.handleIntersections(o,s)){const c=this.hoveredByID.get(i);if(c&&this.triggerOnExit(c.obj,c.data),this.hoveredByID.delete(i),s.isUp){const l=this.pressedByID.get(i);l==null||l.handlers.forEach(u=>{var d;return(d=u.onPointerUp)==null?void 0:d.call(u,s)}),this.pressedByID.delete(i)}}this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:a}))}performRaycast(t){if(!this.raycaster)return null;this._sortedHits.length=0;for(const i of this.raycaster){if(!i.activeAndEnabled)continue;const s=i.performRaycast(t);s&&s.length>0&&this._sortedHits.push(...s)}return this._sortedHits.sort((i,s)=>i.distance-s.distance),this._sortedHits}handleIntersections(t,i){if(!t||t.length<=0)return!1;t=this.sortCandidates(t);for(const s of t){const{object:r}=s;if(this.handleEventOnObject(r,i))return!0}return!1}sortCandidates(t){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let i=0;i<t.length;i++){const s=t[i],r=s.object;if(r.material&&r.material.depthTest===!1){this._noDepthTestingResults.push(s);continue}this._sortingBuffer.push(s)}for(const i of this._sortingBuffer)this._noDepthTestingResults.push(i);return this._noDepthTestingResults}handleEventOnObject(t,i){if(!this.testIsVisible(t))return i.isClicked&&Kd&&console.log("not allowed",t),!1;if(i.pointerId===void 0)return!1;i.object=t;const s=t.parent;let r=!1;const o=i.isClicked??!1;let a=null;if(s&&s.isUI){const u=(i.isPressed||i.isClicked)??!1;if(s[Ba]){const d=s[Ba].gameObject;if(d){if(!Yf.isInteractable(d,this.out))return!1;a=this.out.canvasGroup??null,this.handleMeshUIIntersection(t,u),t=d,r=!0}}if(!r&&this.handleMeshUiObjectWithoutShadowDom(s,u))return!0}o&&Kd&&console.log(this.context.time.frame,t);const c=this.hoveredByID.get(i.pointerId),l=(c==null?void 0:c.obj)!==t;if(l&&(c!=null&&c.obj)&&this.triggerOnExit(c.obj,c.data),this.hoveredByID.set(i.pointerId,{obj:t,data:i}),i.isDown){const u=this.pressedByID.get(i.pointerId);u?(u.obj=t,u.data=i):this.pressedByID.set(i.pointerId,{obj:t,data:i,handlers:new Set})}return(a===null||a.interactable)&&this.handleMainInteraction(t,i,l),!0}propagate(t,i,s){for(;!(i.used||(ne.foreachComponent(t,r=>{s(r)},!1),!t.parent));)t=t.parent}handleMainInteraction(t,i,s){if(i.pointerId===void 0)return;const r=this.pressedByID.get(i.pointerId);this.propagate(t,i,o=>{var d;const a=o;if(a.interactable===!1)return;a.onPointerEnter&&s&&a.onPointerEnter(i),i.isDown&&a.onPointerDown&&(a.onPointerDown(i),r==null||r.handlers.add(a));const c=this.context.input.getPointerPositionLastFrame(i.pointerId),l=this.context.input.getPointerPosition(i.pointerId);c&&!tt.approximately(c,l)&&a.onPointerMove&&a.onPointerMove(i),i.isUp&&(a.onPointerUp&&(a.onPointerUp(i),r==null||r.handlers.delete(a)),a.onPointerExit&&((d=i.event)==null?void 0:d.pointerType)===zf.Touch&&(a.onPointerExit(i),this.hoveredByID.delete(i.pointerId))),i.isClicked&&a.onPointerClick&&a.onPointerClick(i)}),i.isUp&&(r==null||r.handlers.forEach(o=>{o.onPointerUp&&o.onPointerUp(i)}),this.pressedByID.delete(i.pointerId))}triggerOnExit(t,i){i.used=!1,this.propagate(t,i,s=>{if(!s.gameObject||s.destroyed)return;const r=s;r.onPointerExit&&r.onPointerExit(i)})}handleMeshUiObjectWithoutShadowDom(t,i){return!t||!t.isUI?!0:this.handleMeshUIIntersection(t,i)}handleMeshUIIntersection(t,i){const s=Ec.updateState(t,i);return s&&this.currentActiveMeshUIComponents.push(s),s!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&Ec.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let t=0;t<this.currentActiveMeshUIComponents.length;t++){const i=this.currentActiveMeshUIComponents[t];Ec.resetState(i)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(t){return t?ne.isActiveSelf(t)?this.testIsVisible(t.parent):!1:!0}};let $s=Ea;h($s,"_eventSystemMap",new Map),h($s,"didSearchEventSystem",!1);class Ec{static markDirty(){this.needsUpdate=!0}static update(e,t,i=!1){if(i){e.update();return}const s=t.time.frameCount;for(const r of this.lastUpdateFrame)if(r.context===t){if(s===r.frame)return;r.frame=s;let o=this.needsUpdate||s<1;r.nextUpdate===t.time.frameCount&&(o=!0),o&&(Kd&&console.log("Update threemeshui"),this.needsUpdate=!1,e.update());return}this.lastUpdateFrame=[{context:t,frame:s,nextUpdate:s}],e.update()}static updateState(e,t){let i=null;if(e&&(i=this.findBlockInParent(e),i&&i!==this.lastSelected)){if(i.interactable===!1)return null;this.needsUpdate=!0}return i}static resetLastSelected(){const e=this.lastSelected;e&&(this.lastSelected=null,this.resetState(e))}static resetState(e){e&&(this.needsUpdate=!0)}static findBlockInParent(e){return e?e.isBlock?e:this.findBlockInParent(e.parent):null}}h(Ec,"lastSelected",null),h(Ec,"lastUpdateFrame",[]),h(Ec,"needsUpdate",!1);const B0=Symbol("cameraController");function Fte(n){return n[B0]}function AO(n,e,t){t?n[B0]=e:n[B0]===e&&(n[B0]=null)}function yx(n){const e=n[Ba];return e||(n.parent?yx(n.parent):null)}function Tb(n,e){if(!n)return;const t=n.material;if((t==null?void 0:t.isMaterial)===!0){const i=n.parent;i&&i.isText,t.side=e.doubleSided??!0?wi:Ds,t.shadowSide=e.doubleSided?wi:Ds,n.castShadow=e.castShadows?e.castShadows:!1,n.receiveShadow=e.receiveShadows?e.receiveShadows:!1}for(const i of n.children)Tb(i,e)}function Jd(n,e,t){n[e]===void 0&&console.warn("Field",e,"is undefined on",n);const i=Proxy.revocable(n[e],{set(o,a,c,l){const u=o[a],d=Reflect.set(o,a,c,l);return t(c,u),d}}),s=i.revoke,r=n[e];return i.revoke=()=>{n[e]=r,s()},n[e]=i.proxy,i}const vO=Symbol("Scheduled action");function Ute(n,e,t=Tr.OnBeforeRender){let i=n[vO];i||(i=n[vO]={});const s=e.name;i[t]||(i[t]={});const r=i[t];if(r[s])return;function*a(){e==null||e.call(n),r[s]=null}const c=n.startCoroutine(a(),t);r[s]=c}class Lz extends ye{constructor(e,t={}){const s=[e.isCubeTexture?"#define ENVMAP_TYPE_CUBE":""],r=`
|
|
5072
|
+
`&&n.length>1&&wz([t],n[n.length-2]),e.offsetX}function Jee(n){if(!n[0])return 0;let e=[],t;for(let i=0;i<n.length;i++){const s=n[i];if(s.char&&gO[s.char]&&n.length>i){e.push(s),t=n[i+1];continue}break}Sz(e,t),e=[],t=null;for(let i=n.length-1;i>0;i--){const s=n[i];if(s.char&&gO[s.char]&&i>0){e.push(s),t=n[i-1];continue}break}return wz(e,t),n[0].offsetX}function Zee(n){return n[0]?n[0].offsetX:0}function wz(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX+e.cumulativeWidth,i.cumulativeWidth=0}}function Sz(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX,i.cumulativeWidth=0}}function Cz(n,e,t,i){if(i=i||0,!n[e])return i;const s=n[e];return s.lineBreak?i+s.xadvance:Cz(n,e+1,t,i+s.xadvance+s.xoffset+s.kerning+t.LETTERSPACING)}function $ee(n,e,t,i){return!n||!n.char||e+t<i.INNER_WIDTH?!1:i.BREAKON.indexOf(n.char)>-1}class Ez extends P3{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._fontSize._needsProcess=!0,e._layouter._needsProcess=!0}}class Mz extends Wi{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(e){this._value=this._inheritedInput,e._font._fontVariant&&(e._bounds._needsProcess=!0,e._layouter._needsProcess=!0)}process(e){if(!e._font._fontVariant||!e._font._fontVariant.isReady)return;const t=this._value/e._font._fontVariant.typographic.size,i=e._inlines._value;for(let s=0;s<i.length;s++){const r=i[s];r.resetOffsets(),r.fontSize=this._value,r.fontFactor=t}}get value(){return this._value}}class Tz extends B3{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(e,t){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(e)),e._layouter._needsUpdate=!0}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class ete extends Tz{constructor(){super(),this._value="inherit"}}class tte extends fx{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._parent._value._layouter._needsProcess=!1}process(e){if(this._value!=="none"){const t=e._whiteSpace._whiteSpacedContent,i=e._inlines._value;for(let s=1;s<i.length;s++){const r=t[s-1]+t[s];i[s].kerning=e._font._fontVariant.getKerningAmount(r)}}}}class Iz extends Ai{constructor(){super("children",null,!1),this._uis=[]}update(e,t){}process(e){}_compute(e){}dispose(){}}function ite(n,e=!1){const t=n[0].index!==null,i=new Set(Object.keys(n[0].attributes)),s=new Set(Object.keys(n[0].morphAttributes)),r={},o={},a=n[0].morphTargetsRelative,c=new He.BufferGeometry;let l=0;for(let u=0;u<n.length;++u){const d=n[u];let f=0;if(t!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const p in d.attributes){if(!i.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+'. All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.'),null;r[p]===void 0&&(r[p]=[]),r[p].push(d.attributes[p]),f++}if(f!==i.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const p in d.morphAttributes){if(!s.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". .morphAttributes must be consistent throughout all geometries."),null;o[p]===void 0&&(o[p]=[]),o[p].push(d.morphAttributes[p])}if(c.userData.mergedUserData=c.userData.mergedUserData||[],c.userData.mergedUserData.push(d.userData),e){let p;if(t)p=d.index.count;else if(d.attributes.position!==void 0)p=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". The geometry must have either an index or a position attribute"),null;c.addGroup(l,p,u),l+=p}}if(t){let u=0;const d=[];for(let f=0;f<n.length;++f){const p=n[f].index;for(let g=0;g<p.count;++g)d.push(p.getX(g)+u);u+=n[f].attributes.position.count}c.setIndex(d)}for(const u in r){const d=mO(r[u]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+u+" attribute."),null;c.setAttribute(u,d)}for(const u in o){const d=o[u][0].length;if(d===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[u]=[];for(let f=0;f<d;++f){const p=[];for(let A=0;A<o[u].length;++A)p.push(o[u][A][f]);const g=mO(p);if(!g)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+u+" morphAttribute."),null;c.morphAttributes[u].push(g)}}return c}function mO(n){let e,t,i,s=0;for(let a=0;a<n.length;++a){const c=n[a];if(c.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(e===void 0&&(e=c.array.constructor),e!==c.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(t===void 0&&(t=c.itemSize),t!==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;s+=c.array.length}const r=new e(s);let o=0;for(let a=0;a<n.length;++a)r.set(n[a].array,o),o+=n[a].array.length;return new He.BufferAttribute(r,t,i)}class nte extends Ai{constructor(){super("renderer")}render(e){if(!e._inlines._value||!e._inlines._value.length)return;const t=e._inlines._value.map(s=>e._font._fontVariant.getGeometricGlyph(s,e).translate(s.offsetX,s.offsetY,0)),i=ite(t);e.setFontMesh(new He.Mesh(i,e.fontMaterial)),e._fontMesh.renderOrder=1/0}}class ste extends kT{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(e){this._value=this._inheritedInput,e._layouter._needsProcess=!0}}class qf extends GA{constructor(t={}){const i={};qf.definePropertiesValues(i,t);super(i,t);h(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0});qf.init(this)}add(t){const i=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(i.push(r),r.position.z=.005):console.warn("Block element can only contain Box elements.",r)}return super.add(...i)}set textContent(t){this._textContent.value=t}get textContent(){return this._textContent._value}set invertAlpha(t){this._invertAlpha.value=t}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(t,i){t.children||(t.children=Iz),t.textContent||(t.textContent=Nee),t.glyphs||(t.glyphs=Gee),t.inlines||(t.inlines=zee),t.layouter||(t.layouter=vz),t.renderer||(t.renderer=nte),t.fontFamily||(t.fontFamily=_z),t.fontWeight||(t.fontWeight=bz),t.fontStyle||(t.fontStyle=yz),t.fontSize||(t.fontSize=Mz),t.color||(t.color=Hee),t.backgroundColor||(t.backgroundColor=Vee),t.lineBreak||(t.lineBreak=Az),t.letterSpacing||(t.letterSpacing=Ez),t.whiteSpace||(t.whiteSpace=oI),t.segments||(t.segments=ete),t.textAlign||(t.textAlign=ste),t.fontKerning||(t.fontKerning=tte)}static init(t){Object.defineProperties(t,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class rte extends y3{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}update(e,t){this._needsUpdate=!1;for(let i=e.children.length-1;i>=0;i--){const s=e.children[i];s.isUI&&(e.remove(s),s.clear())}e._children._uis=[],this._value&&e.add(new qf({name:"anonymousInline",textContent:this._value}))}}class ote extends Array{constructor(...e){super(...e),this.width=0,this.height=0}}class ate extends Ai{constructor(){super("layouter",null,!1),this._value=null}update(e,t){}process(e){let t=e._width._value;e._width._auto?t=1/0:t=e._bounds._innerWidth;const i=e._lineHeight._value,s=new ote(new pO);let r=0;e._children._inlines.forEach(d=>{if(!d._inlines.value)return;this._resetInlines(d);const f=d._fontSize._value,p=d._letterSpacing._value*f,g=d._whiteSpace._value,A=d._lineBreak._value,v={WHITESPACE:g,LETTERSPACING:p,BREAKON:A,INNER_WIDTH:t},m=d._whiteSpace._inlineWrapper;r+=d._margin._value.w+d._padding._value.w,d._inlines.value.forEach((b,y,_)=>{const C=s[s.length-1];if(m(_,y,r,v)){if(s.push(new pO(b)),b.offsetX=b.xoffset,b.width===0){r=0;return}b.cumulativeWidth=b.xadvance+p,r=b.cumulativeWidth;return}s[s.length-1].push(b),b.offsetX=r+b.xoffset+b.kerning,b.cumulativeWidth=b.xadvance+b.kerning+p,r+=b.cumulativeWidth,C.length-1===1&&C[C.length-2].width===0&&(b.offsetX-=b.xoffset,r-=b.xoffset)}),r+=d._margin._value.y+d._padding._value.y});const o=e._whiteSpace._inlineCollapser;let a=0,c=0,l=0;s.forEach((d,f)=>{const p=o(d);let g=0,A=0;if(d.forEach(v=>{g=Math.max(g,v.lineHeight),A=Math.max(A,v.lineBase),v.offsetX-=p}),d.lineHeight=g,d.lineBase=A,f===0?l=-(g*i-g)*.5:l-=s[f-1].lineHeight*i,d.y=l,d.x=0,d.forEach(v=>{v.offsetY=l-v.anchor,v.lineHeight<d.lineHeight&&(v.offsetY-=d.lineBase-v.lineBase)}),c+=d.lineHeight*i,d.width=0,d[0]){const v=d[d.length-1];d.width=v.offsetX+v.cumulativeWidth+v.paddingRight+v.marginRight+d[0].offsetX,a=Math.max(a,d.width)}}),s.height=c,s.width=a,this._value=s,t===1/0&&e._bounds.setChildrenWidth(e,s.width),e._height._auto&&e._bounds.setChildrenHeight(e,s.height);const u=e._parent._value;u&&(u._autoSize._needsProcess=!0,u._flexDirection._needsProcess=!0),e._inlineJustificator._needsProcess=!0,e._textAlign._needsProcess=!0,e._overflow._needsUpdate=!0}_resetInlines(e){e._fontSize.process(e)}}class cte extends kT{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput,this._needsProcess=!0}process(e){lte(e),e._renderer._needsRender=!0}}function lte(n){const e=n._layouter._value,t=n._textAlign._value,i=n._bounds._innerWidth;for(let s=0;s<e.length;s++){const r=e[s],o=hte(n,r,s===e.length-1),a=n._padding._value,c=n._borderWidth._value,l=(-a.w+a.y)/2+(-c.w+c.y)/2;r.x+=o;for(let u=0;u<r.length;u++)r[u].offsetX+=o-l}if(t.indexOf("justify")===0)for(let s=0;s<e.length;s++){const r=e[s];if(t.indexOf("-")!==-1&&s===e.length-1)return;const o=i-r.width;if(o<=0)return;let a=0;for(let d=1;d<r.length-1;d++)a+=r[d].char===" "?1:0;const c=o/a;let l=1;t==="justify-right"&&(r.reverse(),l=-1);let u=0;for(let d=1;d<=r.length-1;d++){const f=r[d];f.offsetX+=u*l,u+=f.char===" "?c:0}t==="justify-right"&&r.reverse()}}function hte(n,e,t){switch(n._textAlign._value){case"justify-left":case"justify":case"left":return-n._bounds._innerWidth/2;case"justify-right":case"right":return-e.width+n._bounds._innerWidth/2;case"center":return-e.width/2;case"justify-center":return t?-e.width/2:-n._bounds._innerWidth/2;default:console.warn(`textAlign: '${n._textAlign._value}' is not valid`)}}class ute extends LT{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput}}class dte extends I3{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class fte extends fx{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e)}}class pte extends pz{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class gte extends Ai{constructor(){super("children",null,!1);h(this,"_sortOrder",(t,i)=>t._order._value<i._order._value?-1:t._order._value>i._order._value?1:this._uis.indexOf(t)<this._uis.indexOf(i)?-1:1);this._uis=[],this._inlines=[],this._boxes=[]}update(t,i){this._compute(t),this._needsProcess=!0}process(t){this._compute(t),t._overflow._needsRender=!0}_compute(t){this._uis=t.children.filter(i=>i.visible&&i.isUI),this._inlines=this._uis.filter(i=>i.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class mte extends Ai{constructor(){super("autosize")}process(e){if(e._layouter._value&&e._layouter._value.length){const t=e._layouter._value,i=e._padding._value,s=e._borderWidth._value;e._width._auto&&e._bounds.setOffsetWidth(e,t.width+i.w+i.y+s.w+s.y),e._height._auto&&e._bounds.setOffsetHeight(e,t.height+i.x+i.z+s.x+s.z)}}}class Ate extends mz{constructor(){super("renderer"),this._needsUpdate=!1}render(e){super.render(e);for(const t of e._children._inlines)t._renderer.render(t);e.performAfterUpdate()}}class Km extends qm{constructor(e={},t={}){Km.definePropertiesValues(t,e),super(t,e),Km.init(this)}add(e){const t=[];let i=!1;for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(r.isInline&&(i=!0),t.push(r)):console.warn("Block element can only contain Box elements.",r)}return t.length>0&&super.add(...t),i&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(e){this._textContent.value=e}get textContent(){return super.textContent}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(e,t){e.flexDirection=ute,e.justifyContent=FT,e.alignItems=OT,e.bounds=pte,e.autoSize=mte,e.renderer=Ate,e.children||(e.children=gte),e.textContent||(e.textContent=rte),e.layouter||(e.layouter=ate),e.lineHeight||(e.lineHeight=dte),e.textAlign||(e.textAlign=cte),e.whiteSpace||(e.whiteSpace=oI),e.fontKerning||(e.fontKerning=fte),e.segments||(e.segments=Tz),t.width||(t.width="100%"),t.fontSide||(t.fontSide=0)}static init(e){Object.defineProperties(e,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class vte extends Ai{constructor(){super("inlines",null,!1),this._value=[]}process(e){this._value[0].paddingLeft=e._padding._value.w,this._value[0].marginLeft=e._margin._value.w;const t=this._value.length-1;this._value[t].paddingRight=e._padding._value.y,this._value[t].marginRight=e._margin._value.y}}class yte extends Ai{constructor(){super("renderer")}render(e){e._backgroundMesh||e.setBackgroundMesh(new gz(e)),e._backgroundMesh.position.x=e._inlines._value[0].offsetX+e._inlines._value[0].width/2,e._backgroundMesh.position.y=e._inlines._value[0].offsetY+e._inlines._value[0].lineBase/2,e._bounds.render(e)}}class bte extends Ai{constructor(){super("bounds",null,!1),this._size=new He.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(e,t){this.output(t),this._needsProcess=!0}process(e){this._offsetWidth=this._innerWidth=e._inlines._value[0].width,this._offsetHeight=this._innerHeight=e._inlines._value[0].height,this._needsRender=!0,e._borderWidth._needsRender=!0,e._borderRadius._needsRender=!0}render(e){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(e){e.size=this._size}}class Jm extends GA{constructor(e={}){const t={};Jm.definePropertiesValues(t,e),super(t,e),Jm.init(this)}clear(){for(const e of this._inlines._value)e.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new He.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(e){const t=[];for(let i=0;i<arguments.length;i++){const s=arguments[i];s.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",s):(t.push(s),s.position.z=.005)}return super.add(...t)}static definePropertiesValues(e,t){e.children||(e.children=Iz),e.bounds||(e.bounds=bte),e.inlines||(e.inlines=vte),e.layouter||(e.layouter=vz),e.renderer||(e.renderer=yte),e.fontFamily||(e.fontFamily=_z),e.fontWeight||(e.fontWeight=bz),e.fontStyle||(e.fontStyle=yz),e.fontSize||(e.fontSize=Mz),e.backgroundColor||(e.backgroundColor=m3),e.lineBreak||(e.lineBreak=Az),e.letterSpacing||(e.letterSpacing=Ez),e.whiteSpace||(e.whiteSpace=oI),e.fontKerning||(e.fontKerning=fx),t.backgroundSize||(t.backgroundSize="cover"),t.width||(t.width="100%"),t.height||(t.height="100%"),t.boxSizing||(t.boxSizing="border-box")}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),e._inlines._value=[new _te(e)],e.backgroundMaterial=new fz,e._renderer.render(e)}}class _te extends S3{constructor(e){super(),this._uiElement=e}get xadvance(){const e=this._uiElement._padding._value,t=this._uiElement._width;return t._relative?t._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.w+e.y+t.value}get width(){const e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get height(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get anchor(){return this.height}get lineHeight(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get lineBase(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}clear(){this._uiElement=null}}class Rz{constructor(e){this._subject=e}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 Pz=()=>Cb.update(),Bz={BaseProperty:Ai,Block:Ym,Text:Km,Inline:qf,InlineBlock:Jm,MeshUIBaseElement:GA,FontLibrary:Pu,update:Pz,MSDFFontMaterialUtils:Co,ShaderChunkUI:dz,Behavior:Rz,FontVariant:FA};typeof global<"u"&&(global.ThreeMeshUI=Bz);const xte=Bz;var wte=Rn.w8,Dz=Rn.cg,aI=Rn.gO,Ste=Rn.wb,hM=Rn.zV,Cte=Rn.HS,Ete=Rn.Ec,P0=Rn.gF,Mte=Rn.ol,Tte=Rn.pz,Ite=Rn.tx,Rte=Rn.hj,Pte=Rn.FV,Bte=Rn.sV,Oz=Rn.xv,Dte=Rn.mx,Ote=Rn.gE,kte=Rn.ZP,kz=Rn.Vx;const GS=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:wte,Behavior:Dz,Block:aI,DefaultValues:Ste,FontLibrary:hM,FontVariant:Cte,InheritableProperty:Ete,Inline:P0,InlineBlock:Mte,InlineGlyph:Tte,MSDFFontMaterialUtils:Ite,MaterialTransformers:Rte,MeshUIBaseElement:Pte,ShaderChunkUI:Bte,Text:Oz,TypographicFont:Dte,TypographicGlyph:Ote,default:kte,update:kz},Symbol.toStringTag,{value:"Module"})),Lte=re("debugshadowcomponents");aI.prototype.interactable={get(){return this.interactive},set(n){this.interactable=n}};const Ba=Symbol("shadowDomOwner");class aa extends Ie{constructor(){super(...arguments);h(this,"shadowComponent",null);h(this,"_controlsChildLayout",!0);h(this,"_root");h(this,"_parentComponent")}isRoot(){var t;return((t=this.Root)==null?void 0:t.gameObject)===this.gameObject}get canvas(){const t=this.Root;return t!=null&&t.isCanvas?t:null}markDirty(){$s.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(t){this._controlsChildLayout=t,this.shadowComponent&&(this.shadowComponent.autoLayout=t)}get Root(){return this._root===void 0&&(this._root=ne.getComponentInParent(this.gameObject,HA)),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(t,i){var o;this.removeShadowComponent();const s=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=ne.getComponentInParent(s,aa),!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}t.name=this.name+" ("+(this.constructor.name??"UI")+")",t.autoLayout=this._parentComponent.controlsChildLayout,t[Ba]=this,this.setShadowComponentOwner(t);let r=!1;if(((o=this.Root)==null?void 0:o.gameObject)===this.gameObject)this.gameObject.add(t);else{const a=this._parentComponent.shadowComponent;a&&(a==null||a.add(t),r=!0)}this.shadowComponent=t,i&&i.shadowComponent&&this.shadowComponent&&i.shadowComponent.add(this.shadowComponent),IA&&t.add(new tp(.5)),this.onAfterAddedToScene(),r&&kz(),Lte&&console.log(this.shadowComponent)}set(t){}setShadowComponentOwner(t){if(t&&(t[Ba]===void 0||t[Ba]===this)&&(t[Ba]=this,t.children))for(const i of t.children)this.setShadowComponentOwner(i)}traverseOwnedShadowComponents(t,i,s){if(t&&t[Ba]===i){s(t);for(const r of t.children)this.traverseOwnedShadowComponents(r,i,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(t){this.shadowComponent&&(this.shadowComponent.interactable=t)}}class HA extends aa{awake(){super.awake()}}class Yf{static getObject(e){const t=e[Ba];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const i=this.tryFindCanvasGroup(e);if((i==null?void 0:i.isCanvasGroup)===!0&&(t&&(t.canvasGroup=i),i.blocksRaycasts===!1||i.interactable===!1))return!1;const s=Ru(e,r=>{if(r.isGraphic===!0)return r},!1);return t&&(s==null?void 0:s.isGraphic)===!0&&(t.graphic=s),!((s==null?void 0:s.raycastTarget)===!1||(s==null?void 0:s.layer)===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=Ru(e,i=>{const s=i;if(s.blocksRaycasts!==void 0&&s.interactable!==void 0)return s},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}const Pg=re("debugwebxrcontroller");var Ef=(n=>(n[n.PhysicalDevice=0]="PhysicalDevice",n[n.Touch=1]="Touch",n))(Ef||{}),Cc=(n=>(n.SelectStart="select-start",n.SelectEnd="select-end",n.Update="update",n))(Cc||{});class vx extends Ie{}const Xn=class extends Ie{constructor(){super(...arguments);h(this,"webXR");h(this,"index",-1);h(this,"controllerModel");h(this,"controller");h(this,"controllerGrip");h(this,"hand");h(this,"handPointerModel");h(this,"grabbed",null);h(this,"input",null);h(this,"type",0);h(this,"showRaycastLine",!0);h(this,"_wristQuaternion",null);h(this,"movementVector",new w);h(this,"worldRot",new we);h(this,"joystick",new te);h(this,"didRotate",!1);h(this,"didTeleport",!1);h(this,"didChangeScale",!1);h(this,"lastHit",null);h(this,"raycastLine",null);h(this,"_raycastHitPoint",null);h(this,"_connnectedCallback",null);h(this,"_disconnectedCallback",null);h(this,"_selectStartEvt",null);h(this,"_selectEndEvt",null);h(this,"_selectionPressed",!1);h(this,"_selectionPressedLastFrame",!1);h(this,"_selectionStartTime",0);h(this,"_selectionEndTime",0);h(this,"_useSmoothing",!0);h(this,"_isConnected",!1);h(this,"rayRotation",new we);h(this,"_pinchStartTime");h(this,"selectStartCallback",null);h(this,"lastSelectStartObject",null);h(this,"_didNotEndSelection",!1);h(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const t=new dn(this.geometry),i=t.material;return i.color=this.raycastColor,t.layers.set(2),t.name="line",t.scale.z=1,t}static CreateRaycastHitPoint(){const t=new Lo(.5,22,22),i=new ui({color:this.raycastColor}),s=new ye(t,i);return s.visible=!1,s.layers.set(2),s}static Create(t,i,s,r){const o=s?ne.addNewComponent(s,Xn,!1):new Xn;o.webXR=t,o.index=i,o.type=r;const a=t.context;o.controller=a.renderer.xr.getController(i),o.controllerGrip=a.renderer.xr.getControllerGrip(i),o.controllerModel=this.Factory.createControllerModel(o.controller),o.controllerGrip.add(o.controllerModel),o.hand=a.renderer.xr.getHand(i);const c=new cp;DA(c,a),o.webXR.handModelPath&&o.webXR.handModelPath!==""?c.setPath(al(t.sourceId,o.webXR.handModelPath)):c.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const l=new iJ(o.hand,c);return o.hand.add(l),o.hand.traverse(u=>u.layers.set(2)),o.handPointerModel=new lJ(o.hand,o.controller),o.controller.addEventListener("connected",u=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2),setTimeout(()=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2)},1e3)}),o.hand.addEventListener("connected",u=>{var f;if(u.data.hand){t.Rig&&t.Rig.add(o.hand),o.type=0,o.handPointerModel.traverse(g=>g.layers.set(2)),(f=o.handPointerModel.pointerObject)==null||f.traverse(g=>g.layers.set(2));const p=o.hand.joints;if(p)for(const g of Object.keys(p)){const A=p[g];A.parent||o.hand.add(A)}}}),o}static addEventListener(t,i){const s=this.eventSubs[t]??[];s.push(i),this.eventSubs[t]=s}static removeEventListener(t,i){if(!i)return;const s=this.eventSubs[t]??[],r=s.indexOf(i);r>=0&&s.splice(r,1),this.eventSubs[t]=s}get isUsingHands(){var i;const t=(i=this.input)==null?void 0:i.hand;return t!=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 we),zn(t).multiply(this._wristQuaternion.setFromEuler(new mn(-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("WebXRController: Missing controller object.",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,i,s;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(),(i=this.controllerGrip)==null||i.clear(),(s=this.controller)==null||s.clear()}onEnable(){var t,i,s,r,o;if(!this.webXR){console.warn("No WebXR component assigned to WebXRController.");return}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=Xn.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=Xn.CreateRaycastHitPoint()),(t=this.webXR.Rig)==null||t.add(this.hand),(i=this.webXR.Rig)==null||i.add(this.controllerGrip),(s=this.webXR.Rig)==null||s.add(this.controller),(r=this.webXR.Rig)==null||r.add(this.raycastLine),(o=this.raycastLine)==null||o.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),Pg&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var t,i,s,r,o;if((t=this.hand)==null||t.removeFromParent(),(i=this.controllerGrip)==null||i.removeFromParent(),(s=this.controller)==null||s.removeFromParent(),(r=this.raycastLine)==null||r.removeFromParent(),(o=this._raycastHitPoint)==null||o.removeFromParent(),this.webXR){const a=this.webXR.Controllers.indexOf(this);a>=0&&this.webXR.Controllers.splice(a,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()}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.input=null}createPointerEvent(t){switch(t){case"down":this.context.input.createPointerDown(new wc(Sn.PointerDown,null,{clientX:0,clientY:0,button:this.index,pointerType:zf.Touch}));break;case"move":break;case"up":this.context.input.createPointerUp(new wc(Sn.PointerUp,null,{clientX:0,clientY:0,button:this.index,pointerType:zf.Touch}));break}}raycastUpdate(t,i){const s=this.showRaycastLine&&this.type!==1;if(this.type===1)t.visible=!1;else if(this.isUsingHands){t.visible=!this.grabbed&&s,Mn(t,i);const r=this.hand.joints;if(r&&r.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const a=this.getWristQuaternion();a&&this.rayRotation.copy(a)}Mr(t,this.rayRotation)}else t.visible=s,Mr(t,this.rayRotation),Mn(t,i)}update(){if(!this.webXR)return;this.context.time.frameCount%60===0&&(this.setControllerLayers(this.controller,2),this.setControllerLayers(this.controllerGrip,2),this.setControllerLayers(this.hand,2));const t=Xn.eventSubs.update;if(t&&t.length>0)for(const r of t)r(this);let i=1;this.type===0?i=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(i=this.context.time.deltaTime/.3),this.rayRotation.slerp(zn(this.controller),this.useSmoothing?i:1);const s=Ct(this.controller);this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine&&this.raycastUpdate(this.raycastLine,s),this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(t){var r,o;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 s=(o=(r=this.input)==null?void 0:r.gamepad)==null?void 0:o.buttons;switch(this.input.handedness){case"left":this.movementUpdate(i,s);break;case"right":this.rotationUpdate(i,s);break}}movementUpdate(t,i){const s=3*Xn.MovementSpeedFactor,r=2,o=tt.clamp01(this.joystick.length()*2),a=this.joystick.x>0?1:-1;let c=Math.pow(this.joystick.x,r);c*=a,c*=o;const l=this.joystick.y>0?1:-1;let u=Math.pow(this.joystick.y,r);u*=l,c*=o,t.getWorldQuaternion(this.worldRot),this.movementVector.set(c,0,u),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(s*this.context.time.deltaTime),t.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(t,i)}rotationUpdate(t,i){const s=this.joystick.x,r=Math.abs(s);if(r<.4)this.didRotate=!1;else if(r>.5&&!this.didRotate){const o=s>0?-1:1;t.rotateY(tt.toRadians(30*o)),this.didRotate=!0}this.runTeleport(t,i)}runTeleport(t,i){var u,d;let s=-this.joystick.y;if((u=this.hand)!=null&&u.visible&&!this.grabbed){const f=this.handPointerModel.isPinched();f&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),f&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(s=this.handPointerModel.isPinched()?1:0),f||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;const r=this.webXR.IsInVR,o=this.webXR.Rig;let a=s>.5&&r,c=o?((d=o==null?void 0:o.scale)==null?void 0:d.x)<.999:!1,l=null;if(i&&this.input&&!this.input.hand)for(let f=0;f<i.length;f++){const p=i[f];if(f===4)if(p.pressed&&!this.didChangeScale&&r){this.didChangeScale=!0;const g=o;if(g){const A=this.switchScale(g,a,c,l);a=A.doTeleport,c=A.isInMiniatureMode,l=A.newRigScale}}else p.pressed||(this.didChangeScale=!1)}if(a){if(!this.didTeleport){const f=this.raycast();if(this.didTeleport=!0,f&&f.length>0){const p=f[0];if(c||this.isValidTeleportTarget(p.object)){const g=p.point;Mn(t,g)}}}}else s<.1&&(this.didTeleport=!1);l!==null&&(t.scale.set(l,l,l),t.updateMatrixWorld())}isValidTeleportTarget(t){return ne.getComponentInParent(t,vx)!=null}switchScale(t,i,s,r){if(s){s=!1,t.scale.set(1,1,1),r=1,Xn.MovementSpeedFactor=1;const o=this.context.mainCamera;Xn.PreviousCameraFarDistance&&(o.far=Xn.PreviousCameraFarDistance)}else{s=!0,i=!0,r=.1,Xn.MovementSpeedFactor=r*2;const o=this.context.mainCamera;Xn.PreviousCameraFarDistance=o.far,o.far/=r}return{doTeleport:i,isInMiniatureMode:s,newRigScale:r}}updateStick(t){var i;!t||!t.gamepad||((i=t.gamepad.axes)==null?void 0:i.length)<4||(this.joystick.x=t.gamepad.axes[2],this.joystick.y=t.gamepad.axes[3])}updateLastHit(){var r;const t=this.raycast(),i=t?t[0]:null;this.lastHit=i;let s=1;if(this.webXR.Rig&&(s/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=s*(((r=this.lastHit)==null?void 0:r.distance)??9999);const o=this.raycastLine.material;i!=null?o.color=Xn.raycastColor:o.color=Xn.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const o=tt.clamp(this.lastHit.distance*.01*s,.015,.1);this._raycastHitPoint.scale.set(o,o,o)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return i}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,i=!1;if(this.isUsingHands?(t=this.overlap(),t.length<=0?(t=this.raycast(),i=!1):i=!0):t=this.raycast(),Pg&&console.log("onHandleSelectStart","close grab? "+i,"intersections",t),t&&t.length>0)for(const s of t){const r=s.object;this.lastSelectStartObject=r;const o={selected:r,grab:r},a=Xn.eventSubs["select-start"];if(a&&a.length>0)for(const c of a)c(this,o);o.grab!==r&&Pg&&console.log("Grabbed object changed","original",r,"new",o.grab),o.grab&&(this.grabbed=Io.TryTake(this,o.grab,s,i));break}else{const s=Xn.eventSubs["select-start"],r={selected:null,grab:null};if(s&&s.length>0)for(const o of s)o(this,r)}}onSelectEnd(){var s;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 t={grab:((s=this.grabbed)==null?void 0:s.selected)??this.lastSelectStartObject},i=Xn.eventSubs["select-end"];if(i&&i.length>0)for(const r of i)r(this,t);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(t){return!(!t||ne.isActiveInHierarchy(t)===!1||Yf.isInteractable(t)===!1)}setControllerLayers(t,i){var s,r;if(t&&(t.layers.set(i),t.children))for(const o of t.children)((s=this.grabbed)==null?void 0:s.selected)===o||((r=this.grabbed)==null?void 0:r.selectedMesh)===o||this.setControllerLayers(o,i)}getRay(){const t=new Ya;return t.origin.copy(Ct(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(Pg&&(!this.closeGrabBoundingBoxHelper&&t&&(this.closeGrabBoundingBoxHelper=new P_(t,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&t&&this.closeGrabBoundingBoxHelper.setFromObject(t)),!t)return new Array;const i=Ct(t).clone();return this.context.physics.sphereOverlap(i,.02)}raycast(){const t=new ko;t.layerMask=new Ps,t.layerMask.enableAll(),t.layerMask.disable(2),t.ray=this.getRay();const i=this.context.physics.raycast(t);for(let s=0;s<i.length;s++){const r=i[s],o=r.object;if(!this.testIsVisible(o)){i.splice(s,1),s--;continue}r.object=Yf.getObject(o);break}return i}};let sn=Xn;h(sn,"Factory",new _J),h(sn,"raycastColor",new _e(.9,.3,.3)),h(sn,"raycastNoHitColor",new _e(.6,.6,.6)),h(sn,"geometry",new mt().setFromPoints([new w(0,0,0),new w(0,0,-1)])),h(sn,"handModels",{}),h(sn,"eventSubs",{}),h(sn,"PreviousCameraFarDistance"),h(sn,"MovementSpeedFactor",1);var Mb=(n=>(n.WillTake="WillTake",n.DidTake="DidTake",n.WillFree="WillFree",n.DidFree="DidFree",n))(Mb||{});const Xs=class{constructor(){h(this,"sync",null);h(this,"selected",null);h(this,"selectedParent",null);h(this,"selectedMesh",null);h(this,"controller",null);h(this,"grabTime",0);h(this,"grabUUID","");h(this,"isCloseGrab",!1);h(this,"originalMaterial",null);h(this,"usageMarker",null);h(this,"rigidbodies",null);h(this,"didReparent",!1);h(this,"grabDistance",0);h(this,"interactable",null);h(this,"positionSource",null);h(this,"grabPoint",new w);h(this,"localPositionOffsetToGrab",null);h(this,"localPositionOffsetToGrab_worldSpace",new w);h(this,"localQuaternionToGrab",new we(0,0,0,1));h(this,"targetDir",null);h(this,"quaternionLerp",null);h(this,"controllerDir",new w);h(this,"controllerWorldPos",new w);h(this,"lastControllerWorldPos",new w);h(this,"controllerPosDelta",new w);h(this,"totalChangeAlongDirection",0);h(this,"rigPositionLastFrame",new w)}static AddEventListener(e,t){return Xs.Events[e]||(Xs.Events[e]=[]),Xs.Events[e].push(t),t}static RemoveEventListener(e,t){if(!t||!Xs.Events[e])return;const i=Xs.Events[e].indexOf(t);i>=0&&Xs.Events[e].splice(i,1)}static Register(e){this.Current.find(t=>t===e)||this.Current.push(e)}static Remove(e){const t=this.Current.indexOf(e);t>=0&&this.Current.splice(t,1)}static TryTake(e,t,i,s){const r=ne.getComponentInParent(t,up);if(r)t=r.gameObject;else return Pg&&console.warn("Prevented taking object that is not interactable",t),null;let o=t;const a=ne.getComponentInParent(t,ah);a&&(a.requestOwnership(),o=a.gameObject);for(const l of this.Current)if(l.selected===o)return l.controller===e||(l.free(),l.Take(e,o,t,a,r,i,s)),l;const c=new Xs;return c.Take(e,o,t,a,r,i,s),c}Take(e,t,i,s,r,o,a){var p,g;if(console.assert(t!==null,"Expected object to be taken but was",t),e.isUsingHands?this.positionSource=a?e.wrist:e.controller:this.positionSource=e.controller,!this.positionSource)return console.warn("No position source"),this;const c={controller:e,take:t,hit:i,sync:s,interactable:r};(p=Xs.Events.WillTake)==null||p.forEach(A=>A(this,c));const l=i;l!=null&&l.material&&(this.originalMaterial=l.material,Array.isArray(l.material)||(l.material=l.material.clone(),l.material&&l.material.emissive&&(l.material.emissive.b=.2))),this.selected=t,this.selectedParent||(this.selectedParent=t.parent),this.selectedMesh=l,this.controller=e,this.interactable=r,this.isCloseGrab=a,this.didReparent=!1,this.sync=s,this.grabTime=e.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=ne.addNewComponent(this.selected,dp),this.rigidbodies=ne.getComponentsInChildren(this.selected,Ii),Ct(this.positionSource,this.lastControllerWorldPos);const u=()=>a?this.lastControllerWorldPos.clone():o.point.clone();this.grabDistance=u().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(u());const d=e.isUsingHands&&a?this.controller.getWristQuaternion().clone():e.rayRotation.clone();zn(this.selected,this.localQuaternionToGrab).premultiply(d.invert());const f=this.controller.webXR.Rig;return f&&this.rigPositionLastFrame.copy(Ct(f)),ir.Add(e.context,this.selected),Xs.Register(this),this.sync&&(this.sync.fastMode=!0),(g=Xs.Events.DidTake)==null||g.forEach(A=>A(this,c)),this}free(){var s,r,o,a;if(!this.selected)return;const e={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(s=Xs.Events.WillFree)==null||s.forEach(c=>c(this,e)),ir.Remove(this.controller.context,this.selected),Xs.Remove(this),this.sync&&(this.sync.fastMode=!1);const t=this.selectedMesh;t&&this.originalMaterial&&t.material&&(t.material=this.originalMaterial);const i=this.selected;if(this.didReparent&&i.parent){const c=this.selectedParent;c?c.attach(i):(r=this.controller)==null||r.context.scene.attach(i)}if((o=this.usageMarker)==null||o.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const c of this.rigidbodies)c.wakeUp(),c.setVelocity(c.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(a=Xs.Events.DidFree)==null||a.forEach(c=>c(this,e))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),Ct(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const e=this.controller.webXR.Rig;if(e){const i=Ct(e),s=this.rigPositionLastFrame.sub(i);this.controllerPosDelta.add(s),this.rigPositionLastFrame.copy(i)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var e;if(this.rigidbodies)for(const t of this.rigidbodies)t.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 t=((e=this.controller.webXR.Rig)==null?void 0:e.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let i=1;this.controller.type===0&&(i=Math.max(0,1+this.totalChangeAlongDirection*2/t),i=i*i*i),this.grabDistance/t<.8&&(i=1),this.targetDir||(this.targetDir=new w),this.targetDir.set(0,0,-this.grabDistance*i);const s=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),r=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=r.clone()),this.quaternionLerp.slerp(r,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),Mr(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(s),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(Ct(this.selected)),s.sub(this.localPositionOffsetToGrab_worldSpace)),Mn(this.selected,s)}if(this.rigidbodies!=null)for(const t of this.rigidbodies)t.wakeUp();Sr.markDirty(this.selected,!0)}}};let Io=Xs;h(Io,"Events",{}),h(Io,"Current",[]);class Gc{constructor(e,t){h(this,"used",!1);h(this,"inputSource");h(this,"object");h(this,"pointerId");h(this,"isDown");h(this,"isUp");h(this,"isPressed");h(this,"isClicked");h(this,"input");h(this,"_event");this._event=t,this.input=e}use(){this.used=!0,this.pointerId!==void 0&&this.input.setPointerUsed(this.pointerId)}stopPropagation(){var e;(e=this._event)==null||e.stopImmediatePropagation()}Use(){this.use()}StopPropagation(){var e;(e=this._event)==null||e.stopImmediatePropagation()}get event(){return this._event}clone(){const e=new Gc(this.input,this._event);return Object.assign(e,this),e}}class mp extends Ie{awake(){$s.createIfNoneExists(this.context)}onEnable(){var e;(e=$s.get(this.context))==null||e.register(this)}onDisable(){var e;(e=$s.get(this.context))==null||e.unregister(this)}performRaycast(e=null){return null}}class rl extends mp{constructor(){super(...arguments);h(this,"targets",null);h(this,"raycastHits",[])}start(){this.targets=[this.gameObject]}performRaycast(t=null){return this.targets?(t??(t=new ko),t.targets=this.targets,t.results=this.raycastHits,this.context.physics.raycast(t)):null}}class cI extends rl{}const Kd=re("debugeventsystem");var uM=(n=>(n.BeforeHandleInput="BeforeHandleInput",n.AfterHandleInput="AfterHandleInput",n))(uM||{});const Ea=class extends Ie{constructor(){super();h(this,"raycaster",[]);h(this,"_selectStartFn");h(this,"_selectEndFn");h(this,"_selectUpdateFn");h(this,"_handleEventCycleFn");h(this,"_handleInputFn");h(this,"pressedByID",new Map);h(this,"hoveredByID",new Map);h(this,"_sortedHits",[]);h(this,"_sortingBuffer",[]);h(this,"_noDepthTestingResults",[]);h(this,"out",{});h(this,"currentActiveMeshUIComponents",[]);Ea.systems.push(this)}static createIfNoneExists(t){this.didSearchEventSystem||(this.didSearchEventSystem=!0,Ea.systems.length<=0&&Ea.systems.push(...ne.findObjectsOfType(Ea,t)));for(const s of Ea.systems)if(s.context===t)return;const i=new Te;ne.addNewComponent(i,Ea),t.scene.add(i)}static get systems(){const t=Ft.Current;return this._eventSystemMap.has(t)||this._eventSystemMap.set(t,[]),this._eventSystemMap.get(t)}static get(t){const i=this._eventSystemMap.get(t);return i&&i.length>0?i[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(t,i,s=!1){Ec.update(t,i,s)}static markUIDirty(t){Ec.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.hoveredByID.size>0}onDestroy(){Ea.systems.splice(Ea.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!ne.findObjectOfType(mp,this.context)){const i=ne.addNewComponent(this.context.scene,rl);this.raycaster.push(i),(ci()||Kd)&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found")}}register(t){var i;t&&this.raycaster&&!this.raycaster.includes(t)&&((i=this.raycaster)==null||i.push(t))}unregister(t){var s,r;const i=(s=this.raycaster)==null?void 0:s.indexOf(t);i!==void 0&&i!==-1&&((r=this.raycaster)==null||r.splice(i,1))}onEnable(){const t=new Map;this._selectStartFn??(this._selectStartFn=(s,r)=>{if(!r.grab)return;Ec.resetLastSelected();const o=new Gc(this.context.input);o.inputSource=s,o.pointerId=0,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=!1,t.set(s,r.grab),r.grab&&!this.handleEventOnObject(r.grab,o)&&(r.grab=null)}),this._selectEndFn??(this._selectEndFn=(s,r)=>{var c;if(!r.grab)return;const o=new Gc(this.context.input);o.inputSource=s,o.pointerId=0,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=s.selectionClick,this.handleEventOnObject(r.grab,o);const a=t.get(s);if(t.set(s,null),a)for(const l of this.pressedByID.keys()){const u=this.pressedByID[l];u.obj===a&&u.handler&&((c=u.handler.onPointerUp)==null||c.call(u.handler,o),this.pressedByID.delete(l))}});const i=new ko;this._selectUpdateFn??(this._selectUpdateFn=s=>{i.ray=s.getRay();const r=this.performRaycast(i);if(!r)return;const o=new Gc(this.context.input);o.inputSource=s,this.handleIntersections(r,o)}),sn.addEventListener(Cc.SelectStart,this._selectStartFn),sn.addEventListener(Cc.SelectEnd,this._selectEndFn),sn.addEventListener(Cc.Update,this._selectUpdateFn),this._handleInputFn=this.onPointerEvent.bind(this),this.context.input.addEventListener(Sn.PointerDown,this._handleInputFn),this.context.input.addEventListener(Sn.PointerUp,this._handleInputFn),this.context.input.addEventListener(Sn.PointerMove,this._handleInputFn)}onDisable(){sn.removeEventListener(Cc.SelectStart,this._selectStartFn),sn.removeEventListener(Cc.SelectEnd,this._selectEndFn),sn.removeEventListener(Cc.Update,this._selectUpdateFn),this.context.input.removeEventListener(Sn.PointerDown,this._handleInputFn),this.context.input.removeEventListener(Sn.PointerUp,this._handleInputFn),this.context.input.removeEventListener(Sn.PointerMove,this._handleInputFn)}onBeforeRender(){this.resetMeshUIStates()}onPointerEvent(t){if(t===void 0)return;const i=t.pointerType==zf.Touch?t.button:0,s=new Gc(this.context.input,t);s.inputSource=this.context.input,s.pointerId=i,s.isClicked=this.context.input.getPointerClicked(i),s.isDown=t.type==Sn.PointerDown,s.isUp=t.type==Sn.PointerUp,s.isPressed=this.context.input.getPointerPressed(i),Kd&&s.isClicked&&console.log("CLICK",i);const r=new ko;r.screenPoint=this.context.input.getPointerPositionRC(i);const o=this.performRaycast(r);if(!o)return;Kd&&s.isClicked&&pn("EventSystem: "+s.pointerId+" - "+this.context.time.frame+" - Up:"+s.isUp+", Down:"+s.isDown);const a={sender:this,args:s,hasActiveUI:this.currentActiveMeshUIComponents.length>0};if(this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:a})),!this.handleIntersections(o,s)){const c=this.hoveredByID.get(i);if(c&&this.triggerOnExit(c.obj,c.data),this.hoveredByID.delete(i),s.isUp){const l=this.pressedByID.get(i);l==null||l.handlers.forEach(u=>{var d;return(d=u.onPointerUp)==null?void 0:d.call(u,s)}),this.pressedByID.delete(i)}}this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:a}))}performRaycast(t){if(!this.raycaster)return null;this._sortedHits.length=0;for(const i of this.raycaster){if(!i.activeAndEnabled)continue;const s=i.performRaycast(t);s&&s.length>0&&this._sortedHits.push(...s)}return this._sortedHits.sort((i,s)=>i.distance-s.distance),this._sortedHits}handleIntersections(t,i){if(!t||t.length<=0)return!1;t=this.sortCandidates(t);for(const s of t){const{object:r}=s;if(this.handleEventOnObject(r,i))return!0}return!1}sortCandidates(t){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let i=0;i<t.length;i++){const s=t[i],r=s.object;if(r.material&&r.material.depthTest===!1){this._noDepthTestingResults.push(s);continue}this._sortingBuffer.push(s)}for(const i of this._sortingBuffer)this._noDepthTestingResults.push(i);return this._noDepthTestingResults}handleEventOnObject(t,i){if(!this.testIsVisible(t))return i.isClicked&&Kd&&console.log("not allowed",t),!1;if(i.pointerId===void 0)return!1;i.object=t;const s=t.parent;let r=!1;const o=i.isClicked??!1;let a=null;if(s&&s.isUI){const u=(i.isPressed||i.isClicked)??!1;if(s[Ba]){const d=s[Ba].gameObject;if(d){if(!Yf.isInteractable(d,this.out))return!1;a=this.out.canvasGroup??null,this.handleMeshUIIntersection(t,u),t=d,r=!0}}if(!r&&this.handleMeshUiObjectWithoutShadowDom(s,u))return!0}o&&Kd&&console.log(this.context.time.frame,t);const c=this.hoveredByID.get(i.pointerId),l=(c==null?void 0:c.obj)!==t;if(l&&(c!=null&&c.obj)&&this.triggerOnExit(c.obj,c.data),this.hoveredByID.set(i.pointerId,{obj:t,data:i}),i.isDown){const u=this.pressedByID.get(i.pointerId);u?(u.obj=t,u.data=i):this.pressedByID.set(i.pointerId,{obj:t,data:i,handlers:new Set})}return(a===null||a.interactable)&&this.handleMainInteraction(t,i,l),!0}propagate(t,i,s){for(;ne.foreachComponent(t,r=>{s(r)},!1),!!t.parent;)t=t.parent}handleMainInteraction(t,i,s){if(i.pointerId===void 0)return;const r=this.pressedByID.get(i.pointerId);this.propagate(t,i,o=>{var d;const a=o;if(a.interactable===!1)return;a.onPointerEnter&&s&&a.onPointerEnter(i),i.isDown&&a.onPointerDown&&(a.onPointerDown(i),r==null||r.handlers.add(a));const c=this.context.input.getPointerPositionLastFrame(i.pointerId),l=this.context.input.getPointerPosition(i.pointerId);c&&!tt.approximately(c,l)&&a.onPointerMove&&a.onPointerMove(i),i.isUp&&(a.onPointerUp&&(a.onPointerUp(i),r==null||r.handlers.delete(a)),a.onPointerExit&&((d=i.event)==null?void 0:d.pointerType)===zf.Touch&&(a.onPointerExit(i),this.hoveredByID.delete(i.pointerId))),i.isClicked&&a.onPointerClick&&a.onPointerClick(i)}),i.isUp&&(r==null||r.handlers.forEach(o=>{o.onPointerUp&&o.onPointerUp(i)}),this.pressedByID.delete(i.pointerId))}triggerOnExit(t,i){i.used=!1,this.propagate(t,i,s=>{if(!s.gameObject||s.destroyed)return;const r=s;r.onPointerExit&&r.onPointerExit(i)})}handleMeshUiObjectWithoutShadowDom(t,i){return!t||!t.isUI?!0:this.handleMeshUIIntersection(t,i)}handleMeshUIIntersection(t,i){const s=Ec.updateState(t,i);return s&&this.currentActiveMeshUIComponents.push(s),s!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&Ec.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let t=0;t<this.currentActiveMeshUIComponents.length;t++){const i=this.currentActiveMeshUIComponents[t];Ec.resetState(i)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(t){return t?ne.isActiveSelf(t)?this.testIsVisible(t.parent):!1:!0}};let $s=Ea;h($s,"_eventSystemMap",new Map),h($s,"didSearchEventSystem",!1);class Ec{static markDirty(){this.needsUpdate=!0}static update(e,t,i=!1){if(i){e.update();return}const s=t.time.frameCount;for(const r of this.lastUpdateFrame)if(r.context===t){if(s===r.frame)return;r.frame=s;let o=this.needsUpdate||s<1;r.nextUpdate===t.time.frameCount&&(o=!0),o&&(Kd&&console.log("Update threemeshui"),this.needsUpdate=!1,e.update());return}this.lastUpdateFrame=[{context:t,frame:s,nextUpdate:s}],e.update()}static updateState(e,t){let i=null;if(e&&(i=this.findBlockInParent(e),i&&i!==this.lastSelected)){if(i.interactable===!1)return null;this.needsUpdate=!0}return i}static resetLastSelected(){const e=this.lastSelected;e&&(this.lastSelected=null,this.resetState(e))}static resetState(e){e&&(this.needsUpdate=!0)}static findBlockInParent(e){return e?e.isBlock?e:this.findBlockInParent(e.parent):null}}h(Ec,"lastSelected",null),h(Ec,"lastUpdateFrame",[]),h(Ec,"needsUpdate",!1);const B0=Symbol("cameraController");function Fte(n){return n[B0]}function AO(n,e,t){t?n[B0]=e:n[B0]===e&&(n[B0]=null)}function yx(n){const e=n[Ba];return e||(n.parent?yx(n.parent):null)}function Tb(n,e){if(!n)return;const t=n.material;if((t==null?void 0:t.isMaterial)===!0){const i=n.parent;i&&i.isText,t.side=e.doubleSided??!0?wi:Ds,t.shadowSide=e.doubleSided?wi:Ds,n.castShadow=e.castShadows?e.castShadows:!1,n.receiveShadow=e.receiveShadows?e.receiveShadows:!1}for(const i of n.children)Tb(i,e)}function Jd(n,e,t){n[e]===void 0&&console.warn("Field",e,"is undefined on",n);const i=Proxy.revocable(n[e],{set(o,a,c,l){const u=o[a],d=Reflect.set(o,a,c,l);return t(c,u),d}}),s=i.revoke,r=n[e];return i.revoke=()=>{n[e]=r,s()},n[e]=i.proxy,i}const vO=Symbol("Scheduled action");function Ute(n,e,t=Tr.OnBeforeRender){let i=n[vO];i||(i=n[vO]={});const s=e.name;i[t]||(i[t]={});const r=i[t];if(r[s])return;function*a(){e==null||e.call(n),r[s]=null}const c=n.startCoroutine(a(),t);r[s]=c}class Lz extends ye{constructor(e,t={}){const s=[e.isCubeTexture?"#define ENVMAP_TYPE_CUBE":""],r=`
|
|
5073
5073
|
varying vec3 vWorldPosition;
|
|
5074
5074
|
|
|
5075
5075
|
void main() {
|
|
@@ -5178,7 +5178,7 @@ void main() {
|
|
|
5178
5178
|
#include <colorspace_fragment>
|
|
5179
5179
|
|
|
5180
5180
|
}
|
|
5181
|
-
`,a={map:{value:e},height:{value:t.height||15},radius:{value:t.radius||100}},c=new vA(1,16),l=new Lt({uniforms:a,fragmentShader:o,vertexShader:r,side:wi});super(c,l)}set radius(e){this.material.uniforms.radius.value=e}get radius(){return this.material.uniforms.radius.value}set height(e){this.material.uniforms.height.value=e}get height(){return this.material.uniforms.height.value}}var Nte=Object.defineProperty,zte=Object.getOwnPropertyDescriptor,cr=(n,e,t,i)=>{for(var s=i>1?void 0:i?zte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Nte(e,t,s),s};const By=re("freecam"),cg=re("debugcamerafit"),Dy=re("smoothcam"),Gte={LEFT:"",UP:"",RIGHT:"",BOTTOM:""};let HS;class Ji extends Ie{constructor(){super(...arguments);h(this,"enableRotate",!0);h(this,"autoRotate",!1);h(this,"autoRotateSpeed",1);h(this,"autoFit",!1);h(this,"enableKeys",!0);h(this,"enableDamping",!0);h(this,"dampingFactor",.1);h(this,"enableZoom",!0);h(this,"minZoom",0);h(this,"maxZoom",1/0);h(this,"enablePan",!0);h(this,"lookAtConstraint",null);h(this,"lookAtConstraint01",1);h(this,"middleClickToFocus",!0);h(this,"doubleClickToFocus",!0);h(this,"useSlerp",!0);h(this,"debugLog",!1);h(this,"targetLerpSpeed",5);h(this,"autoTarget",!0);h(this,"_lookTargetPosition");h(this,"_controls",null);h(this,"_cameraObject",null);h(this,"_lerpToTargetPosition",!1);h(this,"_lerpCameraToTarget",!1);h(this,"_cameraTargetPosition",null);h(this,"_inputs",0);h(this,"_enableTime",0);h(this,"_startedListeningToKeyEvents",!1);h(this,"_eventSystem");h(this,"_afterHandleInputFn");h(this,"_camera",null);h(this,"_syncedTransform");h(this,"_didStart",!1);h(this,"targetElement",null);h(this,"onControlsChangeStarted",()=>{this._syncedTransform&&this._syncedTransform.requestOwnership()});h(this,"_shouldDisable",!1);h(this,"_haveAttachedKeyboardEvents",!1)}get isCameraController(){return!0}get controls(){return this._controls}get controllerObject(){return this._cameraObject}onStartInteraction(t){var i;(i=this.controls)==null||i.addEventListener("start",t)}awake(){this._didStart=!1,this._lookTargetPosition=new w,this._startedListeningToKeyEvents=!1}start(){if(this._didStart=!0,this.autoTarget&&this._controls){const t=ne.getComponent(this.gameObject,Li);if(t&&!this.setFromTargetPosition()){this.debugLog&&console.log("NO TARGET");const s=Ct(t.cam).length(),r=new w(0,0,-s).applyMatrix4(t.cam.matrixWorld);this.setTarget(r,!0)}if(this.autoTarget&&!this.setFromTargetPosition()){const i=new ko;i.screenPoint=new te(0,0),i.lineThreshold=.1;const s=this.context.physics.raycast(i);s.length>0&&this.setTarget(s[0].point,!0),cg&&console.log("OrbitControls hits",...s)}this.autoFit&&this.fitCamera()}this._eventSystem=$s.get(this.context)??void 0,this._eventSystem&&(this._afterHandleInputFn=this.afterHandleInput.bind(this),this._eventSystem.addEventListener(uM.AfterHandleInput,this._afterHandleInputFn))}onDestroy(){var t,i;(t=this._controls)==null||t.dispose(),(i=this._eventSystem)==null||i.removeEventListener(uM.AfterHandleInput,this._afterHandleInputFn)}onEnable(){this._enableTime=this.context.time.time;const t=ne.getComponent(this.gameObject,Li);this._camera=t;const i=t==null?void 0:t.cam;if(i&&AO(i,this,!0),!this._controls){if(!i){console.warn("OrbitControls: Requires a Camera component on the same object as this component.");return}i&&(this._cameraObject=i);const s=this.targetElement??this.context.domElement,r=i==null?void 0:i.quaternion.clone();this._controls=new JK(i,s),i==null||i.quaternion.copy(r),HS===void 0&&(HS={...this._controls.keys})}this._controls&&(By&&(this.enablePan=!0,this.enableZoom=!0,this.middleClickToFocus=!0,cl()&&(this.doubleClickToFocus=!0)),this._controls.addEventListener("start",this.onControlsChangeStarted),(i==null?void 0:i.type)==="PerspectiveCamera"?By||(this._controls.minDistance=this.minZoom,this._controls.maxDistance=this.maxZoom):By||(this._controls.minZoom=this.minZoom,this._controls.maxZoom=this.maxZoom),this._startedListeningToKeyEvents||(this._startedListeningToKeyEvents=!0,this._controls.listenToKeyEvents(window.document.body))),this._syncedTransform=ne.getComponent(this.gameObject,ah)??void 0}onDisable(){var t;(t=this._camera)!=null&&t.cam&&AO(this._camera.cam,this,!1),this._controls&&(this._controls.enabled=!1,this._controls.autoRotate=!1,this._controls.removeEventListener("start",this.onControlsChangeStarted))}afterHandleInput(t){t.detail.args.pointerId===0&&(t.detail.args.isDown?this._controls&&this._eventSystem&&(this._shouldDisable=this._eventSystem.hasActiveUI):(!t.detail.args.isPressed||t.detail.args.isUp)&&(this._shouldDisable=!1))}onBeforeRender(){var i,s,r;if(!this._controls||this._cameraObject!==this.context.mainCamera)return;(this.context.input.getPointerDown(0)||this.context.input.getPointerDown(1)||this.context.input.getPointerDown(2))&&(this._inputs+=1),this._inputs>0&&(this.enableRotate&&(this.autoRotate=!1),this._lerpCameraToTarget=!1,this._lerpToTargetPosition=!1),this._inputs=0;let t=this.middleClickToFocus&&this.context.input.getPointerClicked(1);if(t||(t=this.doubleClickToFocus&&this.context.input.getPointerDoubleClicked(0)&&this.context.time.time-this._enableTime>.3),t?this.setTargetFromRaycast():(this.context.input.getPointerDown(0)||this.context.input.mouseWheelChanged)&&(this._lerpToTargetPosition=!1,this._lerpCameraToTarget=!1),this._lerpToTargetPosition||this._lerpCameraToTarget){const o=this.context.time.deltaTime*this.targetLerpSpeed;if(this._lerpCameraToTarget&&this._cameraTargetPosition&&this._cameraObject){if(this.useSlerp){const a=(i=this._cameraObject)==null?void 0:i.position;$2(a,this._cameraTargetPosition,o)}else(s=this._cameraObject)==null||s.position.lerp(this._cameraTargetPosition,o);this._cameraObject.position.distanceTo(this._cameraTargetPosition)<1e-4&&(this._lerpCameraToTarget=!1)}this._lerpToTargetPosition&&(this.lerpTarget(this._lookTargetPosition,o),this._lookTargetPosition.distanceTo(this._controls.target)<1e-5&&(this._lerpToTargetPosition=!1))}if(!By&&((r=this.lookAtConstraint)!=null&&r.locked)&&this.setFromTargetPosition(0,this.lookAtConstraint01),this._controls){if(this.debugLog&&(this._controls.domElement=this.context.renderer.domElement),this._controls.enabled=!this._shouldDisable&&this._camera===this.context.mainCameraComponent&&!this.context.isInXR,this._controls.keys=this.enableKeys?HS:Gte,this._controls.autoRotate=this.autoRotate,this._controls.autoRotateSpeed=this.autoRotateSpeed,this._controls.enableZoom=this.enableZoom,this._controls.enableDamping=this.enableDamping,this._controls.dampingFactor=this.dampingFactor,this._controls.enablePan=this.enablePan,this._controls.enableRotate=this.enableRotate,typeof Dy=="number"||Dy===!0){this._controls.enableDamping=!0;const o=typeof Dy=="number"?Dy:.99;this._controls.dampingFactor=Math.max(.001,1-Math.min(1,o))}this.context.isInXR||this._controls.update()}}setCameraTarget(t,i=!1){return this.setCameraTargetPosition(t,i)}setCameraTargetPosition(t,i=!1){var s;t?(this._lerpCameraToTarget=!0,this._cameraTargetPosition=t.clone(),i&&this._cameraTargetPosition&&((s=this.controllerObject)==null||s.position.copy(this._cameraTargetPosition))):this._lerpCameraToTarget=!1}setFromTargetPosition(t=0,i=1){var r;if(!this._controls)return!1;const s=(r=this.lookAtConstraint)==null?void 0:r.sources;if(s&&s.length>0){const o=s[t];if(o)return o.getWorldPosition(this._lookTargetPosition),this.lerpTarget(this._lookTargetPosition,i),!0}return!1}setTarget(t=null,i=!1){this._controls&&(t!==null&&this._lookTargetPosition.copy(t),i?this._controls.target.copy(this._lookTargetPosition):this._lerpToTargetPosition=!0)}lerpTarget(t,i){this._controls&&this._controls.target.lerp(t,i)}distanceToTarget(t){return this._controls?this._controls.target.distanceTo(t):-1}setTargetFromRaycast(){var i,s;if(!this.controls)return;const t=this.context.physics.raycast();for(const r of t)if(r.distance>0&&ne.isActiveInHierarchy(r.object)){const o=yx(r.object);if(o){const a=o.canvas;if(a!=null&&a.screenspace)break}if(this._lookTargetPosition.copy(r.point),this._lerpToTargetPosition=!0,this._cameraTargetPosition=null,this.context.mainCamera){this._lerpCameraToTarget=!0;const a=Ct(this.context.mainCamera);this._cameraTargetPosition=a.clone().sub(this.controls.target).add(this._lookTargetPosition),(s=(i=this._cameraObject)==null?void 0:i.parent)==null||s.worldToLocal(this._cameraTargetPosition)}break}}fitCamera(t,i=1.1,s=!0){const r=this._cameraObject,o=this._controls;if(t!=null&&t.length||(t=this.context.scene.children),t.length<=0||!r||!o)return;const a=new w,c=new w,l=new Un;l.makeEmpty();const u=[];function d(y){let _=!0;if(y.visible&&(y instanceof uE&&(_=!1),y instanceof F1&&(_=!1),y instanceof Lz&&(_=!1),y.material instanceof __&&(_=!1),y instanceof ye||(_=!1),y!==r&&y.isUI!==!0)){if(_){cg&&console.log(y.name,y.type,y);const C=y.children;y.children=u,l.expandByObject(y,!0),y.children=C}for(const C of y.children)d(C)}}for(const y of t)y.updateMatrixWorld(),d(y);if(r.updateMatrixWorld(),r.updateProjectionMatrix(),l.getCenter(c),l.applyMatrix4(r.matrixWorldInverse),l.getSize(a),l.setFromCenterAndSize(c,a),a.length()<=1e-10){cg&&console.warn("Camera fit size is zero",l,[...t]);return}const f=r.fov,p=2*Math.atan(Math.tan(f*Math.PI/360/2)*r.aspect)/Math.PI*360,g=a.y/(2*Math.atan(Math.PI*f/360)),A=a.x/(2*Math.atan(Math.PI*p/360)),v=i*Math.max(g,A)+a.z/2;cg&&console.log("Fit camera to objects",g,A,"distance",v);const m=Ct(r),b=o.target.clone().sub(m).normalize().multiplyScalar(v);if(o.maxDistance=v*10,o.minDistance=v*.01,this.setTarget(c,s),this.autoTarget=!1,r.near=v/100,r.far=v*100,r.updateMatrixWorld(),r.updateProjectionMatrix(),r.parent){const y=r.parent.worldToLocal(o.target.clone().sub(b));this.setCameraTarget(y,s)}else console.error(`Can not fit camera ${r.name} because it has no parent`);if(cg){const y=new uE(l);this.context.scene.add(y),nF(y,O_(r)),this._haveAttachedKeyboardEvents||(this._haveAttachedKeyboardEvents=!0,document.body.addEventListener("keydown",_=>{_.code==="KeyF"&&this.fitCamera(t)}))}o.update()}}cr([x()],Ji.prototype,"enableRotate",2);cr([x()],Ji.prototype,"autoRotate",2);cr([x()],Ji.prototype,"autoRotateSpeed",2);cr([x()],Ji.prototype,"autoFit",2);cr([x()],Ji.prototype,"enableKeys",2);cr([x()],Ji.prototype,"enableDamping",2);cr([x()],Ji.prototype,"dampingFactor",2);cr([x()],Ji.prototype,"enableZoom",2);cr([x()],Ji.prototype,"minZoom",2);cr([x()],Ji.prototype,"maxZoom",2);cr([x()],Ji.prototype,"enablePan",2);cr([x(LA)],Ji.prototype,"lookAtConstraint",2);cr([x()],Ji.prototype,"lookAtConstraint01",2);cr([x()],Ji.prototype,"middleClickToFocus",2);cr([x()],Ji.prototype,"doubleClickToFocus",2);var Hte=Object.defineProperty,Vte=Object.getOwnPropertyDescriptor,to=(n,e,t,i)=>{for(var s=i>1?void 0:i?Vte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Hte(e,t,s),s},Ib=(n=>(n[n.Skybox=1]="Skybox",n[n.SolidColor=2]="SolidColor",n[n.Uninitialized=4]="Uninitialized",n))(Ib||{});const ru=re("debugcam"),yO=re("debugscreenpointtoray");var t0;const Bg=(t0=class extends Ie{constructor(){super(...arguments);h(this,"_nearClipPlane",.1);h(this,"_farClipPlane",1e3);h(this,"orthographic",!1);h(this,"orthographicSize",5);h(this,"ARBackgroundAlpha",0);h(this,"_cullingMask",4294967295);h(this,"_backgroundBlurriness");h(this,"_backgroundIntensity");h(this,"_environmentIntensity");h(this,"_targetTexture",null);h(this,"_backgroundColor");h(this,"_fov");h(this,"_cam",null);h(this,"_clearFlags",2);h(this,"_skybox")}get isCamera(){return!0}get aspect(){return this._cam instanceof qt?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._cam instanceof qt?this._cam.fov:this._fov}set fieldOfView(e){const t=this.fieldOfView!=e;if(this._fov=e,t&&this._cam&&this._cam instanceof qt){if(this._fov===void 0){console.warn("Can not set undefined fov on PerspectiveCamera");return}this._cam.fov=this._fov,this._cam.updateProjectionMatrix()}}get nearClipPlane(){return this._nearClipPlane}set nearClipPlane(e){const t=this._nearClipPlane!=e;this._nearClipPlane=e,this._cam&&t&&(this._cam.near=e,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(e){const t=this._farClipPlane!=e;this._farClipPlane=e,this._cam&&t&&(this._cam.far=e,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(e){e!==this._clearFlags&&(this._clearFlags=e,this.applyClearFlagsIfIsActiveCamera())}set cullingMask(e){this._cullingMask=e,this._cam&&(this._cam.layers.mask=e)}get cullingMask(){return this._cam?this._cam.layers.mask:this._cullingMask}set backgroundBlurriness(e){e!==this._backgroundBlurriness&&(e===void 0?this._backgroundBlurriness=void 0:this._backgroundBlurriness=Math.min(Math.max(e,0),1),this.applyClearFlagsIfIsActiveCamera())}get backgroundBlurriness(){return this._backgroundBlurriness}set backgroundIntensity(e){e!==this._backgroundIntensity&&(e===void 0?this._backgroundIntensity=void 0:this._backgroundIntensity=Math.min(Math.max(e,0),10),this.applyClearFlagsIfIsActiveCamera())}get backgroundIntensity(){return this._backgroundIntensity}set environmentIntensity(e){this._environmentIntensity=e}get environmentIntensity(){return this._environmentIntensity}get backgroundColor(){return this._backgroundColor??null}set backgroundColor(e){if(e){if(this._backgroundColor)this._backgroundColor.copy(e);else{if(!e.clone)return;this._backgroundColor=e.clone()}e.alpha===void 0&&(this._backgroundColor.alpha=1),this.applyClearFlagsIfIsActiveCamera()}}set targetTexture(e){this._targetTexture=e}get targetTexture(){return this._targetTexture}get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}screenPointToRay(e,t,i){const s=this.cam,r=Bg._origin;r.set(e,t,-1),this.context.input.convertScreenspaceToRaycastSpace(r),yO&&console.log("screenPointToRay",e.toFixed(2),t.toFixed(2),"now:",r.x.toFixed(2),r.y.toFixed(2),"isInXR:"+this.context.isInXR),r.z=-1,r.unproject(s);const o=Bg._direction.set(r.x,r.y,r.z),a=Ct(s);return o.sub(a),o.normalize(),i?(i.set(a,o),i):new Ya(a.clone(),o.clone())}awake(){yO&&window.addEventListener("pointerdown",e=>{const t=e.clientX,i=e.clientY;console.log("touch",t.toFixed(2),i.toFixed(2));const s=this.screenPointToRay(t,i),r="#"+Math.floor(Math.random()*16777215).toString(16);zc.DrawRay(s.origin,s.direction,r,10)})}onEnable(){ru&&console.log(`Camera enabled: "${this.name}". ClearFlags=${Ib[this._clearFlags]}`,this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&(this.context.setCurrentCamera(this),Wte(this)),this.applyClearFlagsIfIsActiveCamera()}onDisable(){this.context.removeCamera(this)}onBeforeRender(){if(this._cam&&this._targetTexture){this.context.isManagedExternally&&(this._warnedAboutExternalRenderer||(this._warnedAboutExternalRenderer=!0,console.warn("Rendering with external renderer is not supported yet. This may not work or throw errors. Please remove the the target texture from your camera: "+this.name,this.targetTexture))),this.context.composer;const e=this.context.renderer;if(e){const t=this.context.mainCameraComponent;this.applyClearFlags(),this._targetTexture.render(this.context.scene,this._cam,e),t==null||t.applyClearFlags()}}}buildCamera(){if(this._cam)return;const e=this.gameObject.isCamera;let t=null;if(e?(t=this.gameObject,t==null||t.layers.enableAll(),t instanceof qt&&(this._fov=t.fov)):t=this.gameObject.children[0],t&&t.isCamera)t instanceof qt&&(this._fov&&(t.fov=this._fov),t.near=this._nearClipPlane,t.far=this._farClipPlane,t.updateProjectionMatrix());else if(!this.orthographic)t=new qt(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),this.fieldOfView&&(t.fov=this.fieldOfView),this.gameObject.add(t);else{const i=this.orthographicSize*100;t=new Du(window.innerWidth/-i,window.innerWidth/i,window.innerHeight/i,window.innerHeight/-i,this._nearClipPlane,this._farClipPlane),this.gameObject.add(t)}this._cam=t,this._cam.layers.mask=this._cullingMask,this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){this.context.mainCameraComponent===this&&this.applyClearFlags()}applyClearFlags(){if(!this._cam){ru&&console.log("Camera does not exist (apply clear flags)");return}if(this.fieldOfView=this._fov,ru){const e=`Camera "${this.name}" clear flags: ${Ib[this._clearFlags]}`;console.log(e)}switch(this._clearFlags){case 1:if(Bg.backgroundShouldBeTransparent(this.context)&&(!this.ARBackgroundAlpha||this.ARBackgroundAlpha<.001)){this.context.scene.background=null,this.context.renderer.setClearColor(0,0);return}this.enableSkybox(),this._backgroundBlurriness!==void 0&&(this.context.scene.backgroundBlurriness=this._backgroundBlurriness),this._backgroundIntensity!==void 0&&(this.context.scene.backgroundIntensity=this._backgroundIntensity);break;case 2:if(this._backgroundColor){let e=this._backgroundColor.alpha;Bg.backgroundShouldBeTransparent(this.context)&&(e=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,e)}else ru&&console.warn(`Camera "${this.name}" has no background color`,this);break;case 4:this.context.scene.background=null,this.context.renderer.setClearColor(0,0);break}}enableSkybox(){this._skybox||(this._skybox=new Qte(this)),this._skybox.enable()}static backgroundShouldBeTransparent(e){var r,o,a,c;const t=(r=e.renderer.xr)==null?void 0:r.getSession();if(!t)return!1;const i=t.environmentBlendMode;ru&&pn("Environment blend mode: "+i+" on "+navigator.userAgent);const s=i==="additive"||i==="alpha-blend";if(e.xrSessionMode===zm.ImmersiveAR&&i==="opaque"){if((o=navigator.userAgent)!=null&&o.includes("OculusBrowser"))return!0;if((a=navigator.userAgent)!=null&&a.includes("Mozilla")&&((c=navigator.userAgent)!=null&&c.includes("Mobile WebXRViewer/v2")))return!0}return s}},h(t0,"_origin",new w),h(t0,"_direction",new w),t0);let Li=Bg;to([x()],Li.prototype,"fieldOfView",1);to([x()],Li.prototype,"nearClipPlane",1);to([x()],Li.prototype,"farClipPlane",1);to([x()],Li.prototype,"clearFlags",1);to([x()],Li.prototype,"orthographic",2);to([x()],Li.prototype,"orthographicSize",2);to([x()],Li.prototype,"ARBackgroundAlpha",2);to([x()],Li.prototype,"cullingMask",1);to([x()],Li.prototype,"backgroundBlurriness",1);to([x()],Li.prototype,"backgroundIntensity",1);to([x()],Li.prototype,"environmentIntensity",1);to([x(bi)],Li.prototype,"backgroundColor",1);to([x(Jl)],Li.prototype,"targetTexture",1);class Qte{constructor(e){h(this,"_camera");h(this,"_skybox");this._camera=e}get context(){var e;return(e=this._camera)==null?void 0:e.context}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?this.context.scene.background!==this._skybox&&(ru&&console.log(`Camera "${this._camera.name}" set skybox`,this._camera,this._skybox),this._skybox.colorSpace=Ze,this._skybox.mapping=Ro,this.context.scene.background=this._skybox):(console.warn(`Camera "${this._camera.name}" failed to load/find skybox texture`,this._camera.sourceId,this.context.lightmaps,"Current background: ",this.context.scene.background),(ru||ci())&&Ls(`Camera "${this._camera.name}" has no skybox texture`))}}function Wte(n){re("freecam")&&n.context.mainCameraComponent===n&&ne.getOrAddComponent(n.gameObject,Ji)}class xu extends Ie{constructor(){super(...arguments);h(this,"_listener",null)}get listener(){return this._listener==null&&(this._listener=new O1),this._listener}awake(){yn.registerWaitForAllowAudio(()=>{if(this.destroyed)return;const t=this.listener;if(t==null||t.parent)return;const i=this.context.mainCameraComponent||ne.getComponentInParent(this.gameObject,Li);i!=null&&i.cam?i.cam.add(t):this.gameObject.add(t)})}}var jte=Object.defineProperty,Xte=Object.getOwnPropertyDescriptor,bx=(n,e,t,i)=>{for(var s=i>1?void 0:i?Xte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&jte(e,t,s),s};const qte=re("debugsignals");class VA{constructor(){h(this,"guid")}}bx([x()],VA.prototype,"guid",2);class Ap{constructor(){h(this,"signal");h(this,"reaction")}}bx([x(VA)],Ap.prototype,"signal",2);bx([x(us)],Ap.prototype,"reaction",2);var xC;const bc=(xC=class extends Ie{constructor(){super(...arguments);h(this,"events")}static invoke(e){if(bc.receivers[e]){const t=bc.receivers[e];if(!t)return;for(const i of t)i.invoke(e)}}awake(){qte&&console.log("SignalReceiver awake",this)}onEnable(){if(this.events)for(const e of this.events)bc.receivers[e.signal.guid]||(bc.receivers[e.signal.guid]=[]),bc.receivers[e.signal.guid].push(this)}onDisable(){if(this.events){for(const e of this.events)if(bc.receivers[e.signal.guid]){const t=bc.receivers[e.signal.guid].indexOf(this);t>=0&&bc.receivers[e.signal.guid].splice(t,1)}}}invoke(e){if(!this.events||!Array.isArray(this.events))return;const t=typeof e=="object"?e.guid:e;for(const i of this.events)if(i.signal.guid===t)try{if(i.reaction){if(!i.reaction.invoke){console.warn("Missing invoke - possibly a serialization error",i,this);continue}}else{console.warn("Missing reaction for signal",i,this);continue}i.reaction.invoke()}catch(s){console.error(s)}}},h(xC,"receivers",{}),xC);let vp=bc;bx([x(Ap)],vp.prototype,"events",2);var Lr=(n=>(n.Activation="ActivationTrack",n.Animation="AnimationTrack",n.Audio="AudioTrack",n.Control="ControlTrack",n.Marker="MarkerTrack",n.Signal="SignalTrack",n))(Lr||{}),Sa=(n=>(n[n.None=0]="None",n[n.Hold=1]="Hold",n[n.Loop=2]="Loop",n[n.PingPong=3]="PingPong",n[n.Continue=4]="Continue",n))(Sa||{}),lI=(n=>(n.Signal="SignalEmitter",n))(lI||{});const Fd=re("debugtimeline"),zb=class extends Ie{constructor(){super(...arguments);h(this,"playableAsset");h(this,"playOnAwake");h(this,"extrapolationMode",1);h(this,"waitForAudio",!0);h(this,"_visibilityChangeEvt");h(this,"_clonedPlayableAsset",!1);h(this,"_speed",1);h(this,"_guidsMap");h(this,"_isPlaying",!1);h(this,"_internalUpdateRoutine");h(this,"_isPaused",!1);h(this,"_isStopping",!1);h(this,"_time",0);h(this,"_duration",0);h(this,"_weight",1);h(this,"_animationTracks",[]);h(this,"_audioTracks",[]);h(this,"_signalTracks",[]);h(this,"_controlTracks",[]);h(this,"_customTracks",[]);h(this,"_allTracks",[this._animationTracks,this._audioTracks,this._signalTracks,this._controlTracks,this._customTracks]);h(this,"animationCallbackReceivers",[])}static registerCreateTrack(t,i){this.createTrackFunctions[t]=i}get isPlaying(){return this._isPlaying}get isPaused(){return this._isPaused}get time(){return this._time}set time(t){typeof t=="number"&&!Number.isNaN(t)?this._time=t:(Fd||nr())&&console.error("INVALID TIMELINE.TIME VALUE",t,this.name)}get duration(){return this._duration}set duration(t){this._duration=t}get weight(){return this._weight}set weight(t){this._weight=t}get speed(){return this._speed}set speed(t){this._speed=t}awake(){var t,i,s;Fd&&console.log(this,(t=this.playableAsset)==null?void 0:t.tracks),this.rebuildGraph(),this.isValid()||console.warn("PlayableDirector is not valid",this.playableAsset,(i=this.playableAsset)==null?void 0:i.tracks,Array.isArray((s=this.playableAsset)==null?void 0:s.tracks),this)}onEnable(){var t,i,s;for(const r of this._audioTracks)(t=r.onEnable)==null||t.call(r);for(const r of this._customTracks)(i=r.onEnable)==null||i.call(r);for(const r of this._animationTracks)(s=r.onEnable)==null||s.call(r);this.playOnAwake&&this.play(),this._visibilityChangeEvt||(this._visibilityChangeEvt=()=>{switch(document.visibilityState){case"hidden":this.setAudioTracksAllowPlaying(!1);break;case"visible":this.setAudioTracksAllowPlaying(!0);break}}),window.addEventListener("visibilitychange",this._visibilityChangeEvt)}onDisable(){var t,i,s;this.stop();for(const r of this._audioTracks)(t=r.onDisable)==null||t.call(r);for(const r of this._customTracks)(i=r.onDisable)==null||i.call(r);for(const r of this._animationTracks)(s=r.onDisable)==null||s.call(r);this._visibilityChangeEvt&&window.removeEventListener("visibilitychange",this._visibilityChangeEvt)}onDestroy(){var t;for(const i of this._allTracks)for(const s of i)(t=s.onDestroy)==null||t.call(s)}rebuildGraph(){this.isValid()&&(this.resolveBindings(),this.updateTimelineDuration(),this.setupAndCreateTrackHandlers())}async play(){if(!this.isValid())return;const t=this._isPaused==!0;if(this._isPaused=!1,t&&this.invokePauseChangedMethodsOnTracks(),!this._isPlaying){if(this._isPlaying=!0,this.waitForAudio){const i=[];for(const s of this._audioTracks){const r=s.loadAudio(this._time,1,0);r&&i.push(r)}if(i.length>0&&(await Promise.all(i),!this._isPlaying))return;for(;this._audioTracks.length>0&&this._isPlaying&&!yn.userInteractionRegistered&&this.waitForAudio;)await _A(200)}this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine=this.startCoroutine(this.internalUpdate(),Tr.OnBeforeRender)}}pause(){this.isValid()&&(this._isPlaying=!1,!this._isPaused&&(this._isPaused=!0,this.evaluate(),this.invokePauseChangedMethodsOnTracks(),this.invokeStateChangedMethodsOnTracks()))}stop(){this._isStopping=!0;for(const s of this._audioTracks)s.stop();const t=this._isPaused==!0,i=this._isPlaying;this._isPlaying&&(this._time=0,this._isPlaying=!1,this._isPaused=!1,this.evaluate(),t&&this.invokePauseChangedMethodsOnTracks()),this._isPlaying=!1,this._isPaused=!1,t&&!i&&this.invokePauseChangedMethodsOnTracks(),i&&this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine&&this.stopCoroutine(this._internalUpdateRoutine),this._internalUpdateRoutine=null,this._isStopping=!1}evaluate(){if(!this.isValid())return;let t=this._time;switch(this.extrapolationMode){case 0:this._speed>0?t=Math.min(t,this._duration):this._speed<0&&(t=Math.max(t,0)),this._time=t;break;case 1:t%=this._duration,this._time=t;break;case 2:if(t>this._duration){this.stop();return}break}this.internalEvaluate(t)}isValid(){return this.playableAsset&&this.playableAsset.tracks&&Array.isArray(this.playableAsset.tracks)}*forEachTrack(){for(const t of this._allTracks)for(const i of t)yield i}get audioTracks(){return this._audioTracks}resolveGuids(t){this._guidsMap=t}invokePauseChangedMethodsOnTracks(){var t;for(const i of this.forEachTrack())(t=i.onPauseChanged)==null||t.call(i)}invokeStateChangedMethodsOnTracks(){var t;for(const i of this.forEachTrack())(t=i.onStateChanged)==null||t.call(i,this._isPlaying)}*internalUpdate(){for(;this._isPlaying&&this.activeAndEnabled;)!this._isPaused&&this._isPlaying&&(this._time+=this.context.time.deltaTime*this.speed,this.evaluate()),yield}internalEvaluate(t){for(const i of this.playableAsset.tracks)if(!i.muted)switch(i.type){case Lr.Activation:if(!this._isPlaying)continue;for(let s=0;s<i.outputs.length;s++){const r=i.outputs[s];if(typeof r=="object"){let o=!1;if(i.clips)for(const c of i.clips)c.start<=t&&t<=c.end&&(o=!0);const a=r;a.visible!==void 0&&a.visible!==o&&(a.visible=o,Fd&&console.warn(this.name,"set ActivationTrack-"+s,a.name,o,t))}}break}if(!this._isStopping)for(const i of this._animationTracks)i.evaluate(t);for(const i of this._audioTracks)i.evaluate(t);for(const i of this._signalTracks)i.evaluate(t);for(const i of this._controlTracks)i.evaluate(t);for(const i of this._customTracks)i.evaluate(t)}resolveBindings(){if(this._clonedPlayableAsset||(this._clonedPlayableAsset=!0,this.playableAsset=B_(this.playableAsset)),!this.playableAsset||!this.playableAsset.tracks)return;const t=this.findRoot(this.gameObject);for(const i of this.playableAsset.tracks){for(let s=i.outputs.length-1;s>=0;s--){let r=i.outputs[s];if(typeof r=="string"){this._guidsMap&&this._guidsMap[r]&&(r=this._guidsMap[r]);const o=ne.findByGuid(r,t);o===null||typeof o!="object"?(i.outputs.splice(s,1),console.warn("Failed to resolve binding",r,i.name,i.type)):(Fd&&console.log("Resolved binding",r,"to",o),i.outputs[s]=o)}else if(r===null){if(i.outputs.splice(s,1),zb.createTrackFunctions[i.type])continue;i.type!==Lr.Audio&&i.type!==Lr.Control&&i.type!==Lr.Marker&&i.type!==Lr.Signal&&console.warn("Missing binding",r,i.name,i.type,this.name,this.playableAsset.name)}}if(i.type===Lr.Control&&i.clips)for(let s=0;s<i.clips.length;s++){const r=i.clips[s];let o=r.asset.sourceObject;if(typeof o=="string"){this._guidsMap&&this._guidsMap[o]&&(o=this._guidsMap[o]);const a=ne.findByGuid(o,t);a===null||typeof a!="object"?console.warn("Failed to resolve sourceObject binding",o,i.name,r):(Fd&&console.log("Resolved binding",o,"to",a),r.asset.sourceObject=a)}}}}findRoot(t){return t.parent?this.findRoot(t.parent):t}updateTimelineDuration(){if(this._duration=0,!(!this.playableAsset||!this.playableAsset.tracks)){for(const t of this.playableAsset.tracks)if(t.muted!==!0){if(t.clips)for(const i of t.clips)i.end>this._duration&&(this._duration=i.end);if(t.markers)for(const i of t.markers)i.time>this._duration&&(this._duration=i.time+.001)}}}setupAndCreateTrackHandlers(){var i,s;if(this._animationTracks.length=0,this._audioTracks.length=0,this._signalTracks.length=0,!this.playableAsset)return;const t=ne.findObjectOfType(xu,this.context);for(const r of this.playableAsset.tracks){const o=r.type,a=zb.createTrackFunctions[o];if(a!=null){const c=a(this,r);if(typeof c.evaluate=="function"){c.director=this,c.track=r,this._customTracks.push(c);continue}}if(r.type===Lr.Animation){if(!r.clips||r.clips.length<=0){Fd&&console.warn("Animation track has no clips",r);continue}for(let c=r.outputs.length-1;c>=0;c--){let l=r.outputs[c];if(l instanceof Te){const d=ne.getOrAddComponent(l,ks);d&&(l=d)}const u=(i=l==null?void 0:l.gameObject)==null?void 0:i.animations;if(u){const d=new _x;d.trackOffset=r.trackOffset,d.director=this,d.track=r;for(let f=0;f<r.clips.length;f++){const p=r.clips[f],g=p.asset;if(!g){console.error("MISSING anim model?","clip#"+f,p,r,this.playableAsset,this.name);continue}const A=g.clip;let v=A;if((typeof v=="string"||typeof v=="number")&&(v=u.find(b=>b.name===A)),!v){console.warn("Could not find animationClip for model",p,r.name,this.name,(s=this.playableAsset)==null?void 0:s.name);continue}l instanceof ks&&l.runtimeAnimatorController&&(l.__internalDidAwakeAndStart||l.initializeRuntimeAnimatorController(),l.runtimeAnimatorController.mixer||l.runtimeAnimatorController.bind(l),d.mixer=l.runtimeAnimatorController.mixer),d.mixer||(d.mixer=new R_(l.gameObject)),d.clips.push(v),d.mixer.uncacheAction(v),d.createHooks(p.asset,v);const m=d.mixer.clipAction(v);d.actions.push(m),d.models.push(p)}this._animationTracks.push(d)}}}else if(r.type===Lr.Audio){if(!r.clips||r.clips.length<=0)continue;const c=new wu;if(c.director=this,c.track=r,this._audioTracks.push(c),!t)continue;c.listener=t.listener;for(let l=0;l<r.clips.length;l++){const u=r.clips[l];c.addModel(u)}}else if(r.type===Lr.Marker){const c=new Zm;if(c.director=this,c.track=r,r.markers)for(const l of r.markers)switch(l.type){case lI.Signal:c.models.push(l),c.didTrigger.push(!1);break}if(c!==null&&c.models.length>0){const l=ne.getComponent(this.gameObject,vp);l&&(c.receivers.push(l),this._signalTracks.push(c))}}else if(r.type===Lr.Signal){const c=new Zm;if(c.director=this,c.track=r,r.markers)for(const l of r.markers)c.models.push(l),c.didTrigger.push(!1);for(const l of r.outputs)c.receivers.push(l);this._signalTracks.push(c)}else if(r.type===Lr.Control){const c=new xx;if(c.director=this,c.track=r,r.clips)for(const l of r.clips)c.models.push(l);c.resolveSourceObjects(this.context),this._controlTracks.push(c)}}}setAudioTracksAllowPlaying(t){for(const i of this._audioTracks)i.onAllowAudioChanged(t)}registerAnimationCallback(t){this.animationCallbackReceivers.push(t)}unregisterAnimationCallback(t){const i=this.animationCallbackReceivers.indexOf(t);i!==-1&&this.animationCallbackReceivers.splice(i,1)}};let Zc=zb;h(Zc,"createTrackFunctions",{});const Hc=re("debugtimeline");class QA{constructor(){h(this,"director");h(this,"track")}get muted(){return this.track.muted}set muted(e){var t;e!==this.track.muted&&(this.track.muted=e,(t=this.onMuteChanged)==null||t.call(this))}*forEachClip(e=!1){var t;if((t=this.track)!=null&&t.clips)if(e)for(let i=this.track.clips.length-1;i>=0;i--)yield this.track.clips[i];else for(const i of this.track.clips)yield i}getClipTime(e,t){return t.clipIn+(e-t.start)*t.timeScale}getClipTimeNormalized(e,t){return(e-t.start)/t.duration}evaluateWeight(e,t,i,s=!0){if(t<0||t>=i.length)return 0;const r=i[t];if(s||e>=r.start&&e<=r.end){let o=1;const a=!1;if(r.easeInDuration>0){const c=Math.min((e-r.start)/r.easeInDuration,1);o*=c}if(r.easeOutDuration>0&&!a){const c=Math.min((r.end-e)/r.easeOutDuration,1);o*=c}return o}return 0}}class Yte{constructor(e){h(this,"clip");h(this,"rootPositionOffset");h(this,"rootQuaternionOffset");h(this,"rootStartPosition");h(this,"rootEndPosition");h(this,"rootStartQuaternion");h(this,"rootEndQuaternion");const t=e.getClip();this.clip=t;const i=e.getRoot(),s=i.name+".position",r=i.name+".quaternion";Hc&&console.log(t.name,t.tracks,s);for(const o of t.tracks)if(!(o.times.length<=0)){if(o.name.endsWith(s))this.rootStartPosition=new w().fromArray(o.values,0),this.rootEndPosition=new w().fromArray(o.values,o.values.length-3),this.rootPositionOffset=this.rootEndPosition.clone().sub(this.rootStartPosition),Hc&&console.log(this.rootPositionOffset);else if(o.name.endsWith(r)&&(this.rootStartQuaternion=new we().fromArray(o.values,0),this.rootEndQuaternion=new we().fromArray(o.values,o.values.length-4),this.rootQuaternionOffset=this.rootEndQuaternion.clone().multiply(this.rootStartQuaternion),Hc)){const a=new mn().setFromQuaternion(this.rootQuaternionOffset);console.log("ROT",a)}}}get hasOffsets(){return this.rootPositionOffset!==void 0||this.rootQuaternionOffset!==void 0}}class _x extends QA{constructor(){super(...arguments);h(this,"models",[]);h(this,"trackOffset");h(this,"target");h(this,"mixer");h(this,"clips",[]);h(this,"actions",[]);h(this,"_actionOffsets",[]);h(this,"_didBind",!1);h(this,"_animator",null);h(this,"_useclipOffsets",!0);h(this,"_totalOffsetPosition",new w);h(this,"_totalOffsetRotation",new we);h(this,"_totalOffsetPosition2",new w);h(this,"_totalOffsetRotation2",new we);h(this,"_summedPos",new w);h(this,"_tempPos",new w);h(this,"_summedRot",new we);h(this,"_tempRot",new we);h(this,"_clipRotQuat",new we)}onStateChanged(){this._animator&&KD(this._animator.gameObject,this,this.director.isPlaying)}createHooks(t,i){var u,d;if(((u=i.tracks)==null?void 0:u.length)<=0){console.warn("No tracks in AnimationClip",i);return}const s=i.tracks[0].name.split("."),r=s[s.length-2],o=r+".position",a=r+".quaternion";let c=!1,l=!1;for(const f of i.tracks)f.name.endsWith(o)?(c=!0,this.createPositionInterpolant(i,t,f)):f.name.endsWith(a)&&(l=!0,this.createRotationInterpolant(i,t,f));if(!c||!l){const f=(d=this.mixer)==null?void 0:d.getRoot(),p=i.tracks[0],g=p.name.lastIndexOf("."),A=p.name.substring(0,g),v=A.substring(A.lastIndexOf(".")+1),m=f.getObjectByName(v);if(m)if(c){if(!l){const b=i.tracks[0].name.substring(0,g)+".quaternion";Hc&&console.warn("Create quaternion track",v,m);const y=m.quaternion,_=new ja(b,[0,i.duration],[y.x,y.y,y.z,y.w,y.x,y.y,y.z,y.w]);i.tracks.push(_),this.createRotationInterpolant(i,t,_)}}else{const b=A+".position";Hc&&console.warn("Create position track",v,m);const y=m.position,_=new el(b,[0,i.duration],[y.x,y.y,y.z,y.x,y.y,y.z]);i.tracks.push(_),this.createPositionInterpolant(i,t,_)}}}bind(){if(!this._didBind){this._didBind=!0,Hc&&console.log(this.models),this.mixer?this.target=this.mixer.getRoot():console.warn("No mixer was assigned to animation track");for(const t of this.actions){const i=new Yte(t);this._actionOffsets.push(i)}this.target&&(this._animator=ne.getComponent(this.target,ks)??null,this._animator&&KD(this._animator.gameObject,this,!0));for(const t of this.models){const i=t.asset,s=i.position,r=i.rotation;s&&s.x!==void 0&&(s.isVector3||(i.position=new w(s.x,s.y,s.z)),r.isQuaternion||(i.rotation=new we(r.x,r.y,r.z,r.w)))}this.ensureTrackOffsets()}}ensureTrackOffsets(){if(this.trackOffset){const t=this.trackOffset.position;t&&(t.isVector3||(this.trackOffset.position=new w(t.x,t.y,t.z)));const i=this.trackOffset.rotation;i&&(i.isQuaternion||(this.trackOffset.rotation=new we(i.x,i.y,i.z,i.w)))}}evaluate(t){var c,l,u,d,f,p,g;if(this.track.muted||!this.mixer)return;this.bind(),this._totalOffsetPosition.set(0,0,0),this._totalOffsetRotation.set(0,0,0,1),this._totalOffsetPosition2.set(0,0,0),this._totalOffsetRotation2.set(0,0,0,1);let i=0,s=0,r=!1,o=!1,a=0;for(let A=0;A<this.clips.length;A++){const v=this.models[A],m=this.actions[A],b=v.asset;m.weight=0;const y=t>=v.start&&t<=v.end,_=v.preExtrapolationMode,C=v.postExtrapolationMode,M=A<this.clips.length-1?this.models[A+1]:null;let I=y,R=!1;if(!I&&!r&&v.end<t&&C!==Sa.None?(!M||M.start>t)&&(I=!0,r=!0):A==0&&!I&&!o&&v.start>t&&_!==Sa.None&&(!M||M.start<t)&&(I=!0,R=!0,o=!0),I){let E=1;E*=this.evaluateWeight(t,A,this.models,I),E*=this.director.weight;let T=y;if(R)switch(_){case Sa.Hold:break;case Sa.Loop:t+=v.start,T=!0;break;default:t+=v.start,T=!0;break}let D=this.getClipTime(t,v),K=0;const H=b.duration;if(R&&_===Sa.Hold&&(D=0),T){if(b.loop)for(K+=Math.floor(D/(H+1e-6));D>H;)D-=H}else if(!y&&r)switch(C){case Sa.Hold:D=this.getClipTime(v.end,v);break;case Sa.Loop:D%=H;break;case Sa.PingPong:const N=Math.floor(D/H)%2!==0;D%=H,N&&(D=H-D);break}v.reversed===!0?m.time=m.getClip().duration-D:m.time=D,m.timeScale=0;const V=Math.max(0,E);if(m.weight=V,a+=V,m.clampWhenFinished=!1,m.isRunning()||m.play(),this._useclipOffsets){const Y=i==0?this._totalOffsetPosition:this._totalOffsetPosition2,N=i==0?this._totalOffsetRotation:this._totalOffsetRotation2;i<1&&(s=1-E),i+=1;const L=this._summedPos.set(0,0,0),G=this._tempPos.set(0,0,0),ee=this._summedRot.identity(),$=this._tempRot.identity(),j=b.rotation;j&&(this._clipRotQuat.identity(),this._clipRotQuat.slerp(j,E));const ie=this._actionOffsets[A];if(ie.hasOffsets)for(let Ae=0;Ae<K;Ae++)ie.rootPositionOffset?G.copy(ie.rootPositionOffset):G.set(0,0,0),G.applyQuaternion(ee),this._clipRotQuat&&G.applyQuaternion(this._clipRotQuat),ie.rootQuaternionOffset&&($.copy(ie.rootQuaternionOffset),ee.multiply($)),L.add(G);this._clipRotQuat&&N.multiply(this._clipRotQuat),N.multiply(ee),b.position&&L.add(b.position),Y.add(L)}}}if(this._useclipOffsets&&(this._totalOffsetPosition.lerp(this._totalOffsetPosition2,s),this._totalOffsetRotation.slerp(this._totalOffsetRotation2,s)),this.__mixerError===void 0&&(Hc||ci())&&((l=(c=this._animator)==null?void 0:c.runtimeAnimatorController)!=null&&l.mixer)&&this.mixer!==((d=(u=this._animator)==null?void 0:u.runtimeAnimatorController)==null?void 0:d.mixer)&&(this.__mixerError=!0,console.error("AnimationTrack mixer is not shared with the animator controller - this might result in the timeline to not animate properly. Please report a bug to the Needle Engine team!",this)),(f=this._animator)!=null&&f.runtimeAnimatorController){const A=Math.max(0,1-a);(g=(p=this._animator)==null?void 0:p.runtimeAnimatorController)==null||g.update(A)}else this.mixer.update(t)}createRotationInterpolant(t,i,s){var c;const r=s.createInterpolant.bind(s),o=new we;this.ensureTrackOffsets();const a=(c=this.trackOffset)==null?void 0:c.rotation;s.createInterpolant=()=>{const l=r(),u=l.evaluate.bind(l);return l.evaluate=d=>{var p;const f=u(d);if(o.set(f[0],f[1],f[2],f[3]),o.premultiply(this._totalOffsetRotation),a&&o.premultiply(a),this.director.animationCallbackReceivers)for(const g of this.director.animationCallbackReceivers)(p=g==null?void 0:g.onTimelineRotation)==null||p.call(g,this.director,this.target,d,o);return f[0]=o.x,f[1]=o.y,f[2]=o.z,f[3]=o.w,f},l}}createPositionInterpolant(t,i,s){var u,d;const r=s.createInterpolant.bind(s),o=new w;this.ensureTrackOffsets();const a=(u=this.trackOffset)==null?void 0:u.rotation,c=(d=this.trackOffset)==null?void 0:d.position;let l;s.createInterpolant=()=>{const f=r(),p=f.evaluate.bind(f);return f.evaluate=g=>{var v,m,b;const A=p(g);if(o.set(A[0],A[1],A[2]),i.removeStartOffset&&(l===void 0?(l=null,l=(m=(v=this._actionOffsets.find(y=>y.clip===t))==null?void 0:v.rootStartPosition)==null?void 0:m.clone()):l!=null&&l.isVector3&&o.sub(l)),o.applyQuaternion(this._totalOffsetRotation),o.add(this._totalOffsetPosition),a&&o.applyQuaternion(a),c&&(o.x-=c.x,o.y+=c.y,o.z+=c.z),this.director.animationCallbackReceivers)for(const y of this.director.animationCallbackReceivers)(b=y==null?void 0:y.onTimelinePosition)==null||b.call(y,this.director,this.target,g,o);return A[0]=o.x,A[1]=o.y,A[2]=o.z,A},f}}}const Kte=re("mutetimeline"),gf=class extends QA{constructor(){super(...arguments);h(this,"models",[]);h(this,"listener");h(this,"audio",[]);h(this,"audioContextTimeOffset",[]);h(this,"lastTime",0);h(this,"_audioLoader",null)}getAudioFilePath(t){const i=this.director.sourceId;return al(i,t)}onAllowAudioChanged(t){for(let i=0;i<this.models.length;i++){const s=this.models[i];this.audio[i].setVolume(t?s.asset.volume:0)}}addModel(t){const i=new I_(this.listener);this.audio.push(i),this.models.push(t)}onDisable(){for(const t of this.audio)t.isPlaying&&t.stop()}onDestroy(){for(const t of this.audio)t.source&&(t==null||t.disconnect());this.audio.length=0}onMuteChanged(){if(this.muted)for(let t=0;t<this.audio.length;t++){const i=this.audio[t];i!=null&&i.isPlaying&&i.stop()}}stop(){for(let t=0;t<this.audio.length;t++){const i=this.audio[t];i!=null&&i.isPlaying&&i.stop()}}evaluate(t){if(Kte||this.track.muted||this.director.speed<0)return;const i=this.director.context.application.muted,s=i?.1:0;for(let r=0;r<this.models.length;r++){const o=this.models[r],a=this.audio[r];if((!a||!a.buffer)&&this.isInTimeRange(o,t-1,t+1)&&this.handleAudioLoading(o,a),yn.userInteractionRegistered!==!1&&!(a===null||!a.buffer))if(a.playbackRate=this.director.context.time.timeScale,a.loop=o.asset.loop,t>=o.start&&t<=o.end&&t<this.director.duration){if(this.director.isPlaying==!1){if(a.isPlaying&&a.stop(),this.lastTime===t)continue}else if(!a.isPlaying)a.offset=o.clipIn+(t-o.start)*o.timeScale,a.play(s);else{const l=o.clipIn+(t-o.start)*o.timeScale,u=a.context.currentTime-a._startedAt+a.offset;Math.abs(l-u)>.3&&(a.offset=l,a.stop(),a.play(s))}let c=o.asset.volume;if(i&&(c=0),o.easeInDuration>0){const l=Math.min((t-o.start)/o.easeInDuration,1);c*=l}if(o.easeOutDuration>0){const l=Math.min((o.end-t)/o.easeOutDuration,1);c*=l}a.setVolume(c*this.director.weight)}else a.isPlaying&&a.stop()}this.lastTime=t}loadAudio(t,i=0,s=0){let r=null;const o=t-s,a=t+i;for(const c of this.models)if(this.isInTimeRange(c,o,a)){const l=this.audio[this.models.indexOf(c)],u=this.handleAudioLoading(c,l);u!==null&&(r===null&&(r=[]),r.push(u))}return r!==null?Promise.all(r):null}isInTimeRange(t,i,s){return i<=t.start&&s>=t.end||i>=t.start&&i<=t.end||s>=t.start&&s<=t.end}static dispose(){gf._audioBuffers.clear()}handleAudioLoading(t,i){this._audioLoader||(this._audioLoader=new $0);const s=this.getAudioFilePath(t.asset.clip);if(gf._audioBuffers.get(s)){const o=gf._audioBuffers.get(s);return o.then(a=>{a&&i.setBuffer(a)}),o}Hc&&console.warn("LOAD audio track",s,this.director.sourceId);const r=new Promise((o,a)=>{this._audioLoader.load(s,c=>{i.setBuffer(c),o(c)},void 0,c=>{console.error("Error loading audio",c),o(null)})});return gf._audioBuffers.set(s,r),r}};let wu=gf;h(wu,"_audioBuffers",new Map);class Zm extends QA{constructor(){super(...arguments);h(this,"models",[]);h(this,"didTrigger",[]);h(this,"receivers",[])}evaluate(t){var s;if(this.track.muted)return;const i=this.director.context.time.deltaTime*1.5;for(let r=0;r<this.models.length;r++){const o=this.models[r],a=this.didTrigger[r],c=o.time-t;let l=!1;if(o.retroActive)l=c<=1e-6;else{const u=Math.abs(c);(u===0||u>=1e-5&&u<i)&&(l=!0)}if(l){if(!a)if(Hc&&console.log("Trigger signal",t,o.time,o),this.didTrigger[r]=!0,((s=this.receivers)==null?void 0:s.length)<=0)vp.invoke(o.asset);else for(const u of this.receivers)u&&u.invoke(o.asset)}else o.emitOnce||(this.didTrigger[r]=!1)}}}class xx extends QA{constructor(){super(...arguments);h(this,"models",[]);h(this,"timelines",[]);h(this,"_previousActiveModel",null)}resolveSourceObjects(t){for(let i=this.models.length-1;i>=0;i--){const r=this.models[i].asset;if(!r.sourceObject||typeof r.sourceObject!="object"){console.log("no source object, removing model",i,r),this.models.splice(i,1);continue}else{const o=ne.getComponent(r.sourceObject,Zc);this.timelines.push(o),o&&r.updateDirector&&(o.playOnAwake=!1)}}}evaluate(t){var i;this._previousActiveModel=null;for(let s=0;s<this.models.length;s++){const r=this.models[s],o=r.asset;if(t>=r.start&&t<=r.end){this._previousActiveModel=r;const a=this.getClipTime(t,r);if(o.controlActivation){const c=o.sourceObject;c.visible=!0}if(o.updateDirector){const c=this.timelines[s];c&&(c.isPlaying&&c.pause(),c.time=a,c.evaluate())}}else{const a=(i=this._previousActiveModel)==null?void 0:i.asset;if(o.controlActivation){const c=o.sourceObject;(a==null?void 0:a.sourceObject)!==c&&(c.visible=!1)}}}}}var Jte=Object.defineProperty,Zte=Object.getOwnPropertyDescriptor,Fz=(n,e,t,i)=>{for(var s=i>1?void 0:i?Zte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Jte(e,t,s),s};class Rt{constructor(e){h(this,"_active",!0);h(this,"_value");h(this,"_valueRaw");h(this,"_defaultValue");h(this,"valueProcessor");h(this,"onValueChanged");this._value=e,this._defaultValue=e,this._valueRaw=e}get overrideState(){return this._active}set overrideState(e){if(this._active===e)return;this._active=e;const t=e?this._valueRaw:this._defaultValue;this.processValue(t,!0)}get value(){return this._valueRaw}set value(e){this.processValue(e,!1)}set defaultValue(e){this._defaultValue=e}__init(){this.processValue(this._valueRaw,!0)}processValue(e,t){if(e==null||!t&&this.testIfValueChanged(e)===!1)return;const i=this._value;!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,e=this._defaultValue,this._valueRaw=e):(this._valueRaw=e,this._active&&this.valueProcessor&&(e=this.valueProcessor(e)),this._value=e),this.onValueChanged&&this.onValueChanged(e,i,this)}testIfValueChanged(e){return this._valueRaw!==e}}Fz([x()],Rt.prototype,"overrideState",1);Fz([x()],Rt.prototype,"value",1);var $te=Object.defineProperty,eie=Object.getOwnPropertyDescriptor,tie=(n,e,t,i)=>{for(var s=i>1?void 0:i?eie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&$te(e,t,s),s};const iie=re("debugpost");class Us extends Ah{constructor(t=void 0){super();h(this,"active",!0);h(this,"_result");h(this,"_didCreateVolumeParameters",!1);if(t){this.ensureVolumeParameters();for(const i of Object.keys(t)){const s=t[i],r=this[i];r instanceof Rt&&(r.value=s)}}}onEnable(){this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){this.active=!1}init(){}apply(){var t;return this.ensureVolumeParameters(),this._result||(this._result=(t=this.onCreateEffect)==null?void 0:t.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){iie&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(t=>t.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const t=Object.keys(this);for(const i of t){const s=this[i];s instanceof Rt&&s.__init()}}onAfterDeserialize(t,i){if(typeof t=="object"){const s=this.$serializedTypes;if(s){for(const r of Object.keys(s))if(s[r]===Rt){const a=t[r];if(a!==void 0){const c=this[r];c.value=a}}}}}onEditorModification(t){const i=t.propertyName;if(this[i]instanceof Rt){const s=t.value;return this[i].value=s,!0}}ensureVolumeParameters(){if(this._didCreateVolumeParameters)return;this._didCreateVolumeParameters=!0;const t=this.$serializedTypes;if(t)for(const i of Object.keys(t))t[i]===Rt&&(this[i]||(this[i]=new Rt))}}tie([x()],Us.prototype,"active",2);var nie=Object.defineProperty,sie=Object.getOwnPropertyDescriptor,rie=(n,e,t,i)=>{for(var s=i>1?void 0:i?sie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&nie(e,t,s),s};const oie=re("debugpost"),dM={};function No(n,e){dM[n]=e}function aie(n){return n.__type in dM?dM[n.__type]:(oie&&n.__type&&console.warn("Unknown postprocessing type",n.__type,n),Us)}class WA{constructor(){h(this,"components",[])}init(){var e;(e=this.components)==null||e.forEach(t=>t.init())}}rie([lp([n=>aie(n),Us])],WA.prototype,"components",2);var cie=Object.defineProperty,lie=Object.getOwnPropertyDescriptor,hie=(n,e,t,i)=>{for(var s=i>1?void 0:i?lie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&cie(e,t,s),s};class jA extends Us{constructor(){super(...arguments);h(this,"preset")}get typeName(){return"Antialiasing"}onCreateEffect(){const t=new Iq({preset:Xd.HIGH,edgeDetectionMode:oT.DEPTH});return this.preset.onValueChanged=i=>{t.applyPreset(i)},t}}hie([x(Rt)],jA.prototype,"preset",2);No("Antialiasing",jA);class wx{constructor(){h(this,"files",[])}get extensionName(){return"Audio"}onExportObject(e,t,i){const s=ne.getComponents(e,yn);if(s.length)for(const r of s){if(!r.clip||!r.playOnAwake)continue;const o=r.clip.split("/").pop();this.files.includes(r.clip)||this.files.push(r.clip),t.addEventListener("serialize",(a,c)=>{a.appendLine(),a.beginBlock(`def SpatialAudio "${t.name}"`),a.appendLine(`uniform asset filePath = @audio/${o}@`),a.appendLine(`uniform token auralMode = "${r.spatialBlend>0?"spatial":"nonSpatial"}"`),a.appendLine(`uniform token playbackMode = "${r.loop?"loopFromStage":"onceFromStart"}"`),a.appendLine(`uniform float gain = ${r.volume}`),a.closeBlock()})}}async onAfterSerialize(e){for(const t of this.files){const i=t.split("/").pop(),o=await(await(await fetch(t)).blob()).arrayBuffer(),a=new Uint8Array(o);e.files["audio/"+i]=a}}}const Rb="noVoip",vr=re("debugvoip"),uie=re("voip");class die{constructor(e){h(this,"id");this.id=e}}class fie{constructor(e,t,i,s){h(this,"peer");h(this,"voip");h(this,"userId");h(this,"peerId");h(this,"call",null);h(this,"callErrorListener",null);h(this,"stream",null);this.voip=e,this.peer=t,this.userId=i,this.peerId=s}close(){var e;vr&&console.log("close voip call"),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.open&&this.call.close(),(e=this.stream)==null||e.getTracks().forEach(function(t){t.stop()})}updateMute(e){var i;if(!this.stream)return;const t=(i=this.stream)==null?void 0:i.getAudioTracks();for(const s of t)s.enabled=!e}async startVoipCall(){if(!await dl.HasMicrophonePermissions()){console.warn("no permission to use microphone, can not start call");return}vr&&console.log("start voip call");try{this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}catch(t){console.error(t);return}this.updateMute(this.voip.muteOutput),vr&&console.log(this.stream),this.call=this.peer.call(this.peerId,this.stream,{metadata:{userId:this.userId}}),this.call.on("error",t=>{console.error(t)}),this.call.on("stream",t=>{vr&&console.log("received stream from remote again",t)}),this.peer.on("close",this.onCallClose.bind(this)),this.callErrorListener=t=>{var i;t.message.includes(this.peerId)?(console.log("Could not connect to "+this.peerId),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.close(),(i=this.stream)==null||i.getTracks().forEach(function(s){s.stop()}),this.stream=null):console.error(t)},this.peer.on("error",this.callErrorListener)}onCallClose(e){vr&&console.log("call closed",e)}}class pie{constructor(e,t,i){h(this,"voip");h(this,"call");h(this,"audio",null);h(this,"stream",null);h(this,"obj");h(this,"analyzer",null);h(this,"waitingForStart",!1);h(this,"closed",!1);h(this,"audioElement",null);this.voip=e,this.obj=t,this.call=i}get currentStream(){return this.stream}get currentAudio(){return this.audio}get currentAnalyzer(){return this.analyzer}openAudioStream(e){const t=e.getAudioTracks();for(const i of t)if(i.kind==="audio"&&i.readyState==="live"){this.open(i);return}console.warn("failed finding valid audio stream to begin call")}open(e){console.assert(e.kind==="audio","invalid track kind, expected audio but received "+e.kind),!this.waitingForStart&&(this.waitingForStart=!0,yn.userInteractionRegistered||vr&&console.log("Incoming call, waiting for user interaction before opening audio"),yn.registerWaitForAllowAudio(async()=>{if(this.call.open&&!this.closed){vr&&console.log("Setup audio and begin listening"),this.stream=new MediaStream([e]);const t=new O1;this.audio=new I_(t),this.audio.setVolume(this.voip.muteInput?0:1),this.audio.setMediaStreamSource(this.stream);const i=document.createElement("audio");this.audioElement=i,i.style.display="none",document.body.appendChild(i),i.srcObject=this.stream,i.sinkId!==void 0&&navigator.mediaDevices.enumerateDevices().then(s=>{if(i){console.log(s);for(const r of s)if(r.label==="Speakerphone"){i.sinkId=r.deviceId;break}}}),vr&&console.log("call is setup, you should hear something now"),this.analyzer=new E2(this.audio,32)}}))}close(){var e,t,i;this.closed=!0,(e=this.call)!=null&&e.open&&this.call.close(),(t=this.audio)==null||t.disconnect(),(i=this.stream)==null||i.getTracks().forEach(s=>{s.stop()}),this.stream=null,this.audioElement&&this.audioElement.remove()}}class dl extends Ie{constructor(){super(...arguments);h(this,"requireParam",!1);h(this,"peer",null);h(this,"model",null);h(this,"connections",{});h(this,"currentIncomingCalls",{});h(this,"_inputMuted",!1);h(this,"_outputMuted",!1)}set muteInput(t){var s;if(t===this._inputMuted||(this._inputMuted=t,!this.currentIncomingCalls))return;const i=this._inputMuted?0:1;for(const r in this.currentIncomingCalls){const o=this.currentIncomingCalls[r];(s=o==null?void 0:o.currentAudio)==null||s.setVolume(i)}}get muteInput(){return this._inputMuted}set muteOutput(t){if(t!==this._outputMuted&&(this._outputMuted=t,!!this.connections))for(const i in this.connections){const s=this.connections[i];s==null||s.updateMute(t)}}get muteOutput(){return this._outputMuted}getFrequency(t){if(t===null){for(const s in this.currentIncomingCalls){const r=this.currentIncomingCalls[s];if(r&&r.currentAnalyzer)return r.currentAnalyzer.getAverageFrequency()}return null}const i=this.currentIncomingCalls[t];return i&&i.currentAnalyzer?i.currentAnalyzer.getAverageFrequency():null}awake(){if(re(Rb)){console.log("VOIP is disabled by url parameter: "+Rb);return}if(this.requireParam&&!uie){console.debug("VOIP must be enabled explicitly by url parameter");return}if(Dm()&&Rc()){console.log("VOIP is currently not supported on Safari iOS");return}this.peer=Y1(),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,this.context.connection.beginListen(on.JoinedRoom,t=>{navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).catch(i=>{console.error("Error initializing VoIP connection.",i)})}),this.context.connection.beginListen("peer-update-id",t=>{if(t.id!==this.context.connection.connectionId){const i=this.connections[t.id];if(i&&i.close(),this.peer&&this.context.connection.connectionId){const s=new fie(this,this.peer,this.context.connection.connectionId,t.peerId);this.connections[t.id]=s,s.startVoipCall()}}}),this.context.connection.beginListen(on.UserLeftRoom,t=>{const{userId:i}=t,s=this.connections[i];this.connections[i]=null,s&&s.close();const r=this.currentIncomingCalls[i];vr&&console.log("UserLeftRoom",t,i,r),r&&(r.close(),this.currentIncomingCalls[i]=null)}),this.peer.on("open",this.onOpenPeerConnection.bind(this))}onEnable(){}onDisable(){console.log("TODO: close all");for(const t in this.currentIncomingCalls)try{const i=this.currentIncomingCalls[t];i==null||i.close();const s=this.connections[t];s==null||s.close()}catch(i){console.error(i)}}async onOpenPeerConnection(t){vr&&console.log("Peer connection established and received id"),this.model=new die(t),this.context.connection.send("peer-update-id",this.model,Ar.OnRoomJoin),this.peer&&(this.peer.on("call",this.onReceiveCall.bind(this)),this.peer.on("connection",function(i){vr&&console.log("CONNECTION",i),i.on("data",function(s){vr&&console.log("Received",s)})}))}async onReceiveCall(t){if(!t)return;const{metadata:i}=t;console.assert(i.userId);const{userId:s}=i,r=this.currentIncomingCalls[s];if(r&&r.close(),vr&&console.log("received call"),await dl.HasMicrophonePermissions())try{const o=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1});t.answer(o)}catch(o){console.error("Error initializing VoIP connection.",o)}else t.answer(null);this.currentIncomingCalls[s]=new pie(this,this.gameObject,t),t.on("stream",o=>{var a;vr&&console.log("receive caller stream, will setup audio now"),(a=this.currentIncomingCalls[s])==null||a.openAudioStream(o)}),t.on("error",console.error)}static async HasMicrophonePermissions(){try{return(await navigator.permissions.query({name:"microphone"})).state!=="denied"}catch(t){return console.error("Error querying `microphone` permissions.",t),!1}}}var gie=Object.defineProperty,mie=Object.getOwnPropertyDescriptor,Uz=(n,e,t,i)=>{for(var s=i>1?void 0:i?mie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&gie(e,t,s),s};const Aie=re("debugmouth");class XA extends Ie{constructor(){super(...arguments);h(this,"idle",[]);h(this,"talking",[]);h(this,"marker",null);h(this,"voip",null);h(this,"lastMouthChangeTime",0);h(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=ne.findObjectOfType(dl,this.context),this.marker||(this.marker=ne.getComponentInParent(this.gameObject,Jn))},3e3)}update(){var s;if(!this.voip||this.context.time.frameCount%10!==0)return;let t=((s=this.marker)==null?void 0:s.connectionId)??null;if(!t){Aie&&(t=null);return}const i=this.voip.getFrequency(t)??0;this.updateLips(i)}updateLips(t){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&t>30){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,i)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,i)}}}setMouthShapeActive(t,i){if(t){t!=this.idle?this.idle.map(s=>s.visible=!1):this.talking.map(s=>s.visible=!1);for(let s=0;s<t.length;s++){const r=t[s];r&&(r.visible=s===i)}}}}Uz([x(Te)],XA.prototype,"idle",2);Uz([x(Te)],XA.prototype,"talking",2);class hI extends Ie{constructor(){super(...arguments);h(this,"voip",null);h(this,"marker",null);h(this,"_startPosition",null)}awake(){this.voip=ne.findObjectOfType(dl,this.context),this.marker=ne.getComponentInParent(this.gameObject,Jn)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const t=this.marker.connectionId,i=this.voip.getFrequency(t);if(i==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const s=i/100;this.gameObject.position.y=this._startPosition.y+s*.07}}var vie=Object.defineProperty,yie=Object.getOwnPropertyDescriptor,Sx=(n,e,t,i)=>{for(var s=i>1?void 0:i?yie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&vie(e,t,s),s};class Hu extends Ie{constructor(){super(...arguments);h(this,"eyes",[]);h(this,"lastBlinkTime",0);h(this,"blinkLength",0);h(this,"eyesOpen",!0);h(this,"state",null)}awake(){this.state=ne.getComponentInParent(this.gameObject,jr)}update(){if(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)return;if(this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const i of this.eyes)i&&(i.visible=this.eyesOpen)}}}Sx([x(Te)],Hu.prototype,"eyes",2);Sx([x()],Hu.prototype,"lastBlinkTime",2);Sx([x()],Hu.prototype,"blinkLength",2);Sx([x()],Hu.prototype,"eyesOpen",2);var bie=Object.defineProperty,_ie=Object.getOwnPropertyDescriptor,uI=(n,e,t,i)=>{for(var s=i>1?void 0:i?_ie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&bie(e,t,s),s},wC;const Nz=(wC=class extends Ie{constructor(){super(...arguments);h(this,"head",null);h(this,"eyes",null);h(this,"target",null);h(this,"brain",null);h(this,"vec",new w);h(this,"currentTargetPoint",new w)}awake(){this.brain||(this.brain=ne.getComponentInParent(this.gameObject,Vm)),this.brain||(console.log("No look at brain found, adding it now"),this.brain=ne.addNewComponent(this.gameObject,Vm)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const e=this.target;if(e&&this.head){const t=this.eyes;if(t){const i=Ct(e);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const s=Ct(this.head),r=this.vec.copy(this.currentTargetPoint).sub(s).normalize();if(r.length()<.1)return;const o=Nz.forward;if(o.set(0,0,1),o.applyQuaternion(zn(this.head)),o.dot(r)>.45)for(let c=0;c<t.length;c++)t[c].lookAt(this.currentTargetPoint)}}}},h(wC,"forward",new w(0,0,1)),wC);let yp=Nz;uI([x(Te)],yp.prototype,"head",2);uI([x(Te)],yp.prototype,"eyes",2);uI([x(Te)],yp.prototype,"target",2);var xie=Object.defineProperty,wie=Object.getOwnPropertyDescriptor,dI=(n,e,t,i)=>{for(var s=i>1?void 0:i?wie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&xie(e,t,s),s};class bp extends Ie{constructor(){super(...arguments);h(this,"length",1);h(this,"depthTest",!0);h(this,"isGizmo",!0);h(this,"_axes",null)}onEnable(){if(this.isGizmo&&!IA)return;this._axes||(this._axes=new tp(this.length)),this.gameObject.add(this._axes);const t=this._axes.material;t&&t.depthTest!==void 0&&(t.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}dI([x()],bp.prototype,"length",2);dI([x()],bp.prototype,"depthTest",2);dI([x()],bp.prototype,"isGizmo",2);class fI extends Ie{constructor(){super(...arguments);h(this,"from");h(this,"to");h(this,"hint");h(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const t=Ct(this.to).clone(),i=Ct(this.from).clone(),s=t.distanceTo(i),r=t.clone();r.sub(i);const o=i.clone();o.add(t),o.multiplyScalar(.5);const a=Ct(this.hint).clone();a.sub(o);const c=new w;c.crossVectors(a,r),c.crossVectors(r,c),c.normalize();const l=s*.5,u=Math.max(this.desiredDistance,l),d=Math.sqrt(u*u-l*l),f=c.clone();f.multiplyScalar(d),f.add(o),Mn(this.gameObject,f);const p=o.clone();p.sub(c),this.gameObject.lookAt(p)}}const bO=re("debugusdz");class Cx{constructor(){h(this,"behaviours",[]);h(this,"behaviourComponents",[]);h(this,"behaviourComponentsCopy",[])}get extensionName(){return"Behaviour"}addBehavior(e){this.behaviours.push(e)}onBeforeBuildDocument(e){const t=[];return e.root.traverse(i=>{ne.foreachComponent(i,s=>{var o;const r=s;if(typeof r.createBehaviours=="function"||typeof r.beforeCreateDocument=="function"||typeof r.afterCreateDocument=="function"||typeof r.afterSerialize=="function"){this.behaviourComponents.push(r);const a=(o=r.beforeCreateDocument)==null?void 0:o.call(r,this,e);a instanceof Promise&&t.push(a)}},!1)}),Promise.all(t)}onExportObject(e,t,i){var s;for(const r of this.behaviourComponents)(s=r.createBehaviours)==null||s.call(r,this,t,i)}onAfterBuildDocument(e){for(const t of this.behaviourComponents)typeof t.afterCreateDocument=="function"&&t.afterCreateDocument(this,e);this.behaviourComponentsCopy=this.behaviourComponents.slice(),this.behaviourComponents.length=0}onAfterHierarchy(e,t){var i;if((i=this.behaviours)!=null&&i.length){t.beginBlock('def Scope "Behaviors"');for(const s of this.behaviours)s.writeTo(this,e.document,t);t.closeBlock()}}async onAfterSerialize(e){bO&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const t of this.behaviourComponentsCopy)typeof t.afterSerialize=="function"&&(bO&&console.log("behaviour has afterSerialize",t),t.afterSerialize.constructor.name==="AsyncFunction"?await t.afterSerialize(this,e):t.afterSerialize(this,e))}}var Sie=Object.defineProperty,Cie=Object.getOwnPropertyDescriptor,pI=(n,e,t,i)=>{for(var s=i>1?void 0:i?Cie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Sie(e,t,s),s};class Vu extends Us{constructor(){super(...arguments);h(this,"threshold");h(this,"intensity");h(this,"scatter");h(this,"selectiveBloom",!0)}get typeName(){return"Bloom"}init(){this.threshold.defaultValue=1,this.intensity.defaultValue=0,this.scatter.defaultValue=.2,this.selectiveBloom?(this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>1*Math.PI*(1-t)):(this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>100*(1-t))}onCreateEffect(){let t;if(this.selectiveBloom){const i=t=new nN(this.context.scene,this.context.mainCamera,{blendFunction:zt.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,intensity:this.intensity.value});i.inverted=!0}else t=new hT;return this.intensity.onValueChanged=i=>{t.intensity=i},this.threshold.onValueChanged=i=>{t.luminanceMaterial.threshold=i},this.scatter.onValueChanged=i=>{t.luminancePass.enabled=!0,t.luminanceMaterial.smoothing=i},t}}pI([x(Rt)],Vu.prototype,"threshold",2);pI([x(Rt)],Vu.prototype,"intensity",2);pI([x(Rt)],Vu.prototype,"scatter",2);No("Bloom",Vu);var Eie=Object.defineProperty,Mie=Object.getOwnPropertyDescriptor,fa=(n,e,t,i)=>{for(var s=i>1?void 0:i?Mie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Eie(e,t,s),s};class Za extends Ie{constructor(){super(...arguments);h(this,"attachedRigidbody",null);h(this,"isTrigger",!1);h(this,"sharedMaterial");h(this,"updateProperties",()=>{var t;(t=this.context.physics.engine)==null||t.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ii))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ii))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ii))}onDisable(){var t;(t=this.context.physics.engine)==null||t.removeBody(this)}get body(){var t;return(t=this.context.physics.engine)==null?void 0:t.getBody(this)}}fa([x(Ii)],Za.prototype,"attachedRigidbody",2);fa([x()],Za.prototype,"isTrigger",2);fa([x()],Za.prototype,"sharedMaterial",2);class qA extends Za{constructor(){super(...arguments);h(this,"radius",.5);h(this,"center",new w(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addSphereCollider(this,this.center),z1(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),N2(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}fa([ys(),x()],qA.prototype,"radius",2);fa([x(w)],qA.prototype,"center",2);class YA extends Za{constructor(){super(...arguments);h(this,"size",new w(1,1,1));h(this,"center",new w(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addBoxCollider(this,this.center,this.size)}onValidate(){this.updateProperties()}}fa([ys(),x(w)],YA.prototype,"size",2);fa([x(w)],YA.prototype,"center",2);class KA extends Za{constructor(){super(...arguments);h(this,"sharedMesh");h(this,"convex",!1)}onEnable(){var t,i,s,r,o;if(super.onEnable(),(t=this.sharedMesh)!=null&&t.isMesh||this.gameObject instanceof ye&&(this.sharedMesh=this.gameObject),(i=this.sharedMesh)!=null&&i.isMesh)(s=this.context.physics.engine)==null||s.addMeshCollider(this,this.sharedMesh,this.convex,ls(this.gameObject));else{const a=this.sharedMesh;if(a!=null&&a.isGroup){console.warn(`MeshCollider mesh is a group "${(r=this.sharedMesh)==null?void 0:r.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);for(const c in a.children){const l=a.children[c];l.isMesh&&((o=this.context.physics.engine)==null||o.addMeshCollider(this,l,this.convex,ls(this.gameObject)))}}}}}fa([x()],KA.prototype,"convex",2);class lh extends Za{constructor(){super(...arguments);h(this,"center",new w(0,0,0));h(this,"radius",.5);h(this,"height",2)}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addCapsuleCollider(this,this.center,this.height,this.radius)}}fa([x(w)],lh.prototype,"center",2);fa([x()],lh.prototype,"radius",2);fa([x()],lh.prototype,"height",2);var Tie=Object.defineProperty,Iie=Object.getOwnPropertyDescriptor,gI=(n,e,t,i)=>{for(var s=i>1?void 0:i?Iie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Tie(e,t,s),s};class Qu extends Ie{constructor(){super(...arguments);h(this,"objectBounds",!1);h(this,"color");h(this,"isGizmo",!0);h(this,"_gizmoObject",null);h(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!IA||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new P_(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=YN(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),Tr.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){var t;for(;this._boxHelper;)(t=this._boxHelper)==null||t.update(),yield}}gI([x()],Qu.prototype,"objectBounds",2);gI([x(_e)],Qu.prototype,"color",2);gI([x()],Qu.prototype,"isGizmo",2);var Rie=Object.defineProperty,Pie=Object.getOwnPropertyDescriptor,JA=(n,e,t,i)=>{for(var s=i>1?void 0:i?Pie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Rie(e,t,s),s};const VS=re("debugui"),QS=re("debuguilayout");class mI{constructor(){h(this,"width");h(this,"height")}}class AI{constructor(){h(this,"x");h(this,"y");h(this,"width");h(this,"height")}}const qo=new w,lg=new Me,Oy=new we,zz=class extends aa{constructor(){super(...arguments);h(this,"_anchoredPosition");h(this,"sizeDelta",new te(100,100));h(this,"pivot",new te(.5,.5));h(this,"anchorMin",new te(0,0));h(this,"anchorMax",new te(1,1));h(this,"lastMatrix");h(this,"rectBlock");h(this,"_transformNeedsUpdate",!1);h(this,"_initialPosition");h(this,"_parentRectTransform");h(this,"_lastUpdateFrame",-1);h(this,"_lastAnchoring");h(this,"_createdBlocks",[]);h(this,"_createdTextBlocks",[])}get parent(){return this._parentRectTransform}get translation(){return this.gameObject.position}get rotation(){return this.gameObject.quaternion}get scale(){return this.gameObject.scale}get anchoredPosition(){return this._anchoredPosition||(this._anchoredPosition=new te),this._anchoredPosition}set anchoredPosition(e){this._anchoredPosition=e}get width(){if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const e=this._parentRectTransform.width,t=this.anchorMax.x-this.anchorMin.x;let i=e*t;return i+=this.sizeDelta.x,i}return this.sizeDelta.x}get height(){if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const e=this._parentRectTransform.height,t=this.anchorMax.y-this.anchorMin.y;let i=e*t;return i+=this.sizeDelta.y,i}return this.sizeDelta.y}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new te),this.lastMatrix=new Me,this.rectBlock=new Te,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,Jd(this,"_anchoredPosition",()=>{this.markDirty()}),Jd(this,"sizeDelta",()=>{this.markDirty()}),Jd(this,"pivot",()=>{this.markDirty()}),Jd(this,"anchorMin",()=>{this.markDirty()}),Jd(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var e;super.onEnable(),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(e=this.Canvas)==null||e.registerTransform(this)}onDisable(){var e;super.onDisable(),this.removeShadowComponent(),(e=this.Canvas)==null||e.unregisterTransform(this)}onParentRectTransformChanged(e){this._transformNeedsUpdate||this.onApplyTransform(QS?`${e.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(QS&&console.warn("RectTransform markDirty()",this.name),this._transformNeedsUpdate=!0,this._lastUpdateFrame=-1)}updateTransform(){(this._transformNeedsUpdate||!this.lastMatrix.equals(this.gameObject.matrix))&&this.canUpdate()&&this.onApplyTransform(this._transformNeedsUpdate?"Marked dirty":"Matrix changed")}canUpdate(){return this._transformNeedsUpdate&&this.activeAndEnabled&&this._lastUpdateFrame!==this.context.time.frame}onApplyTransform(e){var s;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const t=this.shadowComponent;if(!t)return;this.gameObject.parent?this._parentRectTransform=ne.getComponentInParent(this.gameObject.parent,zz):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,QS&&console.warn("RectTransform → ApplyTransform",this.name+" because "+e),this.isRoot()?this.Root.screenspace||(t.rotation.y=Math.PI):(t.matrix.identity(),t.matrixAutoUpdate=!1,qo.set(0,0,0),this.applyPivot(qo),t.matrix.setPosition(qo.x,qo.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(Oy.copy(this.gameObject.quaternion),Oy.x*=-1,Oy.z*=-1,lg.makeRotationFromQuaternion(Oy),t.matrix.premultiply(lg)),qo.set(0,0,0),this.applyAnchoring(qo),(s=this.Canvas)!=null&&s.screenspace?qo.z+=.1:qo.z+=.01,lg.identity(),lg.setPosition(qo.x,qo.y,qo.z),t.matrix.premultiply(lg),t.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const i=!0;for(const r of sT(this.gameObject,aa,i,1)){if(r===this||!r.activeAndEnabled)continue;const o=r;o.onParentRectTransformChanged&&o.onParentRectTransformChanged(this)}}applyAnchoring(e){this._lastAnchoring||(this._lastAnchoring=new te);const t=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=t.x,this.gameObject.position.y+=t.y,this._lastAnchoring.copy(this._anchoredPosition),e.x+=this._initialPosition.x-this.gameObject.position.x,e.y+=this._initialPosition.y-this.gameObject.position.y,e.z+=this._initialPosition.z-this.gameObject.position.z;const i=this._parentRectTransform;if(i){let s=0;const r=1-this.anchorMax.y-this.anchorMin.y;s-=i.height*.5*r,e.y+=s;let o=0;const a=1-this.anchorMax.x-this.anchorMin.x;o-=i.width*.5*a,e.x+=o}}applyPivot(e){if(this.pivot&&!this.isRoot()){const t=this.pivot.x-.5;e.x-=t*this.sizeDelta.x*this.gameObject.scale.x;const i=this.pivot.y-.5;e.y-=i*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const e={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(e),e}ensureValidSize(e,t=1e-4){return e.width<=0&&(e.width=t),e.height<=0&&(e.height=1e-4),e}createNewBlock(e){e={...this.getBasicOptions(),...e},VS&&console.log(this.name,e);const t=new aI(e);return this._createdBlocks.push(t),t}createNewText(e){VS&&console.log(e),e={...this.getBasicOptions(),...e},VS&&console.log(this.name,e);const t=new Oz(e);return this._createdTextBlocks.push(t),t}};let rr=zz;JA([x(te)],rr.prototype,"anchoredPosition",1);JA([x(te)],rr.prototype,"sizeDelta",2);JA([x(te)],rr.prototype,"pivot",2);JA([x(te)],rr.prototype,"anchorMin",2);JA([x(te)],rr.prototype,"anchorMax",2);class Bie extends Dz{constructor(e,t={}){super(e),e._simpleState__activeStates=[],e._simpleState__normalStyles={},e._simpleState__states=t,e._simpleState__statesProperties={};for(const i in t)for(const s in t[i])e._simpleState__statesProperties[s]||(e._simpleState__statesProperties[s]=[]),e._simpleState__statesProperties[s].push(i);for(const i of e._components)e._simpleState__statesProperties[i.id]&&(e._simpleState__normalStyles[i.id]=i.inline?i.inline:i._value);e.__overridedSet=e.set,e.set=this.storeSet.bind(e),e.renderStates=this.renderStates.bind(e),e.setupState=this.setupState.bind(e),e.setState=this.setState.bind(e),e.activatePseudoState=this.activatePseudoState.bind(e),e.deactivatePseudoState=this.deactivatePseudoState.bind(e),e.togglePseudoState=this.togglePseudoState.bind(e)}act(){}attach(){}detach(){}setupState(e,t){this._simpleState__states[e]=t;const i=[];for(const s in t)this._simpleState__statesProperties[s]||(this._simpleState__statesProperties[s]=[],i.push(s)),this._simpleState__statesProperties[s].push(e);for(const s of this._components)i.indexOf(s.id)>-1&&(this._simpleState__normalStyles[s.id]=s.inline?s.inline:s._value)}renderStates(){let e={...this._simpleState__normalStyles};for(const t in this._simpleState__states)this._simpleState__activeStates.indexOf(t)>-1&&(e={...e,...this._simpleState__states[t]});this.set(e,!1)}storeSet(e,t=!0){if(t)for(const i in e)this._simpleState__statesProperties[i]&&(this._simpleState__normalStyles[i]=e[i]);this.__overridedSet(e)}activatePseudoState(e){this._simpleState__activeStates.indexOf(e)===-1&&(this._simpleState__activeStates.push(e),this.renderStates())}deactivatePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1&&(this._simpleState__activeStates.splice(t,1),this.renderStates())}togglePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1?this._simpleState__activeStates.splice(t,1):this._simpleState__activeStates.push(e),this.renderStates()}setState(e){Array.isArray(e)?this._simpleState__activeStates=e:this._simpleState__activeStates=[e],this.renderStates()}}var Die=Object.defineProperty,Oie=Object.getOwnPropertyDescriptor,Gz=(n,e,t,i)=>{for(var s=i>1?void 0:i?Oie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Die(e,t,s),s};class _p extends Ie{constructor(){super(...arguments);h(this,"effectColor");h(this,"effectDistance")}}Gz([x(bi)],_p.prototype,"effectColor",2);Gz([x(te)],_p.prototype,"effectDistance",2);var kie=Object.defineProperty,Lie=Object.getOwnPropertyDescriptor,Hz=(n,e,t,i)=>{for(var s=i>1?void 0:i?Lie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&kie(e,t,s),s};const ky={backgroundColor:new _e(1,1,1),backgroundOpacity:1,borderColor:new _e(1,1,1),borderOpacity:1};var SC;const D0=(SC=class extends aa{constructor(){super(...arguments);h(this,"_alphaFactor",1);h(this,"raycastTarget",!0);h(this,"uiObject",null);h(this,"_color",null);h(this,"_rect",null);h(this,"_stateManager",null);h(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new bi(1,1,1,1)),this._color}set color(e){(!this._color||this._color.r!==e.r||this._color.g!==e.g||this._color.b!==e.b||this._color.alpha!==e.alpha)&&(this._color||(this._color=new bi(1,1,1,1)),this._color.copy(e))}setAlphaFactor(e){this._alphaFactor=e,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(ky.backgroundColor=this._color,ky.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(ky,this._alphaFactor),this.uiObject.set(ky),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=ne.getComponent(this.gameObject,rr)),!this._rect)throw new Error("Not Supported: Make sure to add a RectTransform component before adding a UI Graphic component.");return this._rect}onParentRectTransformChanged(){var e;(e=this.uiObject)==null||e.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone())}setState(e){this.makePanel(),this.uiObject&&(this.uiObject.setState(e),this==null||this.markDirty())}setupState(e){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new Bie(this.uiObject)),this.uiObject.setupState(e.state,e.attributes))}setOptions(e){this.makePanel(),this.uiObject&&this.uiObject.set(e)}awake(){super.awake(),this.makePanel(),Jd(this,"_color",()=>Ute(this,this.onColorChanged))}onEnable(){var e;super.onEnable(),this.uiObject&&((e=this.rectTransform.shadowComponent)==null||e.add(this.uiObject),this.addShadowComponent(this.uiObject,this.rectTransform))}onDisable(){super.onDisable(),this.uiObject&&this.removeShadowComponent()}makePanel(){if(this.uiObject||this._currentlyCreatingPanel)return;this._currentlyCreatingPanel=!0;const e=.015,t={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:e};this.onBeforeCreate(t),this.applyEffects(t),this.onCreate(t),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated()}onBeforeCreate(e){}onCreate(e){this.uiObject=this.rectTransform.createNewBlock(e),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(e,t=1){var s;const i=(s=this.gameObject)==null?void 0:s.getComponent(_p);i&&(i.effectDistance&&(e.borderWidth=Math.max(Math.abs(i.effectDistance.x),Math.abs(i.effectDistance.y))),i.effectColor&&(e.borderColor=i.effectColor,e.borderOpacity=i.effectColor.alpha*t))}async setTexture(e){if(this.setOptions({backgroundOpacity:0}),e){if(e.colorSpace===Ze){if(D0.textureCache.has(e))e=D0.textureCache.get(e);else if(!e.isRenderTargetTexture){const t=e.clone();t.colorSpace=An,D0.textureCache.set(e,t),e=t}}this.setOptions({backgroundImage:e,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"})}else this.setOptions({backgroundImage:null,borderRadius:0,backgroundOpacity:this.color.alpha});this.markDirty()}onAfterAddedToScene(){super.onAfterAddedToScene(),this.shadowComponent&&(this.shadowComponent.offset=this.shadowComponent.position.z)}},h(SC,"textureCache",new Map),SC);let Wu=D0;Hz([x(bi)],Wu.prototype,"color",1);Hz([x()],Wu.prototype,"raycastTarget",2);class ZA extends Wu{constructor(){super(...arguments);h(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var Fie=Object.defineProperty,Uie=Object.getOwnPropertyDescriptor,Ex=(n,e,t,i)=>{for(var s=i>1?void 0:i?Uie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Fie(e,t,s),s};let vI=class{constructor(){h(this,"texture",null);h(this,"rect")}};Ex([x(Ot)],vI.prototype,"texture",2);let xp=class extends ZA{constructor(){super(...arguments);h(this,"_sprite");h(this,"pixelsPerUnitMultiplier",1)}set image(t){this.sprite||(this.sprite=new vI),this.sprite.texture=t,this.onAfterCreated()}get image(){return this.sprite?this.sprite.texture:null}get sprite(){return this._sprite}set sprite(t){this._sprite!==t&&(this._sprite=t,this.onAfterCreated())}isBuiltinSprite(){var t,i,s,r,o,a,c,l;switch((i=(t=this.sprite)==null?void 0:t.texture)==null?void 0:i.name){case"InputFieldBackground":case"UISprite":case"Background":case"Knob":return!0}return((o=(r=(s=this.sprite)==null?void 0:s.texture)==null?void 0:r.image)==null?void 0:o.width)===32&&((l=(c=(a=this.sprite)==null?void 0:a.texture)==null?void 0:c.image)==null?void 0:l.height)===32}onBeforeCreate(t){var i,s;super.onBeforeCreate(t),this.isBuiltinSprite()&&(t.borderRadius=5/this.pixelsPerUnitMultiplier,((s=(i=this.sprite)==null?void 0:i.texture)==null?void 0:s.name)==="Knob"&&(t.borderRadius=999))}onAfterCreated(){var t;this.__didAwake&&(super.onAfterCreated(),!this.isBuiltinSprite()&&this.setTexture((t=this.sprite)==null?void 0:t.texture))}};Ex([x(vI)],xp.prototype,"sprite",1);Ex([x()],xp.prototype,"pixelsPerUnitMultiplier",2);class Mx extends ZA{constructor(){super(...arguments);h(this,"_mainTexture")}get mainTexture(){return this._mainTexture}set mainTexture(t){this._mainTexture!==t&&(this._mainTexture=t,this.onAfterCreated())}onAfterCreated(){this.__didAwake&&(super.onAfterCreated(),this.setTexture(this.mainTexture))}}Ex([x(Ot)],Mx.prototype,"mainTexture",1);var Nie=Object.defineProperty,zie=Object.getOwnPropertyDescriptor,io=(n,e,t,i)=>{for(var s=i>1?void 0:i?zie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Nie(e,t,s),s};const Ud=re("debugbutton");class ju{constructor(){h(this,"colorMultiplier");h(this,"disabledColor");h(this,"fadeDuration");h(this,"highlightedColor");h(this,"normalColor");h(this,"pressedColor");h(this,"selectedColor")}}io([x()],ju.prototype,"colorMultiplier",2);io([x(bi)],ju.prototype,"disabledColor",2);io([x()],ju.prototype,"fadeDuration",2);io([x(bi)],ju.prototype,"highlightedColor",2);io([x(bi)],ju.prototype,"normalColor",2);io([x(bi)],ju.prototype,"pressedColor",2);io([x(bi)],ju.prototype,"selectedColor",2);class fl extends Ie{constructor(){super(...arguments);h(this,"onClick");h(this,"_isHovered",!1);h(this,"colors");h(this,"transition");h(this,"animationTriggers");h(this,"animator");h(this,"_interactable",!0);h(this,"_requestedAnimatorTrigger");h(this,"_isInit",!1);h(this,"_image")}onPointerEnter(t){var i,s;Ud&&console.log("Button Enter",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator),this._isHovered=!0,this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.highlightedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("hovered")),this.context.input.setCursorPointer())}onPointerExit(){var t,i;Ud&&console.log("Button Exit",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this._isHovered=!1,this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((i=this._image)==null||i.setState("normal")),this.context.input.setCursorNormal())}onPointerDown(t){var i,s;Ud&&console.log("Button Down",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.pressedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("pressed")))}onPointerUp(t){var i,s;Ud&&console.warn("Button Up",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator,this._isHovered),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this._isHovered?this.animationTriggers.highlightedTrigger:this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState(this._isHovered?"hovered":"normal")))}onPointerClick(t){var i;!this.interactable||t.pointerId===void 0||t.pointerId!==0&&this.context.input.getIsMouse(t.pointerId)||(Ud&&(console.warn("Button Click",this.onClick),pn("CLICKED button "+this.name+" at "+this.context.time.frameCount)),(i=this.onClick)==null||i.invoke(),t.use())}set interactable(t){this._interactable=t,this._image&&(this._image.setInteractable(t),t?this._image.setState("normal"):this._image.setState("disabled"))}get interactable(){return this._interactable}set_interactable(t){this.interactable=t}awake(){super.awake(),Ud&&console.log(this),this._isInit=!1,this.init()}start(){var t;(t=this._image)==null||t.setInteractable(this.interactable)}onEnable(){super.onEnable()}*setAnimatorTriggerAtEndOfFrame(t){var i;this._requestedAnimatorTrigger=t,yield,yield,this._requestedAnimatorTrigger==t&&((i=this.animator)==null||i.SetTrigger(t))}init(){this._isInit||(this._isInit=!0,this._image=ne.getComponent(this.gameObject,xp),this._image&&(this.stateSetup(this._image),this.interactable?this._image.setState("normal"):this._image.setState("disabled")))}stateSetup(t){var p,g,A,v,m;t.setInteractable(this.interactable);const i=this.getFinalColor(t.color,(p=this.colors)==null?void 0:p.normalColor),s={state:"normal",attributes:{backgroundColor:i,backgroundOpacity:i.alpha}};t.setupState(s);const r=this.getFinalColor(t.color,(g=this.colors)==null?void 0:g.highlightedColor),o={state:"hovered",attributes:{backgroundColor:r,backgroundOpacity:r.alpha}};t.setupState(o);const a=this.getFinalColor(t.color,(A=this.colors)==null?void 0:A.pressedColor),c={state:"pressed",attributes:{backgroundColor:a,backgroundOpacity:a.alpha}};t.setupState(c);const l=this.getFinalColor(t.color,(v=this.colors)==null?void 0:v.selectedColor),u={state:"selected",attributes:{backgroundColor:l,backgroundOpacity:l.alpha}};t.setupState(u);const d=this.getFinalColor(t.color,(m=this.colors)==null?void 0:m.disabledColor),f={state:"disabled",attributes:{backgroundColor:d,backgroundOpacity:d.alpha}};t.setupState(f)}getFinalColor(t,i){return i?t.clone().multiply(i):t.clone()}}io([x(us)],fl.prototype,"onClick",2);io([x()],fl.prototype,"colors",2);io([x()],fl.prototype,"transition",2);io([x()],fl.prototype,"animationTriggers",2);io([x(ks)],fl.prototype,"animator",2);io([x()],fl.prototype,"interactable",1);var Gie=Object.defineProperty,Hie=Object.getOwnPropertyDescriptor,Pn=(n,e,t,i)=>{for(var s=i>1?void 0:i?Hie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Gie(e,t,s),s};const _O=re("debuguilayout");class _h{constructor(){h(this,"left",0);h(this,"right",0);h(this,"top",0);h(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Pn([x()],_h.prototype,"left",2);Pn([x()],_h.prototype,"right",2);Pn([x()],_h.prototype,"top",2);Pn([x()],_h.prototype,"bottom",2);class no extends Ie{constructor(){super(...arguments);h(this,"_rectTransform",null);h(this,"_needsUpdate",!1);h(this,"childAlignment",0);h(this,"reverseArrangement",!1);h(this,"spacing",0);h(this,"padding");h(this,"minWidth",0);h(this,"minHeight",0);h(this,"flexibleHeight",0);h(this,"flexibleWidth",0);h(this,"preferredHeight",0);h(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(t){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(_O&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){_O&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(rr);const t=this.gameObject.getComponentInParent(ps);t&&t.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const t=this.gameObject.getComponentInParent(ps);t&&t.unregisterLayoutGroup(this)}set m_Spacing(t){t!==this.spacing&&(this._needsUpdate=!0,this.spacing=t)}get m_Spacing(){return this.spacing}}Pn([x()],no.prototype,"childAlignment",2);Pn([x()],no.prototype,"reverseArrangement",2);Pn([x()],no.prototype,"spacing",2);Pn([x(_h)],no.prototype,"padding",2);Pn([x()],no.prototype,"minWidth",2);Pn([x()],no.prototype,"minHeight",2);Pn([x()],no.prototype,"flexibleHeight",2);Pn([x()],no.prototype,"flexibleWidth",2);Pn([x()],no.prototype,"preferredHeight",2);Pn([x()],no.prototype,"preferredWidth",2);class xh extends no{constructor(){super(...arguments);h(this,"childControlHeight",!0);h(this,"childControlWidth",!0);h(this,"childForceExpandHeight",!1);h(this,"childForceExpandWidth",!1);h(this,"childScaleHeight",!1);h(this,"childScaleWidth",!1)}onCalculateLayout(t){var R;const i=this.primaryAxis,s=t.width;let r=s;const o=t.height;let a=o;r-=this.padding.horizontal,a-=this.padding.vertical,i==="x"?this.padding.horizontal:this.padding.vertical;const c=i==="x",l=c?"y":"x",u=c?this.childControlWidth:this.childControlHeight,d=c?this.childControlHeight:this.childControlWidth,f=c?this.childForceExpandWidth:this.childForceExpandHeight,p=c?this.childForceExpandHeight:this.childForceExpandWidth,g=c?a:r,A=c?s:o,v=.5*(c?this.childAlignment%3:Math.floor(this.childAlignment/3));let m=0;c?m+=this.padding.left:m+=this.padding.top;let b=0,y=0;for(let E=0;E<this.gameObject.children.length;E++){const T=this.gameObject.children[E],D=ne.getComponent(T,rr);D!=null&&D.activeAndEnabled&&(y+=1,c?b+=D.width:b+=D.height)}let _=0;const C=this.spacing*(y-1);if(f||u){let E=0;c?E=r-=C:E=a-=C,y>0&&(_=E/y)}let M=0;M+=this.padding.left,M-=this.padding.right,v!==0&&(m=A-b,m*=v,m-=C*v,c?(m-=this.padding.right*v,m+=this.padding.left*(1-v),m<this.padding.left&&(m=this.padding.left)):(m-=this.padding.bottom*v,m+=this.padding.top*(1-v),m<this.padding.top&&(m=this.padding.top)));let I=1;for(let E=0;E<this.gameObject.children.length;E++){const T=this.gameObject.children[E],D=ne.getComponent(T,rr);if(D!=null&&D.activeAndEnabled){(R=D.pivot)==null||R.set(.5,.5),D.anchorMin.set(0,1),D.anchorMax.set(0,1);const K=s*.5+M*.5;D.anchoredPosition.x!==K&&(D.anchoredPosition.x=K);const H=o*-.5;D.anchoredPosition.y!==H&&(D.anchoredPosition.y=H),p&&d&&D.sizeDelta[l]!==g&&(D.sizeDelta[l]=g),f&&u&&D.sizeDelta[i]!==_&&(D.sizeDelta[i]=_);const V=c?D.width:D.height,Y=V*.5;if(m+=Y,f){const L=_*I-_*.5;L>m&&(m=L-_*.5+V+this.padding.left,m-=Y)}let N=m;i==="y"&&(N=-N),D.anchoredPosition[i]!==N&&(D.anchoredPosition[i]=N),m+=Y,m+=this.spacing,I+=1}}}}Pn([x()],xh.prototype,"childControlHeight",2);Pn([x()],xh.prototype,"childControlWidth",2);Pn([x()],xh.prototype,"childForceExpandHeight",2);Pn([x()],xh.prototype,"childForceExpandWidth",2);Pn([x()],xh.prototype,"childScaleHeight",2);Pn([x()],xh.prototype,"childScaleWidth",2);class yI extends xh{get primaryAxis(){return"y"}}class bI extends xh{get primaryAxis(){return"x"}}class _I extends no{onCalculateLayout(){}}var Vie=Object.defineProperty,Qie=Object.getOwnPropertyDescriptor,$a=(n,e,t,i)=>{for(var s=i>1?void 0:i?Qie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Vie(e,t,s),s},Vz=(n=>(n[n.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",n[n.ScreenSpaceCamera=1]="ScreenSpaceCamera",n[n.WorldSpace=2]="WorldSpace",n[n.Undefined=-1]="Undefined",n))(Vz||{});const WS=re("debuguilayout"),Qz=class extends HA{constructor(){super(...arguments);h(this,"_renderOnTop");h(this,"_depthWrite",!1);h(this,"_doubleSided",!0);h(this,"_castShadows",!1);h(this,"_receiveShadows",!1);h(this,"_renderMode",-1);h(this,"_rootCanvas");h(this,"_scaleFactor",1);h(this,"worldCamera");h(this,"planeDistance",-1);h(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this));h(this,"previousParent",null);h(this,"_lastMatrixWorld",null);h(this,"_rectTransforms",[]);h(this,"_layoutGroups",new Map);h(this,"_receivers",[]);h(this,"onBeforeRenderRoutine",()=>{var e,t,i,s;if(this.context.isInVR){this.onUpdateRenderMode(),this.handleLayoutUpdates(),(e=this.shadowComponent)==null||e.updateMatrixWorld(!0),(t=this.shadowComponent)==null||t.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),$s.ensureUpdateMeshUI(GS,this.context,!0);return}this.previousParent=this.gameObject.parent,this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(i=this.shadowComponent)==null||i.updateMatrixWorld(!0),(s=this.shadowComponent)==null||s.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),$s.ensureUpdateMeshUI(GS,this.context))});h(this,"onAfterRenderRoutine",()=>{var e,t;if(!this.context.isInVR){if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const r=this.context.mainCamera;r==null||r.add(this.gameObject)}else this.previousParent.add(this.gameObject);const i=this.context.renderer.autoClear,s=this.context.renderer.autoClearColor;this.context.renderer.autoClear=!1,this.context.renderer.autoClearColor=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(e=this.shadowComponent)==null||e.updateMatrixWorld(!0),this.invokeBeforeRenderEvents(),$s.ensureUpdateMeshUI(GS,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=i,this.context.renderer.autoClearColor=s,this.previousParent.add(this.gameObject)}(t=this._lastMatrixWorld)==null||t.copy(this.gameObject.matrixWorld)}});h(this,"_updateRenderSettingsRoutine");h(this,"_activeRenderMode",-1);h(this,"_lastWidth",-1);h(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(e){e!==this._renderOnTop&&(this._renderOnTop=e,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(e){this._depthWrite!==e&&(this._depthWrite=e,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(e){this._doubleSided!==e&&(this._doubleSided=e,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(e){this._castShadows!==e&&(this._castShadows=e,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(e){this._receiveShadows!==e&&(this._receiveShadows=e,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(e){this._renderMode!==e&&(this._renderMode=e,this.onRenderSettingsChanged())}set rootCanvas(e){this._rootCanvas instanceof Qz||(this._rootCanvas=e)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(e){this._scaleFactor=e}awake(){var e;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,WS&&console.log("Canvas.Awake()",((e=this.previousParent)==null?void 0:e.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new Me,this.onUpdateRenderMode(),document.addEventListener("resize",this._boundRenderSettingsChanged),this.context.pre_render_callbacks.push(this.onBeforeRenderRoutine),this.context.post_render_callbacks.push(this.onAfterRenderRoutine)}onDisable(){super.onDisable(),document.removeEventListener("resize",this._boundRenderSettingsChanged);const e=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);e!==-1&&this.context.pre_render_callbacks.splice(e,1);const t=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);t!==-1&&this.context.post_render_callbacks.splice(t,1)}registerTransform(e){this._rectTransforms.push(e)}unregisterTransform(e){const t=this._rectTransforms.indexOf(e);t!==-1&&this._rectTransforms.splice(t,1)}registerLayoutGroup(e){const t=e.gameObject;this._layoutGroups.set(t,e)}unregisterLayoutGroup(e){const t=e.gameObject;this._layoutGroups.delete(t)}registerEventReceiver(e){this._receivers.push(e)}unregisterEventReceiver(e){const t=this._receivers.indexOf(e);t!==-1&&this._receivers.splice(t,1)}invokeBeforeRenderEvents(){var e;for(const t of this._receivers)(e=t.onBeforeCanvasRender)==null||e.call(t,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new Me);const e=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);WS&&e&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const t=!1;for(const i of this._rectTransforms){e&&i.markDirty();let s=this._layoutGroups.get(i.gameObject);i.isDirty&&!s&&(s=i.gameObject.getComponentInParent(no)),(i.isDirty||s!=null&&s.isDirty)&&(WS&&!t&&console.log("CANVAS UPDATE ### "+i.name+" ##################################### "+this.context.time.frame),s==null||s.updateLayout(),i.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),Tr.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),Tb(this.shadowComponent,this);for(const e of ne.getComponentsInChildren(this.gameObject,aa))Tb(e.shadowComponent,this)}}onUpdateRenderMode(e=!1){if(!e&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let t=this.context.mainCameraComponent,i=10;switch(t&&t.nearClipPlane>0&&t.farClipPlane>0&&(i=tt.lerp(t.nearClipPlane,t.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(t=this.worldCamera),this.planeDistance>0&&(i=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!t)return;const s=i+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-s,this.gameObject.quaternion.identity();const r=this.gameObject.getComponent(rr);let o=!1;r.sizeDelta.x!==this.context.domWidth&&(o=!0),r.sizeDelta.y!==this.context.domHeight&&(o=!0);const a=t.fieldOfView*Math.PI/180,c=2*Math.tan(a/2)*Math.abs(s);this.gameObject.scale.x=c/this.context.domHeight,this.gameObject.scale.y=c/this.context.domHeight,this.gameObject.scale.z=.01,o&&(r.sizeDelta.x=this.context.domWidth,r.sizeDelta.y=this.context.domHeight,r==null||r.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let ps=Qz;$a([x()],ps.prototype,"renderOnTop",1);$a([x()],ps.prototype,"depthWrite",1);$a([x()],ps.prototype,"doubleSided",1);$a([x()],ps.prototype,"castShadows",1);$a([x()],ps.prototype,"receiveShadows",1);$a([x()],ps.prototype,"renderMode",1);$a([x(ps)],ps.prototype,"rootCanvas",1);$a([x()],ps.prototype,"scaleFactor",1);$a([x(Li)],ps.prototype,"worldCamera",2);$a([x()],ps.prototype,"planeDistance",2);var Wie=Object.defineProperty,jie=Object.getOwnPropertyDescriptor,xI=(n,e,t,i)=>{for(var s=i>1?void 0:i?jie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Wie(e,t,s),s};class hh extends Ie{constructor(){super(...arguments);h(this,"_alpha",1);h(this,"interactable",!0);h(this,"blocksRaycasts",!0);h(this,"_isDirty",!1);h(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(t){t!==this._alpha&&(this._alpha=t,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),Tr.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){for(const t of ne.getComponentsInChildren(this.gameObject,aa,this._buffer)){const i=t;i.setAlphaFactor&&i.setAlphaFactor(this._alpha)}}}xI([x()],hh.prototype,"alpha",1);xI([x()],hh.prototype,"interactable",2);xI([x()],hh.prototype,"blocksRaycasts",2);var Xie=Object.defineProperty,qie=Object.getOwnPropertyDescriptor,Fi=(n,e,t,i)=>{for(var s=i>1?void 0:i?qie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Xie(e,t,s),s};class Xu extends Ie{constructor(){super(...arguments);h(this,"object");h(this,"target");h(this,"duration",1);h(this,"relativeMotion",!1);h(this,"coroutine",null);h(this,"targetPos",new w);h(this,"targetRot",new we);h(this,"targetScale",new w)}*moveToTarget(){if(!this.target||!this.object)return;const t=Ct(this.object).clone(),i=Ct(this.target).clone(),s=zn(this.object).clone(),r=zn(this.target).clone(),o=ls(this.object).clone(),a=ls(this.target).clone(),c=t.distanceTo(i),l=s.angleTo(r),u=o.distanceTo(a);if(c<.01&&l<.01&&u<.01){Mn(this.object,i),Mr(this.object,r),AE(this.object,a),this.coroutine=null;return}let d=0,f=0;for(;d<1;)d+=this.context.time.deltaTime/this.duration,d>1&&(d=1),f=d<.5?4*d*d*d:1-Math.pow(-2*d+2,3)/2,this.targetPos.lerpVectors(t,i,f),this.targetRot.slerpQuaternions(s,r,f),this.targetScale.lerpVectors(o,a,f),Mn(this.object,this.targetPos),Mr(this.object,this.targetRot),AE(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const t=this.object.position.clone(),i=this.object.quaternion.clone(),s=this.object.scale.clone(),r=this.target.position.clone(),o=this.target.quaternion.clone(),a=this.target.scale.clone();r.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(r),this.targetRot.copy(this.object.quaternion).multiply(o),this.targetScale.copy(this.object.scale).multiply(a);let c=0,l=0;for(;c<1;)c+=this.context.time.deltaTime/this.duration,c>1&&(c=1),l=c<.5?4*c*c*c:1-Math.pow(-2*c+2,3)/2,this.object.position.lerpVectors(t,this.targetPos,l),this.object.quaternion.slerpQuaternions(i,this.targetRot,l),this.object.scale.lerpVectors(s,this.targetScale,l),yield;this.coroutine=null}onPointerClick(t){t.use(),this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}beforeCreateDocument(t){var i;if(this.target&&this.object&&this.gameObject){const s=new ds("Move to "+((i=this.target)==null?void 0:i.name),Cr.tapTrigger(this.gameObject),fi.transformAction(this.object,this.target,this.duration,this.relativeMotion?tM.Relative:tM.Absolute));t.addBehavior(s)}}}Fi([x(Te)],Xu.prototype,"object",2);Fi([x(Te)],Xu.prototype,"target",2);Fi([x()],Xu.prototype,"duration",2);Fi([x()],Xu.prototype,"relativeMotion",2);var i0;const _c=(i0=class extends Ie{constructor(){super(...arguments);h(this,"materialToSwitch");h(this,"variantMaterial");h(this,"fadeDuration",0);h(this,"_objectsWithThisMaterial",[]);h(this,"selfModel");h(this,"targetModels")}awake(){if(this.variantMaterial&&this.materialToSwitch){const e=ne.findObjectsOfType(Qi);for(const t of e)for(let i=0;i<t.sharedMaterials.length;i++){const s=t.sharedMaterials[i];if(s===this.materialToSwitch){if(t.gameObject instanceof ye)this._objectsWithThisMaterial.push(t.gameObject);else if(t.gameObject instanceof yr)for(const r of t.gameObject.children)r instanceof ye&&r.material===s&&this._objectsWithThisMaterial.push(r);break}}}}onPointerClick(e){if(e.use(),!!this.variantMaterial)for(let t=0;t<this._objectsWithThisMaterial.length;t++){const i=this._objectsWithThisMaterial[t];i.material=this.variantMaterial}}async beforeCreateDocument(e,t){this.targetModels=[],_c._materialTriggersPerId={},_c.variantSwitchIndex=0,this.materialToSwitch&&await Hr.assignTextureLOD(this.context,this.sourceId,this.materialToSwitch,0),this.variantMaterial&&await Hr.assignTextureLOD(this.context,this.sourceId,this.variantMaterial,0)}createBehaviours(e,t,i){this._objectsWithThisMaterial.find(r=>r.uuid===t.uuid)&&this.targetModels.push(t),this.gameObject.uuid===t.uuid&&(this.selfModel=t,this.materialToSwitch&&(_c._materialTriggersPerId[this.materialToSwitch.uuid]||(_c._materialTriggersPerId[this.materialToSwitch.uuid]=[]),_c._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(e,t){if(!this.materialToSwitch)return;const i=_c._materialTriggersPerId[this.materialToSwitch.uuid];if(i){const s={};for(const o of i){const a=o.createVariants();a&&a.length>0&&(s[o.selfModel.uuid]=a)}const r=[];for(const o of i){for(const a in s)a!==o.selfModel.uuid&&r.push(s[a]);o.createAndAttachBehaviors(e,s[o.selfModel.uuid],r)}}delete _c._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(e,t,i){const s=[],r=[],o=Math.max(0,this.fadeDuration);for(const a of this.targetModels){const c=fi.fadeAction(a,o,!1);r.push(c)}for(const a of i)r.push(fi.fadeAction(a,o,!1));for(const a of t)s.push(fi.fadeAction(a,o,!1)),r.push(fi.fadeAction(a,o,!0));e.addBehavior(new ds("Select "+this.selfModel.name,Cr.tapTrigger(this.selfModel),fi.parallel(...r))),e.addBehavior(new ds("Start hidden "+this.selfModel.name,Cr.sceneStartTrigger(),fi.parallel(...s)))}createVariants(){if(!this.variantMaterial)return null;const e=[];for(const t of this.targetModels){const i=t.clone();i.name+=" variant_"+this.variantMaterial.name+"_"+_c.variantSwitchIndex++,i.name=i.name.replace(/\s/g,"_"),i.material=this.variantMaterial,i.geometry=t.geometry,i.matrix=t.matrix,(!t.parent||!t.parent.isEmpty())&&_r.createEmptyParent(t),t.parent&&t.parent.add(i),e.push(i)}return e}},h(i0,"_materialTriggersPerId",{}),h(i0,"variantSwitchIndex",0),i0);let wp=_c;Fi([x(kt)],wp.prototype,"materialToSwitch",2);Fi([x(kt)],wp.prototype,"variantMaterial",2);Fi([x()],wp.prototype,"fadeDuration",2);class Sp extends Ie{constructor(){super(...arguments);h(this,"target");h(this,"toggleOnClick",!1);h(this,"targetState",!0);h(this,"hideSelf",!0);h(this,"selfModel");h(this,"otherModel");h(this,"toggleModel");h(this,"stateBeforeCreatingDocument",!1)}onPointerClick(t){t.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(t,i,s){i.uuid===this.gameObject.uuid&&(this.selfModel=i)}beforeCreateDocument(){this.stateBeforeCreatingDocument=this.gameObject.visible,this.gameObject.visible=!0}afterCreateDocument(t,i){if(this.target){if(this.otherModel=i.document.findById(this.target.uuid),this.selfModel&&this.otherModel){let s=this.hideSelf;this.targetState,this.toggleOnClick&&(s=!0,this.target.visible,(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&e3.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.clone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel));const r=[];if(s&&r.push(fi.fadeAction(this.selfModel,0,!1)),this.toggleModel&&r.push(fi.fadeAction(this.toggleModel,0,!0)),r.push(fi.fadeAction(this.otherModel,0,this.targetState)),t.addBehavior(new ds("Toggle_"+this.selfModel.name+"_hideSelf",Cr.tapTrigger(this.selfModel),fi.sequence(...r))),this.toggleOnClick&&this.toggleModel){const o=[];o.push(fi.fadeAction(this.toggleModel,0,!1)),o.push(fi.fadeAction(this.selfModel,0,!0)),o.push(fi.fadeAction(this.otherModel,0,!this.targetState)),t.addBehavior(new ds("Toggle_"+this.selfModel.name+"_toggleSelf",Cr.tapTrigger(this.toggleModel),fi.sequence(...o))),t.addBehavior(new ds("HideOnStart_"+this.gameObject.name,Cr.sceneStartTrigger(),fi.fadeAction(this.toggleModel,0,!1)))}}this.gameObject.visible=this.stateBeforeCreatingDocument}}}Fi([x(Te)],Sp.prototype,"target",2);Fi([x()],Sp.prototype,"targetState",2);Fi([x()],Sp.prototype,"hideSelf",2);class wI extends Ie{start(){this.gameObject.visible=!1}createBehaviours(e,t,i){t.uuid===this.gameObject.uuid&&e.addBehavior(new ds("HideOnStart_"+this.gameObject.name,Cr.sceneStartTrigger(),fi.fadeAction(t,0,!1)))}beforeCreateDocument(){this.gameObject.visible=!0}afterCreateDocument(){this.gameObject.visible=!1}}class Cp extends Ie{constructor(){super(...arguments);h(this,"target");h(this,"duration",.5);h(this,"motionType",MT.bounce)}beforeCreateDocument(){}createBehaviours(t,i,s){if(this.target&&i.uuid===this.gameObject.uuid){const r=new ds("emphasize "+this.name,Cr.tapTrigger(this.gameObject),fi.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));t.addBehavior(r)}}afterCreateDocument(t,i){}}Fi([x()],Cp.prototype,"target",2);Fi([x()],Cp.prototype,"duration",2);Fi([x()],Cp.prototype,"motionType",2);class Ep extends Ie{constructor(){super(...arguments);h(this,"target");h(this,"clip","");h(this,"toggleOnClick",!1)}onPointerClick(t){if(t.use(),!(!this.target&&!this.clip)){if(!this.target){const i=this.gameObject.addNewComponent(yn);i&&(i.spatialBlend=1,i.volume=1,i.loop=!1,this.target=i)}this.target&&(this.target.isPlaying&&this.toggleOnClick?this.target.stop():(!this.toggleOnClick&&this.target.isPlaying&&this.target.stop(),this.clip?this.target.play(this.clip):this.target.play()))}}createBehaviours(t,i,s){if(!(!this.target&&!this.clip)&&i.uuid===this.gameObject.uuid){const r=this.clip?this.clip:this.target?this.target.clip:void 0;if(!r)return;const o=this.target?this.target.gameObject:this.gameObject,a=r.split("/").pop(),c=this.target?this.target.volume:1,l=this.target&&this.target.spatialBlend==0?iM.NonSpatial:iM.Spatial,u=new ds("playAudio "+this.name,Cr.tapTrigger(this.gameObject),fi.playAudioAction(o,"audio/"+a,o3.Play,c,l));t.addBehavior(u)}}async afterSerialize(t,i){if(!this.target&&!this.clip)return;const s=this.clip?this.clip:this.target?this.target.clip:void 0;if(!s)return;const r=s.split("/").pop(),c=await(await(await fetch(this.clip)).blob()).arrayBuffer(),l=new Uint8Array(c);i.files["audio/"+r]=l}}Fi([x(yn)],Ep.prototype,"target",2);Fi([x(URL)],Ep.prototype,"clip",2);Fi([x()],Ep.prototype,"toggleOnClick",2);var CC;const Zd=(CC=class extends Ie{constructor(){super(...arguments);h(this,"target");h(this,"animator");h(this,"stateName");h(this,"stateNameAfterPlaying");h(this,"loopAfterPlaying",!1);h(this,"selfModel");h(this,"stateAnimationModel");h(this,"stateAnimation");h(this,"stateAfterPlayingAnimationModel");h(this,"stateAfterPlayingAnimation")}onPointerClick(e){var t;e.use(),this.target&&this.stateName&&((t=this.animator)==null||t.play(this.stateName,0,0,.1))}createBehaviours(e,t,i){t.uuid===this.gameObject.uuid&&(this.selfModel=t)}onAfterHierarchy(){Zd.animationActions=[]}afterCreateDocument(e,t){if(!this.stateAnimation||!this.stateAnimationModel)return;t.document.traverse(s=>{var r,o;if(s.uuid===((r=this.target)==null?void 0:r.uuid)&&this.stateAnimation){const a=[];let c=Zd.animationActions.find(u=>u.affectedObjects==s&&u.start==this.stateAnimation.start&&u.duration==this.stateAnimation.duration);if(c||(c=fi.startAnimationAction(s,this.stateAnimation.start,this.stateAnimation.duration),Zd.animationActions.push(c)),a.push(c),this.stateAfterPlayingAnimation&&this.stateAfterPlayingAnimationModel){let u=Zd.animationActions.find(f=>f.affectedObjects==s&&f.start==this.stateAfterPlayingAnimation.start&&f.duration==this.stateAfterPlayingAnimation.duration);u||(u=fi.startAnimationAction(s,this.stateAfterPlayingAnimation.start,this.stateAfterPlayingAnimation.duration),Zd.animationActions.push(u));const d=fi.sequence(u);this.loopAfterPlaying&&d.makeLooping(),a.push(d)}const l=new ds("tap "+this.name+" for "+this.stateName+" on "+((o=this.target)==null?void 0:o.name),Cr.tapTrigger(this.selfModel),fi.sequence(...a));e.addBehavior(l)}})}createAnimation(e,t,i){var s,r,o,a,c;if(this.target&&this.animator){const l=(r=(s=this.animator)==null?void 0:s.runtimeAnimatorController)==null?void 0:r.findState(this.stateName);if(!((o=l==null?void 0:l.motion)!=null&&o.clip)){ci()&&console.warn("No clip found for state "+this.stateName);return}this.stateAnimationModel=t,this.stateAnimation=e.registerAnimation(this.target,l==null?void 0:l.motion.clip);const u=(c=(a=this.animator)==null?void 0:a.runtimeAnimatorController)==null?void 0:c.findState(this.stateNameAfterPlaying);this.stateAfterPlayingAnimationModel=t,this.stateAfterPlayingAnimation=e.registerAnimation(this.target,u==null?void 0:u.motion.clip)}}},h(CC,"animationActions",[]),CC);let wh=Zd;Fi([x(Te)],wh.prototype,"target",2);Fi([x(ks)],wh.prototype,"animator",2);Fi([x()],wh.prototype,"stateName",2);Fi([x()],wh.prototype,"stateNameAfterPlaying",2);Fi([x()],wh.prototype,"loopAfterPlaying",2);class Mp extends Ie{constructor(){super(...arguments);h(this,"target")}getType(){}getDuration(){}}Fi([x(Te)],Mp.prototype,"target",2);class $A extends Ie{constructor(){super(...arguments);h(this,"target")}}Fi([x(Mp)],$A.prototype,"target",2);class ev extends Mp{constructor(){super(...arguments);h(this,"type",1);h(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}Fi([x()],ev.prototype,"type",2);Fi([x()],ev.prototype,"duration",2);class SI extends $A{}var Yie=Object.defineProperty,Kie=Object.getOwnPropertyDescriptor,pl=(n,e,t,i)=>{for(var s=i>1?void 0:i?Kie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Yie(e,t,s),s};class qu extends Ie{constructor(){super(...arguments);h(this,"center",new w(0,0,0));h(this,"radius",.5);h(this,"height",2);h(this,"_rigidbody",null);h(this,"_activeGroundCollisions")}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(Ii),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(Ii)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const t=this.rigidbody;let i=this.gameObject.getComponent(lh);i||(i=this.gameObject.addNewComponent(lh)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height;const s=new w(0,0,1),r=new w(1,0,0),o=new w(0,1,0),a=this.gameObject.getWorldDirection(new w);a.y=0;const c=r.dot(a)<0?-1:1,l=s.angleTo(a)*c;this.gameObject.setRotationFromAxisAngle(o,l),t.lockRotationX=!0,t.lockRotationY=!0,t.lockRotationZ=!0}move(t){this.gameObject.position.add(t)}onCollisionEnter(t){for(const i of t.contacts)if(i.normal.y>.1){this._activeGroundCollisions.add(t);break}}onCollisionExit(t){this._activeGroundCollisions.delete(t)}get isGrounded(){return this._activeGroundCollisions.size>0}}pl([x(w)],qu.prototype,"center",2);pl([x()],qu.prototype,"radius",2);pl([x()],qu.prototype,"height",2);class gl extends Ie{constructor(){super(...arguments);h(this,"controller");h(this,"movementSpeed",2);h(this,"rotationSpeed",2);h(this,"jumpForce",1);h(this,"doubleJumpForce",2);h(this,"animator");h(this,"lookForward",!0);h(this,"lookInput",new te(0,0));h(this,"moveInput",new te(0,0));h(this,"jumpInput",!1);h(this,"_currentSpeed",new w(0,0,0));h(this,"_currentAngularSpeed",new w(0,0,0));h(this,"_temp",new w(0,0,0));h(this,"_jumpCount",0);h(this,"_currentRotation");h(this,"_raycastOptions",new ko)}awake(){this._currentRotation=new we}update(){const t=this.context.input;t.isKeyPressed("KeyW")?this.moveInput.y+=1:t.isKeyPressed("KeyS")&&(this.moveInput.y-=1),t.isKeyPressed("KeyD")?this.lookInput.x+=1:t.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=t.isKeyDown("Space"))}move(t){this.moveInput.add(t)}look(t){this.lookInput.add(t)}jump(){this.jumpInput=!0}onBeforeRender(){this.handleInput(this.moveInput,this.lookInput,this.jumpInput),this.lookInput.set(0,0),this.moveInput.set(0,0),this.jumpInput=!1}handleInput(t,i,s){var r,o,a,c,l,u,d,f,p,g,A;if((r=this.controller)!=null&&r.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((o=this.animator)==null||o.setBool("doubleJump",!1))),this._currentSpeed.z+=t.y*this.movementSpeed*this.context.time.deltaTime,(a=this.animator)==null||a.setBool("running",t.length()>.01),(l=this.animator)==null||l.setBool("jumping",((c=this.controller)==null?void 0:c.isGrounded)===!0&&s),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp),this._currentAngularSpeed.y+=tt.toRadians(-i.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const v=this.context.mainCameraComponent.forward;v.y=0,v.normalize(),this._currentRotation.setFromUnitVectors(new w(0,0,1),v),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&s&&this.jumpForce>0){let v=(u=this.controller)==null?void 0:u.isGrounded;if(this.doubleJumpForce>0&&!((d=this.controller)!=null&&d.isGrounded)&&this._jumpCount===1&&(v=!0,(f=this.animator)==null||f.setBool("doubleJump",!0)),v){this._jumpCount+=1;const m=this.controller.rigidbody,b=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;m.applyImpulse(new w(0,1,0).multiplyScalar(b))}}if(this.controller){const v=(p=this.controller)==null?void 0:p.rigidbody.getVelocity().y;if(v<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new Ya),this._raycastOptions.ray.origin.copy(Ct(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const m=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const b=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(m),(b.length&&b[0].distance>2||v<-10)&&((g=this.animator)==null||g.setBool("falling",!0))}else(A=this.animator)==null||A.setBool("falling",!1)}}}pl([x(qu)],gl.prototype,"controller",2);pl([x()],gl.prototype,"movementSpeed",2);pl([x()],gl.prototype,"rotationSpeed",2);pl([x()],gl.prototype,"jumpForce",2);pl([x()],gl.prototype,"doubleJumpForce",2);pl([x(ks)],gl.prototype,"animator",2);var Jie=Object.defineProperty,Zie=Object.getOwnPropertyDescriptor,$ie=(n,e,t,i)=>{for(var s=i>1?void 0:i?Zie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Jie(e,t,s),s};class tv extends Us{constructor(){super(...arguments);h(this,"intensity")}get typeName(){return"ChromaticAberration"}init(){this.intensity.defaultValue=0}onCreateEffect(){const t=new $U;return t.offset=new te(0,0),t.radialModulation=!0,t.modulationOffset=.15,this.intensity.valueProcessor=i=>i*.02,this.intensity.onValueChanged=i=>{t.offset.x=-i,t.offset.y=i},t}}$ie([x(Rt)],tv.prototype,"intensity",2);No("ChromaticAberration",tv);var ene=Object.defineProperty,tne=Object.getOwnPropertyDescriptor,Tx=(n,e,t,i)=>{for(var s=i>1?void 0:i?tne(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&ene(e,t,s),s};class Sh extends Us{constructor(){super(...arguments);h(this,"postExposure");h(this,"contrast");h(this,"hueShift");h(this,"saturation")}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=t=>(t=Math.pow(2,t),t),this.postExposure.defaultValue=0,this.contrast.valueProcessor=t=>{let i=1;return t>0?i=200:t<0&&(i=100),t/i},this.contrast.defaultValue=0,this.hueShift.valueProcessor=t=>Math.PI*t/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=t=>t<0?t/100:t/(100*Math.PI),this.saturation.defaultValue=0}unapply(){this.context.renderer.toneMappingExposure=1}onCreateEffect(){this.context.renderer.toneMapping===er&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=_m);const t=new ZU;this.postExposure.onValueChanged=s=>{this.context.renderer.toneMapping===er&&(this.context.renderer.toneMapping=_m),this.postExposure.overrideState&&(this.context.renderer.toneMappingExposure=s)},this.contrast.onValueChanged=s=>{t.contrast=s};const i=new tN;return this.hueShift.onValueChanged=s=>i.hue=s,this.saturation.onValueChanged=s=>i.saturation=s,[i,t]}}Tx([x(Rt)],Sh.prototype,"postExposure",2);Tx([x(Rt)],Sh.prototype,"contrast",2);Tx([x(Rt)],Sh.prototype,"hueShift",2);Tx([x(Rt)],Sh.prototype,"saturation",2);No("ColorAdjustments",Sh);const ine=(Math.sqrt(5)-1)/4,ts=(5-Math.sqrt(5))/20,Ly=n=>Math.floor(n)|0,Fy=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function nne(n=Math.random){const e=sne(n),t=new Float64Array(e).map(o=>Fy[o%32*4]),i=new Float64Array(e).map(o=>Fy[o%32*4+1]),s=new Float64Array(e).map(o=>Fy[o%32*4+2]),r=new Float64Array(e).map(o=>Fy[o%32*4+3]);return function(a,c,l,u){let d,f,p,g,A;const v=(a+c+l+u)*ine,m=Ly(a+v),b=Ly(c+v),y=Ly(l+v),_=Ly(u+v),C=(m+b+y+_)*ts,M=m-C,I=b-C,R=y-C,E=_-C,T=a-M,D=c-I,K=l-R,H=u-E;let V=0,Y=0,N=0,L=0;T>D?V++:Y++,T>K?V++:N++,T>H?V++:L++,D>K?Y++:N++,D>H?Y++:L++,K>H?N++:L++;const G=V>=3?1:0,ee=Y>=3?1:0,$=N>=3?1:0,j=L>=3?1:0,ie=V>=2?1:0,Ae=Y>=2?1:0,ge=N>=2?1:0,Ce=L>=2?1:0,Ee=V>=1?1:0,Ge=Y>=1?1:0,Qe=N>=1?1:0,ut=L>=1?1:0,Et=T-G+ts,st=D-ee+ts,W=K-$+ts,Fe=H-j+ts,me=T-ie+2*ts,Le=D-Ae+2*ts,Se=K-ge+2*ts,it=H-Ce+2*ts,Xe=T-Ee+3*ts,Ye=D-Ge+3*ts,At=K-Qe+3*ts,Mt=H-ut+3*ts,Yt=T-1+4*ts,z=D-1+4*ts,k=K-1+4*ts,he=H-1+4*ts,Pe=m&255,Be=b&255,Ue=y&255,X=_&255;let de=.6-T*T-D*D-K*K-H*H;if(de<0)d=0;else{const ke=Pe+e[Be+e[Ue+e[X]]];de*=de,d=de*de*(t[ke]*T+i[ke]*D+s[ke]*K+r[ke]*H)}let ce=.6-Et*Et-st*st-W*W-Fe*Fe;if(ce<0)f=0;else{const ke=Pe+G+e[Be+ee+e[Ue+$+e[X+j]]];ce*=ce,f=ce*ce*(t[ke]*Et+i[ke]*st+s[ke]*W+r[ke]*Fe)}let je=.6-me*me-Le*Le-Se*Se-it*it;if(je<0)p=0;else{const ke=Pe+ie+e[Be+Ae+e[Ue+ge+e[X+Ce]]];je*=je,p=je*je*(t[ke]*me+i[ke]*Le+s[ke]*Se+r[ke]*it)}let qe=.6-Xe*Xe-Ye*Ye-At*At-Mt*Mt;if(qe<0)g=0;else{const ke=Pe+Ee+e[Be+Ge+e[Ue+Qe+e[X+ut]]];qe*=qe,g=qe*qe*(t[ke]*Xe+i[ke]*Ye+s[ke]*At+r[ke]*Mt)}let Ve=.6-Yt*Yt-z*z-k*k-he*he;if(Ve<0)A=0;else{const ke=Pe+1+e[Be+1+e[Ue+1+e[X+1]]];Ve*=Ve,A=Ve*Ve*(t[ke]*Yt+i[ke]*z+s[ke]*k+r[ke]*he)}return 27*(d+f+p+g+A)}}function sne(n){const t=new Uint8Array(512);for(let i=0;i<512/2;i++)t[i]=i;for(let i=0;i<512/2-1;i++){const s=i+~~(n()*(256-i)),r=t[i];t[i]=t[s],t[s]=r}for(let i=256;i<512;i++)t[i]=t[i-256];return t}var rne=Object.defineProperty,one=Object.getOwnPropertyDescriptor,se=(n,e,t,i)=>{for(var s=i>1?void 0:i?one(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&rne(e,t,s),s};const Uy=re("debugparticles");var Mc=(n=>(n[n.Billboard=0]="Billboard",n[n.Stretch=1]="Stretch",n[n.HorizontalBillboard=2]="HorizontalBillboard",n[n.VerticalBillboard=3]="VerticalBillboard",n[n.Mesh=4]="Mesh",n))(Mc||{});let Ch=class{constructor(){h(this,"alphaKeys");h(this,"colorKeys")}get duration(){return 1}evaluate(e,t){let i,s=0,r=null,o=0;for(let a=0;a<this.alphaKeys.length;a++){const c=this.alphaKeys[a];(c.time<e||!i)&&(i=c,s=a)}for(let a=0;a<this.colorKeys.length;a++){const c=this.colorKeys[a];(c.time<e||!r)&&(r=c,o=a)}if(r)if(o+1<this.colorKeys.length){const c=this.colorKeys[o+1],l=tt.remap(e,r.time,c.time,0,1);t.r=tt.lerp(r.color.r,c.color.r,l),t.g=tt.lerp(r.color.g,c.color.g,l),t.b=tt.lerp(r.color.b,c.color.b,l)}else t.r=r.color.r,t.g=r.color.g,t.b=r.color.b;if(i)if(s+1<this.alphaKeys.length){const c=this.alphaKeys[s+1],l=tt.remap(e,i.time,c.time,0,1);t.alpha=tt.lerp(i.alpha,c.alpha,l)}else t.alpha=i.alpha;return t}};se([x()],Ch.prototype,"alphaKeys",2);se([x()],Ch.prototype,"colorKeys",2);var $m=(n=>(n[n.Local=0]="Local",n[n.World=1]="World",n[n.Custom=2]="Custom",n))($m||{}),Wz=(n=>(n[n.Sphere=0]="Sphere",n[n.SphereShell=1]="SphereShell",n[n.Hemisphere=2]="Hemisphere",n[n.HemisphereShell=3]="HemisphereShell",n[n.Cone=4]="Cone",n[n.Box=5]="Box",n[n.Mesh=6]="Mesh",n[n.ConeShell=7]="ConeShell",n[n.ConeVolume=8]="ConeVolume",n[n.ConeVolumeShell=9]="ConeVolumeShell",n[n.Circle=10]="Circle",n[n.CircleEdge=11]="CircleEdge",n[n.SingleSidedEdge=12]="SingleSidedEdge",n[n.MeshRenderer=13]="MeshRenderer",n[n.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",n[n.BoxShell=15]="BoxShell",n[n.BoxEdge=16]="BoxEdge",n[n.Donut=17]="Donut",n[n.Rectangle=18]="Rectangle",n[n.Sprite=19]="Sprite",n[n.SpriteRenderer=20]="SpriteRenderer",n))(Wz||{});class ht{constructor(){h(this,"mode");h(this,"constant");h(this,"constantMin");h(this,"constantMax");h(this,"curve");h(this,"curveMin");h(this,"curveMax");h(this,"curveMultiplier")}evaluate(e,t){const i=t===void 0?Math.random():t;switch(this.mode){case 0:return this.constant;case 1:return e=tt.clamp01(e),this.curve.evaluate(e)*this.curveMultiplier;case 2:const s=e*this.curveMin.duration,r=e*this.curveMax.duration;return tt.lerp(this.curveMin.evaluate(s),this.curveMax.evaluate(r),i%1)*this.curveMultiplier;case 3:return tt.lerp(this.constantMin,this.constantMax,i%1);default:this.curveMax.evaluate(e)*this.curveMultiplier;break}return 0}getMax(){switch(this.mode){case 0:return this.constant;case 1:return this.getMaxFromCurve(this.curve)*this.curveMultiplier;case 2:return Math.max(this.getMaxFromCurve(this.curveMin),this.getMaxFromCurve(this.curveMax))*this.curveMultiplier;case 3:return Math.max(this.constantMin,this.constantMax);default:return 0}}getMaxFromCurve(e){if(!e)return 0;let t=Number.MIN_VALUE;for(let i=0;i<e.keys.length;i++){const s=e.keys[i];s.value>t&&(t=s.value)}return t}}se([x()],ht.prototype,"mode",2);se([x()],ht.prototype,"constant",2);se([x()],ht.prototype,"constantMin",2);se([x()],ht.prototype,"constantMax",2);se([x(zu)],ht.prototype,"curve",2);se([x(zu)],ht.prototype,"curveMin",2);se([x(zu)],ht.prototype,"curveMax",2);se([x()],ht.prototype,"curveMultiplier",2);var n0;const Ko=(n0=class{constructor(){h(this,"mode");h(this,"color");h(this,"colorMin");h(this,"colorMax");h(this,"gradient");h(this,"gradientMin");h(this,"gradientMax")}evaluate(n,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.color;case 1:return this.gradient.evaluate(n,Ko._temp),Ko._temp;case 2:return Ko._temp.lerpColors(this.colorMin,this.colorMax,t);case 3:return this.gradientMin.evaluate(n,Ko._temp),this.gradientMax.evaluate(n,Ko._temp2),Ko._temp.lerp(Ko._temp2,t)}return Ko._temp.set(16711935),Ko._temp.alpha=1,Ko._temp}},h(n0,"_temp",new bi(0,0,0,1)),h(n0,"_temp2",new bi(0,0,0,1)),n0);let Ir=Ko;se([x(bi)],Ir.prototype,"color",2);se([x(bi)],Ir.prototype,"colorMin",2);se([x(bi)],Ir.prototype,"colorMax",2);se([x(Ch)],Ir.prototype,"gradient",2);se([x(Ch)],Ir.prototype,"gradientMin",2);se([x(Ch)],Ir.prototype,"gradientMax",2);var fM=(n=>(n[n.Hierarchy=0]="Hierarchy",n[n.Local=1]="Local",n[n.Shape=2]="Shape",n))(fM||{});class bs{constructor(){h(this,"cullingMode");h(this,"duration");h(this,"emitterVelocityMode");h(this,"flipRotation");h(this,"gravityModifier");h(this,"gravityModifierMultiplier");h(this,"loop");h(this,"maxParticles");h(this,"playOnAwake");h(this,"prewarm");h(this,"ringBufferLoopRange");h(this,"ringBufferMode");h(this,"scalingMode");h(this,"simulationSpace");h(this,"simulationSpeed");h(this,"startColor");h(this,"startDelay");h(this,"startDelayMultiplier");h(this,"startLifetime");h(this,"startLifetimeMultiplier");h(this,"startRotation");h(this,"startRotationMultiplier");h(this,"startRotation3D");h(this,"startRotationX");h(this,"startRotationXMultiplier");h(this,"startRotationY");h(this,"startRotationYMultiplier");h(this,"startRotationZ");h(this,"startRotationZMultiplier");h(this,"startSize");h(this,"startSize3D");h(this,"startSizeMultiplier");h(this,"startSizeX");h(this,"startSizeXMultiplier");h(this,"startSizeY");h(this,"startSizeYMultiplier");h(this,"startSizeZ");h(this,"startSizeZMultiplier");h(this,"startSpeed");h(this,"startSpeedMultiplier");h(this,"stopAction");h(this,"useUnscaledTime")}}se([x(ht)],bs.prototype,"gravityModifier",2);se([x(Ir)],bs.prototype,"startColor",2);se([x(ht)],bs.prototype,"startDelay",2);se([x(ht)],bs.prototype,"startLifetime",2);se([x(ht)],bs.prototype,"startRotation",2);se([x(ht)],bs.prototype,"startRotationX",2);se([x(ht)],bs.prototype,"startRotationY",2);se([x(ht)],bs.prototype,"startRotationZ",2);se([x(ht)],bs.prototype,"startSize",2);se([x(ht)],bs.prototype,"startSizeX",2);se([x(ht)],bs.prototype,"startSizeY",2);se([x(ht)],bs.prototype,"startSizeZ",2);se([x(ht)],bs.prototype,"startSpeed",2);class eA{constructor(){h(this,"cycleCount");h(this,"maxCount");h(this,"minCount");h(this,"probability");h(this,"repeatInterval");h(this,"time");h(this,"count");h(this,"_performed",0)}reset(){this._performed=0}run(e){if(e<=this.time)return 0;let t=0;if(this.cycleCount===0||this._performed<this.cycleCount){const i=this.time+this.repeatInterval*this._performed;if(e>=i&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:t=this.count.constant;break;case 3:t=tt.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:t=this.count.curve.evaluate(Math.random());break;case 2:const s=Math.random();t=tt.lerp(this.count.curveMin.evaluate(s),this.count.curveMax.evaluate(s),Math.random());break}}return t}}class ec{constructor(){h(this,"enabled");h(this,"bursts");h(this,"rateOverTime");h(this,"rateOverTimeMultiplier");h(this,"rateOverDistance");h(this,"rateOverDistanceMultiplier");h(this,"system")}get burstCount(){var e;return((e=this.bursts)==null?void 0:e.length)??0}reset(){var e;(e=this.bursts)==null||e.forEach(t=>t.reset())}getBurst(){let e=0;if(this.burstCount>0)for(let t=0;t<this.burstCount;t++){const i=this.bursts[t];this.system.main.loop&&i.time>=this.system.time&&i.reset(),e+=Math.round(i.run(this.system.time))}return e}}se([x()],ec.prototype,"enabled",2);se([x()],ec.prototype,"bursts",2);se([x(ht)],ec.prototype,"rateOverTime",2);se([x()],ec.prototype,"rateOverTimeMultiplier",2);se([x(ht)],ec.prototype,"rateOverDistance",2);se([x()],ec.prototype,"rateOverDistanceMultiplier",2);class iv{constructor(){h(this,"enabled");h(this,"color")}}se([x(Ir)],iv.prototype,"color",2);class Eh{constructor(){h(this,"enabled");h(this,"separateAxes");h(this,"size");h(this,"sizeMultiplier");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier");h(this,"_time",0);h(this,"_temp",new w)}evaluate(e,t,i){if(t||(t=this._temp),!this.enabled)return t.x=t.y=t.z=1,t;if(this.separateAxes)t.x=this.x.evaluate(e,i)*this.xMultiplier,t.y=this.y.evaluate(e,i)*this.yMultiplier,t.z=this.z.evaluate(e,i)*this.zMultiplier;else{const s=this.size.evaluate(e,i)*this.sizeMultiplier;t.x=s}return t}}se([x(ht)],Eh.prototype,"size",2);se([x(ht)],Eh.prototype,"x",2);se([x(ht)],Eh.prototype,"y",2);se([x(ht)],Eh.prototype,"z",2);var s0;const Dg=(s0=class{constructor(){h(this,"shapeType",5);h(this,"enabled",!0);h(this,"alignToDirection",!1);h(this,"angle",0);h(this,"arc",360);h(this,"arcSpread");h(this,"arcSpeedMultiplier");h(this,"arcMode");h(this,"boxThickness");h(this,"position");h(this,"rotation");h(this,"_rotation",new mn);h(this,"scale");h(this,"radius");h(this,"radiusThickness");h(this,"sphericalDirectionAmount");h(this,"randomDirectionAmount");h(this,"randomPositionAmount");h(this,"system");h(this,"_space");h(this,"_worldSpaceMatrix",new Me);h(this,"_worldSpaceMatrixInverse",new Me);h(this,"_vector",new w(0,0,0));h(this,"_temp",new w(0,0,0));h(this,"_dir",new w);h(this,"_loopTime",0);h(this,"_loopDirection",1);Uy&&console.log(this)}get type(){return Wz[this.shapeType]}initialize(n){this.getPosition(),n.position.copy(this._vector)}toJSON(){return this}clone(){return new Dg}update(n,e,t,i){this.system=n,this._space=t,t===1&&(this._worldSpaceMatrix.copy(i.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(n){const e=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return e&&(this._rotation.x=tt.toRadians(this.rotation.x),this._rotation.y=tt.toRadians(this.rotation.y),this._rotation.z=tt.toRadians(this.rotation.z),this._rotation.order="ZYX",n.applyEuler(this._rotation)),e}get vector(){return this._vector}getPosition(){this._vector.set(0,0,0);const n=this._temp.copy(this.position),e=this._space===1;e&&n.applyQuaternion(this.system.worldQuaternion);let t=this.radius;if(e&&(t*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:Uy&&zc.DrawBox(this.position,this.scale,14540253,1),this._vector.x=Math.random()*this.scale.x-this.scale.x/2,this._vector.y=Math.random()*this.scale.y-this.scale.y/2,this._vector.z=Math.random()*this.scale.z-this.scale.z/2,this._vector.add(n);break;case 4:this.randomConePoint(this.position,this.angle,t,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,t,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,t,this.radiusThickness,this.arc,this._vector);break;default:this._vector.set(0,0,0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),e&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),Uy&&zc.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(n){var e;if(!this.enabled)return this._dir.set(0,0,1),this._dir;switch(this.shapeType){case 5:this._dir.set(0,0,1);break;case 4:this._dir.set(0,0,1);break;case 10:case 0:const t=n.x,i=n.y,s=n.z;this._dir.set(t,i,s),(e=this.system)!=null&&e.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;default:this._dir.set(0,0,1);break}return this._space===1&&this._dir.applyQuaternion(this.system.worldQuaternion),this.applyRotation(this._dir),this._dir.normalize(),this.spherizeDirection(this._dir,this.sphericalDirectionAmount),this.randomizeDirection(this._dir,this.randomDirectionAmount),Uy&&(zc.DrawSphere(n,.01,8925952,.5,!0),zc.DrawDirection(n,this._dir,8925952,.5,!0)),this._dir}randomizePosition(n,e){if(e<=0)return;const t=Dg._tempVec;t.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),t.x*=e*this.scale.x,t.y*=e*this.scale.y,t.z*=e*this.scale.z,n.add(t)}randomizeDirection(n,e){if(e===0)return;const t=Dg._randomQuat,i=Dg._tempVec;i.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),t.setFromAxisAngle(i,e*Math.random()*Math.PI),n.applyQuaternion(t)}spherizeDirection(n,e){if(e===0)return;const t=Math.random()*Math.PI*2,i=Math.acos(1-Math.random()*2),s=Math.sin(i)*Math.cos(t),r=Math.sin(i)*Math.sin(t),o=Math.cos(i),a=new w(s,r,o);n.lerp(a,e)}randomSpherePoint(n,e,t,i,s){const r=Math.random(),o=Math.random(),a=2*Math.PI*r*(i/360),c=Math.acos(2*o-1),l=tt.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,u=n.x+this.scale.x*(-l*Math.sin(c)*Math.cos(a)),d=n.y+this.scale.y*(l*Math.sin(c)*Math.sin(a)),f=n.z+this.scale.z*(l*Math.cos(c));s.x=u,s.y=d,s.z=f}randomCirclePoint(n,e,t,i,s){const r=Math.random(),o=2*Math.PI*r*(i/360),a=tt.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,c=n.x+this.scale.x*a*Math.cos(o),l=n.y+this.scale.y*a*Math.sin(o),u=n.z;s.x=c,s.y=l,s.z=u}randomConePoint(n,e,t,i,s,r,o){let a=0,c=0;switch(r){case 0:a=Math.random(),c=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:a=.5,c=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let l=2*Math.PI*a*(s/360);switch(r){case 2:case 1:l+=Math.PI+.5,l+=this._loopTime*Math.PI*2,l%=tt.toRadians(s);break}const u=Math.acos(2*c-1),d=tt.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*t,f=n.x+-d*Math.sin(u)*Math.cos(l),p=n.y+d*Math.sin(u)*Math.sin(l),g=n.z;o.x=f*this.scale.x,o.y=p*this.scale.y,o.z=g*this.scale.z}},h(s0,"_randomQuat",new we),h(s0,"_tempVec",new w),s0);let bn=Dg;se([x()],bn.prototype,"shapeType",2);se([x()],bn.prototype,"enabled",2);se([x()],bn.prototype,"alignToDirection",2);se([x()],bn.prototype,"angle",2);se([x()],bn.prototype,"arc",2);se([x()],bn.prototype,"arcSpread",2);se([x()],bn.prototype,"arcSpeedMultiplier",2);se([x()],bn.prototype,"arcMode",2);se([x(w)],bn.prototype,"boxThickness",2);se([x(w)],bn.prototype,"position",2);se([x(w)],bn.prototype,"rotation",2);se([x(w)],bn.prototype,"scale",2);se([x()],bn.prototype,"radius",2);se([x()],bn.prototype,"radiusThickness",2);se([x()],bn.prototype,"sphericalDirectionAmount",2);se([x()],bn.prototype,"randomDirectionAmount",2);se([x()],bn.prototype,"randomPositionAmount",2);class vi{constructor(){h(this,"damping");h(this,"enabled");h(this,"frequency");h(this,"octaveCount");h(this,"octaveMultiplier");h(this,"octaveScale");h(this,"positionAmount");h(this,"quality");h(this,"remap");h(this,"remapEnabled");h(this,"remapMultiplier");h(this,"remapX");h(this,"remapXMultiplier");h(this,"remapY");h(this,"remapYMultiplier");h(this,"remapZ");h(this,"remapZMultiplier");h(this,"scrollSpeedMultiplier");h(this,"separateAxes");h(this,"strengthMultiplier");h(this,"strengthX");h(this,"strengthXMultiplier");h(this,"strengthY");h(this,"strengthYMultiplier");h(this,"strengthZ");h(this,"strengthZMultiplier");h(this,"_noise");h(this,"_time",0);h(this,"_temp",new w)}update(e){this._time+=e.time.deltaTime*this.scrollSpeedMultiplier}apply(e,t,i,s,r,o){if(!this.enabled)return;this._noise||(this._noise=nne(()=>0));const a=this._temp.set(t.x,t.y,t.z).multiplyScalar(this.frequency),c=this._noise(a.x,a.y,a.z,this._time),l=this._noise(a.x,a.y,a.z,this._time+1e3*this.frequency),u=this._noise(a.x,a.y,a.z,this._time+2e3*this.frequency);this._temp.set(c,l,u).normalize();const d=r/o;let f=this.positionAmount.evaluate(d);this.separateAxes?(this._temp.x*=f*this.strengthXMultiplier,this._temp.y*=f*this.strengthYMultiplier,this._temp.z*=f*this.strengthZMultiplier):(this.strengthX&&(f*=this.strengthX.evaluate(d)*1.5),this._temp.multiplyScalar(f)),i.x+=this._temp.x,i.y+=this._temp.y,i.z+=this._temp.z}}se([x()],vi.prototype,"damping",2);se([x()],vi.prototype,"enabled",2);se([x()],vi.prototype,"frequency",2);se([x()],vi.prototype,"octaveCount",2);se([x()],vi.prototype,"octaveMultiplier",2);se([x()],vi.prototype,"octaveScale",2);se([x(ht)],vi.prototype,"positionAmount",2);se([x()],vi.prototype,"quality",2);se([x(ht)],vi.prototype,"remap",2);se([x()],vi.prototype,"remapEnabled",2);se([x()],vi.prototype,"remapMultiplier",2);se([x(ht)],vi.prototype,"remapX",2);se([x()],vi.prototype,"remapXMultiplier",2);se([x(ht)],vi.prototype,"remapY",2);se([x()],vi.prototype,"remapYMultiplier",2);se([x(ht)],vi.prototype,"remapZ",2);se([x()],vi.prototype,"remapZMultiplier",2);se([x()],vi.prototype,"scrollSpeedMultiplier",2);se([x()],vi.prototype,"separateAxes",2);se([x()],vi.prototype,"strengthMultiplier",2);se([x(ht)],vi.prototype,"strengthX",2);se([x()],vi.prototype,"strengthXMultiplier",2);se([x(ht)],vi.prototype,"strengthY",2);se([x()],vi.prototype,"strengthYMultiplier",2);se([x(ht)],vi.prototype,"strengthZ",2);se([x()],vi.prototype,"strengthZMultiplier",2);class ji{constructor(){h(this,"enabled");h(this,"attachRibbonToTransform",!1);h(this,"colorOverLifetime");h(this,"colorOverTrail");h(this,"dieWithParticles",!0);h(this,"inheritParticleColor",!0);h(this,"lifetime");h(this,"lifetimeMultiplier");h(this,"minVertexDistance",.2);h(this,"mode",0);h(this,"ratio",1);h(this,"ribbonCount",1);h(this,"shadowBias",0);h(this,"sizeAffectsLifetime",!1);h(this,"sizeAffectsWidth",!1);h(this,"splitSubEmitterRibbons",!1);h(this,"textureMode",0);h(this,"widthOverTrail");h(this,"widthOverTrailMultiplier");h(this,"worldSpace",!1)}getWidth(e,t,i,s){const r=this.widthOverTrail.evaluate(i,s);return e*=r,e}getColor(e,t,i){const s=this.colorOverTrail.evaluate(i),r=this.colorOverLifetime.evaluate(t);e.x*=s.r*r.r,e.y*=s.g*r.g,e.z*=s.b*r.b,e.w*=s.alpha*r.alpha}}se([x()],ji.prototype,"enabled",2);se([x()],ji.prototype,"attachRibbonToTransform",2);se([x(Ir)],ji.prototype,"colorOverLifetime",2);se([x(Ir)],ji.prototype,"colorOverTrail",2);se([x()],ji.prototype,"dieWithParticles",2);se([x()],ji.prototype,"inheritParticleColor",2);se([x(ht)],ji.prototype,"lifetime",2);se([x()],ji.prototype,"lifetimeMultiplier",2);se([x()],ji.prototype,"minVertexDistance",2);se([x()],ji.prototype,"mode",2);se([x()],ji.prototype,"ratio",2);se([x()],ji.prototype,"ribbonCount",2);se([x()],ji.prototype,"shadowBias",2);se([x()],ji.prototype,"sizeAffectsLifetime",2);se([x()],ji.prototype,"sizeAffectsWidth",2);se([x()],ji.prototype,"splitSubEmitterRibbons",2);se([x()],ji.prototype,"textureMode",2);se([x(ht)],ji.prototype,"widthOverTrail",2);se([x()],ji.prototype,"widthOverTrailMultiplier",2);se([x()],ji.prototype,"worldSpace",2);class Zi{constructor(){h(this,"enabled");h(this,"space",0);h(this,"orbitalX");h(this,"orbitalY");h(this,"orbitalZ");h(this,"orbitalXMultiplier");h(this,"orbitalYMultiplier");h(this,"orbitalZMultiplier");h(this,"orbitalOffsetX");h(this,"orbitalOffsetY");h(this,"orbitalOffsetZ");h(this,"speedModifier");h(this,"speedModifierMultiplier");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier");h(this,"_system");h(this,"_temp",new w);h(this,"_temp2",new w);h(this,"_temp3",new w);h(this,"_hasOrbital",!1);h(this,"_index",0);h(this,"_orbitalMatrix",new Me)}update(e){this._system=e}init(e){this._index==0&&(e.debug=!0),this._index+=1,e.orbitx=this.orbitalX.evaluate(Math.random()),e.orbity=this.orbitalY.evaluate(Math.random()),e.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=e.orbitx!=0||e.orbity!=0||e.orbitz!=0}apply(e,t,i,s,r,o,a){var p;if(!this.enabled)return;const c=o/a,l=this.speedModifier.evaluate(c)*this.speedModifierMultiplier,u=this.x.evaluate(c),d=this.y.evaluate(c),f=this.z.evaluate(c);if(this._temp.set(-u,d,f),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((p=this._system)==null?void 0:p.worldPos)){const A=this._temp2.set(i.x,i.y,i.z),v=this.orbitalXMultiplier,m=this.orbitalYMultiplier,b=this.orbitalZMultiplier,y=l*Math.PI*2*10,_=Math.cos(y*v),C=Math.sin(y*v),M=Math.cos(y*m),I=Math.sin(y*m),R=Math.cos(y*b),E=Math.sin(y*b),T=A.x*(M*R)+A.y*(M*E)+A.z*-I,D=A.x*(C*I*R-_*E)+A.y*(C*I*E+_*R)+A.z*(C*M),K=A.x*(_*I*R+C*E)+A.y*(_*I*E-C*R)+A.z*(_*M),H=this._temp3.set(A.x-T,A.y-D,A.z-K);H.normalize(),H.multiplyScalar(.2/r*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),s.x+=H.x,s.y+=H.y,s.z+=H.z}s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z,s.x*=l,s.y*=l,s.z*=l}}se([x()],Zi.prototype,"enabled",2);se([x()],Zi.prototype,"space",2);se([x(ht)],Zi.prototype,"orbitalX",2);se([x(ht)],Zi.prototype,"orbitalY",2);se([x(ht)],Zi.prototype,"orbitalZ",2);se([x()],Zi.prototype,"orbitalXMultiplier",2);se([x()],Zi.prototype,"orbitalYMultiplier",2);se([x()],Zi.prototype,"orbitalZMultiplier",2);se([x()],Zi.prototype,"orbitalOffsetX",2);se([x()],Zi.prototype,"orbitalOffsetY",2);se([x()],Zi.prototype,"orbitalOffsetZ",2);se([x(ht)],Zi.prototype,"speedModifier",2);se([x()],Zi.prototype,"speedModifierMultiplier",2);se([x(ht)],Zi.prototype,"x",2);se([x()],Zi.prototype,"xMultiplier",2);se([x(ht)],Zi.prototype,"y",2);se([x()],Zi.prototype,"yMultiplier",2);se([x(ht)],Zi.prototype,"z",2);se([x()],Zi.prototype,"zMultiplier",2);class _s{constructor(){h(this,"animation");h(this,"enabled");h(this,"cycleCount");h(this,"frameOverTime");h(this,"frameOverTimeMultiplier");h(this,"numTilesX");h(this,"numTilesY");h(this,"startFrame");h(this,"startFrameMultiplier");h(this,"rowMode");h(this,"rowIndex");h(this,"spriteCount");h(this,"timeMode")}sampleOnceAtStart(){if(this.timeMode===0)switch(this.frameOverTime.mode){case 0:case 3:case 2:case 1:return!0}return!1}getStartIndex(){return this.sampleOnceAtStart()?Math.random()*(this.numTilesX*this.numTilesY):0}evaluate(e){if(!this.sampleOnceAtStart())return this.getIndex(e)}getIndex(e){const t=this.numTilesX*this.numTilesY;e=e*this.cycleCount;let i=this.frameOverTime.evaluate(e%1);return i*=this.frameOverTimeMultiplier,i*=t,i=i%t,i=Math.floor(i),i}}se([x()],_s.prototype,"animation",2);se([x()],_s.prototype,"enabled",2);se([x()],_s.prototype,"cycleCount",2);se([x(ht)],_s.prototype,"frameOverTime",2);se([x()],_s.prototype,"frameOverTimeMultiplier",2);se([x()],_s.prototype,"numTilesX",2);se([x()],_s.prototype,"numTilesY",2);se([x(ht)],_s.prototype,"startFrame",2);se([x()],_s.prototype,"startFrameMultiplier",2);se([x()],_s.prototype,"rowMode",2);se([x()],_s.prototype,"rowIndex",2);se([x()],_s.prototype,"spriteCount",2);se([x()],_s.prototype,"timeMode",2);class zo{constructor(){h(this,"enabled");h(this,"separateAxes");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier")}evaluate(e,t){return this.enabled?this.separateAxes?0:this.z.evaluate(e,t)*-1:0}}se([x()],zo.prototype,"enabled",2);se([x()],zo.prototype,"separateAxes",2);se([x(ht)],zo.prototype,"x",2);se([x()],zo.prototype,"xMultiplier",2);se([x(ht)],zo.prototype,"y",2);se([x()],zo.prototype,"yMultiplier",2);se([x(ht)],zo.prototype,"z",2);se([x()],zo.prototype,"zMultiplier",2);class so{constructor(){h(this,"enabled");h(this,"range");h(this,"separateAxes");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier")}evaluate(e,t){if(!this.enabled)return 0;if(!this.separateAxes){const i=tt.lerp(this.range.x,this.range.y,t);return this.z.evaluate(i)*-1}return 0}}se([x()],so.prototype,"enabled",2);se([x()],so.prototype,"range",2);se([x()],so.prototype,"separateAxes",2);se([x(ht)],so.prototype,"x",2);se([x()],so.prototype,"xMultiplier",2);se([x(ht)],so.prototype,"y",2);se([x()],so.prototype,"yMultiplier",2);se([x(ht)],so.prototype,"z",2);se([x()],so.prototype,"zMultiplier",2);class Bn{constructor(){h(this,"enabled");h(this,"dampen");h(this,"drag");h(this,"dragMultiplier");h(this,"limit");h(this,"limitMultiplier");h(this,"separateAxes");h(this,"limitX");h(this,"limitXMultiplier");h(this,"limitY");h(this,"limitYMultiplier");h(this,"limitZ");h(this,"limitZMultiplier");h(this,"multiplyDragByParticleSize",!1);h(this,"multiplyDragByParticleVelocity",!1);h(this,"space");h(this,"_temp",new w);h(this,"_temp2",new w)}apply(e,t,i,s,r,o,a){if(this.enabled){const c=this.limit.evaluate(r)*this.limitMultiplier;if(t.length()>c){this._temp.copy(t).normalize().multiplyScalar(c);const u=this.dampen*.5;t.x=tt.lerp(t.x,this._temp.x,u),t.y=tt.lerp(t.y,this._temp.y,u),t.z=tt.lerp(t.z,this._temp.z,u),i.x=tt.lerp(i.x,this._temp.x,u),i.y=tt.lerp(i.y,this._temp.y,u),i.z=tt.lerp(i.z,this._temp.z,u)}}}}se([x()],Bn.prototype,"enabled",2);se([x()],Bn.prototype,"dampen",2);se([x(ht)],Bn.prototype,"drag",2);se([x()],Bn.prototype,"dragMultiplier",2);se([x(ht)],Bn.prototype,"limit",2);se([x()],Bn.prototype,"limitMultiplier",2);se([x()],Bn.prototype,"separateAxes",2);se([x(ht)],Bn.prototype,"limitX",2);se([x()],Bn.prototype,"limitXMultiplier",2);se([x(ht)],Bn.prototype,"limitY",2);se([x()],Bn.prototype,"limitYMultiplier",2);se([x(ht)],Bn.prototype,"limitZ",2);se([x()],Bn.prototype,"limitZMultiplier",2);se([x()],Bn.prototype,"multiplyDragByParticleSize",2);se([x()],Bn.prototype,"multiplyDragByParticleVelocity",2);se([x()],Bn.prototype,"space",2);class Mh{constructor(){h(this,"enabled");h(this,"curve");h(this,"curveMultiplier");h(this,"mode");h(this,"system");h(this,"_lastWorldPosition");h(this,"_velocity",new w);h(this,"_temp",new w)}update(e){this.enabled&&this.system.worldspace!==!1&&(this._lastWorldPosition?(this._velocity.copy(this.system.worldPos).sub(this._lastWorldPosition).multiplyScalar(1/this.system.deltaTime),this._lastWorldPosition.copy(this.system.worldPos)):(this._velocity.set(0,0,0),this._lastWorldPosition=this.system.worldPos.clone()))}applyInitial(e){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const t=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(t),e.add(this._temp)}}applyCurrent(e,t,i){if(this.enabled&&this.system.worldspace!==!1&&this.mode===1){const s=this.curve.evaluate(t,i);this._temp.copy(this._velocity).multiplyScalar(s),e.add(this._temp)}}}se([x()],Mh.prototype,"enabled",2);se([x(ht)],Mh.prototype,"curve",2);se([x()],Mh.prototype,"curveMultiplier",2);se([x()],Mh.prototype,"mode",2);class lr{constructor(){h(this,"enabled");h(this,"range");h(this,"separateAxes");h(this,"size");h(this,"sizeMultiplier");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier")}evaluate(e,t,i,s){const r=e.length(),o=tt.remap(r,this.range.x,this.range.y,0,1),a=this.size.evaluate(o,i);return s*a}}se([x()],lr.prototype,"enabled",2);se([x(te)],lr.prototype,"range",2);se([x()],lr.prototype,"separateAxes",2);se([x(ht)],lr.prototype,"size",2);se([x()],lr.prototype,"sizeMultiplier",2);se([x(ht)],lr.prototype,"x",2);se([x()],lr.prototype,"xMultiplier",2);se([x(ht)],lr.prototype,"y",2);se([x()],lr.prototype,"yMultiplier",2);se([x(ht)],lr.prototype,"z",2);se([x()],lr.prototype,"zMultiplier",2);class Yu{constructor(){h(this,"enabled");h(this,"range");h(this,"color")}evaluate(e,t,i){const s=e.length(),r=tt.remap(s,this.range.x,this.range.y,0,1),o=this.color.evaluate(r,t);i.x*=o.r,i.y*=o.g,i.z*=o.b,i.w*=o.alpha}}se([x()],Yu.prototype,"enabled",2);se([x(te)],Yu.prototype,"range",2);se([x(Ir)],Yu.prototype,"color",2);function xO(n){const e=n.domElement.shadowRoot.querySelector("link[rel='ar']");if(e)return e;const t=document.createElement("div");t.classList.add("menu"),t.classList.add("quicklook-menu"),t.style.display="none",t.style.visibility="hidden";const i=document.createElement("button");i.id="open-in-ar",i.innerText="Open in QuickLook",t.appendChild(i);const s=document.createElement("a");s.id="needle-usdz-link",s.style.display="none",s.rel="ar",s.href="",t.appendChild(s);const r=document.createElement("img");return r.id="button",s.appendChild(r),n.domElement.shadowRoot.appendChild(t),s}function ane(){var n=new Date;const e=n.getMonth()+1,t=n.getDate(),i=n.getHours(),s=n.getMinutes(),r=n.getSeconds(),o=(e<10?"0":"")+e,a=(t<10?"0":"")+t,c=(i<10?"0":"")+i,l=(s<10?"0":"")+s,u=(r<10?"0":"")+r;return n.getFullYear()+o+a+"-"+c+l+u}const Ny=re("debugusdz");function cne(n,e){const t=[],i=ne.getComponentsInChildren(n,ks),s=ne.getComponentsInChildren(n,$r);let r=!1;const o=new tr("rest",.01,[]),a=new Map,c=(l,u)=>{if(!r&&u.tracks.length>0&&(r=!0,l.push(o)),u.tracks.length>0)for(const d of u.tracks){const f=Nt.parseTrackName(d.name),p=Nt.findNode(n,f.nodeName);if(p){a.has(p)||a.set(p,[]);const g=a.get(p);switch(f.propertyName){case"position":{if(g.includes("position"))continue;const A=p.position,v=new wr(d.name,[0,.01],[A.x,A.y,A.z,A.x,A.y,A.z]);g.push("position"),o.tracks.push(v);break}case"quaternion":{if(g.includes("quaternion"))continue;const A=p.quaternion,v=new wr(d.name,[0,.01],[A.x,A.y,A.z,A.w,A.x,A.y,A.z,A.w]);g.push("quaternion"),o.tracks.push(v);break}case"scale":{if(g.includes("scale"))continue;const A=p.scale,v=new wr(d.name,[0,.01],[A.x,A.y,A.z,A.x,A.y,A.z]);g.push("scale"),o.tracks.push(v);break}}}}};for(const l of i){if(!l||!l.runtimeAnimatorController)continue;Ny&&console.log(l);const u=[];for(const d of l.runtimeAnimatorController.enumerateActions()){Ny&&console.log(d);const f=d.getClip();c(u,f),u.includes(f)||u.push(f)}t.push({root:l.gameObject,clips:u})}for(const l of s){Ny&&console.log(l);const u=[];for(const d of l.animations)c(u,d),u.includes(d)||u.push(d);t.push({root:l.gameObject,clips:u})}Ny&&(console.log("Rest Pose Clip",o),console.log("USDZ Animation Clips",t));for(const l of t)for(const u of l.clips)e.registerAnimation(l.root,u)}class lne{static createButton(e,t={},i){const s=document.createElement("button");let r=!1;function o(){if(t.optionalFeatures=t.optionalFeatures||[],t.domOverlay===void 0){var u=document.createElement("div");u.style.display="none",document.body.appendChild(u);var d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("width",38),d.setAttribute("height",38),d.style.position="absolute",d.style.right="20px",d.style.top="20px",d.addEventListener("click",function(){p.end()}),u.appendChild(d);var f=document.createElementNS("http://www.w3.org/2000/svg","path");f.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),f.setAttribute("stroke","#fff"),f.setAttribute("stroke-width",2),d.appendChild(f),t.optionalFeatures.push("dom-overlay"),t.domOverlay={root:u},r=!0}let p=null,g=null;async function A(m){var _;const b=/WebXRViewer\//i.test(navigator.userAgent),y=t.domOverlay.root;b&&((_=t.domOverlay)!=null&&_.root?(g=y.parentNode,g&&(console.log("Reparent DOM Overlay to body",y,y.style.display),y.style.display="",y.style.visibility="",document.body.appendChild(y))):console.warn("WebXRViewer: No DOM Overlay found")),m.addEventListener("end",v),await e.xr.setSession(m),s.textContent="STOP AR",r&&(t.domOverlay.root.style.display=""),p=m}function v(){p.removeEventListener("end",v),s.textContent="START AR";const m=t.domOverlay.root;g&&g.appendChild(m),r&&(m.style.display="none"),p=null}s.style.display="",s.style.cursor="pointer",s.style.left="calc(50% - 50px)",s.style.width="100px",s.textContent="START AR",s.onmouseenter=function(){s.style.opacity="1.0"},s.onmouseleave=function(){s.style.opacity="0.5"},s.onclick=function(){p===null?(i==null||i.call(this,t),navigator.xr.requestSession("immersive-ar",t).then(A)):p.end()}}function a(){s.disabled=!0,s.style.display="",s.style.cursor="auto",s.style.left="calc(50% - 75px)",s.style.width="150px",s.onmouseenter=null,s.onmouseleave=null,s.onclick=null}function c(){a(),s.textContent="AR NOT SUPPORTED"}function l(u){u.style.position="absolute",u.style.bottom="20px",u.style.padding="12px 6px",u.style.border="1px solid #fff",u.style.borderRadius="4px",u.style.background="rgba(0,0,0,0.1)",u.style.color="#fff",u.style.font="normal 13px sans-serif",u.style.textAlign="center",u.style.opacity="0.5",u.style.outline="none",u.style.zIndex="999"}if("xr"in navigator)return s.id="ARButton",s.style.display="none",l(s),navigator.xr.isSessionSupported("immersive-ar").then(function(u){u?o():c()}).catch(c),s;{const u=document.createElement("a");return window.isSecureContext===!1?(u.href=document.location.href.replace(/^http:/,"https:"),u.innerHTML="WEBXR NEEDS HTTPS"):(u.href="https://immersiveweb.dev/",u.innerHTML="WEBXR NOT AVAILABLE"),u.style.left="calc(50% - 90px)",u.style.width="180px",u.style.textDecoration="none",l(u),u}}}const Gb=class{static createButton(e,t){const i=document.createElement("button");function s(){let c=null;async function l(d){d.addEventListener("end",u),await e.xr.setSession(d),i.textContent="EXIT VR",c=d}function u(){c.removeEventListener("end",u),i.textContent="ENTER VR",c=null}i.style.display="",i.style.cursor="pointer",i.style.left="calc(50% - 50px)",i.style.width="100px",i.textContent="ENTER VR",i.onmouseenter=function(){i.style.opacity="1.0"},i.onmouseleave=function(){i.style.opacity="0.5"},i.onclick=function(){if(c===null){const d={optionalFeatures:t.optionalFeatures};navigator.xr.requestSession("immersive-vr",d).then(l)}else c.end()}}function r(){i.disabled=!0,i.style.display="",i.style.cursor="auto",i.style.left="calc(50% - 75px)",i.style.width="150px",i.onmouseenter=null,i.onmouseleave=null,i.onclick=null}function o(){r(),i.textContent="VR NOT SUPPORTED"}function a(c){c.style.position="absolute",c.style.bottom="20px",c.style.padding="12px 6px",c.style.border="1px solid #fff",c.style.borderRadius="4px",c.style.background="rgba(0,0,0,0.1)",c.style.color="#fff",c.style.font="normal 13px sans-serif",c.style.textAlign="center",c.style.opacity="0.5",c.style.outline="none",c.style.zIndex="999"}if("xr"in navigator)return i.id="VRButton",i.style.display="none",a(i),navigator.xr.isSessionSupported("immersive-vr").then(function(c){c?s():o(),Gb.xrSessionIsGranted&&(console.log("XR session is granted - will enter immersive web now"),i.click())}),i;{const c=document.createElement("a");return window.isSecureContext===!1?(c.href=document.location.href.replace(/^http:/,"https:"),c.innerHTML="WEBXR NEEDS HTTPS"):(c.href="https://immersiveweb.dev/",c.innerHTML="WEBXR NOT AVAILABLE"),c.style.left="calc(50% - 90px)",c.style.width="180px",c.style.textDecoration="none",a(c),c}}static registerSessionGrantedListener(){if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent))return;navigator.xr.addEventListener("sessiongranted",()=>{Gb.xrSessionIsGranted=!0})}}};let rm=Gb;h(rm,"xrSessionIsGranted",!1);rm.registerSessionGrantedListener();var hne=Object.defineProperty,une=Object.getOwnPropertyDescriptor,CI=(n,e,t,i)=>{for(var s=i>1?void 0:i?une(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&hne(e,t,s),s};const dne=new Me;class ca extends Ie{constructor(){super(...arguments);h(this,"webAR",null);h(this,"invertForward",!1);h(this,"arTouchTransform",!1);h(this,"_initalMatrix",new Me);h(this,"_selectStartFn",this.onSelectStart.bind(this));h(this,"_selectEndFn",this.onSelectEnd.bind(this));h(this,"userInput");h(this,"_arScale",1);h(this,"_rig",null);h(this,"_startPose",null);h(this,"_placementPose",null);h(this,"_isTouching",!1);h(this,"_rigStartPose",null);h(this,"_gotFirstHitTestResult",!1);h(this,"_anchor",null);h(this,"_anchorMatrix",new Me);h(this,"_invertedSessionRootMatrix",new Me);h(this,"_invertForwardMatrix",new Me().makeRotationY(Math.PI))}get rig(){var t;return(t=this.webAR)==null?void 0:t.webxr.Rig}get arScale(){return this._arScale}set arScale(t){t!==this._arScale&&(this._arScale=t,this.setScale(t))}start(){const t=ne.findObjectOfType(It);t&&(t.Rig.updateMatrix(),this._initalMatrix.copy(t.Rig.matrix))}onBegin(t){var i;this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose=this.gameObject.matrix.clone(),this._rigStartPose=(i=this.rig)==null?void 0:i.matrix.clone(),this._gotFirstHitTestResult=!1,this._anchor=null,t.addEventListener("selectstart",this._selectStartFn),t.addEventListener("selectend",this._selectEndFn),this.gameObject.visible=!1,this.rig&&(this.rig.matrixAutoUpdate=!0,this._initalMatrix.decompose(this.rig.position,this.rig.quaternion,this.rig.scale)),this.dispatchEvent(new CustomEvent("onBeginSession"))}onUpdate(t,i,s,r){if(r&&!this._placementPose&&(this._gotFirstHitTestResult||(this._gotFirstHitTestResult=!0,this.dispatchEvent(new CustomEvent("canPlaceSession",{detail:{pose:r}}))),this._isTouching)){const o=new Me().fromArray(r.transform.matrix).invert();return this.dispatchEvent(new CustomEvent("placedSession",{detail:{pose:r,poseMatrix:o}})),this.webAR&&this.webAR.setReticleActive(!1),this.placeAt(t,o),s&&r&&this.onCreatePlacementAnchor(s,r),!0}return!1}onCreatePlacementAnchor(t,i){var s,r;this._anchor=null,(r=(s=t==null?void 0:t.createAnchor)==null?void 0:s.call(t,i.transform))==null||r.then(o=>{this.context.isInAR&&(this._anchor=o)})}onBeforeRender(t){if(t&&this._rig)if(this._anchor){const i=this.context.renderer.xr.getReferenceSpace();if(i){const s=t.getPose(this._anchor.anchorSpace,i);if(s){const r=this._anchorMatrix.fromArray(s.transform.matrix).invert();this.placeAt(this._rig,r);return}}}else this._placementPose&&this.placeAt(this._rig,this._placementPose)}placeAt(t,i){this._placementPose||(this._placementPose=new Me),this._placementPose.copy(i);const s=this._invertedSessionRootMatrix.copy(this.gameObject.matrixWorld).invert();this._placementPose.premultiply(s),t?(this.invertForward&&this._placementPose.premultiply(this._invertForwardMatrix),this.userInput||(this.userInput=new $d(this.context)),this.userInput.enable(),this._rig=t,this.setScale(this.arScale)):this._rig=null,this.gameObject.visible=!0}onEnd(t,i){var s,r;(s=this.userInput)==null||s.disable(),(r=this.userInput)==null||r.reset(),this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._anchor=null,this._startPose&&this.gameObject.matrix.copy(this._startPose),t&&(t.matrixAutoUpdate=!0,this._rigStartPose&&this._rigStartPose.decompose(t.position,t.quaternion,t.scale)),Sr.markDirty(this.gameObject,!0),setTimeout(()=>{this.gameObject&&(this.gameObject.matrixAutoUpdate=!0,this.gameObject.visible=!0)},100)}onSelectStart(){this._isTouching=!0}onSelectEnd(){this._isTouching=!1}setScale(t){const i=this._rig;!i||!this._placementPose||(this._rigStartPose||(this._rigStartPose=i.matrix.clone()),i.matrixAutoUpdate=!1,this.arTouchTransform&&this.userInput&&this.userInput.applyMatrixTo(this._placementPose),i.matrix.multiplyMatrices(dne.makeScale(t,t,t),this._placementPose),i.matrix.decompose(i.position,i.quaternion,i.scale),i.updateMatrixWorld())}}CI([x()],ca.prototype,"invertForward",2);CI([x()],ca.prototype,"arTouchTransform",2);CI([x()],ca.prototype,"arScale",1);const Hb=class{constructor(e){h(this,"oneFingerDrag",!0);h(this,"twoFingerRotate",!0);h(this,"twoFingerScale",!0);h(this,"context");h(this,"offset");h(this,"plane");h(this,"_scale",1);h(this,"_enabled",!1);h(this,"prev",new Map);h(this,"_didMultitouch",!1);h(this,"touchStart",e=>{for(let t=0;t<e.changedTouches.length;t++){const i=e.changedTouches[t];this.prev.has(i.identifier)||this.prev.set(i.identifier,{x:0,z:0,screenx:0,screeny:0});const s=this.prev.get(i.identifier);if(s){const r=this.getPositionOnPlane(i.clientX,i.clientY);s.x=r.x,s.z=r.z,s.screenx=i.clientX,s.screeny=i.clientY}}});h(this,"touchEnd",e=>{e.touches.length<=0&&(this._didMultitouch=!1)});h(this,"touchMove",e=>{if(!e.defaultPrevented){if(e.touches.length===1){if(this._didMultitouch)return;const t=e.touches[0],i=this.prev.get(t.identifier);if(!i)return;const s=this.getPositionOnPlane(t.clientX,t.clientY),r=s.x-i.x,o=s.z-i.z;if(r===0&&o===0)return;this.oneFingerDrag&&this.addMovement(r,o),i.x=s.x,i.z=s.z,i.screenx=t.clientX,i.screeny=t.clientY;return}else if(e.touches.length===2){this._didMultitouch=!0;const t=e.touches[0],i=e.touches[1],s=this.prev.get(t.identifier),r=this.prev.get(i.identifier);if(!s||!r)return;if(this.twoFingerRotate){const o=Math.atan2(t.clientY-i.clientY,t.clientX-i.clientX),a=Math.atan2(s.screeny-r.screeny,s.screenx-r.screenx),c=o-a;Math.abs(c)>.001&&this.addRotation(c)}if(this.twoFingerScale){const o=t.clientX-i.clientX,a=t.clientY-i.clientY,c=Math.sqrt(o*o+a*a),l=s.screenx-r.screenx,u=s.screeny-r.screeny,d=Math.sqrt(l*l+u*u),f=c-d;Math.abs(f)>2&&this.addScale(f)}s.screenx=t.clientX,s.screeny=t.clientY,r.screenx=i.clientX,r.screeny=i.clientY}}});h(this,"_raycaster",new Uu);h(this,"_intersection",new w);h(this,"_screenPos",new w);h(this,"_tempMatrix",new Me);this.context=e,this.offset=new Me,this.plane=new Qr,this.plane.setFromNormalAndCoplanarPoint(Hb.up,Hb.zero)}enable(){this._enabled||(this._enabled=!0,window.addEventListener("touchstart",this.touchStart,{passive:!1}),window.addEventListener("touchmove",this.touchMove,{passive:!1}),window.addEventListener("touchend",this.touchEnd,{passive:!1}))}disable(){this._enabled&&(this._enabled=!1,window.removeEventListener("touchstart",this.touchStart),window.removeEventListener("touchmove",this.touchMove),window.removeEventListener("touchend",this.touchEnd))}reset(){this._scale=1,this.offset.identity()}applyMatrixTo(e){e.premultiply(this.offset)}getPositionOnPlane(e,t){const i=this.context.mainCamera;return this._screenPos.x=e/window.innerWidth*2-1,this._screenPos.y=-(t/window.innerHeight)*2+1,this._screenPos.z=1,this._screenPos.unproject(i),this._raycaster.set(i.position,this._screenPos.sub(i.position)),this._raycaster.ray.intersectPlane(this.plane,this._intersection),this._intersection}addMovement(e,t){e*=.75,t*=.75,e/=this._scale,t/=this._scale,this.offset.elements[12]-=e,this.offset.elements[14]-=t}addScale(e){e/=window.innerWidth,this._scale*=1+e,this._tempMatrix.makeScale(1-e,1-e,1-e),this.offset.premultiply(this._tempMatrix)}addRotation(e){this._tempMatrix.makeRotationY(e),this.offset.premultiply(this._tempMatrix)}};let $d=Hb;h($d,"up",new w(0,1,0)),h($d,"zero",new w(0,0,0)),h($d,"one",new w(1,1,1));const fne=re("debugrig");class Ix extends Ie{awake(){if(fne){const e=new Te;e.position.y+=.5,this.gameObject.add(e);const t=e.addNewComponent(Qu);t&&(t.isGizmo=!1)}}}class Mf{constructor(){h(this,"bb",null);h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,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(e,t,i,s,r){return e.prep(4,16),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(i),e.writeFloat32(t),e.offset()}}class Ms{constructor(){h(this,"bb",null);h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsVrUserStateBuffer(e,t){return(t||new Ms).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsVrUserStateBuffer(e,t){return e.setPosition(e.position()+L_),(t||new Ms).__init(e.readInt32(e.position())+e.position(),e)}guid(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}time(){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):this.bb.createLong(0,0)}avatarId(e){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__string(this.bb_pos+t,e):null}position(e){const t=this.bb.__offset(this.bb_pos,10);return t?(e||new Zr).__init(this.bb_pos+t,this.bb):null}rotation(e){const t=this.bb.__offset(this.bb_pos,12);return t?(e||new Mf).__init(this.bb_pos+t,this.bb):null}scale(){const e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readFloat32(this.bb_pos+e):0}posLeftHand(e){const t=this.bb.__offset(this.bb_pos,16);return t?(e||new Zr).__init(this.bb_pos+t,this.bb):null}posRightHand(e){const t=this.bb.__offset(this.bb_pos,18);return t?(e||new Zr).__init(this.bb_pos+t,this.bb):null}rotLeftHand(e){const t=this.bb.__offset(this.bb_pos,20);return t?(e||new Mf).__init(this.bb_pos+t,this.bb):null}rotRightHand(e){const t=this.bb.__offset(this.bb_pos,22);return t?(e||new Mf).__init(this.bb_pos+t,this.bb):null}static startVrUserStateBuffer(e){e.startObject(10)}static addGuid(e,t){e.addFieldOffset(0,t,0)}static addTime(e,t){e.addFieldInt64(1,t,e.createLong(0,0))}static addAvatarId(e,t){e.addFieldOffset(2,t,0)}static addPosition(e,t){e.addFieldStruct(3,t,0)}static addRotation(e,t){e.addFieldStruct(4,t,0)}static addScale(e,t){e.addFieldFloat32(5,t,0)}static addPosLeftHand(e,t){e.addFieldStruct(6,t,0)}static addPosRightHand(e,t){e.addFieldStruct(7,t,0)}static addRotLeftHand(e,t){e.addFieldStruct(8,t,0)}static addRotRightHand(e,t){e.addFieldStruct(9,t,0)}static endVrUserStateBuffer(e){return e.endObject()}static finishVrUserStateBufferBuffer(e,t){e.finish(t)}static finishSizePrefixedVrUserStateBufferBuffer(e,t){e.finish(t,void 0,!0)}}const wO=re("debugxr"),hg=re("debugavatar"),EI="VRUS";F_(EI,Ms.getRootAsVrUserStateBuffer);function pM(){return new Date().getTime()}function pne(n){const e=n&4294967295,t=n/Math.pow(2,32)&1048575;return Ga.create(e,t)}const Am=class{constructor(e){h(this,"guid");h(this,"time");h(this,"avatarId");h(this,"position",new w);h(this,"rotation",new et);h(this,"scale",1);h(this,"posLeftHand",new w);h(this,"posRightHand",new w);h(this,"rotLeftHand",new we);h(this,"rotRightHand",new we);this.guid=e}update(e,t,i,s,r){var u,d,f,p,g,A;this.time=pM(),this.avatarId=r,this.position.set(t.x,t.y,t.z),e&&this.position.applyMatrix4(e.matrixWorld);let o=Am.quat0;const a=Am.quat1;o.set(i.x,i.y,i.z,i.w),o=o.multiplyQuaternions(o,Am.invertRotation),e&&(e.getWorldQuaternion(a),o.multiplyQuaternions(a,o)),this.rotation.set(o.x,o.y,o.z,o.w),this.scale=e.scale.x;const c=(u=s.LeftController)==null?void 0:u.controllerGrip;c&&(c.getWorldPosition(this.posLeftHand),c.getWorldQuaternion(this.rotLeftHand));const l=(d=s.RightController)==null?void 0:d.controllerGrip;if(l&&(l.getWorldPosition(this.posRightHand),l.getWorldQuaternion(this.rotRightHand)),(p=(f=s.LeftController)==null?void 0:f.hand)!=null&&p.visible){const v=s.LeftController.wrist;v&&(v.getWorldPosition(this.posLeftHand),v.getWorldQuaternion(this.rotLeftHand))}if((A=(g=s.RightController)==null?void 0:g.hand)!=null&&A.visible){const v=s.RightController.wrist;v&&(v.getWorldPosition(this.posRightHand),v.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(e,t){e.clear();const i=e.createString(this.guid),s=e.createString(this.avatarId);Ms.startVrUserStateBuffer(e),Ms.addGuid(e,i),Ms.addTime(e,pne(this.time)),Ms.addAvatarId(e,s),Ms.addPosition(e,Zr.createVec3(e,this.position.x,this.position.y,this.position.z)),Ms.addRotation(e,Mf.createVec4(e,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),Ms.addScale(e,this.scale),Ms.addPosLeftHand(e,Zr.createVec3(e,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),Ms.addPosRightHand(e,Zr.createVec3(e,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),Ms.addRotLeftHand(e,Mf.createVec4(e,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),Ms.addRotRightHand(e,Mf.createVec4(e,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const r=Ms.endVrUserStateBuffer(e);e.finish(r,EI);const o=e.asUint8Array();t.sendBinary(o)}setFromBuffer(e,t){if(!e)return;this.guid=e,this.time=t.time().toFloat64();const i=t.avatarId();i&&(this.avatarId=i);const s=t.position();s&&this.position.set(s.x(),s.y(),s.z());const r=t.rotation();r&&this.rotation.set(r.x(),r.y(),r.z(),r.w());const o=t.posLeftHand();o&&this.posLeftHand.set(o.x(),o.y(),o.z());const a=t.posRightHand();a&&this.posRightHand.set(a.x(),a.y(),a.z());const c=t.rotLeftHand();c&&this.rotLeftHand.set(c.x(),c.y(),c.z(),c.w());const l=t.rotRightHand();l&&this.rotRightHand.set(l.x(),l.y(),l.z(),l.w()),this.scale=t.scale()}};let ta=Am;h(ta,"invertRotation",new we().setFromAxisAngle(new w(0,1,0),Math.PI)),h(ta,"quat0",new we),h(ta,"quat1",new we);class tA extends Ie{constructor(){super(...arguments);h(this,"webXR",null);h(this,"debugAvatarUser",null);h(this,"voip",null);h(this,"tempState",new ta(""));h(this,"_removeAvatarsList",[]);h(this,"eventSub_ConnectionEvent",null);h(this,"eventSub_WebXRStartEvent",null);h(this,"eventSub_WebXREndEvent",null);h(this,"eventSub_WebXRUpdateEvent",null);h(this,"avatars",{});h(this,"localAvatar",null);h(this,"k_LocalAvatarNoNetworkingGuid","local");h(this,"ownership",null);h(this,"xrState",null);h(this,"builder",new ip(1024))}async awake(){if(this.webXR||(this.webXR=ne.getComponent(this.gameObject,It)),this.webXR||(this.webXR=ne.findObjectOfType(It,this.context)),!this.webXR&&(this.webXR=ne.findObjectOfType(It,this.context),!this.webXR)){console.warn("WebXRSync: Could not find WebXR component, won't sync.");return}if(this.voip||(this.voip=ne.findObjectOfType(dl,this.context)),hg){const t="debug-avatar-"+hg,i=new Ua(this.context,t,this.webXR);if(this.debugAvatarUser=i,typeof hg=="string"&&hg.length>0)if(await i.setAvatarOverride(hg)){const s=new ta(t);s.position.y+=1;const r=.5;s.posLeftHand.y+=r,s.posLeftHand.x+=r,s.posRightHand.y+=r,s.posRightHand.x-=r,i.tryUpdate(s,0)}else i.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=ne.getComponent(this.gameObject,It),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),It.addEventListener(Mi.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),It.addEventListener(Mi.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),It.addEventListener(Mi.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen(on.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",t=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",t=>{const i=t.id!==null&&t.id!==void 0;if(i&&(console.log("webxr user left evt"),i)){const s=this.avatars[t.id];s==null||s.destroy(),this.avatars[t.id]=void 0}}),this.context.connection.beginListenBinary(EI,t=>{const i=t.guid();if(!i)return;const s=t.time().toFloat64(),r=this.tempState;r.setFromBuffer(i,t);const o=this.onTryGetAvatar(i,s);o==null||o.tryUpdate(r,s)}),this.context.connection.beginListen("vr-session-update",t=>{const i=t.guid,s=t.time,r=this.onTryGetAvatar(i,s);r==null||r.tryUpdate(t,s)})}onTryGetAvatar(t,i){if(t===this.context.connection.connectionId)return null;const s=new Date().getTime()-i;if(s>5e3)return wO&&console.log("old data",s,t),null;if(!this.webXR)return null;let r=this.avatars[t];if(r===void 0)try{console.log("create new avatar");const o=new Ua(this.context,t,this.webXR);r=o,this.avatars[t]=o}catch(o){this.avatars[t]=null,console.error(o)}return r}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen(on.JoinedRoom,this.eventSub_ConnectionEvent),It.removeEventListener(Mi.XRStarted,this.eventSub_WebXRStartEvent),It.removeEventListener(Mi.XRUpdate,this.eventSub_WebXRUpdateEvent),It.removeEventListener(Mi.XRStopped,this.eventSub_WebXREndEvent)}update(){const t=pM();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=t),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const i in this.avatars){const s=this.avatars[i];s&&s.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const t=pM();for(const i in this.avatars){const s=this.avatars[i];if(!s){this._removeAvatarsList.push(i);continue}t-s.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),s.destroy(),this.avatars[i]=void 0)}for(const i of this._removeAvatarsList)delete this.avatars[i];this._removeAvatarsList.length=0}buildLocalAvatar(){var i;if(this.localAvatar)return;const t=((i=this.context.connection)==null?void 0:i.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new Ua(this.context,t,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var t,i,s;wO&&console.log("Hey you are connected as "+this.context.connection.connectionId),((t=this.localAvatar)==null?void 0:t.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null)}onXRSessionStart(t){var i,s,r;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null,this.avatars)for(const o in this.avatars)(r=this.avatars[o])==null||r.updateFlags()}onXRSessionEnded(t){var i;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(t){this.xrState??(this.xrState=new ta(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new N_(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:i,xr:s,rig:r}=t,o=i.getViewerPose(s.getReferenceSpace());if(!o)return;const a=o==null?void 0:o.transform,c=a.position,l=a.orientation;this.xrState.update(r,c,l,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 re("avatar")??null}}var gne=Object.defineProperty,mne=Object.getOwnPropertyDescriptor,Tp=(n,e,t,i)=>{for(var s=i>1?void 0:i?mne(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&gne(e,t,s),s};const jS=re("debugwebxr");async function jz(){return tb()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function Xz(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let Og=!1,kg=!1;jz().then(n=>Og=n);Xz().then(n=>kg=n);var Mi=(n=>(n.XRStarted="xrStarted",n.XRStopped="xrStopped",n.XRUpdate="xrUpdate",n.RequestVRSession="requestVRSession",n.ModifyAROptions="modify-ar-options",n))(Mi||{}),Wd;const kn=(Wd=class extends Ie{constructor(){super(...arguments);h(this,"enableVR",!0);h(this,"enableAR",!0);h(this,"defaultAvatar");h(this,"handModelPath","");h(this,"createVRButton",!0);h(this,"createARButton",!0);h(this,"controllers",[]);h(this,"rig");h(this,"isInit",!1);h(this,"_requestedAR",!1);h(this,"_requestedVR",!1);h(this,"_isInAR",!1);h(this,"_isInVR",!1);h(this,"_arButton");h(this,"_vrButton");h(this,"webAR",null);h(this,"_transformOrientation",new we);h(this,"_currentHeadPose",null);h(this,"_originalCameraParent",null);h(this,"_originalCameraPosition",new w);h(this,"_originalCameraRotation",new we);h(this,"_originalXRRigParent",null);h(this,"_originalXRRigPosition",new w);h(this,"_originalXRRigRotation",new we);h(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(Og||kg)}static get IsARSupported(){return Og}static get IsVRSupported(){return kg}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(e,t){return this.events.addEventListener(e,t),t}static removeEventListener(e,t){return this.events.removeEventListener(e,t),t}static dispatchEvent(e,t){this.events.dispatchEvent({type:e,detail:t})}static createVRButton(e,t){kn.XRSupported?e.__internalAwake():console.warn("WebXR is not supported on this device");const i={optionalFeatures:kn.OptionalFeatures_VR},s=rm.createButton(e.context.renderer,i);return s.classList.add("webxr-ar-button"),s.classList.add("webxr-button"),this.resetButtonStyles(s),((t==null?void 0:t.registerClick)??!0)&&s.addEventListener("click",e.onClickedVRButton.bind(e)),s}static createARButton(e,t){var o;e.__internalAwake();const i=(o=e.webAR)==null?void 0:o.getAROverlayContainer(),s={optionalFeatures:[...this.OptionalFeatures_AR]};i?(s.domOverlay={root:i},s.optionalFeatures.push("dom-overlay"),s.optionalFeatures.push("hit-test"),s.optionalFeatures.push("anchors")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const r=lne.createButton(e.context.renderer,s,this.onModifyAROptions.bind(this));return r.classList.add("webxr-ar-button"),r.classList.add("webxr-button"),kn.resetButtonStyles(r),((t==null?void 0:t.registerClick)??!0)&&r.addEventListener("click",e.onClickedARButton.bind(e)),r}static onModifyAROptions(e){kn.dispatchEvent("modify-ar-options",e)}static resetButtonStyles(e){e&&(e.style.position="",e.style.bottom="",e.style.left="")}endSession(){const e=this.context.renderer.xr.getSession();e&&e.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var e,t;return this.controllers.length>0&&((e=this.controllers[0].input)==null?void 0:e.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((t=this.controllers[1].input)==null?void 0:t.handedness)==="left"?this.controllers[1]:null}get RightController(){var e,t;return this.controllers.length>0&&((e=this.controllers[0].input)==null?void 0:e.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((t=this.controllers[1].input)==null?void 0:t.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=Tn.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!ne.findObjectOfType(tA,this.context)){const e=ne.addNewComponent(this.gameObject,tA,!1);e.webXR=this}this.webAR=new Su(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(Ls("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,kn.XRSupported;let e,t;const i=document.createElement("div");i.classList.add("webxr-buttons"),i.style.cssText=`
|
|
5181
|
+
`,a={map:{value:e},height:{value:t.height||15},radius:{value:t.radius||100}},c=new vA(1,16),l=new Lt({uniforms:a,fragmentShader:o,vertexShader:r,side:wi});super(c,l)}set radius(e){this.material.uniforms.radius.value=e}get radius(){return this.material.uniforms.radius.value}set height(e){this.material.uniforms.height.value=e}get height(){return this.material.uniforms.height.value}}var Nte=Object.defineProperty,zte=Object.getOwnPropertyDescriptor,cr=(n,e,t,i)=>{for(var s=i>1?void 0:i?zte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Nte(e,t,s),s};const By=re("freecam"),cg=re("debugcamerafit"),Dy=re("smoothcam"),Gte={LEFT:"",UP:"",RIGHT:"",BOTTOM:""};let HS;class Ji extends Ie{constructor(){super(...arguments);h(this,"enableRotate",!0);h(this,"autoRotate",!1);h(this,"autoRotateSpeed",1);h(this,"autoFit",!1);h(this,"enableKeys",!0);h(this,"enableDamping",!0);h(this,"dampingFactor",.1);h(this,"enableZoom",!0);h(this,"minZoom",0);h(this,"maxZoom",1/0);h(this,"enablePan",!0);h(this,"lookAtConstraint",null);h(this,"lookAtConstraint01",1);h(this,"middleClickToFocus",!0);h(this,"doubleClickToFocus",!0);h(this,"useSlerp",!0);h(this,"debugLog",!1);h(this,"targetLerpSpeed",5);h(this,"autoTarget",!0);h(this,"_lookTargetPosition");h(this,"_controls",null);h(this,"_cameraObject",null);h(this,"_lerpToTargetPosition",!1);h(this,"_lerpCameraToTarget",!1);h(this,"_cameraTargetPosition",null);h(this,"_inputs",0);h(this,"_enableTime",0);h(this,"_startedListeningToKeyEvents",!1);h(this,"_eventSystem");h(this,"_afterHandleInputFn");h(this,"_camera",null);h(this,"_syncedTransform");h(this,"_didStart",!1);h(this,"targetElement",null);h(this,"onControlsChangeStarted",()=>{this._syncedTransform&&this._syncedTransform.requestOwnership()});h(this,"_shouldDisable",!1);h(this,"_haveAttachedKeyboardEvents",!1)}get isCameraController(){return!0}get controls(){return this._controls}get controllerObject(){return this._cameraObject}onStartInteraction(t){var i;(i=this.controls)==null||i.addEventListener("start",t)}awake(){this._didStart=!1,this._lookTargetPosition=new w,this._startedListeningToKeyEvents=!1}start(){if(this._didStart=!0,this.autoTarget&&this._controls){const t=ne.getComponent(this.gameObject,Li);if(t&&!this.setFromTargetPosition()){this.debugLog&&console.log("NO TARGET");const s=Ct(t.cam).length(),r=new w(0,0,-s).applyMatrix4(t.cam.matrixWorld);this.setTarget(r,!0)}if(this.autoTarget&&!this.setFromTargetPosition()){const i=new ko;i.screenPoint=new te(0,0),i.lineThreshold=.1;const s=this.context.physics.raycast(i);s.length>0&&this.setTarget(s[0].point,!0),cg&&console.log("OrbitControls hits",...s)}this.autoFit&&this.fitCamera()}this._eventSystem=$s.get(this.context)??void 0,this._eventSystem&&(this._afterHandleInputFn=this.afterHandleInput.bind(this),this._eventSystem.addEventListener(uM.AfterHandleInput,this._afterHandleInputFn))}onDestroy(){var t,i;(t=this._controls)==null||t.dispose(),(i=this._eventSystem)==null||i.removeEventListener(uM.AfterHandleInput,this._afterHandleInputFn)}onEnable(){this._enableTime=this.context.time.time;const t=ne.getComponent(this.gameObject,Li);this._camera=t;const i=t==null?void 0:t.cam;if(i&&AO(i,this,!0),!this._controls){if(!i){console.warn("OrbitControls: Requires a Camera component on the same object as this component.");return}i&&(this._cameraObject=i);const s=this.targetElement??this.context.domElement,r=i==null?void 0:i.quaternion.clone();this._controls=new JK(i,s),i==null||i.quaternion.copy(r),HS===void 0&&(HS={...this._controls.keys})}this._controls&&(By&&(this.enablePan=!0,this.enableZoom=!0,this.middleClickToFocus=!0,cl()&&(this.doubleClickToFocus=!0)),this._controls.addEventListener("start",this.onControlsChangeStarted),(i==null?void 0:i.type)==="PerspectiveCamera"?By||(this._controls.minDistance=this.minZoom,this._controls.maxDistance=this.maxZoom):By||(this._controls.minZoom=this.minZoom,this._controls.maxZoom=this.maxZoom),this._startedListeningToKeyEvents||(this._startedListeningToKeyEvents=!0,this._controls.listenToKeyEvents(window.document.body))),this._syncedTransform=ne.getComponent(this.gameObject,ah)??void 0}onDisable(){var t;(t=this._camera)!=null&&t.cam&&AO(this._camera.cam,this,!1),this._controls&&(this._controls.enabled=!1,this._controls.autoRotate=!1,this._controls.removeEventListener("start",this.onControlsChangeStarted))}afterHandleInput(t){t.detail.args.pointerId===0&&(t.detail.args.isDown?this._controls&&this._eventSystem&&(this._shouldDisable=this._eventSystem.hasActiveUI):(!t.detail.args.isPressed||t.detail.args.isUp)&&(this._shouldDisable=!1))}onBeforeRender(){var i,s,r;if(!this._controls||this._cameraObject!==this.context.mainCamera)return;(this.context.input.getPointerDown(0)||this.context.input.getPointerDown(1)||this.context.input.getPointerDown(2))&&(this._inputs+=1),this._inputs>0&&(this.enableRotate&&(this.autoRotate=!1),this._lerpCameraToTarget=!1,this._lerpToTargetPosition=!1),this._inputs=0;let t=this.middleClickToFocus&&this.context.input.getPointerClicked(1);if(t||(t=this.doubleClickToFocus&&this.context.input.getPointerDoubleClicked(0)&&this.context.time.time-this._enableTime>.3),t?this.setTargetFromRaycast():(this.context.input.getPointerDown(0)||this.context.input.mouseWheelChanged)&&(this._lerpToTargetPosition=!1,this._lerpCameraToTarget=!1),this._lerpToTargetPosition||this._lerpCameraToTarget){const o=this.context.time.deltaTime*this.targetLerpSpeed;if(this._lerpCameraToTarget&&this._cameraTargetPosition&&this._cameraObject){if(this.useSlerp){const a=(i=this._cameraObject)==null?void 0:i.position;$2(a,this._cameraTargetPosition,o)}else(s=this._cameraObject)==null||s.position.lerp(this._cameraTargetPosition,o);this._cameraObject.position.distanceTo(this._cameraTargetPosition)<1e-4&&(this._lerpCameraToTarget=!1)}this._lerpToTargetPosition&&(this.lerpTarget(this._lookTargetPosition,o),this._lookTargetPosition.distanceTo(this._controls.target)<1e-5&&(this._lerpToTargetPosition=!1))}if(!By&&((r=this.lookAtConstraint)!=null&&r.locked)&&this.setFromTargetPosition(0,this.lookAtConstraint01),this._controls){if(this.debugLog&&(this._controls.domElement=this.context.renderer.domElement),this._controls.enabled=!this._shouldDisable&&this._camera===this.context.mainCameraComponent&&!this.context.isInXR,this._controls.keys=this.enableKeys?HS:Gte,this._controls.autoRotate=this.autoRotate,this._controls.autoRotateSpeed=this.autoRotateSpeed,this._controls.enableZoom=this.enableZoom,this._controls.enableDamping=this.enableDamping,this._controls.dampingFactor=this.dampingFactor,this._controls.enablePan=this.enablePan,this._controls.enableRotate=this.enableRotate,typeof Dy=="number"||Dy===!0){this._controls.enableDamping=!0;const o=typeof Dy=="number"?Dy:.99;this._controls.dampingFactor=Math.max(.001,1-Math.min(1,o))}this.context.isInXR||this._controls.update()}}setCameraTarget(t,i=!1){return this.setCameraTargetPosition(t,i)}setCameraTargetPosition(t,i=!1){var s;t?(this._lerpCameraToTarget=!0,this._cameraTargetPosition=t.clone(),i&&this._cameraTargetPosition&&((s=this.controllerObject)==null||s.position.copy(this._cameraTargetPosition))):this._lerpCameraToTarget=!1}setFromTargetPosition(t=0,i=1){var r;if(!this._controls)return!1;const s=(r=this.lookAtConstraint)==null?void 0:r.sources;if(s&&s.length>0){const o=s[t];if(o)return o.getWorldPosition(this._lookTargetPosition),this.lerpTarget(this._lookTargetPosition,i),!0}return!1}setTarget(t=null,i=!1){this._controls&&(t!==null&&this._lookTargetPosition.copy(t),i?this._controls.target.copy(this._lookTargetPosition):this._lerpToTargetPosition=!0)}lerpTarget(t,i){this._controls&&this._controls.target.lerp(t,i)}distanceToTarget(t){return this._controls?this._controls.target.distanceTo(t):-1}setTargetFromRaycast(){var i,s;if(!this.controls)return;const t=this.context.physics.raycast();for(const r of t)if(r.distance>0&&ne.isActiveInHierarchy(r.object)){const o=yx(r.object);if(o){const a=o.canvas;if(a!=null&&a.screenspace)break}if(this._lookTargetPosition.copy(r.point),this._lerpToTargetPosition=!0,this._cameraTargetPosition=null,this.context.mainCamera){this._lerpCameraToTarget=!0;const a=Ct(this.context.mainCamera);this._cameraTargetPosition=a.clone().sub(this.controls.target).add(this._lookTargetPosition),(s=(i=this._cameraObject)==null?void 0:i.parent)==null||s.worldToLocal(this._cameraTargetPosition)}break}}fitCamera(t,i=1.1,s=!0){const r=this._cameraObject,o=this._controls;if(t!=null&&t.length||(t=this.context.scene.children),t.length<=0||!r||!o)return;const a=new w,c=new w,l=new Un;l.makeEmpty();const u=[];function d(y){let _=!0;if(y.visible&&(y instanceof uE&&(_=!1),y instanceof F1&&(_=!1),y instanceof Lz&&(_=!1),y.material instanceof __&&(_=!1),y instanceof ye||(_=!1),y!==r&&y.isUI!==!0)){if(_){cg&&console.log(y.name,y.type,y);const C=y.children;y.children=u,l.expandByObject(y,!0),y.children=C}for(const C of y.children)d(C)}}for(const y of t)y.updateMatrixWorld(),d(y);if(r.updateMatrixWorld(),r.updateProjectionMatrix(),l.getCenter(c),l.applyMatrix4(r.matrixWorldInverse),l.getSize(a),l.setFromCenterAndSize(c,a),a.length()<=1e-10){cg&&console.warn("Camera fit size is zero",l,[...t]);return}const f=r.fov,p=2*Math.atan(Math.tan(f*Math.PI/360/2)*r.aspect)/Math.PI*360,g=a.y/(2*Math.atan(Math.PI*f/360)),A=a.x/(2*Math.atan(Math.PI*p/360)),v=i*Math.max(g,A)+a.z/2;cg&&console.log("Fit camera to objects",g,A,"distance",v);const m=Ct(r),b=o.target.clone().sub(m).normalize().multiplyScalar(v);if(o.maxDistance=v*10,o.minDistance=v*.01,this.setTarget(c,s),this.autoTarget=!1,r.near=v/100,r.far=v*100,r.updateMatrixWorld(),r.updateProjectionMatrix(),r.parent){const y=r.parent.worldToLocal(o.target.clone().sub(b));this.setCameraTarget(y,s)}else console.error(`Can not fit camera ${r.name} because it has no parent`);if(cg){const y=new uE(l);this.context.scene.add(y),nF(y,O_(r)),this._haveAttachedKeyboardEvents||(this._haveAttachedKeyboardEvents=!0,document.body.addEventListener("keydown",_=>{_.code==="KeyF"&&this.fitCamera(t)}))}o.update()}}cr([x()],Ji.prototype,"enableRotate",2);cr([x()],Ji.prototype,"autoRotate",2);cr([x()],Ji.prototype,"autoRotateSpeed",2);cr([x()],Ji.prototype,"autoFit",2);cr([x()],Ji.prototype,"enableKeys",2);cr([x()],Ji.prototype,"enableDamping",2);cr([x()],Ji.prototype,"dampingFactor",2);cr([x()],Ji.prototype,"enableZoom",2);cr([x()],Ji.prototype,"minZoom",2);cr([x()],Ji.prototype,"maxZoom",2);cr([x()],Ji.prototype,"enablePan",2);cr([x(LA)],Ji.prototype,"lookAtConstraint",2);cr([x()],Ji.prototype,"lookAtConstraint01",2);cr([x()],Ji.prototype,"middleClickToFocus",2);cr([x()],Ji.prototype,"doubleClickToFocus",2);var Hte=Object.defineProperty,Vte=Object.getOwnPropertyDescriptor,to=(n,e,t,i)=>{for(var s=i>1?void 0:i?Vte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Hte(e,t,s),s},Ib=(n=>(n[n.Skybox=1]="Skybox",n[n.SolidColor=2]="SolidColor",n[n.Uninitialized=4]="Uninitialized",n))(Ib||{});const ru=re("debugcam"),yO=re("debugscreenpointtoray");var t0;const Bg=(t0=class extends Ie{constructor(){super(...arguments);h(this,"_nearClipPlane",.1);h(this,"_farClipPlane",1e3);h(this,"orthographic",!1);h(this,"orthographicSize",5);h(this,"ARBackgroundAlpha",0);h(this,"_cullingMask",4294967295);h(this,"_backgroundBlurriness");h(this,"_backgroundIntensity");h(this,"_environmentIntensity");h(this,"_targetTexture",null);h(this,"_backgroundColor");h(this,"_fov");h(this,"_cam",null);h(this,"_clearFlags",2);h(this,"_skybox")}get isCamera(){return!0}get aspect(){return this._cam instanceof qt?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._cam instanceof qt?this._cam.fov:this._fov}set fieldOfView(e){const t=this.fieldOfView!=e;if(this._fov=e,t&&this._cam&&this._cam instanceof qt){if(this._fov===void 0){console.warn("Can not set undefined fov on PerspectiveCamera");return}this._cam.fov=this._fov,this._cam.updateProjectionMatrix()}}get nearClipPlane(){return this._nearClipPlane}set nearClipPlane(e){const t=this._nearClipPlane!=e;this._nearClipPlane=e,this._cam&&t&&(this._cam.near=e,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(e){const t=this._farClipPlane!=e;this._farClipPlane=e,this._cam&&t&&(this._cam.far=e,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(e){e!==this._clearFlags&&(this._clearFlags=e,this.applyClearFlagsIfIsActiveCamera())}set cullingMask(e){this._cullingMask=e,this._cam&&(this._cam.layers.mask=e)}get cullingMask(){return this._cam?this._cam.layers.mask:this._cullingMask}set backgroundBlurriness(e){e!==this._backgroundBlurriness&&(e===void 0?this._backgroundBlurriness=void 0:this._backgroundBlurriness=Math.min(Math.max(e,0),1),this.applyClearFlagsIfIsActiveCamera())}get backgroundBlurriness(){return this._backgroundBlurriness}set backgroundIntensity(e){e!==this._backgroundIntensity&&(e===void 0?this._backgroundIntensity=void 0:this._backgroundIntensity=Math.min(Math.max(e,0),10),this.applyClearFlagsIfIsActiveCamera())}get backgroundIntensity(){return this._backgroundIntensity}set environmentIntensity(e){this._environmentIntensity=e}get environmentIntensity(){return this._environmentIntensity}get backgroundColor(){return this._backgroundColor??null}set backgroundColor(e){if(e){if(this._backgroundColor)this._backgroundColor.copy(e);else{if(!e.clone)return;this._backgroundColor=e.clone()}e.alpha===void 0&&(this._backgroundColor.alpha=1),this.applyClearFlagsIfIsActiveCamera()}}set targetTexture(e){this._targetTexture=e}get targetTexture(){return this._targetTexture}get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}screenPointToRay(e,t,i){const s=this.cam,r=Bg._origin;r.set(e,t,-1),this.context.input.convertScreenspaceToRaycastSpace(r),yO&&console.log("screenPointToRay",e.toFixed(2),t.toFixed(2),"now:",r.x.toFixed(2),r.y.toFixed(2),"isInXR:"+this.context.isInXR),r.z=-1,r.unproject(s);const o=Bg._direction.set(r.x,r.y,r.z),a=Ct(s);return o.sub(a),o.normalize(),i?(i.set(a,o),i):new Ya(a.clone(),o.clone())}awake(){yO&&window.addEventListener("pointerdown",e=>{const t=e.clientX,i=e.clientY;console.log("touch",t.toFixed(2),i.toFixed(2));const s=this.screenPointToRay(t,i),r="#"+Math.floor(Math.random()*16777215).toString(16);zc.DrawRay(s.origin,s.direction,r,10)})}onEnable(){ru&&console.log(`Camera enabled: "${this.name}". ClearFlags=${Ib[this._clearFlags]}`,this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&(this.context.setCurrentCamera(this),Wte(this)),this.applyClearFlagsIfIsActiveCamera()}onDisable(){this.context.removeCamera(this)}onBeforeRender(){if(this._cam&&this._targetTexture){this.context.isManagedExternally&&(this._warnedAboutExternalRenderer||(this._warnedAboutExternalRenderer=!0,console.warn("Rendering with external renderer is not supported yet. This may not work or throw errors. Please remove the the target texture from your camera: "+this.name,this.targetTexture))),this.context.composer;const e=this.context.renderer;if(e){const t=this.context.mainCameraComponent;this.applyClearFlags(),this._targetTexture.render(this.context.scene,this._cam,e),t==null||t.applyClearFlags()}}}buildCamera(){if(this._cam)return;const e=this.gameObject.isCamera;let t=null;if(e?(t=this.gameObject,t==null||t.layers.enableAll(),t instanceof qt&&(this._fov=t.fov)):t=this.gameObject.children[0],t&&t.isCamera)t instanceof qt&&(this._fov&&(t.fov=this._fov),t.near=this._nearClipPlane,t.far=this._farClipPlane,t.updateProjectionMatrix());else if(!this.orthographic)t=new qt(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),this.fieldOfView&&(t.fov=this.fieldOfView),this.gameObject.add(t);else{const i=this.orthographicSize*100;t=new Du(window.innerWidth/-i,window.innerWidth/i,window.innerHeight/i,window.innerHeight/-i,this._nearClipPlane,this._farClipPlane),this.gameObject.add(t)}this._cam=t,this._cam.layers.mask=this._cullingMask,this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){this.context.mainCameraComponent===this&&this.applyClearFlags()}applyClearFlags(){if(!this._cam){ru&&console.log("Camera does not exist (apply clear flags)");return}if(this.fieldOfView=this._fov,ru){const e=`Camera "${this.name}" clear flags: ${Ib[this._clearFlags]}`;console.log(e)}switch(this._clearFlags){case 1:if(Bg.backgroundShouldBeTransparent(this.context)&&(!this.ARBackgroundAlpha||this.ARBackgroundAlpha<.001)){this.context.scene.background=null,this.context.renderer.setClearColor(0,0);return}this.enableSkybox(),this._backgroundBlurriness!==void 0&&(this.context.scene.backgroundBlurriness=this._backgroundBlurriness),this._backgroundIntensity!==void 0&&(this.context.scene.backgroundIntensity=this._backgroundIntensity);break;case 2:if(this._backgroundColor){let e=this._backgroundColor.alpha;Bg.backgroundShouldBeTransparent(this.context)&&(e=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,e)}else ru&&console.warn(`Camera "${this.name}" has no background color`,this);break;case 4:this.context.scene.background=null,this.context.renderer.setClearColor(0,0);break}}enableSkybox(){this._skybox||(this._skybox=new Qte(this)),this._skybox.enable()}static backgroundShouldBeTransparent(e){var r,o,a,c;const t=(r=e.renderer.xr)==null?void 0:r.getSession();if(!t)return!1;const i=t.environmentBlendMode;ru&&pn("Environment blend mode: "+i+" on "+navigator.userAgent);const s=i==="additive"||i==="alpha-blend";if(e.xrSessionMode===zm.ImmersiveAR&&i==="opaque"){if((o=navigator.userAgent)!=null&&o.includes("OculusBrowser"))return!0;if((a=navigator.userAgent)!=null&&a.includes("Mozilla")&&((c=navigator.userAgent)!=null&&c.includes("Mobile WebXRViewer/v2")))return!0}return s}},h(t0,"_origin",new w),h(t0,"_direction",new w),t0);let Li=Bg;to([x()],Li.prototype,"fieldOfView",1);to([x()],Li.prototype,"nearClipPlane",1);to([x()],Li.prototype,"farClipPlane",1);to([x()],Li.prototype,"clearFlags",1);to([x()],Li.prototype,"orthographic",2);to([x()],Li.prototype,"orthographicSize",2);to([x()],Li.prototype,"ARBackgroundAlpha",2);to([x()],Li.prototype,"cullingMask",1);to([x()],Li.prototype,"backgroundBlurriness",1);to([x()],Li.prototype,"backgroundIntensity",1);to([x()],Li.prototype,"environmentIntensity",1);to([x(bi)],Li.prototype,"backgroundColor",1);to([x(Jl)],Li.prototype,"targetTexture",1);class Qte{constructor(e){h(this,"_camera");h(this,"_skybox");this._camera=e}get context(){var e;return(e=this._camera)==null?void 0:e.context}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?this.context.scene.background!==this._skybox&&(ru&&console.log(`Camera "${this._camera.name}" set skybox`,this._camera,this._skybox),this._skybox.colorSpace=Ze,this._skybox.mapping=Ro,this.context.scene.background=this._skybox):(console.warn(`Camera "${this._camera.name}" failed to load/find skybox texture`,this._camera.sourceId,this.context.lightmaps,"Current background: ",this.context.scene.background),(ru||ci())&&Ls(`Camera "${this._camera.name}" has no skybox texture`))}}function Wte(n){re("freecam")&&n.context.mainCameraComponent===n&&ne.getOrAddComponent(n.gameObject,Ji)}class xu extends Ie{constructor(){super(...arguments);h(this,"_listener",null)}get listener(){return this._listener==null&&(this._listener=new O1),this._listener}awake(){yn.registerWaitForAllowAudio(()=>{if(this.destroyed)return;const t=this.listener;if(t==null||t.parent)return;const i=this.context.mainCameraComponent||ne.getComponentInParent(this.gameObject,Li);i!=null&&i.cam?i.cam.add(t):this.gameObject.add(t)})}}var jte=Object.defineProperty,Xte=Object.getOwnPropertyDescriptor,bx=(n,e,t,i)=>{for(var s=i>1?void 0:i?Xte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&jte(e,t,s),s};const qte=re("debugsignals");class VA{constructor(){h(this,"guid")}}bx([x()],VA.prototype,"guid",2);class Ap{constructor(){h(this,"signal");h(this,"reaction")}}bx([x(VA)],Ap.prototype,"signal",2);bx([x(us)],Ap.prototype,"reaction",2);var xC;const bc=(xC=class extends Ie{constructor(){super(...arguments);h(this,"events")}static invoke(e){if(bc.receivers[e]){const t=bc.receivers[e];if(!t)return;for(const i of t)i.invoke(e)}}awake(){qte&&console.log("SignalReceiver awake",this)}onEnable(){if(this.events)for(const e of this.events)bc.receivers[e.signal.guid]||(bc.receivers[e.signal.guid]=[]),bc.receivers[e.signal.guid].push(this)}onDisable(){if(this.events){for(const e of this.events)if(bc.receivers[e.signal.guid]){const t=bc.receivers[e.signal.guid].indexOf(this);t>=0&&bc.receivers[e.signal.guid].splice(t,1)}}}invoke(e){if(!this.events||!Array.isArray(this.events))return;const t=typeof e=="object"?e.guid:e;for(const i of this.events)if(i.signal.guid===t)try{if(i.reaction){if(!i.reaction.invoke){console.warn("Missing invoke - possibly a serialization error",i,this);continue}}else{console.warn("Missing reaction for signal",i,this);continue}i.reaction.invoke()}catch(s){console.error(s)}}},h(xC,"receivers",{}),xC);let vp=bc;bx([x(Ap)],vp.prototype,"events",2);var Lr=(n=>(n.Activation="ActivationTrack",n.Animation="AnimationTrack",n.Audio="AudioTrack",n.Control="ControlTrack",n.Marker="MarkerTrack",n.Signal="SignalTrack",n))(Lr||{}),Sa=(n=>(n[n.None=0]="None",n[n.Hold=1]="Hold",n[n.Loop=2]="Loop",n[n.PingPong=3]="PingPong",n[n.Continue=4]="Continue",n))(Sa||{}),lI=(n=>(n.Signal="SignalEmitter",n))(lI||{});const Fd=re("debugtimeline"),zb=class extends Ie{constructor(){super(...arguments);h(this,"playableAsset");h(this,"playOnAwake");h(this,"extrapolationMode",1);h(this,"waitForAudio",!0);h(this,"_visibilityChangeEvt");h(this,"_clonedPlayableAsset",!1);h(this,"_speed",1);h(this,"_guidsMap");h(this,"_isPlaying",!1);h(this,"_internalUpdateRoutine");h(this,"_isPaused",!1);h(this,"_isStopping",!1);h(this,"_time",0);h(this,"_duration",0);h(this,"_weight",1);h(this,"_animationTracks",[]);h(this,"_audioTracks",[]);h(this,"_signalTracks",[]);h(this,"_controlTracks",[]);h(this,"_customTracks",[]);h(this,"_allTracks",[this._animationTracks,this._audioTracks,this._signalTracks,this._controlTracks,this._customTracks]);h(this,"animationCallbackReceivers",[])}static registerCreateTrack(t,i){this.createTrackFunctions[t]=i}get isPlaying(){return this._isPlaying}get isPaused(){return this._isPaused}get time(){return this._time}set time(t){typeof t=="number"&&!Number.isNaN(t)?this._time=t:(Fd||nr())&&console.error("INVALID TIMELINE.TIME VALUE",t,this.name)}get duration(){return this._duration}set duration(t){this._duration=t}get weight(){return this._weight}set weight(t){this._weight=t}get speed(){return this._speed}set speed(t){this._speed=t}awake(){var t,i,s;Fd&&console.log(this,(t=this.playableAsset)==null?void 0:t.tracks),this.rebuildGraph(),this.isValid()||console.warn("PlayableDirector is not valid",this.playableAsset,(i=this.playableAsset)==null?void 0:i.tracks,Array.isArray((s=this.playableAsset)==null?void 0:s.tracks),this)}onEnable(){var t,i,s;for(const r of this._audioTracks)(t=r.onEnable)==null||t.call(r);for(const r of this._customTracks)(i=r.onEnable)==null||i.call(r);for(const r of this._animationTracks)(s=r.onEnable)==null||s.call(r);this.playOnAwake&&this.play(),this._visibilityChangeEvt||(this._visibilityChangeEvt=()=>{switch(document.visibilityState){case"hidden":this.setAudioTracksAllowPlaying(!1);break;case"visible":this.setAudioTracksAllowPlaying(!0);break}}),window.addEventListener("visibilitychange",this._visibilityChangeEvt)}onDisable(){var t,i,s;this.stop();for(const r of this._audioTracks)(t=r.onDisable)==null||t.call(r);for(const r of this._customTracks)(i=r.onDisable)==null||i.call(r);for(const r of this._animationTracks)(s=r.onDisable)==null||s.call(r);this._visibilityChangeEvt&&window.removeEventListener("visibilitychange",this._visibilityChangeEvt)}onDestroy(){var t;for(const i of this._allTracks)for(const s of i)(t=s.onDestroy)==null||t.call(s)}rebuildGraph(){this.isValid()&&(this.resolveBindings(),this.updateTimelineDuration(),this.setupAndCreateTrackHandlers())}async play(){if(!this.isValid())return;const t=this._isPaused==!0;if(this._isPaused=!1,t&&this.invokePauseChangedMethodsOnTracks(),!this._isPlaying){if(this._isPlaying=!0,this.waitForAudio){const i=[];for(const s of this._audioTracks){const r=s.loadAudio(this._time,1,0);r&&i.push(r)}if(i.length>0&&(await Promise.all(i),!this._isPlaying))return;for(;this._audioTracks.length>0&&this._isPlaying&&!yn.userInteractionRegistered&&this.waitForAudio;)await _A(200)}this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine=this.startCoroutine(this.internalUpdate(),Tr.OnBeforeRender)}}pause(){this.isValid()&&(this._isPlaying=!1,!this._isPaused&&(this._isPaused=!0,this.evaluate(),this.invokePauseChangedMethodsOnTracks(),this.invokeStateChangedMethodsOnTracks()))}stop(){this._isStopping=!0;for(const s of this._audioTracks)s.stop();const t=this._isPaused==!0,i=this._isPlaying;this._isPlaying&&(this._time=0,this._isPlaying=!1,this._isPaused=!1,this.evaluate(),t&&this.invokePauseChangedMethodsOnTracks()),this._isPlaying=!1,this._isPaused=!1,t&&!i&&this.invokePauseChangedMethodsOnTracks(),i&&this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine&&this.stopCoroutine(this._internalUpdateRoutine),this._internalUpdateRoutine=null,this._isStopping=!1}evaluate(){if(!this.isValid())return;let t=this._time;switch(this.extrapolationMode){case 0:this._speed>0?t=Math.min(t,this._duration):this._speed<0&&(t=Math.max(t,0)),this._time=t;break;case 1:t%=this._duration,this._time=t;break;case 2:if(t>this._duration){this.stop();return}break}this.internalEvaluate(t)}isValid(){return this.playableAsset&&this.playableAsset.tracks&&Array.isArray(this.playableAsset.tracks)}*forEachTrack(){for(const t of this._allTracks)for(const i of t)yield i}get audioTracks(){return this._audioTracks}resolveGuids(t){this._guidsMap=t}invokePauseChangedMethodsOnTracks(){var t;for(const i of this.forEachTrack())(t=i.onPauseChanged)==null||t.call(i)}invokeStateChangedMethodsOnTracks(){var t;for(const i of this.forEachTrack())(t=i.onStateChanged)==null||t.call(i,this._isPlaying)}*internalUpdate(){for(;this._isPlaying&&this.activeAndEnabled;)!this._isPaused&&this._isPlaying&&(this._time+=this.context.time.deltaTime*this.speed,this.evaluate()),yield}internalEvaluate(t){for(const i of this.playableAsset.tracks)if(!i.muted)switch(i.type){case Lr.Activation:if(!this._isPlaying)continue;for(let s=0;s<i.outputs.length;s++){const r=i.outputs[s];if(typeof r=="object"){let o=!1;if(i.clips)for(const c of i.clips)c.start<=t&&t<=c.end&&(o=!0);const a=r;a.visible!==void 0&&a.visible!==o&&(a.visible=o,Fd&&console.warn(this.name,"set ActivationTrack-"+s,a.name,o,t))}}break}if(!this._isStopping)for(const i of this._animationTracks)i.evaluate(t);for(const i of this._audioTracks)i.evaluate(t);for(const i of this._signalTracks)i.evaluate(t);for(const i of this._controlTracks)i.evaluate(t);for(const i of this._customTracks)i.evaluate(t)}resolveBindings(){if(this._clonedPlayableAsset||(this._clonedPlayableAsset=!0,this.playableAsset=B_(this.playableAsset)),!this.playableAsset||!this.playableAsset.tracks)return;const t=this.findRoot(this.gameObject);for(const i of this.playableAsset.tracks){for(let s=i.outputs.length-1;s>=0;s--){let r=i.outputs[s];if(typeof r=="string"){this._guidsMap&&this._guidsMap[r]&&(r=this._guidsMap[r]);const o=ne.findByGuid(r,t);o===null||typeof o!="object"?(i.outputs.splice(s,1),console.warn("Failed to resolve binding",r,i.name,i.type)):(Fd&&console.log("Resolved binding",r,"to",o),i.outputs[s]=o)}else if(r===null){if(i.outputs.splice(s,1),zb.createTrackFunctions[i.type])continue;i.type!==Lr.Audio&&i.type!==Lr.Control&&i.type!==Lr.Marker&&i.type!==Lr.Signal&&console.warn("Missing binding",r,i.name,i.type,this.name,this.playableAsset.name)}}if(i.type===Lr.Control&&i.clips)for(let s=0;s<i.clips.length;s++){const r=i.clips[s];let o=r.asset.sourceObject;if(typeof o=="string"){this._guidsMap&&this._guidsMap[o]&&(o=this._guidsMap[o]);const a=ne.findByGuid(o,t);a===null||typeof a!="object"?console.warn("Failed to resolve sourceObject binding",o,i.name,r):(Fd&&console.log("Resolved binding",o,"to",a),r.asset.sourceObject=a)}}}}findRoot(t){return t.parent?this.findRoot(t.parent):t}updateTimelineDuration(){if(this._duration=0,!(!this.playableAsset||!this.playableAsset.tracks)){for(const t of this.playableAsset.tracks)if(t.muted!==!0){if(t.clips)for(const i of t.clips)i.end>this._duration&&(this._duration=i.end);if(t.markers)for(const i of t.markers)i.time>this._duration&&(this._duration=i.time+.001)}}}setupAndCreateTrackHandlers(){var i,s;if(this._animationTracks.length=0,this._audioTracks.length=0,this._signalTracks.length=0,!this.playableAsset)return;const t=ne.findObjectOfType(xu,this.context);for(const r of this.playableAsset.tracks){const o=r.type,a=zb.createTrackFunctions[o];if(a!=null){const c=a(this,r);if(typeof c.evaluate=="function"){c.director=this,c.track=r,this._customTracks.push(c);continue}}if(r.type===Lr.Animation){if(!r.clips||r.clips.length<=0){Fd&&console.warn("Animation track has no clips",r);continue}for(let c=r.outputs.length-1;c>=0;c--){let l=r.outputs[c];if(l instanceof Te){const d=ne.getOrAddComponent(l,ks);d&&(l=d)}const u=(i=l==null?void 0:l.gameObject)==null?void 0:i.animations;if(u){const d=new _x;d.trackOffset=r.trackOffset,d.director=this,d.track=r;for(let f=0;f<r.clips.length;f++){const p=r.clips[f],g=p.asset;if(!g){console.error("MISSING anim model?","clip#"+f,p,r,this.playableAsset,this.name);continue}const A=g.clip;let v=A;if((typeof v=="string"||typeof v=="number")&&(v=u.find(b=>b.name===A)),!v){console.warn("Could not find animationClip for model",p,r.name,this.name,(s=this.playableAsset)==null?void 0:s.name);continue}l instanceof ks&&l.runtimeAnimatorController&&(l.__internalDidAwakeAndStart||l.initializeRuntimeAnimatorController(),l.runtimeAnimatorController.mixer||l.runtimeAnimatorController.bind(l),d.mixer=l.runtimeAnimatorController.mixer),d.mixer||(d.mixer=new R_(l.gameObject)),d.clips.push(v),d.mixer.uncacheAction(v),d.createHooks(p.asset,v);const m=d.mixer.clipAction(v);d.actions.push(m),d.models.push(p)}this._animationTracks.push(d)}}}else if(r.type===Lr.Audio){if(!r.clips||r.clips.length<=0)continue;const c=new wu;if(c.director=this,c.track=r,this._audioTracks.push(c),!t)continue;c.listener=t.listener;for(let l=0;l<r.clips.length;l++){const u=r.clips[l];c.addModel(u)}}else if(r.type===Lr.Marker){const c=new Zm;if(c.director=this,c.track=r,r.markers)for(const l of r.markers)switch(l.type){case lI.Signal:c.models.push(l),c.didTrigger.push(!1);break}if(c!==null&&c.models.length>0){const l=ne.getComponent(this.gameObject,vp);l&&(c.receivers.push(l),this._signalTracks.push(c))}}else if(r.type===Lr.Signal){const c=new Zm;if(c.director=this,c.track=r,r.markers)for(const l of r.markers)c.models.push(l),c.didTrigger.push(!1);for(const l of r.outputs)c.receivers.push(l);this._signalTracks.push(c)}else if(r.type===Lr.Control){const c=new xx;if(c.director=this,c.track=r,r.clips)for(const l of r.clips)c.models.push(l);c.resolveSourceObjects(this.context),this._controlTracks.push(c)}}}setAudioTracksAllowPlaying(t){for(const i of this._audioTracks)i.onAllowAudioChanged(t)}registerAnimationCallback(t){this.animationCallbackReceivers.push(t)}unregisterAnimationCallback(t){const i=this.animationCallbackReceivers.indexOf(t);i!==-1&&this.animationCallbackReceivers.splice(i,1)}};let Zc=zb;h(Zc,"createTrackFunctions",{});const Hc=re("debugtimeline");class QA{constructor(){h(this,"director");h(this,"track")}get muted(){return this.track.muted}set muted(e){var t;e!==this.track.muted&&(this.track.muted=e,(t=this.onMuteChanged)==null||t.call(this))}*forEachClip(e=!1){var t;if((t=this.track)!=null&&t.clips)if(e)for(let i=this.track.clips.length-1;i>=0;i--)yield this.track.clips[i];else for(const i of this.track.clips)yield i}getClipTime(e,t){return t.clipIn+(e-t.start)*t.timeScale}getClipTimeNormalized(e,t){return(e-t.start)/t.duration}evaluateWeight(e,t,i,s=!0){if(t<0||t>=i.length)return 0;const r=i[t];if(s||e>=r.start&&e<=r.end){let o=1;const a=!1;if(r.easeInDuration>0){const c=Math.min((e-r.start)/r.easeInDuration,1);o*=c}if(r.easeOutDuration>0&&!a){const c=Math.min((r.end-e)/r.easeOutDuration,1);o*=c}return o}return 0}}class Yte{constructor(e){h(this,"clip");h(this,"rootPositionOffset");h(this,"rootQuaternionOffset");h(this,"rootStartPosition");h(this,"rootEndPosition");h(this,"rootStartQuaternion");h(this,"rootEndQuaternion");const t=e.getClip();this.clip=t;const i=e.getRoot(),s=i.name+".position",r=i.name+".quaternion";Hc&&console.log(t.name,t.tracks,s);for(const o of t.tracks)if(!(o.times.length<=0)){if(o.name.endsWith(s))this.rootStartPosition=new w().fromArray(o.values,0),this.rootEndPosition=new w().fromArray(o.values,o.values.length-3),this.rootPositionOffset=this.rootEndPosition.clone().sub(this.rootStartPosition),Hc&&console.log(this.rootPositionOffset);else if(o.name.endsWith(r)&&(this.rootStartQuaternion=new we().fromArray(o.values,0),this.rootEndQuaternion=new we().fromArray(o.values,o.values.length-4),this.rootQuaternionOffset=this.rootEndQuaternion.clone().multiply(this.rootStartQuaternion),Hc)){const a=new mn().setFromQuaternion(this.rootQuaternionOffset);console.log("ROT",a)}}}get hasOffsets(){return this.rootPositionOffset!==void 0||this.rootQuaternionOffset!==void 0}}class _x extends QA{constructor(){super(...arguments);h(this,"models",[]);h(this,"trackOffset");h(this,"target");h(this,"mixer");h(this,"clips",[]);h(this,"actions",[]);h(this,"_actionOffsets",[]);h(this,"_didBind",!1);h(this,"_animator",null);h(this,"_useclipOffsets",!0);h(this,"_totalOffsetPosition",new w);h(this,"_totalOffsetRotation",new we);h(this,"_totalOffsetPosition2",new w);h(this,"_totalOffsetRotation2",new we);h(this,"_summedPos",new w);h(this,"_tempPos",new w);h(this,"_summedRot",new we);h(this,"_tempRot",new we);h(this,"_clipRotQuat",new we)}onStateChanged(){this._animator&&KD(this._animator.gameObject,this,this.director.isPlaying)}createHooks(t,i){var u,d;if(((u=i.tracks)==null?void 0:u.length)<=0){console.warn("No tracks in AnimationClip",i);return}const s=i.tracks[0].name.split("."),r=s[s.length-2],o=r+".position",a=r+".quaternion";let c=!1,l=!1;for(const f of i.tracks)f.name.endsWith(o)?(c=!0,this.createPositionInterpolant(i,t,f)):f.name.endsWith(a)&&(l=!0,this.createRotationInterpolant(i,t,f));if(!c||!l){const f=(d=this.mixer)==null?void 0:d.getRoot(),p=i.tracks[0],g=p.name.lastIndexOf("."),A=p.name.substring(0,g),v=A.substring(A.lastIndexOf(".")+1),m=f.getObjectByName(v);if(m)if(c){if(!l){const b=i.tracks[0].name.substring(0,g)+".quaternion";Hc&&console.warn("Create quaternion track",v,m);const y=m.quaternion,_=new ja(b,[0,i.duration],[y.x,y.y,y.z,y.w,y.x,y.y,y.z,y.w]);i.tracks.push(_),this.createRotationInterpolant(i,t,_)}}else{const b=A+".position";Hc&&console.warn("Create position track",v,m);const y=m.position,_=new el(b,[0,i.duration],[y.x,y.y,y.z,y.x,y.y,y.z]);i.tracks.push(_),this.createPositionInterpolant(i,t,_)}}}bind(){if(!this._didBind){this._didBind=!0,Hc&&console.log(this.models),this.mixer?this.target=this.mixer.getRoot():console.warn("No mixer was assigned to animation track");for(const t of this.actions){const i=new Yte(t);this._actionOffsets.push(i)}this.target&&(this._animator=ne.getComponent(this.target,ks)??null,this._animator&&KD(this._animator.gameObject,this,!0));for(const t of this.models){const i=t.asset,s=i.position,r=i.rotation;s&&s.x!==void 0&&(s.isVector3||(i.position=new w(s.x,s.y,s.z)),r.isQuaternion||(i.rotation=new we(r.x,r.y,r.z,r.w)))}this.ensureTrackOffsets()}}ensureTrackOffsets(){if(this.trackOffset){const t=this.trackOffset.position;t&&(t.isVector3||(this.trackOffset.position=new w(t.x,t.y,t.z)));const i=this.trackOffset.rotation;i&&(i.isQuaternion||(this.trackOffset.rotation=new we(i.x,i.y,i.z,i.w)))}}evaluate(t){var c,l,u,d,f,p,g;if(this.track.muted||!this.mixer)return;this.bind(),this._totalOffsetPosition.set(0,0,0),this._totalOffsetRotation.set(0,0,0,1),this._totalOffsetPosition2.set(0,0,0),this._totalOffsetRotation2.set(0,0,0,1);let i=0,s=0,r=!1,o=!1,a=0;for(let A=0;A<this.clips.length;A++){const v=this.models[A],m=this.actions[A],b=v.asset;m.weight=0;const y=t>=v.start&&t<=v.end,_=v.preExtrapolationMode,C=v.postExtrapolationMode,M=A<this.clips.length-1?this.models[A+1]:null;let I=y,R=!1;if(!I&&!r&&v.end<t&&C!==Sa.None?(!M||M.start>t)&&(I=!0,r=!0):A==0&&!I&&!o&&v.start>t&&_!==Sa.None&&(!M||M.start<t)&&(I=!0,R=!0,o=!0),I){let E=1;E*=this.evaluateWeight(t,A,this.models,I),E*=this.director.weight;let T=y;if(R)switch(_){case Sa.Hold:break;case Sa.Loop:t+=v.start,T=!0;break;default:t+=v.start,T=!0;break}let D=this.getClipTime(t,v),K=0;const H=b.duration;if(R&&_===Sa.Hold&&(D=0),T){if(b.loop)for(K+=Math.floor(D/(H+1e-6));D>H;)D-=H}else if(!y&&r)switch(C){case Sa.Hold:D=this.getClipTime(v.end,v);break;case Sa.Loop:D%=H;break;case Sa.PingPong:const N=Math.floor(D/H)%2!==0;D%=H,N&&(D=H-D);break}v.reversed===!0?m.time=m.getClip().duration-D:m.time=D,m.timeScale=0;const V=Math.max(0,E);if(m.weight=V,a+=V,m.clampWhenFinished=!1,m.isRunning()||m.play(),this._useclipOffsets){const Y=i==0?this._totalOffsetPosition:this._totalOffsetPosition2,N=i==0?this._totalOffsetRotation:this._totalOffsetRotation2;i<1&&(s=1-E),i+=1;const L=this._summedPos.set(0,0,0),G=this._tempPos.set(0,0,0),ee=this._summedRot.identity(),$=this._tempRot.identity(),j=b.rotation;j&&(this._clipRotQuat.identity(),this._clipRotQuat.slerp(j,E));const ie=this._actionOffsets[A];if(ie.hasOffsets)for(let Ae=0;Ae<K;Ae++)ie.rootPositionOffset?G.copy(ie.rootPositionOffset):G.set(0,0,0),G.applyQuaternion(ee),this._clipRotQuat&&G.applyQuaternion(this._clipRotQuat),ie.rootQuaternionOffset&&($.copy(ie.rootQuaternionOffset),ee.multiply($)),L.add(G);this._clipRotQuat&&N.multiply(this._clipRotQuat),N.multiply(ee),b.position&&L.add(b.position),Y.add(L)}}}if(this._useclipOffsets&&(this._totalOffsetPosition.lerp(this._totalOffsetPosition2,s),this._totalOffsetRotation.slerp(this._totalOffsetRotation2,s)),this.__mixerError===void 0&&(Hc||ci())&&((l=(c=this._animator)==null?void 0:c.runtimeAnimatorController)!=null&&l.mixer)&&this.mixer!==((d=(u=this._animator)==null?void 0:u.runtimeAnimatorController)==null?void 0:d.mixer)&&(this.__mixerError=!0,console.error("AnimationTrack mixer is not shared with the animator controller - this might result in the timeline to not animate properly. Please report a bug to the Needle Engine team!",this)),(f=this._animator)!=null&&f.runtimeAnimatorController){const A=Math.max(0,1-a);(g=(p=this._animator)==null?void 0:p.runtimeAnimatorController)==null||g.update(A)}else this.mixer.update(t)}createRotationInterpolant(t,i,s){var c;const r=s.createInterpolant.bind(s),o=new we;this.ensureTrackOffsets();const a=(c=this.trackOffset)==null?void 0:c.rotation;s.createInterpolant=()=>{const l=r(),u=l.evaluate.bind(l);return l.evaluate=d=>{var p;const f=u(d);if(o.set(f[0],f[1],f[2],f[3]),o.premultiply(this._totalOffsetRotation),a&&o.premultiply(a),this.director.animationCallbackReceivers)for(const g of this.director.animationCallbackReceivers)(p=g==null?void 0:g.onTimelineRotation)==null||p.call(g,this.director,this.target,d,o);return f[0]=o.x,f[1]=o.y,f[2]=o.z,f[3]=o.w,f},l}}createPositionInterpolant(t,i,s){var u,d;const r=s.createInterpolant.bind(s),o=new w;this.ensureTrackOffsets();const a=(u=this.trackOffset)==null?void 0:u.rotation,c=(d=this.trackOffset)==null?void 0:d.position;let l;s.createInterpolant=()=>{const f=r(),p=f.evaluate.bind(f);return f.evaluate=g=>{var v,m,b;const A=p(g);if(o.set(A[0],A[1],A[2]),i.removeStartOffset&&(l===void 0?(l=null,l=(m=(v=this._actionOffsets.find(y=>y.clip===t))==null?void 0:v.rootStartPosition)==null?void 0:m.clone()):l!=null&&l.isVector3&&o.sub(l)),o.applyQuaternion(this._totalOffsetRotation),o.add(this._totalOffsetPosition),a&&o.applyQuaternion(a),c&&(o.x-=c.x,o.y+=c.y,o.z+=c.z),this.director.animationCallbackReceivers)for(const y of this.director.animationCallbackReceivers)(b=y==null?void 0:y.onTimelinePosition)==null||b.call(y,this.director,this.target,g,o);return A[0]=o.x,A[1]=o.y,A[2]=o.z,A},f}}}const Kte=re("mutetimeline"),gf=class extends QA{constructor(){super(...arguments);h(this,"models",[]);h(this,"listener");h(this,"audio",[]);h(this,"audioContextTimeOffset",[]);h(this,"lastTime",0);h(this,"_audioLoader",null)}getAudioFilePath(t){const i=this.director.sourceId;return al(i,t)}onAllowAudioChanged(t){for(let i=0;i<this.models.length;i++){const s=this.models[i];this.audio[i].setVolume(t?s.asset.volume:0)}}addModel(t){const i=new I_(this.listener);this.audio.push(i),this.models.push(t)}onDisable(){for(const t of this.audio)t.isPlaying&&t.stop()}onDestroy(){for(const t of this.audio)t.source&&(t==null||t.disconnect());this.audio.length=0}onMuteChanged(){if(this.muted)for(let t=0;t<this.audio.length;t++){const i=this.audio[t];i!=null&&i.isPlaying&&i.stop()}}stop(){for(let t=0;t<this.audio.length;t++){const i=this.audio[t];i!=null&&i.isPlaying&&i.stop()}}evaluate(t){if(Kte||this.track.muted||this.director.speed<0)return;const i=this.director.context.application.muted,s=i?.1:0;for(let r=0;r<this.models.length;r++){const o=this.models[r],a=this.audio[r];if((!a||!a.buffer)&&this.isInTimeRange(o,t-1,t+1)&&this.handleAudioLoading(o,a),yn.userInteractionRegistered!==!1&&!(a===null||!a.buffer))if(a.playbackRate=this.director.context.time.timeScale,a.loop=o.asset.loop,t>=o.start&&t<=o.end&&t<this.director.duration){if(this.director.isPlaying==!1){if(a.isPlaying&&a.stop(),this.lastTime===t)continue}else if(!a.isPlaying)a.offset=o.clipIn+(t-o.start)*o.timeScale,a.play(s);else{const l=o.clipIn+(t-o.start)*o.timeScale,u=a.context.currentTime-a._startedAt+a.offset;Math.abs(l-u)>.3&&(a.offset=l,a.stop(),a.play(s))}let c=o.asset.volume;if(i&&(c=0),o.easeInDuration>0){const l=Math.min((t-o.start)/o.easeInDuration,1);c*=l}if(o.easeOutDuration>0){const l=Math.min((o.end-t)/o.easeOutDuration,1);c*=l}a.setVolume(c*this.director.weight)}else a.isPlaying&&a.stop()}this.lastTime=t}loadAudio(t,i=0,s=0){let r=null;const o=t-s,a=t+i;for(const c of this.models)if(this.isInTimeRange(c,o,a)){const l=this.audio[this.models.indexOf(c)],u=this.handleAudioLoading(c,l);u!==null&&(r===null&&(r=[]),r.push(u))}return r!==null?Promise.all(r):null}isInTimeRange(t,i,s){return i<=t.start&&s>=t.end||i>=t.start&&i<=t.end||s>=t.start&&s<=t.end}static dispose(){gf._audioBuffers.clear()}handleAudioLoading(t,i){this._audioLoader||(this._audioLoader=new $0);const s=this.getAudioFilePath(t.asset.clip);if(gf._audioBuffers.get(s)){const o=gf._audioBuffers.get(s);return o.then(a=>{a&&i.setBuffer(a)}),o}Hc&&console.warn("LOAD audio track",s,this.director.sourceId);const r=new Promise((o,a)=>{this._audioLoader.load(s,c=>{i.setBuffer(c),o(c)},void 0,c=>{console.error("Error loading audio",c),o(null)})});return gf._audioBuffers.set(s,r),r}};let wu=gf;h(wu,"_audioBuffers",new Map);class Zm extends QA{constructor(){super(...arguments);h(this,"models",[]);h(this,"didTrigger",[]);h(this,"receivers",[])}evaluate(t){var s;if(this.track.muted)return;const i=this.director.context.time.deltaTime*1.5;for(let r=0;r<this.models.length;r++){const o=this.models[r],a=this.didTrigger[r],c=o.time-t;let l=!1;if(o.retroActive)l=c<=1e-6;else{const u=Math.abs(c);(u===0||u>=1e-5&&u<i)&&(l=!0)}if(l){if(!a)if(Hc&&console.log("Trigger signal",t,o.time,o),this.didTrigger[r]=!0,((s=this.receivers)==null?void 0:s.length)<=0)vp.invoke(o.asset);else for(const u of this.receivers)u&&u.invoke(o.asset)}else o.emitOnce||(this.didTrigger[r]=!1)}}}class xx extends QA{constructor(){super(...arguments);h(this,"models",[]);h(this,"timelines",[]);h(this,"_previousActiveModel",null)}resolveSourceObjects(t){for(let i=this.models.length-1;i>=0;i--){const r=this.models[i].asset;if(!r.sourceObject||typeof r.sourceObject!="object"){console.log("no source object, removing model",i,r),this.models.splice(i,1);continue}else{const o=ne.getComponent(r.sourceObject,Zc);this.timelines.push(o),o&&r.updateDirector&&(o.playOnAwake=!1)}}}evaluate(t){var i;this._previousActiveModel=null;for(let s=0;s<this.models.length;s++){const r=this.models[s],o=r.asset;if(t>=r.start&&t<=r.end){this._previousActiveModel=r;const a=this.getClipTime(t,r);if(o.controlActivation){const c=o.sourceObject;c.visible=!0}if(o.updateDirector){const c=this.timelines[s];c&&(c.isPlaying&&c.pause(),c.time=a,c.evaluate())}}else{const a=(i=this._previousActiveModel)==null?void 0:i.asset;if(o.controlActivation){const c=o.sourceObject;(a==null?void 0:a.sourceObject)!==c&&(c.visible=!1)}}}}}var Jte=Object.defineProperty,Zte=Object.getOwnPropertyDescriptor,Fz=(n,e,t,i)=>{for(var s=i>1?void 0:i?Zte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Jte(e,t,s),s};class Rt{constructor(e){h(this,"_active",!0);h(this,"_value");h(this,"_valueRaw");h(this,"_defaultValue");h(this,"valueProcessor");h(this,"onValueChanged");this._value=e,this._defaultValue=e,this._valueRaw=e}get overrideState(){return this._active}set overrideState(e){if(this._active===e)return;this._active=e;const t=e?this._valueRaw:this._defaultValue;this.processValue(t,!0)}get value(){return this._valueRaw}set value(e){this.processValue(e,!1)}set defaultValue(e){this._defaultValue=e}__init(){this.processValue(this._valueRaw,!0)}processValue(e,t){if(e==null||!t&&this.testIfValueChanged(e)===!1)return;const i=this._value;!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,e=this._defaultValue,this._valueRaw=e):(this._valueRaw=e,this._active&&this.valueProcessor&&(e=this.valueProcessor(e)),this._value=e),this.onValueChanged&&this.onValueChanged(e,i,this)}testIfValueChanged(e){return this._valueRaw!==e}}Fz([x()],Rt.prototype,"overrideState",1);Fz([x()],Rt.prototype,"value",1);var $te=Object.defineProperty,eie=Object.getOwnPropertyDescriptor,tie=(n,e,t,i)=>{for(var s=i>1?void 0:i?eie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&$te(e,t,s),s};const iie=re("debugpost");class Us extends Ah{constructor(t=void 0){super();h(this,"active",!0);h(this,"_result");h(this,"_didCreateVolumeParameters",!1);if(t){this.ensureVolumeParameters();for(const i of Object.keys(t)){const s=t[i],r=this[i];r instanceof Rt&&(r.value=s)}}}onEnable(){this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){this.active=!1}init(){}apply(){var t;return this.ensureVolumeParameters(),this._result||(this._result=(t=this.onCreateEffect)==null?void 0:t.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){iie&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(t=>t.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const t=Object.keys(this);for(const i of t){const s=this[i];s instanceof Rt&&s.__init()}}onAfterDeserialize(t,i){if(typeof t=="object"){const s=this.$serializedTypes;if(s){for(const r of Object.keys(s))if(s[r]===Rt){const a=t[r];if(a!==void 0){const c=this[r];c.value=a}}}}}onEditorModification(t){const i=t.propertyName;if(this[i]instanceof Rt){const s=t.value;return this[i].value=s,!0}}ensureVolumeParameters(){if(this._didCreateVolumeParameters)return;this._didCreateVolumeParameters=!0;const t=this.$serializedTypes;if(t)for(const i of Object.keys(t))t[i]===Rt&&(this[i]||(this[i]=new Rt))}}tie([x()],Us.prototype,"active",2);var nie=Object.defineProperty,sie=Object.getOwnPropertyDescriptor,rie=(n,e,t,i)=>{for(var s=i>1?void 0:i?sie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&nie(e,t,s),s};const oie=re("debugpost"),dM={};function No(n,e){dM[n]=e}function aie(n){return n.__type in dM?dM[n.__type]:(oie&&n.__type&&console.warn("Unknown postprocessing type",n.__type,n),Us)}class WA{constructor(){h(this,"components",[])}init(){var e;(e=this.components)==null||e.forEach(t=>t.init())}}rie([lp([n=>aie(n),Us])],WA.prototype,"components",2);var cie=Object.defineProperty,lie=Object.getOwnPropertyDescriptor,hie=(n,e,t,i)=>{for(var s=i>1?void 0:i?lie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&cie(e,t,s),s};class jA extends Us{constructor(){super(...arguments);h(this,"preset")}get typeName(){return"Antialiasing"}onCreateEffect(){const t=new Iq({preset:Xd.HIGH,edgeDetectionMode:oT.DEPTH});return this.preset.onValueChanged=i=>{t.applyPreset(i)},t}}hie([x(Rt)],jA.prototype,"preset",2);No("Antialiasing",jA);class wx{constructor(){h(this,"files",[])}get extensionName(){return"Audio"}onExportObject(e,t,i){const s=ne.getComponents(e,yn);if(s.length)for(const r of s){if(!r.clip||!r.playOnAwake)continue;const o=r.clip.split("/").pop();this.files.includes(r.clip)||this.files.push(r.clip),t.addEventListener("serialize",(a,c)=>{a.appendLine(),a.beginBlock(`def SpatialAudio "${t.name}"`),a.appendLine(`uniform asset filePath = @audio/${o}@`),a.appendLine(`uniform token auralMode = "${r.spatialBlend>0?"spatial":"nonSpatial"}"`),a.appendLine(`uniform token playbackMode = "${r.loop?"loopFromStage":"onceFromStart"}"`),a.appendLine(`uniform float gain = ${r.volume}`),a.closeBlock()})}}async onAfterSerialize(e){for(const t of this.files){const i=t.split("/").pop(),o=await(await(await fetch(t)).blob()).arrayBuffer(),a=new Uint8Array(o);e.files["audio/"+i]=a}}}const Rb="noVoip",vr=re("debugvoip"),uie=re("voip");class die{constructor(e){h(this,"id");this.id=e}}class fie{constructor(e,t,i,s){h(this,"peer");h(this,"voip");h(this,"userId");h(this,"peerId");h(this,"call",null);h(this,"callErrorListener",null);h(this,"stream",null);this.voip=e,this.peer=t,this.userId=i,this.peerId=s}close(){var e;vr&&console.log("close voip call"),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.open&&this.call.close(),(e=this.stream)==null||e.getTracks().forEach(function(t){t.stop()})}updateMute(e){var i;if(!this.stream)return;const t=(i=this.stream)==null?void 0:i.getAudioTracks();for(const s of t)s.enabled=!e}async startVoipCall(){if(!await dl.HasMicrophonePermissions()){console.warn("no permission to use microphone, can not start call");return}vr&&console.log("start voip call");try{this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}catch(t){console.error(t);return}this.updateMute(this.voip.muteOutput),vr&&console.log(this.stream),this.call=this.peer.call(this.peerId,this.stream,{metadata:{userId:this.userId}}),this.call.on("error",t=>{console.error(t)}),this.call.on("stream",t=>{vr&&console.log("received stream from remote again",t)}),this.peer.on("close",this.onCallClose.bind(this)),this.callErrorListener=t=>{var i;t.message.includes(this.peerId)?(console.log("Could not connect to "+this.peerId),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.close(),(i=this.stream)==null||i.getTracks().forEach(function(s){s.stop()}),this.stream=null):console.error(t)},this.peer.on("error",this.callErrorListener)}onCallClose(e){vr&&console.log("call closed",e)}}class pie{constructor(e,t,i){h(this,"voip");h(this,"call");h(this,"audio",null);h(this,"stream",null);h(this,"obj");h(this,"analyzer",null);h(this,"waitingForStart",!1);h(this,"closed",!1);h(this,"audioElement",null);this.voip=e,this.obj=t,this.call=i}get currentStream(){return this.stream}get currentAudio(){return this.audio}get currentAnalyzer(){return this.analyzer}openAudioStream(e){const t=e.getAudioTracks();for(const i of t)if(i.kind==="audio"&&i.readyState==="live"){this.open(i);return}console.warn("failed finding valid audio stream to begin call")}open(e){console.assert(e.kind==="audio","invalid track kind, expected audio but received "+e.kind),!this.waitingForStart&&(this.waitingForStart=!0,yn.userInteractionRegistered||vr&&console.log("Incoming call, waiting for user interaction before opening audio"),yn.registerWaitForAllowAudio(async()=>{if(this.call.open&&!this.closed){vr&&console.log("Setup audio and begin listening"),this.stream=new MediaStream([e]);const t=new O1;this.audio=new I_(t),this.audio.setVolume(this.voip.muteInput?0:1),this.audio.setMediaStreamSource(this.stream);const i=document.createElement("audio");this.audioElement=i,i.style.display="none",document.body.appendChild(i),i.srcObject=this.stream,i.sinkId!==void 0&&navigator.mediaDevices.enumerateDevices().then(s=>{if(i){console.log(s);for(const r of s)if(r.label==="Speakerphone"){i.sinkId=r.deviceId;break}}}),vr&&console.log("call is setup, you should hear something now"),this.analyzer=new E2(this.audio,32)}}))}close(){var e,t,i;this.closed=!0,(e=this.call)!=null&&e.open&&this.call.close(),(t=this.audio)==null||t.disconnect(),(i=this.stream)==null||i.getTracks().forEach(s=>{s.stop()}),this.stream=null,this.audioElement&&this.audioElement.remove()}}class dl extends Ie{constructor(){super(...arguments);h(this,"requireParam",!1);h(this,"peer",null);h(this,"model",null);h(this,"connections",{});h(this,"currentIncomingCalls",{});h(this,"_inputMuted",!1);h(this,"_outputMuted",!1)}set muteInput(t){var s;if(t===this._inputMuted||(this._inputMuted=t,!this.currentIncomingCalls))return;const i=this._inputMuted?0:1;for(const r in this.currentIncomingCalls){const o=this.currentIncomingCalls[r];(s=o==null?void 0:o.currentAudio)==null||s.setVolume(i)}}get muteInput(){return this._inputMuted}set muteOutput(t){if(t!==this._outputMuted&&(this._outputMuted=t,!!this.connections))for(const i in this.connections){const s=this.connections[i];s==null||s.updateMute(t)}}get muteOutput(){return this._outputMuted}getFrequency(t){if(t===null){for(const s in this.currentIncomingCalls){const r=this.currentIncomingCalls[s];if(r&&r.currentAnalyzer)return r.currentAnalyzer.getAverageFrequency()}return null}const i=this.currentIncomingCalls[t];return i&&i.currentAnalyzer?i.currentAnalyzer.getAverageFrequency():null}awake(){if(re(Rb)){console.log("VOIP is disabled by url parameter: "+Rb);return}if(this.requireParam&&!uie){console.debug("VOIP must be enabled explicitly by url parameter");return}if(Dm()&&Rc()){console.log("VOIP is currently not supported on Safari iOS");return}this.peer=Y1(),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,this.context.connection.beginListen(on.JoinedRoom,t=>{navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).catch(i=>{console.error("Error initializing VoIP connection.",i)})}),this.context.connection.beginListen("peer-update-id",t=>{if(t.id!==this.context.connection.connectionId){const i=this.connections[t.id];if(i&&i.close(),this.peer&&this.context.connection.connectionId){const s=new fie(this,this.peer,this.context.connection.connectionId,t.peerId);this.connections[t.id]=s,s.startVoipCall()}}}),this.context.connection.beginListen(on.UserLeftRoom,t=>{const{userId:i}=t,s=this.connections[i];this.connections[i]=null,s&&s.close();const r=this.currentIncomingCalls[i];vr&&console.log("UserLeftRoom",t,i,r),r&&(r.close(),this.currentIncomingCalls[i]=null)}),this.peer.on("open",this.onOpenPeerConnection.bind(this))}onEnable(){}onDisable(){console.log("TODO: close all");for(const t in this.currentIncomingCalls)try{const i=this.currentIncomingCalls[t];i==null||i.close();const s=this.connections[t];s==null||s.close()}catch(i){console.error(i)}}async onOpenPeerConnection(t){vr&&console.log("Peer connection established and received id"),this.model=new die(t),this.context.connection.send("peer-update-id",this.model,Ar.OnRoomJoin),this.peer&&(this.peer.on("call",this.onReceiveCall.bind(this)),this.peer.on("connection",function(i){vr&&console.log("CONNECTION",i),i.on("data",function(s){vr&&console.log("Received",s)})}))}async onReceiveCall(t){if(!t)return;const{metadata:i}=t;console.assert(i.userId);const{userId:s}=i,r=this.currentIncomingCalls[s];if(r&&r.close(),vr&&console.log("received call"),await dl.HasMicrophonePermissions())try{const o=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1});t.answer(o)}catch(o){console.error("Error initializing VoIP connection.",o)}else t.answer(null);this.currentIncomingCalls[s]=new pie(this,this.gameObject,t),t.on("stream",o=>{var a;vr&&console.log("receive caller stream, will setup audio now"),(a=this.currentIncomingCalls[s])==null||a.openAudioStream(o)}),t.on("error",console.error)}static async HasMicrophonePermissions(){try{return(await navigator.permissions.query({name:"microphone"})).state!=="denied"}catch(t){return console.error("Error querying `microphone` permissions.",t),!1}}}var gie=Object.defineProperty,mie=Object.getOwnPropertyDescriptor,Uz=(n,e,t,i)=>{for(var s=i>1?void 0:i?mie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&gie(e,t,s),s};const Aie=re("debugmouth");class XA extends Ie{constructor(){super(...arguments);h(this,"idle",[]);h(this,"talking",[]);h(this,"marker",null);h(this,"voip",null);h(this,"lastMouthChangeTime",0);h(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=ne.findObjectOfType(dl,this.context),this.marker||(this.marker=ne.getComponentInParent(this.gameObject,Jn))},3e3)}update(){var s;if(!this.voip||this.context.time.frameCount%10!==0)return;let t=((s=this.marker)==null?void 0:s.connectionId)??null;if(!t){Aie&&(t=null);return}const i=this.voip.getFrequency(t)??0;this.updateLips(i)}updateLips(t){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&t>30){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,i)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,i)}}}setMouthShapeActive(t,i){if(t){t!=this.idle?this.idle.map(s=>s.visible=!1):this.talking.map(s=>s.visible=!1);for(let s=0;s<t.length;s++){const r=t[s];r&&(r.visible=s===i)}}}}Uz([x(Te)],XA.prototype,"idle",2);Uz([x(Te)],XA.prototype,"talking",2);class hI extends Ie{constructor(){super(...arguments);h(this,"voip",null);h(this,"marker",null);h(this,"_startPosition",null)}awake(){this.voip=ne.findObjectOfType(dl,this.context),this.marker=ne.getComponentInParent(this.gameObject,Jn)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const t=this.marker.connectionId,i=this.voip.getFrequency(t);if(i==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const s=i/100;this.gameObject.position.y=this._startPosition.y+s*.07}}var vie=Object.defineProperty,yie=Object.getOwnPropertyDescriptor,Sx=(n,e,t,i)=>{for(var s=i>1?void 0:i?yie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&vie(e,t,s),s};class Hu extends Ie{constructor(){super(...arguments);h(this,"eyes",[]);h(this,"lastBlinkTime",0);h(this,"blinkLength",0);h(this,"eyesOpen",!0);h(this,"state",null)}awake(){this.state=ne.getComponentInParent(this.gameObject,jr)}update(){if(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)return;if(this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const i of this.eyes)i&&(i.visible=this.eyesOpen)}}}Sx([x(Te)],Hu.prototype,"eyes",2);Sx([x()],Hu.prototype,"lastBlinkTime",2);Sx([x()],Hu.prototype,"blinkLength",2);Sx([x()],Hu.prototype,"eyesOpen",2);var bie=Object.defineProperty,_ie=Object.getOwnPropertyDescriptor,uI=(n,e,t,i)=>{for(var s=i>1?void 0:i?_ie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&bie(e,t,s),s},wC;const Nz=(wC=class extends Ie{constructor(){super(...arguments);h(this,"head",null);h(this,"eyes",null);h(this,"target",null);h(this,"brain",null);h(this,"vec",new w);h(this,"currentTargetPoint",new w)}awake(){this.brain||(this.brain=ne.getComponentInParent(this.gameObject,Vm)),this.brain||(console.log("No look at brain found, adding it now"),this.brain=ne.addNewComponent(this.gameObject,Vm)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const e=this.target;if(e&&this.head){const t=this.eyes;if(t){const i=Ct(e);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const s=Ct(this.head),r=this.vec.copy(this.currentTargetPoint).sub(s).normalize();if(r.length()<.1)return;const o=Nz.forward;if(o.set(0,0,1),o.applyQuaternion(zn(this.head)),o.dot(r)>.45)for(let c=0;c<t.length;c++)t[c].lookAt(this.currentTargetPoint)}}}},h(wC,"forward",new w(0,0,1)),wC);let yp=Nz;uI([x(Te)],yp.prototype,"head",2);uI([x(Te)],yp.prototype,"eyes",2);uI([x(Te)],yp.prototype,"target",2);var xie=Object.defineProperty,wie=Object.getOwnPropertyDescriptor,dI=(n,e,t,i)=>{for(var s=i>1?void 0:i?wie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&xie(e,t,s),s};class bp extends Ie{constructor(){super(...arguments);h(this,"length",1);h(this,"depthTest",!0);h(this,"isGizmo",!0);h(this,"_axes",null)}onEnable(){if(this.isGizmo&&!IA)return;this._axes||(this._axes=new tp(this.length)),this.gameObject.add(this._axes);const t=this._axes.material;t&&t.depthTest!==void 0&&(t.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}dI([x()],bp.prototype,"length",2);dI([x()],bp.prototype,"depthTest",2);dI([x()],bp.prototype,"isGizmo",2);class fI extends Ie{constructor(){super(...arguments);h(this,"from");h(this,"to");h(this,"hint");h(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const t=Ct(this.to).clone(),i=Ct(this.from).clone(),s=t.distanceTo(i),r=t.clone();r.sub(i);const o=i.clone();o.add(t),o.multiplyScalar(.5);const a=Ct(this.hint).clone();a.sub(o);const c=new w;c.crossVectors(a,r),c.crossVectors(r,c),c.normalize();const l=s*.5,u=Math.max(this.desiredDistance,l),d=Math.sqrt(u*u-l*l),f=c.clone();f.multiplyScalar(d),f.add(o),Mn(this.gameObject,f);const p=o.clone();p.sub(c),this.gameObject.lookAt(p)}}const bO=re("debugusdz");class Cx{constructor(){h(this,"behaviours",[]);h(this,"behaviourComponents",[]);h(this,"behaviourComponentsCopy",[])}get extensionName(){return"Behaviour"}addBehavior(e){this.behaviours.push(e)}onBeforeBuildDocument(e){const t=[];return e.root.traverse(i=>{ne.foreachComponent(i,s=>{var o;const r=s;if(typeof r.createBehaviours=="function"||typeof r.beforeCreateDocument=="function"||typeof r.afterCreateDocument=="function"||typeof r.afterSerialize=="function"){this.behaviourComponents.push(r);const a=(o=r.beforeCreateDocument)==null?void 0:o.call(r,this,e);a instanceof Promise&&t.push(a)}},!1)}),Promise.all(t)}onExportObject(e,t,i){var s;for(const r of this.behaviourComponents)(s=r.createBehaviours)==null||s.call(r,this,t,i)}onAfterBuildDocument(e){for(const t of this.behaviourComponents)typeof t.afterCreateDocument=="function"&&t.afterCreateDocument(this,e);this.behaviourComponentsCopy=this.behaviourComponents.slice(),this.behaviourComponents.length=0}onAfterHierarchy(e,t){var i;if((i=this.behaviours)!=null&&i.length){t.beginBlock('def Scope "Behaviors"');for(const s of this.behaviours)s.writeTo(this,e.document,t);t.closeBlock()}}async onAfterSerialize(e){bO&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const t of this.behaviourComponentsCopy)typeof t.afterSerialize=="function"&&(bO&&console.log("behaviour has afterSerialize",t),t.afterSerialize.constructor.name==="AsyncFunction"?await t.afterSerialize(this,e):t.afterSerialize(this,e))}}var Sie=Object.defineProperty,Cie=Object.getOwnPropertyDescriptor,pI=(n,e,t,i)=>{for(var s=i>1?void 0:i?Cie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Sie(e,t,s),s};class Vu extends Us{constructor(){super(...arguments);h(this,"threshold");h(this,"intensity");h(this,"scatter");h(this,"selectiveBloom",!0)}get typeName(){return"Bloom"}init(){this.threshold.defaultValue=1,this.intensity.defaultValue=0,this.scatter.defaultValue=.2,this.selectiveBloom?(this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>1*Math.PI*(1-t)):(this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>100*(1-t))}onCreateEffect(){let t;if(this.selectiveBloom){const i=t=new nN(this.context.scene,this.context.mainCamera,{blendFunction:zt.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,intensity:this.intensity.value});i.inverted=!0}else t=new hT;return this.intensity.onValueChanged=i=>{t.intensity=i},this.threshold.onValueChanged=i=>{t.luminanceMaterial.threshold=i},this.scatter.onValueChanged=i=>{t.luminancePass.enabled=!0,t.luminanceMaterial.smoothing=i},t}}pI([x(Rt)],Vu.prototype,"threshold",2);pI([x(Rt)],Vu.prototype,"intensity",2);pI([x(Rt)],Vu.prototype,"scatter",2);No("Bloom",Vu);var Eie=Object.defineProperty,Mie=Object.getOwnPropertyDescriptor,fa=(n,e,t,i)=>{for(var s=i>1?void 0:i?Mie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Eie(e,t,s),s};class Za extends Ie{constructor(){super(...arguments);h(this,"attachedRigidbody",null);h(this,"isTrigger",!1);h(this,"sharedMaterial");h(this,"updateProperties",()=>{var t;(t=this.context.physics.engine)==null||t.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ii))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ii))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ii))}onDisable(){var t;(t=this.context.physics.engine)==null||t.removeBody(this)}get body(){var t;return(t=this.context.physics.engine)==null?void 0:t.getBody(this)}}fa([x(Ii)],Za.prototype,"attachedRigidbody",2);fa([x()],Za.prototype,"isTrigger",2);fa([x()],Za.prototype,"sharedMaterial",2);class qA extends Za{constructor(){super(...arguments);h(this,"radius",.5);h(this,"center",new w(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addSphereCollider(this,this.center),z1(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),N2(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}fa([ys(),x()],qA.prototype,"radius",2);fa([x(w)],qA.prototype,"center",2);class YA extends Za{constructor(){super(...arguments);h(this,"size",new w(1,1,1));h(this,"center",new w(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addBoxCollider(this,this.center,this.size)}onValidate(){this.updateProperties()}}fa([ys(),x(w)],YA.prototype,"size",2);fa([x(w)],YA.prototype,"center",2);class KA extends Za{constructor(){super(...arguments);h(this,"sharedMesh");h(this,"convex",!1)}onEnable(){var t,i,s,r,o;if(super.onEnable(),(t=this.sharedMesh)!=null&&t.isMesh||this.gameObject instanceof ye&&(this.sharedMesh=this.gameObject),(i=this.sharedMesh)!=null&&i.isMesh)(s=this.context.physics.engine)==null||s.addMeshCollider(this,this.sharedMesh,this.convex,ls(this.gameObject));else{const a=this.sharedMesh;if(a!=null&&a.isGroup){console.warn(`MeshCollider mesh is a group "${(r=this.sharedMesh)==null?void 0:r.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);for(const c in a.children){const l=a.children[c];l.isMesh&&((o=this.context.physics.engine)==null||o.addMeshCollider(this,l,this.convex,ls(this.gameObject)))}}}}}fa([x()],KA.prototype,"convex",2);class lh extends Za{constructor(){super(...arguments);h(this,"center",new w(0,0,0));h(this,"radius",.5);h(this,"height",2)}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addCapsuleCollider(this,this.center,this.height,this.radius)}}fa([x(w)],lh.prototype,"center",2);fa([x()],lh.prototype,"radius",2);fa([x()],lh.prototype,"height",2);var Tie=Object.defineProperty,Iie=Object.getOwnPropertyDescriptor,gI=(n,e,t,i)=>{for(var s=i>1?void 0:i?Iie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Tie(e,t,s),s};class Qu extends Ie{constructor(){super(...arguments);h(this,"objectBounds",!1);h(this,"color");h(this,"isGizmo",!0);h(this,"_gizmoObject",null);h(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!IA||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new P_(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=YN(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),Tr.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){var t;for(;this._boxHelper;)(t=this._boxHelper)==null||t.update(),yield}}gI([x()],Qu.prototype,"objectBounds",2);gI([x(_e)],Qu.prototype,"color",2);gI([x()],Qu.prototype,"isGizmo",2);var Rie=Object.defineProperty,Pie=Object.getOwnPropertyDescriptor,JA=(n,e,t,i)=>{for(var s=i>1?void 0:i?Pie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Rie(e,t,s),s};const VS=re("debugui"),QS=re("debuguilayout");class mI{constructor(){h(this,"width");h(this,"height")}}class AI{constructor(){h(this,"x");h(this,"y");h(this,"width");h(this,"height")}}const qo=new w,lg=new Me,Oy=new we,zz=class extends aa{constructor(){super(...arguments);h(this,"_anchoredPosition");h(this,"sizeDelta",new te(100,100));h(this,"pivot",new te(.5,.5));h(this,"anchorMin",new te(0,0));h(this,"anchorMax",new te(1,1));h(this,"lastMatrix");h(this,"rectBlock");h(this,"_transformNeedsUpdate",!1);h(this,"_initialPosition");h(this,"_parentRectTransform");h(this,"_lastUpdateFrame",-1);h(this,"_lastAnchoring");h(this,"_createdBlocks",[]);h(this,"_createdTextBlocks",[])}get parent(){return this._parentRectTransform}get translation(){return this.gameObject.position}get rotation(){return this.gameObject.quaternion}get scale(){return this.gameObject.scale}get anchoredPosition(){return this._anchoredPosition||(this._anchoredPosition=new te),this._anchoredPosition}set anchoredPosition(e){this._anchoredPosition=e}get width(){if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const e=this._parentRectTransform.width,t=this.anchorMax.x-this.anchorMin.x;let i=e*t;return i+=this.sizeDelta.x,i}return this.sizeDelta.x}get height(){if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const e=this._parentRectTransform.height,t=this.anchorMax.y-this.anchorMin.y;let i=e*t;return i+=this.sizeDelta.y,i}return this.sizeDelta.y}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new te),this.lastMatrix=new Me,this.rectBlock=new Te,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,Jd(this,"_anchoredPosition",()=>{this.markDirty()}),Jd(this,"sizeDelta",()=>{this.markDirty()}),Jd(this,"pivot",()=>{this.markDirty()}),Jd(this,"anchorMin",()=>{this.markDirty()}),Jd(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var e;super.onEnable(),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(e=this.Canvas)==null||e.registerTransform(this)}onDisable(){var e;super.onDisable(),this.removeShadowComponent(),(e=this.Canvas)==null||e.unregisterTransform(this)}onParentRectTransformChanged(e){this._transformNeedsUpdate||this.onApplyTransform(QS?`${e.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(QS&&console.warn("RectTransform markDirty()",this.name),this._transformNeedsUpdate=!0,this._lastUpdateFrame=-1)}updateTransform(){(this._transformNeedsUpdate||!this.lastMatrix.equals(this.gameObject.matrix))&&this.canUpdate()&&this.onApplyTransform(this._transformNeedsUpdate?"Marked dirty":"Matrix changed")}canUpdate(){return this._transformNeedsUpdate&&this.activeAndEnabled&&this._lastUpdateFrame!==this.context.time.frame}onApplyTransform(e){var s;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const t=this.shadowComponent;if(!t)return;this.gameObject.parent?this._parentRectTransform=ne.getComponentInParent(this.gameObject.parent,zz):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,QS&&console.warn("RectTransform → ApplyTransform",this.name+" because "+e),this.isRoot()?this.Root.screenspace||(t.rotation.y=Math.PI):(t.matrix.identity(),t.matrixAutoUpdate=!1,qo.set(0,0,0),this.applyPivot(qo),t.matrix.setPosition(qo.x,qo.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(Oy.copy(this.gameObject.quaternion),Oy.x*=-1,Oy.z*=-1,lg.makeRotationFromQuaternion(Oy),t.matrix.premultiply(lg)),qo.set(0,0,0),this.applyAnchoring(qo),(s=this.Canvas)!=null&&s.screenspace?qo.z+=.1:qo.z+=.01,lg.identity(),lg.setPosition(qo.x,qo.y,qo.z),t.matrix.premultiply(lg),t.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const i=!0;for(const r of sT(this.gameObject,aa,i,1)){if(r===this||!r.activeAndEnabled)continue;const o=r;o.onParentRectTransformChanged&&o.onParentRectTransformChanged(this)}}applyAnchoring(e){this._lastAnchoring||(this._lastAnchoring=new te);const t=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=t.x,this.gameObject.position.y+=t.y,this._lastAnchoring.copy(this._anchoredPosition),e.x+=this._initialPosition.x-this.gameObject.position.x,e.y+=this._initialPosition.y-this.gameObject.position.y,e.z+=this._initialPosition.z-this.gameObject.position.z;const i=this._parentRectTransform;if(i){let s=0;const r=1-this.anchorMax.y-this.anchorMin.y;s-=i.height*.5*r,e.y+=s;let o=0;const a=1-this.anchorMax.x-this.anchorMin.x;o-=i.width*.5*a,e.x+=o}}applyPivot(e){if(this.pivot&&!this.isRoot()){const t=this.pivot.x-.5;e.x-=t*this.sizeDelta.x*this.gameObject.scale.x;const i=this.pivot.y-.5;e.y-=i*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const e={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(e),e}ensureValidSize(e,t=1e-4){return e.width<=0&&(e.width=t),e.height<=0&&(e.height=1e-4),e}createNewBlock(e){e={...this.getBasicOptions(),...e},VS&&console.log(this.name,e);const t=new aI(e);return this._createdBlocks.push(t),t}createNewText(e){VS&&console.log(e),e={...this.getBasicOptions(),...e},VS&&console.log(this.name,e);const t=new Oz(e);return this._createdTextBlocks.push(t),t}};let rr=zz;JA([x(te)],rr.prototype,"anchoredPosition",1);JA([x(te)],rr.prototype,"sizeDelta",2);JA([x(te)],rr.prototype,"pivot",2);JA([x(te)],rr.prototype,"anchorMin",2);JA([x(te)],rr.prototype,"anchorMax",2);class Bie extends Dz{constructor(e,t={}){super(e),e._simpleState__activeStates=[],e._simpleState__normalStyles={},e._simpleState__states=t,e._simpleState__statesProperties={};for(const i in t)for(const s in t[i])e._simpleState__statesProperties[s]||(e._simpleState__statesProperties[s]=[]),e._simpleState__statesProperties[s].push(i);for(const i of e._components)e._simpleState__statesProperties[i.id]&&(e._simpleState__normalStyles[i.id]=i.inline?i.inline:i._value);e.__overridedSet=e.set,e.set=this.storeSet.bind(e),e.renderStates=this.renderStates.bind(e),e.setupState=this.setupState.bind(e),e.setState=this.setState.bind(e),e.activatePseudoState=this.activatePseudoState.bind(e),e.deactivatePseudoState=this.deactivatePseudoState.bind(e),e.togglePseudoState=this.togglePseudoState.bind(e)}act(){}attach(){}detach(){}setupState(e,t){this._simpleState__states[e]=t;const i=[];for(const s in t)this._simpleState__statesProperties[s]||(this._simpleState__statesProperties[s]=[],i.push(s)),this._simpleState__statesProperties[s].push(e);for(const s of this._components)i.indexOf(s.id)>-1&&(this._simpleState__normalStyles[s.id]=s.inline?s.inline:s._value)}renderStates(){let e={...this._simpleState__normalStyles};for(const t in this._simpleState__states)this._simpleState__activeStates.indexOf(t)>-1&&(e={...e,...this._simpleState__states[t]});this.set(e,!1)}storeSet(e,t=!0){if(t)for(const i in e)this._simpleState__statesProperties[i]&&(this._simpleState__normalStyles[i]=e[i]);this.__overridedSet(e)}activatePseudoState(e){this._simpleState__activeStates.indexOf(e)===-1&&(this._simpleState__activeStates.push(e),this.renderStates())}deactivatePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1&&(this._simpleState__activeStates.splice(t,1),this.renderStates())}togglePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1?this._simpleState__activeStates.splice(t,1):this._simpleState__activeStates.push(e),this.renderStates()}setState(e){Array.isArray(e)?this._simpleState__activeStates=e:this._simpleState__activeStates=[e],this.renderStates()}}var Die=Object.defineProperty,Oie=Object.getOwnPropertyDescriptor,Gz=(n,e,t,i)=>{for(var s=i>1?void 0:i?Oie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Die(e,t,s),s};class _p extends Ie{constructor(){super(...arguments);h(this,"effectColor");h(this,"effectDistance")}}Gz([x(bi)],_p.prototype,"effectColor",2);Gz([x(te)],_p.prototype,"effectDistance",2);var kie=Object.defineProperty,Lie=Object.getOwnPropertyDescriptor,Hz=(n,e,t,i)=>{for(var s=i>1?void 0:i?Lie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&kie(e,t,s),s};const ky={backgroundColor:new _e(1,1,1),backgroundOpacity:1,borderColor:new _e(1,1,1),borderOpacity:1};var SC;const D0=(SC=class extends aa{constructor(){super(...arguments);h(this,"_alphaFactor",1);h(this,"raycastTarget",!0);h(this,"uiObject",null);h(this,"_color",null);h(this,"_rect",null);h(this,"_stateManager",null);h(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new bi(1,1,1,1)),this._color}set color(e){(!this._color||this._color.r!==e.r||this._color.g!==e.g||this._color.b!==e.b||this._color.alpha!==e.alpha)&&(this._color||(this._color=new bi(1,1,1,1)),this._color.copy(e))}setAlphaFactor(e){this._alphaFactor=e,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(ky.backgroundColor=this._color,ky.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(ky,this._alphaFactor),this.uiObject.set(ky),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=ne.getComponent(this.gameObject,rr)),!this._rect)throw new Error("Not Supported: Make sure to add a RectTransform component before adding a UI Graphic component.");return this._rect}onParentRectTransformChanged(){var e;(e=this.uiObject)==null||e.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone())}setState(e){this.makePanel(),this.uiObject&&(this.uiObject.setState(e),this==null||this.markDirty())}setupState(e){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new Bie(this.uiObject)),this.uiObject.setupState(e.state,e.attributes))}setOptions(e){this.makePanel(),this.uiObject&&this.uiObject.set(e)}awake(){super.awake(),this.makePanel(),Jd(this,"_color",()=>Ute(this,this.onColorChanged))}onEnable(){var e;super.onEnable(),this.uiObject&&((e=this.rectTransform.shadowComponent)==null||e.add(this.uiObject),this.addShadowComponent(this.uiObject,this.rectTransform))}onDisable(){super.onDisable(),this.uiObject&&this.removeShadowComponent()}makePanel(){if(this.uiObject||this._currentlyCreatingPanel)return;this._currentlyCreatingPanel=!0;const e=.015,t={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:e};this.onBeforeCreate(t),this.applyEffects(t),this.onCreate(t),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated()}onBeforeCreate(e){}onCreate(e){this.uiObject=this.rectTransform.createNewBlock(e),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(e,t=1){var s;const i=(s=this.gameObject)==null?void 0:s.getComponent(_p);i&&(i.effectDistance&&(e.borderWidth=Math.max(Math.abs(i.effectDistance.x),Math.abs(i.effectDistance.y))),i.effectColor&&(e.borderColor=i.effectColor,e.borderOpacity=i.effectColor.alpha*t))}async setTexture(e){if(this.setOptions({backgroundOpacity:0}),e){if(e.colorSpace===Ze){if(D0.textureCache.has(e))e=D0.textureCache.get(e);else if(!e.isRenderTargetTexture){const t=e.clone();t.colorSpace=An,D0.textureCache.set(e,t),e=t}}this.setOptions({backgroundImage:e,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"})}else this.setOptions({backgroundImage:null,borderRadius:0,backgroundOpacity:this.color.alpha});this.markDirty()}onAfterAddedToScene(){super.onAfterAddedToScene(),this.shadowComponent&&(this.shadowComponent.offset=this.shadowComponent.position.z)}},h(SC,"textureCache",new Map),SC);let Wu=D0;Hz([x(bi)],Wu.prototype,"color",1);Hz([x()],Wu.prototype,"raycastTarget",2);class ZA extends Wu{constructor(){super(...arguments);h(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var Fie=Object.defineProperty,Uie=Object.getOwnPropertyDescriptor,Ex=(n,e,t,i)=>{for(var s=i>1?void 0:i?Uie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Fie(e,t,s),s};let vI=class{constructor(){h(this,"texture",null);h(this,"rect")}};Ex([x(Ot)],vI.prototype,"texture",2);let xp=class extends ZA{constructor(){super(...arguments);h(this,"_sprite");h(this,"pixelsPerUnitMultiplier",1)}set image(t){this.sprite||(this.sprite=new vI),this.sprite.texture=t,this.onAfterCreated()}get image(){return this.sprite?this.sprite.texture:null}get sprite(){return this._sprite}set sprite(t){this._sprite!==t&&(this._sprite=t,this.onAfterCreated())}isBuiltinSprite(){var t,i,s,r,o,a,c,l;switch((i=(t=this.sprite)==null?void 0:t.texture)==null?void 0:i.name){case"InputFieldBackground":case"UISprite":case"Background":case"Knob":return!0}return((o=(r=(s=this.sprite)==null?void 0:s.texture)==null?void 0:r.image)==null?void 0:o.width)===32&&((l=(c=(a=this.sprite)==null?void 0:a.texture)==null?void 0:c.image)==null?void 0:l.height)===32}onBeforeCreate(t){var i,s;super.onBeforeCreate(t),this.isBuiltinSprite()&&(t.borderRadius=5/this.pixelsPerUnitMultiplier,((s=(i=this.sprite)==null?void 0:i.texture)==null?void 0:s.name)==="Knob"&&(t.borderRadius=999))}onAfterCreated(){var t;this.__didAwake&&(super.onAfterCreated(),!this.isBuiltinSprite()&&this.setTexture((t=this.sprite)==null?void 0:t.texture))}};Ex([x(vI)],xp.prototype,"sprite",1);Ex([x()],xp.prototype,"pixelsPerUnitMultiplier",2);class Mx extends ZA{constructor(){super(...arguments);h(this,"_mainTexture")}get mainTexture(){return this._mainTexture}set mainTexture(t){this._mainTexture!==t&&(this._mainTexture=t,this.onAfterCreated())}onAfterCreated(){this.__didAwake&&(super.onAfterCreated(),this.setTexture(this.mainTexture))}}Ex([x(Ot)],Mx.prototype,"mainTexture",1);var Nie=Object.defineProperty,zie=Object.getOwnPropertyDescriptor,io=(n,e,t,i)=>{for(var s=i>1?void 0:i?zie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Nie(e,t,s),s};const Ud=re("debugbutton");class ju{constructor(){h(this,"colorMultiplier");h(this,"disabledColor");h(this,"fadeDuration");h(this,"highlightedColor");h(this,"normalColor");h(this,"pressedColor");h(this,"selectedColor")}}io([x()],ju.prototype,"colorMultiplier",2);io([x(bi)],ju.prototype,"disabledColor",2);io([x()],ju.prototype,"fadeDuration",2);io([x(bi)],ju.prototype,"highlightedColor",2);io([x(bi)],ju.prototype,"normalColor",2);io([x(bi)],ju.prototype,"pressedColor",2);io([x(bi)],ju.prototype,"selectedColor",2);class fl extends Ie{constructor(){super(...arguments);h(this,"onClick");h(this,"_isHovered",!1);h(this,"colors");h(this,"transition");h(this,"animationTriggers");h(this,"animator");h(this,"_interactable",!0);h(this,"_requestedAnimatorTrigger");h(this,"_isInit",!1);h(this,"_image")}onPointerEnter(t){var i,s;Ud&&console.log("Button Enter",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator),this._isHovered=!0,this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.highlightedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("hovered")),this.context.input.setCursorPointer())}onPointerExit(){var t,i;Ud&&console.log("Button Exit",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this._isHovered=!1,this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((i=this._image)==null||i.setState("normal")),this.context.input.setCursorNormal())}onPointerDown(t){var i,s;Ud&&console.log("Button Down",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.pressedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("pressed")))}onPointerUp(t){var i,s;Ud&&console.warn("Button Up",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator,this._isHovered),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this._isHovered?this.animationTriggers.highlightedTrigger:this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState(this._isHovered?"hovered":"normal")))}onPointerClick(t){!this.interactable||t.pointerId===void 0||t.pointerId!==0&&this.context.input.getIsMouse(t.pointerId)||(Ud&&(console.warn("Button Click",this.onClick),pn("CLICKED button "+this.name+" at "+this.context.time.frameCount)),this.onClick&&this.onClick.listenerCount>0&&(this.onClick.invoke(),t.use()))}set interactable(t){this._interactable=t,this._image&&(this._image.setInteractable(t),t?this._image.setState("normal"):this._image.setState("disabled"))}get interactable(){return this._interactable}set_interactable(t){this.interactable=t}awake(){super.awake(),Ud&&console.log(this),this._isInit=!1,this.init()}start(){var t;(t=this._image)==null||t.setInteractable(this.interactable)}onEnable(){super.onEnable()}*setAnimatorTriggerAtEndOfFrame(t){var i;this._requestedAnimatorTrigger=t,yield,yield,this._requestedAnimatorTrigger==t&&((i=this.animator)==null||i.SetTrigger(t))}init(){this._isInit||(this._isInit=!0,this._image=ne.getComponent(this.gameObject,xp),this._image&&(this.stateSetup(this._image),this.interactable?this._image.setState("normal"):this._image.setState("disabled")))}stateSetup(t){var p,g,A,v,m;t.setInteractable(this.interactable);const i=this.getFinalColor(t.color,(p=this.colors)==null?void 0:p.normalColor),s={state:"normal",attributes:{backgroundColor:i,backgroundOpacity:i.alpha}};t.setupState(s);const r=this.getFinalColor(t.color,(g=this.colors)==null?void 0:g.highlightedColor),o={state:"hovered",attributes:{backgroundColor:r,backgroundOpacity:r.alpha}};t.setupState(o);const a=this.getFinalColor(t.color,(A=this.colors)==null?void 0:A.pressedColor),c={state:"pressed",attributes:{backgroundColor:a,backgroundOpacity:a.alpha}};t.setupState(c);const l=this.getFinalColor(t.color,(v=this.colors)==null?void 0:v.selectedColor),u={state:"selected",attributes:{backgroundColor:l,backgroundOpacity:l.alpha}};t.setupState(u);const d=this.getFinalColor(t.color,(m=this.colors)==null?void 0:m.disabledColor),f={state:"disabled",attributes:{backgroundColor:d,backgroundOpacity:d.alpha}};t.setupState(f)}getFinalColor(t,i){return i?t.clone().multiply(i):t.clone()}}io([x(us)],fl.prototype,"onClick",2);io([x()],fl.prototype,"colors",2);io([x()],fl.prototype,"transition",2);io([x()],fl.prototype,"animationTriggers",2);io([x(ks)],fl.prototype,"animator",2);io([x()],fl.prototype,"interactable",1);var Gie=Object.defineProperty,Hie=Object.getOwnPropertyDescriptor,Pn=(n,e,t,i)=>{for(var s=i>1?void 0:i?Hie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Gie(e,t,s),s};const _O=re("debuguilayout");class _h{constructor(){h(this,"left",0);h(this,"right",0);h(this,"top",0);h(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Pn([x()],_h.prototype,"left",2);Pn([x()],_h.prototype,"right",2);Pn([x()],_h.prototype,"top",2);Pn([x()],_h.prototype,"bottom",2);class no extends Ie{constructor(){super(...arguments);h(this,"_rectTransform",null);h(this,"_needsUpdate",!1);h(this,"childAlignment",0);h(this,"reverseArrangement",!1);h(this,"spacing",0);h(this,"padding");h(this,"minWidth",0);h(this,"minHeight",0);h(this,"flexibleHeight",0);h(this,"flexibleWidth",0);h(this,"preferredHeight",0);h(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(t){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(_O&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){_O&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(rr);const t=this.gameObject.getComponentInParent(ps);t&&t.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const t=this.gameObject.getComponentInParent(ps);t&&t.unregisterLayoutGroup(this)}set m_Spacing(t){t!==this.spacing&&(this._needsUpdate=!0,this.spacing=t)}get m_Spacing(){return this.spacing}}Pn([x()],no.prototype,"childAlignment",2);Pn([x()],no.prototype,"reverseArrangement",2);Pn([x()],no.prototype,"spacing",2);Pn([x(_h)],no.prototype,"padding",2);Pn([x()],no.prototype,"minWidth",2);Pn([x()],no.prototype,"minHeight",2);Pn([x()],no.prototype,"flexibleHeight",2);Pn([x()],no.prototype,"flexibleWidth",2);Pn([x()],no.prototype,"preferredHeight",2);Pn([x()],no.prototype,"preferredWidth",2);class xh extends no{constructor(){super(...arguments);h(this,"childControlHeight",!0);h(this,"childControlWidth",!0);h(this,"childForceExpandHeight",!1);h(this,"childForceExpandWidth",!1);h(this,"childScaleHeight",!1);h(this,"childScaleWidth",!1)}onCalculateLayout(t){var R;const i=this.primaryAxis,s=t.width;let r=s;const o=t.height;let a=o;r-=this.padding.horizontal,a-=this.padding.vertical,i==="x"?this.padding.horizontal:this.padding.vertical;const c=i==="x",l=c?"y":"x",u=c?this.childControlWidth:this.childControlHeight,d=c?this.childControlHeight:this.childControlWidth,f=c?this.childForceExpandWidth:this.childForceExpandHeight,p=c?this.childForceExpandHeight:this.childForceExpandWidth,g=c?a:r,A=c?s:o,v=.5*(c?this.childAlignment%3:Math.floor(this.childAlignment/3));let m=0;c?m+=this.padding.left:m+=this.padding.top;let b=0,y=0;for(let E=0;E<this.gameObject.children.length;E++){const T=this.gameObject.children[E],D=ne.getComponent(T,rr);D!=null&&D.activeAndEnabled&&(y+=1,c?b+=D.width:b+=D.height)}let _=0;const C=this.spacing*(y-1);if(f||u){let E=0;c?E=r-=C:E=a-=C,y>0&&(_=E/y)}let M=0;M+=this.padding.left,M-=this.padding.right,v!==0&&(m=A-b,m*=v,m-=C*v,c?(m-=this.padding.right*v,m+=this.padding.left*(1-v),m<this.padding.left&&(m=this.padding.left)):(m-=this.padding.bottom*v,m+=this.padding.top*(1-v),m<this.padding.top&&(m=this.padding.top)));let I=1;for(let E=0;E<this.gameObject.children.length;E++){const T=this.gameObject.children[E],D=ne.getComponent(T,rr);if(D!=null&&D.activeAndEnabled){(R=D.pivot)==null||R.set(.5,.5),D.anchorMin.set(0,1),D.anchorMax.set(0,1);const K=s*.5+M*.5;D.anchoredPosition.x!==K&&(D.anchoredPosition.x=K);const H=o*-.5;D.anchoredPosition.y!==H&&(D.anchoredPosition.y=H),p&&d&&D.sizeDelta[l]!==g&&(D.sizeDelta[l]=g),f&&u&&D.sizeDelta[i]!==_&&(D.sizeDelta[i]=_);const V=c?D.width:D.height,Y=V*.5;if(m+=Y,f){const L=_*I-_*.5;L>m&&(m=L-_*.5+V+this.padding.left,m-=Y)}let N=m;i==="y"&&(N=-N),D.anchoredPosition[i]!==N&&(D.anchoredPosition[i]=N),m+=Y,m+=this.spacing,I+=1}}}}Pn([x()],xh.prototype,"childControlHeight",2);Pn([x()],xh.prototype,"childControlWidth",2);Pn([x()],xh.prototype,"childForceExpandHeight",2);Pn([x()],xh.prototype,"childForceExpandWidth",2);Pn([x()],xh.prototype,"childScaleHeight",2);Pn([x()],xh.prototype,"childScaleWidth",2);class yI extends xh{get primaryAxis(){return"y"}}class bI extends xh{get primaryAxis(){return"x"}}class _I extends no{onCalculateLayout(){}}var Vie=Object.defineProperty,Qie=Object.getOwnPropertyDescriptor,$a=(n,e,t,i)=>{for(var s=i>1?void 0:i?Qie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Vie(e,t,s),s},Vz=(n=>(n[n.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",n[n.ScreenSpaceCamera=1]="ScreenSpaceCamera",n[n.WorldSpace=2]="WorldSpace",n[n.Undefined=-1]="Undefined",n))(Vz||{});const WS=re("debuguilayout"),Qz=class extends HA{constructor(){super(...arguments);h(this,"_renderOnTop");h(this,"_depthWrite",!1);h(this,"_doubleSided",!0);h(this,"_castShadows",!1);h(this,"_receiveShadows",!1);h(this,"_renderMode",-1);h(this,"_rootCanvas");h(this,"_scaleFactor",1);h(this,"worldCamera");h(this,"planeDistance",-1);h(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this));h(this,"previousParent",null);h(this,"_lastMatrixWorld",null);h(this,"_rectTransforms",[]);h(this,"_layoutGroups",new Map);h(this,"_receivers",[]);h(this,"onBeforeRenderRoutine",()=>{var e,t,i,s;if(this.context.isInVR){this.onUpdateRenderMode(),this.handleLayoutUpdates(),(e=this.shadowComponent)==null||e.updateMatrixWorld(!0),(t=this.shadowComponent)==null||t.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),$s.ensureUpdateMeshUI(GS,this.context,!0);return}this.previousParent=this.gameObject.parent,this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(i=this.shadowComponent)==null||i.updateMatrixWorld(!0),(s=this.shadowComponent)==null||s.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),$s.ensureUpdateMeshUI(GS,this.context))});h(this,"onAfterRenderRoutine",()=>{var e,t;if(!this.context.isInVR){if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const r=this.context.mainCamera;r==null||r.add(this.gameObject)}else this.previousParent.add(this.gameObject);const i=this.context.renderer.autoClear,s=this.context.renderer.autoClearColor;this.context.renderer.autoClear=!1,this.context.renderer.autoClearColor=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(e=this.shadowComponent)==null||e.updateMatrixWorld(!0),this.invokeBeforeRenderEvents(),$s.ensureUpdateMeshUI(GS,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=i,this.context.renderer.autoClearColor=s,this.previousParent.add(this.gameObject)}(t=this._lastMatrixWorld)==null||t.copy(this.gameObject.matrixWorld)}});h(this,"_updateRenderSettingsRoutine");h(this,"_activeRenderMode",-1);h(this,"_lastWidth",-1);h(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(e){e!==this._renderOnTop&&(this._renderOnTop=e,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(e){this._depthWrite!==e&&(this._depthWrite=e,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(e){this._doubleSided!==e&&(this._doubleSided=e,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(e){this._castShadows!==e&&(this._castShadows=e,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(e){this._receiveShadows!==e&&(this._receiveShadows=e,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(e){this._renderMode!==e&&(this._renderMode=e,this.onRenderSettingsChanged())}set rootCanvas(e){this._rootCanvas instanceof Qz||(this._rootCanvas=e)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(e){this._scaleFactor=e}awake(){var e;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,WS&&console.log("Canvas.Awake()",((e=this.previousParent)==null?void 0:e.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new Me,this.onUpdateRenderMode(),document.addEventListener("resize",this._boundRenderSettingsChanged),this.context.pre_render_callbacks.push(this.onBeforeRenderRoutine),this.context.post_render_callbacks.push(this.onAfterRenderRoutine)}onDisable(){super.onDisable(),document.removeEventListener("resize",this._boundRenderSettingsChanged);const e=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);e!==-1&&this.context.pre_render_callbacks.splice(e,1);const t=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);t!==-1&&this.context.post_render_callbacks.splice(t,1)}registerTransform(e){this._rectTransforms.push(e)}unregisterTransform(e){const t=this._rectTransforms.indexOf(e);t!==-1&&this._rectTransforms.splice(t,1)}registerLayoutGroup(e){const t=e.gameObject;this._layoutGroups.set(t,e)}unregisterLayoutGroup(e){const t=e.gameObject;this._layoutGroups.delete(t)}registerEventReceiver(e){this._receivers.push(e)}unregisterEventReceiver(e){const t=this._receivers.indexOf(e);t!==-1&&this._receivers.splice(t,1)}invokeBeforeRenderEvents(){var e;for(const t of this._receivers)(e=t.onBeforeCanvasRender)==null||e.call(t,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new Me);const e=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);WS&&e&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const t=!1;for(const i of this._rectTransforms){e&&i.markDirty();let s=this._layoutGroups.get(i.gameObject);i.isDirty&&!s&&(s=i.gameObject.getComponentInParent(no)),(i.isDirty||s!=null&&s.isDirty)&&(WS&&!t&&console.log("CANVAS UPDATE ### "+i.name+" ##################################### "+this.context.time.frame),s==null||s.updateLayout(),i.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),Tr.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),Tb(this.shadowComponent,this);for(const e of ne.getComponentsInChildren(this.gameObject,aa))Tb(e.shadowComponent,this)}}onUpdateRenderMode(e=!1){if(!e&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let t=this.context.mainCameraComponent,i=10;switch(t&&t.nearClipPlane>0&&t.farClipPlane>0&&(i=tt.lerp(t.nearClipPlane,t.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(t=this.worldCamera),this.planeDistance>0&&(i=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!t)return;const s=i+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-s,this.gameObject.quaternion.identity();const r=this.gameObject.getComponent(rr);let o=!1;r.sizeDelta.x!==this.context.domWidth&&(o=!0),r.sizeDelta.y!==this.context.domHeight&&(o=!0);const a=t.fieldOfView*Math.PI/180,c=2*Math.tan(a/2)*Math.abs(s);this.gameObject.scale.x=c/this.context.domHeight,this.gameObject.scale.y=c/this.context.domHeight,this.gameObject.scale.z=.01,o&&(r.sizeDelta.x=this.context.domWidth,r.sizeDelta.y=this.context.domHeight,r==null||r.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let ps=Qz;$a([x()],ps.prototype,"renderOnTop",1);$a([x()],ps.prototype,"depthWrite",1);$a([x()],ps.prototype,"doubleSided",1);$a([x()],ps.prototype,"castShadows",1);$a([x()],ps.prototype,"receiveShadows",1);$a([x()],ps.prototype,"renderMode",1);$a([x(ps)],ps.prototype,"rootCanvas",1);$a([x()],ps.prototype,"scaleFactor",1);$a([x(Li)],ps.prototype,"worldCamera",2);$a([x()],ps.prototype,"planeDistance",2);var Wie=Object.defineProperty,jie=Object.getOwnPropertyDescriptor,xI=(n,e,t,i)=>{for(var s=i>1?void 0:i?jie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Wie(e,t,s),s};class hh extends Ie{constructor(){super(...arguments);h(this,"_alpha",1);h(this,"interactable",!0);h(this,"blocksRaycasts",!0);h(this,"_isDirty",!1);h(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(t){t!==this._alpha&&(this._alpha=t,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),Tr.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){for(const t of ne.getComponentsInChildren(this.gameObject,aa,this._buffer)){const i=t;i.setAlphaFactor&&i.setAlphaFactor(this._alpha)}}}xI([x()],hh.prototype,"alpha",1);xI([x()],hh.prototype,"interactable",2);xI([x()],hh.prototype,"blocksRaycasts",2);var Xie=Object.defineProperty,qie=Object.getOwnPropertyDescriptor,Fi=(n,e,t,i)=>{for(var s=i>1?void 0:i?qie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Xie(e,t,s),s};class Xu extends Ie{constructor(){super(...arguments);h(this,"object");h(this,"target");h(this,"duration",1);h(this,"relativeMotion",!1);h(this,"coroutine",null);h(this,"targetPos",new w);h(this,"targetRot",new we);h(this,"targetScale",new w)}*moveToTarget(){if(!this.target||!this.object)return;const t=Ct(this.object).clone(),i=Ct(this.target).clone(),s=zn(this.object).clone(),r=zn(this.target).clone(),o=ls(this.object).clone(),a=ls(this.target).clone(),c=t.distanceTo(i),l=s.angleTo(r),u=o.distanceTo(a);if(c<.01&&l<.01&&u<.01){Mn(this.object,i),Mr(this.object,r),AE(this.object,a),this.coroutine=null;return}let d=0,f=0;for(;d<1;)d+=this.context.time.deltaTime/this.duration,d>1&&(d=1),f=d<.5?4*d*d*d:1-Math.pow(-2*d+2,3)/2,this.targetPos.lerpVectors(t,i,f),this.targetRot.slerpQuaternions(s,r,f),this.targetScale.lerpVectors(o,a,f),Mn(this.object,this.targetPos),Mr(this.object,this.targetRot),AE(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const t=this.object.position.clone(),i=this.object.quaternion.clone(),s=this.object.scale.clone(),r=this.target.position.clone(),o=this.target.quaternion.clone(),a=this.target.scale.clone();r.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(r),this.targetRot.copy(this.object.quaternion).multiply(o),this.targetScale.copy(this.object.scale).multiply(a);let c=0,l=0;for(;c<1;)c+=this.context.time.deltaTime/this.duration,c>1&&(c=1),l=c<.5?4*c*c*c:1-Math.pow(-2*c+2,3)/2,this.object.position.lerpVectors(t,this.targetPos,l),this.object.quaternion.slerpQuaternions(i,this.targetRot,l),this.object.scale.lerpVectors(s,this.targetScale,l),yield;this.coroutine=null}onPointerClick(t){t.use(),this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}beforeCreateDocument(t){var i;if(this.target&&this.object&&this.gameObject){const s=new ds("Move to "+((i=this.target)==null?void 0:i.name),Cr.tapTrigger(this.gameObject),fi.transformAction(this.object,this.target,this.duration,this.relativeMotion?tM.Relative:tM.Absolute));t.addBehavior(s)}}}Fi([x(Te)],Xu.prototype,"object",2);Fi([x(Te)],Xu.prototype,"target",2);Fi([x()],Xu.prototype,"duration",2);Fi([x()],Xu.prototype,"relativeMotion",2);var i0;const _c=(i0=class extends Ie{constructor(){super(...arguments);h(this,"materialToSwitch");h(this,"variantMaterial");h(this,"fadeDuration",0);h(this,"_objectsWithThisMaterial",[]);h(this,"selfModel");h(this,"targetModels")}awake(){if(this.variantMaterial&&this.materialToSwitch){const e=ne.findObjectsOfType(Qi);for(const t of e)for(let i=0;i<t.sharedMaterials.length;i++){const s=t.sharedMaterials[i];if(s===this.materialToSwitch){if(t.gameObject instanceof ye)this._objectsWithThisMaterial.push(t.gameObject);else if(t.gameObject instanceof yr)for(const r of t.gameObject.children)r instanceof ye&&r.material===s&&this._objectsWithThisMaterial.push(r);break}}}}onPointerClick(e){if(e.use(),!!this.variantMaterial)for(let t=0;t<this._objectsWithThisMaterial.length;t++){const i=this._objectsWithThisMaterial[t];i.material=this.variantMaterial}}async beforeCreateDocument(e,t){this.targetModels=[],_c._materialTriggersPerId={},_c.variantSwitchIndex=0,this.materialToSwitch&&await Hr.assignTextureLOD(this.context,this.sourceId,this.materialToSwitch,0),this.variantMaterial&&await Hr.assignTextureLOD(this.context,this.sourceId,this.variantMaterial,0)}createBehaviours(e,t,i){this._objectsWithThisMaterial.find(r=>r.uuid===t.uuid)&&this.targetModels.push(t),this.gameObject.uuid===t.uuid&&(this.selfModel=t,this.materialToSwitch&&(_c._materialTriggersPerId[this.materialToSwitch.uuid]||(_c._materialTriggersPerId[this.materialToSwitch.uuid]=[]),_c._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(e,t){if(!this.materialToSwitch)return;const i=_c._materialTriggersPerId[this.materialToSwitch.uuid];if(i){const s={};for(const o of i){const a=o.createVariants();a&&a.length>0&&(s[o.selfModel.uuid]=a)}const r=[];for(const o of i){for(const a in s)a!==o.selfModel.uuid&&r.push(s[a]);o.createAndAttachBehaviors(e,s[o.selfModel.uuid],r)}}delete _c._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(e,t,i){const s=[],r=[],o=Math.max(0,this.fadeDuration);for(const a of this.targetModels){const c=fi.fadeAction(a,o,!1);r.push(c)}for(const a of i)r.push(fi.fadeAction(a,o,!1));for(const a of t)s.push(fi.fadeAction(a,o,!1)),r.push(fi.fadeAction(a,o,!0));e.addBehavior(new ds("Select "+this.selfModel.name,Cr.tapTrigger(this.selfModel),fi.parallel(...r))),e.addBehavior(new ds("Start hidden "+this.selfModel.name,Cr.sceneStartTrigger(),fi.parallel(...s)))}createVariants(){if(!this.variantMaterial)return null;const e=[];for(const t of this.targetModels){const i=t.clone();i.name+=" variant_"+this.variantMaterial.name+"_"+_c.variantSwitchIndex++,i.name=i.name.replace(/\s/g,"_"),i.material=this.variantMaterial,i.geometry=t.geometry,i.matrix=t.matrix,(!t.parent||!t.parent.isEmpty())&&_r.createEmptyParent(t),t.parent&&t.parent.add(i),e.push(i)}return e}},h(i0,"_materialTriggersPerId",{}),h(i0,"variantSwitchIndex",0),i0);let wp=_c;Fi([x(kt)],wp.prototype,"materialToSwitch",2);Fi([x(kt)],wp.prototype,"variantMaterial",2);Fi([x()],wp.prototype,"fadeDuration",2);class Sp extends Ie{constructor(){super(...arguments);h(this,"target");h(this,"toggleOnClick",!1);h(this,"targetState",!0);h(this,"hideSelf",!0);h(this,"selfModel");h(this,"otherModel");h(this,"toggleModel");h(this,"stateBeforeCreatingDocument",!1)}onPointerClick(t){t.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(t,i,s){i.uuid===this.gameObject.uuid&&(this.selfModel=i)}beforeCreateDocument(){this.stateBeforeCreatingDocument=this.gameObject.visible,this.gameObject.visible=!0}afterCreateDocument(t,i){if(this.target){if(this.otherModel=i.document.findById(this.target.uuid),this.selfModel&&this.otherModel){let s=this.hideSelf;this.targetState,this.toggleOnClick&&(s=!0,this.target.visible,(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&e3.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.clone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel));const r=[];if(s&&r.push(fi.fadeAction(this.selfModel,0,!1)),this.toggleModel&&r.push(fi.fadeAction(this.toggleModel,0,!0)),r.push(fi.fadeAction(this.otherModel,0,this.targetState)),t.addBehavior(new ds("Toggle_"+this.selfModel.name+"_hideSelf",Cr.tapTrigger(this.selfModel),fi.sequence(...r))),this.toggleOnClick&&this.toggleModel){const o=[];o.push(fi.fadeAction(this.toggleModel,0,!1)),o.push(fi.fadeAction(this.selfModel,0,!0)),o.push(fi.fadeAction(this.otherModel,0,!this.targetState)),t.addBehavior(new ds("Toggle_"+this.selfModel.name+"_toggleSelf",Cr.tapTrigger(this.toggleModel),fi.sequence(...o))),t.addBehavior(new ds("HideOnStart_"+this.gameObject.name,Cr.sceneStartTrigger(),fi.fadeAction(this.toggleModel,0,!1)))}}this.gameObject.visible=this.stateBeforeCreatingDocument}}}Fi([x(Te)],Sp.prototype,"target",2);Fi([x()],Sp.prototype,"targetState",2);Fi([x()],Sp.prototype,"hideSelf",2);class wI extends Ie{start(){this.gameObject.visible=!1}createBehaviours(e,t,i){t.uuid===this.gameObject.uuid&&e.addBehavior(new ds("HideOnStart_"+this.gameObject.name,Cr.sceneStartTrigger(),fi.fadeAction(t,0,!1)))}beforeCreateDocument(){this.gameObject.visible=!0}afterCreateDocument(){this.gameObject.visible=!1}}class Cp extends Ie{constructor(){super(...arguments);h(this,"target");h(this,"duration",.5);h(this,"motionType",MT.bounce)}beforeCreateDocument(){}createBehaviours(t,i,s){if(this.target&&i.uuid===this.gameObject.uuid){const r=new ds("emphasize "+this.name,Cr.tapTrigger(this.gameObject),fi.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));t.addBehavior(r)}}afterCreateDocument(t,i){}}Fi([x()],Cp.prototype,"target",2);Fi([x()],Cp.prototype,"duration",2);Fi([x()],Cp.prototype,"motionType",2);class Ep extends Ie{constructor(){super(...arguments);h(this,"target");h(this,"clip","");h(this,"toggleOnClick",!1)}onPointerClick(t){if(t.use(),!(!this.target&&!this.clip)){if(!this.target){const i=this.gameObject.addNewComponent(yn);i&&(i.spatialBlend=1,i.volume=1,i.loop=!1,this.target=i)}this.target&&(this.target.isPlaying&&this.toggleOnClick?this.target.stop():(!this.toggleOnClick&&this.target.isPlaying&&this.target.stop(),this.clip?this.target.play(this.clip):this.target.play()))}}createBehaviours(t,i,s){if(!(!this.target&&!this.clip)&&i.uuid===this.gameObject.uuid){const r=this.clip?this.clip:this.target?this.target.clip:void 0;if(!r)return;const o=this.target?this.target.gameObject:this.gameObject,a=r.split("/").pop(),c=this.target?this.target.volume:1,l=this.target&&this.target.spatialBlend==0?iM.NonSpatial:iM.Spatial,u=new ds("playAudio "+this.name,Cr.tapTrigger(this.gameObject),fi.playAudioAction(o,"audio/"+a,o3.Play,c,l));t.addBehavior(u)}}async afterSerialize(t,i){if(!this.target&&!this.clip)return;const s=this.clip?this.clip:this.target?this.target.clip:void 0;if(!s)return;const r=s.split("/").pop(),c=await(await(await fetch(this.clip)).blob()).arrayBuffer(),l=new Uint8Array(c);i.files["audio/"+r]=l}}Fi([x(yn)],Ep.prototype,"target",2);Fi([x(URL)],Ep.prototype,"clip",2);Fi([x()],Ep.prototype,"toggleOnClick",2);var CC;const Zd=(CC=class extends Ie{constructor(){super(...arguments);h(this,"target");h(this,"animator");h(this,"stateName");h(this,"stateNameAfterPlaying");h(this,"loopAfterPlaying",!1);h(this,"selfModel");h(this,"stateAnimationModel");h(this,"stateAnimation");h(this,"stateAfterPlayingAnimationModel");h(this,"stateAfterPlayingAnimation")}onPointerClick(e){var t;e.use(),this.target&&this.stateName&&((t=this.animator)==null||t.play(this.stateName,0,0,.1))}createBehaviours(e,t,i){t.uuid===this.gameObject.uuid&&(this.selfModel=t)}onAfterHierarchy(){Zd.animationActions=[]}afterCreateDocument(e,t){if(!this.stateAnimation||!this.stateAnimationModel)return;t.document.traverse(s=>{var r,o;if(s.uuid===((r=this.target)==null?void 0:r.uuid)&&this.stateAnimation){const a=[];let c=Zd.animationActions.find(u=>u.affectedObjects==s&&u.start==this.stateAnimation.start&&u.duration==this.stateAnimation.duration);if(c||(c=fi.startAnimationAction(s,this.stateAnimation.start,this.stateAnimation.duration),Zd.animationActions.push(c)),a.push(c),this.stateAfterPlayingAnimation&&this.stateAfterPlayingAnimationModel){let u=Zd.animationActions.find(f=>f.affectedObjects==s&&f.start==this.stateAfterPlayingAnimation.start&&f.duration==this.stateAfterPlayingAnimation.duration);u||(u=fi.startAnimationAction(s,this.stateAfterPlayingAnimation.start,this.stateAfterPlayingAnimation.duration),Zd.animationActions.push(u));const d=fi.sequence(u);this.loopAfterPlaying&&d.makeLooping(),a.push(d)}const l=new ds("tap "+this.name+" for "+this.stateName+" on "+((o=this.target)==null?void 0:o.name),Cr.tapTrigger(this.selfModel),fi.sequence(...a));e.addBehavior(l)}})}createAnimation(e,t,i){var s,r,o,a,c;if(this.target&&this.animator){const l=(r=(s=this.animator)==null?void 0:s.runtimeAnimatorController)==null?void 0:r.findState(this.stateName);if(!((o=l==null?void 0:l.motion)!=null&&o.clip)){ci()&&console.warn("No clip found for state "+this.stateName);return}this.stateAnimationModel=t,this.stateAnimation=e.registerAnimation(this.target,l==null?void 0:l.motion.clip);const u=(c=(a=this.animator)==null?void 0:a.runtimeAnimatorController)==null?void 0:c.findState(this.stateNameAfterPlaying);this.stateAfterPlayingAnimationModel=t,this.stateAfterPlayingAnimation=e.registerAnimation(this.target,u==null?void 0:u.motion.clip)}}},h(CC,"animationActions",[]),CC);let wh=Zd;Fi([x(Te)],wh.prototype,"target",2);Fi([x(ks)],wh.prototype,"animator",2);Fi([x()],wh.prototype,"stateName",2);Fi([x()],wh.prototype,"stateNameAfterPlaying",2);Fi([x()],wh.prototype,"loopAfterPlaying",2);class Mp extends Ie{constructor(){super(...arguments);h(this,"target")}getType(){}getDuration(){}}Fi([x(Te)],Mp.prototype,"target",2);class $A extends Ie{constructor(){super(...arguments);h(this,"target")}}Fi([x(Mp)],$A.prototype,"target",2);class ev extends Mp{constructor(){super(...arguments);h(this,"type",1);h(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}Fi([x()],ev.prototype,"type",2);Fi([x()],ev.prototype,"duration",2);class SI extends $A{}var Yie=Object.defineProperty,Kie=Object.getOwnPropertyDescriptor,pl=(n,e,t,i)=>{for(var s=i>1?void 0:i?Kie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Yie(e,t,s),s};class qu extends Ie{constructor(){super(...arguments);h(this,"center",new w(0,0,0));h(this,"radius",.5);h(this,"height",2);h(this,"_rigidbody",null);h(this,"_activeGroundCollisions")}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(Ii),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(Ii)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const t=this.rigidbody;let i=this.gameObject.getComponent(lh);i||(i=this.gameObject.addNewComponent(lh)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height;const s=new w(0,0,1),r=new w(1,0,0),o=new w(0,1,0),a=this.gameObject.getWorldDirection(new w);a.y=0;const c=r.dot(a)<0?-1:1,l=s.angleTo(a)*c;this.gameObject.setRotationFromAxisAngle(o,l),t.lockRotationX=!0,t.lockRotationY=!0,t.lockRotationZ=!0}move(t){this.gameObject.position.add(t)}onCollisionEnter(t){for(const i of t.contacts)if(i.normal.y>.1){this._activeGroundCollisions.add(t);break}}onCollisionExit(t){this._activeGroundCollisions.delete(t)}get isGrounded(){return this._activeGroundCollisions.size>0}}pl([x(w)],qu.prototype,"center",2);pl([x()],qu.prototype,"radius",2);pl([x()],qu.prototype,"height",2);class gl extends Ie{constructor(){super(...arguments);h(this,"controller");h(this,"movementSpeed",2);h(this,"rotationSpeed",2);h(this,"jumpForce",1);h(this,"doubleJumpForce",2);h(this,"animator");h(this,"lookForward",!0);h(this,"lookInput",new te(0,0));h(this,"moveInput",new te(0,0));h(this,"jumpInput",!1);h(this,"_currentSpeed",new w(0,0,0));h(this,"_currentAngularSpeed",new w(0,0,0));h(this,"_temp",new w(0,0,0));h(this,"_jumpCount",0);h(this,"_currentRotation");h(this,"_raycastOptions",new ko)}awake(){this._currentRotation=new we}update(){const t=this.context.input;t.isKeyPressed("KeyW")?this.moveInput.y+=1:t.isKeyPressed("KeyS")&&(this.moveInput.y-=1),t.isKeyPressed("KeyD")?this.lookInput.x+=1:t.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=t.isKeyDown("Space"))}move(t){this.moveInput.add(t)}look(t){this.lookInput.add(t)}jump(){this.jumpInput=!0}onBeforeRender(){this.handleInput(this.moveInput,this.lookInput,this.jumpInput),this.lookInput.set(0,0),this.moveInput.set(0,0),this.jumpInput=!1}handleInput(t,i,s){var r,o,a,c,l,u,d,f,p,g,A;if((r=this.controller)!=null&&r.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((o=this.animator)==null||o.setBool("doubleJump",!1))),this._currentSpeed.z+=t.y*this.movementSpeed*this.context.time.deltaTime,(a=this.animator)==null||a.setBool("running",t.length()>.01),(l=this.animator)==null||l.setBool("jumping",((c=this.controller)==null?void 0:c.isGrounded)===!0&&s),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp),this._currentAngularSpeed.y+=tt.toRadians(-i.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const v=this.context.mainCameraComponent.forward;v.y=0,v.normalize(),this._currentRotation.setFromUnitVectors(new w(0,0,1),v),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&s&&this.jumpForce>0){let v=(u=this.controller)==null?void 0:u.isGrounded;if(this.doubleJumpForce>0&&!((d=this.controller)!=null&&d.isGrounded)&&this._jumpCount===1&&(v=!0,(f=this.animator)==null||f.setBool("doubleJump",!0)),v){this._jumpCount+=1;const m=this.controller.rigidbody,b=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;m.applyImpulse(new w(0,1,0).multiplyScalar(b))}}if(this.controller){const v=(p=this.controller)==null?void 0:p.rigidbody.getVelocity().y;if(v<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new Ya),this._raycastOptions.ray.origin.copy(Ct(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const m=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const b=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(m),(b.length&&b[0].distance>2||v<-10)&&((g=this.animator)==null||g.setBool("falling",!0))}else(A=this.animator)==null||A.setBool("falling",!1)}}}pl([x(qu)],gl.prototype,"controller",2);pl([x()],gl.prototype,"movementSpeed",2);pl([x()],gl.prototype,"rotationSpeed",2);pl([x()],gl.prototype,"jumpForce",2);pl([x()],gl.prototype,"doubleJumpForce",2);pl([x(ks)],gl.prototype,"animator",2);var Jie=Object.defineProperty,Zie=Object.getOwnPropertyDescriptor,$ie=(n,e,t,i)=>{for(var s=i>1?void 0:i?Zie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Jie(e,t,s),s};class tv extends Us{constructor(){super(...arguments);h(this,"intensity")}get typeName(){return"ChromaticAberration"}init(){this.intensity.defaultValue=0}onCreateEffect(){const t=new $U;return t.offset=new te(0,0),t.radialModulation=!0,t.modulationOffset=.15,this.intensity.valueProcessor=i=>i*.02,this.intensity.onValueChanged=i=>{t.offset.x=-i,t.offset.y=i},t}}$ie([x(Rt)],tv.prototype,"intensity",2);No("ChromaticAberration",tv);var ene=Object.defineProperty,tne=Object.getOwnPropertyDescriptor,Tx=(n,e,t,i)=>{for(var s=i>1?void 0:i?tne(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&ene(e,t,s),s};class Sh extends Us{constructor(){super(...arguments);h(this,"postExposure");h(this,"contrast");h(this,"hueShift");h(this,"saturation")}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=t=>(t=Math.pow(2,t),t),this.postExposure.defaultValue=0,this.contrast.valueProcessor=t=>{let i=1;return t>0?i=200:t<0&&(i=100),t/i},this.contrast.defaultValue=0,this.hueShift.valueProcessor=t=>Math.PI*t/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=t=>t<0?t/100:t/(100*Math.PI),this.saturation.defaultValue=0}unapply(){this.context.renderer.toneMappingExposure=1}onCreateEffect(){this.context.renderer.toneMapping===er&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=_m);const t=new ZU;this.postExposure.onValueChanged=s=>{this.context.renderer.toneMapping===er&&(this.context.renderer.toneMapping=_m),this.postExposure.overrideState&&(this.context.renderer.toneMappingExposure=s)},this.contrast.onValueChanged=s=>{t.contrast=s};const i=new tN;return this.hueShift.onValueChanged=s=>i.hue=s,this.saturation.onValueChanged=s=>i.saturation=s,[i,t]}}Tx([x(Rt)],Sh.prototype,"postExposure",2);Tx([x(Rt)],Sh.prototype,"contrast",2);Tx([x(Rt)],Sh.prototype,"hueShift",2);Tx([x(Rt)],Sh.prototype,"saturation",2);No("ColorAdjustments",Sh);const ine=(Math.sqrt(5)-1)/4,ts=(5-Math.sqrt(5))/20,Ly=n=>Math.floor(n)|0,Fy=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function nne(n=Math.random){const e=sne(n),t=new Float64Array(e).map(o=>Fy[o%32*4]),i=new Float64Array(e).map(o=>Fy[o%32*4+1]),s=new Float64Array(e).map(o=>Fy[o%32*4+2]),r=new Float64Array(e).map(o=>Fy[o%32*4+3]);return function(a,c,l,u){let d,f,p,g,A;const v=(a+c+l+u)*ine,m=Ly(a+v),b=Ly(c+v),y=Ly(l+v),_=Ly(u+v),C=(m+b+y+_)*ts,M=m-C,I=b-C,R=y-C,E=_-C,T=a-M,D=c-I,K=l-R,H=u-E;let V=0,Y=0,N=0,L=0;T>D?V++:Y++,T>K?V++:N++,T>H?V++:L++,D>K?Y++:N++,D>H?Y++:L++,K>H?N++:L++;const G=V>=3?1:0,ee=Y>=3?1:0,$=N>=3?1:0,j=L>=3?1:0,ie=V>=2?1:0,Ae=Y>=2?1:0,ge=N>=2?1:0,Ce=L>=2?1:0,Ee=V>=1?1:0,Ge=Y>=1?1:0,Qe=N>=1?1:0,ut=L>=1?1:0,Et=T-G+ts,st=D-ee+ts,W=K-$+ts,Fe=H-j+ts,me=T-ie+2*ts,Le=D-Ae+2*ts,Se=K-ge+2*ts,it=H-Ce+2*ts,Xe=T-Ee+3*ts,Ye=D-Ge+3*ts,At=K-Qe+3*ts,Mt=H-ut+3*ts,Yt=T-1+4*ts,z=D-1+4*ts,k=K-1+4*ts,he=H-1+4*ts,Pe=m&255,Be=b&255,Ue=y&255,X=_&255;let de=.6-T*T-D*D-K*K-H*H;if(de<0)d=0;else{const ke=Pe+e[Be+e[Ue+e[X]]];de*=de,d=de*de*(t[ke]*T+i[ke]*D+s[ke]*K+r[ke]*H)}let ce=.6-Et*Et-st*st-W*W-Fe*Fe;if(ce<0)f=0;else{const ke=Pe+G+e[Be+ee+e[Ue+$+e[X+j]]];ce*=ce,f=ce*ce*(t[ke]*Et+i[ke]*st+s[ke]*W+r[ke]*Fe)}let je=.6-me*me-Le*Le-Se*Se-it*it;if(je<0)p=0;else{const ke=Pe+ie+e[Be+Ae+e[Ue+ge+e[X+Ce]]];je*=je,p=je*je*(t[ke]*me+i[ke]*Le+s[ke]*Se+r[ke]*it)}let qe=.6-Xe*Xe-Ye*Ye-At*At-Mt*Mt;if(qe<0)g=0;else{const ke=Pe+Ee+e[Be+Ge+e[Ue+Qe+e[X+ut]]];qe*=qe,g=qe*qe*(t[ke]*Xe+i[ke]*Ye+s[ke]*At+r[ke]*Mt)}let Ve=.6-Yt*Yt-z*z-k*k-he*he;if(Ve<0)A=0;else{const ke=Pe+1+e[Be+1+e[Ue+1+e[X+1]]];Ve*=Ve,A=Ve*Ve*(t[ke]*Yt+i[ke]*z+s[ke]*k+r[ke]*he)}return 27*(d+f+p+g+A)}}function sne(n){const t=new Uint8Array(512);for(let i=0;i<512/2;i++)t[i]=i;for(let i=0;i<512/2-1;i++){const s=i+~~(n()*(256-i)),r=t[i];t[i]=t[s],t[s]=r}for(let i=256;i<512;i++)t[i]=t[i-256];return t}var rne=Object.defineProperty,one=Object.getOwnPropertyDescriptor,se=(n,e,t,i)=>{for(var s=i>1?void 0:i?one(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&rne(e,t,s),s};const Uy=re("debugparticles");var Mc=(n=>(n[n.Billboard=0]="Billboard",n[n.Stretch=1]="Stretch",n[n.HorizontalBillboard=2]="HorizontalBillboard",n[n.VerticalBillboard=3]="VerticalBillboard",n[n.Mesh=4]="Mesh",n))(Mc||{});let Ch=class{constructor(){h(this,"alphaKeys");h(this,"colorKeys")}get duration(){return 1}evaluate(e,t){let i,s=0,r=null,o=0;for(let a=0;a<this.alphaKeys.length;a++){const c=this.alphaKeys[a];(c.time<e||!i)&&(i=c,s=a)}for(let a=0;a<this.colorKeys.length;a++){const c=this.colorKeys[a];(c.time<e||!r)&&(r=c,o=a)}if(r)if(o+1<this.colorKeys.length){const c=this.colorKeys[o+1],l=tt.remap(e,r.time,c.time,0,1);t.r=tt.lerp(r.color.r,c.color.r,l),t.g=tt.lerp(r.color.g,c.color.g,l),t.b=tt.lerp(r.color.b,c.color.b,l)}else t.r=r.color.r,t.g=r.color.g,t.b=r.color.b;if(i)if(s+1<this.alphaKeys.length){const c=this.alphaKeys[s+1],l=tt.remap(e,i.time,c.time,0,1);t.alpha=tt.lerp(i.alpha,c.alpha,l)}else t.alpha=i.alpha;return t}};se([x()],Ch.prototype,"alphaKeys",2);se([x()],Ch.prototype,"colorKeys",2);var $m=(n=>(n[n.Local=0]="Local",n[n.World=1]="World",n[n.Custom=2]="Custom",n))($m||{}),Wz=(n=>(n[n.Sphere=0]="Sphere",n[n.SphereShell=1]="SphereShell",n[n.Hemisphere=2]="Hemisphere",n[n.HemisphereShell=3]="HemisphereShell",n[n.Cone=4]="Cone",n[n.Box=5]="Box",n[n.Mesh=6]="Mesh",n[n.ConeShell=7]="ConeShell",n[n.ConeVolume=8]="ConeVolume",n[n.ConeVolumeShell=9]="ConeVolumeShell",n[n.Circle=10]="Circle",n[n.CircleEdge=11]="CircleEdge",n[n.SingleSidedEdge=12]="SingleSidedEdge",n[n.MeshRenderer=13]="MeshRenderer",n[n.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",n[n.BoxShell=15]="BoxShell",n[n.BoxEdge=16]="BoxEdge",n[n.Donut=17]="Donut",n[n.Rectangle=18]="Rectangle",n[n.Sprite=19]="Sprite",n[n.SpriteRenderer=20]="SpriteRenderer",n))(Wz||{});class ht{constructor(){h(this,"mode");h(this,"constant");h(this,"constantMin");h(this,"constantMax");h(this,"curve");h(this,"curveMin");h(this,"curveMax");h(this,"curveMultiplier")}evaluate(e,t){const i=t===void 0?Math.random():t;switch(this.mode){case 0:return this.constant;case 1:return e=tt.clamp01(e),this.curve.evaluate(e)*this.curveMultiplier;case 2:const s=e*this.curveMin.duration,r=e*this.curveMax.duration;return tt.lerp(this.curveMin.evaluate(s),this.curveMax.evaluate(r),i%1)*this.curveMultiplier;case 3:return tt.lerp(this.constantMin,this.constantMax,i%1);default:this.curveMax.evaluate(e)*this.curveMultiplier;break}return 0}getMax(){switch(this.mode){case 0:return this.constant;case 1:return this.getMaxFromCurve(this.curve)*this.curveMultiplier;case 2:return Math.max(this.getMaxFromCurve(this.curveMin),this.getMaxFromCurve(this.curveMax))*this.curveMultiplier;case 3:return Math.max(this.constantMin,this.constantMax);default:return 0}}getMaxFromCurve(e){if(!e)return 0;let t=Number.MIN_VALUE;for(let i=0;i<e.keys.length;i++){const s=e.keys[i];s.value>t&&(t=s.value)}return t}}se([x()],ht.prototype,"mode",2);se([x()],ht.prototype,"constant",2);se([x()],ht.prototype,"constantMin",2);se([x()],ht.prototype,"constantMax",2);se([x(zu)],ht.prototype,"curve",2);se([x(zu)],ht.prototype,"curveMin",2);se([x(zu)],ht.prototype,"curveMax",2);se([x()],ht.prototype,"curveMultiplier",2);var n0;const Ko=(n0=class{constructor(){h(this,"mode");h(this,"color");h(this,"colorMin");h(this,"colorMax");h(this,"gradient");h(this,"gradientMin");h(this,"gradientMax")}evaluate(n,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.color;case 1:return this.gradient.evaluate(n,Ko._temp),Ko._temp;case 2:return Ko._temp.lerpColors(this.colorMin,this.colorMax,t);case 3:return this.gradientMin.evaluate(n,Ko._temp),this.gradientMax.evaluate(n,Ko._temp2),Ko._temp.lerp(Ko._temp2,t)}return Ko._temp.set(16711935),Ko._temp.alpha=1,Ko._temp}},h(n0,"_temp",new bi(0,0,0,1)),h(n0,"_temp2",new bi(0,0,0,1)),n0);let Ir=Ko;se([x(bi)],Ir.prototype,"color",2);se([x(bi)],Ir.prototype,"colorMin",2);se([x(bi)],Ir.prototype,"colorMax",2);se([x(Ch)],Ir.prototype,"gradient",2);se([x(Ch)],Ir.prototype,"gradientMin",2);se([x(Ch)],Ir.prototype,"gradientMax",2);var fM=(n=>(n[n.Hierarchy=0]="Hierarchy",n[n.Local=1]="Local",n[n.Shape=2]="Shape",n))(fM||{});class bs{constructor(){h(this,"cullingMode");h(this,"duration");h(this,"emitterVelocityMode");h(this,"flipRotation");h(this,"gravityModifier");h(this,"gravityModifierMultiplier");h(this,"loop");h(this,"maxParticles");h(this,"playOnAwake");h(this,"prewarm");h(this,"ringBufferLoopRange");h(this,"ringBufferMode");h(this,"scalingMode");h(this,"simulationSpace");h(this,"simulationSpeed");h(this,"startColor");h(this,"startDelay");h(this,"startDelayMultiplier");h(this,"startLifetime");h(this,"startLifetimeMultiplier");h(this,"startRotation");h(this,"startRotationMultiplier");h(this,"startRotation3D");h(this,"startRotationX");h(this,"startRotationXMultiplier");h(this,"startRotationY");h(this,"startRotationYMultiplier");h(this,"startRotationZ");h(this,"startRotationZMultiplier");h(this,"startSize");h(this,"startSize3D");h(this,"startSizeMultiplier");h(this,"startSizeX");h(this,"startSizeXMultiplier");h(this,"startSizeY");h(this,"startSizeYMultiplier");h(this,"startSizeZ");h(this,"startSizeZMultiplier");h(this,"startSpeed");h(this,"startSpeedMultiplier");h(this,"stopAction");h(this,"useUnscaledTime")}}se([x(ht)],bs.prototype,"gravityModifier",2);se([x(Ir)],bs.prototype,"startColor",2);se([x(ht)],bs.prototype,"startDelay",2);se([x(ht)],bs.prototype,"startLifetime",2);se([x(ht)],bs.prototype,"startRotation",2);se([x(ht)],bs.prototype,"startRotationX",2);se([x(ht)],bs.prototype,"startRotationY",2);se([x(ht)],bs.prototype,"startRotationZ",2);se([x(ht)],bs.prototype,"startSize",2);se([x(ht)],bs.prototype,"startSizeX",2);se([x(ht)],bs.prototype,"startSizeY",2);se([x(ht)],bs.prototype,"startSizeZ",2);se([x(ht)],bs.prototype,"startSpeed",2);class eA{constructor(){h(this,"cycleCount");h(this,"maxCount");h(this,"minCount");h(this,"probability");h(this,"repeatInterval");h(this,"time");h(this,"count");h(this,"_performed",0)}reset(){this._performed=0}run(e){if(e<=this.time)return 0;let t=0;if(this.cycleCount===0||this._performed<this.cycleCount){const i=this.time+this.repeatInterval*this._performed;if(e>=i&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:t=this.count.constant;break;case 3:t=tt.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:t=this.count.curve.evaluate(Math.random());break;case 2:const s=Math.random();t=tt.lerp(this.count.curveMin.evaluate(s),this.count.curveMax.evaluate(s),Math.random());break}}return t}}class ec{constructor(){h(this,"enabled");h(this,"bursts");h(this,"rateOverTime");h(this,"rateOverTimeMultiplier");h(this,"rateOverDistance");h(this,"rateOverDistanceMultiplier");h(this,"system")}get burstCount(){var e;return((e=this.bursts)==null?void 0:e.length)??0}reset(){var e;(e=this.bursts)==null||e.forEach(t=>t.reset())}getBurst(){let e=0;if(this.burstCount>0)for(let t=0;t<this.burstCount;t++){const i=this.bursts[t];this.system.main.loop&&i.time>=this.system.time&&i.reset(),e+=Math.round(i.run(this.system.time))}return e}}se([x()],ec.prototype,"enabled",2);se([x()],ec.prototype,"bursts",2);se([x(ht)],ec.prototype,"rateOverTime",2);se([x()],ec.prototype,"rateOverTimeMultiplier",2);se([x(ht)],ec.prototype,"rateOverDistance",2);se([x()],ec.prototype,"rateOverDistanceMultiplier",2);class iv{constructor(){h(this,"enabled");h(this,"color")}}se([x(Ir)],iv.prototype,"color",2);class Eh{constructor(){h(this,"enabled");h(this,"separateAxes");h(this,"size");h(this,"sizeMultiplier");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier");h(this,"_time",0);h(this,"_temp",new w)}evaluate(e,t,i){if(t||(t=this._temp),!this.enabled)return t.x=t.y=t.z=1,t;if(this.separateAxes)t.x=this.x.evaluate(e,i)*this.xMultiplier,t.y=this.y.evaluate(e,i)*this.yMultiplier,t.z=this.z.evaluate(e,i)*this.zMultiplier;else{const s=this.size.evaluate(e,i)*this.sizeMultiplier;t.x=s}return t}}se([x(ht)],Eh.prototype,"size",2);se([x(ht)],Eh.prototype,"x",2);se([x(ht)],Eh.prototype,"y",2);se([x(ht)],Eh.prototype,"z",2);var s0;const Dg=(s0=class{constructor(){h(this,"shapeType",5);h(this,"enabled",!0);h(this,"alignToDirection",!1);h(this,"angle",0);h(this,"arc",360);h(this,"arcSpread");h(this,"arcSpeedMultiplier");h(this,"arcMode");h(this,"boxThickness");h(this,"position");h(this,"rotation");h(this,"_rotation",new mn);h(this,"scale");h(this,"radius");h(this,"radiusThickness");h(this,"sphericalDirectionAmount");h(this,"randomDirectionAmount");h(this,"randomPositionAmount");h(this,"system");h(this,"_space");h(this,"_worldSpaceMatrix",new Me);h(this,"_worldSpaceMatrixInverse",new Me);h(this,"_vector",new w(0,0,0));h(this,"_temp",new w(0,0,0));h(this,"_dir",new w);h(this,"_loopTime",0);h(this,"_loopDirection",1);Uy&&console.log(this)}get type(){return Wz[this.shapeType]}initialize(n){this.getPosition(),n.position.copy(this._vector)}toJSON(){return this}clone(){return new Dg}update(n,e,t,i){this.system=n,this._space=t,t===1&&(this._worldSpaceMatrix.copy(i.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(n){const e=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return e&&(this._rotation.x=tt.toRadians(this.rotation.x),this._rotation.y=tt.toRadians(this.rotation.y),this._rotation.z=tt.toRadians(this.rotation.z),this._rotation.order="ZYX",n.applyEuler(this._rotation)),e}get vector(){return this._vector}getPosition(){this._vector.set(0,0,0);const n=this._temp.copy(this.position),e=this._space===1;e&&n.applyQuaternion(this.system.worldQuaternion);let t=this.radius;if(e&&(t*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:Uy&&zc.DrawBox(this.position,this.scale,14540253,1),this._vector.x=Math.random()*this.scale.x-this.scale.x/2,this._vector.y=Math.random()*this.scale.y-this.scale.y/2,this._vector.z=Math.random()*this.scale.z-this.scale.z/2,this._vector.add(n);break;case 4:this.randomConePoint(this.position,this.angle,t,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,t,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,t,this.radiusThickness,this.arc,this._vector);break;default:this._vector.set(0,0,0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),e&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),Uy&&zc.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(n){var e;if(!this.enabled)return this._dir.set(0,0,1),this._dir;switch(this.shapeType){case 5:this._dir.set(0,0,1);break;case 4:this._dir.set(0,0,1);break;case 10:case 0:const t=n.x,i=n.y,s=n.z;this._dir.set(t,i,s),(e=this.system)!=null&&e.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;default:this._dir.set(0,0,1);break}return this._space===1&&this._dir.applyQuaternion(this.system.worldQuaternion),this.applyRotation(this._dir),this._dir.normalize(),this.spherizeDirection(this._dir,this.sphericalDirectionAmount),this.randomizeDirection(this._dir,this.randomDirectionAmount),Uy&&(zc.DrawSphere(n,.01,8925952,.5,!0),zc.DrawDirection(n,this._dir,8925952,.5,!0)),this._dir}randomizePosition(n,e){if(e<=0)return;const t=Dg._tempVec;t.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),t.x*=e*this.scale.x,t.y*=e*this.scale.y,t.z*=e*this.scale.z,n.add(t)}randomizeDirection(n,e){if(e===0)return;const t=Dg._randomQuat,i=Dg._tempVec;i.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),t.setFromAxisAngle(i,e*Math.random()*Math.PI),n.applyQuaternion(t)}spherizeDirection(n,e){if(e===0)return;const t=Math.random()*Math.PI*2,i=Math.acos(1-Math.random()*2),s=Math.sin(i)*Math.cos(t),r=Math.sin(i)*Math.sin(t),o=Math.cos(i),a=new w(s,r,o);n.lerp(a,e)}randomSpherePoint(n,e,t,i,s){const r=Math.random(),o=Math.random(),a=2*Math.PI*r*(i/360),c=Math.acos(2*o-1),l=tt.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,u=n.x+this.scale.x*(-l*Math.sin(c)*Math.cos(a)),d=n.y+this.scale.y*(l*Math.sin(c)*Math.sin(a)),f=n.z+this.scale.z*(l*Math.cos(c));s.x=u,s.y=d,s.z=f}randomCirclePoint(n,e,t,i,s){const r=Math.random(),o=2*Math.PI*r*(i/360),a=tt.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,c=n.x+this.scale.x*a*Math.cos(o),l=n.y+this.scale.y*a*Math.sin(o),u=n.z;s.x=c,s.y=l,s.z=u}randomConePoint(n,e,t,i,s,r,o){let a=0,c=0;switch(r){case 0:a=Math.random(),c=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:a=.5,c=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let l=2*Math.PI*a*(s/360);switch(r){case 2:case 1:l+=Math.PI+.5,l+=this._loopTime*Math.PI*2,l%=tt.toRadians(s);break}const u=Math.acos(2*c-1),d=tt.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*t,f=n.x+-d*Math.sin(u)*Math.cos(l),p=n.y+d*Math.sin(u)*Math.sin(l),g=n.z;o.x=f*this.scale.x,o.y=p*this.scale.y,o.z=g*this.scale.z}},h(s0,"_randomQuat",new we),h(s0,"_tempVec",new w),s0);let bn=Dg;se([x()],bn.prototype,"shapeType",2);se([x()],bn.prototype,"enabled",2);se([x()],bn.prototype,"alignToDirection",2);se([x()],bn.prototype,"angle",2);se([x()],bn.prototype,"arc",2);se([x()],bn.prototype,"arcSpread",2);se([x()],bn.prototype,"arcSpeedMultiplier",2);se([x()],bn.prototype,"arcMode",2);se([x(w)],bn.prototype,"boxThickness",2);se([x(w)],bn.prototype,"position",2);se([x(w)],bn.prototype,"rotation",2);se([x(w)],bn.prototype,"scale",2);se([x()],bn.prototype,"radius",2);se([x()],bn.prototype,"radiusThickness",2);se([x()],bn.prototype,"sphericalDirectionAmount",2);se([x()],bn.prototype,"randomDirectionAmount",2);se([x()],bn.prototype,"randomPositionAmount",2);class vi{constructor(){h(this,"damping");h(this,"enabled");h(this,"frequency");h(this,"octaveCount");h(this,"octaveMultiplier");h(this,"octaveScale");h(this,"positionAmount");h(this,"quality");h(this,"remap");h(this,"remapEnabled");h(this,"remapMultiplier");h(this,"remapX");h(this,"remapXMultiplier");h(this,"remapY");h(this,"remapYMultiplier");h(this,"remapZ");h(this,"remapZMultiplier");h(this,"scrollSpeedMultiplier");h(this,"separateAxes");h(this,"strengthMultiplier");h(this,"strengthX");h(this,"strengthXMultiplier");h(this,"strengthY");h(this,"strengthYMultiplier");h(this,"strengthZ");h(this,"strengthZMultiplier");h(this,"_noise");h(this,"_time",0);h(this,"_temp",new w)}update(e){this._time+=e.time.deltaTime*this.scrollSpeedMultiplier}apply(e,t,i,s,r,o){if(!this.enabled)return;this._noise||(this._noise=nne(()=>0));const a=this._temp.set(t.x,t.y,t.z).multiplyScalar(this.frequency),c=this._noise(a.x,a.y,a.z,this._time),l=this._noise(a.x,a.y,a.z,this._time+1e3*this.frequency),u=this._noise(a.x,a.y,a.z,this._time+2e3*this.frequency);this._temp.set(c,l,u).normalize();const d=r/o;let f=this.positionAmount.evaluate(d);this.separateAxes?(this._temp.x*=f*this.strengthXMultiplier,this._temp.y*=f*this.strengthYMultiplier,this._temp.z*=f*this.strengthZMultiplier):(this.strengthX&&(f*=this.strengthX.evaluate(d)*1.5),this._temp.multiplyScalar(f)),i.x+=this._temp.x,i.y+=this._temp.y,i.z+=this._temp.z}}se([x()],vi.prototype,"damping",2);se([x()],vi.prototype,"enabled",2);se([x()],vi.prototype,"frequency",2);se([x()],vi.prototype,"octaveCount",2);se([x()],vi.prototype,"octaveMultiplier",2);se([x()],vi.prototype,"octaveScale",2);se([x(ht)],vi.prototype,"positionAmount",2);se([x()],vi.prototype,"quality",2);se([x(ht)],vi.prototype,"remap",2);se([x()],vi.prototype,"remapEnabled",2);se([x()],vi.prototype,"remapMultiplier",2);se([x(ht)],vi.prototype,"remapX",2);se([x()],vi.prototype,"remapXMultiplier",2);se([x(ht)],vi.prototype,"remapY",2);se([x()],vi.prototype,"remapYMultiplier",2);se([x(ht)],vi.prototype,"remapZ",2);se([x()],vi.prototype,"remapZMultiplier",2);se([x()],vi.prototype,"scrollSpeedMultiplier",2);se([x()],vi.prototype,"separateAxes",2);se([x()],vi.prototype,"strengthMultiplier",2);se([x(ht)],vi.prototype,"strengthX",2);se([x()],vi.prototype,"strengthXMultiplier",2);se([x(ht)],vi.prototype,"strengthY",2);se([x()],vi.prototype,"strengthYMultiplier",2);se([x(ht)],vi.prototype,"strengthZ",2);se([x()],vi.prototype,"strengthZMultiplier",2);class ji{constructor(){h(this,"enabled");h(this,"attachRibbonToTransform",!1);h(this,"colorOverLifetime");h(this,"colorOverTrail");h(this,"dieWithParticles",!0);h(this,"inheritParticleColor",!0);h(this,"lifetime");h(this,"lifetimeMultiplier");h(this,"minVertexDistance",.2);h(this,"mode",0);h(this,"ratio",1);h(this,"ribbonCount",1);h(this,"shadowBias",0);h(this,"sizeAffectsLifetime",!1);h(this,"sizeAffectsWidth",!1);h(this,"splitSubEmitterRibbons",!1);h(this,"textureMode",0);h(this,"widthOverTrail");h(this,"widthOverTrailMultiplier");h(this,"worldSpace",!1)}getWidth(e,t,i,s){const r=this.widthOverTrail.evaluate(i,s);return e*=r,e}getColor(e,t,i){const s=this.colorOverTrail.evaluate(i),r=this.colorOverLifetime.evaluate(t);e.x*=s.r*r.r,e.y*=s.g*r.g,e.z*=s.b*r.b,e.w*=s.alpha*r.alpha}}se([x()],ji.prototype,"enabled",2);se([x()],ji.prototype,"attachRibbonToTransform",2);se([x(Ir)],ji.prototype,"colorOverLifetime",2);se([x(Ir)],ji.prototype,"colorOverTrail",2);se([x()],ji.prototype,"dieWithParticles",2);se([x()],ji.prototype,"inheritParticleColor",2);se([x(ht)],ji.prototype,"lifetime",2);se([x()],ji.prototype,"lifetimeMultiplier",2);se([x()],ji.prototype,"minVertexDistance",2);se([x()],ji.prototype,"mode",2);se([x()],ji.prototype,"ratio",2);se([x()],ji.prototype,"ribbonCount",2);se([x()],ji.prototype,"shadowBias",2);se([x()],ji.prototype,"sizeAffectsLifetime",2);se([x()],ji.prototype,"sizeAffectsWidth",2);se([x()],ji.prototype,"splitSubEmitterRibbons",2);se([x()],ji.prototype,"textureMode",2);se([x(ht)],ji.prototype,"widthOverTrail",2);se([x()],ji.prototype,"widthOverTrailMultiplier",2);se([x()],ji.prototype,"worldSpace",2);class Zi{constructor(){h(this,"enabled");h(this,"space",0);h(this,"orbitalX");h(this,"orbitalY");h(this,"orbitalZ");h(this,"orbitalXMultiplier");h(this,"orbitalYMultiplier");h(this,"orbitalZMultiplier");h(this,"orbitalOffsetX");h(this,"orbitalOffsetY");h(this,"orbitalOffsetZ");h(this,"speedModifier");h(this,"speedModifierMultiplier");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier");h(this,"_system");h(this,"_temp",new w);h(this,"_temp2",new w);h(this,"_temp3",new w);h(this,"_hasOrbital",!1);h(this,"_index",0);h(this,"_orbitalMatrix",new Me)}update(e){this._system=e}init(e){this._index==0&&(e.debug=!0),this._index+=1,e.orbitx=this.orbitalX.evaluate(Math.random()),e.orbity=this.orbitalY.evaluate(Math.random()),e.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=e.orbitx!=0||e.orbity!=0||e.orbitz!=0}apply(e,t,i,s,r,o,a){var p;if(!this.enabled)return;const c=o/a,l=this.speedModifier.evaluate(c)*this.speedModifierMultiplier,u=this.x.evaluate(c),d=this.y.evaluate(c),f=this.z.evaluate(c);if(this._temp.set(-u,d,f),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((p=this._system)==null?void 0:p.worldPos)){const A=this._temp2.set(i.x,i.y,i.z),v=this.orbitalXMultiplier,m=this.orbitalYMultiplier,b=this.orbitalZMultiplier,y=l*Math.PI*2*10,_=Math.cos(y*v),C=Math.sin(y*v),M=Math.cos(y*m),I=Math.sin(y*m),R=Math.cos(y*b),E=Math.sin(y*b),T=A.x*(M*R)+A.y*(M*E)+A.z*-I,D=A.x*(C*I*R-_*E)+A.y*(C*I*E+_*R)+A.z*(C*M),K=A.x*(_*I*R+C*E)+A.y*(_*I*E-C*R)+A.z*(_*M),H=this._temp3.set(A.x-T,A.y-D,A.z-K);H.normalize(),H.multiplyScalar(.2/r*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),s.x+=H.x,s.y+=H.y,s.z+=H.z}s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z,s.x*=l,s.y*=l,s.z*=l}}se([x()],Zi.prototype,"enabled",2);se([x()],Zi.prototype,"space",2);se([x(ht)],Zi.prototype,"orbitalX",2);se([x(ht)],Zi.prototype,"orbitalY",2);se([x(ht)],Zi.prototype,"orbitalZ",2);se([x()],Zi.prototype,"orbitalXMultiplier",2);se([x()],Zi.prototype,"orbitalYMultiplier",2);se([x()],Zi.prototype,"orbitalZMultiplier",2);se([x()],Zi.prototype,"orbitalOffsetX",2);se([x()],Zi.prototype,"orbitalOffsetY",2);se([x()],Zi.prototype,"orbitalOffsetZ",2);se([x(ht)],Zi.prototype,"speedModifier",2);se([x()],Zi.prototype,"speedModifierMultiplier",2);se([x(ht)],Zi.prototype,"x",2);se([x()],Zi.prototype,"xMultiplier",2);se([x(ht)],Zi.prototype,"y",2);se([x()],Zi.prototype,"yMultiplier",2);se([x(ht)],Zi.prototype,"z",2);se([x()],Zi.prototype,"zMultiplier",2);class _s{constructor(){h(this,"animation");h(this,"enabled");h(this,"cycleCount");h(this,"frameOverTime");h(this,"frameOverTimeMultiplier");h(this,"numTilesX");h(this,"numTilesY");h(this,"startFrame");h(this,"startFrameMultiplier");h(this,"rowMode");h(this,"rowIndex");h(this,"spriteCount");h(this,"timeMode")}sampleOnceAtStart(){if(this.timeMode===0)switch(this.frameOverTime.mode){case 0:case 3:case 2:case 1:return!0}return!1}getStartIndex(){return this.sampleOnceAtStart()?Math.random()*(this.numTilesX*this.numTilesY):0}evaluate(e){if(!this.sampleOnceAtStart())return this.getIndex(e)}getIndex(e){const t=this.numTilesX*this.numTilesY;e=e*this.cycleCount;let i=this.frameOverTime.evaluate(e%1);return i*=this.frameOverTimeMultiplier,i*=t,i=i%t,i=Math.floor(i),i}}se([x()],_s.prototype,"animation",2);se([x()],_s.prototype,"enabled",2);se([x()],_s.prototype,"cycleCount",2);se([x(ht)],_s.prototype,"frameOverTime",2);se([x()],_s.prototype,"frameOverTimeMultiplier",2);se([x()],_s.prototype,"numTilesX",2);se([x()],_s.prototype,"numTilesY",2);se([x(ht)],_s.prototype,"startFrame",2);se([x()],_s.prototype,"startFrameMultiplier",2);se([x()],_s.prototype,"rowMode",2);se([x()],_s.prototype,"rowIndex",2);se([x()],_s.prototype,"spriteCount",2);se([x()],_s.prototype,"timeMode",2);class zo{constructor(){h(this,"enabled");h(this,"separateAxes");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier")}evaluate(e,t){return this.enabled?this.separateAxes?0:this.z.evaluate(e,t)*-1:0}}se([x()],zo.prototype,"enabled",2);se([x()],zo.prototype,"separateAxes",2);se([x(ht)],zo.prototype,"x",2);se([x()],zo.prototype,"xMultiplier",2);se([x(ht)],zo.prototype,"y",2);se([x()],zo.prototype,"yMultiplier",2);se([x(ht)],zo.prototype,"z",2);se([x()],zo.prototype,"zMultiplier",2);class so{constructor(){h(this,"enabled");h(this,"range");h(this,"separateAxes");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier")}evaluate(e,t){if(!this.enabled)return 0;if(!this.separateAxes){const i=tt.lerp(this.range.x,this.range.y,t);return this.z.evaluate(i)*-1}return 0}}se([x()],so.prototype,"enabled",2);se([x()],so.prototype,"range",2);se([x()],so.prototype,"separateAxes",2);se([x(ht)],so.prototype,"x",2);se([x()],so.prototype,"xMultiplier",2);se([x(ht)],so.prototype,"y",2);se([x()],so.prototype,"yMultiplier",2);se([x(ht)],so.prototype,"z",2);se([x()],so.prototype,"zMultiplier",2);class Bn{constructor(){h(this,"enabled");h(this,"dampen");h(this,"drag");h(this,"dragMultiplier");h(this,"limit");h(this,"limitMultiplier");h(this,"separateAxes");h(this,"limitX");h(this,"limitXMultiplier");h(this,"limitY");h(this,"limitYMultiplier");h(this,"limitZ");h(this,"limitZMultiplier");h(this,"multiplyDragByParticleSize",!1);h(this,"multiplyDragByParticleVelocity",!1);h(this,"space");h(this,"_temp",new w);h(this,"_temp2",new w)}apply(e,t,i,s,r,o,a){if(this.enabled){const c=this.limit.evaluate(r)*this.limitMultiplier;if(t.length()>c){this._temp.copy(t).normalize().multiplyScalar(c);const u=this.dampen*.5;t.x=tt.lerp(t.x,this._temp.x,u),t.y=tt.lerp(t.y,this._temp.y,u),t.z=tt.lerp(t.z,this._temp.z,u),i.x=tt.lerp(i.x,this._temp.x,u),i.y=tt.lerp(i.y,this._temp.y,u),i.z=tt.lerp(i.z,this._temp.z,u)}}}}se([x()],Bn.prototype,"enabled",2);se([x()],Bn.prototype,"dampen",2);se([x(ht)],Bn.prototype,"drag",2);se([x()],Bn.prototype,"dragMultiplier",2);se([x(ht)],Bn.prototype,"limit",2);se([x()],Bn.prototype,"limitMultiplier",2);se([x()],Bn.prototype,"separateAxes",2);se([x(ht)],Bn.prototype,"limitX",2);se([x()],Bn.prototype,"limitXMultiplier",2);se([x(ht)],Bn.prototype,"limitY",2);se([x()],Bn.prototype,"limitYMultiplier",2);se([x(ht)],Bn.prototype,"limitZ",2);se([x()],Bn.prototype,"limitZMultiplier",2);se([x()],Bn.prototype,"multiplyDragByParticleSize",2);se([x()],Bn.prototype,"multiplyDragByParticleVelocity",2);se([x()],Bn.prototype,"space",2);class Mh{constructor(){h(this,"enabled");h(this,"curve");h(this,"curveMultiplier");h(this,"mode");h(this,"system");h(this,"_lastWorldPosition");h(this,"_velocity",new w);h(this,"_temp",new w)}update(e){this.enabled&&this.system.worldspace!==!1&&(this._lastWorldPosition?(this._velocity.copy(this.system.worldPos).sub(this._lastWorldPosition).multiplyScalar(1/this.system.deltaTime),this._lastWorldPosition.copy(this.system.worldPos)):(this._velocity.set(0,0,0),this._lastWorldPosition=this.system.worldPos.clone()))}applyInitial(e){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const t=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(t),e.add(this._temp)}}applyCurrent(e,t,i){if(this.enabled&&this.system.worldspace!==!1&&this.mode===1){const s=this.curve.evaluate(t,i);this._temp.copy(this._velocity).multiplyScalar(s),e.add(this._temp)}}}se([x()],Mh.prototype,"enabled",2);se([x(ht)],Mh.prototype,"curve",2);se([x()],Mh.prototype,"curveMultiplier",2);se([x()],Mh.prototype,"mode",2);class lr{constructor(){h(this,"enabled");h(this,"range");h(this,"separateAxes");h(this,"size");h(this,"sizeMultiplier");h(this,"x");h(this,"xMultiplier");h(this,"y");h(this,"yMultiplier");h(this,"z");h(this,"zMultiplier")}evaluate(e,t,i,s){const r=e.length(),o=tt.remap(r,this.range.x,this.range.y,0,1),a=this.size.evaluate(o,i);return s*a}}se([x()],lr.prototype,"enabled",2);se([x(te)],lr.prototype,"range",2);se([x()],lr.prototype,"separateAxes",2);se([x(ht)],lr.prototype,"size",2);se([x()],lr.prototype,"sizeMultiplier",2);se([x(ht)],lr.prototype,"x",2);se([x()],lr.prototype,"xMultiplier",2);se([x(ht)],lr.prototype,"y",2);se([x()],lr.prototype,"yMultiplier",2);se([x(ht)],lr.prototype,"z",2);se([x()],lr.prototype,"zMultiplier",2);class Yu{constructor(){h(this,"enabled");h(this,"range");h(this,"color")}evaluate(e,t,i){const s=e.length(),r=tt.remap(s,this.range.x,this.range.y,0,1),o=this.color.evaluate(r,t);i.x*=o.r,i.y*=o.g,i.z*=o.b,i.w*=o.alpha}}se([x()],Yu.prototype,"enabled",2);se([x(te)],Yu.prototype,"range",2);se([x(Ir)],Yu.prototype,"color",2);function xO(n){const e=n.domElement.shadowRoot.querySelector("link[rel='ar']");if(e)return e;const t=document.createElement("div");t.classList.add("menu"),t.classList.add("quicklook-menu"),t.style.display="none",t.style.visibility="hidden";const i=document.createElement("button");i.id="open-in-ar",i.innerText="Open in QuickLook",t.appendChild(i);const s=document.createElement("a");s.id="needle-usdz-link",s.style.display="none",s.rel="ar",s.href="",t.appendChild(s);const r=document.createElement("img");return r.id="button",s.appendChild(r),n.domElement.shadowRoot.appendChild(t),s}function ane(){var n=new Date;const e=n.getMonth()+1,t=n.getDate(),i=n.getHours(),s=n.getMinutes(),r=n.getSeconds(),o=(e<10?"0":"")+e,a=(t<10?"0":"")+t,c=(i<10?"0":"")+i,l=(s<10?"0":"")+s,u=(r<10?"0":"")+r;return n.getFullYear()+o+a+"-"+c+l+u}const Ny=re("debugusdz");function cne(n,e){const t=[],i=ne.getComponentsInChildren(n,ks),s=ne.getComponentsInChildren(n,$r);let r=!1;const o=new tr("rest",.01,[]),a=new Map,c=(l,u)=>{if(!r&&u.tracks.length>0&&(r=!0,l.push(o)),u.tracks.length>0)for(const d of u.tracks){const f=Nt.parseTrackName(d.name),p=Nt.findNode(n,f.nodeName);if(p){a.has(p)||a.set(p,[]);const g=a.get(p);switch(f.propertyName){case"position":{if(g.includes("position"))continue;const A=p.position,v=new wr(d.name,[0,.01],[A.x,A.y,A.z,A.x,A.y,A.z]);g.push("position"),o.tracks.push(v);break}case"quaternion":{if(g.includes("quaternion"))continue;const A=p.quaternion,v=new wr(d.name,[0,.01],[A.x,A.y,A.z,A.w,A.x,A.y,A.z,A.w]);g.push("quaternion"),o.tracks.push(v);break}case"scale":{if(g.includes("scale"))continue;const A=p.scale,v=new wr(d.name,[0,.01],[A.x,A.y,A.z,A.x,A.y,A.z]);g.push("scale"),o.tracks.push(v);break}}}}};for(const l of i){if(!l||!l.runtimeAnimatorController)continue;Ny&&console.log(l);const u=[];for(const d of l.runtimeAnimatorController.enumerateActions()){Ny&&console.log(d);const f=d.getClip();c(u,f),u.includes(f)||u.push(f)}t.push({root:l.gameObject,clips:u})}for(const l of s){Ny&&console.log(l);const u=[];for(const d of l.animations)c(u,d),u.includes(d)||u.push(d);t.push({root:l.gameObject,clips:u})}Ny&&(console.log("Rest Pose Clip",o),console.log("USDZ Animation Clips",t));for(const l of t)for(const u of l.clips)e.registerAnimation(l.root,u)}class lne{static createButton(e,t={},i){const s=document.createElement("button");let r=!1;function o(){if(t.optionalFeatures=t.optionalFeatures||[],t.domOverlay===void 0){var u=document.createElement("div");u.style.display="none",document.body.appendChild(u);var d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("width",38),d.setAttribute("height",38),d.style.position="absolute",d.style.right="20px",d.style.top="20px",d.addEventListener("click",function(){p.end()}),u.appendChild(d);var f=document.createElementNS("http://www.w3.org/2000/svg","path");f.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),f.setAttribute("stroke","#fff"),f.setAttribute("stroke-width",2),d.appendChild(f),t.optionalFeatures.push("dom-overlay"),t.domOverlay={root:u},r=!0}let p=null,g=null;async function A(m){var _;const b=/WebXRViewer\//i.test(navigator.userAgent),y=t.domOverlay.root;b&&((_=t.domOverlay)!=null&&_.root?(g=y.parentNode,g&&(console.log("Reparent DOM Overlay to body",y,y.style.display),y.style.display="",y.style.visibility="",document.body.appendChild(y))):console.warn("WebXRViewer: No DOM Overlay found")),m.addEventListener("end",v),await e.xr.setSession(m),s.textContent="STOP AR",r&&(t.domOverlay.root.style.display=""),p=m}function v(){p.removeEventListener("end",v),s.textContent="START AR";const m=t.domOverlay.root;g&&g.appendChild(m),r&&(m.style.display="none"),p=null}s.style.display="",s.style.cursor="pointer",s.style.left="calc(50% - 50px)",s.style.width="100px",s.textContent="START AR",s.onmouseenter=function(){s.style.opacity="1.0"},s.onmouseleave=function(){s.style.opacity="0.5"},s.onclick=function(){p===null?(i==null||i.call(this,t),navigator.xr.requestSession("immersive-ar",t).then(A)):p.end()}}function a(){s.disabled=!0,s.style.display="",s.style.cursor="auto",s.style.left="calc(50% - 75px)",s.style.width="150px",s.onmouseenter=null,s.onmouseleave=null,s.onclick=null}function c(){a(),s.textContent="AR NOT SUPPORTED"}function l(u){u.style.position="absolute",u.style.bottom="20px",u.style.padding="12px 6px",u.style.border="1px solid #fff",u.style.borderRadius="4px",u.style.background="rgba(0,0,0,0.1)",u.style.color="#fff",u.style.font="normal 13px sans-serif",u.style.textAlign="center",u.style.opacity="0.5",u.style.outline="none",u.style.zIndex="999"}if("xr"in navigator)return s.id="ARButton",s.style.display="none",l(s),navigator.xr.isSessionSupported("immersive-ar").then(function(u){u?o():c()}).catch(c),s;{const u=document.createElement("a");return window.isSecureContext===!1?(u.href=document.location.href.replace(/^http:/,"https:"),u.innerHTML="WEBXR NEEDS HTTPS"):(u.href="https://immersiveweb.dev/",u.innerHTML="WEBXR NOT AVAILABLE"),u.style.left="calc(50% - 90px)",u.style.width="180px",u.style.textDecoration="none",l(u),u}}}const Gb=class{static createButton(e,t){const i=document.createElement("button");function s(){let c=null;async function l(d){d.addEventListener("end",u),await e.xr.setSession(d),i.textContent="EXIT VR",c=d}function u(){c.removeEventListener("end",u),i.textContent="ENTER VR",c=null}i.style.display="",i.style.cursor="pointer",i.style.left="calc(50% - 50px)",i.style.width="100px",i.textContent="ENTER VR",i.onmouseenter=function(){i.style.opacity="1.0"},i.onmouseleave=function(){i.style.opacity="0.5"},i.onclick=function(){if(c===null){const d={optionalFeatures:t.optionalFeatures};navigator.xr.requestSession("immersive-vr",d).then(l)}else c.end()}}function r(){i.disabled=!0,i.style.display="",i.style.cursor="auto",i.style.left="calc(50% - 75px)",i.style.width="150px",i.onmouseenter=null,i.onmouseleave=null,i.onclick=null}function o(){r(),i.textContent="VR NOT SUPPORTED"}function a(c){c.style.position="absolute",c.style.bottom="20px",c.style.padding="12px 6px",c.style.border="1px solid #fff",c.style.borderRadius="4px",c.style.background="rgba(0,0,0,0.1)",c.style.color="#fff",c.style.font="normal 13px sans-serif",c.style.textAlign="center",c.style.opacity="0.5",c.style.outline="none",c.style.zIndex="999"}if("xr"in navigator)return i.id="VRButton",i.style.display="none",a(i),navigator.xr.isSessionSupported("immersive-vr").then(function(c){c?s():o(),Gb.xrSessionIsGranted&&(console.log("XR session is granted - will enter immersive web now"),i.click())}),i;{const c=document.createElement("a");return window.isSecureContext===!1?(c.href=document.location.href.replace(/^http:/,"https:"),c.innerHTML="WEBXR NEEDS HTTPS"):(c.href="https://immersiveweb.dev/",c.innerHTML="WEBXR NOT AVAILABLE"),c.style.left="calc(50% - 90px)",c.style.width="180px",c.style.textDecoration="none",a(c),c}}static registerSessionGrantedListener(){if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent))return;navigator.xr.addEventListener("sessiongranted",()=>{Gb.xrSessionIsGranted=!0})}}};let rm=Gb;h(rm,"xrSessionIsGranted",!1);rm.registerSessionGrantedListener();var hne=Object.defineProperty,une=Object.getOwnPropertyDescriptor,CI=(n,e,t,i)=>{for(var s=i>1?void 0:i?une(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&hne(e,t,s),s};const dne=new Me;class ca extends Ie{constructor(){super(...arguments);h(this,"webAR",null);h(this,"invertForward",!1);h(this,"arTouchTransform",!1);h(this,"_initalMatrix",new Me);h(this,"_selectStartFn",this.onSelectStart.bind(this));h(this,"_selectEndFn",this.onSelectEnd.bind(this));h(this,"userInput");h(this,"_arScale",1);h(this,"_rig",null);h(this,"_startPose",null);h(this,"_placementPose",null);h(this,"_isTouching",!1);h(this,"_rigStartPose",null);h(this,"_gotFirstHitTestResult",!1);h(this,"_anchor",null);h(this,"_anchorMatrix",new Me);h(this,"_invertedSessionRootMatrix",new Me);h(this,"_invertForwardMatrix",new Me().makeRotationY(Math.PI))}get rig(){var t;return(t=this.webAR)==null?void 0:t.webxr.Rig}get arScale(){return this._arScale}set arScale(t){t!==this._arScale&&(this._arScale=t,this.setScale(t))}start(){const t=ne.findObjectOfType(It);t&&(t.Rig.updateMatrix(),this._initalMatrix.copy(t.Rig.matrix))}onBegin(t){var i;this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose=this.gameObject.matrix.clone(),this._rigStartPose=(i=this.rig)==null?void 0:i.matrix.clone(),this._gotFirstHitTestResult=!1,this._anchor=null,t.addEventListener("selectstart",this._selectStartFn),t.addEventListener("selectend",this._selectEndFn),this.gameObject.visible=!1,this.rig&&(this.rig.matrixAutoUpdate=!0,this._initalMatrix.decompose(this.rig.position,this.rig.quaternion,this.rig.scale)),this.dispatchEvent(new CustomEvent("onBeginSession"))}onUpdate(t,i,s,r){if(r&&!this._placementPose&&(this._gotFirstHitTestResult||(this._gotFirstHitTestResult=!0,this.dispatchEvent(new CustomEvent("canPlaceSession",{detail:{pose:r}}))),this._isTouching)){const o=new Me().fromArray(r.transform.matrix).invert();return this.dispatchEvent(new CustomEvent("placedSession",{detail:{pose:r,poseMatrix:o}})),this.webAR&&this.webAR.setReticleActive(!1),this.placeAt(t,o),s&&r&&this.onCreatePlacementAnchor(s,r),!0}return!1}onCreatePlacementAnchor(t,i){var s,r;this._anchor=null,(r=(s=t==null?void 0:t.createAnchor)==null?void 0:s.call(t,i.transform))==null||r.then(o=>{this.context.isInAR&&(this._anchor=o)})}onBeforeRender(t){if(t&&this._rig)if(this._anchor){const i=this.context.renderer.xr.getReferenceSpace();if(i){const s=t.getPose(this._anchor.anchorSpace,i);if(s){const r=this._anchorMatrix.fromArray(s.transform.matrix).invert();this.placeAt(this._rig,r);return}}}else this._placementPose&&this.placeAt(this._rig,this._placementPose)}placeAt(t,i){this._placementPose||(this._placementPose=new Me),this._placementPose.copy(i);const s=this._invertedSessionRootMatrix.copy(this.gameObject.matrixWorld).invert();this._placementPose.premultiply(s),t?(this.invertForward&&this._placementPose.premultiply(this._invertForwardMatrix),this.userInput||(this.userInput=new $d(this.context)),this.userInput.enable(),this._rig=t,this.setScale(this.arScale)):this._rig=null,this.gameObject.visible=!0}onEnd(t,i){var s,r;(s=this.userInput)==null||s.disable(),(r=this.userInput)==null||r.reset(),this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._anchor=null,this._startPose&&this.gameObject.matrix.copy(this._startPose),t&&(t.matrixAutoUpdate=!0,this._rigStartPose&&this._rigStartPose.decompose(t.position,t.quaternion,t.scale)),Sr.markDirty(this.gameObject,!0),setTimeout(()=>{this.gameObject&&(this.gameObject.matrixAutoUpdate=!0,this.gameObject.visible=!0)},100)}onSelectStart(){this._isTouching=!0}onSelectEnd(){this._isTouching=!1}setScale(t){const i=this._rig;!i||!this._placementPose||(this._rigStartPose||(this._rigStartPose=i.matrix.clone()),i.matrixAutoUpdate=!1,this.arTouchTransform&&this.userInput&&this.userInput.applyMatrixTo(this._placementPose),i.matrix.multiplyMatrices(dne.makeScale(t,t,t),this._placementPose),i.matrix.decompose(i.position,i.quaternion,i.scale),i.updateMatrixWorld())}}CI([x()],ca.prototype,"invertForward",2);CI([x()],ca.prototype,"arTouchTransform",2);CI([x()],ca.prototype,"arScale",1);const Hb=class{constructor(e){h(this,"oneFingerDrag",!0);h(this,"twoFingerRotate",!0);h(this,"twoFingerScale",!0);h(this,"context");h(this,"offset");h(this,"plane");h(this,"_scale",1);h(this,"_enabled",!1);h(this,"prev",new Map);h(this,"_didMultitouch",!1);h(this,"touchStart",e=>{for(let t=0;t<e.changedTouches.length;t++){const i=e.changedTouches[t];this.prev.has(i.identifier)||this.prev.set(i.identifier,{x:0,z:0,screenx:0,screeny:0});const s=this.prev.get(i.identifier);if(s){const r=this.getPositionOnPlane(i.clientX,i.clientY);s.x=r.x,s.z=r.z,s.screenx=i.clientX,s.screeny=i.clientY}}});h(this,"touchEnd",e=>{e.touches.length<=0&&(this._didMultitouch=!1)});h(this,"touchMove",e=>{if(!e.defaultPrevented){if(e.touches.length===1){if(this._didMultitouch)return;const t=e.touches[0],i=this.prev.get(t.identifier);if(!i)return;const s=this.getPositionOnPlane(t.clientX,t.clientY),r=s.x-i.x,o=s.z-i.z;if(r===0&&o===0)return;this.oneFingerDrag&&this.addMovement(r,o),i.x=s.x,i.z=s.z,i.screenx=t.clientX,i.screeny=t.clientY;return}else if(e.touches.length===2){this._didMultitouch=!0;const t=e.touches[0],i=e.touches[1],s=this.prev.get(t.identifier),r=this.prev.get(i.identifier);if(!s||!r)return;if(this.twoFingerRotate){const o=Math.atan2(t.clientY-i.clientY,t.clientX-i.clientX),a=Math.atan2(s.screeny-r.screeny,s.screenx-r.screenx),c=o-a;Math.abs(c)>.001&&this.addRotation(c)}if(this.twoFingerScale){const o=t.clientX-i.clientX,a=t.clientY-i.clientY,c=Math.sqrt(o*o+a*a),l=s.screenx-r.screenx,u=s.screeny-r.screeny,d=Math.sqrt(l*l+u*u),f=c-d;Math.abs(f)>2&&this.addScale(f)}s.screenx=t.clientX,s.screeny=t.clientY,r.screenx=i.clientX,r.screeny=i.clientY}}});h(this,"_raycaster",new Uu);h(this,"_intersection",new w);h(this,"_screenPos",new w);h(this,"_tempMatrix",new Me);this.context=e,this.offset=new Me,this.plane=new Qr,this.plane.setFromNormalAndCoplanarPoint(Hb.up,Hb.zero)}enable(){this._enabled||(this._enabled=!0,window.addEventListener("touchstart",this.touchStart,{passive:!1}),window.addEventListener("touchmove",this.touchMove,{passive:!1}),window.addEventListener("touchend",this.touchEnd,{passive:!1}))}disable(){this._enabled&&(this._enabled=!1,window.removeEventListener("touchstart",this.touchStart),window.removeEventListener("touchmove",this.touchMove),window.removeEventListener("touchend",this.touchEnd))}reset(){this._scale=1,this.offset.identity()}applyMatrixTo(e){e.premultiply(this.offset)}getPositionOnPlane(e,t){const i=this.context.mainCamera;return this._screenPos.x=e/window.innerWidth*2-1,this._screenPos.y=-(t/window.innerHeight)*2+1,this._screenPos.z=1,this._screenPos.unproject(i),this._raycaster.set(i.position,this._screenPos.sub(i.position)),this._raycaster.ray.intersectPlane(this.plane,this._intersection),this._intersection}addMovement(e,t){e*=.75,t*=.75,e/=this._scale,t/=this._scale,this.offset.elements[12]-=e,this.offset.elements[14]-=t}addScale(e){e/=window.innerWidth,this._scale*=1+e,this._tempMatrix.makeScale(1-e,1-e,1-e),this.offset.premultiply(this._tempMatrix)}addRotation(e){this._tempMatrix.makeRotationY(e),this.offset.premultiply(this._tempMatrix)}};let $d=Hb;h($d,"up",new w(0,1,0)),h($d,"zero",new w(0,0,0)),h($d,"one",new w(1,1,1));const fne=re("debugrig");class Ix extends Ie{awake(){if(fne){const e=new Te;e.position.y+=.5,this.gameObject.add(e);const t=e.addNewComponent(Qu);t&&(t.isGizmo=!1)}}}class Mf{constructor(){h(this,"bb",null);h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,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(e,t,i,s,r){return e.prep(4,16),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(i),e.writeFloat32(t),e.offset()}}class Ms{constructor(){h(this,"bb",null);h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsVrUserStateBuffer(e,t){return(t||new Ms).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsVrUserStateBuffer(e,t){return e.setPosition(e.position()+L_),(t||new Ms).__init(e.readInt32(e.position())+e.position(),e)}guid(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}time(){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):this.bb.createLong(0,0)}avatarId(e){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__string(this.bb_pos+t,e):null}position(e){const t=this.bb.__offset(this.bb_pos,10);return t?(e||new Zr).__init(this.bb_pos+t,this.bb):null}rotation(e){const t=this.bb.__offset(this.bb_pos,12);return t?(e||new Mf).__init(this.bb_pos+t,this.bb):null}scale(){const e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readFloat32(this.bb_pos+e):0}posLeftHand(e){const t=this.bb.__offset(this.bb_pos,16);return t?(e||new Zr).__init(this.bb_pos+t,this.bb):null}posRightHand(e){const t=this.bb.__offset(this.bb_pos,18);return t?(e||new Zr).__init(this.bb_pos+t,this.bb):null}rotLeftHand(e){const t=this.bb.__offset(this.bb_pos,20);return t?(e||new Mf).__init(this.bb_pos+t,this.bb):null}rotRightHand(e){const t=this.bb.__offset(this.bb_pos,22);return t?(e||new Mf).__init(this.bb_pos+t,this.bb):null}static startVrUserStateBuffer(e){e.startObject(10)}static addGuid(e,t){e.addFieldOffset(0,t,0)}static addTime(e,t){e.addFieldInt64(1,t,e.createLong(0,0))}static addAvatarId(e,t){e.addFieldOffset(2,t,0)}static addPosition(e,t){e.addFieldStruct(3,t,0)}static addRotation(e,t){e.addFieldStruct(4,t,0)}static addScale(e,t){e.addFieldFloat32(5,t,0)}static addPosLeftHand(e,t){e.addFieldStruct(6,t,0)}static addPosRightHand(e,t){e.addFieldStruct(7,t,0)}static addRotLeftHand(e,t){e.addFieldStruct(8,t,0)}static addRotRightHand(e,t){e.addFieldStruct(9,t,0)}static endVrUserStateBuffer(e){return e.endObject()}static finishVrUserStateBufferBuffer(e,t){e.finish(t)}static finishSizePrefixedVrUserStateBufferBuffer(e,t){e.finish(t,void 0,!0)}}const wO=re("debugxr"),hg=re("debugavatar"),EI="VRUS";F_(EI,Ms.getRootAsVrUserStateBuffer);function pM(){return new Date().getTime()}function pne(n){const e=n&4294967295,t=n/Math.pow(2,32)&1048575;return Ga.create(e,t)}const Am=class{constructor(e){h(this,"guid");h(this,"time");h(this,"avatarId");h(this,"position",new w);h(this,"rotation",new et);h(this,"scale",1);h(this,"posLeftHand",new w);h(this,"posRightHand",new w);h(this,"rotLeftHand",new we);h(this,"rotRightHand",new we);this.guid=e}update(e,t,i,s,r){var u,d,f,p,g,A;this.time=pM(),this.avatarId=r,this.position.set(t.x,t.y,t.z),e&&this.position.applyMatrix4(e.matrixWorld);let o=Am.quat0;const a=Am.quat1;o.set(i.x,i.y,i.z,i.w),o=o.multiplyQuaternions(o,Am.invertRotation),e&&(e.getWorldQuaternion(a),o.multiplyQuaternions(a,o)),this.rotation.set(o.x,o.y,o.z,o.w),this.scale=e.scale.x;const c=(u=s.LeftController)==null?void 0:u.controllerGrip;c&&(c.getWorldPosition(this.posLeftHand),c.getWorldQuaternion(this.rotLeftHand));const l=(d=s.RightController)==null?void 0:d.controllerGrip;if(l&&(l.getWorldPosition(this.posRightHand),l.getWorldQuaternion(this.rotRightHand)),(p=(f=s.LeftController)==null?void 0:f.hand)!=null&&p.visible){const v=s.LeftController.wrist;v&&(v.getWorldPosition(this.posLeftHand),v.getWorldQuaternion(this.rotLeftHand))}if((A=(g=s.RightController)==null?void 0:g.hand)!=null&&A.visible){const v=s.RightController.wrist;v&&(v.getWorldPosition(this.posRightHand),v.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(e,t){e.clear();const i=e.createString(this.guid),s=e.createString(this.avatarId);Ms.startVrUserStateBuffer(e),Ms.addGuid(e,i),Ms.addTime(e,pne(this.time)),Ms.addAvatarId(e,s),Ms.addPosition(e,Zr.createVec3(e,this.position.x,this.position.y,this.position.z)),Ms.addRotation(e,Mf.createVec4(e,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),Ms.addScale(e,this.scale),Ms.addPosLeftHand(e,Zr.createVec3(e,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),Ms.addPosRightHand(e,Zr.createVec3(e,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),Ms.addRotLeftHand(e,Mf.createVec4(e,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),Ms.addRotRightHand(e,Mf.createVec4(e,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const r=Ms.endVrUserStateBuffer(e);e.finish(r,EI);const o=e.asUint8Array();t.sendBinary(o)}setFromBuffer(e,t){if(!e)return;this.guid=e,this.time=t.time().toFloat64();const i=t.avatarId();i&&(this.avatarId=i);const s=t.position();s&&this.position.set(s.x(),s.y(),s.z());const r=t.rotation();r&&this.rotation.set(r.x(),r.y(),r.z(),r.w());const o=t.posLeftHand();o&&this.posLeftHand.set(o.x(),o.y(),o.z());const a=t.posRightHand();a&&this.posRightHand.set(a.x(),a.y(),a.z());const c=t.rotLeftHand();c&&this.rotLeftHand.set(c.x(),c.y(),c.z(),c.w());const l=t.rotRightHand();l&&this.rotRightHand.set(l.x(),l.y(),l.z(),l.w()),this.scale=t.scale()}};let ta=Am;h(ta,"invertRotation",new we().setFromAxisAngle(new w(0,1,0),Math.PI)),h(ta,"quat0",new we),h(ta,"quat1",new we);class tA extends Ie{constructor(){super(...arguments);h(this,"webXR",null);h(this,"debugAvatarUser",null);h(this,"voip",null);h(this,"tempState",new ta(""));h(this,"_removeAvatarsList",[]);h(this,"eventSub_ConnectionEvent",null);h(this,"eventSub_WebXRStartEvent",null);h(this,"eventSub_WebXREndEvent",null);h(this,"eventSub_WebXRUpdateEvent",null);h(this,"avatars",{});h(this,"localAvatar",null);h(this,"k_LocalAvatarNoNetworkingGuid","local");h(this,"ownership",null);h(this,"xrState",null);h(this,"builder",new ip(1024))}async awake(){if(this.webXR||(this.webXR=ne.getComponent(this.gameObject,It)),this.webXR||(this.webXR=ne.findObjectOfType(It,this.context)),!this.webXR&&(this.webXR=ne.findObjectOfType(It,this.context),!this.webXR)){console.warn("WebXRSync: Could not find WebXR component, won't sync.");return}if(this.voip||(this.voip=ne.findObjectOfType(dl,this.context)),hg){const t="debug-avatar-"+hg,i=new Ua(this.context,t,this.webXR);if(this.debugAvatarUser=i,typeof hg=="string"&&hg.length>0)if(await i.setAvatarOverride(hg)){const s=new ta(t);s.position.y+=1;const r=.5;s.posLeftHand.y+=r,s.posLeftHand.x+=r,s.posRightHand.y+=r,s.posRightHand.x-=r,i.tryUpdate(s,0)}else i.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=ne.getComponent(this.gameObject,It),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),It.addEventListener(Mi.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),It.addEventListener(Mi.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),It.addEventListener(Mi.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen(on.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",t=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",t=>{const i=t.id!==null&&t.id!==void 0;if(i&&(console.log("webxr user left evt"),i)){const s=this.avatars[t.id];s==null||s.destroy(),this.avatars[t.id]=void 0}}),this.context.connection.beginListenBinary(EI,t=>{const i=t.guid();if(!i)return;const s=t.time().toFloat64(),r=this.tempState;r.setFromBuffer(i,t);const o=this.onTryGetAvatar(i,s);o==null||o.tryUpdate(r,s)}),this.context.connection.beginListen("vr-session-update",t=>{const i=t.guid,s=t.time,r=this.onTryGetAvatar(i,s);r==null||r.tryUpdate(t,s)})}onTryGetAvatar(t,i){if(t===this.context.connection.connectionId)return null;const s=new Date().getTime()-i;if(s>5e3)return wO&&console.log("old data",s,t),null;if(!this.webXR)return null;let r=this.avatars[t];if(r===void 0)try{console.log("create new avatar");const o=new Ua(this.context,t,this.webXR);r=o,this.avatars[t]=o}catch(o){this.avatars[t]=null,console.error(o)}return r}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen(on.JoinedRoom,this.eventSub_ConnectionEvent),It.removeEventListener(Mi.XRStarted,this.eventSub_WebXRStartEvent),It.removeEventListener(Mi.XRUpdate,this.eventSub_WebXRUpdateEvent),It.removeEventListener(Mi.XRStopped,this.eventSub_WebXREndEvent)}update(){const t=pM();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=t),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const i in this.avatars){const s=this.avatars[i];s&&s.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const t=pM();for(const i in this.avatars){const s=this.avatars[i];if(!s){this._removeAvatarsList.push(i);continue}t-s.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),s.destroy(),this.avatars[i]=void 0)}for(const i of this._removeAvatarsList)delete this.avatars[i];this._removeAvatarsList.length=0}buildLocalAvatar(){var i;if(this.localAvatar)return;const t=((i=this.context.connection)==null?void 0:i.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new Ua(this.context,t,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var t,i,s;wO&&console.log("Hey you are connected as "+this.context.connection.connectionId),((t=this.localAvatar)==null?void 0:t.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null)}onXRSessionStart(t){var i,s,r;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null,this.avatars)for(const o in this.avatars)(r=this.avatars[o])==null||r.updateFlags()}onXRSessionEnded(t){var i;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(t){this.xrState??(this.xrState=new ta(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new N_(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:i,xr:s,rig:r}=t,o=i.getViewerPose(s.getReferenceSpace());if(!o)return;const a=o==null?void 0:o.transform,c=a.position,l=a.orientation;this.xrState.update(r,c,l,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 re("avatar")??null}}var gne=Object.defineProperty,mne=Object.getOwnPropertyDescriptor,Tp=(n,e,t,i)=>{for(var s=i>1?void 0:i?mne(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&gne(e,t,s),s};const jS=re("debugwebxr");async function jz(){return tb()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function Xz(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let Og=!1,kg=!1;jz().then(n=>Og=n);Xz().then(n=>kg=n);var Mi=(n=>(n.XRStarted="xrStarted",n.XRStopped="xrStopped",n.XRUpdate="xrUpdate",n.RequestVRSession="requestVRSession",n.ModifyAROptions="modify-ar-options",n))(Mi||{}),Wd;const kn=(Wd=class extends Ie{constructor(){super(...arguments);h(this,"enableVR",!0);h(this,"enableAR",!0);h(this,"defaultAvatar");h(this,"handModelPath","");h(this,"createVRButton",!0);h(this,"createARButton",!0);h(this,"controllers",[]);h(this,"rig");h(this,"isInit",!1);h(this,"_requestedAR",!1);h(this,"_requestedVR",!1);h(this,"_isInAR",!1);h(this,"_isInVR",!1);h(this,"_arButton");h(this,"_vrButton");h(this,"webAR",null);h(this,"_transformOrientation",new we);h(this,"_currentHeadPose",null);h(this,"_originalCameraParent",null);h(this,"_originalCameraPosition",new w);h(this,"_originalCameraRotation",new we);h(this,"_originalXRRigParent",null);h(this,"_originalXRRigPosition",new w);h(this,"_originalXRRigRotation",new we);h(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(Og||kg)}static get IsARSupported(){return Og}static get IsVRSupported(){return kg}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(e,t){return this.events.addEventListener(e,t),t}static removeEventListener(e,t){return this.events.removeEventListener(e,t),t}static dispatchEvent(e,t){this.events.dispatchEvent({type:e,detail:t})}static createVRButton(e,t){kn.XRSupported?e.__internalAwake():console.warn("WebXR is not supported on this device");const i={optionalFeatures:kn.OptionalFeatures_VR},s=rm.createButton(e.context.renderer,i);return s.classList.add("webxr-ar-button"),s.classList.add("webxr-button"),this.resetButtonStyles(s),((t==null?void 0:t.registerClick)??!0)&&s.addEventListener("click",e.onClickedVRButton.bind(e)),s}static createARButton(e,t){var o;e.__internalAwake();const i=(o=e.webAR)==null?void 0:o.getAROverlayContainer(),s={optionalFeatures:[...this.OptionalFeatures_AR]};i?(s.domOverlay={root:i},s.optionalFeatures.push("dom-overlay"),s.optionalFeatures.push("hit-test"),s.optionalFeatures.push("anchors")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const r=lne.createButton(e.context.renderer,s,this.onModifyAROptions.bind(this));return r.classList.add("webxr-ar-button"),r.classList.add("webxr-button"),kn.resetButtonStyles(r),((t==null?void 0:t.registerClick)??!0)&&r.addEventListener("click",e.onClickedARButton.bind(e)),r}static onModifyAROptions(e){kn.dispatchEvent("modify-ar-options",e)}static resetButtonStyles(e){e&&(e.style.position="",e.style.bottom="",e.style.left="")}endSession(){const e=this.context.renderer.xr.getSession();e&&e.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var e,t;return this.controllers.length>0&&((e=this.controllers[0].input)==null?void 0:e.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((t=this.controllers[1].input)==null?void 0:t.handedness)==="left"?this.controllers[1]:null}get RightController(){var e,t;return this.controllers.length>0&&((e=this.controllers[0].input)==null?void 0:e.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((t=this.controllers[1].input)==null?void 0:t.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=Tn.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!ne.findObjectOfType(tA,this.context)){const e=ne.addNewComponent(this.gameObject,tA,!1);e.webXR=this}this.webAR=new Su(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(Ls("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,kn.XRSupported;let e,t;const i=document.createElement("div");i.classList.add("webxr-buttons"),i.style.cssText=`
|
|
5182
5182
|
position: absolute;
|
|
5183
5183
|
bottom: 21px;
|
|
5184
5184
|
left: 50%;
|