@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:`,t),this.setLightmapDebugMaterial()),this.applyLightmap())}updateLightm
|
|
|
4489
4489
|
gl_FragColor = lightMapTexel;
|
|
4490
4490
|
gl_FragColor.a = 1.;
|
|
4491
4491
|
}
|
|
4492
|
-
`,defines:{USE_LIGHTMAP:""}})}}const JE=function(i){return D(i)},D=function(i){if(i===void 0&&(i=null),!Array.isArray(i))i=Dq(i);else for(let A=0;A<i.length;A++){const e=i[A];i[A]=Dq(e)}return function(A,e){typeof e!="string"&&(e=e.name),Object.getOwnPropertyDescriptor(A,"$serializedTypes")||(A.$serializedTypes={});const t=A.$serializedTypes=A.$serializedTypes||{};t[e]=i}};function Dq(i){var A,e;switch((e=(A=i==null?void 0:i.prototype)==null?void 0:A.constructor)==null?void 0:e.name){case"Number":case"String":case"Boolean":return null}return i}class St extends SA{constructor(e,t,g,I){super(e,t,g);r(this,"alpha",1);this.alpha=I}get isRGBAColor(){return!0}set a(e){this.alpha=e}get a(){return this.alpha}clone(){const e=super.clone();return e.alpha=this.alpha,e}copy(e){return super.copy(e),"alpha"in e&&typeof e.alpha=="number"?this.alpha=e.alpha:typeof e.a=="number"&&(this.alpha=e.a),this}lerp(e,t){const g=e;return g.alpha&&(this.alpha=ie.lerp(this.alpha,g.alpha,t)),super.lerp(e,t)}lerpColors(e,t,g){const I=e,o=t;return I.alpha&&o.alpha&&(this.alpha=ie.lerp(I.alpha,o.alpha,g)),super.lerpColors(e,t,g)}multiply(e){const t=e;return t.alpha&&(this.alpha=this.alpha*t.alpha),super.multiply(e)}fromArray(e,t=0){return this.alpha=e[t+3],super.fromArray(e,t)}}class QE{constructor(A,e){r(this,"method");r(this,"enabled");this.method=A,this.enabled=e!==void 0?e:!0}invoke(...A){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(...A)}}}const c6=i=>/^[A-Z]*$/.test(i);class ey extends Event{constructor(){super(...arguments);r(this,"args")}}class Dg{constructor(A){r(this,"target");r(this,"key");r(this,"_isInvoking",!1);r(this,"methods",[]);this.methods=A??[]}setEventTarget(A,e){if(this.key=A,this.target=e,this.key!==void 0){let t="",g=!1;for(const I of this.key)g&&c6(I)&&(t+="-"),g=!0,t+=I.toLowerCase();this.key=t}}invoke(...A){if(this._isInvoking)
|
|
4492
|
+
`,defines:{USE_LIGHTMAP:""}})}}const JE=function(i){return D(i)},D=function(i){if(i===void 0&&(i=null),!Array.isArray(i))i=Dq(i);else for(let A=0;A<i.length;A++){const e=i[A];i[A]=Dq(e)}return function(A,e){typeof e!="string"&&(e=e.name),Object.getOwnPropertyDescriptor(A,"$serializedTypes")||(A.$serializedTypes={});const t=A.$serializedTypes=A.$serializedTypes||{};t[e]=i}};function Dq(i){var A,e;switch((e=(A=i==null?void 0:i.prototype)==null?void 0:A.constructor)==null?void 0:e.name){case"Number":case"String":case"Boolean":return null}return i}class St extends SA{constructor(e,t,g,I){super(e,t,g);r(this,"alpha",1);this.alpha=I}get isRGBAColor(){return!0}set a(e){this.alpha=e}get a(){return this.alpha}clone(){const e=super.clone();return e.alpha=this.alpha,e}copy(e){return super.copy(e),"alpha"in e&&typeof e.alpha=="number"?this.alpha=e.alpha:typeof e.a=="number"&&(this.alpha=e.a),this}lerp(e,t){const g=e;return g.alpha&&(this.alpha=ie.lerp(this.alpha,g.alpha,t)),super.lerp(e,t)}lerpColors(e,t,g){const I=e,o=t;return I.alpha&&o.alpha&&(this.alpha=ie.lerp(I.alpha,o.alpha,g)),super.lerpColors(e,t,g)}multiply(e){const t=e;return t.alpha&&(this.alpha=this.alpha*t.alpha),super.multiply(e)}fromArray(e,t=0){return this.alpha=e[t+3],super.fromArray(e,t)}}class QE{constructor(A,e){r(this,"method");r(this,"enabled");this.method=A,this.enabled=e!==void 0?e:!0}invoke(...A){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(...A)}}}const c6=i=>/^[A-Z]*$/.test(i);class ey extends Event{constructor(){super(...arguments);r(this,"args")}}class Dg{constructor(A){r(this,"target");r(this,"key");r(this,"_isInvoking",!1);r(this,"methods",[]);this.methods=A??[]}setEventTarget(A,e){if(this.key=A,this.target=e,this.key!==void 0){let t="",g=!1;for(const I of this.key)g&&c6(I)&&(t+="-"),g=!0,t+=I.toLowerCase();this.key=t}}get listenerCount(){var A;return((A=this.methods)==null?void 0:A.length)??0}invoke(...A){var e;if(this._isInvoking)return console.warn("Circular event invocation detected. Please check your event listeners for circular references.",this),!1;if(((e=this.methods)==null?void 0:e.length)<=0)return!1;this._isInvoking=!0;try{for(const t of this.methods)t.invoke(...A);if(typeof this.target=="object"&&typeof this.key=="string"){const t=this.target.dispatchEvent;if(typeof t=="function"){const g=new ey(this.key);g.args=A,t.call(this.target,g)}}}finally{this._isInvoking=!1}return!0}addEventListener(A){return this.methods.push(new QE(A,!0)),A}removeEventListener(A){if(A)for(let e=this.methods.length-1;e>=0;e--)this.methods[e].method===A&&(this.methods[e].enabled=!1,this.methods.splice(e,1))}removeAllEventListeners(){this.methods.length=0}}const wq=Symbol("previous-visibility"),qQ=class extends at{render(A,e,t){if(t instanceof yR)this._unsupported_effectcomposer_warning||(console.warn("RenderTexture.render() does not yet support EffectComposer"),this._unsupported_effectcomposer_warning=!0);else{this.onBeforeRender();const g=t.getRenderTarget(),I=t.xr.enabled;t.xr.enabled=!1,t.setRenderTarget(this),t.clear(!0,!0,!0),t.render(A,e),t.setRenderTarget(g),t.xr.enabled=I,this.onAfterRender()}}onBeforeRender(){qQ._userSet.clear();const A=lR(this.texture,!0,null,qQ._userSet);for(const e of A)e instanceof wA&&(e[wq]=e.visible,e.visible=!1)}onAfterRender(){for(const A of qQ._userSet)A instanceof wA&&(A.visible=A[wq]);qQ._userSet.clear()}};let ua=qQ;r(ua,"_userSet",new Set);class h6 extends xa{constructor(){super([SA,St])}onDeserialize(A){if(A!=null)return A.a!==void 0?new St(A.r,A.g,A.b,A.a):A.alpha!==void 0?new St(A.r,A.g,A.b,A.alpha):new SA(A.r,A.g,A.b)}onSerialize(A){if(A!=null)return A.a!==void 0?{r:A.r,g:A.g,b:A.b,a:A.a}:{r:A.r,g:A.g,b:A.b}}}const l6=new h6;class d6 extends xa{constructor(){super(FA)}onSerialize(A,e){if(e.objectToNode!==void 0&&A.uuid){const t=e.objectToNode[A.uuid];return Tg&&console.log(t,A.name,A.uuid),{node:t}}}onDeserialize(A,e){var t,g,I;if(typeof A=="string"){(A.endsWith(".glb")||A.endsWith(".gltf"))&&(rt()&&Wg("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 "`+e.path+'" in your script "'+((g=(t=e.target)==null?void 0:t.constructor)==null?void 0:g.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",A,!0),this._newLineBreakability=null}update(A,e){this._needsProcess=!0}process(A){const e=A._whiteSpace._newLineBreakability;if(A._inlines._value)for(let t=0;t<A._inlines._value.length;t++){const g=A._inlines._value[t],I=g.char;let o=null;I!==void 0&&(e!=="nowrap"&&(this._value.includes(I)||I.match(/\s/g))&&(o="possible"),I.match(/\n/g)&&(o=e)),g.lineBreak=o}}get value(){return this._value}}class j_ extends Dt{constructor(){super("layouter",null,!1),this._value=null}update(A,e){this._value=A._parent.find(t=>t.isUI&&t.isText),this._needsProcess=!0}process(A){this._value&&(this._value._layouter._needsProcess=!0)}}class EtA extends fl{constructor(A){super("backgroundColor",A,!1),this._allowsInherit=!1,this._input=0}computeOutputValue(A){this._input==="inherit"?this._value.set(this.getInheritedInput(A)):this._value.set(this._input)}}class Z_ extends XH{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class X_ extends $H{constructor(){super()}computeOutputValue(A){this._value=VR(this.getInheritedInput(A))}}class $_ extends o_{constructor(){super("fontFamily","inherit",!0),this._input="inherit",this._needsUpdate=!0,this._allowsInherit=!1}computeOutputValue(A){let e=this._inheritedInput;if(e==="inherit"&&(e=this.getInheritedInput(A)),e instanceof ry)this._value=e,A._font._needsUpdate=!0;else if(typeof e=="string"){const t=AB.getFontFamily(e);t?(this._value=t,A._font._needsUpdate=!0):console.warn(`(.style) fontFamily, the font '${e}' is not registered. Aborted.`)}else console.warn("(.style) fontFamily requires a registered fontFamily instance, or the id of a registered fontFamily."),console.warn("If you want to set a specific font, please use .font property instead.")}get value(){return this._value}}class fU extends C_{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited,this._whiteSpacedContent="",this._stringCollapser=this.emptyStrategyLogic,this._inlineCollapser=this.emptyStrategyLogic,this._inlineWrapper=this.emptyStrategyLogic}_computeFromInherited(A){switch(super._computeFromInherited(A),this._newLineBreakability=ctA(this._value),this._value){case"nowrap":case"normal":this._stringCollapser=htA;break;case"pre-line":this._stringCollapser=A2;break;default:this._stringCollapser=ltA}switch(this._value){case"pre-line":case"nowrap":case"normal":this._inlineCollapser=DtA;break;case"pre-wrap":this._inlineCollapser=ftA;break;default:this._inlineCollapser=wtA}switch(this._value){case"pre-line":case"pre-wrap":case"normal":this._inlineWrapper=dtA;break;case"pre":this._inlineWrapper=utA;break;default:this._inlineWrapper=ptA}this._needsProcess=!0}process(A){A.isInline&&!A.isInlineBlock&&(this._whiteSpacedContent=this._stringCollapser(A._textContent._value),A._glyphs._needsProcess=!0)}}const ev={" ":" ","\n":`
|
|
5070
5070
|
`,"\r":"\r"," ":" "},ctA=function(i){switch(i){case"pre":case"pre-wrap":case"pre-line":return"mandatory"}return null};function htA(i){return A2(i.replace(/\n/g," "))}function A2(i){return i.replace(/[ ]{2,}/g," ")}function ltA(i){return i}function dtA(i,A,e,t){const g=i[A];if(g.lineBreak==="mandatory"||e+g.xadvance+g.xoffset+g.kerning>t.INNER_WIDTH)return!0;const I=i2(i,A,t);return ytA(i[A-1],e,I,t)}function utA(i,A,e,t){return i[A].lineBreak==="mandatory"}function ptA(){return!1}function ftA(i){if(!i[0])return 0;const A=i[0],e=i[i.length-1];return A.char&&A.char===`
|
|
5071
5071
|
`&&i.length>1&&t2([A],i[1]),e.char&&e.char===`
|
|
5072
|
-
`&&i.length>1&&e2([e],i[i.length-2]),A.offsetX}function DtA(i){if(!i[0])return 0;let A=[],e;for(let t=0;t<i.length;t++){const g=i[t];if(g.char&&ev[g.char]&&i.length>t){A.push(g),e=i[t+1];continue}break}t2(A,e),A=[],e=null;for(let t=i.length-1;t>0;t--){const g=i[t];if(g.char&&ev[g.char]&&t>0){A.push(g),e=i[t-1];continue}break}return e2(A,e),i[0].offsetX}function wtA(i){return i[0]?i[0].offsetX:0}function e2(i,A){if(A)for(let e=0;e<i.length;e++){const t=i[e];t.fontFactor=0,t.offsetX=A.offsetX+A.cumulativeWidth,t.cumulativeWidth=0}}function t2(i,A){if(A)for(let e=0;e<i.length;e++){const t=i[e];t.fontFactor=0,t.offsetX=A.offsetX,t.cumulativeWidth=0}}function i2(i,A,e,t){if(t=t||0,!i[A])return t;const g=i[A];return g.lineBreak?t+g.xadvance:i2(i,A+1,e,t+g.xadvance+g.xoffset+g.kerning+e.LETTERSPACING)}function ytA(i,A,e,t){return!i||!i.char||A+e<t.INNER_WIDTH?!1:t.BREAKON.indexOf(i.char)>-1}class g2 extends n_{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._fontSize._needsProcess=!0,A._layouter._needsProcess=!0}}class I2 extends Zt{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(A){this._value=this._inheritedInput,A._font._fontVariant&&(A._bounds._needsProcess=!0,A._layouter._needsProcess=!0)}process(A){if(!A._font._fontVariant||!A._font._fontVariant.isReady)return;const e=this._value/A._font._fontVariant.typographic.size,t=A._inlines._value;for(let g=0;g<t.length;g++){const I=t[g];I.resetOffsets(),I.fontSize=this._value,I.fontFactor=e}}get value(){return this._value}}class o2 extends a_{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(A,e){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(A)),A._layouter._needsUpdate=!0}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class StA extends o2{constructor(){super(),this._value="inherit"}}class ktA extends By{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._parent._value._layouter._needsProcess=!1}process(A){if(this._value!=="none"){const e=A._whiteSpace._whiteSpacedContent,t=A._inlines._value;for(let g=1;g<t.length;g++){const I=e[g-1]+e[g];t[g].kerning=A._font._fontVariant.getKerningAmount(I)}}}}class s2 extends Dt{constructor(){super("children",null,!1),this._uis=[]}update(A,e){}process(A){}_compute(A){}dispose(){}}function GtA(i,A=!1){const e=i[0].index!==null,t=new Set(Object.keys(i[0].attributes)),g=new Set(Object.keys(i[0].morphAttributes)),I={},o={},s=i[0].morphTargetsRelative,C=new _A.BufferGeometry;let n=0;for(let a=0;a<i.length;++a){const B=i[a];let Q=0;if(e!==(B.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const E in B.attributes){if(!t.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+'. All geometries must have compatible attributes; make sure "'+E+'" attribute exists among all geometries, or in none of them.'),null;I[E]===void 0&&(I[E]=[]),I[E].push(B.attributes[E]),Q++}if(Q!==t.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". Make sure all geometries have the same number of attributes."),null;if(s!==B.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const E in B.morphAttributes){if(!g.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". .morphAttributes must be consistent throughout all geometries."),null;o[E]===void 0&&(o[E]=[]),o[E].push(B.morphAttributes[E])}if(C.userData.mergedUserData=C.userData.mergedUserData||[],C.userData.mergedUserData.push(B.userData),A){let E;if(e)E=B.index.count;else if(B.attributes.position!==void 0)E=B.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". The geometry must have either an index or a position attribute"),null;C.addGroup(n,E,a),n+=E}}if(e){let a=0;const B=[];for(let Q=0;Q<i.length;++Q){const E=i[Q].index;for(let c=0;c<E.count;++c)B.push(E.getX(c)+a);a+=i[Q].attributes.position.count}C.setIndex(B)}for(const a in I){const B=tv(I[a]);if(!B)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+a+" attribute."),null;C.setAttribute(a,B)}for(const a in o){const B=o[a][0].length;if(B===0)break;C.morphAttributes=C.morphAttributes||{},C.morphAttributes[a]=[];for(let Q=0;Q<B;++Q){const E=[];for(let l=0;l<o[a].length;++l)E.push(o[a][l][Q]);const c=tv(E);if(!c)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+a+" morphAttribute."),null;C.morphAttributes[a].push(c)}}return C}function tv(i){let A,e,t,g=0;for(let s=0;s<i.length;++s){const C=i[s];if(C.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(A===void 0&&(A=C.array.constructor),A!==C.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=C.itemSize),e!==C.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(t===void 0&&(t=C.normalized),t!==C.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;g+=C.array.length}const I=new A(g);let o=0;for(let s=0;s<i.length;++s)I.set(i[s].array,o),o+=i[s].array.length;return new _A.BufferAttribute(I,e,t)}class mtA extends Dt{constructor(){super("renderer")}render(A){if(!A._inlines._value||!A._inlines._value.length)return;const e=A._inlines._value.map(g=>A._font._fontVariant.getGeometricGlyph(g,A).translate(g.offsetX,g.offsetY,0)),t=GtA(e);A.setFontMesh(new _A.Mesh(t,A.fontMaterial)),A._fontMesh.renderOrder=1/0}}class MtA extends jR{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(A){this._value=this._inheritedInput,A._layouter._needsProcess=!0}}class hE extends wd{constructor(e={}){const t={};hE.definePropertiesValues(t,e);super(t,e);r(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0});hE.init(this)}add(e){const t=[];for(let g=0;g<arguments.length;g++){const I=arguments[g];!I.isUI||I.isInline?(t.push(I),I.position.z=.005):console.warn("Block element can only contain Box elements.",I)}return super.add(...t)}set textContent(e){this._textContent.value=e}get textContent(){return this._textContent._value}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(e,t){e.children||(e.children=s2),e.textContent||(e.textContent=atA),e.glyphs||(e.glyphs=BtA),e.inlines||(e.inlines=rtA),e.layouter||(e.layouter=j_),e.renderer||(e.renderer=mtA),e.fontFamily||(e.fontFamily=$_),e.fontWeight||(e.fontWeight=X_),e.fontStyle||(e.fontStyle=Z_),e.fontSize||(e.fontSize=I2),e.color||(e.color=QtA),e.backgroundColor||(e.backgroundColor=EtA),e.lineBreak||(e.lineBreak=z_),e.letterSpacing||(e.letterSpacing=g2),e.whiteSpace||(e.whiteSpace=fU),e.segments||(e.segments=StA),e.textAlign||(e.textAlign=MtA),e.fontKerning||(e.fontKerning=ktA)}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class RtA extends ZH{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}update(A,e){this._needsUpdate=!1;for(let t=A.children.length-1;t>=0;t--){const g=A.children[t];g.isUI&&(A.remove(g),g.clear())}A._children._uis=[],this._value&&A.add(new hE({name:"anonymousInline",textContent:this._value}))}}class UtA extends Array{constructor(...A){super(...A),this.width=0,this.height=0}}class FtA extends Dt{constructor(){super("layouter",null,!1),this._value=null}update(A,e){}process(A){let e=A._width._value;A._width._auto?e=1/0:e=A._bounds._innerWidth;const t=A._lineHeight._value,g=new UtA(new Av);let I=0;A._children._inlines.forEach(B=>{if(!B._inlines.value)return;this._resetInlines(B);const Q=B._fontSize._value,E=B._letterSpacing._value*Q,c=B._whiteSpace._value,l=B._lineBreak._value,d={WHITESPACE:c,LETTERSPACING:E,BREAKON:l,INNER_WIDTH:e},h=B._whiteSpace._inlineWrapper;I+=B._margin._value.w+B._padding._value.w,B._inlines.value.forEach((p,u,f)=>{const S=g[g.length-1];if(h(f,u,I,d)){if(g.push(new Av(p)),p.offsetX=p.xoffset,p.width===0){I=0;return}p.cumulativeWidth=p.xadvance+E,I=p.cumulativeWidth;return}g[g.length-1].push(p),p.offsetX=I+p.xoffset+p.kerning,p.cumulativeWidth=p.xadvance+p.kerning+E,I+=p.cumulativeWidth,S.length-1===1&&S[S.length-2].width===0&&(p.offsetX-=p.xoffset,I-=p.xoffset)}),I+=B._margin._value.y+B._padding._value.y});const o=A._whiteSpace._inlineCollapser;let s=0,C=0,n=0;g.forEach((B,Q)=>{const E=o(B);let c=0,l=0;if(B.forEach(d=>{c=Math.max(c,d.lineHeight),l=Math.max(l,d.lineBase),d.offsetX-=E}),B.lineHeight=c,B.lineBase=l,Q===0?n=-(c*t-c)*.5:n-=g[Q-1].lineHeight*t,B.y=n,B.x=0,B.forEach(d=>{d.offsetY=n-d.anchor,d.lineHeight<B.lineHeight&&(d.offsetY-=B.lineBase-d.lineBase)}),C+=B.lineHeight*t,B.width=0,B[0]){const d=B[B.length-1];B.width=d.offsetX+d.cumulativeWidth+d.paddingRight+d.marginRight+B[0].offsetX,s=Math.max(s,B.width)}}),g.height=C,g.width=s,this._value=g,e===1/0&&A._bounds.setChildrenWidth(A,g.width),A._height._auto&&A._bounds.setChildrenHeight(A,g.height);const a=A._parent._value;a&&(a._autoSize._needsProcess=!0,a._flexDirection._needsProcess=!0),A._inlineJustificator._needsProcess=!0,A._textAlign._needsProcess=!0,A._overflow._needsUpdate=!0}_resetInlines(A){A._fontSize.process(A)}}class NtA extends jR{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput,this._needsProcess=!0}process(A){KtA(A),A._renderer._needsRender=!0}}function KtA(i){const A=i._layouter._value,e=i._textAlign._value,t=i._bounds._innerWidth;for(let g=0;g<A.length;g++){const I=A[g],o=JtA(i,I,g===A.length-1),s=i._padding._value,C=i._borderWidth._value,n=(-s.w+s.y)/2+(-C.w+C.y)/2;I.x+=o;for(let a=0;a<I.length;a++)I[a].offsetX+=o-n}if(e.indexOf("justify")===0)for(let g=0;g<A.length;g++){const I=A[g];if(e.indexOf("-")!==-1&&g===A.length-1)return;const o=t-I.width;if(o<=0)return;let s=0;for(let B=1;B<I.length-1;B++)s+=I[B].char===" "?1:0;const C=o/s;let n=1;e==="justify-right"&&(I.reverse(),n=-1);let a=0;for(let B=1;B<=I.length-1;B++){const Q=I[B];Q.offsetX+=a*n,a+=Q.char===" "?C:0}e==="justify-right"&&I.reverse()}}function JtA(i,A,e){switch(i._textAlign._value){case"justify-left":case"justify":case"left":return-i._bounds._innerWidth/2;case"justify-right":case"right":return-A.width+i._bounds._innerWidth/2;case"center":return-A.width/2;case"justify-center":return e?-A.width/2:-i._bounds._innerWidth/2;default:console.warn(`textAlign: '${i._textAlign._value}' is not valid`)}}class qtA extends ZR{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput}}class vtA extends s_{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class btA extends By{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A)}}class LtA extends P_{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class xtA extends Dt{constructor(){super("children",null,!1);r(this,"_sortOrder",(e,t)=>e._order._value<t._order._value?-1:e._order._value>t._order._value?1:this._uis.indexOf(e)<this._uis.indexOf(t)?-1:1);this._uis=[],this._inlines=[],this._boxes=[]}update(e,t){this._compute(e),this._needsProcess=!0}process(e){this._compute(e),e._overflow._needsRender=!0}_compute(e){this._uis=e.children.filter(t=>t.visible&&t.isUI),this._inlines=this._uis.filter(t=>t.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class TtA extends Dt{constructor(){super("autosize")}process(A){if(A._layouter._value&&A._layouter._value.length){const e=A._layouter._value,t=A._padding._value,g=A._borderWidth._value;A._width._auto&&A._bounds.setOffsetWidth(A,e.width+t.w+t.y+g.w+g.y),A._height._auto&&A._bounds.setOffsetHeight(A,e.height+t.x+t.z+g.x+g.z)}}}class YtA extends V_{constructor(){super("renderer"),this._needsUpdate=!1}render(A){super.render(A);for(const e of A._children._inlines)e._renderer.render(e);A.performAfterUpdate()}}class kl extends yl{constructor(A={},e={}){kl.definePropertiesValues(e,A),super(e,A),kl.init(this)}add(A){const e=[];let t=!1;for(let g=0;g<arguments.length;g++){const I=arguments[g];!I.isUI||I.isInline?(I.isInline&&(t=!0),e.push(I)):console.warn("Block element can only contain Box elements.",I)}return e.length>0&&super.add(...e),t&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(A){this._textContent.value=A}get textContent(){return super.textContent}set invertAlpha(A){this._invertAlpha.value=A}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(A,e){A.flexDirection=qtA,A.justifyContent=XR,A.alignItems=zR,A.bounds=LtA,A.autoSize=TtA,A.renderer=YtA,A.children||(A.children=xtA),A.textContent||(A.textContent=RtA),A.layouter||(A.layouter=FtA),A.lineHeight||(A.lineHeight=vtA),A.textAlign||(A.textAlign=NtA),A.whiteSpace||(A.whiteSpace=fU),A.fontKerning||(A.fontKerning=btA),A.segments||(A.segments=o2),e.width||(e.width="100%"),e.fontSide||(e.fontSide=0)}static init(A){Object.defineProperties(A,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class HtA extends Dt{constructor(){super("inlines",null,!1),this._value=[]}process(A){this._value[0].paddingLeft=A._padding._value.w,this._value[0].marginLeft=A._margin._value.w;const e=this._value.length-1;this._value[e].paddingRight=A._padding._value.y,this._value[e].marginRight=A._margin._value.y}}class _tA extends Dt{constructor(){super("renderer")}render(A){A._backgroundMesh||A.setBackgroundMesh(new W_(A)),A._backgroundMesh.position.x=A._inlines._value[0].offsetX+A._inlines._value[0].width/2,A._backgroundMesh.position.y=A._inlines._value[0].offsetY+A._inlines._value[0].lineBase/2,A._bounds.render(A)}}class OtA extends Dt{constructor(){super("bounds",null,!1),this._size=new _A.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(A,e){this.output(e),this._needsProcess=!0}process(A){this._offsetWidth=this._innerWidth=A._inlines._value[0].width,this._offsetHeight=this._innerHeight=A._inlines._value[0].height,this._needsRender=!0,A._borderWidth._needsRender=!0,A._borderRadius._needsRender=!0}render(A){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(A){A.size=this._size}}class Gl extends wd{constructor(A={}){const e={};Gl.definePropertiesValues(e,A),super(e,A),Gl.init(this)}clear(){for(const A of this._inlines._value)A.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new _A.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(A){const e=[];for(let t=0;t<arguments.length;t++){const g=arguments[t];g.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",g):(e.push(g),g.position.z=.005)}return super.add(...e)}static definePropertiesValues(A,e){A.children||(A.children=s2),A.bounds||(A.bounds=OtA),A.inlines||(A.inlines=HtA),A.layouter||(A.layouter=j_),A.renderer||(A.renderer=_tA),A.fontFamily||(A.fontFamily=$_),A.fontWeight||(A.fontWeight=X_),A.fontStyle||(A.fontStyle=Z_),A.fontSize||(A.fontSize=I2),A.backgroundColor||(A.backgroundColor=VH),A.lineBreak||(A.lineBreak=z_),A.letterSpacing||(A.letterSpacing=g2),A.whiteSpace||(A.whiteSpace=fU),A.fontKerning||(A.fontKerning=By),e.backgroundSize||(e.backgroundSize="cover"),e.width||(e.width="100%"),e.height||(e.height="100%"),e.boxSizing||(e.boxSizing="border-box")}static init(A){Object.defineProperties(A,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),A._inlines._value=[new PtA(A)],A.backgroundMaterial=new O_,A._renderer.render(A)}}class PtA extends t_{constructor(A){super(),this._uiElement=A}get xadvance(){const A=this._uiElement._padding._value,e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.w+A.y+e.value}get width(){const A=this._uiElement._width;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get height(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get anchor(){return this.height}get lineHeight(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get lineBase(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}clear(){this._uiElement=null}}class C2{constructor(A){this._subject=A}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const n2=()=>ED.update(),a2={BaseProperty:Dt,Block:Sl,Text:kl,Inline:hE,InlineBlock:Gl,MeshUIBaseElement:wd,FontLibrary:AB,update:n2,MSDFFontMaterialUtils:vo,ShaderChunkUI:__,Behavior:C2,FontVariant:ud};typeof global<"u"&&(global.ThreeMeshUI=a2);const WtA=a2;var VtA=Ti.w8,r2=Ti.cg,DU=Ti.gO,ztA=Ti.wb,Rm=Ti.zV,jtA=Ti.HS,ZtA=Ti.Ec,cf=Ti.gF,XtA=Ti.ol,$tA=Ti.pz,AiA=Ti.tx,eiA=Ti.hj,tiA=Ti.FV,iiA=Ti.sV,B2=Ti.xv,giA=Ti.mx,IiA=Ti.gE,oiA=Ti.ZP,Q2=Ti.Vx;const ok=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:VtA,Behavior:r2,Block:DU,DefaultValues:ztA,FontLibrary:Rm,FontVariant:jtA,InheritableProperty:ZtA,Inline:cf,InlineBlock:XtA,InlineGlyph:$tA,MSDFFontMaterialUtils:AiA,MaterialTransformers:eiA,MeshUIBaseElement:tiA,ShaderChunkUI:iiA,Text:B2,TypographicFont:giA,TypographicGlyph:IiA,default:oiA,update:Q2},Symbol.toStringTag,{value:"Module"})),siA=sA("debugshadowcomponents");DU.prototype.interactable={get(){return this.interactive},set(i){this.interactable=i}};const Os=Symbol("shadowDomOwner");class ps extends NA{constructor(){super(...arguments);r(this,"shadowComponent",null);r(this,"_controlsChildLayout",!0);r(this,"_root");r(this,"_parentComponent")}isRoot(){var e;return((e=this.Root)==null?void 0:e.gameObject)===this.gameObject}get canvas(){const e=this.Root;return e!=null&&e.isCanvas?e:null}markDirty(){nI.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(e){this._controlsChildLayout=e,this.shadowComponent&&(this.shadowComponent.autoLayout=e)}get Root(){return this._root===void 0&&(this._root=IA.getComponentInParent(this.gameObject,yd)),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(e,t){var o;this.removeShadowComponent();const g=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=IA.getComponentInParent(g,ps),!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}e.name=this.name+" ("+(this.constructor.name??"UI")+")",e.autoLayout=this._parentComponent.controlsChildLayout,e[Os]=this,this.setShadowComponentOwner(e);let I=!1;if(((o=this.Root)==null?void 0:o.gameObject)===this.gameObject)this.gameObject.add(e);else{const s=this._parentComponent.shadowComponent;s&&(s==null||s.add(e),I=!0)}this.shadowComponent=e,t&&t.shadowComponent&&this.shadowComponent&&t.shadowComponent.add(this.shadowComponent),rd&&e.add(new GE(.5)),this.onAfterAddedToScene(),I&&Q2(),siA&&console.log(this.shadowComponent)}set(e){}setShadowComponentOwner(e){if(e&&(e[Os]===void 0||e[Os]===this)&&(e[Os]=this,e.children))for(const t of e.children)this.setShadowComponentOwner(t)}traverseOwnedShadowComponents(e,t,g){if(e&&e[Os]===t){g(e);for(const I of e.children)this.traverseOwnedShadowComponents(I,t,g)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(e){this.shadowComponent&&(this.shadowComponent.interactable=e)}}class yd extends ps{awake(){super.awake()}}class lE{static getObject(A){const e=A[Os];return e&&(e.isComponent===!0?A=e.gameObject:A=e),A}static isInteractable(A,e){if(e&&(e.canvasGroup=void 0,e.graphic=void 0),A==null||!A.visible||(A=this.getObject(A),!A.visible))return!1;const t=this.tryFindCanvasGroup(A);if((t==null?void 0:t.isCanvasGroup)===!0&&(e&&(e.canvasGroup=t),t.blocksRaycasts===!1||t.interactable===!1))return!1;const g=$r(A,I=>{if(I.isGraphic===!0)return I},!1);return e&&(g==null?void 0:g.isGraphic)===!0&&(e.graphic=g),!((g==null?void 0:g.raycastTarget)===!1||(g==null?void 0:g.layer)===2)}static tryFindCanvasGroup(A){if(!A)return null;const e=$r(A,t=>{const g=t;if(g.blocksRaycasts!==void 0&&g.interactable!==void 0)return g},!1);return e!==void 0?e:this.tryFindCanvasGroup(A.parent)}}const sh=sA("debugwebxrcontroller");var VQ=(i=>(i[i.PhysicalDevice=0]="PhysicalDevice",i[i.Touch=1]="Touch",i))(VQ||{}),LC=(i=>(i.SelectStart="select-start",i.SelectEnd="select-end",i.Update="update",i))(LC||{});class ly extends NA{}const Ig=class extends NA{constructor(){super(...arguments);r(this,"webXR");r(this,"index",-1);r(this,"controllerModel");r(this,"controller");r(this,"controllerGrip");r(this,"hand");r(this,"handPointerModel");r(this,"grabbed",null);r(this,"input",null);r(this,"type",0);r(this,"showRaycastLine",!0);r(this,"_wristQuaternion",null);r(this,"movementVector",new w);r(this,"worldRot",new GA);r(this,"joystick",new tA);r(this,"didRotate",!1);r(this,"didTeleport",!1);r(this,"didChangeScale",!1);r(this,"lastHit",null);r(this,"raycastLine",null);r(this,"_raycastHitPoint",null);r(this,"_connnectedCallback",null);r(this,"_disconnectedCallback",null);r(this,"_selectStartEvt",null);r(this,"_selectEndEvt",null);r(this,"_selectionPressed",!1);r(this,"_selectionPressedLastFrame",!1);r(this,"_selectionStartTime",0);r(this,"_selectionEndTime",0);r(this,"_useSmoothing",!0);r(this,"_isConnected",!1);r(this,"rayRotation",new GA);r(this,"_pinchStartTime");r(this,"selectStartCallback",null);r(this,"lastSelectStartObject",null);r(this,"_didNotEndSelection",!1);r(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const e=new pi(this.geometry),t=e.material;return t.color=this.raycastColor,e.layers.set(2),e.name="line",e.scale.z=1,e}static CreateRaycastHitPoint(){const e=new Vo(.5,22,22),t=new ct({color:this.raycastColor}),g=new wA(e,t);return g.visible=!1,g.layers.set(2),g}static Create(e,t,g,I){const o=g?IA.addNewComponent(g,Ig,!1):new Ig;o.webXR=e,o.index=t,o.type=I;const s=e.context;o.controller=s.renderer.xr.getController(t),o.controllerGrip=s.renderer.xr.getControllerGrip(t),o.controllerModel=this.Factory.createControllerModel(o.controller),o.controllerGrip.add(o.controllerModel),o.hand=s.renderer.xr.getHand(t);const C=new KE;cd(C,s),o.webXR.handModelPath&&o.webXR.handModelPath!==""?C.setPath(Sn(e.sourceId,o.webXR.handModelPath)):C.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const n=new G7(o.hand,C);return o.hand.add(n),o.hand.traverse(a=>a.layers.set(2)),o.handPointerModel=new K7(o.hand,o.controller),o.controller.addEventListener("connected",a=>{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",a=>{var Q;if(a.data.hand){e.Rig&&e.Rig.add(o.hand),o.type=0,o.handPointerModel.traverse(c=>c.layers.set(2)),(Q=o.handPointerModel.pointerObject)==null||Q.traverse(c=>c.layers.set(2));const E=o.hand.joints;if(E)for(const c of Object.keys(E)){const l=E[c];l.parent||o.hand.add(l)}}}),o}static addEventListener(e,t){const g=this.eventSubs[e]??[];g.push(t),this.eventSubs[e]=g}static removeEventListener(e,t){if(!t)return;const g=this.eventSubs[e]??[],I=g.indexOf(t);I>=0&&g.splice(I,1),this.eventSubs[e]=g}get isUsingHands(){var t;const e=(t=this.input)==null?void 0:t.hand;return e!=null}get wrist(){if(!this.hand)return null;const e=this.hand.joints;return e?e.wrist:null}getWristQuaternion(){const e=this.wrist;return e?(this._wristQuaternion||(this._wristQuaternion=new GA),Zi(e).multiply(this._wristQuaternion.setFromEuler(new yi(-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 e,t,g;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)),(e=this.hand)==null||e.clear(),(t=this.controllerGrip)==null||t.clear(),(g=this.controller)==null||g.clear()}onEnable(){var e,t,g,I,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=Ig.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=Ig.CreateRaycastHitPoint()),(e=this.webXR.Rig)==null||e.add(this.hand),(t=this.webXR.Rig)==null||t.add(this.controllerGrip),(g=this.webXR.Rig)==null||g.add(this.controller),(I=this.webXR.Rig)==null||I.add(this.raycastLine),(o=this.raycastLine)==null||o.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),sh&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var e,t,g,I,o;if((e=this.hand)==null||e.removeFromParent(),(t=this.controllerGrip)==null||t.removeFromParent(),(g=this.controller)==null||g.removeFromParent(),(I=this.raycastLine)==null||I.removeFromParent(),(o=this._raycastHitPoint)==null||o.removeFromParent(),this.webXR){const s=this.webXR.Controllers.indexOf(this);s>=0&&this.webXR.Controllers.splice(s,1)}}onSourceConnected(e){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,e);return}this._isConnected=!0,this.input=e.data,this.type===1&&this.onSelectStart()}onSourceDisconnected(e){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",e);return}this._isConnected=!1,this.type===1&&this.onSelectEnd(),this.input=null}createPointerEvent(e){switch(e){case"down":this.context.input.createPointerDown(new vC(Ki.PointerDown,null,{clientX:0,clientY:0,button:this.index,pointerType:CE.Touch}));break;case"move":break;case"up":this.context.input.createPointerUp(new vC(Ki.PointerUp,null,{clientX:0,clientY:0,button:this.index,pointerType:CE.Touch}));break}}raycastUpdate(e,t){const g=this.showRaycastLine&&this.type!==1;if(this.type===1)e.visible=!1;else if(this.isUsingHands){e.visible=!this.grabbed&&g,bi(e,t);const I=this.hand.joints;if(I&&I.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const s=this.getWristQuaternion();s&&this.rayRotation.copy(s)}LI(e,this.rayRotation)}else e.visible=g,LI(e,this.rayRotation),bi(e,t)}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 e=Ig.eventSubs.update;if(e&&e.length>0)for(const I of e)I(this);let t=1;this.type===0?t=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(t=this.context.time.deltaTime/.3),this.rayRotation.slerp(Zi(this.controller),this.useSmoothing?t:1);const g=ke(this.controller);this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine&&this.raycastUpdate(this.raycastLine,g),this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(e){var I,o;if(this.lastHit=null,!e||e.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=e.inputSources[this.index]),!this.input)return;const t=this.webXR.Rig;if(!t)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const g=(o=(I=this.input)==null?void 0:I.gamepad)==null?void 0:o.buttons;switch(this.input.handedness){case"left":this.movementUpdate(t,g);break;case"right":this.rotationUpdate(t,g);break}}movementUpdate(e,t){const g=3*Ig.MovementSpeedFactor,I=2,o=ie.clamp01(this.joystick.length()*2),s=this.joystick.x>0?1:-1;let C=Math.pow(this.joystick.x,I);C*=s,C*=o;const n=this.joystick.y>0?1:-1;let a=Math.pow(this.joystick.y,I);a*=n,C*=o,e.getWorldQuaternion(this.worldRot),this.movementVector.set(C,0,a),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(g*this.context.time.deltaTime),e.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(e,t)}rotationUpdate(e,t){const g=this.joystick.x,I=Math.abs(g);if(I<.4)this.didRotate=!1;else if(I>.5&&!this.didRotate){const o=g>0?-1:1;e.rotateY(ie.toRadians(30*o)),this.didRotate=!0}this.runTeleport(e,t)}runTeleport(e,t){var a,B;let g=-this.joystick.y;if((a=this.hand)!=null&&a.visible&&!this.grabbed){const Q=this.handPointerModel.isPinched();Q&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),Q&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(g=this.handPointerModel.isPinched()?1:0),Q||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;const I=this.webXR.IsInVR,o=this.webXR.Rig;let s=g>.5&&I,C=o?((B=o==null?void 0:o.scale)==null?void 0:B.x)<.999:!1,n=null;if(t&&this.input&&!this.input.hand)for(let Q=0;Q<t.length;Q++){const E=t[Q];if(Q===4)if(E.pressed&&!this.didChangeScale&&I){this.didChangeScale=!0;const c=o;if(c){const l=this.switchScale(c,s,C,n);s=l.doTeleport,C=l.isInMiniatureMode,n=l.newRigScale}}else E.pressed||(this.didChangeScale=!1)}if(s){if(!this.didTeleport){const Q=this.raycast();if(this.didTeleport=!0,Q&&Q.length>0){const E=Q[0];if(C||this.isValidTeleportTarget(E.object)){const c=E.point;bi(e,c)}}}}else g<.1&&(this.didTeleport=!1);n!==null&&(e.scale.set(n,n,n),e.updateMatrixWorld())}isValidTeleportTarget(e){return IA.getComponentInParent(e,ly)!=null}switchScale(e,t,g,I){if(g){g=!1,e.scale.set(1,1,1),I=1,Ig.MovementSpeedFactor=1;const o=this.context.mainCamera;Ig.PreviousCameraFarDistance&&(o.far=Ig.PreviousCameraFarDistance)}else{g=!0,t=!0,I=.1,Ig.MovementSpeedFactor=I*2;const o=this.context.mainCamera;Ig.PreviousCameraFarDistance=o.far,o.far/=I}return{doTeleport:t,isInMiniatureMode:g,newRigScale:I}}updateStick(e){var t;!e||!e.gamepad||((t=e.gamepad.axes)==null?void 0:t.length)<4||(this.joystick.x=e.gamepad.axes[2],this.joystick.y=e.gamepad.axes[3])}updateLastHit(){var I;const e=this.raycast(),t=e?e[0]:null;this.lastHit=t;let g=1;if(this.webXR.Rig&&(g/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=g*(((I=this.lastHit)==null?void 0:I.distance)??9999);const o=this.raycastLine.material;t!=null?o.color=Ig.raycastColor:o.color=Ig.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const o=ie.clamp(this.lastHit.distance*.01*g,.015,.1);this._raycastHitPoint.scale.set(o,o,o)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return t}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 e=null,t=!1;if(this.isUsingHands?(e=this.overlap(),e.length<=0?(e=this.raycast(),t=!1):t=!0):e=this.raycast(),sh&&console.log("onHandleSelectStart","close grab? "+t,"intersections",e),e&&e.length>0)for(const g of e){const I=g.object;this.lastSelectStartObject=I;const o={selected:I,grab:I},s=Ig.eventSubs["select-start"];if(s&&s.length>0)for(const C of s)C(this,o);o.grab!==I&&sh&&console.log("Grabbed object changed","original",I,"new",o.grab),o.grab&&(this.grabbed=To.TryTake(this,o.grab,g,t));break}else{const g=Ig.eventSubs["select-start"],I={selected:null,grab:null};if(g&&g.length>0)for(const o of g)o(this,I)}}onSelectEnd(){var g;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 e={grab:((g=this.grabbed)==null?void 0:g.selected)??this.lastSelectStartObject},t=Ig.eventSubs["select-end"];if(t&&t.length>0)for(const I of t)I(this,e);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(e){return!(!e||IA.isActiveInHierarchy(e)===!1||lE.isInteractable(e)===!1)}setControllerLayers(e,t){var g,I;if(e&&(e.layers.set(t),e.children))for(const o of e.children)((g=this.grabbed)==null?void 0:g.selected)===o||((I=this.grabbed)==null?void 0:I.selectedMesh)===o||this.setControllerLayers(o,t)}getRay(){const e=new nC;return e.origin.copy(ke(this.controller)),e.direction.set(0,0,-1).applyQuaternion(this.rayRotation),e}overlap(){const e=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(sh&&(!this.closeGrabBoundingBoxHelper&&e&&(this.closeGrabBoundingBoxHelper=new Rw(e,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&e&&this.closeGrabBoundingBoxHelper.setFromObject(e)),!e)return new Array;const t=ke(e).clone();return this.context.physics.sphereOverlap(t,.02)}raycast(){const e=new Wo;e.layerMask=new Yg,e.layerMask.enableAll(),e.layerMask.disable(2),e.ray=this.getRay();const t=this.context.physics.raycast(e);for(let g=0;g<t.length;g++){const I=t[g],o=I.object;if(!this.testIsVisible(o)){t.splice(g,1),g--;continue}I.object=lE.getObject(o);break}return t}};let ai=Ig;r(ai,"Factory",new P7),r(ai,"raycastColor",new SA(.9,.3,.3)),r(ai,"raycastNoHitColor",new SA(.6,.6,.6)),r(ai,"geometry",new le().setFromPoints([new w(0,0,0),new w(0,0,-1)])),r(ai,"handModels",{}),r(ai,"eventSubs",{}),r(ai,"PreviousCameraFarDistance"),r(ai,"MovementSpeedFactor",1);var hD=(i=>(i.WillTake="WillTake",i.DidTake="DidTake",i.WillFree="WillFree",i.DidFree="DidFree",i))(hD||{});const iI=class{constructor(){r(this,"sync",null);r(this,"selected",null);r(this,"selectedParent",null);r(this,"selectedMesh",null);r(this,"controller",null);r(this,"grabTime",0);r(this,"grabUUID","");r(this,"isCloseGrab",!1);r(this,"originalMaterial",null);r(this,"usageMarker",null);r(this,"rigidbodies",null);r(this,"didReparent",!1);r(this,"grabDistance",0);r(this,"interactable",null);r(this,"positionSource",null);r(this,"grabPoint",new w);r(this,"localPositionOffsetToGrab",null);r(this,"localPositionOffsetToGrab_worldSpace",new w);r(this,"localQuaternionToGrab",new GA(0,0,0,1));r(this,"targetDir",null);r(this,"quaternionLerp",null);r(this,"controllerDir",new w);r(this,"controllerWorldPos",new w);r(this,"lastControllerWorldPos",new w);r(this,"controllerPosDelta",new w);r(this,"totalChangeAlongDirection",0);r(this,"rigPositionLastFrame",new w)}static AddEventListener(A,e){return iI.Events[A]||(iI.Events[A]=[]),iI.Events[A].push(e),e}static RemoveEventListener(A,e){if(!e||!iI.Events[A])return;const t=iI.Events[A].indexOf(e);t>=0&&iI.Events[A].splice(t,1)}static Register(A){this.Current.find(e=>e===A)||this.Current.push(A)}static Remove(A){const e=this.Current.indexOf(A);e>=0&&this.Current.splice(e,1)}static TryTake(A,e,t,g){const I=IA.getComponentInParent(e,vE);if(I)e=I.gameObject;else return sh&&console.warn("Prevented taking object that is not interactable",e),null;let o=e;const s=IA.getComponentInParent(e,Ma);s&&(s.requestOwnership(),o=s.gameObject);for(const n of this.Current)if(n.selected===o)return n.controller===A||(n.free(),n.Take(A,o,e,s,I,t,g)),n;const C=new iI;return C.Take(A,o,e,s,I,t,g),C}Take(A,e,t,g,I,o,s){var E,c;if(console.assert(e!==null,"Expected object to be taken but was",e),A.isUsingHands?this.positionSource=s?A.wrist:A.controller:this.positionSource=A.controller,!this.positionSource)return console.warn("No position source"),this;const C={controller:A,take:e,hit:t,sync:g,interactable:I};(E=iI.Events.WillTake)==null||E.forEach(l=>l(this,C));const n=t;n!=null&&n.material&&(this.originalMaterial=n.material,Array.isArray(n.material)||(n.material=n.material.clone(),n.material&&n.material.emissive&&(n.material.emissive.b=.2))),this.selected=e,this.selectedParent||(this.selectedParent=e.parent),this.selectedMesh=n,this.controller=A,this.interactable=I,this.isCloseGrab=s,this.didReparent=!1,this.sync=g,this.grabTime=A.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=IA.addNewComponent(this.selected,bE),this.rigidbodies=IA.getComponentsInChildren(this.selected,qt),ke(this.positionSource,this.lastControllerWorldPos);const a=()=>s?this.lastControllerWorldPos.clone():o.point.clone();this.grabDistance=a().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(a());const B=A.isUsingHands&&s?this.controller.getWristQuaternion().clone():A.rayRotation.clone();Zi(this.selected,this.localQuaternionToGrab).premultiply(B.invert());const Q=this.controller.webXR.Rig;return Q&&this.rigPositionLastFrame.copy(ke(Q)),BI.Add(A.context,this.selected),iI.Register(this),this.sync&&(this.sync.fastMode=!0),(c=iI.Events.DidTake)==null||c.forEach(l=>l(this,C)),this}free(){var g,I,o,s;if(!this.selected)return;const A={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(g=iI.Events.WillFree)==null||g.forEach(C=>C(this,A)),BI.Remove(this.controller.context,this.selected),iI.Remove(this),this.sync&&(this.sync.fastMode=!1);const e=this.selectedMesh;e&&this.originalMaterial&&e.material&&(e.material=this.originalMaterial);const t=this.selected;if(this.didReparent&&t.parent){const C=this.selectedParent;C?C.attach(t):(I=this.controller)==null||I.context.scene.attach(t)}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,(s=iI.Events.DidFree)==null||s.forEach(C=>C(this,A))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),ke(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const A=this.controller.webXR.Rig;if(A){const t=ke(A),g=this.rigPositionLastFrame.sub(t);this.controllerPosDelta.add(g),this.rigPositionLastFrame.copy(t)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var A;if(this.rigidbodies)for(const e of this.rigidbodies)e.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 e=((A=this.controller.webXR.Rig)==null?void 0:A.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let t=1;this.controller.type===0&&(t=Math.max(0,1+this.totalChangeAlongDirection*2/e),t=t*t*t),this.grabDistance/e<.8&&(t=1),this.targetDir||(this.targetDir=new w),this.targetDir.set(0,0,-this.grabDistance*t);const g=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),I=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=I.clone()),this.quaternionLerp.slerp(I,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),LI(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(g),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(ke(this.selected)),g.sub(this.localPositionOffsetToGrab_worldSpace)),bi(this.selected,g)}if(this.rigidbodies!=null)for(const e of this.rigidbodies)e.wakeUp();qI.markDirty(this.selected,!0)}}};let To=iI;r(To,"Events",{}),r(To,"Current",[]);class en{constructor(A,e){r(this,"used",!1);r(this,"inputSource");r(this,"object");r(this,"pointerId");r(this,"isDown");r(this,"isUp");r(this,"isPressed");r(this,"isClicked");r(this,"input");r(this,"_event");this._event=e,this.input=A}use(){this.used=!0,this.pointerId!==void 0&&this.input.setPointerUsed(this.pointerId)}stopPropagation(){var A;(A=this._event)==null||A.stopImmediatePropagation()}Use(){this.use()}StopPropagation(){var A;(A=this._event)==null||A.stopImmediatePropagation()}get event(){return this._event}clone(){const A=new en(this.input,this._event);return Object.assign(A,this),A}}class YE extends NA{awake(){nI.createIfNoneExists(this.context)}onEnable(){var A;(A=nI.get(this.context))==null||A.register(this)}onDisable(){var A;(A=nI.get(this.context))==null||A.unregister(this)}performRaycast(A=null){return null}}class pn extends YE{constructor(){super(...arguments);r(this,"targets",null);r(this,"raycastHits",[])}start(){this.targets=[this.gameObject]}performRaycast(e=null){return this.targets?(e??(e=new Wo),e.targets=this.targets,e.results=this.raycastHits,this.context.physics.raycast(e)):null}}class wU extends pn{}const fQ=sA("debugeventsystem");var Um=(i=>(i.BeforeHandleInput="BeforeHandleInput",i.AfterHandleInput="AfterHandleInput",i))(Um||{});const Ls=class extends NA{constructor(){super();r(this,"raycaster",[]);r(this,"_selectStartFn");r(this,"_selectEndFn");r(this,"_selectUpdateFn");r(this,"_handleEventCycleFn");r(this,"_handleInputFn");r(this,"pressedByID",new Map);r(this,"hoveredByID",new Map);r(this,"_sortedHits",[]);r(this,"_sortingBuffer",[]);r(this,"_noDepthTestingResults",[]);r(this,"out",{});r(this,"currentActiveMeshUIComponents",[]);Ls.systems.push(this)}static createIfNoneExists(e){this.didSearchEventSystem||(this.didSearchEventSystem=!0,Ls.systems.length<=0&&Ls.systems.push(...IA.findObjectsOfType(Ls,e)));for(const g of Ls.systems)if(g.context===e)return;const t=new FA;IA.addNewComponent(t,Ls),e.scene.add(t)}static get systems(){const e=Le.Current;return this._eventSystemMap.has(e)||this._eventSystemMap.set(e,[]),this._eventSystemMap.get(e)}static get(e){const t=this._eventSystemMap.get(e);return t&&t.length>0?t[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(e,t,g=!1){xC.update(e,t,g)}static markUIDirty(e){xC.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.hoveredByID.size>0}onDestroy(){Ls.systems.splice(Ls.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!IA.findObjectOfType(YE,this.context)){const t=IA.addNewComponent(this.context.scene,pn);this.raycaster.push(t),(rt()||fQ)&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found")}}register(e){var t;e&&this.raycaster&&!this.raycaster.includes(e)&&((t=this.raycaster)==null||t.push(e))}unregister(e){var g,I;const t=(g=this.raycaster)==null?void 0:g.indexOf(e);t!==void 0&&t!==-1&&((I=this.raycaster)==null||I.splice(t,1))}onEnable(){const e=new Map;this._selectStartFn??(this._selectStartFn=(g,I)=>{if(!I.grab)return;xC.resetLastSelected();const o=new en(this.context.input);o.inputSource=g,o.pointerId=0,o.isDown=g.selectionDown,o.isUp=g.selectionUp,o.isPressed=g.selectionPressed,o.isClicked=!1,e.set(g,I.grab),I.grab&&!this.handleEventOnObject(I.grab,o)&&(I.grab=null)}),this._selectEndFn??(this._selectEndFn=(g,I)=>{var C;if(!I.grab)return;const o=new en(this.context.input);o.inputSource=g,o.pointerId=0,o.isDown=g.selectionDown,o.isUp=g.selectionUp,o.isPressed=g.selectionPressed,o.isClicked=g.selectionClick,this.handleEventOnObject(I.grab,o);const s=e.get(g);if(e.set(g,null),s)for(const n of this.pressedByID.keys()){const a=this.pressedByID[n];a.obj===s&&a.handler&&((C=a.handler.onPointerUp)==null||C.call(a.handler,o),this.pressedByID.delete(n))}});const t=new Wo;this._selectUpdateFn??(this._selectUpdateFn=g=>{t.ray=g.getRay();const I=this.performRaycast(t);if(!I)return;const o=new en(this.context.input);o.inputSource=g,this.handleIntersections(I,o)}),ai.addEventListener(LC.SelectStart,this._selectStartFn),ai.addEventListener(LC.SelectEnd,this._selectEndFn),ai.addEventListener(LC.Update,this._selectUpdateFn),this._handleInputFn=this.onPointerEvent.bind(this),this.context.input.addEventListener(Ki.PointerDown,this._handleInputFn),this.context.input.addEventListener(Ki.PointerUp,this._handleInputFn),this.context.input.addEventListener(Ki.PointerMove,this._handleInputFn)}onDisable(){ai.removeEventListener(LC.SelectStart,this._selectStartFn),ai.removeEventListener(LC.SelectEnd,this._selectEndFn),ai.removeEventListener(LC.Update,this._selectUpdateFn),this.context.input.removeEventListener(Ki.PointerDown,this._handleInputFn),this.context.input.removeEventListener(Ki.PointerUp,this._handleInputFn),this.context.input.removeEventListener(Ki.PointerMove,this._handleInputFn)}onBeforeRender(){this.resetMeshUIStates()}onPointerEvent(e){if(e===void 0)return;const t=e.pointerType==CE.Touch?e.button:0,g=new en(this.context.input,e);g.inputSource=this.context.input,g.pointerId=t,g.isClicked=this.context.input.getPointerClicked(t),g.isDown=e.type==Ki.PointerDown,g.isUp=e.type==Ki.PointerUp,g.isPressed=this.context.input.getPointerPressed(t),fQ&&g.isClicked&&console.log("CLICK",t);const I=new Wo;I.screenPoint=this.context.input.getPointerPositionRC(t);const o=this.performRaycast(I);if(!o)return;fQ&&g.isClicked&&Di("EventSystem: "+g.pointerId+" - "+this.context.time.frame+" - Up:"+g.isUp+", Down:"+g.isDown);const s={sender:this,args:g,hasActiveUI:this.currentActiveMeshUIComponents.length>0};if(this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:s})),!this.handleIntersections(o,g)){const C=this.hoveredByID.get(t);if(C&&this.triggerOnExit(C.obj,C.data),this.hoveredByID.delete(t),g.isUp){const n=this.pressedByID.get(t);n==null||n.handlers.forEach(a=>{var B;return(B=a.onPointerUp)==null?void 0:B.call(a,g)}),this.pressedByID.delete(t)}}this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:s}))}performRaycast(e){if(!this.raycaster)return null;this._sortedHits.length=0;for(const t of this.raycaster){if(!t.activeAndEnabled)continue;const g=t.performRaycast(e);g&&g.length>0&&this._sortedHits.push(...g)}return this._sortedHits.sort((t,g)=>t.distance-g.distance),this._sortedHits}handleIntersections(e,t){if(!e||e.length<=0)return!1;e=this.sortCandidates(e);for(const g of e){const{object:I}=g;if(this.handleEventOnObject(I,t))return!0}return!1}sortCandidates(e){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let t=0;t<e.length;t++){const g=e[t],I=g.object;if(I.material&&I.material.depthTest===!1){this._noDepthTestingResults.push(g);continue}this._sortingBuffer.push(g)}for(const t of this._sortingBuffer)this._noDepthTestingResults.push(t);return this._noDepthTestingResults}handleEventOnObject(e,t){if(!this.testIsVisible(e))return t.isClicked&&fQ&&console.log("not allowed",e),!1;if(t.pointerId===void 0)return!1;t.object=e;const g=e.parent;let I=!1;const o=t.isClicked??!1;let s=null;if(g&&g.isUI){const a=(t.isPressed||t.isClicked)??!1;if(g[Os]){const B=g[Os].gameObject;if(B){if(!lE.isInteractable(B,this.out))return!1;s=this.out.canvasGroup??null,this.handleMeshUIIntersection(e,a),e=B,I=!0}}if(!I&&this.handleMeshUiObjectWithoutShadowDom(g,a))return!0}o&&fQ&&console.log(this.context.time.frame,e);const C=this.hoveredByID.get(t.pointerId),n=(C==null?void 0:C.obj)!==e;if(n&&(C!=null&&C.obj)&&this.triggerOnExit(C.obj,C.data),this.hoveredByID.set(t.pointerId,{obj:e,data:t}),t.isDown){const a=this.pressedByID.get(t.pointerId);a?(a.obj=e,a.data=t):this.pressedByID.set(t.pointerId,{obj:e,data:t,handlers:new Set})}return(s===null||s.interactable)&&this.handleMainInteraction(e,t,n),!0}propagate(e,t,g){for(;!(t.used||(IA.foreachComponent(e,I=>{g(I)},!1),!e.parent));)e=e.parent}handleMainInteraction(e,t,g){if(t.pointerId===void 0)return;const I=this.pressedByID.get(t.pointerId);this.propagate(e,t,o=>{var B;const s=o;if(s.interactable===!1)return;s.onPointerEnter&&g&&s.onPointerEnter(t),t.isDown&&s.onPointerDown&&(s.onPointerDown(t),I==null||I.handlers.add(s));const C=this.context.input.getPointerPositionLastFrame(t.pointerId),n=this.context.input.getPointerPosition(t.pointerId);C&&!ie.approximately(C,n)&&s.onPointerMove&&s.onPointerMove(t),t.isUp&&(s.onPointerUp&&(s.onPointerUp(t),I==null||I.handlers.delete(s)),s.onPointerExit&&((B=t.event)==null?void 0:B.pointerType)===CE.Touch&&(s.onPointerExit(t),this.hoveredByID.delete(t.pointerId))),t.isClicked&&s.onPointerClick&&s.onPointerClick(t)}),t.isUp&&(I==null||I.handlers.forEach(o=>{o.onPointerUp&&o.onPointerUp(t)}),this.pressedByID.delete(t.pointerId))}triggerOnExit(e,t){t.used=!1,this.propagate(e,t,g=>{if(!g.gameObject||g.destroyed)return;const I=g;I.onPointerExit&&I.onPointerExit(t)})}handleMeshUiObjectWithoutShadowDom(e,t){return!e||!e.isUI?!0:this.handleMeshUIIntersection(e,t)}handleMeshUIIntersection(e,t){const g=xC.updateState(e,t);return g&&this.currentActiveMeshUIComponents.push(g),g!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&xC.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let e=0;e<this.currentActiveMeshUIComponents.length;e++){const t=this.currentActiveMeshUIComponents[e];xC.resetState(t)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(e){return e?IA.isActiveSelf(e)?this.testIsVisible(e.parent):!1:!0}};let nI=Ls;r(nI,"_eventSystemMap",new Map),r(nI,"didSearchEventSystem",!1);class xC{static markDirty(){this.needsUpdate=!0}static update(A,e,t=!1){if(t){A.update();return}const g=e.time.frameCount;for(const I of this.lastUpdateFrame)if(I.context===e){if(g===I.frame)return;I.frame=g;let o=this.needsUpdate||g<1;I.nextUpdate===e.time.frameCount&&(o=!0),o&&(fQ&&console.log("Update threemeshui"),this.needsUpdate=!1,A.update());return}this.lastUpdateFrame=[{context:e,frame:g,nextUpdate:g}],A.update()}static updateState(A,e){let t=null;if(A&&(t=this.findBlockInParent(A),t&&t!==this.lastSelected)){if(t.interactable===!1)return null;this.needsUpdate=!0}return t}static resetLastSelected(){const A=this.lastSelected;A&&(this.lastSelected=null,this.resetState(A))}static resetState(A){A&&(this.needsUpdate=!0)}static findBlockInParent(A){return A?A.isBlock?A:this.findBlockInParent(A.parent):null}}r(xC,"lastSelected",null),r(xC,"lastUpdateFrame",[]),r(xC,"needsUpdate",!1);const hf=Symbol("cameraController");function CiA(i){return i[hf]}function iv(i,A,e){e?i[hf]=A:i[hf]===A&&(i[hf]=null)}function dy(i){const A=i[Os];return A||(i.parent?dy(i.parent):null)}function lD(i,A){if(!i)return;const e=i.material;if((e==null?void 0:e.isMaterial)===!0){const t=i.parent;t&&t.isText,e.side=A.doubleSided??!0?mt:_g,e.shadowSide=A.doubleSided?mt:_g,i.castShadow=A.castShadows?A.castShadows:!1,i.receiveShadow=A.receiveShadows?A.receiveShadows:!1}for(const t of i.children)lD(t,A)}function DQ(i,A,e){i[A]===void 0&&console.warn("Field",A,"is undefined on",i);const t=Proxy.revocable(i[A],{set(o,s,C,n){const a=o[s],B=Reflect.set(o,s,C,n);return e(C,a),B}}),g=t.revoke,I=i[A];return t.revoke=()=>{i[A]=I,g()},i[A]=t.proxy,t}const gv=Symbol("Scheduled action");function niA(i,A,e=xI.OnBeforeRender){let t=i[gv];t||(t=i[gv]={});const g=A.name;t[e]||(t[e]={});const I=t[e];if(I[g])return;function*s(){A==null||A.call(i),I[g]=null}const C=i.startCoroutine(s(),e);I[g]=C}class E2 extends wA{constructor(A,e={}){const g=[A.isCubeTexture?"#define ENVMAP_TYPE_CUBE":""],I=`
|
|
5072
|
+
`&&i.length>1&&e2([e],i[i.length-2]),A.offsetX}function DtA(i){if(!i[0])return 0;let A=[],e;for(let t=0;t<i.length;t++){const g=i[t];if(g.char&&ev[g.char]&&i.length>t){A.push(g),e=i[t+1];continue}break}t2(A,e),A=[],e=null;for(let t=i.length-1;t>0;t--){const g=i[t];if(g.char&&ev[g.char]&&t>0){A.push(g),e=i[t-1];continue}break}return e2(A,e),i[0].offsetX}function wtA(i){return i[0]?i[0].offsetX:0}function e2(i,A){if(A)for(let e=0;e<i.length;e++){const t=i[e];t.fontFactor=0,t.offsetX=A.offsetX+A.cumulativeWidth,t.cumulativeWidth=0}}function t2(i,A){if(A)for(let e=0;e<i.length;e++){const t=i[e];t.fontFactor=0,t.offsetX=A.offsetX,t.cumulativeWidth=0}}function i2(i,A,e,t){if(t=t||0,!i[A])return t;const g=i[A];return g.lineBreak?t+g.xadvance:i2(i,A+1,e,t+g.xadvance+g.xoffset+g.kerning+e.LETTERSPACING)}function ytA(i,A,e,t){return!i||!i.char||A+e<t.INNER_WIDTH?!1:t.BREAKON.indexOf(i.char)>-1}class g2 extends n_{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._fontSize._needsProcess=!0,A._layouter._needsProcess=!0}}class I2 extends Zt{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(A){this._value=this._inheritedInput,A._font._fontVariant&&(A._bounds._needsProcess=!0,A._layouter._needsProcess=!0)}process(A){if(!A._font._fontVariant||!A._font._fontVariant.isReady)return;const e=this._value/A._font._fontVariant.typographic.size,t=A._inlines._value;for(let g=0;g<t.length;g++){const I=t[g];I.resetOffsets(),I.fontSize=this._value,I.fontFactor=e}}get value(){return this._value}}class o2 extends a_{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(A,e){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(A)),A._layouter._needsUpdate=!0}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class StA extends o2{constructor(){super(),this._value="inherit"}}class ktA extends By{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._parent._value._layouter._needsProcess=!1}process(A){if(this._value!=="none"){const e=A._whiteSpace._whiteSpacedContent,t=A._inlines._value;for(let g=1;g<t.length;g++){const I=e[g-1]+e[g];t[g].kerning=A._font._fontVariant.getKerningAmount(I)}}}}class s2 extends Dt{constructor(){super("children",null,!1),this._uis=[]}update(A,e){}process(A){}_compute(A){}dispose(){}}function GtA(i,A=!1){const e=i[0].index!==null,t=new Set(Object.keys(i[0].attributes)),g=new Set(Object.keys(i[0].morphAttributes)),I={},o={},s=i[0].morphTargetsRelative,C=new _A.BufferGeometry;let n=0;for(let a=0;a<i.length;++a){const B=i[a];let Q=0;if(e!==(B.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const E in B.attributes){if(!t.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+'. All geometries must have compatible attributes; make sure "'+E+'" attribute exists among all geometries, or in none of them.'),null;I[E]===void 0&&(I[E]=[]),I[E].push(B.attributes[E]),Q++}if(Q!==t.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". Make sure all geometries have the same number of attributes."),null;if(s!==B.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const E in B.morphAttributes){if(!g.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". .morphAttributes must be consistent throughout all geometries."),null;o[E]===void 0&&(o[E]=[]),o[E].push(B.morphAttributes[E])}if(C.userData.mergedUserData=C.userData.mergedUserData||[],C.userData.mergedUserData.push(B.userData),A){let E;if(e)E=B.index.count;else if(B.attributes.position!==void 0)E=B.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+a+". The geometry must have either an index or a position attribute"),null;C.addGroup(n,E,a),n+=E}}if(e){let a=0;const B=[];for(let Q=0;Q<i.length;++Q){const E=i[Q].index;for(let c=0;c<E.count;++c)B.push(E.getX(c)+a);a+=i[Q].attributes.position.count}C.setIndex(B)}for(const a in I){const B=tv(I[a]);if(!B)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+a+" attribute."),null;C.setAttribute(a,B)}for(const a in o){const B=o[a][0].length;if(B===0)break;C.morphAttributes=C.morphAttributes||{},C.morphAttributes[a]=[];for(let Q=0;Q<B;++Q){const E=[];for(let l=0;l<o[a].length;++l)E.push(o[a][l][Q]);const c=tv(E);if(!c)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+a+" morphAttribute."),null;C.morphAttributes[a].push(c)}}return C}function tv(i){let A,e,t,g=0;for(let s=0;s<i.length;++s){const C=i[s];if(C.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(A===void 0&&(A=C.array.constructor),A!==C.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=C.itemSize),e!==C.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(t===void 0&&(t=C.normalized),t!==C.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;g+=C.array.length}const I=new A(g);let o=0;for(let s=0;s<i.length;++s)I.set(i[s].array,o),o+=i[s].array.length;return new _A.BufferAttribute(I,e,t)}class mtA extends Dt{constructor(){super("renderer")}render(A){if(!A._inlines._value||!A._inlines._value.length)return;const e=A._inlines._value.map(g=>A._font._fontVariant.getGeometricGlyph(g,A).translate(g.offsetX,g.offsetY,0)),t=GtA(e);A.setFontMesh(new _A.Mesh(t,A.fontMaterial)),A._fontMesh.renderOrder=1/0}}class MtA extends jR{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(A){this._value=this._inheritedInput,A._layouter._needsProcess=!0}}class hE extends wd{constructor(e={}){const t={};hE.definePropertiesValues(t,e);super(t,e);r(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0});hE.init(this)}add(e){const t=[];for(let g=0;g<arguments.length;g++){const I=arguments[g];!I.isUI||I.isInline?(t.push(I),I.position.z=.005):console.warn("Block element can only contain Box elements.",I)}return super.add(...t)}set textContent(e){this._textContent.value=e}get textContent(){return this._textContent._value}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(e,t){e.children||(e.children=s2),e.textContent||(e.textContent=atA),e.glyphs||(e.glyphs=BtA),e.inlines||(e.inlines=rtA),e.layouter||(e.layouter=j_),e.renderer||(e.renderer=mtA),e.fontFamily||(e.fontFamily=$_),e.fontWeight||(e.fontWeight=X_),e.fontStyle||(e.fontStyle=Z_),e.fontSize||(e.fontSize=I2),e.color||(e.color=QtA),e.backgroundColor||(e.backgroundColor=EtA),e.lineBreak||(e.lineBreak=z_),e.letterSpacing||(e.letterSpacing=g2),e.whiteSpace||(e.whiteSpace=fU),e.segments||(e.segments=StA),e.textAlign||(e.textAlign=MtA),e.fontKerning||(e.fontKerning=ktA)}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class RtA extends ZH{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}update(A,e){this._needsUpdate=!1;for(let t=A.children.length-1;t>=0;t--){const g=A.children[t];g.isUI&&(A.remove(g),g.clear())}A._children._uis=[],this._value&&A.add(new hE({name:"anonymousInline",textContent:this._value}))}}class UtA extends Array{constructor(...A){super(...A),this.width=0,this.height=0}}class FtA extends Dt{constructor(){super("layouter",null,!1),this._value=null}update(A,e){}process(A){let e=A._width._value;A._width._auto?e=1/0:e=A._bounds._innerWidth;const t=A._lineHeight._value,g=new UtA(new Av);let I=0;A._children._inlines.forEach(B=>{if(!B._inlines.value)return;this._resetInlines(B);const Q=B._fontSize._value,E=B._letterSpacing._value*Q,c=B._whiteSpace._value,l=B._lineBreak._value,d={WHITESPACE:c,LETTERSPACING:E,BREAKON:l,INNER_WIDTH:e},h=B._whiteSpace._inlineWrapper;I+=B._margin._value.w+B._padding._value.w,B._inlines.value.forEach((p,u,f)=>{const S=g[g.length-1];if(h(f,u,I,d)){if(g.push(new Av(p)),p.offsetX=p.xoffset,p.width===0){I=0;return}p.cumulativeWidth=p.xadvance+E,I=p.cumulativeWidth;return}g[g.length-1].push(p),p.offsetX=I+p.xoffset+p.kerning,p.cumulativeWidth=p.xadvance+p.kerning+E,I+=p.cumulativeWidth,S.length-1===1&&S[S.length-2].width===0&&(p.offsetX-=p.xoffset,I-=p.xoffset)}),I+=B._margin._value.y+B._padding._value.y});const o=A._whiteSpace._inlineCollapser;let s=0,C=0,n=0;g.forEach((B,Q)=>{const E=o(B);let c=0,l=0;if(B.forEach(d=>{c=Math.max(c,d.lineHeight),l=Math.max(l,d.lineBase),d.offsetX-=E}),B.lineHeight=c,B.lineBase=l,Q===0?n=-(c*t-c)*.5:n-=g[Q-1].lineHeight*t,B.y=n,B.x=0,B.forEach(d=>{d.offsetY=n-d.anchor,d.lineHeight<B.lineHeight&&(d.offsetY-=B.lineBase-d.lineBase)}),C+=B.lineHeight*t,B.width=0,B[0]){const d=B[B.length-1];B.width=d.offsetX+d.cumulativeWidth+d.paddingRight+d.marginRight+B[0].offsetX,s=Math.max(s,B.width)}}),g.height=C,g.width=s,this._value=g,e===1/0&&A._bounds.setChildrenWidth(A,g.width),A._height._auto&&A._bounds.setChildrenHeight(A,g.height);const a=A._parent._value;a&&(a._autoSize._needsProcess=!0,a._flexDirection._needsProcess=!0),A._inlineJustificator._needsProcess=!0,A._textAlign._needsProcess=!0,A._overflow._needsUpdate=!0}_resetInlines(A){A._fontSize.process(A)}}class NtA extends jR{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput,this._needsProcess=!0}process(A){KtA(A),A._renderer._needsRender=!0}}function KtA(i){const A=i._layouter._value,e=i._textAlign._value,t=i._bounds._innerWidth;for(let g=0;g<A.length;g++){const I=A[g],o=JtA(i,I,g===A.length-1),s=i._padding._value,C=i._borderWidth._value,n=(-s.w+s.y)/2+(-C.w+C.y)/2;I.x+=o;for(let a=0;a<I.length;a++)I[a].offsetX+=o-n}if(e.indexOf("justify")===0)for(let g=0;g<A.length;g++){const I=A[g];if(e.indexOf("-")!==-1&&g===A.length-1)return;const o=t-I.width;if(o<=0)return;let s=0;for(let B=1;B<I.length-1;B++)s+=I[B].char===" "?1:0;const C=o/s;let n=1;e==="justify-right"&&(I.reverse(),n=-1);let a=0;for(let B=1;B<=I.length-1;B++){const Q=I[B];Q.offsetX+=a*n,a+=Q.char===" "?C:0}e==="justify-right"&&I.reverse()}}function JtA(i,A,e){switch(i._textAlign._value){case"justify-left":case"justify":case"left":return-i._bounds._innerWidth/2;case"justify-right":case"right":return-A.width+i._bounds._innerWidth/2;case"center":return-A.width/2;case"justify-center":return e?-A.width/2:-i._bounds._innerWidth/2;default:console.warn(`textAlign: '${i._textAlign._value}' is not valid`)}}class qtA extends ZR{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput}}class vtA extends s_{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class btA extends By{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A)}}class LtA extends P_{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class xtA extends Dt{constructor(){super("children",null,!1);r(this,"_sortOrder",(e,t)=>e._order._value<t._order._value?-1:e._order._value>t._order._value?1:this._uis.indexOf(e)<this._uis.indexOf(t)?-1:1);this._uis=[],this._inlines=[],this._boxes=[]}update(e,t){this._compute(e),this._needsProcess=!0}process(e){this._compute(e),e._overflow._needsRender=!0}_compute(e){this._uis=e.children.filter(t=>t.visible&&t.isUI),this._inlines=this._uis.filter(t=>t.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class TtA extends Dt{constructor(){super("autosize")}process(A){if(A._layouter._value&&A._layouter._value.length){const e=A._layouter._value,t=A._padding._value,g=A._borderWidth._value;A._width._auto&&A._bounds.setOffsetWidth(A,e.width+t.w+t.y+g.w+g.y),A._height._auto&&A._bounds.setOffsetHeight(A,e.height+t.x+t.z+g.x+g.z)}}}class YtA extends V_{constructor(){super("renderer"),this._needsUpdate=!1}render(A){super.render(A);for(const e of A._children._inlines)e._renderer.render(e);A.performAfterUpdate()}}class kl extends yl{constructor(A={},e={}){kl.definePropertiesValues(e,A),super(e,A),kl.init(this)}add(A){const e=[];let t=!1;for(let g=0;g<arguments.length;g++){const I=arguments[g];!I.isUI||I.isInline?(I.isInline&&(t=!0),e.push(I)):console.warn("Block element can only contain Box elements.",I)}return e.length>0&&super.add(...e),t&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(A){this._textContent.value=A}get textContent(){return super.textContent}set invertAlpha(A){this._invertAlpha.value=A}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(A,e){A.flexDirection=qtA,A.justifyContent=XR,A.alignItems=zR,A.bounds=LtA,A.autoSize=TtA,A.renderer=YtA,A.children||(A.children=xtA),A.textContent||(A.textContent=RtA),A.layouter||(A.layouter=FtA),A.lineHeight||(A.lineHeight=vtA),A.textAlign||(A.textAlign=NtA),A.whiteSpace||(A.whiteSpace=fU),A.fontKerning||(A.fontKerning=btA),A.segments||(A.segments=o2),e.width||(e.width="100%"),e.fontSide||(e.fontSide=0)}static init(A){Object.defineProperties(A,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class HtA extends Dt{constructor(){super("inlines",null,!1),this._value=[]}process(A){this._value[0].paddingLeft=A._padding._value.w,this._value[0].marginLeft=A._margin._value.w;const e=this._value.length-1;this._value[e].paddingRight=A._padding._value.y,this._value[e].marginRight=A._margin._value.y}}class _tA extends Dt{constructor(){super("renderer")}render(A){A._backgroundMesh||A.setBackgroundMesh(new W_(A)),A._backgroundMesh.position.x=A._inlines._value[0].offsetX+A._inlines._value[0].width/2,A._backgroundMesh.position.y=A._inlines._value[0].offsetY+A._inlines._value[0].lineBase/2,A._bounds.render(A)}}class OtA extends Dt{constructor(){super("bounds",null,!1),this._size=new _A.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(A,e){this.output(e),this._needsProcess=!0}process(A){this._offsetWidth=this._innerWidth=A._inlines._value[0].width,this._offsetHeight=this._innerHeight=A._inlines._value[0].height,this._needsRender=!0,A._borderWidth._needsRender=!0,A._borderRadius._needsRender=!0}render(A){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(A){A.size=this._size}}class Gl extends wd{constructor(A={}){const e={};Gl.definePropertiesValues(e,A),super(e,A),Gl.init(this)}clear(){for(const A of this._inlines._value)A.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new _A.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(A){const e=[];for(let t=0;t<arguments.length;t++){const g=arguments[t];g.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",g):(e.push(g),g.position.z=.005)}return super.add(...e)}static definePropertiesValues(A,e){A.children||(A.children=s2),A.bounds||(A.bounds=OtA),A.inlines||(A.inlines=HtA),A.layouter||(A.layouter=j_),A.renderer||(A.renderer=_tA),A.fontFamily||(A.fontFamily=$_),A.fontWeight||(A.fontWeight=X_),A.fontStyle||(A.fontStyle=Z_),A.fontSize||(A.fontSize=I2),A.backgroundColor||(A.backgroundColor=VH),A.lineBreak||(A.lineBreak=z_),A.letterSpacing||(A.letterSpacing=g2),A.whiteSpace||(A.whiteSpace=fU),A.fontKerning||(A.fontKerning=By),e.backgroundSize||(e.backgroundSize="cover"),e.width||(e.width="100%"),e.height||(e.height="100%"),e.boxSizing||(e.boxSizing="border-box")}static init(A){Object.defineProperties(A,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),A._inlines._value=[new PtA(A)],A.backgroundMaterial=new O_,A._renderer.render(A)}}class PtA extends t_{constructor(A){super(),this._uiElement=A}get xadvance(){const A=this._uiElement._padding._value,e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.w+A.y+e.value}get width(){const A=this._uiElement._width;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get height(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get anchor(){return this.height}get lineHeight(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get lineBase(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}clear(){this._uiElement=null}}class C2{constructor(A){this._subject=A}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const n2=()=>ED.update(),a2={BaseProperty:Dt,Block:Sl,Text:kl,Inline:hE,InlineBlock:Gl,MeshUIBaseElement:wd,FontLibrary:AB,update:n2,MSDFFontMaterialUtils:vo,ShaderChunkUI:__,Behavior:C2,FontVariant:ud};typeof global<"u"&&(global.ThreeMeshUI=a2);const WtA=a2;var VtA=Ti.w8,r2=Ti.cg,DU=Ti.gO,ztA=Ti.wb,Rm=Ti.zV,jtA=Ti.HS,ZtA=Ti.Ec,cf=Ti.gF,XtA=Ti.ol,$tA=Ti.pz,AiA=Ti.tx,eiA=Ti.hj,tiA=Ti.FV,iiA=Ti.sV,B2=Ti.xv,giA=Ti.mx,IiA=Ti.gE,oiA=Ti.ZP,Q2=Ti.Vx;const ok=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:VtA,Behavior:r2,Block:DU,DefaultValues:ztA,FontLibrary:Rm,FontVariant:jtA,InheritableProperty:ZtA,Inline:cf,InlineBlock:XtA,InlineGlyph:$tA,MSDFFontMaterialUtils:AiA,MaterialTransformers:eiA,MeshUIBaseElement:tiA,ShaderChunkUI:iiA,Text:B2,TypographicFont:giA,TypographicGlyph:IiA,default:oiA,update:Q2},Symbol.toStringTag,{value:"Module"})),siA=sA("debugshadowcomponents");DU.prototype.interactable={get(){return this.interactive},set(i){this.interactable=i}};const Os=Symbol("shadowDomOwner");class ps extends NA{constructor(){super(...arguments);r(this,"shadowComponent",null);r(this,"_controlsChildLayout",!0);r(this,"_root");r(this,"_parentComponent")}isRoot(){var e;return((e=this.Root)==null?void 0:e.gameObject)===this.gameObject}get canvas(){const e=this.Root;return e!=null&&e.isCanvas?e:null}markDirty(){nI.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(e){this._controlsChildLayout=e,this.shadowComponent&&(this.shadowComponent.autoLayout=e)}get Root(){return this._root===void 0&&(this._root=IA.getComponentInParent(this.gameObject,yd)),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(e,t){var o;this.removeShadowComponent();const g=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=IA.getComponentInParent(g,ps),!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}e.name=this.name+" ("+(this.constructor.name??"UI")+")",e.autoLayout=this._parentComponent.controlsChildLayout,e[Os]=this,this.setShadowComponentOwner(e);let I=!1;if(((o=this.Root)==null?void 0:o.gameObject)===this.gameObject)this.gameObject.add(e);else{const s=this._parentComponent.shadowComponent;s&&(s==null||s.add(e),I=!0)}this.shadowComponent=e,t&&t.shadowComponent&&this.shadowComponent&&t.shadowComponent.add(this.shadowComponent),rd&&e.add(new GE(.5)),this.onAfterAddedToScene(),I&&Q2(),siA&&console.log(this.shadowComponent)}set(e){}setShadowComponentOwner(e){if(e&&(e[Os]===void 0||e[Os]===this)&&(e[Os]=this,e.children))for(const t of e.children)this.setShadowComponentOwner(t)}traverseOwnedShadowComponents(e,t,g){if(e&&e[Os]===t){g(e);for(const I of e.children)this.traverseOwnedShadowComponents(I,t,g)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(e){this.shadowComponent&&(this.shadowComponent.interactable=e)}}class yd extends ps{awake(){super.awake()}}class lE{static getObject(A){const e=A[Os];return e&&(e.isComponent===!0?A=e.gameObject:A=e),A}static isInteractable(A,e){if(e&&(e.canvasGroup=void 0,e.graphic=void 0),A==null||!A.visible||(A=this.getObject(A),!A.visible))return!1;const t=this.tryFindCanvasGroup(A);if((t==null?void 0:t.isCanvasGroup)===!0&&(e&&(e.canvasGroup=t),t.blocksRaycasts===!1||t.interactable===!1))return!1;const g=$r(A,I=>{if(I.isGraphic===!0)return I},!1);return e&&(g==null?void 0:g.isGraphic)===!0&&(e.graphic=g),!((g==null?void 0:g.raycastTarget)===!1||(g==null?void 0:g.layer)===2)}static tryFindCanvasGroup(A){if(!A)return null;const e=$r(A,t=>{const g=t;if(g.blocksRaycasts!==void 0&&g.interactable!==void 0)return g},!1);return e!==void 0?e:this.tryFindCanvasGroup(A.parent)}}const sh=sA("debugwebxrcontroller");var VQ=(i=>(i[i.PhysicalDevice=0]="PhysicalDevice",i[i.Touch=1]="Touch",i))(VQ||{}),LC=(i=>(i.SelectStart="select-start",i.SelectEnd="select-end",i.Update="update",i))(LC||{});class ly extends NA{}const Ig=class extends NA{constructor(){super(...arguments);r(this,"webXR");r(this,"index",-1);r(this,"controllerModel");r(this,"controller");r(this,"controllerGrip");r(this,"hand");r(this,"handPointerModel");r(this,"grabbed",null);r(this,"input",null);r(this,"type",0);r(this,"showRaycastLine",!0);r(this,"_wristQuaternion",null);r(this,"movementVector",new w);r(this,"worldRot",new GA);r(this,"joystick",new tA);r(this,"didRotate",!1);r(this,"didTeleport",!1);r(this,"didChangeScale",!1);r(this,"lastHit",null);r(this,"raycastLine",null);r(this,"_raycastHitPoint",null);r(this,"_connnectedCallback",null);r(this,"_disconnectedCallback",null);r(this,"_selectStartEvt",null);r(this,"_selectEndEvt",null);r(this,"_selectionPressed",!1);r(this,"_selectionPressedLastFrame",!1);r(this,"_selectionStartTime",0);r(this,"_selectionEndTime",0);r(this,"_useSmoothing",!0);r(this,"_isConnected",!1);r(this,"rayRotation",new GA);r(this,"_pinchStartTime");r(this,"selectStartCallback",null);r(this,"lastSelectStartObject",null);r(this,"_didNotEndSelection",!1);r(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const e=new pi(this.geometry),t=e.material;return t.color=this.raycastColor,e.layers.set(2),e.name="line",e.scale.z=1,e}static CreateRaycastHitPoint(){const e=new Vo(.5,22,22),t=new ct({color:this.raycastColor}),g=new wA(e,t);return g.visible=!1,g.layers.set(2),g}static Create(e,t,g,I){const o=g?IA.addNewComponent(g,Ig,!1):new Ig;o.webXR=e,o.index=t,o.type=I;const s=e.context;o.controller=s.renderer.xr.getController(t),o.controllerGrip=s.renderer.xr.getControllerGrip(t),o.controllerModel=this.Factory.createControllerModel(o.controller),o.controllerGrip.add(o.controllerModel),o.hand=s.renderer.xr.getHand(t);const C=new KE;cd(C,s),o.webXR.handModelPath&&o.webXR.handModelPath!==""?C.setPath(Sn(e.sourceId,o.webXR.handModelPath)):C.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const n=new G7(o.hand,C);return o.hand.add(n),o.hand.traverse(a=>a.layers.set(2)),o.handPointerModel=new K7(o.hand,o.controller),o.controller.addEventListener("connected",a=>{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",a=>{var Q;if(a.data.hand){e.Rig&&e.Rig.add(o.hand),o.type=0,o.handPointerModel.traverse(c=>c.layers.set(2)),(Q=o.handPointerModel.pointerObject)==null||Q.traverse(c=>c.layers.set(2));const E=o.hand.joints;if(E)for(const c of Object.keys(E)){const l=E[c];l.parent||o.hand.add(l)}}}),o}static addEventListener(e,t){const g=this.eventSubs[e]??[];g.push(t),this.eventSubs[e]=g}static removeEventListener(e,t){if(!t)return;const g=this.eventSubs[e]??[],I=g.indexOf(t);I>=0&&g.splice(I,1),this.eventSubs[e]=g}get isUsingHands(){var t;const e=(t=this.input)==null?void 0:t.hand;return e!=null}get wrist(){if(!this.hand)return null;const e=this.hand.joints;return e?e.wrist:null}getWristQuaternion(){const e=this.wrist;return e?(this._wristQuaternion||(this._wristQuaternion=new GA),Zi(e).multiply(this._wristQuaternion.setFromEuler(new yi(-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 e,t,g;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)),(e=this.hand)==null||e.clear(),(t=this.controllerGrip)==null||t.clear(),(g=this.controller)==null||g.clear()}onEnable(){var e,t,g,I,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=Ig.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=Ig.CreateRaycastHitPoint()),(e=this.webXR.Rig)==null||e.add(this.hand),(t=this.webXR.Rig)==null||t.add(this.controllerGrip),(g=this.webXR.Rig)==null||g.add(this.controller),(I=this.webXR.Rig)==null||I.add(this.raycastLine),(o=this.raycastLine)==null||o.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),sh&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var e,t,g,I,o;if((e=this.hand)==null||e.removeFromParent(),(t=this.controllerGrip)==null||t.removeFromParent(),(g=this.controller)==null||g.removeFromParent(),(I=this.raycastLine)==null||I.removeFromParent(),(o=this._raycastHitPoint)==null||o.removeFromParent(),this.webXR){const s=this.webXR.Controllers.indexOf(this);s>=0&&this.webXR.Controllers.splice(s,1)}}onSourceConnected(e){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,e);return}this._isConnected=!0,this.input=e.data,this.type===1&&this.onSelectStart()}onSourceDisconnected(e){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",e);return}this._isConnected=!1,this.type===1&&this.onSelectEnd(),this.input=null}createPointerEvent(e){switch(e){case"down":this.context.input.createPointerDown(new vC(Ki.PointerDown,null,{clientX:0,clientY:0,button:this.index,pointerType:CE.Touch}));break;case"move":break;case"up":this.context.input.createPointerUp(new vC(Ki.PointerUp,null,{clientX:0,clientY:0,button:this.index,pointerType:CE.Touch}));break}}raycastUpdate(e,t){const g=this.showRaycastLine&&this.type!==1;if(this.type===1)e.visible=!1;else if(this.isUsingHands){e.visible=!this.grabbed&&g,bi(e,t);const I=this.hand.joints;if(I&&I.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const s=this.getWristQuaternion();s&&this.rayRotation.copy(s)}LI(e,this.rayRotation)}else e.visible=g,LI(e,this.rayRotation),bi(e,t)}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 e=Ig.eventSubs.update;if(e&&e.length>0)for(const I of e)I(this);let t=1;this.type===0?t=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(t=this.context.time.deltaTime/.3),this.rayRotation.slerp(Zi(this.controller),this.useSmoothing?t:1);const g=ke(this.controller);this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine&&this.raycastUpdate(this.raycastLine,g),this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(e){var I,o;if(this.lastHit=null,!e||e.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=e.inputSources[this.index]),!this.input)return;const t=this.webXR.Rig;if(!t)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const g=(o=(I=this.input)==null?void 0:I.gamepad)==null?void 0:o.buttons;switch(this.input.handedness){case"left":this.movementUpdate(t,g);break;case"right":this.rotationUpdate(t,g);break}}movementUpdate(e,t){const g=3*Ig.MovementSpeedFactor,I=2,o=ie.clamp01(this.joystick.length()*2),s=this.joystick.x>0?1:-1;let C=Math.pow(this.joystick.x,I);C*=s,C*=o;const n=this.joystick.y>0?1:-1;let a=Math.pow(this.joystick.y,I);a*=n,C*=o,e.getWorldQuaternion(this.worldRot),this.movementVector.set(C,0,a),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(g*this.context.time.deltaTime),e.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(e,t)}rotationUpdate(e,t){const g=this.joystick.x,I=Math.abs(g);if(I<.4)this.didRotate=!1;else if(I>.5&&!this.didRotate){const o=g>0?-1:1;e.rotateY(ie.toRadians(30*o)),this.didRotate=!0}this.runTeleport(e,t)}runTeleport(e,t){var a,B;let g=-this.joystick.y;if((a=this.hand)!=null&&a.visible&&!this.grabbed){const Q=this.handPointerModel.isPinched();Q&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),Q&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(g=this.handPointerModel.isPinched()?1:0),Q||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;const I=this.webXR.IsInVR,o=this.webXR.Rig;let s=g>.5&&I,C=o?((B=o==null?void 0:o.scale)==null?void 0:B.x)<.999:!1,n=null;if(t&&this.input&&!this.input.hand)for(let Q=0;Q<t.length;Q++){const E=t[Q];if(Q===4)if(E.pressed&&!this.didChangeScale&&I){this.didChangeScale=!0;const c=o;if(c){const l=this.switchScale(c,s,C,n);s=l.doTeleport,C=l.isInMiniatureMode,n=l.newRigScale}}else E.pressed||(this.didChangeScale=!1)}if(s){if(!this.didTeleport){const Q=this.raycast();if(this.didTeleport=!0,Q&&Q.length>0){const E=Q[0];if(C||this.isValidTeleportTarget(E.object)){const c=E.point;bi(e,c)}}}}else g<.1&&(this.didTeleport=!1);n!==null&&(e.scale.set(n,n,n),e.updateMatrixWorld())}isValidTeleportTarget(e){return IA.getComponentInParent(e,ly)!=null}switchScale(e,t,g,I){if(g){g=!1,e.scale.set(1,1,1),I=1,Ig.MovementSpeedFactor=1;const o=this.context.mainCamera;Ig.PreviousCameraFarDistance&&(o.far=Ig.PreviousCameraFarDistance)}else{g=!0,t=!0,I=.1,Ig.MovementSpeedFactor=I*2;const o=this.context.mainCamera;Ig.PreviousCameraFarDistance=o.far,o.far/=I}return{doTeleport:t,isInMiniatureMode:g,newRigScale:I}}updateStick(e){var t;!e||!e.gamepad||((t=e.gamepad.axes)==null?void 0:t.length)<4||(this.joystick.x=e.gamepad.axes[2],this.joystick.y=e.gamepad.axes[3])}updateLastHit(){var I;const e=this.raycast(),t=e?e[0]:null;this.lastHit=t;let g=1;if(this.webXR.Rig&&(g/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=g*(((I=this.lastHit)==null?void 0:I.distance)??9999);const o=this.raycastLine.material;t!=null?o.color=Ig.raycastColor:o.color=Ig.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const o=ie.clamp(this.lastHit.distance*.01*g,.015,.1);this._raycastHitPoint.scale.set(o,o,o)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return t}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 e=null,t=!1;if(this.isUsingHands?(e=this.overlap(),e.length<=0?(e=this.raycast(),t=!1):t=!0):e=this.raycast(),sh&&console.log("onHandleSelectStart","close grab? "+t,"intersections",e),e&&e.length>0)for(const g of e){const I=g.object;this.lastSelectStartObject=I;const o={selected:I,grab:I},s=Ig.eventSubs["select-start"];if(s&&s.length>0)for(const C of s)C(this,o);o.grab!==I&&sh&&console.log("Grabbed object changed","original",I,"new",o.grab),o.grab&&(this.grabbed=To.TryTake(this,o.grab,g,t));break}else{const g=Ig.eventSubs["select-start"],I={selected:null,grab:null};if(g&&g.length>0)for(const o of g)o(this,I)}}onSelectEnd(){var g;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 e={grab:((g=this.grabbed)==null?void 0:g.selected)??this.lastSelectStartObject},t=Ig.eventSubs["select-end"];if(t&&t.length>0)for(const I of t)I(this,e);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(e){return!(!e||IA.isActiveInHierarchy(e)===!1||lE.isInteractable(e)===!1)}setControllerLayers(e,t){var g,I;if(e&&(e.layers.set(t),e.children))for(const o of e.children)((g=this.grabbed)==null?void 0:g.selected)===o||((I=this.grabbed)==null?void 0:I.selectedMesh)===o||this.setControllerLayers(o,t)}getRay(){const e=new nC;return e.origin.copy(ke(this.controller)),e.direction.set(0,0,-1).applyQuaternion(this.rayRotation),e}overlap(){const e=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(sh&&(!this.closeGrabBoundingBoxHelper&&e&&(this.closeGrabBoundingBoxHelper=new Rw(e,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&e&&this.closeGrabBoundingBoxHelper.setFromObject(e)),!e)return new Array;const t=ke(e).clone();return this.context.physics.sphereOverlap(t,.02)}raycast(){const e=new Wo;e.layerMask=new Yg,e.layerMask.enableAll(),e.layerMask.disable(2),e.ray=this.getRay();const t=this.context.physics.raycast(e);for(let g=0;g<t.length;g++){const I=t[g],o=I.object;if(!this.testIsVisible(o)){t.splice(g,1),g--;continue}I.object=lE.getObject(o);break}return t}};let ai=Ig;r(ai,"Factory",new P7),r(ai,"raycastColor",new SA(.9,.3,.3)),r(ai,"raycastNoHitColor",new SA(.6,.6,.6)),r(ai,"geometry",new le().setFromPoints([new w(0,0,0),new w(0,0,-1)])),r(ai,"handModels",{}),r(ai,"eventSubs",{}),r(ai,"PreviousCameraFarDistance"),r(ai,"MovementSpeedFactor",1);var hD=(i=>(i.WillTake="WillTake",i.DidTake="DidTake",i.WillFree="WillFree",i.DidFree="DidFree",i))(hD||{});const iI=class{constructor(){r(this,"sync",null);r(this,"selected",null);r(this,"selectedParent",null);r(this,"selectedMesh",null);r(this,"controller",null);r(this,"grabTime",0);r(this,"grabUUID","");r(this,"isCloseGrab",!1);r(this,"originalMaterial",null);r(this,"usageMarker",null);r(this,"rigidbodies",null);r(this,"didReparent",!1);r(this,"grabDistance",0);r(this,"interactable",null);r(this,"positionSource",null);r(this,"grabPoint",new w);r(this,"localPositionOffsetToGrab",null);r(this,"localPositionOffsetToGrab_worldSpace",new w);r(this,"localQuaternionToGrab",new GA(0,0,0,1));r(this,"targetDir",null);r(this,"quaternionLerp",null);r(this,"controllerDir",new w);r(this,"controllerWorldPos",new w);r(this,"lastControllerWorldPos",new w);r(this,"controllerPosDelta",new w);r(this,"totalChangeAlongDirection",0);r(this,"rigPositionLastFrame",new w)}static AddEventListener(A,e){return iI.Events[A]||(iI.Events[A]=[]),iI.Events[A].push(e),e}static RemoveEventListener(A,e){if(!e||!iI.Events[A])return;const t=iI.Events[A].indexOf(e);t>=0&&iI.Events[A].splice(t,1)}static Register(A){this.Current.find(e=>e===A)||this.Current.push(A)}static Remove(A){const e=this.Current.indexOf(A);e>=0&&this.Current.splice(e,1)}static TryTake(A,e,t,g){const I=IA.getComponentInParent(e,vE);if(I)e=I.gameObject;else return sh&&console.warn("Prevented taking object that is not interactable",e),null;let o=e;const s=IA.getComponentInParent(e,Ma);s&&(s.requestOwnership(),o=s.gameObject);for(const n of this.Current)if(n.selected===o)return n.controller===A||(n.free(),n.Take(A,o,e,s,I,t,g)),n;const C=new iI;return C.Take(A,o,e,s,I,t,g),C}Take(A,e,t,g,I,o,s){var E,c;if(console.assert(e!==null,"Expected object to be taken but was",e),A.isUsingHands?this.positionSource=s?A.wrist:A.controller:this.positionSource=A.controller,!this.positionSource)return console.warn("No position source"),this;const C={controller:A,take:e,hit:t,sync:g,interactable:I};(E=iI.Events.WillTake)==null||E.forEach(l=>l(this,C));const n=t;n!=null&&n.material&&(this.originalMaterial=n.material,Array.isArray(n.material)||(n.material=n.material.clone(),n.material&&n.material.emissive&&(n.material.emissive.b=.2))),this.selected=e,this.selectedParent||(this.selectedParent=e.parent),this.selectedMesh=n,this.controller=A,this.interactable=I,this.isCloseGrab=s,this.didReparent=!1,this.sync=g,this.grabTime=A.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=IA.addNewComponent(this.selected,bE),this.rigidbodies=IA.getComponentsInChildren(this.selected,qt),ke(this.positionSource,this.lastControllerWorldPos);const a=()=>s?this.lastControllerWorldPos.clone():o.point.clone();this.grabDistance=a().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(a());const B=A.isUsingHands&&s?this.controller.getWristQuaternion().clone():A.rayRotation.clone();Zi(this.selected,this.localQuaternionToGrab).premultiply(B.invert());const Q=this.controller.webXR.Rig;return Q&&this.rigPositionLastFrame.copy(ke(Q)),BI.Add(A.context,this.selected),iI.Register(this),this.sync&&(this.sync.fastMode=!0),(c=iI.Events.DidTake)==null||c.forEach(l=>l(this,C)),this}free(){var g,I,o,s;if(!this.selected)return;const A={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(g=iI.Events.WillFree)==null||g.forEach(C=>C(this,A)),BI.Remove(this.controller.context,this.selected),iI.Remove(this),this.sync&&(this.sync.fastMode=!1);const e=this.selectedMesh;e&&this.originalMaterial&&e.material&&(e.material=this.originalMaterial);const t=this.selected;if(this.didReparent&&t.parent){const C=this.selectedParent;C?C.attach(t):(I=this.controller)==null||I.context.scene.attach(t)}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,(s=iI.Events.DidFree)==null||s.forEach(C=>C(this,A))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),ke(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const A=this.controller.webXR.Rig;if(A){const t=ke(A),g=this.rigPositionLastFrame.sub(t);this.controllerPosDelta.add(g),this.rigPositionLastFrame.copy(t)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var A;if(this.rigidbodies)for(const e of this.rigidbodies)e.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 e=((A=this.controller.webXR.Rig)==null?void 0:A.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let t=1;this.controller.type===0&&(t=Math.max(0,1+this.totalChangeAlongDirection*2/e),t=t*t*t),this.grabDistance/e<.8&&(t=1),this.targetDir||(this.targetDir=new w),this.targetDir.set(0,0,-this.grabDistance*t);const g=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),I=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=I.clone()),this.quaternionLerp.slerp(I,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),LI(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(g),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(ke(this.selected)),g.sub(this.localPositionOffsetToGrab_worldSpace)),bi(this.selected,g)}if(this.rigidbodies!=null)for(const e of this.rigidbodies)e.wakeUp();qI.markDirty(this.selected,!0)}}};let To=iI;r(To,"Events",{}),r(To,"Current",[]);class en{constructor(A,e){r(this,"used",!1);r(this,"inputSource");r(this,"object");r(this,"pointerId");r(this,"isDown");r(this,"isUp");r(this,"isPressed");r(this,"isClicked");r(this,"input");r(this,"_event");this._event=e,this.input=A}use(){this.used=!0,this.pointerId!==void 0&&this.input.setPointerUsed(this.pointerId)}stopPropagation(){var A;(A=this._event)==null||A.stopImmediatePropagation()}Use(){this.use()}StopPropagation(){var A;(A=this._event)==null||A.stopImmediatePropagation()}get event(){return this._event}clone(){const A=new en(this.input,this._event);return Object.assign(A,this),A}}class YE extends NA{awake(){nI.createIfNoneExists(this.context)}onEnable(){var A;(A=nI.get(this.context))==null||A.register(this)}onDisable(){var A;(A=nI.get(this.context))==null||A.unregister(this)}performRaycast(A=null){return null}}class pn extends YE{constructor(){super(...arguments);r(this,"targets",null);r(this,"raycastHits",[])}start(){this.targets=[this.gameObject]}performRaycast(e=null){return this.targets?(e??(e=new Wo),e.targets=this.targets,e.results=this.raycastHits,this.context.physics.raycast(e)):null}}class wU extends pn{}const fQ=sA("debugeventsystem");var Um=(i=>(i.BeforeHandleInput="BeforeHandleInput",i.AfterHandleInput="AfterHandleInput",i))(Um||{});const Ls=class extends NA{constructor(){super();r(this,"raycaster",[]);r(this,"_selectStartFn");r(this,"_selectEndFn");r(this,"_selectUpdateFn");r(this,"_handleEventCycleFn");r(this,"_handleInputFn");r(this,"pressedByID",new Map);r(this,"hoveredByID",new Map);r(this,"_sortedHits",[]);r(this,"_sortingBuffer",[]);r(this,"_noDepthTestingResults",[]);r(this,"out",{});r(this,"currentActiveMeshUIComponents",[]);Ls.systems.push(this)}static createIfNoneExists(e){this.didSearchEventSystem||(this.didSearchEventSystem=!0,Ls.systems.length<=0&&Ls.systems.push(...IA.findObjectsOfType(Ls,e)));for(const g of Ls.systems)if(g.context===e)return;const t=new FA;IA.addNewComponent(t,Ls),e.scene.add(t)}static get systems(){const e=Le.Current;return this._eventSystemMap.has(e)||this._eventSystemMap.set(e,[]),this._eventSystemMap.get(e)}static get(e){const t=this._eventSystemMap.get(e);return t&&t.length>0?t[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(e,t,g=!1){xC.update(e,t,g)}static markUIDirty(e){xC.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.hoveredByID.size>0}onDestroy(){Ls.systems.splice(Ls.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!IA.findObjectOfType(YE,this.context)){const t=IA.addNewComponent(this.context.scene,pn);this.raycaster.push(t),(rt()||fQ)&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found")}}register(e){var t;e&&this.raycaster&&!this.raycaster.includes(e)&&((t=this.raycaster)==null||t.push(e))}unregister(e){var g,I;const t=(g=this.raycaster)==null?void 0:g.indexOf(e);t!==void 0&&t!==-1&&((I=this.raycaster)==null||I.splice(t,1))}onEnable(){const e=new Map;this._selectStartFn??(this._selectStartFn=(g,I)=>{if(!I.grab)return;xC.resetLastSelected();const o=new en(this.context.input);o.inputSource=g,o.pointerId=0,o.isDown=g.selectionDown,o.isUp=g.selectionUp,o.isPressed=g.selectionPressed,o.isClicked=!1,e.set(g,I.grab),I.grab&&!this.handleEventOnObject(I.grab,o)&&(I.grab=null)}),this._selectEndFn??(this._selectEndFn=(g,I)=>{var C;if(!I.grab)return;const o=new en(this.context.input);o.inputSource=g,o.pointerId=0,o.isDown=g.selectionDown,o.isUp=g.selectionUp,o.isPressed=g.selectionPressed,o.isClicked=g.selectionClick,this.handleEventOnObject(I.grab,o);const s=e.get(g);if(e.set(g,null),s)for(const n of this.pressedByID.keys()){const a=this.pressedByID[n];a.obj===s&&a.handler&&((C=a.handler.onPointerUp)==null||C.call(a.handler,o),this.pressedByID.delete(n))}});const t=new Wo;this._selectUpdateFn??(this._selectUpdateFn=g=>{t.ray=g.getRay();const I=this.performRaycast(t);if(!I)return;const o=new en(this.context.input);o.inputSource=g,this.handleIntersections(I,o)}),ai.addEventListener(LC.SelectStart,this._selectStartFn),ai.addEventListener(LC.SelectEnd,this._selectEndFn),ai.addEventListener(LC.Update,this._selectUpdateFn),this._handleInputFn=this.onPointerEvent.bind(this),this.context.input.addEventListener(Ki.PointerDown,this._handleInputFn),this.context.input.addEventListener(Ki.PointerUp,this._handleInputFn),this.context.input.addEventListener(Ki.PointerMove,this._handleInputFn)}onDisable(){ai.removeEventListener(LC.SelectStart,this._selectStartFn),ai.removeEventListener(LC.SelectEnd,this._selectEndFn),ai.removeEventListener(LC.Update,this._selectUpdateFn),this.context.input.removeEventListener(Ki.PointerDown,this._handleInputFn),this.context.input.removeEventListener(Ki.PointerUp,this._handleInputFn),this.context.input.removeEventListener(Ki.PointerMove,this._handleInputFn)}onBeforeRender(){this.resetMeshUIStates()}onPointerEvent(e){if(e===void 0)return;const t=e.pointerType==CE.Touch?e.button:0,g=new en(this.context.input,e);g.inputSource=this.context.input,g.pointerId=t,g.isClicked=this.context.input.getPointerClicked(t),g.isDown=e.type==Ki.PointerDown,g.isUp=e.type==Ki.PointerUp,g.isPressed=this.context.input.getPointerPressed(t),fQ&&g.isClicked&&console.log("CLICK",t);const I=new Wo;I.screenPoint=this.context.input.getPointerPositionRC(t);const o=this.performRaycast(I);if(!o)return;fQ&&g.isClicked&&Di("EventSystem: "+g.pointerId+" - "+this.context.time.frame+" - Up:"+g.isUp+", Down:"+g.isDown);const s={sender:this,args:g,hasActiveUI:this.currentActiveMeshUIComponents.length>0};if(this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:s})),!this.handleIntersections(o,g)){const C=this.hoveredByID.get(t);if(C&&this.triggerOnExit(C.obj,C.data),this.hoveredByID.delete(t),g.isUp){const n=this.pressedByID.get(t);n==null||n.handlers.forEach(a=>{var B;return(B=a.onPointerUp)==null?void 0:B.call(a,g)}),this.pressedByID.delete(t)}}this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:s}))}performRaycast(e){if(!this.raycaster)return null;this._sortedHits.length=0;for(const t of this.raycaster){if(!t.activeAndEnabled)continue;const g=t.performRaycast(e);g&&g.length>0&&this._sortedHits.push(...g)}return this._sortedHits.sort((t,g)=>t.distance-g.distance),this._sortedHits}handleIntersections(e,t){if(!e||e.length<=0)return!1;e=this.sortCandidates(e);for(const g of e){const{object:I}=g;if(this.handleEventOnObject(I,t))return!0}return!1}sortCandidates(e){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let t=0;t<e.length;t++){const g=e[t],I=g.object;if(I.material&&I.material.depthTest===!1){this._noDepthTestingResults.push(g);continue}this._sortingBuffer.push(g)}for(const t of this._sortingBuffer)this._noDepthTestingResults.push(t);return this._noDepthTestingResults}handleEventOnObject(e,t){if(!this.testIsVisible(e))return t.isClicked&&fQ&&console.log("not allowed",e),!1;if(t.pointerId===void 0)return!1;t.object=e;const g=e.parent;let I=!1;const o=t.isClicked??!1;let s=null;if(g&&g.isUI){const a=(t.isPressed||t.isClicked)??!1;if(g[Os]){const B=g[Os].gameObject;if(B){if(!lE.isInteractable(B,this.out))return!1;s=this.out.canvasGroup??null,this.handleMeshUIIntersection(e,a),e=B,I=!0}}if(!I&&this.handleMeshUiObjectWithoutShadowDom(g,a))return!0}o&&fQ&&console.log(this.context.time.frame,e);const C=this.hoveredByID.get(t.pointerId),n=(C==null?void 0:C.obj)!==e;if(n&&(C!=null&&C.obj)&&this.triggerOnExit(C.obj,C.data),this.hoveredByID.set(t.pointerId,{obj:e,data:t}),t.isDown){const a=this.pressedByID.get(t.pointerId);a?(a.obj=e,a.data=t):this.pressedByID.set(t.pointerId,{obj:e,data:t,handlers:new Set})}return(s===null||s.interactable)&&this.handleMainInteraction(e,t,n),!0}propagate(e,t,g){for(;IA.foreachComponent(e,I=>{g(I)},!1),!!e.parent;)e=e.parent}handleMainInteraction(e,t,g){if(t.pointerId===void 0)return;const I=this.pressedByID.get(t.pointerId);this.propagate(e,t,o=>{var B;const s=o;if(s.interactable===!1)return;s.onPointerEnter&&g&&s.onPointerEnter(t),t.isDown&&s.onPointerDown&&(s.onPointerDown(t),I==null||I.handlers.add(s));const C=this.context.input.getPointerPositionLastFrame(t.pointerId),n=this.context.input.getPointerPosition(t.pointerId);C&&!ie.approximately(C,n)&&s.onPointerMove&&s.onPointerMove(t),t.isUp&&(s.onPointerUp&&(s.onPointerUp(t),I==null||I.handlers.delete(s)),s.onPointerExit&&((B=t.event)==null?void 0:B.pointerType)===CE.Touch&&(s.onPointerExit(t),this.hoveredByID.delete(t.pointerId))),t.isClicked&&s.onPointerClick&&s.onPointerClick(t)}),t.isUp&&(I==null||I.handlers.forEach(o=>{o.onPointerUp&&o.onPointerUp(t)}),this.pressedByID.delete(t.pointerId))}triggerOnExit(e,t){t.used=!1,this.propagate(e,t,g=>{if(!g.gameObject||g.destroyed)return;const I=g;I.onPointerExit&&I.onPointerExit(t)})}handleMeshUiObjectWithoutShadowDom(e,t){return!e||!e.isUI?!0:this.handleMeshUIIntersection(e,t)}handleMeshUIIntersection(e,t){const g=xC.updateState(e,t);return g&&this.currentActiveMeshUIComponents.push(g),g!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&xC.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let e=0;e<this.currentActiveMeshUIComponents.length;e++){const t=this.currentActiveMeshUIComponents[e];xC.resetState(t)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(e){return e?IA.isActiveSelf(e)?this.testIsVisible(e.parent):!1:!0}};let nI=Ls;r(nI,"_eventSystemMap",new Map),r(nI,"didSearchEventSystem",!1);class xC{static markDirty(){this.needsUpdate=!0}static update(A,e,t=!1){if(t){A.update();return}const g=e.time.frameCount;for(const I of this.lastUpdateFrame)if(I.context===e){if(g===I.frame)return;I.frame=g;let o=this.needsUpdate||g<1;I.nextUpdate===e.time.frameCount&&(o=!0),o&&(fQ&&console.log("Update threemeshui"),this.needsUpdate=!1,A.update());return}this.lastUpdateFrame=[{context:e,frame:g,nextUpdate:g}],A.update()}static updateState(A,e){let t=null;if(A&&(t=this.findBlockInParent(A),t&&t!==this.lastSelected)){if(t.interactable===!1)return null;this.needsUpdate=!0}return t}static resetLastSelected(){const A=this.lastSelected;A&&(this.lastSelected=null,this.resetState(A))}static resetState(A){A&&(this.needsUpdate=!0)}static findBlockInParent(A){return A?A.isBlock?A:this.findBlockInParent(A.parent):null}}r(xC,"lastSelected",null),r(xC,"lastUpdateFrame",[]),r(xC,"needsUpdate",!1);const hf=Symbol("cameraController");function CiA(i){return i[hf]}function iv(i,A,e){e?i[hf]=A:i[hf]===A&&(i[hf]=null)}function dy(i){const A=i[Os];return A||(i.parent?dy(i.parent):null)}function lD(i,A){if(!i)return;const e=i.material;if((e==null?void 0:e.isMaterial)===!0){const t=i.parent;t&&t.isText,e.side=A.doubleSided??!0?mt:_g,e.shadowSide=A.doubleSided?mt:_g,i.castShadow=A.castShadows?A.castShadows:!1,i.receiveShadow=A.receiveShadows?A.receiveShadows:!1}for(const t of i.children)lD(t,A)}function DQ(i,A,e){i[A]===void 0&&console.warn("Field",A,"is undefined on",i);const t=Proxy.revocable(i[A],{set(o,s,C,n){const a=o[s],B=Reflect.set(o,s,C,n);return e(C,a),B}}),g=t.revoke,I=i[A];return t.revoke=()=>{i[A]=I,g()},i[A]=t.proxy,t}const gv=Symbol("Scheduled action");function niA(i,A,e=xI.OnBeforeRender){let t=i[gv];t||(t=i[gv]={});const g=A.name;t[e]||(t[e]={});const I=t[e];if(I[g])return;function*s(){A==null||A.call(i),I[g]=null}const C=i.startCoroutine(s(),e);I[g]=C}class E2 extends wA{constructor(A,e={}){const g=[A.isCubeTexture?"#define ENVMAP_TYPE_CUBE":""],I=`
|
|
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
|
-
`,s={map:{value:A},height:{value:e.height||15},radius:{value:e.radius||100}},C=new Ad(1,16),n=new be({uniforms:s,fragmentShader:o,vertexShader:I,side:mt});super(C,n)}set radius(A){this.material.uniforms.radius.value=A}get radius(){return this.material.uniforms.radius.value}set height(A){this.material.uniforms.height.value=A}get height(){return this.material.uniforms.height.value}}var aiA=Object.defineProperty,riA=Object.getOwnPropertyDescriptor,dI=(i,A,e,t)=>{for(var g=t>1?void 0:t?riA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&aiA(A,e,g),g};const cp=sA("freecam"),bc=sA("debugcamerafit"),hp=sA("smoothcam"),BiA={LEFT:"",UP:"",RIGHT:"",BOTTOM:""};let sk;class ii extends NA{constructor(){super(...arguments);r(this,"enableRotate",!0);r(this,"autoRotate",!1);r(this,"autoRotateSpeed",1);r(this,"autoFit",!1);r(this,"enableKeys",!0);r(this,"enableDamping",!0);r(this,"dampingFactor",.1);r(this,"enableZoom",!0);r(this,"minZoom",0);r(this,"maxZoom",1/0);r(this,"enablePan",!0);r(this,"lookAtConstraint",null);r(this,"lookAtConstraint01",1);r(this,"middleClickToFocus",!0);r(this,"doubleClickToFocus",!0);r(this,"useSlerp",!0);r(this,"debugLog",!1);r(this,"targetLerpSpeed",5);r(this,"autoTarget",!0);r(this,"_lookTargetPosition");r(this,"_controls",null);r(this,"_cameraObject",null);r(this,"_lerpToTargetPosition",!1);r(this,"_lerpCameraToTarget",!1);r(this,"_cameraTargetPosition",null);r(this,"_inputs",0);r(this,"_enableTime",0);r(this,"_startedListeningToKeyEvents",!1);r(this,"_eventSystem");r(this,"_afterHandleInputFn");r(this,"_camera",null);r(this,"_syncedTransform");r(this,"_didStart",!1);r(this,"targetElement",null);r(this,"onControlsChangeStarted",()=>{this._syncedTransform&&this._syncedTransform.requestOwnership()});r(this,"_shouldDisable",!1);r(this,"_haveAttachedKeyboardEvents",!1)}get isCameraController(){return!0}get controls(){return this._controls}get controllerObject(){return this._cameraObject}onStartInteraction(e){var t;(t=this.controls)==null||t.addEventListener("start",e)}awake(){this._didStart=!1,this._lookTargetPosition=new w,this._startedListeningToKeyEvents=!1}start(){if(this._didStart=!0,this.autoTarget&&this._controls){const e=IA.getComponent(this.gameObject,Ht);if(e&&!this.setFromTargetPosition()){this.debugLog&&console.log("NO TARGET");const g=ke(e.cam).length(),I=new w(0,0,-g).applyMatrix4(e.cam.matrixWorld);this.setTarget(I,!0)}if(this.autoTarget&&!this.setFromTargetPosition()){const t=new Wo;t.screenPoint=new tA(0,0),t.lineThreshold=.1;const g=this.context.physics.raycast(t);g.length>0&&this.setTarget(g[0].point,!0),bc&&console.log("OrbitControls hits",...g)}this.autoFit&&this.fitCamera()}this._eventSystem=nI.get(this.context)??void 0,this._eventSystem&&(this._afterHandleInputFn=this.afterHandleInput.bind(this),this._eventSystem.addEventListener(Um.AfterHandleInput,this._afterHandleInputFn))}onDestroy(){var e,t;(e=this._controls)==null||e.dispose(),(t=this._eventSystem)==null||t.removeEventListener(Um.AfterHandleInput,this._afterHandleInputFn)}onEnable(){this._enableTime=this.context.time.time;const e=IA.getComponent(this.gameObject,Ht);this._camera=e;const t=e==null?void 0:e.cam;if(t&&iv(t,this,!0),!this._controls){if(!t){console.warn("OrbitControls: Requires a Camera component on the same object as this component.");return}t&&(this._cameraObject=t);const g=this.targetElement??this.context.domElement,I=t==null?void 0:t.quaternion.clone();this._controls=new D7(t,g),t==null||t.quaternion.copy(I),sk===void 0&&(sk={...this._controls.keys})}this._controls&&(cp&&(this.enablePan=!0,this.enableZoom=!0,this.middleClickToFocus=!0,kn()&&(this.doubleClickToFocus=!0)),this._controls.addEventListener("start",this.onControlsChangeStarted),(t==null?void 0:t.type)==="PerspectiveCamera"?cp||(this._controls.minDistance=this.minZoom,this._controls.maxDistance=this.maxZoom):cp||(this._controls.minZoom=this.minZoom,this._controls.maxZoom=this.maxZoom),this._startedListeningToKeyEvents||(this._startedListeningToKeyEvents=!0,this._controls.listenToKeyEvents(window.document.body))),this._syncedTransform=IA.getComponent(this.gameObject,Ma)??void 0}onDisable(){var e;(e=this._camera)!=null&&e.cam&&iv(this._camera.cam,this,!1),this._controls&&(this._controls.enabled=!1,this._controls.autoRotate=!1,this._controls.removeEventListener("start",this.onControlsChangeStarted))}afterHandleInput(e){e.detail.args.pointerId===0&&(e.detail.args.isDown?this._controls&&this._eventSystem&&(this._shouldDisable=this._eventSystem.hasActiveUI):(!e.detail.args.isPressed||e.detail.args.isUp)&&(this._shouldDisable=!1))}onBeforeRender(){var t,g,I;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 e=this.middleClickToFocus&&this.context.input.getPointerClicked(1);if(e||(e=this.doubleClickToFocus&&this.context.input.getPointerDoubleClicked(0)&&this.context.time.time-this._enableTime>.3),e?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 s=(t=this._cameraObject)==null?void 0:t.position;Ux(s,this._cameraTargetPosition,o)}else(g=this._cameraObject)==null||g.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(!cp&&((I=this.lookAtConstraint)!=null&&I.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?sk:BiA,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 hp=="number"||hp===!0){this._controls.enableDamping=!0;const o=typeof hp=="number"?hp:.99;this._controls.dampingFactor=Math.max(.001,1-Math.min(1,o))}this.context.isInXR||this._controls.update()}}setCameraTarget(e,t=!1){return this.setCameraTargetPosition(e,t)}setCameraTargetPosition(e,t=!1){var g;e?(this._lerpCameraToTarget=!0,this._cameraTargetPosition=e.clone(),t&&this._cameraTargetPosition&&((g=this.controllerObject)==null||g.position.copy(this._cameraTargetPosition))):this._lerpCameraToTarget=!1}setFromTargetPosition(e=0,t=1){var I;if(!this._controls)return!1;const g=(I=this.lookAtConstraint)==null?void 0:I.sources;if(g&&g.length>0){const o=g[e];if(o)return o.getWorldPosition(this._lookTargetPosition),this.lerpTarget(this._lookTargetPosition,t),!0}return!1}setTarget(e=null,t=!1){this._controls&&(e!==null&&this._lookTargetPosition.copy(e),t?this._controls.target.copy(this._lookTargetPosition):this._lerpToTargetPosition=!0)}lerpTarget(e,t){this._controls&&this._controls.target.lerp(e,t)}distanceToTarget(e){return this._controls?this._controls.target.distanceTo(e):-1}setTargetFromRaycast(){var t,g;if(!this.controls)return;const e=this.context.physics.raycast();for(const I of e)if(I.distance>0&&IA.isActiveInHierarchy(I.object)){const o=dy(I.object);if(o){const s=o.canvas;if(s!=null&&s.screenspace)break}if(this._lookTargetPosition.copy(I.point),this._lerpToTargetPosition=!0,this._cameraTargetPosition=null,this.context.mainCamera){this._lerpCameraToTarget=!0;const s=ke(this.context.mainCamera);this._cameraTargetPosition=s.clone().sub(this.controls.target).add(this._lookTargetPosition),(g=(t=this._cameraObject)==null?void 0:t.parent)==null||g.worldToLocal(this._cameraTargetPosition)}break}}fitCamera(e,t=1.1,g=!0){const I=this._cameraObject,o=this._controls;if(e!=null&&e.length||(e=this.context.scene.children),e.length<=0||!I||!o)return;const s=new w,C=new w,n=new zi;n.makeEmpty();const a=[];function B(u){let f=!0;if(u.visible&&(u instanceof UG&&(f=!1),u instanceof XM&&(f=!1),u instanceof E2&&(f=!1),u.material instanceof pw&&(f=!1),u instanceof wA||(f=!1),u!==I&&u.isUI!==!0)){if(f){bc&&console.log(u.name,u.type,u);const S=u.children;u.children=a,n.expandByObject(u,!0),u.children=S}for(const S of u.children)B(S)}}for(const u of e)u.updateMatrixWorld(),B(u);if(I.updateMatrixWorld(),I.updateProjectionMatrix(),n.getCenter(C),n.applyMatrix4(I.matrixWorldInverse),n.getSize(s),n.setFromCenterAndSize(C,s),s.length()<=1e-10){bc&&console.warn("Camera fit size is zero",n,[...e]);return}const Q=I.fov,E=2*Math.atan(Math.tan(Q*Math.PI/360/2)*I.aspect)/Math.PI*360,c=s.y/(2*Math.atan(Math.PI*Q/360)),l=s.x/(2*Math.atan(Math.PI*E/360)),d=t*Math.max(c,l)+s.z/2;bc&&console.log("Fit camera to objects",c,l,"distance",d);const h=ke(I),p=o.target.clone().sub(h).normalize().multiplyScalar(d);if(o.maxDistance=d*10,o.minDistance=d*.01,this.setTarget(C,g),this.autoTarget=!1,I.near=d/100,I.far=d*100,I.updateMatrixWorld(),I.updateProjectionMatrix(),I.parent){const u=I.parent.worldToLocal(o.target.clone().sub(p));this.setCameraTarget(u,g)}else console.error(`Can not fit camera ${I.name} because it has no parent`);if(bc){const u=new UG(n);this.context.scene.add(u),Jx(u,Nw(I)),this._haveAttachedKeyboardEvents||(this._haveAttachedKeyboardEvents=!0,document.body.addEventListener("keydown",f=>{f.code==="KeyF"&&this.fitCamera(e)}))}o.update()}}dI([D()],ii.prototype,"enableRotate",2);dI([D()],ii.prototype,"autoRotate",2);dI([D()],ii.prototype,"autoRotateSpeed",2);dI([D()],ii.prototype,"autoFit",2);dI([D()],ii.prototype,"enableKeys",2);dI([D()],ii.prototype,"enableDamping",2);dI([D()],ii.prototype,"dampingFactor",2);dI([D()],ii.prototype,"enableZoom",2);dI([D()],ii.prototype,"minZoom",2);dI([D()],ii.prototype,"maxZoom",2);dI([D()],ii.prototype,"enablePan",2);dI([D(dd)],ii.prototype,"lookAtConstraint",2);dI([D()],ii.prototype,"lookAtConstraint01",2);dI([D()],ii.prototype,"middleClickToFocus",2);dI([D()],ii.prototype,"doubleClickToFocus",2);var QiA=Object.defineProperty,EiA=Object.getOwnPropertyDescriptor,Qo=(i,A,e,t)=>{for(var g=t>1?void 0:t?EiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&QiA(A,e,g),g},dD=(i=>(i[i.Skybox=1]="Skybox",i[i.SolidColor=2]="SolidColor",i[i.Uninitialized=4]="Uninitialized",i))(dD||{});const mr=sA("debugcam"),Iv=sA("debugscreenpointtoray");var bp;const Ch=(bp=class extends NA{constructor(){super(...arguments);r(this,"_nearClipPlane",.1);r(this,"_farClipPlane",1e3);r(this,"orthographic",!1);r(this,"orthographicSize",5);r(this,"ARBackgroundAlpha",0);r(this,"_cullingMask",4294967295);r(this,"_backgroundBlurriness");r(this,"_backgroundIntensity");r(this,"_environmentIntensity");r(this,"_targetTexture",null);r(this,"_backgroundColor");r(this,"_fov");r(this,"_cam",null);r(this,"_clearFlags",2);r(this,"_skybox")}get isCamera(){return!0}get aspect(){return this._cam instanceof Xe?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._cam instanceof Xe?this._cam.fov:this._fov}set fieldOfView(A){const e=this.fieldOfView!=A;if(this._fov=A,e&&this._cam&&this._cam instanceof Xe){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(A){const e=this._nearClipPlane!=A;this._nearClipPlane=A,this._cam&&e&&(this._cam.near=A,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(A){const e=this._farClipPlane!=A;this._farClipPlane=A,this._cam&&e&&(this._cam.far=A,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(A){A!==this._clearFlags&&(this._clearFlags=A,this.applyClearFlagsIfIsActiveCamera())}set cullingMask(A){this._cullingMask=A,this._cam&&(this._cam.layers.mask=A)}get cullingMask(){return this._cam?this._cam.layers.mask:this._cullingMask}set backgroundBlurriness(A){A!==this._backgroundBlurriness&&(A===void 0?this._backgroundBlurriness=void 0:this._backgroundBlurriness=Math.min(Math.max(A,0),1),this.applyClearFlagsIfIsActiveCamera())}get backgroundBlurriness(){return this._backgroundBlurriness}set backgroundIntensity(A){A!==this._backgroundIntensity&&(A===void 0?this._backgroundIntensity=void 0:this._backgroundIntensity=Math.min(Math.max(A,0),10),this.applyClearFlagsIfIsActiveCamera())}get backgroundIntensity(){return this._backgroundIntensity}set environmentIntensity(A){this._environmentIntensity=A}get environmentIntensity(){return this._environmentIntensity}get backgroundColor(){return this._backgroundColor??null}set backgroundColor(A){if(A){if(this._backgroundColor)this._backgroundColor.copy(A);else{if(!A.clone)return;this._backgroundColor=A.clone()}A.alpha===void 0&&(this._backgroundColor.alpha=1),this.applyClearFlagsIfIsActiveCamera()}}set targetTexture(A){this._targetTexture=A}get targetTexture(){return this._targetTexture}get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}screenPointToRay(A,e,t){const g=this.cam,I=Ch._origin;I.set(A,e,-1),this.context.input.convertScreenspaceToRaycastSpace(I),Iv&&console.log("screenPointToRay",A.toFixed(2),e.toFixed(2),"now:",I.x.toFixed(2),I.y.toFixed(2),"isInXR:"+this.context.isInXR),I.z=-1,I.unproject(g);const o=Ch._direction.set(I.x,I.y,I.z),s=ke(g);return o.sub(s),o.normalize(),t?(t.set(s,o),t):new nC(s.clone(),o.clone())}awake(){Iv&&window.addEventListener("pointerdown",A=>{const e=A.clientX,t=A.clientY;console.log("touch",e.toFixed(2),t.toFixed(2));const g=this.screenPointToRay(e,t),I="#"+Math.floor(Math.random()*16777215).toString(16);An.DrawRay(g.origin,g.direction,I,10)})}onEnable(){mr&&console.log(`Camera enabled: "${this.name}". ClearFlags=${dD[this._clearFlags]}`,this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&(this.context.setCurrentCamera(this),hiA(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 A=this.context.renderer;if(A){const e=this.context.mainCameraComponent;this.applyClearFlags(),this._targetTexture.render(this.context.scene,this._cam,A),e==null||e.applyClearFlags()}}}buildCamera(){if(this._cam)return;const A=this.gameObject.isCamera;let e=null;if(A?(e=this.gameObject,e==null||e.layers.enableAll(),e instanceof Xe&&(this._fov=e.fov)):e=this.gameObject.children[0],e&&e.isCamera)e instanceof Xe&&(this._fov&&(e.fov=this._fov),e.near=this._nearClipPlane,e.far=this._farClipPlane,e.updateProjectionMatrix());else if(!this.orthographic)e=new Xe(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),this.fieldOfView&&(e.fov=this.fieldOfView),this.gameObject.add(e);else{const t=this.orthographicSize*100;e=new gB(window.innerWidth/-t,window.innerWidth/t,window.innerHeight/t,window.innerHeight/-t,this._nearClipPlane,this._farClipPlane),this.gameObject.add(e)}this._cam=e,this._cam.layers.mask=this._cullingMask,this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){this.context.mainCameraComponent===this&&this.applyClearFlags()}applyClearFlags(){if(!this._cam){mr&&console.log("Camera does not exist (apply clear flags)");return}if(this.fieldOfView=this._fov,mr){const A=`Camera "${this.name}" clear flags: ${dD[this._clearFlags]}`;console.log(A)}switch(this._clearFlags){case 1:if(Ch.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 A=this._backgroundColor.alpha;Ch.backgroundShouldBeTransparent(this.context)&&(A=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,A)}else mr&&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 ciA(this)),this._skybox.enable()}static backgroundShouldBeTransparent(A){var I,o,s,C;const e=(I=A.renderer.xr)==null?void 0:I.getSession();if(!e)return!1;const t=e.environmentBlendMode;mr&&Di("Environment blend mode: "+t+" on "+navigator.userAgent);const g=t==="additive"||t==="alpha-blend";if(A.xrSessionMode===hl.ImmersiveAR&&t==="opaque"){if((o=navigator.userAgent)!=null&&o.includes("OculusBrowser"))return!0;if((s=navigator.userAgent)!=null&&s.includes("Mozilla")&&((C=navigator.userAgent)!=null&&C.includes("Mobile WebXRViewer/v2")))return!0}return g}},r(bp,"_origin",new w),r(bp,"_direction",new w),bp);let Ht=Ch;Qo([D()],Ht.prototype,"fieldOfView",1);Qo([D()],Ht.prototype,"nearClipPlane",1);Qo([D()],Ht.prototype,"farClipPlane",1);Qo([D()],Ht.prototype,"clearFlags",1);Qo([D()],Ht.prototype,"orthographic",2);Qo([D()],Ht.prototype,"orthographicSize",2);Qo([D()],Ht.prototype,"ARBackgroundAlpha",2);Qo([D()],Ht.prototype,"cullingMask",1);Qo([D()],Ht.prototype,"backgroundBlurriness",1);Qo([D()],Ht.prototype,"backgroundIntensity",1);Qo([D()],Ht.prototype,"environmentIntensity",1);Qo([D(St)],Ht.prototype,"backgroundColor",1);Qo([D(ua)],Ht.prototype,"targetTexture",1);class ciA{constructor(A){r(this,"_camera");r(this,"_skybox");this._camera=A}get context(){var A;return(A=this._camera)==null?void 0:A.context}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?this.context.scene.background!==this._skybox&&(mr&&console.log(`Camera "${this._camera.name}" set skybox`,this._camera,this._skybox),this._skybox.colorSpace=Ae,this._skybox.mapping=Yo,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),(mr||rt())&&Wg(`Camera "${this._camera.name}" has no skybox texture`))}}function hiA(i){sA("freecam")&&i.context.mainCameraComponent===i&&IA.getOrAddComponent(i.gameObject,ii)}class Or extends NA{constructor(){super(...arguments);r(this,"_listener",null)}get listener(){return this._listener==null&&(this._listener=new zM),this._listener}awake(){Gi.registerWaitForAllowAudio(()=>{if(this.destroyed)return;const e=this.listener;if(e==null||e.parent)return;const t=this.context.mainCameraComponent||IA.getComponentInParent(this.gameObject,Ht);t!=null&&t.cam?t.cam.add(e):this.gameObject.add(e)})}}var liA=Object.defineProperty,diA=Object.getOwnPropertyDescriptor,uy=(i,A,e,t)=>{for(var g=t>1?void 0:t?diA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&liA(A,e,g),g};const uiA=sA("debugsignals");class Sd{constructor(){r(this,"guid")}}uy([D()],Sd.prototype,"guid",2);class HE{constructor(){r(this,"signal");r(this,"reaction")}}uy([D(Sd)],HE.prototype,"signal",2);uy([D(Dg)],HE.prototype,"reaction",2);var Yk;const KC=(Yk=class extends NA{constructor(){super(...arguments);r(this,"events")}static invoke(A){if(KC.receivers[A]){const e=KC.receivers[A];if(!e)return;for(const t of e)t.invoke(A)}}awake(){uiA&&console.log("SignalReceiver awake",this)}onEnable(){if(this.events)for(const A of this.events)KC.receivers[A.signal.guid]||(KC.receivers[A.signal.guid]=[]),KC.receivers[A.signal.guid].push(this)}onDisable(){if(this.events){for(const A of this.events)if(KC.receivers[A.signal.guid]){const e=KC.receivers[A.signal.guid].indexOf(this);e>=0&&KC.receivers[A.signal.guid].splice(e,1)}}}invoke(A){if(!this.events||!Array.isArray(this.events))return;const e=typeof A=="object"?A.guid:A;for(const t of this.events)if(t.signal.guid===e)try{if(t.reaction){if(!t.reaction.invoke){console.warn("Missing invoke - possibly a serialization error",t,this);continue}}else{console.warn("Missing reaction for signal",t,this);continue}t.reaction.invoke()}catch(g){console.error(g)}}},r(Yk,"receivers",{}),Yk);let _E=KC;uy([D(HE)],_E.prototype,"events",2);var VI=(i=>(i.Activation="ActivationTrack",i.Animation="AnimationTrack",i.Audio="AudioTrack",i.Control="ControlTrack",i.Marker="MarkerTrack",i.Signal="SignalTrack",i))(VI||{}),bs=(i=>(i[i.None=0]="None",i[i.Hold=1]="Hold",i[i.Loop=2]="Loop",i[i.PingPong=3]="PingPong",i[i.Continue=4]="Continue",i))(bs||{}),yU=(i=>(i.Signal="SignalEmitter",i))(yU||{});const nQ=sA("debugtimeline"),LD=class extends NA{constructor(){super(...arguments);r(this,"playableAsset");r(this,"playOnAwake");r(this,"extrapolationMode",1);r(this,"waitForAudio",!0);r(this,"_visibilityChangeEvt");r(this,"_clonedPlayableAsset",!1);r(this,"_speed",1);r(this,"_guidsMap");r(this,"_isPlaying",!1);r(this,"_internalUpdateRoutine");r(this,"_isPaused",!1);r(this,"_isStopping",!1);r(this,"_time",0);r(this,"_duration",0);r(this,"_weight",1);r(this,"_animationTracks",[]);r(this,"_audioTracks",[]);r(this,"_signalTracks",[]);r(this,"_controlTracks",[]);r(this,"_customTracks",[]);r(this,"_allTracks",[this._animationTracks,this._audioTracks,this._signalTracks,this._controlTracks,this._customTracks]);r(this,"animationCallbackReceivers",[])}static registerCreateTrack(e,t){this.createTrackFunctions[e]=t}get isPlaying(){return this._isPlaying}get isPaused(){return this._isPaused}get time(){return this._time}set time(e){typeof e=="number"&&!Number.isNaN(e)?this._time=e:(nQ||QI())&&console.error("INVALID TIMELINE.TIME VALUE",e,this.name)}get duration(){return this._duration}set duration(e){this._duration=e}get weight(){return this._weight}set weight(e){this._weight=e}get speed(){return this._speed}set speed(e){this._speed=e}awake(){var e,t,g;nQ&&console.log(this,(e=this.playableAsset)==null?void 0:e.tracks),this.rebuildGraph(),this.isValid()||console.warn("PlayableDirector is not valid",this.playableAsset,(t=this.playableAsset)==null?void 0:t.tracks,Array.isArray((g=this.playableAsset)==null?void 0:g.tracks),this)}onEnable(){var e,t,g;for(const I of this._audioTracks)(e=I.onEnable)==null||e.call(I);for(const I of this._customTracks)(t=I.onEnable)==null||t.call(I);for(const I of this._animationTracks)(g=I.onEnable)==null||g.call(I);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 e,t,g;this.stop();for(const I of this._audioTracks)(e=I.onDisable)==null||e.call(I);for(const I of this._customTracks)(t=I.onDisable)==null||t.call(I);for(const I of this._animationTracks)(g=I.onDisable)==null||g.call(I);this._visibilityChangeEvt&&window.removeEventListener("visibilitychange",this._visibilityChangeEvt)}onDestroy(){var e;for(const t of this._allTracks)for(const g of t)(e=g.onDestroy)==null||e.call(g)}rebuildGraph(){this.isValid()&&(this.resolveBindings(),this.updateTimelineDuration(),this.setupAndCreateTrackHandlers())}async play(){if(!this.isValid())return;const e=this._isPaused==!0;if(this._isPaused=!1,e&&this.invokePauseChangedMethodsOnTracks(),!this._isPlaying){if(this._isPlaying=!0,this.waitForAudio){const t=[];for(const g of this._audioTracks){const I=g.loadAudio(this._time,1,0);I&&t.push(I)}if(t.length>0&&(await Promise.all(t),!this._isPlaying))return;for(;this._audioTracks.length>0&&this._isPlaying&&!Gi.userInteractionRegistered&&this.waitForAudio;)await id(200)}this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine=this.startCoroutine(this.internalUpdate(),xI.OnBeforeRender)}}pause(){this.isValid()&&(this._isPlaying=!1,!this._isPaused&&(this._isPaused=!0,this.evaluate(),this.invokePauseChangedMethodsOnTracks(),this.invokeStateChangedMethodsOnTracks()))}stop(){this._isStopping=!0;for(const g of this._audioTracks)g.stop();const e=this._isPaused==!0,t=this._isPlaying;this._isPlaying&&(this._time=0,this._isPlaying=!1,this._isPaused=!1,this.evaluate(),e&&this.invokePauseChangedMethodsOnTracks()),this._isPlaying=!1,this._isPaused=!1,e&&!t&&this.invokePauseChangedMethodsOnTracks(),t&&this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine&&this.stopCoroutine(this._internalUpdateRoutine),this._internalUpdateRoutine=null,this._isStopping=!1}evaluate(){if(!this.isValid())return;let e=this._time;switch(this.extrapolationMode){case 0:this._speed>0?e=Math.min(e,this._duration):this._speed<0&&(e=Math.max(e,0)),this._time=e;break;case 1:e%=this._duration,this._time=e;break;case 2:if(e>this._duration){this.stop();return}break}this.internalEvaluate(e)}isValid(){return this.playableAsset&&this.playableAsset.tracks&&Array.isArray(this.playableAsset.tracks)}*forEachTrack(){for(const e of this._allTracks)for(const t of e)yield t}get audioTracks(){return this._audioTracks}resolveGuids(e){this._guidsMap=e}invokePauseChangedMethodsOnTracks(){var e;for(const t of this.forEachTrack())(e=t.onPauseChanged)==null||e.call(t)}invokeStateChangedMethodsOnTracks(){var e;for(const t of this.forEachTrack())(e=t.onStateChanged)==null||e.call(t,this._isPlaying)}*internalUpdate(){for(;this._isPlaying&&this.activeAndEnabled;)!this._isPaused&&this._isPlaying&&(this._time+=this.context.time.deltaTime*this.speed,this.evaluate()),yield}internalEvaluate(e){for(const t of this.playableAsset.tracks)if(!t.muted)switch(t.type){case VI.Activation:if(!this._isPlaying)continue;for(let g=0;g<t.outputs.length;g++){const I=t.outputs[g];if(typeof I=="object"){let o=!1;if(t.clips)for(const C of t.clips)C.start<=e&&e<=C.end&&(o=!0);const s=I;s.visible!==void 0&&s.visible!==o&&(s.visible=o,nQ&&console.warn(this.name,"set ActivationTrack-"+g,s.name,o,e))}}break}if(!this._isStopping)for(const t of this._animationTracks)t.evaluate(e);for(const t of this._audioTracks)t.evaluate(e);for(const t of this._signalTracks)t.evaluate(e);for(const t of this._controlTracks)t.evaluate(e);for(const t of this._customTracks)t.evaluate(e)}resolveBindings(){if(this._clonedPlayableAsset||(this._clonedPlayableAsset=!0,this.playableAsset=Uw(this.playableAsset)),!this.playableAsset||!this.playableAsset.tracks)return;const e=this.findRoot(this.gameObject);for(const t of this.playableAsset.tracks){for(let g=t.outputs.length-1;g>=0;g--){let I=t.outputs[g];if(typeof I=="string"){this._guidsMap&&this._guidsMap[I]&&(I=this._guidsMap[I]);const o=IA.findByGuid(I,e);o===null||typeof o!="object"?(t.outputs.splice(g,1),console.warn("Failed to resolve binding",I,t.name,t.type)):(nQ&&console.log("Resolved binding",I,"to",o),t.outputs[g]=o)}else if(I===null){if(t.outputs.splice(g,1),LD.createTrackFunctions[t.type])continue;t.type!==VI.Audio&&t.type!==VI.Control&&t.type!==VI.Marker&&t.type!==VI.Signal&&console.warn("Missing binding",I,t.name,t.type,this.name,this.playableAsset.name)}}if(t.type===VI.Control&&t.clips)for(let g=0;g<t.clips.length;g++){const I=t.clips[g];let o=I.asset.sourceObject;if(typeof o=="string"){this._guidsMap&&this._guidsMap[o]&&(o=this._guidsMap[o]);const s=IA.findByGuid(o,e);s===null||typeof s!="object"?console.warn("Failed to resolve sourceObject binding",o,t.name,I):(nQ&&console.log("Resolved binding",o,"to",s),I.asset.sourceObject=s)}}}}findRoot(e){return e.parent?this.findRoot(e.parent):e}updateTimelineDuration(){if(this._duration=0,!(!this.playableAsset||!this.playableAsset.tracks)){for(const e of this.playableAsset.tracks)if(e.muted!==!0){if(e.clips)for(const t of e.clips)t.end>this._duration&&(this._duration=t.end);if(e.markers)for(const t of e.markers)t.time>this._duration&&(this._duration=t.time+.001)}}}setupAndCreateTrackHandlers(){var t,g;if(this._animationTracks.length=0,this._audioTracks.length=0,this._signalTracks.length=0,!this.playableAsset)return;const e=IA.findObjectOfType(Or,this.context);for(const I of this.playableAsset.tracks){const o=I.type,s=LD.createTrackFunctions[o];if(s!=null){const C=s(this,I);if(typeof C.evaluate=="function"){C.director=this,C.track=I,this._customTracks.push(C);continue}}if(I.type===VI.Animation){if(!I.clips||I.clips.length<=0){nQ&&console.warn("Animation track has no clips",I);continue}for(let C=I.outputs.length-1;C>=0;C--){let n=I.outputs[C];if(n instanceof FA){const B=IA.getOrAddComponent(n,Pg);B&&(n=B)}const a=(t=n==null?void 0:n.gameObject)==null?void 0:t.animations;if(a){const B=new py;B.trackOffset=I.trackOffset,B.director=this,B.track=I;for(let Q=0;Q<I.clips.length;Q++){const E=I.clips[Q],c=E.asset;if(!c){console.error("MISSING anim model?","clip#"+Q,E,I,this.playableAsset,this.name);continue}const l=c.clip;let d=l;if((typeof d=="string"||typeof d=="number")&&(d=a.find(p=>p.name===l)),!d){console.warn("Could not find animationClip for model",E,I.name,this.name,(g=this.playableAsset)==null?void 0:g.name);continue}n instanceof Pg&&n.runtimeAnimatorController&&(n.__internalDidAwakeAndStart||n.initializeRuntimeAnimatorController(),n.runtimeAnimatorController.mixer||n.runtimeAnimatorController.bind(n),B.mixer=n.runtimeAnimatorController.mixer),B.mixer||(B.mixer=new Mw(n.gameObject)),B.clips.push(d),B.mixer.uncacheAction(d),B.createHooks(E.asset,d);const h=B.mixer.clipAction(d);B.actions.push(h),B.models.push(E)}this._animationTracks.push(B)}}}else if(I.type===VI.Audio){if(!I.clips||I.clips.length<=0)continue;const C=new Pr;if(C.director=this,C.track=I,this._audioTracks.push(C),!e)continue;C.listener=e.listener;for(let n=0;n<I.clips.length;n++){const a=I.clips[n];C.addModel(a)}}else if(I.type===VI.Marker){const C=new ml;if(C.director=this,C.track=I,I.markers)for(const n of I.markers)switch(n.type){case yU.Signal:C.models.push(n),C.didTrigger.push(!1);break}if(C!==null&&C.models.length>0){const n=IA.getComponent(this.gameObject,_E);n&&(C.receivers.push(n),this._signalTracks.push(C))}}else if(I.type===VI.Signal){const C=new ml;if(C.director=this,C.track=I,I.markers)for(const n of I.markers)C.models.push(n),C.didTrigger.push(!1);for(const n of I.outputs)C.receivers.push(n);this._signalTracks.push(C)}else if(I.type===VI.Control){const C=new fy;if(C.director=this,C.track=I,I.clips)for(const n of I.clips)C.models.push(n);C.resolveSourceObjects(this.context),this._controlTracks.push(C)}}}setAudioTracksAllowPlaying(e){for(const t of this._audioTracks)t.onAllowAudioChanged(e)}registerAnimationCallback(e){this.animationCallbackReceivers.push(e)}unregisterAnimationCallback(e){const t=this.animationCallbackReceivers.indexOf(e);t!==-1&&this.animationCallbackReceivers.splice(t,1)}};let Qn=LD;r(Qn,"createTrackFunctions",{});const tn=sA("debugtimeline");class kd{constructor(){r(this,"director");r(this,"track")}get muted(){return this.track.muted}set muted(A){var e;A!==this.track.muted&&(this.track.muted=A,(e=this.onMuteChanged)==null||e.call(this))}*forEachClip(A=!1){var e;if((e=this.track)!=null&&e.clips)if(A)for(let t=this.track.clips.length-1;t>=0;t--)yield this.track.clips[t];else for(const t of this.track.clips)yield t}getClipTime(A,e){return e.clipIn+(A-e.start)*e.timeScale}getClipTimeNormalized(A,e){return(A-e.start)/e.duration}evaluateWeight(A,e,t,g=!0){if(e<0||e>=t.length)return 0;const I=t[e];if(g||A>=I.start&&A<=I.end){let o=1;const s=!1;if(I.easeInDuration>0){const C=Math.min((A-I.start)/I.easeInDuration,1);o*=C}if(I.easeOutDuration>0&&!s){const C=Math.min((I.end-A)/I.easeOutDuration,1);o*=C}return o}return 0}}class piA{constructor(A){r(this,"clip");r(this,"rootPositionOffset");r(this,"rootQuaternionOffset");r(this,"rootStartPosition");r(this,"rootEndPosition");r(this,"rootStartQuaternion");r(this,"rootEndQuaternion");const e=A.getClip();this.clip=e;const t=A.getRoot(),g=t.name+".position",I=t.name+".quaternion";tn&&console.log(e.name,e.tracks,g);for(const o of e.tracks)if(!(o.times.length<=0)){if(o.name.endsWith(g))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),tn&&console.log(this.rootPositionOffset);else if(o.name.endsWith(I)&&(this.rootStartQuaternion=new GA().fromArray(o.values,0),this.rootEndQuaternion=new GA().fromArray(o.values,o.values.length-4),this.rootQuaternionOffset=this.rootEndQuaternion.clone().multiply(this.rootStartQuaternion),tn)){const s=new yi().setFromQuaternion(this.rootQuaternionOffset);console.log("ROT",s)}}}get hasOffsets(){return this.rootPositionOffset!==void 0||this.rootQuaternionOffset!==void 0}}class py extends kd{constructor(){super(...arguments);r(this,"models",[]);r(this,"trackOffset");r(this,"target");r(this,"mixer");r(this,"clips",[]);r(this,"actions",[]);r(this,"_actionOffsets",[]);r(this,"_didBind",!1);r(this,"_animator",null);r(this,"_useclipOffsets",!0);r(this,"_totalOffsetPosition",new w);r(this,"_totalOffsetRotation",new GA);r(this,"_totalOffsetPosition2",new w);r(this,"_totalOffsetRotation2",new GA);r(this,"_summedPos",new w);r(this,"_tempPos",new w);r(this,"_summedRot",new GA);r(this,"_tempRot",new GA);r(this,"_clipRotQuat",new GA)}onStateChanged(){this._animator&&qq(this._animator.gameObject,this,this.director.isPlaying)}createHooks(e,t){var a,B;if(((a=t.tracks)==null?void 0:a.length)<=0){console.warn("No tracks in AnimationClip",t);return}const g=t.tracks[0].name.split("."),I=g[g.length-2],o=I+".position",s=I+".quaternion";let C=!1,n=!1;for(const Q of t.tracks)Q.name.endsWith(o)?(C=!0,this.createPositionInterpolant(t,e,Q)):Q.name.endsWith(s)&&(n=!0,this.createRotationInterpolant(t,e,Q));if(!C||!n){const Q=(B=this.mixer)==null?void 0:B.getRoot(),E=t.tracks[0],c=E.name.lastIndexOf("."),l=E.name.substring(0,c),d=l.substring(l.lastIndexOf(".")+1),h=Q.getObjectByName(d);if(h)if(C){if(!n){const p=t.tracks[0].name.substring(0,c)+".quaternion";tn&&console.warn("Create quaternion track",d,h);const u=h.quaternion,f=new gC(p,[0,t.duration],[u.x,u.y,u.z,u.w,u.x,u.y,u.z,u.w]);t.tracks.push(f),this.createRotationInterpolant(t,e,f)}}else{const p=l+".position";tn&&console.warn("Create position track",d,h);const u=h.position,f=new cn(p,[0,t.duration],[u.x,u.y,u.z,u.x,u.y,u.z]);t.tracks.push(f),this.createPositionInterpolant(t,e,f)}}}bind(){if(!this._didBind){this._didBind=!0,tn&&console.log(this.models),this.mixer?this.target=this.mixer.getRoot():console.warn("No mixer was assigned to animation track");for(const e of this.actions){const t=new piA(e);this._actionOffsets.push(t)}this.target&&(this._animator=IA.getComponent(this.target,Pg)??null,this._animator&&qq(this._animator.gameObject,this,!0));for(const e of this.models){const t=e.asset,g=t.position,I=t.rotation;g&&g.x!==void 0&&(g.isVector3||(t.position=new w(g.x,g.y,g.z)),I.isQuaternion||(t.rotation=new GA(I.x,I.y,I.z,I.w)))}this.ensureTrackOffsets()}}ensureTrackOffsets(){if(this.trackOffset){const e=this.trackOffset.position;e&&(e.isVector3||(this.trackOffset.position=new w(e.x,e.y,e.z)));const t=this.trackOffset.rotation;t&&(t.isQuaternion||(this.trackOffset.rotation=new GA(t.x,t.y,t.z,t.w)))}}evaluate(e){var C,n,a,B,Q,E,c;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 t=0,g=0,I=!1,o=!1,s=0;for(let l=0;l<this.clips.length;l++){const d=this.models[l],h=this.actions[l],p=d.asset;h.weight=0;const u=e>=d.start&&e<=d.end,f=d.preExtrapolationMode,S=d.postExtrapolationMode,G=l<this.clips.length-1?this.models[l+1]:null;let M=u,R=!1;if(!M&&!I&&d.end<e&&S!==bs.None?(!G||G.start>e)&&(M=!0,I=!0):l==0&&!M&&!o&&d.start>e&&f!==bs.None&&(!G||G.start<e)&&(M=!0,R=!0,o=!0),M){let k=1;k*=this.evaluateWeight(e,l,this.models,M),k*=this.director.weight;let m=u;if(R)switch(f){case bs.Hold:break;case bs.Loop:e+=d.start,m=!0;break;default:e+=d.start,m=!0;break}let K=this.getClipTime(e,d),Z=0;const H=p.duration;if(R&&f===bs.Hold&&(K=0),m){if(p.loop)for(Z+=Math.floor(K/(H+1e-6));K>H;)K-=H}else if(!u&&I)switch(S){case bs.Hold:K=this.getClipTime(d.end,d);break;case bs.Loop:K%=H;break;case bs.PingPong:const x=Math.floor(K/H)%2!==0;K%=H,x&&(K=H-K);break}d.reversed===!0?h.time=h.getClip().duration-K:h.time=K,h.timeScale=0;const _=Math.max(0,k);if(h.weight=_,s+=_,h.clampWhenFinished=!1,h.isRunning()||h.play(),this._useclipOffsets){const j=t==0?this._totalOffsetPosition:this._totalOffsetPosition2,x=t==0?this._totalOffsetRotation:this._totalOffsetRotation2;t<1&&(g=1-k),t+=1;const v=this._summedPos.set(0,0,0),Y=this._tempPos.set(0,0,0),eA=this._summedRot.identity(),AA=this._tempRot.identity(),W=p.rotation;W&&(this._clipRotQuat.identity(),this._clipRotQuat.slerp(W,k));const gA=this._actionOffsets[l];if(gA.hasOffsets)for(let fA=0;fA<Z;fA++)gA.rootPositionOffset?Y.copy(gA.rootPositionOffset):Y.set(0,0,0),Y.applyQuaternion(eA),this._clipRotQuat&&Y.applyQuaternion(this._clipRotQuat),gA.rootQuaternionOffset&&(AA.copy(gA.rootQuaternionOffset),eA.multiply(AA)),v.add(Y);this._clipRotQuat&&x.multiply(this._clipRotQuat),x.multiply(eA),p.position&&v.add(p.position),j.add(v)}}}if(this._useclipOffsets&&(this._totalOffsetPosition.lerp(this._totalOffsetPosition2,g),this._totalOffsetRotation.slerp(this._totalOffsetRotation2,g)),this.__mixerError===void 0&&(tn||rt())&&((n=(C=this._animator)==null?void 0:C.runtimeAnimatorController)!=null&&n.mixer)&&this.mixer!==((B=(a=this._animator)==null?void 0:a.runtimeAnimatorController)==null?void 0:B.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)),(Q=this._animator)!=null&&Q.runtimeAnimatorController){const l=Math.max(0,1-s);(c=(E=this._animator)==null?void 0:E.runtimeAnimatorController)==null||c.update(l)}else this.mixer.update(e)}createRotationInterpolant(e,t,g){var C;const I=g.createInterpolant.bind(g),o=new GA;this.ensureTrackOffsets();const s=(C=this.trackOffset)==null?void 0:C.rotation;g.createInterpolant=()=>{const n=I(),a=n.evaluate.bind(n);return n.evaluate=B=>{var E;const Q=a(B);if(o.set(Q[0],Q[1],Q[2],Q[3]),o.premultiply(this._totalOffsetRotation),s&&o.premultiply(s),this.director.animationCallbackReceivers)for(const c of this.director.animationCallbackReceivers)(E=c==null?void 0:c.onTimelineRotation)==null||E.call(c,this.director,this.target,B,o);return Q[0]=o.x,Q[1]=o.y,Q[2]=o.z,Q[3]=o.w,Q},n}}createPositionInterpolant(e,t,g){var a,B;const I=g.createInterpolant.bind(g),o=new w;this.ensureTrackOffsets();const s=(a=this.trackOffset)==null?void 0:a.rotation,C=(B=this.trackOffset)==null?void 0:B.position;let n;g.createInterpolant=()=>{const Q=I(),E=Q.evaluate.bind(Q);return Q.evaluate=c=>{var d,h,p;const l=E(c);if(o.set(l[0],l[1],l[2]),t.removeStartOffset&&(n===void 0?(n=null,n=(h=(d=this._actionOffsets.find(u=>u.clip===e))==null?void 0:d.rootStartPosition)==null?void 0:h.clone()):n!=null&&n.isVector3&&o.sub(n)),o.applyQuaternion(this._totalOffsetRotation),o.add(this._totalOffsetPosition),s&&o.applyQuaternion(s),C&&(o.x-=C.x,o.y+=C.y,o.z+=C.z),this.director.animationCallbackReceivers)for(const u of this.director.animationCallbackReceivers)(p=u==null?void 0:u.onTimelinePosition)==null||p.call(u,this.director,this.target,c,o);return l[0]=o.x,l[1]=o.y,l[2]=o.z,l},Q}}}const fiA=sA("mutetimeline"),vQ=class extends kd{constructor(){super(...arguments);r(this,"models",[]);r(this,"listener");r(this,"audio",[]);r(this,"audioContextTimeOffset",[]);r(this,"lastTime",0);r(this,"_audioLoader",null)}getAudioFilePath(e){const t=this.director.sourceId;return Sn(t,e)}onAllowAudioChanged(e){for(let t=0;t<this.models.length;t++){const g=this.models[t];this.audio[t].setVolume(e?g.asset.volume:0)}}addModel(e){const t=new mw(this.listener);this.audio.push(t),this.models.push(e)}onDisable(){for(const e of this.audio)e.isPlaying&&e.stop()}onDestroy(){for(const e of this.audio)e.source&&(e==null||e.disconnect());this.audio.length=0}onMuteChanged(){if(this.muted)for(let e=0;e<this.audio.length;e++){const t=this.audio[e];t!=null&&t.isPlaying&&t.stop()}}stop(){for(let e=0;e<this.audio.length;e++){const t=this.audio[e];t!=null&&t.isPlaying&&t.stop()}}evaluate(e){if(fiA||this.track.muted||this.director.speed<0)return;const t=this.director.context.application.muted,g=t?.1:0;for(let I=0;I<this.models.length;I++){const o=this.models[I],s=this.audio[I];if((!s||!s.buffer)&&this.isInTimeRange(o,e-1,e+1)&&this.handleAudioLoading(o,s),Gi.userInteractionRegistered!==!1&&!(s===null||!s.buffer))if(s.playbackRate=this.director.context.time.timeScale,s.loop=o.asset.loop,e>=o.start&&e<=o.end&&e<this.director.duration){if(this.director.isPlaying==!1){if(s.isPlaying&&s.stop(),this.lastTime===e)continue}else if(!s.isPlaying)s.offset=o.clipIn+(e-o.start)*o.timeScale,s.play(g);else{const n=o.clipIn+(e-o.start)*o.timeScale,a=s.context.currentTime-s._startedAt+s.offset;Math.abs(n-a)>.3&&(s.offset=n,s.stop(),s.play(g))}let C=o.asset.volume;if(t&&(C=0),o.easeInDuration>0){const n=Math.min((e-o.start)/o.easeInDuration,1);C*=n}if(o.easeOutDuration>0){const n=Math.min((o.end-e)/o.easeOutDuration,1);C*=n}s.setVolume(C*this.director.weight)}else s.isPlaying&&s.stop()}this.lastTime=e}loadAudio(e,t=0,g=0){let I=null;const o=e-g,s=e+t;for(const C of this.models)if(this.isInTimeRange(C,o,s)){const n=this.audio[this.models.indexOf(C)],a=this.handleAudioLoading(C,n);a!==null&&(I===null&&(I=[]),I.push(a))}return I!==null?Promise.all(I):null}isInTimeRange(e,t,g){return t<=e.start&&g>=e.end||t>=e.start&&t<=e.end||g>=e.start&&g<=e.end}static dispose(){vQ._audioBuffers.clear()}handleAudioLoading(e,t){this._audioLoader||(this._audioLoader=new Yf);const g=this.getAudioFilePath(e.asset.clip);if(vQ._audioBuffers.get(g)){const o=vQ._audioBuffers.get(g);return o.then(s=>{s&&t.setBuffer(s)}),o}tn&&console.warn("LOAD audio track",g,this.director.sourceId);const I=new Promise((o,s)=>{this._audioLoader.load(g,C=>{t.setBuffer(C),o(C)},void 0,C=>{console.error("Error loading audio",C),o(null)})});return vQ._audioBuffers.set(g,I),I}};let Pr=vQ;r(Pr,"_audioBuffers",new Map);class ml extends kd{constructor(){super(...arguments);r(this,"models",[]);r(this,"didTrigger",[]);r(this,"receivers",[])}evaluate(e){var g;if(this.track.muted)return;const t=this.director.context.time.deltaTime*1.5;for(let I=0;I<this.models.length;I++){const o=this.models[I],s=this.didTrigger[I],C=o.time-e;let n=!1;if(o.retroActive)n=C<=1e-6;else{const a=Math.abs(C);(a===0||a>=1e-5&&a<t)&&(n=!0)}if(n){if(!s)if(tn&&console.log("Trigger signal",e,o.time,o),this.didTrigger[I]=!0,((g=this.receivers)==null?void 0:g.length)<=0)_E.invoke(o.asset);else for(const a of this.receivers)a&&a.invoke(o.asset)}else o.emitOnce||(this.didTrigger[I]=!1)}}}class fy extends kd{constructor(){super(...arguments);r(this,"models",[]);r(this,"timelines",[]);r(this,"_previousActiveModel",null)}resolveSourceObjects(e){for(let t=this.models.length-1;t>=0;t--){const I=this.models[t].asset;if(!I.sourceObject||typeof I.sourceObject!="object"){console.log("no source object, removing model",t,I),this.models.splice(t,1);continue}else{const o=IA.getComponent(I.sourceObject,Qn);this.timelines.push(o),o&&I.updateDirector&&(o.playOnAwake=!1)}}}evaluate(e){var t;this._previousActiveModel=null;for(let g=0;g<this.models.length;g++){const I=this.models[g],o=I.asset;if(e>=I.start&&e<=I.end){this._previousActiveModel=I;const s=this.getClipTime(e,I);if(o.controlActivation){const C=o.sourceObject;C.visible=!0}if(o.updateDirector){const C=this.timelines[g];C&&(C.isPlaying&&C.pause(),C.time=s,C.evaluate())}}else{const s=(t=this._previousActiveModel)==null?void 0:t.asset;if(o.controlActivation){const C=o.sourceObject;(s==null?void 0:s.sourceObject)!==C&&(C.visible=!1)}}}}}var DiA=Object.defineProperty,wiA=Object.getOwnPropertyDescriptor,c2=(i,A,e,t)=>{for(var g=t>1?void 0:t?wiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&DiA(A,e,g),g};class Fe{constructor(A){r(this,"_active",!0);r(this,"_value");r(this,"_valueRaw");r(this,"_defaultValue");r(this,"valueProcessor");r(this,"onValueChanged");this._value=A,this._defaultValue=A,this._valueRaw=A}get overrideState(){return this._active}set overrideState(A){if(this._active===A)return;this._active=A;const e=A?this._valueRaw:this._defaultValue;this.processValue(e,!0)}get value(){return this._valueRaw}set value(A){this.processValue(A,!1)}set defaultValue(A){this._defaultValue=A}__init(){this.processValue(this._valueRaw,!0)}processValue(A,e){if(A==null||!e&&this.testIfValueChanged(A)===!1)return;const t=this._value;!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,A=this._defaultValue,this._valueRaw=A):(this._valueRaw=A,this._active&&this.valueProcessor&&(A=this.valueProcessor(A)),this._value=A),this.onValueChanged&&this.onValueChanged(A,t,this)}testIfValueChanged(A){return this._valueRaw!==A}}c2([D()],Fe.prototype,"overrideState",1);c2([D()],Fe.prototype,"value",1);var yiA=Object.defineProperty,SiA=Object.getOwnPropertyDescriptor,kiA=(i,A,e,t)=>{for(var g=t>1?void 0:t?SiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&yiA(A,e,g),g};const GiA=sA("debugpost");class zg extends Ta{constructor(e=void 0){super();r(this,"active",!0);r(this,"_result");r(this,"_didCreateVolumeParameters",!1);if(e){this.ensureVolumeParameters();for(const t of Object.keys(e)){const g=e[t],I=this[t];I instanceof Fe&&(I.value=g)}}}onEnable(){this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){this.active=!1}init(){}apply(){var e;return this.ensureVolumeParameters(),this._result||(this._result=(e=this.onCreateEffect)==null?void 0:e.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){GiA&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(e=>e.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const e=Object.keys(this);for(const t of e){const g=this[t];g instanceof Fe&&g.__init()}}onAfterDeserialize(e,t){if(typeof e=="object"){const g=this.$serializedTypes;if(g){for(const I of Object.keys(g))if(g[I]===Fe){const s=e[I];if(s!==void 0){const C=this[I];C.value=s}}}}}onEditorModification(e){const t=e.propertyName;if(this[t]instanceof Fe){const g=e.value;return this[t].value=g,!0}}ensureVolumeParameters(){if(this._didCreateVolumeParameters)return;this._didCreateVolumeParameters=!0;const e=this.$serializedTypes;if(e)for(const t of Object.keys(e))e[t]===Fe&&(this[t]||(this[t]=new Fe))}}kiA([D()],zg.prototype,"active",2);var miA=Object.defineProperty,MiA=Object.getOwnPropertyDescriptor,RiA=(i,A,e,t)=>{for(var g=t>1?void 0:t?MiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&miA(A,e,g),g};const UiA=sA("debugpost"),Fm={};function Zo(i,A){Fm[i]=A}function FiA(i){return i.__type in Fm?Fm[i.__type]:(UiA&&i.__type&&console.warn("Unknown postprocessing type",i.__type,i),zg)}class Gd{constructor(){r(this,"components",[])}init(){var A;(A=this.components)==null||A.forEach(e=>e.init())}}RiA([JE([i=>FiA(i),zg])],Gd.prototype,"components",2);var NiA=Object.defineProperty,KiA=Object.getOwnPropertyDescriptor,JiA=(i,A,e,t)=>{for(var g=t>1?void 0:t?KiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&NiA(A,e,g),g};class md extends zg{constructor(){super(...arguments);r(this,"preset")}get typeName(){return"Antialiasing"}onCreateEffect(){const e=new AX({preset:dQ.HIGH,edgeDetectionMode:fR.DEPTH});return this.preset.onValueChanged=t=>{e.applyPreset(t)},e}}JiA([D(Fe)],md.prototype,"preset",2);Zo("Antialiasing",md);class Dy{constructor(){r(this,"files",[])}get extensionName(){return"Audio"}onExportObject(A,e,t){const g=IA.getComponents(A,Gi);if(g.length)for(const I of g){if(!I.clip||!I.playOnAwake)continue;const o=I.clip.split("/").pop();this.files.includes(I.clip)||this.files.push(I.clip),e.addEventListener("serialize",(s,C)=>{s.appendLine(),s.beginBlock(`def SpatialAudio "${e.name}"`),s.appendLine(`uniform asset filePath = @audio/${o}@`),s.appendLine(`uniform token auralMode = "${I.spatialBlend>0?"spatial":"nonSpatial"}"`),s.appendLine(`uniform token playbackMode = "${I.loop?"loopFromStage":"onceFromStart"}"`),s.appendLine(`uniform float gain = ${I.volume}`),s.closeBlock()})}}async onAfterSerialize(A){for(const e of this.files){const t=e.split("/").pop(),o=await(await(await fetch(e)).blob()).arrayBuffer(),s=new Uint8Array(o);A.files["audio/"+t]=s}}}const uD="noVoip",RI=sA("debugvoip"),qiA=sA("voip");class viA{constructor(A){r(this,"id");this.id=A}}class biA{constructor(A,e,t,g){r(this,"peer");r(this,"voip");r(this,"userId");r(this,"peerId");r(this,"call",null);r(this,"callErrorListener",null);r(this,"stream",null);this.voip=A,this.peer=e,this.userId=t,this.peerId=g}close(){var A;RI&&console.log("close voip call"),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.open&&this.call.close(),(A=this.stream)==null||A.getTracks().forEach(function(e){e.stop()})}updateMute(A){var t;if(!this.stream)return;const e=(t=this.stream)==null?void 0:t.getAudioTracks();for(const g of e)g.enabled=!A}async startVoipCall(){if(!await Rn.HasMicrophonePermissions()){console.warn("no permission to use microphone, can not start call");return}RI&&console.log("start voip call");try{this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}catch(e){console.error(e);return}this.updateMute(this.voip.muteOutput),RI&&console.log(this.stream),this.call=this.peer.call(this.peerId,this.stream,{metadata:{userId:this.userId}}),this.call.on("error",e=>{console.error(e)}),this.call.on("stream",e=>{RI&&console.log("received stream from remote again",e)}),this.peer.on("close",this.onCallClose.bind(this)),this.callErrorListener=e=>{var t;e.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(),(t=this.stream)==null||t.getTracks().forEach(function(g){g.stop()}),this.stream=null):console.error(e)},this.peer.on("error",this.callErrorListener)}onCallClose(A){RI&&console.log("call closed",A)}}class LiA{constructor(A,e,t){r(this,"voip");r(this,"call");r(this,"audio",null);r(this,"stream",null);r(this,"obj");r(this,"analyzer",null);r(this,"waitingForStart",!1);r(this,"closed",!1);r(this,"audioElement",null);this.voip=A,this.obj=e,this.call=t}get currentStream(){return this.stream}get currentAudio(){return this.audio}get currentAnalyzer(){return this.analyzer}openAudioStream(A){const e=A.getAudioTracks();for(const t of e)if(t.kind==="audio"&&t.readyState==="live"){this.open(t);return}console.warn("failed finding valid audio stream to begin call")}open(A){console.assert(A.kind==="audio","invalid track kind, expected audio but received "+A.kind),!this.waitingForStart&&(this.waitingForStart=!0,Gi.userInteractionRegistered||RI&&console.log("Incoming call, waiting for user interaction before opening audio"),Gi.registerWaitForAllowAudio(async()=>{if(this.call.open&&!this.closed){RI&&console.log("Setup audio and begin listening"),this.stream=new MediaStream([A]);const e=new zM;this.audio=new mw(e),this.audio.setVolume(this.voip.muteInput?0:1),this.audio.setMediaStreamSource(this.stream);const t=document.createElement("audio");this.audioElement=t,t.style.display="none",document.body.appendChild(t),t.srcObject=this.stream,t.sinkId!==void 0&&navigator.mediaDevices.enumerateDevices().then(g=>{if(t){console.log(g);for(const I of g)if(I.label==="Speakerphone"){t.sinkId=I.deviceId;break}}}),RI&&console.log("call is setup, you should hear something now"),this.analyzer=new gx(this.audio,32)}}))}close(){var A,e,t;this.closed=!0,(A=this.call)!=null&&A.open&&this.call.close(),(e=this.audio)==null||e.disconnect(),(t=this.stream)==null||t.getTracks().forEach(g=>{g.stop()}),this.stream=null,this.audioElement&&this.audioElement.remove()}}class Rn extends NA{constructor(){super(...arguments);r(this,"requireParam",!1);r(this,"peer",null);r(this,"model",null);r(this,"connections",{});r(this,"currentIncomingCalls",{});r(this,"_inputMuted",!1);r(this,"_outputMuted",!1)}set muteInput(e){var g;if(e===this._inputMuted||(this._inputMuted=e,!this.currentIncomingCalls))return;const t=this._inputMuted?0:1;for(const I in this.currentIncomingCalls){const o=this.currentIncomingCalls[I];(g=o==null?void 0:o.currentAudio)==null||g.setVolume(t)}}get muteInput(){return this._inputMuted}set muteOutput(e){if(e!==this._outputMuted&&(this._outputMuted=e,!!this.connections))for(const t in this.connections){const g=this.connections[t];g==null||g.updateMute(e)}}get muteOutput(){return this._outputMuted}getFrequency(e){if(e===null){for(const g in this.currentIncomingCalls){const I=this.currentIncomingCalls[g];if(I&&I.currentAnalyzer)return I.currentAnalyzer.getAverageFrequency()}return null}const t=this.currentIncomingCalls[e];return t&&t.currentAnalyzer?t.currentAnalyzer.getAverageFrequency():null}awake(){if(sA(uD)){console.log("VOIP is disabled by url parameter: "+uD);return}if(this.requireParam&&!qiA){console.debug("VOIP must be enabled explicitly by url parameter");return}if(nl()&&_C()){console.log("VOIP is currently not supported on Safari iOS");return}this.peer=aR(),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,this.context.connection.beginListen(Bi.JoinedRoom,e=>{navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).catch(t=>{console.error("Error initializing VoIP connection.",t)})}),this.context.connection.beginListen("peer-update-id",e=>{if(e.id!==this.context.connection.connectionId){const t=this.connections[e.id];if(t&&t.close(),this.peer&&this.context.connection.connectionId){const g=new biA(this,this.peer,this.context.connection.connectionId,e.peerId);this.connections[e.id]=g,g.startVoipCall()}}}),this.context.connection.beginListen(Bi.UserLeftRoom,e=>{const{userId:t}=e,g=this.connections[t];this.connections[t]=null,g&&g.close();const I=this.currentIncomingCalls[t];RI&&console.log("UserLeftRoom",e,t,I),I&&(I.close(),this.currentIncomingCalls[t]=null)}),this.peer.on("open",this.onOpenPeerConnection.bind(this))}onEnable(){}onDisable(){console.log("TODO: close all");for(const e in this.currentIncomingCalls)try{const t=this.currentIncomingCalls[e];t==null||t.close();const g=this.connections[e];g==null||g.close()}catch(t){console.error(t)}}async onOpenPeerConnection(e){RI&&console.log("Peer connection established and received id"),this.model=new viA(e),this.context.connection.send("peer-update-id",this.model,MI.OnRoomJoin),this.peer&&(this.peer.on("call",this.onReceiveCall.bind(this)),this.peer.on("connection",function(t){RI&&console.log("CONNECTION",t),t.on("data",function(g){RI&&console.log("Received",g)})}))}async onReceiveCall(e){if(!e)return;const{metadata:t}=e;console.assert(t.userId);const{userId:g}=t,I=this.currentIncomingCalls[g];if(I&&I.close(),RI&&console.log("received call"),await Rn.HasMicrophonePermissions())try{const o=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1});e.answer(o)}catch(o){console.error("Error initializing VoIP connection.",o)}else e.answer(null);this.currentIncomingCalls[g]=new LiA(this,this.gameObject,e),e.on("stream",o=>{var s;RI&&console.log("receive caller stream, will setup audio now"),(s=this.currentIncomingCalls[g])==null||s.openAudioStream(o)}),e.on("error",console.error)}static async HasMicrophonePermissions(){try{return(await navigator.permissions.query({name:"microphone"})).state!=="denied"}catch(e){return console.error("Error querying `microphone` permissions.",e),!1}}}var xiA=Object.defineProperty,TiA=Object.getOwnPropertyDescriptor,h2=(i,A,e,t)=>{for(var g=t>1?void 0:t?TiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&xiA(A,e,g),g};const YiA=sA("debugmouth");class Md extends NA{constructor(){super(...arguments);r(this,"idle",[]);r(this,"talking",[]);r(this,"marker",null);r(this,"voip",null);r(this,"lastMouthChangeTime",0);r(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=IA.findObjectOfType(Rn,this.context),this.marker||(this.marker=IA.getComponentInParent(this.gameObject,Cg))},3e3)}update(){var g;if(!this.voip||this.context.time.frameCount%10!==0)return;let e=((g=this.marker)==null?void 0:g.connectionId)??null;if(!e){YiA&&(e=null);return}const t=this.voip.getFrequency(e)??0;this.updateLips(t)}updateLips(e){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&e>30){this.lastMouthChangeTime=this.context.time.time;const t=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,t)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const t=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,t)}}}setMouthShapeActive(e,t){if(e){e!=this.idle?this.idle.map(g=>g.visible=!1):this.talking.map(g=>g.visible=!1);for(let g=0;g<e.length;g++){const I=e[g];I&&(I.visible=g===t)}}}}h2([D(FA)],Md.prototype,"idle",2);h2([D(FA)],Md.prototype,"talking",2);class SU extends NA{constructor(){super(...arguments);r(this,"voip",null);r(this,"marker",null);r(this,"_startPosition",null)}awake(){this.voip=IA.findObjectOfType(Rn,this.context),this.marker=IA.getComponentInParent(this.gameObject,Cg)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const e=this.marker.connectionId,t=this.voip.getFrequency(e);if(t==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const g=t/100;this.gameObject.position.y=this._startPosition.y+g*.07}}var HiA=Object.defineProperty,_iA=Object.getOwnPropertyDescriptor,wy=(i,A,e,t)=>{for(var g=t>1?void 0:t?_iA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&HiA(A,e,g),g};class QB extends NA{constructor(){super(...arguments);r(this,"eyes",[]);r(this,"lastBlinkTime",0);r(this,"blinkLength",0);r(this,"eyesOpen",!0);r(this,"state",null)}awake(){this.state=IA.getComponentInParent(this.gameObject,go)}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 t of this.eyes)t&&(t.visible=this.eyesOpen)}}}wy([D(FA)],QB.prototype,"eyes",2);wy([D()],QB.prototype,"lastBlinkTime",2);wy([D()],QB.prototype,"blinkLength",2);wy([D()],QB.prototype,"eyesOpen",2);var OiA=Object.defineProperty,PiA=Object.getOwnPropertyDescriptor,kU=(i,A,e,t)=>{for(var g=t>1?void 0:t?PiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&OiA(A,e,g),g},Hk;const l2=(Hk=class extends NA{constructor(){super(...arguments);r(this,"head",null);r(this,"eyes",null);r(this,"target",null);r(this,"brain",null);r(this,"vec",new w);r(this,"currentTargetPoint",new w)}awake(){this.brain||(this.brain=IA.getComponentInParent(this.gameObject,ul)),this.brain||(console.log("No look at brain found, adding it now"),this.brain=IA.addNewComponent(this.gameObject,ul)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const A=this.target;if(A&&this.head){const e=this.eyes;if(e){const t=ke(A);this.currentTargetPoint.lerp(t,this.context.time.deltaTime/.1);const g=ke(this.head),I=this.vec.copy(this.currentTargetPoint).sub(g).normalize();if(I.length()<.1)return;const o=l2.forward;if(o.set(0,0,1),o.applyQuaternion(Zi(this.head)),o.dot(I)>.45)for(let C=0;C<e.length;C++)e[C].lookAt(this.currentTargetPoint)}}}},r(Hk,"forward",new w(0,0,1)),Hk);let OE=l2;kU([D(FA)],OE.prototype,"head",2);kU([D(FA)],OE.prototype,"eyes",2);kU([D(FA)],OE.prototype,"target",2);var WiA=Object.defineProperty,ViA=Object.getOwnPropertyDescriptor,GU=(i,A,e,t)=>{for(var g=t>1?void 0:t?ViA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&WiA(A,e,g),g};class PE extends NA{constructor(){super(...arguments);r(this,"length",1);r(this,"depthTest",!0);r(this,"isGizmo",!0);r(this,"_axes",null)}onEnable(){if(this.isGizmo&&!rd)return;this._axes||(this._axes=new GE(this.length)),this.gameObject.add(this._axes);const e=this._axes.material;e&&e.depthTest!==void 0&&(e.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}GU([D()],PE.prototype,"length",2);GU([D()],PE.prototype,"depthTest",2);GU([D()],PE.prototype,"isGizmo",2);class mU extends NA{constructor(){super(...arguments);r(this,"from");r(this,"to");r(this,"hint");r(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const e=ke(this.to).clone(),t=ke(this.from).clone(),g=e.distanceTo(t),I=e.clone();I.sub(t);const o=t.clone();o.add(e),o.multiplyScalar(.5);const s=ke(this.hint).clone();s.sub(o);const C=new w;C.crossVectors(s,I),C.crossVectors(I,C),C.normalize();const n=g*.5,a=Math.max(this.desiredDistance,n),B=Math.sqrt(a*a-n*n),Q=C.clone();Q.multiplyScalar(B),Q.add(o),bi(this.gameObject,Q);const E=o.clone();E.sub(C),this.gameObject.lookAt(E)}}const ov=sA("debugusdz");class yy{constructor(){r(this,"behaviours",[]);r(this,"behaviourComponents",[]);r(this,"behaviourComponentsCopy",[])}get extensionName(){return"Behaviour"}addBehavior(A){this.behaviours.push(A)}onBeforeBuildDocument(A){const e=[];return A.root.traverse(t=>{IA.foreachComponent(t,g=>{var o;const I=g;if(typeof I.createBehaviours=="function"||typeof I.beforeCreateDocument=="function"||typeof I.afterCreateDocument=="function"||typeof I.afterSerialize=="function"){this.behaviourComponents.push(I);const s=(o=I.beforeCreateDocument)==null?void 0:o.call(I,this,A);s instanceof Promise&&e.push(s)}},!1)}),Promise.all(e)}onExportObject(A,e,t){var g;for(const I of this.behaviourComponents)(g=I.createBehaviours)==null||g.call(I,this,e,t)}onAfterBuildDocument(A){for(const e of this.behaviourComponents)typeof e.afterCreateDocument=="function"&&e.afterCreateDocument(this,A);this.behaviourComponentsCopy=this.behaviourComponents.slice(),this.behaviourComponents.length=0}onAfterHierarchy(A,e){var t;if((t=this.behaviours)!=null&&t.length){e.beginBlock('def Scope "Behaviors"');for(const g of this.behaviours)g.writeTo(this,A.document,e);e.closeBlock()}}async onAfterSerialize(A){ov&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const e of this.behaviourComponentsCopy)typeof e.afterSerialize=="function"&&(ov&&console.log("behaviour has afterSerialize",e),e.afterSerialize.constructor.name==="AsyncFunction"?await e.afterSerialize(this,A):e.afterSerialize(this,A))}}var ziA=Object.defineProperty,jiA=Object.getOwnPropertyDescriptor,MU=(i,A,e,t)=>{for(var g=t>1?void 0:t?jiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&ziA(A,e,g),g};class EB extends zg{constructor(){super(...arguments);r(this,"threshold");r(this,"intensity");r(this,"scatter");r(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=e=>e,this.intensity.valueProcessor=e=>e,this.scatter.valueProcessor=e=>1*Math.PI*(1-e)):(this.threshold.valueProcessor=e=>e,this.intensity.valueProcessor=e=>e,this.scatter.valueProcessor=e=>100*(1-e))}onCreateEffect(){let e;if(this.selectiveBloom){const t=e=new JY(this.context.scene,this.context.mainCamera,{blendFunction:Ye.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,intensity:this.intensity.value});t.inverted=!0}else e=new SR;return this.intensity.onValueChanged=t=>{e.intensity=t},this.threshold.onValueChanged=t=>{e.luminanceMaterial.threshold=t},this.scatter.onValueChanged=t=>{e.luminancePass.enabled=!0,e.luminanceMaterial.smoothing=t},e}}MU([D(Fe)],EB.prototype,"threshold",2);MU([D(Fe)],EB.prototype,"intensity",2);MU([D(Fe)],EB.prototype,"scatter",2);Zo("Bloom",EB);var ZiA=Object.defineProperty,XiA=Object.getOwnPropertyDescriptor,Gs=(i,A,e,t)=>{for(var g=t>1?void 0:t?XiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&ZiA(A,e,g),g};class BC extends NA{constructor(){super(...arguments);r(this,"attachedRigidbody",null);r(this,"isTrigger",!1);r(this,"sharedMaterial");r(this,"updateProperties",()=>{var e;(e=this.context.physics.engine)==null||e.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(qt))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(qt))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(qt))}onDisable(){var e;(e=this.context.physics.engine)==null||e.removeBody(this)}get body(){var e;return(e=this.context.physics.engine)==null?void 0:e.getBody(this)}}Gs([D(qt)],BC.prototype,"attachedRigidbody",2);Gs([D()],BC.prototype,"isTrigger",2);Gs([D()],BC.prototype,"sharedMaterial",2);class Rd extends BC{constructor(){super(...arguments);r(this,"radius",.5);r(this,"center",new w(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addSphereCollider(this,this.center),eR(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),lx(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}Gs([Rg(),D()],Rd.prototype,"radius",2);Gs([D(w)],Rd.prototype,"center",2);class Ud extends BC{constructor(){super(...arguments);r(this,"size",new w(1,1,1));r(this,"center",new w(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addBoxCollider(this,this.center,this.size)}onValidate(){this.updateProperties()}}Gs([Rg(),D(w)],Ud.prototype,"size",2);Gs([D(w)],Ud.prototype,"center",2);class Fd extends BC{constructor(){super(...arguments);r(this,"sharedMesh");r(this,"convex",!1)}onEnable(){var e,t,g,I,o;if(super.onEnable(),(e=this.sharedMesh)!=null&&e.isMesh||this.gameObject instanceof wA&&(this.sharedMesh=this.gameObject),(t=this.sharedMesh)!=null&&t.isMesh)(g=this.context.physics.engine)==null||g.addMeshCollider(this,this.sharedMesh,this.convex,pg(this.gameObject));else{const s=this.sharedMesh;if(s!=null&&s.isGroup){console.warn(`MeshCollider mesh is a group "${(I=this.sharedMesh)==null?void 0:I.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 s.children){const n=s.children[C];n.isMesh&&((o=this.context.physics.engine)==null||o.addMeshCollider(this,n,this.convex,pg(this.gameObject)))}}}}}Gs([D()],Fd.prototype,"convex",2);class Ua extends BC{constructor(){super(...arguments);r(this,"center",new w(0,0,0));r(this,"radius",.5);r(this,"height",2)}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addCapsuleCollider(this,this.center,this.height,this.radius)}}Gs([D(w)],Ua.prototype,"center",2);Gs([D()],Ua.prototype,"radius",2);Gs([D()],Ua.prototype,"height",2);var $iA=Object.defineProperty,AgA=Object.getOwnPropertyDescriptor,RU=(i,A,e,t)=>{for(var g=t>1?void 0:t?AgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&$iA(A,e,g),g};class cB extends NA{constructor(){super(...arguments);r(this,"objectBounds",!1);r(this,"color");r(this,"isGizmo",!0);r(this,"_gizmoObject",null);r(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!rd||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new Rw(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=GH(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),xI.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){var e;for(;this._boxHelper;)(e=this._boxHelper)==null||e.update(),yield}}RU([D()],cB.prototype,"objectBounds",2);RU([D(SA)],cB.prototype,"color",2);RU([D()],cB.prototype,"isGizmo",2);var egA=Object.defineProperty,tgA=Object.getOwnPropertyDescriptor,Nd=(i,A,e,t)=>{for(var g=t>1?void 0:t?tgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&egA(A,e,g),g};const Ck=sA("debugui"),nk=sA("debuguilayout");class UU{constructor(){r(this,"width");r(this,"height")}}class FU{constructor(){r(this,"x");r(this,"y");r(this,"width");r(this,"height")}}const os=new w,Lc=new UA,lp=new GA,d2=class extends ps{constructor(){super(...arguments);r(this,"_anchoredPosition");r(this,"sizeDelta",new tA(100,100));r(this,"pivot",new tA(.5,.5));r(this,"anchorMin",new tA(0,0));r(this,"anchorMax",new tA(1,1));r(this,"lastMatrix");r(this,"rectBlock");r(this,"_transformNeedsUpdate",!1);r(this,"_initialPosition");r(this,"_parentRectTransform");r(this,"_lastUpdateFrame",-1);r(this,"_lastAnchoring");r(this,"_createdBlocks",[]);r(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 tA),this._anchoredPosition}set anchoredPosition(A){this._anchoredPosition=A}get width(){if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const A=this._parentRectTransform.width,e=this.anchorMax.x-this.anchorMin.x;let t=A*e;return t+=this.sizeDelta.x,t}return this.sizeDelta.x}get height(){if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const A=this._parentRectTransform.height,e=this.anchorMax.y-this.anchorMin.y;let t=A*e;return t+=this.sizeDelta.y,t}return this.sizeDelta.y}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new tA),this.lastMatrix=new UA,this.rectBlock=new FA,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,DQ(this,"_anchoredPosition",()=>{this.markDirty()}),DQ(this,"sizeDelta",()=>{this.markDirty()}),DQ(this,"pivot",()=>{this.markDirty()}),DQ(this,"anchorMin",()=>{this.markDirty()}),DQ(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var A;super.onEnable(),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(A=this.Canvas)==null||A.registerTransform(this)}onDisable(){var A;super.onDisable(),this.removeShadowComponent(),(A=this.Canvas)==null||A.unregisterTransform(this)}onParentRectTransformChanged(A){this._transformNeedsUpdate||this.onApplyTransform(nk?`${A.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(nk&&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(A){var g;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const e=this.shadowComponent;if(!e)return;this.gameObject.parent?this._parentRectTransform=IA.getComponentInParent(this.gameObject.parent,d2):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,nk&&console.warn("RectTransform → ApplyTransform",this.name+" because "+A),this.isRoot()?this.Root.screenspace||(e.rotation.y=Math.PI):(e.matrix.identity(),e.matrixAutoUpdate=!1,os.set(0,0,0),this.applyPivot(os),e.matrix.setPosition(os.x,os.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(lp.copy(this.gameObject.quaternion),lp.x*=-1,lp.z*=-1,Lc.makeRotationFromQuaternion(lp),e.matrix.premultiply(Lc)),os.set(0,0,0),this.applyAnchoring(os),(g=this.Canvas)!=null&&g.screenspace?os.z+=.1:os.z+=.01,Lc.identity(),Lc.setPosition(os.x,os.y,os.z),e.matrix.premultiply(Lc),e.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const t=!0;for(const I of uR(this.gameObject,ps,t,1)){if(I===this||!I.activeAndEnabled)continue;const o=I;o.onParentRectTransformChanged&&o.onParentRectTransformChanged(this)}}applyAnchoring(A){this._lastAnchoring||(this._lastAnchoring=new tA);const e=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=e.x,this.gameObject.position.y+=e.y,this._lastAnchoring.copy(this._anchoredPosition),A.x+=this._initialPosition.x-this.gameObject.position.x,A.y+=this._initialPosition.y-this.gameObject.position.y,A.z+=this._initialPosition.z-this.gameObject.position.z;const t=this._parentRectTransform;if(t){let g=0;const I=1-this.anchorMax.y-this.anchorMin.y;g-=t.height*.5*I,A.y+=g;let o=0;const s=1-this.anchorMax.x-this.anchorMin.x;o-=t.width*.5*s,A.x+=o}}applyPivot(A){if(this.pivot&&!this.isRoot()){const e=this.pivot.x-.5;A.x-=e*this.sizeDelta.x*this.gameObject.scale.x;const t=this.pivot.y-.5;A.y-=t*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const A={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(A),A}ensureValidSize(A,e=1e-4){return A.width<=0&&(A.width=e),A.height<=0&&(A.height=1e-4),A}createNewBlock(A){A={...this.getBasicOptions(),...A},Ck&&console.log(this.name,A);const e=new DU(A);return this._createdBlocks.push(e),e}createNewText(A){Ck&&console.log(A),A={...this.getBasicOptions(),...A},Ck&&console.log(this.name,A);const e=new B2(A);return this._createdTextBlocks.push(e),e}};let cI=d2;Nd([D(tA)],cI.prototype,"anchoredPosition",1);Nd([D(tA)],cI.prototype,"sizeDelta",2);Nd([D(tA)],cI.prototype,"pivot",2);Nd([D(tA)],cI.prototype,"anchorMin",2);Nd([D(tA)],cI.prototype,"anchorMax",2);class igA extends r2{constructor(A,e={}){super(A),A._simpleState__activeStates=[],A._simpleState__normalStyles={},A._simpleState__states=e,A._simpleState__statesProperties={};for(const t in e)for(const g in e[t])A._simpleState__statesProperties[g]||(A._simpleState__statesProperties[g]=[]),A._simpleState__statesProperties[g].push(t);for(const t of A._components)A._simpleState__statesProperties[t.id]&&(A._simpleState__normalStyles[t.id]=t.inline?t.inline:t._value);A.__overridedSet=A.set,A.set=this.storeSet.bind(A),A.renderStates=this.renderStates.bind(A),A.setupState=this.setupState.bind(A),A.setState=this.setState.bind(A),A.activatePseudoState=this.activatePseudoState.bind(A),A.deactivatePseudoState=this.deactivatePseudoState.bind(A),A.togglePseudoState=this.togglePseudoState.bind(A)}act(){}attach(){}detach(){}setupState(A,e){this._simpleState__states[A]=e;const t=[];for(const g in e)this._simpleState__statesProperties[g]||(this._simpleState__statesProperties[g]=[],t.push(g)),this._simpleState__statesProperties[g].push(A);for(const g of this._components)t.indexOf(g.id)>-1&&(this._simpleState__normalStyles[g.id]=g.inline?g.inline:g._value)}renderStates(){let A={...this._simpleState__normalStyles};for(const e in this._simpleState__states)this._simpleState__activeStates.indexOf(e)>-1&&(A={...A,...this._simpleState__states[e]});this.set(A,!1)}storeSet(A,e=!0){if(e)for(const t in A)this._simpleState__statesProperties[t]&&(this._simpleState__normalStyles[t]=A[t]);this.__overridedSet(A)}activatePseudoState(A){this._simpleState__activeStates.indexOf(A)===-1&&(this._simpleState__activeStates.push(A),this.renderStates())}deactivatePseudoState(A){const e=this._simpleState__activeStates.indexOf(A);e>-1&&(this._simpleState__activeStates.splice(e,1),this.renderStates())}togglePseudoState(A){const e=this._simpleState__activeStates.indexOf(A);e>-1?this._simpleState__activeStates.splice(e,1):this._simpleState__activeStates.push(A),this.renderStates()}setState(A){Array.isArray(A)?this._simpleState__activeStates=A:this._simpleState__activeStates=[A],this.renderStates()}}var ggA=Object.defineProperty,IgA=Object.getOwnPropertyDescriptor,u2=(i,A,e,t)=>{for(var g=t>1?void 0:t?IgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&ggA(A,e,g),g};class WE extends NA{constructor(){super(...arguments);r(this,"effectColor");r(this,"effectDistance")}}u2([D(St)],WE.prototype,"effectColor",2);u2([D(tA)],WE.prototype,"effectDistance",2);var ogA=Object.defineProperty,sgA=Object.getOwnPropertyDescriptor,p2=(i,A,e,t)=>{for(var g=t>1?void 0:t?sgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&ogA(A,e,g),g};const dp={backgroundColor:new SA(1,1,1),backgroundOpacity:1,borderColor:new SA(1,1,1),borderOpacity:1};var _k;const lf=(_k=class extends ps{constructor(){super(...arguments);r(this,"_alphaFactor",1);r(this,"raycastTarget",!0);r(this,"uiObject",null);r(this,"_color",null);r(this,"_rect",null);r(this,"_stateManager",null);r(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new St(1,1,1,1)),this._color}set color(A){(!this._color||this._color.r!==A.r||this._color.g!==A.g||this._color.b!==A.b||this._color.alpha!==A.alpha)&&(this._color||(this._color=new St(1,1,1,1)),this._color.copy(A))}setAlphaFactor(A){this._alphaFactor=A,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(dp.backgroundColor=this._color,dp.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(dp,this._alphaFactor),this.uiObject.set(dp),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=IA.getComponent(this.gameObject,cI)),!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 A;(A=this.uiObject)==null||A.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(A){this.makePanel(),this.uiObject&&(this.uiObject.setState(A),this==null||this.markDirty())}setupState(A){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new igA(this.uiObject)),this.uiObject.setupState(A.state,A.attributes))}setOptions(A){this.makePanel(),this.uiObject&&this.uiObject.set(A)}awake(){super.awake(),this.makePanel(),DQ(this,"_color",()=>niA(this,this.onColorChanged))}onEnable(){var A;super.onEnable(),this.uiObject&&((A=this.rectTransform.shadowComponent)==null||A.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 A=.015,e={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:A};this.onBeforeCreate(e),this.applyEffects(e),this.onCreate(e),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated()}onBeforeCreate(A){}onCreate(A){this.uiObject=this.rectTransform.createNewBlock(A),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(A,e=1){var g;const t=(g=this.gameObject)==null?void 0:g.getComponent(WE);t&&(t.effectDistance&&(A.borderWidth=Math.max(Math.abs(t.effectDistance.x),Math.abs(t.effectDistance.y))),t.effectColor&&(A.borderColor=t.effectColor,A.borderOpacity=t.effectColor.alpha*e))}async setTexture(A){if(this.setOptions({backgroundOpacity:0}),A){if(A.colorSpace===Ae){if(lf.textureCache.has(A))A=lf.textureCache.get(A);else if(!A.isRenderTargetTexture){const e=A.clone();e.colorSpace=Si,lf.textureCache.set(A,e),A=e}}this.setOptions({backgroundImage:A,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)}},r(_k,"textureCache",new Map),_k);let hB=lf;p2([D(St)],hB.prototype,"color",1);p2([D()],hB.prototype,"raycastTarget",2);class Kd extends hB{constructor(){super(...arguments);r(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var CgA=Object.defineProperty,ngA=Object.getOwnPropertyDescriptor,Sy=(i,A,e,t)=>{for(var g=t>1?void 0:t?ngA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&CgA(A,e,g),g};let NU=class{constructor(){r(this,"texture",null);r(this,"rect")}};Sy([D(qe)],NU.prototype,"texture",2);let VE=class extends Kd{constructor(){super(...arguments);r(this,"_sprite");r(this,"pixelsPerUnitMultiplier",1)}set image(e){this.sprite||(this.sprite=new NU),this.sprite.texture=e,this.onAfterCreated()}get image(){return this.sprite?this.sprite.texture:null}get sprite(){return this._sprite}set sprite(e){this._sprite!==e&&(this._sprite=e,this.onAfterCreated())}isBuiltinSprite(){var e,t,g,I,o,s,C,n;switch((t=(e=this.sprite)==null?void 0:e.texture)==null?void 0:t.name){case"InputFieldBackground":case"UISprite":case"Background":case"Knob":return!0}return((o=(I=(g=this.sprite)==null?void 0:g.texture)==null?void 0:I.image)==null?void 0:o.width)===32&&((n=(C=(s=this.sprite)==null?void 0:s.texture)==null?void 0:C.image)==null?void 0:n.height)===32}onBeforeCreate(e){var t,g;super.onBeforeCreate(e),this.isBuiltinSprite()&&(e.borderRadius=5/this.pixelsPerUnitMultiplier,((g=(t=this.sprite)==null?void 0:t.texture)==null?void 0:g.name)==="Knob"&&(e.borderRadius=999))}onAfterCreated(){var e;this.__didAwake&&(super.onAfterCreated(),!this.isBuiltinSprite()&&this.setTexture((e=this.sprite)==null?void 0:e.texture))}};Sy([D(NU)],VE.prototype,"sprite",1);Sy([D()],VE.prototype,"pixelsPerUnitMultiplier",2);class ky extends Kd{constructor(){super(...arguments);r(this,"_mainTexture")}get mainTexture(){return this._mainTexture}set mainTexture(e){this._mainTexture!==e&&(this._mainTexture=e,this.onAfterCreated())}onAfterCreated(){this.__didAwake&&(super.onAfterCreated(),this.setTexture(this.mainTexture))}}Sy([D(qe)],ky.prototype,"mainTexture",1);var agA=Object.defineProperty,rgA=Object.getOwnPropertyDescriptor,Eo=(i,A,e,t)=>{for(var g=t>1?void 0:t?rgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&agA(A,e,g),g};const aQ=sA("debugbutton");class lB{constructor(){r(this,"colorMultiplier");r(this,"disabledColor");r(this,"fadeDuration");r(this,"highlightedColor");r(this,"normalColor");r(this,"pressedColor");r(this,"selectedColor")}}Eo([D()],lB.prototype,"colorMultiplier",2);Eo([D(St)],lB.prototype,"disabledColor",2);Eo([D()],lB.prototype,"fadeDuration",2);Eo([D(St)],lB.prototype,"highlightedColor",2);Eo([D(St)],lB.prototype,"normalColor",2);Eo([D(St)],lB.prototype,"pressedColor",2);Eo([D(St)],lB.prototype,"selectedColor",2);class Un extends NA{constructor(){super(...arguments);r(this,"onClick");r(this,"_isHovered",!1);r(this,"colors");r(this,"transition");r(this,"animationTriggers");r(this,"animator");r(this,"_interactable",!0);r(this,"_requestedAnimatorTrigger");r(this,"_isInit",!1);r(this,"_image")}onPointerEnter(e){var t,g;aQ&&console.log("Button Enter",(t=this.animationTriggers)==null?void 0:t.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&&((g=this._image)==null||g.setState("hovered")),this.context.input.setCursorPointer())}onPointerExit(){var e,t;aQ&&console.log("Button Exit",(e=this.animationTriggers)==null?void 0:e.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&&((t=this._image)==null||t.setState("normal")),this.context.input.setCursorNormal())}onPointerDown(e){var t,g;aQ&&console.log("Button Down",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.pressedTrigger):this.transition===1&&this.colors&&((g=this._image)==null||g.setState("pressed")))}onPointerUp(e){var t,g;aQ&&console.warn("Button Up",(t=this.animationTriggers)==null?void 0:t.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&&((g=this._image)==null||g.setState(this._isHovered?"hovered":"normal")))}onPointerClick(e){var t;!this.interactable||e.pointerId===void 0||e.pointerId!==0&&this.context.input.getIsMouse(e.pointerId)||(aQ&&(console.warn("Button Click",this.onClick),Di("CLICKED button "+this.name+" at "+this.context.time.frameCount)),(t=this.onClick)==null||t.invoke(),e.use())}set interactable(e){this._interactable=e,this._image&&(this._image.setInteractable(e),e?this._image.setState("normal"):this._image.setState("disabled"))}get interactable(){return this._interactable}set_interactable(e){this.interactable=e}awake(){super.awake(),aQ&&console.log(this),this._isInit=!1,this.init()}start(){var e;(e=this._image)==null||e.setInteractable(this.interactable)}onEnable(){super.onEnable()}*setAnimatorTriggerAtEndOfFrame(e){var t;this._requestedAnimatorTrigger=e,yield,yield,this._requestedAnimatorTrigger==e&&((t=this.animator)==null||t.SetTrigger(e))}init(){this._isInit||(this._isInit=!0,this._image=IA.getComponent(this.gameObject,VE),this._image&&(this.stateSetup(this._image),this.interactable?this._image.setState("normal"):this._image.setState("disabled")))}stateSetup(e){var E,c,l,d,h;e.setInteractable(this.interactable);const t=this.getFinalColor(e.color,(E=this.colors)==null?void 0:E.normalColor),g={state:"normal",attributes:{backgroundColor:t,backgroundOpacity:t.alpha}};e.setupState(g);const I=this.getFinalColor(e.color,(c=this.colors)==null?void 0:c.highlightedColor),o={state:"hovered",attributes:{backgroundColor:I,backgroundOpacity:I.alpha}};e.setupState(o);const s=this.getFinalColor(e.color,(l=this.colors)==null?void 0:l.pressedColor),C={state:"pressed",attributes:{backgroundColor:s,backgroundOpacity:s.alpha}};e.setupState(C);const n=this.getFinalColor(e.color,(d=this.colors)==null?void 0:d.selectedColor),a={state:"selected",attributes:{backgroundColor:n,backgroundOpacity:n.alpha}};e.setupState(a);const B=this.getFinalColor(e.color,(h=this.colors)==null?void 0:h.disabledColor),Q={state:"disabled",attributes:{backgroundColor:B,backgroundOpacity:B.alpha}};e.setupState(Q)}getFinalColor(e,t){return t?e.clone().multiply(t):e.clone()}}Eo([D(Dg)],Un.prototype,"onClick",2);Eo([D()],Un.prototype,"colors",2);Eo([D()],Un.prototype,"transition",2);Eo([D()],Un.prototype,"animationTriggers",2);Eo([D(Pg)],Un.prototype,"animator",2);Eo([D()],Un.prototype,"interactable",1);var BgA=Object.defineProperty,QgA=Object.getOwnPropertyDescriptor,Yi=(i,A,e,t)=>{for(var g=t>1?void 0:t?QgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&BgA(A,e,g),g};const sv=sA("debuguilayout");class Oa{constructor(){r(this,"left",0);r(this,"right",0);r(this,"top",0);r(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Yi([D()],Oa.prototype,"left",2);Yi([D()],Oa.prototype,"right",2);Yi([D()],Oa.prototype,"top",2);Yi([D()],Oa.prototype,"bottom",2);class co extends NA{constructor(){super(...arguments);r(this,"_rectTransform",null);r(this,"_needsUpdate",!1);r(this,"childAlignment",0);r(this,"reverseArrangement",!1);r(this,"spacing",0);r(this,"padding");r(this,"minWidth",0);r(this,"minHeight",0);r(this,"flexibleHeight",0);r(this,"flexibleWidth",0);r(this,"preferredHeight",0);r(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(e){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(sv&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){sv&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(cI);const e=this.gameObject.getComponentInParent(Sg);e&&e.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const e=this.gameObject.getComponentInParent(Sg);e&&e.unregisterLayoutGroup(this)}set m_Spacing(e){e!==this.spacing&&(this._needsUpdate=!0,this.spacing=e)}get m_Spacing(){return this.spacing}}Yi([D()],co.prototype,"childAlignment",2);Yi([D()],co.prototype,"reverseArrangement",2);Yi([D()],co.prototype,"spacing",2);Yi([D(Oa)],co.prototype,"padding",2);Yi([D()],co.prototype,"minWidth",2);Yi([D()],co.prototype,"minHeight",2);Yi([D()],co.prototype,"flexibleHeight",2);Yi([D()],co.prototype,"flexibleWidth",2);Yi([D()],co.prototype,"preferredHeight",2);Yi([D()],co.prototype,"preferredWidth",2);class Pa extends co{constructor(){super(...arguments);r(this,"childControlHeight",!0);r(this,"childControlWidth",!0);r(this,"childForceExpandHeight",!1);r(this,"childForceExpandWidth",!1);r(this,"childScaleHeight",!1);r(this,"childScaleWidth",!1)}onCalculateLayout(e){var R;const t=this.primaryAxis,g=e.width;let I=g;const o=e.height;let s=o;I-=this.padding.horizontal,s-=this.padding.vertical,t==="x"?this.padding.horizontal:this.padding.vertical;const C=t==="x",n=C?"y":"x",a=C?this.childControlWidth:this.childControlHeight,B=C?this.childControlHeight:this.childControlWidth,Q=C?this.childForceExpandWidth:this.childForceExpandHeight,E=C?this.childForceExpandHeight:this.childForceExpandWidth,c=C?s:I,l=C?g:o,d=.5*(C?this.childAlignment%3:Math.floor(this.childAlignment/3));let h=0;C?h+=this.padding.left:h+=this.padding.top;let p=0,u=0;for(let k=0;k<this.gameObject.children.length;k++){const m=this.gameObject.children[k],K=IA.getComponent(m,cI);K!=null&&K.activeAndEnabled&&(u+=1,C?p+=K.width:p+=K.height)}let f=0;const S=this.spacing*(u-1);if(Q||a){let k=0;C?k=I-=S:k=s-=S,u>0&&(f=k/u)}let G=0;G+=this.padding.left,G-=this.padding.right,d!==0&&(h=l-p,h*=d,h-=S*d,C?(h-=this.padding.right*d,h+=this.padding.left*(1-d),h<this.padding.left&&(h=this.padding.left)):(h-=this.padding.bottom*d,h+=this.padding.top*(1-d),h<this.padding.top&&(h=this.padding.top)));let M=1;for(let k=0;k<this.gameObject.children.length;k++){const m=this.gameObject.children[k],K=IA.getComponent(m,cI);if(K!=null&&K.activeAndEnabled){(R=K.pivot)==null||R.set(.5,.5),K.anchorMin.set(0,1),K.anchorMax.set(0,1);const Z=g*.5+G*.5;K.anchoredPosition.x!==Z&&(K.anchoredPosition.x=Z);const H=o*-.5;K.anchoredPosition.y!==H&&(K.anchoredPosition.y=H),E&&B&&K.sizeDelta[n]!==c&&(K.sizeDelta[n]=c),Q&&a&&K.sizeDelta[t]!==f&&(K.sizeDelta[t]=f);const _=C?K.width:K.height,j=_*.5;if(h+=j,Q){const v=f*M-f*.5;v>h&&(h=v-f*.5+_+this.padding.left,h-=j)}let x=h;t==="y"&&(x=-x),K.anchoredPosition[t]!==x&&(K.anchoredPosition[t]=x),h+=j,h+=this.spacing,M+=1}}}}Yi([D()],Pa.prototype,"childControlHeight",2);Yi([D()],Pa.prototype,"childControlWidth",2);Yi([D()],Pa.prototype,"childForceExpandHeight",2);Yi([D()],Pa.prototype,"childForceExpandWidth",2);Yi([D()],Pa.prototype,"childScaleHeight",2);Yi([D()],Pa.prototype,"childScaleWidth",2);class KU extends Pa{get primaryAxis(){return"y"}}class JU extends Pa{get primaryAxis(){return"x"}}class qU extends co{onCalculateLayout(){}}var EgA=Object.defineProperty,cgA=Object.getOwnPropertyDescriptor,QC=(i,A,e,t)=>{for(var g=t>1?void 0:t?cgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&EgA(A,e,g),g},f2=(i=>(i[i.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",i[i.ScreenSpaceCamera=1]="ScreenSpaceCamera",i[i.WorldSpace=2]="WorldSpace",i[i.Undefined=-1]="Undefined",i))(f2||{});const ak=sA("debuguilayout"),D2=class extends yd{constructor(){super(...arguments);r(this,"_renderOnTop");r(this,"_depthWrite",!1);r(this,"_doubleSided",!0);r(this,"_castShadows",!1);r(this,"_receiveShadows",!1);r(this,"_renderMode",-1);r(this,"_rootCanvas");r(this,"_scaleFactor",1);r(this,"worldCamera");r(this,"planeDistance",-1);r(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this));r(this,"previousParent",null);r(this,"_lastMatrixWorld",null);r(this,"_rectTransforms",[]);r(this,"_layoutGroups",new Map);r(this,"_receivers",[]);r(this,"onBeforeRenderRoutine",()=>{var A,e,t,g;if(this.context.isInVR){this.onUpdateRenderMode(),this.handleLayoutUpdates(),(A=this.shadowComponent)==null||A.updateMatrixWorld(!0),(e=this.shadowComponent)==null||e.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),nI.ensureUpdateMeshUI(ok,this.context,!0);return}this.previousParent=this.gameObject.parent,this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(t=this.shadowComponent)==null||t.updateMatrixWorld(!0),(g=this.shadowComponent)==null||g.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),nI.ensureUpdateMeshUI(ok,this.context))});r(this,"onAfterRenderRoutine",()=>{var A,e;if(!this.context.isInVR){if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const I=this.context.mainCamera;I==null||I.add(this.gameObject)}else this.previousParent.add(this.gameObject);const t=this.context.renderer.autoClear,g=this.context.renderer.autoClearColor;this.context.renderer.autoClear=!1,this.context.renderer.autoClearColor=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(A=this.shadowComponent)==null||A.updateMatrixWorld(!0),this.invokeBeforeRenderEvents(),nI.ensureUpdateMeshUI(ok,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=t,this.context.renderer.autoClearColor=g,this.previousParent.add(this.gameObject)}(e=this._lastMatrixWorld)==null||e.copy(this.gameObject.matrixWorld)}});r(this,"_updateRenderSettingsRoutine");r(this,"_activeRenderMode",-1);r(this,"_lastWidth",-1);r(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(A){A!==this._renderOnTop&&(this._renderOnTop=A,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(A){this._depthWrite!==A&&(this._depthWrite=A,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(A){this._doubleSided!==A&&(this._doubleSided=A,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(A){this._castShadows!==A&&(this._castShadows=A,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(A){this._receiveShadows!==A&&(this._receiveShadows=A,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(A){this._renderMode!==A&&(this._renderMode=A,this.onRenderSettingsChanged())}set rootCanvas(A){this._rootCanvas instanceof D2||(this._rootCanvas=A)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(A){this._scaleFactor=A}awake(){var A;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,ak&&console.log("Canvas.Awake()",((A=this.previousParent)==null?void 0:A.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new UA,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 A=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);A!==-1&&this.context.pre_render_callbacks.splice(A,1);const e=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);e!==-1&&this.context.post_render_callbacks.splice(e,1)}registerTransform(A){this._rectTransforms.push(A)}unregisterTransform(A){const e=this._rectTransforms.indexOf(A);e!==-1&&this._rectTransforms.splice(e,1)}registerLayoutGroup(A){const e=A.gameObject;this._layoutGroups.set(e,A)}unregisterLayoutGroup(A){const e=A.gameObject;this._layoutGroups.delete(e)}registerEventReceiver(A){this._receivers.push(A)}unregisterEventReceiver(A){const e=this._receivers.indexOf(A);e!==-1&&this._receivers.splice(e,1)}invokeBeforeRenderEvents(){var A;for(const e of this._receivers)(A=e.onBeforeCanvasRender)==null||A.call(e,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new UA);const A=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);ak&&A&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const e=!1;for(const t of this._rectTransforms){A&&t.markDirty();let g=this._layoutGroups.get(t.gameObject);t.isDirty&&!g&&(g=t.gameObject.getComponentInParent(co)),(t.isDirty||g!=null&&g.isDirty)&&(ak&&!e&&console.log("CANVAS UPDATE ### "+t.name+" ##################################### "+this.context.time.frame),g==null||g.updateLayout(),t.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),xI.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),lD(this.shadowComponent,this);for(const A of IA.getComponentsInChildren(this.gameObject,ps))lD(A.shadowComponent,this)}}onUpdateRenderMode(A=!1){if(!A&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let e=this.context.mainCameraComponent,t=10;switch(e&&e.nearClipPlane>0&&e.farClipPlane>0&&(t=ie.lerp(e.nearClipPlane,e.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(e=this.worldCamera),this.planeDistance>0&&(t=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!e)return;const g=t+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-g,this.gameObject.quaternion.identity();const I=this.gameObject.getComponent(cI);let o=!1;I.sizeDelta.x!==this.context.domWidth&&(o=!0),I.sizeDelta.y!==this.context.domHeight&&(o=!0);const s=e.fieldOfView*Math.PI/180,C=2*Math.tan(s/2)*Math.abs(g);this.gameObject.scale.x=C/this.context.domHeight,this.gameObject.scale.y=C/this.context.domHeight,this.gameObject.scale.z=.01,o&&(I.sizeDelta.x=this.context.domWidth,I.sizeDelta.y=this.context.domHeight,I==null||I.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let Sg=D2;QC([D()],Sg.prototype,"renderOnTop",1);QC([D()],Sg.prototype,"depthWrite",1);QC([D()],Sg.prototype,"doubleSided",1);QC([D()],Sg.prototype,"castShadows",1);QC([D()],Sg.prototype,"receiveShadows",1);QC([D()],Sg.prototype,"renderMode",1);QC([D(Sg)],Sg.prototype,"rootCanvas",1);QC([D()],Sg.prototype,"scaleFactor",1);QC([D(Ht)],Sg.prototype,"worldCamera",2);QC([D()],Sg.prototype,"planeDistance",2);var hgA=Object.defineProperty,lgA=Object.getOwnPropertyDescriptor,vU=(i,A,e,t)=>{for(var g=t>1?void 0:t?lgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&hgA(A,e,g),g};class Fa extends NA{constructor(){super(...arguments);r(this,"_alpha",1);r(this,"interactable",!0);r(this,"blocksRaycasts",!0);r(this,"_isDirty",!1);r(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(e){e!==this._alpha&&(this._alpha=e,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),xI.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){for(const e of IA.getComponentsInChildren(this.gameObject,ps,this._buffer)){const t=e;t.setAlphaFactor&&t.setAlphaFactor(this._alpha)}}}vU([D()],Fa.prototype,"alpha",1);vU([D()],Fa.prototype,"interactable",2);vU([D()],Fa.prototype,"blocksRaycasts",2);var dgA=Object.defineProperty,ugA=Object.getOwnPropertyDescriptor,_t=(i,A,e,t)=>{for(var g=t>1?void 0:t?ugA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&dgA(A,e,g),g};class dB extends NA{constructor(){super(...arguments);r(this,"object");r(this,"target");r(this,"duration",1);r(this,"relativeMotion",!1);r(this,"coroutine",null);r(this,"targetPos",new w);r(this,"targetRot",new GA);r(this,"targetScale",new w)}*moveToTarget(){if(!this.target||!this.object)return;const e=ke(this.object).clone(),t=ke(this.target).clone(),g=Zi(this.object).clone(),I=Zi(this.target).clone(),o=pg(this.object).clone(),s=pg(this.target).clone(),C=e.distanceTo(t),n=g.angleTo(I),a=o.distanceTo(s);if(C<.01&&n<.01&&a<.01){bi(this.object,t),LI(this.object,I),vG(this.object,s),this.coroutine=null;return}let B=0,Q=0;for(;B<1;)B+=this.context.time.deltaTime/this.duration,B>1&&(B=1),Q=B<.5?4*B*B*B:1-Math.pow(-2*B+2,3)/2,this.targetPos.lerpVectors(e,t,Q),this.targetRot.slerpQuaternions(g,I,Q),this.targetScale.lerpVectors(o,s,Q),bi(this.object,this.targetPos),LI(this.object,this.targetRot),vG(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const e=this.object.position.clone(),t=this.object.quaternion.clone(),g=this.object.scale.clone(),I=this.target.position.clone(),o=this.target.quaternion.clone(),s=this.target.scale.clone();I.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(I),this.targetRot.copy(this.object.quaternion).multiply(o),this.targetScale.copy(this.object.scale).multiply(s);let C=0,n=0;for(;C<1;)C+=this.context.time.deltaTime/this.duration,C>1&&(C=1),n=C<.5?4*C*C*C:1-Math.pow(-2*C+2,3)/2,this.object.position.lerpVectors(e,this.targetPos,n),this.object.quaternion.slerpQuaternions(t,this.targetRot,n),this.object.scale.lerpVectors(g,this.targetScale,n),yield;this.coroutine=null}onPointerClick(e){e.use(),this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}beforeCreateDocument(e){var t;if(this.target&&this.object&&this.gameObject){const g=new wg("Move to "+((t=this.target)==null?void 0:t.name),vI.tapTrigger(this.gameObject),lt.transformAction(this.object,this.target,this.duration,this.relativeMotion?fm.Relative:fm.Absolute));e.addBehavior(g)}}}_t([D(FA)],dB.prototype,"object",2);_t([D(FA)],dB.prototype,"target",2);_t([D()],dB.prototype,"duration",2);_t([D()],dB.prototype,"relativeMotion",2);var Lp;const JC=(Lp=class extends NA{constructor(){super(...arguments);r(this,"materialToSwitch");r(this,"variantMaterial");r(this,"fadeDuration",0);r(this,"_objectsWithThisMaterial",[]);r(this,"selfModel");r(this,"targetModels")}awake(){if(this.variantMaterial&&this.materialToSwitch){const A=IA.findObjectsOfType(jt);for(const e of A)for(let t=0;t<e.sharedMaterials.length;t++){const g=e.sharedMaterials[t];if(g===this.materialToSwitch){if(e.gameObject instanceof wA)this._objectsWithThisMaterial.push(e.gameObject);else if(e.gameObject instanceof UI)for(const I of e.gameObject.children)I instanceof wA&&I.material===g&&this._objectsWithThisMaterial.push(I);break}}}}onPointerClick(A){if(A.use(),!!this.variantMaterial)for(let e=0;e<this._objectsWithThisMaterial.length;e++){const t=this._objectsWithThisMaterial[e];t.material=this.variantMaterial}}async beforeCreateDocument(A,e){this.targetModels=[],JC._materialTriggersPerId={},JC.variantSwitchIndex=0,this.materialToSwitch&&await Ao.assignTextureLOD(this.context,this.sourceId,this.materialToSwitch,0),this.variantMaterial&&await Ao.assignTextureLOD(this.context,this.sourceId,this.variantMaterial,0)}createBehaviours(A,e,t){this._objectsWithThisMaterial.find(I=>I.uuid===e.uuid)&&this.targetModels.push(e),this.gameObject.uuid===e.uuid&&(this.selfModel=e,this.materialToSwitch&&(JC._materialTriggersPerId[this.materialToSwitch.uuid]||(JC._materialTriggersPerId[this.materialToSwitch.uuid]=[]),JC._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(A,e){if(!this.materialToSwitch)return;const t=JC._materialTriggersPerId[this.materialToSwitch.uuid];if(t){const g={};for(const o of t){const s=o.createVariants();s&&s.length>0&&(g[o.selfModel.uuid]=s)}const I=[];for(const o of t){for(const s in g)s!==o.selfModel.uuid&&I.push(g[s]);o.createAndAttachBehaviors(A,g[o.selfModel.uuid],I)}}delete JC._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(A,e,t){const g=[],I=[],o=Math.max(0,this.fadeDuration);for(const s of this.targetModels){const C=lt.fadeAction(s,o,!1);I.push(C)}for(const s of t)I.push(lt.fadeAction(s,o,!1));for(const s of e)g.push(lt.fadeAction(s,o,!1)),I.push(lt.fadeAction(s,o,!0));A.addBehavior(new wg("Select "+this.selfModel.name,vI.tapTrigger(this.selfModel),lt.parallel(...I))),A.addBehavior(new wg("Start hidden "+this.selfModel.name,vI.sceneStartTrigger(),lt.parallel(...g)))}createVariants(){if(!this.variantMaterial)return null;const A=[];for(const e of this.targetModels){const t=e.clone();t.name+=" variant_"+this.variantMaterial.name+"_"+JC.variantSwitchIndex++,t.name=t.name.replace(/\s/g,"_"),t.material=this.variantMaterial,t.geometry=e.geometry,t.matrix=e.matrix,(!e.parent||!e.parent.isEmpty())&&NI.createEmptyParent(e),e.parent&&e.parent.add(t),A.push(t)}return A}},r(Lp,"_materialTriggersPerId",{}),r(Lp,"variantSwitchIndex",0),Lp);let zE=JC;_t([D(ve)],zE.prototype,"materialToSwitch",2);_t([D(ve)],zE.prototype,"variantMaterial",2);_t([D()],zE.prototype,"fadeDuration",2);class jE extends NA{constructor(){super(...arguments);r(this,"target");r(this,"toggleOnClick",!1);r(this,"targetState",!0);r(this,"hideSelf",!0);r(this,"selfModel");r(this,"otherModel");r(this,"toggleModel");r(this,"stateBeforeCreatingDocument",!1)}onPointerClick(e){e.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(e,t,g){t.uuid===this.gameObject.uuid&&(this.selfModel=t)}beforeCreateDocument(){this.stateBeforeCreatingDocument=this.gameObject.visible,this.gameObject.visible=!0}afterCreateDocument(e,t){if(this.target){if(this.otherModel=t.document.findById(this.target.uuid),this.selfModel&&this.otherModel){let g=this.hideSelf;this.targetState,this.toggleOnClick&&(g=!0,this.target.visible,(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&FH.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.clone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel));const I=[];if(g&&I.push(lt.fadeAction(this.selfModel,0,!1)),this.toggleModel&&I.push(lt.fadeAction(this.toggleModel,0,!0)),I.push(lt.fadeAction(this.otherModel,0,this.targetState)),e.addBehavior(new wg("Toggle_"+this.selfModel.name+"_hideSelf",vI.tapTrigger(this.selfModel),lt.sequence(...I))),this.toggleOnClick&&this.toggleModel){const o=[];o.push(lt.fadeAction(this.toggleModel,0,!1)),o.push(lt.fadeAction(this.selfModel,0,!0)),o.push(lt.fadeAction(this.otherModel,0,!this.targetState)),e.addBehavior(new wg("Toggle_"+this.selfModel.name+"_toggleSelf",vI.tapTrigger(this.toggleModel),lt.sequence(...o))),e.addBehavior(new wg("HideOnStart_"+this.gameObject.name,vI.sceneStartTrigger(),lt.fadeAction(this.toggleModel,0,!1)))}}this.gameObject.visible=this.stateBeforeCreatingDocument}}}_t([D(FA)],jE.prototype,"target",2);_t([D()],jE.prototype,"targetState",2);_t([D()],jE.prototype,"hideSelf",2);class bU extends NA{start(){this.gameObject.visible=!1}createBehaviours(A,e,t){e.uuid===this.gameObject.uuid&&A.addBehavior(new wg("HideOnStart_"+this.gameObject.name,vI.sceneStartTrigger(),lt.fadeAction(e,0,!1)))}beforeCreateDocument(){this.gameObject.visible=!0}afterCreateDocument(){this.gameObject.visible=!1}}class ZE extends NA{constructor(){super(...arguments);r(this,"target");r(this,"duration",.5);r(this,"motionType",YR.bounce)}beforeCreateDocument(){}createBehaviours(e,t,g){if(this.target&&t.uuid===this.gameObject.uuid){const I=new wg("emphasize "+this.name,vI.tapTrigger(this.gameObject),lt.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));e.addBehavior(I)}}afterCreateDocument(e,t){}}_t([D()],ZE.prototype,"target",2);_t([D()],ZE.prototype,"duration",2);_t([D()],ZE.prototype,"motionType",2);class XE extends NA{constructor(){super(...arguments);r(this,"target");r(this,"clip","");r(this,"toggleOnClick",!1)}onPointerClick(e){if(e.use(),!(!this.target&&!this.clip)){if(!this.target){const t=this.gameObject.addNewComponent(Gi);t&&(t.spatialBlend=1,t.volume=1,t.loop=!1,this.target=t)}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(e,t,g){if(!(!this.target&&!this.clip)&&t.uuid===this.gameObject.uuid){const I=this.clip?this.clip:this.target?this.target.clip:void 0;if(!I)return;const o=this.target?this.target.gameObject:this.gameObject,s=I.split("/").pop(),C=this.target?this.target.volume:1,n=this.target&&this.target.spatialBlend==0?Dm.NonSpatial:Dm.Spatial,a=new wg("playAudio "+this.name,vI.tapTrigger(this.gameObject),lt.playAudioAction(o,"audio/"+s,bH.Play,C,n));e.addBehavior(a)}}async afterSerialize(e,t){if(!this.target&&!this.clip)return;const g=this.clip?this.clip:this.target?this.target.clip:void 0;if(!g)return;const I=g.split("/").pop(),C=await(await(await fetch(this.clip)).blob()).arrayBuffer(),n=new Uint8Array(C);t.files["audio/"+I]=n}}_t([D(Gi)],XE.prototype,"target",2);_t([D(URL)],XE.prototype,"clip",2);_t([D()],XE.prototype,"toggleOnClick",2);var Ok;const wQ=(Ok=class extends NA{constructor(){super(...arguments);r(this,"target");r(this,"animator");r(this,"stateName");r(this,"stateNameAfterPlaying");r(this,"loopAfterPlaying",!1);r(this,"selfModel");r(this,"stateAnimationModel");r(this,"stateAnimation");r(this,"stateAfterPlayingAnimationModel");r(this,"stateAfterPlayingAnimation")}onPointerClick(A){var e;A.use(),this.target&&this.stateName&&((e=this.animator)==null||e.play(this.stateName,0,0,.1))}createBehaviours(A,e,t){e.uuid===this.gameObject.uuid&&(this.selfModel=e)}onAfterHierarchy(){wQ.animationActions=[]}afterCreateDocument(A,e){if(!this.stateAnimation||!this.stateAnimationModel)return;e.document.traverse(g=>{var I,o;if(g.uuid===((I=this.target)==null?void 0:I.uuid)&&this.stateAnimation){const s=[];let C=wQ.animationActions.find(a=>a.affectedObjects==g&&a.start==this.stateAnimation.start&&a.duration==this.stateAnimation.duration);if(C||(C=lt.startAnimationAction(g,this.stateAnimation.start,this.stateAnimation.duration),wQ.animationActions.push(C)),s.push(C),this.stateAfterPlayingAnimation&&this.stateAfterPlayingAnimationModel){let a=wQ.animationActions.find(Q=>Q.affectedObjects==g&&Q.start==this.stateAfterPlayingAnimation.start&&Q.duration==this.stateAfterPlayingAnimation.duration);a||(a=lt.startAnimationAction(g,this.stateAfterPlayingAnimation.start,this.stateAfterPlayingAnimation.duration),wQ.animationActions.push(a));const B=lt.sequence(a);this.loopAfterPlaying&&B.makeLooping(),s.push(B)}const n=new wg("tap "+this.name+" for "+this.stateName+" on "+((o=this.target)==null?void 0:o.name),vI.tapTrigger(this.selfModel),lt.sequence(...s));A.addBehavior(n)}})}createAnimation(A,e,t){var g,I,o,s,C;if(this.target&&this.animator){const n=(I=(g=this.animator)==null?void 0:g.runtimeAnimatorController)==null?void 0:I.findState(this.stateName);if(!((o=n==null?void 0:n.motion)!=null&&o.clip)){rt()&&console.warn("No clip found for state "+this.stateName);return}this.stateAnimationModel=e,this.stateAnimation=A.registerAnimation(this.target,n==null?void 0:n.motion.clip);const a=(C=(s=this.animator)==null?void 0:s.runtimeAnimatorController)==null?void 0:C.findState(this.stateNameAfterPlaying);this.stateAfterPlayingAnimationModel=e,this.stateAfterPlayingAnimation=A.registerAnimation(this.target,a==null?void 0:a.motion.clip)}}},r(Ok,"animationActions",[]),Ok);let Wa=wQ;_t([D(FA)],Wa.prototype,"target",2);_t([D(Pg)],Wa.prototype,"animator",2);_t([D()],Wa.prototype,"stateName",2);_t([D()],Wa.prototype,"stateNameAfterPlaying",2);_t([D()],Wa.prototype,"loopAfterPlaying",2);class $E extends NA{constructor(){super(...arguments);r(this,"target")}getType(){}getDuration(){}}_t([D(FA)],$E.prototype,"target",2);class Jd extends NA{constructor(){super(...arguments);r(this,"target")}}_t([D($E)],Jd.prototype,"target",2);class qd extends $E{constructor(){super(...arguments);r(this,"type",1);r(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}_t([D()],qd.prototype,"type",2);_t([D()],qd.prototype,"duration",2);class LU extends Jd{}var pgA=Object.defineProperty,fgA=Object.getOwnPropertyDescriptor,Fn=(i,A,e,t)=>{for(var g=t>1?void 0:t?fgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&pgA(A,e,g),g};class uB extends NA{constructor(){super(...arguments);r(this,"center",new w(0,0,0));r(this,"radius",.5);r(this,"height",2);r(this,"_rigidbody",null);r(this,"_activeGroundCollisions")}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(qt),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(qt)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const e=this.rigidbody;let t=this.gameObject.getComponent(Ua);t||(t=this.gameObject.addNewComponent(Ua)),t.center.copy(this.center),t.radius=this.radius,t.height=this.height;const g=new w(0,0,1),I=new w(1,0,0),o=new w(0,1,0),s=this.gameObject.getWorldDirection(new w);s.y=0;const C=I.dot(s)<0?-1:1,n=g.angleTo(s)*C;this.gameObject.setRotationFromAxisAngle(o,n),e.lockRotationX=!0,e.lockRotationY=!0,e.lockRotationZ=!0}move(e){this.gameObject.position.add(e)}onCollisionEnter(e){for(const t of e.contacts)if(t.normal.y>.1){this._activeGroundCollisions.add(e);break}}onCollisionExit(e){this._activeGroundCollisions.delete(e)}get isGrounded(){return this._activeGroundCollisions.size>0}}Fn([D(w)],uB.prototype,"center",2);Fn([D()],uB.prototype,"radius",2);Fn([D()],uB.prototype,"height",2);class Nn extends NA{constructor(){super(...arguments);r(this,"controller");r(this,"movementSpeed",2);r(this,"rotationSpeed",2);r(this,"jumpForce",1);r(this,"doubleJumpForce",2);r(this,"animator");r(this,"lookForward",!0);r(this,"lookInput",new tA(0,0));r(this,"moveInput",new tA(0,0));r(this,"jumpInput",!1);r(this,"_currentSpeed",new w(0,0,0));r(this,"_currentAngularSpeed",new w(0,0,0));r(this,"_temp",new w(0,0,0));r(this,"_jumpCount",0);r(this,"_currentRotation");r(this,"_raycastOptions",new Wo)}awake(){this._currentRotation=new GA}update(){const e=this.context.input;e.isKeyPressed("KeyW")?this.moveInput.y+=1:e.isKeyPressed("KeyS")&&(this.moveInput.y-=1),e.isKeyPressed("KeyD")?this.lookInput.x+=1:e.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=e.isKeyDown("Space"))}move(e){this.moveInput.add(e)}look(e){this.lookInput.add(e)}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(e,t,g){var I,o,s,C,n,a,B,Q,E,c,l;if((I=this.controller)!=null&&I.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((o=this.animator)==null||o.setBool("doubleJump",!1))),this._currentSpeed.z+=e.y*this.movementSpeed*this.context.time.deltaTime,(s=this.animator)==null||s.setBool("running",e.length()>.01),(n=this.animator)==null||n.setBool("jumping",((C=this.controller)==null?void 0:C.isGrounded)===!0&&g),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+=ie.toRadians(-t.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const d=this.context.mainCameraComponent.forward;d.y=0,d.normalize(),this._currentRotation.setFromUnitVectors(new w(0,0,1),d),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&&g&&this.jumpForce>0){let d=(a=this.controller)==null?void 0:a.isGrounded;if(this.doubleJumpForce>0&&!((B=this.controller)!=null&&B.isGrounded)&&this._jumpCount===1&&(d=!0,(Q=this.animator)==null||Q.setBool("doubleJump",!0)),d){this._jumpCount+=1;const h=this.controller.rigidbody,p=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;h.applyImpulse(new w(0,1,0).multiplyScalar(p))}}if(this.controller){const d=(E=this.controller)==null?void 0:E.rigidbody.getVelocity().y;if(d<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new nC),this._raycastOptions.ray.origin.copy(ke(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const h=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const p=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(h),(p.length&&p[0].distance>2||d<-10)&&((c=this.animator)==null||c.setBool("falling",!0))}else(l=this.animator)==null||l.setBool("falling",!1)}}}Fn([D(uB)],Nn.prototype,"controller",2);Fn([D()],Nn.prototype,"movementSpeed",2);Fn([D()],Nn.prototype,"rotationSpeed",2);Fn([D()],Nn.prototype,"jumpForce",2);Fn([D()],Nn.prototype,"doubleJumpForce",2);Fn([D(Pg)],Nn.prototype,"animator",2);var DgA=Object.defineProperty,wgA=Object.getOwnPropertyDescriptor,ygA=(i,A,e,t)=>{for(var g=t>1?void 0:t?wgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&DgA(A,e,g),g};class vd extends zg{constructor(){super(...arguments);r(this,"intensity")}get typeName(){return"ChromaticAberration"}init(){this.intensity.defaultValue=0}onCreateEffect(){const e=new UY;return e.offset=new tA(0,0),e.radialModulation=!0,e.modulationOffset=.15,this.intensity.valueProcessor=t=>t*.02,this.intensity.onValueChanged=t=>{e.offset.x=-t,e.offset.y=t},e}}ygA([D(Fe)],vd.prototype,"intensity",2);Zo("ChromaticAberration",vd);var SgA=Object.defineProperty,kgA=Object.getOwnPropertyDescriptor,Gy=(i,A,e,t)=>{for(var g=t>1?void 0:t?kgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&SgA(A,e,g),g};class Va extends zg{constructor(){super(...arguments);r(this,"postExposure");r(this,"contrast");r(this,"hueShift");r(this,"saturation")}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=e=>(e=Math.pow(2,e),e),this.postExposure.defaultValue=0,this.contrast.valueProcessor=e=>{let t=1;return e>0?t=200:e<0&&(t=100),e/t},this.contrast.defaultValue=0,this.hueShift.valueProcessor=e=>Math.PI*e/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=e=>e<0?e/100:e/(100*Math.PI),this.saturation.defaultValue=0}unapply(){this.context.renderer.toneMappingExposure=1}onCreateEffect(){this.context.renderer.toneMapping===aI&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=Zh);const e=new RY;this.postExposure.onValueChanged=g=>{this.context.renderer.toneMapping===aI&&(this.context.renderer.toneMapping=Zh),this.postExposure.overrideState&&(this.context.renderer.toneMappingExposure=g)},this.contrast.onValueChanged=g=>{e.contrast=g};const t=new NY;return this.hueShift.onValueChanged=g=>t.hue=g,this.saturation.onValueChanged=g=>t.saturation=g,[t,e]}}Gy([D(Fe)],Va.prototype,"postExposure",2);Gy([D(Fe)],Va.prototype,"contrast",2);Gy([D(Fe)],Va.prototype,"hueShift",2);Gy([D(Fe)],Va.prototype,"saturation",2);Zo("ColorAdjustments",Va);const GgA=(Math.sqrt(5)-1)/4,Bg=(5-Math.sqrt(5))/20,up=i=>Math.floor(i)|0,pp=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 mgA(i=Math.random){const A=MgA(i),e=new Float64Array(A).map(o=>pp[o%32*4]),t=new Float64Array(A).map(o=>pp[o%32*4+1]),g=new Float64Array(A).map(o=>pp[o%32*4+2]),I=new Float64Array(A).map(o=>pp[o%32*4+3]);return function(s,C,n,a){let B,Q,E,c,l;const d=(s+C+n+a)*GgA,h=up(s+d),p=up(C+d),u=up(n+d),f=up(a+d),S=(h+p+u+f)*Bg,G=h-S,M=p-S,R=u-S,k=f-S,m=s-G,K=C-M,Z=n-R,H=a-k;let _=0,j=0,x=0,v=0;m>K?_++:j++,m>Z?_++:x++,m>H?_++:v++,K>Z?j++:x++,K>H?j++:v++,Z>H?x++:v++;const Y=_>=3?1:0,eA=j>=3?1:0,AA=x>=3?1:0,W=v>=3?1:0,gA=_>=2?1:0,fA=j>=2?1:0,uA=x>=2?1:0,MA=v>=2?1:0,RA=_>=1?1:0,HA=j>=1?1:0,PA=x>=1?1:0,Qe=v>=1?1:0,Ge=m-Y+Bg,oe=K-eA+Bg,P=Z-AA+Bg,xA=H-W+Bg,pA=m-gA+2*Bg,LA=K-fA+2*Bg,mA=Z-uA+2*Bg,ge=H-MA+2*Bg,zA=m-RA+3*Bg,ZA=K-HA+3*Bg,de=Z-PA+3*Bg,me=H-Qe+3*Bg,$e=m-1+4*Bg,T=K-1+4*Bg,q=Z-1+4*Bg,EA=H-1+4*Bg,KA=h&255,JA=p&255,TA=u&255,V=f&255;let hA=.6-m*m-K*K-Z*Z-H*H;if(hA<0)B=0;else{const bA=KA+A[JA+A[TA+A[V]]];hA*=hA,B=hA*hA*(e[bA]*m+t[bA]*K+g[bA]*Z+I[bA]*H)}let rA=.6-Ge*Ge-oe*oe-P*P-xA*xA;if(rA<0)Q=0;else{const bA=KA+Y+A[JA+eA+A[TA+AA+A[V+W]]];rA*=rA,Q=rA*rA*(e[bA]*Ge+t[bA]*oe+g[bA]*P+I[bA]*xA)}let VA=.6-pA*pA-LA*LA-mA*mA-ge*ge;if(VA<0)E=0;else{const bA=KA+gA+A[JA+fA+A[TA+uA+A[V+MA]]];VA*=VA,E=VA*VA*(e[bA]*pA+t[bA]*LA+g[bA]*mA+I[bA]*ge)}let jA=.6-zA*zA-ZA*ZA-de*de-me*me;if(jA<0)c=0;else{const bA=KA+RA+A[JA+HA+A[TA+PA+A[V+Qe]]];jA*=jA,c=jA*jA*(e[bA]*zA+t[bA]*ZA+g[bA]*de+I[bA]*me)}let OA=.6-$e*$e-T*T-q*q-EA*EA;if(OA<0)l=0;else{const bA=KA+1+A[JA+1+A[TA+1+A[V+1]]];OA*=OA,l=OA*OA*(e[bA]*$e+t[bA]*T+g[bA]*q+I[bA]*EA)}return 27*(B+Q+E+c+l)}}function MgA(i){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const g=t+~~(i()*(256-t)),I=e[t];e[t]=e[g],e[g]=I}for(let t=256;t<512;t++)e[t]=e[t-256];return e}var RgA=Object.defineProperty,UgA=Object.getOwnPropertyDescriptor,oA=(i,A,e,t)=>{for(var g=t>1?void 0:t?UgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&RgA(A,e,g),g};const fp=sA("debugparticles");var TC=(i=>(i[i.Billboard=0]="Billboard",i[i.Stretch=1]="Stretch",i[i.HorizontalBillboard=2]="HorizontalBillboard",i[i.VerticalBillboard=3]="VerticalBillboard",i[i.Mesh=4]="Mesh",i))(TC||{});let za=class{constructor(){r(this,"alphaKeys");r(this,"colorKeys")}get duration(){return 1}evaluate(A,e){let t,g=0,I=null,o=0;for(let s=0;s<this.alphaKeys.length;s++){const C=this.alphaKeys[s];(C.time<A||!t)&&(t=C,g=s)}for(let s=0;s<this.colorKeys.length;s++){const C=this.colorKeys[s];(C.time<A||!I)&&(I=C,o=s)}if(I)if(o+1<this.colorKeys.length){const C=this.colorKeys[o+1],n=ie.remap(A,I.time,C.time,0,1);e.r=ie.lerp(I.color.r,C.color.r,n),e.g=ie.lerp(I.color.g,C.color.g,n),e.b=ie.lerp(I.color.b,C.color.b,n)}else e.r=I.color.r,e.g=I.color.g,e.b=I.color.b;if(t)if(g+1<this.alphaKeys.length){const C=this.alphaKeys[g+1],n=ie.remap(A,t.time,C.time,0,1);e.alpha=ie.lerp(t.alpha,C.alpha,n)}else e.alpha=t.alpha;return e}};oA([D()],za.prototype,"alphaKeys",2);oA([D()],za.prototype,"colorKeys",2);var Ml=(i=>(i[i.Local=0]="Local",i[i.World=1]="World",i[i.Custom=2]="Custom",i))(Ml||{}),w2=(i=>(i[i.Sphere=0]="Sphere",i[i.SphereShell=1]="SphereShell",i[i.Hemisphere=2]="Hemisphere",i[i.HemisphereShell=3]="HemisphereShell",i[i.Cone=4]="Cone",i[i.Box=5]="Box",i[i.Mesh=6]="Mesh",i[i.ConeShell=7]="ConeShell",i[i.ConeVolume=8]="ConeVolume",i[i.ConeVolumeShell=9]="ConeVolumeShell",i[i.Circle=10]="Circle",i[i.CircleEdge=11]="CircleEdge",i[i.SingleSidedEdge=12]="SingleSidedEdge",i[i.MeshRenderer=13]="MeshRenderer",i[i.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",i[i.BoxShell=15]="BoxShell",i[i.BoxEdge=16]="BoxEdge",i[i.Donut=17]="Donut",i[i.Rectangle=18]="Rectangle",i[i.Sprite=19]="Sprite",i[i.SpriteRenderer=20]="SpriteRenderer",i))(w2||{});class Be{constructor(){r(this,"mode");r(this,"constant");r(this,"constantMin");r(this,"constantMax");r(this,"curve");r(this,"curveMin");r(this,"curveMax");r(this,"curveMultiplier")}evaluate(A,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.constant;case 1:return A=ie.clamp01(A),this.curve.evaluate(A)*this.curveMultiplier;case 2:const g=A*this.curveMin.duration,I=A*this.curveMax.duration;return ie.lerp(this.curveMin.evaluate(g),this.curveMax.evaluate(I),t%1)*this.curveMultiplier;case 3:return ie.lerp(this.constantMin,this.constantMax,t%1);default:this.curveMax.evaluate(A)*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(A){if(!A)return 0;let e=Number.MIN_VALUE;for(let t=0;t<A.keys.length;t++){const g=A.keys[t];g.value>e&&(e=g.value)}return e}}oA([D()],Be.prototype,"mode",2);oA([D()],Be.prototype,"constant",2);oA([D()],Be.prototype,"constantMin",2);oA([D()],Be.prototype,"constantMax",2);oA([D(rB)],Be.prototype,"curve",2);oA([D(rB)],Be.prototype,"curveMin",2);oA([D(rB)],Be.prototype,"curveMax",2);oA([D()],Be.prototype,"curveMultiplier",2);var xp;const Cs=(xp=class{constructor(){r(this,"mode");r(this,"color");r(this,"colorMin");r(this,"colorMax");r(this,"gradient");r(this,"gradientMin");r(this,"gradientMax")}evaluate(i,A){const e=A===void 0?Math.random():A;switch(this.mode){case 0:return this.color;case 1:return this.gradient.evaluate(i,Cs._temp),Cs._temp;case 2:return Cs._temp.lerpColors(this.colorMin,this.colorMax,e);case 3:return this.gradientMin.evaluate(i,Cs._temp),this.gradientMax.evaluate(i,Cs._temp2),Cs._temp.lerp(Cs._temp2,e)}return Cs._temp.set(16711935),Cs._temp.alpha=1,Cs._temp}},r(xp,"_temp",new St(0,0,0,1)),r(xp,"_temp2",new St(0,0,0,1)),xp);let TI=Cs;oA([D(St)],TI.prototype,"color",2);oA([D(St)],TI.prototype,"colorMin",2);oA([D(St)],TI.prototype,"colorMax",2);oA([D(za)],TI.prototype,"gradient",2);oA([D(za)],TI.prototype,"gradientMin",2);oA([D(za)],TI.prototype,"gradientMax",2);var Nm=(i=>(i[i.Hierarchy=0]="Hierarchy",i[i.Local=1]="Local",i[i.Shape=2]="Shape",i))(Nm||{});class Ug{constructor(){r(this,"cullingMode");r(this,"duration");r(this,"emitterVelocityMode");r(this,"flipRotation");r(this,"gravityModifier");r(this,"gravityModifierMultiplier");r(this,"loop");r(this,"maxParticles");r(this,"playOnAwake");r(this,"prewarm");r(this,"ringBufferLoopRange");r(this,"ringBufferMode");r(this,"scalingMode");r(this,"simulationSpace");r(this,"simulationSpeed");r(this,"startColor");r(this,"startDelay");r(this,"startDelayMultiplier");r(this,"startLifetime");r(this,"startLifetimeMultiplier");r(this,"startRotation");r(this,"startRotationMultiplier");r(this,"startRotation3D");r(this,"startRotationX");r(this,"startRotationXMultiplier");r(this,"startRotationY");r(this,"startRotationYMultiplier");r(this,"startRotationZ");r(this,"startRotationZMultiplier");r(this,"startSize");r(this,"startSize3D");r(this,"startSizeMultiplier");r(this,"startSizeX");r(this,"startSizeXMultiplier");r(this,"startSizeY");r(this,"startSizeYMultiplier");r(this,"startSizeZ");r(this,"startSizeZMultiplier");r(this,"startSpeed");r(this,"startSpeedMultiplier");r(this,"stopAction");r(this,"useUnscaledTime")}}oA([D(Be)],Ug.prototype,"gravityModifier",2);oA([D(TI)],Ug.prototype,"startColor",2);oA([D(Be)],Ug.prototype,"startDelay",2);oA([D(Be)],Ug.prototype,"startLifetime",2);oA([D(Be)],Ug.prototype,"startRotation",2);oA([D(Be)],Ug.prototype,"startRotationX",2);oA([D(Be)],Ug.prototype,"startRotationY",2);oA([D(Be)],Ug.prototype,"startRotationZ",2);oA([D(Be)],Ug.prototype,"startSize",2);oA([D(Be)],Ug.prototype,"startSizeX",2);oA([D(Be)],Ug.prototype,"startSizeY",2);oA([D(Be)],Ug.prototype,"startSizeZ",2);oA([D(Be)],Ug.prototype,"startSpeed",2);class Rl{constructor(){r(this,"cycleCount");r(this,"maxCount");r(this,"minCount");r(this,"probability");r(this,"repeatInterval");r(this,"time");r(this,"count");r(this,"_performed",0)}reset(){this._performed=0}run(A){if(A<=this.time)return 0;let e=0;if(this.cycleCount===0||this._performed<this.cycleCount){const t=this.time+this.repeatInterval*this._performed;if(A>=t&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:e=this.count.constant;break;case 3:e=ie.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:e=this.count.curve.evaluate(Math.random());break;case 2:const g=Math.random();e=ie.lerp(this.count.curveMin.evaluate(g),this.count.curveMax.evaluate(g),Math.random());break}}return e}}class EC{constructor(){r(this,"enabled");r(this,"bursts");r(this,"rateOverTime");r(this,"rateOverTimeMultiplier");r(this,"rateOverDistance");r(this,"rateOverDistanceMultiplier");r(this,"system")}get burstCount(){var A;return((A=this.bursts)==null?void 0:A.length)??0}reset(){var A;(A=this.bursts)==null||A.forEach(e=>e.reset())}getBurst(){let A=0;if(this.burstCount>0)for(let e=0;e<this.burstCount;e++){const t=this.bursts[e];this.system.main.loop&&t.time>=this.system.time&&t.reset(),A+=Math.round(t.run(this.system.time))}return A}}oA([D()],EC.prototype,"enabled",2);oA([D()],EC.prototype,"bursts",2);oA([D(Be)],EC.prototype,"rateOverTime",2);oA([D()],EC.prototype,"rateOverTimeMultiplier",2);oA([D(Be)],EC.prototype,"rateOverDistance",2);oA([D()],EC.prototype,"rateOverDistanceMultiplier",2);class bd{constructor(){r(this,"enabled");r(this,"color")}}oA([D(TI)],bd.prototype,"color",2);class ja{constructor(){r(this,"enabled");r(this,"separateAxes");r(this,"size");r(this,"sizeMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier");r(this,"_time",0);r(this,"_temp",new w)}evaluate(A,e,t){if(e||(e=this._temp),!this.enabled)return e.x=e.y=e.z=1,e;if(this.separateAxes)e.x=this.x.evaluate(A,t)*this.xMultiplier,e.y=this.y.evaluate(A,t)*this.yMultiplier,e.z=this.z.evaluate(A,t)*this.zMultiplier;else{const g=this.size.evaluate(A,t)*this.sizeMultiplier;e.x=g}return e}}oA([D(Be)],ja.prototype,"size",2);oA([D(Be)],ja.prototype,"x",2);oA([D(Be)],ja.prototype,"y",2);oA([D(Be)],ja.prototype,"z",2);var Tp;const nh=(Tp=class{constructor(){r(this,"shapeType",5);r(this,"enabled",!0);r(this,"alignToDirection",!1);r(this,"angle",0);r(this,"arc",360);r(this,"arcSpread");r(this,"arcSpeedMultiplier");r(this,"arcMode");r(this,"boxThickness");r(this,"position");r(this,"rotation");r(this,"_rotation",new yi);r(this,"scale");r(this,"radius");r(this,"radiusThickness");r(this,"sphericalDirectionAmount");r(this,"randomDirectionAmount");r(this,"randomPositionAmount");r(this,"system");r(this,"_space");r(this,"_worldSpaceMatrix",new UA);r(this,"_worldSpaceMatrixInverse",new UA);r(this,"_vector",new w(0,0,0));r(this,"_temp",new w(0,0,0));r(this,"_dir",new w);r(this,"_loopTime",0);r(this,"_loopDirection",1);fp&&console.log(this)}get type(){return w2[this.shapeType]}initialize(i){this.getPosition(),i.position.copy(this._vector)}toJSON(){return this}clone(){return new nh}update(i,A,e,t){this.system=i,this._space=e,e===1&&(this._worldSpaceMatrix.copy(t.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(i){const A=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return A&&(this._rotation.x=ie.toRadians(this.rotation.x),this._rotation.y=ie.toRadians(this.rotation.y),this._rotation.z=ie.toRadians(this.rotation.z),this._rotation.order="ZYX",i.applyEuler(this._rotation)),A}get vector(){return this._vector}getPosition(){this._vector.set(0,0,0);const i=this._temp.copy(this.position),A=this._space===1;A&&i.applyQuaternion(this.system.worldQuaternion);let e=this.radius;if(A&&(e*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:fp&&An.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(i);break;case 4:this.randomConePoint(this.position,this.angle,e,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,e,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,e,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),A&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),fp&&An.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(i){var A;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 e=i.x,t=i.y,g=i.z;this._dir.set(e,t,g),(A=this.system)!=null&&A.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),fp&&(An.DrawSphere(i,.01,8925952,.5,!0),An.DrawDirection(i,this._dir,8925952,.5,!0)),this._dir}randomizePosition(i,A){if(A<=0)return;const e=nh._tempVec;e.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),e.x*=A*this.scale.x,e.y*=A*this.scale.y,e.z*=A*this.scale.z,i.add(e)}randomizeDirection(i,A){if(A===0)return;const e=nh._randomQuat,t=nh._tempVec;t.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),e.setFromAxisAngle(t,A*Math.random()*Math.PI),i.applyQuaternion(e)}spherizeDirection(i,A){if(A===0)return;const e=Math.random()*Math.PI*2,t=Math.acos(1-Math.random()*2),g=Math.sin(t)*Math.cos(e),I=Math.sin(t)*Math.sin(e),o=Math.cos(t),s=new w(g,I,o);i.lerp(s,A)}randomSpherePoint(i,A,e,t,g){const I=Math.random(),o=Math.random(),s=2*Math.PI*I*(t/360),C=Math.acos(2*o-1),n=ie.lerp(1,1-Math.pow(1-Math.random(),Math.PI),e)*A,a=i.x+this.scale.x*(-n*Math.sin(C)*Math.cos(s)),B=i.y+this.scale.y*(n*Math.sin(C)*Math.sin(s)),Q=i.z+this.scale.z*(n*Math.cos(C));g.x=a,g.y=B,g.z=Q}randomCirclePoint(i,A,e,t,g){const I=Math.random(),o=2*Math.PI*I*(t/360),s=ie.lerp(1,1-Math.pow(1-Math.random(),Math.PI),e)*A,C=i.x+this.scale.x*s*Math.cos(o),n=i.y+this.scale.y*s*Math.sin(o),a=i.z;g.x=C,g.y=n,g.z=a}randomConePoint(i,A,e,t,g,I,o){let s=0,C=0;switch(I){case 0:s=Math.random(),C=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:s=.5,C=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let n=2*Math.PI*s*(g/360);switch(I){case 2:case 1:n+=Math.PI+.5,n+=this._loopTime*Math.PI*2,n%=ie.toRadians(g);break}const a=Math.acos(2*C-1),B=ie.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,Q=i.x+-B*Math.sin(a)*Math.cos(n),E=i.y+B*Math.sin(a)*Math.sin(n),c=i.z;o.x=Q*this.scale.x,o.y=E*this.scale.y,o.z=c*this.scale.z}},r(Tp,"_randomQuat",new GA),r(Tp,"_tempVec",new w),Tp);let mi=nh;oA([D()],mi.prototype,"shapeType",2);oA([D()],mi.prototype,"enabled",2);oA([D()],mi.prototype,"alignToDirection",2);oA([D()],mi.prototype,"angle",2);oA([D()],mi.prototype,"arc",2);oA([D()],mi.prototype,"arcSpread",2);oA([D()],mi.prototype,"arcSpeedMultiplier",2);oA([D()],mi.prototype,"arcMode",2);oA([D(w)],mi.prototype,"boxThickness",2);oA([D(w)],mi.prototype,"position",2);oA([D(w)],mi.prototype,"rotation",2);oA([D(w)],mi.prototype,"scale",2);oA([D()],mi.prototype,"radius",2);oA([D()],mi.prototype,"radiusThickness",2);oA([D()],mi.prototype,"sphericalDirectionAmount",2);oA([D()],mi.prototype,"randomDirectionAmount",2);oA([D()],mi.prototype,"randomPositionAmount",2);class wt{constructor(){r(this,"damping");r(this,"enabled");r(this,"frequency");r(this,"octaveCount");r(this,"octaveMultiplier");r(this,"octaveScale");r(this,"positionAmount");r(this,"quality");r(this,"remap");r(this,"remapEnabled");r(this,"remapMultiplier");r(this,"remapX");r(this,"remapXMultiplier");r(this,"remapY");r(this,"remapYMultiplier");r(this,"remapZ");r(this,"remapZMultiplier");r(this,"scrollSpeedMultiplier");r(this,"separateAxes");r(this,"strengthMultiplier");r(this,"strengthX");r(this,"strengthXMultiplier");r(this,"strengthY");r(this,"strengthYMultiplier");r(this,"strengthZ");r(this,"strengthZMultiplier");r(this,"_noise");r(this,"_time",0);r(this,"_temp",new w)}update(A){this._time+=A.time.deltaTime*this.scrollSpeedMultiplier}apply(A,e,t,g,I,o){if(!this.enabled)return;this._noise||(this._noise=mgA(()=>0));const s=this._temp.set(e.x,e.y,e.z).multiplyScalar(this.frequency),C=this._noise(s.x,s.y,s.z,this._time),n=this._noise(s.x,s.y,s.z,this._time+1e3*this.frequency),a=this._noise(s.x,s.y,s.z,this._time+2e3*this.frequency);this._temp.set(C,n,a).normalize();const B=I/o;let Q=this.positionAmount.evaluate(B);this.separateAxes?(this._temp.x*=Q*this.strengthXMultiplier,this._temp.y*=Q*this.strengthYMultiplier,this._temp.z*=Q*this.strengthZMultiplier):(this.strengthX&&(Q*=this.strengthX.evaluate(B)*1.5),this._temp.multiplyScalar(Q)),t.x+=this._temp.x,t.y+=this._temp.y,t.z+=this._temp.z}}oA([D()],wt.prototype,"damping",2);oA([D()],wt.prototype,"enabled",2);oA([D()],wt.prototype,"frequency",2);oA([D()],wt.prototype,"octaveCount",2);oA([D()],wt.prototype,"octaveMultiplier",2);oA([D()],wt.prototype,"octaveScale",2);oA([D(Be)],wt.prototype,"positionAmount",2);oA([D()],wt.prototype,"quality",2);oA([D(Be)],wt.prototype,"remap",2);oA([D()],wt.prototype,"remapEnabled",2);oA([D()],wt.prototype,"remapMultiplier",2);oA([D(Be)],wt.prototype,"remapX",2);oA([D()],wt.prototype,"remapXMultiplier",2);oA([D(Be)],wt.prototype,"remapY",2);oA([D()],wt.prototype,"remapYMultiplier",2);oA([D(Be)],wt.prototype,"remapZ",2);oA([D()],wt.prototype,"remapZMultiplier",2);oA([D()],wt.prototype,"scrollSpeedMultiplier",2);oA([D()],wt.prototype,"separateAxes",2);oA([D()],wt.prototype,"strengthMultiplier",2);oA([D(Be)],wt.prototype,"strengthX",2);oA([D()],wt.prototype,"strengthXMultiplier",2);oA([D(Be)],wt.prototype,"strengthY",2);oA([D()],wt.prototype,"strengthYMultiplier",2);oA([D(Be)],wt.prototype,"strengthZ",2);oA([D()],wt.prototype,"strengthZMultiplier",2);class Xt{constructor(){r(this,"enabled");r(this,"attachRibbonToTransform",!1);r(this,"colorOverLifetime");r(this,"colorOverTrail");r(this,"dieWithParticles",!0);r(this,"inheritParticleColor",!0);r(this,"lifetime");r(this,"lifetimeMultiplier");r(this,"minVertexDistance",.2);r(this,"mode",0);r(this,"ratio",1);r(this,"ribbonCount",1);r(this,"shadowBias",0);r(this,"sizeAffectsLifetime",!1);r(this,"sizeAffectsWidth",!1);r(this,"splitSubEmitterRibbons",!1);r(this,"textureMode",0);r(this,"widthOverTrail");r(this,"widthOverTrailMultiplier");r(this,"worldSpace",!1)}getWidth(A,e,t,g){const I=this.widthOverTrail.evaluate(t,g);return A*=I,A}getColor(A,e,t){const g=this.colorOverTrail.evaluate(t),I=this.colorOverLifetime.evaluate(e);A.x*=g.r*I.r,A.y*=g.g*I.g,A.z*=g.b*I.b,A.w*=g.alpha*I.alpha}}oA([D()],Xt.prototype,"enabled",2);oA([D()],Xt.prototype,"attachRibbonToTransform",2);oA([D(TI)],Xt.prototype,"colorOverLifetime",2);oA([D(TI)],Xt.prototype,"colorOverTrail",2);oA([D()],Xt.prototype,"dieWithParticles",2);oA([D()],Xt.prototype,"inheritParticleColor",2);oA([D(Be)],Xt.prototype,"lifetime",2);oA([D()],Xt.prototype,"lifetimeMultiplier",2);oA([D()],Xt.prototype,"minVertexDistance",2);oA([D()],Xt.prototype,"mode",2);oA([D()],Xt.prototype,"ratio",2);oA([D()],Xt.prototype,"ribbonCount",2);oA([D()],Xt.prototype,"shadowBias",2);oA([D()],Xt.prototype,"sizeAffectsLifetime",2);oA([D()],Xt.prototype,"sizeAffectsWidth",2);oA([D()],Xt.prototype,"splitSubEmitterRibbons",2);oA([D()],Xt.prototype,"textureMode",2);oA([D(Be)],Xt.prototype,"widthOverTrail",2);oA([D()],Xt.prototype,"widthOverTrailMultiplier",2);oA([D()],Xt.prototype,"worldSpace",2);class gi{constructor(){r(this,"enabled");r(this,"space",0);r(this,"orbitalX");r(this,"orbitalY");r(this,"orbitalZ");r(this,"orbitalXMultiplier");r(this,"orbitalYMultiplier");r(this,"orbitalZMultiplier");r(this,"orbitalOffsetX");r(this,"orbitalOffsetY");r(this,"orbitalOffsetZ");r(this,"speedModifier");r(this,"speedModifierMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier");r(this,"_system");r(this,"_temp",new w);r(this,"_temp2",new w);r(this,"_temp3",new w);r(this,"_hasOrbital",!1);r(this,"_index",0);r(this,"_orbitalMatrix",new UA)}update(A){this._system=A}init(A){this._index==0&&(A.debug=!0),this._index+=1,A.orbitx=this.orbitalX.evaluate(Math.random()),A.orbity=this.orbitalY.evaluate(Math.random()),A.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=A.orbitx!=0||A.orbity!=0||A.orbitz!=0}apply(A,e,t,g,I,o,s){var E;if(!this.enabled)return;const C=o/s,n=this.speedModifier.evaluate(C)*this.speedModifierMultiplier,a=this.x.evaluate(C),B=this.y.evaluate(C),Q=this.z.evaluate(C);if(this._temp.set(-a,B,Q),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((E=this._system)==null?void 0:E.worldPos)){const l=this._temp2.set(t.x,t.y,t.z),d=this.orbitalXMultiplier,h=this.orbitalYMultiplier,p=this.orbitalZMultiplier,u=n*Math.PI*2*10,f=Math.cos(u*d),S=Math.sin(u*d),G=Math.cos(u*h),M=Math.sin(u*h),R=Math.cos(u*p),k=Math.sin(u*p),m=l.x*(G*R)+l.y*(G*k)+l.z*-M,K=l.x*(S*M*R-f*k)+l.y*(S*M*k+f*R)+l.z*(S*G),Z=l.x*(f*M*R+S*k)+l.y*(f*M*k-S*R)+l.z*(f*G),H=this._temp3.set(l.x-m,l.y-K,l.z-Z);H.normalize(),H.multiplyScalar(.2/I*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),g.x+=H.x,g.y+=H.y,g.z+=H.z}g.x+=this._temp.x,g.y+=this._temp.y,g.z+=this._temp.z,g.x*=n,g.y*=n,g.z*=n}}oA([D()],gi.prototype,"enabled",2);oA([D()],gi.prototype,"space",2);oA([D(Be)],gi.prototype,"orbitalX",2);oA([D(Be)],gi.prototype,"orbitalY",2);oA([D(Be)],gi.prototype,"orbitalZ",2);oA([D()],gi.prototype,"orbitalXMultiplier",2);oA([D()],gi.prototype,"orbitalYMultiplier",2);oA([D()],gi.prototype,"orbitalZMultiplier",2);oA([D()],gi.prototype,"orbitalOffsetX",2);oA([D()],gi.prototype,"orbitalOffsetY",2);oA([D()],gi.prototype,"orbitalOffsetZ",2);oA([D(Be)],gi.prototype,"speedModifier",2);oA([D()],gi.prototype,"speedModifierMultiplier",2);oA([D(Be)],gi.prototype,"x",2);oA([D()],gi.prototype,"xMultiplier",2);oA([D(Be)],gi.prototype,"y",2);oA([D()],gi.prototype,"yMultiplier",2);oA([D(Be)],gi.prototype,"z",2);oA([D()],gi.prototype,"zMultiplier",2);class Fg{constructor(){r(this,"animation");r(this,"enabled");r(this,"cycleCount");r(this,"frameOverTime");r(this,"frameOverTimeMultiplier");r(this,"numTilesX");r(this,"numTilesY");r(this,"startFrame");r(this,"startFrameMultiplier");r(this,"rowMode");r(this,"rowIndex");r(this,"spriteCount");r(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(A){if(!this.sampleOnceAtStart())return this.getIndex(A)}getIndex(A){const e=this.numTilesX*this.numTilesY;A=A*this.cycleCount;let t=this.frameOverTime.evaluate(A%1);return t*=this.frameOverTimeMultiplier,t*=e,t=t%e,t=Math.floor(t),t}}oA([D()],Fg.prototype,"animation",2);oA([D()],Fg.prototype,"enabled",2);oA([D()],Fg.prototype,"cycleCount",2);oA([D(Be)],Fg.prototype,"frameOverTime",2);oA([D()],Fg.prototype,"frameOverTimeMultiplier",2);oA([D()],Fg.prototype,"numTilesX",2);oA([D()],Fg.prototype,"numTilesY",2);oA([D(Be)],Fg.prototype,"startFrame",2);oA([D()],Fg.prototype,"startFrameMultiplier",2);oA([D()],Fg.prototype,"rowMode",2);oA([D()],Fg.prototype,"rowIndex",2);oA([D()],Fg.prototype,"spriteCount",2);oA([D()],Fg.prototype,"timeMode",2);class Xo{constructor(){r(this,"enabled");r(this,"separateAxes");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(A,e){return this.enabled?this.separateAxes?0:this.z.evaluate(A,e)*-1:0}}oA([D()],Xo.prototype,"enabled",2);oA([D()],Xo.prototype,"separateAxes",2);oA([D(Be)],Xo.prototype,"x",2);oA([D()],Xo.prototype,"xMultiplier",2);oA([D(Be)],Xo.prototype,"y",2);oA([D()],Xo.prototype,"yMultiplier",2);oA([D(Be)],Xo.prototype,"z",2);oA([D()],Xo.prototype,"zMultiplier",2);class ho{constructor(){r(this,"enabled");r(this,"range");r(this,"separateAxes");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(A,e){if(!this.enabled)return 0;if(!this.separateAxes){const t=ie.lerp(this.range.x,this.range.y,e);return this.z.evaluate(t)*-1}return 0}}oA([D()],ho.prototype,"enabled",2);oA([D()],ho.prototype,"range",2);oA([D()],ho.prototype,"separateAxes",2);oA([D(Be)],ho.prototype,"x",2);oA([D()],ho.prototype,"xMultiplier",2);oA([D(Be)],ho.prototype,"y",2);oA([D()],ho.prototype,"yMultiplier",2);oA([D(Be)],ho.prototype,"z",2);oA([D()],ho.prototype,"zMultiplier",2);class Hi{constructor(){r(this,"enabled");r(this,"dampen");r(this,"drag");r(this,"dragMultiplier");r(this,"limit");r(this,"limitMultiplier");r(this,"separateAxes");r(this,"limitX");r(this,"limitXMultiplier");r(this,"limitY");r(this,"limitYMultiplier");r(this,"limitZ");r(this,"limitZMultiplier");r(this,"multiplyDragByParticleSize",!1);r(this,"multiplyDragByParticleVelocity",!1);r(this,"space");r(this,"_temp",new w);r(this,"_temp2",new w)}apply(A,e,t,g,I,o,s){if(this.enabled){const C=this.limit.evaluate(I)*this.limitMultiplier;if(e.length()>C){this._temp.copy(e).normalize().multiplyScalar(C);const a=this.dampen*.5;e.x=ie.lerp(e.x,this._temp.x,a),e.y=ie.lerp(e.y,this._temp.y,a),e.z=ie.lerp(e.z,this._temp.z,a),t.x=ie.lerp(t.x,this._temp.x,a),t.y=ie.lerp(t.y,this._temp.y,a),t.z=ie.lerp(t.z,this._temp.z,a)}}}}oA([D()],Hi.prototype,"enabled",2);oA([D()],Hi.prototype,"dampen",2);oA([D(Be)],Hi.prototype,"drag",2);oA([D()],Hi.prototype,"dragMultiplier",2);oA([D(Be)],Hi.prototype,"limit",2);oA([D()],Hi.prototype,"limitMultiplier",2);oA([D()],Hi.prototype,"separateAxes",2);oA([D(Be)],Hi.prototype,"limitX",2);oA([D()],Hi.prototype,"limitXMultiplier",2);oA([D(Be)],Hi.prototype,"limitY",2);oA([D()],Hi.prototype,"limitYMultiplier",2);oA([D(Be)],Hi.prototype,"limitZ",2);oA([D()],Hi.prototype,"limitZMultiplier",2);oA([D()],Hi.prototype,"multiplyDragByParticleSize",2);oA([D()],Hi.prototype,"multiplyDragByParticleVelocity",2);oA([D()],Hi.prototype,"space",2);class Za{constructor(){r(this,"enabled");r(this,"curve");r(this,"curveMultiplier");r(this,"mode");r(this,"system");r(this,"_lastWorldPosition");r(this,"_velocity",new w);r(this,"_temp",new w)}update(A){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(A){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const e=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(e),A.add(this._temp)}}applyCurrent(A,e,t){if(this.enabled&&this.system.worldspace!==!1&&this.mode===1){const g=this.curve.evaluate(e,t);this._temp.copy(this._velocity).multiplyScalar(g),A.add(this._temp)}}}oA([D()],Za.prototype,"enabled",2);oA([D(Be)],Za.prototype,"curve",2);oA([D()],Za.prototype,"curveMultiplier",2);oA([D()],Za.prototype,"mode",2);class uI{constructor(){r(this,"enabled");r(this,"range");r(this,"separateAxes");r(this,"size");r(this,"sizeMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(A,e,t,g){const I=A.length(),o=ie.remap(I,this.range.x,this.range.y,0,1),s=this.size.evaluate(o,t);return g*s}}oA([D()],uI.prototype,"enabled",2);oA([D(tA)],uI.prototype,"range",2);oA([D()],uI.prototype,"separateAxes",2);oA([D(Be)],uI.prototype,"size",2);oA([D()],uI.prototype,"sizeMultiplier",2);oA([D(Be)],uI.prototype,"x",2);oA([D()],uI.prototype,"xMultiplier",2);oA([D(Be)],uI.prototype,"y",2);oA([D()],uI.prototype,"yMultiplier",2);oA([D(Be)],uI.prototype,"z",2);oA([D()],uI.prototype,"zMultiplier",2);class pB{constructor(){r(this,"enabled");r(this,"range");r(this,"color")}evaluate(A,e,t){const g=A.length(),I=ie.remap(g,this.range.x,this.range.y,0,1),o=this.color.evaluate(I,e);t.x*=o.r,t.y*=o.g,t.z*=o.b,t.w*=o.alpha}}oA([D()],pB.prototype,"enabled",2);oA([D(tA)],pB.prototype,"range",2);oA([D(TI)],pB.prototype,"color",2);function Cv(i){const A=i.domElement.shadowRoot.querySelector("link[rel='ar']");if(A)return A;const e=document.createElement("div");e.classList.add("menu"),e.classList.add("quicklook-menu"),e.style.display="none",e.style.visibility="hidden";const t=document.createElement("button");t.id="open-in-ar",t.innerText="Open in QuickLook",e.appendChild(t);const g=document.createElement("a");g.id="needle-usdz-link",g.style.display="none",g.rel="ar",g.href="",e.appendChild(g);const I=document.createElement("img");return I.id="button",g.appendChild(I),i.domElement.shadowRoot.appendChild(e),g}function FgA(){var i=new Date;const A=i.getMonth()+1,e=i.getDate(),t=i.getHours(),g=i.getMinutes(),I=i.getSeconds(),o=(A<10?"0":"")+A,s=(e<10?"0":"")+e,C=(t<10?"0":"")+t,n=(g<10?"0":"")+g,a=(I<10?"0":"")+I;return i.getFullYear()+o+s+"-"+C+n+a}const Dp=sA("debugusdz");function NgA(i,A){const e=[],t=IA.getComponentsInChildren(i,Pg),g=IA.getComponentsInChildren(i,ro);let I=!1;const o=new rI("rest",.01,[]),s=new Map,C=(n,a)=>{if(!I&&a.tracks.length>0&&(I=!0,n.push(o)),a.tracks.length>0)for(const B of a.tracks){const Q=Te.parseTrackName(B.name),E=Te.findNode(i,Q.nodeName);if(E){s.has(E)||s.set(E,[]);const c=s.get(E);switch(Q.propertyName){case"position":{if(c.includes("position"))continue;const l=E.position,d=new JI(B.name,[0,.01],[l.x,l.y,l.z,l.x,l.y,l.z]);c.push("position"),o.tracks.push(d);break}case"quaternion":{if(c.includes("quaternion"))continue;const l=E.quaternion,d=new JI(B.name,[0,.01],[l.x,l.y,l.z,l.w,l.x,l.y,l.z,l.w]);c.push("quaternion"),o.tracks.push(d);break}case"scale":{if(c.includes("scale"))continue;const l=E.scale,d=new JI(B.name,[0,.01],[l.x,l.y,l.z,l.x,l.y,l.z]);c.push("scale"),o.tracks.push(d);break}}}}};for(const n of t){if(!n||!n.runtimeAnimatorController)continue;Dp&&console.log(n);const a=[];for(const B of n.runtimeAnimatorController.enumerateActions()){Dp&&console.log(B);const Q=B.getClip();C(a,Q),a.includes(Q)||a.push(Q)}e.push({root:n.gameObject,clips:a})}for(const n of g){Dp&&console.log(n);const a=[];for(const B of n.animations)C(a,B),a.includes(B)||a.push(B);e.push({root:n.gameObject,clips:a})}Dp&&(console.log("Rest Pose Clip",o),console.log("USDZ Animation Clips",e));for(const n of e)for(const a of n.clips)A.registerAnimation(n.root,a)}class KgA{static createButton(A,e={},t){const g=document.createElement("button");let I=!1;function o(){if(e.optionalFeatures=e.optionalFeatures||[],e.domOverlay===void 0){var a=document.createElement("div");a.style.display="none",document.body.appendChild(a);var B=document.createElementNS("http://www.w3.org/2000/svg","svg");B.setAttribute("width",38),B.setAttribute("height",38),B.style.position="absolute",B.style.right="20px",B.style.top="20px",B.addEventListener("click",function(){E.end()}),a.appendChild(B);var Q=document.createElementNS("http://www.w3.org/2000/svg","path");Q.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),Q.setAttribute("stroke","#fff"),Q.setAttribute("stroke-width",2),B.appendChild(Q),e.optionalFeatures.push("dom-overlay"),e.domOverlay={root:a},I=!0}let E=null,c=null;async function l(h){var f;const p=/WebXRViewer\//i.test(navigator.userAgent),u=e.domOverlay.root;p&&((f=e.domOverlay)!=null&&f.root?(c=u.parentNode,c&&(console.log("Reparent DOM Overlay to body",u,u.style.display),u.style.display="",u.style.visibility="",document.body.appendChild(u))):console.warn("WebXRViewer: No DOM Overlay found")),h.addEventListener("end",d),await A.xr.setSession(h),g.textContent="STOP AR",I&&(e.domOverlay.root.style.display=""),E=h}function d(){E.removeEventListener("end",d),g.textContent="START AR";const h=e.domOverlay.root;c&&c.appendChild(h),I&&(h.style.display="none"),E=null}g.style.display="",g.style.cursor="pointer",g.style.left="calc(50% - 50px)",g.style.width="100px",g.textContent="START AR",g.onmouseenter=function(){g.style.opacity="1.0"},g.onmouseleave=function(){g.style.opacity="0.5"},g.onclick=function(){E===null?(t==null||t.call(this,e),navigator.xr.requestSession("immersive-ar",e).then(l)):E.end()}}function s(){g.disabled=!0,g.style.display="",g.style.cursor="auto",g.style.left="calc(50% - 75px)",g.style.width="150px",g.onmouseenter=null,g.onmouseleave=null,g.onclick=null}function C(){s(),g.textContent="AR NOT SUPPORTED"}function n(a){a.style.position="absolute",a.style.bottom="20px",a.style.padding="12px 6px",a.style.border="1px solid #fff",a.style.borderRadius="4px",a.style.background="rgba(0,0,0,0.1)",a.style.color="#fff",a.style.font="normal 13px sans-serif",a.style.textAlign="center",a.style.opacity="0.5",a.style.outline="none",a.style.zIndex="999"}if("xr"in navigator)return g.id="ARButton",g.style.display="none",n(g),navigator.xr.isSessionSupported("immersive-ar").then(function(a){a?o():C()}).catch(C),g;{const a=document.createElement("a");return window.isSecureContext===!1?(a.href=document.location.href.replace(/^http:/,"https:"),a.innerHTML="WEBXR NEEDS HTTPS"):(a.href="https://immersiveweb.dev/",a.innerHTML="WEBXR NOT AVAILABLE"),a.style.left="calc(50% - 90px)",a.style.width="180px",a.style.textDecoration="none",n(a),a}}}const xD=class{static createButton(A,e){const t=document.createElement("button");function g(){let C=null;async function n(B){B.addEventListener("end",a),await A.xr.setSession(B),t.textContent="EXIT VR",C=B}function a(){C.removeEventListener("end",a),t.textContent="ENTER VR",C=null}t.style.display="",t.style.cursor="pointer",t.style.left="calc(50% - 50px)",t.style.width="100px",t.textContent="ENTER VR",t.onmouseenter=function(){t.style.opacity="1.0"},t.onmouseleave=function(){t.style.opacity="0.5"},t.onclick=function(){if(C===null){const B={optionalFeatures:e.optionalFeatures};navigator.xr.requestSession("immersive-vr",B).then(n)}else C.end()}}function I(){t.disabled=!0,t.style.display="",t.style.cursor="auto",t.style.left="calc(50% - 75px)",t.style.width="150px",t.onmouseenter=null,t.onmouseleave=null,t.onclick=null}function o(){I(),t.textContent="VR NOT SUPPORTED"}function s(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 t.id="VRButton",t.style.display="none",s(t),navigator.xr.isSessionSupported("immersive-vr").then(function(C){C?g():o(),xD.xrSessionIsGranted&&(console.log("XR session is granted - will enter immersive web now"),t.click())}),t;{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",s(C),C}}static registerSessionGrantedListener(){if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent))return;navigator.xr.addEventListener("sessiongranted",()=>{xD.xrSessionIsGranted=!0})}}};let Jh=xD;r(Jh,"xrSessionIsGranted",!1);Jh.registerSessionGrantedListener();var JgA=Object.defineProperty,qgA=Object.getOwnPropertyDescriptor,xU=(i,A,e,t)=>{for(var g=t>1?void 0:t?qgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&JgA(A,e,g),g};const vgA=new UA;class fs extends NA{constructor(){super(...arguments);r(this,"webAR",null);r(this,"invertForward",!1);r(this,"arTouchTransform",!1);r(this,"_initalMatrix",new UA);r(this,"_selectStartFn",this.onSelectStart.bind(this));r(this,"_selectEndFn",this.onSelectEnd.bind(this));r(this,"userInput");r(this,"_arScale",1);r(this,"_rig",null);r(this,"_startPose",null);r(this,"_placementPose",null);r(this,"_isTouching",!1);r(this,"_rigStartPose",null);r(this,"_gotFirstHitTestResult",!1);r(this,"_anchor",null);r(this,"_anchorMatrix",new UA);r(this,"_invertedSessionRootMatrix",new UA);r(this,"_invertForwardMatrix",new UA().makeRotationY(Math.PI))}get rig(){var e;return(e=this.webAR)==null?void 0:e.webxr.Rig}get arScale(){return this._arScale}set arScale(e){e!==this._arScale&&(this._arScale=e,this.setScale(e))}start(){const e=IA.findObjectOfType(Ue);e&&(e.Rig.updateMatrix(),this._initalMatrix.copy(e.Rig.matrix))}onBegin(e){var t;this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose=this.gameObject.matrix.clone(),this._rigStartPose=(t=this.rig)==null?void 0:t.matrix.clone(),this._gotFirstHitTestResult=!1,this._anchor=null,e.addEventListener("selectstart",this._selectStartFn),e.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(e,t,g,I){if(I&&!this._placementPose&&(this._gotFirstHitTestResult||(this._gotFirstHitTestResult=!0,this.dispatchEvent(new CustomEvent("canPlaceSession",{detail:{pose:I}}))),this._isTouching)){const o=new UA().fromArray(I.transform.matrix).invert();return this.dispatchEvent(new CustomEvent("placedSession",{detail:{pose:I,poseMatrix:o}})),this.webAR&&this.webAR.setReticleActive(!1),this.placeAt(e,o),g&&I&&this.onCreatePlacementAnchor(g,I),!0}return!1}onCreatePlacementAnchor(e,t){var g,I;this._anchor=null,(I=(g=e==null?void 0:e.createAnchor)==null?void 0:g.call(e,t.transform))==null||I.then(o=>{this.context.isInAR&&(this._anchor=o)})}onBeforeRender(e){if(e&&this._rig)if(this._anchor){const t=this.context.renderer.xr.getReferenceSpace();if(t){const g=e.getPose(this._anchor.anchorSpace,t);if(g){const I=this._anchorMatrix.fromArray(g.transform.matrix).invert();this.placeAt(this._rig,I);return}}}else this._placementPose&&this.placeAt(this._rig,this._placementPose)}placeAt(e,t){this._placementPose||(this._placementPose=new UA),this._placementPose.copy(t);const g=this._invertedSessionRootMatrix.copy(this.gameObject.matrixWorld).invert();this._placementPose.premultiply(g),e?(this.invertForward&&this._placementPose.premultiply(this._invertForwardMatrix),this.userInput||(this.userInput=new yQ(this.context)),this.userInput.enable(),this._rig=e,this.setScale(this.arScale)):this._rig=null,this.gameObject.visible=!0}onEnd(e,t){var g,I;(g=this.userInput)==null||g.disable(),(I=this.userInput)==null||I.reset(),this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._anchor=null,this._startPose&&this.gameObject.matrix.copy(this._startPose),e&&(e.matrixAutoUpdate=!0,this._rigStartPose&&this._rigStartPose.decompose(e.position,e.quaternion,e.scale)),qI.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(e){const t=this._rig;!t||!this._placementPose||(this._rigStartPose||(this._rigStartPose=t.matrix.clone()),t.matrixAutoUpdate=!1,this.arTouchTransform&&this.userInput&&this.userInput.applyMatrixTo(this._placementPose),t.matrix.multiplyMatrices(vgA.makeScale(e,e,e),this._placementPose),t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld())}}xU([D()],fs.prototype,"invertForward",2);xU([D()],fs.prototype,"arTouchTransform",2);xU([D()],fs.prototype,"arScale",1);const TD=class{constructor(A){r(this,"oneFingerDrag",!0);r(this,"twoFingerRotate",!0);r(this,"twoFingerScale",!0);r(this,"context");r(this,"offset");r(this,"plane");r(this,"_scale",1);r(this,"_enabled",!1);r(this,"prev",new Map);r(this,"_didMultitouch",!1);r(this,"touchStart",A=>{for(let e=0;e<A.changedTouches.length;e++){const t=A.changedTouches[e];this.prev.has(t.identifier)||this.prev.set(t.identifier,{x:0,z:0,screenx:0,screeny:0});const g=this.prev.get(t.identifier);if(g){const I=this.getPositionOnPlane(t.clientX,t.clientY);g.x=I.x,g.z=I.z,g.screenx=t.clientX,g.screeny=t.clientY}}});r(this,"touchEnd",A=>{A.touches.length<=0&&(this._didMultitouch=!1)});r(this,"touchMove",A=>{if(!A.defaultPrevented){if(A.touches.length===1){if(this._didMultitouch)return;const e=A.touches[0],t=this.prev.get(e.identifier);if(!t)return;const g=this.getPositionOnPlane(e.clientX,e.clientY),I=g.x-t.x,o=g.z-t.z;if(I===0&&o===0)return;this.oneFingerDrag&&this.addMovement(I,o),t.x=g.x,t.z=g.z,t.screenx=e.clientX,t.screeny=e.clientY;return}else if(A.touches.length===2){this._didMultitouch=!0;const e=A.touches[0],t=A.touches[1],g=this.prev.get(e.identifier),I=this.prev.get(t.identifier);if(!g||!I)return;if(this.twoFingerRotate){const o=Math.atan2(e.clientY-t.clientY,e.clientX-t.clientX),s=Math.atan2(g.screeny-I.screeny,g.screenx-I.screenx),C=o-s;Math.abs(C)>.001&&this.addRotation(C)}if(this.twoFingerScale){const o=e.clientX-t.clientX,s=e.clientY-t.clientY,C=Math.sqrt(o*o+s*s),n=g.screenx-I.screenx,a=g.screeny-I.screeny,B=Math.sqrt(n*n+a*a),Q=C-B;Math.abs(Q)>2&&this.addScale(Q)}g.screenx=e.clientX,g.screeny=e.clientY,I.screenx=t.clientX,I.screeny=t.clientY}}});r(this,"_raycaster",new nB);r(this,"_intersection",new w);r(this,"_screenPos",new w);r(this,"_tempMatrix",new UA);this.context=A,this.offset=new UA,this.plane=new to,this.plane.setFromNormalAndCoplanarPoint(TD.up,TD.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(A){A.premultiply(this.offset)}getPositionOnPlane(A,e){const t=this.context.mainCamera;return this._screenPos.x=A/window.innerWidth*2-1,this._screenPos.y=-(e/window.innerHeight)*2+1,this._screenPos.z=1,this._screenPos.unproject(t),this._raycaster.set(t.position,this._screenPos.sub(t.position)),this._raycaster.ray.intersectPlane(this.plane,this._intersection),this._intersection}addMovement(A,e){A*=.75,e*=.75,A/=this._scale,e/=this._scale,this.offset.elements[12]-=A,this.offset.elements[14]-=e}addScale(A){A/=window.innerWidth,this._scale*=1+A,this._tempMatrix.makeScale(1-A,1-A,1-A),this.offset.premultiply(this._tempMatrix)}addRotation(A){this._tempMatrix.makeRotationY(A),this.offset.premultiply(this._tempMatrix)}};let yQ=TD;r(yQ,"up",new w(0,1,0)),r(yQ,"zero",new w(0,0,0)),r(yQ,"one",new w(1,1,1));const bgA=sA("debugrig");class my extends NA{awake(){if(bgA){const A=new FA;A.position.y+=.5,this.gameObject.add(A);const e=A.addNewComponent(cB);e&&(e.isGizmo=!1)}}}class zQ{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}w(){return this.bb.readFloat32(this.bb_pos+12)}static sizeOf(){return 16}static createVec4(A,e,t,g,I){return A.prep(4,16),A.writeFloat32(I),A.writeFloat32(g),A.writeFloat32(t),A.writeFloat32(e),A.offset()}}class vg{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsVrUserStateBuffer(A,e){return(e||new vg).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsVrUserStateBuffer(A,e){return A.setPosition(A.position()+Jw),(e||new vg).__init(A.readInt32(A.position())+A.position(),A)}guid(A){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}time(){const A=this.bb.__offset(this.bb_pos,6);return A?this.bb.readInt64(this.bb_pos+A):this.bb.createLong(0,0)}avatarId(A){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,A):null}position(A){const e=this.bb.__offset(this.bb_pos,10);return e?(A||new ao).__init(this.bb_pos+e,this.bb):null}rotation(A){const e=this.bb.__offset(this.bb_pos,12);return e?(A||new zQ).__init(this.bb_pos+e,this.bb):null}scale(){const A=this.bb.__offset(this.bb_pos,14);return A?this.bb.readFloat32(this.bb_pos+A):0}posLeftHand(A){const e=this.bb.__offset(this.bb_pos,16);return e?(A||new ao).__init(this.bb_pos+e,this.bb):null}posRightHand(A){const e=this.bb.__offset(this.bb_pos,18);return e?(A||new ao).__init(this.bb_pos+e,this.bb):null}rotLeftHand(A){const e=this.bb.__offset(this.bb_pos,20);return e?(A||new zQ).__init(this.bb_pos+e,this.bb):null}rotRightHand(A){const e=this.bb.__offset(this.bb_pos,22);return e?(A||new zQ).__init(this.bb_pos+e,this.bb):null}static startVrUserStateBuffer(A){A.startObject(10)}static addGuid(A,e){A.addFieldOffset(0,e,0)}static addTime(A,e){A.addFieldInt64(1,e,A.createLong(0,0))}static addAvatarId(A,e){A.addFieldOffset(2,e,0)}static addPosition(A,e){A.addFieldStruct(3,e,0)}static addRotation(A,e){A.addFieldStruct(4,e,0)}static addScale(A,e){A.addFieldFloat32(5,e,0)}static addPosLeftHand(A,e){A.addFieldStruct(6,e,0)}static addPosRightHand(A,e){A.addFieldStruct(7,e,0)}static addRotLeftHand(A,e){A.addFieldStruct(8,e,0)}static addRotRightHand(A,e){A.addFieldStruct(9,e,0)}static endVrUserStateBuffer(A){return A.endObject()}static finishVrUserStateBufferBuffer(A,e){A.finish(e)}static finishSizePrefixedVrUserStateBufferBuffer(A,e){A.finish(e,void 0,!0)}}const nv=sA("debugxr"),xc=sA("debugavatar"),TU="VRUS";qw(TU,vg.getRootAsVrUserStateBuffer);function Km(){return new Date().getTime()}function LgA(i){const A=i&4294967295,e=i/Math.pow(2,32)&1048575;return $s.create(A,e)}const Wh=class{constructor(A){r(this,"guid");r(this,"time");r(this,"avatarId");r(this,"position",new w);r(this,"rotation",new te);r(this,"scale",1);r(this,"posLeftHand",new w);r(this,"posRightHand",new w);r(this,"rotLeftHand",new GA);r(this,"rotRightHand",new GA);this.guid=A}update(A,e,t,g,I){var a,B,Q,E,c,l;this.time=Km(),this.avatarId=I,this.position.set(e.x,e.y,e.z),A&&this.position.applyMatrix4(A.matrixWorld);let o=Wh.quat0;const s=Wh.quat1;o.set(t.x,t.y,t.z,t.w),o=o.multiplyQuaternions(o,Wh.invertRotation),A&&(A.getWorldQuaternion(s),o.multiplyQuaternions(s,o)),this.rotation.set(o.x,o.y,o.z,o.w),this.scale=A.scale.x;const C=(a=g.LeftController)==null?void 0:a.controllerGrip;C&&(C.getWorldPosition(this.posLeftHand),C.getWorldQuaternion(this.rotLeftHand));const n=(B=g.RightController)==null?void 0:B.controllerGrip;if(n&&(n.getWorldPosition(this.posRightHand),n.getWorldQuaternion(this.rotRightHand)),(E=(Q=g.LeftController)==null?void 0:Q.hand)!=null&&E.visible){const d=g.LeftController.wrist;d&&(d.getWorldPosition(this.posLeftHand),d.getWorldQuaternion(this.rotLeftHand))}if((l=(c=g.RightController)==null?void 0:c.hand)!=null&&l.visible){const d=g.RightController.wrist;d&&(d.getWorldPosition(this.posRightHand),d.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(A,e){A.clear();const t=A.createString(this.guid),g=A.createString(this.avatarId);vg.startVrUserStateBuffer(A),vg.addGuid(A,t),vg.addTime(A,LgA(this.time)),vg.addAvatarId(A,g),vg.addPosition(A,ao.createVec3(A,this.position.x,this.position.y,this.position.z)),vg.addRotation(A,zQ.createVec4(A,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),vg.addScale(A,this.scale),vg.addPosLeftHand(A,ao.createVec3(A,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),vg.addPosRightHand(A,ao.createVec3(A,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),vg.addRotLeftHand(A,zQ.createVec4(A,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),vg.addRotRightHand(A,zQ.createVec4(A,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const I=vg.endVrUserStateBuffer(A);A.finish(I,TU);const o=A.asUint8Array();e.sendBinary(o)}setFromBuffer(A,e){if(!A)return;this.guid=A,this.time=e.time().toFloat64();const t=e.avatarId();t&&(this.avatarId=t);const g=e.position();g&&this.position.set(g.x(),g.y(),g.z());const I=e.rotation();I&&this.rotation.set(I.x(),I.y(),I.z(),I.w());const o=e.posLeftHand();o&&this.posLeftHand.set(o.x(),o.y(),o.z());const s=e.posRightHand();s&&this.posRightHand.set(s.x(),s.y(),s.z());const C=e.rotLeftHand();C&&this.rotLeftHand.set(C.x(),C.y(),C.z(),C.w());const n=e.rotRightHand();n&&this.rotRightHand.set(n.x(),n.y(),n.z(),n.w()),this.scale=e.scale()}};let Es=Wh;r(Es,"invertRotation",new GA().setFromAxisAngle(new w(0,1,0),Math.PI)),r(Es,"quat0",new GA),r(Es,"quat1",new GA);class Ul extends NA{constructor(){super(...arguments);r(this,"webXR",null);r(this,"debugAvatarUser",null);r(this,"voip",null);r(this,"tempState",new Es(""));r(this,"_removeAvatarsList",[]);r(this,"eventSub_ConnectionEvent",null);r(this,"eventSub_WebXRStartEvent",null);r(this,"eventSub_WebXREndEvent",null);r(this,"eventSub_WebXRUpdateEvent",null);r(this,"avatars",{});r(this,"localAvatar",null);r(this,"k_LocalAvatarNoNetworkingGuid","local");r(this,"ownership",null);r(this,"xrState",null);r(this,"builder",new mE(1024))}async awake(){if(this.webXR||(this.webXR=IA.getComponent(this.gameObject,Ue)),this.webXR||(this.webXR=IA.findObjectOfType(Ue,this.context)),!this.webXR&&(this.webXR=IA.findObjectOfType(Ue,this.context),!this.webXR)){console.warn("WebXRSync: Could not find WebXR component, won't sync.");return}if(this.voip||(this.voip=IA.findObjectOfType(Rn,this.context)),xc){const e="debug-avatar-"+xc,t=new js(this.context,e,this.webXR);if(this.debugAvatarUser=t,typeof xc=="string"&&xc.length>0)if(await t.setAvatarOverride(xc)){const g=new Es(e);g.position.y+=1;const I=.5;g.posLeftHand.y+=I,g.posLeftHand.x+=I,g.posRightHand.y+=I,g.posRightHand.x-=I,t.tryUpdate(g,0)}else t.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=IA.getComponent(this.gameObject,Ue),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),Ue.addEventListener(Kt.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),Ue.addEventListener(Kt.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Ue.addEventListener(Kt.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen(Bi.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",e=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",e=>{const t=e.id!==null&&e.id!==void 0;if(t&&(console.log("webxr user left evt"),t)){const g=this.avatars[e.id];g==null||g.destroy(),this.avatars[e.id]=void 0}}),this.context.connection.beginListenBinary(TU,e=>{const t=e.guid();if(!t)return;const g=e.time().toFloat64(),I=this.tempState;I.setFromBuffer(t,e);const o=this.onTryGetAvatar(t,g);o==null||o.tryUpdate(I,g)}),this.context.connection.beginListen("vr-session-update",e=>{const t=e.guid,g=e.time,I=this.onTryGetAvatar(t,g);I==null||I.tryUpdate(e,g)})}onTryGetAvatar(e,t){if(e===this.context.connection.connectionId)return null;const g=new Date().getTime()-t;if(g>5e3)return nv&&console.log("old data",g,e),null;if(!this.webXR)return null;let I=this.avatars[e];if(I===void 0)try{console.log("create new avatar");const o=new js(this.context,e,this.webXR);I=o,this.avatars[e]=o}catch(o){this.avatars[e]=null,console.error(o)}return I}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen(Bi.JoinedRoom,this.eventSub_ConnectionEvent),Ue.removeEventListener(Kt.XRStarted,this.eventSub_WebXRStartEvent),Ue.removeEventListener(Kt.XRUpdate,this.eventSub_WebXRUpdateEvent),Ue.removeEventListener(Kt.XRStopped,this.eventSub_WebXREndEvent)}update(){const e=Km();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=e),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const t in this.avatars){const g=this.avatars[t];g&&g.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const e=Km();for(const t in this.avatars){const g=this.avatars[t];if(!g){this._removeAvatarsList.push(t);continue}e-g.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),g.destroy(),this.avatars[t]=void 0)}for(const t of this._removeAvatarsList)delete this.avatars[t];this._removeAvatarsList.length=0}buildLocalAvatar(){var t;if(this.localAvatar)return;const e=((t=this.context.connection)==null?void 0:t.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new js(this.context,e,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var e,t,g;nv&&console.log("Hey you are connected as "+this.context.connection.connectionId),((e=this.localAvatar)==null?void 0:e.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(g=this.ownership)==null||g.freeOwnership(),this.ownership=null)}onXRSessionStart(e){var t,g,I;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(g=this.ownership)==null||g.freeOwnership(),this.ownership=null,this.avatars)for(const o in this.avatars)(I=this.avatars[o])==null||I.updateFlags()}onXRSessionEnded(e){var t;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(e){this.xrState??(this.xrState=new Es(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new bw(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:t,xr:g,rig:I}=e,o=t.getViewerPose(g.getReferenceSpace());if(!o)return;const s=o==null?void 0:o.transform,C=s.position,n=s.orientation;this.xrState.update(I,C,n,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 sA("avatar")??null}}var xgA=Object.defineProperty,TgA=Object.getOwnPropertyDescriptor,Ac=(i,A,e,t)=>{for(var g=t>1?void 0:t?TgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&xgA(A,e,g),g};const rk=sA("debugwebxr");async function y2(){return _f()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function S2(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let ah=!1,rh=!1;y2().then(i=>ah=i);S2().then(i=>rh=i);var Kt=(i=>(i.XRStarted="xrStarted",i.XRStopped="xrStopped",i.XRUpdate="xrUpdate",i.RequestVRSession="requestVRSession",i.ModifyAROptions="modify-ar-options",i))(Kt||{}),hQ;const Pi=(hQ=class extends NA{constructor(){super(...arguments);r(this,"enableVR",!0);r(this,"enableAR",!0);r(this,"defaultAvatar");r(this,"handModelPath","");r(this,"createVRButton",!0);r(this,"createARButton",!0);r(this,"controllers",[]);r(this,"rig");r(this,"isInit",!1);r(this,"_requestedAR",!1);r(this,"_requestedVR",!1);r(this,"_isInAR",!1);r(this,"_isInVR",!1);r(this,"_arButton");r(this,"_vrButton");r(this,"webAR",null);r(this,"_transformOrientation",new GA);r(this,"_currentHeadPose",null);r(this,"_originalCameraParent",null);r(this,"_originalCameraPosition",new w);r(this,"_originalCameraRotation",new GA);r(this,"_originalXRRigParent",null);r(this,"_originalXRRigPosition",new w);r(this,"_originalXRRigRotation",new GA);r(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(ah||rh)}static get IsARSupported(){return ah}static get IsVRSupported(){return rh}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(A,e){return this.events.addEventListener(A,e),e}static removeEventListener(A,e){return this.events.removeEventListener(A,e),e}static dispatchEvent(A,e){this.events.dispatchEvent({type:A,detail:e})}static createVRButton(A,e){Pi.XRSupported?A.__internalAwake():console.warn("WebXR is not supported on this device");const t={optionalFeatures:Pi.OptionalFeatures_VR},g=Jh.createButton(A.context.renderer,t);return g.classList.add("webxr-ar-button"),g.classList.add("webxr-button"),this.resetButtonStyles(g),((e==null?void 0:e.registerClick)??!0)&&g.addEventListener("click",A.onClickedVRButton.bind(A)),g}static createARButton(A,e){var o;A.__internalAwake();const t=(o=A.webAR)==null?void 0:o.getAROverlayContainer(),g={optionalFeatures:[...this.OptionalFeatures_AR]};t?(g.domOverlay={root:t},g.optionalFeatures.push("dom-overlay"),g.optionalFeatures.push("hit-test"),g.optionalFeatures.push("anchors")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const I=KgA.createButton(A.context.renderer,g,this.onModifyAROptions.bind(this));return I.classList.add("webxr-ar-button"),I.classList.add("webxr-button"),Pi.resetButtonStyles(I),((e==null?void 0:e.registerClick)??!0)&&I.addEventListener("click",A.onClickedARButton.bind(A)),I}static onModifyAROptions(A){Pi.dispatchEvent("modify-ar-options",A)}static resetButtonStyles(A){A&&(A.style.position="",A.style.bottom="",A.style.left="")}endSession(){const A=this.context.renderer.xr.getSession();A&&A.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var A,e;return this.controllers.length>0&&((A=this.controllers[0].input)==null?void 0:A.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((e=this.controllers[1].input)==null?void 0:e.handedness)==="left"?this.controllers[1]:null}get RightController(){var A,e;return this.controllers.length>0&&((A=this.controllers[0].input)==null?void 0:A.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((e=this.controllers[1].input)==null?void 0:e.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=Li.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!IA.findObjectOfType(Ul,this.context)){const A=IA.addNewComponent(this.gameObject,Ul,!1);A.webXR=this}this.webAR=new Wr(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(Wg("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,Pi.XRSupported;let A,e;const t=document.createElement("div");t.classList.add("webxr-buttons"),t.style.cssText=`
|
|
5181
|
+
`,s={map:{value:A},height:{value:e.height||15},radius:{value:e.radius||100}},C=new Ad(1,16),n=new be({uniforms:s,fragmentShader:o,vertexShader:I,side:mt});super(C,n)}set radius(A){this.material.uniforms.radius.value=A}get radius(){return this.material.uniforms.radius.value}set height(A){this.material.uniforms.height.value=A}get height(){return this.material.uniforms.height.value}}var aiA=Object.defineProperty,riA=Object.getOwnPropertyDescriptor,dI=(i,A,e,t)=>{for(var g=t>1?void 0:t?riA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&aiA(A,e,g),g};const cp=sA("freecam"),bc=sA("debugcamerafit"),hp=sA("smoothcam"),BiA={LEFT:"",UP:"",RIGHT:"",BOTTOM:""};let sk;class ii extends NA{constructor(){super(...arguments);r(this,"enableRotate",!0);r(this,"autoRotate",!1);r(this,"autoRotateSpeed",1);r(this,"autoFit",!1);r(this,"enableKeys",!0);r(this,"enableDamping",!0);r(this,"dampingFactor",.1);r(this,"enableZoom",!0);r(this,"minZoom",0);r(this,"maxZoom",1/0);r(this,"enablePan",!0);r(this,"lookAtConstraint",null);r(this,"lookAtConstraint01",1);r(this,"middleClickToFocus",!0);r(this,"doubleClickToFocus",!0);r(this,"useSlerp",!0);r(this,"debugLog",!1);r(this,"targetLerpSpeed",5);r(this,"autoTarget",!0);r(this,"_lookTargetPosition");r(this,"_controls",null);r(this,"_cameraObject",null);r(this,"_lerpToTargetPosition",!1);r(this,"_lerpCameraToTarget",!1);r(this,"_cameraTargetPosition",null);r(this,"_inputs",0);r(this,"_enableTime",0);r(this,"_startedListeningToKeyEvents",!1);r(this,"_eventSystem");r(this,"_afterHandleInputFn");r(this,"_camera",null);r(this,"_syncedTransform");r(this,"_didStart",!1);r(this,"targetElement",null);r(this,"onControlsChangeStarted",()=>{this._syncedTransform&&this._syncedTransform.requestOwnership()});r(this,"_shouldDisable",!1);r(this,"_haveAttachedKeyboardEvents",!1)}get isCameraController(){return!0}get controls(){return this._controls}get controllerObject(){return this._cameraObject}onStartInteraction(e){var t;(t=this.controls)==null||t.addEventListener("start",e)}awake(){this._didStart=!1,this._lookTargetPosition=new w,this._startedListeningToKeyEvents=!1}start(){if(this._didStart=!0,this.autoTarget&&this._controls){const e=IA.getComponent(this.gameObject,Ht);if(e&&!this.setFromTargetPosition()){this.debugLog&&console.log("NO TARGET");const g=ke(e.cam).length(),I=new w(0,0,-g).applyMatrix4(e.cam.matrixWorld);this.setTarget(I,!0)}if(this.autoTarget&&!this.setFromTargetPosition()){const t=new Wo;t.screenPoint=new tA(0,0),t.lineThreshold=.1;const g=this.context.physics.raycast(t);g.length>0&&this.setTarget(g[0].point,!0),bc&&console.log("OrbitControls hits",...g)}this.autoFit&&this.fitCamera()}this._eventSystem=nI.get(this.context)??void 0,this._eventSystem&&(this._afterHandleInputFn=this.afterHandleInput.bind(this),this._eventSystem.addEventListener(Um.AfterHandleInput,this._afterHandleInputFn))}onDestroy(){var e,t;(e=this._controls)==null||e.dispose(),(t=this._eventSystem)==null||t.removeEventListener(Um.AfterHandleInput,this._afterHandleInputFn)}onEnable(){this._enableTime=this.context.time.time;const e=IA.getComponent(this.gameObject,Ht);this._camera=e;const t=e==null?void 0:e.cam;if(t&&iv(t,this,!0),!this._controls){if(!t){console.warn("OrbitControls: Requires a Camera component on the same object as this component.");return}t&&(this._cameraObject=t);const g=this.targetElement??this.context.domElement,I=t==null?void 0:t.quaternion.clone();this._controls=new D7(t,g),t==null||t.quaternion.copy(I),sk===void 0&&(sk={...this._controls.keys})}this._controls&&(cp&&(this.enablePan=!0,this.enableZoom=!0,this.middleClickToFocus=!0,kn()&&(this.doubleClickToFocus=!0)),this._controls.addEventListener("start",this.onControlsChangeStarted),(t==null?void 0:t.type)==="PerspectiveCamera"?cp||(this._controls.minDistance=this.minZoom,this._controls.maxDistance=this.maxZoom):cp||(this._controls.minZoom=this.minZoom,this._controls.maxZoom=this.maxZoom),this._startedListeningToKeyEvents||(this._startedListeningToKeyEvents=!0,this._controls.listenToKeyEvents(window.document.body))),this._syncedTransform=IA.getComponent(this.gameObject,Ma)??void 0}onDisable(){var e;(e=this._camera)!=null&&e.cam&&iv(this._camera.cam,this,!1),this._controls&&(this._controls.enabled=!1,this._controls.autoRotate=!1,this._controls.removeEventListener("start",this.onControlsChangeStarted))}afterHandleInput(e){e.detail.args.pointerId===0&&(e.detail.args.isDown?this._controls&&this._eventSystem&&(this._shouldDisable=this._eventSystem.hasActiveUI):(!e.detail.args.isPressed||e.detail.args.isUp)&&(this._shouldDisable=!1))}onBeforeRender(){var t,g,I;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 e=this.middleClickToFocus&&this.context.input.getPointerClicked(1);if(e||(e=this.doubleClickToFocus&&this.context.input.getPointerDoubleClicked(0)&&this.context.time.time-this._enableTime>.3),e?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 s=(t=this._cameraObject)==null?void 0:t.position;Ux(s,this._cameraTargetPosition,o)}else(g=this._cameraObject)==null||g.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(!cp&&((I=this.lookAtConstraint)!=null&&I.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?sk:BiA,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 hp=="number"||hp===!0){this._controls.enableDamping=!0;const o=typeof hp=="number"?hp:.99;this._controls.dampingFactor=Math.max(.001,1-Math.min(1,o))}this.context.isInXR||this._controls.update()}}setCameraTarget(e,t=!1){return this.setCameraTargetPosition(e,t)}setCameraTargetPosition(e,t=!1){var g;e?(this._lerpCameraToTarget=!0,this._cameraTargetPosition=e.clone(),t&&this._cameraTargetPosition&&((g=this.controllerObject)==null||g.position.copy(this._cameraTargetPosition))):this._lerpCameraToTarget=!1}setFromTargetPosition(e=0,t=1){var I;if(!this._controls)return!1;const g=(I=this.lookAtConstraint)==null?void 0:I.sources;if(g&&g.length>0){const o=g[e];if(o)return o.getWorldPosition(this._lookTargetPosition),this.lerpTarget(this._lookTargetPosition,t),!0}return!1}setTarget(e=null,t=!1){this._controls&&(e!==null&&this._lookTargetPosition.copy(e),t?this._controls.target.copy(this._lookTargetPosition):this._lerpToTargetPosition=!0)}lerpTarget(e,t){this._controls&&this._controls.target.lerp(e,t)}distanceToTarget(e){return this._controls?this._controls.target.distanceTo(e):-1}setTargetFromRaycast(){var t,g;if(!this.controls)return;const e=this.context.physics.raycast();for(const I of e)if(I.distance>0&&IA.isActiveInHierarchy(I.object)){const o=dy(I.object);if(o){const s=o.canvas;if(s!=null&&s.screenspace)break}if(this._lookTargetPosition.copy(I.point),this._lerpToTargetPosition=!0,this._cameraTargetPosition=null,this.context.mainCamera){this._lerpCameraToTarget=!0;const s=ke(this.context.mainCamera);this._cameraTargetPosition=s.clone().sub(this.controls.target).add(this._lookTargetPosition),(g=(t=this._cameraObject)==null?void 0:t.parent)==null||g.worldToLocal(this._cameraTargetPosition)}break}}fitCamera(e,t=1.1,g=!0){const I=this._cameraObject,o=this._controls;if(e!=null&&e.length||(e=this.context.scene.children),e.length<=0||!I||!o)return;const s=new w,C=new w,n=new zi;n.makeEmpty();const a=[];function B(u){let f=!0;if(u.visible&&(u instanceof UG&&(f=!1),u instanceof XM&&(f=!1),u instanceof E2&&(f=!1),u.material instanceof pw&&(f=!1),u instanceof wA||(f=!1),u!==I&&u.isUI!==!0)){if(f){bc&&console.log(u.name,u.type,u);const S=u.children;u.children=a,n.expandByObject(u,!0),u.children=S}for(const S of u.children)B(S)}}for(const u of e)u.updateMatrixWorld(),B(u);if(I.updateMatrixWorld(),I.updateProjectionMatrix(),n.getCenter(C),n.applyMatrix4(I.matrixWorldInverse),n.getSize(s),n.setFromCenterAndSize(C,s),s.length()<=1e-10){bc&&console.warn("Camera fit size is zero",n,[...e]);return}const Q=I.fov,E=2*Math.atan(Math.tan(Q*Math.PI/360/2)*I.aspect)/Math.PI*360,c=s.y/(2*Math.atan(Math.PI*Q/360)),l=s.x/(2*Math.atan(Math.PI*E/360)),d=t*Math.max(c,l)+s.z/2;bc&&console.log("Fit camera to objects",c,l,"distance",d);const h=ke(I),p=o.target.clone().sub(h).normalize().multiplyScalar(d);if(o.maxDistance=d*10,o.minDistance=d*.01,this.setTarget(C,g),this.autoTarget=!1,I.near=d/100,I.far=d*100,I.updateMatrixWorld(),I.updateProjectionMatrix(),I.parent){const u=I.parent.worldToLocal(o.target.clone().sub(p));this.setCameraTarget(u,g)}else console.error(`Can not fit camera ${I.name} because it has no parent`);if(bc){const u=new UG(n);this.context.scene.add(u),Jx(u,Nw(I)),this._haveAttachedKeyboardEvents||(this._haveAttachedKeyboardEvents=!0,document.body.addEventListener("keydown",f=>{f.code==="KeyF"&&this.fitCamera(e)}))}o.update()}}dI([D()],ii.prototype,"enableRotate",2);dI([D()],ii.prototype,"autoRotate",2);dI([D()],ii.prototype,"autoRotateSpeed",2);dI([D()],ii.prototype,"autoFit",2);dI([D()],ii.prototype,"enableKeys",2);dI([D()],ii.prototype,"enableDamping",2);dI([D()],ii.prototype,"dampingFactor",2);dI([D()],ii.prototype,"enableZoom",2);dI([D()],ii.prototype,"minZoom",2);dI([D()],ii.prototype,"maxZoom",2);dI([D()],ii.prototype,"enablePan",2);dI([D(dd)],ii.prototype,"lookAtConstraint",2);dI([D()],ii.prototype,"lookAtConstraint01",2);dI([D()],ii.prototype,"middleClickToFocus",2);dI([D()],ii.prototype,"doubleClickToFocus",2);var QiA=Object.defineProperty,EiA=Object.getOwnPropertyDescriptor,Qo=(i,A,e,t)=>{for(var g=t>1?void 0:t?EiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&QiA(A,e,g),g},dD=(i=>(i[i.Skybox=1]="Skybox",i[i.SolidColor=2]="SolidColor",i[i.Uninitialized=4]="Uninitialized",i))(dD||{});const mr=sA("debugcam"),Iv=sA("debugscreenpointtoray");var bp;const Ch=(bp=class extends NA{constructor(){super(...arguments);r(this,"_nearClipPlane",.1);r(this,"_farClipPlane",1e3);r(this,"orthographic",!1);r(this,"orthographicSize",5);r(this,"ARBackgroundAlpha",0);r(this,"_cullingMask",4294967295);r(this,"_backgroundBlurriness");r(this,"_backgroundIntensity");r(this,"_environmentIntensity");r(this,"_targetTexture",null);r(this,"_backgroundColor");r(this,"_fov");r(this,"_cam",null);r(this,"_clearFlags",2);r(this,"_skybox")}get isCamera(){return!0}get aspect(){return this._cam instanceof Xe?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._cam instanceof Xe?this._cam.fov:this._fov}set fieldOfView(A){const e=this.fieldOfView!=A;if(this._fov=A,e&&this._cam&&this._cam instanceof Xe){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(A){const e=this._nearClipPlane!=A;this._nearClipPlane=A,this._cam&&e&&(this._cam.near=A,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(A){const e=this._farClipPlane!=A;this._farClipPlane=A,this._cam&&e&&(this._cam.far=A,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(A){A!==this._clearFlags&&(this._clearFlags=A,this.applyClearFlagsIfIsActiveCamera())}set cullingMask(A){this._cullingMask=A,this._cam&&(this._cam.layers.mask=A)}get cullingMask(){return this._cam?this._cam.layers.mask:this._cullingMask}set backgroundBlurriness(A){A!==this._backgroundBlurriness&&(A===void 0?this._backgroundBlurriness=void 0:this._backgroundBlurriness=Math.min(Math.max(A,0),1),this.applyClearFlagsIfIsActiveCamera())}get backgroundBlurriness(){return this._backgroundBlurriness}set backgroundIntensity(A){A!==this._backgroundIntensity&&(A===void 0?this._backgroundIntensity=void 0:this._backgroundIntensity=Math.min(Math.max(A,0),10),this.applyClearFlagsIfIsActiveCamera())}get backgroundIntensity(){return this._backgroundIntensity}set environmentIntensity(A){this._environmentIntensity=A}get environmentIntensity(){return this._environmentIntensity}get backgroundColor(){return this._backgroundColor??null}set backgroundColor(A){if(A){if(this._backgroundColor)this._backgroundColor.copy(A);else{if(!A.clone)return;this._backgroundColor=A.clone()}A.alpha===void 0&&(this._backgroundColor.alpha=1),this.applyClearFlagsIfIsActiveCamera()}}set targetTexture(A){this._targetTexture=A}get targetTexture(){return this._targetTexture}get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}screenPointToRay(A,e,t){const g=this.cam,I=Ch._origin;I.set(A,e,-1),this.context.input.convertScreenspaceToRaycastSpace(I),Iv&&console.log("screenPointToRay",A.toFixed(2),e.toFixed(2),"now:",I.x.toFixed(2),I.y.toFixed(2),"isInXR:"+this.context.isInXR),I.z=-1,I.unproject(g);const o=Ch._direction.set(I.x,I.y,I.z),s=ke(g);return o.sub(s),o.normalize(),t?(t.set(s,o),t):new nC(s.clone(),o.clone())}awake(){Iv&&window.addEventListener("pointerdown",A=>{const e=A.clientX,t=A.clientY;console.log("touch",e.toFixed(2),t.toFixed(2));const g=this.screenPointToRay(e,t),I="#"+Math.floor(Math.random()*16777215).toString(16);An.DrawRay(g.origin,g.direction,I,10)})}onEnable(){mr&&console.log(`Camera enabled: "${this.name}". ClearFlags=${dD[this._clearFlags]}`,this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&(this.context.setCurrentCamera(this),hiA(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 A=this.context.renderer;if(A){const e=this.context.mainCameraComponent;this.applyClearFlags(),this._targetTexture.render(this.context.scene,this._cam,A),e==null||e.applyClearFlags()}}}buildCamera(){if(this._cam)return;const A=this.gameObject.isCamera;let e=null;if(A?(e=this.gameObject,e==null||e.layers.enableAll(),e instanceof Xe&&(this._fov=e.fov)):e=this.gameObject.children[0],e&&e.isCamera)e instanceof Xe&&(this._fov&&(e.fov=this._fov),e.near=this._nearClipPlane,e.far=this._farClipPlane,e.updateProjectionMatrix());else if(!this.orthographic)e=new Xe(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),this.fieldOfView&&(e.fov=this.fieldOfView),this.gameObject.add(e);else{const t=this.orthographicSize*100;e=new gB(window.innerWidth/-t,window.innerWidth/t,window.innerHeight/t,window.innerHeight/-t,this._nearClipPlane,this._farClipPlane),this.gameObject.add(e)}this._cam=e,this._cam.layers.mask=this._cullingMask,this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){this.context.mainCameraComponent===this&&this.applyClearFlags()}applyClearFlags(){if(!this._cam){mr&&console.log("Camera does not exist (apply clear flags)");return}if(this.fieldOfView=this._fov,mr){const A=`Camera "${this.name}" clear flags: ${dD[this._clearFlags]}`;console.log(A)}switch(this._clearFlags){case 1:if(Ch.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 A=this._backgroundColor.alpha;Ch.backgroundShouldBeTransparent(this.context)&&(A=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,A)}else mr&&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 ciA(this)),this._skybox.enable()}static backgroundShouldBeTransparent(A){var I,o,s,C;const e=(I=A.renderer.xr)==null?void 0:I.getSession();if(!e)return!1;const t=e.environmentBlendMode;mr&&Di("Environment blend mode: "+t+" on "+navigator.userAgent);const g=t==="additive"||t==="alpha-blend";if(A.xrSessionMode===hl.ImmersiveAR&&t==="opaque"){if((o=navigator.userAgent)!=null&&o.includes("OculusBrowser"))return!0;if((s=navigator.userAgent)!=null&&s.includes("Mozilla")&&((C=navigator.userAgent)!=null&&C.includes("Mobile WebXRViewer/v2")))return!0}return g}},r(bp,"_origin",new w),r(bp,"_direction",new w),bp);let Ht=Ch;Qo([D()],Ht.prototype,"fieldOfView",1);Qo([D()],Ht.prototype,"nearClipPlane",1);Qo([D()],Ht.prototype,"farClipPlane",1);Qo([D()],Ht.prototype,"clearFlags",1);Qo([D()],Ht.prototype,"orthographic",2);Qo([D()],Ht.prototype,"orthographicSize",2);Qo([D()],Ht.prototype,"ARBackgroundAlpha",2);Qo([D()],Ht.prototype,"cullingMask",1);Qo([D()],Ht.prototype,"backgroundBlurriness",1);Qo([D()],Ht.prototype,"backgroundIntensity",1);Qo([D()],Ht.prototype,"environmentIntensity",1);Qo([D(St)],Ht.prototype,"backgroundColor",1);Qo([D(ua)],Ht.prototype,"targetTexture",1);class ciA{constructor(A){r(this,"_camera");r(this,"_skybox");this._camera=A}get context(){var A;return(A=this._camera)==null?void 0:A.context}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?this.context.scene.background!==this._skybox&&(mr&&console.log(`Camera "${this._camera.name}" set skybox`,this._camera,this._skybox),this._skybox.colorSpace=Ae,this._skybox.mapping=Yo,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),(mr||rt())&&Wg(`Camera "${this._camera.name}" has no skybox texture`))}}function hiA(i){sA("freecam")&&i.context.mainCameraComponent===i&&IA.getOrAddComponent(i.gameObject,ii)}class Or extends NA{constructor(){super(...arguments);r(this,"_listener",null)}get listener(){return this._listener==null&&(this._listener=new zM),this._listener}awake(){Gi.registerWaitForAllowAudio(()=>{if(this.destroyed)return;const e=this.listener;if(e==null||e.parent)return;const t=this.context.mainCameraComponent||IA.getComponentInParent(this.gameObject,Ht);t!=null&&t.cam?t.cam.add(e):this.gameObject.add(e)})}}var liA=Object.defineProperty,diA=Object.getOwnPropertyDescriptor,uy=(i,A,e,t)=>{for(var g=t>1?void 0:t?diA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&liA(A,e,g),g};const uiA=sA("debugsignals");class Sd{constructor(){r(this,"guid")}}uy([D()],Sd.prototype,"guid",2);class HE{constructor(){r(this,"signal");r(this,"reaction")}}uy([D(Sd)],HE.prototype,"signal",2);uy([D(Dg)],HE.prototype,"reaction",2);var Yk;const KC=(Yk=class extends NA{constructor(){super(...arguments);r(this,"events")}static invoke(A){if(KC.receivers[A]){const e=KC.receivers[A];if(!e)return;for(const t of e)t.invoke(A)}}awake(){uiA&&console.log("SignalReceiver awake",this)}onEnable(){if(this.events)for(const A of this.events)KC.receivers[A.signal.guid]||(KC.receivers[A.signal.guid]=[]),KC.receivers[A.signal.guid].push(this)}onDisable(){if(this.events){for(const A of this.events)if(KC.receivers[A.signal.guid]){const e=KC.receivers[A.signal.guid].indexOf(this);e>=0&&KC.receivers[A.signal.guid].splice(e,1)}}}invoke(A){if(!this.events||!Array.isArray(this.events))return;const e=typeof A=="object"?A.guid:A;for(const t of this.events)if(t.signal.guid===e)try{if(t.reaction){if(!t.reaction.invoke){console.warn("Missing invoke - possibly a serialization error",t,this);continue}}else{console.warn("Missing reaction for signal",t,this);continue}t.reaction.invoke()}catch(g){console.error(g)}}},r(Yk,"receivers",{}),Yk);let _E=KC;uy([D(HE)],_E.prototype,"events",2);var VI=(i=>(i.Activation="ActivationTrack",i.Animation="AnimationTrack",i.Audio="AudioTrack",i.Control="ControlTrack",i.Marker="MarkerTrack",i.Signal="SignalTrack",i))(VI||{}),bs=(i=>(i[i.None=0]="None",i[i.Hold=1]="Hold",i[i.Loop=2]="Loop",i[i.PingPong=3]="PingPong",i[i.Continue=4]="Continue",i))(bs||{}),yU=(i=>(i.Signal="SignalEmitter",i))(yU||{});const nQ=sA("debugtimeline"),LD=class extends NA{constructor(){super(...arguments);r(this,"playableAsset");r(this,"playOnAwake");r(this,"extrapolationMode",1);r(this,"waitForAudio",!0);r(this,"_visibilityChangeEvt");r(this,"_clonedPlayableAsset",!1);r(this,"_speed",1);r(this,"_guidsMap");r(this,"_isPlaying",!1);r(this,"_internalUpdateRoutine");r(this,"_isPaused",!1);r(this,"_isStopping",!1);r(this,"_time",0);r(this,"_duration",0);r(this,"_weight",1);r(this,"_animationTracks",[]);r(this,"_audioTracks",[]);r(this,"_signalTracks",[]);r(this,"_controlTracks",[]);r(this,"_customTracks",[]);r(this,"_allTracks",[this._animationTracks,this._audioTracks,this._signalTracks,this._controlTracks,this._customTracks]);r(this,"animationCallbackReceivers",[])}static registerCreateTrack(e,t){this.createTrackFunctions[e]=t}get isPlaying(){return this._isPlaying}get isPaused(){return this._isPaused}get time(){return this._time}set time(e){typeof e=="number"&&!Number.isNaN(e)?this._time=e:(nQ||QI())&&console.error("INVALID TIMELINE.TIME VALUE",e,this.name)}get duration(){return this._duration}set duration(e){this._duration=e}get weight(){return this._weight}set weight(e){this._weight=e}get speed(){return this._speed}set speed(e){this._speed=e}awake(){var e,t,g;nQ&&console.log(this,(e=this.playableAsset)==null?void 0:e.tracks),this.rebuildGraph(),this.isValid()||console.warn("PlayableDirector is not valid",this.playableAsset,(t=this.playableAsset)==null?void 0:t.tracks,Array.isArray((g=this.playableAsset)==null?void 0:g.tracks),this)}onEnable(){var e,t,g;for(const I of this._audioTracks)(e=I.onEnable)==null||e.call(I);for(const I of this._customTracks)(t=I.onEnable)==null||t.call(I);for(const I of this._animationTracks)(g=I.onEnable)==null||g.call(I);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 e,t,g;this.stop();for(const I of this._audioTracks)(e=I.onDisable)==null||e.call(I);for(const I of this._customTracks)(t=I.onDisable)==null||t.call(I);for(const I of this._animationTracks)(g=I.onDisable)==null||g.call(I);this._visibilityChangeEvt&&window.removeEventListener("visibilitychange",this._visibilityChangeEvt)}onDestroy(){var e;for(const t of this._allTracks)for(const g of t)(e=g.onDestroy)==null||e.call(g)}rebuildGraph(){this.isValid()&&(this.resolveBindings(),this.updateTimelineDuration(),this.setupAndCreateTrackHandlers())}async play(){if(!this.isValid())return;const e=this._isPaused==!0;if(this._isPaused=!1,e&&this.invokePauseChangedMethodsOnTracks(),!this._isPlaying){if(this._isPlaying=!0,this.waitForAudio){const t=[];for(const g of this._audioTracks){const I=g.loadAudio(this._time,1,0);I&&t.push(I)}if(t.length>0&&(await Promise.all(t),!this._isPlaying))return;for(;this._audioTracks.length>0&&this._isPlaying&&!Gi.userInteractionRegistered&&this.waitForAudio;)await id(200)}this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine=this.startCoroutine(this.internalUpdate(),xI.OnBeforeRender)}}pause(){this.isValid()&&(this._isPlaying=!1,!this._isPaused&&(this._isPaused=!0,this.evaluate(),this.invokePauseChangedMethodsOnTracks(),this.invokeStateChangedMethodsOnTracks()))}stop(){this._isStopping=!0;for(const g of this._audioTracks)g.stop();const e=this._isPaused==!0,t=this._isPlaying;this._isPlaying&&(this._time=0,this._isPlaying=!1,this._isPaused=!1,this.evaluate(),e&&this.invokePauseChangedMethodsOnTracks()),this._isPlaying=!1,this._isPaused=!1,e&&!t&&this.invokePauseChangedMethodsOnTracks(),t&&this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine&&this.stopCoroutine(this._internalUpdateRoutine),this._internalUpdateRoutine=null,this._isStopping=!1}evaluate(){if(!this.isValid())return;let e=this._time;switch(this.extrapolationMode){case 0:this._speed>0?e=Math.min(e,this._duration):this._speed<0&&(e=Math.max(e,0)),this._time=e;break;case 1:e%=this._duration,this._time=e;break;case 2:if(e>this._duration){this.stop();return}break}this.internalEvaluate(e)}isValid(){return this.playableAsset&&this.playableAsset.tracks&&Array.isArray(this.playableAsset.tracks)}*forEachTrack(){for(const e of this._allTracks)for(const t of e)yield t}get audioTracks(){return this._audioTracks}resolveGuids(e){this._guidsMap=e}invokePauseChangedMethodsOnTracks(){var e;for(const t of this.forEachTrack())(e=t.onPauseChanged)==null||e.call(t)}invokeStateChangedMethodsOnTracks(){var e;for(const t of this.forEachTrack())(e=t.onStateChanged)==null||e.call(t,this._isPlaying)}*internalUpdate(){for(;this._isPlaying&&this.activeAndEnabled;)!this._isPaused&&this._isPlaying&&(this._time+=this.context.time.deltaTime*this.speed,this.evaluate()),yield}internalEvaluate(e){for(const t of this.playableAsset.tracks)if(!t.muted)switch(t.type){case VI.Activation:if(!this._isPlaying)continue;for(let g=0;g<t.outputs.length;g++){const I=t.outputs[g];if(typeof I=="object"){let o=!1;if(t.clips)for(const C of t.clips)C.start<=e&&e<=C.end&&(o=!0);const s=I;s.visible!==void 0&&s.visible!==o&&(s.visible=o,nQ&&console.warn(this.name,"set ActivationTrack-"+g,s.name,o,e))}}break}if(!this._isStopping)for(const t of this._animationTracks)t.evaluate(e);for(const t of this._audioTracks)t.evaluate(e);for(const t of this._signalTracks)t.evaluate(e);for(const t of this._controlTracks)t.evaluate(e);for(const t of this._customTracks)t.evaluate(e)}resolveBindings(){if(this._clonedPlayableAsset||(this._clonedPlayableAsset=!0,this.playableAsset=Uw(this.playableAsset)),!this.playableAsset||!this.playableAsset.tracks)return;const e=this.findRoot(this.gameObject);for(const t of this.playableAsset.tracks){for(let g=t.outputs.length-1;g>=0;g--){let I=t.outputs[g];if(typeof I=="string"){this._guidsMap&&this._guidsMap[I]&&(I=this._guidsMap[I]);const o=IA.findByGuid(I,e);o===null||typeof o!="object"?(t.outputs.splice(g,1),console.warn("Failed to resolve binding",I,t.name,t.type)):(nQ&&console.log("Resolved binding",I,"to",o),t.outputs[g]=o)}else if(I===null){if(t.outputs.splice(g,1),LD.createTrackFunctions[t.type])continue;t.type!==VI.Audio&&t.type!==VI.Control&&t.type!==VI.Marker&&t.type!==VI.Signal&&console.warn("Missing binding",I,t.name,t.type,this.name,this.playableAsset.name)}}if(t.type===VI.Control&&t.clips)for(let g=0;g<t.clips.length;g++){const I=t.clips[g];let o=I.asset.sourceObject;if(typeof o=="string"){this._guidsMap&&this._guidsMap[o]&&(o=this._guidsMap[o]);const s=IA.findByGuid(o,e);s===null||typeof s!="object"?console.warn("Failed to resolve sourceObject binding",o,t.name,I):(nQ&&console.log("Resolved binding",o,"to",s),I.asset.sourceObject=s)}}}}findRoot(e){return e.parent?this.findRoot(e.parent):e}updateTimelineDuration(){if(this._duration=0,!(!this.playableAsset||!this.playableAsset.tracks)){for(const e of this.playableAsset.tracks)if(e.muted!==!0){if(e.clips)for(const t of e.clips)t.end>this._duration&&(this._duration=t.end);if(e.markers)for(const t of e.markers)t.time>this._duration&&(this._duration=t.time+.001)}}}setupAndCreateTrackHandlers(){var t,g;if(this._animationTracks.length=0,this._audioTracks.length=0,this._signalTracks.length=0,!this.playableAsset)return;const e=IA.findObjectOfType(Or,this.context);for(const I of this.playableAsset.tracks){const o=I.type,s=LD.createTrackFunctions[o];if(s!=null){const C=s(this,I);if(typeof C.evaluate=="function"){C.director=this,C.track=I,this._customTracks.push(C);continue}}if(I.type===VI.Animation){if(!I.clips||I.clips.length<=0){nQ&&console.warn("Animation track has no clips",I);continue}for(let C=I.outputs.length-1;C>=0;C--){let n=I.outputs[C];if(n instanceof FA){const B=IA.getOrAddComponent(n,Pg);B&&(n=B)}const a=(t=n==null?void 0:n.gameObject)==null?void 0:t.animations;if(a){const B=new py;B.trackOffset=I.trackOffset,B.director=this,B.track=I;for(let Q=0;Q<I.clips.length;Q++){const E=I.clips[Q],c=E.asset;if(!c){console.error("MISSING anim model?","clip#"+Q,E,I,this.playableAsset,this.name);continue}const l=c.clip;let d=l;if((typeof d=="string"||typeof d=="number")&&(d=a.find(p=>p.name===l)),!d){console.warn("Could not find animationClip for model",E,I.name,this.name,(g=this.playableAsset)==null?void 0:g.name);continue}n instanceof Pg&&n.runtimeAnimatorController&&(n.__internalDidAwakeAndStart||n.initializeRuntimeAnimatorController(),n.runtimeAnimatorController.mixer||n.runtimeAnimatorController.bind(n),B.mixer=n.runtimeAnimatorController.mixer),B.mixer||(B.mixer=new Mw(n.gameObject)),B.clips.push(d),B.mixer.uncacheAction(d),B.createHooks(E.asset,d);const h=B.mixer.clipAction(d);B.actions.push(h),B.models.push(E)}this._animationTracks.push(B)}}}else if(I.type===VI.Audio){if(!I.clips||I.clips.length<=0)continue;const C=new Pr;if(C.director=this,C.track=I,this._audioTracks.push(C),!e)continue;C.listener=e.listener;for(let n=0;n<I.clips.length;n++){const a=I.clips[n];C.addModel(a)}}else if(I.type===VI.Marker){const C=new ml;if(C.director=this,C.track=I,I.markers)for(const n of I.markers)switch(n.type){case yU.Signal:C.models.push(n),C.didTrigger.push(!1);break}if(C!==null&&C.models.length>0){const n=IA.getComponent(this.gameObject,_E);n&&(C.receivers.push(n),this._signalTracks.push(C))}}else if(I.type===VI.Signal){const C=new ml;if(C.director=this,C.track=I,I.markers)for(const n of I.markers)C.models.push(n),C.didTrigger.push(!1);for(const n of I.outputs)C.receivers.push(n);this._signalTracks.push(C)}else if(I.type===VI.Control){const C=new fy;if(C.director=this,C.track=I,I.clips)for(const n of I.clips)C.models.push(n);C.resolveSourceObjects(this.context),this._controlTracks.push(C)}}}setAudioTracksAllowPlaying(e){for(const t of this._audioTracks)t.onAllowAudioChanged(e)}registerAnimationCallback(e){this.animationCallbackReceivers.push(e)}unregisterAnimationCallback(e){const t=this.animationCallbackReceivers.indexOf(e);t!==-1&&this.animationCallbackReceivers.splice(t,1)}};let Qn=LD;r(Qn,"createTrackFunctions",{});const tn=sA("debugtimeline");class kd{constructor(){r(this,"director");r(this,"track")}get muted(){return this.track.muted}set muted(A){var e;A!==this.track.muted&&(this.track.muted=A,(e=this.onMuteChanged)==null||e.call(this))}*forEachClip(A=!1){var e;if((e=this.track)!=null&&e.clips)if(A)for(let t=this.track.clips.length-1;t>=0;t--)yield this.track.clips[t];else for(const t of this.track.clips)yield t}getClipTime(A,e){return e.clipIn+(A-e.start)*e.timeScale}getClipTimeNormalized(A,e){return(A-e.start)/e.duration}evaluateWeight(A,e,t,g=!0){if(e<0||e>=t.length)return 0;const I=t[e];if(g||A>=I.start&&A<=I.end){let o=1;const s=!1;if(I.easeInDuration>0){const C=Math.min((A-I.start)/I.easeInDuration,1);o*=C}if(I.easeOutDuration>0&&!s){const C=Math.min((I.end-A)/I.easeOutDuration,1);o*=C}return o}return 0}}class piA{constructor(A){r(this,"clip");r(this,"rootPositionOffset");r(this,"rootQuaternionOffset");r(this,"rootStartPosition");r(this,"rootEndPosition");r(this,"rootStartQuaternion");r(this,"rootEndQuaternion");const e=A.getClip();this.clip=e;const t=A.getRoot(),g=t.name+".position",I=t.name+".quaternion";tn&&console.log(e.name,e.tracks,g);for(const o of e.tracks)if(!(o.times.length<=0)){if(o.name.endsWith(g))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),tn&&console.log(this.rootPositionOffset);else if(o.name.endsWith(I)&&(this.rootStartQuaternion=new GA().fromArray(o.values,0),this.rootEndQuaternion=new GA().fromArray(o.values,o.values.length-4),this.rootQuaternionOffset=this.rootEndQuaternion.clone().multiply(this.rootStartQuaternion),tn)){const s=new yi().setFromQuaternion(this.rootQuaternionOffset);console.log("ROT",s)}}}get hasOffsets(){return this.rootPositionOffset!==void 0||this.rootQuaternionOffset!==void 0}}class py extends kd{constructor(){super(...arguments);r(this,"models",[]);r(this,"trackOffset");r(this,"target");r(this,"mixer");r(this,"clips",[]);r(this,"actions",[]);r(this,"_actionOffsets",[]);r(this,"_didBind",!1);r(this,"_animator",null);r(this,"_useclipOffsets",!0);r(this,"_totalOffsetPosition",new w);r(this,"_totalOffsetRotation",new GA);r(this,"_totalOffsetPosition2",new w);r(this,"_totalOffsetRotation2",new GA);r(this,"_summedPos",new w);r(this,"_tempPos",new w);r(this,"_summedRot",new GA);r(this,"_tempRot",new GA);r(this,"_clipRotQuat",new GA)}onStateChanged(){this._animator&&qq(this._animator.gameObject,this,this.director.isPlaying)}createHooks(e,t){var a,B;if(((a=t.tracks)==null?void 0:a.length)<=0){console.warn("No tracks in AnimationClip",t);return}const g=t.tracks[0].name.split("."),I=g[g.length-2],o=I+".position",s=I+".quaternion";let C=!1,n=!1;for(const Q of t.tracks)Q.name.endsWith(o)?(C=!0,this.createPositionInterpolant(t,e,Q)):Q.name.endsWith(s)&&(n=!0,this.createRotationInterpolant(t,e,Q));if(!C||!n){const Q=(B=this.mixer)==null?void 0:B.getRoot(),E=t.tracks[0],c=E.name.lastIndexOf("."),l=E.name.substring(0,c),d=l.substring(l.lastIndexOf(".")+1),h=Q.getObjectByName(d);if(h)if(C){if(!n){const p=t.tracks[0].name.substring(0,c)+".quaternion";tn&&console.warn("Create quaternion track",d,h);const u=h.quaternion,f=new gC(p,[0,t.duration],[u.x,u.y,u.z,u.w,u.x,u.y,u.z,u.w]);t.tracks.push(f),this.createRotationInterpolant(t,e,f)}}else{const p=l+".position";tn&&console.warn("Create position track",d,h);const u=h.position,f=new cn(p,[0,t.duration],[u.x,u.y,u.z,u.x,u.y,u.z]);t.tracks.push(f),this.createPositionInterpolant(t,e,f)}}}bind(){if(!this._didBind){this._didBind=!0,tn&&console.log(this.models),this.mixer?this.target=this.mixer.getRoot():console.warn("No mixer was assigned to animation track");for(const e of this.actions){const t=new piA(e);this._actionOffsets.push(t)}this.target&&(this._animator=IA.getComponent(this.target,Pg)??null,this._animator&&qq(this._animator.gameObject,this,!0));for(const e of this.models){const t=e.asset,g=t.position,I=t.rotation;g&&g.x!==void 0&&(g.isVector3||(t.position=new w(g.x,g.y,g.z)),I.isQuaternion||(t.rotation=new GA(I.x,I.y,I.z,I.w)))}this.ensureTrackOffsets()}}ensureTrackOffsets(){if(this.trackOffset){const e=this.trackOffset.position;e&&(e.isVector3||(this.trackOffset.position=new w(e.x,e.y,e.z)));const t=this.trackOffset.rotation;t&&(t.isQuaternion||(this.trackOffset.rotation=new GA(t.x,t.y,t.z,t.w)))}}evaluate(e){var C,n,a,B,Q,E,c;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 t=0,g=0,I=!1,o=!1,s=0;for(let l=0;l<this.clips.length;l++){const d=this.models[l],h=this.actions[l],p=d.asset;h.weight=0;const u=e>=d.start&&e<=d.end,f=d.preExtrapolationMode,S=d.postExtrapolationMode,G=l<this.clips.length-1?this.models[l+1]:null;let M=u,R=!1;if(!M&&!I&&d.end<e&&S!==bs.None?(!G||G.start>e)&&(M=!0,I=!0):l==0&&!M&&!o&&d.start>e&&f!==bs.None&&(!G||G.start<e)&&(M=!0,R=!0,o=!0),M){let k=1;k*=this.evaluateWeight(e,l,this.models,M),k*=this.director.weight;let m=u;if(R)switch(f){case bs.Hold:break;case bs.Loop:e+=d.start,m=!0;break;default:e+=d.start,m=!0;break}let K=this.getClipTime(e,d),Z=0;const H=p.duration;if(R&&f===bs.Hold&&(K=0),m){if(p.loop)for(Z+=Math.floor(K/(H+1e-6));K>H;)K-=H}else if(!u&&I)switch(S){case bs.Hold:K=this.getClipTime(d.end,d);break;case bs.Loop:K%=H;break;case bs.PingPong:const x=Math.floor(K/H)%2!==0;K%=H,x&&(K=H-K);break}d.reversed===!0?h.time=h.getClip().duration-K:h.time=K,h.timeScale=0;const _=Math.max(0,k);if(h.weight=_,s+=_,h.clampWhenFinished=!1,h.isRunning()||h.play(),this._useclipOffsets){const j=t==0?this._totalOffsetPosition:this._totalOffsetPosition2,x=t==0?this._totalOffsetRotation:this._totalOffsetRotation2;t<1&&(g=1-k),t+=1;const v=this._summedPos.set(0,0,0),Y=this._tempPos.set(0,0,0),eA=this._summedRot.identity(),AA=this._tempRot.identity(),W=p.rotation;W&&(this._clipRotQuat.identity(),this._clipRotQuat.slerp(W,k));const gA=this._actionOffsets[l];if(gA.hasOffsets)for(let fA=0;fA<Z;fA++)gA.rootPositionOffset?Y.copy(gA.rootPositionOffset):Y.set(0,0,0),Y.applyQuaternion(eA),this._clipRotQuat&&Y.applyQuaternion(this._clipRotQuat),gA.rootQuaternionOffset&&(AA.copy(gA.rootQuaternionOffset),eA.multiply(AA)),v.add(Y);this._clipRotQuat&&x.multiply(this._clipRotQuat),x.multiply(eA),p.position&&v.add(p.position),j.add(v)}}}if(this._useclipOffsets&&(this._totalOffsetPosition.lerp(this._totalOffsetPosition2,g),this._totalOffsetRotation.slerp(this._totalOffsetRotation2,g)),this.__mixerError===void 0&&(tn||rt())&&((n=(C=this._animator)==null?void 0:C.runtimeAnimatorController)!=null&&n.mixer)&&this.mixer!==((B=(a=this._animator)==null?void 0:a.runtimeAnimatorController)==null?void 0:B.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)),(Q=this._animator)!=null&&Q.runtimeAnimatorController){const l=Math.max(0,1-s);(c=(E=this._animator)==null?void 0:E.runtimeAnimatorController)==null||c.update(l)}else this.mixer.update(e)}createRotationInterpolant(e,t,g){var C;const I=g.createInterpolant.bind(g),o=new GA;this.ensureTrackOffsets();const s=(C=this.trackOffset)==null?void 0:C.rotation;g.createInterpolant=()=>{const n=I(),a=n.evaluate.bind(n);return n.evaluate=B=>{var E;const Q=a(B);if(o.set(Q[0],Q[1],Q[2],Q[3]),o.premultiply(this._totalOffsetRotation),s&&o.premultiply(s),this.director.animationCallbackReceivers)for(const c of this.director.animationCallbackReceivers)(E=c==null?void 0:c.onTimelineRotation)==null||E.call(c,this.director,this.target,B,o);return Q[0]=o.x,Q[1]=o.y,Q[2]=o.z,Q[3]=o.w,Q},n}}createPositionInterpolant(e,t,g){var a,B;const I=g.createInterpolant.bind(g),o=new w;this.ensureTrackOffsets();const s=(a=this.trackOffset)==null?void 0:a.rotation,C=(B=this.trackOffset)==null?void 0:B.position;let n;g.createInterpolant=()=>{const Q=I(),E=Q.evaluate.bind(Q);return Q.evaluate=c=>{var d,h,p;const l=E(c);if(o.set(l[0],l[1],l[2]),t.removeStartOffset&&(n===void 0?(n=null,n=(h=(d=this._actionOffsets.find(u=>u.clip===e))==null?void 0:d.rootStartPosition)==null?void 0:h.clone()):n!=null&&n.isVector3&&o.sub(n)),o.applyQuaternion(this._totalOffsetRotation),o.add(this._totalOffsetPosition),s&&o.applyQuaternion(s),C&&(o.x-=C.x,o.y+=C.y,o.z+=C.z),this.director.animationCallbackReceivers)for(const u of this.director.animationCallbackReceivers)(p=u==null?void 0:u.onTimelinePosition)==null||p.call(u,this.director,this.target,c,o);return l[0]=o.x,l[1]=o.y,l[2]=o.z,l},Q}}}const fiA=sA("mutetimeline"),vQ=class extends kd{constructor(){super(...arguments);r(this,"models",[]);r(this,"listener");r(this,"audio",[]);r(this,"audioContextTimeOffset",[]);r(this,"lastTime",0);r(this,"_audioLoader",null)}getAudioFilePath(e){const t=this.director.sourceId;return Sn(t,e)}onAllowAudioChanged(e){for(let t=0;t<this.models.length;t++){const g=this.models[t];this.audio[t].setVolume(e?g.asset.volume:0)}}addModel(e){const t=new mw(this.listener);this.audio.push(t),this.models.push(e)}onDisable(){for(const e of this.audio)e.isPlaying&&e.stop()}onDestroy(){for(const e of this.audio)e.source&&(e==null||e.disconnect());this.audio.length=0}onMuteChanged(){if(this.muted)for(let e=0;e<this.audio.length;e++){const t=this.audio[e];t!=null&&t.isPlaying&&t.stop()}}stop(){for(let e=0;e<this.audio.length;e++){const t=this.audio[e];t!=null&&t.isPlaying&&t.stop()}}evaluate(e){if(fiA||this.track.muted||this.director.speed<0)return;const t=this.director.context.application.muted,g=t?.1:0;for(let I=0;I<this.models.length;I++){const o=this.models[I],s=this.audio[I];if((!s||!s.buffer)&&this.isInTimeRange(o,e-1,e+1)&&this.handleAudioLoading(o,s),Gi.userInteractionRegistered!==!1&&!(s===null||!s.buffer))if(s.playbackRate=this.director.context.time.timeScale,s.loop=o.asset.loop,e>=o.start&&e<=o.end&&e<this.director.duration){if(this.director.isPlaying==!1){if(s.isPlaying&&s.stop(),this.lastTime===e)continue}else if(!s.isPlaying)s.offset=o.clipIn+(e-o.start)*o.timeScale,s.play(g);else{const n=o.clipIn+(e-o.start)*o.timeScale,a=s.context.currentTime-s._startedAt+s.offset;Math.abs(n-a)>.3&&(s.offset=n,s.stop(),s.play(g))}let C=o.asset.volume;if(t&&(C=0),o.easeInDuration>0){const n=Math.min((e-o.start)/o.easeInDuration,1);C*=n}if(o.easeOutDuration>0){const n=Math.min((o.end-e)/o.easeOutDuration,1);C*=n}s.setVolume(C*this.director.weight)}else s.isPlaying&&s.stop()}this.lastTime=e}loadAudio(e,t=0,g=0){let I=null;const o=e-g,s=e+t;for(const C of this.models)if(this.isInTimeRange(C,o,s)){const n=this.audio[this.models.indexOf(C)],a=this.handleAudioLoading(C,n);a!==null&&(I===null&&(I=[]),I.push(a))}return I!==null?Promise.all(I):null}isInTimeRange(e,t,g){return t<=e.start&&g>=e.end||t>=e.start&&t<=e.end||g>=e.start&&g<=e.end}static dispose(){vQ._audioBuffers.clear()}handleAudioLoading(e,t){this._audioLoader||(this._audioLoader=new Yf);const g=this.getAudioFilePath(e.asset.clip);if(vQ._audioBuffers.get(g)){const o=vQ._audioBuffers.get(g);return o.then(s=>{s&&t.setBuffer(s)}),o}tn&&console.warn("LOAD audio track",g,this.director.sourceId);const I=new Promise((o,s)=>{this._audioLoader.load(g,C=>{t.setBuffer(C),o(C)},void 0,C=>{console.error("Error loading audio",C),o(null)})});return vQ._audioBuffers.set(g,I),I}};let Pr=vQ;r(Pr,"_audioBuffers",new Map);class ml extends kd{constructor(){super(...arguments);r(this,"models",[]);r(this,"didTrigger",[]);r(this,"receivers",[])}evaluate(e){var g;if(this.track.muted)return;const t=this.director.context.time.deltaTime*1.5;for(let I=0;I<this.models.length;I++){const o=this.models[I],s=this.didTrigger[I],C=o.time-e;let n=!1;if(o.retroActive)n=C<=1e-6;else{const a=Math.abs(C);(a===0||a>=1e-5&&a<t)&&(n=!0)}if(n){if(!s)if(tn&&console.log("Trigger signal",e,o.time,o),this.didTrigger[I]=!0,((g=this.receivers)==null?void 0:g.length)<=0)_E.invoke(o.asset);else for(const a of this.receivers)a&&a.invoke(o.asset)}else o.emitOnce||(this.didTrigger[I]=!1)}}}class fy extends kd{constructor(){super(...arguments);r(this,"models",[]);r(this,"timelines",[]);r(this,"_previousActiveModel",null)}resolveSourceObjects(e){for(let t=this.models.length-1;t>=0;t--){const I=this.models[t].asset;if(!I.sourceObject||typeof I.sourceObject!="object"){console.log("no source object, removing model",t,I),this.models.splice(t,1);continue}else{const o=IA.getComponent(I.sourceObject,Qn);this.timelines.push(o),o&&I.updateDirector&&(o.playOnAwake=!1)}}}evaluate(e){var t;this._previousActiveModel=null;for(let g=0;g<this.models.length;g++){const I=this.models[g],o=I.asset;if(e>=I.start&&e<=I.end){this._previousActiveModel=I;const s=this.getClipTime(e,I);if(o.controlActivation){const C=o.sourceObject;C.visible=!0}if(o.updateDirector){const C=this.timelines[g];C&&(C.isPlaying&&C.pause(),C.time=s,C.evaluate())}}else{const s=(t=this._previousActiveModel)==null?void 0:t.asset;if(o.controlActivation){const C=o.sourceObject;(s==null?void 0:s.sourceObject)!==C&&(C.visible=!1)}}}}}var DiA=Object.defineProperty,wiA=Object.getOwnPropertyDescriptor,c2=(i,A,e,t)=>{for(var g=t>1?void 0:t?wiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&DiA(A,e,g),g};class Fe{constructor(A){r(this,"_active",!0);r(this,"_value");r(this,"_valueRaw");r(this,"_defaultValue");r(this,"valueProcessor");r(this,"onValueChanged");this._value=A,this._defaultValue=A,this._valueRaw=A}get overrideState(){return this._active}set overrideState(A){if(this._active===A)return;this._active=A;const e=A?this._valueRaw:this._defaultValue;this.processValue(e,!0)}get value(){return this._valueRaw}set value(A){this.processValue(A,!1)}set defaultValue(A){this._defaultValue=A}__init(){this.processValue(this._valueRaw,!0)}processValue(A,e){if(A==null||!e&&this.testIfValueChanged(A)===!1)return;const t=this._value;!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,A=this._defaultValue,this._valueRaw=A):(this._valueRaw=A,this._active&&this.valueProcessor&&(A=this.valueProcessor(A)),this._value=A),this.onValueChanged&&this.onValueChanged(A,t,this)}testIfValueChanged(A){return this._valueRaw!==A}}c2([D()],Fe.prototype,"overrideState",1);c2([D()],Fe.prototype,"value",1);var yiA=Object.defineProperty,SiA=Object.getOwnPropertyDescriptor,kiA=(i,A,e,t)=>{for(var g=t>1?void 0:t?SiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&yiA(A,e,g),g};const GiA=sA("debugpost");class zg extends Ta{constructor(e=void 0){super();r(this,"active",!0);r(this,"_result");r(this,"_didCreateVolumeParameters",!1);if(e){this.ensureVolumeParameters();for(const t of Object.keys(e)){const g=e[t],I=this[t];I instanceof Fe&&(I.value=g)}}}onEnable(){this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){this.active=!1}init(){}apply(){var e;return this.ensureVolumeParameters(),this._result||(this._result=(e=this.onCreateEffect)==null?void 0:e.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){GiA&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(e=>e.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const e=Object.keys(this);for(const t of e){const g=this[t];g instanceof Fe&&g.__init()}}onAfterDeserialize(e,t){if(typeof e=="object"){const g=this.$serializedTypes;if(g){for(const I of Object.keys(g))if(g[I]===Fe){const s=e[I];if(s!==void 0){const C=this[I];C.value=s}}}}}onEditorModification(e){const t=e.propertyName;if(this[t]instanceof Fe){const g=e.value;return this[t].value=g,!0}}ensureVolumeParameters(){if(this._didCreateVolumeParameters)return;this._didCreateVolumeParameters=!0;const e=this.$serializedTypes;if(e)for(const t of Object.keys(e))e[t]===Fe&&(this[t]||(this[t]=new Fe))}}kiA([D()],zg.prototype,"active",2);var miA=Object.defineProperty,MiA=Object.getOwnPropertyDescriptor,RiA=(i,A,e,t)=>{for(var g=t>1?void 0:t?MiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&miA(A,e,g),g};const UiA=sA("debugpost"),Fm={};function Zo(i,A){Fm[i]=A}function FiA(i){return i.__type in Fm?Fm[i.__type]:(UiA&&i.__type&&console.warn("Unknown postprocessing type",i.__type,i),zg)}class Gd{constructor(){r(this,"components",[])}init(){var A;(A=this.components)==null||A.forEach(e=>e.init())}}RiA([JE([i=>FiA(i),zg])],Gd.prototype,"components",2);var NiA=Object.defineProperty,KiA=Object.getOwnPropertyDescriptor,JiA=(i,A,e,t)=>{for(var g=t>1?void 0:t?KiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&NiA(A,e,g),g};class md extends zg{constructor(){super(...arguments);r(this,"preset")}get typeName(){return"Antialiasing"}onCreateEffect(){const e=new AX({preset:dQ.HIGH,edgeDetectionMode:fR.DEPTH});return this.preset.onValueChanged=t=>{e.applyPreset(t)},e}}JiA([D(Fe)],md.prototype,"preset",2);Zo("Antialiasing",md);class Dy{constructor(){r(this,"files",[])}get extensionName(){return"Audio"}onExportObject(A,e,t){const g=IA.getComponents(A,Gi);if(g.length)for(const I of g){if(!I.clip||!I.playOnAwake)continue;const o=I.clip.split("/").pop();this.files.includes(I.clip)||this.files.push(I.clip),e.addEventListener("serialize",(s,C)=>{s.appendLine(),s.beginBlock(`def SpatialAudio "${e.name}"`),s.appendLine(`uniform asset filePath = @audio/${o}@`),s.appendLine(`uniform token auralMode = "${I.spatialBlend>0?"spatial":"nonSpatial"}"`),s.appendLine(`uniform token playbackMode = "${I.loop?"loopFromStage":"onceFromStart"}"`),s.appendLine(`uniform float gain = ${I.volume}`),s.closeBlock()})}}async onAfterSerialize(A){for(const e of this.files){const t=e.split("/").pop(),o=await(await(await fetch(e)).blob()).arrayBuffer(),s=new Uint8Array(o);A.files["audio/"+t]=s}}}const uD="noVoip",RI=sA("debugvoip"),qiA=sA("voip");class viA{constructor(A){r(this,"id");this.id=A}}class biA{constructor(A,e,t,g){r(this,"peer");r(this,"voip");r(this,"userId");r(this,"peerId");r(this,"call",null);r(this,"callErrorListener",null);r(this,"stream",null);this.voip=A,this.peer=e,this.userId=t,this.peerId=g}close(){var A;RI&&console.log("close voip call"),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.open&&this.call.close(),(A=this.stream)==null||A.getTracks().forEach(function(e){e.stop()})}updateMute(A){var t;if(!this.stream)return;const e=(t=this.stream)==null?void 0:t.getAudioTracks();for(const g of e)g.enabled=!A}async startVoipCall(){if(!await Rn.HasMicrophonePermissions()){console.warn("no permission to use microphone, can not start call");return}RI&&console.log("start voip call");try{this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}catch(e){console.error(e);return}this.updateMute(this.voip.muteOutput),RI&&console.log(this.stream),this.call=this.peer.call(this.peerId,this.stream,{metadata:{userId:this.userId}}),this.call.on("error",e=>{console.error(e)}),this.call.on("stream",e=>{RI&&console.log("received stream from remote again",e)}),this.peer.on("close",this.onCallClose.bind(this)),this.callErrorListener=e=>{var t;e.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(),(t=this.stream)==null||t.getTracks().forEach(function(g){g.stop()}),this.stream=null):console.error(e)},this.peer.on("error",this.callErrorListener)}onCallClose(A){RI&&console.log("call closed",A)}}class LiA{constructor(A,e,t){r(this,"voip");r(this,"call");r(this,"audio",null);r(this,"stream",null);r(this,"obj");r(this,"analyzer",null);r(this,"waitingForStart",!1);r(this,"closed",!1);r(this,"audioElement",null);this.voip=A,this.obj=e,this.call=t}get currentStream(){return this.stream}get currentAudio(){return this.audio}get currentAnalyzer(){return this.analyzer}openAudioStream(A){const e=A.getAudioTracks();for(const t of e)if(t.kind==="audio"&&t.readyState==="live"){this.open(t);return}console.warn("failed finding valid audio stream to begin call")}open(A){console.assert(A.kind==="audio","invalid track kind, expected audio but received "+A.kind),!this.waitingForStart&&(this.waitingForStart=!0,Gi.userInteractionRegistered||RI&&console.log("Incoming call, waiting for user interaction before opening audio"),Gi.registerWaitForAllowAudio(async()=>{if(this.call.open&&!this.closed){RI&&console.log("Setup audio and begin listening"),this.stream=new MediaStream([A]);const e=new zM;this.audio=new mw(e),this.audio.setVolume(this.voip.muteInput?0:1),this.audio.setMediaStreamSource(this.stream);const t=document.createElement("audio");this.audioElement=t,t.style.display="none",document.body.appendChild(t),t.srcObject=this.stream,t.sinkId!==void 0&&navigator.mediaDevices.enumerateDevices().then(g=>{if(t){console.log(g);for(const I of g)if(I.label==="Speakerphone"){t.sinkId=I.deviceId;break}}}),RI&&console.log("call is setup, you should hear something now"),this.analyzer=new gx(this.audio,32)}}))}close(){var A,e,t;this.closed=!0,(A=this.call)!=null&&A.open&&this.call.close(),(e=this.audio)==null||e.disconnect(),(t=this.stream)==null||t.getTracks().forEach(g=>{g.stop()}),this.stream=null,this.audioElement&&this.audioElement.remove()}}class Rn extends NA{constructor(){super(...arguments);r(this,"requireParam",!1);r(this,"peer",null);r(this,"model",null);r(this,"connections",{});r(this,"currentIncomingCalls",{});r(this,"_inputMuted",!1);r(this,"_outputMuted",!1)}set muteInput(e){var g;if(e===this._inputMuted||(this._inputMuted=e,!this.currentIncomingCalls))return;const t=this._inputMuted?0:1;for(const I in this.currentIncomingCalls){const o=this.currentIncomingCalls[I];(g=o==null?void 0:o.currentAudio)==null||g.setVolume(t)}}get muteInput(){return this._inputMuted}set muteOutput(e){if(e!==this._outputMuted&&(this._outputMuted=e,!!this.connections))for(const t in this.connections){const g=this.connections[t];g==null||g.updateMute(e)}}get muteOutput(){return this._outputMuted}getFrequency(e){if(e===null){for(const g in this.currentIncomingCalls){const I=this.currentIncomingCalls[g];if(I&&I.currentAnalyzer)return I.currentAnalyzer.getAverageFrequency()}return null}const t=this.currentIncomingCalls[e];return t&&t.currentAnalyzer?t.currentAnalyzer.getAverageFrequency():null}awake(){if(sA(uD)){console.log("VOIP is disabled by url parameter: "+uD);return}if(this.requireParam&&!qiA){console.debug("VOIP must be enabled explicitly by url parameter");return}if(nl()&&_C()){console.log("VOIP is currently not supported on Safari iOS");return}this.peer=aR(),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,this.context.connection.beginListen(Bi.JoinedRoom,e=>{navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).catch(t=>{console.error("Error initializing VoIP connection.",t)})}),this.context.connection.beginListen("peer-update-id",e=>{if(e.id!==this.context.connection.connectionId){const t=this.connections[e.id];if(t&&t.close(),this.peer&&this.context.connection.connectionId){const g=new biA(this,this.peer,this.context.connection.connectionId,e.peerId);this.connections[e.id]=g,g.startVoipCall()}}}),this.context.connection.beginListen(Bi.UserLeftRoom,e=>{const{userId:t}=e,g=this.connections[t];this.connections[t]=null,g&&g.close();const I=this.currentIncomingCalls[t];RI&&console.log("UserLeftRoom",e,t,I),I&&(I.close(),this.currentIncomingCalls[t]=null)}),this.peer.on("open",this.onOpenPeerConnection.bind(this))}onEnable(){}onDisable(){console.log("TODO: close all");for(const e in this.currentIncomingCalls)try{const t=this.currentIncomingCalls[e];t==null||t.close();const g=this.connections[e];g==null||g.close()}catch(t){console.error(t)}}async onOpenPeerConnection(e){RI&&console.log("Peer connection established and received id"),this.model=new viA(e),this.context.connection.send("peer-update-id",this.model,MI.OnRoomJoin),this.peer&&(this.peer.on("call",this.onReceiveCall.bind(this)),this.peer.on("connection",function(t){RI&&console.log("CONNECTION",t),t.on("data",function(g){RI&&console.log("Received",g)})}))}async onReceiveCall(e){if(!e)return;const{metadata:t}=e;console.assert(t.userId);const{userId:g}=t,I=this.currentIncomingCalls[g];if(I&&I.close(),RI&&console.log("received call"),await Rn.HasMicrophonePermissions())try{const o=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1});e.answer(o)}catch(o){console.error("Error initializing VoIP connection.",o)}else e.answer(null);this.currentIncomingCalls[g]=new LiA(this,this.gameObject,e),e.on("stream",o=>{var s;RI&&console.log("receive caller stream, will setup audio now"),(s=this.currentIncomingCalls[g])==null||s.openAudioStream(o)}),e.on("error",console.error)}static async HasMicrophonePermissions(){try{return(await navigator.permissions.query({name:"microphone"})).state!=="denied"}catch(e){return console.error("Error querying `microphone` permissions.",e),!1}}}var xiA=Object.defineProperty,TiA=Object.getOwnPropertyDescriptor,h2=(i,A,e,t)=>{for(var g=t>1?void 0:t?TiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&xiA(A,e,g),g};const YiA=sA("debugmouth");class Md extends NA{constructor(){super(...arguments);r(this,"idle",[]);r(this,"talking",[]);r(this,"marker",null);r(this,"voip",null);r(this,"lastMouthChangeTime",0);r(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=IA.findObjectOfType(Rn,this.context),this.marker||(this.marker=IA.getComponentInParent(this.gameObject,Cg))},3e3)}update(){var g;if(!this.voip||this.context.time.frameCount%10!==0)return;let e=((g=this.marker)==null?void 0:g.connectionId)??null;if(!e){YiA&&(e=null);return}const t=this.voip.getFrequency(e)??0;this.updateLips(t)}updateLips(e){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&e>30){this.lastMouthChangeTime=this.context.time.time;const t=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,t)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const t=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,t)}}}setMouthShapeActive(e,t){if(e){e!=this.idle?this.idle.map(g=>g.visible=!1):this.talking.map(g=>g.visible=!1);for(let g=0;g<e.length;g++){const I=e[g];I&&(I.visible=g===t)}}}}h2([D(FA)],Md.prototype,"idle",2);h2([D(FA)],Md.prototype,"talking",2);class SU extends NA{constructor(){super(...arguments);r(this,"voip",null);r(this,"marker",null);r(this,"_startPosition",null)}awake(){this.voip=IA.findObjectOfType(Rn,this.context),this.marker=IA.getComponentInParent(this.gameObject,Cg)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const e=this.marker.connectionId,t=this.voip.getFrequency(e);if(t==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const g=t/100;this.gameObject.position.y=this._startPosition.y+g*.07}}var HiA=Object.defineProperty,_iA=Object.getOwnPropertyDescriptor,wy=(i,A,e,t)=>{for(var g=t>1?void 0:t?_iA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&HiA(A,e,g),g};class QB extends NA{constructor(){super(...arguments);r(this,"eyes",[]);r(this,"lastBlinkTime",0);r(this,"blinkLength",0);r(this,"eyesOpen",!0);r(this,"state",null)}awake(){this.state=IA.getComponentInParent(this.gameObject,go)}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 t of this.eyes)t&&(t.visible=this.eyesOpen)}}}wy([D(FA)],QB.prototype,"eyes",2);wy([D()],QB.prototype,"lastBlinkTime",2);wy([D()],QB.prototype,"blinkLength",2);wy([D()],QB.prototype,"eyesOpen",2);var OiA=Object.defineProperty,PiA=Object.getOwnPropertyDescriptor,kU=(i,A,e,t)=>{for(var g=t>1?void 0:t?PiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&OiA(A,e,g),g},Hk;const l2=(Hk=class extends NA{constructor(){super(...arguments);r(this,"head",null);r(this,"eyes",null);r(this,"target",null);r(this,"brain",null);r(this,"vec",new w);r(this,"currentTargetPoint",new w)}awake(){this.brain||(this.brain=IA.getComponentInParent(this.gameObject,ul)),this.brain||(console.log("No look at brain found, adding it now"),this.brain=IA.addNewComponent(this.gameObject,ul)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const A=this.target;if(A&&this.head){const e=this.eyes;if(e){const t=ke(A);this.currentTargetPoint.lerp(t,this.context.time.deltaTime/.1);const g=ke(this.head),I=this.vec.copy(this.currentTargetPoint).sub(g).normalize();if(I.length()<.1)return;const o=l2.forward;if(o.set(0,0,1),o.applyQuaternion(Zi(this.head)),o.dot(I)>.45)for(let C=0;C<e.length;C++)e[C].lookAt(this.currentTargetPoint)}}}},r(Hk,"forward",new w(0,0,1)),Hk);let OE=l2;kU([D(FA)],OE.prototype,"head",2);kU([D(FA)],OE.prototype,"eyes",2);kU([D(FA)],OE.prototype,"target",2);var WiA=Object.defineProperty,ViA=Object.getOwnPropertyDescriptor,GU=(i,A,e,t)=>{for(var g=t>1?void 0:t?ViA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&WiA(A,e,g),g};class PE extends NA{constructor(){super(...arguments);r(this,"length",1);r(this,"depthTest",!0);r(this,"isGizmo",!0);r(this,"_axes",null)}onEnable(){if(this.isGizmo&&!rd)return;this._axes||(this._axes=new GE(this.length)),this.gameObject.add(this._axes);const e=this._axes.material;e&&e.depthTest!==void 0&&(e.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}GU([D()],PE.prototype,"length",2);GU([D()],PE.prototype,"depthTest",2);GU([D()],PE.prototype,"isGizmo",2);class mU extends NA{constructor(){super(...arguments);r(this,"from");r(this,"to");r(this,"hint");r(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const e=ke(this.to).clone(),t=ke(this.from).clone(),g=e.distanceTo(t),I=e.clone();I.sub(t);const o=t.clone();o.add(e),o.multiplyScalar(.5);const s=ke(this.hint).clone();s.sub(o);const C=new w;C.crossVectors(s,I),C.crossVectors(I,C),C.normalize();const n=g*.5,a=Math.max(this.desiredDistance,n),B=Math.sqrt(a*a-n*n),Q=C.clone();Q.multiplyScalar(B),Q.add(o),bi(this.gameObject,Q);const E=o.clone();E.sub(C),this.gameObject.lookAt(E)}}const ov=sA("debugusdz");class yy{constructor(){r(this,"behaviours",[]);r(this,"behaviourComponents",[]);r(this,"behaviourComponentsCopy",[])}get extensionName(){return"Behaviour"}addBehavior(A){this.behaviours.push(A)}onBeforeBuildDocument(A){const e=[];return A.root.traverse(t=>{IA.foreachComponent(t,g=>{var o;const I=g;if(typeof I.createBehaviours=="function"||typeof I.beforeCreateDocument=="function"||typeof I.afterCreateDocument=="function"||typeof I.afterSerialize=="function"){this.behaviourComponents.push(I);const s=(o=I.beforeCreateDocument)==null?void 0:o.call(I,this,A);s instanceof Promise&&e.push(s)}},!1)}),Promise.all(e)}onExportObject(A,e,t){var g;for(const I of this.behaviourComponents)(g=I.createBehaviours)==null||g.call(I,this,e,t)}onAfterBuildDocument(A){for(const e of this.behaviourComponents)typeof e.afterCreateDocument=="function"&&e.afterCreateDocument(this,A);this.behaviourComponentsCopy=this.behaviourComponents.slice(),this.behaviourComponents.length=0}onAfterHierarchy(A,e){var t;if((t=this.behaviours)!=null&&t.length){e.beginBlock('def Scope "Behaviors"');for(const g of this.behaviours)g.writeTo(this,A.document,e);e.closeBlock()}}async onAfterSerialize(A){ov&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const e of this.behaviourComponentsCopy)typeof e.afterSerialize=="function"&&(ov&&console.log("behaviour has afterSerialize",e),e.afterSerialize.constructor.name==="AsyncFunction"?await e.afterSerialize(this,A):e.afterSerialize(this,A))}}var ziA=Object.defineProperty,jiA=Object.getOwnPropertyDescriptor,MU=(i,A,e,t)=>{for(var g=t>1?void 0:t?jiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&ziA(A,e,g),g};class EB extends zg{constructor(){super(...arguments);r(this,"threshold");r(this,"intensity");r(this,"scatter");r(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=e=>e,this.intensity.valueProcessor=e=>e,this.scatter.valueProcessor=e=>1*Math.PI*(1-e)):(this.threshold.valueProcessor=e=>e,this.intensity.valueProcessor=e=>e,this.scatter.valueProcessor=e=>100*(1-e))}onCreateEffect(){let e;if(this.selectiveBloom){const t=e=new JY(this.context.scene,this.context.mainCamera,{blendFunction:Ye.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,intensity:this.intensity.value});t.inverted=!0}else e=new SR;return this.intensity.onValueChanged=t=>{e.intensity=t},this.threshold.onValueChanged=t=>{e.luminanceMaterial.threshold=t},this.scatter.onValueChanged=t=>{e.luminancePass.enabled=!0,e.luminanceMaterial.smoothing=t},e}}MU([D(Fe)],EB.prototype,"threshold",2);MU([D(Fe)],EB.prototype,"intensity",2);MU([D(Fe)],EB.prototype,"scatter",2);Zo("Bloom",EB);var ZiA=Object.defineProperty,XiA=Object.getOwnPropertyDescriptor,Gs=(i,A,e,t)=>{for(var g=t>1?void 0:t?XiA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&ZiA(A,e,g),g};class BC extends NA{constructor(){super(...arguments);r(this,"attachedRigidbody",null);r(this,"isTrigger",!1);r(this,"sharedMaterial");r(this,"updateProperties",()=>{var e;(e=this.context.physics.engine)==null||e.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(qt))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(qt))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(qt))}onDisable(){var e;(e=this.context.physics.engine)==null||e.removeBody(this)}get body(){var e;return(e=this.context.physics.engine)==null?void 0:e.getBody(this)}}Gs([D(qt)],BC.prototype,"attachedRigidbody",2);Gs([D()],BC.prototype,"isTrigger",2);Gs([D()],BC.prototype,"sharedMaterial",2);class Rd extends BC{constructor(){super(...arguments);r(this,"radius",.5);r(this,"center",new w(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addSphereCollider(this,this.center),eR(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),lx(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}Gs([Rg(),D()],Rd.prototype,"radius",2);Gs([D(w)],Rd.prototype,"center",2);class Ud extends BC{constructor(){super(...arguments);r(this,"size",new w(1,1,1));r(this,"center",new w(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addBoxCollider(this,this.center,this.size)}onValidate(){this.updateProperties()}}Gs([Rg(),D(w)],Ud.prototype,"size",2);Gs([D(w)],Ud.prototype,"center",2);class Fd extends BC{constructor(){super(...arguments);r(this,"sharedMesh");r(this,"convex",!1)}onEnable(){var e,t,g,I,o;if(super.onEnable(),(e=this.sharedMesh)!=null&&e.isMesh||this.gameObject instanceof wA&&(this.sharedMesh=this.gameObject),(t=this.sharedMesh)!=null&&t.isMesh)(g=this.context.physics.engine)==null||g.addMeshCollider(this,this.sharedMesh,this.convex,pg(this.gameObject));else{const s=this.sharedMesh;if(s!=null&&s.isGroup){console.warn(`MeshCollider mesh is a group "${(I=this.sharedMesh)==null?void 0:I.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 s.children){const n=s.children[C];n.isMesh&&((o=this.context.physics.engine)==null||o.addMeshCollider(this,n,this.convex,pg(this.gameObject)))}}}}}Gs([D()],Fd.prototype,"convex",2);class Ua extends BC{constructor(){super(...arguments);r(this,"center",new w(0,0,0));r(this,"radius",.5);r(this,"height",2)}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addCapsuleCollider(this,this.center,this.height,this.radius)}}Gs([D(w)],Ua.prototype,"center",2);Gs([D()],Ua.prototype,"radius",2);Gs([D()],Ua.prototype,"height",2);var $iA=Object.defineProperty,AgA=Object.getOwnPropertyDescriptor,RU=(i,A,e,t)=>{for(var g=t>1?void 0:t?AgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&$iA(A,e,g),g};class cB extends NA{constructor(){super(...arguments);r(this,"objectBounds",!1);r(this,"color");r(this,"isGizmo",!0);r(this,"_gizmoObject",null);r(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!rd||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new Rw(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=GH(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),xI.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){var e;for(;this._boxHelper;)(e=this._boxHelper)==null||e.update(),yield}}RU([D()],cB.prototype,"objectBounds",2);RU([D(SA)],cB.prototype,"color",2);RU([D()],cB.prototype,"isGizmo",2);var egA=Object.defineProperty,tgA=Object.getOwnPropertyDescriptor,Nd=(i,A,e,t)=>{for(var g=t>1?void 0:t?tgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&egA(A,e,g),g};const Ck=sA("debugui"),nk=sA("debuguilayout");class UU{constructor(){r(this,"width");r(this,"height")}}class FU{constructor(){r(this,"x");r(this,"y");r(this,"width");r(this,"height")}}const os=new w,Lc=new UA,lp=new GA,d2=class extends ps{constructor(){super(...arguments);r(this,"_anchoredPosition");r(this,"sizeDelta",new tA(100,100));r(this,"pivot",new tA(.5,.5));r(this,"anchorMin",new tA(0,0));r(this,"anchorMax",new tA(1,1));r(this,"lastMatrix");r(this,"rectBlock");r(this,"_transformNeedsUpdate",!1);r(this,"_initialPosition");r(this,"_parentRectTransform");r(this,"_lastUpdateFrame",-1);r(this,"_lastAnchoring");r(this,"_createdBlocks",[]);r(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 tA),this._anchoredPosition}set anchoredPosition(A){this._anchoredPosition=A}get width(){if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const A=this._parentRectTransform.width,e=this.anchorMax.x-this.anchorMin.x;let t=A*e;return t+=this.sizeDelta.x,t}return this.sizeDelta.x}get height(){if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const A=this._parentRectTransform.height,e=this.anchorMax.y-this.anchorMin.y;let t=A*e;return t+=this.sizeDelta.y,t}return this.sizeDelta.y}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new tA),this.lastMatrix=new UA,this.rectBlock=new FA,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,DQ(this,"_anchoredPosition",()=>{this.markDirty()}),DQ(this,"sizeDelta",()=>{this.markDirty()}),DQ(this,"pivot",()=>{this.markDirty()}),DQ(this,"anchorMin",()=>{this.markDirty()}),DQ(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var A;super.onEnable(),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(A=this.Canvas)==null||A.registerTransform(this)}onDisable(){var A;super.onDisable(),this.removeShadowComponent(),(A=this.Canvas)==null||A.unregisterTransform(this)}onParentRectTransformChanged(A){this._transformNeedsUpdate||this.onApplyTransform(nk?`${A.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(nk&&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(A){var g;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const e=this.shadowComponent;if(!e)return;this.gameObject.parent?this._parentRectTransform=IA.getComponentInParent(this.gameObject.parent,d2):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,nk&&console.warn("RectTransform → ApplyTransform",this.name+" because "+A),this.isRoot()?this.Root.screenspace||(e.rotation.y=Math.PI):(e.matrix.identity(),e.matrixAutoUpdate=!1,os.set(0,0,0),this.applyPivot(os),e.matrix.setPosition(os.x,os.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(lp.copy(this.gameObject.quaternion),lp.x*=-1,lp.z*=-1,Lc.makeRotationFromQuaternion(lp),e.matrix.premultiply(Lc)),os.set(0,0,0),this.applyAnchoring(os),(g=this.Canvas)!=null&&g.screenspace?os.z+=.1:os.z+=.01,Lc.identity(),Lc.setPosition(os.x,os.y,os.z),e.matrix.premultiply(Lc),e.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const t=!0;for(const I of uR(this.gameObject,ps,t,1)){if(I===this||!I.activeAndEnabled)continue;const o=I;o.onParentRectTransformChanged&&o.onParentRectTransformChanged(this)}}applyAnchoring(A){this._lastAnchoring||(this._lastAnchoring=new tA);const e=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=e.x,this.gameObject.position.y+=e.y,this._lastAnchoring.copy(this._anchoredPosition),A.x+=this._initialPosition.x-this.gameObject.position.x,A.y+=this._initialPosition.y-this.gameObject.position.y,A.z+=this._initialPosition.z-this.gameObject.position.z;const t=this._parentRectTransform;if(t){let g=0;const I=1-this.anchorMax.y-this.anchorMin.y;g-=t.height*.5*I,A.y+=g;let o=0;const s=1-this.anchorMax.x-this.anchorMin.x;o-=t.width*.5*s,A.x+=o}}applyPivot(A){if(this.pivot&&!this.isRoot()){const e=this.pivot.x-.5;A.x-=e*this.sizeDelta.x*this.gameObject.scale.x;const t=this.pivot.y-.5;A.y-=t*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const A={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(A),A}ensureValidSize(A,e=1e-4){return A.width<=0&&(A.width=e),A.height<=0&&(A.height=1e-4),A}createNewBlock(A){A={...this.getBasicOptions(),...A},Ck&&console.log(this.name,A);const e=new DU(A);return this._createdBlocks.push(e),e}createNewText(A){Ck&&console.log(A),A={...this.getBasicOptions(),...A},Ck&&console.log(this.name,A);const e=new B2(A);return this._createdTextBlocks.push(e),e}};let cI=d2;Nd([D(tA)],cI.prototype,"anchoredPosition",1);Nd([D(tA)],cI.prototype,"sizeDelta",2);Nd([D(tA)],cI.prototype,"pivot",2);Nd([D(tA)],cI.prototype,"anchorMin",2);Nd([D(tA)],cI.prototype,"anchorMax",2);class igA extends r2{constructor(A,e={}){super(A),A._simpleState__activeStates=[],A._simpleState__normalStyles={},A._simpleState__states=e,A._simpleState__statesProperties={};for(const t in e)for(const g in e[t])A._simpleState__statesProperties[g]||(A._simpleState__statesProperties[g]=[]),A._simpleState__statesProperties[g].push(t);for(const t of A._components)A._simpleState__statesProperties[t.id]&&(A._simpleState__normalStyles[t.id]=t.inline?t.inline:t._value);A.__overridedSet=A.set,A.set=this.storeSet.bind(A),A.renderStates=this.renderStates.bind(A),A.setupState=this.setupState.bind(A),A.setState=this.setState.bind(A),A.activatePseudoState=this.activatePseudoState.bind(A),A.deactivatePseudoState=this.deactivatePseudoState.bind(A),A.togglePseudoState=this.togglePseudoState.bind(A)}act(){}attach(){}detach(){}setupState(A,e){this._simpleState__states[A]=e;const t=[];for(const g in e)this._simpleState__statesProperties[g]||(this._simpleState__statesProperties[g]=[],t.push(g)),this._simpleState__statesProperties[g].push(A);for(const g of this._components)t.indexOf(g.id)>-1&&(this._simpleState__normalStyles[g.id]=g.inline?g.inline:g._value)}renderStates(){let A={...this._simpleState__normalStyles};for(const e in this._simpleState__states)this._simpleState__activeStates.indexOf(e)>-1&&(A={...A,...this._simpleState__states[e]});this.set(A,!1)}storeSet(A,e=!0){if(e)for(const t in A)this._simpleState__statesProperties[t]&&(this._simpleState__normalStyles[t]=A[t]);this.__overridedSet(A)}activatePseudoState(A){this._simpleState__activeStates.indexOf(A)===-1&&(this._simpleState__activeStates.push(A),this.renderStates())}deactivatePseudoState(A){const e=this._simpleState__activeStates.indexOf(A);e>-1&&(this._simpleState__activeStates.splice(e,1),this.renderStates())}togglePseudoState(A){const e=this._simpleState__activeStates.indexOf(A);e>-1?this._simpleState__activeStates.splice(e,1):this._simpleState__activeStates.push(A),this.renderStates()}setState(A){Array.isArray(A)?this._simpleState__activeStates=A:this._simpleState__activeStates=[A],this.renderStates()}}var ggA=Object.defineProperty,IgA=Object.getOwnPropertyDescriptor,u2=(i,A,e,t)=>{for(var g=t>1?void 0:t?IgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&ggA(A,e,g),g};class WE extends NA{constructor(){super(...arguments);r(this,"effectColor");r(this,"effectDistance")}}u2([D(St)],WE.prototype,"effectColor",2);u2([D(tA)],WE.prototype,"effectDistance",2);var ogA=Object.defineProperty,sgA=Object.getOwnPropertyDescriptor,p2=(i,A,e,t)=>{for(var g=t>1?void 0:t?sgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&ogA(A,e,g),g};const dp={backgroundColor:new SA(1,1,1),backgroundOpacity:1,borderColor:new SA(1,1,1),borderOpacity:1};var _k;const lf=(_k=class extends ps{constructor(){super(...arguments);r(this,"_alphaFactor",1);r(this,"raycastTarget",!0);r(this,"uiObject",null);r(this,"_color",null);r(this,"_rect",null);r(this,"_stateManager",null);r(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new St(1,1,1,1)),this._color}set color(A){(!this._color||this._color.r!==A.r||this._color.g!==A.g||this._color.b!==A.b||this._color.alpha!==A.alpha)&&(this._color||(this._color=new St(1,1,1,1)),this._color.copy(A))}setAlphaFactor(A){this._alphaFactor=A,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(dp.backgroundColor=this._color,dp.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(dp,this._alphaFactor),this.uiObject.set(dp),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=IA.getComponent(this.gameObject,cI)),!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 A;(A=this.uiObject)==null||A.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(A){this.makePanel(),this.uiObject&&(this.uiObject.setState(A),this==null||this.markDirty())}setupState(A){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new igA(this.uiObject)),this.uiObject.setupState(A.state,A.attributes))}setOptions(A){this.makePanel(),this.uiObject&&this.uiObject.set(A)}awake(){super.awake(),this.makePanel(),DQ(this,"_color",()=>niA(this,this.onColorChanged))}onEnable(){var A;super.onEnable(),this.uiObject&&((A=this.rectTransform.shadowComponent)==null||A.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 A=.015,e={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:A};this.onBeforeCreate(e),this.applyEffects(e),this.onCreate(e),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated()}onBeforeCreate(A){}onCreate(A){this.uiObject=this.rectTransform.createNewBlock(A),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(A,e=1){var g;const t=(g=this.gameObject)==null?void 0:g.getComponent(WE);t&&(t.effectDistance&&(A.borderWidth=Math.max(Math.abs(t.effectDistance.x),Math.abs(t.effectDistance.y))),t.effectColor&&(A.borderColor=t.effectColor,A.borderOpacity=t.effectColor.alpha*e))}async setTexture(A){if(this.setOptions({backgroundOpacity:0}),A){if(A.colorSpace===Ae){if(lf.textureCache.has(A))A=lf.textureCache.get(A);else if(!A.isRenderTargetTexture){const e=A.clone();e.colorSpace=Si,lf.textureCache.set(A,e),A=e}}this.setOptions({backgroundImage:A,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)}},r(_k,"textureCache",new Map),_k);let hB=lf;p2([D(St)],hB.prototype,"color",1);p2([D()],hB.prototype,"raycastTarget",2);class Kd extends hB{constructor(){super(...arguments);r(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var CgA=Object.defineProperty,ngA=Object.getOwnPropertyDescriptor,Sy=(i,A,e,t)=>{for(var g=t>1?void 0:t?ngA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&CgA(A,e,g),g};let NU=class{constructor(){r(this,"texture",null);r(this,"rect")}};Sy([D(qe)],NU.prototype,"texture",2);let VE=class extends Kd{constructor(){super(...arguments);r(this,"_sprite");r(this,"pixelsPerUnitMultiplier",1)}set image(e){this.sprite||(this.sprite=new NU),this.sprite.texture=e,this.onAfterCreated()}get image(){return this.sprite?this.sprite.texture:null}get sprite(){return this._sprite}set sprite(e){this._sprite!==e&&(this._sprite=e,this.onAfterCreated())}isBuiltinSprite(){var e,t,g,I,o,s,C,n;switch((t=(e=this.sprite)==null?void 0:e.texture)==null?void 0:t.name){case"InputFieldBackground":case"UISprite":case"Background":case"Knob":return!0}return((o=(I=(g=this.sprite)==null?void 0:g.texture)==null?void 0:I.image)==null?void 0:o.width)===32&&((n=(C=(s=this.sprite)==null?void 0:s.texture)==null?void 0:C.image)==null?void 0:n.height)===32}onBeforeCreate(e){var t,g;super.onBeforeCreate(e),this.isBuiltinSprite()&&(e.borderRadius=5/this.pixelsPerUnitMultiplier,((g=(t=this.sprite)==null?void 0:t.texture)==null?void 0:g.name)==="Knob"&&(e.borderRadius=999))}onAfterCreated(){var e;this.__didAwake&&(super.onAfterCreated(),!this.isBuiltinSprite()&&this.setTexture((e=this.sprite)==null?void 0:e.texture))}};Sy([D(NU)],VE.prototype,"sprite",1);Sy([D()],VE.prototype,"pixelsPerUnitMultiplier",2);class ky extends Kd{constructor(){super(...arguments);r(this,"_mainTexture")}get mainTexture(){return this._mainTexture}set mainTexture(e){this._mainTexture!==e&&(this._mainTexture=e,this.onAfterCreated())}onAfterCreated(){this.__didAwake&&(super.onAfterCreated(),this.setTexture(this.mainTexture))}}Sy([D(qe)],ky.prototype,"mainTexture",1);var agA=Object.defineProperty,rgA=Object.getOwnPropertyDescriptor,Eo=(i,A,e,t)=>{for(var g=t>1?void 0:t?rgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&agA(A,e,g),g};const aQ=sA("debugbutton");class lB{constructor(){r(this,"colorMultiplier");r(this,"disabledColor");r(this,"fadeDuration");r(this,"highlightedColor");r(this,"normalColor");r(this,"pressedColor");r(this,"selectedColor")}}Eo([D()],lB.prototype,"colorMultiplier",2);Eo([D(St)],lB.prototype,"disabledColor",2);Eo([D()],lB.prototype,"fadeDuration",2);Eo([D(St)],lB.prototype,"highlightedColor",2);Eo([D(St)],lB.prototype,"normalColor",2);Eo([D(St)],lB.prototype,"pressedColor",2);Eo([D(St)],lB.prototype,"selectedColor",2);class Un extends NA{constructor(){super(...arguments);r(this,"onClick");r(this,"_isHovered",!1);r(this,"colors");r(this,"transition");r(this,"animationTriggers");r(this,"animator");r(this,"_interactable",!0);r(this,"_requestedAnimatorTrigger");r(this,"_isInit",!1);r(this,"_image")}onPointerEnter(e){var t,g;aQ&&console.log("Button Enter",(t=this.animationTriggers)==null?void 0:t.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&&((g=this._image)==null||g.setState("hovered")),this.context.input.setCursorPointer())}onPointerExit(){var e,t;aQ&&console.log("Button Exit",(e=this.animationTriggers)==null?void 0:e.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&&((t=this._image)==null||t.setState("normal")),this.context.input.setCursorNormal())}onPointerDown(e){var t,g;aQ&&console.log("Button Down",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.pressedTrigger):this.transition===1&&this.colors&&((g=this._image)==null||g.setState("pressed")))}onPointerUp(e){var t,g;aQ&&console.warn("Button Up",(t=this.animationTriggers)==null?void 0:t.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&&((g=this._image)==null||g.setState(this._isHovered?"hovered":"normal")))}onPointerClick(e){!this.interactable||e.pointerId===void 0||e.pointerId!==0&&this.context.input.getIsMouse(e.pointerId)||(aQ&&(console.warn("Button Click",this.onClick),Di("CLICKED button "+this.name+" at "+this.context.time.frameCount)),this.onClick&&this.onClick.listenerCount>0&&(this.onClick.invoke(),e.use()))}set interactable(e){this._interactable=e,this._image&&(this._image.setInteractable(e),e?this._image.setState("normal"):this._image.setState("disabled"))}get interactable(){return this._interactable}set_interactable(e){this.interactable=e}awake(){super.awake(),aQ&&console.log(this),this._isInit=!1,this.init()}start(){var e;(e=this._image)==null||e.setInteractable(this.interactable)}onEnable(){super.onEnable()}*setAnimatorTriggerAtEndOfFrame(e){var t;this._requestedAnimatorTrigger=e,yield,yield,this._requestedAnimatorTrigger==e&&((t=this.animator)==null||t.SetTrigger(e))}init(){this._isInit||(this._isInit=!0,this._image=IA.getComponent(this.gameObject,VE),this._image&&(this.stateSetup(this._image),this.interactable?this._image.setState("normal"):this._image.setState("disabled")))}stateSetup(e){var E,c,l,d,h;e.setInteractable(this.interactable);const t=this.getFinalColor(e.color,(E=this.colors)==null?void 0:E.normalColor),g={state:"normal",attributes:{backgroundColor:t,backgroundOpacity:t.alpha}};e.setupState(g);const I=this.getFinalColor(e.color,(c=this.colors)==null?void 0:c.highlightedColor),o={state:"hovered",attributes:{backgroundColor:I,backgroundOpacity:I.alpha}};e.setupState(o);const s=this.getFinalColor(e.color,(l=this.colors)==null?void 0:l.pressedColor),C={state:"pressed",attributes:{backgroundColor:s,backgroundOpacity:s.alpha}};e.setupState(C);const n=this.getFinalColor(e.color,(d=this.colors)==null?void 0:d.selectedColor),a={state:"selected",attributes:{backgroundColor:n,backgroundOpacity:n.alpha}};e.setupState(a);const B=this.getFinalColor(e.color,(h=this.colors)==null?void 0:h.disabledColor),Q={state:"disabled",attributes:{backgroundColor:B,backgroundOpacity:B.alpha}};e.setupState(Q)}getFinalColor(e,t){return t?e.clone().multiply(t):e.clone()}}Eo([D(Dg)],Un.prototype,"onClick",2);Eo([D()],Un.prototype,"colors",2);Eo([D()],Un.prototype,"transition",2);Eo([D()],Un.prototype,"animationTriggers",2);Eo([D(Pg)],Un.prototype,"animator",2);Eo([D()],Un.prototype,"interactable",1);var BgA=Object.defineProperty,QgA=Object.getOwnPropertyDescriptor,Yi=(i,A,e,t)=>{for(var g=t>1?void 0:t?QgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&BgA(A,e,g),g};const sv=sA("debuguilayout");class Oa{constructor(){r(this,"left",0);r(this,"right",0);r(this,"top",0);r(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Yi([D()],Oa.prototype,"left",2);Yi([D()],Oa.prototype,"right",2);Yi([D()],Oa.prototype,"top",2);Yi([D()],Oa.prototype,"bottom",2);class co extends NA{constructor(){super(...arguments);r(this,"_rectTransform",null);r(this,"_needsUpdate",!1);r(this,"childAlignment",0);r(this,"reverseArrangement",!1);r(this,"spacing",0);r(this,"padding");r(this,"minWidth",0);r(this,"minHeight",0);r(this,"flexibleHeight",0);r(this,"flexibleWidth",0);r(this,"preferredHeight",0);r(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(e){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(sv&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){sv&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(cI);const e=this.gameObject.getComponentInParent(Sg);e&&e.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const e=this.gameObject.getComponentInParent(Sg);e&&e.unregisterLayoutGroup(this)}set m_Spacing(e){e!==this.spacing&&(this._needsUpdate=!0,this.spacing=e)}get m_Spacing(){return this.spacing}}Yi([D()],co.prototype,"childAlignment",2);Yi([D()],co.prototype,"reverseArrangement",2);Yi([D()],co.prototype,"spacing",2);Yi([D(Oa)],co.prototype,"padding",2);Yi([D()],co.prototype,"minWidth",2);Yi([D()],co.prototype,"minHeight",2);Yi([D()],co.prototype,"flexibleHeight",2);Yi([D()],co.prototype,"flexibleWidth",2);Yi([D()],co.prototype,"preferredHeight",2);Yi([D()],co.prototype,"preferredWidth",2);class Pa extends co{constructor(){super(...arguments);r(this,"childControlHeight",!0);r(this,"childControlWidth",!0);r(this,"childForceExpandHeight",!1);r(this,"childForceExpandWidth",!1);r(this,"childScaleHeight",!1);r(this,"childScaleWidth",!1)}onCalculateLayout(e){var R;const t=this.primaryAxis,g=e.width;let I=g;const o=e.height;let s=o;I-=this.padding.horizontal,s-=this.padding.vertical,t==="x"?this.padding.horizontal:this.padding.vertical;const C=t==="x",n=C?"y":"x",a=C?this.childControlWidth:this.childControlHeight,B=C?this.childControlHeight:this.childControlWidth,Q=C?this.childForceExpandWidth:this.childForceExpandHeight,E=C?this.childForceExpandHeight:this.childForceExpandWidth,c=C?s:I,l=C?g:o,d=.5*(C?this.childAlignment%3:Math.floor(this.childAlignment/3));let h=0;C?h+=this.padding.left:h+=this.padding.top;let p=0,u=0;for(let k=0;k<this.gameObject.children.length;k++){const m=this.gameObject.children[k],K=IA.getComponent(m,cI);K!=null&&K.activeAndEnabled&&(u+=1,C?p+=K.width:p+=K.height)}let f=0;const S=this.spacing*(u-1);if(Q||a){let k=0;C?k=I-=S:k=s-=S,u>0&&(f=k/u)}let G=0;G+=this.padding.left,G-=this.padding.right,d!==0&&(h=l-p,h*=d,h-=S*d,C?(h-=this.padding.right*d,h+=this.padding.left*(1-d),h<this.padding.left&&(h=this.padding.left)):(h-=this.padding.bottom*d,h+=this.padding.top*(1-d),h<this.padding.top&&(h=this.padding.top)));let M=1;for(let k=0;k<this.gameObject.children.length;k++){const m=this.gameObject.children[k],K=IA.getComponent(m,cI);if(K!=null&&K.activeAndEnabled){(R=K.pivot)==null||R.set(.5,.5),K.anchorMin.set(0,1),K.anchorMax.set(0,1);const Z=g*.5+G*.5;K.anchoredPosition.x!==Z&&(K.anchoredPosition.x=Z);const H=o*-.5;K.anchoredPosition.y!==H&&(K.anchoredPosition.y=H),E&&B&&K.sizeDelta[n]!==c&&(K.sizeDelta[n]=c),Q&&a&&K.sizeDelta[t]!==f&&(K.sizeDelta[t]=f);const _=C?K.width:K.height,j=_*.5;if(h+=j,Q){const v=f*M-f*.5;v>h&&(h=v-f*.5+_+this.padding.left,h-=j)}let x=h;t==="y"&&(x=-x),K.anchoredPosition[t]!==x&&(K.anchoredPosition[t]=x),h+=j,h+=this.spacing,M+=1}}}}Yi([D()],Pa.prototype,"childControlHeight",2);Yi([D()],Pa.prototype,"childControlWidth",2);Yi([D()],Pa.prototype,"childForceExpandHeight",2);Yi([D()],Pa.prototype,"childForceExpandWidth",2);Yi([D()],Pa.prototype,"childScaleHeight",2);Yi([D()],Pa.prototype,"childScaleWidth",2);class KU extends Pa{get primaryAxis(){return"y"}}class JU extends Pa{get primaryAxis(){return"x"}}class qU extends co{onCalculateLayout(){}}var EgA=Object.defineProperty,cgA=Object.getOwnPropertyDescriptor,QC=(i,A,e,t)=>{for(var g=t>1?void 0:t?cgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&EgA(A,e,g),g},f2=(i=>(i[i.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",i[i.ScreenSpaceCamera=1]="ScreenSpaceCamera",i[i.WorldSpace=2]="WorldSpace",i[i.Undefined=-1]="Undefined",i))(f2||{});const ak=sA("debuguilayout"),D2=class extends yd{constructor(){super(...arguments);r(this,"_renderOnTop");r(this,"_depthWrite",!1);r(this,"_doubleSided",!0);r(this,"_castShadows",!1);r(this,"_receiveShadows",!1);r(this,"_renderMode",-1);r(this,"_rootCanvas");r(this,"_scaleFactor",1);r(this,"worldCamera");r(this,"planeDistance",-1);r(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this));r(this,"previousParent",null);r(this,"_lastMatrixWorld",null);r(this,"_rectTransforms",[]);r(this,"_layoutGroups",new Map);r(this,"_receivers",[]);r(this,"onBeforeRenderRoutine",()=>{var A,e,t,g;if(this.context.isInVR){this.onUpdateRenderMode(),this.handleLayoutUpdates(),(A=this.shadowComponent)==null||A.updateMatrixWorld(!0),(e=this.shadowComponent)==null||e.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),nI.ensureUpdateMeshUI(ok,this.context,!0);return}this.previousParent=this.gameObject.parent,this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(t=this.shadowComponent)==null||t.updateMatrixWorld(!0),(g=this.shadowComponent)==null||g.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),nI.ensureUpdateMeshUI(ok,this.context))});r(this,"onAfterRenderRoutine",()=>{var A,e;if(!this.context.isInVR){if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const I=this.context.mainCamera;I==null||I.add(this.gameObject)}else this.previousParent.add(this.gameObject);const t=this.context.renderer.autoClear,g=this.context.renderer.autoClearColor;this.context.renderer.autoClear=!1,this.context.renderer.autoClearColor=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(A=this.shadowComponent)==null||A.updateMatrixWorld(!0),this.invokeBeforeRenderEvents(),nI.ensureUpdateMeshUI(ok,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=t,this.context.renderer.autoClearColor=g,this.previousParent.add(this.gameObject)}(e=this._lastMatrixWorld)==null||e.copy(this.gameObject.matrixWorld)}});r(this,"_updateRenderSettingsRoutine");r(this,"_activeRenderMode",-1);r(this,"_lastWidth",-1);r(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(A){A!==this._renderOnTop&&(this._renderOnTop=A,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(A){this._depthWrite!==A&&(this._depthWrite=A,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(A){this._doubleSided!==A&&(this._doubleSided=A,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(A){this._castShadows!==A&&(this._castShadows=A,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(A){this._receiveShadows!==A&&(this._receiveShadows=A,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(A){this._renderMode!==A&&(this._renderMode=A,this.onRenderSettingsChanged())}set rootCanvas(A){this._rootCanvas instanceof D2||(this._rootCanvas=A)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(A){this._scaleFactor=A}awake(){var A;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,ak&&console.log("Canvas.Awake()",((A=this.previousParent)==null?void 0:A.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new UA,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 A=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);A!==-1&&this.context.pre_render_callbacks.splice(A,1);const e=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);e!==-1&&this.context.post_render_callbacks.splice(e,1)}registerTransform(A){this._rectTransforms.push(A)}unregisterTransform(A){const e=this._rectTransforms.indexOf(A);e!==-1&&this._rectTransforms.splice(e,1)}registerLayoutGroup(A){const e=A.gameObject;this._layoutGroups.set(e,A)}unregisterLayoutGroup(A){const e=A.gameObject;this._layoutGroups.delete(e)}registerEventReceiver(A){this._receivers.push(A)}unregisterEventReceiver(A){const e=this._receivers.indexOf(A);e!==-1&&this._receivers.splice(e,1)}invokeBeforeRenderEvents(){var A;for(const e of this._receivers)(A=e.onBeforeCanvasRender)==null||A.call(e,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new UA);const A=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);ak&&A&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const e=!1;for(const t of this._rectTransforms){A&&t.markDirty();let g=this._layoutGroups.get(t.gameObject);t.isDirty&&!g&&(g=t.gameObject.getComponentInParent(co)),(t.isDirty||g!=null&&g.isDirty)&&(ak&&!e&&console.log("CANVAS UPDATE ### "+t.name+" ##################################### "+this.context.time.frame),g==null||g.updateLayout(),t.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),xI.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),lD(this.shadowComponent,this);for(const A of IA.getComponentsInChildren(this.gameObject,ps))lD(A.shadowComponent,this)}}onUpdateRenderMode(A=!1){if(!A&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let e=this.context.mainCameraComponent,t=10;switch(e&&e.nearClipPlane>0&&e.farClipPlane>0&&(t=ie.lerp(e.nearClipPlane,e.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(e=this.worldCamera),this.planeDistance>0&&(t=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!e)return;const g=t+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-g,this.gameObject.quaternion.identity();const I=this.gameObject.getComponent(cI);let o=!1;I.sizeDelta.x!==this.context.domWidth&&(o=!0),I.sizeDelta.y!==this.context.domHeight&&(o=!0);const s=e.fieldOfView*Math.PI/180,C=2*Math.tan(s/2)*Math.abs(g);this.gameObject.scale.x=C/this.context.domHeight,this.gameObject.scale.y=C/this.context.domHeight,this.gameObject.scale.z=.01,o&&(I.sizeDelta.x=this.context.domWidth,I.sizeDelta.y=this.context.domHeight,I==null||I.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let Sg=D2;QC([D()],Sg.prototype,"renderOnTop",1);QC([D()],Sg.prototype,"depthWrite",1);QC([D()],Sg.prototype,"doubleSided",1);QC([D()],Sg.prototype,"castShadows",1);QC([D()],Sg.prototype,"receiveShadows",1);QC([D()],Sg.prototype,"renderMode",1);QC([D(Sg)],Sg.prototype,"rootCanvas",1);QC([D()],Sg.prototype,"scaleFactor",1);QC([D(Ht)],Sg.prototype,"worldCamera",2);QC([D()],Sg.prototype,"planeDistance",2);var hgA=Object.defineProperty,lgA=Object.getOwnPropertyDescriptor,vU=(i,A,e,t)=>{for(var g=t>1?void 0:t?lgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&hgA(A,e,g),g};class Fa extends NA{constructor(){super(...arguments);r(this,"_alpha",1);r(this,"interactable",!0);r(this,"blocksRaycasts",!0);r(this,"_isDirty",!1);r(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(e){e!==this._alpha&&(this._alpha=e,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),xI.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){for(const e of IA.getComponentsInChildren(this.gameObject,ps,this._buffer)){const t=e;t.setAlphaFactor&&t.setAlphaFactor(this._alpha)}}}vU([D()],Fa.prototype,"alpha",1);vU([D()],Fa.prototype,"interactable",2);vU([D()],Fa.prototype,"blocksRaycasts",2);var dgA=Object.defineProperty,ugA=Object.getOwnPropertyDescriptor,_t=(i,A,e,t)=>{for(var g=t>1?void 0:t?ugA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&dgA(A,e,g),g};class dB extends NA{constructor(){super(...arguments);r(this,"object");r(this,"target");r(this,"duration",1);r(this,"relativeMotion",!1);r(this,"coroutine",null);r(this,"targetPos",new w);r(this,"targetRot",new GA);r(this,"targetScale",new w)}*moveToTarget(){if(!this.target||!this.object)return;const e=ke(this.object).clone(),t=ke(this.target).clone(),g=Zi(this.object).clone(),I=Zi(this.target).clone(),o=pg(this.object).clone(),s=pg(this.target).clone(),C=e.distanceTo(t),n=g.angleTo(I),a=o.distanceTo(s);if(C<.01&&n<.01&&a<.01){bi(this.object,t),LI(this.object,I),vG(this.object,s),this.coroutine=null;return}let B=0,Q=0;for(;B<1;)B+=this.context.time.deltaTime/this.duration,B>1&&(B=1),Q=B<.5?4*B*B*B:1-Math.pow(-2*B+2,3)/2,this.targetPos.lerpVectors(e,t,Q),this.targetRot.slerpQuaternions(g,I,Q),this.targetScale.lerpVectors(o,s,Q),bi(this.object,this.targetPos),LI(this.object,this.targetRot),vG(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const e=this.object.position.clone(),t=this.object.quaternion.clone(),g=this.object.scale.clone(),I=this.target.position.clone(),o=this.target.quaternion.clone(),s=this.target.scale.clone();I.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(I),this.targetRot.copy(this.object.quaternion).multiply(o),this.targetScale.copy(this.object.scale).multiply(s);let C=0,n=0;for(;C<1;)C+=this.context.time.deltaTime/this.duration,C>1&&(C=1),n=C<.5?4*C*C*C:1-Math.pow(-2*C+2,3)/2,this.object.position.lerpVectors(e,this.targetPos,n),this.object.quaternion.slerpQuaternions(t,this.targetRot,n),this.object.scale.lerpVectors(g,this.targetScale,n),yield;this.coroutine=null}onPointerClick(e){e.use(),this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}beforeCreateDocument(e){var t;if(this.target&&this.object&&this.gameObject){const g=new wg("Move to "+((t=this.target)==null?void 0:t.name),vI.tapTrigger(this.gameObject),lt.transformAction(this.object,this.target,this.duration,this.relativeMotion?fm.Relative:fm.Absolute));e.addBehavior(g)}}}_t([D(FA)],dB.prototype,"object",2);_t([D(FA)],dB.prototype,"target",2);_t([D()],dB.prototype,"duration",2);_t([D()],dB.prototype,"relativeMotion",2);var Lp;const JC=(Lp=class extends NA{constructor(){super(...arguments);r(this,"materialToSwitch");r(this,"variantMaterial");r(this,"fadeDuration",0);r(this,"_objectsWithThisMaterial",[]);r(this,"selfModel");r(this,"targetModels")}awake(){if(this.variantMaterial&&this.materialToSwitch){const A=IA.findObjectsOfType(jt);for(const e of A)for(let t=0;t<e.sharedMaterials.length;t++){const g=e.sharedMaterials[t];if(g===this.materialToSwitch){if(e.gameObject instanceof wA)this._objectsWithThisMaterial.push(e.gameObject);else if(e.gameObject instanceof UI)for(const I of e.gameObject.children)I instanceof wA&&I.material===g&&this._objectsWithThisMaterial.push(I);break}}}}onPointerClick(A){if(A.use(),!!this.variantMaterial)for(let e=0;e<this._objectsWithThisMaterial.length;e++){const t=this._objectsWithThisMaterial[e];t.material=this.variantMaterial}}async beforeCreateDocument(A,e){this.targetModels=[],JC._materialTriggersPerId={},JC.variantSwitchIndex=0,this.materialToSwitch&&await Ao.assignTextureLOD(this.context,this.sourceId,this.materialToSwitch,0),this.variantMaterial&&await Ao.assignTextureLOD(this.context,this.sourceId,this.variantMaterial,0)}createBehaviours(A,e,t){this._objectsWithThisMaterial.find(I=>I.uuid===e.uuid)&&this.targetModels.push(e),this.gameObject.uuid===e.uuid&&(this.selfModel=e,this.materialToSwitch&&(JC._materialTriggersPerId[this.materialToSwitch.uuid]||(JC._materialTriggersPerId[this.materialToSwitch.uuid]=[]),JC._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(A,e){if(!this.materialToSwitch)return;const t=JC._materialTriggersPerId[this.materialToSwitch.uuid];if(t){const g={};for(const o of t){const s=o.createVariants();s&&s.length>0&&(g[o.selfModel.uuid]=s)}const I=[];for(const o of t){for(const s in g)s!==o.selfModel.uuid&&I.push(g[s]);o.createAndAttachBehaviors(A,g[o.selfModel.uuid],I)}}delete JC._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(A,e,t){const g=[],I=[],o=Math.max(0,this.fadeDuration);for(const s of this.targetModels){const C=lt.fadeAction(s,o,!1);I.push(C)}for(const s of t)I.push(lt.fadeAction(s,o,!1));for(const s of e)g.push(lt.fadeAction(s,o,!1)),I.push(lt.fadeAction(s,o,!0));A.addBehavior(new wg("Select "+this.selfModel.name,vI.tapTrigger(this.selfModel),lt.parallel(...I))),A.addBehavior(new wg("Start hidden "+this.selfModel.name,vI.sceneStartTrigger(),lt.parallel(...g)))}createVariants(){if(!this.variantMaterial)return null;const A=[];for(const e of this.targetModels){const t=e.clone();t.name+=" variant_"+this.variantMaterial.name+"_"+JC.variantSwitchIndex++,t.name=t.name.replace(/\s/g,"_"),t.material=this.variantMaterial,t.geometry=e.geometry,t.matrix=e.matrix,(!e.parent||!e.parent.isEmpty())&&NI.createEmptyParent(e),e.parent&&e.parent.add(t),A.push(t)}return A}},r(Lp,"_materialTriggersPerId",{}),r(Lp,"variantSwitchIndex",0),Lp);let zE=JC;_t([D(ve)],zE.prototype,"materialToSwitch",2);_t([D(ve)],zE.prototype,"variantMaterial",2);_t([D()],zE.prototype,"fadeDuration",2);class jE extends NA{constructor(){super(...arguments);r(this,"target");r(this,"toggleOnClick",!1);r(this,"targetState",!0);r(this,"hideSelf",!0);r(this,"selfModel");r(this,"otherModel");r(this,"toggleModel");r(this,"stateBeforeCreatingDocument",!1)}onPointerClick(e){e.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(e,t,g){t.uuid===this.gameObject.uuid&&(this.selfModel=t)}beforeCreateDocument(){this.stateBeforeCreatingDocument=this.gameObject.visible,this.gameObject.visible=!0}afterCreateDocument(e,t){if(this.target){if(this.otherModel=t.document.findById(this.target.uuid),this.selfModel&&this.otherModel){let g=this.hideSelf;this.targetState,this.toggleOnClick&&(g=!0,this.target.visible,(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&FH.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.clone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel));const I=[];if(g&&I.push(lt.fadeAction(this.selfModel,0,!1)),this.toggleModel&&I.push(lt.fadeAction(this.toggleModel,0,!0)),I.push(lt.fadeAction(this.otherModel,0,this.targetState)),e.addBehavior(new wg("Toggle_"+this.selfModel.name+"_hideSelf",vI.tapTrigger(this.selfModel),lt.sequence(...I))),this.toggleOnClick&&this.toggleModel){const o=[];o.push(lt.fadeAction(this.toggleModel,0,!1)),o.push(lt.fadeAction(this.selfModel,0,!0)),o.push(lt.fadeAction(this.otherModel,0,!this.targetState)),e.addBehavior(new wg("Toggle_"+this.selfModel.name+"_toggleSelf",vI.tapTrigger(this.toggleModel),lt.sequence(...o))),e.addBehavior(new wg("HideOnStart_"+this.gameObject.name,vI.sceneStartTrigger(),lt.fadeAction(this.toggleModel,0,!1)))}}this.gameObject.visible=this.stateBeforeCreatingDocument}}}_t([D(FA)],jE.prototype,"target",2);_t([D()],jE.prototype,"targetState",2);_t([D()],jE.prototype,"hideSelf",2);class bU extends NA{start(){this.gameObject.visible=!1}createBehaviours(A,e,t){e.uuid===this.gameObject.uuid&&A.addBehavior(new wg("HideOnStart_"+this.gameObject.name,vI.sceneStartTrigger(),lt.fadeAction(e,0,!1)))}beforeCreateDocument(){this.gameObject.visible=!0}afterCreateDocument(){this.gameObject.visible=!1}}class ZE extends NA{constructor(){super(...arguments);r(this,"target");r(this,"duration",.5);r(this,"motionType",YR.bounce)}beforeCreateDocument(){}createBehaviours(e,t,g){if(this.target&&t.uuid===this.gameObject.uuid){const I=new wg("emphasize "+this.name,vI.tapTrigger(this.gameObject),lt.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));e.addBehavior(I)}}afterCreateDocument(e,t){}}_t([D()],ZE.prototype,"target",2);_t([D()],ZE.prototype,"duration",2);_t([D()],ZE.prototype,"motionType",2);class XE extends NA{constructor(){super(...arguments);r(this,"target");r(this,"clip","");r(this,"toggleOnClick",!1)}onPointerClick(e){if(e.use(),!(!this.target&&!this.clip)){if(!this.target){const t=this.gameObject.addNewComponent(Gi);t&&(t.spatialBlend=1,t.volume=1,t.loop=!1,this.target=t)}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(e,t,g){if(!(!this.target&&!this.clip)&&t.uuid===this.gameObject.uuid){const I=this.clip?this.clip:this.target?this.target.clip:void 0;if(!I)return;const o=this.target?this.target.gameObject:this.gameObject,s=I.split("/").pop(),C=this.target?this.target.volume:1,n=this.target&&this.target.spatialBlend==0?Dm.NonSpatial:Dm.Spatial,a=new wg("playAudio "+this.name,vI.tapTrigger(this.gameObject),lt.playAudioAction(o,"audio/"+s,bH.Play,C,n));e.addBehavior(a)}}async afterSerialize(e,t){if(!this.target&&!this.clip)return;const g=this.clip?this.clip:this.target?this.target.clip:void 0;if(!g)return;const I=g.split("/").pop(),C=await(await(await fetch(this.clip)).blob()).arrayBuffer(),n=new Uint8Array(C);t.files["audio/"+I]=n}}_t([D(Gi)],XE.prototype,"target",2);_t([D(URL)],XE.prototype,"clip",2);_t([D()],XE.prototype,"toggleOnClick",2);var Ok;const wQ=(Ok=class extends NA{constructor(){super(...arguments);r(this,"target");r(this,"animator");r(this,"stateName");r(this,"stateNameAfterPlaying");r(this,"loopAfterPlaying",!1);r(this,"selfModel");r(this,"stateAnimationModel");r(this,"stateAnimation");r(this,"stateAfterPlayingAnimationModel");r(this,"stateAfterPlayingAnimation")}onPointerClick(A){var e;A.use(),this.target&&this.stateName&&((e=this.animator)==null||e.play(this.stateName,0,0,.1))}createBehaviours(A,e,t){e.uuid===this.gameObject.uuid&&(this.selfModel=e)}onAfterHierarchy(){wQ.animationActions=[]}afterCreateDocument(A,e){if(!this.stateAnimation||!this.stateAnimationModel)return;e.document.traverse(g=>{var I,o;if(g.uuid===((I=this.target)==null?void 0:I.uuid)&&this.stateAnimation){const s=[];let C=wQ.animationActions.find(a=>a.affectedObjects==g&&a.start==this.stateAnimation.start&&a.duration==this.stateAnimation.duration);if(C||(C=lt.startAnimationAction(g,this.stateAnimation.start,this.stateAnimation.duration),wQ.animationActions.push(C)),s.push(C),this.stateAfterPlayingAnimation&&this.stateAfterPlayingAnimationModel){let a=wQ.animationActions.find(Q=>Q.affectedObjects==g&&Q.start==this.stateAfterPlayingAnimation.start&&Q.duration==this.stateAfterPlayingAnimation.duration);a||(a=lt.startAnimationAction(g,this.stateAfterPlayingAnimation.start,this.stateAfterPlayingAnimation.duration),wQ.animationActions.push(a));const B=lt.sequence(a);this.loopAfterPlaying&&B.makeLooping(),s.push(B)}const n=new wg("tap "+this.name+" for "+this.stateName+" on "+((o=this.target)==null?void 0:o.name),vI.tapTrigger(this.selfModel),lt.sequence(...s));A.addBehavior(n)}})}createAnimation(A,e,t){var g,I,o,s,C;if(this.target&&this.animator){const n=(I=(g=this.animator)==null?void 0:g.runtimeAnimatorController)==null?void 0:I.findState(this.stateName);if(!((o=n==null?void 0:n.motion)!=null&&o.clip)){rt()&&console.warn("No clip found for state "+this.stateName);return}this.stateAnimationModel=e,this.stateAnimation=A.registerAnimation(this.target,n==null?void 0:n.motion.clip);const a=(C=(s=this.animator)==null?void 0:s.runtimeAnimatorController)==null?void 0:C.findState(this.stateNameAfterPlaying);this.stateAfterPlayingAnimationModel=e,this.stateAfterPlayingAnimation=A.registerAnimation(this.target,a==null?void 0:a.motion.clip)}}},r(Ok,"animationActions",[]),Ok);let Wa=wQ;_t([D(FA)],Wa.prototype,"target",2);_t([D(Pg)],Wa.prototype,"animator",2);_t([D()],Wa.prototype,"stateName",2);_t([D()],Wa.prototype,"stateNameAfterPlaying",2);_t([D()],Wa.prototype,"loopAfterPlaying",2);class $E extends NA{constructor(){super(...arguments);r(this,"target")}getType(){}getDuration(){}}_t([D(FA)],$E.prototype,"target",2);class Jd extends NA{constructor(){super(...arguments);r(this,"target")}}_t([D($E)],Jd.prototype,"target",2);class qd extends $E{constructor(){super(...arguments);r(this,"type",1);r(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}_t([D()],qd.prototype,"type",2);_t([D()],qd.prototype,"duration",2);class LU extends Jd{}var pgA=Object.defineProperty,fgA=Object.getOwnPropertyDescriptor,Fn=(i,A,e,t)=>{for(var g=t>1?void 0:t?fgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&pgA(A,e,g),g};class uB extends NA{constructor(){super(...arguments);r(this,"center",new w(0,0,0));r(this,"radius",.5);r(this,"height",2);r(this,"_rigidbody",null);r(this,"_activeGroundCollisions")}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(qt),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(qt)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const e=this.rigidbody;let t=this.gameObject.getComponent(Ua);t||(t=this.gameObject.addNewComponent(Ua)),t.center.copy(this.center),t.radius=this.radius,t.height=this.height;const g=new w(0,0,1),I=new w(1,0,0),o=new w(0,1,0),s=this.gameObject.getWorldDirection(new w);s.y=0;const C=I.dot(s)<0?-1:1,n=g.angleTo(s)*C;this.gameObject.setRotationFromAxisAngle(o,n),e.lockRotationX=!0,e.lockRotationY=!0,e.lockRotationZ=!0}move(e){this.gameObject.position.add(e)}onCollisionEnter(e){for(const t of e.contacts)if(t.normal.y>.1){this._activeGroundCollisions.add(e);break}}onCollisionExit(e){this._activeGroundCollisions.delete(e)}get isGrounded(){return this._activeGroundCollisions.size>0}}Fn([D(w)],uB.prototype,"center",2);Fn([D()],uB.prototype,"radius",2);Fn([D()],uB.prototype,"height",2);class Nn extends NA{constructor(){super(...arguments);r(this,"controller");r(this,"movementSpeed",2);r(this,"rotationSpeed",2);r(this,"jumpForce",1);r(this,"doubleJumpForce",2);r(this,"animator");r(this,"lookForward",!0);r(this,"lookInput",new tA(0,0));r(this,"moveInput",new tA(0,0));r(this,"jumpInput",!1);r(this,"_currentSpeed",new w(0,0,0));r(this,"_currentAngularSpeed",new w(0,0,0));r(this,"_temp",new w(0,0,0));r(this,"_jumpCount",0);r(this,"_currentRotation");r(this,"_raycastOptions",new Wo)}awake(){this._currentRotation=new GA}update(){const e=this.context.input;e.isKeyPressed("KeyW")?this.moveInput.y+=1:e.isKeyPressed("KeyS")&&(this.moveInput.y-=1),e.isKeyPressed("KeyD")?this.lookInput.x+=1:e.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=e.isKeyDown("Space"))}move(e){this.moveInput.add(e)}look(e){this.lookInput.add(e)}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(e,t,g){var I,o,s,C,n,a,B,Q,E,c,l;if((I=this.controller)!=null&&I.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((o=this.animator)==null||o.setBool("doubleJump",!1))),this._currentSpeed.z+=e.y*this.movementSpeed*this.context.time.deltaTime,(s=this.animator)==null||s.setBool("running",e.length()>.01),(n=this.animator)==null||n.setBool("jumping",((C=this.controller)==null?void 0:C.isGrounded)===!0&&g),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+=ie.toRadians(-t.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const d=this.context.mainCameraComponent.forward;d.y=0,d.normalize(),this._currentRotation.setFromUnitVectors(new w(0,0,1),d),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&&g&&this.jumpForce>0){let d=(a=this.controller)==null?void 0:a.isGrounded;if(this.doubleJumpForce>0&&!((B=this.controller)!=null&&B.isGrounded)&&this._jumpCount===1&&(d=!0,(Q=this.animator)==null||Q.setBool("doubleJump",!0)),d){this._jumpCount+=1;const h=this.controller.rigidbody,p=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;h.applyImpulse(new w(0,1,0).multiplyScalar(p))}}if(this.controller){const d=(E=this.controller)==null?void 0:E.rigidbody.getVelocity().y;if(d<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new nC),this._raycastOptions.ray.origin.copy(ke(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const h=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const p=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(h),(p.length&&p[0].distance>2||d<-10)&&((c=this.animator)==null||c.setBool("falling",!0))}else(l=this.animator)==null||l.setBool("falling",!1)}}}Fn([D(uB)],Nn.prototype,"controller",2);Fn([D()],Nn.prototype,"movementSpeed",2);Fn([D()],Nn.prototype,"rotationSpeed",2);Fn([D()],Nn.prototype,"jumpForce",2);Fn([D()],Nn.prototype,"doubleJumpForce",2);Fn([D(Pg)],Nn.prototype,"animator",2);var DgA=Object.defineProperty,wgA=Object.getOwnPropertyDescriptor,ygA=(i,A,e,t)=>{for(var g=t>1?void 0:t?wgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&DgA(A,e,g),g};class vd extends zg{constructor(){super(...arguments);r(this,"intensity")}get typeName(){return"ChromaticAberration"}init(){this.intensity.defaultValue=0}onCreateEffect(){const e=new UY;return e.offset=new tA(0,0),e.radialModulation=!0,e.modulationOffset=.15,this.intensity.valueProcessor=t=>t*.02,this.intensity.onValueChanged=t=>{e.offset.x=-t,e.offset.y=t},e}}ygA([D(Fe)],vd.prototype,"intensity",2);Zo("ChromaticAberration",vd);var SgA=Object.defineProperty,kgA=Object.getOwnPropertyDescriptor,Gy=(i,A,e,t)=>{for(var g=t>1?void 0:t?kgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&SgA(A,e,g),g};class Va extends zg{constructor(){super(...arguments);r(this,"postExposure");r(this,"contrast");r(this,"hueShift");r(this,"saturation")}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=e=>(e=Math.pow(2,e),e),this.postExposure.defaultValue=0,this.contrast.valueProcessor=e=>{let t=1;return e>0?t=200:e<0&&(t=100),e/t},this.contrast.defaultValue=0,this.hueShift.valueProcessor=e=>Math.PI*e/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=e=>e<0?e/100:e/(100*Math.PI),this.saturation.defaultValue=0}unapply(){this.context.renderer.toneMappingExposure=1}onCreateEffect(){this.context.renderer.toneMapping===aI&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=Zh);const e=new RY;this.postExposure.onValueChanged=g=>{this.context.renderer.toneMapping===aI&&(this.context.renderer.toneMapping=Zh),this.postExposure.overrideState&&(this.context.renderer.toneMappingExposure=g)},this.contrast.onValueChanged=g=>{e.contrast=g};const t=new NY;return this.hueShift.onValueChanged=g=>t.hue=g,this.saturation.onValueChanged=g=>t.saturation=g,[t,e]}}Gy([D(Fe)],Va.prototype,"postExposure",2);Gy([D(Fe)],Va.prototype,"contrast",2);Gy([D(Fe)],Va.prototype,"hueShift",2);Gy([D(Fe)],Va.prototype,"saturation",2);Zo("ColorAdjustments",Va);const GgA=(Math.sqrt(5)-1)/4,Bg=(5-Math.sqrt(5))/20,up=i=>Math.floor(i)|0,pp=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 mgA(i=Math.random){const A=MgA(i),e=new Float64Array(A).map(o=>pp[o%32*4]),t=new Float64Array(A).map(o=>pp[o%32*4+1]),g=new Float64Array(A).map(o=>pp[o%32*4+2]),I=new Float64Array(A).map(o=>pp[o%32*4+3]);return function(s,C,n,a){let B,Q,E,c,l;const d=(s+C+n+a)*GgA,h=up(s+d),p=up(C+d),u=up(n+d),f=up(a+d),S=(h+p+u+f)*Bg,G=h-S,M=p-S,R=u-S,k=f-S,m=s-G,K=C-M,Z=n-R,H=a-k;let _=0,j=0,x=0,v=0;m>K?_++:j++,m>Z?_++:x++,m>H?_++:v++,K>Z?j++:x++,K>H?j++:v++,Z>H?x++:v++;const Y=_>=3?1:0,eA=j>=3?1:0,AA=x>=3?1:0,W=v>=3?1:0,gA=_>=2?1:0,fA=j>=2?1:0,uA=x>=2?1:0,MA=v>=2?1:0,RA=_>=1?1:0,HA=j>=1?1:0,PA=x>=1?1:0,Qe=v>=1?1:0,Ge=m-Y+Bg,oe=K-eA+Bg,P=Z-AA+Bg,xA=H-W+Bg,pA=m-gA+2*Bg,LA=K-fA+2*Bg,mA=Z-uA+2*Bg,ge=H-MA+2*Bg,zA=m-RA+3*Bg,ZA=K-HA+3*Bg,de=Z-PA+3*Bg,me=H-Qe+3*Bg,$e=m-1+4*Bg,T=K-1+4*Bg,q=Z-1+4*Bg,EA=H-1+4*Bg,KA=h&255,JA=p&255,TA=u&255,V=f&255;let hA=.6-m*m-K*K-Z*Z-H*H;if(hA<0)B=0;else{const bA=KA+A[JA+A[TA+A[V]]];hA*=hA,B=hA*hA*(e[bA]*m+t[bA]*K+g[bA]*Z+I[bA]*H)}let rA=.6-Ge*Ge-oe*oe-P*P-xA*xA;if(rA<0)Q=0;else{const bA=KA+Y+A[JA+eA+A[TA+AA+A[V+W]]];rA*=rA,Q=rA*rA*(e[bA]*Ge+t[bA]*oe+g[bA]*P+I[bA]*xA)}let VA=.6-pA*pA-LA*LA-mA*mA-ge*ge;if(VA<0)E=0;else{const bA=KA+gA+A[JA+fA+A[TA+uA+A[V+MA]]];VA*=VA,E=VA*VA*(e[bA]*pA+t[bA]*LA+g[bA]*mA+I[bA]*ge)}let jA=.6-zA*zA-ZA*ZA-de*de-me*me;if(jA<0)c=0;else{const bA=KA+RA+A[JA+HA+A[TA+PA+A[V+Qe]]];jA*=jA,c=jA*jA*(e[bA]*zA+t[bA]*ZA+g[bA]*de+I[bA]*me)}let OA=.6-$e*$e-T*T-q*q-EA*EA;if(OA<0)l=0;else{const bA=KA+1+A[JA+1+A[TA+1+A[V+1]]];OA*=OA,l=OA*OA*(e[bA]*$e+t[bA]*T+g[bA]*q+I[bA]*EA)}return 27*(B+Q+E+c+l)}}function MgA(i){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const g=t+~~(i()*(256-t)),I=e[t];e[t]=e[g],e[g]=I}for(let t=256;t<512;t++)e[t]=e[t-256];return e}var RgA=Object.defineProperty,UgA=Object.getOwnPropertyDescriptor,oA=(i,A,e,t)=>{for(var g=t>1?void 0:t?UgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&RgA(A,e,g),g};const fp=sA("debugparticles");var TC=(i=>(i[i.Billboard=0]="Billboard",i[i.Stretch=1]="Stretch",i[i.HorizontalBillboard=2]="HorizontalBillboard",i[i.VerticalBillboard=3]="VerticalBillboard",i[i.Mesh=4]="Mesh",i))(TC||{});let za=class{constructor(){r(this,"alphaKeys");r(this,"colorKeys")}get duration(){return 1}evaluate(A,e){let t,g=0,I=null,o=0;for(let s=0;s<this.alphaKeys.length;s++){const C=this.alphaKeys[s];(C.time<A||!t)&&(t=C,g=s)}for(let s=0;s<this.colorKeys.length;s++){const C=this.colorKeys[s];(C.time<A||!I)&&(I=C,o=s)}if(I)if(o+1<this.colorKeys.length){const C=this.colorKeys[o+1],n=ie.remap(A,I.time,C.time,0,1);e.r=ie.lerp(I.color.r,C.color.r,n),e.g=ie.lerp(I.color.g,C.color.g,n),e.b=ie.lerp(I.color.b,C.color.b,n)}else e.r=I.color.r,e.g=I.color.g,e.b=I.color.b;if(t)if(g+1<this.alphaKeys.length){const C=this.alphaKeys[g+1],n=ie.remap(A,t.time,C.time,0,1);e.alpha=ie.lerp(t.alpha,C.alpha,n)}else e.alpha=t.alpha;return e}};oA([D()],za.prototype,"alphaKeys",2);oA([D()],za.prototype,"colorKeys",2);var Ml=(i=>(i[i.Local=0]="Local",i[i.World=1]="World",i[i.Custom=2]="Custom",i))(Ml||{}),w2=(i=>(i[i.Sphere=0]="Sphere",i[i.SphereShell=1]="SphereShell",i[i.Hemisphere=2]="Hemisphere",i[i.HemisphereShell=3]="HemisphereShell",i[i.Cone=4]="Cone",i[i.Box=5]="Box",i[i.Mesh=6]="Mesh",i[i.ConeShell=7]="ConeShell",i[i.ConeVolume=8]="ConeVolume",i[i.ConeVolumeShell=9]="ConeVolumeShell",i[i.Circle=10]="Circle",i[i.CircleEdge=11]="CircleEdge",i[i.SingleSidedEdge=12]="SingleSidedEdge",i[i.MeshRenderer=13]="MeshRenderer",i[i.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",i[i.BoxShell=15]="BoxShell",i[i.BoxEdge=16]="BoxEdge",i[i.Donut=17]="Donut",i[i.Rectangle=18]="Rectangle",i[i.Sprite=19]="Sprite",i[i.SpriteRenderer=20]="SpriteRenderer",i))(w2||{});class Be{constructor(){r(this,"mode");r(this,"constant");r(this,"constantMin");r(this,"constantMax");r(this,"curve");r(this,"curveMin");r(this,"curveMax");r(this,"curveMultiplier")}evaluate(A,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.constant;case 1:return A=ie.clamp01(A),this.curve.evaluate(A)*this.curveMultiplier;case 2:const g=A*this.curveMin.duration,I=A*this.curveMax.duration;return ie.lerp(this.curveMin.evaluate(g),this.curveMax.evaluate(I),t%1)*this.curveMultiplier;case 3:return ie.lerp(this.constantMin,this.constantMax,t%1);default:this.curveMax.evaluate(A)*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(A){if(!A)return 0;let e=Number.MIN_VALUE;for(let t=0;t<A.keys.length;t++){const g=A.keys[t];g.value>e&&(e=g.value)}return e}}oA([D()],Be.prototype,"mode",2);oA([D()],Be.prototype,"constant",2);oA([D()],Be.prototype,"constantMin",2);oA([D()],Be.prototype,"constantMax",2);oA([D(rB)],Be.prototype,"curve",2);oA([D(rB)],Be.prototype,"curveMin",2);oA([D(rB)],Be.prototype,"curveMax",2);oA([D()],Be.prototype,"curveMultiplier",2);var xp;const Cs=(xp=class{constructor(){r(this,"mode");r(this,"color");r(this,"colorMin");r(this,"colorMax");r(this,"gradient");r(this,"gradientMin");r(this,"gradientMax")}evaluate(i,A){const e=A===void 0?Math.random():A;switch(this.mode){case 0:return this.color;case 1:return this.gradient.evaluate(i,Cs._temp),Cs._temp;case 2:return Cs._temp.lerpColors(this.colorMin,this.colorMax,e);case 3:return this.gradientMin.evaluate(i,Cs._temp),this.gradientMax.evaluate(i,Cs._temp2),Cs._temp.lerp(Cs._temp2,e)}return Cs._temp.set(16711935),Cs._temp.alpha=1,Cs._temp}},r(xp,"_temp",new St(0,0,0,1)),r(xp,"_temp2",new St(0,0,0,1)),xp);let TI=Cs;oA([D(St)],TI.prototype,"color",2);oA([D(St)],TI.prototype,"colorMin",2);oA([D(St)],TI.prototype,"colorMax",2);oA([D(za)],TI.prototype,"gradient",2);oA([D(za)],TI.prototype,"gradientMin",2);oA([D(za)],TI.prototype,"gradientMax",2);var Nm=(i=>(i[i.Hierarchy=0]="Hierarchy",i[i.Local=1]="Local",i[i.Shape=2]="Shape",i))(Nm||{});class Ug{constructor(){r(this,"cullingMode");r(this,"duration");r(this,"emitterVelocityMode");r(this,"flipRotation");r(this,"gravityModifier");r(this,"gravityModifierMultiplier");r(this,"loop");r(this,"maxParticles");r(this,"playOnAwake");r(this,"prewarm");r(this,"ringBufferLoopRange");r(this,"ringBufferMode");r(this,"scalingMode");r(this,"simulationSpace");r(this,"simulationSpeed");r(this,"startColor");r(this,"startDelay");r(this,"startDelayMultiplier");r(this,"startLifetime");r(this,"startLifetimeMultiplier");r(this,"startRotation");r(this,"startRotationMultiplier");r(this,"startRotation3D");r(this,"startRotationX");r(this,"startRotationXMultiplier");r(this,"startRotationY");r(this,"startRotationYMultiplier");r(this,"startRotationZ");r(this,"startRotationZMultiplier");r(this,"startSize");r(this,"startSize3D");r(this,"startSizeMultiplier");r(this,"startSizeX");r(this,"startSizeXMultiplier");r(this,"startSizeY");r(this,"startSizeYMultiplier");r(this,"startSizeZ");r(this,"startSizeZMultiplier");r(this,"startSpeed");r(this,"startSpeedMultiplier");r(this,"stopAction");r(this,"useUnscaledTime")}}oA([D(Be)],Ug.prototype,"gravityModifier",2);oA([D(TI)],Ug.prototype,"startColor",2);oA([D(Be)],Ug.prototype,"startDelay",2);oA([D(Be)],Ug.prototype,"startLifetime",2);oA([D(Be)],Ug.prototype,"startRotation",2);oA([D(Be)],Ug.prototype,"startRotationX",2);oA([D(Be)],Ug.prototype,"startRotationY",2);oA([D(Be)],Ug.prototype,"startRotationZ",2);oA([D(Be)],Ug.prototype,"startSize",2);oA([D(Be)],Ug.prototype,"startSizeX",2);oA([D(Be)],Ug.prototype,"startSizeY",2);oA([D(Be)],Ug.prototype,"startSizeZ",2);oA([D(Be)],Ug.prototype,"startSpeed",2);class Rl{constructor(){r(this,"cycleCount");r(this,"maxCount");r(this,"minCount");r(this,"probability");r(this,"repeatInterval");r(this,"time");r(this,"count");r(this,"_performed",0)}reset(){this._performed=0}run(A){if(A<=this.time)return 0;let e=0;if(this.cycleCount===0||this._performed<this.cycleCount){const t=this.time+this.repeatInterval*this._performed;if(A>=t&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:e=this.count.constant;break;case 3:e=ie.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:e=this.count.curve.evaluate(Math.random());break;case 2:const g=Math.random();e=ie.lerp(this.count.curveMin.evaluate(g),this.count.curveMax.evaluate(g),Math.random());break}}return e}}class EC{constructor(){r(this,"enabled");r(this,"bursts");r(this,"rateOverTime");r(this,"rateOverTimeMultiplier");r(this,"rateOverDistance");r(this,"rateOverDistanceMultiplier");r(this,"system")}get burstCount(){var A;return((A=this.bursts)==null?void 0:A.length)??0}reset(){var A;(A=this.bursts)==null||A.forEach(e=>e.reset())}getBurst(){let A=0;if(this.burstCount>0)for(let e=0;e<this.burstCount;e++){const t=this.bursts[e];this.system.main.loop&&t.time>=this.system.time&&t.reset(),A+=Math.round(t.run(this.system.time))}return A}}oA([D()],EC.prototype,"enabled",2);oA([D()],EC.prototype,"bursts",2);oA([D(Be)],EC.prototype,"rateOverTime",2);oA([D()],EC.prototype,"rateOverTimeMultiplier",2);oA([D(Be)],EC.prototype,"rateOverDistance",2);oA([D()],EC.prototype,"rateOverDistanceMultiplier",2);class bd{constructor(){r(this,"enabled");r(this,"color")}}oA([D(TI)],bd.prototype,"color",2);class ja{constructor(){r(this,"enabled");r(this,"separateAxes");r(this,"size");r(this,"sizeMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier");r(this,"_time",0);r(this,"_temp",new w)}evaluate(A,e,t){if(e||(e=this._temp),!this.enabled)return e.x=e.y=e.z=1,e;if(this.separateAxes)e.x=this.x.evaluate(A,t)*this.xMultiplier,e.y=this.y.evaluate(A,t)*this.yMultiplier,e.z=this.z.evaluate(A,t)*this.zMultiplier;else{const g=this.size.evaluate(A,t)*this.sizeMultiplier;e.x=g}return e}}oA([D(Be)],ja.prototype,"size",2);oA([D(Be)],ja.prototype,"x",2);oA([D(Be)],ja.prototype,"y",2);oA([D(Be)],ja.prototype,"z",2);var Tp;const nh=(Tp=class{constructor(){r(this,"shapeType",5);r(this,"enabled",!0);r(this,"alignToDirection",!1);r(this,"angle",0);r(this,"arc",360);r(this,"arcSpread");r(this,"arcSpeedMultiplier");r(this,"arcMode");r(this,"boxThickness");r(this,"position");r(this,"rotation");r(this,"_rotation",new yi);r(this,"scale");r(this,"radius");r(this,"radiusThickness");r(this,"sphericalDirectionAmount");r(this,"randomDirectionAmount");r(this,"randomPositionAmount");r(this,"system");r(this,"_space");r(this,"_worldSpaceMatrix",new UA);r(this,"_worldSpaceMatrixInverse",new UA);r(this,"_vector",new w(0,0,0));r(this,"_temp",new w(0,0,0));r(this,"_dir",new w);r(this,"_loopTime",0);r(this,"_loopDirection",1);fp&&console.log(this)}get type(){return w2[this.shapeType]}initialize(i){this.getPosition(),i.position.copy(this._vector)}toJSON(){return this}clone(){return new nh}update(i,A,e,t){this.system=i,this._space=e,e===1&&(this._worldSpaceMatrix.copy(t.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(i){const A=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return A&&(this._rotation.x=ie.toRadians(this.rotation.x),this._rotation.y=ie.toRadians(this.rotation.y),this._rotation.z=ie.toRadians(this.rotation.z),this._rotation.order="ZYX",i.applyEuler(this._rotation)),A}get vector(){return this._vector}getPosition(){this._vector.set(0,0,0);const i=this._temp.copy(this.position),A=this._space===1;A&&i.applyQuaternion(this.system.worldQuaternion);let e=this.radius;if(A&&(e*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:fp&&An.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(i);break;case 4:this.randomConePoint(this.position,this.angle,e,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,e,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,e,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),A&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),fp&&An.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(i){var A;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 e=i.x,t=i.y,g=i.z;this._dir.set(e,t,g),(A=this.system)!=null&&A.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),fp&&(An.DrawSphere(i,.01,8925952,.5,!0),An.DrawDirection(i,this._dir,8925952,.5,!0)),this._dir}randomizePosition(i,A){if(A<=0)return;const e=nh._tempVec;e.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),e.x*=A*this.scale.x,e.y*=A*this.scale.y,e.z*=A*this.scale.z,i.add(e)}randomizeDirection(i,A){if(A===0)return;const e=nh._randomQuat,t=nh._tempVec;t.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),e.setFromAxisAngle(t,A*Math.random()*Math.PI),i.applyQuaternion(e)}spherizeDirection(i,A){if(A===0)return;const e=Math.random()*Math.PI*2,t=Math.acos(1-Math.random()*2),g=Math.sin(t)*Math.cos(e),I=Math.sin(t)*Math.sin(e),o=Math.cos(t),s=new w(g,I,o);i.lerp(s,A)}randomSpherePoint(i,A,e,t,g){const I=Math.random(),o=Math.random(),s=2*Math.PI*I*(t/360),C=Math.acos(2*o-1),n=ie.lerp(1,1-Math.pow(1-Math.random(),Math.PI),e)*A,a=i.x+this.scale.x*(-n*Math.sin(C)*Math.cos(s)),B=i.y+this.scale.y*(n*Math.sin(C)*Math.sin(s)),Q=i.z+this.scale.z*(n*Math.cos(C));g.x=a,g.y=B,g.z=Q}randomCirclePoint(i,A,e,t,g){const I=Math.random(),o=2*Math.PI*I*(t/360),s=ie.lerp(1,1-Math.pow(1-Math.random(),Math.PI),e)*A,C=i.x+this.scale.x*s*Math.cos(o),n=i.y+this.scale.y*s*Math.sin(o),a=i.z;g.x=C,g.y=n,g.z=a}randomConePoint(i,A,e,t,g,I,o){let s=0,C=0;switch(I){case 0:s=Math.random(),C=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:s=.5,C=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let n=2*Math.PI*s*(g/360);switch(I){case 2:case 1:n+=Math.PI+.5,n+=this._loopTime*Math.PI*2,n%=ie.toRadians(g);break}const a=Math.acos(2*C-1),B=ie.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,Q=i.x+-B*Math.sin(a)*Math.cos(n),E=i.y+B*Math.sin(a)*Math.sin(n),c=i.z;o.x=Q*this.scale.x,o.y=E*this.scale.y,o.z=c*this.scale.z}},r(Tp,"_randomQuat",new GA),r(Tp,"_tempVec",new w),Tp);let mi=nh;oA([D()],mi.prototype,"shapeType",2);oA([D()],mi.prototype,"enabled",2);oA([D()],mi.prototype,"alignToDirection",2);oA([D()],mi.prototype,"angle",2);oA([D()],mi.prototype,"arc",2);oA([D()],mi.prototype,"arcSpread",2);oA([D()],mi.prototype,"arcSpeedMultiplier",2);oA([D()],mi.prototype,"arcMode",2);oA([D(w)],mi.prototype,"boxThickness",2);oA([D(w)],mi.prototype,"position",2);oA([D(w)],mi.prototype,"rotation",2);oA([D(w)],mi.prototype,"scale",2);oA([D()],mi.prototype,"radius",2);oA([D()],mi.prototype,"radiusThickness",2);oA([D()],mi.prototype,"sphericalDirectionAmount",2);oA([D()],mi.prototype,"randomDirectionAmount",2);oA([D()],mi.prototype,"randomPositionAmount",2);class wt{constructor(){r(this,"damping");r(this,"enabled");r(this,"frequency");r(this,"octaveCount");r(this,"octaveMultiplier");r(this,"octaveScale");r(this,"positionAmount");r(this,"quality");r(this,"remap");r(this,"remapEnabled");r(this,"remapMultiplier");r(this,"remapX");r(this,"remapXMultiplier");r(this,"remapY");r(this,"remapYMultiplier");r(this,"remapZ");r(this,"remapZMultiplier");r(this,"scrollSpeedMultiplier");r(this,"separateAxes");r(this,"strengthMultiplier");r(this,"strengthX");r(this,"strengthXMultiplier");r(this,"strengthY");r(this,"strengthYMultiplier");r(this,"strengthZ");r(this,"strengthZMultiplier");r(this,"_noise");r(this,"_time",0);r(this,"_temp",new w)}update(A){this._time+=A.time.deltaTime*this.scrollSpeedMultiplier}apply(A,e,t,g,I,o){if(!this.enabled)return;this._noise||(this._noise=mgA(()=>0));const s=this._temp.set(e.x,e.y,e.z).multiplyScalar(this.frequency),C=this._noise(s.x,s.y,s.z,this._time),n=this._noise(s.x,s.y,s.z,this._time+1e3*this.frequency),a=this._noise(s.x,s.y,s.z,this._time+2e3*this.frequency);this._temp.set(C,n,a).normalize();const B=I/o;let Q=this.positionAmount.evaluate(B);this.separateAxes?(this._temp.x*=Q*this.strengthXMultiplier,this._temp.y*=Q*this.strengthYMultiplier,this._temp.z*=Q*this.strengthZMultiplier):(this.strengthX&&(Q*=this.strengthX.evaluate(B)*1.5),this._temp.multiplyScalar(Q)),t.x+=this._temp.x,t.y+=this._temp.y,t.z+=this._temp.z}}oA([D()],wt.prototype,"damping",2);oA([D()],wt.prototype,"enabled",2);oA([D()],wt.prototype,"frequency",2);oA([D()],wt.prototype,"octaveCount",2);oA([D()],wt.prototype,"octaveMultiplier",2);oA([D()],wt.prototype,"octaveScale",2);oA([D(Be)],wt.prototype,"positionAmount",2);oA([D()],wt.prototype,"quality",2);oA([D(Be)],wt.prototype,"remap",2);oA([D()],wt.prototype,"remapEnabled",2);oA([D()],wt.prototype,"remapMultiplier",2);oA([D(Be)],wt.prototype,"remapX",2);oA([D()],wt.prototype,"remapXMultiplier",2);oA([D(Be)],wt.prototype,"remapY",2);oA([D()],wt.prototype,"remapYMultiplier",2);oA([D(Be)],wt.prototype,"remapZ",2);oA([D()],wt.prototype,"remapZMultiplier",2);oA([D()],wt.prototype,"scrollSpeedMultiplier",2);oA([D()],wt.prototype,"separateAxes",2);oA([D()],wt.prototype,"strengthMultiplier",2);oA([D(Be)],wt.prototype,"strengthX",2);oA([D()],wt.prototype,"strengthXMultiplier",2);oA([D(Be)],wt.prototype,"strengthY",2);oA([D()],wt.prototype,"strengthYMultiplier",2);oA([D(Be)],wt.prototype,"strengthZ",2);oA([D()],wt.prototype,"strengthZMultiplier",2);class Xt{constructor(){r(this,"enabled");r(this,"attachRibbonToTransform",!1);r(this,"colorOverLifetime");r(this,"colorOverTrail");r(this,"dieWithParticles",!0);r(this,"inheritParticleColor",!0);r(this,"lifetime");r(this,"lifetimeMultiplier");r(this,"minVertexDistance",.2);r(this,"mode",0);r(this,"ratio",1);r(this,"ribbonCount",1);r(this,"shadowBias",0);r(this,"sizeAffectsLifetime",!1);r(this,"sizeAffectsWidth",!1);r(this,"splitSubEmitterRibbons",!1);r(this,"textureMode",0);r(this,"widthOverTrail");r(this,"widthOverTrailMultiplier");r(this,"worldSpace",!1)}getWidth(A,e,t,g){const I=this.widthOverTrail.evaluate(t,g);return A*=I,A}getColor(A,e,t){const g=this.colorOverTrail.evaluate(t),I=this.colorOverLifetime.evaluate(e);A.x*=g.r*I.r,A.y*=g.g*I.g,A.z*=g.b*I.b,A.w*=g.alpha*I.alpha}}oA([D()],Xt.prototype,"enabled",2);oA([D()],Xt.prototype,"attachRibbonToTransform",2);oA([D(TI)],Xt.prototype,"colorOverLifetime",2);oA([D(TI)],Xt.prototype,"colorOverTrail",2);oA([D()],Xt.prototype,"dieWithParticles",2);oA([D()],Xt.prototype,"inheritParticleColor",2);oA([D(Be)],Xt.prototype,"lifetime",2);oA([D()],Xt.prototype,"lifetimeMultiplier",2);oA([D()],Xt.prototype,"minVertexDistance",2);oA([D()],Xt.prototype,"mode",2);oA([D()],Xt.prototype,"ratio",2);oA([D()],Xt.prototype,"ribbonCount",2);oA([D()],Xt.prototype,"shadowBias",2);oA([D()],Xt.prototype,"sizeAffectsLifetime",2);oA([D()],Xt.prototype,"sizeAffectsWidth",2);oA([D()],Xt.prototype,"splitSubEmitterRibbons",2);oA([D()],Xt.prototype,"textureMode",2);oA([D(Be)],Xt.prototype,"widthOverTrail",2);oA([D()],Xt.prototype,"widthOverTrailMultiplier",2);oA([D()],Xt.prototype,"worldSpace",2);class gi{constructor(){r(this,"enabled");r(this,"space",0);r(this,"orbitalX");r(this,"orbitalY");r(this,"orbitalZ");r(this,"orbitalXMultiplier");r(this,"orbitalYMultiplier");r(this,"orbitalZMultiplier");r(this,"orbitalOffsetX");r(this,"orbitalOffsetY");r(this,"orbitalOffsetZ");r(this,"speedModifier");r(this,"speedModifierMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier");r(this,"_system");r(this,"_temp",new w);r(this,"_temp2",new w);r(this,"_temp3",new w);r(this,"_hasOrbital",!1);r(this,"_index",0);r(this,"_orbitalMatrix",new UA)}update(A){this._system=A}init(A){this._index==0&&(A.debug=!0),this._index+=1,A.orbitx=this.orbitalX.evaluate(Math.random()),A.orbity=this.orbitalY.evaluate(Math.random()),A.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=A.orbitx!=0||A.orbity!=0||A.orbitz!=0}apply(A,e,t,g,I,o,s){var E;if(!this.enabled)return;const C=o/s,n=this.speedModifier.evaluate(C)*this.speedModifierMultiplier,a=this.x.evaluate(C),B=this.y.evaluate(C),Q=this.z.evaluate(C);if(this._temp.set(-a,B,Q),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((E=this._system)==null?void 0:E.worldPos)){const l=this._temp2.set(t.x,t.y,t.z),d=this.orbitalXMultiplier,h=this.orbitalYMultiplier,p=this.orbitalZMultiplier,u=n*Math.PI*2*10,f=Math.cos(u*d),S=Math.sin(u*d),G=Math.cos(u*h),M=Math.sin(u*h),R=Math.cos(u*p),k=Math.sin(u*p),m=l.x*(G*R)+l.y*(G*k)+l.z*-M,K=l.x*(S*M*R-f*k)+l.y*(S*M*k+f*R)+l.z*(S*G),Z=l.x*(f*M*R+S*k)+l.y*(f*M*k-S*R)+l.z*(f*G),H=this._temp3.set(l.x-m,l.y-K,l.z-Z);H.normalize(),H.multiplyScalar(.2/I*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),g.x+=H.x,g.y+=H.y,g.z+=H.z}g.x+=this._temp.x,g.y+=this._temp.y,g.z+=this._temp.z,g.x*=n,g.y*=n,g.z*=n}}oA([D()],gi.prototype,"enabled",2);oA([D()],gi.prototype,"space",2);oA([D(Be)],gi.prototype,"orbitalX",2);oA([D(Be)],gi.prototype,"orbitalY",2);oA([D(Be)],gi.prototype,"orbitalZ",2);oA([D()],gi.prototype,"orbitalXMultiplier",2);oA([D()],gi.prototype,"orbitalYMultiplier",2);oA([D()],gi.prototype,"orbitalZMultiplier",2);oA([D()],gi.prototype,"orbitalOffsetX",2);oA([D()],gi.prototype,"orbitalOffsetY",2);oA([D()],gi.prototype,"orbitalOffsetZ",2);oA([D(Be)],gi.prototype,"speedModifier",2);oA([D()],gi.prototype,"speedModifierMultiplier",2);oA([D(Be)],gi.prototype,"x",2);oA([D()],gi.prototype,"xMultiplier",2);oA([D(Be)],gi.prototype,"y",2);oA([D()],gi.prototype,"yMultiplier",2);oA([D(Be)],gi.prototype,"z",2);oA([D()],gi.prototype,"zMultiplier",2);class Fg{constructor(){r(this,"animation");r(this,"enabled");r(this,"cycleCount");r(this,"frameOverTime");r(this,"frameOverTimeMultiplier");r(this,"numTilesX");r(this,"numTilesY");r(this,"startFrame");r(this,"startFrameMultiplier");r(this,"rowMode");r(this,"rowIndex");r(this,"spriteCount");r(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(A){if(!this.sampleOnceAtStart())return this.getIndex(A)}getIndex(A){const e=this.numTilesX*this.numTilesY;A=A*this.cycleCount;let t=this.frameOverTime.evaluate(A%1);return t*=this.frameOverTimeMultiplier,t*=e,t=t%e,t=Math.floor(t),t}}oA([D()],Fg.prototype,"animation",2);oA([D()],Fg.prototype,"enabled",2);oA([D()],Fg.prototype,"cycleCount",2);oA([D(Be)],Fg.prototype,"frameOverTime",2);oA([D()],Fg.prototype,"frameOverTimeMultiplier",2);oA([D()],Fg.prototype,"numTilesX",2);oA([D()],Fg.prototype,"numTilesY",2);oA([D(Be)],Fg.prototype,"startFrame",2);oA([D()],Fg.prototype,"startFrameMultiplier",2);oA([D()],Fg.prototype,"rowMode",2);oA([D()],Fg.prototype,"rowIndex",2);oA([D()],Fg.prototype,"spriteCount",2);oA([D()],Fg.prototype,"timeMode",2);class Xo{constructor(){r(this,"enabled");r(this,"separateAxes");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(A,e){return this.enabled?this.separateAxes?0:this.z.evaluate(A,e)*-1:0}}oA([D()],Xo.prototype,"enabled",2);oA([D()],Xo.prototype,"separateAxes",2);oA([D(Be)],Xo.prototype,"x",2);oA([D()],Xo.prototype,"xMultiplier",2);oA([D(Be)],Xo.prototype,"y",2);oA([D()],Xo.prototype,"yMultiplier",2);oA([D(Be)],Xo.prototype,"z",2);oA([D()],Xo.prototype,"zMultiplier",2);class ho{constructor(){r(this,"enabled");r(this,"range");r(this,"separateAxes");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(A,e){if(!this.enabled)return 0;if(!this.separateAxes){const t=ie.lerp(this.range.x,this.range.y,e);return this.z.evaluate(t)*-1}return 0}}oA([D()],ho.prototype,"enabled",2);oA([D()],ho.prototype,"range",2);oA([D()],ho.prototype,"separateAxes",2);oA([D(Be)],ho.prototype,"x",2);oA([D()],ho.prototype,"xMultiplier",2);oA([D(Be)],ho.prototype,"y",2);oA([D()],ho.prototype,"yMultiplier",2);oA([D(Be)],ho.prototype,"z",2);oA([D()],ho.prototype,"zMultiplier",2);class Hi{constructor(){r(this,"enabled");r(this,"dampen");r(this,"drag");r(this,"dragMultiplier");r(this,"limit");r(this,"limitMultiplier");r(this,"separateAxes");r(this,"limitX");r(this,"limitXMultiplier");r(this,"limitY");r(this,"limitYMultiplier");r(this,"limitZ");r(this,"limitZMultiplier");r(this,"multiplyDragByParticleSize",!1);r(this,"multiplyDragByParticleVelocity",!1);r(this,"space");r(this,"_temp",new w);r(this,"_temp2",new w)}apply(A,e,t,g,I,o,s){if(this.enabled){const C=this.limit.evaluate(I)*this.limitMultiplier;if(e.length()>C){this._temp.copy(e).normalize().multiplyScalar(C);const a=this.dampen*.5;e.x=ie.lerp(e.x,this._temp.x,a),e.y=ie.lerp(e.y,this._temp.y,a),e.z=ie.lerp(e.z,this._temp.z,a),t.x=ie.lerp(t.x,this._temp.x,a),t.y=ie.lerp(t.y,this._temp.y,a),t.z=ie.lerp(t.z,this._temp.z,a)}}}}oA([D()],Hi.prototype,"enabled",2);oA([D()],Hi.prototype,"dampen",2);oA([D(Be)],Hi.prototype,"drag",2);oA([D()],Hi.prototype,"dragMultiplier",2);oA([D(Be)],Hi.prototype,"limit",2);oA([D()],Hi.prototype,"limitMultiplier",2);oA([D()],Hi.prototype,"separateAxes",2);oA([D(Be)],Hi.prototype,"limitX",2);oA([D()],Hi.prototype,"limitXMultiplier",2);oA([D(Be)],Hi.prototype,"limitY",2);oA([D()],Hi.prototype,"limitYMultiplier",2);oA([D(Be)],Hi.prototype,"limitZ",2);oA([D()],Hi.prototype,"limitZMultiplier",2);oA([D()],Hi.prototype,"multiplyDragByParticleSize",2);oA([D()],Hi.prototype,"multiplyDragByParticleVelocity",2);oA([D()],Hi.prototype,"space",2);class Za{constructor(){r(this,"enabled");r(this,"curve");r(this,"curveMultiplier");r(this,"mode");r(this,"system");r(this,"_lastWorldPosition");r(this,"_velocity",new w);r(this,"_temp",new w)}update(A){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(A){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const e=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(e),A.add(this._temp)}}applyCurrent(A,e,t){if(this.enabled&&this.system.worldspace!==!1&&this.mode===1){const g=this.curve.evaluate(e,t);this._temp.copy(this._velocity).multiplyScalar(g),A.add(this._temp)}}}oA([D()],Za.prototype,"enabled",2);oA([D(Be)],Za.prototype,"curve",2);oA([D()],Za.prototype,"curveMultiplier",2);oA([D()],Za.prototype,"mode",2);class uI{constructor(){r(this,"enabled");r(this,"range");r(this,"separateAxes");r(this,"size");r(this,"sizeMultiplier");r(this,"x");r(this,"xMultiplier");r(this,"y");r(this,"yMultiplier");r(this,"z");r(this,"zMultiplier")}evaluate(A,e,t,g){const I=A.length(),o=ie.remap(I,this.range.x,this.range.y,0,1),s=this.size.evaluate(o,t);return g*s}}oA([D()],uI.prototype,"enabled",2);oA([D(tA)],uI.prototype,"range",2);oA([D()],uI.prototype,"separateAxes",2);oA([D(Be)],uI.prototype,"size",2);oA([D()],uI.prototype,"sizeMultiplier",2);oA([D(Be)],uI.prototype,"x",2);oA([D()],uI.prototype,"xMultiplier",2);oA([D(Be)],uI.prototype,"y",2);oA([D()],uI.prototype,"yMultiplier",2);oA([D(Be)],uI.prototype,"z",2);oA([D()],uI.prototype,"zMultiplier",2);class pB{constructor(){r(this,"enabled");r(this,"range");r(this,"color")}evaluate(A,e,t){const g=A.length(),I=ie.remap(g,this.range.x,this.range.y,0,1),o=this.color.evaluate(I,e);t.x*=o.r,t.y*=o.g,t.z*=o.b,t.w*=o.alpha}}oA([D()],pB.prototype,"enabled",2);oA([D(tA)],pB.prototype,"range",2);oA([D(TI)],pB.prototype,"color",2);function Cv(i){const A=i.domElement.shadowRoot.querySelector("link[rel='ar']");if(A)return A;const e=document.createElement("div");e.classList.add("menu"),e.classList.add("quicklook-menu"),e.style.display="none",e.style.visibility="hidden";const t=document.createElement("button");t.id="open-in-ar",t.innerText="Open in QuickLook",e.appendChild(t);const g=document.createElement("a");g.id="needle-usdz-link",g.style.display="none",g.rel="ar",g.href="",e.appendChild(g);const I=document.createElement("img");return I.id="button",g.appendChild(I),i.domElement.shadowRoot.appendChild(e),g}function FgA(){var i=new Date;const A=i.getMonth()+1,e=i.getDate(),t=i.getHours(),g=i.getMinutes(),I=i.getSeconds(),o=(A<10?"0":"")+A,s=(e<10?"0":"")+e,C=(t<10?"0":"")+t,n=(g<10?"0":"")+g,a=(I<10?"0":"")+I;return i.getFullYear()+o+s+"-"+C+n+a}const Dp=sA("debugusdz");function NgA(i,A){const e=[],t=IA.getComponentsInChildren(i,Pg),g=IA.getComponentsInChildren(i,ro);let I=!1;const o=new rI("rest",.01,[]),s=new Map,C=(n,a)=>{if(!I&&a.tracks.length>0&&(I=!0,n.push(o)),a.tracks.length>0)for(const B of a.tracks){const Q=Te.parseTrackName(B.name),E=Te.findNode(i,Q.nodeName);if(E){s.has(E)||s.set(E,[]);const c=s.get(E);switch(Q.propertyName){case"position":{if(c.includes("position"))continue;const l=E.position,d=new JI(B.name,[0,.01],[l.x,l.y,l.z,l.x,l.y,l.z]);c.push("position"),o.tracks.push(d);break}case"quaternion":{if(c.includes("quaternion"))continue;const l=E.quaternion,d=new JI(B.name,[0,.01],[l.x,l.y,l.z,l.w,l.x,l.y,l.z,l.w]);c.push("quaternion"),o.tracks.push(d);break}case"scale":{if(c.includes("scale"))continue;const l=E.scale,d=new JI(B.name,[0,.01],[l.x,l.y,l.z,l.x,l.y,l.z]);c.push("scale"),o.tracks.push(d);break}}}}};for(const n of t){if(!n||!n.runtimeAnimatorController)continue;Dp&&console.log(n);const a=[];for(const B of n.runtimeAnimatorController.enumerateActions()){Dp&&console.log(B);const Q=B.getClip();C(a,Q),a.includes(Q)||a.push(Q)}e.push({root:n.gameObject,clips:a})}for(const n of g){Dp&&console.log(n);const a=[];for(const B of n.animations)C(a,B),a.includes(B)||a.push(B);e.push({root:n.gameObject,clips:a})}Dp&&(console.log("Rest Pose Clip",o),console.log("USDZ Animation Clips",e));for(const n of e)for(const a of n.clips)A.registerAnimation(n.root,a)}class KgA{static createButton(A,e={},t){const g=document.createElement("button");let I=!1;function o(){if(e.optionalFeatures=e.optionalFeatures||[],e.domOverlay===void 0){var a=document.createElement("div");a.style.display="none",document.body.appendChild(a);var B=document.createElementNS("http://www.w3.org/2000/svg","svg");B.setAttribute("width",38),B.setAttribute("height",38),B.style.position="absolute",B.style.right="20px",B.style.top="20px",B.addEventListener("click",function(){E.end()}),a.appendChild(B);var Q=document.createElementNS("http://www.w3.org/2000/svg","path");Q.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),Q.setAttribute("stroke","#fff"),Q.setAttribute("stroke-width",2),B.appendChild(Q),e.optionalFeatures.push("dom-overlay"),e.domOverlay={root:a},I=!0}let E=null,c=null;async function l(h){var f;const p=/WebXRViewer\//i.test(navigator.userAgent),u=e.domOverlay.root;p&&((f=e.domOverlay)!=null&&f.root?(c=u.parentNode,c&&(console.log("Reparent DOM Overlay to body",u,u.style.display),u.style.display="",u.style.visibility="",document.body.appendChild(u))):console.warn("WebXRViewer: No DOM Overlay found")),h.addEventListener("end",d),await A.xr.setSession(h),g.textContent="STOP AR",I&&(e.domOverlay.root.style.display=""),E=h}function d(){E.removeEventListener("end",d),g.textContent="START AR";const h=e.domOverlay.root;c&&c.appendChild(h),I&&(h.style.display="none"),E=null}g.style.display="",g.style.cursor="pointer",g.style.left="calc(50% - 50px)",g.style.width="100px",g.textContent="START AR",g.onmouseenter=function(){g.style.opacity="1.0"},g.onmouseleave=function(){g.style.opacity="0.5"},g.onclick=function(){E===null?(t==null||t.call(this,e),navigator.xr.requestSession("immersive-ar",e).then(l)):E.end()}}function s(){g.disabled=!0,g.style.display="",g.style.cursor="auto",g.style.left="calc(50% - 75px)",g.style.width="150px",g.onmouseenter=null,g.onmouseleave=null,g.onclick=null}function C(){s(),g.textContent="AR NOT SUPPORTED"}function n(a){a.style.position="absolute",a.style.bottom="20px",a.style.padding="12px 6px",a.style.border="1px solid #fff",a.style.borderRadius="4px",a.style.background="rgba(0,0,0,0.1)",a.style.color="#fff",a.style.font="normal 13px sans-serif",a.style.textAlign="center",a.style.opacity="0.5",a.style.outline="none",a.style.zIndex="999"}if("xr"in navigator)return g.id="ARButton",g.style.display="none",n(g),navigator.xr.isSessionSupported("immersive-ar").then(function(a){a?o():C()}).catch(C),g;{const a=document.createElement("a");return window.isSecureContext===!1?(a.href=document.location.href.replace(/^http:/,"https:"),a.innerHTML="WEBXR NEEDS HTTPS"):(a.href="https://immersiveweb.dev/",a.innerHTML="WEBXR NOT AVAILABLE"),a.style.left="calc(50% - 90px)",a.style.width="180px",a.style.textDecoration="none",n(a),a}}}const xD=class{static createButton(A,e){const t=document.createElement("button");function g(){let C=null;async function n(B){B.addEventListener("end",a),await A.xr.setSession(B),t.textContent="EXIT VR",C=B}function a(){C.removeEventListener("end",a),t.textContent="ENTER VR",C=null}t.style.display="",t.style.cursor="pointer",t.style.left="calc(50% - 50px)",t.style.width="100px",t.textContent="ENTER VR",t.onmouseenter=function(){t.style.opacity="1.0"},t.onmouseleave=function(){t.style.opacity="0.5"},t.onclick=function(){if(C===null){const B={optionalFeatures:e.optionalFeatures};navigator.xr.requestSession("immersive-vr",B).then(n)}else C.end()}}function I(){t.disabled=!0,t.style.display="",t.style.cursor="auto",t.style.left="calc(50% - 75px)",t.style.width="150px",t.onmouseenter=null,t.onmouseleave=null,t.onclick=null}function o(){I(),t.textContent="VR NOT SUPPORTED"}function s(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 t.id="VRButton",t.style.display="none",s(t),navigator.xr.isSessionSupported("immersive-vr").then(function(C){C?g():o(),xD.xrSessionIsGranted&&(console.log("XR session is granted - will enter immersive web now"),t.click())}),t;{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",s(C),C}}static registerSessionGrantedListener(){if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent))return;navigator.xr.addEventListener("sessiongranted",()=>{xD.xrSessionIsGranted=!0})}}};let Jh=xD;r(Jh,"xrSessionIsGranted",!1);Jh.registerSessionGrantedListener();var JgA=Object.defineProperty,qgA=Object.getOwnPropertyDescriptor,xU=(i,A,e,t)=>{for(var g=t>1?void 0:t?qgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&JgA(A,e,g),g};const vgA=new UA;class fs extends NA{constructor(){super(...arguments);r(this,"webAR",null);r(this,"invertForward",!1);r(this,"arTouchTransform",!1);r(this,"_initalMatrix",new UA);r(this,"_selectStartFn",this.onSelectStart.bind(this));r(this,"_selectEndFn",this.onSelectEnd.bind(this));r(this,"userInput");r(this,"_arScale",1);r(this,"_rig",null);r(this,"_startPose",null);r(this,"_placementPose",null);r(this,"_isTouching",!1);r(this,"_rigStartPose",null);r(this,"_gotFirstHitTestResult",!1);r(this,"_anchor",null);r(this,"_anchorMatrix",new UA);r(this,"_invertedSessionRootMatrix",new UA);r(this,"_invertForwardMatrix",new UA().makeRotationY(Math.PI))}get rig(){var e;return(e=this.webAR)==null?void 0:e.webxr.Rig}get arScale(){return this._arScale}set arScale(e){e!==this._arScale&&(this._arScale=e,this.setScale(e))}start(){const e=IA.findObjectOfType(Ue);e&&(e.Rig.updateMatrix(),this._initalMatrix.copy(e.Rig.matrix))}onBegin(e){var t;this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose=this.gameObject.matrix.clone(),this._rigStartPose=(t=this.rig)==null?void 0:t.matrix.clone(),this._gotFirstHitTestResult=!1,this._anchor=null,e.addEventListener("selectstart",this._selectStartFn),e.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(e,t,g,I){if(I&&!this._placementPose&&(this._gotFirstHitTestResult||(this._gotFirstHitTestResult=!0,this.dispatchEvent(new CustomEvent("canPlaceSession",{detail:{pose:I}}))),this._isTouching)){const o=new UA().fromArray(I.transform.matrix).invert();return this.dispatchEvent(new CustomEvent("placedSession",{detail:{pose:I,poseMatrix:o}})),this.webAR&&this.webAR.setReticleActive(!1),this.placeAt(e,o),g&&I&&this.onCreatePlacementAnchor(g,I),!0}return!1}onCreatePlacementAnchor(e,t){var g,I;this._anchor=null,(I=(g=e==null?void 0:e.createAnchor)==null?void 0:g.call(e,t.transform))==null||I.then(o=>{this.context.isInAR&&(this._anchor=o)})}onBeforeRender(e){if(e&&this._rig)if(this._anchor){const t=this.context.renderer.xr.getReferenceSpace();if(t){const g=e.getPose(this._anchor.anchorSpace,t);if(g){const I=this._anchorMatrix.fromArray(g.transform.matrix).invert();this.placeAt(this._rig,I);return}}}else this._placementPose&&this.placeAt(this._rig,this._placementPose)}placeAt(e,t){this._placementPose||(this._placementPose=new UA),this._placementPose.copy(t);const g=this._invertedSessionRootMatrix.copy(this.gameObject.matrixWorld).invert();this._placementPose.premultiply(g),e?(this.invertForward&&this._placementPose.premultiply(this._invertForwardMatrix),this.userInput||(this.userInput=new yQ(this.context)),this.userInput.enable(),this._rig=e,this.setScale(this.arScale)):this._rig=null,this.gameObject.visible=!0}onEnd(e,t){var g,I;(g=this.userInput)==null||g.disable(),(I=this.userInput)==null||I.reset(),this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._anchor=null,this._startPose&&this.gameObject.matrix.copy(this._startPose),e&&(e.matrixAutoUpdate=!0,this._rigStartPose&&this._rigStartPose.decompose(e.position,e.quaternion,e.scale)),qI.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(e){const t=this._rig;!t||!this._placementPose||(this._rigStartPose||(this._rigStartPose=t.matrix.clone()),t.matrixAutoUpdate=!1,this.arTouchTransform&&this.userInput&&this.userInput.applyMatrixTo(this._placementPose),t.matrix.multiplyMatrices(vgA.makeScale(e,e,e),this._placementPose),t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld())}}xU([D()],fs.prototype,"invertForward",2);xU([D()],fs.prototype,"arTouchTransform",2);xU([D()],fs.prototype,"arScale",1);const TD=class{constructor(A){r(this,"oneFingerDrag",!0);r(this,"twoFingerRotate",!0);r(this,"twoFingerScale",!0);r(this,"context");r(this,"offset");r(this,"plane");r(this,"_scale",1);r(this,"_enabled",!1);r(this,"prev",new Map);r(this,"_didMultitouch",!1);r(this,"touchStart",A=>{for(let e=0;e<A.changedTouches.length;e++){const t=A.changedTouches[e];this.prev.has(t.identifier)||this.prev.set(t.identifier,{x:0,z:0,screenx:0,screeny:0});const g=this.prev.get(t.identifier);if(g){const I=this.getPositionOnPlane(t.clientX,t.clientY);g.x=I.x,g.z=I.z,g.screenx=t.clientX,g.screeny=t.clientY}}});r(this,"touchEnd",A=>{A.touches.length<=0&&(this._didMultitouch=!1)});r(this,"touchMove",A=>{if(!A.defaultPrevented){if(A.touches.length===1){if(this._didMultitouch)return;const e=A.touches[0],t=this.prev.get(e.identifier);if(!t)return;const g=this.getPositionOnPlane(e.clientX,e.clientY),I=g.x-t.x,o=g.z-t.z;if(I===0&&o===0)return;this.oneFingerDrag&&this.addMovement(I,o),t.x=g.x,t.z=g.z,t.screenx=e.clientX,t.screeny=e.clientY;return}else if(A.touches.length===2){this._didMultitouch=!0;const e=A.touches[0],t=A.touches[1],g=this.prev.get(e.identifier),I=this.prev.get(t.identifier);if(!g||!I)return;if(this.twoFingerRotate){const o=Math.atan2(e.clientY-t.clientY,e.clientX-t.clientX),s=Math.atan2(g.screeny-I.screeny,g.screenx-I.screenx),C=o-s;Math.abs(C)>.001&&this.addRotation(C)}if(this.twoFingerScale){const o=e.clientX-t.clientX,s=e.clientY-t.clientY,C=Math.sqrt(o*o+s*s),n=g.screenx-I.screenx,a=g.screeny-I.screeny,B=Math.sqrt(n*n+a*a),Q=C-B;Math.abs(Q)>2&&this.addScale(Q)}g.screenx=e.clientX,g.screeny=e.clientY,I.screenx=t.clientX,I.screeny=t.clientY}}});r(this,"_raycaster",new nB);r(this,"_intersection",new w);r(this,"_screenPos",new w);r(this,"_tempMatrix",new UA);this.context=A,this.offset=new UA,this.plane=new to,this.plane.setFromNormalAndCoplanarPoint(TD.up,TD.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(A){A.premultiply(this.offset)}getPositionOnPlane(A,e){const t=this.context.mainCamera;return this._screenPos.x=A/window.innerWidth*2-1,this._screenPos.y=-(e/window.innerHeight)*2+1,this._screenPos.z=1,this._screenPos.unproject(t),this._raycaster.set(t.position,this._screenPos.sub(t.position)),this._raycaster.ray.intersectPlane(this.plane,this._intersection),this._intersection}addMovement(A,e){A*=.75,e*=.75,A/=this._scale,e/=this._scale,this.offset.elements[12]-=A,this.offset.elements[14]-=e}addScale(A){A/=window.innerWidth,this._scale*=1+A,this._tempMatrix.makeScale(1-A,1-A,1-A),this.offset.premultiply(this._tempMatrix)}addRotation(A){this._tempMatrix.makeRotationY(A),this.offset.premultiply(this._tempMatrix)}};let yQ=TD;r(yQ,"up",new w(0,1,0)),r(yQ,"zero",new w(0,0,0)),r(yQ,"one",new w(1,1,1));const bgA=sA("debugrig");class my extends NA{awake(){if(bgA){const A=new FA;A.position.y+=.5,this.gameObject.add(A);const e=A.addNewComponent(cB);e&&(e.isGizmo=!1)}}}class zQ{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}w(){return this.bb.readFloat32(this.bb_pos+12)}static sizeOf(){return 16}static createVec4(A,e,t,g,I){return A.prep(4,16),A.writeFloat32(I),A.writeFloat32(g),A.writeFloat32(t),A.writeFloat32(e),A.offset()}}class vg{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsVrUserStateBuffer(A,e){return(e||new vg).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsVrUserStateBuffer(A,e){return A.setPosition(A.position()+Jw),(e||new vg).__init(A.readInt32(A.position())+A.position(),A)}guid(A){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}time(){const A=this.bb.__offset(this.bb_pos,6);return A?this.bb.readInt64(this.bb_pos+A):this.bb.createLong(0,0)}avatarId(A){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__string(this.bb_pos+e,A):null}position(A){const e=this.bb.__offset(this.bb_pos,10);return e?(A||new ao).__init(this.bb_pos+e,this.bb):null}rotation(A){const e=this.bb.__offset(this.bb_pos,12);return e?(A||new zQ).__init(this.bb_pos+e,this.bb):null}scale(){const A=this.bb.__offset(this.bb_pos,14);return A?this.bb.readFloat32(this.bb_pos+A):0}posLeftHand(A){const e=this.bb.__offset(this.bb_pos,16);return e?(A||new ao).__init(this.bb_pos+e,this.bb):null}posRightHand(A){const e=this.bb.__offset(this.bb_pos,18);return e?(A||new ao).__init(this.bb_pos+e,this.bb):null}rotLeftHand(A){const e=this.bb.__offset(this.bb_pos,20);return e?(A||new zQ).__init(this.bb_pos+e,this.bb):null}rotRightHand(A){const e=this.bb.__offset(this.bb_pos,22);return e?(A||new zQ).__init(this.bb_pos+e,this.bb):null}static startVrUserStateBuffer(A){A.startObject(10)}static addGuid(A,e){A.addFieldOffset(0,e,0)}static addTime(A,e){A.addFieldInt64(1,e,A.createLong(0,0))}static addAvatarId(A,e){A.addFieldOffset(2,e,0)}static addPosition(A,e){A.addFieldStruct(3,e,0)}static addRotation(A,e){A.addFieldStruct(4,e,0)}static addScale(A,e){A.addFieldFloat32(5,e,0)}static addPosLeftHand(A,e){A.addFieldStruct(6,e,0)}static addPosRightHand(A,e){A.addFieldStruct(7,e,0)}static addRotLeftHand(A,e){A.addFieldStruct(8,e,0)}static addRotRightHand(A,e){A.addFieldStruct(9,e,0)}static endVrUserStateBuffer(A){return A.endObject()}static finishVrUserStateBufferBuffer(A,e){A.finish(e)}static finishSizePrefixedVrUserStateBufferBuffer(A,e){A.finish(e,void 0,!0)}}const nv=sA("debugxr"),xc=sA("debugavatar"),TU="VRUS";qw(TU,vg.getRootAsVrUserStateBuffer);function Km(){return new Date().getTime()}function LgA(i){const A=i&4294967295,e=i/Math.pow(2,32)&1048575;return $s.create(A,e)}const Wh=class{constructor(A){r(this,"guid");r(this,"time");r(this,"avatarId");r(this,"position",new w);r(this,"rotation",new te);r(this,"scale",1);r(this,"posLeftHand",new w);r(this,"posRightHand",new w);r(this,"rotLeftHand",new GA);r(this,"rotRightHand",new GA);this.guid=A}update(A,e,t,g,I){var a,B,Q,E,c,l;this.time=Km(),this.avatarId=I,this.position.set(e.x,e.y,e.z),A&&this.position.applyMatrix4(A.matrixWorld);let o=Wh.quat0;const s=Wh.quat1;o.set(t.x,t.y,t.z,t.w),o=o.multiplyQuaternions(o,Wh.invertRotation),A&&(A.getWorldQuaternion(s),o.multiplyQuaternions(s,o)),this.rotation.set(o.x,o.y,o.z,o.w),this.scale=A.scale.x;const C=(a=g.LeftController)==null?void 0:a.controllerGrip;C&&(C.getWorldPosition(this.posLeftHand),C.getWorldQuaternion(this.rotLeftHand));const n=(B=g.RightController)==null?void 0:B.controllerGrip;if(n&&(n.getWorldPosition(this.posRightHand),n.getWorldQuaternion(this.rotRightHand)),(E=(Q=g.LeftController)==null?void 0:Q.hand)!=null&&E.visible){const d=g.LeftController.wrist;d&&(d.getWorldPosition(this.posLeftHand),d.getWorldQuaternion(this.rotLeftHand))}if((l=(c=g.RightController)==null?void 0:c.hand)!=null&&l.visible){const d=g.RightController.wrist;d&&(d.getWorldPosition(this.posRightHand),d.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(A,e){A.clear();const t=A.createString(this.guid),g=A.createString(this.avatarId);vg.startVrUserStateBuffer(A),vg.addGuid(A,t),vg.addTime(A,LgA(this.time)),vg.addAvatarId(A,g),vg.addPosition(A,ao.createVec3(A,this.position.x,this.position.y,this.position.z)),vg.addRotation(A,zQ.createVec4(A,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),vg.addScale(A,this.scale),vg.addPosLeftHand(A,ao.createVec3(A,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),vg.addPosRightHand(A,ao.createVec3(A,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),vg.addRotLeftHand(A,zQ.createVec4(A,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),vg.addRotRightHand(A,zQ.createVec4(A,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const I=vg.endVrUserStateBuffer(A);A.finish(I,TU);const o=A.asUint8Array();e.sendBinary(o)}setFromBuffer(A,e){if(!A)return;this.guid=A,this.time=e.time().toFloat64();const t=e.avatarId();t&&(this.avatarId=t);const g=e.position();g&&this.position.set(g.x(),g.y(),g.z());const I=e.rotation();I&&this.rotation.set(I.x(),I.y(),I.z(),I.w());const o=e.posLeftHand();o&&this.posLeftHand.set(o.x(),o.y(),o.z());const s=e.posRightHand();s&&this.posRightHand.set(s.x(),s.y(),s.z());const C=e.rotLeftHand();C&&this.rotLeftHand.set(C.x(),C.y(),C.z(),C.w());const n=e.rotRightHand();n&&this.rotRightHand.set(n.x(),n.y(),n.z(),n.w()),this.scale=e.scale()}};let Es=Wh;r(Es,"invertRotation",new GA().setFromAxisAngle(new w(0,1,0),Math.PI)),r(Es,"quat0",new GA),r(Es,"quat1",new GA);class Ul extends NA{constructor(){super(...arguments);r(this,"webXR",null);r(this,"debugAvatarUser",null);r(this,"voip",null);r(this,"tempState",new Es(""));r(this,"_removeAvatarsList",[]);r(this,"eventSub_ConnectionEvent",null);r(this,"eventSub_WebXRStartEvent",null);r(this,"eventSub_WebXREndEvent",null);r(this,"eventSub_WebXRUpdateEvent",null);r(this,"avatars",{});r(this,"localAvatar",null);r(this,"k_LocalAvatarNoNetworkingGuid","local");r(this,"ownership",null);r(this,"xrState",null);r(this,"builder",new mE(1024))}async awake(){if(this.webXR||(this.webXR=IA.getComponent(this.gameObject,Ue)),this.webXR||(this.webXR=IA.findObjectOfType(Ue,this.context)),!this.webXR&&(this.webXR=IA.findObjectOfType(Ue,this.context),!this.webXR)){console.warn("WebXRSync: Could not find WebXR component, won't sync.");return}if(this.voip||(this.voip=IA.findObjectOfType(Rn,this.context)),xc){const e="debug-avatar-"+xc,t=new js(this.context,e,this.webXR);if(this.debugAvatarUser=t,typeof xc=="string"&&xc.length>0)if(await t.setAvatarOverride(xc)){const g=new Es(e);g.position.y+=1;const I=.5;g.posLeftHand.y+=I,g.posLeftHand.x+=I,g.posRightHand.y+=I,g.posRightHand.x-=I,t.tryUpdate(g,0)}else t.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=IA.getComponent(this.gameObject,Ue),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),Ue.addEventListener(Kt.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),Ue.addEventListener(Kt.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Ue.addEventListener(Kt.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen(Bi.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",e=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",e=>{const t=e.id!==null&&e.id!==void 0;if(t&&(console.log("webxr user left evt"),t)){const g=this.avatars[e.id];g==null||g.destroy(),this.avatars[e.id]=void 0}}),this.context.connection.beginListenBinary(TU,e=>{const t=e.guid();if(!t)return;const g=e.time().toFloat64(),I=this.tempState;I.setFromBuffer(t,e);const o=this.onTryGetAvatar(t,g);o==null||o.tryUpdate(I,g)}),this.context.connection.beginListen("vr-session-update",e=>{const t=e.guid,g=e.time,I=this.onTryGetAvatar(t,g);I==null||I.tryUpdate(e,g)})}onTryGetAvatar(e,t){if(e===this.context.connection.connectionId)return null;const g=new Date().getTime()-t;if(g>5e3)return nv&&console.log("old data",g,e),null;if(!this.webXR)return null;let I=this.avatars[e];if(I===void 0)try{console.log("create new avatar");const o=new js(this.context,e,this.webXR);I=o,this.avatars[e]=o}catch(o){this.avatars[e]=null,console.error(o)}return I}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen(Bi.JoinedRoom,this.eventSub_ConnectionEvent),Ue.removeEventListener(Kt.XRStarted,this.eventSub_WebXRStartEvent),Ue.removeEventListener(Kt.XRUpdate,this.eventSub_WebXRUpdateEvent),Ue.removeEventListener(Kt.XRStopped,this.eventSub_WebXREndEvent)}update(){const e=Km();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=e),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const t in this.avatars){const g=this.avatars[t];g&&g.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const e=Km();for(const t in this.avatars){const g=this.avatars[t];if(!g){this._removeAvatarsList.push(t);continue}e-g.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),g.destroy(),this.avatars[t]=void 0)}for(const t of this._removeAvatarsList)delete this.avatars[t];this._removeAvatarsList.length=0}buildLocalAvatar(){var t;if(this.localAvatar)return;const e=((t=this.context.connection)==null?void 0:t.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new js(this.context,e,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var e,t,g;nv&&console.log("Hey you are connected as "+this.context.connection.connectionId),((e=this.localAvatar)==null?void 0:e.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(g=this.ownership)==null||g.freeOwnership(),this.ownership=null)}onXRSessionStart(e){var t,g,I;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(g=this.ownership)==null||g.freeOwnership(),this.ownership=null,this.avatars)for(const o in this.avatars)(I=this.avatars[o])==null||I.updateFlags()}onXRSessionEnded(e){var t;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(e){this.xrState??(this.xrState=new Es(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new bw(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:t,xr:g,rig:I}=e,o=t.getViewerPose(g.getReferenceSpace());if(!o)return;const s=o==null?void 0:o.transform,C=s.position,n=s.orientation;this.xrState.update(I,C,n,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 sA("avatar")??null}}var xgA=Object.defineProperty,TgA=Object.getOwnPropertyDescriptor,Ac=(i,A,e,t)=>{for(var g=t>1?void 0:t?TgA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&xgA(A,e,g),g};const rk=sA("debugwebxr");async function y2(){return _f()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function S2(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let ah=!1,rh=!1;y2().then(i=>ah=i);S2().then(i=>rh=i);var Kt=(i=>(i.XRStarted="xrStarted",i.XRStopped="xrStopped",i.XRUpdate="xrUpdate",i.RequestVRSession="requestVRSession",i.ModifyAROptions="modify-ar-options",i))(Kt||{}),hQ;const Pi=(hQ=class extends NA{constructor(){super(...arguments);r(this,"enableVR",!0);r(this,"enableAR",!0);r(this,"defaultAvatar");r(this,"handModelPath","");r(this,"createVRButton",!0);r(this,"createARButton",!0);r(this,"controllers",[]);r(this,"rig");r(this,"isInit",!1);r(this,"_requestedAR",!1);r(this,"_requestedVR",!1);r(this,"_isInAR",!1);r(this,"_isInVR",!1);r(this,"_arButton");r(this,"_vrButton");r(this,"webAR",null);r(this,"_transformOrientation",new GA);r(this,"_currentHeadPose",null);r(this,"_originalCameraParent",null);r(this,"_originalCameraPosition",new w);r(this,"_originalCameraRotation",new GA);r(this,"_originalXRRigParent",null);r(this,"_originalXRRigPosition",new w);r(this,"_originalXRRigRotation",new GA);r(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(ah||rh)}static get IsARSupported(){return ah}static get IsVRSupported(){return rh}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(A,e){return this.events.addEventListener(A,e),e}static removeEventListener(A,e){return this.events.removeEventListener(A,e),e}static dispatchEvent(A,e){this.events.dispatchEvent({type:A,detail:e})}static createVRButton(A,e){Pi.XRSupported?A.__internalAwake():console.warn("WebXR is not supported on this device");const t={optionalFeatures:Pi.OptionalFeatures_VR},g=Jh.createButton(A.context.renderer,t);return g.classList.add("webxr-ar-button"),g.classList.add("webxr-button"),this.resetButtonStyles(g),((e==null?void 0:e.registerClick)??!0)&&g.addEventListener("click",A.onClickedVRButton.bind(A)),g}static createARButton(A,e){var o;A.__internalAwake();const t=(o=A.webAR)==null?void 0:o.getAROverlayContainer(),g={optionalFeatures:[...this.OptionalFeatures_AR]};t?(g.domOverlay={root:t},g.optionalFeatures.push("dom-overlay"),g.optionalFeatures.push("hit-test"),g.optionalFeatures.push("anchors")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const I=KgA.createButton(A.context.renderer,g,this.onModifyAROptions.bind(this));return I.classList.add("webxr-ar-button"),I.classList.add("webxr-button"),Pi.resetButtonStyles(I),((e==null?void 0:e.registerClick)??!0)&&I.addEventListener("click",A.onClickedARButton.bind(A)),I}static onModifyAROptions(A){Pi.dispatchEvent("modify-ar-options",A)}static resetButtonStyles(A){A&&(A.style.position="",A.style.bottom="",A.style.left="")}endSession(){const A=this.context.renderer.xr.getSession();A&&A.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var A,e;return this.controllers.length>0&&((A=this.controllers[0].input)==null?void 0:A.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((e=this.controllers[1].input)==null?void 0:e.handedness)==="left"?this.controllers[1]:null}get RightController(){var A,e;return this.controllers.length>0&&((A=this.controllers[0].input)==null?void 0:A.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((e=this.controllers[1].input)==null?void 0:e.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=Li.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!IA.findObjectOfType(Ul,this.context)){const A=IA.addNewComponent(this.gameObject,Ul,!1);A.webXR=this}this.webAR=new Wr(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(Wg("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,Pi.XRSupported;let A,e;const t=document.createElement("div");t.classList.add("webxr-buttons"),t.style.cssText=`
|
|
5182
5182
|
position: absolute;
|
|
5183
5183
|
bottom: 21px;
|
|
5184
5184
|
left: 50%;
|