@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
|
@@ -5092,7 +5092,7 @@ ${r.join(`
|
|
|
5092
5092
|
`)}
|
|
5093
5093
|
|
|
5094
5094
|
}
|
|
5095
|
-
`}function ok(n){return`(${n.r}, ${n.g}, ${n.b})`}function ak(n){return`(${n.x}, ${n.y})`}const bG=[1023,33777,33778,33779,35842,35843,37496,37808,37809,37810,37811,37812,37813,37814,37815,37816,37817,37818,37819,37820,37821,36492];re("debugusdz");const uP=class{constructor(e,t,i){h(this,"id");h(this,"trigger");h(this,"action");h(this,"exclusive",!1);this.id="Behavior_"+zx(e)+"_"+uP.global_id++,this.trigger=t,this.action=i}makeExclusive(e){return this.exclusive=e,this}writeTo(e,t,i){if(!this.trigger||!this.action)return;i.beginBlock(`def Preliminary_Behavior "${this.id}"`),i.appendLine(`rel actions = <${this.action.id}>`),i.appendLine(`uniform bool exclusive = ${this.exclusive}`);let s="";if(Array.isArray(this.trigger)){s="[";for(let r=0;r<this.trigger.length;r++){const o=this.trigger[r];s+="<"+o.id+">",r+1<this.trigger.length&&(s+=", ")}s+="]"}else s=`<${this.trigger.id}>`;if(i.appendLine(`rel triggers = ${s} `),i.appendLine(),Array.isArray(this.trigger))for(const r of this.trigger)r.writeTo(t,i),i.appendLine();else this.trigger.writeTo(t,i);i.appendLine(),this.action.writeTo(t,i),i.closeBlock()}};let zn=uP;h(zn,"global_id",0);function VM(n,e){var i,s;let t="";if(Array.isArray(n)){let r="[ ";for(let o=0;o<n.length;o++){let a=n[o];if(typeof a=="string")r+=a;else if(typeof a=="object"){a.isObject3D&&(a=e.findById(a.uuid));const c=(i=a.getPath)==null?void 0:i.call(a);r+=c}o+1<n.length&&(r+=", ")}r+=" ]",t=r}else typeof n=="object"&&(n.isObject3D&&(n=e.findById(n.uuid)),t=(s=n.getPath)==null?void 0:s.call(n));return t}const dP=class{constructor(e,t){h(this,"id");h(this,"targetId");h(this,"tokenId");h(this,"type");h(this,"distance");e&&(this.targetId=e),t?this.id=t:this.id="Trigger_"+dP.global_id++}writeTo(e,t){t.beginBlock(`def Preliminary_Trigger "${this.id}"`),this.targetId&&(typeof this.targetId!="string"&&(this.targetId=VM(this.targetId,e)),t.appendLine("rel affectedObjects = "+this.targetId)),this.tokenId&&t.appendLine(`token info:id = "${this.tokenId}"`),this.type&&t.appendLine(`token type = "${this.type}"`),typeof this.distance=="number"&&t.appendLine(`double distance = ${this.distance}`),t.closeBlock()}};let ol=dP;h(ol,"global_id",0);class gs{static sceneStartTrigger(){const e=new ol;return e.targetId=void 0,e.tokenId="SceneTransition",e.type="enter",e}static tapTrigger(e){const t=new ol(e);return t.tokenId="TapGesture",t}static isTapTrigger(e){return(e==null?void 0:e.tokenId)==="TapGesture"}static proximityToCameraTrigger(e,t){const i=new ol(e);return i.tokenId="ProximityToCamera",i.distance=t,i}}class th{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 i of this.actions){if(!i)continue;const s=i===this.actions[this.actions.length-1];t.appendLine("<"+i.id+">"+(s?"":", "))}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 i of this.actions)i&&(i.writeTo(e,t),t.appendLine());t.closeBlock()}}h(th,"global_id",0);var JI=(n=>(n[n.pop=0]="pop",n[n.blink=1]="blink",n[n.bounce=2]="bounce",n[n.flip=3]="flip",n[n.float=4]="float",n[n.jiggle=5]="jiggle",n[n.pulse=6]="pulse",n[n.spin=7]="spin",n))(JI||{}),HM=(n=>(n.Relative="relative",n.Absolute="absolute",n))(HM||{}),_G=(n=>(n.Allow="allow",n.Ignore="ignore",n.Stop="stop",n))(_G||{});const v_=class{constructor(e,t){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");e&&(this.affectedObjects=e),t?this.id=t:this.id="Action",this.id+="_"+v_.global_id++}clone(){const e=new v_,t=e.id;return Object.assign(e,this),e.id=t,e}writeTo(e,t){t.beginBlock(`def Preliminary_Action "${this.id}"`),this.affectedObjects&&(typeof this.affectedObjects!="string"&&(this.affectedObjects=VM(this.affectedObjects,e)),t.appendLine("rel affectedObjects = "+this.affectedObjects)),typeof this.duration=="number"&&t.appendLine(`double duration = ${this.duration} `),this.easeType&&t.appendLine(`token easeType = "${this.easeType}"`),this.tokenId&&t.appendLine(`token info:id = "${this.tokenId}"`),this.motionType&&t.appendLine(`token motionType = "${this.motionType}"`),typeof this.moveDistance=="number"&&t.appendLine(`double moveDistance = ${this.moveDistance} `),this.style&&t.appendLine(`token style = "${this.style}"`),this.type&&t.appendLine(`token type = "${this.type}"`),this.front&&t.appendLine(`vector3d front = (${this.front.x}, ${this.front.y}, ${this.front.z})`),this.up&&t.appendLine(`vector3d upVector = (${this.up.x}, ${this.up.y}, ${this.up.z})`),typeof this.start=="number"&&t.appendLine(`double start = ${this.start} `),typeof this.animationSpeed=="number"&&t.appendLine(`double animationSpeed = ${this.animationSpeed} `),typeof this.reversed=="boolean"&&t.appendLine(`bool reversed = ${this.reversed}`),typeof this.pingPong=="boolean"&&t.appendLine(`bool reverses = ${this.pingPong}`),this.xFormTarget&&(typeof this.xFormTarget!="string"&&(this.xFormTarget=VM(this.xFormTarget,e)),t.appendLine(`rel xformTarget = ${this.xFormTarget}`)),typeof this.audio=="string"&&t.appendLine(`asset audio = @${this.audio}@`),typeof this.gain=="number"&&t.appendLine(`double gain = ${this.gain}`),typeof this.auralMode=="string"&&t.appendLine(`token auralMode = "${this.auralMode}"`),typeof this.multiplePerformOperation=="string"&&t.appendLine(`token multiplePerformOperation = "${this.multiplePerformOperation}"`),t.closeBlock()}};let Wr=v_;h(Wr,"global_id",0);let Tf=class mf{constructor(e,t,i){h(this,"x",0);h(this,"y",0);h(this,"z",0);this.x=e,this.y=t,this.z=i}static get up(){return new mf(0,1,0)}static get right(){return new mf(1,0,0)}static get forward(){return new mf(0,0,1)}static get back(){return new mf(0,0,-1)}static get zero(){return new mf(0,0,0)}};var QM=(n=>(n.Play="play",n.Pause="pause",n.Stop="stop",n))(QM||{}),WM=(n=>(n.Spatial="spatial",n.NonSpatial="nonSpatial",n.Ambient="ambient",n))(WM||{});class ni{static sequence(...e){return new th("group_"+th.getId(),e).makeSequence()}static parallel(...e){return new th("group_"+th.getId(),e).makeParallel()}static fadeAction(e,t,i){const s=new Wr(e);return s.tokenId="Visibility",s.type=i?"show":"hide",s.duration=t,s.style="basic",s.motionType="none",s.moveDistance=0,s.easeType="none",s}static startAnimationAction(e,t,i=0,s=1,r=!1,o=!1){const a=new Wr(e);if(a.tokenId="StartAnimation",a.start=t,a.duration=i,a.animationSpeed=s,a.reversed=r,a.pingPong=o,a.multiplePerformOperation="allow",r&&(a.start-=i),o){a.pingPong=!1;const c=a.clone();return c.reversed=!r,c.start=a.start,c.reversed&&(c.start-=i),ni.sequence(a,c)}return a}static waitAction(e){const t=new Wr;return t.tokenId="Wait",t.duration=e,t}static lookAtCameraAction(e,t=9999999999999,i,s){const r=new Wr(e);return r.tokenId="LookAtCamera",r.duration=t,r.front=i??Tf.forward,r.up=s??Tf.up,r}static emphasize(e,t,i=2,s=1,r="basic"){const o=new Wr(e);return o.tokenId="Emphasize",o.duration=t,o.style=r??"basic",o.motionType=JI[i],o.moveDistance=s,o}static transformAction(e,t,i,s,r="inout"){const o=new Wr(e);return o.tokenId="Transform",o.duration=i,o.type=s,o.easeType=r,Array.isArray(t)&&console.error("Transform target must not be an array",t),o.xFormTarget=t,o}static playAudioAction(e,t,i="play",s=1,r="spatial"){const o=new Wr(e);return o.tokenId="Audio",o.type=i,o.audio=t,o.gain=s,o.auralMode=r,o.multiplePerformOperation="allow",o}}class Vte{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 KI extends Vte{constructor(t,i,s,r){super(t);h(this,"matrix");h(this,"material");h(this,"geometry");h(this,"_enableAction");h(this,"_disableAction");this.matrix=i,this.material=s,this.geometry=r}onApply(t){var r,o;const i=this.model;if(!i)return;(r=i.parent)!=null&&r.isDynamic||Cr.createEmptyParent(i);const s=i.clone();this.matrix&&(s.matrix=this.matrix),this.material&&(s.material=this.material),this.geometry&&(s.geometry=this.geometry),(o=i.parent)==null||o.add(s)}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 ZI{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 Hte=Object.defineProperty,Qte=Object.getOwnPropertyDescriptor,xG=(n,e,t,i)=>{for(var s=i>1?void 0:i?Qte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Hte(e,t,s),s};class uv extends Ie{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 t=pt(this.from).clone(),i=pt(this.to).clone(),s=t.distanceTo(i);this._centerPos.copy(t),this._centerPos.add(i),this._centerPos.multiplyScalar(.5),yn(this.gameObject,this.centered?this._centerPos:t),this.gameObject.lookAt(pt(this.to).clone()),this.gameObject.scale.set(this.width,this.width,s)}}xG([x(ne)],uv.prototype,"from",2);xG([x(ne)],uv.prototype,"to",2);var Wte=Object.defineProperty,jte=Object.getOwnPropertyDescriptor,dv=(n,e,t,i)=>{for(var s=i>1?void 0:i?jte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Wte(e,t,s),s};const Zd=re("debuganimation");class no extends Ie{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 t;return(t=this.animations)!=null&&t.length?this.animations[0]:null}set clip(t){if(!this.__didAwake){Zd&&console.warn("Assign clip during serialization",t),this._tempAnimationClipBeforeGameObjectExisted=t;return}t&&(this.gameObject.animations||(this.gameObject.animations=[]),!this.animations.includes(t)&&(this.animations.length>0?this.animations.splice(0,0,t):this.animations.push(t)))}set clips(t){this.animations=t}set animations(t){t==null||!Array.isArray(t)||(this.gameObject?this.gameObject.animations=t:this._tempAnimationsArray=t)}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(t){this._actions=t}awake(){Zd&&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 t;if(this.playAutomatically&&((t=this.animations)==null?void 0:t.length)>0&&this.currentActions.length<=0){const i=Math.floor(Math.random()*this.actions.length);this.play(i)}}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(t){var i;return(i=this.actions)==null?void 0:i.find(s=>s.getClip().name===t)}get isPlaying(){for(let t=0;t<this.actions.length;t++)if(this.actions[t].isRunning())return!0;return!1}play(t=0,i){if(Zd&&console.log("PLAY",t),this.init(),!this.mixer){Zd&&console.warn("Missing mixer",this);return}t===void 0&&(t=0);let s=t;if(typeof t=="number"){if(t>=this.animations.length){Zd&&console.log("No animation at index",t);return}s=this.animations[t]}else typeof t=="string"&&(s=this.animations.find(o=>o.name===t));if(!s){console.error("Could not find clip",t);return}i||(i={}),i.minMaxOffsetNormalized||(i.minMaxOffsetNormalized=this.minMaxOffsetNormalized),i.minMaxSpeed||(i.minMaxSpeed=this.minMaxSpeed),i.loop===void 0&&(i.loop=this.loop),i.clampWhenFinished===void 0&&(i.clampWhenFinished=this.clampWhenFinished);for(const o of this.actions)if(o.getClip()===s)return this.internalOnPlay(o,i);if(!(s instanceof Mr)){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,i)}internalOnPlay(t,i){var s=this.currentAction;if(s===t&&s.isRunning()&&s.time<s.getClip().duration){const c=this.tryFindHandle(t);if(c)return c.getPromise()}const r=(i==null?void 0:i.exclusive)??!0;i!=null&&i.fadeDuration?(r&&(s==null||s.fadeOut(i.fadeDuration)),t.fadeIn(i.fadeDuration)):r&&(s==null||s.stop()),t.reset(),t.enabled=!0,t.time=0,t.timeScale=1;const o=t.getClip();i!=null&&i.minMaxOffsetNormalized&&(t.time=ot.lerp(i.minMaxOffsetNormalized.x,i.minMaxOffsetNormalized.y,Math.random())*o.duration),i!=null&&i.minMaxSpeed&&(t.timeScale=ot.lerp(i.minMaxSpeed.x,i.minMaxSpeed.y,Math.random())),i!=null&&i.clampWhenFinished&&(t.clampWhenFinished=!0),(i==null?void 0:i.startTime)!==void 0&&(t.time=i.startTime),(i==null?void 0:i.loop)!==void 0?t.loop=i.loop?U1:Gg:t.loop=Gg,t.play(),Zd&&console.log("PLAY",t.getClip().name,t);const a=new qte(t,this.mixer,i,c=>{this._handles.splice(this._handles.indexOf(a),1)});return this._handles.push(a),a.getPromise()}tryFindHandle(t){for(const i of this._handles)if(i.action===t)return i}init(){this._didInit||(this._didInit=!0,this.gameObject&&(this.actions=[],this.mixer=new rx(this.gameObject)))}}dv([x()],no.prototype,"playAutomatically",2);dv([x()],no.prototype,"randomStartTime",2);dv([x()],no.prototype,"loop",2);dv([x()],no.prototype,"clampWhenFinished",2);dv([x(Mr)],no.prototype,"clips",1);class qte{constructor(e,t,i,s){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=s,this._options=i}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,i;this.dispose(),(t=this._resolvedOrRejectedCallback)==null||t.call(this,this),(i=this._rejectCallback)==null||i.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 Xte=Object.defineProperty,Yte=Object.getOwnPropertyDescriptor,Th=(n,e,t,i)=>{for(var s=i>1?void 0:i?Yte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Xte(e,t,s),s};class Ih{constructor(){h(this,"time");h(this,"value");h(this,"inTangent");h(this,"inWeight");h(this,"outTangent");h(this,"outWeight");h(this,"weightedMode")}}Th([x()],Ih.prototype,"time",2);Th([x()],Ih.prototype,"value",2);Th([x()],Ih.prototype,"inTangent",2);Th([x()],Ih.prototype,"inWeight",2);Th([x()],Ih.prototype,"outTangent",2);Th([x()],Ih.prototype,"outWeight",2);Th([x()],Ih.prototype,"weightedMode",2);const wG=class{constructor(){h(this,"keys")}get duration(){return!this.keys||this.keys.length==0?0:this.keys[this.keys.length-1].time}evaluate(n){if(!this.keys||this.keys.length==0)return 0;if(this.keys[0].time>=n)return this.keys[0].value;for(let e=0;e<this.keys.length;e++){const t=this.keys[e];if(t.time<=n)if(e+1<this.keys.length){const s=this.keys[e+1];if(s.time<n)continue;return!isFinite(t.outTangent)||!isFinite(s.inTangent)?t.value:wG.interpolateValue(n,t,s)}else return t.value}return this.keys[this.keys.length-1].value}static interpolateValue(n,e,t){const i=e.time,s=e.value,r=e.outTangent,o=t.time,a=t.value,c=t.inTangent,l=o-i,u=l*l,d=u*l,f=((r+c)*l-2*(a-s))/d,p=(3*(a-s)-(c+2*r)*l)/u,m=r,v=s,A=n-i,g=A*A,b=g*A;return f*b+p*g+m*A+v}};let td=wG;Th([x(Ih)],td.prototype,"keys",2);class Jte{constructor(){h(this,"_context")}get context(){return this._context??Lt.Current}get isStateMachineBehaviour(){return!0}}class hb{constructor(e,t,i,s){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=i,this._speed=s}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 SG(n,e){return{name:"",isLooping:!1,guid:(e==null?void 0:e.generateUUID())??As.generateUUID(),index:-1,clip:new Mr(n,1,[])}}var Jl=(n=>(n[n.If=1]="If",n[n.IfNot=2]="IfNot",n[n.Greater=3]="Greater",n[n.Less=4]="Less",n[n.Equals=6]="Equals",n[n.NotEqual=7]="NotEqual",n))(Jl||{}),$I=(n=>(n[n.Float=1]="Float",n[n.Int=3]="Int",n[n.Bool=4]="Bool",n[n.Trigger=9]="Trigger",n))($I||{});const Ao=re("debuganimatorcontroller"),a0=re("debugrootmotion");class Uo{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,Ao&&console.log(this)}static createFromClips(e,t={looping:!1,autoTransition:!0,transitionDuration:0}){const i=[];for(let o=0;o<e.length;o++){const a=e[o],c=[];if(t.autoTransition!==!1){const u=t.transitionDuration??0,d=u/a.duration;let f=o;(t.autoTransition===void 0||t.autoTransition===!0)&&(f=(o+1)%e.length),c.push({exitTime:1-d,offset:0,duration:u,hasExitTime:!0,destinationState:f,conditions:[]})}const l={name:a.name,hash:o,motion:{name:a.name,clip:a,isLooping:(t==null?void 0:t.looping)??!1},transitions:c,behaviours:[]};i.push(l)}const s={name:"AnimatorController",guid:new Vs(Date.now()).generateUUID(),parameters:[],layers:[{name:"Base Layer",stateMachine:{defaultState:0,states:i}}]};return new Uo(s)}play(e,t=-1,i=Number.NEGATIVE_INFINITY,s=0){if(t<0)t=0;else if(t>=this.model.layers.length){console.warn("invalid layer");return}const o=this.model.layers[t].stateMachine;for(const a of o.states)if(a.name===e||a.hash===e){Ao&&console.log("transition to ",a),this.transitionTo(a,s,i);return}console.warn("Could not find "+e+" to play")}reset(){this.setStartTransition()}setBool(e,t){var s,r;const i=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[i]===e).forEach(o=>o.value=t)}getBool(e){var i,s,r;const t=typeof e=="string"?"name":"hash";return((r=(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.find(o=>o[t]===e))==null?void 0:r.value)??!1}setFloat(e,t){var r,o;const i=typeof e=="string"?"name":"hash",s=(o=(r=this.model)==null?void 0:r.parameters)==null?void 0:o.filter(a=>a[i]===e);return s.forEach(a=>a.value=t),(s==null?void 0:s.length)>0}getFloat(e){var i,s,r;const t=typeof e=="string"?"name":"hash";return((r=(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.find(o=>o[t]===e))==null?void 0:r.value)??0}setInteger(e,t){var s,r;const i=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[i]===e).forEach(o=>o.value=t)}getInteger(e){var i,s,r;const t=typeof e=="string"?"name":"hash";return((r=(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.find(o=>o[t]===e))==null?void 0:r.value)??0}setTrigger(e){var i,s;Ao&&console.log("SET TRIGGER",e);const t=typeof e=="string"?"name":"hash";return(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.filter(r=>r[t]===e).forEach(r=>r.value=!0)}resetTrigger(e){var i,s;const t=typeof e=="string"?"name":"hash";return(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.filter(r=>r[t]===e).forEach(r=>r.value=!1)}getTrigger(e){var i,s,r;const t=typeof e=="string"?"name":"hash";return((r=(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.find(o=>o[t]===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 i of t.stateMachine.states)if(i.name===e||i.hash==e)return i}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 rx(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=QA(this.model,(i,s,r)=>r==null?!0:!(r.type==="Object3D"||r.isObject3D===!0||qF(r)||r.tracks!==void 0));return console.assert(e!==this.model),new Uo(e)}update(e){var i,s;if(!this.animator)return;this.evaluateTransitions(),this.updateActiveStates(e);const t=this.animator.context.time.deltaTime;this.animator.applyRootMotion&&((i=this.rootMotionHandler)==null||i.onBeforeUpdate(e)),this._mixer.update(t),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 i=this._activeStates[t],s=i.motion;if(!s.action)this._activeStates.splice(t,1),t--;else{const r=s.action;r.weight=e,r.getEffectiveWeight()<=0&&!r.isRunning()&&(Ao&&console.debug("REMOVE",i.name,r.getEffectiveWeight(),r.isRunning(),r.isScheduled()),this._activeStates.splice(t,1),t--)}}}setStartTransition(){for(const e of this.model.layers){const t=e.stateMachine;t.defaultState===void 0&&(Ao&&console.warn("AnimatorController default state is undefined, will assign state 0 as default",e),t.defaultState=0);const i=t.states[t.defaultState];this.transitionTo(i,0,this.normalizedStartOffset)}}evaluateTransitions(){var r;let e=!1;if(!this._activeState){if(this.setStartTransition(),!this._activeState)return;e=!0}const t=this._activeState,i=t.motion.action;for(const o of t.transitions){if(!o.hasExitTime&&o.conditions.length<=0)continue;let a=!0;for(const c of o.conditions)if(!this.evaluateCondition(c)){a=!1;break}if(a)if(i){const c=t.motion.clip.duration,l=c<=0?1:Math.abs(i.time/c);let u=!1;if(o.hasExitTime?i.timeScale>0?u=l>=o.exitTime:i.timeScale<0&&(u=1-l>=o.exitTime):u=!0,u){for(const d of o.conditions){const f=this.model.parameters.find(p=>p.name===d.parameter);(f==null?void 0:f.type)===$I.Trigger&&f.value&&(f.value=!1)}i.clampWhenFinished=!0,Ao&&console.log("transition to "+o.destinationState,o,l,o.exitTime,o.hasExitTime),this.transitionTo(o.destinationState,o.duration,o.offset);return}}else{this.transitionTo(o.destinationState,o.duration,o.offset);return}}if(i){let o=t.speed??1;t.speedParameter&&(o*=this.getFloat(t.speedParameter)),o!==void 0&&(i.timeScale=o*this._speed)}let s=!1;if(t.motion.isLooping&&i&&(i.time>=i.getClip().duration?(s=!0,i.reset(),i.time=0,i.play()):i.time<=0&&i.timeScale<0&&(s=!0,i.reset(),i.time=i.getClip().duration,i.play())),!s&&t&&!e&&i&&this.animator&&t.behaviours){const o=i==null?void 0:i.getClip().duration,a=i.time/o,c=new hb(this._activeState,a,o,this._speed);for(const l of t.behaviours)l.instance&&((r=l.instance.onStateUpdate)==null||r.call(l.instance,this.animator,c,0))}}getState(e,t){return typeof e=="number"&&(e==-1&&(e=this.model.layers[t].stateMachine.defaultState,e===void 0&&(Ao&&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,i){var l,u,d,f,p,m,v,A;if(!this.animator)return;const s=0;if(e=this.getState(e,s),!(e!=null&&e.motion)||!e.motion.clip||!(e.motion.clip instanceof Mr))return;const r=this._activeState===e;if(r){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((l=this._activeState)!=null&&l.behaviours&&this._activeState.motion.action){const g=(u=this._activeState)==null?void 0:u.motion.clip.duration,b=this._activeState.motion.action.time/g,y=new hb(this._activeState,b,g,this._speed);for(const _ of this._activeState.behaviours)(f=(d=_.instance)==null?void 0:d.onStateExit)==null||f.call(_.instance,this.animator,y,s)}const o=(p=this._activeState)==null?void 0:p.motion.action;o&&o.fadeOut(t),r&&(e.motion.action=e.motion.action_loopback,e.motion.action_loopback=o);const a=this._activeState;this._activeState=e;const c=(m=e.motion)==null?void 0:m.action;if(c){if(i=Math.max(0,Math.min(1,i)),e.cycleOffsetParameter){let b=this.getFloat(e.cycleOffsetParameter);typeof b=="number"?(b<0&&(b+=1),i+=b,i%=1):Ao&&console.warn("AnimatorController cycle offset parameter is not a number",e.cycleOffsetParameter)}else typeof e.cycleOffset=="number"&&(i+=e.cycleOffset,i%=1);c.isRunning()&&c.stop(),c.reset(),c.enabled=!0;const g=e.motion.clip.duration;if(c.time=r?0:i*g,c.timeScale<0&&(c.time=g-c.time),c.clampWhenFinished=!0,c.setLoop(Gg,0),t>0?c.fadeIn(t):c.weight=1,c.play(),this.rootMotionHandler&&this.rootMotionHandler.onStart(c),this._activeStates.includes(e)||this._activeStates.push(e),this._activeState.behaviours){const b=new hb(e,i,g,this._speed);for(const y of this._activeState.behaviours)(A=(v=y.instance)==null?void 0:v.onStateEnter)==null||A.call(y.instance,this.animator,b,s)}}else Ao&&(e.__warned_no_motion||(e.__warned_no_motion=!0,console.warn("No action",e.motion,this)));Ao&&console.log("TRANSITION FROM "+(a==null?void 0:a.name)+" TO "+e.name,t,o,c,c==null?void 0:c.getEffectiveTimeScale(),c==null?void 0:c.getEffectiveWeight(),c==null?void 0:c.isRunning(),c==null?void 0:c.isScheduled(),c==null?void 0:c.paused)}createAction(e){var i,s;if(this._mixer.existingAction(e)&&this._mixer.uncacheAction(e,(i=this.animator)==null?void 0:i.gameObject),(s=this.animator)!=null&&s.applyRootMotion){this.rootMotionHandler||(this.rootMotionHandler=new Kte(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(i=>i.name===e.parameter);if(!t)return!1;switch(e.mode){case Jl.If:return t.value===!0;case Jl.IfNot:return t.value===!1;case Jl.Greater:return t.value>e.threshold;case Jl.Less:return t.value<e.threshold;case Jl.Equals:return t.value===e.threshold;case Jl.NotEqual:return t.value!==e.threshold}return!1}createActions(e){var t,i;for(const s of this.model.layers){const r=s.stateMachine;for(let o=0;o<r.states.length;o++){const a=r.states[o];a.transitions||(a.transitions=[]);for(const c of a.transitions)c.conditions||(c.conditions=[]);if(a.motion||(a.motion=SG(a.name)),this.animator&&a.motion.clips){const c=(t=a.motion.clips)==null?void 0:t.find(l=>{var u,d;return l.node.name===((d=(u=this.animator)==null?void 0:u.gameObject)==null?void 0:d.name)});a.motion.clip=c==null?void 0:c.clip}if(!a.motion.clip){const c=new Mr(void 0,void 0,[]);a.motion.clip=c}if((i=a.motion)!=null&&i.clip){const c=a.motion.clip;if(c instanceof Mr){const l=this.createAction(c);a.motion.action=l}else(Ao||Vt())&&console.warn("No valid animationclip assigned",a)}if(a.behaviours&&Array.isArray(a.behaviours))for(const c of a.behaviours){if(!(c!=null&&c.typeName))continue;const l=Y.get(c.typeName),u=new l;u.isStateMachineBehaviour&&(u._context=this.context??void 0,hp(u,c.properties),c.instance=u),Ao&&console.log("Created animator controller behaviour",a.name,c.typeName,c.properties,u)}}}}*enumerateActions(){if(this.model.layers)for(const e of this.model.layers){const t=e.stateMachine;for(let i=0;i<t.states.length;i++){const s=t.states[i];s!=null&&s.motion&&(s.motion.action&&(yield s.motion.action),s.motion.action_loopback&&(yield s.motion.action_loopback))}}}}class ck{constructor(e,t){h(this,"track");h(this,"createdInterpolant");h(this,"originalEvaluate");h(this,"customEvaluate");this.track=e;const i=e,s=i.createInterpolant.bind(e);i.createInterpolant=()=>(i.createInterpolant=s,this.createdInterpolant=s(),this.originalEvaluate=this.createdInterpolant.evaluate.bind(this.createdInterpolant),this.customEvaluate=r=>{if(!this.originalEvaluate)return;const o=this.originalEvaluate(r);return t(r,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 Nn=class{constructor(e,t,i,s,r){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 Ce);h(this,"_prevTime",0);if(this.context=e,this.root=t,this.clip=i,Nn.firstKeyframeRotation[this.cacheId]||(Nn.firstKeyframeRotation[this.cacheId]=new Ce),r){const o=r.values;Nn.firstKeyframeRotation[this.cacheId].set(o[0],o[1],o[2],o[3])}Nn.spaceRotation[this.cacheId]||(Nn.spaceRotation[this.cacheId]=new Ce),Nn.effectiveSpaceRotation[this.cacheId]||(Nn.effectiveSpaceRotation[this.cacheId]=new Ce),Nn.clipOffsetRotation[this.cacheId]=new Ce,r&&Nn.clipOffsetRotation[this.cacheId].set(r.values[0],r.values[1],r.values[2],r.values[3]).invert(),this.handlePosition(i,s),this.handleRotation(i,r)}set action(e){this._action=e}get action(){return this._action}get cacheId(){return this.root.uuid}onStart(e){if(e.getClip()!==this.clip)return;Nn.lastObjRotation[this.cacheId]||(Nn.lastObjRotation[this.cacheId]=this.root.quaternion.clone());const t=Nn.lastObjRotation[this.cacheId];if(Nn.spaceRotation[this.cacheId].copy(t),a0){const i=new Gn().setFromQuaternion(t);console.log("START",this.clip.name,ot.toDegrees(i.y),this.root.position.z)}}getClipRotationOffset(){return Nn.clipOffsetRotation[this.cacheId]}handlePosition(e,t){if(t){const i=this.root;a0&&i.add(new wp),Nn.lastObjPosition[this.cacheId]||(Nn.lastObjPosition[this.cacheId]=this.root.position.clone());const s=new w,r=new w;this.positionWrapper=new ck(t,(o,a)=>{const c=this.action.getEffectiveWeight();return a0&&i.position.length()>8&&i.position.set(0,i.position.y,0),o>this._prevTime&&(s.set(a[0],a[1],a[2]),s.sub(r),s.multiplyScalar(c),s.applyQuaternion(this.getClipRotationOffset()),s.applyQuaternion(i.quaternion),this.positionChange.copy(s)),r.fromArray(a),this._prevTime=o,a[0]=0,a[1]=0,a[2]=0,a})}}handleRotation(e,t){if(t){if(a0){const o=t.values,a=new Gn().setFromQuaternion(new Ce(o[0],o[1],o[2],o[3]));console.log(e.name,t.name,"FIRST ROTATION IN TRACK",ot.toDegrees(a.y));const c=t.values.length-4,l=new Ce().set(o[c],o[c+1],o[c+2],o[c+3]),u=new Gn().setFromQuaternion(l);console.log(e.name,t.name,"LAST ROTATION IN TRACK",ot.toDegrees(u.y))}let i=0;const s=new Ce,r=new Ce;this.rotationWrapper=new ck(t,(o,a)=>(o>i&&(r.set(a[0],a[1],a[2],a[3]),s.invert(),r.multiply(s),this.rotationChange.copy(r)),s.fromArray(a),i=o,a[0]=0,a[1]=0,a[2]=0,a[3]=1,a))}}onBeforeUpdate(e){this.positionChange.set(0,0,0),this.rotationChange.set(0,0,0,1)}onAfterUpdate(e){return!this.action||(e*=this.action.getEffectiveWeight(),e<=0)?!1:(this.positionChange.multiplyScalar(e),this.rotationChange.slerp(Nn.identityQuaternion,1-e),!0)}};let Ra=Nn;h(Ra,"lastObjPosition",{}),h(Ra,"lastObjRotation",{}),h(Ra,"firstKeyframeRotation",{}),h(Ra,"spaceRotation",{}),h(Ra,"effectiveSpaceRotation",{}),h(Ra,"clipOffsetRotation",{}),h(Ra,"identityQuaternion",new Ce);class Kte{constructor(e){h(this,"controller");h(this,"handler",[]);h(this,"root");h(this,"basePosition",new w);h(this,"baseQuaternion",new Ce);h(this,"baseRotation",new Gn);h(this,"summedPosition",new w);h(this,"summedRotation",new Ce);this.controller=e}createClip(e,t,i){this.root=t,t&&"name"in t&&t.name;const s=this.findRootTrack(i,".position"),r=this.findRootTrack(i,".quaternion"),o=new Ra(this.controller.context,t,i,s,r);this.handler.push(o);const a=e.clipAction(i);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 i=e.tracks;if(!i)return null;for(const s of i)if(s.name.endsWith(t))return s;return null}}class Zte extends Al{onSerialize(e,t){}onDeserialize(e,t){if(t.type===Uo&&(e==null?void 0:e.__type)==="AnimatorController")return new Uo(e)}}new Zte(Uo);class $te extends pn{constructor(e,t=1,i=16,s=2){const r=new At,o=i+s*2,a=new Float32Array((o*3+3)*3);r.setAttribute("position",new Ke(a,3));const c=new xn({color:65280}),l=new xn({color:16776960});super(r,[l,c]),this.audio=e,this.range=t,this.divisionsInnerAngle=i,this.divisionsOuterAngle=s,this.type="PositionalAudioHelper",this.update()}update(){const e=this.audio,t=this.range,i=this.divisionsInnerAngle,s=this.divisionsOuterAngle,r=As.degToRad(e.panner.coneInnerAngle),o=As.degToRad(e.panner.coneOuterAngle),a=r/2,c=o/2;let l=0,u=0,d,f;const p=this.geometry,m=p.attributes.position;p.clearGroups();function v(A,g,b,y){const _=(g-A)/b;for(m.setXYZ(l,0,0,0),u++,d=A;d<g;d+=_)f=l+u,m.setXYZ(f,Math.sin(d)*t,0,Math.cos(d)*t),m.setXYZ(f+1,Math.sin(Math.min(d+_,g))*t,0,Math.cos(Math.min(d+_,g))*t),m.setXYZ(f+2,0,0,0),u+=3;p.addGroup(l,u,y),l+=u,u=0}v(-c,-a,s,0),v(-a,a,i,1),v(a,c,s,0),m.needsUpdate=!0,r===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,bl=(n,e,t,i)=>{for(var s=i>1?void 0:i?tie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&eie(e,t,s),s};const cs=re("debugaudio");let o_=!1;const a_=[];function Gx(){if(o_)return;Vt()&&console.log("User interaction registered: audio can now be played"),o_=!0;const n=[...a_];a_.length=0,n.forEach(e=>e())}document.addEventListener("pointerdown",Gx);document.addEventListener("click",Gx);document.addEventListener("dragstart",Gx);document.addEventListener("touchstart",Gx);const Ic=class extends Ie{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||gl())&&(this.wasPlaying=this.isPlaying,this.isPlaying&&this.pause());break;case"visible":cs&&console.log("visible",this.enabled,this.playOnAwake,!this.isPlaying,Ic.userInteractionRegistered,this.wasPlaying),this.enabled&&this.playOnAwake&&!this.isPlaying&&Ic.userInteractionRegistered&&this.wasPlaying&&this.play();break}});h(this,"onApplicationMuteChanged",()=>{var e,t;this.context.application.muted?(e=this.sound)==null||e.setVolume(0):(t=this.sound)==null||t.setVolume(this.volume)});h(this,"lerp",(e,t,i)=>e*(1-i)+t*i);h(this,"createAudio",e=>{cs&&console.log("audio buffer loaded"),Ic.registerWaitForAllowAudio(()=>{cs&&console.log("finished loading",e);const t=this.Sound;if(!t){console.warn("Failed getting sound",this.name);return}t.isPlaying&&t.stop(),e&&t.setBuffer(e),t.loop=this._loop,this.context.application.muted?t.setVolume(0):t.setVolume(this.volume),t.autoplay=this.shouldPlay,this.applySpatialDistanceSettings(),t.isPlaying&&t.stop(),cs&&console.log(this.name,this.shouldPlay,Ic.userInteractionRegistered,this),this.shouldPlay&&Ic.userInteractionRegistered&&this.play()})});h(this,"_lastContextTime",0);h(this,"_hasEnded",!0);h(this,"_needUpdateSpatialDistanceSettings",!1)}static get userInteractionRegistered(){return o_}static registerWaitForAllowAudio(e){if(e!==null){if(o_){e();return}a_.indexOf(e)===-1&&a_.push(e)}}get loop(){return this.sound&&(this._loop=this.sound.getLoop()),this._loop}set loop(e){this._loop=e,this.sound&&this.sound.setLoop(e)}get spatialBlend(){return this._spatialBlend}set spatialBlend(e){e!==this._spatialBlend&&(this._spatialBlend=e,this._needUpdateSpatialDistanceSettings=!0)}get minDistance(){return this._minDistance}set minDistance(e){this._minDistance!==e&&(this._minDistance=e,this._needUpdateSpatialDistanceSettings=!0)}get maxDistance(){return this._maxDistance}set maxDistance(e){this._maxDistance!==e&&(this._maxDistance=e,this._needUpdateSpatialDistanceSettings=!0)}get volume(){return this._volume}set volume(e){this._volume=e,this.sound&&!this.context.application.muted&&(cs&&console.log(this.name,"audio set volume",e),this.sound.setVolume(e))}get Sound(){if(!this.sound&&Ic.userInteractionRegistered){let e=ne.getComponent(this.context.mainCamera,ah)??ne.findObjectOfType(ah,this.context);!e&&this.context.mainCamera&&(e=ne.addNewComponent(this.context.mainCamera,ah)),e!=null&&e.listener?(this.sound=new bF(e.listener),this.gameObject.add(this.sound)):cs&&console.warn("No audio listener found in scene - can not play audio")}return this.sound}get ShouldPlay(){return this.shouldPlay}awake(){cs&&console.log(this),this.audioLoader=new Rb,this.playOnAwake&&(this.shouldPlay=!0)}onEnable(){Ic.userInteractionRegistered?this.playOnAwake&&this.context.application.isVisible&&this.play():Ic.registerWaitForAllowAudio(()=>{this.enabled&&!this.destroyed&&this.shouldPlay&&this.onNewClip(this.clip)}),globalThis.addEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.addEventListener(Xb.MuteChanged,this.onApplicationMuteChanged)}onDisable(){globalThis.removeEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.removeEventListener(Xb.MuteChanged,this.onApplicationMuteChanged),this.pause()}applySpatialDistanceSettings(){const e=this.sound;if(!e)return;this._needUpdateSpatialDistanceSettings=!1;const t=this.lerp(10*this._maxDistance/Math.max(1e-4,this.spatialBlend),this._minDistance,this.spatialBlend);switch(cs&&console.log(this.name,this._minDistance,this._maxDistance,this.spatialBlend,"Ref distance="+t),e.setRefDistance(t),e.setMaxDistance(Math.max(.01,this._maxDistance)),this.rollOffMode){case 0:e.setDistanceModel("exponential");break;case 1:e.setDistanceModel("linear");break}this.spatialBlend>0?cs&&!this.helper&&(this.helper=new $te(e,e.getRefDistance()),e.add(this.helper)):this.helper&&this.helper.parent&&this.helper.removeFromParent()}onNewClip(e){if(e&&(this.clip=e),typeof e=="string")if(cs&&console.log(e),e.endsWith(".mp3")||e.endsWith(".wav")){if(this.audioLoader||(this.audioLoader=new Rb),this.shouldPlay=!0,this._lastClipStartedLoading===e){cs&&console.log("Is currently loading:",this._lastClipStartedLoading,this);return}this._lastClipStartedLoading=e,cs&&console.log("load audio",e),this.audioLoader.load(e,this.createAudio,()=>{},console.error)}else console.warn("Unsupported audio clip type",e);else this.shouldPlay=!0,this.createAudio()}play(e=void 0){var i,s;!e&&this.clip&&(e=this.clip),e!==void 0&&typeof e!="string"&&!(e instanceof MediaStream)&&(Vt()&&console.warn("Called play on AudioSource with unknown argument type:",e+`
|
|
5095
|
+
`}function ok(n){return`(${n.r}, ${n.g}, ${n.b})`}function ak(n){return`(${n.x}, ${n.y})`}const bG=[1023,33777,33778,33779,35842,35843,37496,37808,37809,37810,37811,37812,37813,37814,37815,37816,37817,37818,37819,37820,37821,36492];re("debugusdz");const uP=class{constructor(e,t,i){h(this,"id");h(this,"trigger");h(this,"action");h(this,"exclusive",!1);this.id="Behavior_"+zx(e)+"_"+uP.global_id++,this.trigger=t,this.action=i}makeExclusive(e){return this.exclusive=e,this}writeTo(e,t,i){if(!this.trigger||!this.action)return;i.beginBlock(`def Preliminary_Behavior "${this.id}"`),i.appendLine(`rel actions = <${this.action.id}>`),i.appendLine(`uniform bool exclusive = ${this.exclusive}`);let s="";if(Array.isArray(this.trigger)){s="[";for(let r=0;r<this.trigger.length;r++){const o=this.trigger[r];s+="<"+o.id+">",r+1<this.trigger.length&&(s+=", ")}s+="]"}else s=`<${this.trigger.id}>`;if(i.appendLine(`rel triggers = ${s} `),i.appendLine(),Array.isArray(this.trigger))for(const r of this.trigger)r.writeTo(t,i),i.appendLine();else this.trigger.writeTo(t,i);i.appendLine(),this.action.writeTo(t,i),i.closeBlock()}};let zn=uP;h(zn,"global_id",0);function VM(n,e){var i,s;let t="";if(Array.isArray(n)){let r="[ ";for(let o=0;o<n.length;o++){let a=n[o];if(typeof a=="string")r+=a;else if(typeof a=="object"){a.isObject3D&&(a=e.findById(a.uuid));const c=(i=a.getPath)==null?void 0:i.call(a);r+=c}o+1<n.length&&(r+=", ")}r+=" ]",t=r}else typeof n=="object"&&(n.isObject3D&&(n=e.findById(n.uuid)),t=(s=n.getPath)==null?void 0:s.call(n));return t}const dP=class{constructor(e,t){h(this,"id");h(this,"targetId");h(this,"tokenId");h(this,"type");h(this,"distance");e&&(this.targetId=e),t?this.id=t:this.id="Trigger_"+dP.global_id++}writeTo(e,t){t.beginBlock(`def Preliminary_Trigger "${this.id}"`),this.targetId&&(typeof this.targetId!="string"&&(this.targetId=VM(this.targetId,e)),t.appendLine("rel affectedObjects = "+this.targetId)),this.tokenId&&t.appendLine(`token info:id = "${this.tokenId}"`),this.type&&t.appendLine(`token type = "${this.type}"`),typeof this.distance=="number"&&t.appendLine(`double distance = ${this.distance}`),t.closeBlock()}};let ol=dP;h(ol,"global_id",0);class gs{static sceneStartTrigger(){const e=new ol;return e.targetId=void 0,e.tokenId="SceneTransition",e.type="enter",e}static tapTrigger(e){const t=new ol(e);return t.tokenId="TapGesture",t}static isTapTrigger(e){return(e==null?void 0:e.tokenId)==="TapGesture"}static proximityToCameraTrigger(e,t){const i=new ol(e);return i.tokenId="ProximityToCamera",i.distance=t,i}}class th{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 i of this.actions){if(!i)continue;const s=i===this.actions[this.actions.length-1];t.appendLine("<"+i.id+">"+(s?"":", "))}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 i of this.actions)i&&(i.writeTo(e,t),t.appendLine());t.closeBlock()}}h(th,"global_id",0);var JI=(n=>(n[n.pop=0]="pop",n[n.blink=1]="blink",n[n.bounce=2]="bounce",n[n.flip=3]="flip",n[n.float=4]="float",n[n.jiggle=5]="jiggle",n[n.pulse=6]="pulse",n[n.spin=7]="spin",n))(JI||{}),HM=(n=>(n.Relative="relative",n.Absolute="absolute",n))(HM||{}),_G=(n=>(n.Allow="allow",n.Ignore="ignore",n.Stop="stop",n))(_G||{});const v_=class{constructor(e,t){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");e&&(this.affectedObjects=e),t?this.id=t:this.id="Action",this.id+="_"+v_.global_id++}clone(){const e=new v_,t=e.id;return Object.assign(e,this),e.id=t,e}writeTo(e,t){t.beginBlock(`def Preliminary_Action "${this.id}"`),this.affectedObjects&&(typeof this.affectedObjects!="string"&&(this.affectedObjects=VM(this.affectedObjects,e)),t.appendLine("rel affectedObjects = "+this.affectedObjects)),typeof this.duration=="number"&&t.appendLine(`double duration = ${this.duration} `),this.easeType&&t.appendLine(`token easeType = "${this.easeType}"`),this.tokenId&&t.appendLine(`token info:id = "${this.tokenId}"`),this.motionType&&t.appendLine(`token motionType = "${this.motionType}"`),typeof this.moveDistance=="number"&&t.appendLine(`double moveDistance = ${this.moveDistance} `),this.style&&t.appendLine(`token style = "${this.style}"`),this.type&&t.appendLine(`token type = "${this.type}"`),this.front&&t.appendLine(`vector3d front = (${this.front.x}, ${this.front.y}, ${this.front.z})`),this.up&&t.appendLine(`vector3d upVector = (${this.up.x}, ${this.up.y}, ${this.up.z})`),typeof this.start=="number"&&t.appendLine(`double start = ${this.start} `),typeof this.animationSpeed=="number"&&t.appendLine(`double animationSpeed = ${this.animationSpeed} `),typeof this.reversed=="boolean"&&t.appendLine(`bool reversed = ${this.reversed}`),typeof this.pingPong=="boolean"&&t.appendLine(`bool reverses = ${this.pingPong}`),this.xFormTarget&&(typeof this.xFormTarget!="string"&&(this.xFormTarget=VM(this.xFormTarget,e)),t.appendLine(`rel xformTarget = ${this.xFormTarget}`)),typeof this.audio=="string"&&t.appendLine(`asset audio = @${this.audio}@`),typeof this.gain=="number"&&t.appendLine(`double gain = ${this.gain}`),typeof this.auralMode=="string"&&t.appendLine(`token auralMode = "${this.auralMode}"`),typeof this.multiplePerformOperation=="string"&&t.appendLine(`token multiplePerformOperation = "${this.multiplePerformOperation}"`),t.closeBlock()}};let Wr=v_;h(Wr,"global_id",0);let Tf=class mf{constructor(e,t,i){h(this,"x",0);h(this,"y",0);h(this,"z",0);this.x=e,this.y=t,this.z=i}static get up(){return new mf(0,1,0)}static get right(){return new mf(1,0,0)}static get forward(){return new mf(0,0,1)}static get back(){return new mf(0,0,-1)}static get zero(){return new mf(0,0,0)}};var QM=(n=>(n.Play="play",n.Pause="pause",n.Stop="stop",n))(QM||{}),WM=(n=>(n.Spatial="spatial",n.NonSpatial="nonSpatial",n.Ambient="ambient",n))(WM||{});class ni{static sequence(...e){return new th("group_"+th.getId(),e).makeSequence()}static parallel(...e){return new th("group_"+th.getId(),e).makeParallel()}static fadeAction(e,t,i){const s=new Wr(e);return s.tokenId="Visibility",s.type=i?"show":"hide",s.duration=t,s.style="basic",s.motionType="none",s.moveDistance=0,s.easeType="none",s}static startAnimationAction(e,t,i=0,s=1,r=!1,o=!1){const a=new Wr(e);if(a.tokenId="StartAnimation",a.start=t,a.duration=i,a.animationSpeed=s,a.reversed=r,a.pingPong=o,a.multiplePerformOperation="allow",r&&(a.start-=i),o){a.pingPong=!1;const c=a.clone();return c.reversed=!r,c.start=a.start,c.reversed&&(c.start-=i),ni.sequence(a,c)}return a}static waitAction(e){const t=new Wr;return t.tokenId="Wait",t.duration=e,t}static lookAtCameraAction(e,t=9999999999999,i,s){const r=new Wr(e);return r.tokenId="LookAtCamera",r.duration=t,r.front=i??Tf.forward,r.up=s??Tf.up,r}static emphasize(e,t,i=2,s=1,r="basic"){const o=new Wr(e);return o.tokenId="Emphasize",o.duration=t,o.style=r??"basic",o.motionType=JI[i],o.moveDistance=s,o}static transformAction(e,t,i,s,r="inout"){const o=new Wr(e);return o.tokenId="Transform",o.duration=i,o.type=s,o.easeType=r,Array.isArray(t)&&console.error("Transform target must not be an array",t),o.xFormTarget=t,o}static playAudioAction(e,t,i="play",s=1,r="spatial"){const o=new Wr(e);return o.tokenId="Audio",o.type=i,o.audio=t,o.gain=s,o.auralMode=r,o.multiplePerformOperation="allow",o}}class Vte{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 KI extends Vte{constructor(t,i,s,r){super(t);h(this,"matrix");h(this,"material");h(this,"geometry");h(this,"_enableAction");h(this,"_disableAction");this.matrix=i,this.material=s,this.geometry=r}onApply(t){var r,o;const i=this.model;if(!i)return;(r=i.parent)!=null&&r.isDynamic||Cr.createEmptyParent(i);const s=i.clone();this.matrix&&(s.matrix=this.matrix),this.material&&(s.material=this.material),this.geometry&&(s.geometry=this.geometry),(o=i.parent)==null||o.add(s)}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 ZI{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 Hte=Object.defineProperty,Qte=Object.getOwnPropertyDescriptor,xG=(n,e,t,i)=>{for(var s=i>1?void 0:i?Qte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Hte(e,t,s),s};class uv extends Ie{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 t=pt(this.from).clone(),i=pt(this.to).clone(),s=t.distanceTo(i);this._centerPos.copy(t),this._centerPos.add(i),this._centerPos.multiplyScalar(.5),yn(this.gameObject,this.centered?this._centerPos:t),this.gameObject.lookAt(pt(this.to).clone()),this.gameObject.scale.set(this.width,this.width,s)}}xG([x(ne)],uv.prototype,"from",2);xG([x(ne)],uv.prototype,"to",2);var Wte=Object.defineProperty,jte=Object.getOwnPropertyDescriptor,dv=(n,e,t,i)=>{for(var s=i>1?void 0:i?jte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Wte(e,t,s),s};const Zd=re("debuganimation");class no extends Ie{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 t;return(t=this.animations)!=null&&t.length?this.animations[0]:null}set clip(t){if(!this.__didAwake){Zd&&console.warn("Assign clip during serialization",t),this._tempAnimationClipBeforeGameObjectExisted=t;return}t&&(this.gameObject.animations||(this.gameObject.animations=[]),!this.animations.includes(t)&&(this.animations.length>0?this.animations.splice(0,0,t):this.animations.push(t)))}set clips(t){this.animations=t}set animations(t){t==null||!Array.isArray(t)||(this.gameObject?this.gameObject.animations=t:this._tempAnimationsArray=t)}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(t){this._actions=t}awake(){Zd&&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 t;if(this.playAutomatically&&((t=this.animations)==null?void 0:t.length)>0&&this.currentActions.length<=0){const i=Math.floor(Math.random()*this.actions.length);this.play(i)}}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(t){var i;return(i=this.actions)==null?void 0:i.find(s=>s.getClip().name===t)}get isPlaying(){for(let t=0;t<this.actions.length;t++)if(this.actions[t].isRunning())return!0;return!1}play(t=0,i){if(Zd&&console.log("PLAY",t),this.init(),!this.mixer){Zd&&console.warn("Missing mixer",this);return}t===void 0&&(t=0);let s=t;if(typeof t=="number"){if(t>=this.animations.length){Zd&&console.log("No animation at index",t);return}s=this.animations[t]}else typeof t=="string"&&(s=this.animations.find(o=>o.name===t));if(!s){console.error("Could not find clip",t);return}i||(i={}),i.minMaxOffsetNormalized||(i.minMaxOffsetNormalized=this.minMaxOffsetNormalized),i.minMaxSpeed||(i.minMaxSpeed=this.minMaxSpeed),i.loop===void 0&&(i.loop=this.loop),i.clampWhenFinished===void 0&&(i.clampWhenFinished=this.clampWhenFinished);for(const o of this.actions)if(o.getClip()===s)return this.internalOnPlay(o,i);if(!(s instanceof Mr)){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,i)}internalOnPlay(t,i){var s=this.currentAction;if(s===t&&s.isRunning()&&s.time<s.getClip().duration){const c=this.tryFindHandle(t);if(c)return c.getPromise()}const r=(i==null?void 0:i.exclusive)??!0;i!=null&&i.fadeDuration?(r&&(s==null||s.fadeOut(i.fadeDuration)),t.fadeIn(i.fadeDuration)):r&&(s==null||s.stop()),t.reset(),t.enabled=!0,t.time=0,t.timeScale=1;const o=t.getClip();i!=null&&i.minMaxOffsetNormalized&&(t.time=ot.lerp(i.minMaxOffsetNormalized.x,i.minMaxOffsetNormalized.y,Math.random())*o.duration),i!=null&&i.minMaxSpeed&&(t.timeScale=ot.lerp(i.minMaxSpeed.x,i.minMaxSpeed.y,Math.random())),i!=null&&i.clampWhenFinished&&(t.clampWhenFinished=!0),(i==null?void 0:i.startTime)!==void 0&&(t.time=i.startTime),(i==null?void 0:i.loop)!==void 0?t.loop=i.loop?U1:Gg:t.loop=Gg,t.play(),Zd&&console.log("PLAY",t.getClip().name,t);const a=new qte(t,this.mixer,i,c=>{this._handles.splice(this._handles.indexOf(a),1)});return this._handles.push(a),a.getPromise()}tryFindHandle(t){for(const i of this._handles)if(i.action===t)return i}init(){this._didInit||(this._didInit=!0,this.gameObject&&(this.actions=[],this.mixer=new rx(this.gameObject)))}}dv([x()],no.prototype,"playAutomatically",2);dv([x()],no.prototype,"randomStartTime",2);dv([x()],no.prototype,"loop",2);dv([x()],no.prototype,"clampWhenFinished",2);dv([x(Mr)],no.prototype,"clips",1);class qte{constructor(e,t,i,s){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=s,this._options=i}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,i;this.dispose(),(t=this._resolvedOrRejectedCallback)==null||t.call(this,this),(i=this._rejectCallback)==null||i.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 Xte=Object.defineProperty,Yte=Object.getOwnPropertyDescriptor,Th=(n,e,t,i)=>{for(var s=i>1?void 0:i?Yte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Xte(e,t,s),s};class Ih{constructor(){h(this,"time");h(this,"value");h(this,"inTangent");h(this,"inWeight");h(this,"outTangent");h(this,"outWeight");h(this,"weightedMode")}}Th([x()],Ih.prototype,"time",2);Th([x()],Ih.prototype,"value",2);Th([x()],Ih.prototype,"inTangent",2);Th([x()],Ih.prototype,"inWeight",2);Th([x()],Ih.prototype,"outTangent",2);Th([x()],Ih.prototype,"outWeight",2);Th([x()],Ih.prototype,"weightedMode",2);const wG=class{constructor(){h(this,"keys")}get duration(){return!this.keys||this.keys.length==0?0:this.keys[this.keys.length-1].time}evaluate(n){if(!this.keys||this.keys.length==0)return 0;if(this.keys[0].time>=n)return this.keys[0].value;for(let e=0;e<this.keys.length;e++){const t=this.keys[e];if(t.time<=n)if(e+1<this.keys.length){const s=this.keys[e+1];if(s.time<n)continue;return!isFinite(t.outTangent)||!isFinite(s.inTangent)?t.value:wG.interpolateValue(n,t,s)}else return t.value}return this.keys[this.keys.length-1].value}static interpolateValue(n,e,t){const i=e.time,s=e.value,r=e.outTangent,o=t.time,a=t.value,c=t.inTangent,l=o-i,u=l*l,d=u*l,f=((r+c)*l-2*(a-s))/d,p=(3*(a-s)-(c+2*r)*l)/u,m=r,v=s,A=n-i,g=A*A,b=g*A;return f*b+p*g+m*A+v}};let td=wG;Th([x(Ih)],td.prototype,"keys",2);class Jte{constructor(){h(this,"_context")}get context(){return this._context??Lt.Current}get isStateMachineBehaviour(){return!0}}class hb{constructor(e,t,i,s){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=i,this._speed=s}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 SG(n,e){return{name:"",isLooping:!1,guid:(e==null?void 0:e.generateUUID())??As.generateUUID(),index:-1,clip:new Mr(n,1,[])}}var Jl=(n=>(n[n.If=1]="If",n[n.IfNot=2]="IfNot",n[n.Greater=3]="Greater",n[n.Less=4]="Less",n[n.Equals=6]="Equals",n[n.NotEqual=7]="NotEqual",n))(Jl||{}),$I=(n=>(n[n.Float=1]="Float",n[n.Int=3]="Int",n[n.Bool=4]="Bool",n[n.Trigger=9]="Trigger",n))($I||{});const Ao=re("debuganimatorcontroller"),a0=re("debugrootmotion");class Uo{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,Ao&&console.log(this)}static createFromClips(e,t={looping:!1,autoTransition:!0,transitionDuration:0}){const i=[];for(let o=0;o<e.length;o++){const a=e[o],c=[];if(t.autoTransition!==!1){const u=t.transitionDuration??0,d=u/a.duration;let f=o;(t.autoTransition===void 0||t.autoTransition===!0)&&(f=(o+1)%e.length),c.push({exitTime:1-d,offset:0,duration:u,hasExitTime:!0,destinationState:f,conditions:[]})}const l={name:a.name,hash:o,motion:{name:a.name,clip:a,isLooping:(t==null?void 0:t.looping)??!1},transitions:c,behaviours:[]};i.push(l)}const s={name:"AnimatorController",guid:new Vs(Date.now()).generateUUID(),parameters:[],layers:[{name:"Base Layer",stateMachine:{defaultState:0,states:i}}]};return new Uo(s)}play(e,t=-1,i=Number.NEGATIVE_INFINITY,s=0){if(t<0)t=0;else if(t>=this.model.layers.length){console.warn("invalid layer");return}const o=this.model.layers[t].stateMachine;for(const a of o.states)if(a.name===e||a.hash===e){Ao&&console.log("transition to ",a),this.transitionTo(a,s,i);return}console.warn("Could not find "+e+" to play")}reset(){this.setStartTransition()}setBool(e,t){var s,r;const i=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[i]===e).forEach(o=>o.value=t)}getBool(e){var i,s,r;const t=typeof e=="string"?"name":"hash";return((r=(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.find(o=>o[t]===e))==null?void 0:r.value)??!1}setFloat(e,t){var r,o;const i=typeof e=="string"?"name":"hash",s=(o=(r=this.model)==null?void 0:r.parameters)==null?void 0:o.filter(a=>a[i]===e);return s.forEach(a=>a.value=t),(s==null?void 0:s.length)>0}getFloat(e){var i,s,r;const t=typeof e=="string"?"name":"hash";return((r=(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.find(o=>o[t]===e))==null?void 0:r.value)??0}setInteger(e,t){var s,r;const i=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[i]===e).forEach(o=>o.value=t)}getInteger(e){var i,s,r;const t=typeof e=="string"?"name":"hash";return((r=(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.find(o=>o[t]===e))==null?void 0:r.value)??0}setTrigger(e){var i,s;Ao&&console.log("SET TRIGGER",e);const t=typeof e=="string"?"name":"hash";return(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.filter(r=>r[t]===e).forEach(r=>r.value=!0)}resetTrigger(e){var i,s;const t=typeof e=="string"?"name":"hash";return(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.filter(r=>r[t]===e).forEach(r=>r.value=!1)}getTrigger(e){var i,s,r;const t=typeof e=="string"?"name":"hash";return((r=(s=(i=this.model)==null?void 0:i.parameters)==null?void 0:s.find(o=>o[t]===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 i of t.stateMachine.states)if(i.name===e||i.hash==e)return i}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 rx(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=QA(this.model,(i,s,r)=>r==null?!0:!(r.type==="Object3D"||r.isObject3D===!0||qF(r)||r.tracks!==void 0));return console.assert(e!==this.model),new Uo(e)}update(e){var i,s;if(!this.animator)return;this.evaluateTransitions(),this.updateActiveStates(e);const t=this.animator.context.time.deltaTime;this.animator.applyRootMotion&&((i=this.rootMotionHandler)==null||i.onBeforeUpdate(e)),this._mixer.update(t),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 i=this._activeStates[t],s=i.motion;if(!s.action)this._activeStates.splice(t,1),t--;else{const r=s.action;r.weight=e,r.getEffectiveWeight()<=0&&!r.isRunning()&&(Ao&&console.debug("REMOVE",i.name,r.getEffectiveWeight(),r.isRunning(),r.isScheduled()),this._activeStates.splice(t,1),t--)}}}setStartTransition(){for(const e of this.model.layers){const t=e.stateMachine;t.defaultState===void 0&&(Ao&&console.warn("AnimatorController default state is undefined, will assign state 0 as default",e),t.defaultState=0);const i=t.states[t.defaultState];this.transitionTo(i,0,this.normalizedStartOffset)}}evaluateTransitions(){var r;let e=!1;if(!this._activeState){if(this.setStartTransition(),!this._activeState)return;e=!0}const t=this._activeState,i=t.motion.action;for(const o of t.transitions){if(!o.hasExitTime&&o.conditions.length<=0)continue;let a=!0;for(const c of o.conditions)if(!this.evaluateCondition(c)){a=!1;break}if(a)if(i){const c=t.motion.clip.duration,l=c<=0?1:Math.abs(i.time/c);let u=!1;if(o.hasExitTime?i.timeScale>0?u=l>=o.exitTime:i.timeScale<0&&(u=1-l>=o.exitTime):u=!0,u){for(const d of o.conditions){const f=this.model.parameters.find(p=>p.name===d.parameter);(f==null?void 0:f.type)===$I.Trigger&&f.value&&(f.value=!1)}i.clampWhenFinished=!0,Ao&&console.log("transition to "+o.destinationState,o,l,o.exitTime,o.hasExitTime),this.transitionTo(o.destinationState,o.duration,o.offset);return}}else{this.transitionTo(o.destinationState,o.duration,o.offset);return}}if(i){let o=t.speed??1;t.speedParameter&&(o*=this.getFloat(t.speedParameter)),o!==void 0&&(i.timeScale=o*this._speed)}let s=!1;if(t.motion.isLooping&&i&&(i.time>=i.getClip().duration?(s=!0,i.reset(),i.time=0,i.play()):i.time<=0&&i.timeScale<0&&(s=!0,i.reset(),i.time=i.getClip().duration,i.play())),!s&&t&&!e&&i&&this.animator&&t.behaviours){const o=i==null?void 0:i.getClip().duration,a=i.time/o,c=new hb(this._activeState,a,o,this._speed);for(const l of t.behaviours)l.instance&&((r=l.instance.onStateUpdate)==null||r.call(l.instance,this.animator,c,0))}}getState(e,t){return typeof e=="number"&&(e==-1&&(e=this.model.layers[t].stateMachine.defaultState,e===void 0&&(Ao&&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,i){var l,u,d,f,p,m,v,A;if(!this.animator)return;const s=0;if(e=this.getState(e,s),!(e!=null&&e.motion)||!e.motion.clip||!(e.motion.clip instanceof Mr))return;const r=this._activeState===e;if(r){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((l=this._activeState)!=null&&l.behaviours&&this._activeState.motion.action){const g=(u=this._activeState)==null?void 0:u.motion.clip.duration,b=this._activeState.motion.action.time/g,y=new hb(this._activeState,b,g,this._speed);for(const _ of this._activeState.behaviours)(f=(d=_.instance)==null?void 0:d.onStateExit)==null||f.call(_.instance,this.animator,y,s)}const o=(p=this._activeState)==null?void 0:p.motion.action;o&&o.fadeOut(t),r&&(e.motion.action=e.motion.action_loopback,e.motion.action_loopback=o);const a=this._activeState;this._activeState=e;const c=(m=e.motion)==null?void 0:m.action;if(c){if(i=Math.max(0,Math.min(1,i)),e.cycleOffsetParameter){let b=this.getFloat(e.cycleOffsetParameter);typeof b=="number"?(b<0&&(b+=1),i+=b,i%=1):Ao&&console.warn("AnimatorController cycle offset parameter is not a number",e.cycleOffsetParameter)}else typeof e.cycleOffset=="number"&&(i+=e.cycleOffset,i%=1);c.isRunning()&&c.stop(),c.reset(),c.enabled=!0;const g=e.motion.clip.duration;if(c.time=r?0:i*g,c.timeScale<0&&(c.time=g-c.time),c.clampWhenFinished=!0,c.setLoop(Gg,0),t>0?c.fadeIn(t):c.weight=1,c.play(),this.rootMotionHandler&&this.rootMotionHandler.onStart(c),this._activeStates.includes(e)||this._activeStates.push(e),this._activeState.behaviours){const b=new hb(e,i,g,this._speed);for(const y of this._activeState.behaviours)(A=(v=y.instance)==null?void 0:v.onStateEnter)==null||A.call(y.instance,this.animator,b,s)}}else Ao&&(e.__warned_no_motion||(e.__warned_no_motion=!0,console.warn("No action",e.motion,this)));Ao&&console.log("TRANSITION FROM "+(a==null?void 0:a.name)+" TO "+e.name,t,o,c,c==null?void 0:c.getEffectiveTimeScale(),c==null?void 0:c.getEffectiveWeight(),c==null?void 0:c.isRunning(),c==null?void 0:c.isScheduled(),c==null?void 0:c.paused)}createAction(e){var i,s;if(this._mixer.existingAction(e)&&this._mixer.uncacheAction(e,(i=this.animator)==null?void 0:i.gameObject),(s=this.animator)!=null&&s.applyRootMotion){this.rootMotionHandler||(this.rootMotionHandler=new Kte(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(i=>i.name===e.parameter);if(!t)return!1;switch(e.mode){case Jl.If:return t.value===e.threshold;case Jl.IfNot:return t.value===e.threshold;case Jl.Greater:return t.value>e.threshold;case Jl.Less:return t.value<e.threshold;case Jl.Equals:return t.value===e.threshold;case Jl.NotEqual:return t.value!==e.threshold}return!1}createActions(e){var t,i;for(const s of this.model.layers){const r=s.stateMachine;for(let o=0;o<r.states.length;o++){const a=r.states[o];a.transitions||(a.transitions=[]);for(const c of a.transitions)c.conditions||(c.conditions=[]);if(a.motion||(a.motion=SG(a.name)),this.animator&&a.motion.clips){const c=(t=a.motion.clips)==null?void 0:t.find(l=>{var u,d;return l.node.name===((d=(u=this.animator)==null?void 0:u.gameObject)==null?void 0:d.name)});a.motion.clip=c==null?void 0:c.clip}if(!a.motion.clip){const c=new Mr(void 0,void 0,[]);a.motion.clip=c}if((i=a.motion)!=null&&i.clip){const c=a.motion.clip;if(c instanceof Mr){const l=this.createAction(c);a.motion.action=l}else(Ao||Vt())&&console.warn("No valid animationclip assigned",a)}if(a.behaviours&&Array.isArray(a.behaviours))for(const c of a.behaviours){if(!(c!=null&&c.typeName))continue;const l=Y.get(c.typeName),u=new l;u.isStateMachineBehaviour&&(u._context=this.context??void 0,hp(u,c.properties),c.instance=u),Ao&&console.log("Created animator controller behaviour",a.name,c.typeName,c.properties,u)}}}}*enumerateActions(){if(this.model.layers)for(const e of this.model.layers){const t=e.stateMachine;for(let i=0;i<t.states.length;i++){const s=t.states[i];s!=null&&s.motion&&(s.motion.action&&(yield s.motion.action),s.motion.action_loopback&&(yield s.motion.action_loopback))}}}}class ck{constructor(e,t){h(this,"track");h(this,"createdInterpolant");h(this,"originalEvaluate");h(this,"customEvaluate");this.track=e;const i=e,s=i.createInterpolant.bind(e);i.createInterpolant=()=>(i.createInterpolant=s,this.createdInterpolant=s(),this.originalEvaluate=this.createdInterpolant.evaluate.bind(this.createdInterpolant),this.customEvaluate=r=>{if(!this.originalEvaluate)return;const o=this.originalEvaluate(r);return t(r,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 Nn=class{constructor(e,t,i,s,r){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 Ce);h(this,"_prevTime",0);if(this.context=e,this.root=t,this.clip=i,Nn.firstKeyframeRotation[this.cacheId]||(Nn.firstKeyframeRotation[this.cacheId]=new Ce),r){const o=r.values;Nn.firstKeyframeRotation[this.cacheId].set(o[0],o[1],o[2],o[3])}Nn.spaceRotation[this.cacheId]||(Nn.spaceRotation[this.cacheId]=new Ce),Nn.effectiveSpaceRotation[this.cacheId]||(Nn.effectiveSpaceRotation[this.cacheId]=new Ce),Nn.clipOffsetRotation[this.cacheId]=new Ce,r&&Nn.clipOffsetRotation[this.cacheId].set(r.values[0],r.values[1],r.values[2],r.values[3]).invert(),this.handlePosition(i,s),this.handleRotation(i,r)}set action(e){this._action=e}get action(){return this._action}get cacheId(){return this.root.uuid}onStart(e){if(e.getClip()!==this.clip)return;Nn.lastObjRotation[this.cacheId]||(Nn.lastObjRotation[this.cacheId]=this.root.quaternion.clone());const t=Nn.lastObjRotation[this.cacheId];if(Nn.spaceRotation[this.cacheId].copy(t),a0){const i=new Gn().setFromQuaternion(t);console.log("START",this.clip.name,ot.toDegrees(i.y),this.root.position.z)}}getClipRotationOffset(){return Nn.clipOffsetRotation[this.cacheId]}handlePosition(e,t){if(t){const i=this.root;a0&&i.add(new wp),Nn.lastObjPosition[this.cacheId]||(Nn.lastObjPosition[this.cacheId]=this.root.position.clone());const s=new w,r=new w;this.positionWrapper=new ck(t,(o,a)=>{const c=this.action.getEffectiveWeight();return a0&&i.position.length()>8&&i.position.set(0,i.position.y,0),o>this._prevTime&&(s.set(a[0],a[1],a[2]),s.sub(r),s.multiplyScalar(c),s.applyQuaternion(this.getClipRotationOffset()),s.applyQuaternion(i.quaternion),this.positionChange.copy(s)),r.fromArray(a),this._prevTime=o,a[0]=0,a[1]=0,a[2]=0,a})}}handleRotation(e,t){if(t){if(a0){const o=t.values,a=new Gn().setFromQuaternion(new Ce(o[0],o[1],o[2],o[3]));console.log(e.name,t.name,"FIRST ROTATION IN TRACK",ot.toDegrees(a.y));const c=t.values.length-4,l=new Ce().set(o[c],o[c+1],o[c+2],o[c+3]),u=new Gn().setFromQuaternion(l);console.log(e.name,t.name,"LAST ROTATION IN TRACK",ot.toDegrees(u.y))}let i=0;const s=new Ce,r=new Ce;this.rotationWrapper=new ck(t,(o,a)=>(o>i&&(r.set(a[0],a[1],a[2],a[3]),s.invert(),r.multiply(s),this.rotationChange.copy(r)),s.fromArray(a),i=o,a[0]=0,a[1]=0,a[2]=0,a[3]=1,a))}}onBeforeUpdate(e){this.positionChange.set(0,0,0),this.rotationChange.set(0,0,0,1)}onAfterUpdate(e){return!this.action||(e*=this.action.getEffectiveWeight(),e<=0)?!1:(this.positionChange.multiplyScalar(e),this.rotationChange.slerp(Nn.identityQuaternion,1-e),!0)}};let Ra=Nn;h(Ra,"lastObjPosition",{}),h(Ra,"lastObjRotation",{}),h(Ra,"firstKeyframeRotation",{}),h(Ra,"spaceRotation",{}),h(Ra,"effectiveSpaceRotation",{}),h(Ra,"clipOffsetRotation",{}),h(Ra,"identityQuaternion",new Ce);class Kte{constructor(e){h(this,"controller");h(this,"handler",[]);h(this,"root");h(this,"basePosition",new w);h(this,"baseQuaternion",new Ce);h(this,"baseRotation",new Gn);h(this,"summedPosition",new w);h(this,"summedRotation",new Ce);this.controller=e}createClip(e,t,i){this.root=t,t&&"name"in t&&t.name;const s=this.findRootTrack(i,".position"),r=this.findRootTrack(i,".quaternion"),o=new Ra(this.controller.context,t,i,s,r);this.handler.push(o);const a=e.clipAction(i);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 i=e.tracks;if(!i)return null;for(const s of i)if(s.name.endsWith(t))return s;return null}}class Zte extends Al{onSerialize(e,t){}onDeserialize(e,t){if(t.type===Uo&&(e==null?void 0:e.__type)==="AnimatorController")return new Uo(e)}}new Zte(Uo);class $te extends pn{constructor(e,t=1,i=16,s=2){const r=new At,o=i+s*2,a=new Float32Array((o*3+3)*3);r.setAttribute("position",new Ke(a,3));const c=new xn({color:65280}),l=new xn({color:16776960});super(r,[l,c]),this.audio=e,this.range=t,this.divisionsInnerAngle=i,this.divisionsOuterAngle=s,this.type="PositionalAudioHelper",this.update()}update(){const e=this.audio,t=this.range,i=this.divisionsInnerAngle,s=this.divisionsOuterAngle,r=As.degToRad(e.panner.coneInnerAngle),o=As.degToRad(e.panner.coneOuterAngle),a=r/2,c=o/2;let l=0,u=0,d,f;const p=this.geometry,m=p.attributes.position;p.clearGroups();function v(A,g,b,y){const _=(g-A)/b;for(m.setXYZ(l,0,0,0),u++,d=A;d<g;d+=_)f=l+u,m.setXYZ(f,Math.sin(d)*t,0,Math.cos(d)*t),m.setXYZ(f+1,Math.sin(Math.min(d+_,g))*t,0,Math.cos(Math.min(d+_,g))*t),m.setXYZ(f+2,0,0,0),u+=3;p.addGroup(l,u,y),l+=u,u=0}v(-c,-a,s,0),v(-a,a,i,1),v(a,c,s,0),m.needsUpdate=!0,r===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,bl=(n,e,t,i)=>{for(var s=i>1?void 0:i?tie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&eie(e,t,s),s};const cs=re("debugaudio");let o_=!1;const a_=[];function Gx(){if(o_)return;Vt()&&console.log("User interaction registered: audio can now be played"),o_=!0;const n=[...a_];a_.length=0,n.forEach(e=>e())}document.addEventListener("pointerdown",Gx);document.addEventListener("click",Gx);document.addEventListener("dragstart",Gx);document.addEventListener("touchstart",Gx);const Ic=class extends Ie{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||gl())&&(this.wasPlaying=this.isPlaying,this.isPlaying&&this.pause());break;case"visible":cs&&console.log("visible",this.enabled,this.playOnAwake,!this.isPlaying,Ic.userInteractionRegistered,this.wasPlaying),this.enabled&&this.playOnAwake&&!this.isPlaying&&Ic.userInteractionRegistered&&this.wasPlaying&&this.play();break}});h(this,"onApplicationMuteChanged",()=>{var e,t;this.context.application.muted?(e=this.sound)==null||e.setVolume(0):(t=this.sound)==null||t.setVolume(this.volume)});h(this,"lerp",(e,t,i)=>e*(1-i)+t*i);h(this,"createAudio",e=>{cs&&console.log("audio buffer loaded"),Ic.registerWaitForAllowAudio(()=>{cs&&console.log("finished loading",e);const t=this.Sound;if(!t){console.warn("Failed getting sound",this.name);return}t.isPlaying&&t.stop(),e&&t.setBuffer(e),t.loop=this._loop,this.context.application.muted?t.setVolume(0):t.setVolume(this.volume),t.autoplay=this.shouldPlay,this.applySpatialDistanceSettings(),t.isPlaying&&t.stop(),cs&&console.log(this.name,this.shouldPlay,Ic.userInteractionRegistered,this),this.shouldPlay&&Ic.userInteractionRegistered&&this.play()})});h(this,"_lastContextTime",0);h(this,"_hasEnded",!0);h(this,"_needUpdateSpatialDistanceSettings",!1)}static get userInteractionRegistered(){return o_}static registerWaitForAllowAudio(e){if(e!==null){if(o_){e();return}a_.indexOf(e)===-1&&a_.push(e)}}get loop(){return this.sound&&(this._loop=this.sound.getLoop()),this._loop}set loop(e){this._loop=e,this.sound&&this.sound.setLoop(e)}get spatialBlend(){return this._spatialBlend}set spatialBlend(e){e!==this._spatialBlend&&(this._spatialBlend=e,this._needUpdateSpatialDistanceSettings=!0)}get minDistance(){return this._minDistance}set minDistance(e){this._minDistance!==e&&(this._minDistance=e,this._needUpdateSpatialDistanceSettings=!0)}get maxDistance(){return this._maxDistance}set maxDistance(e){this._maxDistance!==e&&(this._maxDistance=e,this._needUpdateSpatialDistanceSettings=!0)}get volume(){return this._volume}set volume(e){this._volume=e,this.sound&&!this.context.application.muted&&(cs&&console.log(this.name,"audio set volume",e),this.sound.setVolume(e))}get Sound(){if(!this.sound&&Ic.userInteractionRegistered){let e=ne.getComponent(this.context.mainCamera,ah)??ne.findObjectOfType(ah,this.context);!e&&this.context.mainCamera&&(e=ne.addNewComponent(this.context.mainCamera,ah)),e!=null&&e.listener?(this.sound=new bF(e.listener),this.gameObject.add(this.sound)):cs&&console.warn("No audio listener found in scene - can not play audio")}return this.sound}get ShouldPlay(){return this.shouldPlay}awake(){cs&&console.log(this),this.audioLoader=new Rb,this.playOnAwake&&(this.shouldPlay=!0)}onEnable(){Ic.userInteractionRegistered?this.playOnAwake&&this.context.application.isVisible&&this.play():Ic.registerWaitForAllowAudio(()=>{this.enabled&&!this.destroyed&&this.shouldPlay&&this.onNewClip(this.clip)}),globalThis.addEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.addEventListener(Xb.MuteChanged,this.onApplicationMuteChanged)}onDisable(){globalThis.removeEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.removeEventListener(Xb.MuteChanged,this.onApplicationMuteChanged),this.pause()}applySpatialDistanceSettings(){const e=this.sound;if(!e)return;this._needUpdateSpatialDistanceSettings=!1;const t=this.lerp(10*this._maxDistance/Math.max(1e-4,this.spatialBlend),this._minDistance,this.spatialBlend);switch(cs&&console.log(this.name,this._minDistance,this._maxDistance,this.spatialBlend,"Ref distance="+t),e.setRefDistance(t),e.setMaxDistance(Math.max(.01,this._maxDistance)),this.rollOffMode){case 0:e.setDistanceModel("exponential");break;case 1:e.setDistanceModel("linear");break}this.spatialBlend>0?cs&&!this.helper&&(this.helper=new $te(e,e.getRefDistance()),e.add(this.helper)):this.helper&&this.helper.parent&&this.helper.removeFromParent()}onNewClip(e){if(e&&(this.clip=e),typeof e=="string")if(cs&&console.log(e),e.endsWith(".mp3")||e.endsWith(".wav")){if(this.audioLoader||(this.audioLoader=new Rb),this.shouldPlay=!0,this._lastClipStartedLoading===e){cs&&console.log("Is currently loading:",this._lastClipStartedLoading,this);return}this._lastClipStartedLoading=e,cs&&console.log("load audio",e),this.audioLoader.load(e,this.createAudio,()=>{},console.error)}else console.warn("Unsupported audio clip type",e);else this.shouldPlay=!0,this.createAudio()}play(e=void 0){var i,s;!e&&this.clip&&(e=this.clip),e!==void 0&&typeof e!="string"&&!(e instanceof MediaStream)&&(Vt()&&console.warn("Called play on AudioSource with unknown argument type:",e+`
|
|
5096
5096
|
Using the assigned clip instead:`,this.clip),e=this.clip);let t=!this.sound||e&&e!==this.clip;if(typeof e=="string"&&!this.audioLoader&&(t=!0),(e instanceof MediaStream||typeof e=="string")&&(this.clip=e),t){this.shouldPlay=!0,this.onNewClip(e);return}if(this.shouldPlay=!0,this._hasEnded=!1,cs&&console.log("play",(i=this.sound)==null?void 0:i.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||(s=this.context.domElement.shadowRoot)==null||s.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 e,t;cs&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.isPlaying&&this.sound.source&&(this._lastContextTime=(e=this.sound)==null?void 0:e.context.currentTime,this.sound.pause()),(t=this._audioElement)==null||t.remove()}stop(){var e,t;cs&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.source&&(this._lastContextTime=(e=this.sound)==null?void 0:e.context.currentTime,cs&&console.log(this._lastContextTime),this.sound.stop()),(t=this._audioElement)==null||t.remove()}get isPlaying(){var e;return((e=this.sound)==null?void 0:e.isPlaying)??!1}set isPlaying(e){}get time(){var e,t;return(e=this.sound)!=null&&e.source?((t=this.sound.source)==null?void 0:t.context.currentTime)-this._lastContextTime+this.sound.offset:0}set time(e){if(this.sound){if(e===this.sound.offset)return;const t=this.isPlaying;this.stop(),this.sound.offset=e,t&&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,cs&&console.log("Audio clip ended",this.clip),this.sound.dispatchEvent({type:"ended",target:this}))}};let Sn=Ic;bl([x(URL)],Sn.prototype,"clip",2);bl([x()],Sn.prototype,"playOnAwake",2);bl([x()],Sn.prototype,"loop",1);bl([x()],Sn.prototype,"spatialBlend",1);bl([x()],Sn.prototype,"minDistance",1);bl([x()],Sn.prototype,"maxDistance",1);bl([x()],Sn.prototype,"volume",1);bl([x()],Sn.prototype,"rollOffMode",2);bl([x()],Sn.prototype,"playInBackground",2);var iie=Object.defineProperty,nie=Object.getOwnPropertyDescriptor,sie=(n,e,t,i)=>{for(var s=i>1?void 0:i?nie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&iie(e,t,s),s};class fv extends Ie{constructor(){super(...arguments);h(this,"constraintActive",!0);h(this,"locked",!1);h(this,"sources",[])}}sie([x(_e)],fv.prototype,"sources",2);const lk={type:"change"},_C={type:"start"},hk={type:"end"};let rie=class extends Wn{constructor(e,t){super(),this.object=e,this.domElement=t,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:hu.ROTATE,MIDDLE:hu.DOLLY,RIGHT:hu.PAN},this.touches={ONE:uu.ROTATE,TWO:uu.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 a.phi},this.getAzimuthalAngle=function(){return a.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(J){J.addEventListener("keydown",Tt),this._domElementKeyEvents=J},this.stopListenToKeyEvents=function(){this._domElementKeyEvents.removeEventListener("keydown",Tt),this._domElementKeyEvents=null},this.saveState=function(){i.target0.copy(i.target),i.position0.copy(i.object.position),i.zoom0=i.object.zoom},this.reset=function(){i.target.copy(i.target0),i.object.position.copy(i.position0),i.object.zoom=i.zoom0,i.object.updateProjectionMatrix(),i.dispatchEvent(lk),i.update(),r=s.NONE},this.update=function(){const J=new w,de=new Ce().setFromUnitVectors(e.up,new w(0,1,0)),ce=de.clone().invert(),je=new w,Xe=new Ce,He=new w,ke=2*Math.PI;return function(){const bt=i.object.getWorldPosition(e.position);J.copy(bt).sub(i.target),J.applyQuaternion(de),a.setFromVector3(J),i.autoRotate&&r===s.NONE&&I(R()),i.enableDamping?(a.theta+=c.theta*i.dampingFactor,a.phi+=c.phi*i.dampingFactor):(a.theta+=c.theta,a.phi+=c.phi);let wt=i.minAzimuthAngle,ee=i.maxAzimuthAngle;return isFinite(wt)&&isFinite(ee)&&(wt<-Math.PI?wt+=ke:wt>Math.PI&&(wt-=ke),ee<-Math.PI?ee+=ke:ee>Math.PI&&(ee-=ke),wt<=ee?a.theta=Math.max(wt,Math.min(ee,a.theta)):a.theta=a.theta>(wt+ee)/2?Math.max(wt,a.theta):Math.min(ee,a.theta)),a.phi=Math.max(i.minPolarAngle,Math.min(i.maxPolarAngle,a.phi)),a.makeSafe(),i.enableDamping?u=As.lerp(u,l,i.dampingFactor):u=l,a.radius*=u,a.radius=Math.max(i.minDistance,Math.min(i.maxDistance,a.radius)),i.enableDamping===!0?i.target.addScaledVector(d,i.dampingFactor):i.target.add(d),J.setFromSpherical(a),J.applyQuaternion(ce),bt.copy(i.target).add(J),i.object.parent?i.object.parent.worldToLocal(bt):i.object.position.copy(bt),i.object.lookAt(i.target),i.enableDamping===!0?(c.theta*=1-i.dampingFactor,c.phi*=1-i.dampingFactor,d.multiplyScalar(1-i.dampingFactor)):(c.set(0,0,0),d.set(0,0,0)),l=1,f||je.distanceToSquared(i.object.position)>o||8*(1-Xe.dot(i.object.quaternion))>o||He.distanceToSquared(i.target)>0?(i.dispatchEvent(lk),je.copy(i.object.position),Xe.copy(i.object.quaternion),He.copy(i.target),f=!1,!0):!1}}(),this.dispose=function(){i.domElement.removeEventListener("contextmenu",k),i.domElement.removeEventListener("pointerdown",Le),i.domElement.removeEventListener("pointercancel",et),i.domElement.removeEventListener("wheel",vt),i.domElement.removeEventListener("pointermove",Se),i.domElement.removeEventListener("pointerup",et),i._domElementKeyEvents!==null&&(i._domElementKeyEvents.removeEventListener("keydown",Tt),i._domElementKeyEvents=null)};const i=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 o=1e-6,a=new HE,c=new HE;let l=1,u=1;const d=new w;let f=!1;const p=new te,m=new te,v=new te,A=new te,g=new te,b=new te,y=new te,_=new te,E=new te,M=[],T={};function R(){return 2*Math.PI/60/60*i.autoRotateSpeed}function C(){return Math.pow(.95,i.zoomSpeed)}function I(J){c.theta-=J}function D(J){c.phi-=J}const W=function(){const J=new w;return function(ce,je){J.setFromMatrixColumn(je,0),J.multiplyScalar(-ce),d.add(J)}}(),F=function(){const J=new w;return function(ce,je){i.screenSpacePanning===!0?J.setFromMatrixColumn(je,1):(J.setFromMatrixColumn(je,0),J.crossVectors(i.object.up,J)),J.multiplyScalar(ce),d.add(J)}}(),V=function(){const J=new w,de=new w;return function(je,Xe){const He=i.domElement;if(i.object.isPerspectiveCamera){i.object.getWorldPosition(de),J.copy(de).sub(i.target);let ke=J.length();ke*=Math.tan(i.object.fov/2*Math.PI/180),W(2*je*ke/He.clientHeight,i.object.matrixWorld),F(2*Xe*ke/He.clientHeight,i.object.matrixWorld)}else i.object.isOrthographicCamera?(W(je*(i.object.right-i.object.left)/i.object.zoom/He.clientWidth,i.object.matrixWorld),F(Xe*(i.object.top-i.object.bottom)/i.object.zoom/He.clientHeight,i.object.matrixWorld)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),i.enablePan=!1)}}();function j(J){i.object.isPerspectiveCamera?l/=J:i.object.isOrthographicCamera?(i.object.zoom=Math.max(i.minZoom,Math.min(i.maxZoom,i.object.zoom*J)),i.object.updateProjectionMatrix(),f=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),i.enableZoom=!1)}function U(J){i.object.isPerspectiveCamera?l*=J:i.object.isOrthographicCamera?(i.object.zoom=Math.max(i.minZoom,Math.min(i.maxZoom,i.object.zoom/J)),i.object.updateProjectionMatrix(),f=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),i.enableZoom=!1)}function L(J){p.set(J.clientX,J.clientY)}function G(J){y.set(J.clientX,J.clientY)}function $(J){A.set(J.clientX,J.clientY)}function Z(J){m.set(J.clientX,J.clientY),v.subVectors(m,p).multiplyScalar(i.rotateSpeed);const de=i.domElement;I(2*Math.PI*v.x/de.clientHeight),D(2*Math.PI*v.y/de.clientHeight),p.copy(m),i.update()}function q(J){_.set(J.clientX,J.clientY),E.subVectors(_,y),E.y>0?j(C()):E.y<0&&U(C()),y.copy(_),i.update()}function ie(J){g.set(J.clientX,J.clientY),b.subVectors(g,A).multiplyScalar(i.panSpeed),V(b.x,b.y),A.copy(g),i.update()}function pe(J){J.deltaY<0?U(C()):J.deltaY>0&&j(C()),i.update()}function Ae(J){let de=!1;switch(J.code){case i.keys.UP:J.ctrlKey||J.metaKey||J.shiftKey?D(2*Math.PI*i.rotateSpeed/i.domElement.clientHeight):V(0,i.keyPanSpeed),de=!0;break;case i.keys.BOTTOM:J.ctrlKey||J.metaKey||J.shiftKey?D(-2*Math.PI*i.rotateSpeed/i.domElement.clientHeight):V(0,-i.keyPanSpeed),de=!0;break;case i.keys.LEFT:J.ctrlKey||J.metaKey||J.shiftKey?I(2*Math.PI*i.rotateSpeed/i.domElement.clientHeight):V(i.keyPanSpeed,0),de=!0;break;case i.keys.RIGHT:J.ctrlKey||J.metaKey||J.shiftKey?I(-2*Math.PI*i.rotateSpeed/i.domElement.clientHeight):V(-i.keyPanSpeed,0),de=!0;break}de&&(J.preventDefault(),i.update())}function Ee(){if(M.length===1)p.set(M[0].pageX,M[0].pageY);else{const J=.5*(M[0].pageX+M[1].pageX),de=.5*(M[0].pageY+M[1].pageY);p.set(J,de)}}function Me(){if(M.length===1)A.set(M[0].pageX,M[0].pageY);else{const J=.5*(M[0].pageX+M[1].pageX),de=.5*(M[0].pageY+M[1].pageY);A.set(J,de)}}function Ge(){const J=M[0].pageX-M[1].pageX,de=M[0].pageY-M[1].pageY,ce=Math.sqrt(J*J+de*de);y.set(0,ce)}function Qe(){i.enableZoom&&Ge(),i.enablePan&&Me()}function ut(){i.enableZoom&&Ge(),i.enableRotate&&Ee()}function Mt(J){if(M.length==1)m.set(J.pageX,J.pageY);else{const ce=Ue(J),je=.5*(J.pageX+ce.x),Xe=.5*(J.pageY+ce.y);m.set(je,Xe)}v.subVectors(m,p).multiplyScalar(i.rotateSpeed);const de=i.domElement;I(2*Math.PI*v.x/de.clientHeight),D(2*Math.PI*v.y/de.clientHeight),p.copy(m)}function nt(J){if(M.length===1)g.set(J.pageX,J.pageY);else{const de=Ue(J),ce=.5*(J.pageX+de.x),je=.5*(J.pageY+de.y);g.set(ce,je)}b.subVectors(g,A).multiplyScalar(i.panSpeed),V(b.x,b.y),A.copy(g)}function X(J){const de=Ue(J),ce=J.pageX-de.x,je=J.pageY-de.y,Xe=Math.sqrt(ce*ce+je*je);_.set(0,Xe),E.set(0,Math.pow(_.y/y.y,i.zoomSpeed)),j(E.y),y.copy(_)}function Fe(J){i.enableZoom&&X(J),i.enablePan&&nt(J)}function ve(J){i.enableZoom&&X(J),i.enableRotate&&Mt(J)}function Le(J){i.enabled!==!1&&(M.length===0&&(i.domElement.addEventListener("pointermove",Se),i.domElement.addEventListener("pointerup",et)),he(J),J.pointerType==="touch"?Kt(J):qe(J))}function Se(J){i.enabled!==!1&&(J.pointerType==="touch"?H(J):Ye(J))}function et(J){Pe(J),M.length===0&&(i.domElement.removeEventListener("pointermove",Se),i.domElement.removeEventListener("pointerup",et)),i.dispatchEvent(hk),r=s.NONE}function qe(J){let de;switch(J.button){case 0:de=i.mouseButtons.LEFT;break;case 1:de=i.mouseButtons.MIDDLE;break;case 2:de=i.mouseButtons.RIGHT;break;default:de=-1}switch(de){case hu.DOLLY:if(i.enableZoom===!1)return;G(J),r=s.DOLLY;break;case hu.ROTATE:if(J.ctrlKey||J.metaKey||J.shiftKey){if(i.enablePan===!1)return;$(J),r=s.PAN}else{if(i.enableRotate===!1)return;L(J),r=s.ROTATE}break;case hu.PAN:if(J.ctrlKey||J.metaKey||J.shiftKey){if(i.enableRotate===!1)return;L(J),r=s.ROTATE}else{if(i.enablePan===!1)return;$(J),r=s.PAN}break;default:r=s.NONE}r!==s.NONE&&i.dispatchEvent(_C)}function Ye(J){switch(r){case s.ROTATE:if(i.enableRotate===!1)return;Z(J);break;case s.DOLLY:if(i.enableZoom===!1)return;q(J);break;case s.PAN:if(i.enablePan===!1)return;ie(J);break}}function vt(J){i.enabled===!1||i.enableZoom===!1||r!==s.NONE||(J.preventDefault(),i.dispatchEvent(_C),pe(J),i.dispatchEvent(hk))}function Tt(J){i.enabled===!1||i.enablePan===!1||Ae(J)}function Kt(J){switch(Be(J),M.length){case 1:switch(i.touches.ONE){case uu.ROTATE:if(i.enableRotate===!1)return;Ee(),r=s.TOUCH_ROTATE;break;case uu.PAN:if(i.enablePan===!1)return;Me(),r=s.TOUCH_PAN;break;default:r=s.NONE}break;case 2:switch(i.touches.TWO){case uu.DOLLY_PAN:if(i.enableZoom===!1&&i.enablePan===!1)return;Qe(),r=s.TOUCH_DOLLY_PAN;break;case uu.DOLLY_ROTATE:if(i.enableZoom===!1&&i.enableRotate===!1)return;ut(),r=s.TOUCH_DOLLY_ROTATE;break;default:r=s.NONE}break;default:r=s.NONE}r!==s.NONE&&i.dispatchEvent(_C)}function H(J){switch(Be(J),r){case s.TOUCH_ROTATE:if(i.enableRotate===!1)return;Mt(J),i.update();break;case s.TOUCH_PAN:if(i.enablePan===!1)return;nt(J),i.update();break;case s.TOUCH_DOLLY_PAN:if(i.enableZoom===!1&&i.enablePan===!1)return;Fe(J),i.update();break;case s.TOUCH_DOLLY_ROTATE:if(i.enableZoom===!1&&i.enableRotate===!1)return;ve(J),i.update();break;default:r=s.NONE}}function k(J){i.enabled!==!1&&J.preventDefault()}function he(J){M.push(J)}function Pe(J){delete T[J.pointerId];for(let de=0;de<M.length;de++)if(M[de].pointerId==J.pointerId){M.splice(de,1);return}}function Be(J){let de=T[J.pointerId];de===void 0&&(de=new te,T[J.pointerId]=de),de.set(J.pageX,J.pageY)}function Ue(J){const de=J.pointerId===M[0].pointerId?M[1]:M[0];return T[de.pointerId]}i.domElement.addEventListener("contextmenu",k),i.domElement.addEventListener("pointerdown",Le),i.domElement.addEventListener("pointercancel",et),i.domElement.addEventListener("wheel",vt,{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,i,s,r=null){this.controller=t,this.handModel=e,this.bones=[],r===null&&(r=new Rp,r.setPath(i||oie)),r.load(`${s}.glb`,o=>{const a=o.scene.children[0];this.handModel.add(a),a.layers.mask=this.handModel.layers.mask;const c=a.getObjectByProperty("type","SkinnedMesh");c.frustumCulled=!1,c.castShadow=!0,c.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(u=>{const d=a.getObjectByName(u);d!==void 0?d.jointName=u:console.warn(`Couldn't find ${u} in ${s} hand mesh`),this.bones.push(d)})})}updateMesh(){const e=this.controller.joints;for(let t=0;t<this.bones.length;t++){const i=this.bones[t];if(i){const s=e[i.jointName];if(s.visible){const r=s.position;i.position.copy(r),i.quaternion.copy(s.quaternion)}}}}}const cie=.01,lie="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",i=>{const s=i.data;s.hand&&!this.motionController&&(this.xrInputSource=s,this.motionController=new aie(this,e,this.path,s.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[lie];return e?e.position:null}intersectBoxObject(e){const t=this.getPointerPosition();if(t){const i=new dr(t,cie),s=new Bn().setFromObject(e);return i.intersectsBox(s)}else return!1}checkButton(e){this.intersectBoxObject(e)?e.onPress():e.onClear(),e.isPressed()&&e.whilePressed()}}const uie=.05,uk=.02,c0=.01,dk=.02,fk=1,$d=.4,die=.002,Im=.01,l0=.003,pk=.035,Si=16,vo=12,xC=110,fie=new w(0,1,0),pie=new w(0,0,1),mie=.02,gie=1.5;class Aie 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,i){const s=t.clone();for(let r=0;r<Si;r++){s.applyAxisAngle(pie,Math.PI*2/Si);const o=i*Si+r;e[3*o]=s.x,e[3*o+1]=s.y,e[3*o+2]=s.z}}_updatePointerVertices(e){const t=this.pointerGeometry.attributes.position.array,i=new w(die,0,-1*(pk-e));this._drawVerticesRing(t,i,0);const s=new w(Math.sin(Math.PI*xC/180)*e,Math.cos(Math.PI*xC/180)*e,0);for(let l=0;l<vo;l++)this._drawVerticesRing(t,s,l+1),s.applyAxisAngle(fie,Math.PI*xC/180/(vo*-2));const r=Si*(1+vo),o=Si*(1+vo)+1,a=new w(0,0,-1*(pk-e));t[r*3]=a.x,t[r*3+1]=a.y,t[r*3+2]=a.z;const c=new w(0,0,e);t[o*3]=c.x,t[o*3+1]=c.y,t[o*3+2]=c.z,this.pointerGeometry.setAttribute("position",new ct(t,3))}createPointer(){let e,t;const i=new Array(((vo+1)*Si+2)*3).fill(0),s=[];for(this.pointerGeometry=new At,this.pointerGeometry.setAttribute("position",new ct(i,3)),this._updatePointerVertices(Im),e=0;e<vo;e++){for(t=0;t<Si-1;t++)s.push(e*Si+t,e*Si+t+1,(e+1)*Si+t),s.push(e*Si+t+1,(e+1)*Si+t+1,(e+1)*Si+t);s.push((e+1)*Si-1,e*Si,(e+2)*Si-1),s.push(e*Si,(e+1)*Si,(e+2)*Si-1)}const r=Si*(1+vo),o=Si*(1+vo)+1;for(e=0;e<Si-1;e++)s.push(r,e+1,e),s.push(o,e+Si*vo,e+Si*vo+1);s.push(r,0,Si-1),s.push(o,Si*(vo+1)-1,Si*vo);const a=new ci;a.transparent=!0,a.opacity=$d,this.pointerGeometry.setIndex(s),this.pointerMesh=new ge(this.pointerGeometry,a),this.pointerMesh.position.set(0,0,-1*Im),this.pointerObject=new _e,this.pointerObject.add(this.pointerMesh),this.raycaster=new Zu;const c=new Vo(mie,10,10),l=new ci;l.transparent=!0,l.opacity=$d,this.cursorObject=new ge(c,l),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"],i=e.position.distanceTo(t.position),s=e.position.clone().add(t.position).multiplyScalar(.5);this.pointerObject.position.copy(s),this.pointerObject.quaternion.copy(this.controller.quaternion),this.pinched=i<=uk;const r=(i-c0)/(uie-c0),o=(i-c0)/(uk-c0);if(r>1)this._updatePointerVertices(Im),this.pointerMesh.position.set(0,0,-1*Im),this.pointerMesh.material.opacity=$d;else if(r>0){const a=(Im-l0)*r+l0;this._updatePointerVertices(a),o<1?(this.pointerMesh.position.set(0,0,-1*a-(1-o)*dk),this.pointerMesh.material.opacity=$d+(1-o)*(fk-$d)):(this.pointerMesh.position.set(0,0,-1*a),this.pointerMesh.material.opacity=$d)}else this._updatePointerVertices(l0),this.pointerMesh.position.set(0,0,-1*l0-dk),this.pointerMesh.material.opacity=fk;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 i=this.raycaster.intersectObjects(e,t),s=new w(0,0,-1);if(i.length>0){const o=i[0].distance;this.cursorObject.position.copy(s.multiplyScalar(o))}else this.cursorObject.position.copy(s.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 sn={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 CG(n){const e=await fetch(n);if(e.ok)return e.json();throw new Error(e.statusText)}async function vie(n){if(!n)throw new Error("No basePath supplied");return await CG(`${n}/profilesList.json`)}async function yie(n,e,t=null,i=!0){if(!n)throw new Error("No xrInputSource supplied");if(!e)throw new Error("No basePath supplied");const s=await vie(e);let r;if(n.profiles.some(c=>{const l=s[c];return l&&(r={profileId:c,profilePath:`${e}/${l.path}`,deprecated:!!l.deprecated}),!!r}),!r){if(!t)throw new Error("No matching profile name found");const c=s[t];if(!c)throw new Error(`No matching profile name found and default profile "${t}" missing.`);r={profileId:t,profilePath:`${e}/${c.path}`,deprecated:!!c.deprecated}}const o=await CG(r.profilePath);let a;if(i){let c;if(n.handedness==="any"?c=o.layouts[Object.keys(o.layouts)[0]]:c=o.layouts[n.handedness],!c)throw new Error(`No matching handedness, ${n.handedness}, in profile ${r.profileId}`);c.assetPath&&(a=r.profilePath.replace("profile.json",c.assetPath))}return{profile:o,assetPath:a}}const bie={xAxis:0,yAxis:0,button:0,state:sn.ComponentState.DEFAULT};function _ie(n=0,e=0){let t=n,i=e;if(Math.sqrt(n*n+e*e)>1){const o=Math.atan2(e,n);t=Math.cos(o),i=Math.sin(o)}return{normalizedXAxis:t*.5+.5,normalizedYAxis:i*.5+.5}}class xie{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===sn.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(bie)}updateFromComponent({xAxis:e,yAxis:t,button:i,state:s}){const{normalizedXAxis:r,normalizedYAxis:o}=_ie(e,t);switch(this.componentProperty){case sn.ComponentProperty.X_AXIS:this.value=this.states.includes(s)?r:.5;break;case sn.ComponentProperty.Y_AXIS:this.value=this.states.includes(s)?o:.5;break;case sn.ComponentProperty.BUTTON:this.value=this.states.includes(s)?i:0;break;case sn.ComponentProperty.STATE:this.valueNodeProperty===sn.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(s):this.value=this.states.includes(s)?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(i=>{const s=new xie(t.visualResponses[i]);this.visualResponses[i]=s}),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:sn.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=sn.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=sn.ComponentState.PRESSED:(t.touched||this.values.button>sn.ButtonTouchThreshold)&&(this.values.state=sn.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===sn.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>sn.AxisTouchThreshold&&(this.values.state=sn.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===sn.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>sn.AxisTouchThreshold&&(this.values.state=sn.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(t=>{t.updateFromComponent(this.values)})}}class Sie{constructor(e,t,i){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=i,this.id=t.profileId,this.layoutDescription=t.layouts[e.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(s=>{const r=this.layoutDescription.components[s];this.components[s]=new wie(s,r)}),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(i=>{const{valueNode:s,minNode:r,maxNode:o,value:a,valueNodeProperty:c}=i;s&&(c===sn.VisualResponseProperty.VISIBILITY?s.visible=a:c===sn.VisualResponseProperty.TRANSFORM&&(s.quaternion.slerpQuaternions(r.quaternion,o.quaternion,a),s.position.lerpVectors(r.position,o.position,a)))})}))}}function Tie(n,e){Object.values(n.components).forEach(t=>{const{type:i,touchPointNodeName:s,visualResponses:r}=t;if(i===sn.ComponentType.TOUCHPAD)if(t.touchPointNode=e.getObjectByName(s),t.touchPointNode){const o=new Vo(.001),a=new ci({color:255}),c=new ge(o,a);t.touchPointNode.add(c)}else console.warn(`Could not find touch dot, ${t.touchPointNodeName}, in touchpad component ${t.id}`);Object.values(r).forEach(o=>{const{valueNodeName:a,minNodeName:c,maxNodeName:l,valueNodeProperty:u}=o;if(u===sn.VisualResponseProperty.TRANSFORM){if(o.minNode=e.getObjectByName(c),o.maxNode=e.getObjectByName(l),!o.minNode){console.warn(`Could not find ${c} in the model`);return}if(!o.maxNode){console.warn(`Could not find ${l} in the model`);return}}o.valueNode=e.getObjectByName(a),o.valueNode||console.warn(`Could not find ${a} in the model`)})})}function mk(n,e){Tie(n.motionController,e),n.envMap&&e.traverse(t=>{t.isMesh&&(t.material.envMap=n.envMap,t.material.needsUpdate=!0)}),n.layers.mask!=0&&e.traverse(t=>{t.layers.mask=n.layers.mask}),n.add(e)}class Iie{constructor(e=null){this.gltfLoader=e,this.path=Cie,this._assetCache={},this.gltfLoader||(this.gltfLoader=new Rp)}createControllerModel(e){const t=new Mie;let i=null;return e.addEventListener("connected",s=>{const r=s.data;r.targetRayMode!=="tracked-pointer"||!r.gamepad||yie(r,this.path,Eie).then(({profile:o,assetPath:a})=>{t.motionController=new Sie(r,o,a);const c=this._assetCache[t.motionController.assetUrl];if(c)i=c.scene.clone(),mk(t,i);else{if(!this.gltfLoader)throw new Error("GLTFLoader not set.");this.gltfLoader.setPath(""),this.gltfLoader.load(t.motionController.assetUrl,l=>{this._assetCache[t.motionController.assetUrl]=l,i=l.scene.clone(),mk(t,i)},null,()=>{throw new Error(`Asset ${t.motionController.assetUrl} missing or malformed.`)})}}).catch(o=>{console.warn(o)})}),e.addEventListener("disconnected",()=>{t.motionController=null,t.remove(i),i=null}),t}}const Rm=re("debugavatar");class Vx{constructor(e,t,i,s){h(this,"root");h(this,"head");h(this,"leftHand");h(this,"rigthHand");var r;this.root=e,this.head=t,this.leftHand=i,this.rigthHand=s,(r=this.root)==null||r.traverse(o=>o.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class Hx{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 i=null;if(typeof t=="string"){if(i=await this.loadAvatar(e,t),!i){const r=new nc;i=ne.instantiate(cp(t,e.scene),r)}}else i=t;if(!i)return null;const s=this.findAvatar(i);return s.isValid?(Rm&&console.log("[Custom Avatar] valid config",t,Rm?s:""),s):(console.warn("[Custom Avatar] config isn't valid",t,Rm?s:""),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(Rm&&console.log("[Custom Avatar] "+t+", loading..."),t.endsWith(".glb")||(t+=".glb"),this.avatarRegistryUrl===null){const s=await fetch("./"+t);let r=null;if(s.ok){const a=await s.blob();a&&(r=await a.arrayBuffer())}if(!r&&(r=await nI(t,t,0,"no url here go away",!0),!r))return null;const o=await pa().parseSync(e,r,null,0);return(o==null?void 0:o.scene)??null}const i=new Rp;return rv(i,e),new Promise((s,r)=>{const o=this.avatarRegistryUrl+"/"+t;i.load(o,async a=>{await pa().createBuiltinComponents(e,o,a,null,void 0),s(a.scene)},a=>{Rm&&console.log("[Custom Avatar] "+a.loaded/a.total*100+"% loaded of "+a.total/1024+"kB")},a=>{console.error("[Custom Avatar] Error when loading: "+a),s(null)})})}cacheModel(e,t){}findAvatar(e){const t=e;let i=t;i.children.length==1&&(i=e.children[0]);let s=this.findAvatarPart(i,["head"]);const r=this.findAvatarPart(i,["left","hand"]),o=this.findAvatarPart(i,["right","hand"]);if(!s){s=t;const c=new w;new Bn().setFromObject(s).getSize(c);const l=Math.max(c.x,c.y,c.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+l+" meters! Should be < 0.3m"),l>.3&&s.scale.multiplyScalar(1/l*.3)}return new Vx(t,s,r,o)}findAvatarPart(e,t){const i=e.name.toLowerCase();let s=!0;for(const r of t){if(!s)break;i.indexOf(r)===-1&&(s=!1)}if(s)return e;if(e.children)for(const r of e.children){const o=this.findAvatarPart(r,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=(n,e,t,i)=>{for(var s=i>1?void 0:i?Pie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Rie(e,t,s),s};const gf=re("debugflags");var gn=(n=>(n[n.Never=0]="Never",n[n.Browser=1]="Browser",n[n.AR=2]="AR",n[n.VR=4]="VR",n[n.FirstPerson=8]="FirstPerson",n[n.ThirdPerson=16]="ThirdPerson",n[n.All=4294967295]="All",n))(gn||{});const fP=class{constructor(){h(this,"Mask",17)}Has(e){return(this.Mask&e)!==0}Set(e){gf&&console.warn("Set XR flag state to",e),this.Mask=e,Xr.Apply()}Enable(e){this.Mask|=e,Xr.Apply()}Disable(e){this.Mask&=~e,Xr.Apply()}Toggle(e){this.Mask^=e,Xr.Apply()}EnableAll(){this.Mask=-1,Xr.Apply()}DisableAll(){this.Mask=0,Xr.Apply()}};let sr=fP;h(sr,"Global",new fP);var Nm;const Rc=(Nm=class extends Ie{constructor(){super(...arguments);h(this,"visibleIn")}static Apply(){for(const e of this.registry)e.UpdateVisible(sr.Global)}awake(){Rc.registry.push(this)}onEnable(){Rc.firstApply?this.UpdateVisible(sr.Global):(Rc.firstApply=!0,Rc.Apply())}onDestroy(){const e=Rc.registry.indexOf(this);e>=0&&Rc.registry.splice(e,1)}get isOn(){return this.gameObject.visible}UpdateVisible(e=null){let t;const i=e;i&&typeof i=="number"&&(console.assert(typeof i=="number","XRFlag.UpdateVisible: state must be a number",i),gf&&console.log(i),Rc.buffer.Mask=i,e=Rc.buffer);const s=e;if(s?(gf&&console.warn(this.name,"use passed in mask",s.Mask,this.visibleIn),t=s.Has(this.visibleIn)):(gf&&console.log(this.name,"use global mask"),sr.Global.Has(this.visibleIn)),t!==void 0)if(t)gf&&console.log(this.name,"is visible",this.gameObject.uuid),ne.setActive(this.gameObject,!0);else{if(gf&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},h(Nm,"registry",[]),h(Nm,"firstApply"),h(Nm,"buffer",new sr),Nm);let Xr=Rc;Bie([x()],Xr.prototype,"visibleIn",2);const Wl=re("debugavatar"),na=class extends Ie{constructor(){super(...arguments);h(this,"connectionId");h(this,"avatar")}static getAvatar(t){return t>=0&&t<na.instances.length?na.instances[t]:null}static onAvatarMarkerCreated(t){return na._onNewAvatarMarkerAdded.push(t),t}static onAvatarMarkerDestroyed(t){return na._onAvatarMarkerDestroyed.push(t),t}awake(){na.instances.push(this),Wl&&console.log(this);for(const t of na._onNewAvatarMarkerAdded)t({avatarMarker:this,gameObject:this.gameObject})}onDestroy(){na.instances.splice(na.instances.indexOf(this),1);for(const t of na._onAvatarMarkerDestroyed)t({avatarMarker:this,gameObject:this.gameObject})}isLocalAvatar(){return this.connectionId===this.context.connection.connectionId}setVisible(t){this.avatar&&("setVisible"in this.avatar?this.avatar.setVisible(t):ne.setActive(this.avatar,t))}};let is=na;h(is,"instances",[]),h(is,"_onNewAvatarMarkerAdded",[]),h(is,"_onAvatarMarkerDestroyed",[]);const kg=class{constructor(e,t,i){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=e,this.guid=t,this.webxr=i,this.setupCustomAvatar(this.webxr.defaultAvatar)}setVisible(e){this._isVisible=e,this.updateVisibility()}get isWebXRAvatar(){return!0}updateFlags(){if(!this.flags)return;let e=this.isLocalAvatar?gn.FirstPerson:gn.ThirdPerson;this.context.isInVR?e|=gn.VR:this.context.isInAR?e|=gn.AR:e|=gn.Browser;for(const t of this.flags)t.gameObject.visible=!0,t.UpdateVisible(e)}async setAvatarOverride(e){return this.hasAvatarOverride=e!==null,this.hasAvatarOverride&&this.lastAvatarId!==e&&(this.lastAvatarId=e,e!=null&&e.length>0)?await this.setupCustomAvatar(e):null}tryUpdate(e,t){if(e.guid===this.guid&&(this.lastAvatarId!==e.avatarId&&e.avatarId&&e.avatarId.length>0&&(this.lastAvatarId=e.avatarId,this.setupCustomAvatar(e.avatarId)),this.lastUpdate=e.time,this.head)){const i=this.webxr.IsInAR?$a.Handheld:$a.Headset,s=this.head;this.context.players.setPlayerView(e.guid,s,i),Hs.markDirty(this.head),this._canInterpolate=!0;const r=this.isLocalAvatar?this.head:this._headTarget;if(r.position.set(e.position.x,e.position.y,e.position.z),r.quaternion.set(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w),r.scale.set(e.scale,e.scale,e.scale),r.scale.multiply(this.headScale),this.handLeft){const o=this.isLocalAvatar?this.handLeft:this._handLeftTarget;o.position.set(e.posLeftHand.x,e.posLeftHand.y,e.posLeftHand.z),o.quaternion.set(e.rotLeftHand._x,e.rotLeftHand._y,e.rotLeftHand._z,e.rotLeftHand._w),o.quaternion.multiply(kg.invertRotation),o.scale.set(e.scale,e.scale,e.scale),o.scale.multiply(this.handLeftScale),Hs.markDirty(this.handLeft)}if(this.handRight){const o=this.isLocalAvatar?this.handRight:this._handRightTarget;o.position.set(e.posRightHand.x,e.posRightHand.y,e.posRightHand.z),o.quaternion.set(e.rotRightHand._x,e.rotRightHand._y,e.rotRightHand._z,e.rotRightHand._w),o.quaternion.multiply(kg.invertRotation),o.scale.set(e.scale,e.scale,e.scale),o.scale.multiply(this.handRightScale),Hs.markDirty(this.handRight)}}}update(){if(this.isLocalAvatar||!this._canInterpolate)return;const e=this.context.time.deltaTime/.1;this.head&&(this.head.position.lerp(this._headTarget.position,e),this.head.quaternion.slerp(this._headTarget.quaternion,e),this.head.scale.lerp(this._headTarget.scale,e)),this.handLeft&&this._handLeftTarget&&(this.handLeft.position.lerp(this._handLeftTarget.position,e),this.handLeft.quaternion.slerp(this._handLeftTarget.quaternion,e),this.handLeft.scale.lerp(this._handLeftTarget.scale,e)),this.handRight&&this._handRightTarget&&(this.handRight.position.lerp(this._handRightTarget.position,e),this.handRight.quaternion.slerp(this._handRightTarget.quaternion,e),this.handRight.scale.lerp(this._handRightTarget.scale,e))}destroy(){var e,t;Wl&&console.log("Destroy avatar",this.guid),(e=this.root)==null||e.removeFromParent(),(t=this.avatarMarker)==null||t.destroy(),this.lastAvatarId=null,this.head&&ar.Remove(this.context,this.head)}updateVisibility(){const e=this.root;e&&ne.setActive(e,this._isVisible)}async setupCustomAvatar(e){var s,r,o;if(Wl&&console.log("LOAD",e,this),!e||typeof e=="string"&&e.length<=0)return!1;this.head&&ar.Remove(this.context,this.head);const t=e;if((t==null?void 0:t.loadAssetAsync)!==void 0){await t.loadAssetAsync();const a=t.asset;ne.setActive(a,!1),e=ne.instantiate(a),ne.setActive(e,!0)}Wl&&console.log(e);const i=await kg.loader.getOrCreateNewAvatarInstance(this.context,e);if(Wl&&console.log(i,i==null?void 0:i.isValid,this.lastAvatarId,e),i!=null&&i.isValid){if(this.root=i.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=ne.addNewComponent(this.root,is),this.avatarMarker.connectionId=this.guid,this.avatarMarker.avatar=this,this.head&&this.head!==i.head&&((s=this.head)==null||s.removeFromParent()),this.head=i.head,this.headScale.copy(this.head.scale),this.head&&!this.isLocalAvatar&&ar.Add(this.context,this.head,this.avatarMarker),i.leftHand&&((r=this.handLeft)==null||r.removeFromParent()),this.handLeft=i.leftHand??this.handLeft,this.handLeft?this.handLeftScale.copy(this.handLeft.scale):this.handLeftScale.set(1,1,1),i.rigthHand&&((o=this.handRight)==null||o.removeFromParent()),this.handRight=i.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(...ne.getComponentsInChildren(this.root,Xr)),this.flags.length<=0&&this.head){const a=ne.addNewComponent(this.head,Xr);a.visibleIn=gn.ThirdPerson|gn.VR,this.flags.push(a),Wl&&console.log("Added flag to head: "+a.visibleIn,this.head.name)}return Wl&&console.log("[Avatar], is Local? ",this.isLocalAvatar,this.root),this.updateFlags(),this.updateVisibility(),!0}else return Wl&&console.warn("build avatar failed"),!1}};let qa=kg;h(qa,"loader",new Hx),h(qa,"invertRotation",new Ce().setFromAxisAngle(new w(0,1,0),Math.PI));class ar{static Add(e,t,i=null){if(t){for(const s of this.Pois)if(s.obj===t)return;this.Pois.push({obj:t,avatar:i}),this.LastChangeTime=e.time.time}}static Remove(e,t){var i;if(t){for(const s of this.Pois)if(s.obj===t){this.Pois.splice(this.Pois.indexOf(s),1),this.LastChangeTime=(e==null?void 0:e.time.time)??((i=Lt.Current)==null?void 0:i.time.time);return}}}}h(ar,"Pois",[]),h(ar,"LastChangeTime",0);class Die{constructor(){h(this,"guid");h(this,"position",new w)}}class fA extends Ie{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(t){this.target=t;const i=Y.get("MoveRandom");if(i&&this.target){const s=ne.getComponent(this.target,i);s&&s.destroy()}}awake(){if(this.avatar=ne.getComponentInParent(this.gameObject,is),this.avatar){const t=ne.getComponentInParent(this.gameObject,is);this._model=new ux(this.context.connection,this.guid),t!=null&&t.isLocalAvatar&&this._model.requestOwnership()}this.context.connection.beginListen("avatar-look-target-changed",t=>{var i;this.target&&t&&t.guid===((i=this.avatar)==null?void 0:i.guid)&&yn(this.target,t.position)})}update(){var i;if((!this.context.connection.isConnected||(i=this._model)!=null&&i.hasOwnership)&&(ar.LastChangeTime!==this._lastPoiChangedTime&&(this._lastPoiChangedTime=ar.LastChangeTime,this._lookDuration=0),this.selectTarget(),this._currentTargetObject&&this.context.time.frameCount%10===0&&this.target)){const s=pt(this._currentTargetObject);yn(this.target,s),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(s))}}selectTarget(){if(this.context.time.time-this._lastUpdateTime>this._lookDuration){this._lastUpdateTime=this.context.time.time,this._lookDuration=Math.random()*.5+.2;const i=ar.Pois;if(i.length>0){const s=i[Math.floor(Math.random()*i.length)];if(s&&s.obj){if(s.avatar&&s.avatar===this.avatar)return;this._currentTargetObject=s.obj}}}}}class Lp extends Ie{constructor(){super(...arguments);h(this,"canGrab",!0)}onPointerClick(t){}}class Fp extends Ie{constructor(){super(...arguments);h(this,"isUsed",!0);h(this,"usedBy",null)}}var Yn=(n=>(n[n.Average=0]="Average",n[n.Multiply=1]="Multiply",n[n.Minimum=2]="Minimum",n[n.Maximum=3]="Maximum",n))(Yn||{}),Qx=(n=>(n[n.Discrete=0]="Discrete",n[n.Continuous=1]="Continuous",n))(Qx||{}),hn=(n=>(n[n.None=0]="None",n[n.FreezePositionX=2]="FreezePositionX",n[n.FreezePositionY=4]="FreezePositionY",n[n.FreezePositionZ=8]="FreezePositionZ",n[n.FreezePosition=14]="FreezePosition",n[n.FreezeRotationX=16]="FreezeRotationX",n[n.FreezeRotationY=32]="FreezeRotationY",n[n.FreezeRotationZ=64]="FreezeRotationZ",n[n.FreezeRotation=112]="FreezeRotation",n[n.FreezeAll=126]="FreezeAll",n))(hn||{}),If=(n=>(n[n.None=0]="None",n[n.X=2]="X",n[n.Y=4]="Y",n[n.Z=8]="Z",n[n.All=-1]="All",n))(If||{});const Es=function(n,e){return function(t,i,s){Oie(t,i,s,n,e)}};function Oie(n,e,t,i,s){if(!s&&!i&&!n.onValidate)return;if(t!==void 0){console.error("Invalid usage of validate decorator. Only fields can be validated.",n,e,t),An("Invalid usage of validate decorator. Only fields can be validated. Property: "+e,Fo.Error);return}let r="";if(typeof e=="string"?r=e:r=e.name,n.__internalAwake){const o=Symbol(r),a=n.__internalAwake;n.__internalAwake=function(){var c;if(!this.onValidate){Vt()&&console.warn('Usage of @validate decorate detected but there is no onValidate method in your class: "'+((c=n.constructor)==null?void 0:c.name)+'"');return}if(this[o]===void 0){this[o]=this[r];const l=this[r];if(l instanceof te||l instanceof w||l instanceof Ze||l instanceof Ce){const u=this[r];CT(u,()=>{this.onValidate(r)})}Object.defineProperty(this,r,{set:function(u){var d;if(this[pM]===!0)this[o]=u;else{i==null||i.call(this,u);const f=this[o];this[o]=u,(d=this.onValidate)==null||d.call(this,r,f)}},get:function(){return s==null||s.call(this),this[o]}})}a.call(this)}}}const kie=function(n){return function(e,t,i){let s="";typeof t=="string"?s=t:s=t.name;const r=n.prototype,o=Object.getOwnPropertyDescriptor(r,s);if(!(o!=null&&o.value)){console.warn("Can not apply prefix: type does not have method named",t,n);return}const a=o.value,c=e[s];Object.defineProperty(r,s,{value:function(...l){const u=c==null?void 0:c.call(this,...l);if(u instanceof Promise){u.then(d=>{if(d!==!1)return a.call(this,...l)});return}if(u!==!1)return a.call(this,...l)}})}};var Lie=Object.defineProperty,Fie=Object.getOwnPropertyDescriptor,Qo=(n,e,t,i)=>{for(var s=i>1?void 0:i?Fie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Lie(e,t,s),s};class Uie{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 tl(this.obj.position,["x","y","z"])),this._positionWatch.apply(),this.position={},this._positionWatch.subscribeWrite((r,o)=>{var c;if((c=this.context.physics.engine)!=null&&c.isUpdating||this.mute)return;const a=this.position[o];Math.abs(a-r)<1e-5||(this.position[o]=r,this.positionChanged=!0)})),t&&(this._rotationWatch||(this._rotationWatch=new tl(this.obj.quaternion,["_x","_y","_z","_w"])),this._rotationWatch.apply(),this.quaternion={},this._rotationWatch.subscribeWrite((r,o)=>{var c;if((c=this.context.physics.engine)!=null&&c.isUpdating||this.mute)return;const a=this.quaternion[o];Math.abs(a-r)<1e-5||(this.quaternion[o]=r,this.rotationChanged=!0)}));const i=this.obj.matrixWorld.multiplyMatrices.bind(this.obj.matrixWorld),s=new Te;this.obj.matrixWorld.multiplyMatrices=(r,o)=>{var a;return(a=this.context.physics.engine)!=null&&a.isUpdating||this.mute||s.equals(r)||(this.positionChanged=!0,this.rotationChanged=!0,s.copy(r)),i(r,o)}}stop(){var e,t;(e=this._positionWatch)==null||e.revoke(),(t=this._rotationWatch)==null||t.revoke()}}var iE;const jM=(iE=class extends Ie{constructor(){super(...arguments);h(this,"autoMass",!0);h(this,"_mass",0);h(this,"useGravity",!0);h(this,"constraints",hn.None);h(this,"isKinematic",!1);h(this,"drag",0);h(this,"angularDrag",1);h(this,"detectCollisions",!0);h(this,"sleepThreshold",.01);h(this,"collisionDetectionMode",Qx.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(e){e!==this._mass&&(this._mass=e,this._propertiesChanged=!0,this.__didAwake&&(this.autoMass=!1))}get mass(){var e,t;return this.autoMass?((t=(e=this.context.physics.engine)==null?void 0:e.getBody(this))==null?void 0:t.mass())??-1:this._mass}get lockPositionX(){return(this.constraints&hn.FreezePositionX)!==0}get lockPositionY(){return(this.constraints&hn.FreezePositionY)!==0}get lockPositionZ(){return(this.constraints&hn.FreezePositionZ)!==0}get lockRotationX(){return(this.constraints&hn.FreezeRotationX)!==0}get lockRotationY(){return(this.constraints&hn.FreezeRotationY)!==0}get lockRotationZ(){return(this.constraints&hn.FreezeRotationZ)!==0}set lockPositionX(e){e?this.constraints|=hn.FreezePositionX:this.constraints&=~hn.FreezePositionX}set lockPositionY(e){e?this.constraints|=hn.FreezePositionY:this.constraints&=~hn.FreezePositionY}set lockPositionZ(e){e?this.constraints|=hn.FreezePositionZ:this.constraints&=~hn.FreezePositionZ}set lockRotationX(e){e?this.constraints|=hn.FreezeRotationX:this.constraints&=~hn.FreezeRotationX}set lockRotationY(e){e?this.constraints|=hn.FreezeRotationY:this.constraints&=~hn.FreezeRotationY}set lockRotationZ(e){e?this.constraints|=hn.FreezeRotationZ:this.constraints&=~hn.FreezeRotationZ}set gravityScale(e){this._gravityScale=e}get gravityScale(){return this._gravityScale}awake(){this._watch=void 0,this._propertiesChanged=!1}onEnable(){this._watch||(this._watch=new Uie(this.gameObject,this.context)),this._watch.start(!0,!0),this.startCoroutine(this.beforePhysics(),ns.LateUpdate)}onDisable(){var e,t;(e=this._watch)==null||e.stop(),(t=this.context.physics.engine)==null||t.removeBody(this)}onDestroy(){var e;(e=this.context.physics.engine)==null||e.removeBody(this)}onValidate(){this._propertiesChanged=!0}*beforePhysics(){var e,t,i,s;for(;;)this._propertiesChanged&&(this._propertiesChanged=!1,(e=this.context.physics.engine)==null||e.updateProperties(this)),(t=this._watch)!=null&&t.isDirty?(this._watch.mute=!0,this._watch.applyValues(),(i=this.context.physics.engine)==null||i.updateBody(this,this._watch.positionChanged,this._watch.rotationChanged),this._watch.reset()):(s=this._watch)==null||s.syncValues(),this.captureVelocity(),yield}teleport(e,t=!0){var i;(i=this._watch)==null||i.reset(!0),t?this.gameObject.position.set(e.x,e.y,e.z):this.setWorldPosition(e.x,e.y,e.z),this.resetForcesAndTorques(),this.resetVelocities()}resetForces(e=!0){var t;(t=this.context.physics.engine)==null||t.resetForces(this,e)}resetTorques(e=!0){var t;(t=this.context.physics.engine)==null||t.resetTorques(this,e)}resetVelocities(){this.setVelocity(0,0,0),this.setAngularVelocity(0,0,0)}resetForcesAndTorques(){this.resetForces(),this.resetTorques()}wakeUp(){var e;(e=this.context.physics.engine)==null||e.wakeup(this)}applyForce(e,t,i=!0){var s;(s=this.context.physics.engine)==null||s.addForce(this,e,i)}applyImpulse(e,t=!0){var i;(i=this.context.physics.engine)==null||i.applyImpulse(this,e,t)}setForce(e,t,i,s=!0){var r,o,a;(r=this.context.physics.engine)==null||r.resetForces(this,s),typeof e=="number"?(t??(t=0),i??(i=0),(o=this.context.physics.engine)==null||o.addForce(this,{x:e,y:t,z:i},s)):(a=this.context.physics.engine)==null||a.addForce(this,e,s)}getVelocity(){var t;const e=(t=this.context.physics.engine)==null?void 0:t.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(e,t,i,s=!0){var r,o;if(e instanceof w){const a=e;(r=this.context.physics.engine)==null||r.setLinearVelocity(this,a,s);return}t===void 0||i===void 0||(o=this.context.physics.engine)==null||o.setLinearVelocity(this,{x:e,y:t,z:i},s)}getAngularVelocity(){var t;const e=(t=this.context.physics.engine)==null?void 0:t.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(e,t,i,s=!0){var r,o;if(e instanceof w){const a=e;(r=this.context.physics.engine)==null||r.setAngularVelocity(this,a,s);return}t===void 0||i===void 0||(o=this.context.physics.engine)==null||o.setAngularVelocity(this,{x:e,y:t,z:i},s)}setTorque(e,t,i){this.setAngularVelocity(e,t,i)}get smoothedVelocity(){return this._smoothedVelocityGetter.copy(this._smoothedVelocity),this._smoothedVelocityGetter.multiplyScalar(1/this.context.time.deltaTime)}setBodyFromGameObject(e=null){}captureVelocity(){const e=pt(this.gameObject);jM.tempPosition.copy(e);const t=e.sub(this._lastPosition);this._lastPosition.copy(jM.tempPosition),this._smoothedVelocity.lerp(t,this.context.time.deltaTime/.1)}},h(iE,"tempPosition",new w),iE);let Pi=jM;Qo([Es()],Pi.prototype,"autoMass",2);Qo([x()],Pi.prototype,"mass",1);Qo([Es(),x()],Pi.prototype,"useGravity",2);Qo([Es(),x()],Pi.prototype,"constraints",2);Qo([Es(),x()],Pi.prototype,"isKinematic",2);Qo([Es(),x()],Pi.prototype,"drag",2);Qo([Es(),x()],Pi.prototype,"angularDrag",2);Qo([Es(),x()],Pi.prototype,"detectCollisions",2);Qo([Es(),x()],Pi.prototype,"sleepThreshold",2);Qo([Es(),x()],Pi.prototype,"collisionDetectionMode",2);Qo([Es()],Pi.prototype,"_gravityScale",2);Qo([Es()],Pi.prototype,"dominanceGroup",2);class io{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,i,s){return e.prep(4,12),e.writeFloat32(s),e.writeFloat32(i),e.writeFloat32(t),e.offset()}}class EG{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 io).__init(this.bb_pos,this.bb)}rotation(e){return(e||new io).__init(this.bb_pos+12,this.bb)}scale(e){return(e||new io).__init(this.bb_pos+24,this.bb)}static sizeOf(){return 36}static createTransform(e,t,i,s,r,o,a,c,l,u){return e.prep(4,36),e.prep(4,12),e.writeFloat32(u),e.writeFloat32(l),e.writeFloat32(c),e.prep(4,12),e.writeFloat32(a),e.writeFloat32(o),e.writeFloat32(r),e.prep(4,12),e.writeFloat32(s),e.writeFloat32(i),e.writeFloat32(t),e.offset()}}class Hc{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 Hc).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSyncedTransformModel(e,t){return e.setPosition(e.position()+cx),(t||new Hc).__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 EG).__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 Gl=re("debugsync"),pA="STRS";lx(pA,Hc.getRootAsSyncedTransformModel);const Ta=new Sp;function MG(n,e,t=!0){Ta.clear();const i=Ta.createString(n);Hc.startSyncedTransformModel(Ta),Hc.addGuid(Ta,i),Hc.addFast(Ta,t);const s=e.worldPosition,r=e.worldEuler,o=e.gameObject.scale;Hc.addTransform(Ta,EG.createTransform(Ta,s.x,s.y,s.z,r.x,r.y,r.z,o.x,o.y,o.z));const a=Hc.endSyncedTransformModel(Ta);return Ta.finish(a,pA),Ta.asUint8Array()}class Ah extends Ie{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 Gn);h(this,"receivedUpdate",!1);h(this,"lastWorldPos");h(this,"lastWorldRotation")}requestOwnership(){Gl&&console.log("Request ownership"),this._model?this._model.requestOwnership():(this._shouldRequestOwnership=!0,this._needsUpdate=!0)}hasOwnership(){var t;return((t=this._model)==null?void 0:t.hasOwnership)??void 0}isOwned(){var t;return(t=this._model)==null?void 0:t.isOwned}awake(){Gl&&console.log("new instance",this.guid,this),this._receivedDataBefore=!1,this._targetPosition=new w,this._targetRotation=new Ce,this.lastWorldPos=new w,this.lastWorldRotation=new Ce,this.rb=ne.getComponentInChildren(this.gameObject,Pi),this.rb&&(this._wasKinematic=this.rb.isKinematic),this.receivedUpdate=!0,this._model=new ux(this.context.connection,this.guid),this.context.connection.isConnected&&this.tryGetLastState(),this.joinedRoomCallback=this.tryGetLastState.bind(this),this.context.connection.beginListen(Li.JoinedRoom,this.joinedRoomCallback),this.receivedDataCallback=this.onReceivedData.bind(this),this.context.connection.beginListenBinary(pA,this.receivedDataCallback)}onDestroy(){this.syncDestroy&&KU(this.guid,this.context.connection),this._model=null,this.context.connection.stopListen(Li.JoinedRoom,this.joinedRoomCallback),this.context.connection.stopListenBinary(pA,this.receivedDataCallback)}tryGetLastState(){const t=this.context.connection.tryGetState(this.guid);t&&this.onReceivedData(t)}onReceivedData(t){var i;if(!this.destroyed&&typeof t.guid=="function"&&t.guid()===this.guid){Gl&&console.log("new data",this.context.connection.connectionId,this.context.time.frameCount,this.guid,t),this.receivedUpdate=!0,this._receivedFastUpdate=t.fast();const s=t.transform();if(s){Hs.markDirty(this.gameObject,!0);const r=s.position();r&&(this.interpolatePosition&&((i=this._targetPosition)==null||i.set(r.x(),r.y(),r.z())),(!this.interpolatePosition||!this._receivedDataBefore)&&this.setWorldPosition(r.x(),r.y(),r.z()));const o=s.rotation();o&&(this.tempEuler.set(o.x(),o.y(),o.z()),this.interpolateRotation&&this._targetRotation.setFromEuler(this.tempEuler),(!this.interpolateRotation||!this._receivedDataBefore)&&DT(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){Gl&&console.log("no model or room",this.name,this.guid,this.context.connection.isInRoom);return}this._shouldRequestOwnership&&(this._shouldRequestOwnership=!1,this._model.requestOwnership());const t=this.worldPosition,i=this.worldQuaternion;if(this._model.isOwned&&!this.receivedUpdate){const o=t.distanceTo(this.lastWorldPos),a=i.angleTo(this.lastWorldRotation),c=this._model.hasOwnership||this.fastMode?1e-4:.001;(o>c||a>c)&&(this._model.hasOwnership?this._needsUpdate=!0:(Gl&&console.log(this.guid,"reset because not owned but",this.gameObject.name,this.lastWorldPos),this.worldPosition=this.lastWorldPos,t.copy(this.lastWorldPos),this.worldQuaternion=this.lastWorldRotation,i.copy(this.lastWorldRotation),Hs.markDirty(this.gameObject,!0),this._needsUpdate=!1))}if(this._model&&!this._model.hasOwnership&&this._model.isOwned&&this._receivedDataBefore){const a=this._receivedFastUpdate||this.fastMode?.5:.3;let c=!1;if(this.interpolatePosition&&this._targetPosition){const l=this.worldPosition;l.lerp(this._targetPosition,a),this.worldPosition=l,c=!0}if(this.interpolateRotation&&this._targetRotation){const l=this.worldQuaternion;l.slerp(this._targetRotation,a),this.worldQuaternion=l,c=!0}c&&Hs.markDirty(this.gameObject,!0)}if(this.receivedUpdate=!1,this.lastWorldPos.copy(t),this.lastWorldRotation.copy(i),!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&&(Gl&&console.log("reset kinematic",this.rb.name,this._wasKinematic),this.rb.isKinematic=this._wasKinematic),this.gameObject.position.distanceTo(new w(0,0,0))>1e3&&(Gl&&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)){Gl&&console.log("send update",this.context.connection.connectionId,this.guid,this.gameObject.name,this.gameObject.guid),this.overridePhysics&&this.rb,this._needsUpdate=!1;const o=MG(this.guid,this,!!r);this.context.connection.sendBinary(o)}}}const Nie=re("debugshadowcomponents");WI.prototype.interactable={get(){return this.interactive},set(n){this.interactable=n}};const Bo=Symbol("shadowDomOwner");class ma extends Ie{constructor(){super(...arguments);h(this,"shadowComponent",null);h(this,"_controlsChildLayout",!0);h(this,"_root");h(this,"_parentComponent")}isRoot(){var t;return((t=this.Root)==null?void 0:t.gameObject)===this.gameObject}get canvas(){const t=this.Root;return t!=null&&t.isCanvas?t:null}markDirty(){rr.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(t){this._controlsChildLayout=t,this.shadowComponent&&(this.shadowComponent.autoLayout=t)}get Root(){return this._root===void 0&&(this._root=ne.getComponentInParent(this.gameObject,pv)),this._root}get Canvas(){return this.canvas}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this.shadowComponent=null,this._root=void 0,this._parentComponent=void 0}onEnable(){super.onEnable()}addShadowComponent(t,i){var o;this.removeShadowComponent();const s=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=ne.getComponentInParent(s,ma),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}t.name=this.name+" ("+(this.constructor.name??"UI")+")",t.autoLayout=this._parentComponent.controlsChildLayout,t[Bo]=this,this.setShadowComponentOwner(t);let r=!1;if(((o=this.Root)==null?void 0:o.gameObject)===this.gameObject)this.gameObject.add(t);else{const a=this._parentComponent.shadowComponent;a&&(a==null||a.add(t),r=!0)}this.shadowComponent=t,i&&i.shadowComponent&&this.shadowComponent&&i.shadowComponent.add(this.shadowComponent),tv&&t.add(new wp(.5)),this.onAfterAddedToScene(),r&&lG(),Nie&&console.log(this.shadowComponent)}set(t){}setShadowComponentOwner(t){if(t&&(t[Bo]===void 0||t[Bo]===this)&&(t[Bo]=this,t.children))for(const i of t.children)this.setShadowComponentOwner(i)}traverseOwnedShadowComponents(t,i,s){if(t&&t[Bo]===i){s(t);for(const r of t.children)this.traverseOwnedShadowComponents(r,i,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(t){this.shadowComponent&&(this.shadowComponent.interactable=t)}}class pv extends ma{awake(){super.awake()}}class vp{static getObject(e){const t=e[Bo];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const i=this.tryFindCanvasGroup(e);if((i==null?void 0:i.isCanvasGroup)===!0&&(t&&(t.canvasGroup=i),i.blocksRaycasts===!1||i.interactable===!1))return!1;const s=ju(e,r=>{if(r.isGraphic===!0)return r},!1);return t&&(s==null?void 0:s.isGraphic)===!0&&(t.graphic=s),!((s==null?void 0:s.raycastTarget)===!1||(s==null?void 0:s.layer)===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=ju(e,i=>{const s=i;if(s.blocksRaycasts!==void 0&&s.interactable!==void 0)return s},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}const Zm=re("debugwebxrcontroller");var qf=(n=>(n[n.PhysicalDevice=0]="PhysicalDevice",n[n.Touch=1]="Touch",n))(qf||{}),Lc=(n=>(n.SelectStart="select-start",n.SelectEnd="select-end",n.Update="update",n))(Lc||{});class Wx extends Ie{}const Jn=class extends Ie{constructor(){super(...arguments);h(this,"webXR");h(this,"index",-1);h(this,"controllerModel");h(this,"controller");h(this,"controllerGrip");h(this,"hand");h(this,"handPointerModel");h(this,"grabbed",null);h(this,"input",null);h(this,"type",0);h(this,"showRaycastLine",!0);h(this,"enableRaycasts",!0);h(this,"enableDefaultControls",!0);h(this,"_wristQuaternion",null);h(this,"movementVector",new w);h(this,"worldRot",new Ce);h(this,"joystick",new te);h(this,"didRotate",!1);h(this,"didTeleport",!1);h(this,"didChangeScale",!1);h(this,"lastHit",null);h(this,"raycastLine",null);h(this,"_raycastHitPoint",null);h(this,"_connnectedCallback",null);h(this,"_disconnectedCallback",null);h(this,"_selectStartEvt",null);h(this,"_selectEndEvt",null);h(this,"_selectionPressed",!1);h(this,"_selectionPressedLastFrame",!1);h(this,"_selectionStartTime",0);h(this,"_selectionEndTime",0);h(this,"_useSmoothing",!0);h(this,"_isConnected",!1);h(this,"rayRotation",new Ce);h(this,"_pinchStartTime");h(this,"selectStartCallback",null);h(this,"lastSelectStartObject",null);h(this,"_didNotEndSelection",!1);h(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const t=new pn(this.geometry),i=t.material;return i.color=this.raycastColor,t.layers.set(2),t.name="line",t.scale.z=1,t}static CreateRaycastHitPoint(){const t=new Vo(.5,22,22),i=new ci({color:this.raycastColor}),s=new ge(t,i);return s.visible=!1,s.layers.set(2),s}static Create(t,i,s,r){const o=s?ne.addNewComponent(s,Jn,!1):new Jn;o.webXR=t,o.index=i,o.type=r;const a=t.context;o.controller=a.renderer.xr.getController(i),o.controllerGrip=a.renderer.xr.getControllerGrip(i),o.controllerModel=this.Factory.createControllerModel(o.controller),o.controllerGrip.add(o.controllerModel),o.hand=a.renderer.xr.getHand(i);const c=new Rp;rv(c,a),o.webXR.handModelPath&&o.webXR.handModelPath!==""?c.setPath(ml(t.sourceId,o.webXR.handModelPath)):c.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const l=new hie(o.hand,c);return o.hand.add(l),o.hand.traverse(u=>u.layers.set(2)),o.handPointerModel=new Aie(o.hand,o.controller),o.controller.addEventListener("connected",u=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2),setTimeout(()=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2)},1e3)}),o.hand.addEventListener("connected",u=>{var f;if(u.data.hand){t.Rig&&t.Rig.add(o.hand),o.type=0,o.handPointerModel.traverse(m=>m.layers.set(2)),(f=o.handPointerModel.pointerObject)==null||f.traverse(m=>m.layers.set(2));const p=o.hand.joints;if(p)for(const m of Object.keys(p)){const v=p[m];v.parent||o.hand.add(v)}}}),o}static addEventListener(t,i){const s=this.eventSubs[t]??[];s.push(i),this.eventSubs[t]=s}static removeEventListener(t,i){if(!i)return;const s=this.eventSubs[t]??[],r=s.indexOf(i);r>=0&&s.splice(r,1),this.eventSubs[t]=s}get isUsingHands(){var i;const t=(i=this.input)==null?void 0:i.hand;return t!=null}get wrist(){if(!this.hand)return null;const t=this.hand.joints;return t?t.wrist:null}getWristQuaternion(){const t=this.wrist;return t?(this._wristQuaternion||(this._wristQuaternion=new Ce),Ei(t).multiply(this._wristQuaternion.setFromEuler(new Gn(-Math.PI/4,0,0)))):null}get selectionDown(){return this._selectionPressed&&!this._selectionPressedLastFrame}get selectionUp(){return!this._selectionPressed&&this._selectionPressedLastFrame}get selectionPressed(){return this._selectionPressed}get selectionClick(){return this._selectionEndTime-this._selectionStartTime<.3}get raycastHitPoint(){return this._raycastHitPoint}get useSmoothing(){return this._useSmoothing}awake(){if(!this.controller){console.warn("WebXRController: Missing controller object.",this);return}this._connnectedCallback=this.onSourceConnected.bind(this),this._disconnectedCallback=this.onSourceDisconnected.bind(this),this._selectStartEvt=this.onSelectStart.bind(this),this._selectEndEvt=this.onSelectEnd.bind(this),this.type===1&&(this.controllerGrip.addEventListener("connected",this._connnectedCallback),this.controllerGrip.addEventListener("disconnected",this._disconnectedCallback),this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt))}onDestroy(){var t,i,s;this.type===1&&(this.controllerGrip.removeEventListener("connected",this._connnectedCallback),this.controllerGrip.removeEventListener("disconnected",this._disconnectedCallback),this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),(t=this.hand)==null||t.clear(),(i=this.controllerGrip)==null||i.clear(),(s=this.controller)==null||s.clear()}onEnable(){var t,i,s,r,o;if(!this.webXR){console.warn("No WebXR component assigned to WebXRController.");return}this.hand&&(this.hand.name="Hand"),this.controllerGrip&&(this.controllerGrip.name="ControllerGrip"),this.controller&&(this.controller.name="Controller"),this.raycastLine&&(this.raycastLine.name="RaycastLine;"),this.webXR.Controllers.indexOf(this)<0&&this.webXR.Controllers.push(this),this.raycastLine||(this.raycastLine=Jn.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=Jn.CreateRaycastHitPoint()),(t=this.webXR.Rig)==null||t.add(this.hand),(i=this.webXR.Rig)==null||i.add(this.controllerGrip),(s=this.webXR.Rig)==null||s.add(this.controller),(r=this.webXR.Rig)==null||r.add(this.raycastLine),(o=this.raycastLine)==null||o.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),Zm&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var t,i,s,r,o;if((t=this.hand)==null||t.removeFromParent(),(i=this.controllerGrip)==null||i.removeFromParent(),(s=this.controller)==null||s.removeFromParent(),(r=this.raycastLine)==null||r.removeFromParent(),(o=this._raycastHitPoint)==null||o.removeFromParent(),this.webXR){const a=this.webXR.Controllers.indexOf(this);a>=0&&this.webXR.Controllers.splice(a,1)}}onSourceConnected(t){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,t);return}this._isConnected=!0,this.input=t.data,this.type===1&&this.onSelectStart()}onSourceDisconnected(t){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",t);return}this._isConnected=!1,this.type===1&&this.onSelectEnd(),this.input=null}createPointerEvent(t){switch(t){case"down":this.context.input.createPointerDown(new Oc(fn.PointerDown,null,{clientX:0,clientY:0,button:this.index,pointerType:lp.Touch}));break;case"move":break;case"up":this.context.input.createPointerUp(new Oc(fn.PointerUp,null,{clientX:0,clientY:0,button:this.index,pointerType:lp.Touch}));break}}raycastUpdate(t,i){const s=this.showRaycastLine&&this.type!==1;if(this.type===1)t.visible=!1;else if(this.isUsingHands){t.visible=!this.grabbed&&s,yn(t,i);const r=this.hand.joints;if(r&&r.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const a=this.getWristQuaternion();a&&this.rayRotation.copy(a)}lr(t,this.rayRotation)}else t.visible=s,lr(t,this.rayRotation),yn(t,i)}update(){if(!this.webXR)return;this.context.time.frameCount%60===0&&(this.setControllerLayers(this.controller,2),this.setControllerLayers(this.controllerGrip,2),this.setControllerLayers(this.hand,2));const t=Jn.eventSubs.update;if(t&&t.length>0)for(const r of t)r(this);let i=1;this.type===0?i=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(i=this.context.time.deltaTime/.3),this.rayRotation.slerp(Ei(this.controller),this.useSmoothing?i:1);const s=pt(this.controller);this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.enableRaycasts?(this.raycastLine&&this.raycastUpdate(this.raycastLine,s),this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update()):this.raycastLine&&(this.raycastLine.visible=!1),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(t){var r,o;if(this.lastHit=null,!t||t.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=t.inputSources[this.index]),!this.input)return;const i=this.webXR.Rig;if(!i)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const s=(o=(r=this.input)==null?void 0:r.gamepad)==null?void 0:o.buttons;if(this.enableDefaultControls)switch(this.input.handedness){case"left":this.movementUpdate(i,s);break;case"right":this.rotationUpdate(i,s);break}}movementUpdate(t,i){const s=3*Jn.MovementSpeedFactor,r=2,o=ot.clamp01(this.joystick.length()*2),a=this.joystick.x>0?1:-1;let c=Math.pow(this.joystick.x,r);c*=a,c*=o;const l=this.joystick.y>0?1:-1;let u=Math.pow(this.joystick.y,r);u*=l,c*=o,t.getWorldQuaternion(this.worldRot),this.movementVector.set(c,0,u),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(s*this.context.time.deltaTime),t.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(t,i)}rotationUpdate(t,i){const s=this.joystick.x,r=Math.abs(s);if(r<.4)this.didRotate=!1;else if(r>.5&&!this.didRotate){const o=s>0?-1:1;t.rotateY(ot.toRadians(30*o)),this.didRotate=!0}this.runTeleport(t,i)}runTeleport(t,i){var u,d;let s=-this.joystick.y;if((u=this.hand)!=null&&u.visible&&!this.grabbed){const f=this.handPointerModel.isPinched();f&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),f&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(s=this.handPointerModel.isPinched()?1:0),f||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;const r=this.webXR.IsInVR,o=this.webXR.Rig;let a=s>.5&&r,c=o?((d=o==null?void 0:o.scale)==null?void 0:d.x)<.999:!1,l=null;if(i&&this.input&&!this.input.hand)for(let f=0;f<i.length;f++){const p=i[f];if(f===4)if(p.pressed&&!this.didChangeScale&&r){this.didChangeScale=!0;const m=o;if(m){const v=this.switchScale(m,a,c,l);a=v.doTeleport,c=v.isInMiniatureMode,l=v.newRigScale}}else p.pressed||(this.didChangeScale=!1)}if(a){if(!this.didTeleport){const f=this.raycast();if(this.didTeleport=!0,f&&f.length>0){const p=f[0];if(c||this.isValidTeleportTarget(p.object)){const m=p.point;yn(t,m)}}}}else s<.1&&(this.didTeleport=!1);l!==null&&(t.scale.set(l,l,l),t.updateMatrixWorld())}isValidTeleportTarget(t){return ne.getComponentInParent(t,Wx)!=null}switchScale(t,i,s,r){if(s){s=!1,t.scale.set(1,1,1),r=1,Jn.MovementSpeedFactor=1;const o=this.context.mainCamera;Jn.PreviousCameraFarDistance&&(o.far=Jn.PreviousCameraFarDistance)}else{s=!0,i=!0,r=.1,Jn.MovementSpeedFactor=r*2;const o=this.context.mainCamera;Jn.PreviousCameraFarDistance=o.far,o.far/=r}return{doTeleport:i,isInMiniatureMode:s,newRigScale:r}}updateStick(t){var i;!t||!t.gamepad||((i=t.gamepad.axes)==null?void 0:i.length)<4||(this.joystick.x=t.gamepad.axes[2],this.joystick.y=t.gamepad.axes[3])}updateLastHit(){var r;const t=this.raycast(),i=t?t[0]:null;this.lastHit=i;let s=1;if(this.webXR.Rig&&(s/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=s*(((r=this.lastHit)==null?void 0:r.distance)??9999);const o=this.raycastLine.material;i!=null?o.color=Jn.raycastColor:o.color=Jn.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const o=ot.clamp(this.lastHit.distance*.01*s,.015,.1);this._raycastHitPoint.scale.set(o,o,o)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return i}onSelectStart(){this.context.connection.allowEditing&&(this.selectStartCallback=()=>this.onHandleSelectStart())}onHandleSelectStart(){this.selectStartCallback=null,this._selectionPressed=!0,this._selectionStartTime=this.context.time.time,this._selectionEndTime=1e3;let t=null,i=!1;if(this.isUsingHands?(t=this.overlap(),t.length<=0?(t=this.raycast(),i=!1):i=!0):t=this.raycast(),Zm&&console.log("onHandleSelectStart","close grab? "+i,"intersections",t),t&&t.length>0)for(const s of t){const r=s.object;this.lastSelectStartObject=r;const o={selected:r,grab:r},a=Jn.eventSubs["select-start"];if(a&&a.length>0)for(const c of a)c(this,o);o.grab!==r&&Zm&&console.log("Grabbed object changed","original",r,"new",o.grab),o.grab&&(this.grabbed=Oo.TryTake(this,o.grab,s,i));break}else{const s=Jn.eventSubs["select-start"],r={selected:null,grab:null};if(s&&s.length>0)for(const o of s)o(this,r)}}onSelectEnd(){var s;if(this.isUsingHands&&this.handPointerModel.pinched){this._didNotEndSelection=!0;return}if(!this._selectionPressed)return;this.selectStartCallback=null,this._selectionPressed=!1,this._selectionEndTime=this.context.time.time;const t={grab:((s=this.grabbed)==null?void 0:s.selected)??this.lastSelectStartObject},i=Jn.eventSubs["select-end"];if(i&&i.length>0)for(const r of i)r(this,t);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(t){return!(!t||ne.isActiveInHierarchy(t)===!1||vp.isInteractable(t)===!1)}setControllerLayers(t,i){var s,r;if(t&&(t.layers.set(i),t.children))for(const o of t.children)((s=this.grabbed)==null?void 0:s.selected)===o||((r=this.grabbed)==null?void 0:r.selectedMesh)===o||this.setControllerLayers(o,i)}getRay(){const t=new va;return t.origin.copy(pt(this.controller)),t.direction.set(0,0,-1).applyQuaternion(this.rayRotation),t}overlap(){const t=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(Zm&&(!this.closeGrabBoundingBoxHelper&&t&&(this.closeGrabBoundingBoxHelper=new ox(t,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&t&&this.closeGrabBoundingBoxHelper.setFromObject(t)),!t)return new Array;const i=pt(t).clone();return this.context.physics.sphereOverlap(i,.02)}raycast(){const t=new eo;t.layerMask=new Gs,t.layerMask.enableAll(),t.layerMask.disable(2),t.ray=this.getRay();const i=this.context.physics.raycast(t);for(let s=0;s<i.length;s++){const r=i[s],o=r.object;if(!this.testIsVisible(o)){i.splice(s,1),s--;continue}r.object=vp.getObject(o);break}return i}};let rn=Jn;h(rn,"Factory",new Iie),h(rn,"raycastColor",new be(.9,.3,.3)),h(rn,"raycastNoHitColor",new be(.6,.6,.6)),h(rn,"geometry",new At().setFromPoints([new w(0,0,0),new w(0,0,-1)])),h(rn,"handModels",{}),h(rn,"eventSubs",{}),h(rn,"PreviousCameraFarDistance"),h(rn,"MovementSpeedFactor",1);var c_=(n=>(n.WillTake="WillTake",n.DidTake="DidTake",n.WillFree="WillFree",n.DidFree="DidFree",n))(c_||{});const er=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 Ce(0,0,0,1));h(this,"targetDir",null);h(this,"quaternionLerp",null);h(this,"controllerDir",new w);h(this,"controllerWorldPos",new w);h(this,"lastControllerWorldPos",new w);h(this,"controllerPosDelta",new w);h(this,"totalChangeAlongDirection",0);h(this,"rigPositionLastFrame",new w)}static AddEventListener(e,t){return er.Events[e]||(er.Events[e]=[]),er.Events[e].push(t),t}static RemoveEventListener(e,t){if(!t||!er.Events[e])return;const i=er.Events[e].indexOf(t);i>=0&&er.Events[e].splice(i,1)}static Register(e){this.Current.find(t=>t===e)||this.Current.push(e)}static Remove(e){const t=this.Current.indexOf(e);t>=0&&this.Current.splice(t,1)}static TryTake(e,t,i,s){const r=ne.getComponentInParent(t,Lp);if(r)t=r.gameObject;else return Zm&&console.warn("Prevented taking object that is not interactable",t),null;let o=t;const a=ne.getComponentInParent(t,Ah);a&&(a.requestOwnership(),o=a.gameObject);for(const l of this.Current)if(l.selected===o)return l.controller===e||(l.free(),l.Take(e,o,t,a,r,i,s)),l;const c=new er;return c.Take(e,o,t,a,r,i,s),c}Take(e,t,i,s,r,o,a){var p,m;if(console.assert(t!==null,"Expected object to be taken but was",t),e.isUsingHands?this.positionSource=a?e.wrist:e.controller:this.positionSource=e.controller,!this.positionSource)return console.warn("No position source"),this;const c={controller:e,take:t,hit:i,sync:s,interactable:r};(p=er.Events.WillTake)==null||p.forEach(v=>v(this,c));const l=i;l!=null&&l.material&&(this.originalMaterial=l.material,Array.isArray(l.material)||(l.material=l.material.clone(),l.material&&l.material.emissive&&(l.material.emissive.b=.2))),this.selected=t,this.selectedParent||(this.selectedParent=t.parent),this.selectedMesh=l,this.controller=e,this.interactable=r,this.isCloseGrab=a,this.didReparent=!1,this.sync=s,this.grabTime=e.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=ne.addNewComponent(this.selected,Fp),this.rigidbodies=ne.getComponentsInChildren(this.selected,Pi),pt(this.positionSource,this.lastControllerWorldPos);const u=()=>a?this.lastControllerWorldPos.clone():o.point.clone();this.grabDistance=u().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(u());const d=e.isUsingHands&&a?this.controller.getWristQuaternion().clone():e.rayRotation.clone();Ei(this.selected,this.localQuaternionToGrab).premultiply(d.invert());const f=this.controller.webXR.Rig;return f&&this.rigPositionLastFrame.copy(pt(f)),ar.Add(e.context,this.selected),er.Register(this),this.sync&&(this.sync.fastMode=!0),(m=er.Events.DidTake)==null||m.forEach(v=>v(this,c)),this}free(){var s,r,o,a;if(!this.selected)return;const e={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(s=er.Events.WillFree)==null||s.forEach(c=>c(this,e)),ar.Remove(this.controller.context,this.selected),er.Remove(this),this.sync&&(this.sync.fastMode=!1);const t=this.selectedMesh;t&&this.originalMaterial&&t.material&&(t.material=this.originalMaterial);const i=this.selected;if(this.didReparent&&i.parent){const c=this.selectedParent;c?c.attach(i):(r=this.controller)==null||r.context.scene.attach(i)}if((o=this.usageMarker)==null||o.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const c of this.rigidbodies)c.wakeUp(),c.setVelocity(c.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(a=er.Events.DidFree)==null||a.forEach(c=>c(this,e))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),pt(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const e=this.controller.webXR.Rig;if(e){const i=pt(e),s=this.rigPositionLastFrame.sub(i);this.controllerPosDelta.add(s),this.rigPositionLastFrame.copy(i)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var e;if(this.rigidbodies)for(const t of this.rigidbodies)t.resetVelocities();if(this.sync&&this.controller&&this.controller.context.connection.isInRoom&&this.controller.context.time.time-this.grabTime>3&&this.sync.hasOwnership()===!1&&(console.log("no ownership, will leave",this.sync.guid),this.free()),!(this.interactable&&!this.interactable.canGrab)){if(!this.didReparent&&this.selected&&this.controller){const t=((e=this.controller.webXR.Rig)==null?void 0:e.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let i=1;this.controller.type===0&&(i=Math.max(0,1+this.totalChangeAlongDirection*2/t),i=i*i*i),this.grabDistance/t<.8&&(i=1),this.targetDir||(this.targetDir=new w),this.targetDir.set(0,0,-this.grabDistance*i);const s=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),r=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=r.clone()),this.quaternionLerp.slerp(r,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),lr(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(pt(this.selected)),s.sub(this.localPositionOffsetToGrab_worldSpace)),yn(this.selected,s)}if(this.rigidbodies!=null)for(const t of this.rigidbodies)t.wakeUp();Hs.markDirty(this.selected,!0)}}};let Oo=er;h(Oo,"Events",{}),h(Oo,"Current",[]);class Yc{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==null?void 0: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 Yc(this.input,this._event);return Object.assign(e,this),e}}function qM(n){return ne.foreachComponent(n,t=>{const i=t;if(i.onPointerDown||i.onPointerUp||i.onPointerEnter||i.onPointerExit||i.onPointerClick)return!0},!1)===!0}var zie=Object.defineProperty,Gie=Object.getOwnPropertyDescriptor,Vie=(n,e,t,i)=>{for(var s=i>1?void 0:i?Gie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&zie(e,t,s),s};class Rh extends Ie{awake(){rr.createIfNoneExists(this.context)}onEnable(){var e;(e=rr.get(this.context))==null||e.register(this)}onDisable(){var e;(e=rr.get(this.context))==null||e.unregister(this)}performRaycast(e=null){return null}}class ga extends Rh{constructor(){super(...arguments);h(this,"targets",null);h(this,"raycastHits",[]);h(this,"ignoreSkinnedMeshes",!1)}start(){this.targets=[this.gameObject]}performRaycast(t=null){if(!this.targets)return null;t??(t=new eo),t.targets=this.targets,t.results=this.raycastHits;const i=t.testObject;this.ignoreSkinnedMeshes&&(t.testObject=r=>r instanceof ua?"continue in children":i?i(r):!0);const s=this.context.physics.raycast(t);return t.testObject=i,s}}Vie([x()],ga.prototype,"ignoreSkinnedMeshes",2);class jx extends ga{constructor(){super(),this.ignoreSkinnedMeshes=!0}}function qx(n){const e=n[Bo];return e||(n.parent?qx(n.parent):null)}function Hie(n){return n.isUI===!0||typeof n[Bo]=="object"}function l_(n,e){if(!n)return;const t=n.material;if((t==null?void 0:t.isMaterial)===!0){const i=n.parent;i&&i.isText,t.side=e.doubleSided??!0?bi:Qs,t.shadowSide=e.doubleSided?bi:Qs,n.castShadow=e.castShadows?e.castShadows:!1,n.receiveShadow=e.receiveShadows?e.receiveShadows:!1}for(const i of n.children)l_(i,e)}function Af(n,e,t){n[e]===void 0&&console.warn("Field",e,"is undefined on",n);const i=Proxy.revocable(n[e],{set(o,a,c,l){const u=o[a],d=Reflect.set(o,a,c,l);return t(c,u),d}}),s=i.revoke,r=n[e];return i.revoke=()=>{n[e]=r,s()},n[e]=i.proxy,i}const gk=Symbol("Scheduled action");function Qie(n,e,t=ns.OnBeforeRender){let i=n[gk];i||(i=n[gk]={});const s=e.name;i[t]||(i[t]={});const r=i[t];if(r[s])return;function*a(){e==null||e.call(n),r[s]=null}const c=n.startCoroutine(a(),t);r[s]=c}const mu=re("debugeventsystem");var XM=(n=>(n.BeforeHandleInput="BeforeHandleInput",n.AfterHandleInput="AfterHandleInput",n))(XM||{});const Oa=class extends Ie{constructor(){super();h(this,"raycaster",[]);h(this,"_selectStartFn");h(this,"_selectEndFn");h(this,"_selectUpdateFn");h(this,"_handleEventCycleFn");h(this,"_handleInputFn");h(this,"pressedByID",new Map);h(this,"hoveredByID",new Map);h(this,"_sortedHits",[]);h(this,"_testObjectsCache",new Map);h(this,"shouldRaycastObject",t=>{var r;let i=null;if(Hie(t)&&(i=(r=t[Bo])==null?void 0:r.gameObject),this._testObjectsCache.has(t)||i&&this._testObjectsCache.has(i))return this._testObjectsCache.get(t)===!1?"continue in children":!0;{let o=qM(t);return!o&&i&&(o=qM(i)),o?(this._testObjectsCache.set(t,!0),t.traverse(a=>{this._testObjectsCache.set(a,!0)}),!0):(this._testObjectsCache.set(t,!1),"continue in children")}});h(this,"_sortingBuffer",[]);h(this,"_noDepthTestingResults",[]);h(this,"out",{});h(this,"currentActiveMeshUIComponents",[]);Oa.systems.push(this)}static createIfNoneExists(t){this.didSearchEventSystem||(this.didSearchEventSystem=!0,Oa.systems.length<=0&&Oa.systems.push(...ne.findObjectsOfType(Oa,t)));for(const s of Oa.systems)if(s.context===t)return;const i=new _e;ne.addNewComponent(i,Oa),t.scene.add(i)}static get systems(){const t=Lt.Current;return this._eventSystemMap.has(t)||this._eventSystemMap.set(t,[]),this._eventSystemMap.get(t)}static get(t){const i=this._eventSystemMap.get(t);return i&&i.length>0?i[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(t,i,s=!1){Fc.update(t,i,s)}static markUIDirty(t){Fc.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.hoveredByID.size>0}onDestroy(){Oa.systems.splice(Oa.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!ne.findObjectOfType(Rh,this.context)){const i=ne.addNewComponent(this.context.scene,ga);i.ignoreSkinnedMeshes=!0,this.raycaster.push(i),(Vt()||mu)&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found. Skinnedmeshes will be ignored for better performance")}}register(t){var i;t&&this.raycaster&&!this.raycaster.includes(t)&&((i=this.raycaster)==null||i.push(t))}unregister(t){var s,r;const i=(s=this.raycaster)==null?void 0:s.indexOf(t);i!==void 0&&i!==-1&&((r=this.raycaster)==null||r.splice(i,1))}onEnable(){const t=new Map;this._selectStartFn??(this._selectStartFn=(s,r)=>{if(!r.grab)return;Fc.resetLastSelected();const o=new Yc(this.context.input);o.inputSource=s,o.pointerId=0,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=!1,t.set(s,r.grab),r.grab&&!this.handleEventOnObject(r.grab,o)&&(r.grab=null)}),this._selectEndFn??(this._selectEndFn=(s,r)=>{var c;if(!r.grab)return;const o=new Yc(this.context.input);o.inputSource=s,o.pointerId=0,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=s.selectionClick,this.handleEventOnObject(r.grab,o);const a=t.get(s);if(t.set(s,null),a)for(const l of this.pressedByID.keys()){const u=this.pressedByID[l];u&&u.obj===a&&u.handler&&((c=u.handler.onPointerUp)==null||c.call(u.handler,o),this.pressedByID.delete(l))}});const i=new eo;this._selectUpdateFn??(this._selectUpdateFn=s=>{var a;i.ray=s.getRay();const r=this.performRaycast(i)??[],o=new Yc(this.context.input);o.inputSource=s,o.pointerId=((a=s.input)==null?void 0:a.handedness)==="right"?0:1,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=!1,this.handleIntersections(o.pointerId,r,o)}),rn.addEventListener(Lc.SelectStart,this._selectStartFn),rn.addEventListener(Lc.SelectEnd,this._selectEndFn),rn.addEventListener(Lc.Update,this._selectUpdateFn),this._handleInputFn=this.onPointerEvent.bind(this),this.context.input.addEventListener(fn.PointerDown,this._handleInputFn),this.context.input.addEventListener(fn.PointerUp,this._handleInputFn),this.context.input.addEventListener(fn.PointerMove,this._handleInputFn)}onDisable(){rn.removeEventListener(Lc.SelectStart,this._selectStartFn),rn.removeEventListener(Lc.SelectEnd,this._selectEndFn),rn.removeEventListener(Lc.Update,this._selectUpdateFn),this.context.input.removeEventListener(fn.PointerDown,this._handleInputFn),this.context.input.removeEventListener(fn.PointerUp,this._handleInputFn),this.context.input.removeEventListener(fn.PointerMove,this._handleInputFn)}onBeforeRender(){this.resetMeshUIStates()}onPointerEvent(t){if(t===void 0)return;const i=t.pointerType==lp.Touch?t.button:0,s=new Yc(this.context.input,t);s.inputSource=this.context.input,s.pointerId=t.button,s.isClicked=t.type==fn.PointerUp&&this.context.input.getPointerClicked(t.button),s.isDown=t.type==fn.PointerDown,s.isUp=t.type==fn.PointerUp,s.isPressed=this.context.input.getPointerPressed(t.button),mu&&s.isClicked&&console.log("CLICK",s.pointerId);const r=new eo;r.screenPoint=this.context.input.getPointerPositionRC(i);const o=this.performRaycast(r);if(!o)return;mu&&s.isClicked&&An("EventSystem: "+s.pointerId+" - "+this.context.time.frame+" - Up:"+s.isUp+", Down:"+s.isDown);const a={sender:this,args:s,hasActiveUI:this.currentActiveMeshUIComponents.length>0};this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:a})),this.handleIntersections(i,o,s),this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:a}))}performRaycast(t){if(!this.raycaster)return null;this._sortedHits.length=0,t||(t=new eo),this._testObjectsCache.clear(),t.testObject=this.shouldRaycastObject;for(const i of this.raycaster){if(!i.activeAndEnabled)continue;const s=i.performRaycast(t);s&&s.length>0&&this._sortedHits.push(...s)}return this._sortedHits.sort((i,s)=>i.distance-s.distance),this._sortedHits}handleIntersections(t,i,s){if(i!=null&&i.length){i=this.sortCandidates(i);for(const o of i){const{object:a}=o;if(s.point=o.point,s.normal=o.normal,s.face=o.face,s.distance=o.distance,s.instanceId=o.instanceId,this.handleEventOnObject(a,s))return!0}}const r=this.hoveredByID.get(t);if(r&&this.triggerOnExit(r.obj,r.data),this.hoveredByID.delete(t),s.isUp){const o=this.pressedByID.get(t);o==null||o.handlers.forEach(a=>{var c;return(c=a.onPointerUp)==null?void 0:c.call(a,s)}),this.pressedByID.delete(t)}return!1}sortCandidates(t){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let i=0;i<t.length;i++){const s=t[i],r=s.object;if(r.material&&r.material.depthTest===!1){this._noDepthTestingResults.push(s);continue}this._sortingBuffer.push(s)}for(const i of this._sortingBuffer)this._noDepthTestingResults.push(i);return this._noDepthTestingResults}handleEventOnObject(t,i){if(!this.testIsVisible(t))return i.isClicked&&mu&&console.log("not allowed",t),!1;if(i.pointerId===void 0)return mu&&console.warn("Event without pointer can't be handled",i),!1;i.object=t;const s=t.parent;let r=!1;const o=i.isClicked??!1;let a=null;if(s&&s.isUI){const d=(i.isPressed||i.isClicked)??!1;if(s[Bo]){const f=s[Bo].gameObject;if(f){if(!vp.isInteractable(f,this.out))return!1;a=this.out.canvasGroup??null,this.handleMeshUIIntersection(t,d),t=f,r=!0}}if(!r&&this.handleMeshUiObjectWithoutShadowDom(s,d))return!0}o&&mu&&console.log(this.context.time.frame,t);const c=this.hoveredByID.get(i.pointerId),l=(c==null?void 0:c.obj)!==t;l&&(c!=null&&c.obj)&&this.triggerOnExit(c.obj,c.data);const u=this.hoveredByID.get(i.pointerId);if(u?(u.obj=t,u.data=i):this.hoveredByID.set(i.pointerId,{obj:t,data:i}),i.isDown){const d=this.pressedByID.get(i.pointerId);d?(d.obj=t,d.data=i):this.pressedByID.set(i.pointerId,{obj:t,data:i,handlers:new Set})}return(a===null||a.interactable)&&this.handleMainInteraction(t,i,l),!0}propagate(t,i,s){for(;;){if(i.used)return;if(ne.foreachComponent(t,r=>{s(r)},!1),!t.parent)break;t=t.parent}}handleMainInteraction(t,i,s){if(i.pointerId===void 0)return;const r=this.pressedByID.get(i.pointerId);this.propagate(t,i,o=>{var d;const a=o;if(a.interactable===!1)return;a.onPointerEnter&&s&&a.onPointerEnter(i),i.isDown&&a.onPointerDown&&(a.onPointerDown(i),r==null||r.handlers.add(a));const c=this.context.input.getPointerPositionLastFrame(i.pointerId),l=this.context.input.getPointerPosition(i.pointerId);c&&!ot.approximately(c,l)&&a.onPointerMove&&a.onPointerMove(i),i.isUp&&(a.onPointerUp&&(a.onPointerUp(i),r==null||r.handlers.delete(a)),a.onPointerExit&&((d=i.event)==null?void 0:d.pointerType)===lp.Touch&&(a.onPointerExit(i),this.hoveredByID.delete(i.pointerId))),i.isClicked&&a.onPointerClick&&a.onPointerClick(i)}),i.isUp&&(r==null||r.handlers.forEach(o=>{o.onPointerUp&&o.onPointerUp(i)}),this.pressedByID.delete(i.pointerId))}triggerOnExit(t,i){i.used=!1,this.propagate(t,i,s=>{if(!s.gameObject||s.destroyed)return;const r=s;r.onPointerExit&&r.onPointerExit(i)})}handleMeshUiObjectWithoutShadowDom(t,i){return!t||!t.isUI?!0:this.handleMeshUIIntersection(t,i)}handleMeshUIIntersection(t,i){const s=Fc.updateState(t,i);return s&&this.currentActiveMeshUIComponents.push(s),s!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&Fc.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let t=0;t<this.currentActiveMeshUIComponents.length;t++){const i=this.currentActiveMeshUIComponents[t];Fc.resetState(i)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(t){return t?ne.isActiveSelf(t)?this.testIsVisible(t.parent):!1:!0}};let rr=Oa;h(rr,"_eventSystemMap",new Map),h(rr,"didSearchEventSystem",!1);class Fc{static markDirty(){this.needsUpdate=!0}static update(e,t,i=!1){if(i){e.update();return}const s=t.time.frameCount;for(const r of this.lastUpdateFrame)if(r.context===t){if(s===r.frame)return;r.frame=s;let o=this.needsUpdate||s<1;r.nextUpdate===t.time.frameCount&&(o=!0),o&&(mu&&console.log("Update threemeshui"),this.needsUpdate=!1,e.update());return}this.lastUpdateFrame=[{context:t,frame:s,nextUpdate:s}],e.update()}static updateState(e,t){let i=null;if(e&&(i=this.findBlockInParent(e),i&&i!==this.lastSelected)){if(i.interactable===!1)return null;this.needsUpdate=!0}return i}static resetLastSelected(){const e=this.lastSelected;e&&(this.lastSelected=null,this.resetState(e))}static resetState(e){e&&(this.needsUpdate=!0)}static findBlockInParent(e){return e?e.isBlock?e:this.findBlockInParent(e.parent):null}}h(Fc,"lastSelected",null),h(Fc,"lastUpdateFrame",[]),h(Fc,"needsUpdate",!1);const ub=Symbol("cameraController");function Wie(n){return n[ub]}function Ak(n,e,t){t?n[ub]=e:n[ub]===e&&(n[ub]=null)}const vk=Symbol("camera autofit");function jie(n){return n[vk]===void 0?!0:n[vk]!==!1}class TG extends ge{constructor(e,t={}){const s=[e.isCubeTexture?"#define ENVMAP_TYPE_CUBE":""],r=`
|
|
5097
5097
|
varying vec3 vWorldPosition;
|
|
5098
5098
|
|