@needle-tools/engine 3.28.6-beta → 3.28.7-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/dist/needle-engine.js +2 -2
- package/dist/needle-engine.light.js +2 -2
- package/dist/needle-engine.light.min.js +1 -1
- package/dist/needle-engine.light.umd.cjs +1 -1
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine-components/AnimatorController.js +3 -3
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/package.json +1 -1
- package/src/engine-components/AnimatorController.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,9 @@ All notable changes to this package will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [3.28.7-beta] - 2023-12-30
|
|
8
|
+
- Fix: Issue in AnimatorController evaluation of bool condition where the threshold wasnt taken into account (e.g. only making a transition if a bool parameter was set to false)
|
|
9
|
+
|
|
7
10
|
## [3.28.6-beta] - 2023-12-30
|
|
8
11
|
- Add: EventList can now have multiple arguments allowing support for e.g. `setBool` on Animator component being called from a Button directly
|
|
9
12
|
- Add: Animator `toggleBool` method
|
package/dist/needle-engine.js
CHANGED
|
@@ -58498,9 +58498,9 @@ class ps {
|
|
|
58498
58498
|
return !1;
|
|
58499
58499
|
switch (A.mode) {
|
|
58500
58500
|
case Er.If:
|
|
58501
|
-
return e.value ===
|
|
58501
|
+
return e.value === A.threshold;
|
|
58502
58502
|
case Er.IfNot:
|
|
58503
|
-
return e.value ===
|
|
58503
|
+
return e.value === A.threshold;
|
|
58504
58504
|
case Er.Greater:
|
|
58505
58505
|
return e.value > A.threshold;
|
|
58506
58506
|
case Er.Less:
|
|
@@ -58498,9 +58498,9 @@ class aa {
|
|
|
58498
58498
|
return !1;
|
|
58499
58499
|
switch (e.mode) {
|
|
58500
58500
|
case Wh.If:
|
|
58501
|
-
return t.value ===
|
|
58501
|
+
return t.value === e.threshold;
|
|
58502
58502
|
case Wh.IfNot:
|
|
58503
|
-
return t.value ===
|
|
58503
|
+
return t.value === e.threshold;
|
|
58504
58504
|
case Wh.Greater:
|
|
58505
58505
|
return t.value > e.threshold;
|
|
58506
58506
|
case Wh.Less:
|
|
@@ -5092,7 +5092,7 @@ ${o.join(`
|
|
|
5092
5092
|
`)}
|
|
5093
5093
|
|
|
5094
5094
|
}
|
|
5095
|
-
`}function B3(i){return`(${i.r}, ${i.g}, ${i.b})`}function D3(i){return`(${i.x}, ${i.y})`}const k3=[1023,33777,33778,33779,35842,35843,37496,37808,37809,37810,37811,37812,37813,37814,37815,37816,37817,37818,37819,37820,37821,36492];oe("debugusdz");const O3=class{constructor(i,e,t){h(this,"id"),h(this,"trigger"),h(this,"action"),h(this,"exclusive",!1),this.id="Behavior_"+t_(i)+"_"+O3.global_id++,this.trigger=e,this.action=t}makeExclusive(i){return this.exclusive=i,this}writeTo(i,e,t){if(!this.trigger||!this.action)return;t.beginBlock(`def Preliminary_Behavior "${this.id}"`),t.appendLine(`rel actions = <${this.action.id}>`),t.appendLine(`uniform bool exclusive = ${this.exclusive}`);let s="";if(Array.isArray(this.trigger)){s="[";for(let r=0;r<this.trigger.length;r++){const n=this.trigger[r];s+="<"+n.id+">",r+1<this.trigger.length&&(s+=", ")}s+="]"}else s=`<${this.trigger.id}>`;if(t.appendLine(`rel triggers = ${s} `),t.appendLine(),Array.isArray(this.trigger))for(const r of this.trigger)r.writeTo(e,t),t.appendLine();else this.trigger.writeTo(e,t);t.appendLine(),this.action.writeTo(e,t),t.closeBlock()}};let ur=O3;h(ur,"global_id",0);function pT(i,e){var t,s;let r="";if(Array.isArray(i)){let n="[ ";for(let o=0;o<i.length;o++){let a=i[o];if(typeof a=="string")n+=a;else if(typeof a=="object"){a.isObject3D&&(a=e.findById(a.uuid));const l=(t=a.getPath)==null?void 0:t.call(a);n+=l}o+1<i.length&&(n+=", ")}n+=" ]",r=n}else typeof i=="object"&&(i.isObject3D&&(i=e.findById(i.uuid)),r=(s=i.getPath)==null?void 0:s.call(i));return r}const L3=class{constructor(i,e){h(this,"id"),h(this,"targetId"),h(this,"tokenId"),h(this,"type"),h(this,"distance"),i&&(this.targetId=i),e?this.id=e:this.id="Trigger_"+L3.global_id++}writeTo(i,e){e.beginBlock(`def Preliminary_Trigger "${this.id}"`),this.targetId&&(typeof this.targetId!="string"&&(this.targetId=pT(this.targetId,i)),e.appendLine("rel affectedObjects = "+this.targetId)),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.type&&e.appendLine(`token type = "${this.type}"`),typeof this.distance=="number"&&e.appendLine(`double distance = ${this.distance}`),e.closeBlock()}};let Pu=L3;h(Pu,"global_id",0);class dr{static sceneStartTrigger(){const e=new Pu;return e.targetId=void 0,e.tokenId="SceneTransition",e.type="enter",e}static tapTrigger(e){const t=new Pu(e);return t.tokenId="TapGesture",t}static isTapTrigger(e){return e?.tokenId==="TapGesture"}static proximityToCameraTrigger(e,t){const s=new Pu(e);return s.tokenId="ProximityToCamera",s.distance=t,s}}class ih{constructor(e,t){h(this,"id"),h(this,"actions"),h(this,"loops",0),h(this,"performCount",1),h(this,"type","serial"),this.id=e,this.actions=t}static getId(){return this.global_id++}addAction(e){return this.actions.push(e),this}makeParallel(){return this.type="parallel",this}makeSequence(){return this.type="serial",this}makeLooping(){return this.loops=1,this}makeRepeat(e){return this.performCount=e,this}writeTo(e,t){t.beginBlock(`def Preliminary_Action "${this.id}"`),t.beginArray("rel actions");for(const s of this.actions){if(!s)continue;const r=s===this.actions[this.actions.length-1];t.appendLine("<"+s.id+">"+(r?"":", "))}t.closeArray(),t.appendLine(),t.appendLine('token info:id = "Group"'),t.appendLine(`bool loops = ${this.loops} `),t.appendLine(`int performCount = ${this.performCount} `),t.appendLine(`token type = "${this.type}"`),t.appendLine();for(const s of this.actions)s&&(s.writeTo(e,t),t.appendLine());t.closeBlock()}}h(ih,"global_id",0);var fT=(i=>(i[i.pop=0]="pop",i[i.blink=1]="blink",i[i.bounce=2]="bounce",i[i.flip=3]="flip",i[i.float=4]="float",i[i.jiggle=5]="jiggle",i[i.pulse=6]="pulse",i[i.spin=7]="spin",i))(fT||{}),mT=(i=>(i.Relative="relative",i.Absolute="absolute",i))(mT||{}),U3=(i=>(i.Allow="allow",i.Ignore="ignore",i.Stop="stop",i))(U3||{});const gT=class{constructor(i,e){h(this,"id"),h(this,"tokenId"),h(this,"affectedObjects"),h(this,"easeType"),h(this,"motionType"),h(this,"duration"),h(this,"moveDistance"),h(this,"style"),h(this,"type"),h(this,"front"),h(this,"up"),h(this,"start"),h(this,"animationSpeed"),h(this,"reversed"),h(this,"pingPong"),h(this,"xFormTarget"),h(this,"audio"),h(this,"gain"),h(this,"auralMode"),h(this,"multiplePerformOperation"),i&&(this.affectedObjects=i),e?this.id=e:this.id="Action",this.id+="_"+gT.global_id++}clone(){const i=new gT,e=i.id;return Object.assign(i,this),i.id=e,i}writeTo(i,e){e.beginBlock(`def Preliminary_Action "${this.id}"`),this.affectedObjects&&(typeof this.affectedObjects!="string"&&(this.affectedObjects=pT(this.affectedObjects,i)),e.appendLine("rel affectedObjects = "+this.affectedObjects)),typeof this.duration=="number"&&e.appendLine(`double duration = ${this.duration} `),this.easeType&&e.appendLine(`token easeType = "${this.easeType}"`),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.motionType&&e.appendLine(`token motionType = "${this.motionType}"`),typeof this.moveDistance=="number"&&e.appendLine(`double moveDistance = ${this.moveDistance} `),this.style&&e.appendLine(`token style = "${this.style}"`),this.type&&e.appendLine(`token type = "${this.type}"`),this.front&&e.appendLine(`vector3d front = (${this.front.x}, ${this.front.y}, ${this.front.z})`),this.up&&e.appendLine(`vector3d upVector = (${this.up.x}, ${this.up.y}, ${this.up.z})`),typeof this.start=="number"&&e.appendLine(`double start = ${this.start} `),typeof this.animationSpeed=="number"&&e.appendLine(`double animationSpeed = ${this.animationSpeed} `),typeof this.reversed=="boolean"&&e.appendLine(`bool reversed = ${this.reversed}`),typeof this.pingPong=="boolean"&&e.appendLine(`bool reverses = ${this.pingPong}`),this.xFormTarget&&(typeof this.xFormTarget!="string"&&(this.xFormTarget=pT(this.xFormTarget,i)),e.appendLine(`rel xformTarget = ${this.xFormTarget}`)),typeof this.audio=="string"&&e.appendLine(`asset audio = @${this.audio}@`),typeof this.gain=="number"&&e.appendLine(`double gain = ${this.gain}`),typeof this.auralMode=="string"&&e.appendLine(`token auralMode = "${this.auralMode}"`),typeof this.multiplePerformOperation=="string"&&e.appendLine(`token multiplePerformOperation = "${this.multiplePerformOperation}"`),e.closeBlock()}};let ha=gT;h(ha,"global_id",0);let Np=class Nf{constructor(e,t,s){h(this,"x",0),h(this,"y",0),h(this,"z",0),this.x=e,this.y=t,this.z=s}static get up(){return new Nf(0,1,0)}static get right(){return new Nf(1,0,0)}static get forward(){return new Nf(0,0,1)}static get back(){return new Nf(0,0,-1)}static get zero(){return new Nf(0,0,0)}};var vT=(i=>(i.Play="play",i.Pause="pause",i.Stop="stop",i))(vT||{}),AT=(i=>(i.Spatial="spatial",i.NonSpatial="nonSpatial",i.Ambient="ambient",i))(AT||{});class ni{static sequence(...e){return new ih("group_"+ih.getId(),e).makeSequence()}static parallel(...e){return new ih("group_"+ih.getId(),e).makeParallel()}static fadeAction(e,t,s){const r=new ha(e);return r.tokenId="Visibility",r.type=s?"show":"hide",r.duration=t,r.style="basic",r.motionType="none",r.moveDistance=0,r.easeType="none",r}static startAnimationAction(e,t,s=0,r=1,n=!1,o=!1){const a=new ha(e);if(a.tokenId="StartAnimation",a.start=t,a.duration=s,a.animationSpeed=r,a.reversed=n,a.pingPong=o,a.multiplePerformOperation="allow",n&&(a.start-=s),o){a.pingPong=!1;const l=a.clone();return l.reversed=!n,l.start=a.start,l.reversed&&(l.start-=s),ni.sequence(a,l)}return a}static waitAction(e){const t=new ha;return t.tokenId="Wait",t.duration=e,t}static lookAtCameraAction(e,t=9999999999999,s,r){const n=new ha(e);return n.tokenId="LookAtCamera",n.duration=t,n.front=s??Np.forward,n.up=r??Np.up,n}static emphasize(e,t,s=2,r=1,n="basic"){const o=new ha(e);return o.tokenId="Emphasize",o.duration=t,o.style=n??"basic",o.motionType=fT[s],o.moveDistance=r,o}static transformAction(e,t,s,r,n="inout"){const o=new ha(e);return o.tokenId="Transform",o.duration=s,o.type=r,o.easeType=n,Array.isArray(t)&&console.error("Transform target must not be an array",t),o.xFormTarget=t,o}static playAudioAction(e,t,s="play",r=1,n="spatial"){const o=new ha(e);return o.tokenId="Audio",o.type=s,o.audio=t,o.gain=r,o.auralMode=n,o.multiplePerformOperation="allow",o}}class Gte{constructor(e){h(this,"object"),h(this,"model"),this.object=e}get id(){return this.object.uuid}apply(e){if(!this.model&&(this.model=e.findById(this.object.uuid),!this.model)){console.error("could not find model with id "+this.object.uuid);return}this.onApply(e)}}class yT extends Gte{constructor(e,t,s,r){super(e),h(this,"matrix"),h(this,"material"),h(this,"geometry"),h(this,"_enableAction"),h(this,"_disableAction"),this.matrix=t,this.material=s,this.geometry=r}onApply(e){var t,s;const r=this.model;if(!r)return;(t=r.parent)!=null&&t.isDynamic||wo.createEmptyParent(r);const n=r.clone();this.matrix&&(n.matrix=this.matrix),this.material&&(n.material=this.material),this.geometry&&(n.geometry=this.geometry),(s=r.parent)==null||s.add(n)}enable(){return this._enableAction?this._enableAction:(this._enableAction=ni.fadeAction(this.object,0,!0),this._enableAction)}disable(){return this._disableAction?this._disableAction:(this._disableAction=ni.fadeAction(this.object,0,!1),this._disableAction)}}class bT{constructor(e){h(this,"actions"),h(this,"sortedActions"),this.actions=[...e]}organize(){this.sortedActions={};for(const e of this.actions){const t=e.id;this.sortedActions[t]||(this.sortedActions[t]=[]),this.sortedActions[t].push(e)}}getActions(e){return this.sortedActions||this.organize(),this.sortedActions[e.uuid]}}var Qte=Object.defineProperty,Vte=Object.getOwnPropertyDescriptor,F3=(i,e,t,s)=>{for(var r=s>1?void 0:s?Vte(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Qte(e,t,r),r};class Gg extends Pe{constructor(){super(...arguments),h(this,"from"),h(this,"to"),h(this,"width",0),h(this,"centered",!0),h(this,"_centerPos")}awake(){this._centerPos=new w}update(){if(!this.from||!this.to)return;const e=ft(this.from).clone(),t=ft(this.to).clone(),s=e.distanceTo(t);this._centerPos.copy(e),this._centerPos.add(t),this._centerPos.multiplyScalar(.5),ds(this.gameObject,this.centered?this._centerPos:e),this.gameObject.lookAt(ft(this.to).clone()),this.gameObject.scale.set(this.width,this.width,s)}}F3([x(te)],Gg.prototype,"from",2),F3([x(te)],Gg.prototype,"to",2);var Hte=Object.defineProperty,Wte=Object.getOwnPropertyDescriptor,Qg=(i,e,t,s)=>{for(var r=s>1?void 0:s?Wte(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Hte(e,t,r),r};const zp=oe("debuganimation");class Qn extends Pe{constructor(){super(...arguments),h(this,"playAutomatically",!0),h(this,"randomStartTime",!0),h(this,"minMaxSpeed"),h(this,"minMaxOffsetNormalized"),h(this,"loop",!0),h(this,"clampWhenFinished",!1),h(this,"_tempAnimationClipBeforeGameObjectExisted",null),h(this,"_tempAnimationsArray"),h(this,"mixer"),h(this,"_actions",[]),h(this,"_currentActions",[]),h(this,"_handles",[]),h(this,"_didInit",!1)}get clip(){var e;return(e=this.animations)!=null&&e.length?this.animations[0]:null}set clip(e){if(!this.__didAwake){zp&&console.warn("Assign clip during serialization",e),this._tempAnimationClipBeforeGameObjectExisted=e;return}e&&(this.gameObject.animations||(this.gameObject.animations=[]),!this.animations.includes(e)&&(this.animations.length>0?this.animations.splice(0,0,e):this.animations.push(e)))}set clips(e){this.animations=e}set animations(e){e==null||!Array.isArray(e)||(this.gameObject?this.gameObject.animations=e:this._tempAnimationsArray=e)}get animations(){return this.gameObject.animations||this._tempAnimationsArray||[]}get currentAction(){return this._currentActions[0]}get currentActions(){return this._currentActions}get actions(){return this._actions}set actions(e){this._actions=e}awake(){zp&&console.log("Animation Awake",this.name,this),this._tempAnimationsArray&&(this.animations=this._tempAnimationsArray,this._tempAnimationsArray=void 0),this._tempAnimationClipBeforeGameObjectExisted&&(this.clip=this._tempAnimationClipBeforeGameObjectExisted,this._tempAnimationClipBeforeGameObjectExisted=null),this.playAutomatically&&this.init()}onEnable(){var e;if(this.playAutomatically&&((e=this.animations)==null?void 0:e.length)>0&&this.currentActions.length<=0){const t=Math.floor(Math.random()*this.actions.length);this.play(t)}}start(){this.randomStartTime&&this.currentAction&&(this.currentAction.time=Math.random()*this.currentAction.getClip().duration)}update(){this.mixer&&this.mixer.update(this.context.time.deltaTime)}getAction(e){var t;return(t=this.actions)==null?void 0:t.find(s=>s.getClip().name===e)}get isPlaying(){for(let e=0;e<this.actions.length;e++)if(this.actions[e].isRunning())return!0;return!1}play(e=0,t){if(zp&&console.log("PLAY",e),this.init(),!this.mixer){zp&&console.warn("Missing mixer",this);return}e===void 0&&(e=0);let s=e;if(typeof e=="number"){if(e>=this.animations.length){zp&&console.log("No animation at index",e);return}s=this.animations[e]}else typeof e=="string"&&(s=this.animations.find(n=>n.name===e));if(!s){console.error("Could not find clip",e);return}t||(t={}),t.minMaxOffsetNormalized||(t.minMaxOffsetNormalized=this.minMaxOffsetNormalized),t.minMaxSpeed||(t.minMaxSpeed=this.minMaxSpeed),t.loop===void 0&&(t.loop=this.loop),t.clampWhenFinished===void 0&&(t.clampWhenFinished=this.clampWhenFinished);for(const n of this.actions)if(n.getClip()===s)return this.internalOnPlay(n,t);if(!(s instanceof vn)){console.warn("Clip is no AnimationClip",s,"on object: "+this.name);return}const r=this.mixer.clipAction(s);return this.actions.push(r),this.internalOnPlay(r,t)}internalOnPlay(e,t){var s=this.currentAction;if(s===e&&s.isRunning()&&s.time<s.getClip().duration){const a=this.tryFindHandle(e);if(a)return a.getPromise()}const r=t?.exclusive??!0;t!=null&&t.fadeDuration?(r&&s?.fadeOut(t.fadeDuration),e.fadeIn(t.fadeDuration)):r&&s?.stop(),e.reset(),e.enabled=!0,e.time=0,e.timeScale=1;const n=e.getClip();t!=null&&t.minMaxOffsetNormalized&&(e.time=rt.lerp(t.minMaxOffsetNormalized.x,t.minMaxOffsetNormalized.y,Math.random())*n.duration),t!=null&&t.minMaxSpeed&&(e.timeScale=rt.lerp(t.minMaxSpeed.x,t.minMaxSpeed.y,Math.random())),t!=null&&t.clampWhenFinished&&(e.clampWhenFinished=!0),t?.startTime!==void 0&&(e.time=t.startTime),t?.loop!==void 0?e.loop=t.loop?p1:$f:e.loop=$f,e.play(),zp&&console.log("PLAY",e.getClip().name,e);const o=new Xte(e,this.mixer,t,a=>{this._handles.splice(this._handles.indexOf(o),1)});return this._handles.push(o),o.getPromise()}tryFindHandle(e){for(const t of this._handles)if(t.action===e)return t}init(){this._didInit||(this._didInit=!0,this.gameObject&&(this.actions=[],this.mixer=new Jy(this.gameObject)))}}Qg([x()],Qn.prototype,"playAutomatically",2),Qg([x()],Qn.prototype,"randomStartTime",2),Qg([x()],Qn.prototype,"loop",2),Qg([x()],Qn.prototype,"clampWhenFinished",2),Qg([x(vn)],Qn.prototype,"clips",1);class Xte{constructor(e,t,s,r){h(this,"mixer"),h(this,"action"),h(this,"promise",null),h(this,"resolve",null),h(this,"reject",null),h(this,"_options"),h(this,"_resolveCallback",null),h(this,"_rejectCallback",null),h(this,"_loopCallback"),h(this,"_finishedCallback"),h(this,"_resolvedOrRejectedCallback"),this.action=e,this.mixer=t,this._resolvedOrRejectedCallback=r,this._options=s}getPromise(){return this.promise?this.promise:(this.promise=new Promise((e,t)=>{this._resolveCallback=e,this._rejectCallback=t,this.resolve=this.onResolve.bind(this),this.reject=this.onReject.bind(this)}),this._loopCallback=this.onLoop.bind(this),this._finishedCallback=this.onFinished.bind(this),this.mixer.addEventListener("loop",this._loopCallback),this.mixer.addEventListener("finished",this._finishedCallback),this.promise)}_update(){this._options&&this._options.endTime!==void 0&&this.action.time>this._options.endTime&&(this._options.loop===!0?this.action.time=this._options.startTime??0:(this.action.time=this._options.endTime,this.action.timeScale=0,this.onResolve()))}onResolve(){var e,t;this.dispose(),(e=this._resolvedOrRejectedCallback)==null||e.call(this,this),(t=this._resolveCallback)==null||t.call(this,this.action)}onReject(e){var t,s;this.dispose(),(t=this._resolvedOrRejectedCallback)==null||t.call(this,this),(s=this._rejectCallback)==null||s.call(this,e)}onLoop(e){}onFinished(e){e.action===this.action&&this.onResolve()}dispose(){this._loopCallback&&this.mixer.removeEventListener("loop",this._loopCallback),this._finishedCallback&&this.mixer.removeEventListener("finished",this._finishedCallback),this._loopCallback=void 0,this._finishedCallback=void 0}}var qte=Object.defineProperty,Yte=Object.getOwnPropertyDescriptor,sh=(i,e,t,s)=>{for(var r=s>1?void 0:s?Yte(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&qte(e,t,r),r};class rh{constructor(){h(this,"time"),h(this,"value"),h(this,"inTangent"),h(this,"inWeight"),h(this,"outTangent"),h(this,"outWeight"),h(this,"weightedMode")}}sh([x()],rh.prototype,"time",2),sh([x()],rh.prototype,"value",2),sh([x()],rh.prototype,"inTangent",2),sh([x()],rh.prototype,"inWeight",2),sh([x()],rh.prototype,"outTangent",2),sh([x()],rh.prototype,"outWeight",2),sh([x()],rh.prototype,"weightedMode",2);const N3=class{constructor(){h(this,"keys")}get duration(){return!this.keys||this.keys.length==0?0:this.keys[this.keys.length-1].time}evaluate(i){if(!this.keys||this.keys.length==0)return 0;if(this.keys[0].time>=i)return this.keys[0].value;for(let e=0;e<this.keys.length;e++){const t=this.keys[e];if(t.time<=i)if(e+1<this.keys.length){const s=this.keys[e+1];if(s.time<i)continue;return!isFinite(t.outTangent)||!isFinite(s.inTangent)?t.value:N3.interpolateValue(i,t,s)}else return t.value}return this.keys[this.keys.length-1].value}static interpolateValue(i,e,t){const s=e.time,r=e.value,n=e.outTangent,o=t.time,a=t.value,l=t.inTangent,c=o-s,u=c*c,d=u*c,p=((n+l)*c-2*(a-r))/d,f=(3*(a-r)-(l+2*n)*c)/u,m=n,A=r,v=i-s,g=v*v,b=g*v;return p*b+f*g+m*v+A}};let Bu=N3;sh([x(rh)],Bu.prototype,"keys",2);class Kte{constructor(){h(this,"_context")}get context(){return this._context??Ot.Current}get isStateMachineBehaviour(){return!0}}class a_{constructor(e,t,s,r){h(this,"_name"),h(this,"_nameHash"),h(this,"_normalizedTime"),h(this,"_length"),h(this,"_speed"),this._name=e.name,this._nameHash=e.hash,this._normalizedTime=t,this._length=s,this._speed=r}get name(){return this._name}get nameHash(){return this._nameHash}get normalizedTime(){return this._normalizedTime}get length(){return this._length}get speed(){return this._speed}}function z3(i,e){return{name:"",isLooping:!1,guid:e?.generateUUID()??sr.generateUUID(),index:-1,clip:new vn(i,1,[])}}var nh=(i=>(i[i.If=1]="If",i[i.IfNot=2]="IfNot",i[i.Greater=3]="Greater",i[i.Less=4]="Less",i[i.Equals=6]="Equals",i[i.NotEqual=7]="NotEqual",i))(nh||{}),_T=(i=>(i[i.Float=1]="Float",i[i.Int=3]="Int",i[i.Bool=4]="Bool",i[i.Trigger=9]="Trigger",i))(_T||{});const So=oe("debuganimatorcontroller"),l_=oe("debugrootmotion");class No{constructor(e){h(this,"normalizedStartOffset",0),h(this,"_speed",1),h(this,"animator"),h(this,"model"),h(this,"_mixer"),h(this,"_activeState"),h(this,"_activeStates",[]),h(this,"rootMotionHandler"),this.model=e,So&&console.log(this)}static createFromClips(e,t={looping:!1,autoTransition:!0,transitionDuration:0}){const s=[];for(let n=0;n<e.length;n++){const o=e[n],a=[];if(t.autoTransition!==!1){const c=t.transitionDuration??0,u=c/o.duration;let d=n;(t.autoTransition===void 0||t.autoTransition===!0)&&(d=(n+1)%e.length),a.push({exitTime:1-u,offset:0,duration:c,hasExitTime:!0,destinationState:d,conditions:[]})}const l={name:o.name,hash:n,motion:{name:o.name,clip:o,isLooping:t?.looping??!1},transitions:a,behaviours:[]};s.push(l)}const r={name:"AnimatorController",guid:new Vr(Date.now()).generateUUID(),parameters:[],layers:[{name:"Base Layer",stateMachine:{defaultState:0,states:s}}]};return new No(r)}play(e,t=-1,s=Number.NEGATIVE_INFINITY,r=0){if(t<0)t=0;else if(t>=this.model.layers.length){console.warn("invalid layer");return}const n=this.model.layers[t].stateMachine;for(const o of n.states)if(o.name===e||o.hash===e){So&&console.log("transition to ",o),this.transitionTo(o,r,s);return}console.warn("Could not find "+e+" to play")}reset(){this.setStartTransition()}setBool(e,t){var s,r;const n=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[n]===e).forEach(o=>o.value=t)}getBool(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??!1}setFloat(e,t){var s,r;const n=typeof e=="string"?"name":"hash",o=(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(a=>a[n]===e);return o.forEach(a=>a.value=t),o?.length>0}getFloat(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??0}setInteger(e,t){var s,r;const n=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[n]===e).forEach(o=>o.value=t)}getInteger(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??0}setTrigger(e){var t,s;So&&console.log("SET TRIGGER",e);const r=typeof e=="string"?"name":"hash";return(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.filter(n=>n[r]===e).forEach(n=>n.value=!0)}resetTrigger(e){var t,s;const r=typeof e=="string"?"name":"hash";return(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.filter(n=>n[r]===e).forEach(n=>n.value=!1)}getTrigger(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??!1}isInTransition(){return this._activeStates.length>1}setSpeed(e){this._speed=e}FindState(e){return this.findState(e)}findState(e){if(!e)return null;if(Array.isArray(this.model.layers)){for(const t of this.model.layers)for(const s of t.stateMachine.states)if(s.name===e||s.hash==e)return s}return null}get context(){var e;return(e=this.animator)==null?void 0:e.context}get mixer(){return this._mixer}bind(e){e?this.animator!==e&&(this.animator=e,this._mixer=new Jy(this.animator.gameObject),this.createActions(this.animator)):console.error("AnimatorController.bind: animator is null")}clone(){if(typeof this.model=="string")return console.warn("AnimatorController has not been resolved, can not create model from string",this.model),null;const e=Lm(this.model,(t,s,r)=>r==null?!0:!(r.type==="Object3D"||r.isObject3D===!0||e2(r)||r.tracks!==void 0));return console.assert(e!==this.model),new No(e)}update(e){var t,s;if(!this.animator)return;this.evaluateTransitions(),this.updateActiveStates(e);const r=this.animator.context.time.deltaTime;this.animator.applyRootMotion&&((t=this.rootMotionHandler)==null||t.onBeforeUpdate(e)),this._mixer.update(r),this.animator.applyRootMotion&&((s=this.rootMotionHandler)==null||s.onAfterUpdate(e))}get activeState(){return this._activeState}updateActiveStates(e){for(let t=0;t<this._activeStates.length;t++){const s=this._activeStates[t],r=s.motion;if(!r.action)this._activeStates.splice(t,1),t--;else{const n=r.action;n.weight=e,n.getEffectiveWeight()<=0&&!n.isRunning()&&(So&&console.debug("REMOVE",s.name,n.getEffectiveWeight(),n.isRunning(),n.isScheduled()),this._activeStates.splice(t,1),t--)}}}setStartTransition(){for(const e of this.model.layers){const t=e.stateMachine;t.defaultState===void 0&&(So&&console.warn("AnimatorController default state is undefined, will assign state 0 as default",e),t.defaultState=0);const s=t.states[t.defaultState];this.transitionTo(s,0,this.normalizedStartOffset)}}evaluateTransitions(){var e;let t=!1;if(!this._activeState){if(this.setStartTransition(),!this._activeState)return;t=!0}const s=this._activeState,r=s.motion.action;for(const o of s.transitions){if(!o.hasExitTime&&o.conditions.length<=0)continue;let a=!0;for(const l of o.conditions)if(!this.evaluateCondition(l)){a=!1;break}if(a)if(r){const l=s.motion.clip.duration,c=l<=0?1:Math.abs(r.time/l);let u=!1;if(o.hasExitTime?r.timeScale>0?u=c>=o.exitTime:r.timeScale<0&&(u=1-c>=o.exitTime):u=!0,u){for(const d of o.conditions){const p=this.model.parameters.find(f=>f.name===d.parameter);p?.type===_T.Trigger&&p.value&&(p.value=!1)}r.clampWhenFinished=!0,So&&console.log("transition to "+o.destinationState,o,c,o.exitTime,o.hasExitTime),this.transitionTo(o.destinationState,o.duration,o.offset);return}}else{this.transitionTo(o.destinationState,o.duration,o.offset);return}}if(r){let o=s.speed??1;s.speedParameter&&(o*=this.getFloat(s.speedParameter)),o!==void 0&&(r.timeScale=o*this._speed)}let n=!1;if(s.motion.isLooping&&r&&(r.time>=r.getClip().duration?(n=!0,r.reset(),r.time=0,r.play()):r.time<=0&&r.timeScale<0&&(n=!0,r.reset(),r.time=r.getClip().duration,r.play())),!n&&s&&!t&&r&&this.animator&&s.behaviours){const o=r?.getClip().duration,a=r.time/o,l=new a_(this._activeState,a,o,this._speed);for(const c of s.behaviours)c.instance&&((e=c.instance.onStateUpdate)==null||e.call(c.instance,this.animator,l,0))}}getState(e,t){return typeof e=="number"&&(e==-1&&(e=this.model.layers[t].stateMachine.defaultState,e===void 0&&(So&&console.warn("AnimatorController default state is undefined: ",this.model,"Layer: "+t),e=0)),e=this.model.layers[t].stateMachine.states[e]),e}transitionTo(e,t,s){var r,n,o,a,l,c,u,d;if(!this.animator)return;const p=0;if(e=this.getState(e,p),!(e!=null&&e.motion)||!e.motion.clip||!(e.motion.clip instanceof vn))return;const f=this._activeState===e;if(f){const g=e.motion;if(!g.action_loopback&&g.clip){const b=this.rootMotionHandler?this.animator.gameObject.matrix.clone():null;this._mixer.uncacheAction(g.clip,this.animator.gameObject),b&&b.decompose(this.animator.gameObject.position,this.animator.gameObject.quaternion,this.animator.gameObject.scale),g.action_loopback=this.createAction(g.clip)}}if((r=this._activeState)!=null&&r.behaviours&&this._activeState.motion.action){const g=(n=this._activeState)==null?void 0:n.motion.clip.duration,b=this._activeState.motion.action.time/g,y=new a_(this._activeState,b,g,this._speed);for(const _ of this._activeState.behaviours)(a=(o=_.instance)==null?void 0:o.onStateExit)==null||a.call(_.instance,this.animator,y,p)}const m=(l=this._activeState)==null?void 0:l.motion.action;m&&m.fadeOut(t),f&&(e.motion.action=e.motion.action_loopback,e.motion.action_loopback=m);const A=this._activeState;this._activeState=e;const v=(c=e.motion)==null?void 0:c.action;if(v){if(s=Math.max(0,Math.min(1,s)),e.cycleOffsetParameter){let b=this.getFloat(e.cycleOffsetParameter);typeof b=="number"?(b<0&&(b+=1),s+=b,s%=1):So&&console.warn("AnimatorController cycle offset parameter is not a number",e.cycleOffsetParameter)}else typeof e.cycleOffset=="number"&&(s+=e.cycleOffset,s%=1);v.isRunning()&&v.stop(),v.reset(),v.enabled=!0;const g=e.motion.clip.duration;if(v.time=f?0:s*g,v.timeScale<0&&(v.time=g-v.time),v.clampWhenFinished=!0,v.setLoop($f,0),t>0?v.fadeIn(t):v.weight=1,v.play(),this.rootMotionHandler&&this.rootMotionHandler.onStart(v),this._activeStates.includes(e)||this._activeStates.push(e),this._activeState.behaviours){const b=new a_(e,s,g,this._speed);for(const y of this._activeState.behaviours)(d=(u=y.instance)==null?void 0:u.onStateEnter)==null||d.call(y.instance,this.animator,b,p)}}else So&&(e.__warned_no_motion||(e.__warned_no_motion=!0,console.warn("No action",e.motion,this)));So&&console.log("TRANSITION FROM "+A?.name+" TO "+e.name,t,m,v,v?.getEffectiveTimeScale(),v?.getEffectiveWeight(),v?.isRunning(),v?.isScheduled(),v?.paused)}createAction(e){var t,s;if(this._mixer.existingAction(e)&&this._mixer.uncacheAction(e,(t=this.animator)==null?void 0:t.gameObject),(s=this.animator)!=null&&s.applyRootMotion){this.rootMotionHandler||(this.rootMotionHandler=new Jte(this));const r=this.animator.gameObject;return this.rootMotionHandler.createClip(this._mixer,r,e)}else return this._mixer.clipAction(e)}evaluateCondition(e){const t=this.model.parameters.find(s=>s.name===e.parameter);if(!t)return!1;switch(e.mode){case nh.If:return t.value===!0;case nh.IfNot:return t.value===!1;case nh.Greater:return t.value>e.threshold;case nh.Less:return t.value<e.threshold;case nh.Equals:return t.value===e.threshold;case nh.NotEqual:return t.value!==e.threshold}return!1}createActions(e){var t,s;for(const r of this.model.layers){const n=r.stateMachine;for(let o=0;o<n.states.length;o++){const a=n.states[o];a.transitions||(a.transitions=[]);for(const l of a.transitions)l.conditions||(l.conditions=[]);if(a.motion||(a.motion=z3(a.name)),this.animator&&a.motion.clips){const l=(t=a.motion.clips)==null?void 0:t.find(c=>{var u,d;return c.node.name===((d=(u=this.animator)==null?void 0:u.gameObject)==null?void 0:d.name)});a.motion.clip=l?.clip}if(!a.motion.clip){const l=new vn(void 0,void 0,[]);a.motion.clip=l}if((s=a.motion)!=null&&s.clip){const l=a.motion.clip;if(l instanceof vn){const c=this.createAction(l);a.motion.action=c}else(So||zt())&&console.warn("No valid animationclip assigned",a)}if(a.behaviours&&Array.isArray(a.behaviours))for(const l of a.behaviours){if(!(l!=null&&l.typeName))continue;const c=Y.get(l.typeName),u=new c;u.isStateMachineBehaviour&&(u._context=this.context??void 0,ap(u,l.properties),l.instance=u),So&&console.log("Created animator controller behaviour",a.name,l.typeName,l.properties,u)}}}}*enumerateActions(){if(this.model.layers)for(const e of this.model.layers){const t=e.stateMachine;for(let s=0;s<t.states.length;s++){const r=t.states[s];r!=null&&r.motion&&(r.motion.action&&(yield r.motion.action),r.motion.action_loopback&&(yield r.motion.action_loopback))}}}}class j3{constructor(e,t){h(this,"track"),h(this,"createdInterpolant"),h(this,"originalEvaluate"),h(this,"customEvaluate"),this.track=e;const s=e,r=s.createInterpolant.bind(e);s.createInterpolant=()=>(s.createInterpolant=r,this.createdInterpolant=r(),this.originalEvaluate=this.createdInterpolant.evaluate.bind(this.createdInterpolant),this.customEvaluate=n=>{if(!this.originalEvaluate)return;const o=this.originalEvaluate(n);return t(n,o)},this.createdInterpolant.evaluate=this.customEvaluate,this.createdInterpolant)}dispose(){this.createdInterpolant&&this.originalEvaluate&&(this.createdInterpolant.evaluate=this.originalEvaluate),this.track=void 0,this.createdInterpolant=null,this.originalEvaluate=void 0,this.customEvaluate=void 0}}const Ks=class{constructor(i,e,t,s,r){if(h(this,"_action"),h(this,"root"),h(this,"clip"),h(this,"positionWrapper",null),h(this,"rotationWrapper",null),h(this,"context"),h(this,"positionChange",new w),h(this,"rotationChange",new Me),h(this,"_prevTime",0),this.context=i,this.root=e,this.clip=t,Ks.firstKeyframeRotation[this.cacheId]||(Ks.firstKeyframeRotation[this.cacheId]=new Me),r){const n=r.values;Ks.firstKeyframeRotation[this.cacheId].set(n[0],n[1],n[2],n[3])}Ks.spaceRotation[this.cacheId]||(Ks.spaceRotation[this.cacheId]=new Me),Ks.effectiveSpaceRotation[this.cacheId]||(Ks.effectiveSpaceRotation[this.cacheId]=new Me),Ks.clipOffsetRotation[this.cacheId]=new Me,r&&Ks.clipOffsetRotation[this.cacheId].set(r.values[0],r.values[1],r.values[2],r.values[3]).invert(),this.handlePosition(t,s),this.handleRotation(t,r)}set action(i){this._action=i}get action(){return this._action}get cacheId(){return this.root.uuid}onStart(i){if(i.getClip()!==this.clip)return;Ks.lastObjRotation[this.cacheId]||(Ks.lastObjRotation[this.cacheId]=this.root.quaternion.clone());const e=Ks.lastObjRotation[this.cacheId];if(Ks.spaceRotation[this.cacheId].copy(e),l_){const t=new zs().setFromQuaternion(e);console.log("START",this.clip.name,rt.toDegrees(t.y),this.root.position.z)}}getClipRotationOffset(){return Ks.clipOffsetRotation[this.cacheId]}handlePosition(i,e){if(e){const t=this.root;l_&&t.add(new ep),Ks.lastObjPosition[this.cacheId]||(Ks.lastObjPosition[this.cacheId]=this.root.position.clone());const s=new w,r=new w;this.positionWrapper=new j3(e,(n,o)=>{const a=this.action.getEffectiveWeight();return l_&&t.position.length()>8&&t.position.set(0,t.position.y,0),n>this._prevTime&&(s.set(o[0],o[1],o[2]),s.sub(r),s.multiplyScalar(a),s.applyQuaternion(this.getClipRotationOffset()),s.applyQuaternion(t.quaternion),this.positionChange.copy(s)),r.fromArray(o),this._prevTime=n,o[0]=0,o[1]=0,o[2]=0,o})}}handleRotation(i,e){if(e){if(l_){const n=e.values,o=new zs().setFromQuaternion(new Me(n[0],n[1],n[2],n[3]));console.log(i.name,e.name,"FIRST ROTATION IN TRACK",rt.toDegrees(o.y));const a=e.values.length-4,l=new Me().set(n[a],n[a+1],n[a+2],n[a+3]),c=new zs().setFromQuaternion(l);console.log(i.name,e.name,"LAST ROTATION IN TRACK",rt.toDegrees(c.y))}let t=0;const s=new Me,r=new Me;this.rotationWrapper=new j3(e,(n,o)=>(n>t&&(r.set(o[0],o[1],o[2],o[3]),s.invert(),r.multiply(s),this.rotationChange.copy(r)),s.fromArray(o),t=n,o[0]=0,o[1]=0,o[2]=0,o[3]=1,o))}}onBeforeUpdate(i){this.positionChange.set(0,0,0),this.rotationChange.set(0,0,0,1)}onAfterUpdate(i){return!this.action||(i*=this.action.getEffectiveWeight(),i<=0)?!1:(this.positionChange.multiplyScalar(i),this.rotationChange.slerp(Ks.identityQuaternion,1-i),!0)}};let oh=Ks;h(oh,"lastObjPosition",{}),h(oh,"lastObjRotation",{}),h(oh,"firstKeyframeRotation",{}),h(oh,"spaceRotation",{}),h(oh,"effectiveSpaceRotation",{}),h(oh,"clipOffsetRotation",{}),h(oh,"identityQuaternion",new Me);class Jte{constructor(e){h(this,"controller"),h(this,"handler",[]),h(this,"root"),h(this,"basePosition",new w),h(this,"baseQuaternion",new Me),h(this,"baseRotation",new zs),h(this,"summedPosition",new w),h(this,"summedRotation",new Me),this.controller=e}createClip(e,t,s){this.root=t,t&&"name"in t&&t.name;const r=this.findRootTrack(s,".position"),n=this.findRootTrack(s,".quaternion"),o=new oh(this.controller.context,t,s,r,n);this.handler.push(o);const a=e.clipAction(s);return o.action=a,a}onStart(e){for(const t of this.handler)t.onStart(e)}onBeforeUpdate(e){this.basePosition.copy(this.root.position),this.baseQuaternion.copy(this.root.quaternion);for(const t of this.handler)t.onBeforeUpdate(e)}onAfterUpdate(e){if(!(e<=0)){this.root.position.copy(this.basePosition),this.root.quaternion.copy(this.baseQuaternion),this.summedPosition.set(0,0,0),this.summedRotation.set(0,0,0,1);for(const t of this.handler)t.onAfterUpdate(e)&&(this.summedPosition.add(t.positionChange),this.summedRotation.multiply(t.rotationChange));this.root.position.add(this.summedPosition),this.root.quaternion.multiply(this.summedRotation)}}findRootTrack(e,t){const s=e.tracks;if(!s)return null;for(const r of s)if(r.name.endsWith(t))return r;return null}}class Zte extends Pl{onSerialize(e,t){}onDeserialize(e,t){if(t.type===No&&e?.__type==="AnimatorController")return new No(e)}}new Zte(No);class $te extends ls{constructor(e,t=1,s=16,r=2){const n=new gt,o=s+r*2,a=new Float32Array((o*3+3)*3);n.setAttribute("position",new et(a,3));const l=new as({color:65280}),c=new as({color:16776960});super(n,[c,l]),this.audio=e,this.range=t,this.divisionsInnerAngle=s,this.divisionsOuterAngle=r,this.type="PositionalAudioHelper",this.update()}update(){const e=this.audio,t=this.range,s=this.divisionsInnerAngle,r=this.divisionsOuterAngle,n=sr.degToRad(e.panner.coneInnerAngle),o=sr.degToRad(e.panner.coneOuterAngle),a=n/2,l=o/2;let c=0,u=0,d,p;const f=this.geometry,m=f.attributes.position;f.clearGroups();function A(v,g,b,y){const _=(g-v)/b;for(m.setXYZ(c,0,0,0),u++,d=v;d<g;d+=_)p=c+u,m.setXYZ(p,Math.sin(d)*t,0,Math.cos(d)*t),m.setXYZ(p+1,Math.sin(Math.min(d+_,g))*t,0,Math.cos(Math.min(d+_,g))*t),m.setXYZ(p+2,0,0,0),u+=3;f.addGroup(c,u,y),c+=u,u=0}A(-l,-a,r,0),A(-a,a,s,1),A(a,l,r,0),m.needsUpdate=!0,n===o&&(this.material[0].visible=!1)}dispose(){this.geometry.dispose(),this.material[0].dispose(),this.material[1].dispose()}}var eie=Object.defineProperty,tie=Object.getOwnPropertyDescriptor,Xl=(i,e,t,s)=>{for(var r=s>1?void 0:s?tie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&eie(e,t,r),r};const pr=oe("debugaudio");let c_=!1;const h_=[];function u_(){if(c_)return;zt()&&console.log("User interaction registered: audio can now be played"),c_=!0;const i=[...h_];h_.length=0,i.forEach(e=>e())}document.addEventListener("pointerdown",u_),document.addEventListener("click",u_),document.addEventListener("dragstart",u_),document.addEventListener("touchstart",u_);const ql=class extends Pe{constructor(){super(...arguments),h(this,"clip",""),h(this,"playOnAwake",!1),h(this,"_spatialBlend",0),h(this,"_minDistance",1),h(this,"_maxDistance",100),h(this,"_volume",1),h(this,"rollOffMode",0),h(this,"playInBackground",!0),h(this,"_loop",!1),h(this,"sound",null),h(this,"helper",null),h(this,"wasPlaying",!1),h(this,"audioLoader",null),h(this,"shouldPlay",!1),h(this,"_lastClipStartedLoading",null),h(this,"_audioElement",null),h(this,"onVisibilityChanged",()=>{switch(document.visibilityState){case"hidden":(this.playInBackground===!1||_l())&&(this.wasPlaying=this.isPlaying,this.isPlaying&&this.pause());break;case"visible":pr&&console.log("visible",this.enabled,this.playOnAwake,!this.isPlaying,ql.userInteractionRegistered,this.wasPlaying),this.enabled&&this.playOnAwake&&!this.isPlaying&&ql.userInteractionRegistered&&this.wasPlaying&&this.play();break}}),h(this,"onApplicationMuteChanged",()=>{var i,e;this.context.application.muted?(i=this.sound)==null||i.setVolume(0):(e=this.sound)==null||e.setVolume(this.volume)}),h(this,"lerp",(i,e,t)=>i*(1-t)+e*t),h(this,"createAudio",i=>{pr&&console.log("audio buffer loaded"),ql.registerWaitForAllowAudio(()=>{pr&&console.log("finished loading",i);const e=this.Sound;if(!e){console.warn("Failed getting sound",this.name);return}e.isPlaying&&e.stop(),i&&e.setBuffer(i),e.loop=this._loop,this.context.application.muted?e.setVolume(0):e.setVolume(this.volume),e.autoplay=this.shouldPlay,this.applySpatialDistanceSettings(),e.isPlaying&&e.stop(),pr&&console.log(this.name,this.shouldPlay,ql.userInteractionRegistered,this),this.shouldPlay&&ql.userInteractionRegistered&&this.play()})}),h(this,"_lastContextTime",0),h(this,"_hasEnded",!0),h(this,"_needUpdateSpatialDistanceSettings",!1)}static get userInteractionRegistered(){return c_}static registerWaitForAllowAudio(i){if(i!==null){if(c_){i();return}h_.indexOf(i)===-1&&h_.push(i)}}get loop(){return this.sound&&(this._loop=this.sound.getLoop()),this._loop}set loop(i){this._loop=i,this.sound&&this.sound.setLoop(i)}get spatialBlend(){return this._spatialBlend}set spatialBlend(i){i!==this._spatialBlend&&(this._spatialBlend=i,this._needUpdateSpatialDistanceSettings=!0)}get minDistance(){return this._minDistance}set minDistance(i){this._minDistance!==i&&(this._minDistance=i,this._needUpdateSpatialDistanceSettings=!0)}get maxDistance(){return this._maxDistance}set maxDistance(i){this._maxDistance!==i&&(this._maxDistance=i,this._needUpdateSpatialDistanceSettings=!0)}get volume(){return this._volume}set volume(i){this._volume=i,this.sound&&!this.context.application.muted&&(pr&&console.log(this.name,"audio set volume",i),this.sound.setVolume(i))}get Sound(){if(!this.sound&&ql.userInteractionRegistered){let i=te.getComponent(this.context.mainCamera,dh)??te.findObjectOfType(dh,this.context);!i&&this.context.mainCamera&&(i=te.addNewComponent(this.context.mainCamera,dh)),i!=null&&i.listener?(this.sound=new ok(i.listener),this.gameObject.add(this.sound)):pr&&console.warn("No audio listener found in scene - can not play audio")}return this.sound}get ShouldPlay(){return this.shouldPlay}awake(){pr&&console.log(this),this.audioLoader=new Ky,this.playOnAwake&&(this.shouldPlay=!0)}onEnable(){ql.userInteractionRegistered?this.playOnAwake&&this.context.application.isVisible&&this.play():ql.registerWaitForAllowAudio(()=>{this.enabled&&!this.destroyed&&this.shouldPlay&&this.onNewClip(this.clip)}),globalThis.addEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.addEventListener(pb.MuteChanged,this.onApplicationMuteChanged)}onDisable(){globalThis.removeEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.removeEventListener(pb.MuteChanged,this.onApplicationMuteChanged),this.pause()}applySpatialDistanceSettings(){const i=this.sound;if(!i)return;this._needUpdateSpatialDistanceSettings=!1;const e=this.lerp(10*this._maxDistance/Math.max(1e-4,this.spatialBlend),this._minDistance,this.spatialBlend);switch(pr&&console.log(this.name,this._minDistance,this._maxDistance,this.spatialBlend,"Ref distance="+e),i.setRefDistance(e),i.setMaxDistance(Math.max(.01,this._maxDistance)),this.rollOffMode){case 0:i.setDistanceModel("exponential");break;case 1:i.setDistanceModel("linear");break}this.spatialBlend>0?pr&&!this.helper&&(this.helper=new $te(i,i.getRefDistance()),i.add(this.helper)):this.helper&&this.helper.parent&&this.helper.removeFromParent()}onNewClip(i){if(i&&(this.clip=i),typeof i=="string")if(pr&&console.log(i),i.endsWith(".mp3")||i.endsWith(".wav")){if(this.audioLoader||(this.audioLoader=new Ky),this.shouldPlay=!0,this._lastClipStartedLoading===i){pr&&console.log("Is currently loading:",this._lastClipStartedLoading,this);return}this._lastClipStartedLoading=i,pr&&console.log("load audio",i),this.audioLoader.load(i,this.createAudio,()=>{},console.error)}else console.warn("Unsupported audio clip type",i);else this.shouldPlay=!0,this.createAudio()}play(i=void 0){var e,t;!i&&this.clip&&(i=this.clip),i!==void 0&&typeof i!="string"&&!(i instanceof MediaStream)&&(zt()&&console.warn("Called play on AudioSource with unknown argument type:",i+`
|
|
5095
|
+
`}function B3(i){return`(${i.r}, ${i.g}, ${i.b})`}function D3(i){return`(${i.x}, ${i.y})`}const k3=[1023,33777,33778,33779,35842,35843,37496,37808,37809,37810,37811,37812,37813,37814,37815,37816,37817,37818,37819,37820,37821,36492];oe("debugusdz");const O3=class{constructor(i,e,t){h(this,"id"),h(this,"trigger"),h(this,"action"),h(this,"exclusive",!1),this.id="Behavior_"+t_(i)+"_"+O3.global_id++,this.trigger=e,this.action=t}makeExclusive(i){return this.exclusive=i,this}writeTo(i,e,t){if(!this.trigger||!this.action)return;t.beginBlock(`def Preliminary_Behavior "${this.id}"`),t.appendLine(`rel actions = <${this.action.id}>`),t.appendLine(`uniform bool exclusive = ${this.exclusive}`);let s="";if(Array.isArray(this.trigger)){s="[";for(let r=0;r<this.trigger.length;r++){const n=this.trigger[r];s+="<"+n.id+">",r+1<this.trigger.length&&(s+=", ")}s+="]"}else s=`<${this.trigger.id}>`;if(t.appendLine(`rel triggers = ${s} `),t.appendLine(),Array.isArray(this.trigger))for(const r of this.trigger)r.writeTo(e,t),t.appendLine();else this.trigger.writeTo(e,t);t.appendLine(),this.action.writeTo(e,t),t.closeBlock()}};let ur=O3;h(ur,"global_id",0);function pT(i,e){var t,s;let r="";if(Array.isArray(i)){let n="[ ";for(let o=0;o<i.length;o++){let a=i[o];if(typeof a=="string")n+=a;else if(typeof a=="object"){a.isObject3D&&(a=e.findById(a.uuid));const l=(t=a.getPath)==null?void 0:t.call(a);n+=l}o+1<i.length&&(n+=", ")}n+=" ]",r=n}else typeof i=="object"&&(i.isObject3D&&(i=e.findById(i.uuid)),r=(s=i.getPath)==null?void 0:s.call(i));return r}const L3=class{constructor(i,e){h(this,"id"),h(this,"targetId"),h(this,"tokenId"),h(this,"type"),h(this,"distance"),i&&(this.targetId=i),e?this.id=e:this.id="Trigger_"+L3.global_id++}writeTo(i,e){e.beginBlock(`def Preliminary_Trigger "${this.id}"`),this.targetId&&(typeof this.targetId!="string"&&(this.targetId=pT(this.targetId,i)),e.appendLine("rel affectedObjects = "+this.targetId)),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.type&&e.appendLine(`token type = "${this.type}"`),typeof this.distance=="number"&&e.appendLine(`double distance = ${this.distance}`),e.closeBlock()}};let Pu=L3;h(Pu,"global_id",0);class dr{static sceneStartTrigger(){const e=new Pu;return e.targetId=void 0,e.tokenId="SceneTransition",e.type="enter",e}static tapTrigger(e){const t=new Pu(e);return t.tokenId="TapGesture",t}static isTapTrigger(e){return e?.tokenId==="TapGesture"}static proximityToCameraTrigger(e,t){const s=new Pu(e);return s.tokenId="ProximityToCamera",s.distance=t,s}}class ih{constructor(e,t){h(this,"id"),h(this,"actions"),h(this,"loops",0),h(this,"performCount",1),h(this,"type","serial"),this.id=e,this.actions=t}static getId(){return this.global_id++}addAction(e){return this.actions.push(e),this}makeParallel(){return this.type="parallel",this}makeSequence(){return this.type="serial",this}makeLooping(){return this.loops=1,this}makeRepeat(e){return this.performCount=e,this}writeTo(e,t){t.beginBlock(`def Preliminary_Action "${this.id}"`),t.beginArray("rel actions");for(const s of this.actions){if(!s)continue;const r=s===this.actions[this.actions.length-1];t.appendLine("<"+s.id+">"+(r?"":", "))}t.closeArray(),t.appendLine(),t.appendLine('token info:id = "Group"'),t.appendLine(`bool loops = ${this.loops} `),t.appendLine(`int performCount = ${this.performCount} `),t.appendLine(`token type = "${this.type}"`),t.appendLine();for(const s of this.actions)s&&(s.writeTo(e,t),t.appendLine());t.closeBlock()}}h(ih,"global_id",0);var fT=(i=>(i[i.pop=0]="pop",i[i.blink=1]="blink",i[i.bounce=2]="bounce",i[i.flip=3]="flip",i[i.float=4]="float",i[i.jiggle=5]="jiggle",i[i.pulse=6]="pulse",i[i.spin=7]="spin",i))(fT||{}),mT=(i=>(i.Relative="relative",i.Absolute="absolute",i))(mT||{}),U3=(i=>(i.Allow="allow",i.Ignore="ignore",i.Stop="stop",i))(U3||{});const gT=class{constructor(i,e){h(this,"id"),h(this,"tokenId"),h(this,"affectedObjects"),h(this,"easeType"),h(this,"motionType"),h(this,"duration"),h(this,"moveDistance"),h(this,"style"),h(this,"type"),h(this,"front"),h(this,"up"),h(this,"start"),h(this,"animationSpeed"),h(this,"reversed"),h(this,"pingPong"),h(this,"xFormTarget"),h(this,"audio"),h(this,"gain"),h(this,"auralMode"),h(this,"multiplePerformOperation"),i&&(this.affectedObjects=i),e?this.id=e:this.id="Action",this.id+="_"+gT.global_id++}clone(){const i=new gT,e=i.id;return Object.assign(i,this),i.id=e,i}writeTo(i,e){e.beginBlock(`def Preliminary_Action "${this.id}"`),this.affectedObjects&&(typeof this.affectedObjects!="string"&&(this.affectedObjects=pT(this.affectedObjects,i)),e.appendLine("rel affectedObjects = "+this.affectedObjects)),typeof this.duration=="number"&&e.appendLine(`double duration = ${this.duration} `),this.easeType&&e.appendLine(`token easeType = "${this.easeType}"`),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.motionType&&e.appendLine(`token motionType = "${this.motionType}"`),typeof this.moveDistance=="number"&&e.appendLine(`double moveDistance = ${this.moveDistance} `),this.style&&e.appendLine(`token style = "${this.style}"`),this.type&&e.appendLine(`token type = "${this.type}"`),this.front&&e.appendLine(`vector3d front = (${this.front.x}, ${this.front.y}, ${this.front.z})`),this.up&&e.appendLine(`vector3d upVector = (${this.up.x}, ${this.up.y}, ${this.up.z})`),typeof this.start=="number"&&e.appendLine(`double start = ${this.start} `),typeof this.animationSpeed=="number"&&e.appendLine(`double animationSpeed = ${this.animationSpeed} `),typeof this.reversed=="boolean"&&e.appendLine(`bool reversed = ${this.reversed}`),typeof this.pingPong=="boolean"&&e.appendLine(`bool reverses = ${this.pingPong}`),this.xFormTarget&&(typeof this.xFormTarget!="string"&&(this.xFormTarget=pT(this.xFormTarget,i)),e.appendLine(`rel xformTarget = ${this.xFormTarget}`)),typeof this.audio=="string"&&e.appendLine(`asset audio = @${this.audio}@`),typeof this.gain=="number"&&e.appendLine(`double gain = ${this.gain}`),typeof this.auralMode=="string"&&e.appendLine(`token auralMode = "${this.auralMode}"`),typeof this.multiplePerformOperation=="string"&&e.appendLine(`token multiplePerformOperation = "${this.multiplePerformOperation}"`),e.closeBlock()}};let ha=gT;h(ha,"global_id",0);let Np=class Nf{constructor(e,t,s){h(this,"x",0),h(this,"y",0),h(this,"z",0),this.x=e,this.y=t,this.z=s}static get up(){return new Nf(0,1,0)}static get right(){return new Nf(1,0,0)}static get forward(){return new Nf(0,0,1)}static get back(){return new Nf(0,0,-1)}static get zero(){return new Nf(0,0,0)}};var vT=(i=>(i.Play="play",i.Pause="pause",i.Stop="stop",i))(vT||{}),AT=(i=>(i.Spatial="spatial",i.NonSpatial="nonSpatial",i.Ambient="ambient",i))(AT||{});class ni{static sequence(...e){return new ih("group_"+ih.getId(),e).makeSequence()}static parallel(...e){return new ih("group_"+ih.getId(),e).makeParallel()}static fadeAction(e,t,s){const r=new ha(e);return r.tokenId="Visibility",r.type=s?"show":"hide",r.duration=t,r.style="basic",r.motionType="none",r.moveDistance=0,r.easeType="none",r}static startAnimationAction(e,t,s=0,r=1,n=!1,o=!1){const a=new ha(e);if(a.tokenId="StartAnimation",a.start=t,a.duration=s,a.animationSpeed=r,a.reversed=n,a.pingPong=o,a.multiplePerformOperation="allow",n&&(a.start-=s),o){a.pingPong=!1;const l=a.clone();return l.reversed=!n,l.start=a.start,l.reversed&&(l.start-=s),ni.sequence(a,l)}return a}static waitAction(e){const t=new ha;return t.tokenId="Wait",t.duration=e,t}static lookAtCameraAction(e,t=9999999999999,s,r){const n=new ha(e);return n.tokenId="LookAtCamera",n.duration=t,n.front=s??Np.forward,n.up=r??Np.up,n}static emphasize(e,t,s=2,r=1,n="basic"){const o=new ha(e);return o.tokenId="Emphasize",o.duration=t,o.style=n??"basic",o.motionType=fT[s],o.moveDistance=r,o}static transformAction(e,t,s,r,n="inout"){const o=new ha(e);return o.tokenId="Transform",o.duration=s,o.type=r,o.easeType=n,Array.isArray(t)&&console.error("Transform target must not be an array",t),o.xFormTarget=t,o}static playAudioAction(e,t,s="play",r=1,n="spatial"){const o=new ha(e);return o.tokenId="Audio",o.type=s,o.audio=t,o.gain=r,o.auralMode=n,o.multiplePerformOperation="allow",o}}class Gte{constructor(e){h(this,"object"),h(this,"model"),this.object=e}get id(){return this.object.uuid}apply(e){if(!this.model&&(this.model=e.findById(this.object.uuid),!this.model)){console.error("could not find model with id "+this.object.uuid);return}this.onApply(e)}}class yT extends Gte{constructor(e,t,s,r){super(e),h(this,"matrix"),h(this,"material"),h(this,"geometry"),h(this,"_enableAction"),h(this,"_disableAction"),this.matrix=t,this.material=s,this.geometry=r}onApply(e){var t,s;const r=this.model;if(!r)return;(t=r.parent)!=null&&t.isDynamic||wo.createEmptyParent(r);const n=r.clone();this.matrix&&(n.matrix=this.matrix),this.material&&(n.material=this.material),this.geometry&&(n.geometry=this.geometry),(s=r.parent)==null||s.add(n)}enable(){return this._enableAction?this._enableAction:(this._enableAction=ni.fadeAction(this.object,0,!0),this._enableAction)}disable(){return this._disableAction?this._disableAction:(this._disableAction=ni.fadeAction(this.object,0,!1),this._disableAction)}}class bT{constructor(e){h(this,"actions"),h(this,"sortedActions"),this.actions=[...e]}organize(){this.sortedActions={};for(const e of this.actions){const t=e.id;this.sortedActions[t]||(this.sortedActions[t]=[]),this.sortedActions[t].push(e)}}getActions(e){return this.sortedActions||this.organize(),this.sortedActions[e.uuid]}}var Qte=Object.defineProperty,Vte=Object.getOwnPropertyDescriptor,F3=(i,e,t,s)=>{for(var r=s>1?void 0:s?Vte(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Qte(e,t,r),r};class Gg extends Pe{constructor(){super(...arguments),h(this,"from"),h(this,"to"),h(this,"width",0),h(this,"centered",!0),h(this,"_centerPos")}awake(){this._centerPos=new w}update(){if(!this.from||!this.to)return;const e=ft(this.from).clone(),t=ft(this.to).clone(),s=e.distanceTo(t);this._centerPos.copy(e),this._centerPos.add(t),this._centerPos.multiplyScalar(.5),ds(this.gameObject,this.centered?this._centerPos:e),this.gameObject.lookAt(ft(this.to).clone()),this.gameObject.scale.set(this.width,this.width,s)}}F3([x(te)],Gg.prototype,"from",2),F3([x(te)],Gg.prototype,"to",2);var Hte=Object.defineProperty,Wte=Object.getOwnPropertyDescriptor,Qg=(i,e,t,s)=>{for(var r=s>1?void 0:s?Wte(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Hte(e,t,r),r};const zp=oe("debuganimation");class Qn extends Pe{constructor(){super(...arguments),h(this,"playAutomatically",!0),h(this,"randomStartTime",!0),h(this,"minMaxSpeed"),h(this,"minMaxOffsetNormalized"),h(this,"loop",!0),h(this,"clampWhenFinished",!1),h(this,"_tempAnimationClipBeforeGameObjectExisted",null),h(this,"_tempAnimationsArray"),h(this,"mixer"),h(this,"_actions",[]),h(this,"_currentActions",[]),h(this,"_handles",[]),h(this,"_didInit",!1)}get clip(){var e;return(e=this.animations)!=null&&e.length?this.animations[0]:null}set clip(e){if(!this.__didAwake){zp&&console.warn("Assign clip during serialization",e),this._tempAnimationClipBeforeGameObjectExisted=e;return}e&&(this.gameObject.animations||(this.gameObject.animations=[]),!this.animations.includes(e)&&(this.animations.length>0?this.animations.splice(0,0,e):this.animations.push(e)))}set clips(e){this.animations=e}set animations(e){e==null||!Array.isArray(e)||(this.gameObject?this.gameObject.animations=e:this._tempAnimationsArray=e)}get animations(){return this.gameObject.animations||this._tempAnimationsArray||[]}get currentAction(){return this._currentActions[0]}get currentActions(){return this._currentActions}get actions(){return this._actions}set actions(e){this._actions=e}awake(){zp&&console.log("Animation Awake",this.name,this),this._tempAnimationsArray&&(this.animations=this._tempAnimationsArray,this._tempAnimationsArray=void 0),this._tempAnimationClipBeforeGameObjectExisted&&(this.clip=this._tempAnimationClipBeforeGameObjectExisted,this._tempAnimationClipBeforeGameObjectExisted=null),this.playAutomatically&&this.init()}onEnable(){var e;if(this.playAutomatically&&((e=this.animations)==null?void 0:e.length)>0&&this.currentActions.length<=0){const t=Math.floor(Math.random()*this.actions.length);this.play(t)}}start(){this.randomStartTime&&this.currentAction&&(this.currentAction.time=Math.random()*this.currentAction.getClip().duration)}update(){this.mixer&&this.mixer.update(this.context.time.deltaTime)}getAction(e){var t;return(t=this.actions)==null?void 0:t.find(s=>s.getClip().name===e)}get isPlaying(){for(let e=0;e<this.actions.length;e++)if(this.actions[e].isRunning())return!0;return!1}play(e=0,t){if(zp&&console.log("PLAY",e),this.init(),!this.mixer){zp&&console.warn("Missing mixer",this);return}e===void 0&&(e=0);let s=e;if(typeof e=="number"){if(e>=this.animations.length){zp&&console.log("No animation at index",e);return}s=this.animations[e]}else typeof e=="string"&&(s=this.animations.find(n=>n.name===e));if(!s){console.error("Could not find clip",e);return}t||(t={}),t.minMaxOffsetNormalized||(t.minMaxOffsetNormalized=this.minMaxOffsetNormalized),t.minMaxSpeed||(t.minMaxSpeed=this.minMaxSpeed),t.loop===void 0&&(t.loop=this.loop),t.clampWhenFinished===void 0&&(t.clampWhenFinished=this.clampWhenFinished);for(const n of this.actions)if(n.getClip()===s)return this.internalOnPlay(n,t);if(!(s instanceof vn)){console.warn("Clip is no AnimationClip",s,"on object: "+this.name);return}const r=this.mixer.clipAction(s);return this.actions.push(r),this.internalOnPlay(r,t)}internalOnPlay(e,t){var s=this.currentAction;if(s===e&&s.isRunning()&&s.time<s.getClip().duration){const a=this.tryFindHandle(e);if(a)return a.getPromise()}const r=t?.exclusive??!0;t!=null&&t.fadeDuration?(r&&s?.fadeOut(t.fadeDuration),e.fadeIn(t.fadeDuration)):r&&s?.stop(),e.reset(),e.enabled=!0,e.time=0,e.timeScale=1;const n=e.getClip();t!=null&&t.minMaxOffsetNormalized&&(e.time=rt.lerp(t.minMaxOffsetNormalized.x,t.minMaxOffsetNormalized.y,Math.random())*n.duration),t!=null&&t.minMaxSpeed&&(e.timeScale=rt.lerp(t.minMaxSpeed.x,t.minMaxSpeed.y,Math.random())),t!=null&&t.clampWhenFinished&&(e.clampWhenFinished=!0),t?.startTime!==void 0&&(e.time=t.startTime),t?.loop!==void 0?e.loop=t.loop?p1:$f:e.loop=$f,e.play(),zp&&console.log("PLAY",e.getClip().name,e);const o=new Xte(e,this.mixer,t,a=>{this._handles.splice(this._handles.indexOf(o),1)});return this._handles.push(o),o.getPromise()}tryFindHandle(e){for(const t of this._handles)if(t.action===e)return t}init(){this._didInit||(this._didInit=!0,this.gameObject&&(this.actions=[],this.mixer=new Jy(this.gameObject)))}}Qg([x()],Qn.prototype,"playAutomatically",2),Qg([x()],Qn.prototype,"randomStartTime",2),Qg([x()],Qn.prototype,"loop",2),Qg([x()],Qn.prototype,"clampWhenFinished",2),Qg([x(vn)],Qn.prototype,"clips",1);class Xte{constructor(e,t,s,r){h(this,"mixer"),h(this,"action"),h(this,"promise",null),h(this,"resolve",null),h(this,"reject",null),h(this,"_options"),h(this,"_resolveCallback",null),h(this,"_rejectCallback",null),h(this,"_loopCallback"),h(this,"_finishedCallback"),h(this,"_resolvedOrRejectedCallback"),this.action=e,this.mixer=t,this._resolvedOrRejectedCallback=r,this._options=s}getPromise(){return this.promise?this.promise:(this.promise=new Promise((e,t)=>{this._resolveCallback=e,this._rejectCallback=t,this.resolve=this.onResolve.bind(this),this.reject=this.onReject.bind(this)}),this._loopCallback=this.onLoop.bind(this),this._finishedCallback=this.onFinished.bind(this),this.mixer.addEventListener("loop",this._loopCallback),this.mixer.addEventListener("finished",this._finishedCallback),this.promise)}_update(){this._options&&this._options.endTime!==void 0&&this.action.time>this._options.endTime&&(this._options.loop===!0?this.action.time=this._options.startTime??0:(this.action.time=this._options.endTime,this.action.timeScale=0,this.onResolve()))}onResolve(){var e,t;this.dispose(),(e=this._resolvedOrRejectedCallback)==null||e.call(this,this),(t=this._resolveCallback)==null||t.call(this,this.action)}onReject(e){var t,s;this.dispose(),(t=this._resolvedOrRejectedCallback)==null||t.call(this,this),(s=this._rejectCallback)==null||s.call(this,e)}onLoop(e){}onFinished(e){e.action===this.action&&this.onResolve()}dispose(){this._loopCallback&&this.mixer.removeEventListener("loop",this._loopCallback),this._finishedCallback&&this.mixer.removeEventListener("finished",this._finishedCallback),this._loopCallback=void 0,this._finishedCallback=void 0}}var qte=Object.defineProperty,Yte=Object.getOwnPropertyDescriptor,sh=(i,e,t,s)=>{for(var r=s>1?void 0:s?Yte(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&qte(e,t,r),r};class rh{constructor(){h(this,"time"),h(this,"value"),h(this,"inTangent"),h(this,"inWeight"),h(this,"outTangent"),h(this,"outWeight"),h(this,"weightedMode")}}sh([x()],rh.prototype,"time",2),sh([x()],rh.prototype,"value",2),sh([x()],rh.prototype,"inTangent",2),sh([x()],rh.prototype,"inWeight",2),sh([x()],rh.prototype,"outTangent",2),sh([x()],rh.prototype,"outWeight",2),sh([x()],rh.prototype,"weightedMode",2);const N3=class{constructor(){h(this,"keys")}get duration(){return!this.keys||this.keys.length==0?0:this.keys[this.keys.length-1].time}evaluate(i){if(!this.keys||this.keys.length==0)return 0;if(this.keys[0].time>=i)return this.keys[0].value;for(let e=0;e<this.keys.length;e++){const t=this.keys[e];if(t.time<=i)if(e+1<this.keys.length){const s=this.keys[e+1];if(s.time<i)continue;return!isFinite(t.outTangent)||!isFinite(s.inTangent)?t.value:N3.interpolateValue(i,t,s)}else return t.value}return this.keys[this.keys.length-1].value}static interpolateValue(i,e,t){const s=e.time,r=e.value,n=e.outTangent,o=t.time,a=t.value,l=t.inTangent,c=o-s,u=c*c,d=u*c,p=((n+l)*c-2*(a-r))/d,f=(3*(a-r)-(l+2*n)*c)/u,m=n,A=r,v=i-s,g=v*v,b=g*v;return p*b+f*g+m*v+A}};let Bu=N3;sh([x(rh)],Bu.prototype,"keys",2);class Kte{constructor(){h(this,"_context")}get context(){return this._context??Ot.Current}get isStateMachineBehaviour(){return!0}}class a_{constructor(e,t,s,r){h(this,"_name"),h(this,"_nameHash"),h(this,"_normalizedTime"),h(this,"_length"),h(this,"_speed"),this._name=e.name,this._nameHash=e.hash,this._normalizedTime=t,this._length=s,this._speed=r}get name(){return this._name}get nameHash(){return this._nameHash}get normalizedTime(){return this._normalizedTime}get length(){return this._length}get speed(){return this._speed}}function z3(i,e){return{name:"",isLooping:!1,guid:e?.generateUUID()??sr.generateUUID(),index:-1,clip:new vn(i,1,[])}}var nh=(i=>(i[i.If=1]="If",i[i.IfNot=2]="IfNot",i[i.Greater=3]="Greater",i[i.Less=4]="Less",i[i.Equals=6]="Equals",i[i.NotEqual=7]="NotEqual",i))(nh||{}),_T=(i=>(i[i.Float=1]="Float",i[i.Int=3]="Int",i[i.Bool=4]="Bool",i[i.Trigger=9]="Trigger",i))(_T||{});const So=oe("debuganimatorcontroller"),l_=oe("debugrootmotion");class No{constructor(e){h(this,"normalizedStartOffset",0),h(this,"_speed",1),h(this,"animator"),h(this,"model"),h(this,"_mixer"),h(this,"_activeState"),h(this,"_activeStates",[]),h(this,"rootMotionHandler"),this.model=e,So&&console.log(this)}static createFromClips(e,t={looping:!1,autoTransition:!0,transitionDuration:0}){const s=[];for(let n=0;n<e.length;n++){const o=e[n],a=[];if(t.autoTransition!==!1){const c=t.transitionDuration??0,u=c/o.duration;let d=n;(t.autoTransition===void 0||t.autoTransition===!0)&&(d=(n+1)%e.length),a.push({exitTime:1-u,offset:0,duration:c,hasExitTime:!0,destinationState:d,conditions:[]})}const l={name:o.name,hash:n,motion:{name:o.name,clip:o,isLooping:t?.looping??!1},transitions:a,behaviours:[]};s.push(l)}const r={name:"AnimatorController",guid:new Vr(Date.now()).generateUUID(),parameters:[],layers:[{name:"Base Layer",stateMachine:{defaultState:0,states:s}}]};return new No(r)}play(e,t=-1,s=Number.NEGATIVE_INFINITY,r=0){if(t<0)t=0;else if(t>=this.model.layers.length){console.warn("invalid layer");return}const n=this.model.layers[t].stateMachine;for(const o of n.states)if(o.name===e||o.hash===e){So&&console.log("transition to ",o),this.transitionTo(o,r,s);return}console.warn("Could not find "+e+" to play")}reset(){this.setStartTransition()}setBool(e,t){var s,r;const n=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[n]===e).forEach(o=>o.value=t)}getBool(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??!1}setFloat(e,t){var s,r;const n=typeof e=="string"?"name":"hash",o=(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(a=>a[n]===e);return o.forEach(a=>a.value=t),o?.length>0}getFloat(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??0}setInteger(e,t){var s,r;const n=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[n]===e).forEach(o=>o.value=t)}getInteger(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??0}setTrigger(e){var t,s;So&&console.log("SET TRIGGER",e);const r=typeof e=="string"?"name":"hash";return(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.filter(n=>n[r]===e).forEach(n=>n.value=!0)}resetTrigger(e){var t,s;const r=typeof e=="string"?"name":"hash";return(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.filter(n=>n[r]===e).forEach(n=>n.value=!1)}getTrigger(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??!1}isInTransition(){return this._activeStates.length>1}setSpeed(e){this._speed=e}FindState(e){return this.findState(e)}findState(e){if(!e)return null;if(Array.isArray(this.model.layers)){for(const t of this.model.layers)for(const s of t.stateMachine.states)if(s.name===e||s.hash==e)return s}return null}get context(){var e;return(e=this.animator)==null?void 0:e.context}get mixer(){return this._mixer}bind(e){e?this.animator!==e&&(this.animator=e,this._mixer=new Jy(this.animator.gameObject),this.createActions(this.animator)):console.error("AnimatorController.bind: animator is null")}clone(){if(typeof this.model=="string")return console.warn("AnimatorController has not been resolved, can not create model from string",this.model),null;const e=Lm(this.model,(t,s,r)=>r==null?!0:!(r.type==="Object3D"||r.isObject3D===!0||e2(r)||r.tracks!==void 0));return console.assert(e!==this.model),new No(e)}update(e){var t,s;if(!this.animator)return;this.evaluateTransitions(),this.updateActiveStates(e);const r=this.animator.context.time.deltaTime;this.animator.applyRootMotion&&((t=this.rootMotionHandler)==null||t.onBeforeUpdate(e)),this._mixer.update(r),this.animator.applyRootMotion&&((s=this.rootMotionHandler)==null||s.onAfterUpdate(e))}get activeState(){return this._activeState}updateActiveStates(e){for(let t=0;t<this._activeStates.length;t++){const s=this._activeStates[t],r=s.motion;if(!r.action)this._activeStates.splice(t,1),t--;else{const n=r.action;n.weight=e,n.getEffectiveWeight()<=0&&!n.isRunning()&&(So&&console.debug("REMOVE",s.name,n.getEffectiveWeight(),n.isRunning(),n.isScheduled()),this._activeStates.splice(t,1),t--)}}}setStartTransition(){for(const e of this.model.layers){const t=e.stateMachine;t.defaultState===void 0&&(So&&console.warn("AnimatorController default state is undefined, will assign state 0 as default",e),t.defaultState=0);const s=t.states[t.defaultState];this.transitionTo(s,0,this.normalizedStartOffset)}}evaluateTransitions(){var e;let t=!1;if(!this._activeState){if(this.setStartTransition(),!this._activeState)return;t=!0}const s=this._activeState,r=s.motion.action;for(const o of s.transitions){if(!o.hasExitTime&&o.conditions.length<=0)continue;let a=!0;for(const l of o.conditions)if(!this.evaluateCondition(l)){a=!1;break}if(a)if(r){const l=s.motion.clip.duration,c=l<=0?1:Math.abs(r.time/l);let u=!1;if(o.hasExitTime?r.timeScale>0?u=c>=o.exitTime:r.timeScale<0&&(u=1-c>=o.exitTime):u=!0,u){for(const d of o.conditions){const p=this.model.parameters.find(f=>f.name===d.parameter);p?.type===_T.Trigger&&p.value&&(p.value=!1)}r.clampWhenFinished=!0,So&&console.log("transition to "+o.destinationState,o,c,o.exitTime,o.hasExitTime),this.transitionTo(o.destinationState,o.duration,o.offset);return}}else{this.transitionTo(o.destinationState,o.duration,o.offset);return}}if(r){let o=s.speed??1;s.speedParameter&&(o*=this.getFloat(s.speedParameter)),o!==void 0&&(r.timeScale=o*this._speed)}let n=!1;if(s.motion.isLooping&&r&&(r.time>=r.getClip().duration?(n=!0,r.reset(),r.time=0,r.play()):r.time<=0&&r.timeScale<0&&(n=!0,r.reset(),r.time=r.getClip().duration,r.play())),!n&&s&&!t&&r&&this.animator&&s.behaviours){const o=r?.getClip().duration,a=r.time/o,l=new a_(this._activeState,a,o,this._speed);for(const c of s.behaviours)c.instance&&((e=c.instance.onStateUpdate)==null||e.call(c.instance,this.animator,l,0))}}getState(e,t){return typeof e=="number"&&(e==-1&&(e=this.model.layers[t].stateMachine.defaultState,e===void 0&&(So&&console.warn("AnimatorController default state is undefined: ",this.model,"Layer: "+t),e=0)),e=this.model.layers[t].stateMachine.states[e]),e}transitionTo(e,t,s){var r,n,o,a,l,c,u,d;if(!this.animator)return;const p=0;if(e=this.getState(e,p),!(e!=null&&e.motion)||!e.motion.clip||!(e.motion.clip instanceof vn))return;const f=this._activeState===e;if(f){const g=e.motion;if(!g.action_loopback&&g.clip){const b=this.rootMotionHandler?this.animator.gameObject.matrix.clone():null;this._mixer.uncacheAction(g.clip,this.animator.gameObject),b&&b.decompose(this.animator.gameObject.position,this.animator.gameObject.quaternion,this.animator.gameObject.scale),g.action_loopback=this.createAction(g.clip)}}if((r=this._activeState)!=null&&r.behaviours&&this._activeState.motion.action){const g=(n=this._activeState)==null?void 0:n.motion.clip.duration,b=this._activeState.motion.action.time/g,y=new a_(this._activeState,b,g,this._speed);for(const _ of this._activeState.behaviours)(a=(o=_.instance)==null?void 0:o.onStateExit)==null||a.call(_.instance,this.animator,y,p)}const m=(l=this._activeState)==null?void 0:l.motion.action;m&&m.fadeOut(t),f&&(e.motion.action=e.motion.action_loopback,e.motion.action_loopback=m);const A=this._activeState;this._activeState=e;const v=(c=e.motion)==null?void 0:c.action;if(v){if(s=Math.max(0,Math.min(1,s)),e.cycleOffsetParameter){let b=this.getFloat(e.cycleOffsetParameter);typeof b=="number"?(b<0&&(b+=1),s+=b,s%=1):So&&console.warn("AnimatorController cycle offset parameter is not a number",e.cycleOffsetParameter)}else typeof e.cycleOffset=="number"&&(s+=e.cycleOffset,s%=1);v.isRunning()&&v.stop(),v.reset(),v.enabled=!0;const g=e.motion.clip.duration;if(v.time=f?0:s*g,v.timeScale<0&&(v.time=g-v.time),v.clampWhenFinished=!0,v.setLoop($f,0),t>0?v.fadeIn(t):v.weight=1,v.play(),this.rootMotionHandler&&this.rootMotionHandler.onStart(v),this._activeStates.includes(e)||this._activeStates.push(e),this._activeState.behaviours){const b=new a_(e,s,g,this._speed);for(const y of this._activeState.behaviours)(d=(u=y.instance)==null?void 0:u.onStateEnter)==null||d.call(y.instance,this.animator,b,p)}}else So&&(e.__warned_no_motion||(e.__warned_no_motion=!0,console.warn("No action",e.motion,this)));So&&console.log("TRANSITION FROM "+A?.name+" TO "+e.name,t,m,v,v?.getEffectiveTimeScale(),v?.getEffectiveWeight(),v?.isRunning(),v?.isScheduled(),v?.paused)}createAction(e){var t,s;if(this._mixer.existingAction(e)&&this._mixer.uncacheAction(e,(t=this.animator)==null?void 0:t.gameObject),(s=this.animator)!=null&&s.applyRootMotion){this.rootMotionHandler||(this.rootMotionHandler=new Jte(this));const r=this.animator.gameObject;return this.rootMotionHandler.createClip(this._mixer,r,e)}else return this._mixer.clipAction(e)}evaluateCondition(e){const t=this.model.parameters.find(s=>s.name===e.parameter);if(!t)return!1;switch(e.mode){case nh.If:return t.value===e.threshold;case nh.IfNot:return t.value===e.threshold;case nh.Greater:return t.value>e.threshold;case nh.Less:return t.value<e.threshold;case nh.Equals:return t.value===e.threshold;case nh.NotEqual:return t.value!==e.threshold}return!1}createActions(e){var t,s;for(const r of this.model.layers){const n=r.stateMachine;for(let o=0;o<n.states.length;o++){const a=n.states[o];a.transitions||(a.transitions=[]);for(const l of a.transitions)l.conditions||(l.conditions=[]);if(a.motion||(a.motion=z3(a.name)),this.animator&&a.motion.clips){const l=(t=a.motion.clips)==null?void 0:t.find(c=>{var u,d;return c.node.name===((d=(u=this.animator)==null?void 0:u.gameObject)==null?void 0:d.name)});a.motion.clip=l?.clip}if(!a.motion.clip){const l=new vn(void 0,void 0,[]);a.motion.clip=l}if((s=a.motion)!=null&&s.clip){const l=a.motion.clip;if(l instanceof vn){const c=this.createAction(l);a.motion.action=c}else(So||zt())&&console.warn("No valid animationclip assigned",a)}if(a.behaviours&&Array.isArray(a.behaviours))for(const l of a.behaviours){if(!(l!=null&&l.typeName))continue;const c=Y.get(l.typeName),u=new c;u.isStateMachineBehaviour&&(u._context=this.context??void 0,ap(u,l.properties),l.instance=u),So&&console.log("Created animator controller behaviour",a.name,l.typeName,l.properties,u)}}}}*enumerateActions(){if(this.model.layers)for(const e of this.model.layers){const t=e.stateMachine;for(let s=0;s<t.states.length;s++){const r=t.states[s];r!=null&&r.motion&&(r.motion.action&&(yield r.motion.action),r.motion.action_loopback&&(yield r.motion.action_loopback))}}}}class j3{constructor(e,t){h(this,"track"),h(this,"createdInterpolant"),h(this,"originalEvaluate"),h(this,"customEvaluate"),this.track=e;const s=e,r=s.createInterpolant.bind(e);s.createInterpolant=()=>(s.createInterpolant=r,this.createdInterpolant=r(),this.originalEvaluate=this.createdInterpolant.evaluate.bind(this.createdInterpolant),this.customEvaluate=n=>{if(!this.originalEvaluate)return;const o=this.originalEvaluate(n);return t(n,o)},this.createdInterpolant.evaluate=this.customEvaluate,this.createdInterpolant)}dispose(){this.createdInterpolant&&this.originalEvaluate&&(this.createdInterpolant.evaluate=this.originalEvaluate),this.track=void 0,this.createdInterpolant=null,this.originalEvaluate=void 0,this.customEvaluate=void 0}}const Ks=class{constructor(i,e,t,s,r){if(h(this,"_action"),h(this,"root"),h(this,"clip"),h(this,"positionWrapper",null),h(this,"rotationWrapper",null),h(this,"context"),h(this,"positionChange",new w),h(this,"rotationChange",new Me),h(this,"_prevTime",0),this.context=i,this.root=e,this.clip=t,Ks.firstKeyframeRotation[this.cacheId]||(Ks.firstKeyframeRotation[this.cacheId]=new Me),r){const n=r.values;Ks.firstKeyframeRotation[this.cacheId].set(n[0],n[1],n[2],n[3])}Ks.spaceRotation[this.cacheId]||(Ks.spaceRotation[this.cacheId]=new Me),Ks.effectiveSpaceRotation[this.cacheId]||(Ks.effectiveSpaceRotation[this.cacheId]=new Me),Ks.clipOffsetRotation[this.cacheId]=new Me,r&&Ks.clipOffsetRotation[this.cacheId].set(r.values[0],r.values[1],r.values[2],r.values[3]).invert(),this.handlePosition(t,s),this.handleRotation(t,r)}set action(i){this._action=i}get action(){return this._action}get cacheId(){return this.root.uuid}onStart(i){if(i.getClip()!==this.clip)return;Ks.lastObjRotation[this.cacheId]||(Ks.lastObjRotation[this.cacheId]=this.root.quaternion.clone());const e=Ks.lastObjRotation[this.cacheId];if(Ks.spaceRotation[this.cacheId].copy(e),l_){const t=new zs().setFromQuaternion(e);console.log("START",this.clip.name,rt.toDegrees(t.y),this.root.position.z)}}getClipRotationOffset(){return Ks.clipOffsetRotation[this.cacheId]}handlePosition(i,e){if(e){const t=this.root;l_&&t.add(new ep),Ks.lastObjPosition[this.cacheId]||(Ks.lastObjPosition[this.cacheId]=this.root.position.clone());const s=new w,r=new w;this.positionWrapper=new j3(e,(n,o)=>{const a=this.action.getEffectiveWeight();return l_&&t.position.length()>8&&t.position.set(0,t.position.y,0),n>this._prevTime&&(s.set(o[0],o[1],o[2]),s.sub(r),s.multiplyScalar(a),s.applyQuaternion(this.getClipRotationOffset()),s.applyQuaternion(t.quaternion),this.positionChange.copy(s)),r.fromArray(o),this._prevTime=n,o[0]=0,o[1]=0,o[2]=0,o})}}handleRotation(i,e){if(e){if(l_){const n=e.values,o=new zs().setFromQuaternion(new Me(n[0],n[1],n[2],n[3]));console.log(i.name,e.name,"FIRST ROTATION IN TRACK",rt.toDegrees(o.y));const a=e.values.length-4,l=new Me().set(n[a],n[a+1],n[a+2],n[a+3]),c=new zs().setFromQuaternion(l);console.log(i.name,e.name,"LAST ROTATION IN TRACK",rt.toDegrees(c.y))}let t=0;const s=new Me,r=new Me;this.rotationWrapper=new j3(e,(n,o)=>(n>t&&(r.set(o[0],o[1],o[2],o[3]),s.invert(),r.multiply(s),this.rotationChange.copy(r)),s.fromArray(o),t=n,o[0]=0,o[1]=0,o[2]=0,o[3]=1,o))}}onBeforeUpdate(i){this.positionChange.set(0,0,0),this.rotationChange.set(0,0,0,1)}onAfterUpdate(i){return!this.action||(i*=this.action.getEffectiveWeight(),i<=0)?!1:(this.positionChange.multiplyScalar(i),this.rotationChange.slerp(Ks.identityQuaternion,1-i),!0)}};let oh=Ks;h(oh,"lastObjPosition",{}),h(oh,"lastObjRotation",{}),h(oh,"firstKeyframeRotation",{}),h(oh,"spaceRotation",{}),h(oh,"effectiveSpaceRotation",{}),h(oh,"clipOffsetRotation",{}),h(oh,"identityQuaternion",new Me);class Jte{constructor(e){h(this,"controller"),h(this,"handler",[]),h(this,"root"),h(this,"basePosition",new w),h(this,"baseQuaternion",new Me),h(this,"baseRotation",new zs),h(this,"summedPosition",new w),h(this,"summedRotation",new Me),this.controller=e}createClip(e,t,s){this.root=t,t&&"name"in t&&t.name;const r=this.findRootTrack(s,".position"),n=this.findRootTrack(s,".quaternion"),o=new oh(this.controller.context,t,s,r,n);this.handler.push(o);const a=e.clipAction(s);return o.action=a,a}onStart(e){for(const t of this.handler)t.onStart(e)}onBeforeUpdate(e){this.basePosition.copy(this.root.position),this.baseQuaternion.copy(this.root.quaternion);for(const t of this.handler)t.onBeforeUpdate(e)}onAfterUpdate(e){if(!(e<=0)){this.root.position.copy(this.basePosition),this.root.quaternion.copy(this.baseQuaternion),this.summedPosition.set(0,0,0),this.summedRotation.set(0,0,0,1);for(const t of this.handler)t.onAfterUpdate(e)&&(this.summedPosition.add(t.positionChange),this.summedRotation.multiply(t.rotationChange));this.root.position.add(this.summedPosition),this.root.quaternion.multiply(this.summedRotation)}}findRootTrack(e,t){const s=e.tracks;if(!s)return null;for(const r of s)if(r.name.endsWith(t))return r;return null}}class Zte extends Pl{onSerialize(e,t){}onDeserialize(e,t){if(t.type===No&&e?.__type==="AnimatorController")return new No(e)}}new Zte(No);class $te extends ls{constructor(e,t=1,s=16,r=2){const n=new gt,o=s+r*2,a=new Float32Array((o*3+3)*3);n.setAttribute("position",new et(a,3));const l=new as({color:65280}),c=new as({color:16776960});super(n,[c,l]),this.audio=e,this.range=t,this.divisionsInnerAngle=s,this.divisionsOuterAngle=r,this.type="PositionalAudioHelper",this.update()}update(){const e=this.audio,t=this.range,s=this.divisionsInnerAngle,r=this.divisionsOuterAngle,n=sr.degToRad(e.panner.coneInnerAngle),o=sr.degToRad(e.panner.coneOuterAngle),a=n/2,l=o/2;let c=0,u=0,d,p;const f=this.geometry,m=f.attributes.position;f.clearGroups();function A(v,g,b,y){const _=(g-v)/b;for(m.setXYZ(c,0,0,0),u++,d=v;d<g;d+=_)p=c+u,m.setXYZ(p,Math.sin(d)*t,0,Math.cos(d)*t),m.setXYZ(p+1,Math.sin(Math.min(d+_,g))*t,0,Math.cos(Math.min(d+_,g))*t),m.setXYZ(p+2,0,0,0),u+=3;f.addGroup(c,u,y),c+=u,u=0}A(-l,-a,r,0),A(-a,a,s,1),A(a,l,r,0),m.needsUpdate=!0,n===o&&(this.material[0].visible=!1)}dispose(){this.geometry.dispose(),this.material[0].dispose(),this.material[1].dispose()}}var eie=Object.defineProperty,tie=Object.getOwnPropertyDescriptor,Xl=(i,e,t,s)=>{for(var r=s>1?void 0:s?tie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&eie(e,t,r),r};const pr=oe("debugaudio");let c_=!1;const h_=[];function u_(){if(c_)return;zt()&&console.log("User interaction registered: audio can now be played"),c_=!0;const i=[...h_];h_.length=0,i.forEach(e=>e())}document.addEventListener("pointerdown",u_),document.addEventListener("click",u_),document.addEventListener("dragstart",u_),document.addEventListener("touchstart",u_);const ql=class extends Pe{constructor(){super(...arguments),h(this,"clip",""),h(this,"playOnAwake",!1),h(this,"_spatialBlend",0),h(this,"_minDistance",1),h(this,"_maxDistance",100),h(this,"_volume",1),h(this,"rollOffMode",0),h(this,"playInBackground",!0),h(this,"_loop",!1),h(this,"sound",null),h(this,"helper",null),h(this,"wasPlaying",!1),h(this,"audioLoader",null),h(this,"shouldPlay",!1),h(this,"_lastClipStartedLoading",null),h(this,"_audioElement",null),h(this,"onVisibilityChanged",()=>{switch(document.visibilityState){case"hidden":(this.playInBackground===!1||_l())&&(this.wasPlaying=this.isPlaying,this.isPlaying&&this.pause());break;case"visible":pr&&console.log("visible",this.enabled,this.playOnAwake,!this.isPlaying,ql.userInteractionRegistered,this.wasPlaying),this.enabled&&this.playOnAwake&&!this.isPlaying&&ql.userInteractionRegistered&&this.wasPlaying&&this.play();break}}),h(this,"onApplicationMuteChanged",()=>{var i,e;this.context.application.muted?(i=this.sound)==null||i.setVolume(0):(e=this.sound)==null||e.setVolume(this.volume)}),h(this,"lerp",(i,e,t)=>i*(1-t)+e*t),h(this,"createAudio",i=>{pr&&console.log("audio buffer loaded"),ql.registerWaitForAllowAudio(()=>{pr&&console.log("finished loading",i);const e=this.Sound;if(!e){console.warn("Failed getting sound",this.name);return}e.isPlaying&&e.stop(),i&&e.setBuffer(i),e.loop=this._loop,this.context.application.muted?e.setVolume(0):e.setVolume(this.volume),e.autoplay=this.shouldPlay,this.applySpatialDistanceSettings(),e.isPlaying&&e.stop(),pr&&console.log(this.name,this.shouldPlay,ql.userInteractionRegistered,this),this.shouldPlay&&ql.userInteractionRegistered&&this.play()})}),h(this,"_lastContextTime",0),h(this,"_hasEnded",!0),h(this,"_needUpdateSpatialDistanceSettings",!1)}static get userInteractionRegistered(){return c_}static registerWaitForAllowAudio(i){if(i!==null){if(c_){i();return}h_.indexOf(i)===-1&&h_.push(i)}}get loop(){return this.sound&&(this._loop=this.sound.getLoop()),this._loop}set loop(i){this._loop=i,this.sound&&this.sound.setLoop(i)}get spatialBlend(){return this._spatialBlend}set spatialBlend(i){i!==this._spatialBlend&&(this._spatialBlend=i,this._needUpdateSpatialDistanceSettings=!0)}get minDistance(){return this._minDistance}set minDistance(i){this._minDistance!==i&&(this._minDistance=i,this._needUpdateSpatialDistanceSettings=!0)}get maxDistance(){return this._maxDistance}set maxDistance(i){this._maxDistance!==i&&(this._maxDistance=i,this._needUpdateSpatialDistanceSettings=!0)}get volume(){return this._volume}set volume(i){this._volume=i,this.sound&&!this.context.application.muted&&(pr&&console.log(this.name,"audio set volume",i),this.sound.setVolume(i))}get Sound(){if(!this.sound&&ql.userInteractionRegistered){let i=te.getComponent(this.context.mainCamera,dh)??te.findObjectOfType(dh,this.context);!i&&this.context.mainCamera&&(i=te.addNewComponent(this.context.mainCamera,dh)),i!=null&&i.listener?(this.sound=new ok(i.listener),this.gameObject.add(this.sound)):pr&&console.warn("No audio listener found in scene - can not play audio")}return this.sound}get ShouldPlay(){return this.shouldPlay}awake(){pr&&console.log(this),this.audioLoader=new Ky,this.playOnAwake&&(this.shouldPlay=!0)}onEnable(){ql.userInteractionRegistered?this.playOnAwake&&this.context.application.isVisible&&this.play():ql.registerWaitForAllowAudio(()=>{this.enabled&&!this.destroyed&&this.shouldPlay&&this.onNewClip(this.clip)}),globalThis.addEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.addEventListener(pb.MuteChanged,this.onApplicationMuteChanged)}onDisable(){globalThis.removeEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.removeEventListener(pb.MuteChanged,this.onApplicationMuteChanged),this.pause()}applySpatialDistanceSettings(){const i=this.sound;if(!i)return;this._needUpdateSpatialDistanceSettings=!1;const e=this.lerp(10*this._maxDistance/Math.max(1e-4,this.spatialBlend),this._minDistance,this.spatialBlend);switch(pr&&console.log(this.name,this._minDistance,this._maxDistance,this.spatialBlend,"Ref distance="+e),i.setRefDistance(e),i.setMaxDistance(Math.max(.01,this._maxDistance)),this.rollOffMode){case 0:i.setDistanceModel("exponential");break;case 1:i.setDistanceModel("linear");break}this.spatialBlend>0?pr&&!this.helper&&(this.helper=new $te(i,i.getRefDistance()),i.add(this.helper)):this.helper&&this.helper.parent&&this.helper.removeFromParent()}onNewClip(i){if(i&&(this.clip=i),typeof i=="string")if(pr&&console.log(i),i.endsWith(".mp3")||i.endsWith(".wav")){if(this.audioLoader||(this.audioLoader=new Ky),this.shouldPlay=!0,this._lastClipStartedLoading===i){pr&&console.log("Is currently loading:",this._lastClipStartedLoading,this);return}this._lastClipStartedLoading=i,pr&&console.log("load audio",i),this.audioLoader.load(i,this.createAudio,()=>{},console.error)}else console.warn("Unsupported audio clip type",i);else this.shouldPlay=!0,this.createAudio()}play(i=void 0){var e,t;!i&&this.clip&&(i=this.clip),i!==void 0&&typeof i!="string"&&!(i instanceof MediaStream)&&(zt()&&console.warn("Called play on AudioSource with unknown argument type:",i+`
|
|
5096
5096
|
Using the assigned clip instead:`,this.clip),i=this.clip);let s=!this.sound||i&&i!==this.clip;if(typeof i=="string"&&!this.audioLoader&&(s=!0),(i instanceof MediaStream||typeof i=="string")&&(this.clip=i),s){this.shouldPlay=!0,this.onNewClip(i);return}if(this.shouldPlay=!0,this._hasEnded=!1,pr&&console.log("play",(e=this.sound)==null?void 0:e.getVolume(),this.sound),this.sound&&!this.sound.isPlaying){const r=this.context.application.muted;r&&this.sound.setVolume(0),this.clip instanceof MediaStream?(this.sound.setMediaStreamSource(this.clip),this._audioElement||(this._audioElement=document.createElement("audio"),this._audioElement.style.display="none"),this._audioElement.parentNode||(t=this.context.domElement.shadowRoot)==null||t.append(this._audioElement),this._audioElement.srcObject=this.clip,this._audioElement.autoplay=!1):(this._audioElement&&this._audioElement.remove(),this.sound.play(r?.1:0))}}pause(){var i,e;pr&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.isPlaying&&this.sound.source&&(this._lastContextTime=(i=this.sound)==null?void 0:i.context.currentTime,this.sound.pause()),(e=this._audioElement)==null||e.remove()}stop(){var i,e;pr&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.source&&(this._lastContextTime=(i=this.sound)==null?void 0:i.context.currentTime,pr&&console.log(this._lastContextTime),this.sound.stop()),(e=this._audioElement)==null||e.remove()}get isPlaying(){var i;return((i=this.sound)==null?void 0:i.isPlaying)??!1}set isPlaying(i){}get time(){var i,e;return(i=this.sound)!=null&&i.source?((e=this.sound.source)==null?void 0:e.context.currentTime)-this._lastContextTime+this.sound.offset:0}set time(i){if(this.sound){if(i===this.sound.offset)return;const e=this.isPlaying;this.stop(),this.sound.offset=i,e&&this.play()}}update(){this.helper&&(this.isPlaying&&this.helper.update(),this.helper.visible=this.isPlaying),this._needUpdateSpatialDistanceSettings&&this.applySpatialDistanceSettings(),this.sound&&!this.sound.isPlaying&&this.shouldPlay&&!this._hasEnded&&(this._hasEnded=!0,pr&&console.log("Audio clip ended",this.clip),this.sound.dispatchEvent({type:"ended",target:this}))}};let gs=ql;Xl([x(URL)],gs.prototype,"clip",2),Xl([x()],gs.prototype,"playOnAwake",2),Xl([x()],gs.prototype,"loop",1),Xl([x()],gs.prototype,"spatialBlend",1),Xl([x()],gs.prototype,"minDistance",1),Xl([x()],gs.prototype,"maxDistance",1),Xl([x()],gs.prototype,"volume",1),Xl([x()],gs.prototype,"rollOffMode",2),Xl([x()],gs.prototype,"playInBackground",2);var iie=Object.defineProperty,sie=Object.getOwnPropertyDescriptor,rie=(i,e,t,s)=>{for(var r=s>1?void 0:s?sie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&iie(e,t,r),r};class Vg extends Pe{constructor(){super(...arguments),h(this,"constraintActive",!0),h(this,"locked",!1),h(this,"sources",[])}}rie([x(_e)],Vg.prototype,"sources",2);const G3={type:"change"},xT={type:"start"},Q3={type:"end"};let nie=class extends Ds{constructor(i,e){super(),this.object=i,this.domElement=e,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new w,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:Lh.ROTATE,MIDDLE:Lh.DOLLY,RIGHT:Lh.PAN},this.touches={ONE:Uh.ROTATE,TWO:Uh.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return o.phi},this.getAzimuthalAngle=function(){return o.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(H){H.addEventListener("keydown",pt),this._domElementKeyEvents=H},this.stopListenToKeyEvents=function(){this._domElementKeyEvents.removeEventListener("keydown",pt),this._domElementKeyEvents=null},this.saveState=function(){t.target0.copy(t.target),t.position0.copy(t.object.position),t.zoom0=t.object.zoom},this.reset=function(){t.target.copy(t.target0),t.object.position.copy(t.position0),t.object.zoom=t.zoom0,t.object.updateProjectionMatrix(),t.dispatchEvent(G3),t.update(),r=s.NONE},this.update=function(){const H=new w,be=new Me().setFromUnitVectors(i.up,new w(0,1,0)),Ie=be.clone().invert(),de=new w,Xe=new Me,Ye=new w,Se=2*Math.PI;return function(){const st=t.object.getWorldPosition(i.position);H.copy(st).sub(t.target),H.applyQuaternion(be),o.setFromVector3(H),t.autoRotate&&r===s.NONE&&E(M()),t.enableDamping?(o.theta+=a.theta*t.dampingFactor,o.phi+=a.phi*t.dampingFactor):(o.theta+=a.theta,o.phi+=a.phi);let $e=t.minAzimuthAngle,I=t.maxAzimuthAngle;return isFinite($e)&&isFinite(I)&&($e<-Math.PI?$e+=Se:$e>Math.PI&&($e-=Se),I<-Math.PI?I+=Se:I>Math.PI&&(I-=Se),$e<=I?o.theta=Math.max($e,Math.min(I,o.theta)):o.theta=o.theta>($e+I)/2?Math.max($e,o.theta):Math.min(I,o.theta)),o.phi=Math.max(t.minPolarAngle,Math.min(t.maxPolarAngle,o.phi)),o.makeSafe(),t.enableDamping?c=sr.lerp(c,l,t.dampingFactor):c=l,o.radius*=c,o.radius=Math.max(t.minDistance,Math.min(t.maxDistance,o.radius)),t.enableDamping===!0?t.target.addScaledVector(u,t.dampingFactor):t.target.add(u),H.setFromSpherical(o),H.applyQuaternion(Ie),st.copy(t.target).add(H),t.object.parent?t.object.parent.worldToLocal(st):t.object.position.copy(st),t.object.lookAt(t.target),t.enableDamping===!0?(a.theta*=1-t.dampingFactor,a.phi*=1-t.dampingFactor,u.multiplyScalar(1-t.dampingFactor)):(a.set(0,0,0),u.set(0,0,0)),l=1,d||de.distanceToSquared(t.object.position)>n||8*(1-Xe.dot(t.object.quaternion))>n||Ye.distanceToSquared(t.target)>0?(t.dispatchEvent(G3),de.copy(t.object.position),Xe.copy(t.object.quaternion),Ye.copy(t.target),d=!1,!0):!1}}(),this.dispose=function(){t.domElement.removeEventListener("contextmenu",z),t.domElement.removeEventListener("pointerdown",we),t.domElement.removeEventListener("pointercancel",je),t.domElement.removeEventListener("wheel",ot),t.domElement.removeEventListener("pointermove",Ae),t.domElement.removeEventListener("pointerup",je),t._domElementKeyEvents!==null&&(t._domElementKeyEvents.removeEventListener("keydown",pt),t._domElementKeyEvents=null)};const t=this,s={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let r=s.NONE;const n=1e-6,o=new US,a=new US;let l=1,c=1;const u=new w;let d=!1;const p=new ee,f=new ee,m=new ee,A=new ee,v=new ee,g=new ee,b=new ee,y=new ee,_=new ee,S=[],T={};function M(){return 2*Math.PI/60/60*t.autoRotateSpeed}function R(){return Math.pow(.95,t.zoomSpeed)}function E(H){a.theta-=H}function C(H){a.phi-=H}const F=function(){const H=new w;return function(be,Ie){H.setFromMatrixColumn(Ie,0),H.multiplyScalar(-be),u.add(H)}}(),V=function(){const H=new w;return function(be,Ie){t.screenSpacePanning===!0?H.setFromMatrixColumn(Ie,1):(H.setFromMatrixColumn(Ie,0),H.crossVectors(t.object.up,H)),H.multiplyScalar(be),u.add(H)}}(),U=function(){const H=new w,be=new w;return function(Ie,de){const Xe=t.domElement;if(t.object.isPerspectiveCamera){t.object.getWorldPosition(be),H.copy(be).sub(t.target);let Ye=H.length();Ye*=Math.tan(t.object.fov/2*Math.PI/180),F(2*Ie*Ye/Xe.clientHeight,t.object.matrixWorld),V(2*de*Ye/Xe.clientHeight,t.object.matrixWorld)}else t.object.isOrthographicCamera?(F(Ie*(t.object.right-t.object.left)/t.object.zoom/Xe.clientWidth,t.object.matrixWorld),V(de*(t.object.top-t.object.bottom)/t.object.zoom/Xe.clientHeight,t.object.matrixWorld)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),t.enablePan=!1)}}();function G(H){t.object.isPerspectiveCamera?l/=H:t.object.isOrthographicCamera?(t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom*H)),t.object.updateProjectionMatrix(),d=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function K(H){t.object.isPerspectiveCamera?l*=H:t.object.isOrthographicCamera?(t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom/H)),t.object.updateProjectionMatrix(),d=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function N(H){p.set(H.clientX,H.clientY)}function O(H){b.set(H.clientX,H.clientY)}function j(H){A.set(H.clientX,H.clientY)}function se(H){f.set(H.clientX,H.clientY),m.subVectors(f,p).multiplyScalar(t.rotateSpeed);const be=t.domElement;E(2*Math.PI*m.x/be.clientHeight),C(2*Math.PI*m.y/be.clientHeight),p.copy(f),t.update()}function $(H){y.set(H.clientX,H.clientY),_.subVectors(y,b),_.y>0?G(R()):_.y<0&&K(R()),b.copy(y),t.update()}function X(H){v.set(H.clientX,H.clientY),g.subVectors(v,A).multiplyScalar(t.panSpeed),U(g.x,g.y),A.copy(v),t.update()}function ie(H){H.deltaY<0?K(R()):H.deltaY>0&&G(R()),t.update()}function fe(H){let be=!1;switch(H.code){case t.keys.UP:H.ctrlKey||H.metaKey||H.shiftKey?C(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):U(0,t.keyPanSpeed),be=!0;break;case t.keys.BOTTOM:H.ctrlKey||H.metaKey||H.shiftKey?C(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):U(0,-t.keyPanSpeed),be=!0;break;case t.keys.LEFT:H.ctrlKey||H.metaKey||H.shiftKey?E(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):U(t.keyPanSpeed,0),be=!0;break;case t.keys.RIGHT:H.ctrlKey||H.metaKey||H.shiftKey?E(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):U(-t.keyPanSpeed,0),be=!0;break}be&&(H.preventDefault(),t.update())}function xe(){if(S.length===1)p.set(S[0].pageX,S[0].pageY);else{const H=.5*(S[0].pageX+S[1].pageX),be=.5*(S[0].pageY+S[1].pageY);p.set(H,be)}}function Be(){if(S.length===1)A.set(S[0].pageX,S[0].pageY);else{const H=.5*(S[0].pageX+S[1].pageX),be=.5*(S[0].pageY+S[1].pageY);A.set(H,be)}}function Fe(){const H=S[0].pageX-S[1].pageX,be=S[0].pageY-S[1].pageY,Ie=Math.sqrt(H*H+be*be);b.set(0,Ie)}function We(){t.enableZoom&&Fe(),t.enablePan&&Be()}function Je(){t.enableZoom&&Fe(),t.enableRotate&&xe()}function qe(H){if(S.length==1)f.set(H.pageX,H.pageY);else{const Ie=Oe(H),de=.5*(H.pageX+Ie.x),Xe=.5*(H.pageY+Ie.y);f.set(de,Xe)}m.subVectors(f,p).multiplyScalar(t.rotateSpeed);const be=t.domElement;E(2*Math.PI*m.x/be.clientHeight),C(2*Math.PI*m.y/be.clientHeight),p.copy(f)}function wt(H){if(S.length===1)v.set(H.pageX,H.pageY);else{const be=Oe(H),Ie=.5*(H.pageX+be.x),de=.5*(H.pageY+be.y);v.set(Ie,de)}g.subVectors(v,A).multiplyScalar(t.panSpeed),U(g.x,g.y),A.copy(v)}function pe(H){const be=Oe(H),Ie=H.pageX-be.x,de=H.pageY-be.y,Xe=Math.sqrt(Ie*Ie+de*de);y.set(0,Xe),_.set(0,Math.pow(y.y/b.y,t.zoomSpeed)),G(_.y),b.copy(y)}function q(H){t.enableZoom&&pe(H),t.enablePan&&wt(H)}function Ue(H){t.enableZoom&&pe(H),t.enableRotate&&qe(H)}function we(H){t.enabled!==!1&&(S.length===0&&(t.domElement.addEventListener("pointermove",Ae),t.domElement.addEventListener("pointerup",je)),k(H),H.pointerType==="touch"?Yt(H):ve(H))}function Ae(H){t.enabled!==!1&&(H.pointerType==="touch"?oi(H):Ke(H))}function je(H){ue(H),S.length===0&&(t.domElement.removeEventListener("pointermove",Ae),t.domElement.removeEventListener("pointerup",je)),t.dispatchEvent(Q3),r=s.NONE}function ve(H){let be;switch(H.button){case 0:be=t.mouseButtons.LEFT;break;case 1:be=t.mouseButtons.MIDDLE;break;case 2:be=t.mouseButtons.RIGHT;break;default:be=-1}switch(be){case Lh.DOLLY:if(t.enableZoom===!1)return;O(H),r=s.DOLLY;break;case Lh.ROTATE:if(H.ctrlKey||H.metaKey||H.shiftKey){if(t.enablePan===!1)return;j(H),r=s.PAN}else{if(t.enableRotate===!1)return;N(H),r=s.ROTATE}break;case Lh.PAN:if(H.ctrlKey||H.metaKey||H.shiftKey){if(t.enableRotate===!1)return;N(H),r=s.ROTATE}else{if(t.enablePan===!1)return;j(H),r=s.PAN}break;default:r=s.NONE}r!==s.NONE&&t.dispatchEvent(xT)}function Ke(H){switch(r){case s.ROTATE:if(t.enableRotate===!1)return;se(H);break;case s.DOLLY:if(t.enableZoom===!1)return;$(H);break;case s.PAN:if(t.enablePan===!1)return;X(H);break}}function ot(H){t.enabled===!1||t.enableZoom===!1||r!==s.NONE||(H.preventDefault(),t.dispatchEvent(xT),ie(H),t.dispatchEvent(Q3))}function pt(H){t.enabled===!1||t.enablePan===!1||fe(H)}function Yt(H){switch(ke(H),S.length){case 1:switch(t.touches.ONE){case Uh.ROTATE:if(t.enableRotate===!1)return;xe(),r=s.TOUCH_ROTATE;break;case Uh.PAN:if(t.enablePan===!1)return;Be(),r=s.TOUCH_PAN;break;default:r=s.NONE}break;case 2:switch(t.touches.TWO){case Uh.DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;We(),r=s.TOUCH_DOLLY_PAN;break;case Uh.DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;Je(),r=s.TOUCH_DOLLY_ROTATE;break;default:r=s.NONE}break;default:r=s.NONE}r!==s.NONE&&t.dispatchEvent(xT)}function oi(H){switch(ke(H),r){case s.TOUCH_ROTATE:if(t.enableRotate===!1)return;qe(H),t.update();break;case s.TOUCH_PAN:if(t.enablePan===!1)return;wt(H),t.update();break;case s.TOUCH_DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;q(H),t.update();break;case s.TOUCH_DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;Ue(H),t.update();break;default:r=s.NONE}}function z(H){t.enabled!==!1&&H.preventDefault()}function k(H){S.push(H)}function ue(H){delete T[H.pointerId];for(let be=0;be<S.length;be++)if(S[be].pointerId==H.pointerId){S.splice(be,1);return}}function ke(H){let be=T[H.pointerId];be===void 0&&(be=new ee,T[H.pointerId]=be),be.set(H.pageX,H.pageY)}function Oe(H){const be=H.pointerId===S[0].pointerId?S[1]:S[0];return T[be.pointerId]}t.domElement.addEventListener("contextmenu",z),t.domElement.addEventListener("pointerdown",we),t.domElement.addEventListener("pointercancel",je),t.domElement.addEventListener("wheel",ot,{passive:!1}),this.update()}};const oie="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/";class aie{constructor(e,t,s,r,n=null){this.controller=t,this.handModel=e,this.bones=[],n===null&&(n=new yp,n.setPath(s||oie)),n.load(`${r}.glb`,o=>{const a=o.scene.children[0];this.handModel.add(a),a.layers.mask=this.handModel.layers.mask;const l=a.getObjectByProperty("type","SkinnedMesh");l.frustumCulled=!1,l.castShadow=!0,l.receiveShadow=!0,["wrist","thumb-metacarpal","thumb-phalanx-proximal","thumb-phalanx-distal","thumb-tip","index-finger-metacarpal","index-finger-phalanx-proximal","index-finger-phalanx-intermediate","index-finger-phalanx-distal","index-finger-tip","middle-finger-metacarpal","middle-finger-phalanx-proximal","middle-finger-phalanx-intermediate","middle-finger-phalanx-distal","middle-finger-tip","ring-finger-metacarpal","ring-finger-phalanx-proximal","ring-finger-phalanx-intermediate","ring-finger-phalanx-distal","ring-finger-tip","pinky-finger-metacarpal","pinky-finger-phalanx-proximal","pinky-finger-phalanx-intermediate","pinky-finger-phalanx-distal","pinky-finger-tip"].forEach(c=>{const u=a.getObjectByName(c);u!==void 0?u.jointName=c:console.warn(`Couldn't find ${c} in ${r} hand mesh`),this.bones.push(u)})})}updateMesh(){const e=this.controller.joints;for(let t=0;t<this.bones.length;t++){const s=this.bones[t];if(s){const r=e[s.jointName];if(r.visible){const n=r.position;s.position.copy(n),s.quaternion.copy(r.quaternion)}}}}}const lie=.01,cie="index-finger-tip";class hie extends _e{constructor(e,t=null){super(),this.controller=e,this.motionController=null,this.envMap=null,this.loader=t,this.mesh=null,e.addEventListener("connected",s=>{const r=s.data;r.hand&&!this.motionController&&(this.xrInputSource=r,this.motionController=new aie(this,e,this.path,r.handedness,this.loader))}),e.addEventListener("disconnected",()=>{this.clear(),this.motionController=null})}updateMatrixWorld(e){super.updateMatrixWorld(e),this.motionController&&this.motionController.updateMesh()}getPointerPosition(){const e=this.controller.joints[cie];return e?e.position:null}intersectBoxObject(e){const t=this.getPointerPosition();if(t){const s=new Xr(t,lie),r=new xs().setFromObject(e);return s.intersectsBox(r)}else return!1}checkButton(e){this.intersectBoxObject(e)?e.onPress():e.onClear(),e.isPressed()&&e.whilePressed()}}const uie=.05,V3=.02,d_=.01,H3=.02,W3=1,jp=.4,die=.002,Hg=.01,p_=.003,X3=.035,Ci=16,Co=12,wT=110,pie=new w(0,1,0),fie=new w(0,0,1),mie=.02,gie=1.5;class vie extends _e{constructor(e,t){super(),this.hand=e,this.controller=t,this.motionController=null,this.envMap=null,this.mesh=null,this.pointerGeometry=null,this.pointerMesh=null,this.pointerObject=null,this.pinched=!1,this.attached=!1,this.cursorObject=null,this.raycaster=null,this._onConnected=this._onConnected.bind(this),this._onDisconnected=this._onDisconnected.bind(this),this.hand.addEventListener("connected",this._onConnected),this.hand.addEventListener("disconnected",this._onDisconnected)}_onConnected(e){const t=e.data;t.hand&&(this.visible=!0,this.xrInputSource=t,this.createPointer())}_onDisconnected(){this.visible=!1,this.xrInputSource=null,this.pointerGeometry&&this.pointerGeometry.dispose(),this.pointerMesh&&this.pointerMesh.material&&this.pointerMesh.material.dispose(),this.clear()}_drawVerticesRing(e,t,s){const r=t.clone();for(let n=0;n<Ci;n++){r.applyAxisAngle(fie,Math.PI*2/Ci);const o=s*Ci+n;e[3*o]=r.x,e[3*o+1]=r.y,e[3*o+2]=r.z}}_updatePointerVertices(e){const t=this.pointerGeometry.attributes.position.array,s=new w(die,0,-1*(X3-e));this._drawVerticesRing(t,s,0);const r=new w(Math.sin(Math.PI*wT/180)*e,Math.cos(Math.PI*wT/180)*e,0);for(let c=0;c<Co;c++)this._drawVerticesRing(t,r,c+1),r.applyAxisAngle(pie,Math.PI*wT/180/(Co*-2));const n=Ci*(1+Co),o=Ci*(1+Co)+1,a=new w(0,0,-1*(X3-e));t[n*3]=a.x,t[n*3+1]=a.y,t[n*3+2]=a.z;const l=new w(0,0,e);t[o*3]=l.x,t[o*3+1]=l.y,t[o*3+2]=l.z,this.pointerGeometry.setAttribute("position",new at(t,3))}createPointer(){let e,t;const s=new Array(((Co+1)*Ci+2)*3).fill(0),r=[];for(this.pointerGeometry=new gt,this.pointerGeometry.setAttribute("position",new at(s,3)),this._updatePointerVertices(Hg),e=0;e<Co;e++){for(t=0;t<Ci-1;t++)r.push(e*Ci+t,e*Ci+t+1,(e+1)*Ci+t),r.push(e*Ci+t+1,(e+1)*Ci+t+1,(e+1)*Ci+t);r.push((e+1)*Ci-1,e*Ci,(e+2)*Ci-1),r.push(e*Ci,(e+1)*Ci,(e+2)*Ci-1)}const n=Ci*(1+Co),o=Ci*(1+Co)+1;for(e=0;e<Ci-1;e++)r.push(n,e+1,e),r.push(o,e+Ci*Co,e+Ci*Co+1);r.push(n,0,Ci-1),r.push(o,Ci*(Co+1)-1,Ci*Co);const a=new li;a.transparent=!0,a.opacity=jp,this.pointerGeometry.setIndex(r),this.pointerMesh=new ge(this.pointerGeometry,a),this.pointerMesh.position.set(0,0,-1*Hg),this.pointerObject=new _e,this.pointerObject.add(this.pointerMesh),this.raycaster=new cu;const l=new Fo(mie,10,10),c=new li;c.transparent=!0,c.opacity=jp,this.cursorObject=new ge(l,c),this.pointerObject.add(this.cursorObject),this.add(this.pointerObject),this.pointerObject.layers.mask=this.layers.mask,this.pointerMesh.layers.mask=this.layers.mask}_updateRaycaster(){if(this.raycaster){const e=this.pointerObject.matrixWorld,t=new Te;t.identity().extractRotation(e),this.raycaster.ray.origin.setFromMatrixPosition(e),this.raycaster.ray.direction.set(0,0,-1).applyMatrix4(t)}}_updatePointer(){this.pointerObject.visible=this.controller.visible;const e=this.hand.joints["index-finger-tip"],t=this.hand.joints["thumb-tip"],s=e.position.distanceTo(t.position),r=e.position.clone().add(t.position).multiplyScalar(.5);this.pointerObject.position.copy(r),this.pointerObject.quaternion.copy(this.controller.quaternion),this.pinched=s<=V3;const n=(s-d_)/(uie-d_),o=(s-d_)/(V3-d_);if(n>1)this._updatePointerVertices(Hg),this.pointerMesh.position.set(0,0,-1*Hg),this.pointerMesh.material.opacity=jp;else if(n>0){const a=(Hg-p_)*n+p_;this._updatePointerVertices(a),o<1?(this.pointerMesh.position.set(0,0,-1*a-(1-o)*H3),this.pointerMesh.material.opacity=jp+(1-o)*(W3-jp)):(this.pointerMesh.position.set(0,0,-1*a),this.pointerMesh.material.opacity=jp)}else this._updatePointerVertices(p_),this.pointerMesh.position.set(0,0,-1*p_-H3),this.pointerMesh.material.opacity=W3;this.cursorObject.material.opacity=this.pointerMesh.material.opacity}updateMatrixWorld(e){super.updateMatrixWorld(e),this.pointerGeometry&&(this._updatePointer(),this._updateRaycaster())}isPinched(){return this.pinched}setAttached(e){this.attached=e}isAttached(){return this.attached}intersectObject(e,t=!0){if(this.raycaster)return this.raycaster.intersectObject(e,t)}intersectObjects(e,t=!0){if(this.raycaster)return this.raycaster.intersectObjects(e,t)}checkIntersections(e,t=!1){if(this.raycaster&&!this.attached){const s=this.raycaster.intersectObjects(e,t),r=new w(0,0,-1);if(s.length>0){const n=s[0].distance;this.cursorObject.position.copy(r.multiplyScalar(n))}else this.cursorObject.position.copy(r.multiplyScalar(gie))}}setCursor(e){const t=new w(0,0,-1);this.raycaster&&!this.attached&&this.cursorObject.position.copy(t.multiplyScalar(e))}dispose(){this._onDisconnected(),this.hand.removeEventListener("connected",this._onConnected),this.hand.removeEventListener("disconnected",this._onDisconnected)}}const is={Handedness:Object.freeze({NONE:"none",LEFT:"left",RIGHT:"right"}),ComponentState:Object.freeze({DEFAULT:"default",TOUCHED:"touched",PRESSED:"pressed"}),ComponentProperty:Object.freeze({BUTTON:"button",X_AXIS:"xAxis",Y_AXIS:"yAxis",STATE:"state"}),ComponentType:Object.freeze({TRIGGER:"trigger",SQUEEZE:"squeeze",TOUCHPAD:"touchpad",THUMBSTICK:"thumbstick",BUTTON:"button"}),ButtonTouchThreshold:.05,AxisTouchThreshold:.1,VisualResponseProperty:Object.freeze({TRANSFORM:"transform",VISIBILITY:"visibility"})};async function q3(i){const e=await fetch(i);if(e.ok)return e.json();throw new Error(e.statusText)}async function Aie(i){if(!i)throw new Error("No basePath supplied");return await q3(`${i}/profilesList.json`)}async function yie(i,e,t=null,s=!0){if(!i)throw new Error("No xrInputSource supplied");if(!e)throw new Error("No basePath supplied");const r=await Aie(e);let n;if(i.profiles.some(l=>{const c=r[l];return c&&(n={profileId:l,profilePath:`${e}/${c.path}`,deprecated:!!c.deprecated}),!!n}),!n){if(!t)throw new Error("No matching profile name found");const l=r[t];if(!l)throw new Error(`No matching profile name found and default profile "${t}" missing.`);n={profileId:t,profilePath:`${e}/${l.path}`,deprecated:!!l.deprecated}}const o=await q3(n.profilePath);let a;if(s){let l;if(i.handedness==="any"?l=o.layouts[Object.keys(o.layouts)[0]]:l=o.layouts[i.handedness],!l)throw new Error(`No matching handedness, ${i.handedness}, in profile ${n.profileId}`);l.assetPath&&(a=n.profilePath.replace("profile.json",l.assetPath))}return{profile:o,assetPath:a}}const bie={xAxis:0,yAxis:0,button:0,state:is.ComponentState.DEFAULT};function _ie(i=0,e=0){let t=i,s=e;if(Math.sqrt(i*i+e*e)>1){const r=Math.atan2(e,i);t=Math.cos(r),s=Math.sin(r)}return{normalizedXAxis:t*.5+.5,normalizedYAxis:s*.5+.5}}class xie{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===is.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(bie)}updateFromComponent({xAxis:e,yAxis:t,button:s,state:r}){const{normalizedXAxis:n,normalizedYAxis:o}=_ie(e,t);switch(this.componentProperty){case is.ComponentProperty.X_AXIS:this.value=this.states.includes(r)?n:.5;break;case is.ComponentProperty.Y_AXIS:this.value=this.states.includes(r)?o:.5;break;case is.ComponentProperty.BUTTON:this.value=this.states.includes(r)?s:0;break;case is.ComponentProperty.STATE:this.valueNodeProperty===is.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(r):this.value=this.states.includes(r)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}}class wie{constructor(e,t){if(!e||!t||!t.visualResponses||!t.gamepadIndices||Object.keys(t.gamepadIndices).length===0)throw new Error("Invalid arguments supplied");this.id=e,this.type=t.type,this.rootNodeName=t.rootNodeName,this.touchPointNodeName=t.touchPointNodeName,this.visualResponses={},Object.keys(t.visualResponses).forEach(s=>{const r=new xie(t.visualResponses[s]);this.visualResponses[s]=r}),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:is.ComponentState.DEFAULT,button:this.gamepadIndices.button!==void 0?0:void 0,xAxis:this.gamepadIndices.xAxis!==void 0?0:void 0,yAxis:this.gamepadIndices.yAxis!==void 0?0:void 0}}get data(){return{id:this.id,...this.values}}updateFromGamepad(e){if(this.values.state=is.ComponentState.DEFAULT,this.gamepadIndices.button!==void 0&&e.buttons.length>this.gamepadIndices.button){const t=e.buttons[this.gamepadIndices.button];this.values.button=t.value,this.values.button=this.values.button<0?0:this.values.button,this.values.button=this.values.button>1?1:this.values.button,t.pressed||this.values.button===1?this.values.state=is.ComponentState.PRESSED:(t.touched||this.values.button>is.ButtonTouchThreshold)&&(this.values.state=is.ComponentState.TOUCHED)}this.gamepadIndices.xAxis!==void 0&&e.axes.length>this.gamepadIndices.xAxis&&(this.values.xAxis=e.axes[this.gamepadIndices.xAxis],this.values.xAxis=this.values.xAxis<-1?-1:this.values.xAxis,this.values.xAxis=this.values.xAxis>1?1:this.values.xAxis,this.values.state===is.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>is.AxisTouchThreshold&&(this.values.state=is.ComponentState.TOUCHED)),this.gamepadIndices.yAxis!==void 0&&e.axes.length>this.gamepadIndices.yAxis&&(this.values.yAxis=e.axes[this.gamepadIndices.yAxis],this.values.yAxis=this.values.yAxis<-1?-1:this.values.yAxis,this.values.yAxis=this.values.yAxis>1?1:this.values.yAxis,this.values.state===is.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>is.AxisTouchThreshold&&(this.values.state=is.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(t=>{t.updateFromComponent(this.values)})}}class Sie{constructor(e,t,s){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=s,this.id=t.profileId,this.layoutDescription=t.layouts[e.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(r=>{const n=this.layoutDescription.components[r];this.components[r]=new wie(r,n)}),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const e=[];return Object.values(this.components).forEach(t=>{e.push(t.data)}),e}updateFromGamepad(){Object.values(this.components).forEach(e=>{e.updateFromGamepad(this.xrInputSource.gamepad)})}}const Cie="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",Eie="generic-trigger";class Mie extends _e{constructor(){super(),this.motionController=null,this.envMap=null}setEnvironmentMap(e){return this.envMap==e?this:(this.envMap=e,this.traverse(t=>{t.isMesh&&(t.material.envMap=this.envMap,t.material.needsUpdate=!0)}),this)}updateMatrixWorld(e){super.updateMatrixWorld(e),this.motionController&&(this.motionController.updateFromGamepad(),Object.values(this.motionController.components).forEach(t=>{Object.values(t.visualResponses).forEach(s=>{const{valueNode:r,minNode:n,maxNode:o,value:a,valueNodeProperty:l}=s;r&&(l===is.VisualResponseProperty.VISIBILITY?r.visible=a:l===is.VisualResponseProperty.TRANSFORM&&(r.quaternion.slerpQuaternions(n.quaternion,o.quaternion,a),r.position.lerpVectors(n.position,o.position,a)))})}))}}function Tie(i,e){Object.values(i.components).forEach(t=>{const{type:s,touchPointNodeName:r,visualResponses:n}=t;if(s===is.ComponentType.TOUCHPAD)if(t.touchPointNode=e.getObjectByName(r),t.touchPointNode){const o=new Fo(.001),a=new li({color:255}),l=new ge(o,a);t.touchPointNode.add(l)}else console.warn(`Could not find touch dot, ${t.touchPointNodeName}, in touchpad component ${t.id}`);Object.values(n).forEach(o=>{const{valueNodeName:a,minNodeName:l,maxNodeName:c,valueNodeProperty:u}=o;if(u===is.VisualResponseProperty.TRANSFORM){if(o.minNode=e.getObjectByName(l),o.maxNode=e.getObjectByName(c),!o.minNode){console.warn(`Could not find ${l} in the model`);return}if(!o.maxNode){console.warn(`Could not find ${c} in the model`);return}}o.valueNode=e.getObjectByName(a),o.valueNode||console.warn(`Could not find ${a} in the model`)})})}function Y3(i,e){Tie(i.motionController,e),i.envMap&&e.traverse(t=>{t.isMesh&&(t.material.envMap=i.envMap,t.material.needsUpdate=!0)}),i.layers.mask!=0&&e.traverse(t=>{t.layers.mask=i.layers.mask}),i.add(e)}class Iie{constructor(e=null){this.gltfLoader=e,this.path=Cie,this._assetCache={},this.gltfLoader||(this.gltfLoader=new yp)}createControllerModel(e){const t=new Mie;let s=null;return e.addEventListener("connected",r=>{const n=r.data;n.targetRayMode!=="tracked-pointer"||!n.gamepad||yie(n,this.path,Eie).then(({profile:o,assetPath:a})=>{t.motionController=new Sie(n,o,a);const l=this._assetCache[t.motionController.assetUrl];if(l)s=l.scene.clone(),Y3(t,s);else{if(!this.gltfLoader)throw new Error("GLTFLoader not set.");this.gltfLoader.setPath(""),this.gltfLoader.load(t.motionController.assetUrl,c=>{this._assetCache[t.motionController.assetUrl]=c,s=c.scene.clone(),Y3(t,s)},null,()=>{throw new Error(`Asset ${t.motionController.assetUrl} missing or malformed.`)})}}).catch(o=>{console.warn(o)})}),e.addEventListener("disconnected",()=>{t.motionController=null,t.remove(s),s=null}),t}}const Wg=oe("debugavatar");class f_{constructor(e,t,s,r){h(this,"root"),h(this,"head"),h(this,"leftHand"),h(this,"rigthHand");var n;this.root=e,this.head=t,this.leftHand=s,this.rigthHand=r,(n=this.root)==null||n.traverse(o=>o.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class m_{constructor(){h(this,"avatarRegistryUrl",null)}async getOrCreateNewAvatarInstance(e,t){if(!t)return console.error("Can not create avatar: failed to provide id or root object"),null;let s=null;if(typeof t=="string"){if(s=await this.loadAvatar(e,t),!s){const n=new Ia;s=te.instantiate(tp(t,e.scene),n)}}else s=t;if(!s)return null;const r=this.findAvatar(s);return r.isValid?(Wg&&console.log("[Custom Avatar] valid config",t,Wg?r:""),r):(console.warn("[Custom Avatar] config isn't valid",t,Wg?r:""),null)}async loadAvatar(e,t){if(console.assert(t!=null&&typeof t=="string","Avatar id must not be null"),t.length<=0||!t)return null;if(Wg&&console.log("[Custom Avatar] "+t+", loading..."),t.endsWith(".glb")||(t+=".glb"),this.avatarRegistryUrl===null){const r=await fetch("./"+t);let n=null;if(r.ok){const a=await r.blob();a&&(n=await a.arrayBuffer())}if(!n&&(n=await AE(t,t,0,"no url here go away",!0),!n))return null;const o=await ea().parseSync(e,n,null,0);return o?.scene??null}const s=new yp;return Tg(s,e),new Promise((r,n)=>{const o=this.avatarRegistryUrl+"/"+t;s.load(o,async a=>{await ea().createBuiltinComponents(e,o,a,null,void 0),r(a.scene)},a=>{Wg&&console.log("[Custom Avatar] "+a.loaded/a.total*100+"% loaded of "+a.total/1024+"kB")},a=>{console.error("[Custom Avatar] Error when loading: "+a),r(null)})})}cacheModel(e,t){}findAvatar(e){const t=e;let s=t;s.children.length==1&&(s=e.children[0]);let r=this.findAvatarPart(s,["head"]);const n=this.findAvatarPart(s,["left","hand"]),o=this.findAvatarPart(s,["right","hand"]);if(!r){r=t;const a=new w;new xs().setFromObject(r).getSize(a);const l=Math.max(a.x,a.y,a.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+l+" meters! Should be < 0.3m"),l>.3&&r.scale.multiplyScalar(1/l*.3)}return new f_(t,r,n,o)}findAvatarPart(e,t){const s=e.name.toLowerCase();let r=!0;for(const n of t){if(!r)break;s.indexOf(n)===-1&&(r=!1)}if(r)return e;if(e.children)for(const n of e.children){const o=this.findAvatarPart(n,t);if(o)return o}return null}handleCustomAvatarErrors(e){if(!e.ok)throw Error(e.statusText);return e}}var Rie=Object.defineProperty,Pie=Object.getOwnPropertyDescriptor,Bie=(i,e,t,s)=>{for(var r=s>1?void 0:s?Pie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Rie(e,t,r),r};const Gp=oe("debugflags");var vs=(i=>(i[i.Never=0]="Never",i[i.Browser=1]="Browser",i[i.AR=2]="AR",i[i.VR=4]="VR",i[i.FirstPerson=8]="FirstPerson",i[i.ThirdPerson=16]="ThirdPerson",i[i.All=4294967295]="All",i))(vs||{});const K3=class{constructor(){h(this,"Mask",17)}Has(i){return(this.Mask&i)!==0}Set(i){Gp&&console.warn("Set XR flag state to",i),this.Mask=i,Hn.Apply()}Enable(i){this.Mask|=i,Hn.Apply()}Disable(i){this.Mask&=~i,Hn.Apply()}Toggle(i){this.Mask^=i,Hn.Apply()}EnableAll(){this.Mask=-1,Hn.Apply()}DisableAll(){this.Mask=0,Hn.Apply()}};let Vn=K3;h(Vn,"Global",new K3);var Xg;const Yl=(Xg=class extends Pe{constructor(){super(...arguments),h(this,"visibleIn")}static Apply(){for(const i of this.registry)i.UpdateVisible(Vn.Global)}awake(){Yl.registry.push(this)}onEnable(){Yl.firstApply?this.UpdateVisible(Vn.Global):(Yl.firstApply=!0,Yl.Apply())}onDestroy(){const i=Yl.registry.indexOf(this);i>=0&&Yl.registry.splice(i,1)}get isOn(){return this.gameObject.visible}UpdateVisible(i=null){let e;const t=i;t&&typeof t=="number"&&(console.assert(typeof t=="number","XRFlag.UpdateVisible: state must be a number",t),Gp&&console.log(t),Yl.buffer.Mask=t,i=Yl.buffer);const s=i;if(s?(Gp&&console.warn(this.name,"use passed in mask",s.Mask,this.visibleIn),e=s.Has(this.visibleIn)):(Gp&&console.log(this.name,"use global mask"),Vn.Global.Has(this.visibleIn)),e!==void 0)if(e)Gp&&console.log(this.name,"is visible",this.gameObject.uuid),te.setActive(this.gameObject,!0);else{if(Gp&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},h(Xg,"registry",[]),h(Xg,"firstApply"),h(Xg,"buffer",new Vn),Xg);let Hn=Yl;Bie([x()],Hn.prototype,"visibleIn",2);const ah=oe("debugavatar"),Fa=class extends Pe{constructor(){super(...arguments),h(this,"connectionId"),h(this,"avatar")}static getAvatar(i){return i>=0&&i<Fa.instances.length?Fa.instances[i]:null}static onAvatarMarkerCreated(i){return Fa._onNewAvatarMarkerAdded.push(i),i}static onAvatarMarkerDestroyed(i){return Fa._onAvatarMarkerDestroyed.push(i),i}awake(){Fa.instances.push(this),ah&&console.log(this);for(const i of Fa._onNewAvatarMarkerAdded)i({avatarMarker:this,gameObject:this.gameObject})}onDestroy(){Fa.instances.splice(Fa.instances.indexOf(this),1);for(const i of Fa._onAvatarMarkerDestroyed)i({avatarMarker:this,gameObject:this.gameObject})}isLocalAvatar(){return this.connectionId===this.context.connection.connectionId}setVisible(i){this.avatar&&("setVisible"in this.avatar?this.avatar.setVisible(i):te.setActive(this.avatar,i))}};let Ur=Fa;h(Ur,"instances",[]),h(Ur,"_onNewAvatarMarkerAdded",[]),h(Ur,"_onAvatarMarkerDestroyed",[]);const g_=class{constructor(i,e,t){h(this,"_isVisible",!0),h(this,"guid"),h(this,"root",null),h(this,"head",null),h(this,"handLeft",null),h(this,"handRight",null),h(this,"lastUpdate",-1),h(this,"isLocalAvatar",!1),h(this,"flags",null),h(this,"headScale",new w(1,1,1)),h(this,"handLeftScale",new w(1,1,1)),h(this,"handRightScale",new w(1,1,1)),h(this,"webxr"),h(this,"lastAvatarId",null),h(this,"hasAvatarOverride",!1),h(this,"context"),h(this,"avatarMarker",null),h(this,"_headTarget",new _e),h(this,"_handLeftTarget",new _e),h(this,"_handRightTarget",new _e),h(this,"_canInterpolate",!1),this.context=i,this.guid=e,this.webxr=t,this.setupCustomAvatar(this.webxr.defaultAvatar)}setVisible(i){this._isVisible=i,this.updateVisibility()}get isWebXRAvatar(){return!0}updateFlags(){if(!this.flags)return;let i=this.isLocalAvatar?vs.FirstPerson:vs.ThirdPerson;this.context.isInVR?i|=vs.VR:this.context.isInAR?i|=vs.AR:i|=vs.Browser;for(const e of this.flags)e.gameObject.visible=!0,e.UpdateVisible(i)}async setAvatarOverride(i){return this.hasAvatarOverride=i!==null,this.hasAvatarOverride&&this.lastAvatarId!==i&&(this.lastAvatarId=i,i!=null&&i.length>0)?await this.setupCustomAvatar(i):null}tryUpdate(i,e){if(i.guid===this.guid&&(this.lastAvatarId!==i.avatarId&&i.avatarId&&i.avatarId.length>0&&(this.lastAvatarId=i.avatarId,this.setupCustomAvatar(i.avatarId)),this.lastUpdate=i.time,this.head)){const t=this.webxr.IsInAR?Da.Handheld:Da.Headset,s=this.head;this.context.players.setPlayerView(i.guid,s,t),Gr.markDirty(this.head),this._canInterpolate=!0;const r=this.isLocalAvatar?this.head:this._headTarget;if(r.position.set(i.position.x,i.position.y,i.position.z),r.quaternion.set(i.rotation.x,i.rotation.y,i.rotation.z,i.rotation.w),r.scale.set(i.scale,i.scale,i.scale),r.scale.multiply(this.headScale),this.handLeft){const n=this.isLocalAvatar?this.handLeft:this._handLeftTarget;n.position.set(i.posLeftHand.x,i.posLeftHand.y,i.posLeftHand.z),n.quaternion.set(i.rotLeftHand._x,i.rotLeftHand._y,i.rotLeftHand._z,i.rotLeftHand._w),n.quaternion.multiply(g_.invertRotation),n.scale.set(i.scale,i.scale,i.scale),n.scale.multiply(this.handLeftScale),Gr.markDirty(this.handLeft)}if(this.handRight){const n=this.isLocalAvatar?this.handRight:this._handRightTarget;n.position.set(i.posRightHand.x,i.posRightHand.y,i.posRightHand.z),n.quaternion.set(i.rotRightHand._x,i.rotRightHand._y,i.rotRightHand._z,i.rotRightHand._w),n.quaternion.multiply(g_.invertRotation),n.scale.set(i.scale,i.scale,i.scale),n.scale.multiply(this.handRightScale),Gr.markDirty(this.handRight)}}}update(){if(this.isLocalAvatar||!this._canInterpolate)return;const i=this.context.time.deltaTime/.1;this.head&&(this.head.position.lerp(this._headTarget.position,i),this.head.quaternion.slerp(this._headTarget.quaternion,i),this.head.scale.lerp(this._headTarget.scale,i)),this.handLeft&&this._handLeftTarget&&(this.handLeft.position.lerp(this._handLeftTarget.position,i),this.handLeft.quaternion.slerp(this._handLeftTarget.quaternion,i),this.handLeft.scale.lerp(this._handLeftTarget.scale,i)),this.handRight&&this._handRightTarget&&(this.handRight.position.lerp(this._handRightTarget.position,i),this.handRight.quaternion.slerp(this._handRightTarget.quaternion,i),this.handRight.scale.lerp(this._handRightTarget.scale,i))}destroy(){var i,e;ah&&console.log("Destroy avatar",this.guid),(i=this.root)==null||i.removeFromParent(),(e=this.avatarMarker)==null||e.destroy(),this.lastAvatarId=null,this.head&&an.Remove(this.context,this.head)}updateVisibility(){const i=this.root;i&&te.setActive(i,this._isVisible)}async setupCustomAvatar(i){var e,t,s;if(ah&&console.log("LOAD",i,this),!i||typeof i=="string"&&i.length<=0)return!1;this.head&&an.Remove(this.context,this.head);const r=i;if(r?.loadAssetAsync!==void 0){await r.loadAssetAsync();const o=r.asset;te.setActive(o,!1),i=te.instantiate(o),te.setActive(i,!0)}ah&&console.log(i);const n=await g_.loader.getOrCreateNewAvatarInstance(this.context,i);if(ah&&console.log(n,n?.isValid,this.lastAvatarId,i),n!=null&&n.isValid){if(this.root=n.root,this.root.position.set(0,0,0),this.root.quaternion.set(0,0,0,1),this.root.scale.set(1,1,1),this.avatarMarker=te.addNewComponent(this.root,Ur),this.avatarMarker.connectionId=this.guid,this.avatarMarker.avatar=this,this.head&&this.head!==n.head&&((e=this.head)==null||e.removeFromParent()),this.head=n.head,this.headScale.copy(this.head.scale),this.head&&!this.isLocalAvatar&&an.Add(this.context,this.head,this.avatarMarker),n.leftHand&&((t=this.handLeft)==null||t.removeFromParent()),this.handLeft=n.leftHand??this.handLeft,this.handLeft?this.handLeftScale.copy(this.handLeft.scale):this.handLeftScale.set(1,1,1),n.rigthHand&&((s=this.handRight)==null||s.removeFromParent()),this.handRight=n.rigthHand??this.handRight,this.handRight?this.handRightScale.copy(this.handRight.scale):this.handRightScale.set(1,1,1),this.context.scene.add(this.root),this.flags==null&&(this.flags=[]),this.flags.length=0,this.flags.push(...te.getComponentsInChildren(this.root,Hn)),this.flags.length<=0&&this.head){const o=te.addNewComponent(this.head,Hn);o.visibleIn=vs.ThirdPerson|vs.VR,this.flags.push(o),ah&&console.log("Added flag to head: "+o.visibleIn,this.head.name)}return ah&&console.log("[Avatar], is Local? ",this.isLocalAvatar,this.root),this.updateFlags(),this.updateVisibility(),!0}else return ah&&console.warn("build avatar failed"),!1}};let lh=g_;h(lh,"loader",new m_),h(lh,"invertRotation",new Me().setFromAxisAngle(new w(0,1,0),Math.PI));class an{static Add(e,t,s=null){if(t){for(const r of this.Pois)if(r.obj===t)return;this.Pois.push({obj:t,avatar:s}),this.LastChangeTime=e.time.time}}static Remove(e,t){var s;if(t){for(const r of this.Pois)if(r.obj===t){this.Pois.splice(this.Pois.indexOf(r),1),this.LastChangeTime=e?.time.time??((s=Ot.Current)==null?void 0:s.time.time);return}}}}h(an,"Pois",[]),h(an,"LastChangeTime",0);class Die{constructor(){h(this,"guid"),h(this,"position",new w)}}class qg extends Pe{constructor(){super(...arguments),h(this,"target",null),h(this,"avatar",null),h(this,"_model",null),h(this,"_targetModel",new Die),h(this,"_currentTargetObject",null),h(this,"_lastUpdateTime",0),h(this,"_lookDuration",0),h(this,"_lastPoiChangedTime",0)}set controlledTarget(e){this.target=e;const t=Y.get("MoveRandom");if(t&&this.target){const s=te.getComponent(this.target,t);s&&s.destroy()}}awake(){if(this.avatar=te.getComponentInParent(this.gameObject,Ur),this.avatar){const e=te.getComponentInParent(this.gameObject,Ur);this._model=new I0(this.context.connection,this.guid),e!=null&&e.isLocalAvatar&&this._model.requestOwnership()}this.context.connection.beginListen("avatar-look-target-changed",e=>{var t;this.target&&e&&e.guid===((t=this.avatar)==null?void 0:t.guid)&&ds(this.target,e.position)})}update(){var e;if((!this.context.connection.isConnected||(e=this._model)!=null&&e.hasOwnership)&&(an.LastChangeTime!==this._lastPoiChangedTime&&(this._lastPoiChangedTime=an.LastChangeTime,this._lookDuration=0),this.selectTarget(),this._currentTargetObject&&this.context.time.frameCount%10===0&&this.target)){const t=ft(this._currentTargetObject);ds(this.target,t),this.context.connection.isConnected&&this.avatar&&(this.context.connection.send("avatar-look-target-changed",this._targetModel),this._targetModel.guid=this.avatar.guid,this._targetModel.position.copy(t))}}selectTarget(){if(this.context.time.time-this._lastUpdateTime>this._lookDuration){this._lastUpdateTime=this.context.time.time,this._lookDuration=Math.random()*.5+.2;const e=an.Pois;if(e.length>0){const t=e[Math.floor(Math.random()*e.length)];if(t&&t.obj){if(t.avatar&&t.avatar===this.avatar)return;this._currentTargetObject=t.obj}}}}}class Qp extends Pe{constructor(){super(...arguments),h(this,"canGrab",!0)}onPointerClick(e){}}class Vp extends Pe{constructor(){super(...arguments),h(this,"isUsed",!0),h(this,"usedBy",null)}}var Js=(i=>(i[i.Average=0]="Average",i[i.Multiply=1]="Multiply",i[i.Minimum=2]="Minimum",i[i.Maximum=3]="Maximum",i))(Js||{}),v_=(i=>(i[i.Discrete=0]="Discrete",i[i.Continuous=1]="Continuous",i))(v_||{}),As=(i=>(i[i.None=0]="None",i[i.FreezePositionX=2]="FreezePositionX",i[i.FreezePositionY=4]="FreezePositionY",i[i.FreezePositionZ=8]="FreezePositionZ",i[i.FreezePosition=14]="FreezePosition",i[i.FreezeRotationX=16]="FreezeRotationX",i[i.FreezeRotationY=32]="FreezeRotationY",i[i.FreezeRotationZ=64]="FreezeRotationZ",i[i.FreezeRotation=112]="FreezeRotation",i[i.FreezeAll=126]="FreezeAll",i))(As||{}),Hp=(i=>(i[i.None=0]="None",i[i.X=2]="X",i[i.Y=4]="Y",i[i.Z=8]="Z",i[i.All=-1]="All",i))(Hp||{});const fr=function(i,e){return function(t,s,r){kie(t,s,r,i,e)}};function kie(i,e,t,s,r){if(!r&&!s&&!i.onValidate)return;if(t!==void 0){console.error("Invalid usage of validate decorator. Only fields can be validated.",i,e,t),hs("Invalid usage of validate decorator. Only fields can be validated. Property: "+e,po.Error);return}let n="";if(typeof e=="string"?n=e:n=e.name,i.__internalAwake){const o=Symbol(n),a=i.__internalAwake;i.__internalAwake=function(){var l;if(!this.onValidate){zt()&&console.warn('Usage of @validate decorate detected but there is no onValidate method in your class: "'+((l=i.constructor)==null?void 0:l.name)+'"');return}if(this[o]===void 0){this[o]=this[n];const c=this[n];if(c instanceof ee||c instanceof w||c instanceof tt||c instanceof Me){const u=this[n];HS(u,()=>{this.onValidate(n)})}Object.defineProperty(this,n,{set:function(u){var d;if(this[XC]===!0)this[o]=u;else{s?.call(this,u);const p=this[o];this[o]=u,(d=this.onValidate)==null||d.call(this,n,p)}},get:function(){return r?.call(this),this[o]}})}a.call(this)}}}const Oie=function(i){return function(e,t,s){let r="";typeof t=="string"?r=t:r=t.name;const n=i.prototype,o=Object.getOwnPropertyDescriptor(n,r);if(!(o!=null&&o.value)){console.warn("Can not apply prefix: type does not have method named",t,i);return}const a=o.value,l=e[r];Object.defineProperty(n,r,{value:function(...c){const u=l?.call(this,...c);if(u instanceof Promise){u.then(d=>{if(d!==!1)return a.call(this,...c)});return}if(u!==!1)return a.call(this,...c)}})}};var Lie=Object.defineProperty,Uie=Object.getOwnPropertyDescriptor,Eo=(i,e,t,s)=>{for(var r=s>1?void 0:s?Uie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Lie(e,t,r),r};class Fie{constructor(e,t){h(this,"positionChanged",!1),h(this,"rotationChanged",!1),h(this,"position"),h(this,"quaternion"),h(this,"_positionKeys",["x","y","z"]),h(this,"_quaternionKeys",["_x","_y","_z","_w"]),h(this,"mute",!1),h(this,"context"),h(this,"obj"),h(this,"_positionWatch"),h(this,"_rotationWatch"),this.context=t,this.obj=e}get isDirty(){return this.positionChanged||this.rotationChanged}reset(e=!1){if(this.positionChanged=!1,this.rotationChanged=!1,this.mute=!1,e){if(this.position)for(const t of this._positionKeys)delete this.position[t];if(this.quaternion)for(const t of this._quaternionKeys)delete this.quaternion[t]}}syncValues(){for(const e of this._positionKeys)this.position[e]=this.obj.position[e];for(const e of this._quaternionKeys)this.quaternion[e]=this.obj.quaternion[e]}applyValues(){if(this.positionChanged&&this.position)for(const e of this._positionKeys){const t=this.position[e];t!==void 0&&(this.obj.position[e]=t)}if(this.rotationChanged&&this.quaternion)for(const e of this._quaternionKeys){const t=this.quaternion[e];t!==void 0&&(this.obj.quaternion[e]=t)}}start(e,t){this.reset(),e&&(this._positionWatch||(this._positionWatch=new gc(this.obj.position,["x","y","z"])),this._positionWatch.apply(),this.position={},this._positionWatch.subscribeWrite((n,o)=>{var a;if((a=this.context.physics.engine)!=null&&a.isUpdating||this.mute)return;const l=this.position[o];Math.abs(l-n)<1e-5||(this.position[o]=n,this.positionChanged=!0)})),t&&(this._rotationWatch||(this._rotationWatch=new gc(this.obj.quaternion,["_x","_y","_z","_w"])),this._rotationWatch.apply(),this.quaternion={},this._rotationWatch.subscribeWrite((n,o)=>{var a;if((a=this.context.physics.engine)!=null&&a.isUpdating||this.mute)return;const l=this.quaternion[o];Math.abs(l-n)<1e-5||(this.quaternion[o]=n,this.rotationChanged=!0)}));const s=this.obj.matrixWorld.multiplyMatrices.bind(this.obj.matrixWorld),r=new Te;this.obj.matrixWorld.multiplyMatrices=(n,o)=>{var a;return(a=this.context.physics.engine)!=null&&a.isUpdating||this.mute||r.equals(n)||(this.positionChanged=!0,this.rotationChanged=!0,r.copy(n)),s(n,o)}}stop(){var e,t;(e=this._positionWatch)==null||e.revoke(),(t=this._rotationWatch)==null||t.revoke()}}var ST;const CT=(ST=class extends Pe{constructor(){super(...arguments),h(this,"autoMass",!0),h(this,"_mass",0),h(this,"useGravity",!0),h(this,"constraints",As.None),h(this,"isKinematic",!1),h(this,"drag",0),h(this,"angularDrag",1),h(this,"detectCollisions",!0),h(this,"sleepThreshold",.01),h(this,"collisionDetectionMode",v_.Discrete),h(this,"_gravityScale",1),h(this,"dominanceGroup",0),h(this,"_propertiesChanged",!1),h(this,"_currentVelocity",new w),h(this,"_smoothedVelocity",new w),h(this,"_smoothedVelocityGetter",new w),h(this,"_lastPosition",new w),h(this,"_watch")}set mass(i){i!==this._mass&&(this._mass=i,this._propertiesChanged=!0,this.__didAwake&&(this.autoMass=!1))}get mass(){var i,e;return this.autoMass?((e=(i=this.context.physics.engine)==null?void 0:i.getBody(this))==null?void 0:e.mass())??-1:this._mass}get lockPositionX(){return(this.constraints&As.FreezePositionX)!==0}get lockPositionY(){return(this.constraints&As.FreezePositionY)!==0}get lockPositionZ(){return(this.constraints&As.FreezePositionZ)!==0}get lockRotationX(){return(this.constraints&As.FreezeRotationX)!==0}get lockRotationY(){return(this.constraints&As.FreezeRotationY)!==0}get lockRotationZ(){return(this.constraints&As.FreezeRotationZ)!==0}set lockPositionX(i){i?this.constraints|=As.FreezePositionX:this.constraints&=~As.FreezePositionX}set lockPositionY(i){i?this.constraints|=As.FreezePositionY:this.constraints&=~As.FreezePositionY}set lockPositionZ(i){i?this.constraints|=As.FreezePositionZ:this.constraints&=~As.FreezePositionZ}set lockRotationX(i){i?this.constraints|=As.FreezeRotationX:this.constraints&=~As.FreezeRotationX}set lockRotationY(i){i?this.constraints|=As.FreezeRotationY:this.constraints&=~As.FreezeRotationY}set lockRotationZ(i){i?this.constraints|=As.FreezeRotationZ:this.constraints&=~As.FreezeRotationZ}set gravityScale(i){this._gravityScale=i}get gravityScale(){return this._gravityScale}awake(){this._watch=void 0,this._propertiesChanged=!1}onEnable(){this._watch||(this._watch=new Fie(this.gameObject,this.context)),this._watch.start(!0,!0),this.startCoroutine(this.beforePhysics(),Xs.LateUpdate)}onDisable(){var i,e;(i=this._watch)==null||i.stop(),(e=this.context.physics.engine)==null||e.removeBody(this)}onDestroy(){var i;(i=this.context.physics.engine)==null||i.removeBody(this)}onValidate(){this._propertiesChanged=!0}*beforePhysics(){for(var i,e,t,s;;)this._propertiesChanged&&(this._propertiesChanged=!1,(i=this.context.physics.engine)==null||i.updateProperties(this)),(e=this._watch)!=null&&e.isDirty?(this._watch.mute=!0,this._watch.applyValues(),(t=this.context.physics.engine)==null||t.updateBody(this,this._watch.positionChanged,this._watch.rotationChanged),this._watch.reset()):(s=this._watch)==null||s.syncValues(),this.captureVelocity(),yield}teleport(i,e=!0){var t;(t=this._watch)==null||t.reset(!0),e?this.gameObject.position.set(i.x,i.y,i.z):this.setWorldPosition(i.x,i.y,i.z),this.resetForcesAndTorques(),this.resetVelocities()}resetForces(i=!0){var e;(e=this.context.physics.engine)==null||e.resetForces(this,i)}resetTorques(i=!0){var e;(e=this.context.physics.engine)==null||e.resetTorques(this,i)}resetVelocities(){this.setVelocity(0,0,0),this.setAngularVelocity(0,0,0)}resetForcesAndTorques(){this.resetForces(),this.resetTorques()}wakeUp(){var i;(i=this.context.physics.engine)==null||i.wakeup(this)}applyForce(i,e,t=!0){var s;(s=this.context.physics.engine)==null||s.addForce(this,i,t)}applyImpulse(i,e=!0){var t;(t=this.context.physics.engine)==null||t.applyImpulse(this,i,e)}setForce(i,e,t,s=!0){var r,n,o;(r=this.context.physics.engine)==null||r.resetForces(this,s),typeof i=="number"?(e??(e=0),t??(t=0),(n=this.context.physics.engine)==null||n.addForce(this,{x:i,y:e,z:t},s)):(o=this.context.physics.engine)==null||o.addForce(this,i,s)}getVelocity(){var i;const e=(i=this.context.physics.engine)==null?void 0:i.getLinearVelocity(this);return e?(this._currentVelocity.x=e.x,this._currentVelocity.y=e.y,this._currentVelocity.z=e.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setVelocity(i,e,t,s=!0){var r,n;if(i instanceof w){const o=i;(r=this.context.physics.engine)==null||r.setLinearVelocity(this,o,s);return}e===void 0||t===void 0||(n=this.context.physics.engine)==null||n.setLinearVelocity(this,{x:i,y:e,z:t},s)}getAngularVelocity(){var i;const e=(i=this.context.physics.engine)==null?void 0:i.getAngularVelocity(this);return e?(this._currentVelocity.x=e.x,this._currentVelocity.y=e.y,this._currentVelocity.z=e.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setAngularVelocity(i,e,t,s=!0){var r,n;if(i instanceof w){const o=i;(r=this.context.physics.engine)==null||r.setAngularVelocity(this,o,s);return}e===void 0||t===void 0||(n=this.context.physics.engine)==null||n.setAngularVelocity(this,{x:i,y:e,z:t},s)}setTorque(i,e,t){this.setAngularVelocity(i,e,t)}get smoothedVelocity(){return this._smoothedVelocityGetter.copy(this._smoothedVelocity),this._smoothedVelocityGetter.multiplyScalar(1/this.context.time.deltaTime)}setBodyFromGameObject(i=null){}captureVelocity(){const i=ft(this.gameObject);CT.tempPosition.copy(i);const e=i.sub(this._lastPosition);this._lastPosition.copy(CT.tempPosition),this._smoothedVelocity.lerp(e,this.context.time.deltaTime/.1)}},h(ST,"tempPosition",new w),ST);let Ii=CT;Eo([fr()],Ii.prototype,"autoMass",2),Eo([x()],Ii.prototype,"mass",1),Eo([fr(),x()],Ii.prototype,"useGravity",2),Eo([fr(),x()],Ii.prototype,"constraints",2),Eo([fr(),x()],Ii.prototype,"isKinematic",2),Eo([fr(),x()],Ii.prototype,"drag",2),Eo([fr(),x()],Ii.prototype,"angularDrag",2),Eo([fr(),x()],Ii.prototype,"detectCollisions",2),Eo([fr(),x()],Ii.prototype,"sleepThreshold",2),Eo([fr(),x()],Ii.prototype,"collisionDetectionMode",2),Eo([fr()],Ii.prototype,"_gravityScale",2),Eo([fr()],Ii.prototype,"dominanceGroup",2);class Wn{constructor(){h(this,"bb",null),h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}static sizeOf(){return 12}static createVec3(e,t,s,r){return e.prep(4,12),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(t),e.offset()}}class J3{constructor(){h(this,"bb",null),h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}position(e){return(e||new Wn).__init(this.bb_pos,this.bb)}rotation(e){return(e||new Wn).__init(this.bb_pos+12,this.bb)}scale(e){return(e||new Wn).__init(this.bb_pos+24,this.bb)}static sizeOf(){return 36}static createTransform(e,t,s,r,n,o,a,l,c,u){return e.prep(4,36),e.prep(4,12),e.writeFloat32(u),e.writeFloat32(c),e.writeFloat32(l),e.prep(4,12),e.writeFloat32(a),e.writeFloat32(o),e.writeFloat32(n),e.prep(4,12),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(t),e.offset()}}class Ac{constructor(){h(this,"bb",null),h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsSyncedTransformModel(e,t){return(t||new Ac).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSyncedTransformModel(e,t){return e.setPosition(e.position()+m0),(t||new Ac).__init(e.readInt32(e.position())+e.position(),e)}guid(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}fast(){const e=this.bb.__offset(this.bb_pos,6);return e?!!this.bb.readInt8(this.bb_pos+e):!1}transform(e){const t=this.bb.__offset(this.bb_pos,8);return t?(e||new J3).__init(this.bb_pos+t,this.bb):null}dontSave(){const e=this.bb.__offset(this.bb_pos,10);return e?!!this.bb.readInt8(this.bb_pos+e):!1}static startSyncedTransformModel(e){e.startObject(4)}static addGuid(e,t){e.addFieldOffset(0,t,0)}static addFast(e,t){e.addFieldInt8(1,+t,0)}static addTransform(e,t){e.addFieldStruct(2,t,0)}static addDontSave(e,t){e.addFieldInt8(3,+t,0)}static endSyncedTransformModel(e){return e.endObject()}static finishSyncedTransformModelBuffer(e,t){e.finish(t)}static finishSizePrefixedSyncedTransformModelBuffer(e,t){e.finish(t,void 0,!0)}}const ch=oe("debugsync"),Yg="STRS";v0(Yg,Ac.getRootAsSyncedTransformModel);const Na=new jf;function Z3(i,e,t=!0){Na.clear();const s=Na.createString(i);Ac.startSyncedTransformModel(Na),Ac.addGuid(Na,s),Ac.addFast(Na,t);const r=e.worldPosition,n=e.worldEuler,o=e.gameObject.scale;Ac.addTransform(Na,J3.createTransform(Na,r.x,r.y,r.z,n.x,n.y,n.z,o.x,o.y,o.z));const a=Ac.endSyncedTransformModel(Na);return Na.finish(a,Yg),Na.asUint8Array()}class hh extends Pe{constructor(){super(...arguments),h(this,"overridePhysics",!0),h(this,"interpolatePosition",!0),h(this,"interpolateRotation",!0),h(this,"fastMode",!1),h(this,"syncDestroy",!1),h(this,"_model",null),h(this,"_needsUpdate",!0),h(this,"rb",null),h(this,"_wasKinematic",!1),h(this,"_receivedDataBefore",!1),h(this,"_targetPosition"),h(this,"_targetRotation"),h(this,"_receivedFastUpdate",!1),h(this,"_shouldRequestOwnership",!1),h(this,"joinedRoomCallback",null),h(this,"receivedDataCallback",null),h(this,"tempEuler",new zs),h(this,"receivedUpdate",!1),h(this,"lastWorldPos"),h(this,"lastWorldRotation")}requestOwnership(){ch&&console.log("Request ownership"),this._model?this._model.requestOwnership():(this._shouldRequestOwnership=!0,this._needsUpdate=!0)}hasOwnership(){var e;return((e=this._model)==null?void 0:e.hasOwnership)??void 0}isOwned(){var e;return(e=this._model)==null?void 0:e.isOwned}awake(){ch&&console.log("new instance",this.guid,this),this._receivedDataBefore=!1,this._targetPosition=new w,this._targetRotation=new Me,this.lastWorldPos=new w,this.lastWorldRotation=new Me,this.rb=te.getComponentInChildren(this.gameObject,Ii),this.rb&&(this._wasKinematic=this.rb.isKinematic),this.receivedUpdate=!0,this._model=new I0(this.context.connection,this.guid),this.context.connection.isConnected&&this.tryGetLastState(),this.joinedRoomCallback=this.tryGetLastState.bind(this),this.context.connection.beginListen(Di.JoinedRoom,this.joinedRoomCallback),this.receivedDataCallback=this.onReceivedData.bind(this),this.context.connection.beginListenBinary(Yg,this.receivedDataCallback)}onDestroy(){this.syncDestroy&&OO(this.guid,this.context.connection),this._model=null,this.context.connection.stopListen(Di.JoinedRoom,this.joinedRoomCallback),this.context.connection.stopListenBinary(Yg,this.receivedDataCallback)}tryGetLastState(){const e=this.context.connection.tryGetState(this.guid);e&&this.onReceivedData(e)}onReceivedData(e){var t;if(!this.destroyed&&typeof e.guid=="function"&&e.guid()===this.guid){ch&&console.log("new data",this.context.connection.connectionId,this.context.time.frameCount,this.guid,e),this.receivedUpdate=!0,this._receivedFastUpdate=e.fast();const s=e.transform();if(s){Gr.markDirty(this.gameObject,!0);const r=s.position();r&&(this.interpolatePosition&&((t=this._targetPosition)==null||t.set(r.x(),r.y(),r.z())),(!this.interpolatePosition||!this._receivedDataBefore)&&this.setWorldPosition(r.x(),r.y(),r.z()));const n=s.rotation();n&&(this.tempEuler.set(n.x(),n.y(),n.z()),this.interpolateRotation&&this._targetRotation.setFromEuler(this.tempEuler),(!this.interpolateRotation||!this._receivedDataBefore)&&hC(this.gameObject,this.tempEuler))}this._receivedDataBefore=!0}}onEnable(){this.lastWorldPos.copy(this.worldPosition),this.lastWorldRotation.copy(this.worldQuaternion),this._needsUpdate=!0,this._model&&this._model.updateIsOwned()}onDisable(){this._model&&this._model.freeOwnership()}onBeforeRender(){if(!this.activeAndEnabled||!this.context.connection.isConnected)return;if(!this.context.connection.isInRoom||!this._model){ch&&console.log("no model or room",this.name,this.guid,this.context.connection.isInRoom);return}this._shouldRequestOwnership&&(this._shouldRequestOwnership=!1,this._model.requestOwnership());const e=this.worldPosition,t=this.worldQuaternion;if(this._model.isOwned&&!this.receivedUpdate){const n=e.distanceTo(this.lastWorldPos),o=t.angleTo(this.lastWorldRotation),a=this._model.hasOwnership||this.fastMode?1e-4:.001;(n>a||o>a)&&(this._model.hasOwnership?this._needsUpdate=!0:(ch&&console.log(this.guid,"reset because not owned but",this.gameObject.name,this.lastWorldPos),this.worldPosition=this.lastWorldPos,e.copy(this.lastWorldPos),this.worldQuaternion=this.lastWorldRotation,t.copy(this.lastWorldRotation),Gr.markDirty(this.gameObject,!0),this._needsUpdate=!1))}if(this._model&&!this._model.hasOwnership&&this._model.isOwned&&this._receivedDataBefore){const n=this._receivedFastUpdate||this.fastMode?.5:.3;let o=!1;if(this.interpolatePosition&&this._targetPosition){const a=this.worldPosition;a.lerp(this._targetPosition,n),this.worldPosition=a,o=!0}if(this.interpolateRotation&&this._targetRotation){const a=this.worldQuaternion;a.slerp(this._targetRotation,n),this.worldQuaternion=a,o=!0}o&&Gr.markDirty(this.gameObject,!0)}if(this.receivedUpdate=!1,this.lastWorldPos.copy(e),this.lastWorldRotation.copy(t),!this._model)return;if(!this._model||this._model.hasOwnership===void 0||!this._model.hasOwnership){this.rb&&(this.rb.isKinematic=this._model.isOwned??!1,this.rb.setVelocity(0,0,0));return}this.rb&&(this._wasKinematic!==void 0&&(ch&&console.log("reset kinematic",this.rb.name,this._wasKinematic),this.rb.isKinematic=this._wasKinematic),this.gameObject.position.distanceTo(new w(0,0,0))>1e3&&(ch&&console.log("RESET",this.name),this.gameObject.position.set(0,1,0),this.rb.setVelocity(0,0,0)));const s=10,r=this.rb||this.fastMode;if(this._needsUpdate&&(this.context.time.frameCount%s===0||r)){ch&&console.log("send update",this.context.connection.connectionId,this.guid,this.gameObject.name,this.gameObject.guid),this.overridePhysics&&this.rb,this._needsUpdate=!1;const n=Z3(this.guid,this,!!r);this.context.connection.sendBinary(n)}}}const Nie=oe("debugshadowcomponents");iT.prototype.interactable={get(){return this.interactive},set(i){this.interactable=i}};const Mo=Symbol("shadowDomOwner");class Aa extends Pe{constructor(){super(...arguments),h(this,"shadowComponent",null),h(this,"_controlsChildLayout",!0),h(this,"_root"),h(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(){Xn.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=te.getComponentInParent(this.gameObject,Kg)),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 s;this.removeShadowComponent();const r=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=te.getComponentInParent(r,Aa),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}e.name=this.name+" ("+(this.constructor.name??"UI")+")",e.autoLayout=this._parentComponent.controlsChildLayout,e[Mo]=this,this.setShadowComponentOwner(e);let n=!1;if(((s=this.Root)==null?void 0:s.gameObject)===this.gameObject)this.gameObject.add(e);else{const o=this._parentComponent.shadowComponent;o&&(o?.add(e),n=!0)}this.shadowComponent=e,t&&t.shadowComponent&&this.shadowComponent&&t.shadowComponent.add(this.shadowComponent),lg&&e.add(new ep(.5)),this.onAfterAddedToScene(),n&&l3(),Nie&&console.log(this.shadowComponent)}set(e){}setShadowComponentOwner(e){if(e&&(e[Mo]===void 0||e[Mo]===this)&&(e[Mo]=this,e.children))for(const t of e.children)this.setShadowComponentOwner(t)}traverseOwnedShadowComponents(e,t,s){if(e&&e[Mo]===t){s(e);for(const r of e.children)this.traverseOwnedShadowComponents(r,t,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(e){this.shadowComponent&&(this.shadowComponent.interactable=e)}}class Kg extends Aa{awake(){super.awake()}}class Wp{static getObject(e){const t=e[Mo];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const s=this.tryFindCanvasGroup(e);if(s?.isCanvasGroup===!0&&(t&&(t.canvasGroup=s),s.blocksRaycasts===!1||s.interactable===!1))return!1;const r=bu(e,n=>{if(n.isGraphic===!0)return n},!1);return t&&r?.isGraphic===!0&&(t.graphic=r),!(r?.raycastTarget===!1||r?.layer===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=bu(e,s=>{const r=s;if(r.blocksRaycasts!==void 0&&r.interactable!==void 0)return r},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}const Jg=oe("debugwebxrcontroller");var Xp=(i=>(i[i.PhysicalDevice=0]="PhysicalDevice",i[i.Touch=1]="Touch",i))(Xp||{}),Kl=(i=>(i.SelectStart="select-start",i.SelectEnd="select-end",i.Update="update",i))(Kl||{});class A_ extends Pe{}const mr=class extends Pe{constructor(){super(...arguments),h(this,"webXR"),h(this,"index",-1),h(this,"controllerModel"),h(this,"controller"),h(this,"controllerGrip"),h(this,"hand"),h(this,"handPointerModel"),h(this,"grabbed",null),h(this,"input",null),h(this,"type",0),h(this,"showRaycastLine",!0),h(this,"enableRaycasts",!0),h(this,"enableDefaultControls",!0),h(this,"_wristQuaternion",null),h(this,"movementVector",new w),h(this,"worldRot",new Me),h(this,"joystick",new ee),h(this,"didRotate",!1),h(this,"didTeleport",!1),h(this,"didChangeScale",!1),h(this,"lastHit",null),h(this,"raycastLine",null),h(this,"_raycastHitPoint",null),h(this,"_connnectedCallback",null),h(this,"_disconnectedCallback",null),h(this,"_selectStartEvt",null),h(this,"_selectEndEvt",null),h(this,"_selectionPressed",!1),h(this,"_selectionPressedLastFrame",!1),h(this,"_selectionStartTime",0),h(this,"_selectionEndTime",0),h(this,"_useSmoothing",!0),h(this,"_isConnected",!1),h(this,"rayRotation",new Me),h(this,"_pinchStartTime"),h(this,"selectStartCallback",null),h(this,"lastSelectStartObject",null),h(this,"_didNotEndSelection",!1),h(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const i=new ls(this.geometry),e=i.material;return e.color=this.raycastColor,i.layers.set(2),i.name="line",i.scale.z=1,i}static CreateRaycastHitPoint(){const i=new Fo(.5,22,22),e=new li({color:this.raycastColor}),t=new ge(i,e);return t.visible=!1,t.layers.set(2),t}static Create(i,e,t,s){const r=t?te.addNewComponent(t,mr,!1):new mr;r.webXR=i,r.index=e,r.type=s;const n=i.context;r.controller=n.renderer.xr.getController(e),r.controllerGrip=n.renderer.xr.getControllerGrip(e),r.controllerModel=this.Factory.createControllerModel(r.controller),r.controllerGrip.add(r.controllerModel),r.hand=n.renderer.xr.getHand(e);const o=new yp;Tg(o,n),r.webXR.handModelPath&&r.webXR.handModelPath!==""?o.setPath(bl(i.sourceId,r.webXR.handModelPath)):o.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const a=new hie(r.hand,o);return r.hand.add(a),r.hand.traverse(l=>l.layers.set(2)),r.handPointerModel=new vie(r.hand,r.controller),r.controller.addEventListener("connected",l=>{r.setControllerLayers(r.controllerModel,2),r.setControllerLayers(r.controllerGrip,2),r.setControllerLayers(r.hand,2),setTimeout(()=>{r.setControllerLayers(r.controllerModel,2),r.setControllerLayers(r.controllerGrip,2),r.setControllerLayers(r.hand,2)},1e3)}),r.hand.addEventListener("connected",l=>{var c;if(l.data.hand){i.Rig&&i.Rig.add(r.hand),r.type=0,r.handPointerModel.traverse(d=>d.layers.set(2)),(c=r.handPointerModel.pointerObject)==null||c.traverse(d=>d.layers.set(2));const u=r.hand.joints;if(u)for(const d of Object.keys(u)){const p=u[d];p.parent||r.hand.add(p)}}}),r}static addEventListener(i,e){const t=this.eventSubs[i]??[];t.push(e),this.eventSubs[i]=t}static removeEventListener(i,e){if(!e)return;const t=this.eventSubs[i]??[],s=t.indexOf(e);s>=0&&t.splice(s,1),this.eventSubs[i]=t}get isUsingHands(){var i;return((i=this.input)==null?void 0:i.hand)!=null}get wrist(){if(!this.hand)return null;const i=this.hand.joints;return i?i.wrist:null}getWristQuaternion(){const i=this.wrist;return i?(this._wristQuaternion||(this._wristQuaternion=new Me),wi(i).multiply(this._wristQuaternion.setFromEuler(new zs(-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 i,e,t;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)),(i=this.hand)==null||i.clear(),(e=this.controllerGrip)==null||e.clear(),(t=this.controller)==null||t.clear()}onEnable(){var i,e,t,s,r;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=mr.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=mr.CreateRaycastHitPoint()),(i=this.webXR.Rig)==null||i.add(this.hand),(e=this.webXR.Rig)==null||e.add(this.controllerGrip),(t=this.webXR.Rig)==null||t.add(this.controller),(s=this.webXR.Rig)==null||s.add(this.raycastLine),(r=this.raycastLine)==null||r.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),Jg&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var i,e,t,s,r;if((i=this.hand)==null||i.removeFromParent(),(e=this.controllerGrip)==null||e.removeFromParent(),(t=this.controller)==null||t.removeFromParent(),(s=this.raycastLine)==null||s.removeFromParent(),(r=this._raycastHitPoint)==null||r.removeFromParent(),this.webXR){const n=this.webXR.Controllers.indexOf(this);n>=0&&this.webXR.Controllers.splice(n,1)}}onSourceConnected(i){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,i);return}this._isConnected=!0,this.input=i.data,this.type===1&&this.onSelectStart()}onSourceDisconnected(i){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",i);return}this._isConnected=!1,this.type===1&&this.onSelectEnd(),this.input=null}createPointerEvent(i){switch(i){case"down":this.context.input.createPointerDown(new Sl(us.PointerDown,null,{clientX:0,clientY:0,button:this.index,pointerType:rp.Touch}));break;case"move":break;case"up":this.context.input.createPointerUp(new Sl(us.PointerUp,null,{clientX:0,clientY:0,button:this.index,pointerType:rp.Touch}));break}}raycastUpdate(i,e){const t=this.showRaycastLine&&this.type!==1;if(this.type===1)i.visible=!1;else if(this.isUsingHands){i.visible=!this.grabbed&&t,ds(i,e);const s=this.hand.joints;if(s&&s.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const r=this.getWristQuaternion();r&&this.rayRotation.copy(r)}Zr(i,this.rayRotation)}else i.visible=t,Zr(i,this.rayRotation),ds(i,e)}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 i=mr.eventSubs.update;if(i&&i.length>0)for(const s of i)s(this);let e=1;this.type===0?e=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(e=this.context.time.deltaTime/.3),this.rayRotation.slerp(wi(this.controller),this.useSmoothing?e:1);const t=ft(this.controller);this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.enableRaycasts?(this.raycastLine&&this.raycastUpdate(this.raycastLine,t),this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update()):this.raycastLine&&(this.raycastLine.visible=!1),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(i){var e,t;if(this.lastHit=null,!i||i.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=i.inputSources[this.index]),!this.input)return;const s=this.webXR.Rig;if(!s)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const r=(t=(e=this.input)==null?void 0:e.gamepad)==null?void 0:t.buttons;if(this.enableDefaultControls)switch(this.input.handedness){case"left":this.movementUpdate(s,r);break;case"right":this.rotationUpdate(s,r);break}}movementUpdate(i,e){const t=3*mr.MovementSpeedFactor,s=2,r=rt.clamp01(this.joystick.length()*2),n=this.joystick.x>0?1:-1;let o=Math.pow(this.joystick.x,s);o*=n,o*=r;const a=this.joystick.y>0?1:-1;let l=Math.pow(this.joystick.y,s);l*=a,o*=r,i.getWorldQuaternion(this.worldRot),this.movementVector.set(o,0,l),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(t*this.context.time.deltaTime),i.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(i,e)}rotationUpdate(i,e){const t=this.joystick.x,s=Math.abs(t);if(s<.4)this.didRotate=!1;else if(s>.5&&!this.didRotate){const r=t>0?-1:1;i.rotateY(rt.toRadians(30*r)),this.didRotate=!0}this.runTeleport(i,e)}runTeleport(i,e){var t,s;let r=-this.joystick.y;if((t=this.hand)!=null&&t.visible&&!this.grabbed){const u=this.handPointerModel.isPinched();u&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),u&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(r=this.handPointerModel.isPinched()?1:0),u||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;const n=this.webXR.IsInVR,o=this.webXR.Rig;let a=r>.5&&n,l=o?((s=o?.scale)==null?void 0:s.x)<.999:!1,c=null;if(e&&this.input&&!this.input.hand)for(let u=0;u<e.length;u++){const d=e[u];if(u===4)if(d.pressed&&!this.didChangeScale&&n){this.didChangeScale=!0;const p=o;if(p){const f=this.switchScale(p,a,l,c);a=f.doTeleport,l=f.isInMiniatureMode,c=f.newRigScale}}else d.pressed||(this.didChangeScale=!1)}if(a){if(!this.didTeleport){const u=this.raycast();if(this.didTeleport=!0,u&&u.length>0){const d=u[0];if(l||this.isValidTeleportTarget(d.object)){const p=d.point;ds(i,p)}}}}else r<.1&&(this.didTeleport=!1);c!==null&&(i.scale.set(c,c,c),i.updateMatrixWorld())}isValidTeleportTarget(i){return te.getComponentInParent(i,A_)!=null}switchScale(i,e,t,s){if(t){t=!1,i.scale.set(1,1,1),s=1,mr.MovementSpeedFactor=1;const r=this.context.mainCamera;mr.PreviousCameraFarDistance&&(r.far=mr.PreviousCameraFarDistance)}else{t=!0,e=!0,s=.1,mr.MovementSpeedFactor=s*2;const r=this.context.mainCamera;mr.PreviousCameraFarDistance=r.far,r.far/=s}return{doTeleport:e,isInMiniatureMode:t,newRigScale:s}}updateStick(i){var e;!i||!i.gamepad||((e=i.gamepad.axes)==null?void 0:e.length)<4||(this.joystick.x=i.gamepad.axes[2],this.joystick.y=i.gamepad.axes[3])}updateLastHit(){var i;const e=this.raycast(),t=e?e[0]:null;this.lastHit=t;let s=1;if(this.webXR.Rig&&(s/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=s*(((i=this.lastHit)==null?void 0:i.distance)??9999);const r=this.raycastLine.material;t!=null?r.color=mr.raycastColor:r.color=mr.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const r=rt.clamp(this.lastHit.distance*.01*s,.015,.1);this._raycastHitPoint.scale.set(r,r,r)}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 i=null,e=!1;if(this.isUsingHands?(i=this.overlap(),i.length<=0?(i=this.raycast(),e=!1):e=!0):i=this.raycast(),Jg&&console.log("onHandleSelectStart","close grab? "+e,"intersections",i),i&&i.length>0)for(const t of i){const s=t.object;this.lastSelectStartObject=s;const r={selected:s,grab:s},n=mr.eventSubs["select-start"];if(n&&n.length>0)for(const o of n)o(this,r);r.grab!==s&&Jg&&console.log("Grabbed object changed","original",s,"new",r.grab),r.grab&&(this.grabbed=za.TryTake(this,r.grab,t,e));break}else{const t=mr.eventSubs["select-start"],s={selected:null,grab:null};if(t&&t.length>0)for(const r of t)r(this,s)}}onSelectEnd(){var i;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:((i=this.grabbed)==null?void 0:i.selected)??this.lastSelectStartObject},t=mr.eventSubs["select-end"];if(t&&t.length>0)for(const s of t)s(this,e);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(i){return!(!i||te.isActiveInHierarchy(i)===!1||Wp.isInteractable(i)===!1)}setControllerLayers(i,e){var t,s;if(i&&(i.layers.set(e),i.children))for(const r of i.children)((t=this.grabbed)==null?void 0:t.selected)===r||((s=this.grabbed)==null?void 0:s.selectedMesh)===r||this.setControllerLayers(r,e)}getRay(){const i=new Qo;return i.origin.copy(ft(this.controller)),i.direction.set(0,0,-1).applyQuaternion(this.rayRotation),i}overlap(){const i=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(Jg&&(!this.closeGrabBoundingBoxHelper&&i&&(this.closeGrabBoundingBoxHelper=new s0(i,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&i&&this.closeGrabBoundingBoxHelper.setFromObject(i)),!i)return new Array;const e=ft(i).clone();return this.context.physics.sphereOverlap(e,.02)}raycast(){const i=new Nn;i.layerMask=new Pr,i.layerMask.enableAll(),i.layerMask.disable(2),i.ray=this.getRay();const e=this.context.physics.raycast(i);for(let t=0;t<e.length;t++){const s=e[t],r=s.object;if(!this.testIsVisible(r)){e.splice(t,1),t--;continue}s.object=Wp.getObject(r);break}return e}};let Ms=mr;h(Ms,"Factory",new Iie),h(Ms,"raycastColor",new ye(.9,.3,.3)),h(Ms,"raycastNoHitColor",new ye(.6,.6,.6)),h(Ms,"geometry",new gt().setFromPoints([new w(0,0,0),new w(0,0,-1)])),h(Ms,"handModels",{}),h(Ms,"eventSubs",{}),h(Ms,"PreviousCameraFarDistance"),h(Ms,"MovementSpeedFactor",1);var y_=(i=>(i.WillTake="WillTake",i.DidTake="DidTake",i.WillFree="WillFree",i.DidFree="DidFree",i))(y_||{});const xn=class{constructor(){h(this,"sync",null),h(this,"selected",null),h(this,"selectedParent",null),h(this,"selectedMesh",null),h(this,"controller",null),h(this,"grabTime",0),h(this,"grabUUID",""),h(this,"isCloseGrab",!1),h(this,"originalMaterial",null),h(this,"usageMarker",null),h(this,"rigidbodies",null),h(this,"didReparent",!1),h(this,"grabDistance",0),h(this,"interactable",null),h(this,"positionSource",null),h(this,"grabPoint",new w),h(this,"localPositionOffsetToGrab",null),h(this,"localPositionOffsetToGrab_worldSpace",new w),h(this,"localQuaternionToGrab",new Me(0,0,0,1)),h(this,"targetDir",null),h(this,"quaternionLerp",null),h(this,"controllerDir",new w),h(this,"controllerWorldPos",new w),h(this,"lastControllerWorldPos",new w),h(this,"controllerPosDelta",new w),h(this,"totalChangeAlongDirection",0),h(this,"rigPositionLastFrame",new w)}static AddEventListener(i,e){return xn.Events[i]||(xn.Events[i]=[]),xn.Events[i].push(e),e}static RemoveEventListener(i,e){if(!e||!xn.Events[i])return;const t=xn.Events[i].indexOf(e);t>=0&&xn.Events[i].splice(t,1)}static Register(i){this.Current.find(e=>e===i)||this.Current.push(i)}static Remove(i){const e=this.Current.indexOf(i);e>=0&&this.Current.splice(e,1)}static TryTake(i,e,t,s){const r=te.getComponentInParent(e,Qp);if(r)e=r.gameObject;else return Jg&&console.warn("Prevented taking object that is not interactable",e),null;let n=e;const o=te.getComponentInParent(e,hh);o&&(o.requestOwnership(),n=o.gameObject);for(const l of this.Current)if(l.selected===n)return l.controller===i||(l.free(),l.Take(i,n,e,o,r,t,s)),l;const a=new xn;return a.Take(i,n,e,o,r,t,s),a}Take(i,e,t,s,r,n,o){var a,l;if(console.assert(e!==null,"Expected object to be taken but was",e),i.isUsingHands?this.positionSource=o?i.wrist:i.controller:this.positionSource=i.controller,!this.positionSource)return console.warn("No position source"),this;const c={controller:i,take:e,hit:t,sync:s,interactable:r};(a=xn.Events.WillTake)==null||a.forEach(m=>m(this,c));const u=t;u!=null&&u.material&&(this.originalMaterial=u.material,Array.isArray(u.material)||(u.material=u.material.clone(),u.material&&u.material.emissive&&(u.material.emissive.b=.2))),this.selected=e,this.selectedParent||(this.selectedParent=e.parent),this.selectedMesh=u,this.controller=i,this.interactable=r,this.isCloseGrab=o,this.didReparent=!1,this.sync=s,this.grabTime=i.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=te.addNewComponent(this.selected,Vp),this.rigidbodies=te.getComponentsInChildren(this.selected,Ii),ft(this.positionSource,this.lastControllerWorldPos);const d=()=>o?this.lastControllerWorldPos.clone():n.point.clone();this.grabDistance=d().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(d());const p=i.isUsingHands&&o?this.controller.getWristQuaternion().clone():i.rayRotation.clone();wi(this.selected,this.localQuaternionToGrab).premultiply(p.invert());const f=this.controller.webXR.Rig;return f&&this.rigPositionLastFrame.copy(ft(f)),an.Add(i.context,this.selected),xn.Register(this),this.sync&&(this.sync.fastMode=!0),(l=xn.Events.DidTake)==null||l.forEach(m=>m(this,c)),this}free(){var i,e,t,s;if(!this.selected)return;const r={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(i=xn.Events.WillFree)==null||i.forEach(a=>a(this,r)),an.Remove(this.controller.context,this.selected),xn.Remove(this),this.sync&&(this.sync.fastMode=!1);const n=this.selectedMesh;n&&this.originalMaterial&&n.material&&(n.material=this.originalMaterial);const o=this.selected;if(this.didReparent&&o.parent){const a=this.selectedParent;a?a.attach(o):(e=this.controller)==null||e.context.scene.attach(o)}if((t=this.usageMarker)==null||t.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const a of this.rigidbodies)a.wakeUp(),a.setVelocity(a.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(s=xn.Events.DidFree)==null||s.forEach(a=>a(this,r))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),ft(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const i=this.controller.webXR.Rig;if(i){const e=ft(i),t=this.rigPositionLastFrame.sub(e);this.controllerPosDelta.add(t),this.rigPositionLastFrame.copy(e)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var i;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=((i=this.controller.webXR.Rig)==null?void 0:i.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 s=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),r=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=r.clone()),this.quaternionLerp.slerp(r,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),Zr(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(s),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(ft(this.selected)),s.sub(this.localPositionOffsetToGrab_worldSpace)),ds(this.selected,s)}if(this.rigidbodies!=null)for(const e of this.rigidbodies)e.wakeUp();Gr.markDirty(this.selected,!0)}}};let za=xn;h(za,"Events",{}),h(za,"Current",[]);class vc{constructor(e,t){h(this,"used",!1),h(this,"inputSource"),h(this,"object"),h(this,"point"),h(this,"normal"),h(this,"face"),h(this,"distance"),h(this,"instanceId"),h(this,"pointerId"),h(this,"isDown"),h(this,"isUp"),h(this,"isPressed"),h(this,"isClicked"),h(this,"button"),h(this,"input"),h(this,"_event"),this._event=t,this.input=e,this.button=t?.button??0}use(){this.used=!0,this.pointerId!==void 0&&this.input.setPointerUsed(this.pointerId)}stopPropagation(){var e;(e=this._event)==null||e.stopImmediatePropagation()}Use(){this.use()}StopPropagation(){var e;(e=this._event)==null||e.stopImmediatePropagation()}get event(){return this._event}clone(){const e=new vc(this.input,this._event);return Object.assign(e,this),e}}function ET(i){return te.foreachComponent(i,e=>{const t=e;if(t.onPointerDown||t.onPointerUp||t.onPointerEnter||t.onPointerExit||t.onPointerClick)return!0},!1)===!0}var zie=Object.defineProperty,jie=Object.getOwnPropertyDescriptor,Gie=(i,e,t,s)=>{for(var r=s>1?void 0:s?jie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&zie(e,t,r),r};class uh extends Pe{awake(){Xn.createIfNoneExists(this.context)}onEnable(){var e;(e=Xn.get(this.context))==null||e.register(this)}onDisable(){var e;(e=Xn.get(this.context))==null||e.unregister(this)}performRaycast(e=null){return null}}class ua extends uh{constructor(){super(...arguments),h(this,"targets",null),h(this,"raycastHits",[]),h(this,"ignoreSkinnedMeshes",!1)}start(){this.targets=[this.gameObject]}performRaycast(e=null){if(!this.targets)return null;e??(e=new Nn),e.targets=this.targets,e.results=this.raycastHits;const t=e.testObject;this.ignoreSkinnedMeshes&&(e.testObject=r=>r instanceof Xo?"continue in children":t?t(r):!0);const s=this.context.physics.raycast(e);return e.testObject=t,s}}Gie([x()],ua.prototype,"ignoreSkinnedMeshes",2);class b_ extends ua{constructor(){super(),this.ignoreSkinnedMeshes=!0}}function __(i){return i[Mo]||(i.parent?__(i.parent):null)}function Qie(i){return i.isUI===!0||typeof i[Mo]=="object"}function x_(i,e){if(!i)return;const t=i.material;if(t?.isMaterial===!0){const s=i.parent;s&&s.isText,t.side=e.doubleSided??!0?Ai:Tr,t.shadowSide=e.doubleSided?Ai:Tr,i.castShadow=e.castShadows?e.castShadows:!1,i.receiveShadow=e.receiveShadows?e.receiveShadows:!1}for(const s of i.children)x_(s,e)}function qp(i,e,t){i[e]===void 0&&console.warn("Field",e,"is undefined on",i);const s=Proxy.revocable(i[e],{set(o,a,l,c){const u=o[a],d=Reflect.set(o,a,l,c);return t(l,u),d}}),r=s.revoke,n=i[e];return s.revoke=()=>{i[e]=n,r()},i[e]=s.proxy,s}const $3=Symbol("Scheduled action");function Vie(i,e,t=Xs.OnBeforeRender){let s=i[$3];s||(s=i[$3]={});const r=e.name;s[t]||(s[t]={});const n=s[t];if(n[r])return;function*o(){e?.call(i),n[r]=null}const a=i.startCoroutine(o(),t);n[r]=a}const Du=oe("debugeventsystem");var MT=(i=>(i.BeforeHandleInput="BeforeHandleInput",i.AfterHandleInput="AfterHandleInput",i))(MT||{});const Jl=class extends Pe{constructor(){super(),h(this,"raycaster",[]),h(this,"_selectStartFn"),h(this,"_selectEndFn"),h(this,"_selectUpdateFn"),h(this,"_handleEventCycleFn"),h(this,"_handleInputFn"),h(this,"pressedByID",new Map),h(this,"hoveredByID",new Map),h(this,"_sortedHits",[]),h(this,"_testObjectsCache",new Map),h(this,"shouldRaycastObject",i=>{var e;let t=null;if(Qie(i)&&(t=(e=i[Mo])==null?void 0:e.gameObject),this._testObjectsCache.has(i)||t&&this._testObjectsCache.has(t))return this._testObjectsCache.get(i)===!1?"continue in children":!0;{let s=ET(i);return!s&&t&&(s=ET(t)),s?(this._testObjectsCache.set(i,!0),i.traverse(r=>{this._testObjectsCache.set(r,!0)}),!0):(this._testObjectsCache.set(i,!1),"continue in children")}}),h(this,"_sortingBuffer",[]),h(this,"_noDepthTestingResults",[]),h(this,"out",{}),h(this,"currentActiveMeshUIComponents",[]),Jl.systems.push(this)}static createIfNoneExists(i){this.didSearchEventSystem||(this.didSearchEventSystem=!0,Jl.systems.length<=0&&Jl.systems.push(...te.findObjectsOfType(Jl,i)));for(const t of Jl.systems)if(t.context===i)return;const e=new _e;te.addNewComponent(e,Jl),i.scene.add(e)}static get systems(){const i=Ot.Current;return this._eventSystemMap.has(i)||this._eventSystemMap.set(i,[]),this._eventSystemMap.get(i)}static get(i){const e=this._eventSystemMap.get(i);return e&&e.length>0?e[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(i,e,t=!1){Zl.update(i,e,t)}static markUIDirty(i){Zl.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.hoveredByID.size>0}onDestroy(){Jl.systems.splice(Jl.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!te.findObjectOfType(uh,this.context)){const i=te.addNewComponent(this.context.scene,ua);i.ignoreSkinnedMeshes=!0,this.raycaster.push(i),(zt()||Du)&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found. Skinnedmeshes will be ignored for better performance")}}register(i){var e;i&&this.raycaster&&!this.raycaster.includes(i)&&((e=this.raycaster)==null||e.push(i))}unregister(i){var e,t;const s=(e=this.raycaster)==null?void 0:e.indexOf(i);s!==void 0&&s!==-1&&((t=this.raycaster)==null||t.splice(s,1))}onEnable(){const i=new Map;this._selectStartFn??(this._selectStartFn=(t,s)=>{if(!s.grab)return;Zl.resetLastSelected();const r=new vc(this.context.input);r.inputSource=t,r.pointerId=0,r.isDown=t.selectionDown,r.isUp=t.selectionUp,r.isPressed=t.selectionPressed,r.isClicked=!1,i.set(t,s.grab),s.grab&&!this.handleEventOnObject(s.grab,r)&&(s.grab=null)}),this._selectEndFn??(this._selectEndFn=(t,s)=>{var r;if(!s.grab)return;const n=new vc(this.context.input);n.inputSource=t,n.pointerId=0,n.isDown=t.selectionDown,n.isUp=t.selectionUp,n.isPressed=t.selectionPressed,n.isClicked=t.selectionClick,this.handleEventOnObject(s.grab,n);const o=i.get(t);if(i.set(t,null),o)for(const a of this.pressedByID.keys()){const l=this.pressedByID[a];l&&l.obj===o&&l.handler&&((r=l.handler.onPointerUp)==null||r.call(l.handler,n),this.pressedByID.delete(a))}});const e=new Nn;this._selectUpdateFn??(this._selectUpdateFn=t=>{var s;e.ray=t.getRay();const r=this.performRaycast(e)??[],n=new vc(this.context.input);n.inputSource=t,n.pointerId=((s=t.input)==null?void 0:s.handedness)==="right"?0:1,n.isDown=t.selectionDown,n.isUp=t.selectionUp,n.isPressed=t.selectionPressed,n.isClicked=!1,this.handleIntersections(n.pointerId,r,n)}),Ms.addEventListener(Kl.SelectStart,this._selectStartFn),Ms.addEventListener(Kl.SelectEnd,this._selectEndFn),Ms.addEventListener(Kl.Update,this._selectUpdateFn),this._handleInputFn=this.onPointerEvent.bind(this),this.context.input.addEventListener(us.PointerDown,this._handleInputFn),this.context.input.addEventListener(us.PointerUp,this._handleInputFn),this.context.input.addEventListener(us.PointerMove,this._handleInputFn)}onDisable(){Ms.removeEventListener(Kl.SelectStart,this._selectStartFn),Ms.removeEventListener(Kl.SelectEnd,this._selectEndFn),Ms.removeEventListener(Kl.Update,this._selectUpdateFn),this.context.input.removeEventListener(us.PointerDown,this._handleInputFn),this.context.input.removeEventListener(us.PointerUp,this._handleInputFn),this.context.input.removeEventListener(us.PointerMove,this._handleInputFn)}onBeforeRender(){this.resetMeshUIStates()}onPointerEvent(i){if(i===void 0)return;const e=i.pointerType==rp.Touch?i.button:0,t=new vc(this.context.input,i);t.inputSource=this.context.input,t.pointerId=i.button,t.isClicked=i.type==us.PointerUp&&this.context.input.getPointerClicked(i.button),t.isDown=i.type==us.PointerDown,t.isUp=i.type==us.PointerUp,t.isPressed=this.context.input.getPointerPressed(i.button),Du&&t.isClicked&&console.log("CLICK",t.pointerId);const s=new Nn;s.screenPoint=this.context.input.getPointerPositionRC(e);const r=this.performRaycast(s);if(!r)return;Du&&t.isClicked&&hs("EventSystem: "+t.pointerId+" - "+this.context.time.frame+" - Up:"+t.isUp+", Down:"+t.isDown);const n={sender:this,args:t,hasActiveUI:this.currentActiveMeshUIComponents.length>0};this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:n})),this.handleIntersections(e,r,t),this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:n}))}performRaycast(i){if(!this.raycaster)return null;this._sortedHits.length=0,i||(i=new Nn),this._testObjectsCache.clear(),i.testObject=this.shouldRaycastObject;for(const e of this.raycaster){if(!e.activeAndEnabled)continue;const t=e.performRaycast(i);t&&t.length>0&&this._sortedHits.push(...t)}return this._sortedHits.sort((e,t)=>e.distance-t.distance),this._sortedHits}handleIntersections(i,e,t){if(e!=null&&e.length){e=this.sortCandidates(e);for(const r of e){const{object:n}=r;if(t.point=r.point,t.normal=r.normal,t.face=r.face,t.distance=r.distance,t.instanceId=r.instanceId,this.handleEventOnObject(n,t))return!0}}const s=this.hoveredByID.get(i);if(s&&this.triggerOnExit(s.obj,s.data),this.hoveredByID.delete(i),t.isUp){const r=this.pressedByID.get(i);r?.handlers.forEach(n=>{var o;return(o=n.onPointerUp)==null?void 0:o.call(n,t)}),this.pressedByID.delete(i)}return!1}sortCandidates(i){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let e=0;e<i.length;e++){const t=i[e],s=t.object;if(s.material&&s.material.depthTest===!1){this._noDepthTestingResults.push(t);continue}this._sortingBuffer.push(t)}for(const e of this._sortingBuffer)this._noDepthTestingResults.push(e);return this._noDepthTestingResults}handleEventOnObject(i,e){if(!this.testIsVisible(i))return e.isClicked&&Du&&console.log("not allowed",i),!1;if(e.pointerId===void 0)return Du&&console.warn("Event without pointer can't be handled",e),!1;e.object=i;const t=i.parent;let s=!1;const r=e.isClicked??!1;let n=null;if(t&&t.isUI){const c=(e.isPressed||e.isClicked)??!1;if(t[Mo]){const u=t[Mo].gameObject;if(u){if(!Wp.isInteractable(u,this.out))return!1;n=this.out.canvasGroup??null,this.handleMeshUIIntersection(i,c),i=u,s=!0}}if(!s&&this.handleMeshUiObjectWithoutShadowDom(t,c))return!0}r&&Du&&console.log(this.context.time.frame,i);const o=this.hoveredByID.get(e.pointerId),a=o?.obj!==i;a&&o!=null&&o.obj&&this.triggerOnExit(o.obj,o.data);const l=this.hoveredByID.get(e.pointerId);if(l?(l.obj=i,l.data=e):this.hoveredByID.set(e.pointerId,{obj:i,data:e}),e.isDown){const c=this.pressedByID.get(e.pointerId);c?(c.obj=i,c.data=e):this.pressedByID.set(e.pointerId,{obj:i,data:e,handlers:new Set})}return(n===null||n.interactable)&&this.handleMainInteraction(i,e,a),!0}propagate(i,e,t){for(;;){if(e.used)return;if(te.foreachComponent(i,s=>{t(s)},!1),!i.parent)break;i=i.parent}}handleMainInteraction(i,e,t){if(e.pointerId===void 0)return;const s=this.pressedByID.get(e.pointerId);this.propagate(i,e,r=>{var n;const o=r;if(o.interactable===!1)return;o.onPointerEnter&&t&&o.onPointerEnter(e),e.isDown&&o.onPointerDown&&(o.onPointerDown(e),s?.handlers.add(o));const a=this.context.input.getPointerPositionLastFrame(e.pointerId),l=this.context.input.getPointerPosition(e.pointerId);a&&!rt.approximately(a,l)&&o.onPointerMove&&o.onPointerMove(e),e.isUp&&(o.onPointerUp&&(o.onPointerUp(e),s?.handlers.delete(o)),o.onPointerExit&&((n=e.event)==null?void 0:n.pointerType)===rp.Touch&&(o.onPointerExit(e),this.hoveredByID.delete(e.pointerId))),e.isClicked&&o.onPointerClick&&o.onPointerClick(e)}),e.isUp&&(s?.handlers.forEach(r=>{r.onPointerUp&&r.onPointerUp(e)}),this.pressedByID.delete(e.pointerId))}triggerOnExit(i,e){e.used=!1,this.propagate(i,e,t=>{if(!t.gameObject||t.destroyed)return;const s=t;s.onPointerExit&&s.onPointerExit(e)})}handleMeshUiObjectWithoutShadowDom(i,e){return!i||!i.isUI?!0:this.handleMeshUIIntersection(i,e)}handleMeshUIIntersection(i,e){const t=Zl.updateState(i,e);return t&&this.currentActiveMeshUIComponents.push(t),t!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&Zl.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let i=0;i<this.currentActiveMeshUIComponents.length;i++){const e=this.currentActiveMeshUIComponents[i];Zl.resetState(e)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(i){return i?te.isActiveSelf(i)?this.testIsVisible(i.parent):!1:!0}};let Xn=Jl;h(Xn,"_eventSystemMap",new Map),h(Xn,"didSearchEventSystem",!1);class Zl{static markDirty(){this.needsUpdate=!0}static update(e,t,s=!1){if(s){e.update();return}const r=t.time.frameCount;for(const n of this.lastUpdateFrame)if(n.context===t){if(r===n.frame)return;n.frame=r;let o=this.needsUpdate||r<1;n.nextUpdate===t.time.frameCount&&(o=!0),o&&(Du&&console.log("Update threemeshui"),this.needsUpdate=!1,e.update());return}this.lastUpdateFrame=[{context:t,frame:r,nextUpdate:r}],e.update()}static updateState(e,t){let s=null;if(e&&(s=this.findBlockInParent(e),s&&s!==this.lastSelected)){if(s.interactable===!1)return null;this.needsUpdate=!0}return s}static resetLastSelected(){const e=this.lastSelected;e&&(this.lastSelected=null,this.resetState(e))}static resetState(e){e&&(this.needsUpdate=!0)}static findBlockInParent(e){return e?e.isBlock?e:this.findBlockInParent(e.parent):null}}h(Zl,"lastSelected",null),h(Zl,"lastUpdateFrame",[]),h(Zl,"needsUpdate",!1);const w_=Symbol("cameraController");function Hie(i){return i[w_]}function ez(i,e,t){t?i[w_]=e:i[w_]===e&&(i[w_]=null)}const tz=Symbol("camera autofit");function Wie(i){return i[tz]===void 0?!0:i[tz]!==!1}class iz extends ge{constructor(e,t={}){const s=[e.isCubeTexture?"#define ENVMAP_TYPE_CUBE":""],r=`
|
|
5097
5097
|
varying vec3 vWorldPosition;
|
|
5098
5098
|
|