@needle-tools/engine 3.7.1-alpha → 3.7.2-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1
- package/dist/needle-engine.js +3 -3
- package/dist/needle-engine.light.js +3 -3
- package/dist/needle-engine.light.min.js +2 -2
- package/dist/needle-engine.light.umd.cjs +2 -2
- package/dist/needle-engine.min.js +2 -2
- package/dist/needle-engine.umd.cjs +2 -2
- package/lib/engine-components/SpectatorCamera.js +1 -1
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/package.json +1 -1
- package/src/engine-components/SpectatorCamera.ts +1 -1
|
@@ -4176,7 +4176,7 @@ ${I.join(`
|
|
|
4176
4176
|
`)}
|
|
4177
4177
|
|
|
4178
4178
|
}
|
|
4179
|
-
`}function uJ(i){return`(${i.r}, ${i.g}, ${i.b})`}function pJ(i){return`(${i.x}, ${i.y})`}const AF=class{constructor(A,e,t){r(this,"id");r(this,"trigger");r(this,"action");r(this,"exclusive",!1);this.id="Behavior_"+_m(A)+"_"+AF.global_id++,this.trigger=e,this.action=t}makeExclusive(A){return this.exclusive=A,this}writeTo(A,e,t){if(!this.trigger||!this.action)return;t.beginBlock(`def Preliminary_Behavior "${this.id}"`),t.appendLine(`rel actions = <${this.action.id}>`),t.appendLine(`uniform bool exclusive = ${this.exclusive}`);let g="";if(Array.isArray(this.trigger)){g="[";for(let I=0;I<this.trigger.length;I++){const o=this.trigger[I];g+="<"+o.id+">",I+1<this.trigger.length&&(g+=", ")}g+="]"}else g=`<${this.trigger.id}>`;if(t.appendLine(`rel triggers = ${g} `),t.appendLine(),Array.isArray(this.trigger))for(const I of this.trigger)I.writeTo(e,t),t.appendLine();else this.trigger.writeTo(e,t);t.appendLine(),this.action.writeTo(e,t),t.closeBlock()}};let dg=AF;r(dg,"global_id",0);function GG(i,A){var t,g;let e="";if(Array.isArray(i)){let I="[ ";for(let o=0;o<i.length;o++){let C=i[o];if(typeof C=="string")I+=C;else if(typeof C=="object"){C.isObject3D&&(C=A.findById(C.uuid));const s=(t=C.getPath)==null?void 0:t.call(C);I+=s}o+1<i.length&&(I+=", ")}I+=" ]",e=I}else typeof i=="object"&&(i.isObject3D&&(i=A.findById(i.uuid)),e=(g=i.getPath)==null?void 0:g.call(i));return e=e.replace(A.name,A.name+"/Scenes/Scene"),e}const eF=class{constructor(A,e){r(this,"id");r(this,"targetId");r(this,"tokenId");r(this,"type");r(this,"distance");A&&(this.targetId=A),e?this.id=e:this.id="Trigger_"+eF.global_id++}writeTo(A,e){e.beginBlock(`def Preliminary_Trigger "${this.id}"`),this.targetId&&(typeof this.targetId!="string"&&(this.targetId=GG(this.targetId,A)),e.appendLine("rel affectedObjects = "+this.targetId)),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.type&&e.appendLine(`token type = "${this.type}"`),typeof this.distance=="number"&&e.appendLine(`double distance = ${this.distance}`),e.closeBlock()}};let js=eF;r(js,"global_id",0);class SI{static sceneStartTrigger(){const A=new js;return A.targetId=void 0,A.tokenId="SceneTransition",A.type="enter",A}static tapTrigger(A){const e=new js(A);return e.tokenId="TapGesture",e}static isTapTrigger(A){return(A==null?void 0:A.tokenId)==="TapGesture"}static proximityToCameraTrigger(A,e){const t=new js(A);return t.tokenId="ProximityToCamera",t.distance=e,t}}class oa{constructor(A,e){r(this,"id");r(this,"actions");r(this,"loops",0);r(this,"performCount",1);r(this,"type","serial");this.id=A,this.actions=e}static getId(){return this.global_id++}addAction(A){return this.actions.push(A),this}makeParallel(){return this.type="parallel",this}makeSequence(){return this.type="serial",this}makeLooping(){return this.loops=1,this}makeRepeat(A){return this.performCount=A,this}writeTo(A,e){e.beginBlock(`def Preliminary_Action "${this.id}"`),e.beginArray("rel actions");for(const t of this.actions)t&&e.appendLine("<"+t.id+">,");e.closeArray(),e.appendLine(),e.appendLine('token info:id = "Group"'),e.appendLine(`bool loops = ${this.loops} `),e.appendLine(`int performCount = ${this.performCount} `),e.appendLine(`token type = "${this.type}"`),e.appendLine();for(const t of this.actions)t&&(t.writeTo(A,e),e.appendLine());e.closeBlock()}}r(oa,"global_id",0);var Om=(i=>(i[i.pop=0]="pop",i[i.blink=1]="blink",i[i.bounce=2]="bounce",i[i.flip=3]="flip",i[i.float=4]="float",i[i.jiggle=5]="jiggle",i[i.pulse=6]="pulse",i[i.spin=7]="spin",i))(Om||{}),MG=(i=>(i.Relative="relative",i.Absolute="absolute",i))(MG||{});const Ff=class{constructor(A,e){r(this,"id");r(this,"tokenId");r(this,"affectedObjects");r(this,"easeType");r(this,"motionType");r(this,"duration");r(this,"moveDistance");r(this,"style");r(this,"type");r(this,"front");r(this,"up");r(this,"start");r(this,"animationSpeed");r(this,"reversed");r(this,"pingPong");r(this,"xFormTarget");r(this,"audio");r(this,"gain");r(this,"auralMode");r(this,"multiplePerformOperation");A&&(this.affectedObjects=A),e?this.id=e:this.id="Action",this.id+="_"+Ff.global_id++}clone(){const A=new Ff,e=A.id;return Object.assign(A,this),A.id=e,A}writeTo(A,e){e.beginBlock(`def Preliminary_Action "${this.id}"`),this.affectedObjects&&(typeof this.affectedObjects!="string"&&(this.affectedObjects=GG(this.affectedObjects,A)),e.appendLine("rel affectedObjects = "+this.affectedObjects)),typeof this.duration=="number"&&e.appendLine(`double duration = ${this.duration} `),this.easeType&&e.appendLine(`token easeType = "${this.easeType}"`),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.motionType&&e.appendLine(`token motionType = "${this.motionType}"`),typeof this.moveDistance=="number"&&e.appendLine(`double moveDistance = ${this.moveDistance} `),this.style&&e.appendLine(`token style = "${this.style}"`),this.type&&e.appendLine(`token type = "${this.type}"`),this.front&&e.appendLine(`vector3d front = (${this.front.x}, ${this.front.y}, ${this.front.z})`),this.up&&e.appendLine(`vector3d upVector = (${this.up.x}, ${this.up.y}, ${this.up.z})`),typeof this.start=="number"&&e.appendLine(`double start = ${this.start} `),typeof this.animationSpeed=="number"&&e.appendLine(`double animationSpeed = ${this.animationSpeed} `),typeof this.reversed=="boolean"&&e.appendLine(`bool reversed = ${this.reversed}`),typeof this.pingPong=="boolean"&&e.appendLine(`bool reverses = ${this.pingPong}`),this.xFormTarget&&(typeof this.xFormTarget!="string"&&(this.xFormTarget=GG(this.xFormTarget,A)),e.appendLine(`rel xformTarget = ${this.xFormTarget}`)),typeof this.audio=="string"&&e.appendLine(`asset audio = @${this.audio}@`),typeof this.gain=="number"&&e.appendLine(`double gain = ${this.gain}`),typeof this.auralMode=="string"&&e.appendLine(`token auralMode = "${this.auralMode}"`),typeof this.multiplePerformOperation=="string"&&e.appendLine(`token multiplePerformOperation = "${this.multiplePerformOperation}"`),e.closeBlock()}};let TI=Ff;r(TI,"global_id",0);let uQ=class sQ{constructor(A,e,t){r(this,"x",0);r(this,"y",0);r(this,"z",0);this.x=A,this.y=e,this.z=t}static get up(){return new sQ(0,1,0)}static get right(){return new sQ(1,0,0)}static get forward(){return new sQ(0,0,1)}static get back(){return new sQ(0,0,-1)}static get zero(){return new sQ(0,0,0)}};var LT=(i=>(i.Play="play",i.Pause="pause",i.Stop="stop",i))(LT||{}),mG=(i=>(i.Spatial="spatial",i.NonSpatial="nonSpatial",i.Ambient="ambient",i))(mG||{});class rt{static sequence(...A){return new oa("group_"+oa.getId(),A).makeSequence()}static parallel(...A){return new oa("group_"+oa.getId(),A).makeParallel()}static fadeAction(A,e,t){const g=new TI(A);return g.tokenId="Visibility",g.type=t?"show":"hide",g.duration=e,g.style="basic",g.motionType="none",g.moveDistance=0,g.easeType="none",g}static startAnimationAction(A,e,t=0,g=1,I=!1,o=!1){const C=new TI(A);if(C.tokenId="StartAnimation",C.start=e,C.duration=t,C.animationSpeed=g,C.reversed=I,C.pingPong=o,I&&(C.start-=t),o){C.pingPong=!1;const s=C.clone();return s.reversed=!I,s.start=C.start,s.reversed&&(s.start-=t),rt.sequence(C,s)}return C}static waitAction(A){const e=new TI;return e.tokenId="Wait",e.duration=A,e}static lookAtCameraAction(A,e=9999999999999,t,g){const I=new TI(A);return I.tokenId="LookAtCamera",I.duration=e,I.front=t??uQ.forward,I.up=g??uQ.up,I}static emphasize(A,e,t=2,g=1,I="basic"){const o=new TI(A);return o.tokenId="Emphasize",o.duration=e,o.style=I??"basic",o.motionType=Om[t],o.moveDistance=g,o}static transformAction(A,e,t,g,I="inout"){const o=new TI(A);return o.tokenId="Transform",o.duration=t,o.type=g,o.easeType=I,Array.isArray(e)&&console.error("Transform target must not be an array",e),o.xFormTarget=e,o}static playAudioAction(A,e,t="play",g=1,I="spatial"){const o=new TI(A);return o.tokenId="Audio",o.type=t,o.audio=e,o.gain=g,o.auralMode=I,o.multiplePerformOperation="allow",o}}class Q6{constructor(A){r(this,"object");r(this,"model");this.object=A}get id(){return this.object.uuid}apply(A){if(!this.model&&(this.model=A.findById(this.object.uuid),!this.model)){console.error("could not find model with id "+this.object.uuid);return}this.onApply(A)}}class Pm extends Q6{constructor(e,t,g,I){super(e);r(this,"matrix");r(this,"material");r(this,"geometry");r(this,"_enableAction");r(this,"_disableAction");this.matrix=t,this.material=g,this.geometry=I}onApply(e){var I,o;const t=this.model;if(!t)return;(I=t.parent)!=null&&I.isDynamic||Go.createEmptyParent(t);const g=t.clone();this.matrix&&(g.matrix=this.matrix),this.material&&(g.material=this.material),this.geometry&&(g.geometry=this.geometry),(o=t.parent)==null||o.add(g)}enable(){return this._enableAction?this._enableAction:(this._enableAction=rt.fadeAction(this.object,0,!0),this._enableAction)}disable(){return this._disableAction?this._disableAction:(this._disableAction=rt.fadeAction(this.object,0,!1),this._disableAction)}}class Wm{constructor(A){r(this,"actions");r(this,"sortedActions");this.actions=[...A]}organize(){this.sortedActions={};for(const A of this.actions){const e=A.id;this.sortedActions[e]||(this.sortedActions[e]=[]),this.sortedActions[e].push(A)}}getActions(A){return this.sortedActions||this.organize(),this.sortedActions[A.uuid]}}var E6=Object.defineProperty,c6=Object.getOwnPropertyDescriptor,vT=(i,A,e,t)=>{for(var g=t>1?void 0:t?c6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&E6(A,e,g),g};class dd extends MA{constructor(){super(...arguments);r(this,"from");r(this,"to");r(this,"width",0);r(this,"centered",!0);r(this,"_centerPos")}awake(){this._centerPos=new S}update(){if(!this.from||!this.to)return;const e=ye(this.from).clone(),t=ye(this.to).clone(),g=e.distanceTo(t);this._centerPos.copy(e),this._centerPos.add(t),this._centerPos.multiplyScalar(.5),di(this.gameObject,this.centered?this._centerPos:e),this.gameObject.lookAt(ye(this.to).clone()),this.gameObject.scale.set(this.width,this.width,g)}}vT([w(AA)],dd.prototype,"from",2);vT([w(AA)],dd.prototype,"to",2);var h6=Object.defineProperty,l6=Object.getOwnPropertyDescriptor,ud=(i,A,e,t)=>{for(var g=t>1?void 0:t?l6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&h6(A,e,g),g};const On=nA("debuganimation");class Lo extends MA{constructor(){super(...arguments);r(this,"playAutomatically",!0);r(this,"randomStartTime",!0);r(this,"minMaxSpeed");r(this,"minMaxOffsetNormalized");r(this,"loop",!0);r(this,"clampWhenFinished",!1);r(this,"_tempAnimationClipBeforeGameObjectExisted",null);r(this,"mixer");r(this,"_actions",[]);r(this,"_currentActions",[]);r(this,"_handles",[]);r(this,"_didInit",!1)}get clip(){var e;return(e=this.animations)!=null&&e.length?this.animations[0]:null}set clip(e){if(!this.__didAwake){On&&console.log("Assign clip during serialization",e),this._tempAnimationClipBeforeGameObjectExisted=e;return}e&&(On&&console.log("Assign clip",e,!!this.gameObject),this.gameObject.animations||(this.gameObject.animations=[]),!this.animations.includes(e)&&(this.animations.length>0?this.animations.splice(0,0,e):this.animations.push(e)))}set clips(e){this.animations=e}set animations(e){On&&console.log("assign animations",e),this.gameObject.animations=e}get animations(){return this.gameObject.animations}get currentAction(){return this._currentActions[0]}get currentActions(){return this._currentActions}get actions(){return this._actions}set actions(e){this._actions=e}awake(){On&&console.log(this),this._tempAnimationClipBeforeGameObjectExisted&&(this.clip=this._tempAnimationClipBeforeGameObjectExisted,this._tempAnimationClipBeforeGameObjectExisted=null),this.playAutomatically&&this.init()}onEnable(){var e;if(this.playAutomatically&&((e=this.animations)==null?void 0:e.length)>0&&this.currentActions.length<=0){const t=Math.floor(Math.random()*this.actions.length);this.play(t)}}start(){this.randomStartTime&&this.currentAction&&(this.currentAction.time=Math.random()*this.currentAction.getClip().duration)}update(){this.mixer&&this.mixer.update(this.context.time.deltaTime)}getAction(e){var t;return(t=this.actions)==null?void 0:t.find(g=>g.getClip().name===e)}get isPlaying(){for(let e=0;e<this._currentActions.length;e++)if(this._currentActions[e].isRunning())return!0;return!1}play(e=0,t){if(On&&console.log("PLAY",e),this.init(),!this.mixer){On&&console.warn("Missing mixer",this);return}e===void 0&&(e=0);let g=e;if(typeof e=="number"){if(e>=this.animations.length){On&&console.log("No animation at index",e);return}g=this.animations[e]}else typeof e=="string"&&(g=this.animations.find(o=>o.name===e));if(!g){console.error("Could not find clip",e);return}t||(t={}),t.minMaxOffsetNormalized||(t.minMaxOffsetNormalized=this.minMaxOffsetNormalized),t.minMaxSpeed||(t.minMaxSpeed=this.minMaxSpeed),t.loop===void 0&&(t.loop=this.loop),t.clampWhenFinished===void 0&&(t.clampWhenFinished=this.clampWhenFinished);for(const o of this.actions)if(o.getClip()===g)return this.internalOnPlay(o,t);if(!(g instanceof Jo)){console.warn("Clip is no AnimationClip",g,"on object: "+this.name);return}const I=this.mixer.clipAction(g);return this.actions.push(I),this.internalOnPlay(I,t)}internalOnPlay(e,t){var g=this.currentAction;if(g===e&&g.isRunning()&&g.time<g.getClip().duration){const s=this.tryFindHandle(e);if(s)return s.getPromise()}const I=(t==null?void 0:t.exclusive)??!0;t!=null&&t.fadeDuration?(I&&(g==null||g.fadeOut(t.fadeDuration)),e.fadeIn(t.fadeDuration)):I&&(g==null||g.stop()),e.reset(),e.enabled=!0,e.time=0,e.timeScale=1;const o=e.getClip();t!=null&&t.minMaxOffsetNormalized&&(e.time=ee.lerp(t.minMaxOffsetNormalized.x,t.minMaxOffsetNormalized.y,Math.random())*o.duration),t!=null&&t.minMaxSpeed&&(e.timeScale=ee.lerp(t.minMaxSpeed.x,t.minMaxSpeed.y,Math.random())),t!=null&&t.clampWhenFinished&&(e.clampWhenFinished=!0),(t==null?void 0:t.startTime)!==void 0&&(e.time=t.startTime),(t==null?void 0:t.loop)!==void 0?e.loop=t.loop?BM:Ph:e.loop=Ph,e.play(),On&&console.log("PLAY",e.getClip().name,e);const C=new d6(e,this.mixer,t,s=>{this._handles.splice(this._handles.indexOf(C),1)});return this._handles.push(C),C.getPromise()}tryFindHandle(e){for(const t of this._handles)if(t.action===e)return t}init(){this._didInit||(this._didInit=!0,this.gameObject&&(this.actions=[],this.mixer=new nw(this.gameObject)))}}ud([w()],Lo.prototype,"playAutomatically",2);ud([w()],Lo.prototype,"randomStartTime",2);ud([w()],Lo.prototype,"loop",2);ud([w()],Lo.prototype,"clampWhenFinished",2);ud([w(Jo)],Lo.prototype,"clips",1);class d6{constructor(A,e,t,g){r(this,"mixer");r(this,"action");r(this,"promise",null);r(this,"resolve",null);r(this,"reject",null);r(this,"_options");r(this,"_resolveCallback",null);r(this,"_rejectCallback",null);r(this,"_loopCallback");r(this,"_finishedCallback");r(this,"_resolvedOrRejectedCallback");this.action=A,this.mixer=e,this._resolvedOrRejectedCallback=g,this._options=t}getPromise(){return this.promise?this.promise:(this.promise=new Promise((A,e)=>{this._resolveCallback=A,this._rejectCallback=e,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 A,e;this.dispose(),(A=this._resolvedOrRejectedCallback)==null||A.call(this,this),(e=this._resolveCallback)==null||e.call(this,this.action)}onReject(A){var e,t;this.dispose(),(e=this._resolvedOrRejectedCallback)==null||e.call(this,this),(t=this._rejectCallback)==null||t.call(this,A)}onLoop(A){}onFinished(A){A.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 u6=Object.defineProperty,p6=Object.getOwnPropertyDescriptor,Ja=(i,A,e,t)=>{for(var g=t>1?void 0:t?p6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&u6(A,e,g),g};class qa{constructor(){r(this,"time");r(this,"value");r(this,"inTangent");r(this,"inWeight");r(this,"outTangent");r(this,"outWeight");r(this,"weightedMode")}}Ja([w()],qa.prototype,"time",2);Ja([w()],qa.prototype,"value",2);Ja([w()],qa.prototype,"inTangent",2);Ja([w()],qa.prototype,"inWeight",2);Ja([w()],qa.prototype,"outTangent",2);Ja([w()],qa.prototype,"outWeight",2);Ja([w()],qa.prototype,"weightedMode",2);const xT=class{constructor(){r(this,"keys")}get duration(){return!this.keys||this.keys.length==0?0:this.keys[this.keys.length-1].time}evaluate(i){if(!this.keys||this.keys.length==0)return 0;if(this.keys[0].time>=i)return this.keys[0].value;for(let A=0;A<this.keys.length;A++){const e=this.keys[A];if(e.time<=i)if(A+1<this.keys.length){const g=this.keys[A+1];if(g.time<i)continue;return!isFinite(e.outTangent)||!isFinite(g.inTangent)?e.value:xT.interpolateValue(i,e,g)}else return e.value}return this.keys[this.keys.length-1].value}static interpolateValue(i,A,e){const t=A.time,g=A.value,I=A.outTangent,o=e.time,C=e.value,s=e.inTangent,n=o-t,a=n*n,B=a*n,Q=((I+s)*n-2*(C-g))/B,E=(3*(C-g)-(s+2*I)*n)/a,c=I,h=g,l=i-t,d=l*l,p=d*l;return Q*p+E*d+c*l+h}};let IB=xT;Ja([w(qa)],IB.prototype,"keys",2);const pQ=nA("debugusdzanimation");class qw{constructor(A,e,t){r(this,"ext");r(this,"root");r(this,"clip");this.ext=A,this.root=e,this.clip=t}get start(){return this.ext.getStartTime01(this.root,this.clip)}get duration(){return this.clip.duration}}class bw{constructor(A,e,t,g){r(this,"clip");r(this,"pos");r(this,"rot");r(this,"scale");r(this,"ext");r(this,"root");r(this,"target");this.ext=A,this.root=e,this.target=t,this.clip=g}get frameRate(){return 60}addTrack(A){A.name.endsWith("position")&&(this.pos=A),A.name.endsWith("quaternion")&&(this.rot=A),A.name.endsWith("scale")&&(this.scale=A)}getFrames(){var A,e,t,g,I,o;return Math.max(((e=(A=this.pos)==null?void 0:A.times)==null?void 0:e.length)??0,((g=(t=this.rot)==null?void 0:t.times)==null?void 0:g.length)??0,((o=(I=this.scale)==null?void 0:I.times)==null?void 0:o.length)??0)}getDuration(){var e,t,g;const A=((e=this.pos)==null?void 0:e.times)??((t=this.rot)==null?void 0:t.times)??((g=this.scale)==null?void 0:g.times);return A?A[A.length-1]:0}getStartTime(A){let e=0;for(let t=0;t<A.length;t++){const g=A[t];if(g===this)return e;e+=g.getDuration()}return e}}class Lw{constructor(){r(this,"dict",new Map);r(this,"rootTargetMap",new Map);r(this,"serializers",[])}get extensionName(){return"animation"}getStartTime01(A,e){const t=this.rootTargetMap.get(A);if(!t)return 1/0;let g=-1;for(const I of t){const o=this.dict.get(I);let C=0;if(o!=null&&o.length){for(const s of o){if(s.clip===e)break;C+=s.getDuration()}g=Math.max(g,C)}else console.warn("No animation found on root",A,e,o)}return g}registerAnimation(A,e){if(!e||!A)return null;this.rootTargetMap.has(A)||this.rootTargetMap.set(A,[]);for(const g of e.tracks){const I=g.name.split(".")[2],o=A.getObjectByName(I);if(!o){console.warn("no object found for track",g.name,"using "+A.name+" instead");continue}this.dict.has(o)||this.dict.set(o,[]);const C=this.dict.get(o);if(!C)continue;let s=C.find(a=>a.clip===e);s||(s=new bw(this,A,o,e),C.push(s)),s.addTrack(g);const n=this.rootTargetMap.get(A);n!=null&&n.includes(o)||n==null||n.push(o)}return new qw(this,A,e)}onAfterHierarchy(A){pQ&&console.log(this.dict)}onAfterBuildDocument(A){var e,t;for(const g of this.serializers){const I=(e=g.model)==null?void 0:e.parent,o=(I==null?void 0:I.isDynamic)===!0;pQ&&console.log(o,(t=g.model)==null?void 0:t.parent),o&&g.registerCallback(I)}}onExportObject(A,e,t){AA.foreachComponent(A,I=>{const o=I;typeof o.createAnimation=="function"&&o.createAnimation(this,e,t)},!1);const g=new D6(A,this.dict);this.serializers.push(g),g.registerCallback(e)}}class D6{constructor(A,e){r(this,"object");r(this,"dict");r(this,"model");r(this,"callback");this.object=A,this.dict=e}registerCallback(A){this.model&&this.callback&&this.model.removeEventListener("serialize",this.callback),this.callback||(this.callback=this.onSerialize.bind(this)),pQ&&console.log("REPARENT",A),this.model=A,this.model.addEventListener("serialize",this.callback)}onSerialize(A,e){var n,a,B,Q,E,c;if(!this.model)return;pQ&&console.log("SERIALIZE",this.model.name,this.object.type);const t=this.object,g=this.dict.get(t);if(!g)return;const I=new NA,o=new S,C=new kA,s=new S(1,1,1);A.appendLine("matrix4d xformOp:transform.timeSamples = {"),A.indent++;for(const h of g){let l=(n=h.pos)==null?void 0:n.times,d=(a=h.rot)==null?void 0:a.times,p=(B=h.scale)==null?void 0:B.times,u=[];if(l)for(const f of l)u.push(f);if(d)for(const f of d)u.push(f);if(p)for(const f of p)u.push(f);if(u.sort((f,M)=>f-M),u=[...new Set(u)],!u||u.length===0){console.error("got an animated object but no time values??",t,h);continue}const D=h.getStartTime(g);pQ&&A.appendLine(h.clip.name+": start="+D.toFixed(3)+", length="+h.getDuration().toFixed(3)+", frames="+h.getFrames());const y=(Q=h.pos)==null?void 0:Q.createInterpolant(),k=(E=h.rot)==null?void 0:E.createInterpolant(),R=(c=h.scale)==null?void 0:c.createInterpolant();y||o.set(t.position.x,t.position.y,t.position.z),k||C.set(t.quaternion.x,t.quaternion.y,t.quaternion.z,t.quaternion.w),R||s.set(t.scale.x,t.scale.y,t.scale.z);for(let f=0;f<u.length;f++){const M=u[f];if(y){const J=y.evaluate(M);o.set(J[0],J[1],J[2])}if(k){const J=k.evaluate(M);C.set(J[0],J[1],J[2],J[3])}if(R){const J=R.evaluate(M);s.set(J[0],J[1],J[2])}I.compose(o,C,s);let U=`${(D+M)*h.frameRate}: ${bT(I)},`;pQ&&(U="#"+f+" "+U),A.appendLine(U)}}A.indent--,A.appendLine("}")}}class f6{constructor(){r(this,"_context")}get context(){return this._context??qe.Current}get isStateMachineBehaviour(){return!0}}class oD{constructor(A,e,t,g){r(this,"_name");r(this,"_nameHash");r(this,"_normalizedTime");r(this,"_length");r(this,"_speed");this._name=A.name,this._nameHash=A.hash,this._normalizedTime=e,this._length=t,this._speed=g}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 YT(i,A){return{name:"",isLooping:!1,guid:(A==null?void 0:A.generateUUID())??AI.generateUUID(),index:-1,clip:new Jo(i,1,[])}}var Xn=(i=>(i[i.If=1]="If",i[i.IfNot=2]="IfNot",i[i.Greater=3]="Greater",i[i.Less=4]="Less",i[i.Equals=6]="Equals",i[i.NotEqual=7]="NotEqual",i))(Xn||{}),Vm=(i=>(i[i.Float=1]="Float",i[i.Int=3]="Int",i[i.Bool=4]="Bool",i[i.Trigger=9]="Trigger",i))(Vm||{});const DC=nA("debuganimatorcontroller"),Ip=nA("debugrootmotion");class Pr{constructor(A){r(this,"normalizedStartOffset",0);r(this,"_speed",1);r(this,"animator");r(this,"model");r(this,"_mixer");r(this,"_activeState");r(this,"_activeStates",[]);r(this,"rootMotionHandler");this.model=A,DC&&console.log(this)}play(A,e=-1,t=Number.NEGATIVE_INFINITY,g=0){if(e<0)e=0;else if(e>=this.model.layers.length){console.warn("invalid layer");return}const o=this.model.layers[e].stateMachine;for(const C of o.states)if(C.name===A||C.hash===A){DC&&console.log("transition to ",C),this.transitionTo(C,g,t);return}console.warn("Could not find "+A+" to play")}reset(){this.setStartTransition()}setBool(A,e){var g,I;const t=typeof A=="string"?"name":"hash";return(I=(g=this.model)==null?void 0:g.parameters)==null?void 0:I.filter(o=>o[t]===A).forEach(o=>o.value=e)}getBool(A){var t,g,I;const e=typeof A=="string"?"name":"hash";return((I=(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.find(o=>o[e]===A))==null?void 0:I.value)??!1}setFloat(A,e){var g,I;const t=typeof A=="string"?"name":"hash";return(I=(g=this.model)==null?void 0:g.parameters)==null?void 0:I.filter(o=>o[t]===A).forEach(o=>o.value=e)}getFloat(A){var t,g,I;const e=typeof A=="string"?"name":"hash";return((I=(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.find(o=>o[e]===A))==null?void 0:I.value)??0}setInteger(A,e){var g,I;const t=typeof A=="string"?"name":"hash";return(I=(g=this.model)==null?void 0:g.parameters)==null?void 0:I.filter(o=>o[t]===A).forEach(o=>o.value=e)}getInteger(A){var t,g,I;const e=typeof A=="string"?"name":"hash";return((I=(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.find(o=>o[e]===A))==null?void 0:I.value)??0}setTrigger(A){var t,g;DC&&console.log("SET TRIGGER",A);const e=typeof A=="string"?"name":"hash";return(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.filter(I=>I[e]===A).forEach(I=>I.value=!0)}resetTrigger(A){var t,g;const e=typeof A=="string"?"name":"hash";return(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.filter(I=>I[e]===A).forEach(I=>I.value=!1)}isInTransition(){return this._activeStates.length>1}setSpeed(A){this._speed=A}FindState(A){return this.findState(A)}findState(A){if(!A)return null;if(Array.isArray(this.model.layers)){for(const e of this.model.layers)for(const t of e.stateMachine.states)if(t.name===A)return t}return null}get context(){var A;return(A=this.animator)==null?void 0:A.context}bind(A){this.animator=A,this._mixer=new nw(this.animator.gameObject),this.createActions(this.animator)}clone(){if(typeof this.model=="string")return console.warn("AnimatorController has not been resolved, can not create model from string",this.model),null;const A=qf(this.model,(t,g,I)=>I==null?!0:!(I.type==="Object3D"||I.isObject3D===!0||nv(I)||I.tracks!==void 0));return console.assert(A!==this.model),new Pr(A)}update(){var e,t;if(!this.animator||(this.evaluateTransitions(),this.updateActiveStates(),!this._activeState))return;const A=this.animator.context.time.deltaTime;this.animator.applyRootMotion&&((e=this.rootMotionHandler)==null||e.onBeforeUpdate()),this._mixer.update(A),this.animator.applyRootMotion&&((t=this.rootMotionHandler)==null||t.onAfterUpdate())}updateActiveStates(){for(let A=0;A<this._activeStates.length;A++){const e=this._activeStates[A],t=e.motion;if(!t.action)this._activeStates.splice(A,1),A--;else{const g=t.action;g.getEffectiveWeight()<=0&&!g.isRunning()&&(DC&&console.debug("REMOVE",e.name,g.getEffectiveWeight(),g.isRunning(),g.isScheduled()),this._activeStates.splice(A,1),A--)}}}setStartTransition(){for(const A of this.model.layers){const e=A.stateMachine;e.defaultState===void 0&&(DC&&console.warn("AnimatorController default state is undefined, will assign state 0 as default",A),e.defaultState=0);const t=e.states[e.defaultState];this.transitionTo(t,0,this.normalizedStartOffset)}}evaluateTransitions(){var I;let A=!1;if(!this._activeState){if(this.setStartTransition(),!this._activeState)return;A=!0}const e=this._activeState,t=e.motion.action;for(const o of e.transitions){if(!o.hasExitTime&&o.conditions.length<=0)continue;let C=!0;for(const s of o.conditions)if(!this.evaluateCondition(s)){C=!1;break}if(C){for(const s of o.conditions){const n=this.model.parameters.find(a=>a.name===s.parameter);(n==null?void 0:n.type)===Vm.Trigger&&(n.value=!1)}if(t){const s=e.motion.clip.duration,n=s<=0?1:Math.abs(t.time/s);let a=!1;if(o.hasExitTime?t.timeScale>0?a=n>=o.exitTime:t.timeScale<0&&(a=1-n>=o.exitTime):a=!0,a){t.clampWhenFinished=!0,DC&&console.log("transition to "+o.destinationState,o,n,o.exitTime,o.hasExitTime),this.transitionTo(o.destinationState,o.duration,o.offset);return}}else{this.transitionTo(o.destinationState,o.duration,o.offset);return}}}let g=!1;if(e.motion.isLooping&&t&&(t.time>=t.getClip().duration?(g=!0,t.reset(),t.time=0,t.play()):t.time<=0&&t.timeScale<0&&(g=!0,t.reset(),t.time=t.getClip().duration,t.play())),!g&&e&&!A&&t&&this.animator&&e.behaviours){const o=t==null?void 0:t.getClip().duration,C=t.time/o,s=new oD(this._activeState,C,o,this._speed);for(const n of e.behaviours)n.instance&&((I=n.instance.onStateUpdate)==null||I.call(n.instance,this.animator,s,0))}}getState(A,e){return typeof A=="number"&&(A==-1&&(A=this.model.layers[e].stateMachine.defaultState,A===void 0&&(DC&&console.warn("AnimatorController default state is undefined: ",this.model,"Layer: "+e),A=0)),A=this.model.layers[e].stateMachine.states[A]),A}transitionTo(A,e,t){var n,a,B,Q,E,c,h,l;if(!this.animator)return;const g=0;if(A=this.getState(A,g),!(A!=null&&A.motion)||!A.motion.clip)return;const I=this._activeState===A;if(I){const d=A.motion;!d.action_loopback&&d.clip&&(this._mixer.uncacheAction(d.clip,this.animator.gameObject),d.action_loopback=this.createAction(d.clip))}if((n=this._activeState)!=null&&n.behaviours&&this._activeState.motion.action){const d=(a=this._activeState)==null?void 0:a.motion.clip.duration,p=this._activeState.motion.action.time/d,u=new oD(this._activeState,p,d,this._speed);for(const D of this._activeState.behaviours)(Q=(B=D.instance)==null?void 0:B.onStateExit)==null||Q.call(D.instance,this.animator,u,g)}const o=(E=this._activeState)==null?void 0:E.motion.action;o&&o.fadeOut(e),I&&(A.motion.action=A.motion.action_loopback,A.motion.action_loopback=o);const C=this._activeState;this._activeState=A;const s=(c=A.motion)==null?void 0:c.action;if(s){t=Math.max(0,Math.min(1,t)),s.isRunning()&&s.stop(),s.reset(),s.timeScale=this._speed,A.speed!==void 0&&(s.timeScale*=A.speed),s.enabled=!0;const d=A.motion.clip.duration;if(s.time=t*d,s.timeScale<0&&(s.time=d-s.time),s.clampWhenFinished=!0,s.setLoop(Ph,0),e>0?s.fadeIn(e):s.setEffectiveWeight(1),s.play(),this.rootMotionHandler&&this.rootMotionHandler.onStart(s),this._activeStates.includes(A)||this._activeStates.push(A),this._activeState.behaviours){const p=new oD(A,t,d,this._speed);for(const u of this._activeState.behaviours)(l=(h=u.instance)==null?void 0:h.onStateEnter)==null||l.call(u.instance,this.animator,p,g)}}else DC&&(A.__warned_no_motion||(A.__warned_no_motion=!0,console.warn("No action",A.motion,this)));DC&&console.log("TRANSITION FROM "+(C==null?void 0:C.name)+" TO "+A.name,e,o,s,s==null?void 0:s.getEffectiveTimeScale(),s==null?void 0:s.getEffectiveWeight(),s==null?void 0:s.isRunning(),s==null?void 0:s.isScheduled(),s==null?void 0:s.paused)}createAction(A){var t,g;if(this._mixer.existingAction(A)&&this._mixer.uncacheAction(A,(t=this.animator)==null?void 0:t.gameObject),(g=this.animator)!=null&&g.applyRootMotion){this.rootMotionHandler||(this.rootMotionHandler=new w6(this));const I=this.animator.gameObject;return this.rootMotionHandler.createClip(this._mixer,I,A)}else return this._mixer.clipAction(A)}evaluateCondition(A){const e=this.model.parameters.find(t=>t.name===A.parameter);if(!e)return!1;switch(A.mode){case Xn.If:return e.value===!0;case Xn.IfNot:return e.value===!1;case Xn.Greater:return e.value>A.threshold;case Xn.Less:return e.value<A.threshold;case Xn.Equals:return e.value===A.threshold;case Xn.NotEqual:return e.value!==A.threshold}return!1}createActions(A){var e,t;for(const g of this.model.layers){const I=g.stateMachine;for(let o=0;o<I.states.length;o++){const C=I.states[o];C.transitions||(C.transitions=[]);for(const s of C.transitions)s.conditions||(s.conditions=[]);if(C.motion||(C.motion=YT(C.name)),this.animator&&C.motion.clips){const s=(e=C.motion.clips)==null?void 0:e.find(n=>{var a,B;return n.node.name===((B=(a=this.animator)==null?void 0:a.gameObject)==null?void 0:B.name)});C.motion.clip=s==null?void 0:s.clip}if(!C.motion.clip){const s=new Jo(void 0,void 0,[]);C.motion.clip=s}if((t=C.motion)!=null&&t.clip){const s=C.motion.clip,n=this.createAction(s);C.motion.action=n}if(C.behaviours&&Array.isArray(C.behaviours))for(const s of C.behaviours){if(!(s!=null&&s.typeName))continue;const n=T.get(s.typeName),a=new n;a.isStateMachineBehaviour&&(a._context=this.context??void 0,_r(a,s.properties),s.instance=a),DC&&console.log("Created animator controller behaviour",C.name,s.typeName,s.properties,a)}}}}*enumerateActions(){for(const A of this.model.layers){const e=A.stateMachine;for(let t=0;t<e.states.length;t++){const g=e.states[t];g!=null&&g.motion&&(g.motion.action&&(yield g.motion.action),g.motion.action_loopback&&(yield g.motion.action_loopback))}}}}class DJ{constructor(A,e){r(this,"track");r(this,"createdInterpolant");r(this,"originalEvaluate");r(this,"customEvaluate");this.track=A;const t=A,g=t.createInterpolant.bind(A);t.createInterpolant=()=>(t.createInterpolant=g,this.createdInterpolant=g(),this.originalEvaluate=this.createdInterpolant.evaluate.bind(this.createdInterpolant),this.customEvaluate=I=>{if(!this.originalEvaluate)return;const o=this.originalEvaluate(I);return e(I,o)},this.createdInterpolant.evaluate=this.customEvaluate,this.createdInterpolant)}evaluate(A){this.customEvaluate&&this.customEvaluate(A)}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 Si=class{constructor(A,e,t,g,I){r(this,"_action");r(this,"root");r(this,"clip");r(this,"positionWrapper",null);r(this,"rotationWrapper",null);r(this,"context");r(this,"positionChange",new S);r(this,"rotationChange",new kA);if(this.context=A,this.root=e,this.clip=t,Si.firstKeyframeRotation[t.uuid]||(Si.firstKeyframeRotation[t.uuid]=new kA),I){const o=I.values;Si.firstKeyframeRotation[t.uuid].set(o[0],o[1],o[2],o[3])}Si.spaceRotation[t.uuid]||(Si.spaceRotation[t.uuid]=new kA),Si.effectiveSpaceRotation[t.uuid]||(Si.effectiveSpaceRotation[t.uuid]=new kA),Si.clipOffsetRotation[t.uuid]=new kA,I&&Si.clipOffsetRotation[t.uuid].set(I.values[0],I.values[1],I.values[2],I.values[3]).invert(),this.handlePosition(t,g),this.handleRotation(t,I)}set action(A){this._action=A}get action(){return this._action}onStart(A){if(A.getClip()!==this.clip)return;const e=Si.lastObjRotation[this.root.uuid];if(Si.spaceRotation[this.clip.uuid].copy(e),Ip){const t=new Fi().setFromQuaternion(e);console.log("START",this.clip.name,ee.toDegrees(t.y))}}getClipRotationOffset(){return Si.clipOffsetRotation[this.clip.uuid]}handlePosition(A,e){if(e){const t=this.root;Ip&&t.add(new pE),Si.lastObjPosition[t.uuid]||(Si.lastObjPosition[t.uuid]=new S);const g=new S,I=new S;let o=0;this.positionWrapper=new DJ(e,(C,s)=>{const n=this.action.getEffectiveWeight();if(Ip&&t.position.length()>8&&t.position.set(0,t.position.y,0),C>o){g.set(s[0],s[1],s[2]),g.sub(I),g.multiplyScalar(n),g.applyQuaternion(this.getClipRotationOffset());const a=this.clip.uuid;g.applyQuaternion(Si.spaceRotation[a]),this.positionChange.copy(g)}return I.fromArray(s),o=C,s[0]=0,s[1]=0,s[2]=0,s})}}handleRotation(A,e){if(e){if(Ip){const C=e.values,s=new Fi().setFromQuaternion(new kA(C[0],C[1],C[2],C[3]));console.log(A.name,e.name,"FIRST ROTATION IN TRACK",ee.toDegrees(s.y));const n=e.values.length-4,a=new kA().set(C[n],C[n+1],C[n+2],C[n+3]),B=new Fi().setFromQuaternion(a);console.log(A.name,e.name,"LAST ROTATION IN TRACK",ee.toDegrees(B.y))}const t=this.root;Si.lastObjRotation[t.uuid]||(Si.lastObjRotation[t.uuid]=new kA);let g=0;const I=new kA,o=new kA;this.rotationWrapper=new DJ(e,(C,s)=>(C>g&&(o.set(s[0],s[1],s[2],s[3]),I.invert(),o.multiply(I),this.rotationChange.copy(o)),I.fromArray(s),g=C,s[0]=0,s[1]=0,s[2]=0,s[3]=1,s))}}onBeforeUpdate(){this.positionChange.set(0,0,0),this.rotationChange.set(0,0,0,1)}onAfterUpdate(){if(!this.action)return;const A=this.action.getEffectiveWeight();this.positionChange.multiplyScalar(A),this.rotationChange.slerp(Si.identityQuaternion,1-A)}};let Xo=Si;r(Xo,"lastObjPosition",{}),r(Xo,"lastObjRotation",{}),r(Xo,"firstKeyframeRotation",{}),r(Xo,"spaceRotation",{}),r(Xo,"effectiveSpaceRotation",{}),r(Xo,"clipOffsetRotation",{}),r(Xo,"identityQuaternion",new kA);class w6{constructor(A){r(this,"controller");r(this,"handler",[]);r(this,"root");r(this,"summedPosition",new S);r(this,"summedRotation",new kA);this.controller=A}createClip(A,e,t){this.root=e,e&&"name"in e&&e.name;const g=this.findRootTrack(t,".position"),I=this.findRootTrack(t,".quaternion"),o=new Xo(this.controller.context,e,t,g,I);this.handler.push(o);const C=A.clipAction(t);return o.action=C,C}onStart(A){for(const e of this.handler)e.onStart(A)}onBeforeUpdate(){for(const A of this.handler)A.onBeforeUpdate()}onAfterUpdate(){this.summedPosition.set(0,0,0),this.summedRotation.set(0,0,0,1);for(const A of this.handler)A.onAfterUpdate(),this.summedPosition.add(A.positionChange),this.summedRotation.multiply(A.rotationChange);this.root.position.add(this.summedPosition),this.root.quaternion.multiply(this.summedRotation),Xo.lastObjRotation[this.root.uuid].copy(this.root.quaternion)}findRootTrack(A,e){const t=A.tracks;if(!t)return null;for(const g of t)if(g.name.endsWith(e))return g;return null}}var y6=Object.defineProperty,S6=Object.getOwnPropertyDescriptor,vw=(i,A,e,t)=>{for(var g=t>1?void 0:t?S6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&y6(A,e,g),g};const l0=nA("debuganimator");class oI extends MA{constructor(){super(...arguments);r(this,"applyRootMotion",!1);r(this,"hasRootMotion",!1);r(this,"keepAnimatorControllerStateOnDisable",!1);r(this,"speed",1);r(this,"normalizedStartOffset",0);r(this,"_animatorController",null)}set runtimeAnimatorController(e){this._animatorController&&this._animatorController.model===e||(e?e instanceof Pr?this._animatorController=e:(l0&&console.log("Assign animator controller",e,this),this._animatorController=new Pr(e)):this._animatorController=null)}get runtimeAnimatorController(){return this._animatorController}Play(e,t=-1,g=Number.NEGATIVE_INFINITY,I=0){this.play(e,t,g,I)}play(e,t=-1,g=Number.NEGATIVE_INFINITY,I=0){var o;(o=this.runtimeAnimatorController)==null||o.play(e,t,g,I)}Reset(){this.reset()}reset(){var e;(e=this._animatorController)==null||e.reset()}SetBool(e,t){this.setBool(e,t)}setBool(e,t){var g;(g=this.runtimeAnimatorController)==null||g.setBool(e,t)}GetBool(e){return this.getBool(e)}getBool(e){var t;return((t=this.runtimeAnimatorController)==null?void 0:t.getBool(e))??!1}SetFloat(e,t){this.setFloat(e,t)}setFloat(e,t){var g;(g=this.runtimeAnimatorController)==null||g.setFloat(e,t)}GetFloat(e){return this.getFloat(e)}getFloat(e){var t;return((t=this.runtimeAnimatorController)==null?void 0:t.getFloat(e))??-1}SetInteger(e,t){this.setInteger(e,t)}setInteger(e,t){var g;(g=this.runtimeAnimatorController)==null||g.setInteger(e,t)}GetInteger(e){return this.getInteger(e)}getInteger(e){var t;return((t=this.runtimeAnimatorController)==null?void 0:t.getInteger(e))??-1}SetTrigger(e){this.setTrigger(e)}setTrigger(e){var t;l0&&console.log("SetTrigger",e),(t=this.runtimeAnimatorController)==null||t.setTrigger(e)}ResetTrigger(e){this.resetTrigger(e)}resetTrigger(e){var t;(t=this.runtimeAnimatorController)==null||t.resetTrigger(e)}IsInTransition(){return this.isInTransition()}isInTransition(){var e;return((e=this.runtimeAnimatorController)==null?void 0:e.isInTransition())??!1}SetSpeed(e){return this.setSpeed(e)}setSpeed(e){var t;e!==this.speed&&(this.speed=e,(t=this._animatorController)==null||t.setSpeed(e))}set minMaxSpeed(e){this.speed=ee.lerp(e.x,e.y,Math.random())}set minMaxOffsetNormalized(e){this.normalizedStartOffset=ee.lerp(e.x,e.y,Math.random()),this.runtimeAnimatorController&&(this.runtimeAnimatorController.normalizedStartOffset=this.normalizedStartOffset)}awake(){if(l0&&console.log("ANIMATOR",this.name,this),!!this.gameObject&&this.runtimeAnimatorController){const e=this.runtimeAnimatorController.clone();e?(console.assert(this.runtimeAnimatorController!==e),this.runtimeAnimatorController=e,console.assert(this.runtimeAnimatorController===e),this.runtimeAnimatorController.bind(this),this.runtimeAnimatorController.setSpeed(this.speed),this.runtimeAnimatorController.normalizedStartOffset=this.normalizedStartOffset):console.warn("Could not clone animator controller",this.runtimeAnimatorController)}}onDisable(){var e;this.keepAnimatorControllerStateOnDisable||(e=this._animatorController)==null||e.reset()}onBeforeRender(){this._animatorController&&this._animatorController.update()}}vw([w()],oI.prototype,"applyRootMotion",2);vw([w()],oI.prototype,"hasRootMotion",2);vw([w()],oI.prototype,"keepAnimatorControllerStateOnDisable",2);vw([w()],oI.prototype,"runtimeAnimatorController",1);class k6 extends ci{constructor(A,e=1,t=16,g=2){const I=new de,o=t+g*2,C=new Float32Array((o*3+3)*3);I.setAttribute("position",new Ce(C,3));const s=new pi({color:65280}),n=new pi({color:16776960});super(I,[n,s]),this.audio=A,this.range=e,this.divisionsInnerAngle=t,this.divisionsOuterAngle=g,this.type="PositionalAudioHelper",this.update()}update(){const A=this.audio,e=this.range,t=this.divisionsInnerAngle,g=this.divisionsOuterAngle,I=AI.degToRad(A.panner.coneInnerAngle),o=AI.degToRad(A.panner.coneOuterAngle),C=I/2,s=o/2;let n=0,a=0,B,Q;const E=this.geometry,c=E.attributes.position;E.clearGroups();function h(l,d,p,u){const D=(d-l)/p;for(c.setXYZ(n,0,0,0),a++,B=l;B<d;B+=D)Q=n+a,c.setXYZ(Q,Math.sin(B)*e,0,Math.cos(B)*e),c.setXYZ(Q+1,Math.sin(Math.min(B+D,d))*e,0,Math.cos(Math.min(B+D,d))*e),c.setXYZ(Q+2,0,0,0),a+=3;E.addGroup(n,a,u),n+=a,a=0}h(-s,-C,g,0),h(-C,C,t,1),h(C,s,g,0),c.needsUpdate=!0,I===o&&(this.material[0].visible=!1)}dispose(){this.geometry.dispose(),this.material[0].dispose(),this.material[1].dispose()}}var G6=Object.defineProperty,M6=Object.getOwnPropertyDescriptor,ba=(i,A,e,t)=>{for(var g=t>1?void 0:t?M6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&G6(A,e,g),g};const Mg=nA("debugaudio");var _c;const eg=(_c=class extends MA{constructor(){super(...arguments);r(this,"clip","");r(this,"playOnAwake",!1);r(this,"_spatialBlend",0);r(this,"_minDistance",1);r(this,"_maxDistance",100);r(this,"_volume",1);r(this,"rollOffMode",0);r(this,"playInBackground",!0);r(this,"_loop",!1);r(this,"sound",null);r(this,"helper",null);r(this,"wasPlaying",!1);r(this,"audioLoader",null);r(this,"shouldPlay",!1);r(this,"_lastClipStartedLoading",null);r(this,"onVisibilityChanged",()=>{switch(document.visibilityState){case"hidden":(this.playInBackground===!1||Xr())&&(this.wasPlaying=this.isPlaying,this.isPlaying&&this.pause());break;case"visible":Mg&&console.log("visible",this.enabled,this.playOnAwake,!this.isPlaying,eg._userInteractionRegistered,this.wasPlaying),this.enabled&&this.playOnAwake&&!this.isPlaying&&eg._userInteractionRegistered&&this.wasPlaying&&this.play();break}});r(this,"onApplicationMuteChanged",()=>{var A,e;this.context.application.muted?(A=this.sound)==null||A.setVolume(0):(e=this.sound)==null||e.setVolume(this.volume)});r(this,"lerp",(A,e,t)=>A*(1-t)+e*t);r(this,"_lastContextTime",0);r(this,"_hasEnded",!0);r(this,"_needUpdateSpatialDistanceSettings",!1)}static get userInteractionRegistered(){return eg._didCallBeginWaitForUserInteraction||(eg._didCallBeginWaitForUserInteraction=!0,eg._beginWaitForUserInteraction()),eg._userInteractionRegistered}static registerWaitForAllowAudio(A){if(A!==null){if(this._userInteractionRegistered){A();return}this.callbacks.indexOf(A)===-1&&this.callbacks.push(A),eg._didCallBeginWaitForUserInteraction||(eg._didCallBeginWaitForUserInteraction=!0,eg._beginWaitForUserInteraction())}}static _beginWaitForUserInteraction(A=null){if(this._userInteractionRegistered){A&&A();return}A!==null&&this.registerWaitForAllowAudio(A);const t=(()=>{if(t!=null&&!eg._userInteractionRegistered){eg._userInteractionRegistered=!0,Mg&&console.log("🔊 registered interaction, can play audio now"),document.removeEventListener("pointerdown",t),document.removeEventListener("click",t),document.removeEventListener("dragstart",t),document.removeEventListener("touchstart",t);for(const g of this.callbacks)g();this.callbacks.length=0}}).bind(this);document.addEventListener("pointerdown",t),document.addEventListener("click",t),document.addEventListener("dragstart",t),document.addEventListener("touchstart",t)}get loop(){return this.sound&&(this._loop=this.sound.getLoop()),this._loop}set loop(A){this._loop=A,this.sound&&this.sound.setLoop(A)}get spatialBlend(){return this._spatialBlend}set spatialBlend(A){A!==this._spatialBlend&&(this._spatialBlend=A,this._needUpdateSpatialDistanceSettings=!0)}get minDistance(){return this._minDistance}set minDistance(A){this._minDistance!==A&&(this._minDistance=A,this._needUpdateSpatialDistanceSettings=!0)}get maxDistance(){return this._maxDistance}set maxDistance(A){this._maxDistance!==A&&(this._maxDistance=A,this._needUpdateSpatialDistanceSettings=!0)}get volume(){return this._volume}set volume(A){this._volume=A,this.sound&&!this.context.application.muted&&(Mg&&console.log(this.name,"audio set volume",A),this.sound.setVolume(A))}get Sound(){if(!this.sound&&eg._userInteractionRegistered){const A=AA.getComponent(this.context.mainCamera,IE)??AA.findObjectOfType(IE,this.context);A!=null&&A.listener&&(this.sound=new HL(A.listener),this.gameObject.add(this.sound))}return this.sound}get ShouldPlay(){return this.shouldPlay}awake(){this.audioLoader=new qD,this.playOnAwake&&(this.shouldPlay=!0)}onEnable(){eg._userInteractionRegistered?this.playOnAwake&&this.context.application.isVisible&&this.play():eg._beginWaitForUserInteraction(()=>{this.enabled&&!this.destroyed&&this.shouldPlay&&this.loadAndPlay(this.clip)}),globalThis.addEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.addEventListener(jD.MuteChanged,this.onApplicationMuteChanged)}onDisable(){globalThis.removeEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.removeEventListener(jD.MuteChanged,this.onApplicationMuteChanged),this.stop()}onLoaded(A){Mg&&console.log("audio buffer loaded"),eg.registerWaitForAllowAudio(()=>{Mg&&console.log("finished loading",A);const e=this.Sound;if(!e){console.warn("Failed getting sound",this.name);return}e.isPlaying&&e.stop(),e.setBuffer(A),e.loop=this._loop,this.context.application.muted?e.setVolume(0):e.setVolume(this.volume),e.autoplay=this.shouldPlay,this.applySpatialDistanceSettings(),e.isPlaying&&e.stop(),Mg&&console.log(this.name,this.shouldPlay,eg.userInteractionRegistered,this),this.shouldPlay&&eg._userInteractionRegistered&&this.play()})}applySpatialDistanceSettings(){const A=this.sound;if(!A)return;this._needUpdateSpatialDistanceSettings=!1;const e=this.lerp(10*this._maxDistance/Math.max(1e-4,this.spatialBlend),this._minDistance,this.spatialBlend);switch(Mg&&console.log(this.name,this._minDistance,this._maxDistance,this.spatialBlend,"Ref distance="+e),A.setRefDistance(e),A.setMaxDistance(Math.max(.01,this._maxDistance)),this.rollOffMode){case 0:A.setDistanceModel("exponential");break;case 1:A.setDistanceModel("linear");break}this.spatialBlend>0?Mg&&!this.helper&&(this.helper=new k6(A,A.getRefDistance()),A.add(this.helper)):this.helper&&this.helper.parent&&this.helper.removeFromParent()}loadAndPlay(A){if(A&&(this.clip=A),this.clip&&(Mg&&console.log(this.clip),this.clip.endsWith(".mp3")||this.clip.endsWith(".wav"))){if(this.audioLoader||(this.audioLoader=new qD),this.shouldPlay=!0,this._lastClipStartedLoading===this.clip){Mg&&console.log("Is currently loading:",this._lastClipStartedLoading,this);return}this._lastClipStartedLoading=this.clip,Mg&&console.log("load audio",this.clip),this.audioLoader.load(this.clip,this.onLoaded.bind(this),()=>{},console.error)}}play(A=void 0){var e;if(!this.audioLoader||!this.sound||A&&A!==this.clip){this.loadAndPlay(A);return}if(this.shouldPlay=!0,this._hasEnded=!1,Mg&&console.log("play",(e=this.sound)==null?void 0:e.getVolume(),this.sound),this.sound&&!this.sound.isPlaying){const t=this.context.application.muted;t&&this.sound.setVolume(0),this.sound.play(t?.1:0)}}pause(){var A;Mg&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.isPlaying&&this.sound.source&&(this._lastContextTime=(A=this.sound)==null?void 0:A.context.currentTime,this.sound.pause())}stop(){var A;Mg&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.source&&(this._lastContextTime=(A=this.sound)==null?void 0:A.context.currentTime,Mg&&console.log(this._lastContextTime),this.sound.stop())}get isPlaying(){var A;return((A=this.sound)==null?void 0:A.isPlaying)??!1}set isPlaying(A){}get time(){var A,e;return(A=this.sound)!=null&&A.source?((e=this.sound.source)==null?void 0:e.context.currentTime)-this._lastContextTime+this.sound.offset:0}set time(A){if(this.sound){if(A===this.sound.offset)return;const e=this.isPlaying;this.stop(),this.sound.offset=A,e&&this.play()}}update(){this.helper&&(this.isPlaying&&this.helper.update(),this.helper.visible=this.isPlaying),this._needUpdateSpatialDistanceSettings&&this.applySpatialDistanceSettings(),this.sound&&!this.sound.isPlaying&&this.shouldPlay&&!this._hasEnded&&(this._hasEnded=!0,Mg&&console.log("Audio clip ended",this.clip),this.sound.dispatchEvent({type:"ended",target:this}))}},r(_c,"_didCallBeginWaitForUserInteraction",!1),r(_c,"callbacks",[]),r(_c,"_userInteractionRegistered",!1),_c);let Ni=eg;ba([w(URL)],Ni.prototype,"clip",2);ba([w()],Ni.prototype,"playOnAwake",2);ba([w()],Ni.prototype,"loop",1);ba([w()],Ni.prototype,"spatialBlend",1);ba([w()],Ni.prototype,"minDistance",1);ba([w()],Ni.prototype,"maxDistance",1);ba([w()],Ni.prototype,"volume",1);ba([w()],Ni.prototype,"rollOffMode",2);var m6=Object.defineProperty,R6=Object.getOwnPropertyDescriptor,U6=(i,A,e,t)=>{for(var g=t>1?void 0:t?R6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&m6(A,e,g),g};class pd extends MA{constructor(){super(...arguments);r(this,"constraintActive",!0);r(this,"locked",!1);r(this,"sources",[])}}U6([w(UA)],pd.prototype,"sources",2);const fJ={type:"change"},d0={type:"start"},wJ={type:"end"};let F6=class extends ji{constructor(A,e){super(),this.object=A,this.domElement=e,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new S,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:ar.ROTATE,MIDDLE:ar.DOLLY,RIGHT:ar.PAN},this.touches={ONE:rr.ROTATE,TWO:rr.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 C.phi},this.getAzimuthalAngle=function(){return C.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(q){q.addEventListener("keydown",v),this._domElementKeyEvents=q},this.saveState=function(){t.target0.copy(t.target),t.position0.copy(t.object.position),t.zoom0=t.object.zoom},this.reset=function(){t.target.copy(t.target0),t.object.position.copy(t.position0),t.object.zoom=t.zoom0,t.object.updateProjectionMatrix(),t.dispatchEvent(fJ),t.update(),I=g.NONE},this.update=function(){const q=new S,fA=new kA().setFromUnitVectors(A.up,new S(0,1,0)),XA=fA.clone().invert(),HA=new S,WA=new kA,YA=2*Math.PI;return function(){const xe=t.object.getWorldPosition(A.position);q.copy(xe).sub(t.target),q.applyQuaternion(fA),C.setFromVector3(q),t.autoRotate&&I===g.NONE&&U(f()),t.enableDamping?(C.theta+=s.theta*t.dampingFactor,C.phi+=s.phi*t.dampingFactor):(C.theta+=s.theta,C.phi+=s.phi);let Ue=t.minAzimuthAngle,V=t.maxAzimuthAngle;return isFinite(Ue)&&isFinite(V)&&(Ue<-Math.PI?Ue+=YA:Ue>Math.PI&&(Ue-=YA),V<-Math.PI?V+=YA:V>Math.PI&&(V-=YA),Ue<=V?C.theta=Math.max(Ue,Math.min(V,C.theta)):C.theta=C.theta>(Ue+V)/2?Math.max(Ue,C.theta):Math.min(V,C.theta)),C.phi=Math.max(t.minPolarAngle,Math.min(t.maxPolarAngle,C.phi)),C.makeSafe(),a=AI.lerp(a,n,t.enableDamping?t.dampingFactor:1),C.radius*=a,C.radius=Math.max(t.minDistance,Math.min(t.maxDistance,C.radius)),t.enableDamping===!0?t.target.addScaledVector(B,t.dampingFactor):t.target.add(B),q.setFromSpherical(C),q.applyQuaternion(XA),xe.copy(t.target).add(q),t.object.parent?t.object.parent.worldToLocal(xe):t.object.position.copy(xe),t.object.lookAt(t.target),t.enableDamping===!0?(s.theta*=1-t.dampingFactor,s.phi*=1-t.dampingFactor,B.multiplyScalar(1-t.dampingFactor)):(s.set(0,0,0),B.set(0,0,0)),n=1,Q||HA.distanceToSquared(t.object.position)>o||8*(1-WA.dot(t.object.quaternion))>o?(t.dispatchEvent(fJ),HA.copy(t.object.position),WA.copy(t.object.quaternion),Q=!1,!0):!1}}(),this.dispose=function(){t.domElement.removeEventListener("contextmenu",RA),t.domElement.removeEventListener("pointerdown",Ae),t.domElement.removeEventListener("pointercancel",Be),t.domElement.removeEventListener("wheel",ve),t.domElement.removeEventListener("pointermove",VA),t.domElement.removeEventListener("pointerup",Ee),t._domElementKeyEvents!==null&&t._domElementKeyEvents.removeEventListener("keydown",v)};const t=this,g={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let I=g.NONE;const o=1e-6,C=new Hk,s=new Hk;let n=1,a=1;const B=new S;let Q=!1;const E=new P,c=new P,h=new P,l=new P,d=new P,p=new P,u=new P,D=new P,y=new P,k=[],R={};function f(){return 2*Math.PI/60/60*t.autoRotateSpeed}function M(){return Math.pow(.95,t.zoomSpeed)}function U(q){s.theta-=q}function J(q){s.phi-=q}const H=function(){const q=new S;return function(XA,HA){q.setFromMatrixColumn(HA,0),q.multiplyScalar(-XA),B.add(q)}}(),Y=function(){const q=new S;return function(XA,HA){t.screenSpacePanning===!0?q.setFromMatrixColumn(HA,1):(q.setFromMatrixColumn(HA,0),q.crossVectors(t.object.up,q)),q.multiplyScalar(XA),B.add(q)}}(),b=function(){const q=new S,fA=new S;return function(HA,WA){const YA=t.domElement;if(t.object.isPerspectiveCamera){t.object.getWorldPosition(fA),q.copy(fA).sub(t.target);let Ne=q.length();Ne*=Math.tan(t.object.fov/2*Math.PI/180),H(2*HA*Ne/YA.clientHeight,t.object.matrixWorld),Y(2*WA*Ne/YA.clientHeight,t.object.matrixWorld)}else t.object.isOrthographicCamera?(H(HA*(t.object.right-t.object.left)/t.object.zoom/YA.clientWidth,t.object.matrixWorld),Y(WA*(t.object.top-t.object.bottom)/t.object.zoom/YA.clientHeight,t.object.matrixWorld)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),t.enablePan=!1)}}();function _(q){t.object.isPerspectiveCamera?n/=q:t.object.isOrthographicCamera?(t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom*q)),t.object.updateProjectionMatrix(),Q=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function eA(q){t.object.isPerspectiveCamera?n*=q:t.object.isOrthographicCamera?(t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom/q)),t.object.updateProjectionMatrix(),Q=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function $(q){E.set(q.clientX,q.clientY)}function X(q){u.set(q.clientX,q.clientY)}function cA(q){l.set(q.clientX,q.clientY)}function EA(q){c.set(q.clientX,q.clientY),h.subVectors(c,E).multiplyScalar(t.rotateSpeed);const fA=t.domElement;U(2*Math.PI*h.x/fA.clientHeight),J(2*Math.PI*h.y/fA.clientHeight),E.copy(c),t.update()}function KA(q){D.set(q.clientX,q.clientY),y.subVectors(D,u),y.y>0?_(M()):y.y<0&&eA(M()),u.copy(D),t.update()}function uA(q){d.set(q.clientX,q.clientY),p.subVectors(d,l).multiplyScalar(t.panSpeed),b(p.x,p.y),l.copy(d),t.update()}function gA(q){q.deltaY<0?eA(M()):q.deltaY>0&&_(M()),t.update()}function rA(q){let fA=!1;switch(q.code){case t.keys.UP:q.ctrlKey||q.metaKey||q.shiftKey?J(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):b(0,t.keyPanSpeed),fA=!0;break;case t.keys.BOTTOM:q.ctrlKey||q.metaKey||q.shiftKey?J(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):b(0,-t.keyPanSpeed),fA=!0;break;case t.keys.LEFT:q.ctrlKey||q.metaKey||q.shiftKey?U(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):b(t.keyPanSpeed,0),fA=!0;break;case t.keys.RIGHT:q.ctrlKey||q.metaKey||q.shiftKey?U(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):b(-t.keyPanSpeed,0),fA=!0;break}fA&&(q.preventDefault(),t.update())}function GA(){if(k.length===1)E.set(k[0].pageX,k[0].pageY);else{const q=.5*(k[0].pageX+k[1].pageX),fA=.5*(k[0].pageY+k[1].pageY);E.set(q,fA)}}function W(){if(k.length===1)l.set(k[0].pageX,k[0].pageY);else{const q=.5*(k[0].pageX+k[1].pageX),fA=.5*(k[0].pageY+k[1].pageY);l.set(q,fA)}}function xA(){const q=k[0].pageX-k[1].pageX,fA=k[0].pageY-k[1].pageY,XA=Math.sqrt(q*q+fA*fA);u.set(0,XA)}function JA(){t.enableZoom&&xA(),t.enablePan&&W()}function jA(){t.enableZoom&&xA(),t.enableRotate&&GA()}function yA(q){if(k.length==1)c.set(q.pageX,q.pageY);else{const XA=OA(q),HA=.5*(q.pageX+XA.x),WA=.5*(q.pageY+XA.y);c.set(HA,WA)}h.subVectors(c,E).multiplyScalar(t.rotateSpeed);const fA=t.domElement;U(2*Math.PI*h.x/fA.clientHeight),J(2*Math.PI*h.y/fA.clientHeight),E.copy(c)}function ae(q){if(k.length===1)d.set(q.pageX,q.pageY);else{const fA=OA(q),XA=.5*(q.pageX+fA.x),HA=.5*(q.pageY+fA.y);d.set(XA,HA)}p.subVectors(d,l).multiplyScalar(t.panSpeed),b(p.x,p.y),l.copy(d)}function dA(q){const fA=OA(q),XA=q.pageX-fA.x,HA=q.pageY-fA.y,WA=Math.sqrt(XA*XA+HA*HA);D.set(0,WA),y.set(0,Math.pow(D.y/u.y,t.zoomSpeed)),_(y.y),u.copy(D)}function lA(q){t.enableZoom&&dA(q),t.enablePan&&ae(q)}function bA(q){t.enableZoom&&dA(q),t.enableRotate&&yA(q)}function Ae(q){t.enabled!==!1&&(k.length===0&&(t.domElement.addEventListener("pointermove",VA),t.domElement.addEventListener("pointerup",Ee)),qA(q),q.pointerType==="touch"?K(q):oe(q))}function VA(q){t.enabled!==!1&&(q.pointerType==="touch"?BA(q):We(q))}function Ee(q){PA(q),k.length===0&&(t.domElement.removeEventListener("pointermove",VA),t.domElement.removeEventListener("pointerup",Ee)),t.dispatchEvent(wJ),I=g.NONE}function Be(q){PA(q)}function oe(q){let fA;switch(q.button){case 0:fA=t.mouseButtons.LEFT;break;case 1:fA=t.mouseButtons.MIDDLE;break;case 2:fA=t.mouseButtons.RIGHT;break;default:fA=-1}switch(fA){case ar.DOLLY:if(t.enableZoom===!1)return;X(q),I=g.DOLLY;break;case ar.ROTATE:if(q.ctrlKey||q.metaKey||q.shiftKey){if(t.enablePan===!1)return;cA(q),I=g.PAN}else{if(t.enableRotate===!1)return;$(q),I=g.ROTATE}break;case ar.PAN:if(q.ctrlKey||q.metaKey||q.shiftKey){if(t.enableRotate===!1)return;$(q),I=g.ROTATE}else{if(t.enablePan===!1)return;cA(q),I=g.PAN}break;default:I=g.NONE}I!==g.NONE&&t.dispatchEvent(d0)}function We(q){switch(I){case g.ROTATE:if(t.enableRotate===!1)return;EA(q);break;case g.DOLLY:if(t.enableZoom===!1)return;KA(q);break;case g.PAN:if(t.enablePan===!1)return;uA(q);break}}function ve(q){t.enabled===!1||t.enableZoom===!1||I!==g.NONE||(q.preventDefault(),t.dispatchEvent(d0),gA(q),t.dispatchEvent(wJ))}function v(q){t.enabled===!1||t.enablePan===!1||rA(q)}function K(q){switch(re(q),k.length){case 1:switch(t.touches.ONE){case rr.ROTATE:if(t.enableRotate===!1)return;GA(),I=g.TOUCH_ROTATE;break;case rr.PAN:if(t.enablePan===!1)return;W(),I=g.TOUCH_PAN;break;default:I=g.NONE}break;case 2:switch(t.touches.TWO){case rr.DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;JA(),I=g.TOUCH_DOLLY_PAN;break;case rr.DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;jA(),I=g.TOUCH_DOLLY_ROTATE;break;default:I=g.NONE}break;default:I=g.NONE}I!==g.NONE&&t.dispatchEvent(d0)}function BA(q){switch(re(q),I){case g.TOUCH_ROTATE:if(t.enableRotate===!1)return;yA(q),t.update();break;case g.TOUCH_PAN:if(t.enablePan===!1)return;ae(q),t.update();break;case g.TOUCH_DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;lA(q),t.update();break;case g.TOUCH_DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;bA(q),t.update();break;default:I=g.NONE}}function RA(q){t.enabled!==!1&&q.preventDefault()}function qA(q){k.push(q)}function PA(q){delete R[q.pointerId];for(let fA=0;fA<k.length;fA++)if(k[fA].pointerId==q.pointerId){k.splice(fA,1);return}}function re(q){let fA=R[q.pointerId];fA===void 0&&(fA=new P,R[q.pointerId]=fA),fA.set(q.pageX,q.pageY)}function OA(q){const fA=q.pointerId===k[0].pointerId?k[1]:k[0];return R[fA.pointerId]}t.domElement.addEventListener("contextmenu",RA),t.domElement.addEventListener("pointerdown",Ae),t.domElement.addEventListener("pointercancel",Be),t.domElement.addEventListener("wheel",ve,{passive:!1}),this.update()}};class N6{static createButton(A,e={},t){const g=document.createElement("button");let I=!1;function o(){if(e.optionalFeatures=e.optionalFeatures||[],e.domOverlay===void 0){var a=document.createElement("div");a.style.display="none",document.body.appendChild(a);var B=document.createElementNS("http://www.w3.org/2000/svg","svg");B.setAttribute("width",38),B.setAttribute("height",38),B.style.position="absolute",B.style.right="20px",B.style.top="20px",B.addEventListener("click",function(){E.end()}),a.appendChild(B);var Q=document.createElementNS("http://www.w3.org/2000/svg","path");Q.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),Q.setAttribute("stroke","#fff"),Q.setAttribute("stroke-width",2),B.appendChild(Q),e.optionalFeatures.push("dom-overlay"),e.domOverlay={root:a},I=!0}let E=null,c=null;async function h(d){var D;const p=/WebXRViewer\//i.test(navigator.userAgent),u=e.domOverlay.root;p&&((D=e.domOverlay)!=null&&D.root?(c=u.parentNode,c&&(console.log("Reparent DOM Overlay to body",u,u.style.display),u.style.display="",u.style.visibility="",document.body.appendChild(u))):console.warn("WebXRViewer: No DOM Overlay found")),d.addEventListener("end",l),await A.xr.setSession(d),g.textContent="STOP AR",I&&(e.domOverlay.root.style.display=""),E=d}function l(){E.removeEventListener("end",l),g.textContent="START AR";const d=e.domOverlay.root;c&&c.appendChild(d),I&&(d.style.display="none"),E=null}g.style.display="",g.style.cursor="pointer",g.style.left="calc(50% - 50px)",g.style.width="100px",g.textContent="START AR",g.onmouseenter=function(){g.style.opacity="1.0"},g.onmouseleave=function(){g.style.opacity="0.5"},g.onclick=function(){E===null?(t==null||t.call(this,e),navigator.xr.requestSession("immersive-ar",e).then(h)):E.end()}}function C(){g.disabled=!0,g.style.display="",g.style.cursor="auto",g.style.left="calc(50% - 75px)",g.style.width="150px",g.onmouseenter=null,g.onmouseleave=null,g.onclick=null}function s(){C(),g.textContent="AR NOT SUPPORTED"}function n(a){a.style.position="absolute",a.style.bottom="20px",a.style.padding="12px 6px",a.style.border="1px solid #fff",a.style.borderRadius="4px",a.style.background="rgba(0,0,0,0.1)",a.style.color="#fff",a.style.font="normal 13px sans-serif",a.style.textAlign="center",a.style.opacity="0.5",a.style.outline="none",a.style.zIndex="999"}if("xr"in navigator)return g.id="ARButton",g.style.display="none",n(g),navigator.xr.isSessionSupported("immersive-ar").then(function(a){a?o():s()}).catch(s),g;{const a=document.createElement("a");return window.isSecureContext===!1?(a.href=document.location.href.replace(/^http:/,"https:"),a.innerHTML="WEBXR NEEDS HTTPS"):(a.href="https://immersiveweb.dev/",a.innerHTML="WEBXR NOT AVAILABLE"),a.style.left="calc(50% - 90px)",a.style.width="180px",a.style.textDecoration="none",n(a),a}}}const Nf=class{static createButton(A,e){const t=document.createElement("button");function g(){let s=null;async function n(B){B.addEventListener("end",a),await A.xr.setSession(B),t.textContent="EXIT VR",s=B}function a(){s.removeEventListener("end",a),t.textContent="ENTER VR",s=null}t.style.display="",t.style.cursor="pointer",t.style.left="calc(50% - 50px)",t.style.width="100px",t.textContent="ENTER VR",t.onmouseenter=function(){t.style.opacity="1.0"},t.onmouseleave=function(){t.style.opacity="0.5"},t.onclick=function(){if(s===null){const B={optionalFeatures:e.optionalFeatures};navigator.xr.requestSession("immersive-vr",B).then(n)}else s.end()}}function I(){t.disabled=!0,t.style.display="",t.style.cursor="auto",t.style.left="calc(50% - 75px)",t.style.width="150px",t.onmouseenter=null,t.onmouseleave=null,t.onclick=null}function o(){I(),t.textContent="VR NOT SUPPORTED"}function C(s){s.style.position="absolute",s.style.bottom="20px",s.style.padding="12px 6px",s.style.border="1px solid #fff",s.style.borderRadius="4px",s.style.background="rgba(0,0,0,0.1)",s.style.color="#fff",s.style.font="normal 13px sans-serif",s.style.textAlign="center",s.style.opacity="0.5",s.style.outline="none",s.style.zIndex="999"}if("xr"in navigator)return t.id="VRButton",t.style.display="none",C(t),navigator.xr.isSessionSupported("immersive-vr").then(function(s){s?g():o(),Nf.xrSessionIsGranted&&(console.log("XR session is granted - will enter immersive web now"),t.click())}),t;{const s=document.createElement("a");return window.isSecureContext===!1?(s.href=document.location.href.replace(/^http:/,"https:"),s.innerHTML="WEBXR NEEDS HTTPS"):(s.href="https://immersiveweb.dev/",s.innerHTML="WEBXR NOT AVAILABLE"),s.style.left="calc(50% - 90px)",s.style.width="180px",s.style.textDecoration="none",C(s),s}}static registerSessionGrantedListener(){if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent))return;navigator.xr.addEventListener("sessiongranted",()=>{Nf.xrSessionIsGranted=!0})}}};let kh=Nf;r(kh,"xrSessionIsGranted",!1);kh.registerSessionGrantedListener();const If="noVoip",uI=nA("debugvoip"),K6=nA("voip");class J6{constructor(A){r(this,"id");this.id=A}}class q6{constructor(A,e,t,g){r(this,"peer");r(this,"voip");r(this,"userId");r(this,"peerId");r(this,"call",null);r(this,"callErrorListener",null);r(this,"stream",null);this.voip=A,this.peer=e,this.userId=t,this.peerId=g}close(){var A;uI&&console.log("close voip call"),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.open&&this.call.close(),(A=this.stream)==null||A.getTracks().forEach(function(e){e.stop()})}updateMute(A){var t;if(!this.stream)return;const e=(t=this.stream)==null?void 0:t.getAudioTracks();for(const g of e)g.enabled=!A}async startVoipCall(){if(!await hn.HasMicrophonePermissions()){console.warn("no permission to use microphone, can not start call");return}uI&&console.log("start voip call"),this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),this.updateMute(this.voip.muteOutput),uI&&console.log(this.stream),this.call=this.peer.call(this.peerId,this.stream,{metadata:{userId:this.userId}}),this.call.on("error",e=>{console.error(e)}),this.call.on("stream",e=>{uI&&console.log("received stream from remote again",e)}),this.peer.on("close",this.onCallClose.bind(this)),this.callErrorListener=e=>{var t;e.message.includes(this.peerId)?(console.log("Could not connect to "+this.peerId),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.close(),(t=this.stream)==null||t.getTracks().forEach(function(g){g.stop()}),this.stream=null):console.error(e)},this.peer.on("error",this.callErrorListener)}onCallClose(A){uI&&console.log("call closed",A)}}class b6{constructor(A,e,t){r(this,"voip");r(this,"call");r(this,"audio",null);r(this,"stream",null);r(this,"obj");r(this,"analyzer",null);r(this,"waitingForStart",!1);r(this,"closed",!1);r(this,"audioElement",null);this.voip=A,this.obj=e,this.call=t}get currentStream(){return this.stream}get currentAudio(){return this.audio}get currentAnalyzer(){return this.analyzer}openAudioStream(A){const e=A.getAudioTracks();for(const t of e)if(t.kind==="audio"&&t.readyState==="live"){this.open(t);return}console.warn("failed finding valid audio stream to begin call")}open(A){console.assert(A.kind==="audio","invalid track kind, expected audio but received "+A.kind),!this.waitingForStart&&(this.waitingForStart=!0,Ni.userInteractionRegistered||uI&&console.log("Incoming call, waiting for user interaction before opening audio"),Ni.registerWaitForAllowAudio(async()=>{if(this.call.open&&!this.closed){uI&&console.log("Setup audio and begin listening"),this.stream=new MediaStream([A]);const e=new WM;this.audio=new sw(e),this.audio.setVolume(this.voip.muteInput?0:1),this.audio.setMediaStreamSource(this.stream);const t=document.createElement("audio");this.audioElement=t,t.style.display="none",document.body.appendChild(t),t.srcObject=this.stream,t.sinkId!==void 0&&navigator.mediaDevices.enumerateDevices().then(g=>{if(t){console.log(g);for(const I of g)if(I.label==="Speakerphone"){t.sinkId=I.deviceId;break}}}),uI&&console.log("call is setup, you should hear something now"),this.analyzer=new _L(this.audio,32)}}))}close(){var A,e,t;this.closed=!0,(A=this.call)!=null&&A.open&&this.call.close(),(e=this.audio)==null||e.disconnect(),(t=this.stream)==null||t.getTracks().forEach(g=>{g.stop()}),this.stream=null,this.audioElement&&this.audioElement.remove()}}class hn extends MA{constructor(){super(...arguments);r(this,"requireParam",!1);r(this,"peer",null);r(this,"model",null);r(this,"connections",{});r(this,"currentIncomingCalls",{});r(this,"_inputMuted",!1);r(this,"_outputMuted",!1)}set muteInput(e){var g;if(e===this._inputMuted||(this._inputMuted=e,!this.currentIncomingCalls))return;const t=this._inputMuted?0:1;for(const I in this.currentIncomingCalls){const o=this.currentIncomingCalls[I];(g=o==null?void 0:o.currentAudio)==null||g.setVolume(t)}}get muteInput(){return this._inputMuted}set muteOutput(e){if(e!==this._outputMuted&&(this._outputMuted=e,!!this.connections))for(const t in this.connections){const g=this.connections[t];g==null||g.updateMute(e)}}get muteOutput(){return this._outputMuted}getFrequency(e){if(e===null){for(const g in this.currentIncomingCalls){const I=this.currentIncomingCalls[g];if(I&&I.currentAnalyzer)return I.currentAnalyzer.getAverageFrequency()}return null}const t=this.currentIncomingCalls[e];return t&&t.currentAnalyzer?t.currentAnalyzer.getAverageFrequency():null}awake(){if(nA(If)){console.log("VOIP is disabled by url parameter: "+If);return}if(this.requireParam&&!K6){console.debug("VOIP must be enabled explicitly by url parameter");return}if(Hh()&&ms()){console.log("VOIP is currently not supported on Safari iOS");return}this.peer=new _D,navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,this.context.connection.beginListen(oi.JoinedRoom,e=>{navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}),this.context.connection.beginListen("peer-update-id",e=>{if(e.id!==this.context.connection.connectionId){const t=this.connections[e.id];if(t&&t.close(),this.peer&&this.context.connection.connectionId){const g=new q6(this,this.peer,this.context.connection.connectionId,e.peerId);this.connections[e.id]=g,g.startVoipCall()}}}),this.context.connection.beginListen(oi.UserLeftRoom,e=>{const{userId:t}=e,g=this.connections[t];this.connections[t]=null,g&&g.close();const I=this.currentIncomingCalls[t];uI&&console.log("UserLeftRoom",e,t,I),I&&(I.close(),this.currentIncomingCalls[t]=null)}),this.peer.on("open",this.onOpenPeerConnection.bind(this))}onEnable(){}onDisable(){console.log("TODO: close all");for(const e in this.currentIncomingCalls)try{const t=this.currentIncomingCalls[e];t==null||t.close();const g=this.connections[e];g==null||g.close()}catch(t){console.error(t)}}async onOpenPeerConnection(e){uI&&console.log("Peer connection established and received id"),this.model=new J6(e),this.context.connection.send("peer-update-id",this.model,dI.OnRoomJoin),this.peer&&(this.peer.on("call",this.onReceiveCall.bind(this)),this.peer.on("connection",function(t){uI&&console.log("CONNECTION",t),t.on("data",function(g){uI&&console.log("Received",g)})}))}async onReceiveCall(e){const{metadata:t}=e;console.assert(t.userId);const{userId:g}=t,I=this.currentIncomingCalls[g];if(I&&I.close(),uI&&console.log("received call"),await hn.HasMicrophonePermissions()){const o=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1});e.answer(o)}else e.answer(null);this.currentIncomingCalls[g]=new b6(this,this.gameObject,e),e.on("stream",o=>{var C;uI&&console.log("receive caller stream, will setup audio now"),(C=this.currentIncomingCalls[g])==null||C.openAudioStream(o)}),e.on("error",console.error)}static async HasMicrophonePermissions(){return(await navigator.permissions.query({name:"microphone"})).state!=="denied"}}var L6=Object.defineProperty,v6=Object.getOwnPropertyDescriptor,TT=(i,A,e,t)=>{for(var g=t>1?void 0:t?v6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&L6(A,e,g),g};class La extends MA{constructor(){super(...arguments);r(this,"webAR",null);r(this,"invertForward",!1);r(this,"_initalMatrix",new NA);r(this,"_selectStartFn",this.onSelectStart.bind(this));r(this,"_selectEndFn",this.onSelectEnd.bind(this));r(this,"_arScale",5);r(this,"_rig",null);r(this,"_startPose",null);r(this,"_placementPose",null);r(this,"_isTouching",!1);r(this,"_rigStartPose",null);r(this,"_gotFirstHitTestResult",!1)}get rig(){var e;return(e=this.webAR)==null?void 0:e.webxr.Rig}get arScale(){return this._arScale}set arScale(e){e!==this._arScale&&(this._arScale=e,this.setScale(e))}start(){const e=AA.findObjectOfType(Se);e&&(e.Rig.updateMatrix(),this._initalMatrix.copy(e.Rig.matrix))}onBegin(e){var t;this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose=this.gameObject.matrix.clone(),this._rigStartPose=(t=this.rig)==null?void 0:t.matrix.clone(),this._gotFirstHitTestResult=!1,e.addEventListener("selectstart",this._selectStartFn),e.addEventListener("selectend",this._selectEndFn),this.gameObject.visible=!1,this.rig&&(this.rig.matrixAutoUpdate=!0,this._initalMatrix.decompose(this.rig.position,this.rig.quaternion,this.rig.scale)),this.dispatchEvent(new CustomEvent("onBeginSession"))}onUpdate(e,t,g){if(g&&!this._placementPose&&(this._gotFirstHitTestResult||(this._gotFirstHitTestResult=!0,this.dispatchEvent(new CustomEvent("canPlaceSession",{detail:{pose:g}}))),this._isTouching)){const I=new NA().fromArray(g.transform.matrix).invert();return this.dispatchEvent(new CustomEvent("placedSession",{detail:{pose:g,poseMatrix:I}})),this.webAR&&this.webAR.setReticleActive(!1),this.placeAt(e,I),!0}return!1}placeAt(e,t){this._placementPose||(this._placementPose=new NA),this._placementPose.copy(t);const g=this.gameObject.matrixWorld.clone().invert();if(this._placementPose.premultiply(g),e){if(this.invertForward){const I=new NA().makeRotationY(Math.PI);this._placementPose.premultiply(I)}this._rig=e,this.setScale(this.arScale)}else this._rig=null;this.gameObject.visible=!0}onEnd(e,t){this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose&&this.gameObject.matrix.copy(this._startPose),e&&(e.matrixAutoUpdate=!0,this._rigStartPose&&this._rigStartPose.decompose(e.position,e.quaternion,e.scale)),fI.markDirty(this.gameObject,!0),setTimeout(()=>{this.gameObject.matrixAutoUpdate=!0,this.gameObject.visible=!0},100)}onSelectStart(){this._isTouching=!0}onSelectEnd(){this._isTouching=!1}setScale(e){const t=this._rig;!t||!this._placementPose||(this._rigStartPose||(this._rigStartPose=t.matrix.clone()),t.matrixAutoUpdate=!1,t.matrix.multiplyMatrices(new NA().makeScale(e,e,e),this._placementPose),t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(),console.log("Place",t.position))}}TT([w()],La.prototype,"invertForward",2);TT([w()],La.prototype,"arScale",1);const x6="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/";class Y6{constructor(A,e,t,g,I=null){this.controller=e,this.handModel=A,this.bones=[],I===null&&(I=new kE,I.setPath(t||x6)),I.load(`${g}.glb`,o=>{const C=o.scene.children[0];this.handModel.add(C),C.layers.mask=this.handModel.layers.mask;const s=C.getObjectByProperty("type","SkinnedMesh");s.frustumCulled=!1,s.castShadow=!0,s.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(a=>{const B=C.getObjectByName(a);B!==void 0?B.jointName=a:console.warn(`Couldn't find ${a} in ${g} hand mesh`),this.bones.push(B)})})}updateMesh(){const A=this.controller.joints;for(let e=0;e<this.bones.length;e++){const t=this.bones[e];if(t){const g=A[t.jointName];if(g.visible){const I=g.position;t.position.copy(I),t.quaternion.copy(g.quaternion)}}}}}const T6=.01,H6="index-finger-tip";class _6 extends UA{constructor(A,e=null){super(),this.controller=A,this.motionController=null,this.envMap=null,this.loader=e,this.mesh=null,A.addEventListener("connected",t=>{const g=t.data;g.hand&&!this.motionController&&(this.xrInputSource=g,this.motionController=new Y6(this,A,this.path,g.handedness,this.loader))}),A.addEventListener("disconnected",()=>{this.clear(),this.motionController=null})}updateMatrixWorld(A){super.updateMatrixWorld(A),this.motionController&&this.motionController.updateMesh()}getPointerPosition(){const A=this.controller.joints[H6];return A?A.position:null}intersectBoxObject(A){const e=this.getPointerPosition();if(e){const t=new BC(e,T6),g=new Jg().setFromObject(A);return t.intersectsBox(g)}else return!1}checkButton(A){this.intersectBoxObject(A)?A.onPress():A.onClear(),A.isPressed()&&A.whilePressed()}}const O6=.05,yJ=.02,op=.01,SJ=.02,kJ=1,XB=.4,P6=.002,Fc=.01,Cp=.003,GJ=.035,yt=16,no=12,u0=110,W6=new S(0,1,0),V6=new S(0,0,1),j6=.02,z6=1.5;class Z6 extends UA{constructor(A,e){super(),this.hand=A,this.controller=e,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,A.addEventListener("connected",t=>{const g=t.data;g.hand&&(this.visible=!0,this.xrInputSource=g,this.pointerObject===null&&this.createPointer())})}_drawVerticesRing(A,e,t){const g=e.clone();for(let I=0;I<yt;I++){g.applyAxisAngle(V6,Math.PI*2/yt);const o=t*yt+I;A[3*o]=g.x,A[3*o+1]=g.y,A[3*o+2]=g.z}}_updatePointerVertices(A){const e=this.pointerGeometry.attributes.position.array,t=new S(P6,0,-1*(GJ-A));this._drawVerticesRing(e,t,0);const g=new S(Math.sin(Math.PI*u0/180)*A,Math.cos(Math.PI*u0/180)*A,0);for(let n=0;n<no;n++)this._drawVerticesRing(e,g,n+1),g.applyAxisAngle(W6,Math.PI*u0/180/(no*-2));const I=yt*(1+no),o=yt*(1+no)+1,C=new S(0,0,-1*(GJ-A));e[I*3]=C.x,e[I*3+1]=C.y,e[I*3+2]=C.z;const s=new S(0,0,A);e[o*3]=s.x,e[o*3+1]=s.y,e[o*3+2]=s.z,this.pointerGeometry.setAttribute("position",new Ie(e,3))}createPointer(){let A,e;const t=new Array(((no+1)*yt+2)*3).fill(0),g=[];for(this.pointerGeometry=new de,this.pointerGeometry.setAttribute("position",new Ie(t,3)),this._updatePointerVertices(Fc),A=0;A<no;A++){for(e=0;e<yt-1;e++)g.push(A*yt+e,A*yt+e+1,(A+1)*yt+e),g.push(A*yt+e+1,(A+1)*yt+e+1,(A+1)*yt+e);g.push((A+1)*yt-1,A*yt,(A+2)*yt-1),g.push(A*yt,(A+1)*yt,(A+2)*yt-1)}const I=yt*(1+no),o=yt*(1+no)+1;for(A=0;A<yt-1;A++)g.push(I,A+1,A),g.push(o,A+yt*no,A+yt*no+1);g.push(I,0,yt-1),g.push(o,yt*(no+1)-1,yt*no);const C=new wt;C.transparent=!0,C.opacity=XB,this.pointerGeometry.setIndex(g),this.pointerMesh=new pA(this.pointerGeometry,C),this.pointerMesh.position.set(0,0,-1*Fc),this.pointerObject=new UA,this.pointerObject.add(this.pointerMesh),this.raycaster=new uE;const s=new $I(j6,10,10),n=new wt;n.transparent=!0,n.opacity=XB,this.cursorObject=new pA(s,n),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 A=this.pointerObject.matrixWorld,e=new NA;e.identity().extractRotation(A),this.raycaster.ray.origin.setFromMatrixPosition(A),this.raycaster.ray.direction.set(0,0,-1).applyMatrix4(e)}}_updatePointer(){this.pointerObject.visible=this.controller.visible;const A=this.hand.joints["index-finger-tip"],e=this.hand.joints["thumb-tip"],t=A.position.distanceTo(e.position),g=A.position.clone().add(e.position).multiplyScalar(.5);this.pointerObject.position.copy(g),this.pointerObject.quaternion.copy(this.controller.quaternion),this.pinched=t<=yJ;const I=(t-op)/(O6-op),o=(t-op)/(yJ-op);if(I>1)this._updatePointerVertices(Fc),this.pointerMesh.position.set(0,0,-1*Fc),this.pointerMesh.material.opacity=XB;else if(I>0){const C=(Fc-Cp)*I+Cp;this._updatePointerVertices(C),o<1?(this.pointerMesh.position.set(0,0,-1*C-(1-o)*SJ),this.pointerMesh.material.opacity=XB+(1-o)*(kJ-XB)):(this.pointerMesh.position.set(0,0,-1*C),this.pointerMesh.material.opacity=XB)}else this._updatePointerVertices(Cp),this.pointerMesh.position.set(0,0,-1*Cp-SJ),this.pointerMesh.material.opacity=kJ;this.cursorObject.material.opacity=this.pointerMesh.material.opacity}updateMatrixWorld(A){super.updateMatrixWorld(A),this.pointerGeometry&&(this._updatePointer(),this._updateRaycaster())}isPinched(){return this.pinched}setAttached(A){this.attached=A}isAttached(){return this.attached}intersectObject(A,e=!0){if(this.raycaster)return this.raycaster.intersectObject(A,e)}intersectObjects(A,e=!0){if(this.raycaster)return this.raycaster.intersectObjects(A,e)}checkIntersections(A,e=!1){if(this.raycaster&&!this.attached){const t=this.raycaster.intersectObjects(A,e),g=new S(0,0,-1);if(t.length>0){const o=t[0].distance;this.cursorObject.position.copy(g.multiplyScalar(o))}else this.cursorObject.position.copy(g.multiplyScalar(z6))}}setCursor(A){const e=new S(0,0,-1);this.raycaster&&!this.attached&&this.cursorObject.position.copy(e.multiplyScalar(A))}}const ii={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 HT(i){const A=await fetch(i);if(A.ok)return A.json();throw new Error(A.statusText)}async function X6(i){if(!i)throw new Error("No basePath supplied");return await HT(`${i}/profilesList.json`)}async function $6(i,A,e=null,t=!0){if(!i)throw new Error("No xrInputSource supplied");if(!A)throw new Error("No basePath supplied");const g=await X6(A);let I;if(i.profiles.some(s=>{const n=g[s];return n&&(I={profileId:s,profilePath:`${A}/${n.path}`,deprecated:!!n.deprecated}),!!I}),!I){if(!e)throw new Error("No matching profile name found");const s=g[e];if(!s)throw new Error(`No matching profile name found and default profile "${e}" missing.`);I={profileId:e,profilePath:`${A}/${s.path}`,deprecated:!!s.deprecated}}const o=await HT(I.profilePath);let C;if(t){let s;if(i.handedness==="any"?s=o.layouts[Object.keys(o.layouts)[0]]:s=o.layouts[i.handedness],!s)throw new Error(`No matching handedness, ${i.handedness}, in profile ${I.profileId}`);s.assetPath&&(C=I.profilePath.replace("profile.json",s.assetPath))}return{profile:o,assetPath:C}}const A7={xAxis:0,yAxis:0,button:0,state:ii.ComponentState.DEFAULT};function e7(i=0,A=0){let e=i,t=A;if(Math.sqrt(i*i+A*A)>1){const o=Math.atan2(A,i);e=Math.cos(o),t=Math.sin(o)}return{normalizedXAxis:e*.5+.5,normalizedYAxis:t*.5+.5}}class t7{constructor(A){this.componentProperty=A.componentProperty,this.states=A.states,this.valueNodeName=A.valueNodeName,this.valueNodeProperty=A.valueNodeProperty,this.valueNodeProperty===ii.VisualResponseProperty.TRANSFORM&&(this.minNodeName=A.minNodeName,this.maxNodeName=A.maxNodeName),this.value=0,this.updateFromComponent(A7)}updateFromComponent({xAxis:A,yAxis:e,button:t,state:g}){const{normalizedXAxis:I,normalizedYAxis:o}=e7(A,e);switch(this.componentProperty){case ii.ComponentProperty.X_AXIS:this.value=this.states.includes(g)?I:.5;break;case ii.ComponentProperty.Y_AXIS:this.value=this.states.includes(g)?o:.5;break;case ii.ComponentProperty.BUTTON:this.value=this.states.includes(g)?t:0;break;case ii.ComponentProperty.STATE:this.valueNodeProperty===ii.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(g):this.value=this.states.includes(g)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}}class i7{constructor(A,e){if(!A||!e||!e.visualResponses||!e.gamepadIndices||Object.keys(e.gamepadIndices).length===0)throw new Error("Invalid arguments supplied");this.id=A,this.type=e.type,this.rootNodeName=e.rootNodeName,this.touchPointNodeName=e.touchPointNodeName,this.visualResponses={},Object.keys(e.visualResponses).forEach(t=>{const g=new t7(e.visualResponses[t]);this.visualResponses[t]=g}),this.gamepadIndices=Object.assign({},e.gamepadIndices),this.values={state:ii.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(A){if(this.values.state=ii.ComponentState.DEFAULT,this.gamepadIndices.button!==void 0&&A.buttons.length>this.gamepadIndices.button){const e=A.buttons[this.gamepadIndices.button];this.values.button=e.value,this.values.button=this.values.button<0?0:this.values.button,this.values.button=this.values.button>1?1:this.values.button,e.pressed||this.values.button===1?this.values.state=ii.ComponentState.PRESSED:(e.touched||this.values.button>ii.ButtonTouchThreshold)&&(this.values.state=ii.ComponentState.TOUCHED)}this.gamepadIndices.xAxis!==void 0&&A.axes.length>this.gamepadIndices.xAxis&&(this.values.xAxis=A.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===ii.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>ii.AxisTouchThreshold&&(this.values.state=ii.ComponentState.TOUCHED)),this.gamepadIndices.yAxis!==void 0&&A.axes.length>this.gamepadIndices.yAxis&&(this.values.yAxis=A.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===ii.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>ii.AxisTouchThreshold&&(this.values.state=ii.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(e=>{e.updateFromComponent(this.values)})}}class g7{constructor(A,e,t){if(!A)throw new Error("No xrInputSource supplied");if(!e)throw new Error("No profile supplied");this.xrInputSource=A,this.assetUrl=t,this.id=e.profileId,this.layoutDescription=e.layouts[A.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(g=>{const I=this.layoutDescription.components[g];this.components[g]=new i7(g,I)}),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const A=[];return Object.values(this.components).forEach(e=>{A.push(e.data)}),A}updateFromGamepad(){Object.values(this.components).forEach(A=>{A.updateFromGamepad(this.xrInputSource.gamepad)})}}const I7="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",o7="generic-trigger";class C7 extends UA{constructor(){super(),this.motionController=null,this.envMap=null}setEnvironmentMap(A){return this.envMap==A?this:(this.envMap=A,this.traverse(e=>{e.isMesh&&(e.material.envMap=this.envMap,e.material.needsUpdate=!0)}),this)}updateMatrixWorld(A){super.updateMatrixWorld(A),this.motionController&&(this.motionController.updateFromGamepad(),Object.values(this.motionController.components).forEach(e=>{Object.values(e.visualResponses).forEach(t=>{const{valueNode:g,minNode:I,maxNode:o,value:C,valueNodeProperty:s}=t;g&&(s===ii.VisualResponseProperty.VISIBILITY?g.visible=C:s===ii.VisualResponseProperty.TRANSFORM&&(g.quaternion.slerpQuaternions(I.quaternion,o.quaternion,C),g.position.lerpVectors(I.position,o.position,C)))})}))}}function s7(i,A){Object.values(i.components).forEach(e=>{const{type:t,touchPointNodeName:g,visualResponses:I}=e;if(t===ii.ComponentType.TOUCHPAD)if(e.touchPointNode=A.getObjectByName(g),e.touchPointNode){const o=new $I(.001),C=new wt({color:255}),s=new pA(o,C);e.touchPointNode.add(s)}else console.warn(`Could not find touch dot, ${e.touchPointNodeName}, in touchpad component ${e.id}`);Object.values(I).forEach(o=>{const{valueNodeName:C,minNodeName:s,maxNodeName:n,valueNodeProperty:a}=o;if(a===ii.VisualResponseProperty.TRANSFORM){if(o.minNode=A.getObjectByName(s),o.maxNode=A.getObjectByName(n),!o.minNode){console.warn(`Could not find ${s} in the model`);return}if(!o.maxNode){console.warn(`Could not find ${n} in the model`);return}}o.valueNode=A.getObjectByName(C),o.valueNode||console.warn(`Could not find ${C} in the model`)})})}function MJ(i,A){s7(i.motionController,A),i.envMap&&A.traverse(e=>{e.isMesh&&(e.material.envMap=i.envMap,e.material.needsUpdate=!0)}),i.layers.mask!=0&&A.traverse(e=>{e.layers.mask=i.layers.mask}),i.add(A)}class n7{constructor(A=null){this.gltfLoader=A,this.path=I7,this._assetCache={},this.gltfLoader||(this.gltfLoader=new kE)}createControllerModel(A){const e=new C7;let t=null;return A.addEventListener("connected",g=>{const I=g.data;I.targetRayMode!=="tracked-pointer"||!I.gamepad||$6(I,this.path,o7).then(({profile:o,assetPath:C})=>{e.motionController=new g7(I,o,C);const s=this._assetCache[e.motionController.assetUrl];if(s)t=s.scene.clone(),MJ(e,t);else{if(!this.gltfLoader)throw new Error("GLTFLoader not set.");this.gltfLoader.setPath(""),this.gltfLoader.load(e.motionController.assetUrl,n=>{this._assetCache[e.motionController.assetUrl]=n,t=n.scene.clone(),MJ(e,t)},null,()=>{throw new Error(`Asset ${e.motionController.assetUrl} missing or malformed.`)})}}).catch(o=>{console.warn(o)})}),A.addEventListener("disconnected",()=>{e.motionController=null,e.remove(t),t=null}),e}}const Nc=nA("debugavatar");class xw{constructor(A,e,t,g){r(this,"root");r(this,"head");r(this,"leftHand");r(this,"rigthHand");var I;this.root=A,this.head=e,this.leftHand=t,this.rigthHand=g,(I=this.root)==null||I.traverse(o=>o.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class Yw{constructor(){r(this,"avatarRegistryUrl",null)}async getOrCreateNewAvatarInstance(A,e){if(!e)return console.error("Can not create avatar: failed to provide id or root object"),null;let t=null;if(typeof e=="string"){if(t=await this.loadAvatar(A,e),!t){const I=new WC;t=AA.instantiate(vQ(e,A.scene),I)}}else t=e;if(!t)return null;const g=this.findAvatar(t);return g.isValid?(Nc&&console.log("[Custom Avatar] valid config",e,Nc?g:""),g):(console.warn("[Custom Avatar] config isn't valid",e,Nc?g:""),null)}async loadAvatar(A,e){if(console.assert(e!=null&&typeof e=="string","Avatar id must not be null"),e.length<=0||!e)return null;if(Nc&&console.log("[Custom Avatar] "+e+", loading..."),e.endsWith(".glb")||(e+=".glb"),this.avatarRegistryUrl===null){const g=await fetch("./"+e);let I=null;if(g.ok){const C=await g.blob();C&&(I=await C.arrayBuffer())}if(!I&&(I=await Dm(e,e,0,"no url here go away",!0),!I))return null;const o=await sC().parseSync(A,I,null,0);return(o==null?void 0:o.scene)??null}const t=new kE;return Qd(t,A),new Promise((g,I)=>{const o=this.avatarRegistryUrl+"/"+e;t.load(o,async C=>{await sC().createBuiltinComponents(A,o,C,null,void 0),g(C.scene)},C=>{Nc&&console.log("[Custom Avatar] "+C.loaded/C.total*100+"% loaded of "+C.total/1024+"kB")},C=>{console.error("[Custom Avatar] Error when loading: "+C),g(null)})})}cacheModel(A,e){}findAvatar(A){const e=A;let t=e;t.children.length==1&&(t=A.children[0]);let g=this.findAvatarPart(t,["head"]);const I=this.findAvatarPart(t,["left","hand"]),o=this.findAvatarPart(t,["right","hand"]);if(!g){g=e;const s=new S;new Jg().setFromObject(g).getSize(s);const n=Math.max(s.x,s.y,s.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+n+" meters! Should be < 0.3m"),n>.3&&g.scale.multiplyScalar(1/n*.3)}return new xw(e,g,I,o)}findAvatarPart(A,e){const t=A.name.toLowerCase();let g=!0;for(const I of e){if(!g)break;t.indexOf(I)===-1&&(g=!1)}if(g)return A;if(A.children)for(const I of A.children){const o=this.findAvatarPart(I,e);if(o)return o}return null}handleCustomAvatarErrors(A){if(!A.ok)throw Error(A.statusText);return A}}const nQ=nA("debugflags");var Mi=(i=>(i[i.Never=0]="Never",i[i.Browser=1]="Browser",i[i.AR=2]="AR",i[i.VR=4]="VR",i[i.FirstPerson=8]="FirstPerson",i[i.ThirdPerson=16]="ThirdPerson",i[i.All=4294967295]="All",i))(Mi||{});const tF=class{constructor(){r(this,"Mask",17)}Has(A){return(this.Mask&A)!==0}Set(A){nQ&&console.warn("Set XR flag state to",A),this.Mask=A,lg.Apply()}Enable(A){this.Mask|=A,lg.Apply()}Disable(A){this.Mask&=~A,lg.Apply()}Toggle(A){this.Mask^=A,lg.Apply()}EnableAll(){this.Mask=-1,lg.Apply()}DisableAll(){this.Mask=0,lg.Apply()}};let Mo=tF;r(Mo,"Global",new tF);const MC=class extends MA{constructor(){super(...arguments);r(this,"visibleIn")}static Apply(){for(const e of this.registry)e.UpdateVisible(Mo.Global)}awake(){MC.registry.push(this)}onEnable(){MC.firstApply?this.UpdateVisible(Mo.Global):(MC.firstApply=!0,MC.Apply())}onDestroy(){const e=MC.registry.indexOf(this);e>=0&&MC.registry.splice(e,1)}get isOn(){return this.gameObject.visible}UpdateVisible(e=null){let t;const g=e;g&&typeof g=="number"&&(console.assert(typeof g=="number","XRFlag.UpdateVisible: state must be a number",g),nQ&&console.log(g),MC.buffer.Mask=g,e=MC.buffer);const I=e;if(I?(nQ&&console.warn(this.name,"use passed in mask",I.Mask,this.visibleIn),t=I.Has(this.visibleIn)):(nQ&&console.log(this.name,"use global mask"),Mo.Global.Has(this.visibleIn)),t!==void 0)if(t)nQ&&console.log(this.name,"is visible",this.gameObject.uuid),AA.setActive(this.gameObject,!0);else{if(nQ&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}};let lg=MC;r(lg,"registry",[]),r(lg,"firstApply"),r(lg,"buffer",new Mo);const jn=nA("debugavatar"),$o=class extends MA{constructor(){super(...arguments);r(this,"connectionId");r(this,"avatar")}static getAvatar(e){return e>=0&&e<$o.instances.length?$o.instances[e]:null}static onAvatarMarkerCreated(e){return $o._onNewAvatarMarkerAdded.push(e),e}static onAvatarMarkerDestroyed(e){return $o._onAvatarMarkerDestroyed.push(e),e}awake(){$o.instances.push(this),jn&&console.log(this);for(const e of $o._onNewAvatarMarkerAdded)e({avatarMarker:this,gameObject:this.gameObject})}onDestroy(){$o.instances.splice($o.instances.indexOf(this),1);for(const e of $o._onAvatarMarkerDestroyed)e({avatarMarker:this,gameObject:this.gameObject})}isLocalAvatar(){return this.connectionId===this.context.connection.connectionId}setVisible(e){this.avatar&&("setVisible"in this.avatar?this.avatar.setVisible(e):AA.setActive(this.avatar,e))}};let Ig=$o;r(Ig,"instances",[]),r(Ig,"_onNewAvatarMarkerAdded",[]),r(Ig,"_onAvatarMarkerDestroyed",[]);const Lh=class{constructor(A,e,t){r(this,"_isVisible",!0);r(this,"guid");r(this,"root",null);r(this,"head",null);r(this,"handLeft",null);r(this,"handRight",null);r(this,"lastUpdate",-1);r(this,"isLocalAvatar",!1);r(this,"flags",null);r(this,"headScale",new S(1,1,1));r(this,"handLeftScale",new S(1,1,1));r(this,"handRightScale",new S(1,1,1));r(this,"webxr");r(this,"lastAvatarId",null);r(this,"hasAvatarOverride",!1);r(this,"context");r(this,"avatarMarker",null);r(this,"_headTarget",new UA);r(this,"_handLeftTarget",new UA);r(this,"_handRightTarget",new UA);r(this,"_canInterpolate",!1);this.context=A,this.guid=e,this.webxr=t,this.setupCustomAvatar(this.webxr.defaultAvatar)}setVisible(A){this._isVisible=A,this.updateVisibility()}get isWebXRAvatar(){return!0}updateFlags(){if(!this.flags)return;let A=this.isLocalAvatar?Mi.FirstPerson:Mi.ThirdPerson;this.context.isInVR?A|=Mi.VR:this.context.isInAR?A|=Mi.AR:A|=Mi.Browser;for(const e of this.flags)e.gameObject.visible=!0,e.UpdateVisible(A)}async setAvatarOverride(A){return this.hasAvatarOverride=A!==null,this.hasAvatarOverride&&this.lastAvatarId!==A&&(this.lastAvatarId=A,A!=null&&A.length>0)?await this.setupCustomAvatar(A):null}tryUpdate(A,e){if(A.guid===this.guid&&(this.lastAvatarId!==A.avatarId&&A.avatarId&&A.avatarId.length>0&&(this.lastAvatarId=A.avatarId,this.setupCustomAvatar(A.avatarId)),this.lastUpdate=A.time,this.head)){const t=this.webxr.IsInAR?_C.Handheld:_C.Headset;let g=this.head;this.context.players.setPlayerView(A.guid,g,t),fI.markDirty(this.head),this._canInterpolate=!0;const I=this.isLocalAvatar?this.head:this._headTarget;if(I.position.set(A.position.x,A.position.y,A.position.z),I.quaternion.set(A.rotation.x,A.rotation.y,A.rotation.z,A.rotation.w),I.scale.set(A.scale,A.scale,A.scale),I.scale.multiply(this.headScale),this.handLeft){const o=this.isLocalAvatar?this.handLeft:this._handLeftTarget;o.position.set(A.posLeftHand.x,A.posLeftHand.y,A.posLeftHand.z),o.quaternion.set(A.rotLeftHand._x,A.rotLeftHand._y,A.rotLeftHand._z,A.rotLeftHand._w),o.quaternion.multiply(Lh.invertRotation),o.scale.set(A.scale,A.scale,A.scale),o.scale.multiply(this.handLeftScale),fI.markDirty(this.handLeft)}if(this.handRight){const o=this.isLocalAvatar?this.handRight:this._handRightTarget;o.position.set(A.posRightHand.x,A.posRightHand.y,A.posRightHand.z),o.quaternion.set(A.rotRightHand._x,A.rotRightHand._y,A.rotRightHand._z,A.rotRightHand._w),o.quaternion.multiply(Lh.invertRotation),o.scale.set(A.scale,A.scale,A.scale),o.scale.multiply(this.handRightScale),fI.markDirty(this.handRight)}}}update(){if(this.isLocalAvatar||!this._canInterpolate)return;const A=this.context.time.deltaTime/.1;this.head&&(this.head.position.lerp(this._headTarget.position,A),this.head.quaternion.slerp(this._headTarget.quaternion,A),this.head.scale.lerp(this._headTarget.scale,A)),this.handLeft&&this._handLeftTarget&&(this.handLeft.position.lerp(this._handLeftTarget.position,A),this.handLeft.quaternion.slerp(this._handLeftTarget.quaternion,A),this.handLeft.scale.lerp(this._handLeftTarget.scale,A)),this.handRight&&this._handRightTarget&&(this.handRight.position.lerp(this._handRightTarget.position,A),this.handRight.quaternion.slerp(this._handRightTarget.quaternion,A),this.handRight.scale.lerp(this._handRightTarget.scale,A))}destroy(){var A,e;jn&&console.log("Destroy avatar",this.guid),(A=this.root)==null||A.removeFromParent(),(e=this.avatarMarker)==null||e.destroy(),this.lastAvatarId=null,this.head&&tI.Remove(this.context,this.head)}updateVisibility(){const A=this.root;A&&AA.setActive(A,this._isVisible)}async setupCustomAvatar(A){var g,I,o;if(jn&&console.log("LOAD",A,this),!A||typeof A=="string"&&A.length<=0)return!1;this.head&&tI.Remove(this.context,this.head);const e=A;if((e==null?void 0:e.loadAssetAsync)!==void 0){await e.loadAssetAsync();const C=e.asset;AA.setActive(C,!1),A=AA.instantiate(C),AA.setActive(A,!0)}jn&&console.log(A);const t=await Lh.loader.getOrCreateNewAvatarInstance(this.context,A);if(jn&&console.log(t,t==null?void 0:t.isValid,this.lastAvatarId,A),t!=null&&t.isValid){if(this.root=t.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=AA.addNewComponent(this.root,Ig),this.avatarMarker.connectionId=this.guid,this.avatarMarker.avatar=this,this.head&&this.head!==t.head&&((g=this.head)==null||g.removeFromParent()),this.head=t.head,this.headScale.copy(this.head.scale),this.head&&!this.isLocalAvatar&&tI.Add(this.context,this.head,this.avatarMarker),t.leftHand&&((I=this.handLeft)==null||I.removeFromParent()),this.handLeft=t.leftHand??this.handLeft,this.handLeft?this.handLeftScale.copy(this.handLeft.scale):this.handLeftScale.set(1,1,1),t.rigthHand&&((o=this.handRight)==null||o.removeFromParent()),this.handRight=t.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(...AA.getComponentsInChildren(this.root,lg)),this.flags.length<=0&&this.head){const C=AA.addNewComponent(this.head,lg);C.visibleIn=Mi.ThirdPerson|Mi.VR,this.flags.push(C),jn&&console.log("Added flag to head: "+C.visibleIn,this.head.name)}return jn&&console.log("[Avatar], is Local? ",this.isLocalAvatar,this.root),this.updateFlags(),this.updateVisibility(),!0}else return jn&&console.warn("build avatar failed"),!1}};let xC=Lh;r(xC,"loader",new Yw),r(xC,"invertRotation",new kA().setFromAxisAngle(new S(0,1,0),Math.PI));class tI{static Add(A,e,t=null){if(e){for(const g of this.Pois)if(g.obj===e)return;this.Pois.push({obj:e,avatar:t}),this.LastChangeTime=A.time.time}}static Remove(A,e){var t;if(e){for(const g of this.Pois)if(g.obj===e){this.Pois.splice(this.Pois.indexOf(g),1),this.LastChangeTime=(A==null?void 0:A.time.time)??((t=qe.Current)==null?void 0:t.time.time);return}}}}r(tI,"Pois",[]),r(tI,"LastChangeTime",0);class a7{constructor(){r(this,"guid");r(this,"position",new S)}}class rl extends MA{constructor(){super(...arguments);r(this,"target",null);r(this,"avatar",null);r(this,"_model",null);r(this,"_targetModel",new a7);r(this,"_currentTargetObject",null);r(this,"_lastUpdateTime",0);r(this,"_lookDuration",0);r(this,"_lastPoiChangedTime",0)}set controlledTarget(e){this.target=e;const t=T.get("MoveRandom");if(t&&this.target){const g=AA.getComponent(this.target,t);g&&g.destroy()}}awake(){if(this.avatar=AA.getComponentInParent(this.gameObject,Ig),this.avatar){const e=AA.getComponentInParent(this.gameObject,Ig);this._model=new fw(this.context.connection,this.guid),e!=null&&e.isLocalAvatar&&this._model.requestOwnership()}this.context.connection.beginListen("avatar-look-target-changed",e=>{var t;this.target&&e&&e.guid===((t=this.avatar)==null?void 0:t.guid)&&di(this.target,e.position)})}update(){var t;if((!this.context.connection.isConnected||(t=this._model)!=null&&t.hasOwnership)&&(tI.LastChangeTime!==this._lastPoiChangedTime&&(this._lastPoiChangedTime=tI.LastChangeTime,this._lookDuration=0),this.selectTarget(),this._currentTargetObject&&this.context.time.frameCount%10===0&&this.target)){const g=ye(this._currentTargetObject);di(this.target,g),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(g))}}selectTarget(){if(this.context.time.time-this._lastUpdateTime>this._lookDuration){this._lastUpdateTime=this.context.time.time,this._lookDuration=Math.random()*.5+.2;const t=tI.Pois;if(t.length>0){const g=t[Math.floor(Math.random()*t.length)];if(g&&g.obj){if(g.avatar&&g.avatar===this.avatar)return;this._currentTargetObject=g.obj}}}}}class bE extends MA{constructor(){super(...arguments);r(this,"canGrab",!0)}onPointerClick(e){}}class LE extends MA{constructor(){super(...arguments);r(this,"isUsed",!0);r(this,"usedBy",null)}}var GC=(i=>(i[i.Average=0]="Average",i[i.Multiply=1]="Multiply",i[i.Minimum=2]="Minimum",i[i.Maximum=3]="Maximum",i))(GC||{}),Tw=(i=>(i[i.Discrete=0]="Discrete",i[i.Continuous=1]="Continuous",i))(Tw||{}),ai=(i=>(i[i.None=0]="None",i[i.FreezePositionX=2]="FreezePositionX",i[i.FreezePositionY=4]="FreezePositionY",i[i.FreezePositionZ=8]="FreezePositionZ",i[i.FreezePosition=14]="FreezePosition",i[i.FreezeRotationX=16]="FreezeRotationX",i[i.FreezeRotationY=32]="FreezeRotationY",i[i.FreezeRotationZ=64]="FreezeRotationZ",i[i.FreezeRotation=112]="FreezeRotation",i[i.FreezeAll=126]="FreezeAll",i))(ai||{}),DQ=(i=>(i[i.None=0]="None",i[i.X=2]="X",i[i.Y=4]="Y",i[i.Z=8]="Z",i[i.All=-1]="All",i))(DQ||{});const Ao=function(i,A){return function(e,t,g){r7(e,t,g,i,A)}};function r7(i,A,e,t,g){if(!(!g&&!t&&!i.onValidate)){if(e!==void 0){console.error("Invalid usage of validate decorator. Only fields can be validated.",i,A,e),mi("Invalid usage of validate decorator. Only fields can be validated. Property: "+A,oC.Error);return}if(i.__internalAwake){const I=Symbol(A),o=i.__internalAwake;i.__internalAwake=function(){this[I]===void 0&&(this[I]=this[A],Object.defineProperty(this,A,{set:function(C){var s;if(this[zk]===!0)this[I]=C;else{t==null||t.call(this,C);const n=this[I];this[I]=C,(s=this.onValidate)==null||s.call(this,A,n)}},get:function(){return g==null||g.call(this),this[I]}})),o.call(this)}}}}const B7=function(i){return function(A,e,t){const g=i.prototype,I=Object.getOwnPropertyDescriptor(g,e);if(!(I!=null&&I.value)){console.warn("Can not apply prefix: type does not have method named",e,i);return}const o=I.value,C=A[e];Object.defineProperty(g,e,{value:function(...s){const n=C==null?void 0:C.call(this,...s);if(n instanceof Promise){n.then(a=>{if(a!==!1)return o.call(this,...s)});return}if(n!==!1)return o.call(this,...s)}})}};var Q7=Object.defineProperty,E7=Object.getOwnPropertyDescriptor,ln=(i,A,e,t)=>{for(var g=t>1?void 0:t?E7(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&Q7(A,e,g),g};class c7{constructor(A,e){r(this,"positionChanged",!1);r(this,"rotationChanged",!1);r(this,"position");r(this,"quaternion");r(this,"_positionKeys",["x","y","z"]);r(this,"_quaternionKeys",["_x","_y","_z","_w"]);r(this,"mute",!1);r(this,"context");r(this,"obj");r(this,"_positionWatch");r(this,"_rotationWatch");this.context=e,this.obj=A}get isDirty(){return this.positionChanged||this.rotationChanged}reset(A=!1){if(this.positionChanged=!1,this.rotationChanged=!1,this.mute=!1,A){if(this.position)for(const e of this._positionKeys)delete this.position[e];if(this.quaternion)for(const e of this._quaternionKeys)delete this.quaternion[e]}}syncValues(){for(const A of this._positionKeys)this.position[A]=this.obj.position[A];for(const A of this._quaternionKeys)this.quaternion[A]=this.obj.quaternion[A]}applyValues(){if(this.positionChanged&&this.position)for(const A of this._positionKeys){const e=this.position[A];e!==void 0&&(this.obj.position[A]=e)}if(this.rotationChanged&&this.quaternion)for(const A of this._quaternionKeys){const e=this.quaternion[A];e!==void 0&&(this.obj.quaternion[A]=e)}}start(A,e){this.reset(),A&&(this._positionWatch||(this._positionWatch=new xQ(this.obj.position,["x","y","z"])),this._positionWatch.apply(),this.position={},this._positionWatch.subscribeWrite((I,o)=>{var s;if((s=this.context.physics.engine)!=null&&s.isUpdating||this.mute)return;const C=this.position[o];Math.abs(C-I)<1e-5||(this.position[o]=I,this.positionChanged=!0)})),e&&(this._rotationWatch||(this._rotationWatch=new xQ(this.obj.quaternion,["_x","_y","_z","_w"])),this._rotationWatch.apply(),this.quaternion={},this._rotationWatch.subscribeWrite((I,o)=>{var s;if((s=this.context.physics.engine)!=null&&s.isUpdating||this.mute)return;const C=this.quaternion[o];Math.abs(C-I)<1e-5||(this.quaternion[o]=I,this.rotationChanged=!0)}));const t=this.obj.matrixWorld.multiplyMatrices.bind(this.obj.matrixWorld),g=new NA;this.obj.matrixWorld.multiplyMatrices=(I,o)=>(g.equals(I)||(this.positionChanged=!0,this.rotationChanged=!0,g.copy(I)),t(I,o))}stop(){var A,e;(A=this._positionWatch)==null||A.revoke(),(e=this._rotationWatch)==null||e.revoke()}}var tk;const RG=(tk=class extends MA{constructor(){super(...arguments);r(this,"mass",1);r(this,"useGravity",!0);r(this,"constraints",ai.None);r(this,"isKinematic",!1);r(this,"drag",0);r(this,"angularDrag",1);r(this,"detectCollisions",!0);r(this,"sleepThreshold",.01);r(this,"collisionDetectionMode",Tw.Discrete);r(this,"_gravityScale",1);r(this,"_propertiesChanged",!1);r(this,"_currentVelocity",new S);r(this,"_smoothedVelocity",new S);r(this,"_smoothedVelocityGetter",new S);r(this,"_lastPosition",new S);r(this,"_watch")}get lockPositionX(){return(this.constraints&ai.FreezePositionX)!==0}get lockPositionY(){return(this.constraints&ai.FreezePositionY)!==0}get lockPositionZ(){return(this.constraints&ai.FreezePositionZ)!==0}get lockRotationX(){return(this.constraints&ai.FreezeRotationX)!==0}get lockRotationY(){return(this.constraints&ai.FreezeRotationY)!==0}get lockRotationZ(){return(this.constraints&ai.FreezeRotationZ)!==0}set lockPositionX(A){A?this.constraints|=ai.FreezePositionX:this.constraints&=~ai.FreezePositionX}set lockPositionY(A){A?this.constraints|=ai.FreezePositionY:this.constraints&=~ai.FreezePositionY}set lockPositionZ(A){A?this.constraints|=ai.FreezePositionZ:this.constraints&=~ai.FreezePositionZ}set lockRotationX(A){A?this.constraints|=ai.FreezeRotationX:this.constraints&=~ai.FreezeRotationX}set lockRotationY(A){A?this.constraints|=ai.FreezeRotationY:this.constraints&=~ai.FreezeRotationY}set lockRotationZ(A){A?this.constraints|=ai.FreezeRotationZ:this.constraints&=~ai.FreezeRotationZ}set gravityScale(A){this._gravityScale=A}get gravityScale(){return this._gravityScale}awake(){this._watch=void 0,this._propertiesChanged=!1}onEnable(){this._watch||(this._watch=new c7(this.gameObject,this.context)),this._watch.start(!0,!0),this.startCoroutine(this.beforePhysics(),ZI.LateUpdate)}onDisable(){var A,e;(A=this._watch)==null||A.stop(),(e=this.context.physics.engine)==null||e.removeBody(this)}onDestroy(){var A;(A=this.context.physics.engine)==null||A.removeBody(this)}onValidate(){this._propertiesChanged=!0}*beforePhysics(){var A,e,t,g;for(;;)this._propertiesChanged&&(this._propertiesChanged=!1,(A=this.context.physics.engine)==null||A.updateProperties(this)),(e=this._watch)!=null&&e.isDirty?(this._watch.mute=!0,this._watch.applyValues(),(t=this.context.physics.engine)==null||t.updateBody(this,this._watch.positionChanged,this._watch.rotationChanged),this._watch.reset()):(g=this._watch)==null||g.syncValues(),this.captureVelocity(),yield}teleport(A,e=!0){var t;(t=this._watch)==null||t.reset(!0),e?this.gameObject.position.set(A.x,A.y,A.z):this.setWorldPosition(A.x,A.y,A.z),this.resetForcesAndTorques(),this.resetVelocities()}resetForces(){var A;(A=this.context.physics.engine)==null||A.resetForces(this,!0)}resetTorques(){var A;(A=this.context.physics.engine)==null||A.resetTorques(this,!0)}resetVelocities(){this.setVelocity(0,0,0),this.setAngularVelocity(0,0,0)}resetForcesAndTorques(){this.resetForces(),this.resetTorques()}wakeUp(){var A;(A=this.context.physics.engine)==null||A.wakeup(this)}applyForce(A,e){var t;(t=this.context.physics.engine)==null||t.addForce(this,A,!0)}applyImpulse(A){var e;(e=this.context.physics.engine)==null||e.applyImpulse(this,A,!0)}setForce(A,e,t){var g,I;(g=this.context.physics.engine)==null||g.resetForces(this,!0),(I=this.context.physics.engine)==null||I.addForce(this,{x:A,y:e,z:t},!0)}getVelocity(){var e;const A=(e=this.context.physics.engine)==null?void 0:e.getLinearVelocity(this);return A?(this._currentVelocity.x=A.x,this._currentVelocity.y=A.y,this._currentVelocity.z=A.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setVelocity(A,e,t){var g,I;if(A instanceof S){const o=A;(g=this.context.physics.engine)==null||g.setLinearVelocity(this,o,!0);return}e===void 0||t===void 0||(I=this.context.physics.engine)==null||I.setLinearVelocity(this,{x:A,y:e,z:t},!0)}setAngularVelocity(A,e,t){var g,I;if(A instanceof S){const o=A;(g=this.context.physics.engine)==null||g.setAngularVelocity(this,o,!0);return}e===void 0||t===void 0||(I=this.context.physics.engine)==null||I.setAngularVelocity(this,{x:A,y:e,z:t},!0)}getAngularVelocity(){var e;const A=(e=this.context.physics.engine)==null?void 0:e.getAngularVelocity(this);return A?(this._currentVelocity.x=A.x,this._currentVelocity.y=A.y,this._currentVelocity.z=A.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setTorque(A,e,t){this.setAngularVelocity(A,e,t)}get smoothedVelocity(){return this._smoothedVelocityGetter.copy(this._smoothedVelocity),this._smoothedVelocityGetter.multiplyScalar(1/this.context.time.deltaTime)}setBodyFromGameObject(A=null){}captureVelocity(){const A=ye(this.gameObject);RG.tempPosition.copy(A);const e=A.sub(this._lastPosition);this._lastPosition.copy(RG.tempPosition),this._smoothedVelocity.lerp(e,this.context.time.deltaTime/.1)}},r(tk,"tempPosition",new S),tk);let Xt=RG;ln([Ao(),w()],Xt.prototype,"mass",2);ln([Ao(),w()],Xt.prototype,"useGravity",2);ln([Ao(),w()],Xt.prototype,"constraints",2);ln([Ao(),w()],Xt.prototype,"isKinematic",2);ln([Ao(),w()],Xt.prototype,"drag",2);ln([Ao(),w()],Xt.prototype,"angularDrag",2);ln([Ao(),w()],Xt.prototype,"detectCollisions",2);ln([Ao(),w()],Xt.prototype,"sleepThreshold",2);ln([Ao(),w()],Xt.prototype,"collisionDetectionMode",2);class jI{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}static sizeOf(){return 12}static createVec3(A,e,t,g){return A.prep(4,12),A.writeFloat32(g),A.writeFloat32(t),A.writeFloat32(e),A.offset()}}class _T{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}position(A){return(A||new jI).__init(this.bb_pos,this.bb)}rotation(A){return(A||new jI).__init(this.bb_pos+12,this.bb)}scale(A){return(A||new jI).__init(this.bb_pos+24,this.bb)}static sizeOf(){return 36}static createTransform(A,e,t,g,I,o,C,s,n,a){return A.prep(4,36),A.prep(4,12),A.writeFloat32(a),A.writeFloat32(n),A.writeFloat32(s),A.prep(4,12),A.writeFloat32(C),A.writeFloat32(o),A.writeFloat32(I),A.prep(4,12),A.writeFloat32(g),A.writeFloat32(t),A.writeFloat32(e),A.offset()}}class Ks{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsSyncedTransformModel(A,e){return(e||new Ks).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedTransformModel(A,e){return A.setPosition(A.position()+pw),(e||new Ks).__init(A.readInt32(A.position())+A.position(),A)}guid(A){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}fast(){const A=this.bb.__offset(this.bb_pos,6);return A?!!this.bb.readInt8(this.bb_pos+A):!1}transform(A){const e=this.bb.__offset(this.bb_pos,8);return e?(A||new _T).__init(this.bb_pos+e,this.bb):null}dontSave(){const A=this.bb.__offset(this.bb_pos,10);return A?!!this.bb.readInt8(this.bb_pos+A):!1}static startSyncedTransformModel(A){A.startObject(4)}static addGuid(A,e){A.addFieldOffset(0,e,0)}static addFast(A,e){A.addFieldInt8(1,+e,0)}static addTransform(A,e){A.addFieldStruct(2,e,0)}static addDontSave(A,e){A.addFieldInt8(3,+e,0)}static endSyncedTransformModel(A){return A.endObject()}static finishSyncedTransformModelBuffer(A,e){A.finish(e)}static finishSizePrefixedSyncedTransformModelBuffer(A,e){A.finish(e,void 0,!0)}}const Pn=nA("debugsync"),Bl="STRS";em(Bl,Ks.getRootAsSyncedTransformModel);const fC=new DE;function OT(i,A,e=!0){fC.clear();const t=fC.createString(i);Ks.startSyncedTransformModel(fC),Ks.addGuid(fC,t),Ks.addFast(fC,e);const g=A.worldPosition,I=A.worldEuler,o=A.gameObject.scale;Ks.addTransform(fC,_T.createTransform(fC,g.x,g.y,g.z,I.x,I.y,I.z,o.x,o.y,o.z));const C=Ks.endSyncedTransformModel(fC);return fC.finish(C,Bl),fC.asUint8Array()}class wa extends MA{constructor(){super(...arguments);r(this,"overridePhysics",!0);r(this,"interpolatePosition",!0);r(this,"interpolateRotation",!0);r(this,"fastMode",!1);r(this,"syncDestroy",!1);r(this,"_model",null);r(this,"_needsUpdate",!0);r(this,"rb",null);r(this,"_wasKinematic",!1);r(this,"_receivedDataBefore",!1);r(this,"_targetPosition");r(this,"_targetRotation");r(this,"_receivedFastUpdate",!1);r(this,"_shouldRequestOwnership",!1);r(this,"joinedRoomCallback",null);r(this,"receivedDataCallback",null);r(this,"tempEuler",new Fi);r(this,"receivedUpdate",!1);r(this,"lastWorldPos");r(this,"lastWorldRotation")}requestOwnership(){Pn&&console.log("Request ownership"),this._model?this._model.requestOwnership():(this._shouldRequestOwnership=!0,this._needsUpdate=!0)}hasOwnership(){var e;return((e=this._model)==null?void 0:e.hasOwnership)??void 0}isOwned(){var e;return(e=this._model)==null?void 0:e.isOwned}awake(){Pn&&console.log("new instance",this.guid,this),this._receivedDataBefore=!1,this._targetPosition=new S,this._targetRotation=new kA,this.lastWorldPos=new S,this.lastWorldRotation=new kA,this.rb=AA.getComponentInChildren(this.gameObject,Xt),this.rb&&(this._wasKinematic=this.rb.isKinematic),this.receivedUpdate=!0,this._model=new fw(this.context.connection,this.guid),this.context.connection.isConnected&&this.tryGetLastState(),this.joinedRoomCallback=this.tryGetLastState.bind(this),this.context.connection.beginListen(oi.JoinedRoom,this.joinedRoomCallback),this.receivedDataCallback=this.onReceivedData.bind(this),this.context.connection.beginListenBinary(Bl,this.receivedDataCallback)}onDestroy(){this.syncDestroy&&Ex(this.guid,this.context.connection),this._model=null,this.context.connection.stopListen(oi.JoinedRoom,this.joinedRoomCallback),this.context.connection.stopListenBinary(Bl,this.receivedDataCallback)}tryGetLastState(){const e=this.context.connection.tryGetState(this.guid);e&&this.onReceivedData(e)}onReceivedData(e){var t;if(!this.destroyed&&typeof e.guid=="function"&&e.guid()===this.guid){Pn&&console.log("new data",this.context.connection.connectionId,this.context.time.frameCount,this.guid,e),this.receivedUpdate=!0,this._receivedFastUpdate=e.fast();const g=e.transform();if(g){fI.markDirty(this.gameObject,!0);const I=g.position();I&&(this.interpolatePosition&&((t=this._targetPosition)==null||t.set(I.x(),I.y(),I.z())),(!this.interpolatePosition||!this._receivedDataBefore)&&this.setWorldPosition(I.x(),I.y(),I.z()));const o=g.rotation();o&&(this.tempEuler.set(o.x(),o.y(),o.z()),this.interpolateRotation&&this._targetRotation.setFromEuler(this.tempEuler),(!this.interpolateRotation||!this._receivedDataBefore)&&Cv(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){Pn&&console.log("no model or room",this.name,this.guid,this.context.connection.isInRoom);return}this._shouldRequestOwnership&&(this._shouldRequestOwnership=!1,this._model.requestOwnership());let e=this.worldPosition,t=this.worldQuaternion;if(this._model.isOwned&&!this.receivedUpdate){const o=e.distanceTo(this.lastWorldPos),C=t.angleTo(this.lastWorldRotation),s=this._model.hasOwnership||this.fastMode?1e-4:.001;(o>s||C>s)&&(this._model.hasOwnership?this._needsUpdate=!0:(Pn&&console.log(this.guid,"reset because not owned but",this.gameObject.name,this.lastWorldPos),this.worldPosition=this.lastWorldPos,e.copy(this.lastWorldPos),this.worldQuaternion=this.lastWorldRotation,t.copy(this.lastWorldRotation),fI.markDirty(this.gameObject,!0),this._needsUpdate=!1))}if(this._model&&!this._model.hasOwnership&&this._model.isOwned&&this._receivedDataBefore){const C=this._receivedFastUpdate||this.fastMode?.5:.3;let s=!1;if(this.interpolatePosition&&this._targetPosition){const n=this.worldPosition;n.lerp(this._targetPosition,C),this.worldPosition=n,s=!0}if(this.interpolateRotation&&this._targetRotation){const n=this.worldQuaternion;n.slerp(this._targetRotation,C),this.worldQuaternion=n,s=!0}s&&fI.markDirty(this.gameObject,!0)}if(this.receivedUpdate=!1,this.lastWorldPos.copy(e),this.lastWorldRotation.copy(t),!this._model)return;if(!this._model||this._model.hasOwnership===void 0||!this._model.hasOwnership){this.rb&&(this.rb.isKinematic=this._model.isOwned??!1,this.rb.setVelocity(0,0,0));return}this.rb&&(this._wasKinematic!==void 0&&(Pn&&console.log("reset kinematic",this.rb.name,this._wasKinematic),this.rb.isKinematic=this._wasKinematic),this.gameObject.position.distanceTo(new S(0,0,0))>1e3&&(Pn&&console.log("RESET",this.name),this.gameObject.position.set(0,1,0),this.rb.setVelocity(0,0,0)));const g=10,I=this.rb||this.fastMode;if(this._needsUpdate&&(this.context.time.frameCount%g===0||I)){Pn&&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=OT(this.guid,this,!!I);this.context.connection.sendBinary(o)}}}var CC={};CC.d=(i,A)=>{for(var e in A)CC.o(A,e)&&!CC.o(i,e)&&Object.defineProperty(i,e,{enumerable:!0,get:A[e]})};CC.o=(i,A)=>Object.prototype.hasOwnProperty.call(i,A);CC.r=i=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(i,"__esModule",{value:!0})};var Ji={};CC.d(Ji,{w8:()=>ht,cg:()=>n2,gO:()=>ll,wb:()=>jm,zV:()=>Wr,HS:()=>Dd,Ec:()=>oB,gF:()=>iE,ol:()=>ul,pz:()=>gH,tx:()=>Do,hj:()=>zm,FV:()=>Sd,sV:()=>OH,xv:()=>dl,mx:()=>eH,gE:()=>tH,ZP:()=>gtA,Vx:()=>a2});var jm={};CC.r(jm);CC.d(jm,{get:()=>PT,set:()=>h7});var zm={};CC.r(zm);CC.d(zm,{alphaTestTransformer:()=>_w,asPreprocessorValueTransformer:()=>IH,toPreprocessorTriggerTransformer:()=>oR,toUserDataTransformer:()=>k$,uniformOrUserDataTransformer:()=>uo});const UG={fontFamily:null,fontSize:.05,fontKerning:"normal",fontStyle:"normal",fontWeight:"400",offset:.005,lineHeight:1.2,lineBreak:`- ,.:?!
|
|
4179
|
+
`}function uJ(i){return`(${i.r}, ${i.g}, ${i.b})`}function pJ(i){return`(${i.x}, ${i.y})`}const AF=class{constructor(A,e,t){r(this,"id");r(this,"trigger");r(this,"action");r(this,"exclusive",!1);this.id="Behavior_"+_m(A)+"_"+AF.global_id++,this.trigger=e,this.action=t}makeExclusive(A){return this.exclusive=A,this}writeTo(A,e,t){if(!this.trigger||!this.action)return;t.beginBlock(`def Preliminary_Behavior "${this.id}"`),t.appendLine(`rel actions = <${this.action.id}>`),t.appendLine(`uniform bool exclusive = ${this.exclusive}`);let g="";if(Array.isArray(this.trigger)){g="[";for(let I=0;I<this.trigger.length;I++){const o=this.trigger[I];g+="<"+o.id+">",I+1<this.trigger.length&&(g+=", ")}g+="]"}else g=`<${this.trigger.id}>`;if(t.appendLine(`rel triggers = ${g} `),t.appendLine(),Array.isArray(this.trigger))for(const I of this.trigger)I.writeTo(e,t),t.appendLine();else this.trigger.writeTo(e,t);t.appendLine(),this.action.writeTo(e,t),t.closeBlock()}};let dg=AF;r(dg,"global_id",0);function GG(i,A){var t,g;let e="";if(Array.isArray(i)){let I="[ ";for(let o=0;o<i.length;o++){let C=i[o];if(typeof C=="string")I+=C;else if(typeof C=="object"){C.isObject3D&&(C=A.findById(C.uuid));const s=(t=C.getPath)==null?void 0:t.call(C);I+=s}o+1<i.length&&(I+=", ")}I+=" ]",e=I}else typeof i=="object"&&(i.isObject3D&&(i=A.findById(i.uuid)),e=(g=i.getPath)==null?void 0:g.call(i));return e=e.replace(A.name,A.name+"/Scenes/Scene"),e}const eF=class{constructor(A,e){r(this,"id");r(this,"targetId");r(this,"tokenId");r(this,"type");r(this,"distance");A&&(this.targetId=A),e?this.id=e:this.id="Trigger_"+eF.global_id++}writeTo(A,e){e.beginBlock(`def Preliminary_Trigger "${this.id}"`),this.targetId&&(typeof this.targetId!="string"&&(this.targetId=GG(this.targetId,A)),e.appendLine("rel affectedObjects = "+this.targetId)),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.type&&e.appendLine(`token type = "${this.type}"`),typeof this.distance=="number"&&e.appendLine(`double distance = ${this.distance}`),e.closeBlock()}};let js=eF;r(js,"global_id",0);class SI{static sceneStartTrigger(){const A=new js;return A.targetId=void 0,A.tokenId="SceneTransition",A.type="enter",A}static tapTrigger(A){const e=new js(A);return e.tokenId="TapGesture",e}static isTapTrigger(A){return(A==null?void 0:A.tokenId)==="TapGesture"}static proximityToCameraTrigger(A,e){const t=new js(A);return t.tokenId="ProximityToCamera",t.distance=e,t}}class oa{constructor(A,e){r(this,"id");r(this,"actions");r(this,"loops",0);r(this,"performCount",1);r(this,"type","serial");this.id=A,this.actions=e}static getId(){return this.global_id++}addAction(A){return this.actions.push(A),this}makeParallel(){return this.type="parallel",this}makeSequence(){return this.type="serial",this}makeLooping(){return this.loops=1,this}makeRepeat(A){return this.performCount=A,this}writeTo(A,e){e.beginBlock(`def Preliminary_Action "${this.id}"`),e.beginArray("rel actions");for(const t of this.actions)t&&e.appendLine("<"+t.id+">,");e.closeArray(),e.appendLine(),e.appendLine('token info:id = "Group"'),e.appendLine(`bool loops = ${this.loops} `),e.appendLine(`int performCount = ${this.performCount} `),e.appendLine(`token type = "${this.type}"`),e.appendLine();for(const t of this.actions)t&&(t.writeTo(A,e),e.appendLine());e.closeBlock()}}r(oa,"global_id",0);var Om=(i=>(i[i.pop=0]="pop",i[i.blink=1]="blink",i[i.bounce=2]="bounce",i[i.flip=3]="flip",i[i.float=4]="float",i[i.jiggle=5]="jiggle",i[i.pulse=6]="pulse",i[i.spin=7]="spin",i))(Om||{}),MG=(i=>(i.Relative="relative",i.Absolute="absolute",i))(MG||{});const Ff=class{constructor(A,e){r(this,"id");r(this,"tokenId");r(this,"affectedObjects");r(this,"easeType");r(this,"motionType");r(this,"duration");r(this,"moveDistance");r(this,"style");r(this,"type");r(this,"front");r(this,"up");r(this,"start");r(this,"animationSpeed");r(this,"reversed");r(this,"pingPong");r(this,"xFormTarget");r(this,"audio");r(this,"gain");r(this,"auralMode");r(this,"multiplePerformOperation");A&&(this.affectedObjects=A),e?this.id=e:this.id="Action",this.id+="_"+Ff.global_id++}clone(){const A=new Ff,e=A.id;return Object.assign(A,this),A.id=e,A}writeTo(A,e){e.beginBlock(`def Preliminary_Action "${this.id}"`),this.affectedObjects&&(typeof this.affectedObjects!="string"&&(this.affectedObjects=GG(this.affectedObjects,A)),e.appendLine("rel affectedObjects = "+this.affectedObjects)),typeof this.duration=="number"&&e.appendLine(`double duration = ${this.duration} `),this.easeType&&e.appendLine(`token easeType = "${this.easeType}"`),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.motionType&&e.appendLine(`token motionType = "${this.motionType}"`),typeof this.moveDistance=="number"&&e.appendLine(`double moveDistance = ${this.moveDistance} `),this.style&&e.appendLine(`token style = "${this.style}"`),this.type&&e.appendLine(`token type = "${this.type}"`),this.front&&e.appendLine(`vector3d front = (${this.front.x}, ${this.front.y}, ${this.front.z})`),this.up&&e.appendLine(`vector3d upVector = (${this.up.x}, ${this.up.y}, ${this.up.z})`),typeof this.start=="number"&&e.appendLine(`double start = ${this.start} `),typeof this.animationSpeed=="number"&&e.appendLine(`double animationSpeed = ${this.animationSpeed} `),typeof this.reversed=="boolean"&&e.appendLine(`bool reversed = ${this.reversed}`),typeof this.pingPong=="boolean"&&e.appendLine(`bool reverses = ${this.pingPong}`),this.xFormTarget&&(typeof this.xFormTarget!="string"&&(this.xFormTarget=GG(this.xFormTarget,A)),e.appendLine(`rel xformTarget = ${this.xFormTarget}`)),typeof this.audio=="string"&&e.appendLine(`asset audio = @${this.audio}@`),typeof this.gain=="number"&&e.appendLine(`double gain = ${this.gain}`),typeof this.auralMode=="string"&&e.appendLine(`token auralMode = "${this.auralMode}"`),typeof this.multiplePerformOperation=="string"&&e.appendLine(`token multiplePerformOperation = "${this.multiplePerformOperation}"`),e.closeBlock()}};let TI=Ff;r(TI,"global_id",0);let uQ=class sQ{constructor(A,e,t){r(this,"x",0);r(this,"y",0);r(this,"z",0);this.x=A,this.y=e,this.z=t}static get up(){return new sQ(0,1,0)}static get right(){return new sQ(1,0,0)}static get forward(){return new sQ(0,0,1)}static get back(){return new sQ(0,0,-1)}static get zero(){return new sQ(0,0,0)}};var LT=(i=>(i.Play="play",i.Pause="pause",i.Stop="stop",i))(LT||{}),mG=(i=>(i.Spatial="spatial",i.NonSpatial="nonSpatial",i.Ambient="ambient",i))(mG||{});class rt{static sequence(...A){return new oa("group_"+oa.getId(),A).makeSequence()}static parallel(...A){return new oa("group_"+oa.getId(),A).makeParallel()}static fadeAction(A,e,t){const g=new TI(A);return g.tokenId="Visibility",g.type=t?"show":"hide",g.duration=e,g.style="basic",g.motionType="none",g.moveDistance=0,g.easeType="none",g}static startAnimationAction(A,e,t=0,g=1,I=!1,o=!1){const C=new TI(A);if(C.tokenId="StartAnimation",C.start=e,C.duration=t,C.animationSpeed=g,C.reversed=I,C.pingPong=o,I&&(C.start-=t),o){C.pingPong=!1;const s=C.clone();return s.reversed=!I,s.start=C.start,s.reversed&&(s.start-=t),rt.sequence(C,s)}return C}static waitAction(A){const e=new TI;return e.tokenId="Wait",e.duration=A,e}static lookAtCameraAction(A,e=9999999999999,t,g){const I=new TI(A);return I.tokenId="LookAtCamera",I.duration=e,I.front=t??uQ.forward,I.up=g??uQ.up,I}static emphasize(A,e,t=2,g=1,I="basic"){const o=new TI(A);return o.tokenId="Emphasize",o.duration=e,o.style=I??"basic",o.motionType=Om[t],o.moveDistance=g,o}static transformAction(A,e,t,g,I="inout"){const o=new TI(A);return o.tokenId="Transform",o.duration=t,o.type=g,o.easeType=I,Array.isArray(e)&&console.error("Transform target must not be an array",e),o.xFormTarget=e,o}static playAudioAction(A,e,t="play",g=1,I="spatial"){const o=new TI(A);return o.tokenId="Audio",o.type=t,o.audio=e,o.gain=g,o.auralMode=I,o.multiplePerformOperation="allow",o}}class Q6{constructor(A){r(this,"object");r(this,"model");this.object=A}get id(){return this.object.uuid}apply(A){if(!this.model&&(this.model=A.findById(this.object.uuid),!this.model)){console.error("could not find model with id "+this.object.uuid);return}this.onApply(A)}}class Pm extends Q6{constructor(e,t,g,I){super(e);r(this,"matrix");r(this,"material");r(this,"geometry");r(this,"_enableAction");r(this,"_disableAction");this.matrix=t,this.material=g,this.geometry=I}onApply(e){var I,o;const t=this.model;if(!t)return;(I=t.parent)!=null&&I.isDynamic||Go.createEmptyParent(t);const g=t.clone();this.matrix&&(g.matrix=this.matrix),this.material&&(g.material=this.material),this.geometry&&(g.geometry=this.geometry),(o=t.parent)==null||o.add(g)}enable(){return this._enableAction?this._enableAction:(this._enableAction=rt.fadeAction(this.object,0,!0),this._enableAction)}disable(){return this._disableAction?this._disableAction:(this._disableAction=rt.fadeAction(this.object,0,!1),this._disableAction)}}class Wm{constructor(A){r(this,"actions");r(this,"sortedActions");this.actions=[...A]}organize(){this.sortedActions={};for(const A of this.actions){const e=A.id;this.sortedActions[e]||(this.sortedActions[e]=[]),this.sortedActions[e].push(A)}}getActions(A){return this.sortedActions||this.organize(),this.sortedActions[A.uuid]}}var E6=Object.defineProperty,c6=Object.getOwnPropertyDescriptor,vT=(i,A,e,t)=>{for(var g=t>1?void 0:t?c6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&E6(A,e,g),g};class dd extends MA{constructor(){super(...arguments);r(this,"from");r(this,"to");r(this,"width",0);r(this,"centered",!0);r(this,"_centerPos")}awake(){this._centerPos=new S}update(){if(!this.from||!this.to)return;const e=ye(this.from).clone(),t=ye(this.to).clone(),g=e.distanceTo(t);this._centerPos.copy(e),this._centerPos.add(t),this._centerPos.multiplyScalar(.5),di(this.gameObject,this.centered?this._centerPos:e),this.gameObject.lookAt(ye(this.to).clone()),this.gameObject.scale.set(this.width,this.width,g)}}vT([w(AA)],dd.prototype,"from",2);vT([w(AA)],dd.prototype,"to",2);var h6=Object.defineProperty,l6=Object.getOwnPropertyDescriptor,ud=(i,A,e,t)=>{for(var g=t>1?void 0:t?l6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&h6(A,e,g),g};const On=nA("debuganimation");class Lo extends MA{constructor(){super(...arguments);r(this,"playAutomatically",!0);r(this,"randomStartTime",!0);r(this,"minMaxSpeed");r(this,"minMaxOffsetNormalized");r(this,"loop",!0);r(this,"clampWhenFinished",!1);r(this,"_tempAnimationClipBeforeGameObjectExisted",null);r(this,"mixer");r(this,"_actions",[]);r(this,"_currentActions",[]);r(this,"_handles",[]);r(this,"_didInit",!1)}get clip(){var e;return(e=this.animations)!=null&&e.length?this.animations[0]:null}set clip(e){if(!this.__didAwake){On&&console.log("Assign clip during serialization",e),this._tempAnimationClipBeforeGameObjectExisted=e;return}e&&(On&&console.log("Assign clip",e,!!this.gameObject),this.gameObject.animations||(this.gameObject.animations=[]),!this.animations.includes(e)&&(this.animations.length>0?this.animations.splice(0,0,e):this.animations.push(e)))}set clips(e){this.animations=e}set animations(e){On&&console.log("assign animations",e),this.gameObject.animations=e}get animations(){return this.gameObject.animations}get currentAction(){return this._currentActions[0]}get currentActions(){return this._currentActions}get actions(){return this._actions}set actions(e){this._actions=e}awake(){On&&console.log(this),this._tempAnimationClipBeforeGameObjectExisted&&(this.clip=this._tempAnimationClipBeforeGameObjectExisted,this._tempAnimationClipBeforeGameObjectExisted=null),this.playAutomatically&&this.init()}onEnable(){var e;if(this.playAutomatically&&((e=this.animations)==null?void 0:e.length)>0&&this.currentActions.length<=0){const t=Math.floor(Math.random()*this.actions.length);this.play(t)}}start(){this.randomStartTime&&this.currentAction&&(this.currentAction.time=Math.random()*this.currentAction.getClip().duration)}update(){this.mixer&&this.mixer.update(this.context.time.deltaTime)}getAction(e){var t;return(t=this.actions)==null?void 0:t.find(g=>g.getClip().name===e)}get isPlaying(){for(let e=0;e<this._currentActions.length;e++)if(this._currentActions[e].isRunning())return!0;return!1}play(e=0,t){if(On&&console.log("PLAY",e),this.init(),!this.mixer){On&&console.warn("Missing mixer",this);return}e===void 0&&(e=0);let g=e;if(typeof e=="number"){if(e>=this.animations.length){On&&console.log("No animation at index",e);return}g=this.animations[e]}else typeof e=="string"&&(g=this.animations.find(o=>o.name===e));if(!g){console.error("Could not find clip",e);return}t||(t={}),t.minMaxOffsetNormalized||(t.minMaxOffsetNormalized=this.minMaxOffsetNormalized),t.minMaxSpeed||(t.minMaxSpeed=this.minMaxSpeed),t.loop===void 0&&(t.loop=this.loop),t.clampWhenFinished===void 0&&(t.clampWhenFinished=this.clampWhenFinished);for(const o of this.actions)if(o.getClip()===g)return this.internalOnPlay(o,t);if(!(g instanceof Jo)){console.warn("Clip is no AnimationClip",g,"on object: "+this.name);return}const I=this.mixer.clipAction(g);return this.actions.push(I),this.internalOnPlay(I,t)}internalOnPlay(e,t){var g=this.currentAction;if(g===e&&g.isRunning()&&g.time<g.getClip().duration){const s=this.tryFindHandle(e);if(s)return s.getPromise()}const I=(t==null?void 0:t.exclusive)??!0;t!=null&&t.fadeDuration?(I&&(g==null||g.fadeOut(t.fadeDuration)),e.fadeIn(t.fadeDuration)):I&&(g==null||g.stop()),e.reset(),e.enabled=!0,e.time=0,e.timeScale=1;const o=e.getClip();t!=null&&t.minMaxOffsetNormalized&&(e.time=ee.lerp(t.minMaxOffsetNormalized.x,t.minMaxOffsetNormalized.y,Math.random())*o.duration),t!=null&&t.minMaxSpeed&&(e.timeScale=ee.lerp(t.minMaxSpeed.x,t.minMaxSpeed.y,Math.random())),t!=null&&t.clampWhenFinished&&(e.clampWhenFinished=!0),(t==null?void 0:t.startTime)!==void 0&&(e.time=t.startTime),(t==null?void 0:t.loop)!==void 0?e.loop=t.loop?BM:Ph:e.loop=Ph,e.play(),On&&console.log("PLAY",e.getClip().name,e);const C=new d6(e,this.mixer,t,s=>{this._handles.splice(this._handles.indexOf(C),1)});return this._handles.push(C),C.getPromise()}tryFindHandle(e){for(const t of this._handles)if(t.action===e)return t}init(){this._didInit||(this._didInit=!0,this.gameObject&&(this.actions=[],this.mixer=new nw(this.gameObject)))}}ud([w()],Lo.prototype,"playAutomatically",2);ud([w()],Lo.prototype,"randomStartTime",2);ud([w()],Lo.prototype,"loop",2);ud([w()],Lo.prototype,"clampWhenFinished",2);ud([w(Jo)],Lo.prototype,"clips",1);class d6{constructor(A,e,t,g){r(this,"mixer");r(this,"action");r(this,"promise",null);r(this,"resolve",null);r(this,"reject",null);r(this,"_options");r(this,"_resolveCallback",null);r(this,"_rejectCallback",null);r(this,"_loopCallback");r(this,"_finishedCallback");r(this,"_resolvedOrRejectedCallback");this.action=A,this.mixer=e,this._resolvedOrRejectedCallback=g,this._options=t}getPromise(){return this.promise?this.promise:(this.promise=new Promise((A,e)=>{this._resolveCallback=A,this._rejectCallback=e,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 A,e;this.dispose(),(A=this._resolvedOrRejectedCallback)==null||A.call(this,this),(e=this._resolveCallback)==null||e.call(this,this.action)}onReject(A){var e,t;this.dispose(),(e=this._resolvedOrRejectedCallback)==null||e.call(this,this),(t=this._rejectCallback)==null||t.call(this,A)}onLoop(A){}onFinished(A){A.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 u6=Object.defineProperty,p6=Object.getOwnPropertyDescriptor,Ja=(i,A,e,t)=>{for(var g=t>1?void 0:t?p6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&u6(A,e,g),g};class qa{constructor(){r(this,"time");r(this,"value");r(this,"inTangent");r(this,"inWeight");r(this,"outTangent");r(this,"outWeight");r(this,"weightedMode")}}Ja([w()],qa.prototype,"time",2);Ja([w()],qa.prototype,"value",2);Ja([w()],qa.prototype,"inTangent",2);Ja([w()],qa.prototype,"inWeight",2);Ja([w()],qa.prototype,"outTangent",2);Ja([w()],qa.prototype,"outWeight",2);Ja([w()],qa.prototype,"weightedMode",2);const xT=class{constructor(){r(this,"keys")}get duration(){return!this.keys||this.keys.length==0?0:this.keys[this.keys.length-1].time}evaluate(i){if(!this.keys||this.keys.length==0)return 0;if(this.keys[0].time>=i)return this.keys[0].value;for(let A=0;A<this.keys.length;A++){const e=this.keys[A];if(e.time<=i)if(A+1<this.keys.length){const g=this.keys[A+1];if(g.time<i)continue;return!isFinite(e.outTangent)||!isFinite(g.inTangent)?e.value:xT.interpolateValue(i,e,g)}else return e.value}return this.keys[this.keys.length-1].value}static interpolateValue(i,A,e){const t=A.time,g=A.value,I=A.outTangent,o=e.time,C=e.value,s=e.inTangent,n=o-t,a=n*n,B=a*n,Q=((I+s)*n-2*(C-g))/B,E=(3*(C-g)-(s+2*I)*n)/a,c=I,h=g,l=i-t,d=l*l,p=d*l;return Q*p+E*d+c*l+h}};let IB=xT;Ja([w(qa)],IB.prototype,"keys",2);const pQ=nA("debugusdzanimation");class qw{constructor(A,e,t){r(this,"ext");r(this,"root");r(this,"clip");this.ext=A,this.root=e,this.clip=t}get start(){return this.ext.getStartTime01(this.root,this.clip)}get duration(){return this.clip.duration}}class bw{constructor(A,e,t,g){r(this,"clip");r(this,"pos");r(this,"rot");r(this,"scale");r(this,"ext");r(this,"root");r(this,"target");this.ext=A,this.root=e,this.target=t,this.clip=g}get frameRate(){return 60}addTrack(A){A.name.endsWith("position")&&(this.pos=A),A.name.endsWith("quaternion")&&(this.rot=A),A.name.endsWith("scale")&&(this.scale=A)}getFrames(){var A,e,t,g,I,o;return Math.max(((e=(A=this.pos)==null?void 0:A.times)==null?void 0:e.length)??0,((g=(t=this.rot)==null?void 0:t.times)==null?void 0:g.length)??0,((o=(I=this.scale)==null?void 0:I.times)==null?void 0:o.length)??0)}getDuration(){var e,t,g;const A=((e=this.pos)==null?void 0:e.times)??((t=this.rot)==null?void 0:t.times)??((g=this.scale)==null?void 0:g.times);return A?A[A.length-1]:0}getStartTime(A){let e=0;for(let t=0;t<A.length;t++){const g=A[t];if(g===this)return e;e+=g.getDuration()}return e}}class Lw{constructor(){r(this,"dict",new Map);r(this,"rootTargetMap",new Map);r(this,"serializers",[])}get extensionName(){return"animation"}getStartTime01(A,e){const t=this.rootTargetMap.get(A);if(!t)return 1/0;let g=-1;for(const I of t){const o=this.dict.get(I);let C=0;if(o!=null&&o.length){for(const s of o){if(s.clip===e)break;C+=s.getDuration()}g=Math.max(g,C)}else console.warn("No animation found on root",A,e,o)}return g}registerAnimation(A,e){if(!e||!A)return null;this.rootTargetMap.has(A)||this.rootTargetMap.set(A,[]);for(const g of e.tracks){const I=g.name.split(".")[2],o=A.getObjectByName(I);if(!o){console.warn("no object found for track",g.name,"using "+A.name+" instead");continue}this.dict.has(o)||this.dict.set(o,[]);const C=this.dict.get(o);if(!C)continue;let s=C.find(a=>a.clip===e);s||(s=new bw(this,A,o,e),C.push(s)),s.addTrack(g);const n=this.rootTargetMap.get(A);n!=null&&n.includes(o)||n==null||n.push(o)}return new qw(this,A,e)}onAfterHierarchy(A){pQ&&console.log(this.dict)}onAfterBuildDocument(A){var e,t;for(const g of this.serializers){const I=(e=g.model)==null?void 0:e.parent,o=(I==null?void 0:I.isDynamic)===!0;pQ&&console.log(o,(t=g.model)==null?void 0:t.parent),o&&g.registerCallback(I)}}onExportObject(A,e,t){AA.foreachComponent(A,I=>{const o=I;typeof o.createAnimation=="function"&&o.createAnimation(this,e,t)},!1);const g=new D6(A,this.dict);this.serializers.push(g),g.registerCallback(e)}}class D6{constructor(A,e){r(this,"object");r(this,"dict");r(this,"model");r(this,"callback");this.object=A,this.dict=e}registerCallback(A){this.model&&this.callback&&this.model.removeEventListener("serialize",this.callback),this.callback||(this.callback=this.onSerialize.bind(this)),pQ&&console.log("REPARENT",A),this.model=A,this.model.addEventListener("serialize",this.callback)}onSerialize(A,e){var n,a,B,Q,E,c;if(!this.model)return;pQ&&console.log("SERIALIZE",this.model.name,this.object.type);const t=this.object,g=this.dict.get(t);if(!g)return;const I=new NA,o=new S,C=new kA,s=new S(1,1,1);A.appendLine("matrix4d xformOp:transform.timeSamples = {"),A.indent++;for(const h of g){let l=(n=h.pos)==null?void 0:n.times,d=(a=h.rot)==null?void 0:a.times,p=(B=h.scale)==null?void 0:B.times,u=[];if(l)for(const f of l)u.push(f);if(d)for(const f of d)u.push(f);if(p)for(const f of p)u.push(f);if(u.sort((f,M)=>f-M),u=[...new Set(u)],!u||u.length===0){console.error("got an animated object but no time values??",t,h);continue}const D=h.getStartTime(g);pQ&&A.appendLine(h.clip.name+": start="+D.toFixed(3)+", length="+h.getDuration().toFixed(3)+", frames="+h.getFrames());const y=(Q=h.pos)==null?void 0:Q.createInterpolant(),k=(E=h.rot)==null?void 0:E.createInterpolant(),R=(c=h.scale)==null?void 0:c.createInterpolant();y||o.set(t.position.x,t.position.y,t.position.z),k||C.set(t.quaternion.x,t.quaternion.y,t.quaternion.z,t.quaternion.w),R||s.set(t.scale.x,t.scale.y,t.scale.z);for(let f=0;f<u.length;f++){const M=u[f];if(y){const J=y.evaluate(M);o.set(J[0],J[1],J[2])}if(k){const J=k.evaluate(M);C.set(J[0],J[1],J[2],J[3])}if(R){const J=R.evaluate(M);s.set(J[0],J[1],J[2])}I.compose(o,C,s);let U=`${(D+M)*h.frameRate}: ${bT(I)},`;pQ&&(U="#"+f+" "+U),A.appendLine(U)}}A.indent--,A.appendLine("}")}}class f6{constructor(){r(this,"_context")}get context(){return this._context??qe.Current}get isStateMachineBehaviour(){return!0}}class oD{constructor(A,e,t,g){r(this,"_name");r(this,"_nameHash");r(this,"_normalizedTime");r(this,"_length");r(this,"_speed");this._name=A.name,this._nameHash=A.hash,this._normalizedTime=e,this._length=t,this._speed=g}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 YT(i,A){return{name:"",isLooping:!1,guid:(A==null?void 0:A.generateUUID())??AI.generateUUID(),index:-1,clip:new Jo(i,1,[])}}var Xn=(i=>(i[i.If=1]="If",i[i.IfNot=2]="IfNot",i[i.Greater=3]="Greater",i[i.Less=4]="Less",i[i.Equals=6]="Equals",i[i.NotEqual=7]="NotEqual",i))(Xn||{}),Vm=(i=>(i[i.Float=1]="Float",i[i.Int=3]="Int",i[i.Bool=4]="Bool",i[i.Trigger=9]="Trigger",i))(Vm||{});const DC=nA("debuganimatorcontroller"),Ip=nA("debugrootmotion");class Pr{constructor(A){r(this,"normalizedStartOffset",0);r(this,"_speed",1);r(this,"animator");r(this,"model");r(this,"_mixer");r(this,"_activeState");r(this,"_activeStates",[]);r(this,"rootMotionHandler");this.model=A,DC&&console.log(this)}play(A,e=-1,t=Number.NEGATIVE_INFINITY,g=0){if(e<0)e=0;else if(e>=this.model.layers.length){console.warn("invalid layer");return}const o=this.model.layers[e].stateMachine;for(const C of o.states)if(C.name===A||C.hash===A){DC&&console.log("transition to ",C),this.transitionTo(C,g,t);return}console.warn("Could not find "+A+" to play")}reset(){this.setStartTransition()}setBool(A,e){var g,I;const t=typeof A=="string"?"name":"hash";return(I=(g=this.model)==null?void 0:g.parameters)==null?void 0:I.filter(o=>o[t]===A).forEach(o=>o.value=e)}getBool(A){var t,g,I;const e=typeof A=="string"?"name":"hash";return((I=(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.find(o=>o[e]===A))==null?void 0:I.value)??!1}setFloat(A,e){var g,I;const t=typeof A=="string"?"name":"hash";return(I=(g=this.model)==null?void 0:g.parameters)==null?void 0:I.filter(o=>o[t]===A).forEach(o=>o.value=e)}getFloat(A){var t,g,I;const e=typeof A=="string"?"name":"hash";return((I=(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.find(o=>o[e]===A))==null?void 0:I.value)??0}setInteger(A,e){var g,I;const t=typeof A=="string"?"name":"hash";return(I=(g=this.model)==null?void 0:g.parameters)==null?void 0:I.filter(o=>o[t]===A).forEach(o=>o.value=e)}getInteger(A){var t,g,I;const e=typeof A=="string"?"name":"hash";return((I=(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.find(o=>o[e]===A))==null?void 0:I.value)??0}setTrigger(A){var t,g;DC&&console.log("SET TRIGGER",A);const e=typeof A=="string"?"name":"hash";return(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.filter(I=>I[e]===A).forEach(I=>I.value=!0)}resetTrigger(A){var t,g;const e=typeof A=="string"?"name":"hash";return(g=(t=this.model)==null?void 0:t.parameters)==null?void 0:g.filter(I=>I[e]===A).forEach(I=>I.value=!1)}isInTransition(){return this._activeStates.length>1}setSpeed(A){this._speed=A}FindState(A){return this.findState(A)}findState(A){if(!A)return null;if(Array.isArray(this.model.layers)){for(const e of this.model.layers)for(const t of e.stateMachine.states)if(t.name===A)return t}return null}get context(){var A;return(A=this.animator)==null?void 0:A.context}bind(A){this.animator=A,this._mixer=new nw(this.animator.gameObject),this.createActions(this.animator)}clone(){if(typeof this.model=="string")return console.warn("AnimatorController has not been resolved, can not create model from string",this.model),null;const A=qf(this.model,(t,g,I)=>I==null?!0:!(I.type==="Object3D"||I.isObject3D===!0||nv(I)||I.tracks!==void 0));return console.assert(A!==this.model),new Pr(A)}update(){var e,t;if(!this.animator||(this.evaluateTransitions(),this.updateActiveStates(),!this._activeState))return;const A=this.animator.context.time.deltaTime;this.animator.applyRootMotion&&((e=this.rootMotionHandler)==null||e.onBeforeUpdate()),this._mixer.update(A),this.animator.applyRootMotion&&((t=this.rootMotionHandler)==null||t.onAfterUpdate())}updateActiveStates(){for(let A=0;A<this._activeStates.length;A++){const e=this._activeStates[A],t=e.motion;if(!t.action)this._activeStates.splice(A,1),A--;else{const g=t.action;g.getEffectiveWeight()<=0&&!g.isRunning()&&(DC&&console.debug("REMOVE",e.name,g.getEffectiveWeight(),g.isRunning(),g.isScheduled()),this._activeStates.splice(A,1),A--)}}}setStartTransition(){for(const A of this.model.layers){const e=A.stateMachine;e.defaultState===void 0&&(DC&&console.warn("AnimatorController default state is undefined, will assign state 0 as default",A),e.defaultState=0);const t=e.states[e.defaultState];this.transitionTo(t,0,this.normalizedStartOffset)}}evaluateTransitions(){var I;let A=!1;if(!this._activeState){if(this.setStartTransition(),!this._activeState)return;A=!0}const e=this._activeState,t=e.motion.action;for(const o of e.transitions){if(!o.hasExitTime&&o.conditions.length<=0)continue;let C=!0;for(const s of o.conditions)if(!this.evaluateCondition(s)){C=!1;break}if(C){for(const s of o.conditions){const n=this.model.parameters.find(a=>a.name===s.parameter);(n==null?void 0:n.type)===Vm.Trigger&&(n.value=!1)}if(t){const s=e.motion.clip.duration,n=s<=0?1:Math.abs(t.time/s);let a=!1;if(o.hasExitTime?t.timeScale>0?a=n>=o.exitTime:t.timeScale<0&&(a=1-n>=o.exitTime):a=!0,a){t.clampWhenFinished=!0,DC&&console.log("transition to "+o.destinationState,o,n,o.exitTime,o.hasExitTime),this.transitionTo(o.destinationState,o.duration,o.offset);return}}else{this.transitionTo(o.destinationState,o.duration,o.offset);return}}}let g=!1;if(e.motion.isLooping&&t&&(t.time>=t.getClip().duration?(g=!0,t.reset(),t.time=0,t.play()):t.time<=0&&t.timeScale<0&&(g=!0,t.reset(),t.time=t.getClip().duration,t.play())),!g&&e&&!A&&t&&this.animator&&e.behaviours){const o=t==null?void 0:t.getClip().duration,C=t.time/o,s=new oD(this._activeState,C,o,this._speed);for(const n of e.behaviours)n.instance&&((I=n.instance.onStateUpdate)==null||I.call(n.instance,this.animator,s,0))}}getState(A,e){return typeof A=="number"&&(A==-1&&(A=this.model.layers[e].stateMachine.defaultState,A===void 0&&(DC&&console.warn("AnimatorController default state is undefined: ",this.model,"Layer: "+e),A=0)),A=this.model.layers[e].stateMachine.states[A]),A}transitionTo(A,e,t){var n,a,B,Q,E,c,h,l;if(!this.animator)return;const g=0;if(A=this.getState(A,g),!(A!=null&&A.motion)||!A.motion.clip)return;const I=this._activeState===A;if(I){const d=A.motion;!d.action_loopback&&d.clip&&(this._mixer.uncacheAction(d.clip,this.animator.gameObject),d.action_loopback=this.createAction(d.clip))}if((n=this._activeState)!=null&&n.behaviours&&this._activeState.motion.action){const d=(a=this._activeState)==null?void 0:a.motion.clip.duration,p=this._activeState.motion.action.time/d,u=new oD(this._activeState,p,d,this._speed);for(const D of this._activeState.behaviours)(Q=(B=D.instance)==null?void 0:B.onStateExit)==null||Q.call(D.instance,this.animator,u,g)}const o=(E=this._activeState)==null?void 0:E.motion.action;o&&o.fadeOut(e),I&&(A.motion.action=A.motion.action_loopback,A.motion.action_loopback=o);const C=this._activeState;this._activeState=A;const s=(c=A.motion)==null?void 0:c.action;if(s){t=Math.max(0,Math.min(1,t)),s.isRunning()&&s.stop(),s.reset(),s.timeScale=this._speed,A.speed!==void 0&&(s.timeScale*=A.speed),s.enabled=!0;const d=A.motion.clip.duration;if(s.time=t*d,s.timeScale<0&&(s.time=d-s.time),s.clampWhenFinished=!0,s.setLoop(Ph,0),e>0?s.fadeIn(e):s.setEffectiveWeight(1),s.play(),this.rootMotionHandler&&this.rootMotionHandler.onStart(s),this._activeStates.includes(A)||this._activeStates.push(A),this._activeState.behaviours){const p=new oD(A,t,d,this._speed);for(const u of this._activeState.behaviours)(l=(h=u.instance)==null?void 0:h.onStateEnter)==null||l.call(u.instance,this.animator,p,g)}}else DC&&(A.__warned_no_motion||(A.__warned_no_motion=!0,console.warn("No action",A.motion,this)));DC&&console.log("TRANSITION FROM "+(C==null?void 0:C.name)+" TO "+A.name,e,o,s,s==null?void 0:s.getEffectiveTimeScale(),s==null?void 0:s.getEffectiveWeight(),s==null?void 0:s.isRunning(),s==null?void 0:s.isScheduled(),s==null?void 0:s.paused)}createAction(A){var t,g;if(this._mixer.existingAction(A)&&this._mixer.uncacheAction(A,(t=this.animator)==null?void 0:t.gameObject),(g=this.animator)!=null&&g.applyRootMotion){this.rootMotionHandler||(this.rootMotionHandler=new w6(this));const I=this.animator.gameObject;return this.rootMotionHandler.createClip(this._mixer,I,A)}else return this._mixer.clipAction(A)}evaluateCondition(A){const e=this.model.parameters.find(t=>t.name===A.parameter);if(!e)return!1;switch(A.mode){case Xn.If:return e.value===!0;case Xn.IfNot:return e.value===!1;case Xn.Greater:return e.value>A.threshold;case Xn.Less:return e.value<A.threshold;case Xn.Equals:return e.value===A.threshold;case Xn.NotEqual:return e.value!==A.threshold}return!1}createActions(A){var e,t;for(const g of this.model.layers){const I=g.stateMachine;for(let o=0;o<I.states.length;o++){const C=I.states[o];C.transitions||(C.transitions=[]);for(const s of C.transitions)s.conditions||(s.conditions=[]);if(C.motion||(C.motion=YT(C.name)),this.animator&&C.motion.clips){const s=(e=C.motion.clips)==null?void 0:e.find(n=>{var a,B;return n.node.name===((B=(a=this.animator)==null?void 0:a.gameObject)==null?void 0:B.name)});C.motion.clip=s==null?void 0:s.clip}if(!C.motion.clip){const s=new Jo(void 0,void 0,[]);C.motion.clip=s}if((t=C.motion)!=null&&t.clip){const s=C.motion.clip,n=this.createAction(s);C.motion.action=n}if(C.behaviours&&Array.isArray(C.behaviours))for(const s of C.behaviours){if(!(s!=null&&s.typeName))continue;const n=T.get(s.typeName),a=new n;a.isStateMachineBehaviour&&(a._context=this.context??void 0,_r(a,s.properties),s.instance=a),DC&&console.log("Created animator controller behaviour",C.name,s.typeName,s.properties,a)}}}}*enumerateActions(){for(const A of this.model.layers){const e=A.stateMachine;for(let t=0;t<e.states.length;t++){const g=e.states[t];g!=null&&g.motion&&(g.motion.action&&(yield g.motion.action),g.motion.action_loopback&&(yield g.motion.action_loopback))}}}}class DJ{constructor(A,e){r(this,"track");r(this,"createdInterpolant");r(this,"originalEvaluate");r(this,"customEvaluate");this.track=A;const t=A,g=t.createInterpolant.bind(A);t.createInterpolant=()=>(t.createInterpolant=g,this.createdInterpolant=g(),this.originalEvaluate=this.createdInterpolant.evaluate.bind(this.createdInterpolant),this.customEvaluate=I=>{if(!this.originalEvaluate)return;const o=this.originalEvaluate(I);return e(I,o)},this.createdInterpolant.evaluate=this.customEvaluate,this.createdInterpolant)}evaluate(A){this.customEvaluate&&this.customEvaluate(A)}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 Si=class{constructor(A,e,t,g,I){r(this,"_action");r(this,"root");r(this,"clip");r(this,"positionWrapper",null);r(this,"rotationWrapper",null);r(this,"context");r(this,"positionChange",new S);r(this,"rotationChange",new kA);if(this.context=A,this.root=e,this.clip=t,Si.firstKeyframeRotation[t.uuid]||(Si.firstKeyframeRotation[t.uuid]=new kA),I){const o=I.values;Si.firstKeyframeRotation[t.uuid].set(o[0],o[1],o[2],o[3])}Si.spaceRotation[t.uuid]||(Si.spaceRotation[t.uuid]=new kA),Si.effectiveSpaceRotation[t.uuid]||(Si.effectiveSpaceRotation[t.uuid]=new kA),Si.clipOffsetRotation[t.uuid]=new kA,I&&Si.clipOffsetRotation[t.uuid].set(I.values[0],I.values[1],I.values[2],I.values[3]).invert(),this.handlePosition(t,g),this.handleRotation(t,I)}set action(A){this._action=A}get action(){return this._action}onStart(A){if(A.getClip()!==this.clip)return;const e=Si.lastObjRotation[this.root.uuid];if(Si.spaceRotation[this.clip.uuid].copy(e),Ip){const t=new Fi().setFromQuaternion(e);console.log("START",this.clip.name,ee.toDegrees(t.y))}}getClipRotationOffset(){return Si.clipOffsetRotation[this.clip.uuid]}handlePosition(A,e){if(e){const t=this.root;Ip&&t.add(new pE),Si.lastObjPosition[t.uuid]||(Si.lastObjPosition[t.uuid]=new S);const g=new S,I=new S;let o=0;this.positionWrapper=new DJ(e,(C,s)=>{const n=this.action.getEffectiveWeight();if(Ip&&t.position.length()>8&&t.position.set(0,t.position.y,0),C>o){g.set(s[0],s[1],s[2]),g.sub(I),g.multiplyScalar(n),g.applyQuaternion(this.getClipRotationOffset());const a=this.clip.uuid;g.applyQuaternion(Si.spaceRotation[a]),this.positionChange.copy(g)}return I.fromArray(s),o=C,s[0]=0,s[1]=0,s[2]=0,s})}}handleRotation(A,e){if(e){if(Ip){const C=e.values,s=new Fi().setFromQuaternion(new kA(C[0],C[1],C[2],C[3]));console.log(A.name,e.name,"FIRST ROTATION IN TRACK",ee.toDegrees(s.y));const n=e.values.length-4,a=new kA().set(C[n],C[n+1],C[n+2],C[n+3]),B=new Fi().setFromQuaternion(a);console.log(A.name,e.name,"LAST ROTATION IN TRACK",ee.toDegrees(B.y))}const t=this.root;Si.lastObjRotation[t.uuid]||(Si.lastObjRotation[t.uuid]=new kA);let g=0;const I=new kA,o=new kA;this.rotationWrapper=new DJ(e,(C,s)=>(C>g&&(o.set(s[0],s[1],s[2],s[3]),I.invert(),o.multiply(I),this.rotationChange.copy(o)),I.fromArray(s),g=C,s[0]=0,s[1]=0,s[2]=0,s[3]=1,s))}}onBeforeUpdate(){this.positionChange.set(0,0,0),this.rotationChange.set(0,0,0,1)}onAfterUpdate(){if(!this.action)return;const A=this.action.getEffectiveWeight();this.positionChange.multiplyScalar(A),this.rotationChange.slerp(Si.identityQuaternion,1-A)}};let Xo=Si;r(Xo,"lastObjPosition",{}),r(Xo,"lastObjRotation",{}),r(Xo,"firstKeyframeRotation",{}),r(Xo,"spaceRotation",{}),r(Xo,"effectiveSpaceRotation",{}),r(Xo,"clipOffsetRotation",{}),r(Xo,"identityQuaternion",new kA);class w6{constructor(A){r(this,"controller");r(this,"handler",[]);r(this,"root");r(this,"summedPosition",new S);r(this,"summedRotation",new kA);this.controller=A}createClip(A,e,t){this.root=e,e&&"name"in e&&e.name;const g=this.findRootTrack(t,".position"),I=this.findRootTrack(t,".quaternion"),o=new Xo(this.controller.context,e,t,g,I);this.handler.push(o);const C=A.clipAction(t);return o.action=C,C}onStart(A){for(const e of this.handler)e.onStart(A)}onBeforeUpdate(){for(const A of this.handler)A.onBeforeUpdate()}onAfterUpdate(){this.summedPosition.set(0,0,0),this.summedRotation.set(0,0,0,1);for(const A of this.handler)A.onAfterUpdate(),this.summedPosition.add(A.positionChange),this.summedRotation.multiply(A.rotationChange);this.root.position.add(this.summedPosition),this.root.quaternion.multiply(this.summedRotation),Xo.lastObjRotation[this.root.uuid].copy(this.root.quaternion)}findRootTrack(A,e){const t=A.tracks;if(!t)return null;for(const g of t)if(g.name.endsWith(e))return g;return null}}var y6=Object.defineProperty,S6=Object.getOwnPropertyDescriptor,vw=(i,A,e,t)=>{for(var g=t>1?void 0:t?S6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&y6(A,e,g),g};const l0=nA("debuganimator");class oI extends MA{constructor(){super(...arguments);r(this,"applyRootMotion",!1);r(this,"hasRootMotion",!1);r(this,"keepAnimatorControllerStateOnDisable",!1);r(this,"speed",1);r(this,"normalizedStartOffset",0);r(this,"_animatorController",null)}set runtimeAnimatorController(e){this._animatorController&&this._animatorController.model===e||(e?e instanceof Pr?this._animatorController=e:(l0&&console.log("Assign animator controller",e,this),this._animatorController=new Pr(e)):this._animatorController=null)}get runtimeAnimatorController(){return this._animatorController}Play(e,t=-1,g=Number.NEGATIVE_INFINITY,I=0){this.play(e,t,g,I)}play(e,t=-1,g=Number.NEGATIVE_INFINITY,I=0){var o;(o=this.runtimeAnimatorController)==null||o.play(e,t,g,I)}Reset(){this.reset()}reset(){var e;(e=this._animatorController)==null||e.reset()}SetBool(e,t){this.setBool(e,t)}setBool(e,t){var g;(g=this.runtimeAnimatorController)==null||g.setBool(e,t)}GetBool(e){return this.getBool(e)}getBool(e){var t;return((t=this.runtimeAnimatorController)==null?void 0:t.getBool(e))??!1}SetFloat(e,t){this.setFloat(e,t)}setFloat(e,t){var g;(g=this.runtimeAnimatorController)==null||g.setFloat(e,t)}GetFloat(e){return this.getFloat(e)}getFloat(e){var t;return((t=this.runtimeAnimatorController)==null?void 0:t.getFloat(e))??-1}SetInteger(e,t){this.setInteger(e,t)}setInteger(e,t){var g;(g=this.runtimeAnimatorController)==null||g.setInteger(e,t)}GetInteger(e){return this.getInteger(e)}getInteger(e){var t;return((t=this.runtimeAnimatorController)==null?void 0:t.getInteger(e))??-1}SetTrigger(e){this.setTrigger(e)}setTrigger(e){var t;l0&&console.log("SetTrigger",e),(t=this.runtimeAnimatorController)==null||t.setTrigger(e)}ResetTrigger(e){this.resetTrigger(e)}resetTrigger(e){var t;(t=this.runtimeAnimatorController)==null||t.resetTrigger(e)}IsInTransition(){return this.isInTransition()}isInTransition(){var e;return((e=this.runtimeAnimatorController)==null?void 0:e.isInTransition())??!1}SetSpeed(e){return this.setSpeed(e)}setSpeed(e){var t;e!==this.speed&&(this.speed=e,(t=this._animatorController)==null||t.setSpeed(e))}set minMaxSpeed(e){this.speed=ee.lerp(e.x,e.y,Math.random())}set minMaxOffsetNormalized(e){this.normalizedStartOffset=ee.lerp(e.x,e.y,Math.random()),this.runtimeAnimatorController&&(this.runtimeAnimatorController.normalizedStartOffset=this.normalizedStartOffset)}awake(){if(l0&&console.log("ANIMATOR",this.name,this),!!this.gameObject&&this.runtimeAnimatorController){const e=this.runtimeAnimatorController.clone();e?(console.assert(this.runtimeAnimatorController!==e),this.runtimeAnimatorController=e,console.assert(this.runtimeAnimatorController===e),this.runtimeAnimatorController.bind(this),this.runtimeAnimatorController.setSpeed(this.speed),this.runtimeAnimatorController.normalizedStartOffset=this.normalizedStartOffset):console.warn("Could not clone animator controller",this.runtimeAnimatorController)}}onDisable(){var e;this.keepAnimatorControllerStateOnDisable||(e=this._animatorController)==null||e.reset()}onBeforeRender(){this._animatorController&&this._animatorController.update()}}vw([w()],oI.prototype,"applyRootMotion",2);vw([w()],oI.prototype,"hasRootMotion",2);vw([w()],oI.prototype,"keepAnimatorControllerStateOnDisable",2);vw([w()],oI.prototype,"runtimeAnimatorController",1);class k6 extends ci{constructor(A,e=1,t=16,g=2){const I=new de,o=t+g*2,C=new Float32Array((o*3+3)*3);I.setAttribute("position",new Ce(C,3));const s=new pi({color:65280}),n=new pi({color:16776960});super(I,[n,s]),this.audio=A,this.range=e,this.divisionsInnerAngle=t,this.divisionsOuterAngle=g,this.type="PositionalAudioHelper",this.update()}update(){const A=this.audio,e=this.range,t=this.divisionsInnerAngle,g=this.divisionsOuterAngle,I=AI.degToRad(A.panner.coneInnerAngle),o=AI.degToRad(A.panner.coneOuterAngle),C=I/2,s=o/2;let n=0,a=0,B,Q;const E=this.geometry,c=E.attributes.position;E.clearGroups();function h(l,d,p,u){const D=(d-l)/p;for(c.setXYZ(n,0,0,0),a++,B=l;B<d;B+=D)Q=n+a,c.setXYZ(Q,Math.sin(B)*e,0,Math.cos(B)*e),c.setXYZ(Q+1,Math.sin(Math.min(B+D,d))*e,0,Math.cos(Math.min(B+D,d))*e),c.setXYZ(Q+2,0,0,0),a+=3;E.addGroup(n,a,u),n+=a,a=0}h(-s,-C,g,0),h(-C,C,t,1),h(C,s,g,0),c.needsUpdate=!0,I===o&&(this.material[0].visible=!1)}dispose(){this.geometry.dispose(),this.material[0].dispose(),this.material[1].dispose()}}var G6=Object.defineProperty,M6=Object.getOwnPropertyDescriptor,ba=(i,A,e,t)=>{for(var g=t>1?void 0:t?M6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&G6(A,e,g),g};const Mg=nA("debugaudio");var _c;const eg=(_c=class extends MA{constructor(){super(...arguments);r(this,"clip","");r(this,"playOnAwake",!1);r(this,"_spatialBlend",0);r(this,"_minDistance",1);r(this,"_maxDistance",100);r(this,"_volume",1);r(this,"rollOffMode",0);r(this,"playInBackground",!0);r(this,"_loop",!1);r(this,"sound",null);r(this,"helper",null);r(this,"wasPlaying",!1);r(this,"audioLoader",null);r(this,"shouldPlay",!1);r(this,"_lastClipStartedLoading",null);r(this,"onVisibilityChanged",()=>{switch(document.visibilityState){case"hidden":(this.playInBackground===!1||Xr())&&(this.wasPlaying=this.isPlaying,this.isPlaying&&this.pause());break;case"visible":Mg&&console.log("visible",this.enabled,this.playOnAwake,!this.isPlaying,eg._userInteractionRegistered,this.wasPlaying),this.enabled&&this.playOnAwake&&!this.isPlaying&&eg._userInteractionRegistered&&this.wasPlaying&&this.play();break}});r(this,"onApplicationMuteChanged",()=>{var A,e;this.context.application.muted?(A=this.sound)==null||A.setVolume(0):(e=this.sound)==null||e.setVolume(this.volume)});r(this,"lerp",(A,e,t)=>A*(1-t)+e*t);r(this,"_lastContextTime",0);r(this,"_hasEnded",!0);r(this,"_needUpdateSpatialDistanceSettings",!1)}static get userInteractionRegistered(){return eg._didCallBeginWaitForUserInteraction||(eg._didCallBeginWaitForUserInteraction=!0,eg._beginWaitForUserInteraction()),eg._userInteractionRegistered}static registerWaitForAllowAudio(A){if(A!==null){if(this._userInteractionRegistered){A();return}this.callbacks.indexOf(A)===-1&&this.callbacks.push(A),eg._didCallBeginWaitForUserInteraction||(eg._didCallBeginWaitForUserInteraction=!0,eg._beginWaitForUserInteraction())}}static _beginWaitForUserInteraction(A=null){if(this._userInteractionRegistered){A&&A();return}A!==null&&this.registerWaitForAllowAudio(A);const t=(()=>{if(t!=null&&!eg._userInteractionRegistered){eg._userInteractionRegistered=!0,Mg&&console.log("🔊 registered interaction, can play audio now"),document.removeEventListener("pointerdown",t),document.removeEventListener("click",t),document.removeEventListener("dragstart",t),document.removeEventListener("touchstart",t);for(const g of this.callbacks)g();this.callbacks.length=0}}).bind(this);document.addEventListener("pointerdown",t),document.addEventListener("click",t),document.addEventListener("dragstart",t),document.addEventListener("touchstart",t)}get loop(){return this.sound&&(this._loop=this.sound.getLoop()),this._loop}set loop(A){this._loop=A,this.sound&&this.sound.setLoop(A)}get spatialBlend(){return this._spatialBlend}set spatialBlend(A){A!==this._spatialBlend&&(this._spatialBlend=A,this._needUpdateSpatialDistanceSettings=!0)}get minDistance(){return this._minDistance}set minDistance(A){this._minDistance!==A&&(this._minDistance=A,this._needUpdateSpatialDistanceSettings=!0)}get maxDistance(){return this._maxDistance}set maxDistance(A){this._maxDistance!==A&&(this._maxDistance=A,this._needUpdateSpatialDistanceSettings=!0)}get volume(){return this._volume}set volume(A){this._volume=A,this.sound&&!this.context.application.muted&&(Mg&&console.log(this.name,"audio set volume",A),this.sound.setVolume(A))}get Sound(){if(!this.sound&&eg._userInteractionRegistered){const A=AA.getComponent(this.context.mainCamera,IE)??AA.findObjectOfType(IE,this.context);A!=null&&A.listener&&(this.sound=new HL(A.listener),this.gameObject.add(this.sound))}return this.sound}get ShouldPlay(){return this.shouldPlay}awake(){this.audioLoader=new qD,this.playOnAwake&&(this.shouldPlay=!0)}onEnable(){eg._userInteractionRegistered?this.playOnAwake&&this.context.application.isVisible&&this.play():eg._beginWaitForUserInteraction(()=>{this.enabled&&!this.destroyed&&this.shouldPlay&&this.loadAndPlay(this.clip)}),globalThis.addEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.addEventListener(jD.MuteChanged,this.onApplicationMuteChanged)}onDisable(){globalThis.removeEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.removeEventListener(jD.MuteChanged,this.onApplicationMuteChanged),this.stop()}onLoaded(A){Mg&&console.log("audio buffer loaded"),eg.registerWaitForAllowAudio(()=>{Mg&&console.log("finished loading",A);const e=this.Sound;if(!e){console.warn("Failed getting sound",this.name);return}e.isPlaying&&e.stop(),e.setBuffer(A),e.loop=this._loop,this.context.application.muted?e.setVolume(0):e.setVolume(this.volume),e.autoplay=this.shouldPlay,this.applySpatialDistanceSettings(),e.isPlaying&&e.stop(),Mg&&console.log(this.name,this.shouldPlay,eg.userInteractionRegistered,this),this.shouldPlay&&eg._userInteractionRegistered&&this.play()})}applySpatialDistanceSettings(){const A=this.sound;if(!A)return;this._needUpdateSpatialDistanceSettings=!1;const e=this.lerp(10*this._maxDistance/Math.max(1e-4,this.spatialBlend),this._minDistance,this.spatialBlend);switch(Mg&&console.log(this.name,this._minDistance,this._maxDistance,this.spatialBlend,"Ref distance="+e),A.setRefDistance(e),A.setMaxDistance(Math.max(.01,this._maxDistance)),this.rollOffMode){case 0:A.setDistanceModel("exponential");break;case 1:A.setDistanceModel("linear");break}this.spatialBlend>0?Mg&&!this.helper&&(this.helper=new k6(A,A.getRefDistance()),A.add(this.helper)):this.helper&&this.helper.parent&&this.helper.removeFromParent()}loadAndPlay(A){if(A&&(this.clip=A),this.clip&&(Mg&&console.log(this.clip),this.clip.endsWith(".mp3")||this.clip.endsWith(".wav"))){if(this.audioLoader||(this.audioLoader=new qD),this.shouldPlay=!0,this._lastClipStartedLoading===this.clip){Mg&&console.log("Is currently loading:",this._lastClipStartedLoading,this);return}this._lastClipStartedLoading=this.clip,Mg&&console.log("load audio",this.clip),this.audioLoader.load(this.clip,this.onLoaded.bind(this),()=>{},console.error)}}play(A=void 0){var e;if(!this.audioLoader||!this.sound||A&&A!==this.clip){this.loadAndPlay(A);return}if(this.shouldPlay=!0,this._hasEnded=!1,Mg&&console.log("play",(e=this.sound)==null?void 0:e.getVolume(),this.sound),this.sound&&!this.sound.isPlaying){const t=this.context.application.muted;t&&this.sound.setVolume(0),this.sound.play(t?.1:0)}}pause(){var A;Mg&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.isPlaying&&this.sound.source&&(this._lastContextTime=(A=this.sound)==null?void 0:A.context.currentTime,this.sound.pause())}stop(){var A;Mg&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.source&&(this._lastContextTime=(A=this.sound)==null?void 0:A.context.currentTime,Mg&&console.log(this._lastContextTime),this.sound.stop())}get isPlaying(){var A;return((A=this.sound)==null?void 0:A.isPlaying)??!1}set isPlaying(A){}get time(){var A,e;return(A=this.sound)!=null&&A.source?((e=this.sound.source)==null?void 0:e.context.currentTime)-this._lastContextTime+this.sound.offset:0}set time(A){if(this.sound){if(A===this.sound.offset)return;const e=this.isPlaying;this.stop(),this.sound.offset=A,e&&this.play()}}update(){this.helper&&(this.isPlaying&&this.helper.update(),this.helper.visible=this.isPlaying),this._needUpdateSpatialDistanceSettings&&this.applySpatialDistanceSettings(),this.sound&&!this.sound.isPlaying&&this.shouldPlay&&!this._hasEnded&&(this._hasEnded=!0,Mg&&console.log("Audio clip ended",this.clip),this.sound.dispatchEvent({type:"ended",target:this}))}},r(_c,"_didCallBeginWaitForUserInteraction",!1),r(_c,"callbacks",[]),r(_c,"_userInteractionRegistered",!1),_c);let Ni=eg;ba([w(URL)],Ni.prototype,"clip",2);ba([w()],Ni.prototype,"playOnAwake",2);ba([w()],Ni.prototype,"loop",1);ba([w()],Ni.prototype,"spatialBlend",1);ba([w()],Ni.prototype,"minDistance",1);ba([w()],Ni.prototype,"maxDistance",1);ba([w()],Ni.prototype,"volume",1);ba([w()],Ni.prototype,"rollOffMode",2);var m6=Object.defineProperty,R6=Object.getOwnPropertyDescriptor,U6=(i,A,e,t)=>{for(var g=t>1?void 0:t?R6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&m6(A,e,g),g};class pd extends MA{constructor(){super(...arguments);r(this,"constraintActive",!0);r(this,"locked",!1);r(this,"sources",[])}}U6([w(UA)],pd.prototype,"sources",2);const fJ={type:"change"},d0={type:"start"},wJ={type:"end"};let F6=class extends ji{constructor(A,e){super(),this.object=A,this.domElement=e,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new S,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:ar.ROTATE,MIDDLE:ar.DOLLY,RIGHT:ar.PAN},this.touches={ONE:rr.ROTATE,TWO:rr.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 C.phi},this.getAzimuthalAngle=function(){return C.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(q){q.addEventListener("keydown",v),this._domElementKeyEvents=q},this.saveState=function(){t.target0.copy(t.target),t.position0.copy(t.object.position),t.zoom0=t.object.zoom},this.reset=function(){t.target.copy(t.target0),t.object.position.copy(t.position0),t.object.zoom=t.zoom0,t.object.updateProjectionMatrix(),t.dispatchEvent(fJ),t.update(),I=g.NONE},this.update=function(){const q=new S,fA=new kA().setFromUnitVectors(A.up,new S(0,1,0)),XA=fA.clone().invert(),HA=new S,WA=new kA,YA=2*Math.PI;return function(){const xe=t.object.getWorldPosition(A.position);q.copy(xe).sub(t.target),q.applyQuaternion(fA),C.setFromVector3(q),t.autoRotate&&I===g.NONE&&U(f()),t.enableDamping?(C.theta+=s.theta*t.dampingFactor,C.phi+=s.phi*t.dampingFactor):(C.theta+=s.theta,C.phi+=s.phi);let Ue=t.minAzimuthAngle,V=t.maxAzimuthAngle;return isFinite(Ue)&&isFinite(V)&&(Ue<-Math.PI?Ue+=YA:Ue>Math.PI&&(Ue-=YA),V<-Math.PI?V+=YA:V>Math.PI&&(V-=YA),Ue<=V?C.theta=Math.max(Ue,Math.min(V,C.theta)):C.theta=C.theta>(Ue+V)/2?Math.max(Ue,C.theta):Math.min(V,C.theta)),C.phi=Math.max(t.minPolarAngle,Math.min(t.maxPolarAngle,C.phi)),C.makeSafe(),t.enableDamping?a=AI.lerp(a,n,t.dampingFactor):a=n,C.radius*=a,C.radius=Math.max(t.minDistance,Math.min(t.maxDistance,C.radius)),t.enableDamping===!0?t.target.addScaledVector(B,t.dampingFactor):t.target.add(B),q.setFromSpherical(C),q.applyQuaternion(XA),xe.copy(t.target).add(q),t.object.parent?t.object.parent.worldToLocal(xe):t.object.position.copy(xe),t.object.lookAt(t.target),t.enableDamping===!0?(s.theta*=1-t.dampingFactor,s.phi*=1-t.dampingFactor,B.multiplyScalar(1-t.dampingFactor)):(s.set(0,0,0),B.set(0,0,0)),n=1,Q||HA.distanceToSquared(t.object.position)>o||8*(1-WA.dot(t.object.quaternion))>o?(t.dispatchEvent(fJ),HA.copy(t.object.position),WA.copy(t.object.quaternion),Q=!1,!0):!1}}(),this.dispose=function(){t.domElement.removeEventListener("contextmenu",RA),t.domElement.removeEventListener("pointerdown",Ae),t.domElement.removeEventListener("pointercancel",Be),t.domElement.removeEventListener("wheel",ve),t.domElement.removeEventListener("pointermove",VA),t.domElement.removeEventListener("pointerup",Ee),t._domElementKeyEvents!==null&&t._domElementKeyEvents.removeEventListener("keydown",v)};const t=this,g={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let I=g.NONE;const o=1e-6,C=new Hk,s=new Hk;let n=1,a=1;const B=new S;let Q=!1;const E=new P,c=new P,h=new P,l=new P,d=new P,p=new P,u=new P,D=new P,y=new P,k=[],R={};function f(){return 2*Math.PI/60/60*t.autoRotateSpeed}function M(){return Math.pow(.95,t.zoomSpeed)}function U(q){s.theta-=q}function J(q){s.phi-=q}const H=function(){const q=new S;return function(XA,HA){q.setFromMatrixColumn(HA,0),q.multiplyScalar(-XA),B.add(q)}}(),Y=function(){const q=new S;return function(XA,HA){t.screenSpacePanning===!0?q.setFromMatrixColumn(HA,1):(q.setFromMatrixColumn(HA,0),q.crossVectors(t.object.up,q)),q.multiplyScalar(XA),B.add(q)}}(),b=function(){const q=new S,fA=new S;return function(HA,WA){const YA=t.domElement;if(t.object.isPerspectiveCamera){t.object.getWorldPosition(fA),q.copy(fA).sub(t.target);let Ne=q.length();Ne*=Math.tan(t.object.fov/2*Math.PI/180),H(2*HA*Ne/YA.clientHeight,t.object.matrixWorld),Y(2*WA*Ne/YA.clientHeight,t.object.matrixWorld)}else t.object.isOrthographicCamera?(H(HA*(t.object.right-t.object.left)/t.object.zoom/YA.clientWidth,t.object.matrixWorld),Y(WA*(t.object.top-t.object.bottom)/t.object.zoom/YA.clientHeight,t.object.matrixWorld)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),t.enablePan=!1)}}();function _(q){t.object.isPerspectiveCamera?n/=q:t.object.isOrthographicCamera?(t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom*q)),t.object.updateProjectionMatrix(),Q=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function eA(q){t.object.isPerspectiveCamera?n*=q:t.object.isOrthographicCamera?(t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom/q)),t.object.updateProjectionMatrix(),Q=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function $(q){E.set(q.clientX,q.clientY)}function X(q){u.set(q.clientX,q.clientY)}function cA(q){l.set(q.clientX,q.clientY)}function EA(q){c.set(q.clientX,q.clientY),h.subVectors(c,E).multiplyScalar(t.rotateSpeed);const fA=t.domElement;U(2*Math.PI*h.x/fA.clientHeight),J(2*Math.PI*h.y/fA.clientHeight),E.copy(c),t.update()}function KA(q){D.set(q.clientX,q.clientY),y.subVectors(D,u),y.y>0?_(M()):y.y<0&&eA(M()),u.copy(D),t.update()}function uA(q){d.set(q.clientX,q.clientY),p.subVectors(d,l).multiplyScalar(t.panSpeed),b(p.x,p.y),l.copy(d),t.update()}function gA(q){q.deltaY<0?eA(M()):q.deltaY>0&&_(M()),t.update()}function rA(q){let fA=!1;switch(q.code){case t.keys.UP:q.ctrlKey||q.metaKey||q.shiftKey?J(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):b(0,t.keyPanSpeed),fA=!0;break;case t.keys.BOTTOM:q.ctrlKey||q.metaKey||q.shiftKey?J(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):b(0,-t.keyPanSpeed),fA=!0;break;case t.keys.LEFT:q.ctrlKey||q.metaKey||q.shiftKey?U(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):b(t.keyPanSpeed,0),fA=!0;break;case t.keys.RIGHT:q.ctrlKey||q.metaKey||q.shiftKey?U(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):b(-t.keyPanSpeed,0),fA=!0;break}fA&&(q.preventDefault(),t.update())}function GA(){if(k.length===1)E.set(k[0].pageX,k[0].pageY);else{const q=.5*(k[0].pageX+k[1].pageX),fA=.5*(k[0].pageY+k[1].pageY);E.set(q,fA)}}function W(){if(k.length===1)l.set(k[0].pageX,k[0].pageY);else{const q=.5*(k[0].pageX+k[1].pageX),fA=.5*(k[0].pageY+k[1].pageY);l.set(q,fA)}}function xA(){const q=k[0].pageX-k[1].pageX,fA=k[0].pageY-k[1].pageY,XA=Math.sqrt(q*q+fA*fA);u.set(0,XA)}function JA(){t.enableZoom&&xA(),t.enablePan&&W()}function jA(){t.enableZoom&&xA(),t.enableRotate&&GA()}function yA(q){if(k.length==1)c.set(q.pageX,q.pageY);else{const XA=OA(q),HA=.5*(q.pageX+XA.x),WA=.5*(q.pageY+XA.y);c.set(HA,WA)}h.subVectors(c,E).multiplyScalar(t.rotateSpeed);const fA=t.domElement;U(2*Math.PI*h.x/fA.clientHeight),J(2*Math.PI*h.y/fA.clientHeight),E.copy(c)}function ae(q){if(k.length===1)d.set(q.pageX,q.pageY);else{const fA=OA(q),XA=.5*(q.pageX+fA.x),HA=.5*(q.pageY+fA.y);d.set(XA,HA)}p.subVectors(d,l).multiplyScalar(t.panSpeed),b(p.x,p.y),l.copy(d)}function dA(q){const fA=OA(q),XA=q.pageX-fA.x,HA=q.pageY-fA.y,WA=Math.sqrt(XA*XA+HA*HA);D.set(0,WA),y.set(0,Math.pow(D.y/u.y,t.zoomSpeed)),_(y.y),u.copy(D)}function lA(q){t.enableZoom&&dA(q),t.enablePan&&ae(q)}function bA(q){t.enableZoom&&dA(q),t.enableRotate&&yA(q)}function Ae(q){t.enabled!==!1&&(k.length===0&&(t.domElement.addEventListener("pointermove",VA),t.domElement.addEventListener("pointerup",Ee)),qA(q),q.pointerType==="touch"?K(q):oe(q))}function VA(q){t.enabled!==!1&&(q.pointerType==="touch"?BA(q):We(q))}function Ee(q){PA(q),k.length===0&&(t.domElement.removeEventListener("pointermove",VA),t.domElement.removeEventListener("pointerup",Ee)),t.dispatchEvent(wJ),I=g.NONE}function Be(q){PA(q)}function oe(q){let fA;switch(q.button){case 0:fA=t.mouseButtons.LEFT;break;case 1:fA=t.mouseButtons.MIDDLE;break;case 2:fA=t.mouseButtons.RIGHT;break;default:fA=-1}switch(fA){case ar.DOLLY:if(t.enableZoom===!1)return;X(q),I=g.DOLLY;break;case ar.ROTATE:if(q.ctrlKey||q.metaKey||q.shiftKey){if(t.enablePan===!1)return;cA(q),I=g.PAN}else{if(t.enableRotate===!1)return;$(q),I=g.ROTATE}break;case ar.PAN:if(q.ctrlKey||q.metaKey||q.shiftKey){if(t.enableRotate===!1)return;$(q),I=g.ROTATE}else{if(t.enablePan===!1)return;cA(q),I=g.PAN}break;default:I=g.NONE}I!==g.NONE&&t.dispatchEvent(d0)}function We(q){switch(I){case g.ROTATE:if(t.enableRotate===!1)return;EA(q);break;case g.DOLLY:if(t.enableZoom===!1)return;KA(q);break;case g.PAN:if(t.enablePan===!1)return;uA(q);break}}function ve(q){t.enabled===!1||t.enableZoom===!1||I!==g.NONE||(q.preventDefault(),t.dispatchEvent(d0),gA(q),t.dispatchEvent(wJ))}function v(q){t.enabled===!1||t.enablePan===!1||rA(q)}function K(q){switch(re(q),k.length){case 1:switch(t.touches.ONE){case rr.ROTATE:if(t.enableRotate===!1)return;GA(),I=g.TOUCH_ROTATE;break;case rr.PAN:if(t.enablePan===!1)return;W(),I=g.TOUCH_PAN;break;default:I=g.NONE}break;case 2:switch(t.touches.TWO){case rr.DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;JA(),I=g.TOUCH_DOLLY_PAN;break;case rr.DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;jA(),I=g.TOUCH_DOLLY_ROTATE;break;default:I=g.NONE}break;default:I=g.NONE}I!==g.NONE&&t.dispatchEvent(d0)}function BA(q){switch(re(q),I){case g.TOUCH_ROTATE:if(t.enableRotate===!1)return;yA(q),t.update();break;case g.TOUCH_PAN:if(t.enablePan===!1)return;ae(q),t.update();break;case g.TOUCH_DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;lA(q),t.update();break;case g.TOUCH_DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;bA(q),t.update();break;default:I=g.NONE}}function RA(q){t.enabled!==!1&&q.preventDefault()}function qA(q){k.push(q)}function PA(q){delete R[q.pointerId];for(let fA=0;fA<k.length;fA++)if(k[fA].pointerId==q.pointerId){k.splice(fA,1);return}}function re(q){let fA=R[q.pointerId];fA===void 0&&(fA=new P,R[q.pointerId]=fA),fA.set(q.pageX,q.pageY)}function OA(q){const fA=q.pointerId===k[0].pointerId?k[1]:k[0];return R[fA.pointerId]}t.domElement.addEventListener("contextmenu",RA),t.domElement.addEventListener("pointerdown",Ae),t.domElement.addEventListener("pointercancel",Be),t.domElement.addEventListener("wheel",ve,{passive:!1}),this.update()}};class N6{static createButton(A,e={},t){const g=document.createElement("button");let I=!1;function o(){if(e.optionalFeatures=e.optionalFeatures||[],e.domOverlay===void 0){var a=document.createElement("div");a.style.display="none",document.body.appendChild(a);var B=document.createElementNS("http://www.w3.org/2000/svg","svg");B.setAttribute("width",38),B.setAttribute("height",38),B.style.position="absolute",B.style.right="20px",B.style.top="20px",B.addEventListener("click",function(){E.end()}),a.appendChild(B);var Q=document.createElementNS("http://www.w3.org/2000/svg","path");Q.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),Q.setAttribute("stroke","#fff"),Q.setAttribute("stroke-width",2),B.appendChild(Q),e.optionalFeatures.push("dom-overlay"),e.domOverlay={root:a},I=!0}let E=null,c=null;async function h(d){var D;const p=/WebXRViewer\//i.test(navigator.userAgent),u=e.domOverlay.root;p&&((D=e.domOverlay)!=null&&D.root?(c=u.parentNode,c&&(console.log("Reparent DOM Overlay to body",u,u.style.display),u.style.display="",u.style.visibility="",document.body.appendChild(u))):console.warn("WebXRViewer: No DOM Overlay found")),d.addEventListener("end",l),await A.xr.setSession(d),g.textContent="STOP AR",I&&(e.domOverlay.root.style.display=""),E=d}function l(){E.removeEventListener("end",l),g.textContent="START AR";const d=e.domOverlay.root;c&&c.appendChild(d),I&&(d.style.display="none"),E=null}g.style.display="",g.style.cursor="pointer",g.style.left="calc(50% - 50px)",g.style.width="100px",g.textContent="START AR",g.onmouseenter=function(){g.style.opacity="1.0"},g.onmouseleave=function(){g.style.opacity="0.5"},g.onclick=function(){E===null?(t==null||t.call(this,e),navigator.xr.requestSession("immersive-ar",e).then(h)):E.end()}}function C(){g.disabled=!0,g.style.display="",g.style.cursor="auto",g.style.left="calc(50% - 75px)",g.style.width="150px",g.onmouseenter=null,g.onmouseleave=null,g.onclick=null}function s(){C(),g.textContent="AR NOT SUPPORTED"}function n(a){a.style.position="absolute",a.style.bottom="20px",a.style.padding="12px 6px",a.style.border="1px solid #fff",a.style.borderRadius="4px",a.style.background="rgba(0,0,0,0.1)",a.style.color="#fff",a.style.font="normal 13px sans-serif",a.style.textAlign="center",a.style.opacity="0.5",a.style.outline="none",a.style.zIndex="999"}if("xr"in navigator)return g.id="ARButton",g.style.display="none",n(g),navigator.xr.isSessionSupported("immersive-ar").then(function(a){a?o():s()}).catch(s),g;{const a=document.createElement("a");return window.isSecureContext===!1?(a.href=document.location.href.replace(/^http:/,"https:"),a.innerHTML="WEBXR NEEDS HTTPS"):(a.href="https://immersiveweb.dev/",a.innerHTML="WEBXR NOT AVAILABLE"),a.style.left="calc(50% - 90px)",a.style.width="180px",a.style.textDecoration="none",n(a),a}}}const Nf=class{static createButton(A,e){const t=document.createElement("button");function g(){let s=null;async function n(B){B.addEventListener("end",a),await A.xr.setSession(B),t.textContent="EXIT VR",s=B}function a(){s.removeEventListener("end",a),t.textContent="ENTER VR",s=null}t.style.display="",t.style.cursor="pointer",t.style.left="calc(50% - 50px)",t.style.width="100px",t.textContent="ENTER VR",t.onmouseenter=function(){t.style.opacity="1.0"},t.onmouseleave=function(){t.style.opacity="0.5"},t.onclick=function(){if(s===null){const B={optionalFeatures:e.optionalFeatures};navigator.xr.requestSession("immersive-vr",B).then(n)}else s.end()}}function I(){t.disabled=!0,t.style.display="",t.style.cursor="auto",t.style.left="calc(50% - 75px)",t.style.width="150px",t.onmouseenter=null,t.onmouseleave=null,t.onclick=null}function o(){I(),t.textContent="VR NOT SUPPORTED"}function C(s){s.style.position="absolute",s.style.bottom="20px",s.style.padding="12px 6px",s.style.border="1px solid #fff",s.style.borderRadius="4px",s.style.background="rgba(0,0,0,0.1)",s.style.color="#fff",s.style.font="normal 13px sans-serif",s.style.textAlign="center",s.style.opacity="0.5",s.style.outline="none",s.style.zIndex="999"}if("xr"in navigator)return t.id="VRButton",t.style.display="none",C(t),navigator.xr.isSessionSupported("immersive-vr").then(function(s){s?g():o(),Nf.xrSessionIsGranted&&(console.log("XR session is granted - will enter immersive web now"),t.click())}),t;{const s=document.createElement("a");return window.isSecureContext===!1?(s.href=document.location.href.replace(/^http:/,"https:"),s.innerHTML="WEBXR NEEDS HTTPS"):(s.href="https://immersiveweb.dev/",s.innerHTML="WEBXR NOT AVAILABLE"),s.style.left="calc(50% - 90px)",s.style.width="180px",s.style.textDecoration="none",C(s),s}}static registerSessionGrantedListener(){if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent))return;navigator.xr.addEventListener("sessiongranted",()=>{Nf.xrSessionIsGranted=!0})}}};let kh=Nf;r(kh,"xrSessionIsGranted",!1);kh.registerSessionGrantedListener();const If="noVoip",uI=nA("debugvoip"),K6=nA("voip");class J6{constructor(A){r(this,"id");this.id=A}}class q6{constructor(A,e,t,g){r(this,"peer");r(this,"voip");r(this,"userId");r(this,"peerId");r(this,"call",null);r(this,"callErrorListener",null);r(this,"stream",null);this.voip=A,this.peer=e,this.userId=t,this.peerId=g}close(){var A;uI&&console.log("close voip call"),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.open&&this.call.close(),(A=this.stream)==null||A.getTracks().forEach(function(e){e.stop()})}updateMute(A){var t;if(!this.stream)return;const e=(t=this.stream)==null?void 0:t.getAudioTracks();for(const g of e)g.enabled=!A}async startVoipCall(){if(!await hn.HasMicrophonePermissions()){console.warn("no permission to use microphone, can not start call");return}uI&&console.log("start voip call"),this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),this.updateMute(this.voip.muteOutput),uI&&console.log(this.stream),this.call=this.peer.call(this.peerId,this.stream,{metadata:{userId:this.userId}}),this.call.on("error",e=>{console.error(e)}),this.call.on("stream",e=>{uI&&console.log("received stream from remote again",e)}),this.peer.on("close",this.onCallClose.bind(this)),this.callErrorListener=e=>{var t;e.message.includes(this.peerId)?(console.log("Could not connect to "+this.peerId),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.close(),(t=this.stream)==null||t.getTracks().forEach(function(g){g.stop()}),this.stream=null):console.error(e)},this.peer.on("error",this.callErrorListener)}onCallClose(A){uI&&console.log("call closed",A)}}class b6{constructor(A,e,t){r(this,"voip");r(this,"call");r(this,"audio",null);r(this,"stream",null);r(this,"obj");r(this,"analyzer",null);r(this,"waitingForStart",!1);r(this,"closed",!1);r(this,"audioElement",null);this.voip=A,this.obj=e,this.call=t}get currentStream(){return this.stream}get currentAudio(){return this.audio}get currentAnalyzer(){return this.analyzer}openAudioStream(A){const e=A.getAudioTracks();for(const t of e)if(t.kind==="audio"&&t.readyState==="live"){this.open(t);return}console.warn("failed finding valid audio stream to begin call")}open(A){console.assert(A.kind==="audio","invalid track kind, expected audio but received "+A.kind),!this.waitingForStart&&(this.waitingForStart=!0,Ni.userInteractionRegistered||uI&&console.log("Incoming call, waiting for user interaction before opening audio"),Ni.registerWaitForAllowAudio(async()=>{if(this.call.open&&!this.closed){uI&&console.log("Setup audio and begin listening"),this.stream=new MediaStream([A]);const e=new WM;this.audio=new sw(e),this.audio.setVolume(this.voip.muteInput?0:1),this.audio.setMediaStreamSource(this.stream);const t=document.createElement("audio");this.audioElement=t,t.style.display="none",document.body.appendChild(t),t.srcObject=this.stream,t.sinkId!==void 0&&navigator.mediaDevices.enumerateDevices().then(g=>{if(t){console.log(g);for(const I of g)if(I.label==="Speakerphone"){t.sinkId=I.deviceId;break}}}),uI&&console.log("call is setup, you should hear something now"),this.analyzer=new _L(this.audio,32)}}))}close(){var A,e,t;this.closed=!0,(A=this.call)!=null&&A.open&&this.call.close(),(e=this.audio)==null||e.disconnect(),(t=this.stream)==null||t.getTracks().forEach(g=>{g.stop()}),this.stream=null,this.audioElement&&this.audioElement.remove()}}class hn extends MA{constructor(){super(...arguments);r(this,"requireParam",!1);r(this,"peer",null);r(this,"model",null);r(this,"connections",{});r(this,"currentIncomingCalls",{});r(this,"_inputMuted",!1);r(this,"_outputMuted",!1)}set muteInput(e){var g;if(e===this._inputMuted||(this._inputMuted=e,!this.currentIncomingCalls))return;const t=this._inputMuted?0:1;for(const I in this.currentIncomingCalls){const o=this.currentIncomingCalls[I];(g=o==null?void 0:o.currentAudio)==null||g.setVolume(t)}}get muteInput(){return this._inputMuted}set muteOutput(e){if(e!==this._outputMuted&&(this._outputMuted=e,!!this.connections))for(const t in this.connections){const g=this.connections[t];g==null||g.updateMute(e)}}get muteOutput(){return this._outputMuted}getFrequency(e){if(e===null){for(const g in this.currentIncomingCalls){const I=this.currentIncomingCalls[g];if(I&&I.currentAnalyzer)return I.currentAnalyzer.getAverageFrequency()}return null}const t=this.currentIncomingCalls[e];return t&&t.currentAnalyzer?t.currentAnalyzer.getAverageFrequency():null}awake(){if(nA(If)){console.log("VOIP is disabled by url parameter: "+If);return}if(this.requireParam&&!K6){console.debug("VOIP must be enabled explicitly by url parameter");return}if(Hh()&&ms()){console.log("VOIP is currently not supported on Safari iOS");return}this.peer=new _D,navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,this.context.connection.beginListen(oi.JoinedRoom,e=>{navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}),this.context.connection.beginListen("peer-update-id",e=>{if(e.id!==this.context.connection.connectionId){const t=this.connections[e.id];if(t&&t.close(),this.peer&&this.context.connection.connectionId){const g=new q6(this,this.peer,this.context.connection.connectionId,e.peerId);this.connections[e.id]=g,g.startVoipCall()}}}),this.context.connection.beginListen(oi.UserLeftRoom,e=>{const{userId:t}=e,g=this.connections[t];this.connections[t]=null,g&&g.close();const I=this.currentIncomingCalls[t];uI&&console.log("UserLeftRoom",e,t,I),I&&(I.close(),this.currentIncomingCalls[t]=null)}),this.peer.on("open",this.onOpenPeerConnection.bind(this))}onEnable(){}onDisable(){console.log("TODO: close all");for(const e in this.currentIncomingCalls)try{const t=this.currentIncomingCalls[e];t==null||t.close();const g=this.connections[e];g==null||g.close()}catch(t){console.error(t)}}async onOpenPeerConnection(e){uI&&console.log("Peer connection established and received id"),this.model=new J6(e),this.context.connection.send("peer-update-id",this.model,dI.OnRoomJoin),this.peer&&(this.peer.on("call",this.onReceiveCall.bind(this)),this.peer.on("connection",function(t){uI&&console.log("CONNECTION",t),t.on("data",function(g){uI&&console.log("Received",g)})}))}async onReceiveCall(e){const{metadata:t}=e;console.assert(t.userId);const{userId:g}=t,I=this.currentIncomingCalls[g];if(I&&I.close(),uI&&console.log("received call"),await hn.HasMicrophonePermissions()){const o=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1});e.answer(o)}else e.answer(null);this.currentIncomingCalls[g]=new b6(this,this.gameObject,e),e.on("stream",o=>{var C;uI&&console.log("receive caller stream, will setup audio now"),(C=this.currentIncomingCalls[g])==null||C.openAudioStream(o)}),e.on("error",console.error)}static async HasMicrophonePermissions(){return(await navigator.permissions.query({name:"microphone"})).state!=="denied"}}var L6=Object.defineProperty,v6=Object.getOwnPropertyDescriptor,TT=(i,A,e,t)=>{for(var g=t>1?void 0:t?v6(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&L6(A,e,g),g};class La extends MA{constructor(){super(...arguments);r(this,"webAR",null);r(this,"invertForward",!1);r(this,"_initalMatrix",new NA);r(this,"_selectStartFn",this.onSelectStart.bind(this));r(this,"_selectEndFn",this.onSelectEnd.bind(this));r(this,"_arScale",5);r(this,"_rig",null);r(this,"_startPose",null);r(this,"_placementPose",null);r(this,"_isTouching",!1);r(this,"_rigStartPose",null);r(this,"_gotFirstHitTestResult",!1)}get rig(){var e;return(e=this.webAR)==null?void 0:e.webxr.Rig}get arScale(){return this._arScale}set arScale(e){e!==this._arScale&&(this._arScale=e,this.setScale(e))}start(){const e=AA.findObjectOfType(Se);e&&(e.Rig.updateMatrix(),this._initalMatrix.copy(e.Rig.matrix))}onBegin(e){var t;this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose=this.gameObject.matrix.clone(),this._rigStartPose=(t=this.rig)==null?void 0:t.matrix.clone(),this._gotFirstHitTestResult=!1,e.addEventListener("selectstart",this._selectStartFn),e.addEventListener("selectend",this._selectEndFn),this.gameObject.visible=!1,this.rig&&(this.rig.matrixAutoUpdate=!0,this._initalMatrix.decompose(this.rig.position,this.rig.quaternion,this.rig.scale)),this.dispatchEvent(new CustomEvent("onBeginSession"))}onUpdate(e,t,g){if(g&&!this._placementPose&&(this._gotFirstHitTestResult||(this._gotFirstHitTestResult=!0,this.dispatchEvent(new CustomEvent("canPlaceSession",{detail:{pose:g}}))),this._isTouching)){const I=new NA().fromArray(g.transform.matrix).invert();return this.dispatchEvent(new CustomEvent("placedSession",{detail:{pose:g,poseMatrix:I}})),this.webAR&&this.webAR.setReticleActive(!1),this.placeAt(e,I),!0}return!1}placeAt(e,t){this._placementPose||(this._placementPose=new NA),this._placementPose.copy(t);const g=this.gameObject.matrixWorld.clone().invert();if(this._placementPose.premultiply(g),e){if(this.invertForward){const I=new NA().makeRotationY(Math.PI);this._placementPose.premultiply(I)}this._rig=e,this.setScale(this.arScale)}else this._rig=null;this.gameObject.visible=!0}onEnd(e,t){this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose&&this.gameObject.matrix.copy(this._startPose),e&&(e.matrixAutoUpdate=!0,this._rigStartPose&&this._rigStartPose.decompose(e.position,e.quaternion,e.scale)),fI.markDirty(this.gameObject,!0),setTimeout(()=>{this.gameObject.matrixAutoUpdate=!0,this.gameObject.visible=!0},100)}onSelectStart(){this._isTouching=!0}onSelectEnd(){this._isTouching=!1}setScale(e){const t=this._rig;!t||!this._placementPose||(this._rigStartPose||(this._rigStartPose=t.matrix.clone()),t.matrixAutoUpdate=!1,t.matrix.multiplyMatrices(new NA().makeScale(e,e,e),this._placementPose),t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(),console.log("Place",t.position))}}TT([w()],La.prototype,"invertForward",2);TT([w()],La.prototype,"arScale",1);const x6="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/";class Y6{constructor(A,e,t,g,I=null){this.controller=e,this.handModel=A,this.bones=[],I===null&&(I=new kE,I.setPath(t||x6)),I.load(`${g}.glb`,o=>{const C=o.scene.children[0];this.handModel.add(C),C.layers.mask=this.handModel.layers.mask;const s=C.getObjectByProperty("type","SkinnedMesh");s.frustumCulled=!1,s.castShadow=!0,s.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(a=>{const B=C.getObjectByName(a);B!==void 0?B.jointName=a:console.warn(`Couldn't find ${a} in ${g} hand mesh`),this.bones.push(B)})})}updateMesh(){const A=this.controller.joints;for(let e=0;e<this.bones.length;e++){const t=this.bones[e];if(t){const g=A[t.jointName];if(g.visible){const I=g.position;t.position.copy(I),t.quaternion.copy(g.quaternion)}}}}}const T6=.01,H6="index-finger-tip";class _6 extends UA{constructor(A,e=null){super(),this.controller=A,this.motionController=null,this.envMap=null,this.loader=e,this.mesh=null,A.addEventListener("connected",t=>{const g=t.data;g.hand&&!this.motionController&&(this.xrInputSource=g,this.motionController=new Y6(this,A,this.path,g.handedness,this.loader))}),A.addEventListener("disconnected",()=>{this.clear(),this.motionController=null})}updateMatrixWorld(A){super.updateMatrixWorld(A),this.motionController&&this.motionController.updateMesh()}getPointerPosition(){const A=this.controller.joints[H6];return A?A.position:null}intersectBoxObject(A){const e=this.getPointerPosition();if(e){const t=new BC(e,T6),g=new Jg().setFromObject(A);return t.intersectsBox(g)}else return!1}checkButton(A){this.intersectBoxObject(A)?A.onPress():A.onClear(),A.isPressed()&&A.whilePressed()}}const O6=.05,yJ=.02,op=.01,SJ=.02,kJ=1,XB=.4,P6=.002,Fc=.01,Cp=.003,GJ=.035,yt=16,no=12,u0=110,W6=new S(0,1,0),V6=new S(0,0,1),j6=.02,z6=1.5;class Z6 extends UA{constructor(A,e){super(),this.hand=A,this.controller=e,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,A.addEventListener("connected",t=>{const g=t.data;g.hand&&(this.visible=!0,this.xrInputSource=g,this.pointerObject===null&&this.createPointer())})}_drawVerticesRing(A,e,t){const g=e.clone();for(let I=0;I<yt;I++){g.applyAxisAngle(V6,Math.PI*2/yt);const o=t*yt+I;A[3*o]=g.x,A[3*o+1]=g.y,A[3*o+2]=g.z}}_updatePointerVertices(A){const e=this.pointerGeometry.attributes.position.array,t=new S(P6,0,-1*(GJ-A));this._drawVerticesRing(e,t,0);const g=new S(Math.sin(Math.PI*u0/180)*A,Math.cos(Math.PI*u0/180)*A,0);for(let n=0;n<no;n++)this._drawVerticesRing(e,g,n+1),g.applyAxisAngle(W6,Math.PI*u0/180/(no*-2));const I=yt*(1+no),o=yt*(1+no)+1,C=new S(0,0,-1*(GJ-A));e[I*3]=C.x,e[I*3+1]=C.y,e[I*3+2]=C.z;const s=new S(0,0,A);e[o*3]=s.x,e[o*3+1]=s.y,e[o*3+2]=s.z,this.pointerGeometry.setAttribute("position",new Ie(e,3))}createPointer(){let A,e;const t=new Array(((no+1)*yt+2)*3).fill(0),g=[];for(this.pointerGeometry=new de,this.pointerGeometry.setAttribute("position",new Ie(t,3)),this._updatePointerVertices(Fc),A=0;A<no;A++){for(e=0;e<yt-1;e++)g.push(A*yt+e,A*yt+e+1,(A+1)*yt+e),g.push(A*yt+e+1,(A+1)*yt+e+1,(A+1)*yt+e);g.push((A+1)*yt-1,A*yt,(A+2)*yt-1),g.push(A*yt,(A+1)*yt,(A+2)*yt-1)}const I=yt*(1+no),o=yt*(1+no)+1;for(A=0;A<yt-1;A++)g.push(I,A+1,A),g.push(o,A+yt*no,A+yt*no+1);g.push(I,0,yt-1),g.push(o,yt*(no+1)-1,yt*no);const C=new wt;C.transparent=!0,C.opacity=XB,this.pointerGeometry.setIndex(g),this.pointerMesh=new pA(this.pointerGeometry,C),this.pointerMesh.position.set(0,0,-1*Fc),this.pointerObject=new UA,this.pointerObject.add(this.pointerMesh),this.raycaster=new uE;const s=new $I(j6,10,10),n=new wt;n.transparent=!0,n.opacity=XB,this.cursorObject=new pA(s,n),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 A=this.pointerObject.matrixWorld,e=new NA;e.identity().extractRotation(A),this.raycaster.ray.origin.setFromMatrixPosition(A),this.raycaster.ray.direction.set(0,0,-1).applyMatrix4(e)}}_updatePointer(){this.pointerObject.visible=this.controller.visible;const A=this.hand.joints["index-finger-tip"],e=this.hand.joints["thumb-tip"],t=A.position.distanceTo(e.position),g=A.position.clone().add(e.position).multiplyScalar(.5);this.pointerObject.position.copy(g),this.pointerObject.quaternion.copy(this.controller.quaternion),this.pinched=t<=yJ;const I=(t-op)/(O6-op),o=(t-op)/(yJ-op);if(I>1)this._updatePointerVertices(Fc),this.pointerMesh.position.set(0,0,-1*Fc),this.pointerMesh.material.opacity=XB;else if(I>0){const C=(Fc-Cp)*I+Cp;this._updatePointerVertices(C),o<1?(this.pointerMesh.position.set(0,0,-1*C-(1-o)*SJ),this.pointerMesh.material.opacity=XB+(1-o)*(kJ-XB)):(this.pointerMesh.position.set(0,0,-1*C),this.pointerMesh.material.opacity=XB)}else this._updatePointerVertices(Cp),this.pointerMesh.position.set(0,0,-1*Cp-SJ),this.pointerMesh.material.opacity=kJ;this.cursorObject.material.opacity=this.pointerMesh.material.opacity}updateMatrixWorld(A){super.updateMatrixWorld(A),this.pointerGeometry&&(this._updatePointer(),this._updateRaycaster())}isPinched(){return this.pinched}setAttached(A){this.attached=A}isAttached(){return this.attached}intersectObject(A,e=!0){if(this.raycaster)return this.raycaster.intersectObject(A,e)}intersectObjects(A,e=!0){if(this.raycaster)return this.raycaster.intersectObjects(A,e)}checkIntersections(A,e=!1){if(this.raycaster&&!this.attached){const t=this.raycaster.intersectObjects(A,e),g=new S(0,0,-1);if(t.length>0){const o=t[0].distance;this.cursorObject.position.copy(g.multiplyScalar(o))}else this.cursorObject.position.copy(g.multiplyScalar(z6))}}setCursor(A){const e=new S(0,0,-1);this.raycaster&&!this.attached&&this.cursorObject.position.copy(e.multiplyScalar(A))}}const ii={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 HT(i){const A=await fetch(i);if(A.ok)return A.json();throw new Error(A.statusText)}async function X6(i){if(!i)throw new Error("No basePath supplied");return await HT(`${i}/profilesList.json`)}async function $6(i,A,e=null,t=!0){if(!i)throw new Error("No xrInputSource supplied");if(!A)throw new Error("No basePath supplied");const g=await X6(A);let I;if(i.profiles.some(s=>{const n=g[s];return n&&(I={profileId:s,profilePath:`${A}/${n.path}`,deprecated:!!n.deprecated}),!!I}),!I){if(!e)throw new Error("No matching profile name found");const s=g[e];if(!s)throw new Error(`No matching profile name found and default profile "${e}" missing.`);I={profileId:e,profilePath:`${A}/${s.path}`,deprecated:!!s.deprecated}}const o=await HT(I.profilePath);let C;if(t){let s;if(i.handedness==="any"?s=o.layouts[Object.keys(o.layouts)[0]]:s=o.layouts[i.handedness],!s)throw new Error(`No matching handedness, ${i.handedness}, in profile ${I.profileId}`);s.assetPath&&(C=I.profilePath.replace("profile.json",s.assetPath))}return{profile:o,assetPath:C}}const A7={xAxis:0,yAxis:0,button:0,state:ii.ComponentState.DEFAULT};function e7(i=0,A=0){let e=i,t=A;if(Math.sqrt(i*i+A*A)>1){const o=Math.atan2(A,i);e=Math.cos(o),t=Math.sin(o)}return{normalizedXAxis:e*.5+.5,normalizedYAxis:t*.5+.5}}class t7{constructor(A){this.componentProperty=A.componentProperty,this.states=A.states,this.valueNodeName=A.valueNodeName,this.valueNodeProperty=A.valueNodeProperty,this.valueNodeProperty===ii.VisualResponseProperty.TRANSFORM&&(this.minNodeName=A.minNodeName,this.maxNodeName=A.maxNodeName),this.value=0,this.updateFromComponent(A7)}updateFromComponent({xAxis:A,yAxis:e,button:t,state:g}){const{normalizedXAxis:I,normalizedYAxis:o}=e7(A,e);switch(this.componentProperty){case ii.ComponentProperty.X_AXIS:this.value=this.states.includes(g)?I:.5;break;case ii.ComponentProperty.Y_AXIS:this.value=this.states.includes(g)?o:.5;break;case ii.ComponentProperty.BUTTON:this.value=this.states.includes(g)?t:0;break;case ii.ComponentProperty.STATE:this.valueNodeProperty===ii.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(g):this.value=this.states.includes(g)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}}class i7{constructor(A,e){if(!A||!e||!e.visualResponses||!e.gamepadIndices||Object.keys(e.gamepadIndices).length===0)throw new Error("Invalid arguments supplied");this.id=A,this.type=e.type,this.rootNodeName=e.rootNodeName,this.touchPointNodeName=e.touchPointNodeName,this.visualResponses={},Object.keys(e.visualResponses).forEach(t=>{const g=new t7(e.visualResponses[t]);this.visualResponses[t]=g}),this.gamepadIndices=Object.assign({},e.gamepadIndices),this.values={state:ii.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(A){if(this.values.state=ii.ComponentState.DEFAULT,this.gamepadIndices.button!==void 0&&A.buttons.length>this.gamepadIndices.button){const e=A.buttons[this.gamepadIndices.button];this.values.button=e.value,this.values.button=this.values.button<0?0:this.values.button,this.values.button=this.values.button>1?1:this.values.button,e.pressed||this.values.button===1?this.values.state=ii.ComponentState.PRESSED:(e.touched||this.values.button>ii.ButtonTouchThreshold)&&(this.values.state=ii.ComponentState.TOUCHED)}this.gamepadIndices.xAxis!==void 0&&A.axes.length>this.gamepadIndices.xAxis&&(this.values.xAxis=A.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===ii.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>ii.AxisTouchThreshold&&(this.values.state=ii.ComponentState.TOUCHED)),this.gamepadIndices.yAxis!==void 0&&A.axes.length>this.gamepadIndices.yAxis&&(this.values.yAxis=A.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===ii.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>ii.AxisTouchThreshold&&(this.values.state=ii.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(e=>{e.updateFromComponent(this.values)})}}class g7{constructor(A,e,t){if(!A)throw new Error("No xrInputSource supplied");if(!e)throw new Error("No profile supplied");this.xrInputSource=A,this.assetUrl=t,this.id=e.profileId,this.layoutDescription=e.layouts[A.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(g=>{const I=this.layoutDescription.components[g];this.components[g]=new i7(g,I)}),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const A=[];return Object.values(this.components).forEach(e=>{A.push(e.data)}),A}updateFromGamepad(){Object.values(this.components).forEach(A=>{A.updateFromGamepad(this.xrInputSource.gamepad)})}}const I7="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",o7="generic-trigger";class C7 extends UA{constructor(){super(),this.motionController=null,this.envMap=null}setEnvironmentMap(A){return this.envMap==A?this:(this.envMap=A,this.traverse(e=>{e.isMesh&&(e.material.envMap=this.envMap,e.material.needsUpdate=!0)}),this)}updateMatrixWorld(A){super.updateMatrixWorld(A),this.motionController&&(this.motionController.updateFromGamepad(),Object.values(this.motionController.components).forEach(e=>{Object.values(e.visualResponses).forEach(t=>{const{valueNode:g,minNode:I,maxNode:o,value:C,valueNodeProperty:s}=t;g&&(s===ii.VisualResponseProperty.VISIBILITY?g.visible=C:s===ii.VisualResponseProperty.TRANSFORM&&(g.quaternion.slerpQuaternions(I.quaternion,o.quaternion,C),g.position.lerpVectors(I.position,o.position,C)))})}))}}function s7(i,A){Object.values(i.components).forEach(e=>{const{type:t,touchPointNodeName:g,visualResponses:I}=e;if(t===ii.ComponentType.TOUCHPAD)if(e.touchPointNode=A.getObjectByName(g),e.touchPointNode){const o=new $I(.001),C=new wt({color:255}),s=new pA(o,C);e.touchPointNode.add(s)}else console.warn(`Could not find touch dot, ${e.touchPointNodeName}, in touchpad component ${e.id}`);Object.values(I).forEach(o=>{const{valueNodeName:C,minNodeName:s,maxNodeName:n,valueNodeProperty:a}=o;if(a===ii.VisualResponseProperty.TRANSFORM){if(o.minNode=A.getObjectByName(s),o.maxNode=A.getObjectByName(n),!o.minNode){console.warn(`Could not find ${s} in the model`);return}if(!o.maxNode){console.warn(`Could not find ${n} in the model`);return}}o.valueNode=A.getObjectByName(C),o.valueNode||console.warn(`Could not find ${C} in the model`)})})}function MJ(i,A){s7(i.motionController,A),i.envMap&&A.traverse(e=>{e.isMesh&&(e.material.envMap=i.envMap,e.material.needsUpdate=!0)}),i.layers.mask!=0&&A.traverse(e=>{e.layers.mask=i.layers.mask}),i.add(A)}class n7{constructor(A=null){this.gltfLoader=A,this.path=I7,this._assetCache={},this.gltfLoader||(this.gltfLoader=new kE)}createControllerModel(A){const e=new C7;let t=null;return A.addEventListener("connected",g=>{const I=g.data;I.targetRayMode!=="tracked-pointer"||!I.gamepad||$6(I,this.path,o7).then(({profile:o,assetPath:C})=>{e.motionController=new g7(I,o,C);const s=this._assetCache[e.motionController.assetUrl];if(s)t=s.scene.clone(),MJ(e,t);else{if(!this.gltfLoader)throw new Error("GLTFLoader not set.");this.gltfLoader.setPath(""),this.gltfLoader.load(e.motionController.assetUrl,n=>{this._assetCache[e.motionController.assetUrl]=n,t=n.scene.clone(),MJ(e,t)},null,()=>{throw new Error(`Asset ${e.motionController.assetUrl} missing or malformed.`)})}}).catch(o=>{console.warn(o)})}),A.addEventListener("disconnected",()=>{e.motionController=null,e.remove(t),t=null}),e}}const Nc=nA("debugavatar");class xw{constructor(A,e,t,g){r(this,"root");r(this,"head");r(this,"leftHand");r(this,"rigthHand");var I;this.root=A,this.head=e,this.leftHand=t,this.rigthHand=g,(I=this.root)==null||I.traverse(o=>o.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class Yw{constructor(){r(this,"avatarRegistryUrl",null)}async getOrCreateNewAvatarInstance(A,e){if(!e)return console.error("Can not create avatar: failed to provide id or root object"),null;let t=null;if(typeof e=="string"){if(t=await this.loadAvatar(A,e),!t){const I=new WC;t=AA.instantiate(vQ(e,A.scene),I)}}else t=e;if(!t)return null;const g=this.findAvatar(t);return g.isValid?(Nc&&console.log("[Custom Avatar] valid config",e,Nc?g:""),g):(console.warn("[Custom Avatar] config isn't valid",e,Nc?g:""),null)}async loadAvatar(A,e){if(console.assert(e!=null&&typeof e=="string","Avatar id must not be null"),e.length<=0||!e)return null;if(Nc&&console.log("[Custom Avatar] "+e+", loading..."),e.endsWith(".glb")||(e+=".glb"),this.avatarRegistryUrl===null){const g=await fetch("./"+e);let I=null;if(g.ok){const C=await g.blob();C&&(I=await C.arrayBuffer())}if(!I&&(I=await Dm(e,e,0,"no url here go away",!0),!I))return null;const o=await sC().parseSync(A,I,null,0);return(o==null?void 0:o.scene)??null}const t=new kE;return Qd(t,A),new Promise((g,I)=>{const o=this.avatarRegistryUrl+"/"+e;t.load(o,async C=>{await sC().createBuiltinComponents(A,o,C,null,void 0),g(C.scene)},C=>{Nc&&console.log("[Custom Avatar] "+C.loaded/C.total*100+"% loaded of "+C.total/1024+"kB")},C=>{console.error("[Custom Avatar] Error when loading: "+C),g(null)})})}cacheModel(A,e){}findAvatar(A){const e=A;let t=e;t.children.length==1&&(t=A.children[0]);let g=this.findAvatarPart(t,["head"]);const I=this.findAvatarPart(t,["left","hand"]),o=this.findAvatarPart(t,["right","hand"]);if(!g){g=e;const s=new S;new Jg().setFromObject(g).getSize(s);const n=Math.max(s.x,s.y,s.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+n+" meters! Should be < 0.3m"),n>.3&&g.scale.multiplyScalar(1/n*.3)}return new xw(e,g,I,o)}findAvatarPart(A,e){const t=A.name.toLowerCase();let g=!0;for(const I of e){if(!g)break;t.indexOf(I)===-1&&(g=!1)}if(g)return A;if(A.children)for(const I of A.children){const o=this.findAvatarPart(I,e);if(o)return o}return null}handleCustomAvatarErrors(A){if(!A.ok)throw Error(A.statusText);return A}}const nQ=nA("debugflags");var Mi=(i=>(i[i.Never=0]="Never",i[i.Browser=1]="Browser",i[i.AR=2]="AR",i[i.VR=4]="VR",i[i.FirstPerson=8]="FirstPerson",i[i.ThirdPerson=16]="ThirdPerson",i[i.All=4294967295]="All",i))(Mi||{});const tF=class{constructor(){r(this,"Mask",17)}Has(A){return(this.Mask&A)!==0}Set(A){nQ&&console.warn("Set XR flag state to",A),this.Mask=A,lg.Apply()}Enable(A){this.Mask|=A,lg.Apply()}Disable(A){this.Mask&=~A,lg.Apply()}Toggle(A){this.Mask^=A,lg.Apply()}EnableAll(){this.Mask=-1,lg.Apply()}DisableAll(){this.Mask=0,lg.Apply()}};let Mo=tF;r(Mo,"Global",new tF);const MC=class extends MA{constructor(){super(...arguments);r(this,"visibleIn")}static Apply(){for(const e of this.registry)e.UpdateVisible(Mo.Global)}awake(){MC.registry.push(this)}onEnable(){MC.firstApply?this.UpdateVisible(Mo.Global):(MC.firstApply=!0,MC.Apply())}onDestroy(){const e=MC.registry.indexOf(this);e>=0&&MC.registry.splice(e,1)}get isOn(){return this.gameObject.visible}UpdateVisible(e=null){let t;const g=e;g&&typeof g=="number"&&(console.assert(typeof g=="number","XRFlag.UpdateVisible: state must be a number",g),nQ&&console.log(g),MC.buffer.Mask=g,e=MC.buffer);const I=e;if(I?(nQ&&console.warn(this.name,"use passed in mask",I.Mask,this.visibleIn),t=I.Has(this.visibleIn)):(nQ&&console.log(this.name,"use global mask"),Mo.Global.Has(this.visibleIn)),t!==void 0)if(t)nQ&&console.log(this.name,"is visible",this.gameObject.uuid),AA.setActive(this.gameObject,!0);else{if(nQ&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}};let lg=MC;r(lg,"registry",[]),r(lg,"firstApply"),r(lg,"buffer",new Mo);const jn=nA("debugavatar"),$o=class extends MA{constructor(){super(...arguments);r(this,"connectionId");r(this,"avatar")}static getAvatar(e){return e>=0&&e<$o.instances.length?$o.instances[e]:null}static onAvatarMarkerCreated(e){return $o._onNewAvatarMarkerAdded.push(e),e}static onAvatarMarkerDestroyed(e){return $o._onAvatarMarkerDestroyed.push(e),e}awake(){$o.instances.push(this),jn&&console.log(this);for(const e of $o._onNewAvatarMarkerAdded)e({avatarMarker:this,gameObject:this.gameObject})}onDestroy(){$o.instances.splice($o.instances.indexOf(this),1);for(const e of $o._onAvatarMarkerDestroyed)e({avatarMarker:this,gameObject:this.gameObject})}isLocalAvatar(){return this.connectionId===this.context.connection.connectionId}setVisible(e){this.avatar&&("setVisible"in this.avatar?this.avatar.setVisible(e):AA.setActive(this.avatar,e))}};let Ig=$o;r(Ig,"instances",[]),r(Ig,"_onNewAvatarMarkerAdded",[]),r(Ig,"_onAvatarMarkerDestroyed",[]);const Lh=class{constructor(A,e,t){r(this,"_isVisible",!0);r(this,"guid");r(this,"root",null);r(this,"head",null);r(this,"handLeft",null);r(this,"handRight",null);r(this,"lastUpdate",-1);r(this,"isLocalAvatar",!1);r(this,"flags",null);r(this,"headScale",new S(1,1,1));r(this,"handLeftScale",new S(1,1,1));r(this,"handRightScale",new S(1,1,1));r(this,"webxr");r(this,"lastAvatarId",null);r(this,"hasAvatarOverride",!1);r(this,"context");r(this,"avatarMarker",null);r(this,"_headTarget",new UA);r(this,"_handLeftTarget",new UA);r(this,"_handRightTarget",new UA);r(this,"_canInterpolate",!1);this.context=A,this.guid=e,this.webxr=t,this.setupCustomAvatar(this.webxr.defaultAvatar)}setVisible(A){this._isVisible=A,this.updateVisibility()}get isWebXRAvatar(){return!0}updateFlags(){if(!this.flags)return;let A=this.isLocalAvatar?Mi.FirstPerson:Mi.ThirdPerson;this.context.isInVR?A|=Mi.VR:this.context.isInAR?A|=Mi.AR:A|=Mi.Browser;for(const e of this.flags)e.gameObject.visible=!0,e.UpdateVisible(A)}async setAvatarOverride(A){return this.hasAvatarOverride=A!==null,this.hasAvatarOverride&&this.lastAvatarId!==A&&(this.lastAvatarId=A,A!=null&&A.length>0)?await this.setupCustomAvatar(A):null}tryUpdate(A,e){if(A.guid===this.guid&&(this.lastAvatarId!==A.avatarId&&A.avatarId&&A.avatarId.length>0&&(this.lastAvatarId=A.avatarId,this.setupCustomAvatar(A.avatarId)),this.lastUpdate=A.time,this.head)){const t=this.webxr.IsInAR?_C.Handheld:_C.Headset;let g=this.head;this.context.players.setPlayerView(A.guid,g,t),fI.markDirty(this.head),this._canInterpolate=!0;const I=this.isLocalAvatar?this.head:this._headTarget;if(I.position.set(A.position.x,A.position.y,A.position.z),I.quaternion.set(A.rotation.x,A.rotation.y,A.rotation.z,A.rotation.w),I.scale.set(A.scale,A.scale,A.scale),I.scale.multiply(this.headScale),this.handLeft){const o=this.isLocalAvatar?this.handLeft:this._handLeftTarget;o.position.set(A.posLeftHand.x,A.posLeftHand.y,A.posLeftHand.z),o.quaternion.set(A.rotLeftHand._x,A.rotLeftHand._y,A.rotLeftHand._z,A.rotLeftHand._w),o.quaternion.multiply(Lh.invertRotation),o.scale.set(A.scale,A.scale,A.scale),o.scale.multiply(this.handLeftScale),fI.markDirty(this.handLeft)}if(this.handRight){const o=this.isLocalAvatar?this.handRight:this._handRightTarget;o.position.set(A.posRightHand.x,A.posRightHand.y,A.posRightHand.z),o.quaternion.set(A.rotRightHand._x,A.rotRightHand._y,A.rotRightHand._z,A.rotRightHand._w),o.quaternion.multiply(Lh.invertRotation),o.scale.set(A.scale,A.scale,A.scale),o.scale.multiply(this.handRightScale),fI.markDirty(this.handRight)}}}update(){if(this.isLocalAvatar||!this._canInterpolate)return;const A=this.context.time.deltaTime/.1;this.head&&(this.head.position.lerp(this._headTarget.position,A),this.head.quaternion.slerp(this._headTarget.quaternion,A),this.head.scale.lerp(this._headTarget.scale,A)),this.handLeft&&this._handLeftTarget&&(this.handLeft.position.lerp(this._handLeftTarget.position,A),this.handLeft.quaternion.slerp(this._handLeftTarget.quaternion,A),this.handLeft.scale.lerp(this._handLeftTarget.scale,A)),this.handRight&&this._handRightTarget&&(this.handRight.position.lerp(this._handRightTarget.position,A),this.handRight.quaternion.slerp(this._handRightTarget.quaternion,A),this.handRight.scale.lerp(this._handRightTarget.scale,A))}destroy(){var A,e;jn&&console.log("Destroy avatar",this.guid),(A=this.root)==null||A.removeFromParent(),(e=this.avatarMarker)==null||e.destroy(),this.lastAvatarId=null,this.head&&tI.Remove(this.context,this.head)}updateVisibility(){const A=this.root;A&&AA.setActive(A,this._isVisible)}async setupCustomAvatar(A){var g,I,o;if(jn&&console.log("LOAD",A,this),!A||typeof A=="string"&&A.length<=0)return!1;this.head&&tI.Remove(this.context,this.head);const e=A;if((e==null?void 0:e.loadAssetAsync)!==void 0){await e.loadAssetAsync();const C=e.asset;AA.setActive(C,!1),A=AA.instantiate(C),AA.setActive(A,!0)}jn&&console.log(A);const t=await Lh.loader.getOrCreateNewAvatarInstance(this.context,A);if(jn&&console.log(t,t==null?void 0:t.isValid,this.lastAvatarId,A),t!=null&&t.isValid){if(this.root=t.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=AA.addNewComponent(this.root,Ig),this.avatarMarker.connectionId=this.guid,this.avatarMarker.avatar=this,this.head&&this.head!==t.head&&((g=this.head)==null||g.removeFromParent()),this.head=t.head,this.headScale.copy(this.head.scale),this.head&&!this.isLocalAvatar&&tI.Add(this.context,this.head,this.avatarMarker),t.leftHand&&((I=this.handLeft)==null||I.removeFromParent()),this.handLeft=t.leftHand??this.handLeft,this.handLeft?this.handLeftScale.copy(this.handLeft.scale):this.handLeftScale.set(1,1,1),t.rigthHand&&((o=this.handRight)==null||o.removeFromParent()),this.handRight=t.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(...AA.getComponentsInChildren(this.root,lg)),this.flags.length<=0&&this.head){const C=AA.addNewComponent(this.head,lg);C.visibleIn=Mi.ThirdPerson|Mi.VR,this.flags.push(C),jn&&console.log("Added flag to head: "+C.visibleIn,this.head.name)}return jn&&console.log("[Avatar], is Local? ",this.isLocalAvatar,this.root),this.updateFlags(),this.updateVisibility(),!0}else return jn&&console.warn("build avatar failed"),!1}};let xC=Lh;r(xC,"loader",new Yw),r(xC,"invertRotation",new kA().setFromAxisAngle(new S(0,1,0),Math.PI));class tI{static Add(A,e,t=null){if(e){for(const g of this.Pois)if(g.obj===e)return;this.Pois.push({obj:e,avatar:t}),this.LastChangeTime=A.time.time}}static Remove(A,e){var t;if(e){for(const g of this.Pois)if(g.obj===e){this.Pois.splice(this.Pois.indexOf(g),1),this.LastChangeTime=(A==null?void 0:A.time.time)??((t=qe.Current)==null?void 0:t.time.time);return}}}}r(tI,"Pois",[]),r(tI,"LastChangeTime",0);class a7{constructor(){r(this,"guid");r(this,"position",new S)}}class rl extends MA{constructor(){super(...arguments);r(this,"target",null);r(this,"avatar",null);r(this,"_model",null);r(this,"_targetModel",new a7);r(this,"_currentTargetObject",null);r(this,"_lastUpdateTime",0);r(this,"_lookDuration",0);r(this,"_lastPoiChangedTime",0)}set controlledTarget(e){this.target=e;const t=T.get("MoveRandom");if(t&&this.target){const g=AA.getComponent(this.target,t);g&&g.destroy()}}awake(){if(this.avatar=AA.getComponentInParent(this.gameObject,Ig),this.avatar){const e=AA.getComponentInParent(this.gameObject,Ig);this._model=new fw(this.context.connection,this.guid),e!=null&&e.isLocalAvatar&&this._model.requestOwnership()}this.context.connection.beginListen("avatar-look-target-changed",e=>{var t;this.target&&e&&e.guid===((t=this.avatar)==null?void 0:t.guid)&&di(this.target,e.position)})}update(){var t;if((!this.context.connection.isConnected||(t=this._model)!=null&&t.hasOwnership)&&(tI.LastChangeTime!==this._lastPoiChangedTime&&(this._lastPoiChangedTime=tI.LastChangeTime,this._lookDuration=0),this.selectTarget(),this._currentTargetObject&&this.context.time.frameCount%10===0&&this.target)){const g=ye(this._currentTargetObject);di(this.target,g),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(g))}}selectTarget(){if(this.context.time.time-this._lastUpdateTime>this._lookDuration){this._lastUpdateTime=this.context.time.time,this._lookDuration=Math.random()*.5+.2;const t=tI.Pois;if(t.length>0){const g=t[Math.floor(Math.random()*t.length)];if(g&&g.obj){if(g.avatar&&g.avatar===this.avatar)return;this._currentTargetObject=g.obj}}}}}class bE extends MA{constructor(){super(...arguments);r(this,"canGrab",!0)}onPointerClick(e){}}class LE extends MA{constructor(){super(...arguments);r(this,"isUsed",!0);r(this,"usedBy",null)}}var GC=(i=>(i[i.Average=0]="Average",i[i.Multiply=1]="Multiply",i[i.Minimum=2]="Minimum",i[i.Maximum=3]="Maximum",i))(GC||{}),Tw=(i=>(i[i.Discrete=0]="Discrete",i[i.Continuous=1]="Continuous",i))(Tw||{}),ai=(i=>(i[i.None=0]="None",i[i.FreezePositionX=2]="FreezePositionX",i[i.FreezePositionY=4]="FreezePositionY",i[i.FreezePositionZ=8]="FreezePositionZ",i[i.FreezePosition=14]="FreezePosition",i[i.FreezeRotationX=16]="FreezeRotationX",i[i.FreezeRotationY=32]="FreezeRotationY",i[i.FreezeRotationZ=64]="FreezeRotationZ",i[i.FreezeRotation=112]="FreezeRotation",i[i.FreezeAll=126]="FreezeAll",i))(ai||{}),DQ=(i=>(i[i.None=0]="None",i[i.X=2]="X",i[i.Y=4]="Y",i[i.Z=8]="Z",i[i.All=-1]="All",i))(DQ||{});const Ao=function(i,A){return function(e,t,g){r7(e,t,g,i,A)}};function r7(i,A,e,t,g){if(!(!g&&!t&&!i.onValidate)){if(e!==void 0){console.error("Invalid usage of validate decorator. Only fields can be validated.",i,A,e),mi("Invalid usage of validate decorator. Only fields can be validated. Property: "+A,oC.Error);return}if(i.__internalAwake){const I=Symbol(A),o=i.__internalAwake;i.__internalAwake=function(){this[I]===void 0&&(this[I]=this[A],Object.defineProperty(this,A,{set:function(C){var s;if(this[zk]===!0)this[I]=C;else{t==null||t.call(this,C);const n=this[I];this[I]=C,(s=this.onValidate)==null||s.call(this,A,n)}},get:function(){return g==null||g.call(this),this[I]}})),o.call(this)}}}}const B7=function(i){return function(A,e,t){const g=i.prototype,I=Object.getOwnPropertyDescriptor(g,e);if(!(I!=null&&I.value)){console.warn("Can not apply prefix: type does not have method named",e,i);return}const o=I.value,C=A[e];Object.defineProperty(g,e,{value:function(...s){const n=C==null?void 0:C.call(this,...s);if(n instanceof Promise){n.then(a=>{if(a!==!1)return o.call(this,...s)});return}if(n!==!1)return o.call(this,...s)}})}};var Q7=Object.defineProperty,E7=Object.getOwnPropertyDescriptor,ln=(i,A,e,t)=>{for(var g=t>1?void 0:t?E7(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&Q7(A,e,g),g};class c7{constructor(A,e){r(this,"positionChanged",!1);r(this,"rotationChanged",!1);r(this,"position");r(this,"quaternion");r(this,"_positionKeys",["x","y","z"]);r(this,"_quaternionKeys",["_x","_y","_z","_w"]);r(this,"mute",!1);r(this,"context");r(this,"obj");r(this,"_positionWatch");r(this,"_rotationWatch");this.context=e,this.obj=A}get isDirty(){return this.positionChanged||this.rotationChanged}reset(A=!1){if(this.positionChanged=!1,this.rotationChanged=!1,this.mute=!1,A){if(this.position)for(const e of this._positionKeys)delete this.position[e];if(this.quaternion)for(const e of this._quaternionKeys)delete this.quaternion[e]}}syncValues(){for(const A of this._positionKeys)this.position[A]=this.obj.position[A];for(const A of this._quaternionKeys)this.quaternion[A]=this.obj.quaternion[A]}applyValues(){if(this.positionChanged&&this.position)for(const A of this._positionKeys){const e=this.position[A];e!==void 0&&(this.obj.position[A]=e)}if(this.rotationChanged&&this.quaternion)for(const A of this._quaternionKeys){const e=this.quaternion[A];e!==void 0&&(this.obj.quaternion[A]=e)}}start(A,e){this.reset(),A&&(this._positionWatch||(this._positionWatch=new xQ(this.obj.position,["x","y","z"])),this._positionWatch.apply(),this.position={},this._positionWatch.subscribeWrite((I,o)=>{var s;if((s=this.context.physics.engine)!=null&&s.isUpdating||this.mute)return;const C=this.position[o];Math.abs(C-I)<1e-5||(this.position[o]=I,this.positionChanged=!0)})),e&&(this._rotationWatch||(this._rotationWatch=new xQ(this.obj.quaternion,["_x","_y","_z","_w"])),this._rotationWatch.apply(),this.quaternion={},this._rotationWatch.subscribeWrite((I,o)=>{var s;if((s=this.context.physics.engine)!=null&&s.isUpdating||this.mute)return;const C=this.quaternion[o];Math.abs(C-I)<1e-5||(this.quaternion[o]=I,this.rotationChanged=!0)}));const t=this.obj.matrixWorld.multiplyMatrices.bind(this.obj.matrixWorld),g=new NA;this.obj.matrixWorld.multiplyMatrices=(I,o)=>(g.equals(I)||(this.positionChanged=!0,this.rotationChanged=!0,g.copy(I)),t(I,o))}stop(){var A,e;(A=this._positionWatch)==null||A.revoke(),(e=this._rotationWatch)==null||e.revoke()}}var tk;const RG=(tk=class extends MA{constructor(){super(...arguments);r(this,"mass",1);r(this,"useGravity",!0);r(this,"constraints",ai.None);r(this,"isKinematic",!1);r(this,"drag",0);r(this,"angularDrag",1);r(this,"detectCollisions",!0);r(this,"sleepThreshold",.01);r(this,"collisionDetectionMode",Tw.Discrete);r(this,"_gravityScale",1);r(this,"_propertiesChanged",!1);r(this,"_currentVelocity",new S);r(this,"_smoothedVelocity",new S);r(this,"_smoothedVelocityGetter",new S);r(this,"_lastPosition",new S);r(this,"_watch")}get lockPositionX(){return(this.constraints&ai.FreezePositionX)!==0}get lockPositionY(){return(this.constraints&ai.FreezePositionY)!==0}get lockPositionZ(){return(this.constraints&ai.FreezePositionZ)!==0}get lockRotationX(){return(this.constraints&ai.FreezeRotationX)!==0}get lockRotationY(){return(this.constraints&ai.FreezeRotationY)!==0}get lockRotationZ(){return(this.constraints&ai.FreezeRotationZ)!==0}set lockPositionX(A){A?this.constraints|=ai.FreezePositionX:this.constraints&=~ai.FreezePositionX}set lockPositionY(A){A?this.constraints|=ai.FreezePositionY:this.constraints&=~ai.FreezePositionY}set lockPositionZ(A){A?this.constraints|=ai.FreezePositionZ:this.constraints&=~ai.FreezePositionZ}set lockRotationX(A){A?this.constraints|=ai.FreezeRotationX:this.constraints&=~ai.FreezeRotationX}set lockRotationY(A){A?this.constraints|=ai.FreezeRotationY:this.constraints&=~ai.FreezeRotationY}set lockRotationZ(A){A?this.constraints|=ai.FreezeRotationZ:this.constraints&=~ai.FreezeRotationZ}set gravityScale(A){this._gravityScale=A}get gravityScale(){return this._gravityScale}awake(){this._watch=void 0,this._propertiesChanged=!1}onEnable(){this._watch||(this._watch=new c7(this.gameObject,this.context)),this._watch.start(!0,!0),this.startCoroutine(this.beforePhysics(),ZI.LateUpdate)}onDisable(){var A,e;(A=this._watch)==null||A.stop(),(e=this.context.physics.engine)==null||e.removeBody(this)}onDestroy(){var A;(A=this.context.physics.engine)==null||A.removeBody(this)}onValidate(){this._propertiesChanged=!0}*beforePhysics(){var A,e,t,g;for(;;)this._propertiesChanged&&(this._propertiesChanged=!1,(A=this.context.physics.engine)==null||A.updateProperties(this)),(e=this._watch)!=null&&e.isDirty?(this._watch.mute=!0,this._watch.applyValues(),(t=this.context.physics.engine)==null||t.updateBody(this,this._watch.positionChanged,this._watch.rotationChanged),this._watch.reset()):(g=this._watch)==null||g.syncValues(),this.captureVelocity(),yield}teleport(A,e=!0){var t;(t=this._watch)==null||t.reset(!0),e?this.gameObject.position.set(A.x,A.y,A.z):this.setWorldPosition(A.x,A.y,A.z),this.resetForcesAndTorques(),this.resetVelocities()}resetForces(){var A;(A=this.context.physics.engine)==null||A.resetForces(this,!0)}resetTorques(){var A;(A=this.context.physics.engine)==null||A.resetTorques(this,!0)}resetVelocities(){this.setVelocity(0,0,0),this.setAngularVelocity(0,0,0)}resetForcesAndTorques(){this.resetForces(),this.resetTorques()}wakeUp(){var A;(A=this.context.physics.engine)==null||A.wakeup(this)}applyForce(A,e){var t;(t=this.context.physics.engine)==null||t.addForce(this,A,!0)}applyImpulse(A){var e;(e=this.context.physics.engine)==null||e.applyImpulse(this,A,!0)}setForce(A,e,t){var g,I;(g=this.context.physics.engine)==null||g.resetForces(this,!0),(I=this.context.physics.engine)==null||I.addForce(this,{x:A,y:e,z:t},!0)}getVelocity(){var e;const A=(e=this.context.physics.engine)==null?void 0:e.getLinearVelocity(this);return A?(this._currentVelocity.x=A.x,this._currentVelocity.y=A.y,this._currentVelocity.z=A.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setVelocity(A,e,t){var g,I;if(A instanceof S){const o=A;(g=this.context.physics.engine)==null||g.setLinearVelocity(this,o,!0);return}e===void 0||t===void 0||(I=this.context.physics.engine)==null||I.setLinearVelocity(this,{x:A,y:e,z:t},!0)}setAngularVelocity(A,e,t){var g,I;if(A instanceof S){const o=A;(g=this.context.physics.engine)==null||g.setAngularVelocity(this,o,!0);return}e===void 0||t===void 0||(I=this.context.physics.engine)==null||I.setAngularVelocity(this,{x:A,y:e,z:t},!0)}getAngularVelocity(){var e;const A=(e=this.context.physics.engine)==null?void 0:e.getAngularVelocity(this);return A?(this._currentVelocity.x=A.x,this._currentVelocity.y=A.y,this._currentVelocity.z=A.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setTorque(A,e,t){this.setAngularVelocity(A,e,t)}get smoothedVelocity(){return this._smoothedVelocityGetter.copy(this._smoothedVelocity),this._smoothedVelocityGetter.multiplyScalar(1/this.context.time.deltaTime)}setBodyFromGameObject(A=null){}captureVelocity(){const A=ye(this.gameObject);RG.tempPosition.copy(A);const e=A.sub(this._lastPosition);this._lastPosition.copy(RG.tempPosition),this._smoothedVelocity.lerp(e,this.context.time.deltaTime/.1)}},r(tk,"tempPosition",new S),tk);let Xt=RG;ln([Ao(),w()],Xt.prototype,"mass",2);ln([Ao(),w()],Xt.prototype,"useGravity",2);ln([Ao(),w()],Xt.prototype,"constraints",2);ln([Ao(),w()],Xt.prototype,"isKinematic",2);ln([Ao(),w()],Xt.prototype,"drag",2);ln([Ao(),w()],Xt.prototype,"angularDrag",2);ln([Ao(),w()],Xt.prototype,"detectCollisions",2);ln([Ao(),w()],Xt.prototype,"sleepThreshold",2);ln([Ao(),w()],Xt.prototype,"collisionDetectionMode",2);class jI{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}static sizeOf(){return 12}static createVec3(A,e,t,g){return A.prep(4,12),A.writeFloat32(g),A.writeFloat32(t),A.writeFloat32(e),A.offset()}}class _T{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}position(A){return(A||new jI).__init(this.bb_pos,this.bb)}rotation(A){return(A||new jI).__init(this.bb_pos+12,this.bb)}scale(A){return(A||new jI).__init(this.bb_pos+24,this.bb)}static sizeOf(){return 36}static createTransform(A,e,t,g,I,o,C,s,n,a){return A.prep(4,36),A.prep(4,12),A.writeFloat32(a),A.writeFloat32(n),A.writeFloat32(s),A.prep(4,12),A.writeFloat32(C),A.writeFloat32(o),A.writeFloat32(I),A.prep(4,12),A.writeFloat32(g),A.writeFloat32(t),A.writeFloat32(e),A.offset()}}class Ks{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsSyncedTransformModel(A,e){return(e||new Ks).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedTransformModel(A,e){return A.setPosition(A.position()+pw),(e||new Ks).__init(A.readInt32(A.position())+A.position(),A)}guid(A){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}fast(){const A=this.bb.__offset(this.bb_pos,6);return A?!!this.bb.readInt8(this.bb_pos+A):!1}transform(A){const e=this.bb.__offset(this.bb_pos,8);return e?(A||new _T).__init(this.bb_pos+e,this.bb):null}dontSave(){const A=this.bb.__offset(this.bb_pos,10);return A?!!this.bb.readInt8(this.bb_pos+A):!1}static startSyncedTransformModel(A){A.startObject(4)}static addGuid(A,e){A.addFieldOffset(0,e,0)}static addFast(A,e){A.addFieldInt8(1,+e,0)}static addTransform(A,e){A.addFieldStruct(2,e,0)}static addDontSave(A,e){A.addFieldInt8(3,+e,0)}static endSyncedTransformModel(A){return A.endObject()}static finishSyncedTransformModelBuffer(A,e){A.finish(e)}static finishSizePrefixedSyncedTransformModelBuffer(A,e){A.finish(e,void 0,!0)}}const Pn=nA("debugsync"),Bl="STRS";em(Bl,Ks.getRootAsSyncedTransformModel);const fC=new DE;function OT(i,A,e=!0){fC.clear();const t=fC.createString(i);Ks.startSyncedTransformModel(fC),Ks.addGuid(fC,t),Ks.addFast(fC,e);const g=A.worldPosition,I=A.worldEuler,o=A.gameObject.scale;Ks.addTransform(fC,_T.createTransform(fC,g.x,g.y,g.z,I.x,I.y,I.z,o.x,o.y,o.z));const C=Ks.endSyncedTransformModel(fC);return fC.finish(C,Bl),fC.asUint8Array()}class wa extends MA{constructor(){super(...arguments);r(this,"overridePhysics",!0);r(this,"interpolatePosition",!0);r(this,"interpolateRotation",!0);r(this,"fastMode",!1);r(this,"syncDestroy",!1);r(this,"_model",null);r(this,"_needsUpdate",!0);r(this,"rb",null);r(this,"_wasKinematic",!1);r(this,"_receivedDataBefore",!1);r(this,"_targetPosition");r(this,"_targetRotation");r(this,"_receivedFastUpdate",!1);r(this,"_shouldRequestOwnership",!1);r(this,"joinedRoomCallback",null);r(this,"receivedDataCallback",null);r(this,"tempEuler",new Fi);r(this,"receivedUpdate",!1);r(this,"lastWorldPos");r(this,"lastWorldRotation")}requestOwnership(){Pn&&console.log("Request ownership"),this._model?this._model.requestOwnership():(this._shouldRequestOwnership=!0,this._needsUpdate=!0)}hasOwnership(){var e;return((e=this._model)==null?void 0:e.hasOwnership)??void 0}isOwned(){var e;return(e=this._model)==null?void 0:e.isOwned}awake(){Pn&&console.log("new instance",this.guid,this),this._receivedDataBefore=!1,this._targetPosition=new S,this._targetRotation=new kA,this.lastWorldPos=new S,this.lastWorldRotation=new kA,this.rb=AA.getComponentInChildren(this.gameObject,Xt),this.rb&&(this._wasKinematic=this.rb.isKinematic),this.receivedUpdate=!0,this._model=new fw(this.context.connection,this.guid),this.context.connection.isConnected&&this.tryGetLastState(),this.joinedRoomCallback=this.tryGetLastState.bind(this),this.context.connection.beginListen(oi.JoinedRoom,this.joinedRoomCallback),this.receivedDataCallback=this.onReceivedData.bind(this),this.context.connection.beginListenBinary(Bl,this.receivedDataCallback)}onDestroy(){this.syncDestroy&&Ex(this.guid,this.context.connection),this._model=null,this.context.connection.stopListen(oi.JoinedRoom,this.joinedRoomCallback),this.context.connection.stopListenBinary(Bl,this.receivedDataCallback)}tryGetLastState(){const e=this.context.connection.tryGetState(this.guid);e&&this.onReceivedData(e)}onReceivedData(e){var t;if(!this.destroyed&&typeof e.guid=="function"&&e.guid()===this.guid){Pn&&console.log("new data",this.context.connection.connectionId,this.context.time.frameCount,this.guid,e),this.receivedUpdate=!0,this._receivedFastUpdate=e.fast();const g=e.transform();if(g){fI.markDirty(this.gameObject,!0);const I=g.position();I&&(this.interpolatePosition&&((t=this._targetPosition)==null||t.set(I.x(),I.y(),I.z())),(!this.interpolatePosition||!this._receivedDataBefore)&&this.setWorldPosition(I.x(),I.y(),I.z()));const o=g.rotation();o&&(this.tempEuler.set(o.x(),o.y(),o.z()),this.interpolateRotation&&this._targetRotation.setFromEuler(this.tempEuler),(!this.interpolateRotation||!this._receivedDataBefore)&&Cv(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){Pn&&console.log("no model or room",this.name,this.guid,this.context.connection.isInRoom);return}this._shouldRequestOwnership&&(this._shouldRequestOwnership=!1,this._model.requestOwnership());let e=this.worldPosition,t=this.worldQuaternion;if(this._model.isOwned&&!this.receivedUpdate){const o=e.distanceTo(this.lastWorldPos),C=t.angleTo(this.lastWorldRotation),s=this._model.hasOwnership||this.fastMode?1e-4:.001;(o>s||C>s)&&(this._model.hasOwnership?this._needsUpdate=!0:(Pn&&console.log(this.guid,"reset because not owned but",this.gameObject.name,this.lastWorldPos),this.worldPosition=this.lastWorldPos,e.copy(this.lastWorldPos),this.worldQuaternion=this.lastWorldRotation,t.copy(this.lastWorldRotation),fI.markDirty(this.gameObject,!0),this._needsUpdate=!1))}if(this._model&&!this._model.hasOwnership&&this._model.isOwned&&this._receivedDataBefore){const C=this._receivedFastUpdate||this.fastMode?.5:.3;let s=!1;if(this.interpolatePosition&&this._targetPosition){const n=this.worldPosition;n.lerp(this._targetPosition,C),this.worldPosition=n,s=!0}if(this.interpolateRotation&&this._targetRotation){const n=this.worldQuaternion;n.slerp(this._targetRotation,C),this.worldQuaternion=n,s=!0}s&&fI.markDirty(this.gameObject,!0)}if(this.receivedUpdate=!1,this.lastWorldPos.copy(e),this.lastWorldRotation.copy(t),!this._model)return;if(!this._model||this._model.hasOwnership===void 0||!this._model.hasOwnership){this.rb&&(this.rb.isKinematic=this._model.isOwned??!1,this.rb.setVelocity(0,0,0));return}this.rb&&(this._wasKinematic!==void 0&&(Pn&&console.log("reset kinematic",this.rb.name,this._wasKinematic),this.rb.isKinematic=this._wasKinematic),this.gameObject.position.distanceTo(new S(0,0,0))>1e3&&(Pn&&console.log("RESET",this.name),this.gameObject.position.set(0,1,0),this.rb.setVelocity(0,0,0)));const g=10,I=this.rb||this.fastMode;if(this._needsUpdate&&(this.context.time.frameCount%g===0||I)){Pn&&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=OT(this.guid,this,!!I);this.context.connection.sendBinary(o)}}}var CC={};CC.d=(i,A)=>{for(var e in A)CC.o(A,e)&&!CC.o(i,e)&&Object.defineProperty(i,e,{enumerable:!0,get:A[e]})};CC.o=(i,A)=>Object.prototype.hasOwnProperty.call(i,A);CC.r=i=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(i,"__esModule",{value:!0})};var Ji={};CC.d(Ji,{w8:()=>ht,cg:()=>n2,gO:()=>ll,wb:()=>jm,zV:()=>Wr,HS:()=>Dd,Ec:()=>oB,gF:()=>iE,ol:()=>ul,pz:()=>gH,tx:()=>Do,hj:()=>zm,FV:()=>Sd,sV:()=>OH,xv:()=>dl,mx:()=>eH,gE:()=>tH,ZP:()=>gtA,Vx:()=>a2});var jm={};CC.r(jm);CC.d(jm,{get:()=>PT,set:()=>h7});var zm={};CC.r(zm);CC.d(zm,{alphaTestTransformer:()=>_w,asPreprocessorValueTransformer:()=>IH,toPreprocessorTriggerTransformer:()=>oR,toUserDataTransformer:()=>k$,uniformOrUserDataTransformer:()=>uo});const UG={fontFamily:null,fontSize:.05,fontKerning:"normal",fontStyle:"normal",fontWeight:"400",offset:.005,lineHeight:1.2,lineBreak:`- ,.:?!
|
|
4180
4180
|
`,whiteSpace:"pre-line",flexDirection:"column",justifyContent:"start",alignItems:"start",backgroundImage:null,textAlign:"left",boxSizing:"content-box",position:"static",color:16777215,fontColor:16777215,fontOpacity:1,opacity:1,fontPXRange:4,fontSupersampling:!0,fontSmooth:"antialiased",borderRadius:0,borderWidth:0,borderColor:"black",borderOpacity:1,backgroundSize:"cover",backgroundColor:0,backgroundOpacity:0,overflow:"visible",letterSpacing:0,invertAlpha:!1,segments:1},h7=function(i){for(const A in i)UG[A]=i[A]},PT=function(i){return Object.prototype.hasOwnProperty.call(UG,i)||console.warn(`ThreeMeshUI::DefaultValues is trying to retrieve non-existing property '${i}'`),UG[i]};class ht{constructor(A,e=null,t=!0){this._id=A,this._value=e,this._needsUpdate=!0,this._needsProcess=!1,this._needsRender=!1,this._isPrimitive=t}get id(){return this._id}get value(){return this._value}set value(A){this.isValid(A)&&this._value!==A&&(this._value=A,this._needsUpdate=!0)}update(A,e){this.output(e)}output(A){}_outputValue(A){A[this._id]=this._value}process(A){}render(A){}getInheritedInput(A){if(this._value!=="inherit")return this._value;const e=A._parent._value;return e&&e[`_${this._id}`]?e[`_${this._id}`].getInheritedInput(e):this.getDefaultValue()}getDefaultValue(){return PT(this._id)}isValid(A){return!0}emptyStrategyLogic(){throw new Error(`ThreeMeshUI::${this.constructor.name} has empty strategy. Update has not been processed.`)}requestUpdate(){this._needsUpdate=!0}requestProcess(){this._needsProcess=!1}requestRender(){this._needsRender=!1}}class l7 extends ht{constructor(){super("renderOrder","auto",!0),this.output=this._outputValue,this._actualValue=0}set value(A){this.isValid(A)&&(this._value=A,this._needsUpdate=!0)}update(A,e){if(this._value!=="auto")this._actualValue=this._value;else{const t=A._parent._value;if(t!==null){const g=t._renderOrder._actualValue,I=1+t._children._uis.indexOf(A);this._actualValue=g+I}}for(const t of A._children._uis)t._renderOrder._value==="auto"&&(t._renderOrder._needsUpdate=!0);this._outputValue(e)}_outputValue(A){A[this._id]=this._actualValue}get value(){return this._value}}class oB extends ht{constructor(A,e=null,t=!0){super(A,e,t),this.output=this._outputValue,this._notInheritedValue=null}update(A,e){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(A)),this.propagate(A),this._outputValue(e)}propagate(A){for(const e of A._children._uis){const t=e[`_${this._id}`];t!==void 0&&t._value==="inherit"&&(e[`_${this._id}`]._needsUpdate=!0)}}_outputValue(A){A[this._id]=this._notInheritedValue}set value(A){this.isValid(A)&&this._value!==A&&(this._value=A,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class d7 extends oB{constructor(){super("offset","inherit",!1)}update(A,e){super.update(A,e),A._parent._value!==null&&(A.position.z=this._notInheritedValue)}}class u7 extends oB{constructor(){super("fontSmooth","inherit",!0),this._needsUpdate=!1,this.isValid=D7,this.output=this._outputValue}}const p7=["inherit","none","antialiased"];function D7(i){return p7.indexOf(i)===-1?(console.warn(`.fontSmoothing value '${i}' is not valid. Aborted`),!1):!0}var f7=i=>{var A={};return CC.d(A,i),A};const $A=f7({BackSide:()=>Hi,BufferAttribute:()=>Ce,BufferGeometry:()=>de,Color:()=>wA,DoubleSide:()=>Nt,EventDispatcher:()=>ji,FileLoader:()=>Oi,FrontSide:()=>gI,LinearFilter:()=>be,Mesh:()=>pA,Object3D:()=>UA,Plane:()=>fo,PlaneGeometry:()=>ng,ShaderMaterial:()=>Le,Texture:()=>Te,TextureLoader:()=>Ea,Vector2:()=>P,Vector3:()=>S,Vector4:()=>se});class Pt extends ht{constructor(A,e,t=!0){super(A,"unset",t),this._input="inherit",this._allowsInherit=!0,this._inheritedInput=void 0,this._inline=void 0}update(A,e){this._allowsInherit||(this._inheritedInput=this.getInheritedInput(A)),this.computeOutputValue(A);for(const t of A._children._uis){const g=t[`_${this._id}`];(g._input?g._input:g._value)==="inherit"&&(t[`_${this._id}`]._needsUpdate=!0)}this.output(e)}computeOutputValue(A){this._value=this._input}_computeFromInherited(A){this._value=this._inheritedInput}set value(A){console.warn(".(style) sub-property cannot be directly set. It must comes from inline or computed setter.")}set inline(A){this.isValidValue(A)&&A!==this._inline&&(this._input=this._inline=A,this._needsUpdate=!0)}get inline(){return this._inline}isValidValue(A){return!0}getInheritedInput(A){if(this._input!=="inherit")return this._input;const e=A._parent._value;return e?e[`_${this._id}`].getInheritedInput(e):this.getDefaultValue()}}class Hw extends Pt{constructor(A,e){super(A,e,!1),this._input=new $A.Vector4(0,0,0,0),this._inline=null,this._value=new $A.Vector4(0,0,0,0)}get value(){return this._value}computeOutputValue(A){this._vector4ValueSetter(this._value,this._input)}set inline(A){this._vector4ValueSetter(this._input,A),!this._input.equals(this._value)&&(this._needsUpdate=!0)}set top(A){this._input.x!==A&&(this._input.x=A,this._needsUpdate=!0)}get top(){return this._input.x}set right(A){this._input.y!==A&&(this._input.y=A,this._needsUpdate=!0)}get right(){return this._input.y}set bottom(A){this._input.z!==A&&(this._input.z=A,this._needsUpdate=!0)}get bottom(){return this._input.z}set left(A){this._input.w!==A&&(this._input.w=A,this._needsUpdate=!0)}get left(){return this._input.w}dispose(){this._computed=null,this._inline=null,this._input=null,this._output=null}_vector4ValueSetter(A,e){if(e instanceof $A.Vector4){A.copy(e);return}if((typeof e=="string"||e instanceof String)&&(e=e.split(" ")),Array.isArray(e))switch(e=e.map(t=>parseFloat(t)),e.length){case 1:A.setScalar(e[0]);return;case 2:A.x=A.z=e[0],A.y=A.w=e[1];return;case 3:A.x=e[0],A.y=e[1],A.z=e[2];return;case 4:A.x=e[0],A.y=e[1],A.z=e[2],A.w=e[3];return;default:console.error("StyleVector4Property::set() Four Dimension property had more than four values");return}isNaN(e)||A.setScalar(e)}}class w7 extends Hw{constructor(){super("padding",new $A.Vector4(0,0,0,0))}computeOutputValue(A){super.computeOutputValue(A),A._bounds._needsUpdate=!0,A._bounds._needsRender=!0,A._layouter._needsProcess=!0,A._renderer._needsRender=!0,A._parent._value&&(A._parent._value._layouter._needsProcess=!0)}}class y7 extends Hw{constructor(){super("margin",new $A.Vector4(0,0,0,0))}computeOutputValue(A){super.computeOutputValue(A),A._renderer._needsRender=!0,A._parent._value&&(A._parent._value._flexDirection._needsProcess=!0)}}const mJ=function(i,A,e){i[A]=e},S7=function(i,A,e){e!==null&&(i[A]=e)};class sp{constructor(A){this._definition=A}set definition(A){this._definition=A}mediate(A,e,t,g=null){for(const I in this._definition){const o=this._definition[I];if(t[I]!==void 0){const C=o.t?o.t:mJ;C(e,o.m,t[I]),g&&C(g,o.m,t[I])}}}static mediate(A,e,t,g,I=null){if(e)for(const o in g){const C=g[o];if(t[o]!==void 0){const s=C.t?C.t:mJ;s(e,C.m,t[o]),I&&s(I,C.m,t[o])}}}}class k7 extends ht{constructor(){super("parent",null,!1)}update(A,e){A.parent&&A.parent.isUI?this._value=A.parent:this._value=null}set value(A){console.warn("ParentProperty is readonly")}get value(){return this._value}find(A){return this._value?A(this._value)?this._value:this._value._parent.find(A):null}dispose(){this._value=null}}const FG=function(i,A,e=6){return i.toFixed(e)===A.toFixed(e)};class RJ extends ht{constructor(A,e){super(A,e,!0),this.output=this._outputValue}set value(A){this.isValid(A)&&(FG(this._value,A)||(this._value=A,this._needsUpdate=!0))}get value(){return this._value}}class UJ extends oB{constructor(A){super(A,"inherit",!0),this.isValid=M7}}const G7=[$A.FrontSide,$A.BackSide,$A.DoubleSide];function M7(i){return G7.indexOf(i)===-1?(console.warn(`SideProperty value '${i}' is not valid. Abort`),!1):!0}class m7 extends $A.EventDispatcher{constructor(A,e){super(),this._isReady=!1,this._weight=A,this._style=e,this._size=42,this._lineHeight=42,this._lineBase=42,this._font=null}get typographic(){return this._font}get isReady(){return this._isReady}get weight(){return this._weight}get style(){return this._style}get texture(){return this._texture}set fontMaterial(A){throw Error(`FontVariant('${this.id}')::fontMaterial - is abstract.`)}get fontMaterial(){throw Error(`FontVariant('${this.id}')::fontMaterial - is abstract.`)}get id(){return`${this._name}(w:${this.weight},s:${this.style})`}getTypographicGlyph(A){let e=this._chars[A];if(e)return e;if(A.match(/\s/))return this._chars[" "];const t=this._getFallbackCharacter(A);if(t&&(e=this._chars[t],e))return e;throw Error(`FontVariant('${this.id}')::getTypographicGlyph() - character('${A}') and/or fallback character were not found in provided msdf charset.`)}_getFallbackCharacter(A){throw new Error(`FontVariant(${typeof this})::_getFallbackCharacter() is abstract and should therefore be overridden.`)}getGeometricGlyph(A,e){throw new Error(`FontVariant(${typeof this})::getGeometryCharacter() is abstract and should therefore be overridden.`)}getKerningAmount(A){return this._kernings[A]?this._kernings[A]:0}adjustTypographicGlyphs(A){for(const e in A){const t=this.getTypographicGlyph(e),g=A[e];for(const I in g)t["_"+I]=A[e][I]}}_checkReadiness(){this._readyCondition()&&U7(this)}_alterElementProperties(A){throw new Error(`FontVariant(${typeof this})::_alterElementProperties() is abstract and should therefore be overridden.`)}_readyCondition(){throw new Error(`FontVariant(${typeof this})::_readyCondition() is abstract and should therefore be overridden.`)}}const R7={type:"ready"};function U7(i){i._isReady=!0,i.dispatchEvent(R7)}const Dd=m7;class F7 extends ht{constructor(A=null){super("font",A,!1),this._needsUpdate=!1,this._fontVariant=null,this._handleFontReadyClosure=null,this.isValid=N7}output(A){A[this._id]=this._fontVariant}update(A,e){if(this._fontVariant&&!this._fontVariant.isReady&&this._fontVariant.removeEventListener("ready",this._handleFontReadyClosure),this._value&&this._value instanceof Dd)this._fontVariant=this._value;else{const t=A._fontFamily._value;t&&(this._fontVariant=t.getVariant(A._fontWeight._value,A._fontStyle._value))}this._fontVariant&&(this._fontVariant._alterElementProperties(A),this._handleFontReadyClosure=K7(A,this),this._fontVariant.isReady?this._handleFontReadyClosure():this._fontVariant.addEventListener("ready",this._handleFontReadyClosure),(!A._fontMaterial._defaultMaterial||!(A._fontMaterial._defaultMaterial instanceof this._fontVariant.fontMaterial))&&(A._fontMaterial._defaultMaterial=new this._fontVariant.fontMaterial,A._fontMaterial._needsUpdate=!0))}set value(A){this.isValid(A)&&this._value!==A&&(this._value=A,this._needsUpdate=!0)}get value(){return this._value}get fontVariant(){return this._fontVariant}dispose(){this._handleFontReadyClosure&&(this._fontVariant.removeEventListener("ready",this._handleFontReadyClosure),this._handleFontReadyClosure=null),this._value=null,this._fontVariant=null}}function N7(i){return i instanceof Dd?!0:(console.warn(`.font value '${i}' is not valid. It requires a FontVariant instance. Aborted`),!1)}function K7(i,A){return function(){A._needsUpdate=!0,i._glyphs._needsProcess=!0,A._fontVariant.removeEventListener("ready",A._handleFontReadyClosure),A._handleFontReadyClosure=null}}class J7 extends Pt{constructor(A){super("display",A),this._value="flex",this._allowsInherit=!1,this._needsUpdate=!1,this.isValidValue=b7}computeOutputValue(A){A._visible._value=this._output!=="none"}}const q7=["none","flex"];function b7(i){return q7.indexOf(i)===-1?(console.warn(`(.style) display value '${i}' is not valid. Aborted`),!1):!0}class L7 extends Pt{constructor(A){super("boxSizing",A),this._allowsInherit=!1,this.isValidValue=x7}computeOutputValue(A){this._value=this._inheritedInput,A._bounds._needsUpdate=!0}}const v7=["border-box","content-box"];function x7(i){return v7.indexOf(i)===-1?(console.warn(`(.style) boxSizing value '${i}' is not valid. Aborted`),!1):!0}class Ql extends Pt{constructor(A,e){super(A,e,!1),this._value=new $A.Color,this.output=this._outputValue}computeOutputValue(A){this._input!=="inherit"&&this._value.set(this._input)}set inline(A){this._input=this._inline=A,this._needsUpdate=!0}}class p0 extends Pt{constructor(A,e){super(A,e,!0),this.isValidValue=Y7,this._allowsInherit=!1,this._input=e,this._value=e,this.output=this._outputValue,this.computeOutputValue=this._computeFromInherited}_outputValue(A){A[this._id]=this._inheritedInput}}function Y7(i){return i<0&&i>1?(console.warn(`(.style) styleFactorProperty('${this.id}') value '${i}' is not valid)`),!1):!0}class T7 extends Pt{constructor(A){super("backgroundImage",A,!0),this._input=null,this._allowsInherit=!1,this._textureSize=new $A.Vector2(1,1),this.isValidValue=H7}get value(){return this._value}output(A){A[this._id]=this._value,A.tSize=this._textureSize}computeOutputValue(A){if(this._value=this._inheritedInput,this._value instanceof $A.Texture&&!this._value.image){console.warn("ThreeMeshUI - .backgroundImage :: Please provide preloaded texture in order to have accurate sizing.");return}this._needsProcess=!0}process(A){this._value?this._textureSize.set(this._value.image.width,this._value.image.height):this._textureSize.set(1,1)}}function H7(i){return!0}class _7 extends Pt{constructor(A){super("backgroundSize",A,!0),this.isValidValue=P7,this.output=this._outputValue}}const O7=["cover","contain","stretch"];function P7(i){return O7.indexOf(i)===-1?(console.warn(`(.style) backgroundSize value '${i}' is not valid. Aborted`),!1):!0}class W7 extends Pt{constructor(A){super("overflow",A,!0),this.isValidValue=j7,this._clippingPlanes=null,this._renderStrategy=this._emptyRender}update(A,e){this._inline!==void 0&&this._inline!=="unset"?this._input=this._inline:this._computed!==void 0&&(this._input=this._computed),this._allowsInherit||(this._inheritedInput=this.getInheritedInput(A)),this.computeOutputValue(A);for(const t of A._children._uis)t._overflow._needsUpdate=!0;this.output(e)}output(A){A.clippingPlanes=this._clippingPlanes}computeOutputValue(A){super.computeOutputValue(A),this._value==="hidden"?this._renderStrategy=this._propagateRender:(this._renderStrategy=this._emptyRender,this._clippingPlanes=null);const e=A._parent._value;if(e!==null){const t=e._overflow;if((t._value==="hidden"||t._clippingPlanes!==null)&&!this._clippingPlanes){this._clippingPlanes=[new $A.Plane(new $A.Vector3(0,-1,0),1),new $A.Plane(new $A.Vector3(-1,0,0),1),new $A.Plane(new $A.Vector3(0,1,0),1),new $A.Plane(new $A.Vector3(1,0,0),1)];for(let g=0;g<this._clippingPlanes.length;g++)this._clippingPlanes[g].parent=e;t._clippingPlanes!==null&&this._clippingPlanes.push(...t._clippingPlanes),this._renderStrategy=this._hiddenRender,this._needsRender=!0}else(t._value==="visible"||t._clippingPlanes===null)&&this._clippingPlanes!==null&&(this._clippingPlanes=null,this._renderStrategy=this._emptyRender,this._needsRender=!0)}}render(A){this._renderStrategy(A)}_emptyRender(A){}_hiddenRender(A){const e=A._parent._value,t=e._bounds._offsetHeight,g=e._bounds._offsetWidth,I=e._padding._value,o=e._borderWidth._value;for(let C=0;C<4&&C<this._clippingPlanes.length;C++){const s=this._clippingPlanes[C];switch(C%4){case 0:s.constant=t/2-(I.x+o.x);break;case 1:s.constant=g/2-(I.y+o.y);break;case 2:s.constant=t/2-(I.z+o.z);break;case 3:s.constant=g/2-(I.w+o.w);break}s.applyMatrix4(e.matrixWorld)}for(let C=0;C<A._children._uis.length;C++){const s=A._children._uis[C];s._overflow._needsRender=!0}}_propagateRender(A){for(let e=0;e<A._children._uis.length;e++){const t=A._children._uis[e];t._overflow._needsRender=!0}}}const V7=["visible","hidden"];function j7(i){return V7.indexOf(i)===-1?(console.warn(`(.style) overflow value '${i}' is not valid. Aborted`),!1):!0}const eE="rem",WT="em",of="%",z7=[eE,WT,of],VT=function(i){return z7.indexOf(i)===-1?eE:i};class Z7 extends Hw{constructor(A){super("borderRadius",A),this._valueUV=this._value.clone(),this._input=new $A.Vector4(0,0,0,0),this._mediation=!0,this._cornerTL=new $A.Vector2(0,1),this._cornerTR=new $A.Vector2(1,1),this._cornerBR=new $A.Vector2(1,0),this._cornerBL=new $A.Vector2(0,0);const e=new np(this._valueUV,["x","y"]),t=new np(this._valueUV,["z","w"]),g=new np(this._valueUV,["x","w"]),I=new np(this._valueUV,["y","z"]);e.complementaryMediation=t,t.complementaryMediation=e,g.complementaryMediation=I,I.complementaryMediation=g,this._sideMediators=[e,t,g,I],this._units=eE}set units(A){this._units=VT(A),this._needsProcess=!0}get units(){return this._units}set mediation(A){A!==this._mediation&&(this._mediation=A,this._needsUpdate=!0)}get mediation(){return this._mediation}output(A){A.cornerTL=this._cornerTL,A.cornerTR=this._cornerTR,A.cornerBR=this._cornerBR,A.cornerBL=this._cornerBL}computeOutputValue(A){this._vector4ValueSetter(this._value,this._input),this._needsProcess=!0}process(A){this._needsRender=!0}render(A){this._valueUV.copy(this._value);const e=A._bounds._offsetWidth,t=A._bounds._offsetHeight;if(this._units===of&&this._valueUV.divideScalar(100),this._units===eE&&this._valueUV.divideScalar(Math.min(e,t)),this._mediation)do this._sideMediators.forEach(o=>o.computeValue()),this._sideMediators.sort((o,C)=>o.value<C.value?1:-1),this._sideMediators[0].value>1&&this._sideMediators[0].mediate();while(this._sideMediators[0].value>1);let g=e>t?t/e:1,I=e<t?e/t:1;this._units===of&&(g=I=1),this._cornerTL.x=this._valueUV.x*g,this._cornerTL.y=1-this._valueUV.x*I,this._cornerTR.x=1-this._valueUV.y*g,this._cornerTR.y=1-this._valueUV.y*I,this._cornerBR.x=1-this._valueUV.z*g,this._cornerBR.y=this._valueUV.z*I,this._cornerBL.x=this._valueUV.w*g,this._cornerBL.y=this._valueUV.w*I}dispose(){for(const A of this._sideMediators)A.dispose();this._sideMediators=null,this._cornerTL=null,this._cornerTR=null,this._cornerBR=null,this._cornerBL=null,super.dispose()}set topLeft(A){this._input.x!==A&&(this._input.x=A,this._needsUpdate=!0)}get topLeft(){return this._input.x}set topRight(A){this._input.y!==A&&(this._input.y=A,this._needsUpdate=!0)}get topRight(){return this._input.y}set bottomRight(A){this._input.z!==A&&(this._input.z=A,this._needsUpdate=!0)}get bottomRight(){return this._input.z}set bottomLeft(A){this._input.w!==A&&(this._input.w=A,this._needsUpdate=!0)}get bottomLeft(){return this._input.w}set top(A){this._input.x===A&&this._input.y===A||(this._input.x=this._input.y=A,this._needsUpdate=!0)}get top(){return(this._input.x+this._input.y)/2}set right(A){this._input.y===A&&this._input.z===A||(this._input.y=this._input.z=A,this._needsUpdate=!0)}get right(){return(this._input.y+this._input.z)/2}set bottom(A){this._input.z===A&&this._input.w===A||(this._input.z=this._input.w=A,this._needsUpdate=!0)}get bottom(){return(this._input.z+this._input.w)/2}set left(A){this._input.w===A&&this._input.x===A||(this._input.w=this._input.x=A,this._needsUpdate=!0)}get left(){return(this._input.w+this._input.x)/2}}class np{constructor(A,e){this._borderRadiuses=A,this._sideProperties=e,this._complementaryMediation=null,this._value=0}get value(){return this._value}set complementaryMediation(A){this._complementaryMediation=A}computeValue(){let A=0;for(const e of this._sideProperties)A+=this._borderRadiuses[e];this._value=A}mediate(A=!0){if(!(this._value<1)){for(const e of this._sideProperties)this._borderRadiuses[e]/=this._value;A&&this._complementaryMediation.mediate(!1)}}dispose(){this._complementaryMediation=null,this._borderRadiuses=null}}class X7 extends Hw{constructor(A){super("borderWidth",A,!1),this._valueUV=this._value.clone(),this.output=this._outputValue,this._units=eE}set units(A){this._units=VT(A),this._needsUpdate=!0}get units(){return this._units}computeOutputValue(A){this._vector4ValueSetter(this._value,this._input),this._needsProcess=!0,A._bounds._needsUpdate=!0,A._layouter._needsUpdate=!0}_outputValue(A){A[this._id]=this._valueUV}process(A){this._needsRender=!0,A._borderRadius._needsRender=!0}render(A){this._valueUV.copy(this._value);const e=A._bounds._offsetWidth,t=A._bounds._offsetHeight;if(this._units===of&&(console.log("Percent"),console.log(this._valueUV)),this._units===eE)e!==0&&(this._valueUV.w/=e,this._valueUV.y/=e),t!==0&&(this._valueUV.x/=t,this._valueUV.z/=t);else if(this._units===WT){if(e!==0){const g=e>t?t/e:1;this._valueUV.y*=g,this._valueUV.w*=g}if(t!==0){const g=e<t?e/t:1;this._valueUV.x*=g,this._valueUV.z*=g}}}}class $7 extends ht{constructor(A,e=!0){super("visible",e,!0),this._needsUpdate=!1}update(A,e){A.visible=this._value,A._parent._value&&(A._parent._value._children._needsUpdate=!0)}set value(A){this.isValid(A)&&this._value!==A&&(this._value=A,this._needsUpdate=!0)}get value(){return this._value}}class jT extends Ql{constructor(A){super("backgroundColor",A,!1),this._input="transparent",this._allowsInherit=!1}computeOutputValue(A){A._backgroundMesh.visible=!(this._input==="none"||this._input==="transparent"),this._input==="inherit"?this._value.set(this.getInheritedInput(A)):this._input==="transparent"||this._input==="none"||this._value.set(this._input)}}class Ds extends ht{constructor(A="untitled"){super(A,void 0,!1)}update(A,e){}output(A){}}class A$ extends ht{constructor(){super("inlineJustificator",null,!1),this._value=null}update(A,e){}process(A){const e=A._bounds._innerHeight,t=A._layouter._value,g=Math.abs(t.height);let I=(()=>{switch(A._alignItems._value){case"inherit":case"start":return e/2;case"end":return g-e/2;case"stretch":case"center":return g/2}})();const o=A._padding._value,C=A._borderWidth._value;I+=(-o.x+o.z)/2+(-C.x+C.z)/2,t.forEach(s=>{s.y+=I,s.forEach(n=>{n.offsetY+=I})})}}const e$=["start","center","end","stretch"],t$=function(i){return e$.indexOf(i)===-1?(console.warn(`(.style) alignItems value '${i}' is not valid. Aborted`),!1):!0};class Zm extends Pt{constructor(){super("alignItems","inherit",!0),this.isValidValue=t$}}class Xm extends Pt{constructor(){super("textAlign","inherit",!0),this.isValidValue=g$}}const i$=["left","right","center","justify","justify-left","justify-right","justify-center"],g$=function(i){return i$.indexOf(i)===-1?(console.warn(`(.style) textAlign value '${i}' is not valid. Aborted`),!1):!0};class $m extends Pt{constructor(){super("flexDirection","inherit",!0),this.isValid=o$}}const I$=["row","row-reverse","column","column-reverse"];function o$(i){return I$.indexOf(i)===-1?(console.warn(`(.style) flexDirection value '${i}' is not valid. Aborted`),!1):!0}class AR extends Pt{constructor(){super("justifyContent","inherit",!0),this.isValidValue=s$}}const C$=["start","center","end","space-between","space-around","space-evenly"];function s$(i){return C$.indexOf(i)===-1?(console.warn(`(.style) justifyContent value '${i}' is not valid. Aborted`),!1):!0}class n$ extends Pt{constructor(){super("order",0,!0),this._value=0,this._input=0,this._allowsInherit=!1}computeOutputValue(A){this._value=this._inheritedInput,A._parent._value&&(A._parent._value._children._needsProcess=!0)}}class zT extends Pt{constructor(){super("position","static",!0),this._allowsInherit=!1,this._value="static",this._needsUpdate=!1,this.computeOutputValue=this._computeFromInherited,this.isValidValue=r$}_computeFromInherited(A){super._computeFromInherited(A),A._parent._value&&(A._parent._value._children._needsProcess=!0)}}const a$=["static","absolute"];function r$(i){return a$.indexOf(i)===-1?(console.warn(`(.style) position value '${i}' is not valid. Aborted`),!1):!0}class ZT extends Pt{constructor(A,e=null){super(A,e,!0),this._input="auto",this._auto=!0,this._relative=!1,this._updateRequired=!0}set inline(A){this.isValidValue(A)&&A!==this._inline&&(this._inline=A,this._input!==this._inline&&this._parseInput())}get inline(){return this._inline}_parseInput(){let A=!0;if(this._inline!==void 0&&this._inline!=="unset"?this._input=this._inline:this._computed!==void 0?(this._computed===this._input&&(A=!1),this._input=this._computed):A=this._input==="inherit",A){if(this._auto=!this._input||this._input==="auto",this._auto)this._relative=!1;else if((typeof this._input=="string"||this._input instanceof String)&&this._input.endsWith("%")){this._relative=!0,this._value=0;const e=parseFloat(this._input.replace("%","").trim());isNaN(e)||(this._value=e/100)}else this._relative=!1,this._value=this._input;this._needsUpdate=this._updateRequired=A}}update(A,e){if(this._updateRequired){this._updateRequired=!1,this._allowsInherit||(this._inheritedInput=this.getInheritedInput(A)),this.computeOutputValue(A);for(const t of A._children._uis)t[`_${this._id}`]._needsUpdate=!0;this.output(e),A._parent._value&&(A._parent._value._layouter._needsProcess=!0)}}computeOutputValue(A){A._bounds._needsUpdate=!0,A._renderer._needsRender=!0}getInheritedInput(A){if(this._input!=="inherit"&&!this._auto)return this._input;const e=A._parent._value;return e?e[`_${this._id}`].getInheritedInput(e):this.getDefaultValue()}getDefaultValue(){return 0}get value(){return this._value}}class B$ extends ZT{constructor(){super("width")}}class Q$ extends ZT{constructor(){super("height")}computeOutputValue(A){super.computeOutputValue(A)}}class XT extends Ds{constructor(){super("textContent"),this._needsUpdate=!1}set value(A){}process(A){let e="";for(let t=0;t<A.children.length;t++){const g=A.children[t];g.isUI&&(e+=g.textContent)}this._value=e}}class $T extends Pt{constructor(A){super("fontStyle",A,!0),this.isValidValue=c$}}const E$=["normal","italic"];function c$(i){return E$.indexOf(i)===-1?(console.warn(`(.style) fontStyle value '${i}' is not valid. Aborted`),!1):!0}class AH extends Pt{constructor(){super("fontWeight","inherit",!0),this.isValid=l$}}const h$=["100","200","300","400","500","600","700","800","900","light","normal","bold","bolder"];function l$(i){return h$.indexOf(i.toString())===-1?(console.warn(`(.style) fontWeight value '${i}' is not valid. Aborted`),!1):!0}class eH{constructor(){this._size=42,this._lineHeight=42,this._lineBase=38,this._name="-",this._charset=""}get size(){return this._size}get lineHeight(){return this._lineHeight}get lineBase(){return this._lineBase}get name(){return this._name}get charset(){return this._charset}}class d$ extends eH{constructor(A){super(),this._size=A.info.size,this._lineHeight=A.common.lineHeight,this._lineBase=A.common.base,this._name=A.info.face,this._textureWidth=A.common.scaleW,this._textureHeight=A.common.scaleH,this._charset=A.chars.map(e=>e.char).join("")}get textureWidth(){return this._textureWidth}get textureHeight(){return this._textureHeight}}class tH{constructor(A){this._char="",this._width=1,this._heigth=1,this._xadvance=1,this._xoffset=0,this._yoffset=0,this._font=A}get font(){return this._font}get char(){return this._char}get width(){return this._width}get height(){return this._heigth}get xadvance(){return this._xadvance}get xoffset(){return this._xoffset}get yoffset(){return this._yoffset}set yoffset(A){this._yoffset=A}clone(A){throw new Error("Abstract... Need to be implemented")}asInlineGlyph(){throw new Error("Abstract... Need to be implemented")}}class iH{constructor(){this._offsetX=0,this._offsetY=0,this._lineBreak=null,this._kerning=0,this._fontFactor=1,this._fontSize=0,this._cumulativeWidth=0,this._paddingLeft=0,this._paddingRight=0,this._marginLeft=0,this._marginRight=0}resetOffsets(){this._offsetX=this._offsetY=0,this._cumulativeWidth=0}get xadvance(){return 0}get xoffset(){return 0}get yoffset(){return 0}get width(){return 0}get height(){return 0}set lineBreak(A){this._lineBreak=A}get lineBreak(){return this._lineBreak}get anchor(){return 0}get kerning(){return this._kerning*this._fontFactor}set kerning(A){this._kerning=A}get fontSize(){return this._fontSize}set fontSize(A){this._fontSize=A}get lineHeight(){return 0}get offsetX(){return this._offsetX}set offsetX(A){this._offsetX=A}get offsetY(){return this._offsetY}set offsetY(A){this._offsetY=A}get cumulativeWidth(){return this._cumulativeWidth}set cumulativeWidth(A){this._cumulativeWidth=A}get marginLeft(){return this._marginLeft}set marginLeft(A){this._marginLeft=A}get marginRight(){return this._marginRight}set marginRight(A){this._marginRight=A}get paddingLeft(){return this._paddingLeft}set paddingLeft(A){this._paddingLeft=A}get paddingRight(){return this._paddingRight}set paddingRight(A){this._paddingRight=A}get lineBase(){return 0}set fontFactor(A){this._fontFactor=A}get fontFactor(){return this._fontFactor}}class gH extends iH{constructor(A){super(),this._typographic=A}get typographic(){return this._typographic}get xadvance(){return this._typographic.xadvance*this._fontFactor}get xoffset(){return this._typographic.xoffset*this._fontFactor}get yoffset(){return this._typographic.yoffset*this._fontFactor}get width(){return this._typographic.width*this._fontFactor}get height(){return this._typographic.height*this._fontFactor}get char(){return this._typographic.char}get anchor(){return this.yoffset}get lineHeight(){return this._typographic.font.lineHeight*this._fontFactor}get lineBase(){return this._typographic.font.lineBase*this._fontFactor}}class u$ extends gH{constructor(A){super(A)}get uv(){return this.typographic.uv}}class Cf extends tH{constructor(A,e){super(A),this._char=e.char,this._width=e.width,this._heigth=e.height,this._xadvance=e.xadvance?e.xadvance:this._width,this._xoffset=e.xoffset?e.xoffset:0,this._yoffset=e.yoffset?e.yoffset:0,this._uv=e.uv?e.uv:null,isNaN(e.x)||(this._uv={left:e.x/A.textureWidth,right:(e.x+e.width)/A.textureWidth,top:1-(e.y+e.height)/A.textureHeight,bottom:1-e.y/A.textureHeight})}get uv(){return this._uv}clone(A){return new Cf(this._font,{char:A,width:this._width,height:this._heigth,xadvance:this._xadvance,xoffset:this._xoffset,yoffset:this._yoffset,uv:null})}asInlineGlyph(){return new u$(this)}}class p$ extends $A.PlaneGeometry{constructor(A,e){let t=1,g=1;const I=A.typographic.font.size,o=e._segments.value;t=Math.ceil(A.typographic.width/I*o),g=Math.ceil(A.typographic.height/I*o),super(A.width,A.height,t,g),A.uv?(this._mapUVs(A),this._transformGeometry(A)):(this._nullifyUVs(),this.scale(0,0,1),this.translate(0,A.fontSize/2,0)),this.name="GlyphGeometry"}_mapUVs(A){const e=A.uv.right-A.uv.left,t=A.uv.bottom-A.uv.top,g=this.getAttribute("uv").array.slice(),I=[];for(let o=0;o<g.length;o+=2){const C=g[o],s=g[o+1];I.push(A.uv.left+e*C),I.push(A.uv.top+t*s)}this.setAttribute("uvG",new $A.BufferAttribute(new Float32Array(I),2))}_nullifyUVs(){const A=[],e=this.getAttribute("uv").array.length;for(let t=0;t<e;t++)A.push(0);this.setAttribute("uvG",new $A.BufferAttribute(new Float32Array(A),2))}_transformGeometry(A){this.translate(A.width/2,-A.height/2,0)}}const D$=`
|
|
4181
4181
|
attribute vec2 uvG;
|
|
4182
4182
|
varying vec2 vUvG;
|
|
@@ -5435,7 +5435,7 @@ void main() {
|
|
|
5435
5435
|
// be blended onto the scene.
|
|
5436
5436
|
gl_FragColor = vec4(direct, max);
|
|
5437
5437
|
return;
|
|
5438
|
-
`)}}}applyShadowMaterial(){var t;const e=AA.getComponent(this.gameObject,_t);if(e)if(((t=e.sharedMaterial)==null?void 0:t.type)!=="ShadowMaterial"){const g=new qM;g.color=this.shadowColor,g.opacity=this.shadowColor.alpha,this.applyMaterialOptions(g),e.sharedMaterial=g}else{const g=e.sharedMaterial;g.color=this.shadowColor,g.opacity=this.shadowColor.alpha,this.applyMaterialOptions(g)}}applyOccluderMaterial(){const e=AA.getComponent(this.gameObject,_t);if(e){const t=e.sharedMaterial;t.depthWrite=!0,t.stencilWrite=!0,t.colorWrite=!1,this.gameObject.renderOrder=-100}}applyMaterialOptions(e){e&&(e.depthWrite=!1,e.stencilWrite=!1)}}V2([w()],Vd.prototype,"mode",2);V2([w(Gt)],Vd.prototype,"shadowColor",2);var PoA=Object.defineProperty,WoA=Object.getOwnPropertyDescriptor,wy=(i,A,e,t)=>{for(var g=t>1?void 0:t?WoA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&PoA(A,e,g),g},nk;const j2=(nk=class extends MA{constructor(){super(...arguments);r(this,"target",null);r(this,"followFactor",.1);r(this,"rotateFactor",.1);r(this,"positionAxes",DQ.All);r(this,"flipForward",!1);r(this,"_firstUpdate",!0)}onBeforeRender(){this.updateNow(!1)}updateNow(A){if(!(!this.target||this.target===this.gameObject)){if(this.followFactor>0){const e=ye(this.target),t=this._firstUpdate||A?1:ee.clamp01(this.context.time.deltaTime*this.followFactor),g=this.worldPosition;this.positionAxes&DQ.X&&(g.x=ee.lerp(g.x,e.x,t)),this.positionAxes&DQ.Y&&(g.y=ee.lerp(g.y,e.y,t)),this.positionAxes&DQ.Z&&(g.z=ee.lerp(g.z,e.z,t)),this.worldPosition=g}if(this.rotateFactor>0){const e=Pi(this.target);this.flipForward&&e.premultiply(j2._invertForward);const t=this._firstUpdate||A?1:ee.clamp01(this.context.time.deltaTime*this.rotateFactor);this.worldQuaternion=this.worldQuaternion.slerp(e,t)}this._firstUpdate=!1}}},r(nk,"_invertForward",new kA().setFromAxisAngle(new S(0,1,0),Math.PI)),nk);let Va=j2;wy([w(UA)],Va.prototype,"target",2);wy([w()],Va.prototype,"followFactor",2);wy([w()],Va.prototype,"rotateFactor",2);wy([w()],Va.prototype,"positionAxes",2);class VoA extends pA{constructor(A){const e=new joA(A),t=new ng(e.image.width*.001,e.image.height*.001),g=new wt({map:e,toneMapped:!1,transparent:!0});super(t,g);function I(o){g.map.dispatchDOMEvent(o)}this.addEventListener("mousedown",I),this.addEventListener("mousemove",I),this.addEventListener("mouseup",I),this.addEventListener("click",I),this.dispose=function(){t.dispose(),g.dispose(),g.map.dispose(),VG.delete(A),this.removeEventListener("mousedown",I),this.removeEventListener("mousemove",I),this.removeEventListener("mouseup",I),this.removeEventListener("click",I)}}}class joA extends pL{constructor(A){super(qq(A)),this.dom=A,this.anisotropy=16,this.encoding=pe,this.minFilter=be,this.magFilter=be;const e=new MutationObserver(()=>{this.scheduleUpdate||(this.scheduleUpdate=setTimeout(()=>this.update(),16))}),t={attributes:!0,childList:!0,subtree:!0,characterData:!0};e.observe(A,t),this.observer=e}dispatchDOMEvent(A){A.data&&zoA(this.dom,A.type,A.data.x,A.data.y)}update(){this.image=qq(this.dom),this.needsUpdate=!0,this.scheduleUpdate=null}dispose(){this.observer&&this.observer.disconnect(),this.scheduleUpdate=clearTimeout(this.scheduleUpdate),super.dispose()}}const VG=new WeakMap;function qq(i){const A=document.createRange(),e=new wA;function t(Q){const E=[];let c=!1;function h(){if(c&&(c=!1,Q.restore()),E.length===0)return;let l=-1/0,d=-1/0,p=1/0,u=1/0;for(let D=0;D<E.length;D++){const y=E[D];l=Math.max(l,y.x),d=Math.max(d,y.y),p=Math.min(p,y.x+y.width),u=Math.min(u,y.y+y.height)}Q.save(),Q.beginPath(),Q.rect(l,d,p-l,u-d),Q.clip(),c=!0}return{add:function(l){E.push(l),h()},remove:function(){E.pop(),h()}}}function g(Q,E,c,h){h!==""&&(Q.textTransform==="uppercase"&&(h=h.toUpperCase()),a.font=Q.fontWeight+" "+Q.fontSize+" "+Q.fontFamily,a.textBaseline="top",a.fillStyle=Q.color,a.fillText(h,E,c+parseFloat(Q.fontSize)*.1))}function I(Q,E,c,h,l){c<2*l&&(l=c/2),h<2*l&&(l=h/2),a.beginPath(),a.moveTo(Q+l,E),a.arcTo(Q+c,E,Q+c,E+h,l),a.arcTo(Q+c,E+h,Q,E+h,l),a.arcTo(Q,E+h,Q,E,l),a.arcTo(Q,E,Q+c,E,l),a.closePath()}function o(Q,E,c,h,l,d){const p=Q[E+"Width"],u=Q[E+"Style"],D=Q[E+"Color"];p!=="0px"&&u!=="none"&&D!=="transparent"&&D!=="rgba(0, 0, 0, 0)"&&(a.strokeStyle=D,a.lineWidth=parseFloat(p),a.beginPath(),a.moveTo(c,h),a.lineTo(c+l,h+d),a.stroke())}function C(Q,E){let c=0,h=0,l=0,d=0;if(Q.nodeType===Node.TEXT_NODE){A.selectNode(Q);const u=A.getBoundingClientRect();c=u.left-s.left-.5,h=u.top-s.top-.5,l=u.width,d=u.height,g(E,c,h,Q.nodeValue.trim())}else{if(Q.nodeType===Node.COMMENT_NODE)return;if(Q instanceof HTMLCanvasElement){if(Q.style.display==="none")return;a.save();const u=window.devicePixelRatio;a.scale(1/u,1/u),a.drawImage(Q,0,0),a.restore()}else{if(Q.style.display==="none")return;const u=Q.getBoundingClientRect();c=u.left-s.left-.5,h=u.top-s.top-.5,l=u.width,d=u.height,E=window.getComputedStyle(Q),I(c,h,l,d,parseFloat(E.borderRadius));const D=E.backgroundColor;D!=="transparent"&&D!=="rgba(0, 0, 0, 0)"&&(a.fillStyle=D,a.fill());const y=["borderTop","borderLeft","borderBottom","borderRight"];let k=!0,R=null;for(const f of y){if(R!==null&&(k=E[f+"Width"]===E[R+"Width"]&&E[f+"Color"]===E[R+"Color"]&&E[f+"Style"]===E[R+"Style"]),k===!1)break;R=f}if(k===!0){const f=parseFloat(E.borderTopWidth);E.borderTopWidth!=="0px"&&E.borderTopStyle!=="none"&&E.borderTopColor!=="transparent"&&E.borderTopColor!=="rgba(0, 0, 0, 0)"&&(a.strokeStyle=E.borderTopColor,a.lineWidth=f,a.stroke())}else o(E,"borderTop",c,h,l,0),o(E,"borderLeft",c,h,0,d),o(E,"borderBottom",c,h+d,l,0),o(E,"borderRight",c+l,h,0,d);if(Q instanceof HTMLInputElement){let f=E.accentColor;(f===void 0||f==="auto")&&(f=E.color),e.set(f);const U=Math.sqrt(.299*e.r**2+.587*e.g**2+.114*e.b**2)<.5?"white":"#111111";if(Q.type==="radio"&&(I(c,h,l,d,d),a.fillStyle="white",a.strokeStyle=f,a.lineWidth=1,a.fill(),a.stroke(),Q.checked&&(I(c+2,h+2,l-4,d-4,d),a.fillStyle=f,a.strokeStyle=U,a.lineWidth=2,a.fill(),a.stroke())),Q.type==="checkbox"&&(I(c,h,l,d,2),a.fillStyle=Q.checked?f:"white",a.strokeStyle=Q.checked?U:f,a.lineWidth=1,a.stroke(),a.fill(),Q.checked)){const J=a.textAlign;a.textAlign="center";const H={color:U,fontFamily:E.fontFamily,fontSize:d+"px",fontWeight:"bold"};g(H,c+l/2,h,"✔"),a.textAlign=J}if(Q.type==="range"){const[J,H,Y]=["min","max","value"].map(_=>parseFloat(Q[_])),b=(Y-J)/(H-J)*(l-d);I(c,h+d/4,l,d/2,d/4),a.fillStyle=U,a.strokeStyle=f,a.lineWidth=1,a.fill(),a.stroke(),I(c,h+d/4,b+d/2,d/2,d/4),a.fillStyle=f,a.fill(),I(c+b,h,d,d,d/2),a.fillStyle=f,a.fill()}(Q.type==="color"||Q.type==="text"||Q.type==="number")&&(B.add({x:c,y:h,width:l,height:d}),g(E,c+parseInt(E.paddingLeft),h+parseInt(E.paddingTop),Q.value),B.remove())}}}const p=E.overflow==="auto"||E.overflow==="hidden";p&&B.add({x:c,y:h,width:l,height:d});for(let u=0;u<Q.childNodes.length;u++)C(Q.childNodes[u],E);p&&B.remove()}const s=i.getBoundingClientRect();let n=VG.get(i);n===void 0&&(n=document.createElement("canvas"),n.width=s.width,n.height=s.height,VG.set(i,n));const a=n.getContext("2d"),B=new t(a);return C(i),n}function zoA(i,A,e,t){const g={clientX:e*i.offsetWidth+i.offsetLeft,clientY:t*i.offsetHeight+i.offsetTop,view:i.ownerDocument.defaultView};window.dispatchEvent(new MouseEvent(A,g));const I=i.getBoundingClientRect();e=e*I.width+I.left,t=t*I.height+I.top;function o(C){if(C.nodeType!==Node.TEXT_NODE&&C.nodeType!==Node.COMMENT_NODE){const s=C.getBoundingClientRect();if(e>s.left&&e<s.right&&t>s.top&&t<s.bottom&&(C.dispatchEvent(new MouseEvent(A,g)),C instanceof HTMLInputElement&&C.type==="range"&&(A==="mousedown"||A==="click"))){const[n,a]=["min","max"].map(c=>parseFloat(C[c])),B=s.width,E=(e-s.x)/B;C.value=n+(a-n)*E,C.dispatchEvent(new InputEvent("input",{bubbles:!0}))}for(let n=0;n<C.childNodes.length;n++)o(C.childNodes[n])}}o(i)}const hD=new P,tQ={type:"",data:hD};class ZoA extends ko{constructor(A,e){super();const t=this,g=new uE,I=new NA,o=A.domElement;function C(Q){Q.stopPropagation();const E=A.domElement.getBoundingClientRect();hD.x=(Q.clientX-E.left)/E.width*2-1,hD.y=-(Q.clientY-E.top)/E.height*2+1,g.setFromCamera(hD,e);const c=g.intersectObjects(t.children,!1);if(c.length>0){const h=c[0],l=h.object,d=h.uv;tQ.type=Q.type,tQ.data.set(d.x,1-d.y),l.dispatchEvent(tQ)}}o.addEventListener("pointerdown",C),o.addEventListener("pointerup",C),o.addEventListener("pointermove",C),o.addEventListener("mousedown",C),o.addEventListener("mouseup",C),o.addEventListener("mousemove",C),o.addEventListener("click",C);const s={move:"mousemove",select:"click",selectstart:"mousedown",selectend:"mouseup"};function n(Q){const E=Q.target;I.identity().extractRotation(E.matrixWorld),g.ray.origin.setFromMatrixPosition(E.matrixWorld),g.ray.direction.set(0,0,-1).applyMatrix4(I);const c=g.intersectObjects(t.children,!1);if(c.length>0){const h=c[0],l=h.object,d=h.uv;tQ.type=s[Q.type],tQ.data.set(d.x,1-d.y),l.dispatchEvent(tQ)}}const a=A.xr.getController(0);a.addEventListener("move",n),a.addEventListener("select",n),a.addEventListener("selectstart",n),a.addEventListener("selectend",n);const B=A.xr.getController(1);B.addEventListener("move",n),B.addEventListener("select",n),B.addEventListener("selectstart",n),B.addEventListener("selectend",n)}}class rU extends MA{constructor(){super(...arguments);r(this,"id",null);r(this,"keepAspect",!1)}start(){if(!this.id||!this.context.mainCamera)return;const e=document.getElementById(this.id);if(!e){console.warn('Could not find element with id "'+this.id+'"');return}e.style.display="block",e.style.visibility="hidden";const t=new ZoA(this.context.renderer,this.context.mainCamera);this.gameObject.add(t);const g=new VoA(e);t.add(g),g.visible=!1,console.log(g);const I=g.material;I.transparent=!0,setTimeout(()=>{g.visible=!0;const o=rw(this.gameObject).clone();Bw(this.gameObject,0,0,0),this.gameObject.updateMatrixWorld();const C=new Jg;C.setFromObject(t),this.setWorldRotation(o.x,o.y,o.z);const s=C.max.x-C.min.x,n=C.max.y-C.min.y;if(this.keepAspect){const B=s/n;s>n?g.scale.set(1/s,1/n/B,1):g.scale.set(1/s*B,1/n,1)}else g.scale.set(1/s,1/n,1);const a=this.gameObject.scale;g.scale.multiply(a)},1)}}var XoA=Object.defineProperty,$oA=Object.getOwnPropertyDescriptor,jd=(i,A,e,t)=>{for(var g=t>1?void 0:t?$oA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&XoA(A,e,g),g};const Rh=nA("debugspatialtrigger"),bq=new Ko,Lq=new Ko;function ACA(i,A){return bq.mask=i,Lq.mask=A,bq.test(Lq)}class OC extends MA{constructor(){super(...arguments);r(this,"triggerMask",0);r(this,"onEnter");r(this,"onStay");r(this,"onExit");r(this,"currentIntersected",[]);r(this,"lastIntersected",[])}start(){Rh&&console.log(this.name,this.triggerMask,this)}update(){this.currentIntersected.length=0;for(const e of zd.triggers)ACA(e.triggerMask,this.triggerMask)&&e.test(this.gameObject)&&this.currentIntersected.push(e);for(let e=this.lastIntersected.length-1;e>=0;e--){const t=this.lastIntersected[e];this.currentIntersected.indexOf(t)<0&&(this.onExitTrigger(t),this.lastIntersected.splice(e,1))}for(const e of this.currentIntersected)this.lastIntersected.indexOf(e)<0&&this.onEnterTrigger(e),this.onStayTrigger(e);this.lastIntersected.length=0,this.lastIntersected.push(...this.currentIntersected)}onEnterTrigger(e){var t;Rh&&console.log("ENTER TRIGGER",this.name,e.name,this,e),e.raiseOnEnterEvent(this),(t=this.onEnter)==null||t.invoke(this,e)}onExitTrigger(e){var t;Rh&&console.log("EXIT TRIGGER",this.name,e.name,this,e),e.raiseOnExitEvent(this),(t=this.onExit)==null||t.invoke(this,e)}onStayTrigger(e){var t;e.raiseOnStayEvent(this),(t=this.onStay)==null||t.invoke(this,e)}}jd([w()],OC.prototype,"triggerMask",2);jd([w(yI)],OC.prototype,"onEnter",2);jd([w(yI)],OC.prototype,"onStay",2);jd([w(yI)],OC.prototype,"onExit",2);var ak;const lD=(ak=class extends MA{constructor(){super(...arguments);r(this,"triggerMask");r(this,"boxHelper")}start(){Rh&&console.log(this.name,this.triggerMask,this)}onEnable(){var A;lD.triggers.push(this),this.boxHelper||(this.boxHelper=AA.addNewComponent(this.gameObject,yo),(A=this.boxHelper)==null||A.showHelper(null,Rh))}onDisable(){lD.triggers.splice(lD.triggers.indexOf(this),1)}test(A){return this.boxHelper?this.boxHelper.isInBox(A)??!1:!1}raiseOnEnterEvent(A){AA.foreachComponent(this.gameObject,e=>{e!==A&&e instanceof OC&&e.onEnterTrigger(this)},!1)}raiseOnStayEvent(A){AA.foreachComponent(this.gameObject,e=>{e!==A&&e instanceof OC&&e.onStayTrigger(this)},!1)}raiseOnExitEvent(A){AA.foreachComponent(this.gameObject,e=>{e!==A&&e instanceof OC&&e.onExitTrigger(this)},!1)}},r(ak,"triggers",[]),ak);let zd=lD;jd([w()],zd.prototype,"triggerMask",2);var eCA=Object.defineProperty,tCA=Object.getOwnPropertyDescriptor,iCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?tCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&eCA(A,e,g),g};const OI=nA("debugspectator");class yy extends MA{constructor(){super(...arguments);r(this,"cam",null);r(this,"useKeys",!0);r(this,"_mode",0);r(this,"orbit",null);r(this,"_handler");r(this,"eventSub_WebXRRequestStartEvent",null);r(this,"eventSub_WebXRStartEvent",null);r(this,"eventSub_WebXREndEvent",null);r(this,"_debug");r(this,"_networking")}get mode(){return this._mode}set mode(e){this._mode=e}get isSpectating(){var e;return((e=this._handler)==null?void 0:e.currentTarget)!==void 0}isSpectatingUser(e){var t;return((t=this.target)==null?void 0:t.userId)===e}isFollowedBy(e){var t;return(t=this.followers)==null?void 0:t.includes(e)}get followers(){return this._networking.followers}stopSpectating(){if(this.context.isInXR){this.followSelf();return}this.target=void 0}get localId(){return this.context.connection.connectionId??"local"}set target(e){var t;if(this._handler){const g=(t=this._handler.currentTarget)==null?void 0:t.userId,I=this.context.players.getPlayerView(this.localId);e===void 0||this.context.isInXR===!1&&(I==null?void 0:I.currentObject)===e.currentObject?this._handler.currentTarget!==void 0&&(this._handler.disable(),AA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),this._networking.onSpectatedObjectChanged(e,g)):this._handler.currentTarget!==e&&(this._handler.set(e),AA.setActive(this.gameObject,!0),this.orbit&&(this.orbit.enabled=!1),this._networking.onSpectatedObjectChanged(e,g))}}get target(){var e;return(e=this._handler)==null?void 0:e.currentTarget}requestAllFollowMe(){this._networking.onRequestFollowMe()}get isSpectatingSelf(){var e,t;return this.isSpectating&&((e=this.target)==null?void 0:e.currentObject)===((t=this.context.players.getPlayerView(this.localId))==null?void 0:t.currentObject)}awake(){if(this._debug=new oCA(this.context,this),this._networking=new nCA(this.context,this),this._networking.awake(),AA.setActive(this.gameObject,!1),this.cam=AA.getComponent(this.gameObject,Ot),!this.cam){console.error("Spectator camera needs camera component",this);return}!this._handler&&this.cam&&(this._handler=new gCA(this.context,this.cam,this)),this.eventSub_WebXRRequestStartEvent=this.onXRSessionRequestStart.bind(this),this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Se.addEventListener(Ft.RequestVRSession,this.eventSub_WebXRRequestStartEvent),Se.addEventListener(Ft.XRStarted,this.eventSub_WebXRStartEvent),Se.addEventListener(Ft.XRStopped,this.eventSub_WebXREndEvent),this.orbit=AA.getComponent(this.context.mainCamera,un)}onDestroy(){var e;this.stopSpectating(),Se.removeEventListener(Ft.RequestVRSession,this.eventSub_WebXRStartEvent),Se.removeEventListener(Ft.XRStarted,this.eventSub_WebXRStartEvent),Se.removeEventListener(Ft.XRStopped,this.eventSub_WebXREndEvent),(e=this._handler)==null||e.destroy(),this._networking.destroy()}isSupportedPlatform(){const e=window.navigator.userAgent,t=/Windows|MacOS/.test(e),g=/Windows NT/.test(e)&&/Edg/.test(e)&&!/Win64/.test(e);return t&&!g}onXRSessionRequestStart(e){this.isSupportedPlatform()&&AA.setActive(this.gameObject,!0)}onXRSessionStart(e){this.isSupportedPlatform()&&(OI&&console.log(this.context.mainCamera),this.context.mainCamera&&this.followSelf())}onXRSessionEnded(e){var t,g;this.context.removeCamera(this.cam),AA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),(t=this._handler)==null||t.set(void 0),(g=this._handler)==null||g.disable(),this.isSpectatingSelf&&this.stopSpectating()}followSelf(){this.target=this.context.players.getPlayerView(this.context.connection.connectionId),this.target||(this.context.players.setPlayerView(this.localId,this.context.mainCamera,_C.Headset),this.target=this.context.players.getPlayerView(this.localId)),OI&&console.log("Follow self",this.target)}onAfterRender(){var n,a,B;if(!this.cam)return;const e=this.context.renderer,t=e.xr.enabled;if(!e.xr.isPresenting&&!((n=this._handler)!=null&&n.currentTarget))return;(a=this._handler)==null||a.update(this._mode);const g=e.getRenderTarget();let I=null;if(!g){if(!e.state.bindFramebuffer||!e.state.bindXRFramebuffer)return;I=e._framebuffer,e.state.bindXRFramebuffer(null)}this.setAvatarFlagsBeforeRender();const o=this.context.mainCameraComponent;if(o){const Q=o.backgroundColor;Q&&e.setClearColor(Q,Q.alpha),this.cam.backgroundColor=Q,this.cam.clearFlags=o.clearFlags,this.cam.nearClipPlane=o.nearClipPlane,this.cam.farClipPlane=o.farClipPlane}else e.setClearColor(new wA(1,1,1));e.setRenderTarget(null),e.xr.enabled=!1;const C=(B=this.cam)==null?void 0:B.cam;this.context.updateAspect(C);const s=e.xr.isPresenting;e.xr.isPresenting=!1,e.setSize(this.context.domWidth,this.context.domHeight),e.render(this.context.scene,C),e.xr.isPresenting=s,e.xr.enabled=t,g?e.setRenderTarget(g):e.state.bindXRFramebuffer(I),this.resetAvatarFlags()}setAvatarFlagsBeforeRender(){const e=this._mode===0;for(const t of Ig.instances)if(t.avatar&&"isLocalAvatar"in t.avatar){let g=Mi.All;this.isSpectatingSelf&&(g=e&&t.avatar.isLocalAvatar?Mi.FirstPerson:Mi.ThirdPerson);const I=t.avatar.flags;if(!I)continue;for(const o of I)o.UpdateVisible(g)}}resetAvatarFlags(){var e;for(const t of Ig.instances)if(t.avatar&&"flags"in t.avatar){const g=t.avatar.flags;if(!g)continue;for(const I of g)(e=t.avatar)!=null&&e.isLocalAvatar?I.UpdateVisible(Mi.FirstPerson):I.UpdateVisible(Mi.ThirdPerson)}}}iCA([w()],yy.prototype,"useKeys",2);class gCA{constructor(A,e,t){r(this,"context");r(this,"cam");r(this,"spectator");r(this,"follow");r(this,"target");r(this,"view");r(this,"currentObject");this.context=A,this.cam=e,this.spectator=t}get currentTarget(){return this.view}set(A){const e=A==null?void 0:A.currentObject;if(!e){this.spectator.stopSpectating();return}e!==this.currentObject&&(this.currentObject=e,this.view=A,this.follow||(this.follow=AA.addNewComponent(this.cam.gameObject,Va)),this.target||(this.target=new UA),e.add(this.target),this.follow.enabled=!0,this.follow.target=this.target,OI&&console.log("FOLLOW",e),this.context.isInXR?this.context.removeCamera(this.cam):this.context.setCurrentCamera(this.cam))}disable(){OI&&console.log("STOP FOLLOW",this.currentObject),this.view=void 0,this.currentObject=void 0,this.context.removeCamera(this.cam),this.follow&&(this.follow.enabled=!1)}destroy(){var A;(A=this.target)==null||A.removeFromParent(),this.follow&&AA.destroy(this.follow)}update(A){var g,I,o,C,s,n;if(((g=this.currentTarget)==null?void 0:g.isConnected)===!1||((I=this.currentTarget)==null?void 0:I.removed)===!0){OI&&console.log("Target disconnected or timeout",this.currentTarget),this.spectator.stopSpectating();return}this.currentTarget&&((o=this.currentTarget)==null?void 0:o.currentObject)!==this.currentObject&&(OI&&console.log("Target changed",this.currentObject,"to",this.currentTarget.currentObject),this.set(this.currentTarget));const e=this.context.mainCamera;e&&(this.cam.cam.near!==e.near||this.cam.cam.far!==e.far)&&(this.cam.cam.near=e.near,this.cam.cam.far=e.far,this.cam.cam.updateProjectionMatrix());const t=(C=this.follow)==null?void 0:C.target;if(!(!t||!this.follow)){switch(A){case 0:((s=this.view)==null?void 0:s.viewDevice)!==_C.Browser?(this.follow.followFactor=5,this.follow.rotateFactor=5):(this.follow.followFactor=50,this.follow.rotateFactor=50),t.position.set(0,0,0);break;case 1:this.follow.followFactor=3,this.follow.rotateFactor=2,t.position.set(0,.5,1.5);break}this.follow.flipForward=!1,((n=this.view)==null?void 0:n.viewDevice)!==_C.Browser?t.quaternion.copy(ICA):t.quaternion.identity()}}}const ICA=new kA().setFromAxisAngle(new S(0,1,0),Math.PI);class oCA{constructor(A,e){r(this,"context");r(this,"spectator");this.context=A,this.spectator=e,console.log("Click other avatars or cameras to follow them. Press ESC to exit spectator mode."),this.context.domElement.addEventListener("keydown",g=>{if(!this.spectator.useKeys)return;g.key==="Escape"&&this.spectator.stopSpectating()});let t=0;this.context.input.addEventListener(RC.PointerDown,g=>{t=this.context.time.time}),this.context.input.addEventListener(RC.PointerUp,g=>{const I=this.context.time.time-t;I>1?this.spectator.stopSpectating():this.context.input.getPointerClicked(0)&&I<.3&&this.trySelectObject()})}trySelectObject(){const A=new EC;A.setMask(16777215);const e=this.context.physics.raycast(A);if(OI&&console.log(...e),e!=null&&e.length)for(const t of e){if(t.distance<.2)continue;const g=t.object,I=AA.getComponentInParent(g,Ig),o=I==null?void 0:I.connectionId;if(o){const C=this.context.players.getPlayerView(o);this.spectator.target=C,OI&&console.log("spectate",o,I);break}}}}class CCA{constructor(A,e,t){r(this,"guid");r(this,"dontSave",!0);r(this,"targetUserId");r(this,"stoppedFollowing");this.guid=A,this.targetUserId=e,this.stoppedFollowing=t}}class sCA{constructor(A,e){r(this,"guid");r(this,"userId");this.guid=A.guid,this.userId=e}}class nCA{constructor(A,e){r(this,"followers",[]);r(this,"context");r(this,"spectator");r(this,"_followerEventMethod");r(this,"_requestFollowMethod");r(this,"_joinedRoomMethod");r(this,"_lastRequestFollowUser");r(this,"_enforceFollowInterval");this.context=A,this.spectator=e,this._followerEventMethod=this.onFollowerEvent.bind(this),this._requestFollowMethod=this.onRequestFollowEvent.bind(this),this._joinedRoomMethod=this.onUserJoinedRoom.bind(this)}awake(){this.context.connection.beginListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.beginListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.beginListen(oi.JoinedRoom,this._joinedRoomMethod),this.context.domElement.addEventListener("keydown",A=>{this.spectator.useKeys&&(A.key==="f"?this.onRequestFollowMe():A.key==="Escape"&&this.onRequestFollowMe(!0))})}destroy(){this.context.connection.stopListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.stopListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.stopListen(oi.JoinedRoom,this._joinedRoomMethod)}onSpectatedObjectChanged(A,e){if(OI&&console.log(this.context.connection.connectionId,"onSpectatedObjectChanged",A,e),this.context.connection.connectionId){const t=(A==null?void 0:A.userId)===void 0,g=t?e:A==null?void 0:A.userId,I=new CCA(this.context.connection.connectionId,g,t);this.context.connection.send("spectator-follower-changed",I)}}onRequestFollowMe(A=!1){if(OI&&console.log("Request follow",this.context.connection.connectionId),this.context.connection.connectionId){this.spectator.stopSpectating();const e=A?void 0:this.context.connection.connectionId,t=new sCA(this.spectator,e);this.context.connection.send("spectator-request-follow",t)}}onUserJoinedRoom(){nA("followme")&&this.onRequestFollowMe()}onFollowerEvent(A){const e=A.targetUserId,t=A.guid;if(OI&&console.log(A),e===this.context.connection.connectionId)if(A.stoppedFollowing){const g=this.followers.indexOf(t);g!==-1&&(this.followers.splice(g,1),this.removeDisconnectedFollowers(),console.log(t,"unfollows you",this.followers.length))}else this.followers.includes(t)||(this.followers.push(t),this.removeDisconnectedFollowers(),console.log(t,"follows you",this.followers.length))}removeDisconnectedFollowers(){for(let A=this.followers.length-1;A>=0;A--){const e=this.followers[A];this.context.connection.userIsInRoom(e)===!1&&this.followers.splice(A,1)}}onRequestFollowEvent(A){if(this._lastRequestFollowUser=A,A.userId===this.context.connection.connectionId)this.spectator.stopSpectating();else if(A.userId===void 0)this.spectator.stopSpectating();else{const e=this.context.players.getPlayerView(A.userId);if(e)this.spectator.target=e;else return OI&&console.warn("Could not find view",A.userId),this.enforceFollow(),!1}return!0}enforceFollow(){this._enforceFollowInterval||(this._enforceFollowInterval=setInterval(()=>{this._lastRequestFollowUser===void 0||this._lastRequestFollowUser.userId&&this.spectator.isFollowedBy(this._lastRequestFollowUser.userId)?(clearInterval(this._enforceFollowInterval),this._enforceFollowInterval=void 0):(OI&&console.log("REQUEST FOLLOW AGAIN",this._lastRequestFollowUser.userId),this.onRequestFollowEvent(this._lastRequestFollowUser))},1e3))}}var aCA=Object.defineProperty,rCA=Object.getOwnPropertyDescriptor,aI=(i,A,e,t)=>{for(var g=t>1?void 0:t?rCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&aCA(A,e,g),g};const jG=nA("debugspriterenderer"),BCA=nA("wireframe"),Jf=class{static getOrCreateGeometry(A){if(A._geometry)return A._geometry;if(A.guid&&Jf.cache[A.guid])return jG&&console.log("Take cached geometry for sprite",A.guid),Jf.cache[A.guid];const e=new de;A._geometry=e;const t=new Float32Array(A.triangles.length*3),g=new Float32Array(A.triangles.length*2);for(let I=0;I<A.triangles.length;I+=1){const o=A.triangles[I];t[I*3]=-A.vertices[o].x,t[I*3+1]=A.vertices[o].y,t[I*3+2]=0;const C=A.uv[o];g[I*2]=C.x,g[I*2+1]=1-C.y}return e.setAttribute("position",new Ce(t,3)),e.setAttribute("uv",new Ce(g,2)),A.guid&&(this.cache[A.guid]=e),jG&&console.log("Built sprite geometry",A,e),e}};let Uh=Jf;r(Uh,"cache",{});class kn{constructor(){r(this,"guid");r(this,"texture");r(this,"triangles");r(this,"uv");r(this,"vertices");r(this,"_geometry")}}aI([w()],kn.prototype,"guid",2);aI([w(Te)],kn.prototype,"texture",2);aI([JE()],kn.prototype,"triangles",2);aI([JE()],kn.prototype,"uv",2);aI([JE()],kn.prototype,"vertices",2);const O0=Symbol("spriteOwner");class Zd{constructor(){r(this,"sprites")}}aI([w(kn)],Zd.prototype,"sprites",2);class sc{constructor(){r(this,"spriteSheet");r(this,"index",0)}update(){if(!this.spriteSheet)return;const A=this.index;if(A<0||A>=this.spriteSheet.sprites.length)return;const e=this.spriteSheet.sprites[A];let t=e==null?void 0:e.texture;t&&(t.encoding=pe,t.minFilter==$e&&t.magFilter==$e&&(t.anisotropy=1),t.needsUpdate=!0)}}aI([w(Zd)],sc.prototype,"spriteSheet",2);aI([w()],sc.prototype,"index",2);class Cs extends MA{constructor(){super(...arguments);r(this,"drawMode",0);r(this,"size",{x:1,y:1});r(this,"color");r(this,"sharedMaterial");r(this,"_spriteSheet");r(this,"_currentSprite");r(this,"transparent",!0);r(this,"cutoutThreshold",0);r(this,"castShadows",!1)}get sprite(){return this._spriteSheet}set sprite(e){if(e!==this._spriteSheet)if(typeof e=="number"){const t=Math.floor(e);t===e&&(this.spriteIndex=t);return}else this._spriteSheet=e,this.updateSprite()}set spriteIndex(e){this._spriteSheet&&(this._spriteSheet.index=e,this.updateSprite())}get spriteIndex(){var e;return((e=this._spriteSheet)==null?void 0:e.index)??0}get spriteFrames(){var e,t;return((t=(e=this._spriteSheet)==null?void 0:e.spriteSheet)==null?void 0:t.sprites.length)??0}awake(){this._currentSprite=void 0,jG&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(){var t,g,I;if(!this.__didAwake||!((g=(t=this.sprite)==null?void 0:t.spriteSheet)!=null&&g.sprites))return;const e=this.sprite.spriteSheet.sprites[this.spriteIndex];if(this._currentSprite)this._currentSprite.geometry=Uh.getOrCreateGeometry(e),this._currentSprite.material.map=e.texture;else{const o=new wt({color:16777215,side:Nt});if(!o)return;if(BCA&&(o.wireframe=!0),this.color&&(o.color||(o.color=new wA),o.color.copy(this.color),o.opacity=this.color.alpha),o.transparent=!0,e.texture&&!o.wireframe){let C=e.texture;C[O0]!==void 0&&C[O0]!==this&&this.spriteFrames>1&&(C=e.texture=C.clone()),C[O0]=this,o.map=C}this.sharedMaterial=o,this._currentSprite=new pA(Uh.getOrCreateGeometry(e),o)}this._currentSprite.parent!==this.gameObject&&(this.drawMode===2&&this._currentSprite.scale.set(this.size.x,this.size.y,1),this.gameObject&&this.gameObject.add(this._currentSprite)),this._currentSprite&&this._currentSprite.layers.set(this.layer),this.sharedMaterial&&(this.sharedMaterial.alphaTest=this.cutoutThreshold,this.sharedMaterial.transparent=this.transparent),this._currentSprite.castShadow=this.castShadows,(I=this._spriteSheet)==null||I.update()}}aI([w()],Cs.prototype,"drawMode",2);aI([w(Gt)],Cs.prototype,"color",2);aI([w(Ke)],Cs.prototype,"sharedMaterial",2);aI([w(sc)],Cs.prototype,"sprite",1);aI([w()],Cs.prototype,"transparent",2);aI([w()],Cs.prototype,"cutoutThreshold",2);aI([w()],Cs.prototype,"castShadows",2);class FC{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsSyncedCameraModel(A,e){return(e||new FC).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedCameraModel(A,e){return A.setPosition(A.position()+pw),(e||new FC).__init(A.readInt32(A.position())+A.position(),A)}userId(A){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}guid(A){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,A):null}dontSave(){const A=this.bb.__offset(this.bb_pos,8);return A?!!this.bb.readInt8(this.bb_pos+A):!1}pos(A){const e=this.bb.__offset(this.bb_pos,10);return e?(A||new jI).__init(this.bb_pos+e,this.bb):null}rot(A){const e=this.bb.__offset(this.bb_pos,12);return e?(A||new jI).__init(this.bb_pos+e,this.bb):null}static startSyncedCameraModel(A){A.startObject(5)}static addUserId(A,e){A.addFieldOffset(0,e,0)}static addGuid(A,e){A.addFieldOffset(1,e,0)}static addDontSave(A,e){A.addFieldInt8(2,+e,0)}static addPos(A,e){A.addFieldStruct(3,e,0)}static addRot(A,e){A.addFieldStruct(4,e,0)}static endSyncedCameraModel(A){return A.endObject()}static finishSyncedCameraModelBuffer(A,e){A.finish(e)}static finishSizePrefixedSyncedCameraModelBuffer(A,e){A.finish(e,void 0,!0)}}var QCA=Object.defineProperty,ECA=Object.getOwnPropertyDescriptor,cCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?ECA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&QCA(A,e,g),g};const df="SCAM";em(df,FC.getRootAsSyncedCameraModel);const KI=new DE;class hCA{constructor(A,e){r(this,"userId");r(this,"guid");this.guid=e,this.userId=A}send(A,e){if(A){KI.clear();const t=KI.createString(this.guid),g=KI.createString(this.userId);FC.startSyncedCameraModel(KI),FC.addGuid(KI,t),FC.addUserId(KI,g);const I=ye(A),o=rw(A);FC.addPos(KI,jI.createVec3(KI,I.x,I.y,I.z)),FC.addRot(KI,jI.createVec3(KI,o.x,o.y,o.z));const C=FC.endSyncedCameraModel(KI);KI.finish(C,df),e.sendBinary(KI.asUint8Array())}}}var rk;const zG=(rk=class extends MA{constructor(){super(...arguments);r(this,"cameraPrefab",null);r(this,"_lastWorldPosition");r(this,"_lastWorldQuaternion");r(this,"_model",null);r(this,"_needsUpdate",!0);r(this,"_lastUpdateTime",0);r(this,"remoteCams",{});r(this,"userToCamMap",{});r(this,"_camTimeoutInSeconds",10);r(this,"_receiveCallback",null)}getCameraObject(A){const e=this.userToCamMap[A];return e?this.remoteCams[e].obj:null}async awake(){this._lastWorldPosition=this.worldPosition.clone(),this._lastWorldQuaternion=this.worldQuaternion.clone(),this.cameraPrefab&&("uri"in this.cameraPrefab&&(this.cameraPrefab=await this.cameraPrefab.instantiate(this.gameObject)),this.cameraPrefab&&"isObject3D"in this.cameraPrefab&&(this.cameraPrefab.visible=!1))}onEnable(){this._receiveCallback=this.context.connection.beginListenBinary(df,this.onReceivedRemoteCameraInfoBin.bind(this))}onDisable(){this.context.connection.stopListenBinary(df,this._receiveCallback)}update(){for(const g in this.remoteCams){const I=this.remoteCams[g],o=this.context.time.realtimeSinceStartup-I.lastUpdate;if(!I||o>this._camTimeoutInSeconds){console.log("Remote cam timeout",I,o),I!=null&&I.obj&&AA.destroy(I.obj),delete this.remoteCams[g],I&&delete this.userToCamMap[I.userId],zG.instances.push(I),this.context.players.removePlayerView(I.userId,_C.Browser);continue}}if(Se.IsInWebXR)return;const A=this.context.mainCamera;if(A===null){this.enabled=!1;return}if(!this.context.connection.isConnected||this.context.connection.connectionId===null)return;this._model===null&&(this._model=new hCA(this.context.connection.connectionId,this.context.connection.connectionId+"_camera"));const e=ye(A),t=Pi(A);(e.distanceTo(this._lastWorldPosition)>.001||t.angleTo(this._lastWorldQuaternion)>.01)&&(this._needsUpdate=!0),this._lastWorldPosition.copy(e),this._lastWorldQuaternion.copy(t),!((!this._needsUpdate||this.context.time.frameCount%2!==0)&&!(this.context.time.realtimeSinceStartup-this._lastUpdateTime>this._camTimeoutInSeconds*.5))&&(this._lastUpdateTime=this.context.time.realtimeSinceStartup,this._needsUpdate=!1,this._model.send(A,this.context.connection),this.context.isInXR||this.context.players.setPlayerView(this.context.connection.connectionId,A,_C.Browser))}onReceivedRemoteCameraInfoBin(A){const e=A.guid();if(!e)return;const t=A.userId();if(!t||!this.context.connection.userIsInRoom(t)||!this.cameraPrefab)return;let g=this.remoteCams[e];if(!g)if("isObject3D"in this.cameraPrefab){const s=new WC;s.context=this.context;const n=AA.instantiate(this.cameraPrefab,s);g=this.remoteCams[e]={obj:n,lastUpdate:this.context.time.realtimeSinceStartup,userId:t},g.obj.visible=!0,this.gameObject.add(n),this.userToCamMap[t]=e,zG.instances.push(g);const a=AA.getOrAddComponent(n,Ig);a.connectionId=t,a.avatar=n}else return;const I=g.obj;this.context.players.setPlayerView(t,I,_C.Browser),g.lastUpdate=this.context.time.realtimeSinceStartup,fI.markDirty(I);const o=A.pos();o&&zQ(I,o.x(),o.y(),o.z());const C=A.rot();C&&Bw(I,C.x(),C.y(),C.z())}},r(rk,"instances",[]),rk);let Sy=zG;cCA([w([UA,Cg])],Sy.prototype,"cameraPrefab",2);var lCA=Object.defineProperty,dCA=Object.getOwnPropertyDescriptor,Xd=(i,A,e,t)=>{for(var g=t>1?void 0:t?dCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&lCA(A,e,g),g};const P0="view",W0=nA("debugsyncedroom");class ja extends MA{constructor(){super(...arguments);r(this,"roomName");r(this,"urlParameterName","room");r(this,"joinRandomRoom",!0);r(this,"requireRoomParameter",!1);r(this,"autoRejoin",!0);r(this,"_roomPrefix");r(this,"_lastPingTime",0);r(this,"_lastRoomTime",-1)}get RoomPrefix(){return this._roomPrefix}awake(){W0&&console.log("Room",this.roomName,this.urlParameterName,this.joinRandomRoom,this.requireRoomParameter,this.autoRejoin),this._roomPrefix===void 0&&(this._roomPrefix=this.roomName,this.roomName="")}onEnable(){const e=nA(P0);if(e&&typeof e=="string"&&e.length>0){console.log("Join as viewer"),this.context.connection.joinRoom(e,!0);return}(this.joinRandomRoom||nA(this.urlParameterName))&&this.tryJoinRoom()}onDisable(){this.roomName&&this.roomName.length>0&&this.context.connection.leaveRoom(this.roomName)}tryJoinRandomRoom(){this.setRandomRoomUrlParameter(),this.tryJoinRoom()}tryJoinRoom(e=0){e===void 0&&(e=0);let t=!1;if(this.urlParameterName){const g=nA(this.urlParameterName);if(g&&typeof g=="string"){t=!0;const I=tb(g);this.roomName=I}else if(this.joinRandomRoom&&(console.log("No room name found in url, generating random one"),this.setRandomRoomUrlParameter(),e<1))return this.tryJoinRoom(e+1)}else this.joinRandomRoom&&(this.roomName===null||this.roomName===void 0||this.roomName.length<=0)&&(console.log("generate room name"),this.roomName=this.generateRoomName());return this.requireRoomParameter&&!t?(W0&&console.log('No required room parameter "'+this.urlParameterName+'" in url - will not connect to networking backend.'),!1):(this.context.connection.isConnected||this.context.connection.connect(),W0&&console.log("Join "+this.roomName),this._roomPrefix&&(this.roomName=this._roomPrefix+this.roomName),this.context.connection.joinRoom(this.roomName),!0)}update(){this.context.connection.isConnected&&(this.context.time.time-this._lastPingTime>3&&(this._lastPingTime=this.context.time.time,this.context.connection.sendPing()),this.context.connection.isInRoom&&(this._lastRoomTime=this.context.time.time)),this._lastRoomTime>0&&this.context.time.time-this._lastRoomTime>.3&&(this._lastRoomTime=-1,this.autoRejoin?(console.log("Disconnected from networking backend - attempt reconnecting now"),this.tryJoinRoom()):console.warn("You are not connected to a room anymore (possibly because the tab was inactive for too long and the server kicked you)"))}get currentRoomName(){const e=nA(P0);return e||nA(this.urlParameterName)}setRandomRoomUrlParameter(){const e=ql(),t=this.generateRoomName();nA(this.urlParameterName)?e.set(this.urlParameterName,t):e.append(this.urlParameterName,t),AM(t,e)}generateRoomName(){return eb()+"_"+Ab(100,999)}getViewOnlyUrl(){if(this.context.connection.isConnected&&this.context.connection.currentRoomViewId){const e=window.location.search,t=new URLSearchParams(e);return t.has(this.urlParameterName)&&t.delete(this.urlParameterName),t.set(P0,this.context.connection.currentRoomViewId),window.location.origin+window.location.pathname+"?"+t.toString()}return null}}Xd([w()],ja.prototype,"roomName",2);Xd([w()],ja.prototype,"urlParameterName",2);Xd([w()],ja.prototype,"joinRandomRoom",2);Xd([w()],ja.prototype,"requireRoomParameter",2);Xd([w()],ja.prototype,"autoRejoin",2);function uCA(){const i=nA("testwindowcount")||0;i&&i>0&&pCA(i)}function pCA(i){if(nA("testwindow"))return null;const A=new URL(window.location.href);Th(A.searchParams,If,1),Th(A.searchParams,"testwindow",1);const e=A.toString(),t=[];window.onbeforeunload=()=>{for(const s of t)s.close()};const g=.05,I=128;let o=0,C=0;for(let s=0;s<i;s++){o*I+I*.01>=window.innerWidth&&(C+=1,o=0);const n=o*(I*(1+g))+window.screenLeft,a=C*(I*(1+g))+window.screenTop+90+60*C;o+=1;const B=window.open(e,"test window "+s,`popup=yes width=${I} height=${I} top=${a} left=${n}`);if(!B){console.warn("Failed to open window");continue}t.push(B),B.onload=()=>{B.onbeforeunload=()=>{for(let Q=0;Q<t.length;Q++){const E=t[Q];E!==B&&E.close()}t.length=0}}}return t}class BU extends MA{awake(){uCA()}}class QU extends MA{constructor(){super(...arguments);r(this,"transformsPerFrame",10);r(this,"interval",0);r(this,"useFlatbuffers",!0);r(this,"builder",null);r(this,"models",null)}awake(){if(this.useFlatbuffers)this.context.connection.beginListenBinary(Bl,e=>{});else{this.models=[];for(let e=0;e<this.transformsPerFrame;e++)this.models.push(new z2(this.context.connection.connectionId+"_simulatedTransform_"+e,this))}}update(){if(this.context.connection.isConnected){if(this.useFlatbuffers){if(!this.context.connection.connectionId||this.context.time.frameCount%this.interval!==0)return;this.builder===null&&(this.builder=new DE(1024));const e=this.builder;for(let t=0;t<this.transformsPerFrame;t++){e.clear();const g=OT(this.context.connection.connectionId,this);this.context.connection.sendBinary(g)}}else if(this.models)for(let e=0;e<this.models.length;e++){const t=this.models[e];t.dontSave=!0,t.update(this,null),this.context.connection.send("TestSimulateUserData-"+e,t)}}}}class z2{constructor(A,e){r(this,"guid");r(this,"fast",!1);r(this,"position");r(this,"rotation");r(this,"velocity");r(this,"dontSave");this.guid=A,this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0,w:0},this.update(e,null)}isValid(){return this.fast!==void 0||this.position!==void 0||this.rotation!==void 0||this.velocity!==void 0}update(A,e){const t=A.worldPosition;this.position.x=t.x,this.position.y=t.y,this.position.z=t.z;const g=A.worldQuaternion;if(this.rotation.x=g.x,this.rotation.y=g.y,this.rotation.z=g.z,this.rotation.w=g.w,this.fast=!1,e){const I=e.getVelocity();this.velocity===void 0&&(this.velocity={x:0,y:0,z:0}),this.velocity.x=I.x,this.velocity.y=I.y,this.velocity.z=I.z}}}r(z2,"temp",new S);var DCA=Object.defineProperty,fCA=Object.getOwnPropertyDescriptor,nc=(i,A,e,t)=>{for(var g=t>1?void 0:t?fCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&DCA(A,e,g),g};class ss extends Yg{constructor(){super(...arguments);r(this,"offset");r(this,"rotation");r(this,"focusArea");r(this,"feather");r(this,"kernelSize");r(this,"resolutionScale")}get typeName(){return"TiltShiftEffect"}init(){this.offset.defaultValue=0,this.rotation.defaultValue=0,this.focusArea.defaultValue=.4,this.feather.defaultValue=.3,this.kernelSize.defaultValue=In.MEDIUM,this.resolutionScale.defaultValue=1/window.devicePixelRatio}onCreateEffect(){console.log(this);const e=new f5({kernelSize:In.VERY_LARGE});return this.offset.onValueChanged=t=>e.offset=t,this.rotation.onValueChanged=t=>e.rotation=t,this.focusArea.onValueChanged=t=>e.focusArea=t,this.feather.onValueChanged=t=>e.feather=t,this.kernelSize.onValueChanged=t=>e.blurPass.kernelSize=t,this.resolutionScale.onValueChanged=t=>e.resolution.scale=t/window.devicePixelRatio,e}}nc([w(Me)],ss.prototype,"offset",2);nc([w(Me)],ss.prototype,"rotation",2);nc([w(Me)],ss.prototype,"focusArea",2);nc([w(Me)],ss.prototype,"feather",2);nc([w(Me)],ss.prototype,"kernelSize",2);nc([w(Me)],ss.prototype,"resolutionScale",2);Yo("TiltShiftEffect",ss);var wCA=Object.defineProperty,yCA=Object.getOwnPropertyDescriptor,SCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?yCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&wCA(A,e,g),g};class $d extends Yg{constructor(){super(...arguments);r(this,"mode")}get typeName(){return"ToneMapping"}get isToneMapping(){return!0}init(){this.mode.defaultValue=$g}apply(){this.mode.onValueChanged=this._apply.bind(this),this._apply(this.mode.value)}unapply(){this.context.renderer.toneMapping=$g}_apply(e){switch(e){case 0:this.context.renderer.toneMapping=Oh;break;case 1:this.context.renderer.toneMapping=sM;break;case 2:this.context.renderer.toneMapping=nM;break}}}SCA([w(Me)],$d.prototype,"mode",2);Yo("Tonemapping",$d);const sr=new uE,hI=new S,Vn=new S,Yt=new kA,vq={X:new S(1,0,0),Y:new S(0,1,0),Z:new S(0,0,1)},V0={type:"change"},xq={type:"mouseDown"},Yq={type:"mouseUp",mode:null},Tq={type:"objectChange"};class kCA extends UA{constructor(A,e){super(),e===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),e=document),this.isTransformControls=!0,this.visible=!1,this.domElement=e,this.domElement.style.touchAction="none";const t=new FCA;this._gizmo=t,this.add(t);const g=new NCA;this._plane=g,this.add(g);const I=this;function o(p,u){let D=u;Object.defineProperty(I,p,{get:function(){return D!==void 0?D:u},set:function(y){D!==y&&(D=y,g[p]=y,t[p]=y,I.dispatchEvent({type:p+"-changed",value:y}),I.dispatchEvent(V0))}}),I[p]=u,g[p]=u,t[p]=u}o("camera",A),o("object",void 0),o("enabled",!0),o("axis",null),o("mode","translate"),o("translationSnap",null),o("rotationSnap",null),o("scaleSnap",null),o("space","world"),o("size",1),o("dragging",!1),o("showX",!0),o("showY",!0),o("showZ",!0);const C=new S,s=new S,n=new kA,a=new kA,B=new S,Q=new kA,E=new S,c=new S,h=new S,l=0,d=new S;o("worldPosition",C),o("worldPositionStart",s),o("worldQuaternion",n),o("worldQuaternionStart",a),o("cameraPosition",B),o("cameraQuaternion",Q),o("pointStart",E),o("pointEnd",c),o("rotationAxis",h),o("rotationAngle",l),o("eye",d),this._offset=new S,this._startNorm=new S,this._endNorm=new S,this._cameraScale=new S,this._parentPosition=new S,this._parentQuaternion=new kA,this._parentQuaternionInv=new kA,this._parentScale=new S,this._worldScaleStart=new S,this._worldQuaternionInv=new kA,this._worldScale=new S,this._positionStart=new S,this._quaternionStart=new kA,this._scaleStart=new S,this._getPointer=GCA.bind(this),this._onPointerDown=mCA.bind(this),this._onPointerHover=MCA.bind(this),this._onPointerMove=RCA.bind(this),this._onPointerUp=UCA.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){this.object!==void 0&&(this.object.updateMatrixWorld(),this.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(A){if(this.object===void 0||this.dragging===!0)return;sr.setFromCamera(A,this.camera);const e=j0(this._gizmo.picker[this.mode],sr);e?this.axis=e.object.name:this.axis=null}pointerDown(A){if(!(this.object===void 0||this.dragging===!0||A.button!==0)&&this.axis!==null){sr.setFromCamera(A,this.camera);const e=j0(this._plane,sr,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,xq.mode=this.mode,this.dispatchEvent(xq)}}pointerMove(A){const e=this.axis,t=this.mode,g=this.object;let I=this.space;if(t==="scale"?I="local":(e==="E"||e==="XYZE"||e==="XYZ")&&(I="world"),g===void 0||e===null||this.dragging===!1||A.button!==-1)return;sr.setFromCamera(A,this.camera);const o=j0(this._plane,sr,!0);if(o){if(this.pointEnd.copy(o.point).sub(this.worldPositionStart),t==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),I==="local"&&e!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),e.indexOf("X")===-1&&(this._offset.x=0),e.indexOf("Y")===-1&&(this._offset.y=0),e.indexOf("Z")===-1&&(this._offset.z=0),I==="local"&&e!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),g.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(I==="local"&&(g.position.applyQuaternion(Yt.copy(this._quaternionStart).invert()),e.search("X")!==-1&&(g.position.x=Math.round(g.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(g.position.y=Math.round(g.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(g.position.z=Math.round(g.position.z/this.translationSnap)*this.translationSnap),g.position.applyQuaternion(this._quaternionStart)),I==="world"&&(g.parent&&g.position.add(hI.setFromMatrixPosition(g.parent.matrixWorld)),e.search("X")!==-1&&(g.position.x=Math.round(g.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(g.position.y=Math.round(g.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(g.position.z=Math.round(g.position.z/this.translationSnap)*this.translationSnap),g.parent&&g.position.sub(hI.setFromMatrixPosition(g.parent.matrixWorld))));else if(t==="scale"){if(e.search("XYZ")!==-1){let C=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(C*=-1),Vn.set(C,C,C)}else hI.copy(this.pointStart),Vn.copy(this.pointEnd),hI.applyQuaternion(this._worldQuaternionInv),Vn.applyQuaternion(this._worldQuaternionInv),Vn.divide(hI),e.search("X")===-1&&(Vn.x=1),e.search("Y")===-1&&(Vn.y=1),e.search("Z")===-1&&(Vn.z=1);g.scale.copy(this._scaleStart).multiply(Vn),this.scaleSnap&&(e.search("X")!==-1&&(g.scale.x=Math.round(g.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Y")!==-1&&(g.scale.y=Math.round(g.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Z")!==-1&&(g.scale.z=Math.round(g.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(t==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const C=20/this.worldPosition.distanceTo(hI.setFromMatrixPosition(this.camera.matrixWorld));e==="E"?(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1):e==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(hI.copy(this.rotationAxis).cross(this.eye))*C):(e==="X"||e==="Y"||e==="Z")&&(this.rotationAxis.copy(vq[e]),hI.copy(vq[e]),I==="local"&&hI.applyQuaternion(this.worldQuaternion),this.rotationAngle=this._offset.dot(hI.cross(this.eye).normalize())*C),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),I==="local"&&e!=="E"&&e!=="XYZE"?(g.quaternion.copy(this._quaternionStart),g.quaternion.multiply(Yt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),g.quaternion.copy(Yt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),g.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(V0),this.dispatchEvent(Tq)}}pointerUp(A){A.button===0&&(this.dragging&&this.axis!==null&&(Yq.mode=this.mode,this.dispatchEvent(Yq)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(A){A.geometry&&A.geometry.dispose(),A.material&&A.material.dispose()})}attach(A){return this.object=A,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(V0),this.dispatchEvent(Tq),this.pointStart.copy(this.pointEnd))}getRaycaster(){return sr}getMode(){return this.mode}setMode(A){this.mode=A}setTranslationSnap(A){this.translationSnap=A}setRotationSnap(A){this.rotationSnap=A}setScaleSnap(A){this.scaleSnap=A}setSize(A){this.size=A}setSpace(A){this.space=A}}function GCA(i){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:i.button};{const A=this.domElement.getBoundingClientRect();return{x:(i.clientX-A.left)/A.width*2-1,y:-(i.clientY-A.top)/A.height*2+1,button:i.button}}}function MCA(i){if(this.enabled)switch(i.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(i));break}}function mCA(i){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(i.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(i)),this.pointerDown(this._getPointer(i)))}function RCA(i){this.enabled&&this.pointerMove(this._getPointer(i))}function UCA(i){this.enabled&&(this.domElement.releasePointerCapture(i.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(i)))}function j0(i,A,e){const t=A.intersectObject(i,!0);for(let g=0;g<t.length;g++)if(t[g].object.visible||e)return t[g];return!1}const kp=new Fi,St=new S(0,1,0),Hq=new S(0,0,0),_q=new NA,Gp=new kA,dD=new kA,SC=new S,Oq=new NA,oh=new S(1,0,0),cr=new S(0,1,0),Ch=new S(0,0,1),Mp=new S,vc=new S,xc=new S;class FCA extends UA{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const A=new wt({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=new pi({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=A.clone();t.opacity=.15;const g=e.clone();g.opacity=.5;const I=A.clone();I.color.setHex(16711680);const o=A.clone();o.color.setHex(65280);const C=A.clone();C.color.setHex(255);const s=A.clone();s.color.setHex(16711680),s.opacity=.5;const n=A.clone();n.color.setHex(65280),n.opacity=.5;const a=A.clone();a.color.setHex(255),a.opacity=.5;const B=A.clone();B.opacity=.25;const Q=A.clone();Q.color.setHex(16776960),Q.opacity=.25,A.clone().color.setHex(16776960);const c=A.clone();c.color.setHex(7895160);const h=new ei(0,.04,.1,12);h.translate(0,.05,0);const l=new pt(.08,.08,.08);l.translate(0,.04,0);const d=new de;d.setAttribute("position",new Ie([0,0,0,1,0,0],3));const p=new ei(.0075,.0075,.5,3);p.translate(0,.25,0);function u(_,eA){const $=new KC(_,.0075,3,64,eA*Math.PI*2);return $.rotateY(Math.PI/2),$.rotateX(Math.PI/2),$}function D(){const _=new de;return _.setAttribute("position",new Ie([0,0,0,1,1,1],3)),_}const y={X:[[new pA(h,I),[.5,0,0],[0,0,-Math.PI/2]],[new pA(h,I),[-.5,0,0],[0,0,Math.PI/2]],[new pA(p,I),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new pA(h,o),[0,.5,0]],[new pA(h,o),[0,-.5,0],[Math.PI,0,0]],[new pA(p,o)]],Z:[[new pA(h,C),[0,0,.5],[Math.PI/2,0,0]],[new pA(h,C),[0,0,-.5],[-Math.PI/2,0,0]],[new pA(p,C),null,[Math.PI/2,0,0]]],XYZ:[[new pA(new bC(.1,0),B.clone()),[0,0,0]]],XY:[[new pA(new pt(.15,.15,.01),a.clone()),[.15,.15,0]]],YZ:[[new pA(new pt(.15,.15,.01),s.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new pA(new pt(.15,.15,.01),n.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},k={X:[[new pA(new ei(.2,0,.6,4),t),[.3,0,0],[0,0,-Math.PI/2]],[new pA(new ei(.2,0,.6,4),t),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new pA(new ei(.2,0,.6,4),t),[0,.3,0]],[new pA(new ei(.2,0,.6,4),t),[0,-.3,0],[0,0,Math.PI]]],Z:[[new pA(new ei(.2,0,.6,4),t),[0,0,.3],[Math.PI/2,0,0]],[new pA(new ei(.2,0,.6,4),t),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new pA(new bC(.2,0),t)]],XY:[[new pA(new pt(.2,.2,.01),t),[.15,.15,0]]],YZ:[[new pA(new pt(.2,.2,.01),t),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new pA(new pt(.2,.2,.01),t),[.15,0,.15],[-Math.PI/2,0,0]]]},R={START:[[new pA(new bC(.01,2),g),null,null,null,"helper"]],END:[[new pA(new bC(.01,2),g),null,null,null,"helper"]],DELTA:[[new ci(D(),g),null,null,null,"helper"]],X:[[new ci(d,g.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new ci(d,g.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new ci(d,g.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},f={XYZE:[[new pA(u(.5,1),c),null,[0,Math.PI/2,0]]],X:[[new pA(u(.5,.5),I)]],Y:[[new pA(u(.5,.5),o),null,[0,0,-Math.PI/2]]],Z:[[new pA(u(.5,.5),C),null,[0,Math.PI/2,0]]],E:[[new pA(u(.75,1),Q),null,[0,Math.PI/2,0]]]},M={AXIS:[[new ci(d,g.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},U={XYZE:[[new pA(new $I(.25,10,8),t)]],X:[[new pA(new KC(.5,.1,4,24),t),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new pA(new KC(.5,.1,4,24),t),[0,0,0],[Math.PI/2,0,0]]],Z:[[new pA(new KC(.5,.1,4,24),t),[0,0,0],[0,0,-Math.PI/2]]],E:[[new pA(new KC(.75,.1,2,24),t)]]},J={X:[[new pA(l,I),[.5,0,0],[0,0,-Math.PI/2]],[new pA(p,I),[0,0,0],[0,0,-Math.PI/2]],[new pA(l,I),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new pA(l,o),[0,.5,0]],[new pA(p,o)],[new pA(l,o),[0,-.5,0],[0,0,Math.PI]]],Z:[[new pA(l,C),[0,0,.5],[Math.PI/2,0,0]],[new pA(p,C),[0,0,0],[Math.PI/2,0,0]],[new pA(l,C),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new pA(new pt(.15,.15,.01),a),[.15,.15,0]]],YZ:[[new pA(new pt(.15,.15,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new pA(new pt(.15,.15,.01),n),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new pA(new pt(.1,.1,.1),B.clone())]]},H={X:[[new pA(new ei(.2,0,.6,4),t),[.3,0,0],[0,0,-Math.PI/2]],[new pA(new ei(.2,0,.6,4),t),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new pA(new ei(.2,0,.6,4),t),[0,.3,0]],[new pA(new ei(.2,0,.6,4),t),[0,-.3,0],[0,0,Math.PI]]],Z:[[new pA(new ei(.2,0,.6,4),t),[0,0,.3],[Math.PI/2,0,0]],[new pA(new ei(.2,0,.6,4),t),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new pA(new pt(.2,.2,.01),t),[.15,.15,0]]],YZ:[[new pA(new pt(.2,.2,.01),t),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new pA(new pt(.2,.2,.01),t),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new pA(new pt(.2,.2,.2),t),[0,0,0]]]},Y={X:[[new ci(d,g.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new ci(d,g.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new ci(d,g.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function b(_){const eA=new UA;for(const $ in _)for(let X=_[$].length;X--;){const cA=_[$][X][0].clone(),EA=_[$][X][1],KA=_[$][X][2],uA=_[$][X][3],gA=_[$][X][4];cA.name=$,cA.tag=gA,EA&&cA.position.set(EA[0],EA[1],EA[2]),KA&&cA.rotation.set(KA[0],KA[1],KA[2]),uA&&cA.scale.set(uA[0],uA[1],uA[2]),cA.updateMatrix();const rA=cA.geometry.clone();rA.applyMatrix4(cA.matrix),cA.geometry=rA,cA.renderOrder=1/0,cA.position.set(0,0,0),cA.rotation.set(0,0,0),cA.scale.set(1,1,1),eA.add(cA)}return eA}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=b(y)),this.add(this.gizmo.rotate=b(f)),this.add(this.gizmo.scale=b(J)),this.add(this.picker.translate=b(k)),this.add(this.picker.rotate=b(U)),this.add(this.picker.scale=b(H)),this.add(this.helper.translate=b(R)),this.add(this.helper.rotate=b(M)),this.add(this.helper.scale=b(Y)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(A){const t=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:dD;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let g=[];g=g.concat(this.picker[this.mode].children),g=g.concat(this.gizmo[this.mode].children),g=g.concat(this.helper[this.mode].children);for(let I=0;I<g.length;I++){const o=g[I];o.visible=!0,o.rotation.set(0,0,0),o.position.copy(this.worldPosition);let C;if(this.camera.isOrthographicCamera?C=(this.camera.top-this.camera.bottom)/this.camera.zoom:C=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),o.scale.set(1,1,1).multiplyScalar(C*this.size/4),o.tag==="helper"){o.visible=!1,o.name==="AXIS"?(o.position.copy(this.worldPositionStart),o.visible=!!this.axis,this.axis==="X"&&(Yt.setFromEuler(kp.set(0,0,0)),o.quaternion.copy(t).multiply(Yt),Math.abs(St.copy(oh).applyQuaternion(t).dot(this.eye))>.9&&(o.visible=!1)),this.axis==="Y"&&(Yt.setFromEuler(kp.set(0,0,Math.PI/2)),o.quaternion.copy(t).multiply(Yt),Math.abs(St.copy(cr).applyQuaternion(t).dot(this.eye))>.9&&(o.visible=!1)),this.axis==="Z"&&(Yt.setFromEuler(kp.set(0,Math.PI/2,0)),o.quaternion.copy(t).multiply(Yt),Math.abs(St.copy(Ch).applyQuaternion(t).dot(this.eye))>.9&&(o.visible=!1)),this.axis==="XYZE"&&(Yt.setFromEuler(kp.set(0,Math.PI/2,0)),St.copy(this.rotationAxis),o.quaternion.setFromRotationMatrix(_q.lookAt(Hq,St,cr)),o.quaternion.multiply(Yt),o.visible=this.dragging),this.axis==="E"&&(o.visible=!1)):o.name==="START"?(o.position.copy(this.worldPositionStart),o.visible=this.dragging):o.name==="END"?(o.position.copy(this.worldPosition),o.visible=this.dragging):o.name==="DELTA"?(o.position.copy(this.worldPositionStart),o.quaternion.copy(this.worldQuaternionStart),hI.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),hI.applyQuaternion(this.worldQuaternionStart.clone().invert()),o.scale.copy(hI),o.visible=this.dragging):(o.quaternion.copy(t),this.dragging?o.position.copy(this.worldPositionStart):o.position.copy(this.worldPosition),this.axis&&(o.visible=this.axis.search(o.name)!==-1));continue}o.quaternion.copy(t),this.mode==="translate"||this.mode==="scale"?(o.name==="X"&&Math.abs(St.copy(oh).applyQuaternion(t).dot(this.eye))>.99&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="Y"&&Math.abs(St.copy(cr).applyQuaternion(t).dot(this.eye))>.99&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="Z"&&Math.abs(St.copy(Ch).applyQuaternion(t).dot(this.eye))>.99&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="XY"&&Math.abs(St.copy(Ch).applyQuaternion(t).dot(this.eye))<.2&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="YZ"&&Math.abs(St.copy(oh).applyQuaternion(t).dot(this.eye))<.2&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="XZ"&&Math.abs(St.copy(cr).applyQuaternion(t).dot(this.eye))<.2&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1)):this.mode==="rotate"&&(Gp.copy(t),St.copy(this.eye).applyQuaternion(Yt.copy(t).invert()),o.name.search("E")!==-1&&o.quaternion.setFromRotationMatrix(_q.lookAt(this.eye,Hq,cr)),o.name==="X"&&(Yt.setFromAxisAngle(oh,Math.atan2(-St.y,St.z)),Yt.multiplyQuaternions(Gp,Yt),o.quaternion.copy(Yt)),o.name==="Y"&&(Yt.setFromAxisAngle(cr,Math.atan2(St.x,St.z)),Yt.multiplyQuaternions(Gp,Yt),o.quaternion.copy(Yt)),o.name==="Z"&&(Yt.setFromAxisAngle(Ch,Math.atan2(St.y,St.x)),Yt.multiplyQuaternions(Gp,Yt),o.quaternion.copy(Yt))),o.visible=o.visible&&(o.name.indexOf("X")===-1||this.showX),o.visible=o.visible&&(o.name.indexOf("Y")===-1||this.showY),o.visible=o.visible&&(o.name.indexOf("Z")===-1||this.showZ),o.visible=o.visible&&(o.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),o.material._color=o.material._color||o.material.color.clone(),o.material._opacity=o.material._opacity||o.material.opacity,o.material.color.copy(o.material._color),o.material.opacity=o.material._opacity,this.enabled&&this.axis&&(o.name===this.axis||this.axis.split("").some(function(s){return o.name===s}))&&(o.material.color.setHex(16776960),o.material.opacity=1)}super.updateMatrixWorld(A)}}class NCA extends pA{constructor(){super(new ng(1e5,1e5,2,2),new wt({visible:!1,wireframe:!0,side:Nt,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(A){let e=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(e="local"),Mp.copy(oh).applyQuaternion(e==="local"?this.worldQuaternion:dD),vc.copy(cr).applyQuaternion(e==="local"?this.worldQuaternion:dD),xc.copy(Ch).applyQuaternion(e==="local"?this.worldQuaternion:dD),St.copy(vc),this.mode){case"translate":case"scale":switch(this.axis){case"X":St.copy(this.eye).cross(Mp),SC.copy(Mp).cross(St);break;case"Y":St.copy(this.eye).cross(vc),SC.copy(vc).cross(St);break;case"Z":St.copy(this.eye).cross(xc),SC.copy(xc).cross(St);break;case"XY":SC.copy(xc);break;case"YZ":SC.copy(Mp);break;case"XZ":St.copy(xc),SC.copy(vc);break;case"XYZ":case"E":SC.set(0,0,0);break}break;case"rotate":default:SC.set(0,0,0)}SC.length()===0?this.quaternion.copy(this.cameraQuaternion):(Oq.lookAt(hI.set(0,0,0),SC,St),this.quaternion.setFromRotationMatrix(Oq)),super.updateMatrixWorld(A)}}var KCA=Object.defineProperty,JCA=Object.getOwnPropertyDescriptor,ky=(i,A,e,t)=>{for(var g=t>1?void 0:t?JCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&KCA(A,e,g),g};class SB extends MA{constructor(){super(...arguments);r(this,"isGizmo",!1);r(this,"translationSnap",1);r(this,"rotationSnapAngle",15);r(this,"scaleSnap",.25);r(this,"control");r(this,"orbit");r(this,"changeEventListener");r(this,"windowKeyDownListener");r(this,"windowKeyUpListener")}onEnable(){var e;this.isGizmo&&!td||this.context.mainCamera&&(this.control||(this.control=new kCA(this.context.mainCamera,this.context.domElement),this.control.visible=!0,this.control.enabled=!0,this.control.getRaycaster().layers.set(2),this.control.size=1,this.control.traverse(t=>{const g=t;if(g.layers.set(2),g){const I=g.material;I&&(I.opacity=.3)}}),this.orbit=AA.getComponentInParent(this.context.mainCamera,un)??void 0),this.control&&(this.context.scene.add(this.control),this.control.attach(this.gameObject),this.changeEventListener=this.onControlChangedEvent.bind(this),(e=this.control)==null||e.addEventListener("dragging-changed",this.changeEventListener),this.addWindowEvents()))}onDisable(){var e,t;(e=this.control)==null||e.removeFromParent(),this.changeEventListener&&((t=this.control)==null||t.removeEventListener("dragging-changed",this.changeEventListener)),this.removeWindowEvents()}enableSnapping(){this.control&&(this.control.setTranslationSnap(this.translationSnap),this.control.setRotationSnap(AI.degToRad(this.rotationSnapAngle)),this.control.setScaleSnap(this.scaleSnap))}disableSnapping(){this.control&&(this.control.setTranslationSnap(null),this.control.setRotationSnap(null),this.control.setScaleSnap(null))}onControlChangedEvent(e){const t=this.orbit;if(t&&(t.enabled=!e.value),e.value){const g=AA.getComponentInParent(this.gameObject,wa);g&&g.requestOwnership()}}addWindowEvents(){const e=this.control;e&&(this.windowKeyDownListener||(this.windowKeyDownListener=t=>{if(this.enabled)switch(t.keyCode){case 81:e.setSpace(e.space==="local"?"world":"local");break;case 16:this.enableSnapping();break;case 87:e.setMode("translate");break;case 69:e.setMode("rotate");break;case 82:e.setMode("scale");break;case 187:case 107:e.setSize(e.size+.1);break;case 189:case 109:e.setSize(Math.max(e.size-.1,.1));break;case 88:e.showX=!e.showX;break;case 89:e.showY=!e.showY;break;case 90:e.showZ=!e.showZ;break;case 32:e.enabled=!e.enabled;break}}),this.windowKeyUpListener||(this.windowKeyUpListener=t=>{if(this.enabled)switch(t.keyCode){case 16:this.disableSnapping();break}}),window.addEventListener("keydown",this.windowKeyDownListener),window.addEventListener("keyup",this.windowKeyUpListener))}removeWindowEvents(){window.removeEventListener("keydown",this.windowKeyDownListener),window.removeEventListener("keyup",this.windowKeyUpListener)}}ky([w()],SB.prototype,"isGizmo",2);ky([w()],SB.prototype,"translationSnap",2);ky([w()],SB.prototype,"rotationSnapAngle",2);ky([w()],SB.prototype,"scaleSnap",2);var qCA=Object.defineProperty,bCA=Object.getOwnPropertyDescriptor,EU=(i,A,e,t)=>{for(var g=t>1?void 0:t?bCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&qCA(A,e,g),g};class kB extends Yg{constructor(){super(...arguments);r(this,"color");r(this,"intensity");r(this,"center")}get typeName(){return"Vignette"}init(){this.color.defaultValue={r:0,g:0,b:0,a:1},this.intensity.defaultValue=0,this.center.defaultValue={x:.5,y:.5}}onCreateEffect(){const e=new gY;return this.intensity.onValueChanged=t=>{e.offset=t,this.updateDarkness(e)},this.color.onValueChanged=t=>{this.updateDarkness(e)},e}updateDarkness(e){const t=this.intensity.value;e.darkness=t}}EU([w(Me)],kB.prototype,"color",2);EU([w(Me)],kB.prototype,"intensity",2);EU([w(Me)],kB.prototype,"center",2);Yo("Vignette",kB);var LCA=Object.defineProperty,vCA=Object.getOwnPropertyDescriptor,xCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?vCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&LCA(A,e,g),g};const z0=nA("debugpost");class Gy extends MA{constructor(){super(...arguments);r(this,"sharedProfile");r(this,"_postprocessing");r(this,"_effects",[]);r(this,"_lastApplyTime");r(this,"_rapidApplyCount",0);r(this,"_isDirty",!1);r(this,"_modificationQueue");r(this,"_recreateId",-1)}markDirty(){this._isDirty=!0}awake(){var e;(e=this.sharedProfile)==null||e.init(),z0&&(console.log(this),console.log("Press P to toggle post processing"),window.addEventListener("keydown",t=>{t.key==="p"&&(console.log("Toggle volume: "+this.name,!this.enabled),this.enabled=!this.enabled)}))}onDisable(){var e;(e=this._postprocessing)==null||e.unapply()}onBeforeRender(){if(!this.context.isInXR){if(this.context.composer&&!(this.context.composer instanceof dm))return;this.context.mainCamera&&(!this._postprocessing||!this._postprocessing.isActive||this._isDirty)&&this.apply(),this.context.composer&&(this.context.composer.setRenderer(this.context.renderer),this.context.composer.setMainScene(this.context.scene),this.context.mainCamera&&this.context.composer.setMainCamera(this.context.mainCamera))}}onDestroy(){var e;(e=this._postprocessing)==null||e.dispose()}apply(){var t,g;z0&&console.log("Apply PostProcessing",this,(t=this.context.mainCamera)==null?void 0:t.name),qg()&&(this._lastApplyTime!==void 0&&Date.now()-this._lastApplyTime<100&&(this._rapidApplyCount++,this._rapidApplyCount===5&&console.warn("Detected rapid post processing modifications - this might be a bug",this)),this._lastApplyTime=Date.now()),this._isDirty=!1,this.unapply(),this._effects.length=0,(g=this.sharedProfile)!=null&&g.components&&this._effects.push(...this.sharedProfile.components);const e=this.gameObject.getComponentsInChildren(Yg);if(z0&&(e!=null&&e.length)&&console.log("Additional",e),e)for(const I of e)I.active&&this._effects.push(I);this._effects.length>0&&(this._postprocessing||(this._postprocessing=new Dy(this.context)),this._postprocessing.apply(this._effects),this._applyPostQueue())}unapply(){var e;(e=this._postprocessing)==null||e.unapply()}_applyPostQueue(){if(this._modificationQueue){for(const e of this._modificationQueue.values())this.onEditorModification(e);this._modificationQueue.clear()}}onEditorModification(e){var t,g;if(e.propertyName.startsWith("postprocessing.")){if(!this._postprocessing)return this._modificationQueue||(this._modificationQueue=new Map),this._modificationQueue.set(e.propertyName,e),!0;if(!((t=this._effects)!=null&&t.length))return;const I=e.propertyName.split(".");if(I.length===3||I.length===4){const o=I[1],C=I[2];for(const s of this._effects)if(((g=s.typeName)==null?void 0:g.toLowerCase())===o.toLowerCase()){if(C==="active"){s.active=e.value,this.scheduleRecreate();return}if(!mp.has(o)){const n=new Array;mp.set(o,n);const a=Object.keys(s);for(const B of a)s[B]instanceof Me&&n.push(B)}if(mp.has(o)){const n=C.toLowerCase(),a=mp.get(o);for(const B of a)if(B.toLowerCase()===n){const Q=s[B];Q instanceof Me&&(I.length===4&&I[3]==="active"?(Q.overrideState=e.value,this.scheduleRecreate()):Q&&Q.value!==void 0&&(Q.value=e.value));return}}console.warn("Unknown modification",C);return}}return!0}return!1}scheduleRecreate(){const e=++this._recreateId;setTimeout(()=>{e===this._recreateId&&(this.onDisable(),this.onEnable())},200)}}xCA([JE(md)],Gy.prototype,"sharedProfile",2);const mp=new Map;var YCA=Object.defineProperty,TCA=Object.getOwnPropertyDescriptor,HCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?TCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&YCA(A,e,g),g};class My extends MA{constructor(){super(...arguments);r(this,"backgroundTint",new Gt(1,1,1,1));r(this,"_preRender");r(this,"backgroundPlane");r(this,"threeTexture");r(this,"forceTextureInitialization",function(){const e=new wt,t=new ng,g=new GI;g.add(new pA(t,e));const I=new $r;return function(C,s){e.map=s,C.render(g,I)}}())}awake(){Se.OptionalFeatures_AR.push("camera-access")}get background(){return this.backgroundPlane}onEnable(){this._preRender=this.preRender.bind(this),this.context.pre_render_callbacks.push(this._preRender),this.backgroundPlane&&(this.gameObject.add(this.backgroundPlane),this.backgroundPlane.visible=!1)}onDisable(){this.context.pre_render_callbacks=this.context.pre_render_callbacks.filter(e=>e!==this._preRender),this.backgroundPlane&&this.gameObject.remove(this.backgroundPlane)}preRender(){if(!this||!this.gameObject)return;const t=this.context.renderer.xr.getFrame();t&&(!this.threeTexture&&this.context.renderer&&(this.threeTexture=new Te,this.forceTextureInitialization(this.context.renderer,this.threeTexture)),this.backgroundPlane===void 0&&(this.backgroundPlane=OCA(this.backgroundTint),this.gameObject.add(this.backgroundPlane)),this.updateFromFrame(t))}onBeforeRender(e){this.updateFromFrame(e)}updateFromFrame(e){if(!e)return;const t=e.getViewerPose(this.context.renderer.xr.getReferenceSpace());if(t){for(const g of t.views)if("camera"in g&&g.camera){let o=this.context.renderer.xr.getBinding();if(o||(o=new XRWebGLBinding(e.session,this.context.renderer.getContext())),o){let C=null;if("getCameraImage"in o){C=o.getCameraImage(g.camera);const s=this.context.renderer.properties.get(this.threeTexture);s.__webglTexture=C,this.backgroundPlane&&(this.backgroundPlane.setTexture(this.threeTexture),this.backgroundPlane.visible=!0)}}}}}}HCA([w()],My.prototype,"backgroundTint",2);let _CA=`
|
|
5438
|
+
`)}}}applyShadowMaterial(){var t;const e=AA.getComponent(this.gameObject,_t);if(e)if(((t=e.sharedMaterial)==null?void 0:t.type)!=="ShadowMaterial"){const g=new qM;g.color=this.shadowColor,g.opacity=this.shadowColor.alpha,this.applyMaterialOptions(g),e.sharedMaterial=g}else{const g=e.sharedMaterial;g.color=this.shadowColor,g.opacity=this.shadowColor.alpha,this.applyMaterialOptions(g)}}applyOccluderMaterial(){const e=AA.getComponent(this.gameObject,_t);if(e){const t=e.sharedMaterial;t.depthWrite=!0,t.stencilWrite=!0,t.colorWrite=!1,this.gameObject.renderOrder=-100}}applyMaterialOptions(e){e&&(e.depthWrite=!1,e.stencilWrite=!1)}}V2([w()],Vd.prototype,"mode",2);V2([w(Gt)],Vd.prototype,"shadowColor",2);var PoA=Object.defineProperty,WoA=Object.getOwnPropertyDescriptor,wy=(i,A,e,t)=>{for(var g=t>1?void 0:t?WoA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&PoA(A,e,g),g},nk;const j2=(nk=class extends MA{constructor(){super(...arguments);r(this,"target",null);r(this,"followFactor",.1);r(this,"rotateFactor",.1);r(this,"positionAxes",DQ.All);r(this,"flipForward",!1);r(this,"_firstUpdate",!0)}onBeforeRender(){this.updateNow(!1)}updateNow(A){if(!(!this.target||this.target===this.gameObject)){if(this.followFactor>0){const e=ye(this.target),t=this._firstUpdate||A?1:ee.clamp01(this.context.time.deltaTime*this.followFactor),g=this.worldPosition;this.positionAxes&DQ.X&&(g.x=ee.lerp(g.x,e.x,t)),this.positionAxes&DQ.Y&&(g.y=ee.lerp(g.y,e.y,t)),this.positionAxes&DQ.Z&&(g.z=ee.lerp(g.z,e.z,t)),this.worldPosition=g}if(this.rotateFactor>0){const e=Pi(this.target);this.flipForward&&e.premultiply(j2._invertForward);const t=this._firstUpdate||A?1:ee.clamp01(this.context.time.deltaTime*this.rotateFactor);this.worldQuaternion=this.worldQuaternion.slerp(e,t)}this._firstUpdate=!1}}},r(nk,"_invertForward",new kA().setFromAxisAngle(new S(0,1,0),Math.PI)),nk);let Va=j2;wy([w(UA)],Va.prototype,"target",2);wy([w()],Va.prototype,"followFactor",2);wy([w()],Va.prototype,"rotateFactor",2);wy([w()],Va.prototype,"positionAxes",2);class VoA extends pA{constructor(A){const e=new joA(A),t=new ng(e.image.width*.001,e.image.height*.001),g=new wt({map:e,toneMapped:!1,transparent:!0});super(t,g);function I(o){g.map.dispatchDOMEvent(o)}this.addEventListener("mousedown",I),this.addEventListener("mousemove",I),this.addEventListener("mouseup",I),this.addEventListener("click",I),this.dispose=function(){t.dispose(),g.dispose(),g.map.dispose(),VG.delete(A),this.removeEventListener("mousedown",I),this.removeEventListener("mousemove",I),this.removeEventListener("mouseup",I),this.removeEventListener("click",I)}}}class joA extends pL{constructor(A){super(qq(A)),this.dom=A,this.anisotropy=16,this.encoding=pe,this.minFilter=be,this.magFilter=be;const e=new MutationObserver(()=>{this.scheduleUpdate||(this.scheduleUpdate=setTimeout(()=>this.update(),16))}),t={attributes:!0,childList:!0,subtree:!0,characterData:!0};e.observe(A,t),this.observer=e}dispatchDOMEvent(A){A.data&&zoA(this.dom,A.type,A.data.x,A.data.y)}update(){this.image=qq(this.dom),this.needsUpdate=!0,this.scheduleUpdate=null}dispose(){this.observer&&this.observer.disconnect(),this.scheduleUpdate=clearTimeout(this.scheduleUpdate),super.dispose()}}const VG=new WeakMap;function qq(i){const A=document.createRange(),e=new wA;function t(Q){const E=[];let c=!1;function h(){if(c&&(c=!1,Q.restore()),E.length===0)return;let l=-1/0,d=-1/0,p=1/0,u=1/0;for(let D=0;D<E.length;D++){const y=E[D];l=Math.max(l,y.x),d=Math.max(d,y.y),p=Math.min(p,y.x+y.width),u=Math.min(u,y.y+y.height)}Q.save(),Q.beginPath(),Q.rect(l,d,p-l,u-d),Q.clip(),c=!0}return{add:function(l){E.push(l),h()},remove:function(){E.pop(),h()}}}function g(Q,E,c,h){h!==""&&(Q.textTransform==="uppercase"&&(h=h.toUpperCase()),a.font=Q.fontWeight+" "+Q.fontSize+" "+Q.fontFamily,a.textBaseline="top",a.fillStyle=Q.color,a.fillText(h,E,c+parseFloat(Q.fontSize)*.1))}function I(Q,E,c,h,l){c<2*l&&(l=c/2),h<2*l&&(l=h/2),a.beginPath(),a.moveTo(Q+l,E),a.arcTo(Q+c,E,Q+c,E+h,l),a.arcTo(Q+c,E+h,Q,E+h,l),a.arcTo(Q,E+h,Q,E,l),a.arcTo(Q,E,Q+c,E,l),a.closePath()}function o(Q,E,c,h,l,d){const p=Q[E+"Width"],u=Q[E+"Style"],D=Q[E+"Color"];p!=="0px"&&u!=="none"&&D!=="transparent"&&D!=="rgba(0, 0, 0, 0)"&&(a.strokeStyle=D,a.lineWidth=parseFloat(p),a.beginPath(),a.moveTo(c,h),a.lineTo(c+l,h+d),a.stroke())}function C(Q,E){let c=0,h=0,l=0,d=0;if(Q.nodeType===Node.TEXT_NODE){A.selectNode(Q);const u=A.getBoundingClientRect();c=u.left-s.left-.5,h=u.top-s.top-.5,l=u.width,d=u.height,g(E,c,h,Q.nodeValue.trim())}else{if(Q.nodeType===Node.COMMENT_NODE)return;if(Q instanceof HTMLCanvasElement){if(Q.style.display==="none")return;a.save();const u=window.devicePixelRatio;a.scale(1/u,1/u),a.drawImage(Q,0,0),a.restore()}else{if(Q.style.display==="none")return;const u=Q.getBoundingClientRect();c=u.left-s.left-.5,h=u.top-s.top-.5,l=u.width,d=u.height,E=window.getComputedStyle(Q),I(c,h,l,d,parseFloat(E.borderRadius));const D=E.backgroundColor;D!=="transparent"&&D!=="rgba(0, 0, 0, 0)"&&(a.fillStyle=D,a.fill());const y=["borderTop","borderLeft","borderBottom","borderRight"];let k=!0,R=null;for(const f of y){if(R!==null&&(k=E[f+"Width"]===E[R+"Width"]&&E[f+"Color"]===E[R+"Color"]&&E[f+"Style"]===E[R+"Style"]),k===!1)break;R=f}if(k===!0){const f=parseFloat(E.borderTopWidth);E.borderTopWidth!=="0px"&&E.borderTopStyle!=="none"&&E.borderTopColor!=="transparent"&&E.borderTopColor!=="rgba(0, 0, 0, 0)"&&(a.strokeStyle=E.borderTopColor,a.lineWidth=f,a.stroke())}else o(E,"borderTop",c,h,l,0),o(E,"borderLeft",c,h,0,d),o(E,"borderBottom",c,h+d,l,0),o(E,"borderRight",c+l,h,0,d);if(Q instanceof HTMLInputElement){let f=E.accentColor;(f===void 0||f==="auto")&&(f=E.color),e.set(f);const U=Math.sqrt(.299*e.r**2+.587*e.g**2+.114*e.b**2)<.5?"white":"#111111";if(Q.type==="radio"&&(I(c,h,l,d,d),a.fillStyle="white",a.strokeStyle=f,a.lineWidth=1,a.fill(),a.stroke(),Q.checked&&(I(c+2,h+2,l-4,d-4,d),a.fillStyle=f,a.strokeStyle=U,a.lineWidth=2,a.fill(),a.stroke())),Q.type==="checkbox"&&(I(c,h,l,d,2),a.fillStyle=Q.checked?f:"white",a.strokeStyle=Q.checked?U:f,a.lineWidth=1,a.stroke(),a.fill(),Q.checked)){const J=a.textAlign;a.textAlign="center";const H={color:U,fontFamily:E.fontFamily,fontSize:d+"px",fontWeight:"bold"};g(H,c+l/2,h,"✔"),a.textAlign=J}if(Q.type==="range"){const[J,H,Y]=["min","max","value"].map(_=>parseFloat(Q[_])),b=(Y-J)/(H-J)*(l-d);I(c,h+d/4,l,d/2,d/4),a.fillStyle=U,a.strokeStyle=f,a.lineWidth=1,a.fill(),a.stroke(),I(c,h+d/4,b+d/2,d/2,d/4),a.fillStyle=f,a.fill(),I(c+b,h,d,d,d/2),a.fillStyle=f,a.fill()}(Q.type==="color"||Q.type==="text"||Q.type==="number")&&(B.add({x:c,y:h,width:l,height:d}),g(E,c+parseInt(E.paddingLeft),h+parseInt(E.paddingTop),Q.value),B.remove())}}}const p=E.overflow==="auto"||E.overflow==="hidden";p&&B.add({x:c,y:h,width:l,height:d});for(let u=0;u<Q.childNodes.length;u++)C(Q.childNodes[u],E);p&&B.remove()}const s=i.getBoundingClientRect();let n=VG.get(i);n===void 0&&(n=document.createElement("canvas"),n.width=s.width,n.height=s.height,VG.set(i,n));const a=n.getContext("2d"),B=new t(a);return C(i),n}function zoA(i,A,e,t){const g={clientX:e*i.offsetWidth+i.offsetLeft,clientY:t*i.offsetHeight+i.offsetTop,view:i.ownerDocument.defaultView};window.dispatchEvent(new MouseEvent(A,g));const I=i.getBoundingClientRect();e=e*I.width+I.left,t=t*I.height+I.top;function o(C){if(C.nodeType!==Node.TEXT_NODE&&C.nodeType!==Node.COMMENT_NODE){const s=C.getBoundingClientRect();if(e>s.left&&e<s.right&&t>s.top&&t<s.bottom&&(C.dispatchEvent(new MouseEvent(A,g)),C instanceof HTMLInputElement&&C.type==="range"&&(A==="mousedown"||A==="click"))){const[n,a]=["min","max"].map(c=>parseFloat(C[c])),B=s.width,E=(e-s.x)/B;C.value=n+(a-n)*E,C.dispatchEvent(new InputEvent("input",{bubbles:!0}))}for(let n=0;n<C.childNodes.length;n++)o(C.childNodes[n])}}o(i)}const hD=new P,tQ={type:"",data:hD};class ZoA extends ko{constructor(A,e){super();const t=this,g=new uE,I=new NA,o=A.domElement;function C(Q){Q.stopPropagation();const E=A.domElement.getBoundingClientRect();hD.x=(Q.clientX-E.left)/E.width*2-1,hD.y=-(Q.clientY-E.top)/E.height*2+1,g.setFromCamera(hD,e);const c=g.intersectObjects(t.children,!1);if(c.length>0){const h=c[0],l=h.object,d=h.uv;tQ.type=Q.type,tQ.data.set(d.x,1-d.y),l.dispatchEvent(tQ)}}o.addEventListener("pointerdown",C),o.addEventListener("pointerup",C),o.addEventListener("pointermove",C),o.addEventListener("mousedown",C),o.addEventListener("mouseup",C),o.addEventListener("mousemove",C),o.addEventListener("click",C);const s={move:"mousemove",select:"click",selectstart:"mousedown",selectend:"mouseup"};function n(Q){const E=Q.target;I.identity().extractRotation(E.matrixWorld),g.ray.origin.setFromMatrixPosition(E.matrixWorld),g.ray.direction.set(0,0,-1).applyMatrix4(I);const c=g.intersectObjects(t.children,!1);if(c.length>0){const h=c[0],l=h.object,d=h.uv;tQ.type=s[Q.type],tQ.data.set(d.x,1-d.y),l.dispatchEvent(tQ)}}const a=A.xr.getController(0);a.addEventListener("move",n),a.addEventListener("select",n),a.addEventListener("selectstart",n),a.addEventListener("selectend",n);const B=A.xr.getController(1);B.addEventListener("move",n),B.addEventListener("select",n),B.addEventListener("selectstart",n),B.addEventListener("selectend",n)}}class rU extends MA{constructor(){super(...arguments);r(this,"id",null);r(this,"keepAspect",!1)}start(){if(!this.id||!this.context.mainCamera)return;const e=document.getElementById(this.id);if(!e){console.warn('Could not find element with id "'+this.id+'"');return}e.style.display="block",e.style.visibility="hidden";const t=new ZoA(this.context.renderer,this.context.mainCamera);this.gameObject.add(t);const g=new VoA(e);t.add(g),g.visible=!1,console.log(g);const I=g.material;I.transparent=!0,setTimeout(()=>{g.visible=!0;const o=rw(this.gameObject).clone();Bw(this.gameObject,0,0,0),this.gameObject.updateMatrixWorld();const C=new Jg;C.setFromObject(t),this.setWorldRotation(o.x,o.y,o.z);const s=C.max.x-C.min.x,n=C.max.y-C.min.y;if(this.keepAspect){const B=s/n;s>n?g.scale.set(1/s,1/n/B,1):g.scale.set(1/s*B,1/n,1)}else g.scale.set(1/s,1/n,1);const a=this.gameObject.scale;g.scale.multiply(a)},1)}}var XoA=Object.defineProperty,$oA=Object.getOwnPropertyDescriptor,jd=(i,A,e,t)=>{for(var g=t>1?void 0:t?$oA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&XoA(A,e,g),g};const Rh=nA("debugspatialtrigger"),bq=new Ko,Lq=new Ko;function ACA(i,A){return bq.mask=i,Lq.mask=A,bq.test(Lq)}class OC extends MA{constructor(){super(...arguments);r(this,"triggerMask",0);r(this,"onEnter");r(this,"onStay");r(this,"onExit");r(this,"currentIntersected",[]);r(this,"lastIntersected",[])}start(){Rh&&console.log(this.name,this.triggerMask,this)}update(){this.currentIntersected.length=0;for(const e of zd.triggers)ACA(e.triggerMask,this.triggerMask)&&e.test(this.gameObject)&&this.currentIntersected.push(e);for(let e=this.lastIntersected.length-1;e>=0;e--){const t=this.lastIntersected[e];this.currentIntersected.indexOf(t)<0&&(this.onExitTrigger(t),this.lastIntersected.splice(e,1))}for(const e of this.currentIntersected)this.lastIntersected.indexOf(e)<0&&this.onEnterTrigger(e),this.onStayTrigger(e);this.lastIntersected.length=0,this.lastIntersected.push(...this.currentIntersected)}onEnterTrigger(e){var t;Rh&&console.log("ENTER TRIGGER",this.name,e.name,this,e),e.raiseOnEnterEvent(this),(t=this.onEnter)==null||t.invoke(this,e)}onExitTrigger(e){var t;Rh&&console.log("EXIT TRIGGER",this.name,e.name,this,e),e.raiseOnExitEvent(this),(t=this.onExit)==null||t.invoke(this,e)}onStayTrigger(e){var t;e.raiseOnStayEvent(this),(t=this.onStay)==null||t.invoke(this,e)}}jd([w()],OC.prototype,"triggerMask",2);jd([w(yI)],OC.prototype,"onEnter",2);jd([w(yI)],OC.prototype,"onStay",2);jd([w(yI)],OC.prototype,"onExit",2);var ak;const lD=(ak=class extends MA{constructor(){super(...arguments);r(this,"triggerMask");r(this,"boxHelper")}start(){Rh&&console.log(this.name,this.triggerMask,this)}onEnable(){var A;lD.triggers.push(this),this.boxHelper||(this.boxHelper=AA.addNewComponent(this.gameObject,yo),(A=this.boxHelper)==null||A.showHelper(null,Rh))}onDisable(){lD.triggers.splice(lD.triggers.indexOf(this),1)}test(A){return this.boxHelper?this.boxHelper.isInBox(A)??!1:!1}raiseOnEnterEvent(A){AA.foreachComponent(this.gameObject,e=>{e!==A&&e instanceof OC&&e.onEnterTrigger(this)},!1)}raiseOnStayEvent(A){AA.foreachComponent(this.gameObject,e=>{e!==A&&e instanceof OC&&e.onStayTrigger(this)},!1)}raiseOnExitEvent(A){AA.foreachComponent(this.gameObject,e=>{e!==A&&e instanceof OC&&e.onExitTrigger(this)},!1)}},r(ak,"triggers",[]),ak);let zd=lD;jd([w()],zd.prototype,"triggerMask",2);var eCA=Object.defineProperty,tCA=Object.getOwnPropertyDescriptor,iCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?tCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&eCA(A,e,g),g};const OI=nA("debugspectator");class yy extends MA{constructor(){super(...arguments);r(this,"cam",null);r(this,"useKeys",!0);r(this,"_mode",0);r(this,"orbit",null);r(this,"_handler");r(this,"eventSub_WebXRRequestStartEvent",null);r(this,"eventSub_WebXRStartEvent",null);r(this,"eventSub_WebXREndEvent",null);r(this,"_debug");r(this,"_networking")}get mode(){return this._mode}set mode(e){this._mode=e}get isSpectating(){var e;return((e=this._handler)==null?void 0:e.currentTarget)!==void 0}isSpectatingUser(e){var t;return((t=this.target)==null?void 0:t.userId)===e}isFollowedBy(e){var t;return(t=this.followers)==null?void 0:t.includes(e)}get followers(){return this._networking.followers}stopSpectating(){if(this.context.isInXR){this.followSelf();return}this.target=void 0}get localId(){return this.context.connection.connectionId??"local"}set target(e){var t;if(this._handler){const g=(t=this._handler.currentTarget)==null?void 0:t.userId,I=this.context.players.getPlayerView(this.localId);e===void 0||this.context.isInXR===!1&&(I==null?void 0:I.currentObject)===e.currentObject?this._handler.currentTarget!==void 0&&(this._handler.disable(),AA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),this._networking.onSpectatedObjectChanged(e,g)):this._handler.currentTarget!==e&&(this._handler.set(e),AA.setActive(this.gameObject,!0),this.orbit&&(this.orbit.enabled=!1),this._networking.onSpectatedObjectChanged(e,g))}}get target(){var e;return(e=this._handler)==null?void 0:e.currentTarget}requestAllFollowMe(){this._networking.onRequestFollowMe()}get isSpectatingSelf(){var e,t;return this.isSpectating&&((e=this.target)==null?void 0:e.currentObject)===((t=this.context.players.getPlayerView(this.localId))==null?void 0:t.currentObject)}awake(){if(this._debug=new oCA(this.context,this),this._networking=new nCA(this.context,this),this._networking.awake(),AA.setActive(this.gameObject,!1),this.cam=AA.getComponent(this.gameObject,Ot),!this.cam){console.error("Spectator camera needs camera component",this);return}!this._handler&&this.cam&&(this._handler=new gCA(this.context,this.cam,this)),this.eventSub_WebXRRequestStartEvent=this.onXRSessionRequestStart.bind(this),this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Se.addEventListener(Ft.RequestVRSession,this.eventSub_WebXRRequestStartEvent),Se.addEventListener(Ft.XRStarted,this.eventSub_WebXRStartEvent),Se.addEventListener(Ft.XRStopped,this.eventSub_WebXREndEvent),this.orbit=AA.getComponent(this.context.mainCamera,un)}onDestroy(){var e,t;this.stopSpectating(),Se.removeEventListener(Ft.RequestVRSession,this.eventSub_WebXRStartEvent),Se.removeEventListener(Ft.XRStarted,this.eventSub_WebXRStartEvent),Se.removeEventListener(Ft.XRStopped,this.eventSub_WebXREndEvent),(e=this._handler)==null||e.destroy(),(t=this._networking)==null||t.destroy()}isSupportedPlatform(){const e=window.navigator.userAgent,t=/Windows|MacOS/.test(e),g=/Windows NT/.test(e)&&/Edg/.test(e)&&!/Win64/.test(e);return t&&!g}onXRSessionRequestStart(e){this.isSupportedPlatform()&&AA.setActive(this.gameObject,!0)}onXRSessionStart(e){this.isSupportedPlatform()&&(OI&&console.log(this.context.mainCamera),this.context.mainCamera&&this.followSelf())}onXRSessionEnded(e){var t,g;this.context.removeCamera(this.cam),AA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),(t=this._handler)==null||t.set(void 0),(g=this._handler)==null||g.disable(),this.isSpectatingSelf&&this.stopSpectating()}followSelf(){this.target=this.context.players.getPlayerView(this.context.connection.connectionId),this.target||(this.context.players.setPlayerView(this.localId,this.context.mainCamera,_C.Headset),this.target=this.context.players.getPlayerView(this.localId)),OI&&console.log("Follow self",this.target)}onAfterRender(){var n,a,B;if(!this.cam)return;const e=this.context.renderer,t=e.xr.enabled;if(!e.xr.isPresenting&&!((n=this._handler)!=null&&n.currentTarget))return;(a=this._handler)==null||a.update(this._mode);const g=e.getRenderTarget();let I=null;if(!g){if(!e.state.bindFramebuffer||!e.state.bindXRFramebuffer)return;I=e._framebuffer,e.state.bindXRFramebuffer(null)}this.setAvatarFlagsBeforeRender();const o=this.context.mainCameraComponent;if(o){const Q=o.backgroundColor;Q&&e.setClearColor(Q,Q.alpha),this.cam.backgroundColor=Q,this.cam.clearFlags=o.clearFlags,this.cam.nearClipPlane=o.nearClipPlane,this.cam.farClipPlane=o.farClipPlane}else e.setClearColor(new wA(1,1,1));e.setRenderTarget(null),e.xr.enabled=!1;const C=(B=this.cam)==null?void 0:B.cam;this.context.updateAspect(C);const s=e.xr.isPresenting;e.xr.isPresenting=!1,e.setSize(this.context.domWidth,this.context.domHeight),e.render(this.context.scene,C),e.xr.isPresenting=s,e.xr.enabled=t,g?e.setRenderTarget(g):e.state.bindXRFramebuffer(I),this.resetAvatarFlags()}setAvatarFlagsBeforeRender(){const e=this._mode===0;for(const t of Ig.instances)if(t.avatar&&"isLocalAvatar"in t.avatar){let g=Mi.All;this.isSpectatingSelf&&(g=e&&t.avatar.isLocalAvatar?Mi.FirstPerson:Mi.ThirdPerson);const I=t.avatar.flags;if(!I)continue;for(const o of I)o.UpdateVisible(g)}}resetAvatarFlags(){var e;for(const t of Ig.instances)if(t.avatar&&"flags"in t.avatar){const g=t.avatar.flags;if(!g)continue;for(const I of g)(e=t.avatar)!=null&&e.isLocalAvatar?I.UpdateVisible(Mi.FirstPerson):I.UpdateVisible(Mi.ThirdPerson)}}}iCA([w()],yy.prototype,"useKeys",2);class gCA{constructor(A,e,t){r(this,"context");r(this,"cam");r(this,"spectator");r(this,"follow");r(this,"target");r(this,"view");r(this,"currentObject");this.context=A,this.cam=e,this.spectator=t}get currentTarget(){return this.view}set(A){const e=A==null?void 0:A.currentObject;if(!e){this.spectator.stopSpectating();return}e!==this.currentObject&&(this.currentObject=e,this.view=A,this.follow||(this.follow=AA.addNewComponent(this.cam.gameObject,Va)),this.target||(this.target=new UA),e.add(this.target),this.follow.enabled=!0,this.follow.target=this.target,OI&&console.log("FOLLOW",e),this.context.isInXR?this.context.removeCamera(this.cam):this.context.setCurrentCamera(this.cam))}disable(){OI&&console.log("STOP FOLLOW",this.currentObject),this.view=void 0,this.currentObject=void 0,this.context.removeCamera(this.cam),this.follow&&(this.follow.enabled=!1)}destroy(){var A;(A=this.target)==null||A.removeFromParent(),this.follow&&AA.destroy(this.follow)}update(A){var g,I,o,C,s,n;if(((g=this.currentTarget)==null?void 0:g.isConnected)===!1||((I=this.currentTarget)==null?void 0:I.removed)===!0){OI&&console.log("Target disconnected or timeout",this.currentTarget),this.spectator.stopSpectating();return}this.currentTarget&&((o=this.currentTarget)==null?void 0:o.currentObject)!==this.currentObject&&(OI&&console.log("Target changed",this.currentObject,"to",this.currentTarget.currentObject),this.set(this.currentTarget));const e=this.context.mainCamera;e&&(this.cam.cam.near!==e.near||this.cam.cam.far!==e.far)&&(this.cam.cam.near=e.near,this.cam.cam.far=e.far,this.cam.cam.updateProjectionMatrix());const t=(C=this.follow)==null?void 0:C.target;if(!(!t||!this.follow)){switch(A){case 0:((s=this.view)==null?void 0:s.viewDevice)!==_C.Browser?(this.follow.followFactor=5,this.follow.rotateFactor=5):(this.follow.followFactor=50,this.follow.rotateFactor=50),t.position.set(0,0,0);break;case 1:this.follow.followFactor=3,this.follow.rotateFactor=2,t.position.set(0,.5,1.5);break}this.follow.flipForward=!1,((n=this.view)==null?void 0:n.viewDevice)!==_C.Browser?t.quaternion.copy(ICA):t.quaternion.identity()}}}const ICA=new kA().setFromAxisAngle(new S(0,1,0),Math.PI);class oCA{constructor(A,e){r(this,"context");r(this,"spectator");this.context=A,this.spectator=e,console.log("Click other avatars or cameras to follow them. Press ESC to exit spectator mode."),this.context.domElement.addEventListener("keydown",g=>{if(!this.spectator.useKeys)return;g.key==="Escape"&&this.spectator.stopSpectating()});let t=0;this.context.input.addEventListener(RC.PointerDown,g=>{t=this.context.time.time}),this.context.input.addEventListener(RC.PointerUp,g=>{const I=this.context.time.time-t;I>1?this.spectator.stopSpectating():this.context.input.getPointerClicked(0)&&I<.3&&this.trySelectObject()})}trySelectObject(){const A=new EC;A.setMask(16777215);const e=this.context.physics.raycast(A);if(OI&&console.log(...e),e!=null&&e.length)for(const t of e){if(t.distance<.2)continue;const g=t.object,I=AA.getComponentInParent(g,Ig),o=I==null?void 0:I.connectionId;if(o){const C=this.context.players.getPlayerView(o);this.spectator.target=C,OI&&console.log("spectate",o,I);break}}}}class CCA{constructor(A,e,t){r(this,"guid");r(this,"dontSave",!0);r(this,"targetUserId");r(this,"stoppedFollowing");this.guid=A,this.targetUserId=e,this.stoppedFollowing=t}}class sCA{constructor(A,e){r(this,"guid");r(this,"userId");this.guid=A.guid,this.userId=e}}class nCA{constructor(A,e){r(this,"followers",[]);r(this,"context");r(this,"spectator");r(this,"_followerEventMethod");r(this,"_requestFollowMethod");r(this,"_joinedRoomMethod");r(this,"_lastRequestFollowUser");r(this,"_enforceFollowInterval");this.context=A,this.spectator=e,this._followerEventMethod=this.onFollowerEvent.bind(this),this._requestFollowMethod=this.onRequestFollowEvent.bind(this),this._joinedRoomMethod=this.onUserJoinedRoom.bind(this)}awake(){this.context.connection.beginListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.beginListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.beginListen(oi.JoinedRoom,this._joinedRoomMethod),this.context.domElement.addEventListener("keydown",A=>{this.spectator.useKeys&&(A.key==="f"?this.onRequestFollowMe():A.key==="Escape"&&this.onRequestFollowMe(!0))})}destroy(){this.context.connection.stopListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.stopListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.stopListen(oi.JoinedRoom,this._joinedRoomMethod)}onSpectatedObjectChanged(A,e){if(OI&&console.log(this.context.connection.connectionId,"onSpectatedObjectChanged",A,e),this.context.connection.connectionId){const t=(A==null?void 0:A.userId)===void 0,g=t?e:A==null?void 0:A.userId,I=new CCA(this.context.connection.connectionId,g,t);this.context.connection.send("spectator-follower-changed",I)}}onRequestFollowMe(A=!1){if(OI&&console.log("Request follow",this.context.connection.connectionId),this.context.connection.connectionId){this.spectator.stopSpectating();const e=A?void 0:this.context.connection.connectionId,t=new sCA(this.spectator,e);this.context.connection.send("spectator-request-follow",t)}}onUserJoinedRoom(){nA("followme")&&this.onRequestFollowMe()}onFollowerEvent(A){const e=A.targetUserId,t=A.guid;if(OI&&console.log(A),e===this.context.connection.connectionId)if(A.stoppedFollowing){const g=this.followers.indexOf(t);g!==-1&&(this.followers.splice(g,1),this.removeDisconnectedFollowers(),console.log(t,"unfollows you",this.followers.length))}else this.followers.includes(t)||(this.followers.push(t),this.removeDisconnectedFollowers(),console.log(t,"follows you",this.followers.length))}removeDisconnectedFollowers(){for(let A=this.followers.length-1;A>=0;A--){const e=this.followers[A];this.context.connection.userIsInRoom(e)===!1&&this.followers.splice(A,1)}}onRequestFollowEvent(A){if(this._lastRequestFollowUser=A,A.userId===this.context.connection.connectionId)this.spectator.stopSpectating();else if(A.userId===void 0)this.spectator.stopSpectating();else{const e=this.context.players.getPlayerView(A.userId);if(e)this.spectator.target=e;else return OI&&console.warn("Could not find view",A.userId),this.enforceFollow(),!1}return!0}enforceFollow(){this._enforceFollowInterval||(this._enforceFollowInterval=setInterval(()=>{this._lastRequestFollowUser===void 0||this._lastRequestFollowUser.userId&&this.spectator.isFollowedBy(this._lastRequestFollowUser.userId)?(clearInterval(this._enforceFollowInterval),this._enforceFollowInterval=void 0):(OI&&console.log("REQUEST FOLLOW AGAIN",this._lastRequestFollowUser.userId),this.onRequestFollowEvent(this._lastRequestFollowUser))},1e3))}}var aCA=Object.defineProperty,rCA=Object.getOwnPropertyDescriptor,aI=(i,A,e,t)=>{for(var g=t>1?void 0:t?rCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&aCA(A,e,g),g};const jG=nA("debugspriterenderer"),BCA=nA("wireframe"),Jf=class{static getOrCreateGeometry(A){if(A._geometry)return A._geometry;if(A.guid&&Jf.cache[A.guid])return jG&&console.log("Take cached geometry for sprite",A.guid),Jf.cache[A.guid];const e=new de;A._geometry=e;const t=new Float32Array(A.triangles.length*3),g=new Float32Array(A.triangles.length*2);for(let I=0;I<A.triangles.length;I+=1){const o=A.triangles[I];t[I*3]=-A.vertices[o].x,t[I*3+1]=A.vertices[o].y,t[I*3+2]=0;const C=A.uv[o];g[I*2]=C.x,g[I*2+1]=1-C.y}return e.setAttribute("position",new Ce(t,3)),e.setAttribute("uv",new Ce(g,2)),A.guid&&(this.cache[A.guid]=e),jG&&console.log("Built sprite geometry",A,e),e}};let Uh=Jf;r(Uh,"cache",{});class kn{constructor(){r(this,"guid");r(this,"texture");r(this,"triangles");r(this,"uv");r(this,"vertices");r(this,"_geometry")}}aI([w()],kn.prototype,"guid",2);aI([w(Te)],kn.prototype,"texture",2);aI([JE()],kn.prototype,"triangles",2);aI([JE()],kn.prototype,"uv",2);aI([JE()],kn.prototype,"vertices",2);const O0=Symbol("spriteOwner");class Zd{constructor(){r(this,"sprites")}}aI([w(kn)],Zd.prototype,"sprites",2);class sc{constructor(){r(this,"spriteSheet");r(this,"index",0)}update(){if(!this.spriteSheet)return;const A=this.index;if(A<0||A>=this.spriteSheet.sprites.length)return;const e=this.spriteSheet.sprites[A];let t=e==null?void 0:e.texture;t&&(t.encoding=pe,t.minFilter==$e&&t.magFilter==$e&&(t.anisotropy=1),t.needsUpdate=!0)}}aI([w(Zd)],sc.prototype,"spriteSheet",2);aI([w()],sc.prototype,"index",2);class Cs extends MA{constructor(){super(...arguments);r(this,"drawMode",0);r(this,"size",{x:1,y:1});r(this,"color");r(this,"sharedMaterial");r(this,"_spriteSheet");r(this,"_currentSprite");r(this,"transparent",!0);r(this,"cutoutThreshold",0);r(this,"castShadows",!1)}get sprite(){return this._spriteSheet}set sprite(e){if(e!==this._spriteSheet)if(typeof e=="number"){const t=Math.floor(e);t===e&&(this.spriteIndex=t);return}else this._spriteSheet=e,this.updateSprite()}set spriteIndex(e){this._spriteSheet&&(this._spriteSheet.index=e,this.updateSprite())}get spriteIndex(){var e;return((e=this._spriteSheet)==null?void 0:e.index)??0}get spriteFrames(){var e,t;return((t=(e=this._spriteSheet)==null?void 0:e.spriteSheet)==null?void 0:t.sprites.length)??0}awake(){this._currentSprite=void 0,jG&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(){var t,g,I;if(!this.__didAwake||!((g=(t=this.sprite)==null?void 0:t.spriteSheet)!=null&&g.sprites))return;const e=this.sprite.spriteSheet.sprites[this.spriteIndex];if(this._currentSprite)this._currentSprite.geometry=Uh.getOrCreateGeometry(e),this._currentSprite.material.map=e.texture;else{const o=new wt({color:16777215,side:Nt});if(!o)return;if(BCA&&(o.wireframe=!0),this.color&&(o.color||(o.color=new wA),o.color.copy(this.color),o.opacity=this.color.alpha),o.transparent=!0,e.texture&&!o.wireframe){let C=e.texture;C[O0]!==void 0&&C[O0]!==this&&this.spriteFrames>1&&(C=e.texture=C.clone()),C[O0]=this,o.map=C}this.sharedMaterial=o,this._currentSprite=new pA(Uh.getOrCreateGeometry(e),o)}this._currentSprite.parent!==this.gameObject&&(this.drawMode===2&&this._currentSprite.scale.set(this.size.x,this.size.y,1),this.gameObject&&this.gameObject.add(this._currentSprite)),this._currentSprite&&this._currentSprite.layers.set(this.layer),this.sharedMaterial&&(this.sharedMaterial.alphaTest=this.cutoutThreshold,this.sharedMaterial.transparent=this.transparent),this._currentSprite.castShadow=this.castShadows,(I=this._spriteSheet)==null||I.update()}}aI([w()],Cs.prototype,"drawMode",2);aI([w(Gt)],Cs.prototype,"color",2);aI([w(Ke)],Cs.prototype,"sharedMaterial",2);aI([w(sc)],Cs.prototype,"sprite",1);aI([w()],Cs.prototype,"transparent",2);aI([w()],Cs.prototype,"cutoutThreshold",2);aI([w()],Cs.prototype,"castShadows",2);class FC{constructor(){r(this,"bb",null);r(this,"bb_pos",0)}__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsSyncedCameraModel(A,e){return(e||new FC).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedCameraModel(A,e){return A.setPosition(A.position()+pw),(e||new FC).__init(A.readInt32(A.position())+A.position(),A)}userId(A){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}guid(A){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,A):null}dontSave(){const A=this.bb.__offset(this.bb_pos,8);return A?!!this.bb.readInt8(this.bb_pos+A):!1}pos(A){const e=this.bb.__offset(this.bb_pos,10);return e?(A||new jI).__init(this.bb_pos+e,this.bb):null}rot(A){const e=this.bb.__offset(this.bb_pos,12);return e?(A||new jI).__init(this.bb_pos+e,this.bb):null}static startSyncedCameraModel(A){A.startObject(5)}static addUserId(A,e){A.addFieldOffset(0,e,0)}static addGuid(A,e){A.addFieldOffset(1,e,0)}static addDontSave(A,e){A.addFieldInt8(2,+e,0)}static addPos(A,e){A.addFieldStruct(3,e,0)}static addRot(A,e){A.addFieldStruct(4,e,0)}static endSyncedCameraModel(A){return A.endObject()}static finishSyncedCameraModelBuffer(A,e){A.finish(e)}static finishSizePrefixedSyncedCameraModelBuffer(A,e){A.finish(e,void 0,!0)}}var QCA=Object.defineProperty,ECA=Object.getOwnPropertyDescriptor,cCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?ECA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&QCA(A,e,g),g};const df="SCAM";em(df,FC.getRootAsSyncedCameraModel);const KI=new DE;class hCA{constructor(A,e){r(this,"userId");r(this,"guid");this.guid=e,this.userId=A}send(A,e){if(A){KI.clear();const t=KI.createString(this.guid),g=KI.createString(this.userId);FC.startSyncedCameraModel(KI),FC.addGuid(KI,t),FC.addUserId(KI,g);const I=ye(A),o=rw(A);FC.addPos(KI,jI.createVec3(KI,I.x,I.y,I.z)),FC.addRot(KI,jI.createVec3(KI,o.x,o.y,o.z));const C=FC.endSyncedCameraModel(KI);KI.finish(C,df),e.sendBinary(KI.asUint8Array())}}}var rk;const zG=(rk=class extends MA{constructor(){super(...arguments);r(this,"cameraPrefab",null);r(this,"_lastWorldPosition");r(this,"_lastWorldQuaternion");r(this,"_model",null);r(this,"_needsUpdate",!0);r(this,"_lastUpdateTime",0);r(this,"remoteCams",{});r(this,"userToCamMap",{});r(this,"_camTimeoutInSeconds",10);r(this,"_receiveCallback",null)}getCameraObject(A){const e=this.userToCamMap[A];return e?this.remoteCams[e].obj:null}async awake(){this._lastWorldPosition=this.worldPosition.clone(),this._lastWorldQuaternion=this.worldQuaternion.clone(),this.cameraPrefab&&("uri"in this.cameraPrefab&&(this.cameraPrefab=await this.cameraPrefab.instantiate(this.gameObject)),this.cameraPrefab&&"isObject3D"in this.cameraPrefab&&(this.cameraPrefab.visible=!1))}onEnable(){this._receiveCallback=this.context.connection.beginListenBinary(df,this.onReceivedRemoteCameraInfoBin.bind(this))}onDisable(){this.context.connection.stopListenBinary(df,this._receiveCallback)}update(){for(const g in this.remoteCams){const I=this.remoteCams[g],o=this.context.time.realtimeSinceStartup-I.lastUpdate;if(!I||o>this._camTimeoutInSeconds){console.log("Remote cam timeout",I,o),I!=null&&I.obj&&AA.destroy(I.obj),delete this.remoteCams[g],I&&delete this.userToCamMap[I.userId],zG.instances.push(I),this.context.players.removePlayerView(I.userId,_C.Browser);continue}}if(Se.IsInWebXR)return;const A=this.context.mainCamera;if(A===null){this.enabled=!1;return}if(!this.context.connection.isConnected||this.context.connection.connectionId===null)return;this._model===null&&(this._model=new hCA(this.context.connection.connectionId,this.context.connection.connectionId+"_camera"));const e=ye(A),t=Pi(A);(e.distanceTo(this._lastWorldPosition)>.001||t.angleTo(this._lastWorldQuaternion)>.01)&&(this._needsUpdate=!0),this._lastWorldPosition.copy(e),this._lastWorldQuaternion.copy(t),!((!this._needsUpdate||this.context.time.frameCount%2!==0)&&!(this.context.time.realtimeSinceStartup-this._lastUpdateTime>this._camTimeoutInSeconds*.5))&&(this._lastUpdateTime=this.context.time.realtimeSinceStartup,this._needsUpdate=!1,this._model.send(A,this.context.connection),this.context.isInXR||this.context.players.setPlayerView(this.context.connection.connectionId,A,_C.Browser))}onReceivedRemoteCameraInfoBin(A){const e=A.guid();if(!e)return;const t=A.userId();if(!t||!this.context.connection.userIsInRoom(t)||!this.cameraPrefab)return;let g=this.remoteCams[e];if(!g)if("isObject3D"in this.cameraPrefab){const s=new WC;s.context=this.context;const n=AA.instantiate(this.cameraPrefab,s);g=this.remoteCams[e]={obj:n,lastUpdate:this.context.time.realtimeSinceStartup,userId:t},g.obj.visible=!0,this.gameObject.add(n),this.userToCamMap[t]=e,zG.instances.push(g);const a=AA.getOrAddComponent(n,Ig);a.connectionId=t,a.avatar=n}else return;const I=g.obj;this.context.players.setPlayerView(t,I,_C.Browser),g.lastUpdate=this.context.time.realtimeSinceStartup,fI.markDirty(I);const o=A.pos();o&&zQ(I,o.x(),o.y(),o.z());const C=A.rot();C&&Bw(I,C.x(),C.y(),C.z())}},r(rk,"instances",[]),rk);let Sy=zG;cCA([w([UA,Cg])],Sy.prototype,"cameraPrefab",2);var lCA=Object.defineProperty,dCA=Object.getOwnPropertyDescriptor,Xd=(i,A,e,t)=>{for(var g=t>1?void 0:t?dCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&lCA(A,e,g),g};const P0="view",W0=nA("debugsyncedroom");class ja extends MA{constructor(){super(...arguments);r(this,"roomName");r(this,"urlParameterName","room");r(this,"joinRandomRoom",!0);r(this,"requireRoomParameter",!1);r(this,"autoRejoin",!0);r(this,"_roomPrefix");r(this,"_lastPingTime",0);r(this,"_lastRoomTime",-1)}get RoomPrefix(){return this._roomPrefix}awake(){W0&&console.log("Room",this.roomName,this.urlParameterName,this.joinRandomRoom,this.requireRoomParameter,this.autoRejoin),this._roomPrefix===void 0&&(this._roomPrefix=this.roomName,this.roomName="")}onEnable(){const e=nA(P0);if(e&&typeof e=="string"&&e.length>0){console.log("Join as viewer"),this.context.connection.joinRoom(e,!0);return}(this.joinRandomRoom||nA(this.urlParameterName))&&this.tryJoinRoom()}onDisable(){this.roomName&&this.roomName.length>0&&this.context.connection.leaveRoom(this.roomName)}tryJoinRandomRoom(){this.setRandomRoomUrlParameter(),this.tryJoinRoom()}tryJoinRoom(e=0){e===void 0&&(e=0);let t=!1;if(this.urlParameterName){const g=nA(this.urlParameterName);if(g&&typeof g=="string"){t=!0;const I=tb(g);this.roomName=I}else if(this.joinRandomRoom&&(console.log("No room name found in url, generating random one"),this.setRandomRoomUrlParameter(),e<1))return this.tryJoinRoom(e+1)}else this.joinRandomRoom&&(this.roomName===null||this.roomName===void 0||this.roomName.length<=0)&&(console.log("generate room name"),this.roomName=this.generateRoomName());return this.requireRoomParameter&&!t?(W0&&console.log('No required room parameter "'+this.urlParameterName+'" in url - will not connect to networking backend.'),!1):(this.context.connection.isConnected||this.context.connection.connect(),W0&&console.log("Join "+this.roomName),this._roomPrefix&&(this.roomName=this._roomPrefix+this.roomName),this.context.connection.joinRoom(this.roomName),!0)}update(){this.context.connection.isConnected&&(this.context.time.time-this._lastPingTime>3&&(this._lastPingTime=this.context.time.time,this.context.connection.sendPing()),this.context.connection.isInRoom&&(this._lastRoomTime=this.context.time.time)),this._lastRoomTime>0&&this.context.time.time-this._lastRoomTime>.3&&(this._lastRoomTime=-1,this.autoRejoin?(console.log("Disconnected from networking backend - attempt reconnecting now"),this.tryJoinRoom()):console.warn("You are not connected to a room anymore (possibly because the tab was inactive for too long and the server kicked you)"))}get currentRoomName(){const e=nA(P0);return e||nA(this.urlParameterName)}setRandomRoomUrlParameter(){const e=ql(),t=this.generateRoomName();nA(this.urlParameterName)?e.set(this.urlParameterName,t):e.append(this.urlParameterName,t),AM(t,e)}generateRoomName(){return eb()+"_"+Ab(100,999)}getViewOnlyUrl(){if(this.context.connection.isConnected&&this.context.connection.currentRoomViewId){const e=window.location.search,t=new URLSearchParams(e);return t.has(this.urlParameterName)&&t.delete(this.urlParameterName),t.set(P0,this.context.connection.currentRoomViewId),window.location.origin+window.location.pathname+"?"+t.toString()}return null}}Xd([w()],ja.prototype,"roomName",2);Xd([w()],ja.prototype,"urlParameterName",2);Xd([w()],ja.prototype,"joinRandomRoom",2);Xd([w()],ja.prototype,"requireRoomParameter",2);Xd([w()],ja.prototype,"autoRejoin",2);function uCA(){const i=nA("testwindowcount")||0;i&&i>0&&pCA(i)}function pCA(i){if(nA("testwindow"))return null;const A=new URL(window.location.href);Th(A.searchParams,If,1),Th(A.searchParams,"testwindow",1);const e=A.toString(),t=[];window.onbeforeunload=()=>{for(const s of t)s.close()};const g=.05,I=128;let o=0,C=0;for(let s=0;s<i;s++){o*I+I*.01>=window.innerWidth&&(C+=1,o=0);const n=o*(I*(1+g))+window.screenLeft,a=C*(I*(1+g))+window.screenTop+90+60*C;o+=1;const B=window.open(e,"test window "+s,`popup=yes width=${I} height=${I} top=${a} left=${n}`);if(!B){console.warn("Failed to open window");continue}t.push(B),B.onload=()=>{B.onbeforeunload=()=>{for(let Q=0;Q<t.length;Q++){const E=t[Q];E!==B&&E.close()}t.length=0}}}return t}class BU extends MA{awake(){uCA()}}class QU extends MA{constructor(){super(...arguments);r(this,"transformsPerFrame",10);r(this,"interval",0);r(this,"useFlatbuffers",!0);r(this,"builder",null);r(this,"models",null)}awake(){if(this.useFlatbuffers)this.context.connection.beginListenBinary(Bl,e=>{});else{this.models=[];for(let e=0;e<this.transformsPerFrame;e++)this.models.push(new z2(this.context.connection.connectionId+"_simulatedTransform_"+e,this))}}update(){if(this.context.connection.isConnected){if(this.useFlatbuffers){if(!this.context.connection.connectionId||this.context.time.frameCount%this.interval!==0)return;this.builder===null&&(this.builder=new DE(1024));const e=this.builder;for(let t=0;t<this.transformsPerFrame;t++){e.clear();const g=OT(this.context.connection.connectionId,this);this.context.connection.sendBinary(g)}}else if(this.models)for(let e=0;e<this.models.length;e++){const t=this.models[e];t.dontSave=!0,t.update(this,null),this.context.connection.send("TestSimulateUserData-"+e,t)}}}}class z2{constructor(A,e){r(this,"guid");r(this,"fast",!1);r(this,"position");r(this,"rotation");r(this,"velocity");r(this,"dontSave");this.guid=A,this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0,w:0},this.update(e,null)}isValid(){return this.fast!==void 0||this.position!==void 0||this.rotation!==void 0||this.velocity!==void 0}update(A,e){const t=A.worldPosition;this.position.x=t.x,this.position.y=t.y,this.position.z=t.z;const g=A.worldQuaternion;if(this.rotation.x=g.x,this.rotation.y=g.y,this.rotation.z=g.z,this.rotation.w=g.w,this.fast=!1,e){const I=e.getVelocity();this.velocity===void 0&&(this.velocity={x:0,y:0,z:0}),this.velocity.x=I.x,this.velocity.y=I.y,this.velocity.z=I.z}}}r(z2,"temp",new S);var DCA=Object.defineProperty,fCA=Object.getOwnPropertyDescriptor,nc=(i,A,e,t)=>{for(var g=t>1?void 0:t?fCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&DCA(A,e,g),g};class ss extends Yg{constructor(){super(...arguments);r(this,"offset");r(this,"rotation");r(this,"focusArea");r(this,"feather");r(this,"kernelSize");r(this,"resolutionScale")}get typeName(){return"TiltShiftEffect"}init(){this.offset.defaultValue=0,this.rotation.defaultValue=0,this.focusArea.defaultValue=.4,this.feather.defaultValue=.3,this.kernelSize.defaultValue=In.MEDIUM,this.resolutionScale.defaultValue=1/window.devicePixelRatio}onCreateEffect(){console.log(this);const e=new f5({kernelSize:In.VERY_LARGE});return this.offset.onValueChanged=t=>e.offset=t,this.rotation.onValueChanged=t=>e.rotation=t,this.focusArea.onValueChanged=t=>e.focusArea=t,this.feather.onValueChanged=t=>e.feather=t,this.kernelSize.onValueChanged=t=>e.blurPass.kernelSize=t,this.resolutionScale.onValueChanged=t=>e.resolution.scale=t/window.devicePixelRatio,e}}nc([w(Me)],ss.prototype,"offset",2);nc([w(Me)],ss.prototype,"rotation",2);nc([w(Me)],ss.prototype,"focusArea",2);nc([w(Me)],ss.prototype,"feather",2);nc([w(Me)],ss.prototype,"kernelSize",2);nc([w(Me)],ss.prototype,"resolutionScale",2);Yo("TiltShiftEffect",ss);var wCA=Object.defineProperty,yCA=Object.getOwnPropertyDescriptor,SCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?yCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&wCA(A,e,g),g};class $d extends Yg{constructor(){super(...arguments);r(this,"mode")}get typeName(){return"ToneMapping"}get isToneMapping(){return!0}init(){this.mode.defaultValue=$g}apply(){this.mode.onValueChanged=this._apply.bind(this),this._apply(this.mode.value)}unapply(){this.context.renderer.toneMapping=$g}_apply(e){switch(e){case 0:this.context.renderer.toneMapping=Oh;break;case 1:this.context.renderer.toneMapping=sM;break;case 2:this.context.renderer.toneMapping=nM;break}}}SCA([w(Me)],$d.prototype,"mode",2);Yo("Tonemapping",$d);const sr=new uE,hI=new S,Vn=new S,Yt=new kA,vq={X:new S(1,0,0),Y:new S(0,1,0),Z:new S(0,0,1)},V0={type:"change"},xq={type:"mouseDown"},Yq={type:"mouseUp",mode:null},Tq={type:"objectChange"};class kCA extends UA{constructor(A,e){super(),e===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),e=document),this.isTransformControls=!0,this.visible=!1,this.domElement=e,this.domElement.style.touchAction="none";const t=new FCA;this._gizmo=t,this.add(t);const g=new NCA;this._plane=g,this.add(g);const I=this;function o(p,u){let D=u;Object.defineProperty(I,p,{get:function(){return D!==void 0?D:u},set:function(y){D!==y&&(D=y,g[p]=y,t[p]=y,I.dispatchEvent({type:p+"-changed",value:y}),I.dispatchEvent(V0))}}),I[p]=u,g[p]=u,t[p]=u}o("camera",A),o("object",void 0),o("enabled",!0),o("axis",null),o("mode","translate"),o("translationSnap",null),o("rotationSnap",null),o("scaleSnap",null),o("space","world"),o("size",1),o("dragging",!1),o("showX",!0),o("showY",!0),o("showZ",!0);const C=new S,s=new S,n=new kA,a=new kA,B=new S,Q=new kA,E=new S,c=new S,h=new S,l=0,d=new S;o("worldPosition",C),o("worldPositionStart",s),o("worldQuaternion",n),o("worldQuaternionStart",a),o("cameraPosition",B),o("cameraQuaternion",Q),o("pointStart",E),o("pointEnd",c),o("rotationAxis",h),o("rotationAngle",l),o("eye",d),this._offset=new S,this._startNorm=new S,this._endNorm=new S,this._cameraScale=new S,this._parentPosition=new S,this._parentQuaternion=new kA,this._parentQuaternionInv=new kA,this._parentScale=new S,this._worldScaleStart=new S,this._worldQuaternionInv=new kA,this._worldScale=new S,this._positionStart=new S,this._quaternionStart=new kA,this._scaleStart=new S,this._getPointer=GCA.bind(this),this._onPointerDown=mCA.bind(this),this._onPointerHover=MCA.bind(this),this._onPointerMove=RCA.bind(this),this._onPointerUp=UCA.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){this.object!==void 0&&(this.object.updateMatrixWorld(),this.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(A){if(this.object===void 0||this.dragging===!0)return;sr.setFromCamera(A,this.camera);const e=j0(this._gizmo.picker[this.mode],sr);e?this.axis=e.object.name:this.axis=null}pointerDown(A){if(!(this.object===void 0||this.dragging===!0||A.button!==0)&&this.axis!==null){sr.setFromCamera(A,this.camera);const e=j0(this._plane,sr,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,xq.mode=this.mode,this.dispatchEvent(xq)}}pointerMove(A){const e=this.axis,t=this.mode,g=this.object;let I=this.space;if(t==="scale"?I="local":(e==="E"||e==="XYZE"||e==="XYZ")&&(I="world"),g===void 0||e===null||this.dragging===!1||A.button!==-1)return;sr.setFromCamera(A,this.camera);const o=j0(this._plane,sr,!0);if(o){if(this.pointEnd.copy(o.point).sub(this.worldPositionStart),t==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),I==="local"&&e!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),e.indexOf("X")===-1&&(this._offset.x=0),e.indexOf("Y")===-1&&(this._offset.y=0),e.indexOf("Z")===-1&&(this._offset.z=0),I==="local"&&e!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),g.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(I==="local"&&(g.position.applyQuaternion(Yt.copy(this._quaternionStart).invert()),e.search("X")!==-1&&(g.position.x=Math.round(g.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(g.position.y=Math.round(g.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(g.position.z=Math.round(g.position.z/this.translationSnap)*this.translationSnap),g.position.applyQuaternion(this._quaternionStart)),I==="world"&&(g.parent&&g.position.add(hI.setFromMatrixPosition(g.parent.matrixWorld)),e.search("X")!==-1&&(g.position.x=Math.round(g.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(g.position.y=Math.round(g.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(g.position.z=Math.round(g.position.z/this.translationSnap)*this.translationSnap),g.parent&&g.position.sub(hI.setFromMatrixPosition(g.parent.matrixWorld))));else if(t==="scale"){if(e.search("XYZ")!==-1){let C=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(C*=-1),Vn.set(C,C,C)}else hI.copy(this.pointStart),Vn.copy(this.pointEnd),hI.applyQuaternion(this._worldQuaternionInv),Vn.applyQuaternion(this._worldQuaternionInv),Vn.divide(hI),e.search("X")===-1&&(Vn.x=1),e.search("Y")===-1&&(Vn.y=1),e.search("Z")===-1&&(Vn.z=1);g.scale.copy(this._scaleStart).multiply(Vn),this.scaleSnap&&(e.search("X")!==-1&&(g.scale.x=Math.round(g.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Y")!==-1&&(g.scale.y=Math.round(g.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Z")!==-1&&(g.scale.z=Math.round(g.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(t==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const C=20/this.worldPosition.distanceTo(hI.setFromMatrixPosition(this.camera.matrixWorld));e==="E"?(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1):e==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(hI.copy(this.rotationAxis).cross(this.eye))*C):(e==="X"||e==="Y"||e==="Z")&&(this.rotationAxis.copy(vq[e]),hI.copy(vq[e]),I==="local"&&hI.applyQuaternion(this.worldQuaternion),this.rotationAngle=this._offset.dot(hI.cross(this.eye).normalize())*C),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),I==="local"&&e!=="E"&&e!=="XYZE"?(g.quaternion.copy(this._quaternionStart),g.quaternion.multiply(Yt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),g.quaternion.copy(Yt.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),g.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(V0),this.dispatchEvent(Tq)}}pointerUp(A){A.button===0&&(this.dragging&&this.axis!==null&&(Yq.mode=this.mode,this.dispatchEvent(Yq)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(A){A.geometry&&A.geometry.dispose(),A.material&&A.material.dispose()})}attach(A){return this.object=A,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(V0),this.dispatchEvent(Tq),this.pointStart.copy(this.pointEnd))}getRaycaster(){return sr}getMode(){return this.mode}setMode(A){this.mode=A}setTranslationSnap(A){this.translationSnap=A}setRotationSnap(A){this.rotationSnap=A}setScaleSnap(A){this.scaleSnap=A}setSize(A){this.size=A}setSpace(A){this.space=A}}function GCA(i){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:i.button};{const A=this.domElement.getBoundingClientRect();return{x:(i.clientX-A.left)/A.width*2-1,y:-(i.clientY-A.top)/A.height*2+1,button:i.button}}}function MCA(i){if(this.enabled)switch(i.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(i));break}}function mCA(i){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(i.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(i)),this.pointerDown(this._getPointer(i)))}function RCA(i){this.enabled&&this.pointerMove(this._getPointer(i))}function UCA(i){this.enabled&&(this.domElement.releasePointerCapture(i.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(i)))}function j0(i,A,e){const t=A.intersectObject(i,!0);for(let g=0;g<t.length;g++)if(t[g].object.visible||e)return t[g];return!1}const kp=new Fi,St=new S(0,1,0),Hq=new S(0,0,0),_q=new NA,Gp=new kA,dD=new kA,SC=new S,Oq=new NA,oh=new S(1,0,0),cr=new S(0,1,0),Ch=new S(0,0,1),Mp=new S,vc=new S,xc=new S;class FCA extends UA{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const A=new wt({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=new pi({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=A.clone();t.opacity=.15;const g=e.clone();g.opacity=.5;const I=A.clone();I.color.setHex(16711680);const o=A.clone();o.color.setHex(65280);const C=A.clone();C.color.setHex(255);const s=A.clone();s.color.setHex(16711680),s.opacity=.5;const n=A.clone();n.color.setHex(65280),n.opacity=.5;const a=A.clone();a.color.setHex(255),a.opacity=.5;const B=A.clone();B.opacity=.25;const Q=A.clone();Q.color.setHex(16776960),Q.opacity=.25,A.clone().color.setHex(16776960);const c=A.clone();c.color.setHex(7895160);const h=new ei(0,.04,.1,12);h.translate(0,.05,0);const l=new pt(.08,.08,.08);l.translate(0,.04,0);const d=new de;d.setAttribute("position",new Ie([0,0,0,1,0,0],3));const p=new ei(.0075,.0075,.5,3);p.translate(0,.25,0);function u(_,eA){const $=new KC(_,.0075,3,64,eA*Math.PI*2);return $.rotateY(Math.PI/2),$.rotateX(Math.PI/2),$}function D(){const _=new de;return _.setAttribute("position",new Ie([0,0,0,1,1,1],3)),_}const y={X:[[new pA(h,I),[.5,0,0],[0,0,-Math.PI/2]],[new pA(h,I),[-.5,0,0],[0,0,Math.PI/2]],[new pA(p,I),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new pA(h,o),[0,.5,0]],[new pA(h,o),[0,-.5,0],[Math.PI,0,0]],[new pA(p,o)]],Z:[[new pA(h,C),[0,0,.5],[Math.PI/2,0,0]],[new pA(h,C),[0,0,-.5],[-Math.PI/2,0,0]],[new pA(p,C),null,[Math.PI/2,0,0]]],XYZ:[[new pA(new bC(.1,0),B.clone()),[0,0,0]]],XY:[[new pA(new pt(.15,.15,.01),a.clone()),[.15,.15,0]]],YZ:[[new pA(new pt(.15,.15,.01),s.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new pA(new pt(.15,.15,.01),n.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},k={X:[[new pA(new ei(.2,0,.6,4),t),[.3,0,0],[0,0,-Math.PI/2]],[new pA(new ei(.2,0,.6,4),t),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new pA(new ei(.2,0,.6,4),t),[0,.3,0]],[new pA(new ei(.2,0,.6,4),t),[0,-.3,0],[0,0,Math.PI]]],Z:[[new pA(new ei(.2,0,.6,4),t),[0,0,.3],[Math.PI/2,0,0]],[new pA(new ei(.2,0,.6,4),t),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new pA(new bC(.2,0),t)]],XY:[[new pA(new pt(.2,.2,.01),t),[.15,.15,0]]],YZ:[[new pA(new pt(.2,.2,.01),t),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new pA(new pt(.2,.2,.01),t),[.15,0,.15],[-Math.PI/2,0,0]]]},R={START:[[new pA(new bC(.01,2),g),null,null,null,"helper"]],END:[[new pA(new bC(.01,2),g),null,null,null,"helper"]],DELTA:[[new ci(D(),g),null,null,null,"helper"]],X:[[new ci(d,g.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new ci(d,g.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new ci(d,g.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},f={XYZE:[[new pA(u(.5,1),c),null,[0,Math.PI/2,0]]],X:[[new pA(u(.5,.5),I)]],Y:[[new pA(u(.5,.5),o),null,[0,0,-Math.PI/2]]],Z:[[new pA(u(.5,.5),C),null,[0,Math.PI/2,0]]],E:[[new pA(u(.75,1),Q),null,[0,Math.PI/2,0]]]},M={AXIS:[[new ci(d,g.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},U={XYZE:[[new pA(new $I(.25,10,8),t)]],X:[[new pA(new KC(.5,.1,4,24),t),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new pA(new KC(.5,.1,4,24),t),[0,0,0],[Math.PI/2,0,0]]],Z:[[new pA(new KC(.5,.1,4,24),t),[0,0,0],[0,0,-Math.PI/2]]],E:[[new pA(new KC(.75,.1,2,24),t)]]},J={X:[[new pA(l,I),[.5,0,0],[0,0,-Math.PI/2]],[new pA(p,I),[0,0,0],[0,0,-Math.PI/2]],[new pA(l,I),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new pA(l,o),[0,.5,0]],[new pA(p,o)],[new pA(l,o),[0,-.5,0],[0,0,Math.PI]]],Z:[[new pA(l,C),[0,0,.5],[Math.PI/2,0,0]],[new pA(p,C),[0,0,0],[Math.PI/2,0,0]],[new pA(l,C),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new pA(new pt(.15,.15,.01),a),[.15,.15,0]]],YZ:[[new pA(new pt(.15,.15,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new pA(new pt(.15,.15,.01),n),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new pA(new pt(.1,.1,.1),B.clone())]]},H={X:[[new pA(new ei(.2,0,.6,4),t),[.3,0,0],[0,0,-Math.PI/2]],[new pA(new ei(.2,0,.6,4),t),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new pA(new ei(.2,0,.6,4),t),[0,.3,0]],[new pA(new ei(.2,0,.6,4),t),[0,-.3,0],[0,0,Math.PI]]],Z:[[new pA(new ei(.2,0,.6,4),t),[0,0,.3],[Math.PI/2,0,0]],[new pA(new ei(.2,0,.6,4),t),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new pA(new pt(.2,.2,.01),t),[.15,.15,0]]],YZ:[[new pA(new pt(.2,.2,.01),t),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new pA(new pt(.2,.2,.01),t),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new pA(new pt(.2,.2,.2),t),[0,0,0]]]},Y={X:[[new ci(d,g.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new ci(d,g.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new ci(d,g.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function b(_){const eA=new UA;for(const $ in _)for(let X=_[$].length;X--;){const cA=_[$][X][0].clone(),EA=_[$][X][1],KA=_[$][X][2],uA=_[$][X][3],gA=_[$][X][4];cA.name=$,cA.tag=gA,EA&&cA.position.set(EA[0],EA[1],EA[2]),KA&&cA.rotation.set(KA[0],KA[1],KA[2]),uA&&cA.scale.set(uA[0],uA[1],uA[2]),cA.updateMatrix();const rA=cA.geometry.clone();rA.applyMatrix4(cA.matrix),cA.geometry=rA,cA.renderOrder=1/0,cA.position.set(0,0,0),cA.rotation.set(0,0,0),cA.scale.set(1,1,1),eA.add(cA)}return eA}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=b(y)),this.add(this.gizmo.rotate=b(f)),this.add(this.gizmo.scale=b(J)),this.add(this.picker.translate=b(k)),this.add(this.picker.rotate=b(U)),this.add(this.picker.scale=b(H)),this.add(this.helper.translate=b(R)),this.add(this.helper.rotate=b(M)),this.add(this.helper.scale=b(Y)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(A){const t=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:dD;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let g=[];g=g.concat(this.picker[this.mode].children),g=g.concat(this.gizmo[this.mode].children),g=g.concat(this.helper[this.mode].children);for(let I=0;I<g.length;I++){const o=g[I];o.visible=!0,o.rotation.set(0,0,0),o.position.copy(this.worldPosition);let C;if(this.camera.isOrthographicCamera?C=(this.camera.top-this.camera.bottom)/this.camera.zoom:C=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),o.scale.set(1,1,1).multiplyScalar(C*this.size/4),o.tag==="helper"){o.visible=!1,o.name==="AXIS"?(o.position.copy(this.worldPositionStart),o.visible=!!this.axis,this.axis==="X"&&(Yt.setFromEuler(kp.set(0,0,0)),o.quaternion.copy(t).multiply(Yt),Math.abs(St.copy(oh).applyQuaternion(t).dot(this.eye))>.9&&(o.visible=!1)),this.axis==="Y"&&(Yt.setFromEuler(kp.set(0,0,Math.PI/2)),o.quaternion.copy(t).multiply(Yt),Math.abs(St.copy(cr).applyQuaternion(t).dot(this.eye))>.9&&(o.visible=!1)),this.axis==="Z"&&(Yt.setFromEuler(kp.set(0,Math.PI/2,0)),o.quaternion.copy(t).multiply(Yt),Math.abs(St.copy(Ch).applyQuaternion(t).dot(this.eye))>.9&&(o.visible=!1)),this.axis==="XYZE"&&(Yt.setFromEuler(kp.set(0,Math.PI/2,0)),St.copy(this.rotationAxis),o.quaternion.setFromRotationMatrix(_q.lookAt(Hq,St,cr)),o.quaternion.multiply(Yt),o.visible=this.dragging),this.axis==="E"&&(o.visible=!1)):o.name==="START"?(o.position.copy(this.worldPositionStart),o.visible=this.dragging):o.name==="END"?(o.position.copy(this.worldPosition),o.visible=this.dragging):o.name==="DELTA"?(o.position.copy(this.worldPositionStart),o.quaternion.copy(this.worldQuaternionStart),hI.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),hI.applyQuaternion(this.worldQuaternionStart.clone().invert()),o.scale.copy(hI),o.visible=this.dragging):(o.quaternion.copy(t),this.dragging?o.position.copy(this.worldPositionStart):o.position.copy(this.worldPosition),this.axis&&(o.visible=this.axis.search(o.name)!==-1));continue}o.quaternion.copy(t),this.mode==="translate"||this.mode==="scale"?(o.name==="X"&&Math.abs(St.copy(oh).applyQuaternion(t).dot(this.eye))>.99&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="Y"&&Math.abs(St.copy(cr).applyQuaternion(t).dot(this.eye))>.99&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="Z"&&Math.abs(St.copy(Ch).applyQuaternion(t).dot(this.eye))>.99&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="XY"&&Math.abs(St.copy(Ch).applyQuaternion(t).dot(this.eye))<.2&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="YZ"&&Math.abs(St.copy(oh).applyQuaternion(t).dot(this.eye))<.2&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1),o.name==="XZ"&&Math.abs(St.copy(cr).applyQuaternion(t).dot(this.eye))<.2&&(o.scale.set(1e-10,1e-10,1e-10),o.visible=!1)):this.mode==="rotate"&&(Gp.copy(t),St.copy(this.eye).applyQuaternion(Yt.copy(t).invert()),o.name.search("E")!==-1&&o.quaternion.setFromRotationMatrix(_q.lookAt(this.eye,Hq,cr)),o.name==="X"&&(Yt.setFromAxisAngle(oh,Math.atan2(-St.y,St.z)),Yt.multiplyQuaternions(Gp,Yt),o.quaternion.copy(Yt)),o.name==="Y"&&(Yt.setFromAxisAngle(cr,Math.atan2(St.x,St.z)),Yt.multiplyQuaternions(Gp,Yt),o.quaternion.copy(Yt)),o.name==="Z"&&(Yt.setFromAxisAngle(Ch,Math.atan2(St.y,St.x)),Yt.multiplyQuaternions(Gp,Yt),o.quaternion.copy(Yt))),o.visible=o.visible&&(o.name.indexOf("X")===-1||this.showX),o.visible=o.visible&&(o.name.indexOf("Y")===-1||this.showY),o.visible=o.visible&&(o.name.indexOf("Z")===-1||this.showZ),o.visible=o.visible&&(o.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),o.material._color=o.material._color||o.material.color.clone(),o.material._opacity=o.material._opacity||o.material.opacity,o.material.color.copy(o.material._color),o.material.opacity=o.material._opacity,this.enabled&&this.axis&&(o.name===this.axis||this.axis.split("").some(function(s){return o.name===s}))&&(o.material.color.setHex(16776960),o.material.opacity=1)}super.updateMatrixWorld(A)}}class NCA extends pA{constructor(){super(new ng(1e5,1e5,2,2),new wt({visible:!1,wireframe:!0,side:Nt,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(A){let e=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(e="local"),Mp.copy(oh).applyQuaternion(e==="local"?this.worldQuaternion:dD),vc.copy(cr).applyQuaternion(e==="local"?this.worldQuaternion:dD),xc.copy(Ch).applyQuaternion(e==="local"?this.worldQuaternion:dD),St.copy(vc),this.mode){case"translate":case"scale":switch(this.axis){case"X":St.copy(this.eye).cross(Mp),SC.copy(Mp).cross(St);break;case"Y":St.copy(this.eye).cross(vc),SC.copy(vc).cross(St);break;case"Z":St.copy(this.eye).cross(xc),SC.copy(xc).cross(St);break;case"XY":SC.copy(xc);break;case"YZ":SC.copy(Mp);break;case"XZ":St.copy(xc),SC.copy(vc);break;case"XYZ":case"E":SC.set(0,0,0);break}break;case"rotate":default:SC.set(0,0,0)}SC.length()===0?this.quaternion.copy(this.cameraQuaternion):(Oq.lookAt(hI.set(0,0,0),SC,St),this.quaternion.setFromRotationMatrix(Oq)),super.updateMatrixWorld(A)}}var KCA=Object.defineProperty,JCA=Object.getOwnPropertyDescriptor,ky=(i,A,e,t)=>{for(var g=t>1?void 0:t?JCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&KCA(A,e,g),g};class SB extends MA{constructor(){super(...arguments);r(this,"isGizmo",!1);r(this,"translationSnap",1);r(this,"rotationSnapAngle",15);r(this,"scaleSnap",.25);r(this,"control");r(this,"orbit");r(this,"changeEventListener");r(this,"windowKeyDownListener");r(this,"windowKeyUpListener")}onEnable(){var e;this.isGizmo&&!td||this.context.mainCamera&&(this.control||(this.control=new kCA(this.context.mainCamera,this.context.domElement),this.control.visible=!0,this.control.enabled=!0,this.control.getRaycaster().layers.set(2),this.control.size=1,this.control.traverse(t=>{const g=t;if(g.layers.set(2),g){const I=g.material;I&&(I.opacity=.3)}}),this.orbit=AA.getComponentInParent(this.context.mainCamera,un)??void 0),this.control&&(this.context.scene.add(this.control),this.control.attach(this.gameObject),this.changeEventListener=this.onControlChangedEvent.bind(this),(e=this.control)==null||e.addEventListener("dragging-changed",this.changeEventListener),this.addWindowEvents()))}onDisable(){var e,t;(e=this.control)==null||e.removeFromParent(),this.changeEventListener&&((t=this.control)==null||t.removeEventListener("dragging-changed",this.changeEventListener)),this.removeWindowEvents()}enableSnapping(){this.control&&(this.control.setTranslationSnap(this.translationSnap),this.control.setRotationSnap(AI.degToRad(this.rotationSnapAngle)),this.control.setScaleSnap(this.scaleSnap))}disableSnapping(){this.control&&(this.control.setTranslationSnap(null),this.control.setRotationSnap(null),this.control.setScaleSnap(null))}onControlChangedEvent(e){const t=this.orbit;if(t&&(t.enabled=!e.value),e.value){const g=AA.getComponentInParent(this.gameObject,wa);g&&g.requestOwnership()}}addWindowEvents(){const e=this.control;e&&(this.windowKeyDownListener||(this.windowKeyDownListener=t=>{if(this.enabled)switch(t.keyCode){case 81:e.setSpace(e.space==="local"?"world":"local");break;case 16:this.enableSnapping();break;case 87:e.setMode("translate");break;case 69:e.setMode("rotate");break;case 82:e.setMode("scale");break;case 187:case 107:e.setSize(e.size+.1);break;case 189:case 109:e.setSize(Math.max(e.size-.1,.1));break;case 88:e.showX=!e.showX;break;case 89:e.showY=!e.showY;break;case 90:e.showZ=!e.showZ;break;case 32:e.enabled=!e.enabled;break}}),this.windowKeyUpListener||(this.windowKeyUpListener=t=>{if(this.enabled)switch(t.keyCode){case 16:this.disableSnapping();break}}),window.addEventListener("keydown",this.windowKeyDownListener),window.addEventListener("keyup",this.windowKeyUpListener))}removeWindowEvents(){window.removeEventListener("keydown",this.windowKeyDownListener),window.removeEventListener("keyup",this.windowKeyUpListener)}}ky([w()],SB.prototype,"isGizmo",2);ky([w()],SB.prototype,"translationSnap",2);ky([w()],SB.prototype,"rotationSnapAngle",2);ky([w()],SB.prototype,"scaleSnap",2);var qCA=Object.defineProperty,bCA=Object.getOwnPropertyDescriptor,EU=(i,A,e,t)=>{for(var g=t>1?void 0:t?bCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&qCA(A,e,g),g};class kB extends Yg{constructor(){super(...arguments);r(this,"color");r(this,"intensity");r(this,"center")}get typeName(){return"Vignette"}init(){this.color.defaultValue={r:0,g:0,b:0,a:1},this.intensity.defaultValue=0,this.center.defaultValue={x:.5,y:.5}}onCreateEffect(){const e=new gY;return this.intensity.onValueChanged=t=>{e.offset=t,this.updateDarkness(e)},this.color.onValueChanged=t=>{this.updateDarkness(e)},e}updateDarkness(e){const t=this.intensity.value;e.darkness=t}}EU([w(Me)],kB.prototype,"color",2);EU([w(Me)],kB.prototype,"intensity",2);EU([w(Me)],kB.prototype,"center",2);Yo("Vignette",kB);var LCA=Object.defineProperty,vCA=Object.getOwnPropertyDescriptor,xCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?vCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&LCA(A,e,g),g};const z0=nA("debugpost");class Gy extends MA{constructor(){super(...arguments);r(this,"sharedProfile");r(this,"_postprocessing");r(this,"_effects",[]);r(this,"_lastApplyTime");r(this,"_rapidApplyCount",0);r(this,"_isDirty",!1);r(this,"_modificationQueue");r(this,"_recreateId",-1)}markDirty(){this._isDirty=!0}awake(){var e;(e=this.sharedProfile)==null||e.init(),z0&&(console.log(this),console.log("Press P to toggle post processing"),window.addEventListener("keydown",t=>{t.key==="p"&&(console.log("Toggle volume: "+this.name,!this.enabled),this.enabled=!this.enabled)}))}onDisable(){var e;(e=this._postprocessing)==null||e.unapply()}onBeforeRender(){if(!this.context.isInXR){if(this.context.composer&&!(this.context.composer instanceof dm))return;this.context.mainCamera&&(!this._postprocessing||!this._postprocessing.isActive||this._isDirty)&&this.apply(),this.context.composer&&(this.context.composer.setRenderer(this.context.renderer),this.context.composer.setMainScene(this.context.scene),this.context.mainCamera&&this.context.composer.setMainCamera(this.context.mainCamera))}}onDestroy(){var e;(e=this._postprocessing)==null||e.dispose()}apply(){var t,g;z0&&console.log("Apply PostProcessing",this,(t=this.context.mainCamera)==null?void 0:t.name),qg()&&(this._lastApplyTime!==void 0&&Date.now()-this._lastApplyTime<100&&(this._rapidApplyCount++,this._rapidApplyCount===5&&console.warn("Detected rapid post processing modifications - this might be a bug",this)),this._lastApplyTime=Date.now()),this._isDirty=!1,this.unapply(),this._effects.length=0,(g=this.sharedProfile)!=null&&g.components&&this._effects.push(...this.sharedProfile.components);const e=this.gameObject.getComponentsInChildren(Yg);if(z0&&(e!=null&&e.length)&&console.log("Additional",e),e)for(const I of e)I.active&&this._effects.push(I);this._effects.length>0&&(this._postprocessing||(this._postprocessing=new Dy(this.context)),this._postprocessing.apply(this._effects),this._applyPostQueue())}unapply(){var e;(e=this._postprocessing)==null||e.unapply()}_applyPostQueue(){if(this._modificationQueue){for(const e of this._modificationQueue.values())this.onEditorModification(e);this._modificationQueue.clear()}}onEditorModification(e){var t,g;if(e.propertyName.startsWith("postprocessing.")){if(!this._postprocessing)return this._modificationQueue||(this._modificationQueue=new Map),this._modificationQueue.set(e.propertyName,e),!0;if(!((t=this._effects)!=null&&t.length))return;const I=e.propertyName.split(".");if(I.length===3||I.length===4){const o=I[1],C=I[2];for(const s of this._effects)if(((g=s.typeName)==null?void 0:g.toLowerCase())===o.toLowerCase()){if(C==="active"){s.active=e.value,this.scheduleRecreate();return}if(!mp.has(o)){const n=new Array;mp.set(o,n);const a=Object.keys(s);for(const B of a)s[B]instanceof Me&&n.push(B)}if(mp.has(o)){const n=C.toLowerCase(),a=mp.get(o);for(const B of a)if(B.toLowerCase()===n){const Q=s[B];Q instanceof Me&&(I.length===4&&I[3]==="active"?(Q.overrideState=e.value,this.scheduleRecreate()):Q&&Q.value!==void 0&&(Q.value=e.value));return}}console.warn("Unknown modification",C);return}}return!0}return!1}scheduleRecreate(){const e=++this._recreateId;setTimeout(()=>{e===this._recreateId&&(this.onDisable(),this.onEnable())},200)}}xCA([JE(md)],Gy.prototype,"sharedProfile",2);const mp=new Map;var YCA=Object.defineProperty,TCA=Object.getOwnPropertyDescriptor,HCA=(i,A,e,t)=>{for(var g=t>1?void 0:t?TCA(A,e):A,I=i.length-1,o;I>=0;I--)(o=i[I])&&(g=(t?o(A,e,g):o(g))||g);return t&&g&&YCA(A,e,g),g};class My extends MA{constructor(){super(...arguments);r(this,"backgroundTint",new Gt(1,1,1,1));r(this,"_preRender");r(this,"backgroundPlane");r(this,"threeTexture");r(this,"forceTextureInitialization",function(){const e=new wt,t=new ng,g=new GI;g.add(new pA(t,e));const I=new $r;return function(C,s){e.map=s,C.render(g,I)}}())}awake(){Se.OptionalFeatures_AR.push("camera-access")}get background(){return this.backgroundPlane}onEnable(){this._preRender=this.preRender.bind(this),this.context.pre_render_callbacks.push(this._preRender),this.backgroundPlane&&(this.gameObject.add(this.backgroundPlane),this.backgroundPlane.visible=!1)}onDisable(){this.context.pre_render_callbacks=this.context.pre_render_callbacks.filter(e=>e!==this._preRender),this.backgroundPlane&&this.gameObject.remove(this.backgroundPlane)}preRender(){if(!this||!this.gameObject)return;const t=this.context.renderer.xr.getFrame();t&&(!this.threeTexture&&this.context.renderer&&(this.threeTexture=new Te,this.forceTextureInitialization(this.context.renderer,this.threeTexture)),this.backgroundPlane===void 0&&(this.backgroundPlane=OCA(this.backgroundTint),this.gameObject.add(this.backgroundPlane)),this.updateFromFrame(t))}onBeforeRender(e){this.updateFromFrame(e)}updateFromFrame(e){if(!e)return;const t=e.getViewerPose(this.context.renderer.xr.getReferenceSpace());if(t){for(const g of t.views)if("camera"in g&&g.camera){let o=this.context.renderer.xr.getBinding();if(o||(o=new XRWebGLBinding(e.session,this.context.renderer.getContext())),o){let C=null;if("getCameraImage"in o){C=o.getCameraImage(g.camera);const s=this.context.renderer.properties.get(this.threeTexture);s.__webglTexture=C,this.backgroundPlane&&(this.backgroundPlane.setTexture(this.threeTexture),this.backgroundPlane.visible=!0)}}}}}}HCA([w()],My.prototype,"backgroundTint",2);let _CA=`
|
|
5439
5439
|
uniform sampler2D t2D;
|
|
5440
5440
|
|
|
5441
5441
|
varying vec2 vUv;
|