@needle-tools/engine 3.32.18-alpha → 3.32.19-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 +3 -0
- package/dist/needle-engine.js +14 -12
- package/dist/needle-engine.light.js +14 -12
- package/dist/needle-engine.light.min.js +7 -5
- package/dist/needle-engine.light.umd.cjs +7 -5
- package/dist/needle-engine.min.js +7 -5
- package/dist/needle-engine.umd.cjs +7 -5
- package/lib/engine/engine_context.d.ts +2 -1
- package/lib/engine/engine_context.js +4 -3
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine-components/ui/CanvasGroup.js +1 -0
- package/lib/engine-components/ui/CanvasGroup.js.map +1 -1
- package/package.json +1 -1
- package/plugins/vite/dependency-watcher.js +3 -2
- package/src/engine/engine_context.ts +4 -3
- package/src/engine-components/ui/CanvasGroup.ts +1 -0
|
@@ -3944,7 +3944,7 @@ Open this page console: `+e.toString())}const i=ja()||W0()&&wt();if(i&&(D9(),Vk(
|
|
|
3944
3944
|
}
|
|
3945
3945
|
}
|
|
3946
3946
|
`,Mo?.prepend(t),i===!0&&EC()<=0&&z9(),console.log("\u{1F335} Debug console has loaded")}},e.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(e)}function H9(){return document.querySelector("#__vconsole .vc-switch")||null}function W9(){return document.querySelector("#__vconsole")||null}const X9=te("nodevlogs");function ms(i,e=Eo.Log){Ql(e,i)}function is(i){ms(i,Eo.Warn)}function Xk(i){ms(i,Eo.Error)}let DC;function wt(){return X9?!1:DC!==void 0?DC:un()}function q9(i){DC=i}const Iu=new Tp,Wr=new w,nh=new w,Hi=new Ie,qk={X:new w(1,0,0),Y:new w(0,1,0),Z:new w(0,0,1)},kC={type:"change"},Yk={type:"mouseDown"},Jk={type:"mouseUp",mode:null},Kk={type:"objectChange"};class Y9 extends ye{constructor(e,t){super(),t===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),t=document),this.isTransformControls=!0,this.visible=!1,this.domElement=t,this.domElement.style.touchAction="none";const s=new LC;this._gizmo=s,this.add(s);const r=new tX;this._plane=r,this.add(r);const n=this;function o(v,b){let _=b;Object.defineProperty(n,v,{get:function(){return _!==void 0?_:b},set:function(S){_!==S&&(_=S,r[v]=S,s[v]=S,n.dispatchEvent({type:v+"-changed",value:S}),n.dispatchEvent(kC))}}),n[v]=b,r[v]=b,s[v]=b}o("camera",e),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 a=new w,l=new w,c=new Ie,u=new Ie,d=new w,p=new Ie,f=new w,m=new w,A=new w,y=0,g=new w;o("worldPosition",a),o("worldPositionStart",l),o("worldQuaternion",c),o("worldQuaternionStart",u),o("cameraPosition",d),o("cameraQuaternion",p),o("pointStart",f),o("pointEnd",m),o("rotationAxis",A),o("rotationAngle",y),o("eye",g),this._offset=new w,this._startNorm=new w,this._endNorm=new w,this._cameraScale=new w,this._parentPosition=new w,this._parentQuaternion=new Ie,this._parentQuaternionInv=new Ie,this._parentScale=new w,this._worldScaleStart=new w,this._worldQuaternionInv=new Ie,this._worldScale=new w,this._positionStart=new w,this._quaternionStart=new Ie,this._scaleStart=new w,this._getPointer=J9.bind(this),this._onPointerDown=Z9.bind(this),this._onPointerHover=K9.bind(this),this._onPointerMove=$9.bind(this),this._onPointerUp=eX.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(e){if(this.object===void 0||this.dragging===!0)return;Iu.setFromCamera(e,this.camera);const t=OC(this._gizmo.picker[this.mode],Iu);t?this.axis=t.object.name:this.axis=null}pointerDown(e){if(!(this.object===void 0||this.dragging===!0||e.button!==0)&&this.axis!==null){Iu.setFromCamera(e,this.camera);const t=OC(this._plane,Iu,!0);t&&(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(t.point).sub(this.worldPositionStart)),this.dragging=!0,Yk.mode=this.mode,this.dispatchEvent(Yk)}}pointerMove(e){const t=this.axis,s=this.mode,r=this.object;let n=this.space;if(s==="scale"?n="local":(t==="E"||t==="XYZE"||t==="XYZ")&&(n="world"),r===void 0||t===null||this.dragging===!1||e.button!==-1)return;Iu.setFromCamera(e,this.camera);const o=OC(this._plane,Iu,!0);if(o){if(this.pointEnd.copy(o.point).sub(this.worldPositionStart),s==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),n==="local"&&t!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),t.indexOf("X")===-1&&(this._offset.x=0),t.indexOf("Y")===-1&&(this._offset.y=0),t.indexOf("Z")===-1&&(this._offset.z=0),n==="local"&&t!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),r.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(n==="local"&&(r.position.applyQuaternion(Hi.copy(this._quaternionStart).invert()),t.search("X")!==-1&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.position.applyQuaternion(this._quaternionStart)),n==="world"&&(r.parent&&r.position.add(Wr.setFromMatrixPosition(r.parent.matrixWorld)),t.search("X")!==-1&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.parent&&r.position.sub(Wr.setFromMatrixPosition(r.parent.matrixWorld))));else if(s==="scale"){if(t.search("XYZ")!==-1){let a=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(a*=-1),nh.set(a,a,a)}else Wr.copy(this.pointStart),nh.copy(this.pointEnd),Wr.applyQuaternion(this._worldQuaternionInv),nh.applyQuaternion(this._worldQuaternionInv),nh.divide(Wr),t.search("X")===-1&&(nh.x=1),t.search("Y")===-1&&(nh.y=1),t.search("Z")===-1&&(nh.z=1);r.scale.copy(this._scaleStart).multiply(nh),this.scaleSnap&&(t.search("X")!==-1&&(r.scale.x=Math.round(r.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Y")!==-1&&(r.scale.y=Math.round(r.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Z")!==-1&&(r.scale.z=Math.round(r.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(s==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const a=20/this.worldPosition.distanceTo(Wr.setFromMatrixPosition(this.camera.matrixWorld));let l=!1;t==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(Wr.copy(this.rotationAxis).cross(this.eye))*a):(t==="X"||t==="Y"||t==="Z")&&(this.rotationAxis.copy(qk[t]),Wr.copy(qk[t]),n==="local"&&Wr.applyQuaternion(this.worldQuaternion),Wr.cross(this.eye),Wr.length()===0?l=!0:this.rotationAngle=this._offset.dot(Wr.normalize())*a),(t==="E"||l)&&(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),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),n==="local"&&t!=="E"&&t!=="XYZE"?(r.quaternion.copy(this._quaternionStart),r.quaternion.multiply(Hi.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),r.quaternion.copy(Hi.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),r.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(kC),this.dispatchEvent(Kk)}}pointerUp(e){e.button===0&&(this.dragging&&this.axis!==null&&(Jk.mode=this.mode,this.dispatchEvent(Jk)),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(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}attach(e){return this.object=e,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(kC),this.dispatchEvent(Kk),this.pointStart.copy(this.pointEnd))}getRaycaster(){return Iu}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}}function J9(i){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:i.button};{const e=this.domElement.getBoundingClientRect();return{x:(i.clientX-e.left)/e.width*2-1,y:-(i.clientY-e.top)/e.height*2+1,button:i.button}}}function K9(i){if(this.enabled)switch(i.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(i));break}}function Z9(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 $9(i){this.enabled&&this.pointerMove(this._getPointer(i))}function eX(i){this.enabled&&(this.domElement.releasePointerCapture(i.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(i)))}function OC(i,e,t){const s=e.intersectObject(i,!0);for(let r=0;r<s.length;r++)if(s[r].object.visible||t)return s[r];return!1}const q0=new Ur,Bi=new w(0,1,0),Zk=new w(0,0,0),$k=new Te,Y0=new Ie,J0=new Ie,Qa=new w,eO=new Te,cg=new w(1,0,0),Ru=new w(0,1,0),hg=new w(0,0,1),K0=new w,ug=new w,dg=new w;class LC extends ye{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const e=new ri({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new _s({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),s=e.clone();s.opacity=.15;const r=t.clone();r.opacity=.5;const n=e.clone();n.color.setHex(16711680);const o=e.clone();o.color.setHex(65280);const a=e.clone();a.color.setHex(255);const l=e.clone();l.color.setHex(16711680),l.opacity=.5;const c=e.clone();c.color.setHex(65280),c.opacity=.5;const u=e.clone();u.color.setHex(255),u.opacity=.5;const d=e.clone();d.opacity=.25;const p=e.clone();p.color.setHex(16776960),p.opacity=.25,e.clone().color.setHex(16776960);const f=e.clone();f.color.setHex(7895160);const m=new Ms(0,.04,.1,12);m.translate(0,.05,0);const A=new Fi(.08,.08,.08);A.translate(0,.04,0);const y=new gt;y.setAttribute("position",new ot([0,0,0,1,0,0],3));const g=new Ms(.0075,.0075,.5,3);g.translate(0,.25,0);function v(N,H){const L=new Pc(N,.0075,3,64,H*Math.PI*2);return L.rotateY(Math.PI/2),L.rotateX(Math.PI/2),L}function b(){const N=new gt;return N.setAttribute("position",new ot([0,0,0,1,1,1],3)),N}const _={X:[[new ve(m,n),[.5,0,0],[0,0,-Math.PI/2]],[new ve(m,n),[-.5,0,0],[0,0,Math.PI/2]],[new ve(g,n),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new ve(m,o),[0,.5,0]],[new ve(m,o),[0,-.5,0],[Math.PI,0,0]],[new ve(g,o)]],Z:[[new ve(m,a),[0,0,.5],[Math.PI/2,0,0]],[new ve(m,a),[0,0,-.5],[-Math.PI/2,0,0]],[new ve(g,a),null,[Math.PI/2,0,0]]],XYZ:[[new ve(new Rc(.1,0),d.clone()),[0,0,0]]],XY:[[new ve(new Fi(.15,.15,.01),u.clone()),[.15,.15,0]]],YZ:[[new ve(new Fi(.15,.15,.01),l.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new ve(new Fi(.15,.15,.01),c.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},S={X:[[new ve(new Ms(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new ve(new Ms(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new ve(new Ms(.2,0,.6,4),s),[0,.3,0]],[new ve(new Ms(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new ve(new Ms(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new ve(new Ms(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new ve(new Rc(.2,0),s)]],XY:[[new ve(new Fi(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new ve(new Fi(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new ve(new Fi(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]]},M={START:[[new ve(new Rc(.01,2),r),null,null,null,"helper"]],END:[[new ve(new Rc(.01,2),r),null,null,null,"helper"]],DELTA:[[new xs(b(),r),null,null,null,"helper"]],X:[[new xs(y,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new xs(y,r.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new xs(y,r.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},C={XYZE:[[new ve(v(.5,1),f),null,[0,Math.PI/2,0]]],X:[[new ve(v(.5,.5),n)]],Y:[[new ve(v(.5,.5),o),null,[0,0,-Math.PI/2]]],Z:[[new ve(v(.5,.5),a),null,[0,Math.PI/2,0]]],E:[[new ve(v(.75,1),p),null,[0,Math.PI/2,0]]]},R={AXIS:[[new xs(y,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},I={XYZE:[[new ve(new Ta(.25,10,8),s)]],X:[[new ve(new Pc(.5,.1,4,24),s),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new ve(new Pc(.5,.1,4,24),s),[0,0,0],[Math.PI/2,0,0]]],Z:[[new ve(new Pc(.5,.1,4,24),s),[0,0,0],[0,0,-Math.PI/2]]],E:[[new ve(new Pc(.75,.1,2,24),s)]]},E={X:[[new ve(A,n),[.5,0,0],[0,0,-Math.PI/2]],[new ve(g,n),[0,0,0],[0,0,-Math.PI/2]],[new ve(A,n),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new ve(A,o),[0,.5,0]],[new ve(g,o)],[new ve(A,o),[0,-.5,0],[0,0,Math.PI]]],Z:[[new ve(A,a),[0,0,.5],[Math.PI/2,0,0]],[new ve(g,a),[0,0,0],[Math.PI/2,0,0]],[new ve(A,a),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new ve(new Fi(.15,.15,.01),u),[.15,.15,0]]],YZ:[[new ve(new Fi(.15,.15,.01),l),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new ve(new Fi(.15,.15,.01),c),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new ve(new Fi(.1,.1,.1),d.clone())]]},z={X:[[new ve(new Ms(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new ve(new Ms(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new ve(new Ms(.2,0,.6,4),s),[0,.3,0]],[new ve(new Ms(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new ve(new Ms(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new ve(new Ms(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new ve(new Fi(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new ve(new Fi(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new ve(new Fi(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new ve(new Fi(.2,.2,.2),s),[0,0,0]]]},F={X:[[new xs(y,r.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new xs(y,r.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new xs(y,r.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function q(N){const H=new ye;for(const L in N)for(let j=N[L].length;j--;){const Q=N[L][j][0].clone(),$=N[L][j][1],Z=N[L][j][2],se=N[L][j][3],Ae=N[L][j][4];Q.name=L,Q.tag=Ae,$&&Q.position.set($[0],$[1],$[2]),Z&&Q.rotation.set(Z[0],Z[1],Z[2]),se&&Q.scale.set(se[0],se[1],se[2]),Q.updateMatrix();const Ue=Q.geometry.clone();Ue.applyMatrix4(Q.matrix),Q.geometry=Ue,Q.renderOrder=1/0,Q.position.set(0,0,0),Q.rotation.set(0,0,0),Q.scale.set(1,1,1),H.add(Q)}return H}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=q(_)),this.add(this.gizmo.rotate=q(C)),this.add(this.gizmo.scale=q(E)),this.add(this.picker.translate=q(S)),this.add(this.picker.rotate=q(I)),this.add(this.picker.scale=q(z)),this.add(this.helper.translate=q(M)),this.add(this.helper.rotate=q(R)),this.add(this.helper.scale=q(F)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){const t=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:J0;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 s=[];s=s.concat(this.picker[this.mode].children),s=s.concat(this.gizmo[this.mode].children),s=s.concat(this.helper[this.mode].children);for(let r=0;r<s.length;r++){const n=s[r];n.visible=!0,n.rotation.set(0,0,0),n.position.copy(this.worldPosition);let o;if(this.camera.isOrthographicCamera?o=(this.camera.top-this.camera.bottom)/this.camera.zoom:o=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),n.scale.set(1,1,1).multiplyScalar(o*this.size/4),n.tag==="helper"){n.visible=!1,n.name==="AXIS"?(n.visible=!!this.axis,this.axis==="X"&&(Hi.setFromEuler(q0.set(0,0,0)),n.quaternion.copy(t).multiply(Hi),Math.abs(Bi.copy(cg).applyQuaternion(t).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="Y"&&(Hi.setFromEuler(q0.set(0,0,Math.PI/2)),n.quaternion.copy(t).multiply(Hi),Math.abs(Bi.copy(Ru).applyQuaternion(t).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="Z"&&(Hi.setFromEuler(q0.set(0,Math.PI/2,0)),n.quaternion.copy(t).multiply(Hi),Math.abs(Bi.copy(hg).applyQuaternion(t).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="XYZE"&&(Hi.setFromEuler(q0.set(0,Math.PI/2,0)),Bi.copy(this.rotationAxis),n.quaternion.setFromRotationMatrix($k.lookAt(Zk,Bi,Ru)),n.quaternion.multiply(Hi),n.visible=this.dragging),this.axis==="E"&&(n.visible=!1)):n.name==="START"?(n.position.copy(this.worldPositionStart),n.visible=this.dragging):n.name==="END"?(n.position.copy(this.worldPosition),n.visible=this.dragging):n.name==="DELTA"?(n.position.copy(this.worldPositionStart),n.quaternion.copy(this.worldQuaternionStart),Wr.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),Wr.applyQuaternion(this.worldQuaternionStart.clone().invert()),n.scale.copy(Wr),n.visible=this.dragging):(n.quaternion.copy(t),this.dragging?n.position.copy(this.worldPositionStart):n.position.copy(this.worldPosition),this.axis&&(n.visible=this.axis.search(n.name)!==-1));continue}n.quaternion.copy(t),this.mode==="translate"||this.mode==="scale"?(n.name==="X"&&Math.abs(Bi.copy(cg).applyQuaternion(t).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Y"&&Math.abs(Bi.copy(Ru).applyQuaternion(t).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Z"&&Math.abs(Bi.copy(hg).applyQuaternion(t).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XY"&&Math.abs(Bi.copy(hg).applyQuaternion(t).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="YZ"&&Math.abs(Bi.copy(cg).applyQuaternion(t).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XZ"&&Math.abs(Bi.copy(Ru).applyQuaternion(t).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1)):this.mode==="rotate"&&(Y0.copy(t),Bi.copy(this.eye).applyQuaternion(Hi.copy(t).invert()),n.name.search("E")!==-1&&n.quaternion.setFromRotationMatrix($k.lookAt(this.eye,Zk,Ru)),n.name==="X"&&(Hi.setFromAxisAngle(cg,Math.atan2(-Bi.y,Bi.z)),Hi.multiplyQuaternions(Y0,Hi),n.quaternion.copy(Hi)),n.name==="Y"&&(Hi.setFromAxisAngle(Ru,Math.atan2(Bi.x,Bi.z)),Hi.multiplyQuaternions(Y0,Hi),n.quaternion.copy(Hi)),n.name==="Z"&&(Hi.setFromAxisAngle(hg,Math.atan2(Bi.y,Bi.x)),Hi.multiplyQuaternions(Y0,Hi),n.quaternion.copy(Hi))),n.visible=n.visible&&(n.name.indexOf("X")===-1||this.showX),n.visible=n.visible&&(n.name.indexOf("Y")===-1||this.showY),n.visible=n.visible&&(n.name.indexOf("Z")===-1||this.showZ),n.visible=n.visible&&(n.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),n.material._color=n.material._color||n.material.color.clone(),n.material._opacity=n.material._opacity||n.material.opacity,n.material.color.copy(n.material._color),n.material.opacity=n.material._opacity,this.enabled&&this.axis&&(n.name===this.axis||this.axis.split("").some(function(a){return n.name===a}))&&(n.material.color.setHex(16776960),n.material.opacity=1)}super.updateMatrixWorld(e)}}class tX extends ve{constructor(){super(new Ys(1e5,1e5,2,2),new ri({visible:!1,wireframe:!0,side:fi,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(t="local"),K0.copy(cg).applyQuaternion(t==="local"?this.worldQuaternion:J0),ug.copy(Ru).applyQuaternion(t==="local"?this.worldQuaternion:J0),dg.copy(hg).applyQuaternion(t==="local"?this.worldQuaternion:J0),Bi.copy(ug),this.mode){case"translate":case"scale":switch(this.axis){case"X":Bi.copy(this.eye).cross(K0),Qa.copy(K0).cross(Bi);break;case"Y":Bi.copy(this.eye).cross(ug),Qa.copy(ug).cross(Bi);break;case"Z":Bi.copy(this.eye).cross(dg),Qa.copy(dg).cross(Bi);break;case"XY":Qa.copy(dg);break;case"YZ":Qa.copy(K0);break;case"XZ":Bi.copy(dg),Qa.copy(ug);break;case"XYZ":case"E":Qa.set(0,0,0);break}break;case"rotate":default:Qa.set(0,0,0)}Qa.length()===0?this.quaternion.copy(this.cameraQuaternion):(eO.lookAt(Wr.set(0,0,0),Qa,Bi),this.quaternion.setFromRotationMatrix(eO)),super.updateMatrixWorld(e)}}const iX=te("debugpatch");function Z0(i,e,t,s){const r=iX===e;if(!t&&!s)return;const n=e+"___needle";rX(i,e,t,s);const o=Object.getOwnPropertyDescriptor(i,e),a=i[e];r&&console.log("Patch",i.constructor.name,e,o,a),o?(r&&console.log("Apply patch with existing descriptor",i.constructor.name,e,o),typeof o.value=="function"&&(i[e]=iO(o.value,i,e))):(r&&console.log("Create patch with new property",i.constructor.name,e,o),Object.defineProperty(i,e,{set:function(l){if(typeof l=="function")this[n]=iO(l,i,e);else{const c=this[n];sO(i,e,this,c,l),this[n]=l,rO(i,e,this,c,l)}},get:function(){const l=this[n];return typeof l=="function"&&l[n]?l[n]:l}}))}function sX(i,e,t){const s=FC(i,e);if(s)for(let r=s.length-1;r>=0;r--){const n=s[r];n.prefix===t&&(n.prefix=null),n.postfix===t&&(n.postfix=null),!n.prefix&&!n.postfix&&s.splice(r,1)}}const tO=Symbol("Needle:Patches:WrappedFunction");function iO(i,e,t){if(i[tO])return i;const s=function(...r){sO(e,t,this,...r);const n=i.apply(this,r);return rO(e,t,this,n,...r),n};return s[tO]=!0,s}const $0="Needle:Patches";function UC(){return globalThis[$0]||(globalThis[$0]=new WeakMap),globalThis[$0]}function FC(i,e){const t=UC().get(i);return t?t.get(e):null}function rX(i,e,t,s){let r=UC().get(i);r||(r=new Map,UC().set(i,r));let n=r.get(e);n||(n=[],r.set(e,n)),n.push({prefix:t,postfix:s})}function sO(i,e,t,...s){var r;if(!t)return;const n=FC(i,e);if(n)for(const o of n)(r=o.prefix)==null||r.call(t,...s)}function rO(i,e,t,s,...r){var n;if(!t)return;const o=FC(i,e);if(o)for(const a of o)(n=a.postfix)==null||n.call(t,s,...r)}const nO=Symbol("gltf-loader-internal-usage-tracker"),nX=te("debugusers"),eb=class{constructor(i){h(this,"parser"),h(this,"_getDependency"),h(this,"_loadingId"),h(this,"_loadedObjects",new Set),this.parser=i,this._getDependency=this.parser.getDependency,this._loadingId=Date.now().toString()}get name(){return"NEEDLE_internal_usage_tracker"}static isLoading(i){return eb._loadingProcesses>0}beforeRoot(){eb._loadingProcesses++;const i=this,e=this._getDependency;return this.parser.getDependency=function(t,s){const r=e.call(this,t,s);return r.then(n=>(n&&(i._loadedObjects.add(n),n[nO]=i._loadingId),n)),r},null}afterRoot(i){eb._loadingProcesses--,this.parser.getDependency=this._getDependency;for(const e of this._loadedObjects)delete e[nO],e instanceof ye&&(e.parent||e instanceof ve&&(nX&&console.warn("> GLTF LOADER: Mesh not used in scene!",e),e.material=null,e.geometry=null));return null}};let NC=eb;h(NC,"_loadingProcesses",0);class oO{constructor(){window.addEventListener("unhandledrejection",e=>{var t;if(e.defaultPrevented)return;const s=(t=e?.reason)==null?void 0:t.path;if(s){const r=s[0];r&&r.tagName==="IMG"&&(console.warn(`Could not load image:
|
|
3947
|
-
`+r.src),e.preventDefault())}})}}const tb=te("trackresources");function aO(){return tb==="dispose"}let Pu=!0;tb===0&&(Pu=!1);function oX(i){Pu=i}function lO(){return Pu}const cO=Symbol("disposable");function zC(i,e){i&&(i[cO]=e,Bu&&console.warn("Set disposable",e,i))}const hO=Symbol("disposed");function aX(i){return i[hO]===!0}function Oi(i){var e;if(i){if(i[cO]===!1){Bu&&console.warn("Object is marked as not disposable",i);return}if(i[hO]=!0,i instanceof Vr)Oi(i.environment),Oi(i.background),Oi(i.customDepthMaterial),Oi(i.customDistanceMaterial);else if(i instanceof oa)Oi(i.geometry),Oi(i.material),Oi(i.skeleton),Oi(i.bindMatrix),Oi(i.bindMatrixInverse),Oi(i.customDepthMaterial),Oi(i.customDistanceMaterial),i.geometry=null,i.material=null;else if(i instanceof ve)Oi(i.geometry),Oi(i.material),Oi(i.customDepthMaterial),Oi(i.customDistanceMaterial),i.geometry=null,i.material=null;else if(i instanceof gt){kp(i);for(const t of Object.keys(i.attributes)){const s=i.attributes[t];Oi(s)}}else if(i instanceof Ze||i instanceof Tn)Bu&&console.warn("BufferAttribute dispose not supported",i.count);else if(i instanceof Array)for(const t of i)t instanceof Lt&&Oi(t);else if(i instanceof Lt){kp(i);for(const s of Object.keys(i)){const r=i[s];r instanceof Nt&&(Oi(r),i[s]=null)}const t=i.uniforms;if(t)for(const s of Object.keys(t)){const r=t[s];r instanceof Nt?(Oi(r),t[s]=null):r instanceof Me&&(Oi(r.value),r.value=null)}}else i instanceof Nt?(kp(i),kp(i.source),((e=i.source)==null?void 0:e.data)instanceof ImageBitmap&&kp(i.source.data)):i instanceof lm?(kp(i.boneTexture),i.boneTexture=null):i instanceof Wm||!(i instanceof ye)&&Bu&&console.warn("Unknown object type",i)}}function kp(i){i&&((Bu||aO()||tb)&&console.warn("\u{1F9E8} FREE",i),i instanceof ImageBitmap?i.close():i instanceof Rl?i.data=null:i.dispose())}function uO(i){(i instanceof ve||i instanceof oa)&&(i.material=null,i.geometry=null)}const lX=new Set;function jC(i,e,t=null,s){if(s||(s=lX,s.clear()),!i)return s;const r=i[pg];if(r)for(const n of r)s.has(n)||t?.call(null,n)!==!1&&(s.add(n),e&&jC(n,!0,t,s));return s}function cX(i){return i[fg]}const Bu=te("debugresourceusers")||te("debugmemory"),pg=Symbol("needle-resource-users"),fg=Symbol("needle-resource-users-count");function dn(i,e){Z0(i,e,function(t,s){Pu&&(ib(pg,this,t,!1),ib(pg,this,s,!0))})}Pu&&(dn(ve.prototype,"material"),dn(ve.prototype,"geometry"),dn(Lt.prototype,"map"),dn(Lt.prototype,"bumpMap"),dn(Lt.prototype,"alphaMap"),dn(Lt.prototype,"normalMap"),dn(Lt.prototype,"displacementMap"),dn(Lt.prototype,"roughnessMap"),dn(Lt.prototype,"metalnessMap"),dn(Lt.prototype,"emissiveMap"),dn(Lt.prototype,"specularMap"),dn(Lt.prototype,"envMap"),dn(Lt.prototype,"lightMap"),dn(Lt.prototype,"aoMap"),dn(Lt.prototype,"gradientMap"));function hX(i){if(Pu===!1)return;const e=i[pg];if(e)for(const t of e)ib(pg,t,i,!1)}Pu&&Z0(Lt.prototype,"dispose",function(){hX(this)});let GC=0;function ib(i,e,t,s){if(GC>0)return;if(Array.isArray(t)){for(const n of t)ib(i,e,n,s);return}if(!t)return;let r=t[i];if(r||(r=new Set),s){if(e&&!r.has(e)){r.add(e);let n=t[fg]||0;n+=1,t[fg]=n,Bu&&console.warn(`\u{1F7E2} Added user of "${t.type}"`,e,t,n,"users:",r)}}else if(e&&r.has(e)){r.delete(e);let n=t[fg]||0;n>0&&(n-=1,t[fg]=n),Bu&&console.warn(`\u{1F534} Removed user of "${t.type}"`,e,t,n,"users:",r),n<=0&&(NC.isLoading(t)||(tb&&console.warn(`\u{1F534} Removed all user of "${t.type}"`,t),aO()&&Oi(t)))}t[i]=r}try{Z0(Fl.prototype,"render",function(){GC++},function(){GC--})}catch(i){console.warn("Could not wrap WebGLRenderer.render",i)}var mg=(i=>(i.Added="component-added",i.Removing="removing-component",i))(mg||{});const dO=te("debugcomponentevents");class gg{static addComponentLifecylceEventListener(e,t){this.eventListeners.has(e)&&this.eventListeners.set(e,[]);let s=this.eventListeners.get(e);s||(s=[]),s.push(t),this.eventListeners.set(e,s),dO&&console.log("Added event listener for "+e,this.eventListeners)}static removeComponentLifecylceEventListener(e,t){const s=this.eventListeners.get(e);if(!s)return;const r=s.indexOf(t);r<0||s.splice(r,1)}static dispatchComponentLifecycleEvent(e,t){const s=this.eventListeners.get(e);if(dO&&console.log("Dispatching event "+e,s),!!s)for(const r of s)r(t)}}h(gg,"eventListeners",new Map);const pO=te("debugdefines");Op('if(!globalThis[""3.32.
|
|
3947
|
+
`+r.src),e.preventDefault())}})}}const tb=te("trackresources");function aO(){return tb==="dispose"}let Pu=!0;tb===0&&(Pu=!1);function oX(i){Pu=i}function lO(){return Pu}const cO=Symbol("disposable");function zC(i,e){i&&(i[cO]=e,Bu&&console.warn("Set disposable",e,i))}const hO=Symbol("disposed");function aX(i){return i[hO]===!0}function Oi(i){var e;if(i){if(i[cO]===!1){Bu&&console.warn("Object is marked as not disposable",i);return}if(i[hO]=!0,i instanceof Vr)Oi(i.environment),Oi(i.background),Oi(i.customDepthMaterial),Oi(i.customDistanceMaterial);else if(i instanceof oa)Oi(i.geometry),Oi(i.material),Oi(i.skeleton),Oi(i.bindMatrix),Oi(i.bindMatrixInverse),Oi(i.customDepthMaterial),Oi(i.customDistanceMaterial),i.geometry=null,i.material=null;else if(i instanceof ve)Oi(i.geometry),Oi(i.material),Oi(i.customDepthMaterial),Oi(i.customDistanceMaterial),i.geometry=null,i.material=null;else if(i instanceof gt){kp(i);for(const t of Object.keys(i.attributes)){const s=i.attributes[t];Oi(s)}}else if(i instanceof Ze||i instanceof Tn)Bu&&console.warn("BufferAttribute dispose not supported",i.count);else if(i instanceof Array)for(const t of i)t instanceof Lt&&Oi(t);else if(i instanceof Lt){kp(i);for(const s of Object.keys(i)){const r=i[s];r instanceof Nt&&(Oi(r),i[s]=null)}const t=i.uniforms;if(t)for(const s of Object.keys(t)){const r=t[s];r instanceof Nt?(Oi(r),t[s]=null):r instanceof Me&&(Oi(r.value),r.value=null)}}else i instanceof Nt?(kp(i),kp(i.source),((e=i.source)==null?void 0:e.data)instanceof ImageBitmap&&kp(i.source.data)):i instanceof lm?(kp(i.boneTexture),i.boneTexture=null):i instanceof Wm||!(i instanceof ye)&&Bu&&console.warn("Unknown object type",i)}}function kp(i){i&&((Bu||aO()||tb)&&console.warn("\u{1F9E8} FREE",i),i instanceof ImageBitmap?i.close():i instanceof Rl?i.data=null:i.dispose())}function uO(i){(i instanceof ve||i instanceof oa)&&(i.material=null,i.geometry=null)}const lX=new Set;function jC(i,e,t=null,s){if(s||(s=lX,s.clear()),!i)return s;const r=i[pg];if(r)for(const n of r)s.has(n)||t?.call(null,n)!==!1&&(s.add(n),e&&jC(n,!0,t,s));return s}function cX(i){return i[fg]}const Bu=te("debugresourceusers")||te("debugmemory"),pg=Symbol("needle-resource-users"),fg=Symbol("needle-resource-users-count");function dn(i,e){Z0(i,e,function(t,s){Pu&&(ib(pg,this,t,!1),ib(pg,this,s,!0))})}Pu&&(dn(ve.prototype,"material"),dn(ve.prototype,"geometry"),dn(Lt.prototype,"map"),dn(Lt.prototype,"bumpMap"),dn(Lt.prototype,"alphaMap"),dn(Lt.prototype,"normalMap"),dn(Lt.prototype,"displacementMap"),dn(Lt.prototype,"roughnessMap"),dn(Lt.prototype,"metalnessMap"),dn(Lt.prototype,"emissiveMap"),dn(Lt.prototype,"specularMap"),dn(Lt.prototype,"envMap"),dn(Lt.prototype,"lightMap"),dn(Lt.prototype,"aoMap"),dn(Lt.prototype,"gradientMap"));function hX(i){if(Pu===!1)return;const e=i[pg];if(e)for(const t of e)ib(pg,t,i,!1)}Pu&&Z0(Lt.prototype,"dispose",function(){hX(this)});let GC=0;function ib(i,e,t,s){if(GC>0)return;if(Array.isArray(t)){for(const n of t)ib(i,e,n,s);return}if(!t)return;let r=t[i];if(r||(r=new Set),s){if(e&&!r.has(e)){r.add(e);let n=t[fg]||0;n+=1,t[fg]=n,Bu&&console.warn(`\u{1F7E2} Added user of "${t.type}"`,e,t,n,"users:",r)}}else if(e&&r.has(e)){r.delete(e);let n=t[fg]||0;n>0&&(n-=1,t[fg]=n),Bu&&console.warn(`\u{1F534} Removed user of "${t.type}"`,e,t,n,"users:",r),n<=0&&(NC.isLoading(t)||(tb&&console.warn(`\u{1F534} Removed all user of "${t.type}"`,t),aO()&&Oi(t)))}t[i]=r}try{Z0(Fl.prototype,"render",function(){GC++},function(){GC--})}catch(i){console.warn("Could not wrap WebGLRenderer.render",i)}var mg=(i=>(i.Added="component-added",i.Removing="removing-component",i))(mg||{});const dO=te("debugcomponentevents");class gg{static addComponentLifecylceEventListener(e,t){this.eventListeners.has(e)&&this.eventListeners.set(e,[]);let s=this.eventListeners.get(e);s||(s=[]),s.push(t),this.eventListeners.set(e,s),dO&&console.log("Added event listener for "+e,this.eventListeners)}static removeComponentLifecylceEventListener(e,t){const s=this.eventListeners.get(e);if(!s)return;const r=s.indexOf(t);r<0||s.splice(r,1)}static dispatchComponentLifecycleEvent(e,t){const s=this.eventListeners.get(e);if(dO&&console.log("Dispatching event "+e,s),!!s)for(const r of s)r(t)}}h(gg,"eventListeners",new Map);const pO=te("debugdefines");Op('if(!globalThis[""3.32.19-alpha""]) globalThis[""3.32.19-alpha""] = "0.0.0";'),Op('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),Op('if(!globalThis[""Fri Feb 09 2024 21:56:39 GMT+0800 (Pacific Standard Time)""]) globalThis[""Fri Feb 09 2024 21:56:39 GMT+0800 (Pacific Standard Time)""] = "unknown";'),Op('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.32.19-alpha";'),Op('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),Op('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Fri Feb 09 2024 21:56:39 GMT+0800 (Pacific Standard Time)";');const Hl="3.32.19-alpha",sb="undefined",uX="Fri Feb 09 2024 21:56:39 GMT+0800 (Pacific Standard Time)";pO&&console.log(`Engine version: ${Hl} (generator: ${sb})
|
|
3948
3948
|
Project built at ${uX}`);const Wl="needle_isActiveInHierarchy",Du="builtin_components",vg="needle_editor_guid";function Op(i){try{(0,eval)(i)}catch(e){pO&&console.error(e)}}const Ag=Symbol("NEEDLE_NEED_UPDATE_INSTANCE"),fO=Symbol("isUsingInstancing"),mO=Symbol("instancingRenderer"),QC=Symbol("instancingAutoUpdateBounds");class Pa{static isUsingInstancing(e){return e[fO]===!0}static getRenderer(e){return e[mO]||null}setAutoUpdateBounds(e,t){const s=Pa.getRenderer(e);s&&(s[QC]=t)}static markDirty(e,t=!0){if(e&&(this.isUsingInstancing(e)&&(e[Ag]=!0,e.matrixWorldNeedsUpdate=!0),t))for(const s of e.children)Pa.markDirty(s,!0)}}function ku(i,e){try{e?i(e):i()}catch(t){return console.error(t),!1}return!0}const VC=te("debugnewscripts"),dX=te("debughierarchy"),Wi=[];function pX(){return Wi.length>0}function rb(i){if(!(i.new_scripts.length<=0)){if(VC&&console.log("Register new components",i.new_scripts.length,[...i.new_scripts],i.alias?"element: "+i.alias:i.hash,i),i.new_scripts_pre_setup_callbacks.length>0){for(const e of i.new_scripts_pre_setup_callbacks)e&&e();i.new_scripts_pre_setup_callbacks.length=0}Wi.length=0,i.new_scripts.length>0&&Wi.push(...i.new_scripts),i.new_scripts.length=0;for(let e=0;e<Wi.length;e++)try{const t=Wi[e];if(t.isComponent!==!0){(wt()||VC)&&console.error(`Registered script is not a Needle Engine component.
|
|
3949
3949
|
The script will be ignored. Please make sure your component extends "Behaviour" imported from "@needle-tools/engine"
|
|
3950
3950
|
`,t),Wi.splice(e,1),e--;continue}if(t.destroyed)continue;if(!t.gameObject){console.error("MISSING GAMEOBJECT - will ignore",t),Wi.splice(e,1),e--;continue}t.context=i,yg(t.gameObject),HC(t,i)}catch(t){console.error(t),Xl(Wi[e],i),Wi.splice(e,1),e--}for(let e=0;e<Wi.length;e++)try{const t=Wi[e];if(t.destroyed){Xl(Wi[e],i),Wi.splice(e,1),e--;continue}if(t.registering)try{t.registering()}catch(s){console.error(s)}t.__internalAwake!==void 0&&(t.gameObject||console.error("MISSING GAMEOBJECT",t,t.gameObject),yg(t.gameObject),t.activeAndEnabled&&ku(t.__internalAwake.bind(t)))}catch(t){console.error(t),Xl(Wi[e],i),Wi.splice(e,1),e--}for(let e=0;e<Wi.length;e++)try{const t=Wi[e];if(t.destroyed||t.enabled===!1||(yg(t.gameObject),t.activeAndEnabled===!1))continue;t.__internalEnable!==void 0&&(t.enabled=!0,ku(t.__internalEnable.bind(t)))}catch(t){console.error(t),Xl(Wi[e],i),Wi.splice(e,1),e--}for(let e=0;e<Wi.length;e++)try{const t=Wi[e];if(t.destroyed||!t.gameObject)continue;i.new_script_start.push(t)}catch(t){console.error(t),Xl(Wi[e],i),Wi.splice(e,1),e--}Wi.length=0;for(const e of i.new_scripts_post_setup_callbacks)e&&e();i.new_scripts_post_setup_callbacks.length=0}}function fX(i){i&&(i.__internalDisable(!0),Xl(i,i.context))}function gO(i,e){for(let t=0;t<i.new_script_start.length;t++)try{const s=i.new_script_start[t];if(e!==void 0&&s.gameObject!==e||s.destroyed||s.activeAndEnabled===!1)continue;ku(s.__internalAwake.bind(s)),s.enabled&&(ku(s.__internalEnable.bind(s)),ku(s.__internalStart.bind(s)),i.new_script_start.splice(t,1),t--)}catch(s){console.error(s),Xl(i.new_script_start[t],i),i.new_script_start.splice(t,1),t--}}function HC(i,e){e.scripts.indexOf(i)===-1&&(e.scripts.push(i),i.earlyUpdate&&e.scripts_earlyUpdate.push(i),i.update&&e.scripts_update.push(i),i.lateUpdate&&e.scripts_lateUpdate.push(i),i.onBeforeRender&&e.scripts_onBeforeRender.push(i),i.onAfterRender&&e.scripts_onAfterRender.push(i),i.onPausedChanged&&e.scripts_pausedChanged.push(i),WC(i,null)&&e.new_scripts_xr.push(i),WC(i,"immersive-vr")&&e.scripts_immersive_vr.push(i),WC(i,"immersive-ar")&&e.scripts_immersive_ar.push(i))}function Xl(i,e){To(i,e.new_scripts),To(i,e.new_script_start),To(i,e.scripts),To(i,e.scripts_earlyUpdate),To(i,e.scripts_update),To(i,e.scripts_lateUpdate),To(i,e.scripts_onBeforeRender),To(i,e.scripts_onAfterRender),To(i,e.scripts_pausedChanged),To(i,e.new_scripts_xr),To(i,e.scripts_immersive_vr),To(i,e.scripts_immersive_ar),e.stopAllCoroutinesFrom(i)}function To(i,e){const t=e.indexOf(i);t>=0&&e.splice(t,1)}function WC(i,e){var t;if(i){const s=i;if(s.onBeforeXR||s.onEnterXR||s.onUpdateXR||s.onLeaveXR||s.onXRControllerAdded||s.onXRControllerRemoved)return!(e!=null&&((t=s.supportsXR)==null?void 0:t.call(s,e))===!1)}return!1}function nb(i){if(i||(i=Ti.Current.scene),!i){console.trace("Invalid call - no current context.");return}const e=Kp(i);vO(i,e,!0)||(VC||wt()?console.error(`Error updating hierarchy
|
|
@@ -4988,10 +4988,12 @@ Pinch: ${(e=this.getGesture("pinch"))==null?void 0:e.value.toFixed(3)}`),r+=`
|
|
|
4988
4988
|
`+s.uuid,.01,5,0,new Si(1,1,1,.1))}this.emitPointerEvent(u,0,"pinch",!1,null,d)}}}}}onUpdateMove(){var e,t;let s=!1;if(this._lastPointerMovePosition.distanceTo(this.gripWorldPosition)>.02&&(s=!0),s||this._lastPointerMoveQuaternion.angleTo(this.gripWorldQuaternion)>.02&&(s=!0),s){this._didMoveLastFrame=!0,this._lastPointerMovePosition.copy(this.gripWorldPosition),this._lastPointerMoveQuaternion.copy(this.gripWorldQuaternion),gh&&Pt.DrawLabel(this.rayWorldPosition.add(this.object.worldForward.multiplyScalar(.1)),"move",.01);let r=this.xr.context.input.getFirstPressedButtonForPointer(this.index);r===void 0&&(r=0);const n=(t=(e=this.gamepad)==null?void 0:e.buttons[r])==null?void 0:t.value;this.emitPointerEvent("pointermove",r,"none",!1,null,n)}else this._didMoveLastFrame=!1}emitPointerEvent(e,t,s,r,n=null,o){if(!this.emitEvents){gh&&e!==Xi.PointerMove&&console.warn("Pointer events are disabled for this controller",this.index,e,t);return}if(this.xr.mode==="immersive-vr"||this.xr.isPassThrough){this.pointerInit.origin=this,this.pointerInit.pointerId=this.index*10+t,this.pointerInit.pointerType=this.hand?"hand":"controller",this.pointerInit.button=t,this.pointerInit.buttonName=s,this.pointerInit.isPrimary=r,this.pointerInit.mode=this.inputSource.targetRayMode,this.pointerInit.ray=this.ray,this.pointerInit.device=this.object,this.pointerInit.pressure=o;const a=kt.Current;kt.Current=this.xr.context,gh&&e!=="pointermove"&&console.warn("Pointer event",e,t,s,{...this.pointerInit}),this.xr.context.input.createInputEvent(new Zl(e,n,this.pointerInit)),kt.Current=a}}}class ON{constructor(){h(this,"isDown",!1),h(this,"isUp",!1),h(this,"pressed",!1),h(this,"value",0)}}class LN{constructor(){h(this,"touched",!1),h(this,"pressed",!1),h(this,"value",0),h(this,"isDown",!1),h(this,"isUp",!1)}}const $g=te("debugwebxr");class eT{constructor(e,t){h(this,"controllerStates",[]),h(this,"userId"),h(this,"context"),h(this,"userStateEvtName"),h(this,"onReceivedControllerState",s=>{$g&&console.log(`XRSync: Received change for ${this.userId}: ${s.type} ${s.handedness}; tracked=${s.isTracking}`);let r=!1;for(let n=0;n<this.controllerStates.length;n++)if(this.controllerStates[n].index===s.index){this.controllerStates[n]=s,r=!0;break}r||this.controllerStates.push(s)}),this.userId=e,this.context=t,this.userStateEvtName="xr-sync-user-state-"+e,this.context.connection.beginListen(this.userStateEvtName,this.onReceivedControllerState)}dispose(){this.context.connection.stopListen(this.userStateEvtName,this.onReceivedControllerState)}update(e){if(this.context.connection.isConnected!=!1){for(let t=this.controllerStates.length-1;t>=0;t--){const s=this.controllerStates[t];let r=!1;for(let n=0;n<e.controllers.length;n++)e.controllers[n].index===s.index&&(r=!0);r||($g&&console.log(`XRSync: ${s.type} ${s.handedness} removed`,s.index),this.controllerStates.splice(t,1),this.sendControllerRemoved(s))}for(const t of e.controllers)this.updateControllerStates(t)}}onExitXR(e){for(const t of this.controllerStates)this.sendControllerRemoved(t);this.controllerStates.length=0}sendControllerRemoved(e){e.isTracking=!1,e.guid="",this.context.connection.send(this.userStateEvtName,e),this.context.connection.sendDeleteRemoteState(e.guid)}updateControllerStates(e){const t=this.controllerStates.find(s=>s.index===e.index);if(t){let s=!1;s||(s=t.isTracking!=e.isTracking),s&&(t.isTracking=e.isTracking,this.context.connection.send(this.userStateEvtName,t))}else{const s={guid:this.userId+"-"+e.index,isTracking:e.isTracking,handedness:e.side,index:e.index,type:e.hand?"hand":"controller"};this.controllerStates.push(s),this.context.connection.send(this.userStateEvtName,s),$g&&console.log(`XRSync: ${s.type} ${s.handedness} added`,s.index)}}}class UN{constructor(e){h(this,"context"),h(this,"onJoinedRoom",()=>{if(this.context.connection.connectionId){this._states.has(this.context.connection.connectionId)||($g&&console.log("XRSync: Local user joined room",this.context.connection.connectionId),this._states.set(this.context.connection.connectionId,new eT(this.context.connection.connectionId,this.context)));for(const t of this.context.connection.usersInRoom())this._states.has(t)||this._states.set(t,new eT(t,this.context))}}),h(this,"onLeftRoom",()=>{if(this.context.connection.connectionId&&!this._states.has(this.context.connection.connectionId)){const t=this._states.get(this.context.connection.connectionId);t?.dispose(),this._states.delete(this.context.connection.connectionId)}}),h(this,"onOtherUserJoinedRoom",t=>{const s=t.userId;this._states.has(s)||($g&&console.log("XRSync: Remote user joined room",s),this._states.set(s,new eT(s,this.context)))}),h(this,"onOtherUserLeftRoom",t=>{const s=t.userId;if(!this._states.has(s)){const r=this._states.get(s);r?.dispose(),this._states.delete(s)}}),h(this,"_states",new Map),this.context=e,this.context.connection.beginListen(di.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(di.LeftRoom,this.onLeftRoom),this.context.connection.beginListen(di.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.beginListen(di.UserLeftRoom,this.onOtherUserLeftRoom)}hasState(e){return e?this._states.has(e):!1}isTracking(e,t){if(!e)return;const s=this._states.get(e);if(!s)return;const r=s.controllerStates.find(n=>n.handedness===t);return r?.isTracking||!1}getDeviceType(e,t){if(!e)return;const s=this._states.get(e);if(!s)return;const r=s.controllerStates.find(n=>n.handedness===t);return r?.type||"unknown"}destroy(){this.context.connection.stopListen(di.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(di.LeftRoom,this.onLeftRoom),this.context.connection.stopListen(di.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.stopListen(di.UserLeftRoom,this.onOtherUserLeftRoom)}onUpdate(e){if(this.context.connection.isConnected&&this.context.connection.connectionId){const t=this._states.get(this.context.connection.connectionId);t?.update(e)}}onExitXR(e){if(this.context.connection.isConnected&&this.context.connection.connectionId){const t=this._states.get(this.context.connection.connectionId);t?.onExitXR(e)}}}class FN{constructor(){h(this,"_fadeToColorQuad"),h(this,"_fadeToColorMaterial"),h(this,"_requestedFadeValue",0),h(this,"_transitionPromise",null),h(this,"_transitionResolve",null),this._fadeToColorMaterial=new ri({color:0,transparent:!0,depthTest:!1,fog:!1,side:fi}),this._fadeToColorQuad=new ve(new Ys(10,10),this._fadeToColorMaterial)}dispose(){this._fadeToColorQuad.geometry.dispose(),this._fadeToColorMaterial.dispose()}update(e,t){const s=this._fadeToColorQuad,r=this._fadeToColorMaterial;s.parent!==e&&r.opacity>0?e.add(s):r.opacity===0&&s.removeFromParent(),s.layers.set(2),s.material=this._fadeToColorMaterial,s.position.z=-1,s.renderOrder=1/0;const n=this._requestedFadeValue;r.opacity=st.lerp(r.opacity,n,t/.03),Math.abs(r.opacity-n)<=.01&&this._transitionResolve&&(this._transitionResolve(),this._transitionResolve=null,this._transitionPromise=null,this._requestedFadeValue=0)}remove(){this._fadeToColorQuad.removeFromParent()}fadeTransition(){if(this._transitionPromise)return this._transitionPromise;this._requestedFadeValue=1;const e=new Promise(t=>{this._transitionResolve=t});return this._transitionPromise=e,e}}var Hu=(i=>(i[i.Quad=0]="Quad",i[i.Cube=1]="Cube",i[i.Sphere=2]="Sphere",i))(Hu||{});class Yp{static createPrimitive(e,t){let s;switch(e){case 0:const r=new Ys(1,1,1,1),n=t?.material??new On({color:16777215});s=new ve(r,n);break;case 1:const o=new Fi(1,1,1),a=t?.material??new On({color:16777215});s=new ve(o,a);break;case 2:const l=new Ta(.5,16,16),c=t?.material??new On({color:16777215});s=new ve(l,c);break}return t!=null&&t.name&&(s.name=t.name),t!=null&&t.position&&s.position.set(t.position.x,t.position.y,t.position.z),t!=null&&t.rotation&&s.rotation.set(t.rotation.x,t.rotation.y,t.rotation.z),t!=null&&t.scale&&s.scale.set(t.scale.x,t.scale.y,t.scale.z),s}}const NN=class{constructor(i,e,t){h(this,"_session"),h(this,"_mode"),h(this,"_init"),h(this,"_renderer"),h(this,"_camera"),h(this,"_scene"),h(this,"onEnd",()=>{var s;(s=this._session)==null||s.removeEventListener("end",this.onEnd),this._renderer.setAnimationLoop(null),this._renderer.dispose(),this._scene.clear()}),h(this,"_lastTime",0),h(this,"onFrame",(s,r)=>{const n=s-this._lastTime;this.update(s,n),this._camera.parent!==this._scene&&this._scene.add(this._camera),this._renderer.render(this._scene,this._camera)}),h(this,"_spheres",[]),this._mode=i,this._init=e,this._session=t,this._session.addEventListener("end",this.onEnd),this._renderer=new Fl({alpha:!0}),this._renderer.setAnimationLoop(this.onFrame),this._renderer.xr.setSession(t),this._renderer.xr.enabled=!0,this._camera=new Ht,this._scene=new Vr,this._scene.add(this._camera),this.setupScene()}static get active(){return this._active}static async start(i,e){if(this._active)return console.error("Cannot start a new XR session while one is already active"),null;if(this._requestInFlight)return console.error("Cannot start a new XR session while a request is already in flight"),null;if("xr"in navigator&&navigator.xr){if(!e)return console.error("XRSessionInit must be provided"),null;this._requestInFlight=!0;const t=await navigator.xr.requestSession(i,e);return t.addEventListener("end",()=>{this._active=null}),this._requestInFlight?(this._requestInFlight=!1,this._active=new NN(i,e,t),this._active):(t.end(),null)}return null}static async handoff(){return this._active?this._active.handoff():null}static async stop(){this._requestInFlight=!1,this._active&&(await this._active.end(),await Co(100)),this._active=null}end(){return this._session?this._session.end():Promise.resolve()}async handoff(){if(!this._session)throw new Error("Cannot handoff a session that has already ended");const i={session:this._session,mode:this._mode,init:this._init};return await this.onBeforeHandoff(),this.onEnd(),this._session=null,i}async onBeforeHandoff(){const i=Yp.createPrimitive(Hu.Cube);i.position.z=-3,i.position.y=.5,this._scene.add(i),await Co(4e3),this._scene.clear(),await Co(100)}setupScene(){this._scene.background=new xe(0),this._scene.add(new N0(5,10,1118481,2236962));const i=new Mp(16777215,1);i.position.set(2,2,2),i.castShadow=!1,this._scene.add(i);const e=new Mp(16777215,1);e.position.set(-2,-2,-2),e.castShadow=!1,this._scene.add(e);const t=50;for(let s=0;s<100;s++){const r=Yp.createPrimitive(Hu.Sphere,{material:new On({color:2236962,metalness:1,roughness:.8})});r.position.x=st.random(-t,t),r.position.y=st.random(3,40),r.position.z=st.random(-t,t),r.scale.multiplyScalar(2),this._spheres.push(r),this._scene.add(r)}}update(i,e){const t=i*4e-4;for(let s=0;s<this._spheres.length;s++){const r=this._spheres[s];r.position.y+=Math.sin(t+s*.5)*.002}}};let ev=NN;h(ev,"_active",null),h(ev,"_requestInFlight",!1);const Zr=te("debugwebxr"),Fee=te("stats");function Nee(i){let e=null;const t=i;return t.getAROverlayContainer?e=t.getAROverlayContainer():e=i,e}zee();function zee(){var i;if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent)){console.warn("WebXRViewer does not support addEventListener");return}(i=navigator.xr)==null||i.addEventListener("sessiongranted",()=>{console.log("Received Session Granted...");const e=sessionStorage.getItem("needle_xr_session_mode"),t=sessionStorage.getItem("needle_xr_session_init");if(e&&t){console.log("Session Granted: Restore last session");const s=JSON.parse(t);vt.start(e,s).catch(r=>console.warn(r))}else vt.start("immersive-vr").catch(s=>console.warn("Session Granted failed:",s))})}}function jee(i,e){sessionStorage.setItem("needle_xr_session_mode",i),sessionStorage.setItem("needle_xr_session_init",JSON.stringify(e))}function Gee(){sessionStorage.removeItem("needle_xr_session_mode"),sessionStorage.removeItem("needle_xr_session_init")}if(ag()&&wt()&&window.addEventListener("keydown",i=>{i.key==="x"&&vt.active&&vt.stop()}),te("simulatewebxrloading")){Ti.registerCallback(Hs.ContextCreationStart,async e=>{await Co(3e3),setTimeout(async()=>{const t=await ev.handoff();t?vt.setSession(t.mode,t.session,t.init,kt.Current):vt.start("immersive-vr")},6e3)});let i=!1;window.addEventListener("click",()=>{i||(i=!0,ev.start("immersive-vr",vt.getDefaultSessionInit("immersive-vr")))})}const Wu=class{constructor(i,e,t,s){h(this,"context"),h(this,"session"),h(this,"mode"),h(this,"controllers",[]),h(this,"_rigScale",1),h(this,"_lastRigScaleUpdate",-1),h(this,"_rigs",[]),h(this,"_viewerHitTestSource",null),h(this,"_defaultRig"),h(this,"_xr_scripts"),h(this,"_xr_update_scripts",[]),h(this,"_inactive_scripts",[]),h(this,"_controllerAdded"),h(this,"_controllerRemoved"),h(this,"_originalCameraWorldPosition"),h(this,"_originalCameraWorldRotation"),h(this,"_originalCameraWorldScale"),h(this,"_originalCameraParent"),h(this,"_mainCamera",null),h(this,"onRendererSessionSet",()=>{this.running&&(this.context.renderer.xr.enabled=!0,this.context.renderer.xr.updateCamera(this.context.mainCamera))}),h(this,"onInputSourceAdded",a=>{if(a.targetRayMode==="screen")return;let l=0;for(let u=0;u<this.session.inputSources.length;u++)if(this.session.inputSources[u]===a){l=u;break}if(this.controllers.find(u=>u.inputSource===a))return;const c=new $M(this,a,l);this.controllers.push(c),this.controllers.sort((u,d)=>u.index-d.index),this._newControllers.push(c),this.invokeControllerEvent(c,this._controllerAdded,"added")}),h(this,"_ended",!1),h(this,"_newControllers",[]),h(this,"onEnd",a=>{var l,c,u,d;if(this._ended)return;this._ended=!0,Zr&&console.log("XR Session ended"),Gee(),this.onAfterRender(),this.revertCustomForward(),this._didStart=!1,this._previousCameraParent=null,K7(this.onBefore,ks.LateUpdate);const p=this.context.pre_render_callbacks.indexOf(this.onBeforeRender);p>=0&&this.context.pre_render_callbacks.splice(p,1);const f=this.context.post_render_callbacks.indexOf(this.onAfterRender);f>=0&&this.context.post_render_callbacks.splice(f,1),this.context.xr=null,this.context.renderer.xr.enabled=!1,(l=this.context.mainCameraComponent)==null||l.applyClearFlags();for(const m of Wu._xrEndListeners)m({xr:this});for(let m=0;m<this.controllers.length;m++)this.disconnectInputSource(this.controllers[m].inputSource);for(const m of this._xr_scripts)(c=m?.onLeaveXR)==null||c.call(m,{xr:this});(u=this.sync)==null||u.onExitXR(this),this.context.mainCamera&&((d=this._originalCameraParent)==null||d.add(this.context.mainCamera),this._originalCameraWorldPosition&&Kr(this.context.mainCamera,this._originalCameraWorldPosition),this._originalCameraWorldRotation&&ko(this.context.mainCamera,this._originalCameraWorldRotation),this._originalCameraWorldScale&&Yg(this.context.mainCamera,this._originalCameraWorldScale)),this.context.requestSizeUpdate(),this._defaultRig.gameObject.removeFromParent()}),h(this,"_didStart",!1),h(this,"onBefore",a=>{var l,c,u,d,p,f,m,A;const y=a.xrFrame;if(!y)return;this.context.xr=this,this.context.mainCameraComponent&&this.context.mainCameraComponent!==this._mainCamera&&(this._mainCamera=this.context.mainCameraComponent),((l=this.rig)==null?void 0:l.isActive)==!1&&(Zr&&console.warn("Latest rig is not active - trying to activate a different rig",this.rig),this.updateActiveXRRig()),this.rig&&(c=this._mainCamera)!=null&&c.gameObject&&((d=(u=this._mainCamera)==null?void 0:u.gameObject)==null?void 0:d.parent)!==this.rig.gameObject&&this.rig.gameObject.add((p=this._mainCamera)==null?void 0:p.gameObject),this.internalUpdateState(),this.applyCustomForward();const g={xr:this};if(this._didStart){if(this.context.new_scripts_xr.length>0){const v=[...this.context.new_scripts_xr];for(let b=0;b<v.length;b++){const _=this.context.new_scripts_xr[b];if(!_||_.destroyed||((f=_.supportsXR)==null?void 0:f.call(_,this.mode))==!1){this.context.new_scripts_xr.splice(b,1);continue}if(!_.activeAndEnabled){this.context.new_scripts_xr.splice(b,1),this.markInactive(_);continue}if(this.addScript(_)){this.invokeCallback_EnterXR(_);for(const S of this.controllers)this.invokeCallback_ControllerAdded(_,S)}}}}else{this._didStart=!0;for(const b of Wu._xrStartListeners)b(g);const v=[...this._xr_scripts];Zr&&console.log("NeedleXRSession start, handle scripts:",v);for(const b of v){if(b.destroyed){this._script_to_remove.push(b);continue}if(!b.activeAndEnabled){this.markInactive(b);continue}this.invokeCallback_EnterXR(b);for(const _ of this.controllers)this.invokeCallback_ControllerAdded(b,_)}}this.syncCameraCullingMask();for(const v of this.controllers)v.onUpdate(y);for(const v of this._newControllers)for(const b of this._xr_scripts){if(b.destroyed){this._script_to_remove.push(b);continue}b.onXRControllerAdded&&b.onXRControllerAdded({xr:this,controller:v,change:"added"})}this._newControllers.length=0;for(const v of this._xr_update_scripts){if(v.destroyed===!0){this._script_to_remove.push(v);continue}if(v.activeAndEnabled===!1){this.markInactive(v);continue}v.onUpdateXR&&v.onUpdateXR(g)}if(this.handleInactiveScripts(),this._script_to_remove.length>0){const v=[...new Set(this._script_to_remove)];this._script_to_remove.length=0;for(const b of v)!b.destroyed&&this.running&&((m=b.onLeaveXR)==null||m.call(b,g)),this.removeScript(b)}(A=this.sync)==null||A.onUpdate(this),this.onRenderDebug()}),h(this,"onBeforeRender",()=>{this.context.mainCamera&&this.updateFade(this.context.mainCamera)}),h(this,"onAfterRender",()=>{if(this.onUpdateFade_PostRender(),ag()){const a=this.context.renderer;if(a.xr.isPresenting&&this.context.mainCamera){const l=a.xr.enabled,c=a.getRenderTarget();a.xr.enabled=!1,a.setRenderTarget(null),a.render(this.context.scene,this.context.mainCamera),a.xr.enabled=l,a.setRenderTarget(c)}}}),h(this,"_script_to_remove",[]),h(this,"_camera"),h(this,"_cameraRenderParent",new ye().rotateY(Math.PI)),h(this,"_previousCameraParent"),h(this,"_customforward",!0),h(this,"originalCameraNearPlane"),h(this,"_viewerPose"),h(this,"_transformOrientation",new Ie),h(this,"_transformPosition",new w),h(this,"_transition");var r,n,o;jee(i,s.init),this.session=e,this.mode=i,this.context=t,this.context.xr=this,this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet),this._xr_scripts=[...s.scripts],this._xr_update_scripts=this._xr_scripts.filter(a=>typeof a.onUpdateXR=="function"),this._controllerAdded=s.controller_added,this._controllerRemoved=s.controller_removed,Eg(this.onBefore,ks.LateUpdate),this.context.pre_render_callbacks.push(this.onBeforeRender),this.context.post_render_callbacks.push(this.onAfterRender),((r=s.init.optionalFeatures)!=null&&r.includes("hit-test")||(n=s.init.requiredFeatures)!=null&&n.includes("hit-test"))&&e.requestReferenceSpace("viewer").then(a=>{var l,c;return(c=(l=e.requestHitTestSource)==null?void 0:l.call(e,{space:a}))==null?void 0:c.then(u=>this._viewerHitTestSource=u)}).catch(a=>console.warn(a)),this.context.mainCamera&&(this._originalCameraWorldPosition=Rt(this.context.mainCamera,new w),this._originalCameraWorldRotation=Ii(this.context.mainCamera,new Ie),this._originalCameraWorldScale=ss(this.context.mainCamera,new w),this._originalCameraParent=this.context.mainCamera.parent),(o=this.context.mainCameraComponent)==null||o.applyClearFlags(),this._defaultRig=new Oee,this.context.scene.add(this._defaultRig.gameObject),this.addRig(this._defaultRig);for(const a of this.session.inputSources)this.onInputSourceAdded(a);this.session.addEventListener("end",this.onEnd),this.session.addEventListener("inputsourceschange",a=>{for(const l of a.removed)this.disconnectInputSource(l);for(const l of a.added)this.onInputSourceAdded(l)})}static getXRSync(i){return this._sync||(this._sync=new UN(i)),this._sync}static get currentSessionRequest(){return this._currentSessionRequestMode}static get active(){return this._activeSession}static get activeMode(){var i;return((i=this._activeSession)==null?void 0:i.mode)??null}static get xrSystem(){return"xr"in navigator?navigator.xr:void 0}static isXRSupported(){return Promise.all([this.isVRSupported(),this.isARSupported()]).then(i=>i.some(e=>e)).catch(()=>!1)}static isVRSupported(){var i;return((i=this.xrSystem)==null?void 0:i.isSessionSupported("immersive-vr").catch(e=>(Zr&&console.error(e),!1)))??Promise.resolve(!1)}static isARSupported(){var i;return((i=this.xrSystem)==null?void 0:i.isSessionSupported("immersive-ar").catch(e=>(Zr&&console.error(e),!1)))??Promise.resolve(!1)}static onSessionRequestStart(i){this._sessionRequestStartListeners.push(i)}static offSessionRequestStart(i){const e=this._sessionRequestStartListeners.indexOf(i);e>=0&&this._sessionRequestStartListeners.splice(e,1)}static onSessionRequestEnd(i){this._sessionRequestEndListeners.push(i)}static offSessionRequestEnd(i){const e=this._sessionRequestEndListeners.indexOf(i);e>=0&&this._sessionRequestEndListeners.splice(e,1)}static onXRSessionStart(i){this._xrStartListeners.push(i)}static offXRSessionStart(i){const e=this._xrStartListeners.indexOf(i);e>=0&&this._xrStartListeners.splice(e,1)}static onXRSessionEnd(i){this._xrEndListeners.push(i)}static offXRSessionEnd(i){const e=this._xrEndListeners.indexOf(i);e>=0&&this._xrEndListeners.splice(e,1)}static onControllerAdded(i){this._controllerAddedListeners.push(i)}static offControllerAdded(i){const e=this._controllerAddedListeners.indexOf(i);e>=0&&this._controllerAddedListeners.splice(e,1)}static onControllerRemoved(i){this._controllerRemovedListeners.push(i)}static offControllerRemoved(i){const e=this._controllerRemovedListeners.indexOf(i);e>=0&&this._controllerRemovedListeners.splice(e,1)}static offerSession(i,e,t){return"xr"in navigator&&navigator.xr&&"offerSession"in navigator.xr?(typeof navigator.xr.offerSession=="function"&&(console.log("WebXR offerSession is available - requesting mode: "+i),e=="default"&&(e=this.getDefaultSessionInit(i)),navigator.xr.offerSession(i,{...e}).then(s=>Wu.setSession(i,s,e,t)).catch(s=>{console.log("XRSession offer rejected (perhaps because another call to offerSession was made or a call to requestSession was made)")})),!0):!1}static getDefaultSessionInit(i){switch(i){case"immersive-ar":return{optionalFeatures:["anchors","local-floor","hand-tracking","layers","dom-overlay","hit-test"]};case"immersive-vr":return{optionalFeatures:["local-floor","bounded-floor","hand-tracking","high-fixed-foveation-level","layers"]};default:return console.warn("No default session init for mode",i),{}}}static async start(i,e,t){var s,r,n,o;if(this._currentSessionRequest)return console.warn("A XRSession is already being requested"),(Zr||wt())&&is("A XRSession is already being requested"),this._currentSessionRequest.then(()=>this._activeSession);if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;if(t||(t=kt.Current),t||(t=Ti.All[0]),!t)throw new Error("No Needle Engine Context found");switch(e||(e={}),i){case"immersive-ar":{if(await((s=this.xrSystem)==null?void 0:s.isSessionSupported("immersive-ar"))!==!0)return console.error(i+" is not supported by this browser."),null;const c=this.getDefaultSessionInit(i),u=Nee(t.domElement);u&&!W0()&&(c.domOverlay={root:u},c.optionalFeatures.push("dom-overlay")),e={...c,...e}}break;case"immersive-vr":{if(await((r=this.xrSystem)==null?void 0:r.isSessionSupported("immersive-vr"))!==!0)return console.error(i+" is not supported by this browser."),null;e={...this.getDefaultSessionInit(i),...e}}break;default:console.warn("No default session init for mode",i);break}await ev.stop();const a=i=="immersive-ar"?t.scripts_immersive_ar:t.scripts_immersive_vr;Zr?console.log(`%cRequesting ${i} session`,"font-weight:bold;",e,a):console.log(`%cRequesting ${i} session`,"font-weight:bold;");for(const c of a)c.onBeforeXR&&c.onBeforeXR(i,e);for(const c of this._sessionRequestStartListeners)c({mode:i,init:e});Zr&&ms("Requesting "+i+" session ("+Date.now()+")"),this._currentSessionRequest=(n=navigator.xr)==null?void 0:n.requestSession(i,e),this._currentSessionRequestMode=i;const l=await((o=this._currentSessionRequest)==null?void 0:o.catch(c=>{console.error(c,"Code: "+c.code),c.code===9&&is("Make sure your device has the required permissions (e.g. camera access)"),console.log("If the specified XR configuration is not supported (e.g. entering AR doesnt work) - make sure you access the website on a secure connection (HTTPS) and your device has the required permissions (e.g. camera access)"),location.protocol==="http:"&&is("XR requires a secure connection (HTTPS)")}));this._currentSessionRequest=void 0,this._currentSessionRequestMode=null;for(const c of this._sessionRequestEndListeners)c({mode:i,init:e,newSession:l||null});return l?this.setSession(i,l,e,t):(console.warn("XR Session request was rejected"),null)}static setSession(i,e,t,s){if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;const r=i=="immersive-ar"?s.scripts_immersive_ar:s.scripts_immersive_vr;return this._activeSession=new Wu(i,e,s,{scripts:r,controller_added:this._controllerAddedListeners,controller_removed:this._controllerRemovedListeners,init:t}),e.addEventListener("end",this.onEnd),Zr?console.log(`%cStarted ${i} session`,"font-weight:bold;",r):console.log(`%cStarted ${i} session`,"font-weight:bold;"),this._activeSession}static stop(){var i;(i=this._activeSession)==null||i.end()}get sync(){return Wu._sync}get running(){return!this._ended&&this.session!=null}get interactionMode(){return this.session.interactionMode}get visibilityState(){return this.session.visibilityState}get environmentBlendMode(){return this.session.environmentBlendMode}get frame(){return this.context.xrFrame}get leftController(){return this.controllers.find(i=>i.isLeft)}get rightController(){return this.controllers.find(i=>i.isRight)}getController(i){return this.controllers.find(e=>e.side===i)||null}get isPassThrough(){return!!(this.environmentBlendMode!=="opaque"&&this.interactionMode==="world-space"||this.mode==="immersive-ar"&&this.environmentBlendMode!=="opaque"&&this.controllers.some(i=>i.inputSource.targetRayMode==="tracked-pointer")||wt()&&ag()&&this.mode==="immersive-ar")}get isAR(){return this.mode==="immersive-ar"}get isVR(){return this.mode==="immersive-vr"}get posePosition(){return this._transformPosition}get poseOrientation(){return this._transformOrientation}get referenceSpace(){return this.context.renderer.xr.getReferenceSpace()}get viewerPose(){return this._viewerPose}get isTrackingImages(){if(this.frame&&"getImageTrackingResults"in this.frame&&typeof this.frame.getImageTrackingResults=="function")try{const i=this.frame.getImageTrackingResults();for(const e of i)if(e.trackingState==="tracked")return!0}catch{return!1}return!1}get rig(){const i=this._rigs[0]??null;return i!=null&&i.gameObject&&Xu(i.gameObject)||i?.isActive===!1?(this.updateActiveXRRig(),this._rigs[0]??null):i}get rigScale(){return this._rigs[0]?(this._lastRigScaleUpdate!==this.context.time.frame&&(this._lastRigScaleUpdate=this.context.time.frame,this._rigScale=this._rigs[0].gameObject.worldScale.x),this._rigScale):1}addRig(i){this._rigs.indexOf(i)>=0||(i.priority===void 0&&(i.priority=0),this._rigs.push(i),this.updateActiveXRRig())}removeRig(i){const e=this._rigs.indexOf(i);e!==-1&&(this._rigs.splice(e,1),this.updateActiveXRRig())}setRigActive(i){const e=this._rigs.indexOf(i);this._rigs.splice(e,1),this._rigs.unshift(i),this.updateActiveXRRig()}updateActiveXRRig(){const i=this._rigs[0]??null;this._defaultRig.gameObject.parent!==this.context.scene&&this.context.scene.add(this._defaultRig.gameObject),this._defaultRig.gameObject.visible=!0,this._rigs.includes(this._defaultRig)||this._rigs.push(this._defaultRig);let e=this._rigs[0];e&&e.priority===void 0&&(e.priority=0);for(let t=1;t<this._rigs.length;t++){const s=this._rigs[t];if(s.isActive){if(Xu(s.gameObject)){this._rigs.splice(t,1),t--;continue}(!e||e.isActive===!1||s.priority!==void 0&&s.priority>e.priority)&&(e=s)}}if(i!==e){const t=this._rigs.indexOf(e);t>=0&&this._rigs.splice(t,1),this._rigs.unshift(e)}Zr&&(i===e?console.log("Updated Active XR Rig:",e,"prev:",i):console.log("Updated Active XRRig:",e," (the same as before)"))}getHitTest(i){if(i)return this.getControllerHitTest(i);if(!this._viewerHitTestSource)return null;const e=this._viewerHitTestSource,t=this.frame.getHitTestResults(e);if(t.length>0){const s=t[0];return this.convertHitTestResult(s)}return null}getControllerHitTest(i){const e=i.hitTestSource;if(!e)return null;const t=this.frame.getHitTestResultsForTransientInput(e);for(const s of t)if(s.inputSource===i.inputSource)for(const r of s.results)return this.convertHitTestResult(r);return null}convertHitTestResult(i){const e=this.context.renderer.xr.getReferenceSpace(),t=e&&i.getPose(e);if(t){const s=Bs(t.transform.position),r=Gu(t.transform.orientation),n=this.context.mainCamera;if(n?.parent!==this._cameraRenderParent&&s.applyMatrix4(r_),n!=null&&n.parent){s.applyMatrix4(n.parent.matrixWorld),r.multiply(va);const o=Ii(n.parent);o.premultiply(va),r.premultiply(o)}return{hit:i,position:s,quaternion:r}}return null}convertSpace(i){const e=Bs(i.position);e.applyMatrix4(r_);const t=Gu(i.orientation);return t.premultiply(va),{position:e,quaternion:t}}end(){this._ended||this.session.end().catch(i=>console.warn(i))}disconnectInputSource(i){for(let e=this.controllers.length-1;e>=0;e--){const t=this.controllers[e];if(t.inputSource===i){this.controllers.splice(e,1),this.invokeControllerEvent(t,this._controllerRemoved,"removed");const s={xr:this,controller:t,change:"removed"};for(const r of this._xr_scripts)r.onXRControllerRemoved&&r.onXRControllerRemoved(s);t.onDisconnected()}}}onRenderDebug(){if(Zr)for(const i of this.controllers)i.onRenderDebug();if((Zr||Fee)&&this.rig){const i=this.rig.gameObject.worldPosition,e=this.rig.gameObject.worldForward;i.add(e.multiplyScalar(1.5));const t=this.rig.gameObject.worldUp;i.add(t.multiplyScalar(2.5));let s="";if(s+=this.context.time.smoothedFps.toFixed(1),Zr)for(const r of this.controllers)s+=`
|
|
4989
4989
|
${r.hand?"hand":"ctrl"} ${r.inputSource.handedness}[${r.index}] con:${r.connected} tr:${r.isTracking}`;Pt.DrawLabel(i,s)}}addScript(i){return this._xr_scripts.includes(i)?!1:(Zr&&console.log("Register new XRScript",i),this._xr_scripts.push(i),typeof i.onUpdateXR=="function"&&this._xr_update_scripts.push(i),!0)}markInactive(i){if(!(this._inactive_scripts.indexOf(i)>=0)){this.removeScript(i,!1),this._inactive_scripts.push(i);for(const e of this.controllers)this.invokeCallback_ControllerRemoved(i,e);this.invokeCallback_LeaveXR(i)}}handleInactiveScripts(){if(this._inactive_scripts.length>0)for(let i=this._inactive_scripts.length-1;i>=0;i--){const e=this._inactive_scripts[i];if(e.activeAndEnabled){this._inactive_scripts.splice(i,1),this.addScript(e),this.invokeCallback_EnterXR(e);for(const t of this.controllers)this.invokeCallback_ControllerAdded(e,t)}}}removeScript(i,e=!0){Zr&&console.log("Remove XRScript",i);const t=this._xr_scripts.indexOf(i);t>=0&&this._xr_scripts.splice(t,1);const s=this._xr_update_scripts.indexOf(i);if(s>=0&&this._xr_update_scripts.splice(s,1),e){const r=this._inactive_scripts.indexOf(i);r>=0&&this._inactive_scripts.splice(r,1)}}invokeCallback_EnterXR(i){i.onEnterXR&&i.onEnterXR({xr:this})}invokeCallback_ControllerAdded(i,e){i.onXRControllerAdded&&i.onXRControllerAdded({xr:this,controller:e,change:"added"})}invokeCallback_ControllerRemoved(i,e){i.onXRControllerRemoved&&i.onXRControllerRemoved({xr:this,controller:e,change:"removed"})}invokeCallback_LeaveXR(i){i.onLeaveXR&&!i.destroyed&&i.onLeaveXR({xr:this})}syncCameraCullingMask(){var i;const e=this.context.xrCamera,t=(i=this.context.mainCameraComponent)==null?void 0:i.cullingMask;if(e&&t!==void 0){for(const s of e.cameras)s.layers.mask=t;e.layers.mask=t}else if(e){for(const s of e.cameras)s.layers.enableAll();e.layers.enableAll()}}invokeControllerEvent(i,e,t){for(let s=e.length-1;s>=0;s--){const r=e[s];if(r)try{r({xr:this,controller:i,change:t})}catch(n){console.error(n)}}}applyCustomForward(){var i;if(this.context.mainCamera&&this._customforward){this._camera=this.context.mainCamera,this._camera.parent!==this._cameraRenderParent&&(this._previousCameraParent=this._camera.parent,(i=this._previousCameraParent)==null||i.add(this._cameraRenderParent)),this._cameraRenderParent.name="XR Camera Render Parent",this._cameraRenderParent.add(this._camera);let e=.02;if(this.rig){const t=ss(this.rig.gameObject);e*=t.x}this._camera instanceof Ht&&this._camera.near>e&&(this.originalCameraNearPlane=this._camera.near,this._camera.near=e)}}revertCustomForward(){this._camera&&this._previousCameraParent&&this._previousCameraParent.add(this._camera),this._previousCameraParent=null,this._camera instanceof Ht&&this.originalCameraNearPlane!=null&&(this._camera.near=this.originalCameraNearPlane)}internalUpdateState(){const i=this.context.renderer.xr.getReferenceSpace();if(!i){this._viewerPose=void 0;return}if(this._viewerPose=this.frame.getViewerPose(i),this._viewerPose){const e=this._viewerPose.transform;this._transformPosition.set(e.position.x,e.position.y,e.position.z),this._transformOrientation.set(e.orientation.x,e.orientation.y,e.orientation.z,e.orientation.w)}}get transition(){return this._transition||(this._transition=new FN),this._transition}fadeTransition(){return this._transition||(this._transition=new FN),this._transition.fadeTransition()}updateFade(i){this._transition&&i instanceof Ht&&this._transition.update(i,this.context.time.deltaTime)}onUpdateFade_PostRender(){var i;(i=this._transition)==null||i.remove()}};let vt=Wu;h(vt,"_sync",null),h(vt,"_currentSessionRequestMode",null),h(vt,"_currentSessionRequest"),h(vt,"_activeSession"),h(vt,"_sessionRequestStartListeners",[]),h(vt,"_sessionRequestEndListeners",[]),h(vt,"_xrStartListeners",[]),h(vt,"_xrEndListeners",[]),h(vt,"_controllerAddedListeners",[]),h(vt,"_controllerRemovedListeners",[]),h(vt,"onEnd",()=>{Zr&&console.log("XR Session ended"),Wu._activeSession=null});const tT=te("debugwebxr");class zN{static tryFindAvatarObjects(e,t,s){if(s.head&&s.leftHand&&s.rightHand)return;const r=e.name.toLocaleLowerCase();!s.head&&r.includes("head")&&(tT&&console.log("FOUND AVATAR HEAD",e.name),s.head=new ni("",t,e)),r.includes("hand")&&(!s.leftHand&&r.includes("left")&&(tT&&console.log("FOUND AVATAR LEFT HAND",e.name),s.leftHand=new ni("",t,e)),!s.rightHand&&r.includes("right")&&(tT&&console.log("FOUND AVATAR RIGHT HAND",e.name),s.rightHand=new ni("",t,e)));for(let n=0;n<e.children.length;n++){if(s.head&&s.leftHand&&s.rightHand)return;const o=e.children[n];this.tryFindAvatarObjects(o,t,s)}}}const vn=new w,jN=new w,GN=new Ie,Qee=te("debuggizmos"),lc=8947848,Ya=class{static isGizmo(i){return i[sT]!==void 0}static DrawLabel(i,e,t=.05,s=0,r,n,o){var a;if(!Ya.enabled)return null;r||(r=lc);const l=((a=vt.active)==null?void 0:a.rigScale)??1,c=Ds.getTextLabel(s,e,t*l,r,n);return o instanceof ye&&o.add(c),c.position.x=i.x,c.position.y=i.y,c.position.z=i.z,c}static DrawRay(i,e,t=lc,s=0,r=!0){if(!Ya.enabled)return;const n=Ds.getLine(s),o=n.geometry.getAttribute("position");o.setXYZ(0,i.x,i.y,i.z),vn.set(e.x,e.y,e.z).multiplyScalar(999999999),o.setXYZ(1,i.x+vn.x,i.y+vn.y,i.z+vn.z),o.needsUpdate=!0,n.material.color.set(t),n.material.depthTest=r,n.material.depthWrite=!1}static DrawDirection(i,e,t=lc,s=0,r=!0,n=1){if(!Ya.enabled)return;const o=Ds.getLine(s),a=o.geometry.getAttribute("position");a.setXYZ(0,i.x,i.y,i.z),e.w!==void 0?(vn.set(0,0,-n),GN.set(e.x,e.y,e.z,e.w),vn.applyQuaternion(GN)):(vn.set(e.x,e.y,e.z),vn.multiplyScalar(n)),a.setXYZ(1,i.x+vn.x,i.y+vn.y,i.z+vn.z),a.needsUpdate=!0,o.material.color.set(t),o.material.depthTest=r,o.material.depthWrite=!1}static DrawLine(i,e,t=lc,s=0,r=!0){if(!Ya.enabled)return;const n=Ds.getLine(s),o=n.geometry.getAttribute("position");o.setXYZ(0,i.x,i.y,i.z),o.setXYZ(1,e.x,e.y,e.z),o.needsUpdate=!0,n.material.color.set(t),n.material.depthTest=r,n.material.depthWrite=!1}static DrawWireSphere(i,e,t=lc,s=0,r=!0){if(!Ya.enabled)return;const n=Ds.getSphere(e,s,!0);Qu(n,i.x,i.y,i.z),n.material.color.set(t),n.material.depthTest=r,n.material.depthWrite=!1}static DrawSphere(i,e,t=lc,s=0,r=!0){if(!Ya.enabled)return;const n=Ds.getSphere(e,s,!1);Qu(n,i.x,i.y,i.z),n.material.color.set(t),n.material.depthTest=r,n.material.depthWrite=!1}static DrawWireBox(i,e,t=lc,s=0,r=!0){if(!Ya.enabled)return;const n=Ds.getBox(s);n.position.set(i.x,i.y,i.z),n.scale.set(e.x,e.y,e.z),n.material.color.set(t),n.material.depthTest=r,n.material.wireframe=!0,n.material.depthWrite=!1}static DrawWireBox3(i,e=lc,t=0,s=!0){if(!Ya.enabled)return;const r=Ds.getBox(t);r.position.copy(i.getCenter(vn)),r.scale.copy(i.getSize(vn)),r.material.color.set(e),r.material.depthTest=s,r.material.wireframe=!0,r.material.depthWrite=!1}static DrawArrow(i,e,t=lc,s=0,r=!0,n=!1){if(!Ya.enabled)return;const o=Ds.getArrowHead(s);o.position.set(e.x,e.y,e.z),o.quaternion.setFromUnitVectors(this._up.set(0,1,0),vn.set(e.x,e.y,e.z).sub(jN.set(i.x,i.y,i.z)).normalize());const a=vn.set(e.x,e.y,e.z).sub(jN.set(i.x,i.y,i.z)).length()*.1;o.scale.set(a,a,a),o.material.color.set(t),o.material.depthTest=r,o.material.wireframe=n,this.DrawLine(i,e,t,s,r)}};let Pt=Ya;h(Pt,"enabled",!0),h(Pt,"_up",new w(0,1,0));const Vee=new Fi(1,1,1);function iT(i=null){const e=new xe(i??14540253),t=new W1(Vee);return new Jn(t,new _s({color:e}))}const sT=Symbol("GizmoCache");class Ds{static ensureFont(){let e=qp.FontLibrary.getFontFamily(this.familyName);if(!e){e=qp.FontLibrary.addFontFamily(this.familyName);const t=e.addVariant("normal","normal","./include/needle/arial-msdf.json","./include/needle/arial.png");t?.addEventListener("ready",()=>{qp.update()})}}static getTextLabel(e,t,s,r,n){this.ensureFont();let o=this.textLabelCache.pop(),a=1;n&&typeof n=="string"&&n?.length>=8&&n.startsWith("#")?(a=parseInt(n.substring(7),16)/255,n=n.substring(0,7),Qee&&console.log(n,a)):typeof n=="object"&&n.a!==void 0&&(a=n.a);const l={boxSizing:"border-box",fontFamily:this.familyName,width:"auto",fontSize:s,color:r,lineHeight:1,backgroundColor:n??void 0,backgroundOpacity:a,textContent:t,borderRadius:.5*s,padding:.8*s,whiteSpace:"pre"};if(o)o.set(l);else{o=new QM(l);const c=this,u=o;u.setText=function(d){this.set({textContent:d}),c.tmuiNeedsUpdate=!0}}return this.tmuiNeedsUpdate=!0,this.registerTimedObject(kt.Current,o,e,this.textLabelCache),o}static getBox(e){let t=this.boxesCache.pop();if(!t){const s=new Fi(1,1,1);t=new ve(s)}return this.registerTimedObject(kt.Current,t,e,this.boxesCache),t}static getLine(e){let t=this.linesCache.pop();if(!t){t=new xs;let s=t.geometry.getAttribute("position");s||(s=new Ze(new Float32Array(2*3),3),t.geometry.setAttribute("position",s))}return t.frustumCulled=!1,this.registerTimedObject(kt.Current,t,e,this.linesCache),t}static getSphere(e,t,s){let r=this.spheresCache.pop();return r||(r=new ve(new Ta(1,8,8))),r.scale.set(e,e,e),r.material.wireframe=s,this.registerTimedObject(kt.Current,r,t,this.spheresCache),r}static getArrowHead(e){let t=this.arrowHeadsCache.pop();return t||(t=new ve(new Ms(0,.5,1,8))),this.registerTimedObject(kt.Current,t,e,this.arrowHeadsCache),t}static registerTimedObject(e,t,s,r){const n=this.contextBeforeRenderCallbacks.get(e),o=this.contextPostRenderCallbacks.get(e);if(n){if(e.pre_render_callbacks[e.pre_render_callbacks.length-1]!==n){const a=e.pre_render_callbacks.indexOf(n);a>=0&&e.pre_render_callbacks.splice(a,1),e.pre_render_callbacks.push(n)}}else{const a=()=>{this.onBeforeRender(e,this.timedObjectsBuffer)};this.contextBeforeRenderCallbacks.set(e,a),e.pre_render_callbacks.push(a)}if(o){if(e.post_render_callbacks[e.post_render_callbacks.length-1]!==o){const a=e.post_render_callbacks.indexOf(o);a>=0&&e.post_render_callbacks.splice(a,1),e.post_render_callbacks.push(o)}}else{const a=()=>{this.onPostRender(e,this.timedObjectsBuffer,this.timesBuffer)};this.contextPostRenderCallbacks.set(e,a),e.post_render_callbacks.push(a)}t.traverse(a=>{a.layers.disableAll(),a.layers.enable(2)}),t.renderOrder=999999,t[sT]=r,this.timedObjectsBuffer.push(t),this.timesBuffer.push(kt.Current.time.realtimeSinceStartup+s),e.scene.add(t)}static onBeforeRender(e,t){this.tmuiNeedsUpdate&&qp.update();for(let s=0;s<t.length;s++){const r=t[s];if(e.mainCamera&&r instanceof qp.MeshUIBaseElement){if(Xu(r))continue;const n=e.isInVR,o=!1,a=!n;VM(r,e.mainCamera,o,a)}}}static onPostRender(e,t,s){const r=e.time.realtimeSinceStartup;for(let n=t.length-1;n>=0;n--){const o=t[n];r>s[n]&&(t.splice(n,1),s.splice(n,1),o.removeFromParent(),Xu(o)!=!0&&o[sT].push(o))}}}h(Ds,"familyName","needle-gizmos"),h(Ds,"linesCache",[]),h(Ds,"spheresCache",[]),h(Ds,"boxesCache",[]),h(Ds,"arrowHeadsCache",[]),h(Ds,"textLabelCache",[]),h(Ds,"timedObjectsBuffer",new Array),h(Ds,"timesBuffer",new Array),h(Ds,"contextPostRenderCallbacks",new Map),h(Ds,"contextBeforeRenderCallbacks",new Map),h(Ds,"tmuiNeedsUpdate",!1);const Hee=te("debugphysics"),QN=new on;class Oo{constructor(){h(this,"ray"),h(this,"cam"),h(this,"screenPoint"),h(this,"raycaster"),h(this,"results"),h(this,"targets"),h(this,"recursive",!0),h(this,"minDistance"),h(this,"maxDistance"),h(this,"lineThreshold"),h(this,"layerMask"),h(this,"ignore"),h(this,"testObject")}screenPointFromOffset(e,t){this.screenPoint===void 0&&(this.screenPoint=new ee),this.screenPoint.x=e/window.innerWidth*2-1,this.screenPoint.y=-(t/window.innerHeight)*2+1}setLayer(e){QN.set(e),this.layerMask=QN}setMask(e){this.layerMask||(this.layerMask=new on);const t=this.layerMask;t?t.mask=e:this.layerMask=e}}h(Oo,"AllLayers",4294967295);class VN{constructor(e,t,s){h(this,"distance"),h(this,"point"),h(this,"object"),this.object=e,this.distance=t,this.point=s}}class HN{constructor(e){h(this,"context"),h(this,"engine"),h(this,"raycaster",new Tp),h(this,"defaultRaycastOptions",new Oo),h(this,"targetBuffer",new Array(1)),h(this,"defaultThresholds",{Mesh:{},Line:{threshold:-1},LOD:{},Points:{threshold:0},Sprite:{}}),h(this,"sphereResults",new Array),h(this,"sphereMask",new on),h(this,"tempBoundingBox",new Mi),this.context=e}raycastPhysicsFast(e,t=void 0,s=1/0,r=!0){var n;return((n=this.context.physics.engine)==null?void 0:n.raycast(e,t,s,r))??null}raycastPhysicsFastAndGetNormal(e,t=void 0,s=1/0,r=!0){var n;return((n=this.context.physics.engine)==null?void 0:n.raycastAndGetNormal(e,t,s,r))??null}sphereOverlapPhysics(e,t){var s;return((s=this.context.physics.engine)==null?void 0:s.sphereOverlap(e,t))??null}sphereOverlap(e,t,s=!0){if(this.sphereResults.length=0,!this.context.scene)return this.sphereResults;const r=new bs(e,t),n=this.sphereMask;n.enableAll(),n.disable(2);for(const o of this.context.scene.children)this.onSphereOverlap(o,r,n,this.sphereResults,s);return this.sphereResults.sort((o,a)=>o.distance-a.distance)}onSphereOverlap(e,t,s,r,n){if(e.type==="Mesh"&&e.layers.test(s)&&!Pt.isGizmo(e)){const o=e,a=o.geometry;if(a&&(a.boundingBox||a.computeBoundingBox(),a.boundingBox)){o.matrixWorldNeedsUpdate&&o.updateMatrixWorld();const l=this.tempBoundingBox.copy(a.boundingBox).applyMatrix4(o.matrixWorld);if(t.intersectsBox(l)){const c=Rt(e),u=c.distanceTo(t.center),d=new VN(e,u,c);if(r.push(d),!n)return}}}if(e.children)for(const o of e.children){const a=r.length;if(this.onSphereOverlap(o,t,s,r,n),a!=r.length&&!n)return}}raycastFromRay(e,t=null){const s=t??this.defaultRaycastOptions;s.ray=e;const r=this.raycast(s);return s===this.defaultRaycastOptions&&(s.ray=void 0),r}raycast(e=null){e||(e=this.defaultRaycastOptions);const t=e.screenPoint??this.context.input.mousePositionRC,s=e.raycaster??this.raycaster;if(s.near=e.minDistance??0,s.far=e.maxDistance??1/0,s.params=this.defaultThresholds,e.lineThreshold===void 0&&(e.lineThreshold=-1),s.params.Line={threshold:e.lineThreshold},e.ray)s.ray.copy(e.ray);else{const a=e.cam??this.context.mainCamera;if(!a)return Hee&&console.error("Can not perform raycast - no main camera found"),this.defaultRaycastOptions.results&&(this.defaultRaycastOptions.results.length=0),this.defaultRaycastOptions.results??[];s.setFromCamera(t,a)}let r=e.targets;r||(r=this.targetBuffer,r.length=1,r[0]=this.context.scene);let n=e.results;this.defaultRaycastOptions.results&&(this.defaultRaycastOptions.results.length=0),n||(this.defaultRaycastOptions.results||(this.defaultRaycastOptions.results=new Array),n=this.defaultRaycastOptions.results),e.layerMask!==void 0?e.layerMask instanceof on?s.layers.mask=e.layerMask.mask:s.layers.mask=e.layerMask:(s.layers.enableAll(),s.layers.disable(2)),n.length=0,this.intersect(this.raycaster,r,n,e),n.sort((a,l)=>a.distance-l.distance);const o=e.ignore;return o!==void 0&&o.length>0&&(n=n.filter(a=>!o.includes(a.object))),n}intersect(e,t,s,r){var n;for(const o of t){if(o.visible===!1||Pt.isGizmo(o)||r.lineThreshold!==void 0&&r.lineThreshold<0&&o instanceof xs)continue;const a=(n=r.testObject)==null?void 0:n.call(r,o);a!==!1&&(a!=="continue in children"&&e.intersectObject(o,!1,s),r.recursive!==!1&&this.intersect(e,o.children,s,r))}return s}}const Wee=te("debugplayerview");var vh=(i=>(i.Browser="browser",i.Headset="headset",i.Handheld="handheld",i))(vh||{});class WN{constructor(e,t){h(this,"userId"),h(this,"context"),h(this,"viewDevice","browser"),h(this,"removed",!1),h(this,"_object"),this.userId=e,this.context=t}get currentObject(){return this._object}set currentObject(e){this._object=e}get isConnected(){return this.context.connection.userIsInRoom(this.userId)}}class XN{constructor(e){h(this,"context"),h(this,"playerViews",new Map),this.context=e}setPlayerView(e,t,s){let r=this.playerViews.get(e);r||(r=new WN(e,this.context),this.playerViews.set(e,r)),r.viewDevice=s,r.currentObject=t,r.removed=!1}getPlayerView(e){if(!!e){if(!this.context.connection.userIsInRoom(e)){this.playerViews.delete(e);return}return this.playerViews.get(e)}}removePlayerView(e,t){const s=this.playerViews.get(e);s?.viewDevice===t&&(Wee&&console.log("REMOVE",e),s.removed=!0,this.playerViews.delete(e))}}new Vs;const tv=new Uint8Array(4);tv[0]=255,tv[1]=255,tv[2]=255,tv[3]=255;const Xee=new Yn(tv,1,1,Ai);function qN(i,e=1){const t="alpha"in i,s=e*e,r=new Uint8Array(4*s),n=Math.floor(i.r*255),o=Math.floor(i.g*255),a=Math.floor(i.b*255);for(let c=0;c<s;c++){const u=c*4;r[u+0]=n,r[u+1]=o,r[u+2]=a,t?r[u+3]=Math.floor(i.alpha*255):r[u+3]=255}const l=new Yn(r,e,e);return l.needsUpdate=!0,l}function qee(i,e,t,s=1,r=3){const n=s*r,o=[i,e,t],a=o.length,l=new Uint8Array(4*a*n),c=new xe;for(let d=0;d<r;d++){const p=Math.floor(d/r*a),f=st.clamp(p+1,0,a-1),m=o[p],A=o[f],y=d/r*a%1;c.lerpColors(m,A,y);const g=Math.floor(c.r*255),v=Math.floor(c.g*255),b=Math.floor(c.b*255);for(let _=0;_<s;_++){const S=(d*s+_)*4;l[S+0]=g,l[S+1]=v,l[S+2]=b,l[S+3]=255}}const u=new Yn(l,s,r);return u.needsUpdate=!0,u}function n_(i,e){const t=i.elements;e||(e=[]),e.length=0;for(let s=0;s<16;s+=4){const r=t[s],n=t[s+1],o=t[s+2],a=t[s+3],l=new tt(r,n,o,a);e.push(l)}return e}const rT=[],YN=[];function Yee(i,e){if(rT.length===0)for(let t=0;t<27;t++)rT.push(0);e||(e=rT);for(let t=0;t<27;t++)YN[t]=e[t];e=YN,i.unity_SHAr={value:new tt(e[9],e[3],e[6],e[0])},i.unity_SHBr={value:new tt(e[12],e[15],e[18],e[21])},i.unity_SHAg={value:new tt(e[10],e[4],e[7],e[1])},i.unity_SHBg={value:new tt(e[13],e[16],e[19],e[22])},i.unity_SHAb={value:new tt(e[11],e[5],e[8],e[2])},i.unity_SHBb={value:new tt(e[14],e[17],e[20],e[23])},i.unity_SHC={value:new tt(e[24],e[25],e[26],1)}}class Jee{constructor(e,t,s){h(this,"vertexShader"),h(this,"fragmentShader"),h(this,"technique"),this.vertexShader=e,this.fragmentShader=t,this.technique=s}}async function Kee(i,e){if(!i)return console.error("Can not find technique: no shader data"),null;const t=i.programs[e],s=t.vertexShader,r=t.fragmentShader;if(s!==void 0&&r!==void 0){const n=i.shaders[s],o=i.shaders[r];if(n.uri&&o.uri||n.code&&o.code){if(!n.code&&n.uri&&await JN(n),!o.code&&o.uri&&await JN(o),!n.code||!o.code)return null;const a=i.techniques[e];return new Jee(n.code,o.code,a)}}return console.error("Shader technique not found",e),null}async function JN(i){const e=i.uri;if(e)if(e.endsWith(".glsl")){const t=await new Vs().loadAsync(e);i.code=t.toString()}else i.code=Zee(i.uri)}function Zee(i){return decodeURIComponent(Array.prototype.map.call(atob(i),function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)}).join(""))}const Ja=te("debugenvlight");var Jp=(i=>(i[i.Skybox=0]="Skybox",i[i.Trilight=1]="Trilight",i[i.Flat=3]="Flat",i[i.Custom=4]="Custom",i))(Jp||{}),o_=(i=>(i[i.Skybox=0]="Skybox",i[i.Custom=1]="Custom",i))(o_||{});class KN{constructor(e){h(this,"context"),h(this,"_currentLightSettingsId"),h(this,"_sceneLightSettings"),h(this,"_timevec4",new tt),h(this,"__currentReflectionId",null),h(this,"_lighting",{}),this.context=e,this.context.pre_update_callbacks.push(this.preUpdate.bind(this))}preUpdate(){const e=this.context.time;this._timevec4.x=e.time,this._timevec4.y=Math.sin(e.time),this._timevec4.z=Math.cos(e.time),this._timevec4.w=e.deltaTime}get timeVec4(){return this._timevec4}get environmentIntensity(){if(!this._sceneLightSettings||!this._currentLightSettingsId)return 1;const e=this._sceneLightSettings.get(this._currentLightSettingsId);return e?e.ambientIntensity:1}get sceneLightSettings(){var e;return(e=this._sceneLightSettings)==null?void 0:e.values()}enable(e){var t;e instanceof ni&&(e=e.uri);const s=(t=this._sceneLightSettings)==null?void 0:t.get(e);return s?(Ja&&console.log("Enable scene light settings",e,s),e!==this._currentLightSettingsId&&this._currentLightSettingsId&&this.disable(this._currentLightSettingsId),this._currentLightSettingsId=e,s.enabled=!0,!0):!1}disable(e){var t;if(e instanceof ni&&(e=e.uri),e==null)return!1;const s=(t=this._sceneLightSettings)==null?void 0:t.get(e);return s?(Ja&&console.log("Disable scene light settings",e,s),s.enabled=!1,!0):!1}disableCurrent(){if(this._currentLightSettingsId){const e=this._currentLightSettingsId;return this.disable(this._currentLightSettingsId),e}return null}internalRegisterSceneLightSettings(e){const t=e.sourceId;if(!t){console.error("Missing source id for scene light settings, can not register:",e);return}Ja&&console.log("Register "+e?.sourceId+" lighting",e),this._sceneLightSettings||(this._sceneLightSettings=new Map),this._sceneLightSettings.set(t,e)}internalUnregisterSceneLightSettings(e){const t=e.sourceId;if(!t){console.error("Missing source id for scene light settings, can not unregister:",e);return}Ja&&console.log("Unregister "+e?.sourceId+" lighting",e),this._sceneLightSettings&&this._sceneLightSettings.delete(t)}internalRegisterReflection(e,t){Ja&&console.log("Register reflection",e,t);const s=new ZN(this.context,t,1);this._lighting[e]=s}internalGetReflection(e){return this._lighting[e]}internalEnableReflection(e){var t;this.__currentReflectionId=e;const s=(t=this._sceneLightSettings)==null?void 0:t.get(e);switch(Ja&&console.log("Enable reflection",e,s?Jp[s.ambientMode]:"Unknown ambient mode"),s?.ambientMode){case 0:case 4:const r=this.internalGetReflection(e);if(r&&r.Source){Ja&&console.log("Setting environment reflection",r);const n=this.context.scene,o=r.Source;o.colorSpace=Gt,o.mapping=bo,n.environment=o;return}else Ja&&console.warn("Could not find reflection for source",e);break}if(s?.environmentReflectionSource===1)switch(s?.ambientMode){case 1:if(s.ambientTrilight){const r=s.ambientTrilight,n=qee(r[0],r[1],r[2],64,64);n.colorSpace=Gt,n.mapping=bo,this.context.scene.environment=n}else console.error("Missing ambient trilight",s.sourceId);return;case 3:if(s.ambientLight){const r=qN(s.ambientLight,64);r.colorSpace=Gt,r.mapping=bo,this.context.scene.environment=r}else console.error("Missing ambientlight",s.sourceId);return;default:return}}internalDisableReflection(e){if(e&&e!==this.__currentReflectionId){Ja&&console.log("Not disabling reflection for",e,"because it is not the current light settings id",this.__currentReflectionId);return}Ja&&console.log("Disable reflection",e);const t=this.context.scene;t.environment=null}}class ZN{constructor(e,t,s=1){h(this,"_context"),h(this,"_source"),h(this,"_sphericalHarmonics",null),h(this,"_sphericalHarmonicsArray"),h(this,"_ambientScale",1),h(this,"_lightProbe"),this._context=e,this._source=t,this._ambientScale=s,t.mapping=bo,t.colorSpace=Gt}get Source(){return this._source}get Array(){return this._sphericalHarmonicsArray}}const $N=te("timescale");let nT=1;typeof $N=="number"&&(nT=$N);class e3{constructor(){h(this,"deltaTime",0),h(this,"time",0),h(this,"timeScale",1),h(this,"frame",0),h(this,"clock",new oC),h(this,"_smoothedFps",0),h(this,"_smoothedDeltaTime",0),h(this,"_fpsSamples",[]),h(this,"_fpsSampleIndex",0),typeof nT=="number"&&(this.timeScale=nT)}get realtimeSinceStartup(){return this.clock.elapsedTime}get frameCount(){return this.frame}get smoothedFps(){return this._smoothedFps}get smoothedDeltaTime(){return 1/this._smoothedFps}update(){this.deltaTime=this.clock.getDelta(),this.deltaTime=Math.min(.1,this.deltaTime),this.deltaTime*=this.timeScale,this.deltaTime<=0&&(this.deltaTime=1e-12),this.frame+=1,this.time+=this.deltaTime,this._fpsSamples.length<60?this._fpsSamples.push(this.deltaTime):this._fpsSamples[this._fpsSampleIndex++%60]=this.deltaTime;let e=0;for(let t=0;t<this._fpsSamples.length;t++)e+=this._fpsSamples[t];this._smoothedDeltaTime=e/this._fpsSamples.length,this._smoothedFps=1/this._smoothedDeltaTime}}const zn=te("debugcontext"),$ee=te("stats"),ete=te("debugactive"),tte=te("debugframerate"),ite=te("debugcoroutine"),ste={};class rte{constructor(){h(this,"name"),h(this,"alias"),h(this,"hash"),h(this,"runInBackground"),h(this,"domElement"),h(this,"renderer"),h(this,"camera"),h(this,"scene")}}var ks=(i=>(i[i.Start=-1]="Start",i[i.EarlyUpdate=0]="EarlyUpdate",i[i.Update=1]="Update",i[i.LateUpdate=2]="LateUpdate",i[i.OnBeforeRender=3]="OnBeforeRender",i[i.OnAfterRender=4]="OnAfterRender",i[i.PrePhysicsStep=9]="PrePhysicsStep",i[i.PostPhysicsStep=10]="PostPhysicsStep",i[i.Undefined=-1]="Undefined",i))(ks||{});function a_(i,e){if(!i)return;if(!i.isComponent){(wt()||zn)&&console.error(`Registered script is not a Needle Engine component.
|
|
4990
4990
|
The script will be ignored. Please make sure your component extends "Behaviour" imported from "@needle-tools/engine"
|
|
4991
|
-
`,i);return}const t=e?.new_scripts??kt.Current.new_scripts;t.includes(i)||t.push(i)}const Ji=class{constructor(i){h(this,"name"),h(this,"alias"),h(this,"isManagedExternally",!1),h(this,"isPaused",!1),h(this,"runInBackground",!1),h(this,"targetFrameRate"),h(this,"physicsSteps",1),h(this,"hash"),h(this,"domElement"),h(this,"_resolutionScaleFactor",1),h(this,"_boundingClientRectFrame",-1),h(this,"_boundingClientRect",null),h(this,"_domX"),h(this,"_domY"),h(this,"xr",null),h(this,"_xrFrame",null),h(this,"_currentFrameEvent",-1),h(this,"scene"),h(this,"renderer"),h(this,"composer",null),h(this,"scripts",[]),h(this,"scripts_pausedChanged",[]),h(this,"scripts_earlyUpdate",[]),h(this,"scripts_update",[]),h(this,"scripts_lateUpdate",[]),h(this,"scripts_onBeforeRender",[]),h(this,"scripts_onAfterRender",[]),h(this,"scripts_WithCorroutines",[]),h(this,"scripts_immersive_vr",[]),h(this,"scripts_immersive_ar",[]),h(this,"coroutines",{}),h(this,"post_setup_callbacks",[]),h(this,"pre_update_callbacks",[]),h(this,"pre_render_callbacks",[]),h(this,"post_render_callbacks",[]),h(this,"pre_update_oneshot_callbacks",[]),h(this,"new_scripts",[]),h(this,"new_script_start",[]),h(this,"new_scripts_pre_setup_callbacks",[]),h(this,"new_scripts_post_setup_callbacks",[]),h(this,"new_scripts_xr",[]),h(this,"mainCameraComponent"),h(this,"_camera",null),h(this,"application"),h(this,"time"),h(this,"input"),h(this,"physics"),h(this,"connection"),h(this,"assets"),h(this,"mainLight",null),h(this,"sceneLighting"),h(this,"addressables"),h(this,"lightmaps"),h(this,"players"),h(this,"_sizeChanged",!1),h(this,"_isCreated",!1),h(this,"_isCreating",!1),h(this,"_isVisible",!1),h(this,"_stats",$ee?new C7:null),h(this,"_intersectionObserver",null),h(this,"_disposeCallbacks",[]),h(this,"_originalCreationArgs"),h(this,"onUnhandledRejection",s=>{this.domElement.dispatchEvent(new CustomEvent("error",{detail:s.reason}))}),h(this,"_cameraStack",[]),h(this,"_onBeforeRenderListeners",new Map),h(this,"_onAfterRenderListeners",new Map),h(this,"_requireDepthTexture",!1),h(this,"_requireColorTexture",!1),h(this,"_renderTarget"),h(this,"_isRendering",!1),h(this,"_createId",0),h(this,"_renderlooperrors",0),h(this,"_lastTimestamp",0),h(this,"_accumulatedTime",0),h(this,"_dispatchReadyAfterFrame",!1),h(this,"_wasPaused",!1),this.name=i?.name||"",this.alias=i?.alias,this.domElement=i?.domElement||document.body,this.hash=i?.hash,i!=null&&i.renderer&&(this.renderer=i.renderer,this.isManagedExternally=!0),i?.runInBackground!==void 0&&(this.runInBackground=i.runInBackground),i!=null&&i.scene?this.scene=i.scene:this.scene=new Vr,i!=null&&i.camera&&(this._camera=i.camera),this.application=new sL(this),this.time=new e3,this.input=new oL(this),this.physics=new HN(this),this.connection=new VU(this),this.assets=new oO,this.sceneLighting=new KN(this),this.addressables=new tL(this),this.lightmaps=new vY(this),this.players=new XN(this);const e=()=>this._sizeChanged=!0;window.addEventListener("resize",e),this._disposeCallbacks.push(()=>window.removeEventListener("resize",e));const t=new ResizeObserver(s=>this._sizeChanged=!0);t.observe(this.domElement),this._disposeCallbacks.push(()=>t.disconnect()),this._intersectionObserver=new IntersectionObserver(s=>{this._isVisible=s[0].isIntersecting}),this._disposeCallbacks.push(()=>{var s;return(s=this._intersectionObserver)==null?void 0:s.disconnect()}),Ti.register(this)}static get DefaultTargetFrameRate(){return Ji._defaultTargetFramerate.value}static set DefaultTargetFrameRate(i){Ji._defaultTargetFramerate.value=i}static get DefaultWebGLRendererParameters(){return Ji._defaultWebglRendererParameters}get version(){return Hl}static get Current(){return Ti.Current}static set Current(i){Ti.Current=i}appendHTMLElement(i){return this.domElement.shadowRoot?this.domElement.shadowRoot.appendChild(i):this.domElement.appendChild(i)}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(i){if(i!==this._resolutionScaleFactor&&typeof i=="number"){if(i<=0){console.error("Invalid resolution scale factor",i);return}this._resolutionScaleFactor=i,this.updateSize()}}calculateBoundingClientRect(){if(this.isInAR){this._domX=0,this._domY=0;return}this._boundingClientRectFrame!==this.time.frame&&(this._boundingClientRectFrame=this.time.frame,this._boundingClientRect=this.domElement.getBoundingClientRect(),this._domX=this._boundingClientRect.x,this._domY=this._boundingClientRect.y)}get domWidth(){return this.isInAR?window.innerWidth:this.domElement.clientWidth}get domHeight(){return this.isInAR?window.innerHeight:this.domElement.clientHeight}get domX(){return this.calculateBoundingClientRect(),this._domX}get domY(){return this.calculateBoundingClientRect(),this._domY}get isInXR(){var i,e;return((e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.isPresenting)||!1}get xrSessionMode(){var i;return(i=this.xr)==null?void 0:i.mode}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get isInPassThrough(){return this.xr?this.xr.isPassThrough:!1}get xrSession(){var i,e;return(e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.getSession()}get xrFrame(){return this._xrFrame}get xrCamera(){var i,e;return(e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.getCamera()}get arOverlayElement(){const i=this.domElement;return typeof i.getAROverlayContainer=="function"?i.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this._camera)return this._camera;if(this.mainCameraComponent){const i=this.mainCameraComponent;return i.cam||i.buildCamera(),i.cam}return null}set mainCamera(i){this._camera=i}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}createNewRenderer(){var
|
|
4991
|
+
`,i);return}const t=e?.new_scripts??kt.Current.new_scripts;t.includes(i)||t.push(i)}const Ji=class{constructor(i){h(this,"name"),h(this,"alias"),h(this,"isManagedExternally",!1),h(this,"isPaused",!1),h(this,"runInBackground",!1),h(this,"targetFrameRate"),h(this,"physicsSteps",1),h(this,"hash"),h(this,"domElement"),h(this,"_resolutionScaleFactor",1),h(this,"_boundingClientRectFrame",-1),h(this,"_boundingClientRect",null),h(this,"_domX"),h(this,"_domY"),h(this,"xr",null),h(this,"_xrFrame",null),h(this,"_currentFrameEvent",-1),h(this,"scene"),h(this,"renderer"),h(this,"composer",null),h(this,"scripts",[]),h(this,"scripts_pausedChanged",[]),h(this,"scripts_earlyUpdate",[]),h(this,"scripts_update",[]),h(this,"scripts_lateUpdate",[]),h(this,"scripts_onBeforeRender",[]),h(this,"scripts_onAfterRender",[]),h(this,"scripts_WithCorroutines",[]),h(this,"scripts_immersive_vr",[]),h(this,"scripts_immersive_ar",[]),h(this,"coroutines",{}),h(this,"post_setup_callbacks",[]),h(this,"pre_update_callbacks",[]),h(this,"pre_render_callbacks",[]),h(this,"post_render_callbacks",[]),h(this,"pre_update_oneshot_callbacks",[]),h(this,"new_scripts",[]),h(this,"new_script_start",[]),h(this,"new_scripts_pre_setup_callbacks",[]),h(this,"new_scripts_post_setup_callbacks",[]),h(this,"new_scripts_xr",[]),h(this,"mainCameraComponent"),h(this,"_camera",null),h(this,"application"),h(this,"time"),h(this,"input"),h(this,"physics"),h(this,"connection"),h(this,"assets"),h(this,"mainLight",null),h(this,"sceneLighting"),h(this,"addressables"),h(this,"lightmaps"),h(this,"players"),h(this,"_sizeChanged",!1),h(this,"_isCreated",!1),h(this,"_isCreating",!1),h(this,"_isVisible",!1),h(this,"_stats",$ee?new C7:null),h(this,"_intersectionObserver",null),h(this,"_disposeCallbacks",[]),h(this,"_originalCreationArgs"),h(this,"onUnhandledRejection",s=>{this.domElement.dispatchEvent(new CustomEvent("error",{detail:s.reason}))}),h(this,"_cameraStack",[]),h(this,"_onBeforeRenderListeners",new Map),h(this,"_onAfterRenderListeners",new Map),h(this,"_requireDepthTexture",!1),h(this,"_requireColorTexture",!1),h(this,"_renderTarget"),h(this,"_isRendering",!1),h(this,"_createId",0),h(this,"_renderlooperrors",0),h(this,"_lastTimestamp",0),h(this,"_accumulatedTime",0),h(this,"_dispatchReadyAfterFrame",!1),h(this,"_wasPaused",!1),this.name=i?.name||"",this.alias=i?.alias,this.domElement=i?.domElement||document.body,this.hash=i?.hash,i!=null&&i.renderer&&(this.renderer=i.renderer,this.isManagedExternally=!0),i?.runInBackground!==void 0&&(this.runInBackground=i.runInBackground),i!=null&&i.scene?this.scene=i.scene:this.scene=new Vr,i!=null&&i.camera&&(this._camera=i.camera),this.application=new sL(this),this.time=new e3,this.input=new oL(this),this.physics=new HN(this),this.connection=new VU(this),this.assets=new oO,this.sceneLighting=new KN(this),this.addressables=new tL(this),this.lightmaps=new vY(this),this.players=new XN(this);const e=()=>this._sizeChanged=!0;window.addEventListener("resize",e),this._disposeCallbacks.push(()=>window.removeEventListener("resize",e));const t=new ResizeObserver(s=>this._sizeChanged=!0);t.observe(this.domElement),this._disposeCallbacks.push(()=>t.disconnect()),this._intersectionObserver=new IntersectionObserver(s=>{this._isVisible=s[0].isIntersecting}),this._disposeCallbacks.push(()=>{var s;return(s=this._intersectionObserver)==null?void 0:s.disconnect()}),Ti.register(this)}static get DefaultTargetFrameRate(){return Ji._defaultTargetFramerate.value}static set DefaultTargetFrameRate(i){Ji._defaultTargetFramerate.value=i}static get DefaultWebGLRendererParameters(){return Ji._defaultWebglRendererParameters}get version(){return Hl}static get Current(){return Ti.Current}static set Current(i){Ti.Current=i}appendHTMLElement(i){return this.domElement.shadowRoot?this.domElement.shadowRoot.appendChild(i):this.domElement.appendChild(i)}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(i){if(i!==this._resolutionScaleFactor&&typeof i=="number"){if(i<=0){console.error("Invalid resolution scale factor",i);return}this._resolutionScaleFactor=i,this.updateSize()}}calculateBoundingClientRect(){if(this.isInAR){this._domX=0,this._domY=0;return}this._boundingClientRectFrame!==this.time.frame&&(this._boundingClientRectFrame=this.time.frame,this._boundingClientRect=this.domElement.getBoundingClientRect(),this._domX=this._boundingClientRect.x,this._domY=this._boundingClientRect.y)}get domWidth(){return this.isInAR?window.innerWidth:this.domElement.clientWidth}get domHeight(){return this.isInAR?window.innerHeight:this.domElement.clientHeight}get domX(){return this.calculateBoundingClientRect(),this._domX}get domY(){return this.calculateBoundingClientRect(),this._domY}get isInXR(){var i,e;return((e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.isPresenting)||!1}get xrSessionMode(){var i;return(i=this.xr)==null?void 0:i.mode}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get isInPassThrough(){return this.xr?this.xr.isPassThrough:!1}get xrSession(){var i,e;return(e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.getSession()}get xrFrame(){return this._xrFrame}get xrCamera(){var i,e;return(e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.getCamera()}get arOverlayElement(){const i=this.domElement;return typeof i.getAROverlayContainer=="function"?i.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this._camera)return this._camera;if(this.mainCameraComponent){const i=this.mainCameraComponent;return i.cam||i.buildCamera(),i.cam}return null}set mainCamera(i){this._camera=i}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}createNewRenderer(i){var e,t,s;if((e=this.renderer)==null||e.dispose(),i={...Ji.DefaultWebGLRendererParameters,...i},!i.canvas){const r=(s=(t=this.domElement)==null?void 0:t.shadowRoot)==null?void 0:s.querySelector("canvas");r&&(i.canvas=r,zn&&console.log("Using canvas from shadow root",r))}zn&&console.log("Using Renderer Parameters:",i,this.domElement),this.renderer=new Fl(i),this.renderer.debug.checkShaderErrors=wt()||te("checkshadererrors")===!0,this.renderer.toneMappingExposure=1,this.renderer.toneMapping=Pn,this.renderer.setClearColor(new xe("lightgrey"),0),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=rS,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputColorSpace=Gt,this.renderer.useLegacyLights=!1,this.input.bindEvents()}internalOnUpdateVisible(){var i,e;(i=this._intersectionObserver)==null||i.disconnect(),(e=this._intersectionObserver)==null||e.observe(this.domElement)}requestSizeUpdate(){this._sizeChanged=!0}updateSize(i=!1){var e,t,s;if(i||!this.isManagedExternally&&((e=this.renderer.xr)==null?void 0:e.isPresenting)===!1){this._sizeChanged=!1;const r=this.resolutionScaleFactor,n=this.domWidth*r,o=this.domHeight*r,a=this.mainCamera;this.updateAspect(a),this.renderer.setSize(n,o,!0),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&((t=this.composer.setSize)==null||t.call(this.composer,n,o),"setPixelRatio"in this.composer&&typeof this.composer.setPixelRatio=="function"&&((s=this.composer.setPixelRatio)==null||s.call(this.composer,window.devicePixelRatio)))}}updateAspect(i,e,t){if(!i)return;e===void 0&&(e=this.domWidth),t===void 0&&(t=this.domHeight);const s=i.aspect;i.aspect=e/t,s!==i.aspect&&i.updateProjectionMatrix()}recreate(){this.clear(),this.create(this._originalCreationArgs)}async onCreate(i){return this.create(i)}async create(i){try{this._isCreating=!0,i!==this._originalCreationArgs&&(this._originalCreationArgs=og(i)),window.addEventListener("unhandledrejection",this.onUnhandledRejection);const e=await this.internalOnCreate(i);return this._isCreated=!0,e}finally{window.removeEventListener("unhandledrejection",this.onUnhandledRejection),this._isCreating=!1}}clear(){var i,e,t,s;Ti.dispatchCallback(Hs.ContextClearing,this),Aa(this.scene,!0,!0),this.scene=new Vr,(i=this.addressables)==null||i.dispose(),(e=this.lightmaps)==null||e.clear(),(s=(t=this.physics)==null?void 0:t.engine)==null||s.clearCaches(),this.isManagedExternally||this.renderer&&(this.renderer.renderLists.dispose(),this.renderer.state.reset(),this.renderer.resetState()),Ti.dispatchCallback(Hs.ContextCleared,this)}dispose(){this.internalOnDestroy()}onDestroy(){this.internalOnDestroy()}internalOnDestroy(){var i,e;this.clear(),(i=this.renderer)==null||i.setAnimationLoop(null),this.renderer&&(this.renderer.setClearAlpha(0),this.renderer.clear(),this.isManagedExternally||(zn&&console.log("Disposing renderer"),this.renderer.dispose())),this.scene=null,this.renderer=null,this.input.dispose();for(const t of this._disposeCallbacks)try{t()}catch(s){console.error("Error in on dispose callback:",s,t)}(e=this.domElement)!=null&&e.parentElement&&this.domElement.parentElement.removeChild(this.domElement),this._isCreated=!1,Ti.dispatchCallback(Hs.ContextDestroyed,this),Ti.unregister(this),Ji.Current===this&&(Ji.Current=null)}registerCoroutineUpdate(i,e,t){return typeof e?.next!="function"?(console.error("Registered invalid coroutine function from "+i.name+`
|
|
4992
4992
|
Coroutine functions must be generators: "*myCoroutine() {...}"
|
|
4993
4993
|
Start a coroutine from a component by calling "this.startCoroutine(myCoroutine())"`),e):(this.coroutines[t]||(this.coroutines[t]=[]),this.coroutines[t].push({comp:i,main:e}),e)}unregisterCoroutineUpdate(i,e){if(!this.coroutines[e])return;const t=this.coroutines[e].findIndex(s=>s.main===i);t>=0&&this.coroutines[e].splice(t,1)}stopAllCoroutinesFrom(i){for(const e in this.coroutines){const t=this.coroutines[e];for(let s=t.length-1;s>=0;s--)t[s].comp===i&&t.splice(s,1)}}setCurrentCamera(i){var e;if(!i)return;if(i.cam||i.buildCamera(),!i.cam){console.warn("Camera component is missing camera",i);return}const t=this._cameraStack.indexOf(i);t>=0&&this._cameraStack.splice(t,1),this._cameraStack.push(i),this.mainCameraComponent=i;const s=i.cam;s.isPerspectiveCamera&&this.updateAspect(s),(e=this.mainCameraComponent)==null||e.applyClearFlagsIfIsActiveCamera()}removeCamera(i){if(!i)return;const e=this._cameraStack.indexOf(i);if(e>=0&&this._cameraStack.splice(e,1),this.mainCameraComponent===i&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){const t=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(t)}}addBeforeRenderListener(i,e){this._onBeforeRenderListeners.has(i.uuid)||(this._onBeforeRenderListeners.set(i.uuid,[]),i.onBeforeRender=this._createRenderCallbackWrapper(i,this._onBeforeRenderListeners)),this._onBeforeRenderListeners.get(i.uuid).push(e)}removeBeforeRenderListener(i,e){if(this._onBeforeRenderListeners.has(i.uuid)){const t=this._onBeforeRenderListeners.get(i.uuid),s=t.indexOf(e);s>=0&&t.splice(s,1)}}addAfterRenderListener(i,e){var t;this._onAfterRenderListeners.has(i.uuid)||(this._onAfterRenderListeners.set(i.uuid,[]),i.onAfterRender=this._createRenderCallbackWrapper(i,this._onAfterRenderListeners)),(t=this._onAfterRenderListeners.get(i.uuid))==null||t.push(e)}removeAfterRenderListener(i,e){if(this._onAfterRenderListeners.has(i.uuid)){const t=this._onAfterRenderListeners.get(i.uuid),s=t.indexOf(e);s>=0&&t.splice(s,1)}}_createRenderCallbackWrapper(i,e){return(t,s,r,n,o,a)=>{const l=e.get(i.uuid);if(l)for(let c=0;c<l.length;c++){const u=l[c];u(t,s,r,n,o,a)}}}get isRendering(){return this._isRendering}setRequireDepth(i){this._requireDepthTexture=i}setRequireColor(i){this._requireColorTexture=i}get depthTexture(){var i;return((i=this._renderTarget)==null?void 0:i.depthTexture)||null}get opaqueColorTexture(){var i;return((i=this._renderTarget)==null?void 0:i.texture)||null}get isVisibleToUser(){if(this.isInXR)return!0;if(!this._isVisible)return!1;const i=getComputedStyle(this.domElement);return i.visibility!=="hidden"&&i.display!=="none"&&i.opacity!=="0"}async internalOnCreate(i){var e,t,s,r,n;const o=++this._createId;zn&&console.log("Creating context",this.name,i),this.clear(),this.isManagedExternally===!1&&(this.createNewRenderer(),(e=this.renderer)==null||e.setAnimationLoop(null)),await Co(1),Ji.Current=this,await Ti.dispatchCallback(Hs.ContextCreationStart,this);let a=!0,l;try{Ji.Current=this,i?l=await this.internalLoadInitialContent(o,i):l=[]}catch(u){console.error(u),a=!1}if(!a||o!==this._createId)return!1;if(this.internalOnUpdateVisible(),!this.renderer)return zn&&console.warn("Context has no renderer (perhaps it was disconnected?",this.domElement.isConnected),!1;!this.isManagedExternally&&!this.domElement.shadowRoot&&this.domElement.prepend(this.renderer.domElement),Ji.Current=this,Ji.Current=this;for(let u=0;u<this.new_scripts.length;u++){const d=this.new_scripts[u];if(d.gameObject!==void 0&&d.gameObject!==null){d.gameObject.userData===void 0&&(d.gameObject.userData={}),d.gameObject.userData.components===void 0&&(d.gameObject.userData.components=[]);const p=d.gameObject.userData.components;p.includes(d)||p.push(d)}}if(this.post_setup_callbacks)for(let u=0;u<this.post_setup_callbacks.length;u++)Ji.Current=this,await this.post_setup_callbacks[u](this);if(!this.mainCamera){Ji.Current=this;let u=null;qu(this.scene,d=>{const p=d;if(p!=null&&p.isCamera){if(yg(p.gameObject),!p.activeAndEnabled)return;if(p.tag==="MainCamera")return u=p,!0;u=p}}),u?this.setCurrentCamera(u):!Ti.dispatchCallback(Hs.MissingCamera,this,{files:l})&&!this.mainCamera&&!this.isManagedExternally&&console.warn("Missing camera in main scene",this)}if(this.input.bindEvents(),Ji.Current=this,rb(this),this.physics.engine&&((t=this.physics.engine)==null||t.step(0),(s=this.physics.engine)==null||s.postStep()),!this.isManagedExternally&&this.composer&&this.mainCamera){const u=new ub(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(u),this.composer.setSize(this.domWidth,this.domHeight)}this._sizeChanged=!0,this._stats&&(this._stats.showPanel(0),(r=this.domElement.shadowRoot)==null||r.appendChild(this._stats.dom)),zn&&s_(this.scene,!0),this.targetFrameRate===void 0?(zn&&console.warn("No target framerate set, using default",Ji.DefaultTargetFrameRate),this.targetFrameRate=Ji._defaultTargetFramerate):zn&&console.log("Target framerate set to",this.targetFrameRate),this._dispatchReadyAfterFrame=!0;const c=Ti.dispatchCallback(Hs.ContextCreated,this,{files:l});return c&&("internalSetLoadingMessage"in this.domElement&&typeof this.domElement.internalSetLoadingMessage=="function"&&((n=this.domElement)==null||n.internalSetLoadingMessage("finish loading")),await c),Lu(this,Hs.ContextCreated),zn&&console.log("Context Created...",this.renderer,this.renderer.domElement),this._isCreating=!1,this.isManagedExternally||this.restartRenderLoop(),c}async internalLoadInitialContent(i,e){var t,s;const r=new Array;if(e.files.length===0)return r;const n=[...e.files],o={name:"",progress:null,index:0,count:n.length},a=ta(),l=0;for(let c=0;c<n.length;c++){if(i!==this._createId){zn&&console.log("Aborting loading because create id changed",i,this._createId);break}const u=n[c];if(!u.includes(".glb")&&!u.includes(".gltf")){const p=`Needle Engine: found suspicious src "${u}"`;console.warn(p),un()&&is(p)}(t=e?.onLoadingStart)==null||t.call(this,c,u),zn&&console.log("Context Load "+u);const d=await a.loadSync(this,u,u,l,p=>{var f;o.name=u,o.progress=p,o.index=c,o.count=n.length,(f=e.onLoadingProgress)==null||f.call(this,o)});(s=e?.onLoadingFinished)==null||s.call(this,c,u,d??null),d?r.push({src:u,file:d}):console.warn("Could not load file: "+u)}if(i!==this._createId){for(const c of r)if(c&&c.file)for(const u of c.file.scenes)Aa(u,!0,!0)}else for(const c of r)c&&c.file&&this.scene.add(c.file.scene);return r}restartRenderLoop(){return this.renderer?this._isCreating?(console.warn("Can not start render loop while creating context"),!1):(this.renderer.setAnimationLoop((i,e)=>{this.isManagedExternally||this.update(i,e)}),!0):(console.error("Can not start render loop without renderer"),!1)}update(i,e){if(e===void 0&&(e=null),wt()||zn||pX())try{this.internalStep(i,e),this._renderlooperrors=0}catch(t){this._renderlooperrors+=1,(wt()||zn)&&(t instanceof Error||t instanceof TypeError)&&ms("Caught unhandled exception during render-loop - see console for details.",Eo.Error),console.error("Frame #"+this.time.frame+`
|
|
4994
|
-
`,t),this._renderlooperrors>=3&&(console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null)),this.domElement.dispatchEvent(new CustomEvent("error",{detail:t}))}else this.internalStep(i,e)}updatePhysics(i){this.internalUpdatePhysics(i)}internalStep(i,e){this.internalOnBeforeRender(i,e)!==!1&&(this.internalOnRender(),this.internalOnAfterRender())}internalOnBeforeRender(i,e){var t;const s=e!==null&&this._xrFrame===null;if(this._xrFrame=e,s&&this.domElement.dispatchEvent(new CustomEvent("xr-session-started",{detail:{context:this,session:this.xrSession,frame:e}})),this._currentFrameEvent=-1,this.isManagedExternally===!1&&this.isInXR===!1&&this.targetFrameRate!==void 0){this._lastTimestamp===0&&(this._lastTimestamp=i),this._accumulatedTime+=(i-this._lastTimestamp)/1e3,this._lastTimestamp=i;let r=this.targetFrameRate;if(typeof r=="object"&&(r=r.value),this._accumulatedTime<1/(r+1))return!1;this._accumulatedTime=0}if((t=this._stats)==null||t.begin(),Ji.Current=this,this.onHandlePaused())return!1;for(Ji.Current=this,this.time.update(),tte&&console.log("FPS",this.time.smoothedFps.toFixed(0)),rb(this),nb(this.scene),gO(this),Lu(this,-1);this._cameraStack.length>0&&(!this.mainCameraComponent||this.mainCameraComponent.destroyed);){this._cameraStack.splice(this._cameraStack.length-1,1);const r=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(r)}if(this.pre_update_oneshot_callbacks){for(const r in this.pre_update_oneshot_callbacks)this.pre_update_oneshot_callbacks[r]();this.pre_update_oneshot_callbacks.length=0}if(this.pre_update_callbacks)for(const r in this.pre_update_callbacks)this.pre_update_callbacks[r]();this._currentFrameEvent=0;for(let r=0;r<this.scripts_earlyUpdate.length;r++){const n=this.scripts_earlyUpdate[r];n.activeAndEnabled&&n.earlyUpdate!==void 0&&(Ji.Current=this,n.earlyUpdate())}if(this.executeCoroutines(0),Lu(this,0),this.onHandlePaused())return!1;this._currentFrameEvent=1;for(let r=0;r<this.scripts_update.length;r++){const n=this.scripts_update[r];n.activeAndEnabled&&n.update!==void 0&&(Ji.Current=this,n.update())}if(this.executeCoroutines(1),Lu(this,1),this.onHandlePaused())return!1;this._currentFrameEvent=2;for(let r=0;r<this.scripts_lateUpdate.length;r++){const n=this.scripts_lateUpdate[r];n.activeAndEnabled&&n.lateUpdate!==void 0&&(Ji.Current=this,n.lateUpdate())}if(this.executeCoroutines(2),Lu(this,2),this.onHandlePaused()||(this.physicsSteps===void 0&&(this.physicsSteps=1),this.physics.engine&&this.physicsSteps>0&&this.internalUpdatePhysics(this.physicsSteps),this.onHandlePaused()))return!1;if(this.isVisibleToUser||this.runInBackground){this._currentFrameEvent=3;for(let r=0;r<this.scripts_onBeforeRender.length;r++){const n=this.scripts_onBeforeRender[r];n.activeAndEnabled&&n.onBeforeRender!==void 0&&(Ji.Current=this,n.onBeforeRender(e))}if(this.executeCoroutines(3),Lu(this,3),this._sizeChanged&&this.updateSize(),this.pre_render_callbacks)for(const r in this.pre_render_callbacks)this.pre_render_callbacks[r](e)}return!0}internalUpdatePhysics(i){if(!this.physics.engine)return!1;const e=i,t=this.time.deltaTime/e;for(let s=0;s<e;s++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(t),this._currentFrameEvent=10,this.executeCoroutines(10);return this.physics.engine.postStep(),!0}internalOnRender(){this.isManagedExternally||(gX(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4)}internalOnAfterRender(){if(this.isVisibleToUser||this.runInBackground){for(let i=0;i<this.scripts_onAfterRender.length;i++){const e=this.scripts_onAfterRender[i];e.activeAndEnabled&&e.onAfterRender!==void 0&&(Ji.Current=this,e.onAfterRender())}if(this.executeCoroutines(4),Lu(this,4),this.post_render_callbacks)for(const i in this.post_render_callbacks)this.post_render_callbacks[i]()}this._currentFrameEvent=-1,this.connection.sendBufferedMessagesNow(),this._stats&&(this._stats.end(),this.time.frameCount%150===0&&console.log({...this.renderer.info.memory},{...this.renderer.info.render})),this._dispatchReadyAfterFrame&&(this._dispatchReadyAfterFrame=!1,this.domElement.dispatchEvent(new CustomEvent("ready")),Ti.dispatchCallback(Hs.ContextFirstFrameRendered,this))}renderNow(i){return!i&&(i=this.mainCamera,!i)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):i&&this.renderer.render(this.scene,i),this._isRendering=!1,!0)}onHandlePaused(){const i=this.evaluatePaused();if(this._wasPaused!==i){ete&&console.log("Paused?",i,"context:"+this.alias);for(let e=0;e<this.scripts_pausedChanged.length;e++){const t=this.scripts_pausedChanged[e];t.activeAndEnabled&&t.onPausedChanged!==void 0&&(Ji.Current=this,t.onPausedChanged(i,this._wasPaused))}}return this._wasPaused=i,i}evaluatePaused(){return this.isInXR?!1:this.isPaused?!0:this.runInBackground?!1:!this.isVisibleToUser}renderRequiredTextures(){if(!this.mainCamera||!this._requireDepthTexture&&!this._requireColorTexture)return;if(!this._renderTarget){if(this._renderTarget=new $t(this.domWidth,this.domHeight),this._requireDepthTexture){const t=new gp(this.domWidth,this.domHeight);this._renderTarget.depthTexture=t}this._requireColorTexture&&(this._renderTarget.texture=new Nt,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=jt,this._renderTarget.texture.magFilter=jt,this._renderTarget.texture.format=Ai)}const i=this._renderTarget;i.texture&&(i.texture.colorSpace=this.renderer.outputColorSpace);const e=this.renderer.getRenderTarget();this.renderer.setRenderTarget(i),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(e)}executeCoroutines(i){var e;if(this.coroutines[i]){const s=this.coroutines[i];for(let r=0;r<s.length;r++)try{const n=s[r];if(!n.comp||n.comp.destroyed||!n.main||n.comp.enabled===!1){ite&&console.log("Removing coroutine",n.comp,n.comp.enabled),s.splice(r,1),--r;continue}const o=n.chained;if(o&&o.length>0){const c=o[o.length-1].next();if(c.done&&o.pop(),t(c)&&(n.chained||(n.chained=[]),n.chained.push(c.value)),!c.done)continue}const a=n.main.next();if(a.done===!0){s.splice(r,1),--r;continue}const l=a.value;if(t(l)){if(l.next().done)continue;n.chained||(n.chained=[]),n.chained.push(l)}else if(l instanceof Promise){const c=l;n.chained||(n.chained=[]);const u=nL(c);(e=n.chained)==null||e.push(u);continue}}catch(n){console.error(n)}}function t(s){return!!(s&&s.next&&s.return)}}};let kt=Ji;h(kt,"_defaultTargetFramerate",{value:60}),h(kt,"_defaultWebglRendererParameters",{antialias:!0,alpha:!1}),Ti.registerCallback(Hs.ContextCreated,i=>{const e=i.context;a3(e),n3(e)});const l_=te("debugcomponents"),t3="eff8ba80-635d-11ec-90d6-0242ac120003";class cr{constructor(e){h(this,"_originalSeed"),h(this,"_seed"),typeof e=="string"&&(e=cr.hash(e)),this._originalSeed=e,this._seed=e}get seed(){return this._seed}set seed(e){this._seed=e}reset(){this._seed=this._originalSeed}generateUUID(e){if(typeof e=="string")return bO(e,t3);const t=this._seed;return this._seed-=1,bO(t.toString(),t3)}initialize(e){typeof e=="string"?this._seed=cr.hash(e):this._seed=e}static createFromString(e){return new cr(this.hash(e))}static hash(e){let t=0;for(let s=0;s<e.length;s++)t=e.charCodeAt(s)+((t<<5)-t);return t}}var i3=(i=>(i.NewInstanceCreated="new-instance-created",i.InstanceDestroyed="instance-destroyed",i))(i3||{});class s3{constructor(e){h(this,"guid"),this.guid=e}}function c_(i,e,t=!0){if(!i)return;const s=i;if(Aa(i,t),!e){console.warn("Can not send destroy: No networking connection provided",i.guid);return}if(!e.isConnected){console.warn("Can not send destroy: not connected",i.guid);return}let r=i.guid;if(!r&&s.uuid&&(r=s.uuid),!r){console.warn("Can not send destroy: failed to find guid",i);return}const n=new s3(r);e.send("instance-destroyed",n,ca.Queued)}function r3(i,e){const t=new s3(i);e.send("instance-destroyed",t,ca.Queued)}function n3(i){i.connection.beginListen("instance-destroyed",e=>{l_&&console.log("[Remote] Destroyed",i.scene,e);const t=sv(e.guid,i.scene);t&&Aa(t)})}class nte{constructor(e,t,s){h(this,"filename"),h(this,"hash"),h(this,"size"),this.filename=e,this.hash=t,this.size=s}}class o3{constructor(e,t){h(this,"guid"),h(this,"originalGuid"),h(this,"seed"),h(this,"visible"),h(this,"hostData"),h(this,"dontSave"),h(this,"parent"),h(this,"position"),h(this,"rotation"),h(this,"scale"),h(this,"preventCreation"),this.originalGuid=e,this.guid=t}}function oT(i,e,t,s){var r;const n=i;if(!n.guid)return console.warn("Can not instantiate: No guid",n),null;if(e.context||(e.context=kt.Current),!e.context)return console.error("Missing network instantiate options / reference to network connection in sync instantiate"),null;const o=e?{...e}:null,{instance:a,seed:l}=ote(n,e);if(a){const c=a;if(c.guid){l_&&console.log("[Local] new instance","gameobject:",a?.guid);const u=new o3(n.guid,c.guid);u.seed=l,o&&(o.position&&(u.position={x:o.position.x,y:o.position.y,z:o.position.z}),o.rotation&&(u.rotation={x:o.rotation.x,y:o.rotation.y,z:o.rotation.z,w:o.rotation.w}),o.scale&&(u.scale={x:o.scale.x,y:o.scale.y,z:o.scale.z})),u.position||(u.position={x:c.position.x,y:c.position.y,z:c.position.z}),u.rotation||(u.rotation={x:c.quaternion.x,y:c.quaternion.y,z:c.quaternion.z,w:c.quaternion.w}),u.scale||(u.scale={x:c.scale.x,y:c.scale.y,z:c.scale.z}),u.visible=n.visible,o!=null&&o.parent&&(typeof o.parent=="string"?u.parent=o.parent:u.parent=o.parent.guid),u.hostData=t,s===!1&&(u.dontSave=!0),(r=e?.context)==null||r.connection.send("new-instance-created",u)}else console.warn("Missing guid, can not send new instance event",c)}return a}function h_(){return Math.random()*9999999}function a3(i){i.connection.beginListen("new-instance-created",async e=>{const t=await ate(e.originalGuid,i.scene);if(e.preventCreation===!0)return;if(!t){console.warn("could not find object that was instantiated: "+e.guid);return}const s=new Ia;e.position&&(s.position=new w(e.position.x,e.position.y,e.position.z)),e.rotation&&(s.rotation=new Ie(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w)),e.scale&&(s.scale=new w(e.scale.x,e.scale.y,e.scale.z)),s.parent=e.parent,e.seed&&(s.idProvider=new cr(e.seed)),s.visible=e.visible,s.context=i,l_&&i.alias&&console.log("[Remote] instantiate in: "+i.alias);const r=Zp(t,s);r&&(e.parent==="scene"&&i.scene.add(r),l_&&console.log("[Remote] new instance","gameobject:",r?.guid,t))})}function ote(i,e){const t=h_(),s=e??new Ia;s.idProvider=new cr(t);const r=Zp(i,s);return{seed:t,instance:r}}const l3={};function c3(i,e){l3[i]=e}async function ate(i,e){const t=l3[i];if(t!=null){const s=await t(i);if(s)return s}return h3(i,e)}function h3(i,e){if(e===null||!i)return null;if(e.guid===i)return e;if(e.children)for(const t of e.children){const s=h3(i,t);if(s)return s}return null}const u_=te("debuggetcomponent"),d_=te("debuginstantiate");var u3=(i=>(i[i.None=0]="None",i[i.HideInHierarchy=1]="HideInHierarchy",i[i.HideInInspector=2]="HideInInspector",i[i.DontSaveInEditor=4]="DontSaveInEditor",i[i.NotEditable=8]="NotEditable",i[i.DontSaveInBuild=16]="DontSaveInBuild",i[i.DontUnloadUnusedAsset=32]="DontUnloadUnusedAsset",i[i.DontSave=52]="DontSave",i[i.HideAndDontSave=61]="HideAndDontSave",i))(u3||{});class Ia{constructor(){h(this,"idProvider"),h(this,"parent"),h(this,"keepWorldPosition"),h(this,"position"),h(this,"rotation"),h(this,"scale"),h(this,"visible"),h(this,"context")}clone(){var e,t,s;const r=new Ia;return r.idProvider=this.idProvider,r.parent=this.parent,r.keepWorldPosition=this.keepWorldPosition,r.position=(e=this.position)==null?void 0:e.clone(),r.rotation=(t=this.rotation)==null?void 0:t.clone(),r.scale=(s=this.scale)==null?void 0:s.clone(),r}cloneAssign(e){var t,s,r;this.idProvider=e.idProvider,this.parent=e.parent,this.keepWorldPosition=e.keepWorldPosition,this.position=(t=e.position)==null?void 0:t.clone(),this.rotation=(s=e.rotation)==null?void 0:s.clone(),this.scale=(r=e.scale)==null?void 0:r.clone()}}function Kp(i){return i.visible}function iv(i,e){return typeof e=="number"&&(e=e>.5),i.visible=e,i.visible}function d3(i){return i[Wl]||p_(i)}function p3(i,e){i[fO]=e}function p_(i){return Pa.isUsingInstancing(i)}function sv(i,e){return Ip(i,e,!0,!0)}const f3=Symbol("isDestroyed");function Xu(i){return i[f3]}function m3(i,e){i[f3]=e}const aT=Symbol("isDontDestroy");function lT(i,e=!0){i[aT]=e}const f_=[],m_=[];function Aa(i,e=!0,t=!1){f_.length=0,m_.length=0,cT(i,e,t,!0);for(const s of f_)s.gameObject=null,s.context=null;for(const s of m_)m3(s,!0),t&&Oi(s),uO(s);m_.length=0,f_.length=0}function cT(i,e=!0,t=!1,s=!0){if(i==null)return;const r=i;if(r.isComponent){if(r[aT])return;f_.push(r);const a=r.gameObject;r.__internalDisable(),r.__internalDestroy(),r.gameObject=a;return}if(i[aT])return;const n=i;u_&&console.log(n),m_.push(n);const o=n.userData.components;if(o){let a=o.length;for(let l=0;l<o.length;l++){const c=o[l];cT(c,e,t,!1),o.length<a&&(a=o.length,l--)}}if(e&&n.children)for(const a of n.children)cT(a,e,t,!1);s&&n.removeFromParent()}function qu(i,e,t=!0){return g3(i,e,t)}function*hT(i,e,t=!1,s=999,r=0){if(i!=null&&i.userData.components&&!(r>s)){for(const n of i.userData.components)e&&n?.isComponent===!0&&n instanceof e?yield n:yield n;if(t===!0)for(const n of i.children)yield*hT(n,e,!0,s,r+1)}}function g3(i,e,t,s=0){var r;if(i){if(i.isObject3D,s>1e3){console.warn("Failed to iterate components: too many levels");return}if((r=i.userData)!=null&&r.components)for(let n=0;n<i.userData.components.length;n++){const o=i.userData.components[n];if(o?.isComponent===!0){const a=e(o);if(a!==void 0)return a}}if(t&&i.children){const n=s+1;for(let o=0;o<i.children.length;o++){const a=i.children[o];if(!a)continue;const l=g3(a,e,t,n);if(l!==void 0)return l}}}}function Zp(i,e=null){let t=null;e!==null&&(e.x!==void 0?(t=new Ia,t.position=e):t=e);let s=kt.Current;t!=null&&t.context&&(s=t.context),u_&&s.alias&&console.log("context",s.alias),t&&!t.idProvider&&(t.idProvider=new cr(Date.now()));const r=[],n={},o={},a=v3(s,i,t,r,n,o);a&&(cte(n),lte(o,n)),u_&&(s_(i,!0),s_(a,!0));const l={};for(const c in r){const u=r[c],d=u.guid;t&&t.idProvider&&(u.guid=t.idProvider.generateUUID(),l[d]=u.guid,u_&&console.log(u.name,u.guid)),a_(u,s),u.__internalNewInstanceCreated&&u.__internalNewInstanceCreated()}for(const c in r){const u=r[c];u.resolveGuids&&u.resolveGuids(l),u.enabled!==!1&&(u.enabled=!0)}return rb(s),a}function v3(i,e,t,s,r,n){var o;if(!e)return null;const a=e.userData;e.userData={};const l=e.children;e.children=[];const c=e.clone(!1);if(g_(c),e.userData=a,e.children=l,r[e.uuid]={original:e,clone:c},d_&&console.log("ADD",e,c),e.type==="SkinnedMesh"&&(n[e.uuid]={original:e,clone:c}),t?.visible!==void 0&&(c.visible=t.visible),t!=null&&t.idProvider){c.uuid=t.idProvider.generateUUID();const d=c;d&&(d.guid=c.uuid)}e.animations&&e.animations.length>0&&(c.animations=[...e.animations]);const u=e.parent;if(u&&u.add(c),t!=null&&t.position?Kr(c,t.position):c.position.copy(e.position),t!=null&&t.rotation?ko(c,t.rotation):c.quaternion.copy(e.quaternion),t!=null&&t.scale?c.scale.copy(t.scale):c.scale.copy(e.scale),t!=null&&t.parent&&t.parent!=="scene"){let d=null;if(typeof t.parent=="string"?d=Ip(t.parent,i.scene,!0):d=t.parent,d){const p=t.keepWorldPosition===!0?d.attach:d.add;p?p.call(d,c):console.error("Invalid parent object",d,"received when instantiating:",e)}else console.warn("could not find parent:",t.parent)}for(const[d,p]of Object.entries(e.userData))d!=="components"&&(c.userData[d]=p);if((o=e.userData)!=null&&o.components){const d=e.userData.components,p=[];c.userData.components=p;for(let f=0;f<d.length;f++){const m=d[f],A=new m.constructor;zp(A,m),m[vg]!==void 0&&(A[vg]=m[vg]),p.push(A),A.gameObject=c,s.push(A),gg.dispatchComponentLifecycleEvent(mg.Added,A)}}t&&(t.position=void 0,t.rotation=void 0,t.scale=void 0,t.parent=void 0);for(const d in e.children){const p=e.children[d],f=v3(i,p,t,s,r,n);f&&c.add(f)}return c}function lte(i,e){for(const t in i){const s=i[t],r=s.original,n=r.skeleton,o=s.clone;if(!n){console.warn("Skinned mesh has no skeleton?",s);continue}const a=n.bones,l=o.skeleton.clone();o.skeleton=l,o.bindMatrix.clone().copy(r.bindMatrix),o.bindMatrixInverse.copy(r.bindMatrixInverse);const c=[];l.bones=c;for(let u=0;u<a.length;u++){const d=a[u],p=e[d.uuid].clone;c.push(p)}}for(const t in i){const s=i[t].clone;s.skeleton.update(),s.bind(s.skeleton,s.bindMatrix),s.updateMatrixWorld(!0)}}function cte(i){var e;for(const t in i){const s=i[t].clone;if((e=s.userData)!=null&&e.components)for(let r=0;r<s.userData.components.length;r++){const n=s.userData.components[r],o=Object.entries(n);for(const[a,l]of o)if(Array.isArray(l)){const c=[];n[a]=c;for(let u=0;u<l.length;u++){const d=l[u];if(typeof d!="object"){c.push(d);continue}const p=A3(n,a,d,i);p!==void 0?c.push(p):c.push(d)}}else if(typeof l=="object"){const c=A3(n,a,l,i);c!==void 0&&(n[a]=c)}}}}function A3(i,e,t,s){var r,n;if(t!=null)if(t.isComponent===!0){const o=t.gameObject;if(o){const a=o.uuid,l=(r=s[a])==null?void 0:r.clone;if(!l){d_&&console.log("reference did not change",e,i,t);return}const c=o.userData.components.indexOf(t);if(c>=0)return d_&&console.log(e,a),l.userData.components[c];console.warn("could not find component",e,t)}}else if(t.isObject3D===!0){if(e==="gameObject")return;const o=t;if(o){const a=o.uuid,l=(n=s[a])==null?void 0:n.clone;if(l)return d_&&console.log(e,"old",t,"new",l),l}}else{if(t.isVector4||t.isVector3||t.isVector2||t.isQuaternion||t.isEuler||t.isColor===!0)return t.clone();if(t.isEventList===!0)return new t.constructor}}const y3=new Map;function hte(i,e){if(!i)return;if(!e){console.warn("No prototype found",i,i.prototype,i.constructor);return}const t=y3.get(e);t&&t.apply(i)}function ute(i){const e=dte(i.prototype);y3.set(i,e)}function dte(i){return new pte(i)}class pte{constructor(e){h(this,"$symbol"),h(this,"extensions"),h(this,"descriptors"),this.$symbol=Symbol("prototype-extension"),this.extensions=Object.keys(e),this.descriptors=new Array;for(let t=0;t<this.extensions.length;t++){const s=this.extensions[t],r=Object.getOwnPropertyDescriptor(e,s);r&&this.descriptors.push(r)}}apply(e){if(!e[this.$symbol]){e[this.$symbol]=!0;for(let t=0;t<this.extensions.length;t++){const s=this.extensions[t],r=this.descriptors[t];r&&Object.defineProperty(e,s,r)}}}}function g_(i){i&&i.isObject3D===!0&&hte(i,ye)}ye.prototype.SetActive=function(i){this.visible=i},ye.prototype.setActive=function(i){this.visible=i},ye.prototype.destroy=function(){Aa(this)},ye.prototype.addComponent=function(i){return pT(this,i)},ye.prototype.addNewComponent=function(i){return Ah(this,new i)},ye.prototype.removeComponent=function(i){return dT(this,i)},ye.prototype.getOrAddComponent=function(i){return v_(this,i)},ye.prototype.getComponent=function(i){return $p(this,i)},ye.prototype.getComponents=function(i,e){return rv(this,i,e)},ye.prototype.getComponentInChildren=function(i){return nv(this,i)},ye.prototype.getComponentsInChildren=function(i,e){return ov(this,i,e)},ye.prototype.getComponentInParent=function(i){return av(this,i)},ye.prototype.getComponentsInParent=function(i,e){return A_(this,i,e)},Object.getOwnPropertyDescriptor(ye.prototype,"activeSelf")||Object.defineProperty(ye.prototype,"activeSelf",{get:function(){return Kp(this)},set:function(i){iv(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"transform")||Object.defineProperty(ye.prototype,"transform",{get:function(){return this}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldPosition")||Object.defineProperty(ye.prototype,"worldPosition",{get:function(){return this instanceof LC?Rt(this.object):Rt(this)},set:function(i){Kr(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldQuaternion")||Object.defineProperty(ye.prototype,"worldQuaternion",{get:function(){return this instanceof LC?Ii(this.object):Ii(this)},set:function(i){ko(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldRotation")||Object.defineProperty(ye.prototype,"worldRotation",{get:function(){return Jg(this)},set:function(i){KM(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldScale")||Object.defineProperty(ye.prototype,"worldScale",{get:function(){return ss(this)},set:function(i){Yg(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldForward")||Object.defineProperty(ye.prototype,"worldForward",{get:function(){return Bs().set(0,0,1).applyQuaternion(Ii(this))}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldRight")||Object.defineProperty(ye.prototype,"worldRight",{get:function(){return Bs().set(1,0,0).applyQuaternion(Ii(this))}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldUp")||Object.defineProperty(ye.prototype,"worldUp",{get:function(){return Bs().set(0,1,0).applyQuaternion(Ii(this))}}),ute(ye);const uT=te("debuggetcomponent");function fte(i){return i==null||i.isObject3D?i:i.object&&i.object.isObject3D?i.object:i}function dT(i,e){if(!i||!i.userData.components)return;const t=i.userData.components.indexOf(e);t<0||(gg.dispatchComponentLifecycleEvent(mg.Removing,e),e.gameObject=null,i.userData.components.splice(t,1))}function v_(i,e){const t=$p(i,e);if(t)return t;const s=new e;return Ah(i,s)}const b3=new cr("addComponentIdProvider");function Ah(i,e,t=!0){i.userData||(i.userData={}),i.userData.components||(i.userData.components=[]),i.userData.components.push(e),e.gameObject=i,(e.guid===void 0||e.guid==="invalid")&&(e.guid=b3.generateUUID()),g_(i),a_(e);try{t&&e.__internalAwake&&(yg(i),e.activeAndEnabled&&e.__internalAwake()),gg.dispatchComponentLifecycleEvent(mg.Added,e)}catch(s){console.error(s)}return e}function pT(i,e){if(typeof e=="function")return Ah(i,new e);if(e.destroyed)return console.warn("Can not move/add a destroyed component",e),e;if(e.gameObject===i)return e;if(e.gameObject&&e.gameObject.userData.components){const t=e.gameObject.userData.components.indexOf(e);e.gameObject.userData.components.splice(t,1)}if(!i.userData.components)i.userData.components=[];else if(i.userData.components.includes(e))return e;return i.userData.components.push(e),e.gameObject=i,(e.guid===void 0||e.guid==="invalid")&&(e.guid=b3.generateUUID()),a_(e),e}function _3(i){if(i.gameObject&&i.gameObject.userData.components){const e=i.gameObject.userData.components.indexOf(i);i.gameObject.userData.components.splice(e,1)}i.__internalDisable&&i.__internalDisable(),Xl(i,i.context??kt.Current),i.destroy(),i.gameObject=null}let x3=!1;function w3(i,e,t){var s;if(i==null)return null;if(!i.isObject3D)return console.error("Object is not object3D"),null;if(!((s=i?.userData)!=null&&s.components)||(typeof e=="string"&&(x3||(x3=!0,console.warn(`Accessing components by name is not supported.
|
|
4994
|
+
`,t),this._renderlooperrors>=3&&(console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null)),this.domElement.dispatchEvent(new CustomEvent("error",{detail:t}))}else this.internalStep(i,e)}updatePhysics(i){this.internalUpdatePhysics(i)}internalStep(i,e){this.internalOnBeforeRender(i,e)!==!1&&(this.internalOnRender(),this.internalOnAfterRender())}internalOnBeforeRender(i,e){var t;const s=e!==null&&this._xrFrame===null;if(this._xrFrame=e,s&&this.domElement.dispatchEvent(new CustomEvent("xr-session-started",{detail:{context:this,session:this.xrSession,frame:e}})),this._currentFrameEvent=-1,this.isManagedExternally===!1&&this.isInXR===!1&&this.targetFrameRate!==void 0){this._lastTimestamp===0&&(this._lastTimestamp=i),this._accumulatedTime+=(i-this._lastTimestamp)/1e3,this._lastTimestamp=i;let r=this.targetFrameRate;if(typeof r=="object"&&(r=r.value),this._accumulatedTime<1/(r+1))return!1;this._accumulatedTime=0}if((t=this._stats)==null||t.begin(),Ji.Current=this,this.onHandlePaused())return!1;for(Ji.Current=this,this.time.update(),tte&&console.log("FPS",this.time.smoothedFps.toFixed(0)),rb(this),nb(this.scene),gO(this),Lu(this,-1);this._cameraStack.length>0&&(!this.mainCameraComponent||this.mainCameraComponent.destroyed);){this._cameraStack.splice(this._cameraStack.length-1,1);const r=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(r)}if(this.pre_update_oneshot_callbacks){for(const r in this.pre_update_oneshot_callbacks)this.pre_update_oneshot_callbacks[r]();this.pre_update_oneshot_callbacks.length=0}if(this.pre_update_callbacks)for(const r in this.pre_update_callbacks)this.pre_update_callbacks[r]();this._currentFrameEvent=0;for(let r=0;r<this.scripts_earlyUpdate.length;r++){const n=this.scripts_earlyUpdate[r];n.activeAndEnabled&&n.earlyUpdate!==void 0&&(Ji.Current=this,n.earlyUpdate())}if(this.executeCoroutines(0),Lu(this,0),this.onHandlePaused())return!1;this._currentFrameEvent=1;for(let r=0;r<this.scripts_update.length;r++){const n=this.scripts_update[r];n.activeAndEnabled&&n.update!==void 0&&(Ji.Current=this,n.update())}if(this.executeCoroutines(1),Lu(this,1),this.onHandlePaused())return!1;this._currentFrameEvent=2;for(let r=0;r<this.scripts_lateUpdate.length;r++){const n=this.scripts_lateUpdate[r];n.activeAndEnabled&&n.lateUpdate!==void 0&&(Ji.Current=this,n.lateUpdate())}if(this.executeCoroutines(2),Lu(this,2),this.onHandlePaused()||(this.physicsSteps===void 0&&(this.physicsSteps=1),this.physics.engine&&this.physicsSteps>0&&this.internalUpdatePhysics(this.physicsSteps),this.onHandlePaused()))return!1;if(this.isVisibleToUser||this.runInBackground){this._currentFrameEvent=3;for(let r=0;r<this.scripts_onBeforeRender.length;r++){const n=this.scripts_onBeforeRender[r];n.activeAndEnabled&&n.onBeforeRender!==void 0&&(Ji.Current=this,n.onBeforeRender(e))}if(this.executeCoroutines(3),Lu(this,3),this._sizeChanged&&this.updateSize(),this.pre_render_callbacks)for(const r in this.pre_render_callbacks)this.pre_render_callbacks[r](e)}return!0}internalUpdatePhysics(i){if(!this.physics.engine)return!1;const e=i,t=this.time.deltaTime/e;for(let s=0;s<e;s++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(t),this._currentFrameEvent=10,this.executeCoroutines(10);return this.physics.engine.postStep(),!0}internalOnRender(){this.isManagedExternally||(gX(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4)}internalOnAfterRender(){if(this.isVisibleToUser||this.runInBackground){for(let i=0;i<this.scripts_onAfterRender.length;i++){const e=this.scripts_onAfterRender[i];e.activeAndEnabled&&e.onAfterRender!==void 0&&(Ji.Current=this,e.onAfterRender())}if(this.executeCoroutines(4),Lu(this,4),this.post_render_callbacks)for(const i in this.post_render_callbacks)this.post_render_callbacks[i]()}this._currentFrameEvent=-1,this.connection.sendBufferedMessagesNow(),this._stats&&(this._stats.end(),this.time.frameCount%150===0&&console.log(this.renderer.info.render.calls+" DrawCalls",`
|
|
4995
|
+
Render:`,{...this.renderer.info.render},`
|
|
4996
|
+
Memory:`,{...this.renderer.info.memory})),this._dispatchReadyAfterFrame&&(this._dispatchReadyAfterFrame=!1,this.domElement.dispatchEvent(new CustomEvent("ready")),Ti.dispatchCallback(Hs.ContextFirstFrameRendered,this))}renderNow(i){return!i&&(i=this.mainCamera,!i)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):i&&this.renderer.render(this.scene,i),this._isRendering=!1,!0)}onHandlePaused(){const i=this.evaluatePaused();if(this._wasPaused!==i){ete&&console.log("Paused?",i,"context:"+this.alias);for(let e=0;e<this.scripts_pausedChanged.length;e++){const t=this.scripts_pausedChanged[e];t.activeAndEnabled&&t.onPausedChanged!==void 0&&(Ji.Current=this,t.onPausedChanged(i,this._wasPaused))}}return this._wasPaused=i,i}evaluatePaused(){return this.isInXR?!1:this.isPaused?!0:this.runInBackground?!1:!this.isVisibleToUser}renderRequiredTextures(){if(!this.mainCamera||!this._requireDepthTexture&&!this._requireColorTexture)return;if(!this._renderTarget){if(this._renderTarget=new $t(this.domWidth,this.domHeight),this._requireDepthTexture){const t=new gp(this.domWidth,this.domHeight);this._renderTarget.depthTexture=t}this._requireColorTexture&&(this._renderTarget.texture=new Nt,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=jt,this._renderTarget.texture.magFilter=jt,this._renderTarget.texture.format=Ai)}const i=this._renderTarget;i.texture&&(i.texture.colorSpace=this.renderer.outputColorSpace);const e=this.renderer.getRenderTarget();this.renderer.setRenderTarget(i),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(e)}executeCoroutines(i){var e;if(this.coroutines[i]){const s=this.coroutines[i];for(let r=0;r<s.length;r++)try{const n=s[r];if(!n.comp||n.comp.destroyed||!n.main||n.comp.enabled===!1){ite&&console.log("Removing coroutine",n.comp,n.comp.enabled),s.splice(r,1),--r;continue}const o=n.chained;if(o&&o.length>0){const c=o[o.length-1].next();if(c.done&&o.pop(),t(c)&&(n.chained||(n.chained=[]),n.chained.push(c.value)),!c.done)continue}const a=n.main.next();if(a.done===!0){s.splice(r,1),--r;continue}const l=a.value;if(t(l)){if(l.next().done)continue;n.chained||(n.chained=[]),n.chained.push(l)}else if(l instanceof Promise){const c=l;n.chained||(n.chained=[]);const u=nL(c);(e=n.chained)==null||e.push(u);continue}}catch(n){console.error(n)}}function t(s){return!!(s&&s.next&&s.return)}}};let kt=Ji;h(kt,"_defaultTargetFramerate",{value:60}),h(kt,"_defaultWebglRendererParameters",{antialias:!0,alpha:!1}),Ti.registerCallback(Hs.ContextCreated,i=>{const e=i.context;a3(e),n3(e)});const l_=te("debugcomponents"),t3="eff8ba80-635d-11ec-90d6-0242ac120003";class cr{constructor(e){h(this,"_originalSeed"),h(this,"_seed"),typeof e=="string"&&(e=cr.hash(e)),this._originalSeed=e,this._seed=e}get seed(){return this._seed}set seed(e){this._seed=e}reset(){this._seed=this._originalSeed}generateUUID(e){if(typeof e=="string")return bO(e,t3);const t=this._seed;return this._seed-=1,bO(t.toString(),t3)}initialize(e){typeof e=="string"?this._seed=cr.hash(e):this._seed=e}static createFromString(e){return new cr(this.hash(e))}static hash(e){let t=0;for(let s=0;s<e.length;s++)t=e.charCodeAt(s)+((t<<5)-t);return t}}var i3=(i=>(i.NewInstanceCreated="new-instance-created",i.InstanceDestroyed="instance-destroyed",i))(i3||{});class s3{constructor(e){h(this,"guid"),this.guid=e}}function c_(i,e,t=!0){if(!i)return;const s=i;if(Aa(i,t),!e){console.warn("Can not send destroy: No networking connection provided",i.guid);return}if(!e.isConnected){console.warn("Can not send destroy: not connected",i.guid);return}let r=i.guid;if(!r&&s.uuid&&(r=s.uuid),!r){console.warn("Can not send destroy: failed to find guid",i);return}const n=new s3(r);e.send("instance-destroyed",n,ca.Queued)}function r3(i,e){const t=new s3(i);e.send("instance-destroyed",t,ca.Queued)}function n3(i){i.connection.beginListen("instance-destroyed",e=>{l_&&console.log("[Remote] Destroyed",i.scene,e);const t=sv(e.guid,i.scene);t&&Aa(t)})}class nte{constructor(e,t,s){h(this,"filename"),h(this,"hash"),h(this,"size"),this.filename=e,this.hash=t,this.size=s}}class o3{constructor(e,t){h(this,"guid"),h(this,"originalGuid"),h(this,"seed"),h(this,"visible"),h(this,"hostData"),h(this,"dontSave"),h(this,"parent"),h(this,"position"),h(this,"rotation"),h(this,"scale"),h(this,"preventCreation"),this.originalGuid=e,this.guid=t}}function oT(i,e,t,s){var r;const n=i;if(!n.guid)return console.warn("Can not instantiate: No guid",n),null;if(e.context||(e.context=kt.Current),!e.context)return console.error("Missing network instantiate options / reference to network connection in sync instantiate"),null;const o=e?{...e}:null,{instance:a,seed:l}=ote(n,e);if(a){const c=a;if(c.guid){l_&&console.log("[Local] new instance","gameobject:",a?.guid);const u=new o3(n.guid,c.guid);u.seed=l,o&&(o.position&&(u.position={x:o.position.x,y:o.position.y,z:o.position.z}),o.rotation&&(u.rotation={x:o.rotation.x,y:o.rotation.y,z:o.rotation.z,w:o.rotation.w}),o.scale&&(u.scale={x:o.scale.x,y:o.scale.y,z:o.scale.z})),u.position||(u.position={x:c.position.x,y:c.position.y,z:c.position.z}),u.rotation||(u.rotation={x:c.quaternion.x,y:c.quaternion.y,z:c.quaternion.z,w:c.quaternion.w}),u.scale||(u.scale={x:c.scale.x,y:c.scale.y,z:c.scale.z}),u.visible=n.visible,o!=null&&o.parent&&(typeof o.parent=="string"?u.parent=o.parent:u.parent=o.parent.guid),u.hostData=t,s===!1&&(u.dontSave=!0),(r=e?.context)==null||r.connection.send("new-instance-created",u)}else console.warn("Missing guid, can not send new instance event",c)}return a}function h_(){return Math.random()*9999999}function a3(i){i.connection.beginListen("new-instance-created",async e=>{const t=await ate(e.originalGuid,i.scene);if(e.preventCreation===!0)return;if(!t){console.warn("could not find object that was instantiated: "+e.guid);return}const s=new Ia;e.position&&(s.position=new w(e.position.x,e.position.y,e.position.z)),e.rotation&&(s.rotation=new Ie(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w)),e.scale&&(s.scale=new w(e.scale.x,e.scale.y,e.scale.z)),s.parent=e.parent,e.seed&&(s.idProvider=new cr(e.seed)),s.visible=e.visible,s.context=i,l_&&i.alias&&console.log("[Remote] instantiate in: "+i.alias);const r=Zp(t,s);r&&(e.parent==="scene"&&i.scene.add(r),l_&&console.log("[Remote] new instance","gameobject:",r?.guid,t))})}function ote(i,e){const t=h_(),s=e??new Ia;s.idProvider=new cr(t);const r=Zp(i,s);return{seed:t,instance:r}}const l3={};function c3(i,e){l3[i]=e}async function ate(i,e){const t=l3[i];if(t!=null){const s=await t(i);if(s)return s}return h3(i,e)}function h3(i,e){if(e===null||!i)return null;if(e.guid===i)return e;if(e.children)for(const t of e.children){const s=h3(i,t);if(s)return s}return null}const u_=te("debuggetcomponent"),d_=te("debuginstantiate");var u3=(i=>(i[i.None=0]="None",i[i.HideInHierarchy=1]="HideInHierarchy",i[i.HideInInspector=2]="HideInInspector",i[i.DontSaveInEditor=4]="DontSaveInEditor",i[i.NotEditable=8]="NotEditable",i[i.DontSaveInBuild=16]="DontSaveInBuild",i[i.DontUnloadUnusedAsset=32]="DontUnloadUnusedAsset",i[i.DontSave=52]="DontSave",i[i.HideAndDontSave=61]="HideAndDontSave",i))(u3||{});class Ia{constructor(){h(this,"idProvider"),h(this,"parent"),h(this,"keepWorldPosition"),h(this,"position"),h(this,"rotation"),h(this,"scale"),h(this,"visible"),h(this,"context")}clone(){var e,t,s;const r=new Ia;return r.idProvider=this.idProvider,r.parent=this.parent,r.keepWorldPosition=this.keepWorldPosition,r.position=(e=this.position)==null?void 0:e.clone(),r.rotation=(t=this.rotation)==null?void 0:t.clone(),r.scale=(s=this.scale)==null?void 0:s.clone(),r}cloneAssign(e){var t,s,r;this.idProvider=e.idProvider,this.parent=e.parent,this.keepWorldPosition=e.keepWorldPosition,this.position=(t=e.position)==null?void 0:t.clone(),this.rotation=(s=e.rotation)==null?void 0:s.clone(),this.scale=(r=e.scale)==null?void 0:r.clone()}}function Kp(i){return i.visible}function iv(i,e){return typeof e=="number"&&(e=e>.5),i.visible=e,i.visible}function d3(i){return i[Wl]||p_(i)}function p3(i,e){i[fO]=e}function p_(i){return Pa.isUsingInstancing(i)}function sv(i,e){return Ip(i,e,!0,!0)}const f3=Symbol("isDestroyed");function Xu(i){return i[f3]}function m3(i,e){i[f3]=e}const aT=Symbol("isDontDestroy");function lT(i,e=!0){i[aT]=e}const f_=[],m_=[];function Aa(i,e=!0,t=!1){f_.length=0,m_.length=0,cT(i,e,t,!0);for(const s of f_)s.gameObject=null,s.context=null;for(const s of m_)m3(s,!0),t&&Oi(s),uO(s);m_.length=0,f_.length=0}function cT(i,e=!0,t=!1,s=!0){if(i==null)return;const r=i;if(r.isComponent){if(r[aT])return;f_.push(r);const a=r.gameObject;r.__internalDisable(),r.__internalDestroy(),r.gameObject=a;return}if(i[aT])return;const n=i;u_&&console.log(n),m_.push(n);const o=n.userData.components;if(o){let a=o.length;for(let l=0;l<o.length;l++){const c=o[l];cT(c,e,t,!1),o.length<a&&(a=o.length,l--)}}if(e&&n.children)for(const a of n.children)cT(a,e,t,!1);s&&n.removeFromParent()}function qu(i,e,t=!0){return g3(i,e,t)}function*hT(i,e,t=!1,s=999,r=0){if(i!=null&&i.userData.components&&!(r>s)){for(const n of i.userData.components)e&&n?.isComponent===!0&&n instanceof e?yield n:yield n;if(t===!0)for(const n of i.children)yield*hT(n,e,!0,s,r+1)}}function g3(i,e,t,s=0){var r;if(i){if(i.isObject3D,s>1e3){console.warn("Failed to iterate components: too many levels");return}if((r=i.userData)!=null&&r.components)for(let n=0;n<i.userData.components.length;n++){const o=i.userData.components[n];if(o?.isComponent===!0){const a=e(o);if(a!==void 0)return a}}if(t&&i.children){const n=s+1;for(let o=0;o<i.children.length;o++){const a=i.children[o];if(!a)continue;const l=g3(a,e,t,n);if(l!==void 0)return l}}}}function Zp(i,e=null){let t=null;e!==null&&(e.x!==void 0?(t=new Ia,t.position=e):t=e);let s=kt.Current;t!=null&&t.context&&(s=t.context),u_&&s.alias&&console.log("context",s.alias),t&&!t.idProvider&&(t.idProvider=new cr(Date.now()));const r=[],n={},o={},a=v3(s,i,t,r,n,o);a&&(cte(n),lte(o,n)),u_&&(s_(i,!0),s_(a,!0));const l={};for(const c in r){const u=r[c],d=u.guid;t&&t.idProvider&&(u.guid=t.idProvider.generateUUID(),l[d]=u.guid,u_&&console.log(u.name,u.guid)),a_(u,s),u.__internalNewInstanceCreated&&u.__internalNewInstanceCreated()}for(const c in r){const u=r[c];u.resolveGuids&&u.resolveGuids(l),u.enabled!==!1&&(u.enabled=!0)}return rb(s),a}function v3(i,e,t,s,r,n){var o;if(!e)return null;const a=e.userData;e.userData={};const l=e.children;e.children=[];const c=e.clone(!1);if(g_(c),e.userData=a,e.children=l,r[e.uuid]={original:e,clone:c},d_&&console.log("ADD",e,c),e.type==="SkinnedMesh"&&(n[e.uuid]={original:e,clone:c}),t?.visible!==void 0&&(c.visible=t.visible),t!=null&&t.idProvider){c.uuid=t.idProvider.generateUUID();const d=c;d&&(d.guid=c.uuid)}e.animations&&e.animations.length>0&&(c.animations=[...e.animations]);const u=e.parent;if(u&&u.add(c),t!=null&&t.position?Kr(c,t.position):c.position.copy(e.position),t!=null&&t.rotation?ko(c,t.rotation):c.quaternion.copy(e.quaternion),t!=null&&t.scale?c.scale.copy(t.scale):c.scale.copy(e.scale),t!=null&&t.parent&&t.parent!=="scene"){let d=null;if(typeof t.parent=="string"?d=Ip(t.parent,i.scene,!0):d=t.parent,d){const p=t.keepWorldPosition===!0?d.attach:d.add;p?p.call(d,c):console.error("Invalid parent object",d,"received when instantiating:",e)}else console.warn("could not find parent:",t.parent)}for(const[d,p]of Object.entries(e.userData))d!=="components"&&(c.userData[d]=p);if((o=e.userData)!=null&&o.components){const d=e.userData.components,p=[];c.userData.components=p;for(let f=0;f<d.length;f++){const m=d[f],A=new m.constructor;zp(A,m),m[vg]!==void 0&&(A[vg]=m[vg]),p.push(A),A.gameObject=c,s.push(A),gg.dispatchComponentLifecycleEvent(mg.Added,A)}}t&&(t.position=void 0,t.rotation=void 0,t.scale=void 0,t.parent=void 0);for(const d in e.children){const p=e.children[d],f=v3(i,p,t,s,r,n);f&&c.add(f)}return c}function lte(i,e){for(const t in i){const s=i[t],r=s.original,n=r.skeleton,o=s.clone;if(!n){console.warn("Skinned mesh has no skeleton?",s);continue}const a=n.bones,l=o.skeleton.clone();o.skeleton=l,o.bindMatrix.clone().copy(r.bindMatrix),o.bindMatrixInverse.copy(r.bindMatrixInverse);const c=[];l.bones=c;for(let u=0;u<a.length;u++){const d=a[u],p=e[d.uuid].clone;c.push(p)}}for(const t in i){const s=i[t].clone;s.skeleton.update(),s.bind(s.skeleton,s.bindMatrix),s.updateMatrixWorld(!0)}}function cte(i){var e;for(const t in i){const s=i[t].clone;if((e=s.userData)!=null&&e.components)for(let r=0;r<s.userData.components.length;r++){const n=s.userData.components[r],o=Object.entries(n);for(const[a,l]of o)if(Array.isArray(l)){const c=[];n[a]=c;for(let u=0;u<l.length;u++){const d=l[u];if(typeof d!="object"){c.push(d);continue}const p=A3(n,a,d,i);p!==void 0?c.push(p):c.push(d)}}else if(typeof l=="object"){const c=A3(n,a,l,i);c!==void 0&&(n[a]=c)}}}}function A3(i,e,t,s){var r,n;if(t!=null)if(t.isComponent===!0){const o=t.gameObject;if(o){const a=o.uuid,l=(r=s[a])==null?void 0:r.clone;if(!l){d_&&console.log("reference did not change",e,i,t);return}const c=o.userData.components.indexOf(t);if(c>=0)return d_&&console.log(e,a),l.userData.components[c];console.warn("could not find component",e,t)}}else if(t.isObject3D===!0){if(e==="gameObject")return;const o=t;if(o){const a=o.uuid,l=(n=s[a])==null?void 0:n.clone;if(l)return d_&&console.log(e,"old",t,"new",l),l}}else{if(t.isVector4||t.isVector3||t.isVector2||t.isQuaternion||t.isEuler||t.isColor===!0)return t.clone();if(t.isEventList===!0)return new t.constructor}}const y3=new Map;function hte(i,e){if(!i)return;if(!e){console.warn("No prototype found",i,i.prototype,i.constructor);return}const t=y3.get(e);t&&t.apply(i)}function ute(i){const e=dte(i.prototype);y3.set(i,e)}function dte(i){return new pte(i)}class pte{constructor(e){h(this,"$symbol"),h(this,"extensions"),h(this,"descriptors"),this.$symbol=Symbol("prototype-extension"),this.extensions=Object.keys(e),this.descriptors=new Array;for(let t=0;t<this.extensions.length;t++){const s=this.extensions[t],r=Object.getOwnPropertyDescriptor(e,s);r&&this.descriptors.push(r)}}apply(e){if(!e[this.$symbol]){e[this.$symbol]=!0;for(let t=0;t<this.extensions.length;t++){const s=this.extensions[t],r=this.descriptors[t];r&&Object.defineProperty(e,s,r)}}}}function g_(i){i&&i.isObject3D===!0&&hte(i,ye)}ye.prototype.SetActive=function(i){this.visible=i},ye.prototype.setActive=function(i){this.visible=i},ye.prototype.destroy=function(){Aa(this)},ye.prototype.addComponent=function(i){return pT(this,i)},ye.prototype.addNewComponent=function(i){return Ah(this,new i)},ye.prototype.removeComponent=function(i){return dT(this,i)},ye.prototype.getOrAddComponent=function(i){return v_(this,i)},ye.prototype.getComponent=function(i){return $p(this,i)},ye.prototype.getComponents=function(i,e){return rv(this,i,e)},ye.prototype.getComponentInChildren=function(i){return nv(this,i)},ye.prototype.getComponentsInChildren=function(i,e){return ov(this,i,e)},ye.prototype.getComponentInParent=function(i){return av(this,i)},ye.prototype.getComponentsInParent=function(i,e){return A_(this,i,e)},Object.getOwnPropertyDescriptor(ye.prototype,"activeSelf")||Object.defineProperty(ye.prototype,"activeSelf",{get:function(){return Kp(this)},set:function(i){iv(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"transform")||Object.defineProperty(ye.prototype,"transform",{get:function(){return this}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldPosition")||Object.defineProperty(ye.prototype,"worldPosition",{get:function(){return this instanceof LC?Rt(this.object):Rt(this)},set:function(i){Kr(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldQuaternion")||Object.defineProperty(ye.prototype,"worldQuaternion",{get:function(){return this instanceof LC?Ii(this.object):Ii(this)},set:function(i){ko(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldRotation")||Object.defineProperty(ye.prototype,"worldRotation",{get:function(){return Jg(this)},set:function(i){KM(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldScale")||Object.defineProperty(ye.prototype,"worldScale",{get:function(){return ss(this)},set:function(i){Yg(this,i)}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldForward")||Object.defineProperty(ye.prototype,"worldForward",{get:function(){return Bs().set(0,0,1).applyQuaternion(Ii(this))}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldRight")||Object.defineProperty(ye.prototype,"worldRight",{get:function(){return Bs().set(1,0,0).applyQuaternion(Ii(this))}}),Object.getOwnPropertyDescriptor(ye.prototype,"worldUp")||Object.defineProperty(ye.prototype,"worldUp",{get:function(){return Bs().set(0,1,0).applyQuaternion(Ii(this))}}),ute(ye);const uT=te("debuggetcomponent");function fte(i){return i==null||i.isObject3D?i:i.object&&i.object.isObject3D?i.object:i}function dT(i,e){if(!i||!i.userData.components)return;const t=i.userData.components.indexOf(e);t<0||(gg.dispatchComponentLifecycleEvent(mg.Removing,e),e.gameObject=null,i.userData.components.splice(t,1))}function v_(i,e){const t=$p(i,e);if(t)return t;const s=new e;return Ah(i,s)}const b3=new cr("addComponentIdProvider");function Ah(i,e,t=!0){i.userData||(i.userData={}),i.userData.components||(i.userData.components=[]),i.userData.components.push(e),e.gameObject=i,(e.guid===void 0||e.guid==="invalid")&&(e.guid=b3.generateUUID()),g_(i),a_(e);try{t&&e.__internalAwake&&(yg(i),e.activeAndEnabled&&e.__internalAwake()),gg.dispatchComponentLifecycleEvent(mg.Added,e)}catch(s){console.error(s)}return e}function pT(i,e){if(typeof e=="function")return Ah(i,new e);if(e.destroyed)return console.warn("Can not move/add a destroyed component",e),e;if(e.gameObject===i)return e;if(e.gameObject&&e.gameObject.userData.components){const t=e.gameObject.userData.components.indexOf(e);e.gameObject.userData.components.splice(t,1)}if(!i.userData.components)i.userData.components=[];else if(i.userData.components.includes(e))return e;return i.userData.components.push(e),e.gameObject=i,(e.guid===void 0||e.guid==="invalid")&&(e.guid=b3.generateUUID()),a_(e),e}function _3(i){if(i.gameObject&&i.gameObject.userData.components){const e=i.gameObject.userData.components.indexOf(i);i.gameObject.userData.components.splice(e,1)}i.__internalDisable&&i.__internalDisable(),Xl(i,i.context??kt.Current),i.destroy(),i.gameObject=null}let x3=!1;function w3(i,e,t){var s;if(i==null)return null;if(!i.isObject3D)return console.error("Object is not object3D"),null;if(!((s=i?.userData)!=null&&s.components)||(typeof e=="string"&&(x3||(x3=!0,console.warn(`Accessing components by name is not supported.
|
|
4995
4997
|
Please use the component type instead. This may keep working in local development but it will fail when bundling your application.
|
|
4996
4998
|
|
|
4997
4999
|
You can import other modules your main module to get access to types
|
|
@@ -5405,9 +5407,9 @@ ${o.join(`
|
|
|
5405
5407
|
|
|
5406
5408
|
}
|
|
5407
5409
|
`}function kz(i){return`(${i.r}, ${i.g}, ${i.b})`}function Oz(i){return`(${i.x}, ${i.y})`}const Lz=[1023,33777,33778,33779,35842,35843,37496,37808,37809,37810,37811,37812,37813,37814,37815,37816,37817,37818,37819,37820,37821,36492];te("debugusdz");const Uz=class{constructor(i,e,t){h(this,"id"),h(this,"trigger"),h(this,"action"),h(this,"exclusive",!1),this.id="Behavior_"+M_(i)+"_"+Uz.global_id++,this.trigger=e,this.action=t}makeExclusive(i){return this.exclusive=i,this}writeTo(i,e,t){if(!this.trigger||!this.action)return;t.beginBlock(`def Preliminary_Behavior "${this.id}"`),t.appendLine(`rel actions = <${this.action.id}>`),t.appendLine(`uniform bool exclusive = ${this.exclusive}`);let s="";if(Array.isArray(this.trigger)){s="[";for(let r=0;r<this.trigger.length;r++){const n=this.trigger[r];s+="<"+n.id+">",r+1<this.trigger.length&&(s+=", ")}s+="]"}else s=`<${this.trigger.id}>`;if(t.appendLine(`rel triggers = ${s} `),t.appendLine(),Array.isArray(this.trigger))for(const r of this.trigger)r.writeTo(e,t),t.appendLine();else this.trigger.writeTo(e,t);t.appendLine(),this.action.writeTo(e,t),t.closeBlock()}};let xr=Uz;h(xr,"global_id",0);function ZT(i,e){var t,s;let r="";if(Array.isArray(i)){let n="[ ";for(let o=0;o<i.length;o++){let a=i[o];if(typeof a=="string")n+=a;else if(typeof a=="object"){a.isObject3D&&(a=e.findById(a.uuid));const l=(t=a.getPath)==null?void 0:t.call(a);n+=l}o+1<i.length&&(n+=", ")}n+=" ]",r=n}else typeof i=="object"&&(i.isObject3D&&(i=e.findById(i.uuid)),r=(s=i.getPath)==null?void 0:s.call(i));return r}const Fz=class{constructor(i,e){h(this,"id"),h(this,"targetId"),h(this,"tokenId"),h(this,"type"),h(this,"distance"),i&&(this.targetId=i),e?this.id=e:this.id="Trigger_"+Fz.global_id++}writeTo(i,e){e.beginBlock(`def Preliminary_Trigger "${this.id}"`),this.targetId&&(typeof this.targetId!="string"&&(this.targetId=ZT(this.targetId,i)),e.appendLine("rel affectedObjects = "+this.targetId)),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.type&&e.appendLine(`token type = "${this.type}"`),typeof this.distance=="number"&&e.appendLine(`double distance = ${this.distance}`),e.closeBlock()}};let ed=Fz;h(ed,"global_id",0);class wr{static sceneStartTrigger(){const e=new ed;return e.targetId=void 0,e.tokenId="SceneTransition",e.type="enter",e}static tapTrigger(e){const t=new ed(e);return t.tokenId="TapGesture",t}static isTapTrigger(e){return e?.tokenId==="TapGesture"}static proximityToCameraTrigger(e,t){const s=new ed(e);return s.tokenId="ProximityToCamera",s.distance=t,s}}class wh{constructor(e,t){h(this,"id"),h(this,"actions"),h(this,"loops",0),h(this,"performCount",1),h(this,"type","serial"),this.id=e,this.actions=t}static getId(){return this.global_id++}addAction(e){return this.actions.push(e),this}makeParallel(){return this.type="parallel",this}makeSequence(){return this.type="serial",this}makeLooping(){return this.loops=1,this}makeRepeat(e){return this.performCount=e,this}writeTo(e,t){t.beginBlock(`def Preliminary_Action "${this.id}"`),t.beginArray("rel actions");for(const s of this.actions){if(!s)continue;const r=s===this.actions[this.actions.length-1];t.appendLine("<"+s.id+">"+(r?"":", "))}t.closeArray(),t.appendLine(),t.appendLine('token info:id = "Group"'),t.appendLine(`bool loops = ${this.loops} `),t.appendLine(`int performCount = ${this.performCount} `),t.appendLine(`token type = "${this.type}"`),t.appendLine();for(const s of this.actions)s&&(s.writeTo(e,t),t.appendLine());t.closeBlock()}}h(wh,"global_id",0);var $T=(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))($T||{}),eI=(i=>(i.Relative="relative",i.Absolute="absolute",i))(eI||{}),Nz=(i=>(i.Allow="allow",i.Ignore="ignore",i.Stop="stop",i))(Nz||{});const tI=class{constructor(i,e){h(this,"id"),h(this,"tokenId"),h(this,"affectedObjects"),h(this,"easeType"),h(this,"motionType"),h(this,"duration"),h(this,"moveDistance"),h(this,"style"),h(this,"type"),h(this,"front"),h(this,"up"),h(this,"start"),h(this,"animationSpeed"),h(this,"reversed"),h(this,"pingPong"),h(this,"xFormTarget"),h(this,"audio"),h(this,"gain"),h(this,"auralMode"),h(this,"multiplePerformOperation"),i&&(this.affectedObjects=i),e?this.id=e:this.id="Action",this.id+="_"+tI.global_id++}clone(){const i=new tI,e=i.id;return Object.assign(i,this),i.id=e,i}writeTo(i,e){e.beginBlock(`def Preliminary_Action "${this.id}"`),this.affectedObjects&&(typeof this.affectedObjects!="string"&&(this.affectedObjects=ZT(this.affectedObjects,i)),e.appendLine("rel affectedObjects = "+this.affectedObjects)),typeof this.duration=="number"&&e.appendLine(`double duration = ${this.duration} `),this.easeType&&e.appendLine(`token easeType = "${this.easeType}"`),this.tokenId&&e.appendLine(`token info:id = "${this.tokenId}"`),this.motionType&&e.appendLine(`token motionType = "${this.motionType}"`),typeof this.moveDistance=="number"&&e.appendLine(`double moveDistance = ${this.moveDistance} `),this.style&&e.appendLine(`token style = "${this.style}"`),this.type&&e.appendLine(`token type = "${this.type}"`),this.front&&e.appendLine(`vector3d front = (${this.front.x}, ${this.front.y}, ${this.front.z})`),this.up&&e.appendLine(`vector3d upVector = (${this.up.x}, ${this.up.y}, ${this.up.z})`),typeof this.start=="number"&&e.appendLine(`double start = ${this.start} `),typeof this.animationSpeed=="number"&&e.appendLine(`double animationSpeed = ${this.animationSpeed} `),typeof this.reversed=="boolean"&&e.appendLine(`bool reversed = ${this.reversed}`),typeof this.pingPong=="boolean"&&e.appendLine(`bool reverses = ${this.pingPong}`),this.xFormTarget&&(typeof this.xFormTarget!="string"&&(this.xFormTarget=ZT(this.xFormTarget,i)),e.appendLine(`rel xformTarget = ${this.xFormTarget}`)),typeof this.audio=="string"&&e.appendLine(`asset audio = @${this.audio}@`),typeof this.gain=="number"&&e.appendLine(`double gain = ${this.gain}`),typeof this.auralMode=="string"&&e.appendLine(`token auralMode = "${this.auralMode}"`),typeof this.multiplePerformOperation=="string"&&e.appendLine(`token multiplePerformOperation = "${this.multiplePerformOperation}"`),e.closeBlock()}};let xa=tI;h(xa,"global_id",0);let gf=class am{constructor(e,t,s){h(this,"x",0),h(this,"y",0),h(this,"z",0),this.x=e,this.y=t,this.z=s}static get up(){return new am(0,1,0)}static get right(){return new am(1,0,0)}static get forward(){return new am(0,0,1)}static get back(){return new am(0,0,-1)}static get zero(){return new am(0,0,0)}};var iI=(i=>(i.Play="play",i.Pause="pause",i.Stop="stop",i))(iI||{}),sI=(i=>(i.Spatial="spatial",i.NonSpatial="nonSpatial",i.Ambient="ambient",i))(sI||{});class ui{static sequence(...e){return new wh("group_"+wh.getId(),e).makeSequence()}static parallel(...e){return new wh("group_"+wh.getId(),e).makeParallel()}static fadeAction(e,t,s){const r=new xa(e);return r.tokenId="Visibility",r.type=s?"show":"hide",r.duration=t,r.style="basic",r.motionType="none",r.moveDistance=0,r.easeType="none",r}static startAnimationAction(e,t,s=0,r=1,n=!1,o=!1){const a=new xa(e);if(a.tokenId="StartAnimation",a.start=t,a.duration=s,a.animationSpeed=r,a.reversed=n,a.pingPong=o,a.multiplePerformOperation="allow",n&&(a.start-=s),o){a.pingPong=!1;const l=a.clone();return l.reversed=!n,l.start=a.start,l.reversed&&(l.start-=s),ui.sequence(a,l)}return a}static waitAction(e){const t=new xa;return t.tokenId="Wait",t.duration=e,t}static lookAtCameraAction(e,t=9999999999999,s,r){const n=new xa(e);return n.tokenId="LookAtCamera",n.duration=t,n.front=s??gf.forward,n.up=r??gf.up,n}static emphasize(e,t,s=2,r=1,n="basic"){const o=new xa(e);return o.tokenId="Emphasize",o.duration=t,o.style=n??"basic",o.motionType=$T[s],o.moveDistance=r,o}static transformAction(e,t,s,r,n="inout"){const o=new xa(e);return o.tokenId="Transform",o.duration=s,o.type=r,o.easeType=n,Array.isArray(t)&&console.error("Transform target must not be an array",t),o.xFormTarget=t,o}static playAudioAction(e,t,s="play",r=1,n="spatial"){const o=new xa(e);return o.tokenId="Audio",o.type=s,o.audio=t,o.gain=r,o.auralMode=n,o.multiplePerformOperation="allow",o}}class hse{constructor(e){h(this,"object"),h(this,"model"),this.object=e}get id(){return this.object.uuid}apply(e){if(!this.model&&(this.model=e.findById(this.object.uuid),!this.model)){console.error("could not find model with id "+this.object.uuid);return}this.onApply(e)}}class rI extends hse{constructor(e,t,s,r){super(e),h(this,"matrix"),h(this,"material"),h(this,"geometry"),h(this,"_enableAction"),h(this,"_disableAction"),this.matrix=t,this.material=s,this.geometry=r}onApply(e){var t,s;const r=this.model;if(!r)return;(t=r.parent)!=null&&t.isDynamic||Fo.createEmptyParent(r);const n=r.clone();this.matrix&&(n.matrix=this.matrix),this.material&&(n.material=this.material),this.geometry&&(n.geometry=this.geometry),(s=r.parent)==null||s.add(n)}enable(){return this._enableAction?this._enableAction:(this._enableAction=ui.fadeAction(this.object,0,!0),this._enableAction)}disable(){return this._disableAction?this._disableAction:(this._disableAction=ui.fadeAction(this.object,0,!1),this._disableAction)}}class nI{constructor(e){h(this,"actions"),h(this,"sortedActions"),this.actions=[...e]}organize(){this.sortedActions={};for(const e of this.actions){const t=e.id;this.sortedActions[t]||(this.sortedActions[t]=[]),this.sortedActions[t].push(e)}}getActions(e){return this.sortedActions||this.organize(),this.sortedActions[e.uuid]}}var use=Object.defineProperty,dse=Object.getOwnPropertyDescriptor,zz=(i,e,t,s)=>{for(var r=s>1?void 0:s?dse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&use(e,t,r),r};class yv extends Pe{constructor(){super(...arguments),h(this,"from"),h(this,"to"),h(this,"width",0),h(this,"centered",!0),h(this,"_centerPos")}awake(){this._centerPos=new w}update(){if(!this.from||!this.to)return;const e=Rt(this.from).clone(),t=Rt(this.to).clone(),s=e.distanceTo(t);this._centerPos.copy(e),this._centerPos.add(t),this._centerPos.multiplyScalar(.5),Kr(this.gameObject,this.centered?this._centerPos:e),this.gameObject.lookAt(Rt(this.to).clone()),this.gameObject.scale.set(this.width,this.width,s)}}zz([x(oe)],yv.prototype,"from",2),zz([x(oe)],yv.prototype,"to",2);var pse=Object.defineProperty,fse=Object.getOwnPropertyDescriptor,bv=(i,e,t,s)=>{for(var r=s>1?void 0:s?fse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&pse(e,t,r),r};const vf=te("debuganimation");class eo extends Pe{constructor(){super(...arguments),h(this,"playAutomatically",!0),h(this,"randomStartTime",!0),h(this,"minMaxSpeed"),h(this,"minMaxOffsetNormalized"),h(this,"loop",!0),h(this,"clampWhenFinished",!1),h(this,"_tempAnimationClipBeforeGameObjectExisted",null),h(this,"_tempAnimationsArray"),h(this,"mixer"),h(this,"_actions",[]),h(this,"_currentActions",[]),h(this,"_handles",[]),h(this,"_didInit",!1)}get clip(){var e;return(e=this.animations)!=null&&e.length?this.animations[0]:null}set clip(e){if(!this.__didAwake){vf&&console.warn("Assign clip during serialization",e),this._tempAnimationClipBeforeGameObjectExisted=e;return}e&&(this.gameObject.animations||(this.gameObject.animations=[]),!this.animations.includes(e)&&(this.animations.length>0?this.animations.splice(0,0,e):this.animations.push(e)))}set clips(e){this.animations=e}set animations(e){e==null||!Array.isArray(e)||(this.gameObject?this.gameObject.animations=e:this._tempAnimationsArray=e)}get animations(){return this.gameObject.animations||this._tempAnimationsArray||[]}get currentAction(){return this._currentActions[0]}get currentActions(){return this._currentActions}get actions(){return this._actions}set actions(e){this._actions=e}awake(){vf&&console.log("Animation Awake",this.name,this),this._tempAnimationsArray&&(this.animations=this._tempAnimationsArray,this._tempAnimationsArray=void 0),this._tempAnimationClipBeforeGameObjectExisted&&(this.clip=this._tempAnimationClipBeforeGameObjectExisted,this._tempAnimationClipBeforeGameObjectExisted=null),this.playAutomatically&&this.init()}onEnable(){var e;if(this.playAutomatically&&((e=this.animations)==null?void 0:e.length)>0&&this.currentActions.length<=0){const t=Math.floor(Math.random()*this.actions.length);this.play(t)}}start(){this.randomStartTime&&this.currentAction&&(this.currentAction.time=Math.random()*this.currentAction.getClip().duration)}update(){this.mixer&&this.mixer.update(this.context.time.deltaTime)}getAction(e){var t;return(t=this.actions)==null?void 0:t.find(s=>s.getClip().name===e)}get isPlaying(){for(let e=0;e<this.actions.length;e++)if(this.actions[e].isRunning())return!0;return!1}play(e=0,t){if(vf&&console.log("PLAY",e),this.init(),!this.mixer){vf&&console.warn("Missing mixer",this);return}e===void 0&&(e=0);let s=e;if(typeof e=="number"){if(e>=this.animations.length){vf&&console.log("No animation at index",e);return}s=this.animations[e]}else typeof e=="string"&&(s=this.animations.find(n=>n.name===e));if(!s){console.error("Could not find clip",e);return}t||(t={}),t.minMaxOffsetNormalized||(t.minMaxOffsetNormalized=this.minMaxOffsetNormalized),t.minMaxSpeed||(t.minMaxSpeed=this.minMaxSpeed),t.loop===void 0&&(t.loop=this.loop),t.clampWhenFinished===void 0&&(t.clampWhenFinished=this.clampWhenFinished);for(const n of this.actions)if(n.getClip()===s)return this.internalOnPlay(n,t);if(!(s instanceof Ln)){console.warn("Clip is no AnimationClip",s,"on object: "+this.name);return}const r=this.mixer.clipAction(s);return this.actions.push(r),this.internalOnPlay(r,t)}internalOnPlay(e,t){var s=this.currentAction;if(s===e&&s.isRunning()&&s.time<s.getClip().duration){const a=this.tryFindHandle(e);if(a)return a.getPromise()}const r=t?.exclusive??!0;t!=null&&t.fadeDuration?(r&&s?.fadeOut(t.fadeDuration),e.fadeIn(t.fadeDuration)):r&&s?.stop(),e.reset(),e.enabled=!0,e.time=0,e.timeScale=1;const n=e.getClip();t!=null&&t.minMaxOffsetNormalized&&(e.time=st.lerp(t.minMaxOffsetNormalized.x,t.minMaxOffsetNormalized.y,Math.random())*n.duration),t!=null&&t.minMaxSpeed&&(e.timeScale=st.lerp(t.minMaxSpeed.x,t.minMaxSpeed.y,Math.random())),t!=null&&t.clampWhenFinished&&(e.clampWhenFinished=!0),t?.startTime!==void 0&&(e.time=t.startTime),t?.loop!==void 0?e.loop=t.loop?FS:xm:e.loop=xm,e.play(),vf&&console.log("PLAY",e.getClip().name,e);const o=new mse(e,this.mixer,t,a=>{this._handles.splice(this._handles.indexOf(o),1)});return this._handles.push(o),o.getPromise()}tryFindHandle(e){for(const t of this._handles)if(t.action===e)return t}init(){this._didInit||(this._didInit=!0,this.gameObject&&(this.actions=[],this.mixer=new O0(this.gameObject)))}}bv([x()],eo.prototype,"playAutomatically",2),bv([x()],eo.prototype,"randomStartTime",2),bv([x()],eo.prototype,"loop",2),bv([x()],eo.prototype,"clampWhenFinished",2),bv([x(Ln)],eo.prototype,"clips",1);class mse{constructor(e,t,s,r){h(this,"mixer"),h(this,"action"),h(this,"promise",null),h(this,"resolve",null),h(this,"reject",null),h(this,"_options"),h(this,"_resolveCallback",null),h(this,"_rejectCallback",null),h(this,"_loopCallback"),h(this,"_finishedCallback"),h(this,"_resolvedOrRejectedCallback"),this.action=e,this.mixer=t,this._resolvedOrRejectedCallback=r,this._options=s}getPromise(){return this.promise?this.promise:(this.promise=new Promise((e,t)=>{this._resolveCallback=e,this._rejectCallback=t,this.resolve=this.onResolve.bind(this),this.reject=this.onReject.bind(this)}),this._loopCallback=this.onLoop.bind(this),this._finishedCallback=this.onFinished.bind(this),this.mixer.addEventListener("loop",this._loopCallback),this.mixer.addEventListener("finished",this._finishedCallback),this.promise)}_update(){this._options&&this._options.endTime!==void 0&&this.action.time>this._options.endTime&&(this._options.loop===!0?this.action.time=this._options.startTime??0:(this.action.time=this._options.endTime,this.action.timeScale=0,this.onResolve()))}onResolve(){var e,t;this.dispose(),(e=this._resolvedOrRejectedCallback)==null||e.call(this,this),(t=this._resolveCallback)==null||t.call(this,this.action)}onReject(e){var t,s;this.dispose(),(t=this._resolvedOrRejectedCallback)==null||t.call(this,this),(s=this._rejectCallback)==null||s.call(this,e)}onLoop(e){}onFinished(e){e.action===this.action&&this.onResolve()}dispose(){this._loopCallback&&this.mixer.removeEventListener("loop",this._loopCallback),this._finishedCallback&&this.mixer.removeEventListener("finished",this._finishedCallback),this._loopCallback=void 0,this._finishedCallback=void 0}}var gse=Object.defineProperty,vse=Object.getOwnPropertyDescriptor,Sh=(i,e,t,s)=>{for(var r=s>1?void 0:s?vse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&gse(e,t,r),r};class dc{constructor(){h(this,"time"),h(this,"value"),h(this,"inTangent"),h(this,"inWeight"),h(this,"outTangent"),h(this,"outWeight"),h(this,"weightedMode")}}Sh([x()],dc.prototype,"time",2),Sh([x()],dc.prototype,"value",2),Sh([x()],dc.prototype,"inTangent",2),Sh([x()],dc.prototype,"inWeight",2),Sh([x()],dc.prototype,"outTangent",2),Sh([x()],dc.prototype,"outWeight",2),Sh([x()],dc.prototype,"weightedMode",2);const oI=class{constructor(){h(this,"keys")}clone(){var i;const e=new oI;return e.keys=((i=this.keys)==null?void 0:i.map(t=>{const s=new dc;return s.time=t.time,s.value=t.value,s.inTangent=t.inTangent,s.inWeight=t.inWeight,s.outTangent=t.outTangent,s.outWeight=t.outWeight,s.weightedMode=t.weightedMode,s}))||[],e}get duration(){return!this.keys||this.keys.length==0?0:this.keys[this.keys.length-1].time}evaluate(i){if(!this.keys||this.keys.length==0)return 0;if(this.keys[0].time>=i)return this.keys[0].value;for(let e=0;e<this.keys.length;e++){const t=this.keys[e];if(t.time<=i)if(e+1<this.keys.length){const s=this.keys[e+1];if(s.time<i)continue;return!isFinite(t.outTangent)||!isFinite(s.inTangent)?t.value:oI.interpolateValue(i,t,s)}else return t.value}return this.keys[this.keys.length-1].value}static interpolateValue(i,e,t){const s=e.time,r=e.value,n=e.outTangent,o=t.time,a=t.value,l=t.inTangent,c=o-s,u=c*c,d=u*c,p=((n+l)*c-2*(a-r))/d,f=(3*(a-r)-(l+2*n)*c)/u,m=n,A=r,y=i-s,g=y*y,v=g*y;return p*v+f*g+m*y+A}};let td=oI;Sh([x(dc)],td.prototype,"keys",2);class Ase extends xs{constructor(e,t=1,s=16,r=2){const n=new gt,o=s+r*2,a=new Float32Array((o*3+3)*3);n.setAttribute("position",new Ze(a,3));const l=new _s({color:65280}),c=new _s({color:16776960});super(n,[c,l]),this.audio=e,this.range=t,this.divisionsInnerAngle=s,this.divisionsOuterAngle=r,this.type="PositionalAudioHelper",this.update()}update(){const e=this.audio,t=this.range,s=this.divisionsInnerAngle,r=this.divisionsOuterAngle,n=js.degToRad(e.panner.coneInnerAngle),o=js.degToRad(e.panner.coneOuterAngle),a=n/2,l=o/2;let c=0,u=0,d,p;const f=this.geometry,m=f.attributes.position;f.clearGroups();function A(y,g,v,b){const _=(g-y)/v;for(m.setXYZ(c,0,0,0),u++,d=y;d<g;d+=_)p=c+u,m.setXYZ(p,Math.sin(d)*t,0,Math.cos(d)*t),m.setXYZ(p+1,Math.sin(Math.min(d+_,g))*t,0,Math.cos(Math.min(d+_,g))*t),m.setXYZ(p+2,0,0,0),u+=3;f.addGroup(c,u,b),c+=u,u=0}A(-l,-a,r,0),A(-a,a,s,1),A(a,l,r,0),m.needsUpdate=!0,n===o&&(this.material[0].visible=!1)}dispose(){this.geometry.dispose(),this.material[0].dispose(),this.material[1].dispose()}}var yse=Object.defineProperty,bse=Object.getOwnPropertyDescriptor,Za=(i,e,t,s)=>{for(var r=s>1?void 0:s?bse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&yse(e,t,r),r};const $r=te("debugaudio");let D_=!1;const k_=[];function O_(){if(D_)return;wt()&&console.log("User interaction registered: audio can now be played"),D_=!0;const i=[...k_];k_.length=0,i.forEach(e=>e())}document.addEventListener("pointerdown",O_),document.addEventListener("click",O_),document.addEventListener("dragstart",O_),document.addEventListener("touchstart",O_);const Ch=class extends Pe{constructor(){super(...arguments),h(this,"clip",""),h(this,"playOnAwake",!1),h(this,"preload",!1),h(this,"_spatialBlend",0),h(this,"_minDistance",1),h(this,"_maxDistance",100),h(this,"_volume",1),h(this,"rollOffMode",0),h(this,"playInBackground",!0),h(this,"_loop",!1),h(this,"sound",null),h(this,"helper",null),h(this,"wasPlaying",!1),h(this,"audioLoader",null),h(this,"shouldPlay",!1),h(this,"_lastClipStartedLoading",null),h(this,"_audioElement",null),h(this,"onVisibilityChanged",()=>{switch(document.visibilityState){case"hidden":(this.playInBackground===!1||ja())&&(this.wasPlaying=this.isPlaying,this.isPlaying&&this.pause());break;case"visible":$r&&console.log("visible",this.enabled,this.playOnAwake,!this.isPlaying,Ch.userInteractionRegistered,this.wasPlaying),this.enabled&&this.playOnAwake&&!this.isPlaying&&Ch.userInteractionRegistered&&this.wasPlaying&&this.play();break}}),h(this,"onApplicationMuteChanged",()=>{var i,e;this.context.application.muted?(i=this.sound)==null||i.setVolume(0):(e=this.sound)==null||e.setVolume(this.volume)}),h(this,"createAudio",i=>{$r&&console.log("AudioBuffer finished loading",i);const e=this.Sound;if(!e){$r&&console.warn("Failed getting sound?",this.name);return}e.isPlaying&&e.stop(),i&&e.setBuffer(i),e.loop=this._loop,this.context.application.muted?e.setVolume(0):e.setVolume(this.volume),e.autoplay=this.shouldPlay&&Ch.userInteractionRegistered,this.applySpatialDistanceSettings(),e.isPlaying&&e.stop(),Ch.registerWaitForAllowAudio(this.__onAllowAudioCallback)}),h(this,"__onAllowAudioCallback",()=>{this.shouldPlay&&this.play()}),h(this,"_lastContextTime",0),h(this,"_hasEnded",!0),h(this,"_needUpdateSpatialDistanceSettings",!1)}static get userInteractionRegistered(){return D_}static registerWaitForAllowAudio(i){if(i!==null){if(D_){i();return}k_.indexOf(i)===-1&&k_.push(i)}}get loop(){return this.sound&&(this._loop=this.sound.getLoop()),this._loop}set loop(i){this._loop=i,this.sound&&this.sound.setLoop(i)}get spatialBlend(){return this._spatialBlend}set spatialBlend(i){i!==this._spatialBlend&&(this._spatialBlend=i,this._needUpdateSpatialDistanceSettings=!0)}get minDistance(){return this._minDistance}set minDistance(i){this._minDistance!==i&&(this._minDistance=i,this._needUpdateSpatialDistanceSettings=!0)}get maxDistance(){return this._maxDistance}set maxDistance(i){this._maxDistance!==i&&(this._maxDistance=i,this._needUpdateSpatialDistanceSettings=!0)}get volume(){return this._volume}set volume(i){this._volume=i,this.sound&&!this.context.application.muted&&($r&&console.log(this.name,"audio set volume",i),this.sound.setVolume(i))}get Sound(){var i;if(!this.sound&&Ch.userInteractionRegistered){let e=oe.getComponent(this.context.mainCamera,Th)??oe.findObjectOfType(Th,this.context);!e&&this.context.mainCamera&&(e=oe.addNewComponent(this.context.mainCamera,Th)),e!=null&&e.listener?(this.sound=new ak(e.listener),(i=this.gameObject)==null||i.add(this.sound)):$r&&console.warn("No audio listener found in scene - can not play audio")}return this.sound}get ShouldPlay(){return this.shouldPlay}get audioContext(){var i;return(i=this.sound)==null?void 0:i.context}awake(){$r&&console.log(this),this.audioLoader=new k0,this.playOnAwake&&(this.shouldPlay=!0),this.preload&&typeof this.clip=="string"&&this.audioLoader.load(this.clip,this.createAudio,()=>{},console.error)}onEnable(){this.sound&&this.gameObject.add(this.sound),Ch.userInteractionRegistered?this.playOnAwake&&this.context.application.isVisible&&this.play():Ch.registerWaitForAllowAudio(()=>{this.enabled&&!this.destroyed&&this.shouldPlay&&this.onNewClip(this.clip)}),globalThis.addEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.addEventListener(yb.MuteChanged,this.onApplicationMuteChanged)}onDisable(){globalThis.removeEventListener("visibilitychange",this.onVisibilityChanged),this.context.application.removeEventListener(yb.MuteChanged,this.onApplicationMuteChanged),this.pause()}applySpatialDistanceSettings(){const i=this.sound;if(!i)return;this._needUpdateSpatialDistanceSettings=!1;const e=st.lerp(10*this._maxDistance/Math.max(1e-4,this.spatialBlend),this._minDistance,this.spatialBlend);switch($r&&console.log(this.name,this._minDistance,this._maxDistance,this.spatialBlend,"Ref distance="+e),i.setRefDistance(e),i.setMaxDistance(Math.max(.01,this._maxDistance)),this.rollOffMode){case 0:i.setDistanceModel("exponential");break;case 1:i.setDistanceModel("linear");break}this.spatialBlend>0?$r&&!this.helper&&(this.helper=new Ase(i,i.getRefDistance()),i.add(this.helper)):this.helper&&this.helper.parent&&this.helper.removeFromParent()}async onNewClip(i){if(i&&(this.clip=i),typeof i=="string")if($r&&console.log(i),i.endsWith(".mp3")||i.endsWith(".wav")){if(this.audioLoader||(this.audioLoader=new k0),this.shouldPlay=!0,this._lastClipStartedLoading===i){$r&&console.log("Is currently loading:",this._lastClipStartedLoading,this);return}this._lastClipStartedLoading=i,$r&&console.log("load audio",i);const e=await this.audioLoader.loadAsync(i).catch(console.error);this._lastClipStartedLoading=null,e&&this.createAudio(e)}else console.warn("Unsupported audio clip type",i);else this.shouldPlay=!0,this.createAudio()}play(i=void 0){var e,t,s;!i&&this.clip&&(i=this.clip),i!==void 0&&typeof i!="string"&&!(i instanceof MediaStream)&&(wt()&&console.warn("Called play on AudioSource with unknown argument type:",i+`
|
|
5408
|
-
Using the assigned clip instead:`,this.clip),i=this.clip);let r=!this.sound||i&&i!==this.clip;if(typeof i=="string"&&!this.audioLoader&&(r=!0),(i instanceof MediaStream||typeof i=="string")&&(this.clip=i),r){this.shouldPlay=!0,this.onNewClip(i);return}if(this.shouldPlay=!0,this._hasEnded=!1,$r&&console.log("play",(e=this.sound)==null?void 0:e.getVolume(),this.sound),this.sound&&!this.sound.isPlaying){const n=this.context.application.muted;n&&this.sound.setVolume(0),(t=this.gameObject)==null||t.add(this.sound),this.clip instanceof MediaStream?(this.sound.setMediaStreamSource(this.clip),this._audioElement||(this._audioElement=document.createElement("audio"),this._audioElement.style.display="none"),this._audioElement.parentNode||(s=this.context.domElement.shadowRoot)==null||s.append(this._audioElement),this._audioElement.srcObject=this.clip,this._audioElement.autoplay=!1):(this._audioElement&&this._audioElement.remove(),this.sound.play(n?.1:0))}}pause(){var i,e;$r&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.isPlaying&&this.sound.source&&(this._lastContextTime=(i=this.sound)==null?void 0:i.context.currentTime,this.sound.pause()),(e=this._audioElement)==null||e.remove()}stop(){var i,e;$r&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.source&&(this._lastContextTime=(i=this.sound)==null?void 0:i.context.currentTime,$r&&console.log(this._lastContextTime),this.sound.stop()),(e=this._audioElement)==null||e.remove()}get isPlaying(){var i;return((i=this.sound)==null?void 0:i.isPlaying)??!1}set isPlaying(i){}get time(){var i,e;return(i=this.sound)!=null&&i.source?((e=this.sound.source)==null?void 0:e.context.currentTime)-this._lastContextTime+this.sound.offset:0}set time(i){if(this.sound){if(i===this.sound.offset)return;const e=this.isPlaying;this.stop(),this.sound.offset=i,e&&this.play()}}update(){this.helper&&(this.isPlaying&&this.helper.update(),this.helper.visible=this.isPlaying),this._needUpdateSpatialDistanceSettings&&this.applySpatialDistanceSettings(),this.sound&&!this.sound.isPlaying&&this.shouldPlay&&!this._hasEnded&&(this._hasEnded=!0,$r&&console.log("Audio clip ended",this.clip),this.dispatchEvent(new CustomEvent("ended",{detail:this})))}};let vs=Ch;Za([x(URL)],vs.prototype,"clip",2),Za([x()],vs.prototype,"playOnAwake",2),Za([x()],vs.prototype,"preload",2),Za([x()],vs.prototype,"loop",1),Za([x()],vs.prototype,"spatialBlend",1),Za([x()],vs.prototype,"minDistance",1),Za([x()],vs.prototype,"maxDistance",1),Za([x()],vs.prototype,"volume",1),Za([x()],vs.prototype,"rollOffMode",2),Za([x()],vs.prototype,"playInBackground",2);const jz={type:"change"},aI={type:"start"},Gz={type:"end"},L_=new Wn,Qz=new ln,_se=Math.cos(70*js.DEG2RAD);let xse=class extends Ks{constructor(i,e){super(),this.object=i,this.domElement=e,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new w,this.cursor=new w,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=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.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:tu.ROTATE,MIDDLE:tu.DOLLY,RIGHT:tu.PAN},this.touches={ONE:iu.ROTATE,TWO:iu.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return o.phi},this.getAzimuthalAngle=function(){return o.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(W){W.addEventListener("keydown",nt),this._domElementKeyEvents=W},this.stopListenToKeyEvents=function(){this._domElementKeyEvents.removeEventListener("keydown",nt),this._domElementKeyEvents=null},this.saveState=function(){t.target0.copy(t.target),t.position0.copy(t.object.position),t.zoom0=t.object.zoom},this.reset=function(){t.target.copy(t.target0),t.object.position.copy(t.position0),t.object.zoom=t.zoom0,t.object.updateProjectionMatrix(),t.dispatchEvent(jz),t.update(),r=s.NONE},this.update=function(){const W=new w,T=new Ie().setFromUnitVectors(i.up,new w(0,1,0)),B=T.clone().invert(),G=new w,V=new Ie,k=new w,Y=2*Math.PI;return function(ce=null){const me=t.object.getWorldPosition(i.position);W.copy(me).sub(t.target),W.applyQuaternion(T),o.setFromVector3(W),t.autoRotate&&r===s.NONE&&F(E(ce)),t.enableDamping?(o.theta+=a.theta*t.dampingFactor,o.phi+=a.phi*t.dampingFactor):(o.theta+=a.theta,o.phi+=a.phi);let ge=t.minAzimuthAngle,be=t.maxAzimuthAngle;isFinite(ge)&&isFinite(be)&&(ge<-Math.PI?ge+=Y:ge>Math.PI&&(ge-=Y),be<-Math.PI?be+=Y:be>Math.PI&&(be-=Y),ge<=be?o.theta=Math.max(ge,Math.min(be,o.theta)):o.theta=o.theta>(ge+be)/2?Math.max(ge,o.theta):Math.min(be,o.theta)),o.phi=Math.max(t.minPolarAngle,Math.min(t.maxPolarAngle,o.phi)),o.makeSafe(),t.enableDamping===!0?t.target.addScaledVector(u,t.dampingFactor):t.target.add(u),t.target.sub(t.cursor),t.target.clampLength(t.minTargetRadius,t.maxTargetRadius),t.target.add(t.cursor),t.zoomToCursor&&M||t.object.isOrthographicCamera?o.radius=Z(o.radius):(t.enableDamping?c=js.lerp(c,l,t.dampingFactor):c=l,o.radius=Z(o.radius*c)),W.setFromSpherical(o),W.applyQuaternion(B),me.copy(t.target).add(W),t.object.parent?t.object.parent.worldToLocal(me):t.object.position.copy(me),t.object.lookAt(t.target),t.enableDamping===!0?(a.theta*=1-t.dampingFactor,a.phi*=1-t.dampingFactor,u.multiplyScalar(1-t.dampingFactor)):(a.set(0,0,0),u.set(0,0,0));let Re=!1;if(t.zoomToCursor&&M){let Ve=null;if(t.object.isPerspectiveCamera){const qe=W.length();Ve=Z(qe*l);const Ye=qe-Ve;t.object.position.addScaledVector(_,Ye),t.object.updateMatrixWorld()}else if(t.object.isOrthographicCamera){const qe=new w(S.x,S.y,0);qe.unproject(t.object),t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom/l)),t.object.updateProjectionMatrix(),Re=!0;const Ye=new w(S.x,S.y,0);Ye.unproject(t.object),t.object.position.sub(Ye).add(qe),t.object.updateMatrixWorld(),Ve=W.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),t.zoomToCursor=!1;Ve!==null&&(this.screenSpacePanning?t.target.set(0,0,-1).transformDirection(t.object.matrix).multiplyScalar(Ve).add(t.object.position):(L_.origin.copy(t.object.position),L_.direction.set(0,0,-1).transformDirection(t.object.matrix),Math.abs(t.object.up.dot(L_.direction))<_se?i.lookAt(t.target):(Qz.setFromNormalAndCoplanarPoint(t.object.up,t.target),L_.intersectPlane(Qz,t.target))))}else t.object.isOrthographicCamera&&(Re=l!==1,Re&&(t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom/l)),t.object.updateProjectionMatrix()));return l=1,M=!1,Re||G.distanceToSquared(t.object.position)>n||8*(1-V.dot(t.object.quaternion))>n||k.distanceToSquared(t.target)>0?(t.dispatchEvent(jz),G.copy(t.object.position),V.copy(t.object.quaternion),k.copy(t.target),!0):!1}}(),this.dispose=function(){t.domElement.removeEventListener("contextmenu",Ot),t.domElement.removeEventListener("pointerdown",U),t.domElement.removeEventListener("pointercancel",ne),t.domElement.removeEventListener("wheel",Le),t.domElement.removeEventListener("pointermove",P),t.domElement.removeEventListener("pointerup",ne),t._domElementKeyEvents!==null&&(t._domElementKeyEvents.removeEventListener("keydown",nt),t._domElementKeyEvents=null)};const t=this,s={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let r=s.NONE;const n=1e-6,o=new uC,a=new uC;let l=1,c=1;const u=new w,d=new ee,p=new ee,f=new ee,m=new ee,A=new ee,y=new ee,g=new ee,v=new ee,b=new ee,_=new w,S=new ee;let M=!1;const C=[],R={};let I=!1;function E(W){return W!==null?2*Math.PI/60*t.autoRotateSpeed*W:2*Math.PI/60/60*t.autoRotateSpeed}function z(W){const T=Math.abs(W*.01);return Math.pow(.95,t.zoomSpeed*T)}function F(W){a.theta-=W}function q(W){a.phi-=W}const N=function(){const W=new w;return function(T,B){W.setFromMatrixColumn(B,0),W.multiplyScalar(-T),u.add(W)}}(),H=function(){const W=new w;return function(T,B){t.screenSpacePanning===!0?W.setFromMatrixColumn(B,1):(W.setFromMatrixColumn(B,0),W.crossVectors(t.object.up,W)),W.multiplyScalar(T),u.add(W)}}(),L=function(){const W=new w,T=new w;return function(B,G){const V=t.domElement;if(t.object.isPerspectiveCamera){t.object.getWorldPosition(T),W.copy(T).sub(t.target);let k=W.length();k*=Math.tan(t.object.fov/2*Math.PI/180),N(2*B*k/V.clientHeight,t.object.matrixWorld),H(2*G*k/V.clientHeight,t.object.matrixWorld)}else t.object.isOrthographicCamera?(N(B*(t.object.right-t.object.left)/t.object.zoom/V.clientWidth,t.object.matrixWorld),H(G*(t.object.top-t.object.bottom)/t.object.zoom/V.clientHeight,t.object.matrixWorld)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),t.enablePan=!1)}}();function j(W){t.object.isPerspectiveCamera||t.object.isOrthographicCamera?l/=W:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function Q(W){t.object.isPerspectiveCamera||t.object.isOrthographicCamera?l*=W:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function $(W,T){if(!t.zoomToCursor)return;M=!0;const B=t.domElement.getBoundingClientRect(),G=W-B.left,V=T-B.top,k=B.width,Y=B.height;S.x=G/k*2-1,S.y=-(V/Y)*2+1,_.set(S.x,S.y,1).unproject(t.object).sub(t.object.position).normalize()}function Z(W){return Math.max(t.minDistance,Math.min(t.maxDistance,W))}function se(W){d.set(W.clientX,W.clientY)}function Ae(W){$(W.clientX,W.clientX),g.set(W.clientX,W.clientY)}function Ue(W){m.set(W.clientX,W.clientY)}function Qe(W){p.set(W.clientX,W.clientY),f.subVectors(p,d).multiplyScalar(t.rotateSpeed);const T=t.domElement;F(2*Math.PI*f.x/T.clientHeight),q(2*Math.PI*f.y/T.clientHeight),d.copy(p),t.update()}function Ke(W){v.set(W.clientX,W.clientY),b.subVectors(v,g),b.y>0?j(z(b.y)):b.y<0&&Q(z(b.y)),g.copy(v),t.update()}function ae(W){A.set(W.clientX,W.clientY),y.subVectors(A,m).multiplyScalar(t.panSpeed),L(y.x,y.y),m.copy(A),t.update()}function Ee(W){$(W.clientX,W.clientY),W.deltaY<0?Q(z(W.deltaY)):W.deltaY>0&&j(z(W.deltaY)),t.update()}function He(W){let T=!1;switch(W.code){case t.keys.UP:W.ctrlKey||W.metaKey||W.shiftKey?q(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):L(0,t.keyPanSpeed),T=!0;break;case t.keys.BOTTOM:W.ctrlKey||W.metaKey||W.shiftKey?q(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):L(0,-t.keyPanSpeed),T=!0;break;case t.keys.LEFT:W.ctrlKey||W.metaKey||W.shiftKey?F(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):L(t.keyPanSpeed,0),T=!0;break;case t.keys.RIGHT:W.ctrlKey||W.metaKey||W.shiftKey?F(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):L(-t.keyPanSpeed,0),T=!0;break}T&&(W.preventDefault(),t.update())}function Fe(W){if(C.length===1)d.set(W.pageX,W.pageY);else{const T=ut(W),B=.5*(W.pageX+T.x),G=.5*(W.pageY+T.y);d.set(B,G)}}function We(W){if(C.length===1)m.set(W.pageX,W.pageY);else{const T=ut(W),B=.5*(W.pageX+T.x),G=.5*(W.pageY+T.y);m.set(B,G)}}function le(W){const T=ut(W),B=W.pageX-T.x,G=W.pageY-T.y,V=Math.sqrt(B*B+G*G);g.set(0,V)}function Ne(W){t.enableZoom&&le(W),t.enablePan&&We(W)}function X(W){t.enableZoom&&le(W),t.enableRotate&&Fe(W)}function Se(W){if(C.length==1)p.set(W.pageX,W.pageY);else{const B=ut(W),G=.5*(W.pageX+B.x),V=.5*(W.pageY+B.y);p.set(G,V)}f.subVectors(p,d).multiplyScalar(t.rotateSpeed);const T=t.domElement;F(2*Math.PI*f.x/T.clientHeight),q(2*Math.PI*f.y/T.clientHeight),d.copy(p)}function _e(W){if(C.length===1)A.set(W.pageX,W.pageY);else{const T=ut(W),B=.5*(W.pageX+T.x),G=.5*(W.pageY+T.y);A.set(B,G)}y.subVectors(A,m).multiplyScalar(t.panSpeed),L(y.x,y.y),m.copy(A)}function Ge(W){const T=ut(W),B=W.pageX-T.x,G=W.pageY-T.y,V=Math.sqrt(B*B+G*G);v.set(0,V),b.set(0,Math.pow(v.y/g.y,t.zoomSpeed)),j(b.y),g.copy(v);const k=(W.pageX+T.x)*.5,Y=(W.pageY+T.y)*.5;$(k,Y)}function ue(W){t.enableZoom&&Ge(W),t.enablePan&&_e(W)}function dt(W){t.enableZoom&&Ge(W),t.enableRotate&&Se(W)}function U(W){t.enabled!==!1&&(C.length===0&&(t.domElement.addEventListener("pointermove",P),t.domElement.addEventListener("pointerup",ne)),lt(W),W.pointerType==="touch"?bt(W):ke(W))}function P(W){t.enabled!==!1&&(W.pointerType==="touch"?De(W):Ce(W))}function ne(W){switch(ht(W),C.length){case 0:t.domElement.removeEventListener("pointermove",P),t.domElement.removeEventListener("pointerup",ne),t.dispatchEvent(Gz),r=s.NONE;break;case 1:const T=C[0],B=R[T];bt({pointerId:T,pageX:B.x,pageY:B.y});break}}function ke(W){let T;switch(W.button){case 0:T=t.mouseButtons.LEFT;break;case 1:T=t.mouseButtons.MIDDLE;break;case 2:T=t.mouseButtons.RIGHT;break;default:T=-1}switch(T){case tu.DOLLY:if(t.enableZoom===!1)return;Ae(W),r=s.DOLLY;break;case tu.ROTATE:if(W.ctrlKey||W.metaKey||W.shiftKey){if(t.enablePan===!1)return;Ue(W),r=s.PAN}else{if(t.enableRotate===!1)return;se(W),r=s.ROTATE}break;case tu.PAN:if(W.ctrlKey||W.metaKey||W.shiftKey){if(t.enableRotate===!1)return;se(W),r=s.ROTATE}else{if(t.enablePan===!1)return;Ue(W),r=s.PAN}break;default:r=s.NONE}r!==s.NONE&&t.dispatchEvent(aI)}function Ce(W){switch(r){case s.ROTATE:if(t.enableRotate===!1)return;Qe(W);break;case s.DOLLY:if(t.enableZoom===!1)return;Ke(W);break;case s.PAN:if(t.enablePan===!1)return;ae(W);break}}function Le(W){t.enabled===!1||t.enableZoom===!1||r!==s.NONE||(W.preventDefault(),t.dispatchEvent(aI),Ee(it(W)),t.dispatchEvent(Gz))}function it(W){const T=W.deltaMode,B={clientX:W.clientX,clientY:W.clientY,deltaY:W.deltaY};switch(T){case 1:B.deltaY*=16;break;case 2:B.deltaY*=100;break}return W.ctrlKey&&!I&&(B.deltaY*=10),B}function ze(W){W.key==="Control"&&(I=!0,t.domElement.getRootNode().addEventListener("keyup",Je,{passive:!0,capture:!0}))}function Je(W){W.key==="Control"&&(I=!1,t.domElement.getRootNode().removeEventListener("keyup",Je,{passive:!0,capture:!0}))}function nt(W){t.enabled===!1||t.enablePan===!1||He(W)}function bt(W){switch(we(W),C.length){case 1:switch(t.touches.ONE){case iu.ROTATE:if(t.enableRotate===!1)return;Fe(W),r=s.TOUCH_ROTATE;break;case iu.PAN:if(t.enablePan===!1)return;We(W),r=s.TOUCH_PAN;break;default:r=s.NONE}break;case 2:switch(t.touches.TWO){case iu.DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;Ne(W),r=s.TOUCH_DOLLY_PAN;break;case iu.DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;X(W),r=s.TOUCH_DOLLY_ROTATE;break;default:r=s.NONE}break;default:r=s.NONE}r!==s.NONE&&t.dispatchEvent(aI)}function De(W){switch(we(W),r){case s.TOUCH_ROTATE:if(t.enableRotate===!1)return;Se(W),t.update();break;case s.TOUCH_PAN:if(t.enablePan===!1)return;_e(W),t.update();break;case s.TOUCH_DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;ue(W),t.update();break;case s.TOUCH_DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;dt(W),t.update();break;default:r=s.NONE}}function Ot(W){t.enabled!==!1&&W.preventDefault()}function lt(W){C.push(W.pointerId)}function ht(W){delete R[W.pointerId];for(let T=0;T<C.length;T++)if(C[T]==W.pointerId){C.splice(T,1);return}}function we(W){let T=R[W.pointerId];T===void 0&&(T=new ee,R[W.pointerId]=T),T.set(W.pageX,W.pageY)}function ut(W){const T=W.pointerId===C[0]?C[1]:C[0];return R[T]}t.domElement.addEventListener("contextmenu",Ot),t.domElement.addEventListener("pointerdown",U),t.domElement.addEventListener("pointercancel",ne),t.domElement.addEventListener("wheel",Le,{passive:!1}),t.domElement.getRootNode().addEventListener("keydown",ze,{passive:!0,capture:!0}),this.update()}};class Vz extends ve{constructor(e,t,s,r=128){if(t<=0||s<=0||r<=0)throw new Error("GroundedSkybox height, radius, and resolution must be positive.");const n=new Ta(s,2*r,r);n.scale(1,1,-1);const o=n.getAttribute("position"),a=new w;for(let l=0;l<o.count;++l)if(a.fromBufferAttribute(o,l),a.y<0){const c=-t*3/2,u=a.y<c?-t/a.y:1-a.y*a.y/(3*c*c);a.multiplyScalar(u),a.toArray(o.array,3*l)}o.needsUpdate=!0,super(n,new ri({map:e,depthWrite:!1}))}}const U_=Symbol("cameraController");function wse(i){return i[U_]}function Hz(i,e,t){t?i[U_]=e:i[U_]===e&&(i[U_]=null)}const Wz=Symbol("camera autofit");function Sse(i){return i[Wz]===void 0?!0:i[Wz]!==!1}var Cse=Object.defineProperty,Ese=Object.getOwnPropertyDescriptor,Mse=(i,e,t,s)=>{for(var r=s>1?void 0:s?Ese(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Cse(e,t,r),r};class _v extends Pe{constructor(){super(...arguments),h(this,"constraintActive",!0),h(this,"locked",!1),h(this,"sources",[])}}Mse([x(ye)],_v.prototype,"sources",2);function Tse(i){Eg(i,Hs.ContextCreated)}function Ise(i){Eg(i,ks.Start)}function Xz(i){Eg(i,ks.Update)}function Rse(i){Eg(i,ks.OnBeforeRender)}class id{constructor(){h(this,"bb",null),h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}static sizeOf(){return 12}static createVec3(e,t,s,r){return e.prep(4,12),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(t),e.offset()}}class qz{constructor(){h(this,"bb",null),h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}position(e){return(e||new id).__init(this.bb_pos,this.bb)}rotation(e){return(e||new id).__init(this.bb_pos+12,this.bb)}scale(e){return(e||new id).__init(this.bb_pos+24,this.bb)}static sizeOf(){return 36}static createTransform(e,t,s,r,n,o,a,l,c,u){return e.prep(4,36),e.prep(4,12),e.writeFloat32(u),e.writeFloat32(c),e.writeFloat32(l),e.prep(4,12),e.writeFloat32(a),e.writeFloat32(o),e.writeFloat32(n),e.prep(4,12),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(t),e.offset()}}class kc{constructor(){h(this,"bb",null),h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsSyncedTransformModel(e,t){return(t||new kc).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSyncedTransformModel(e,t){return e.setPosition(e.position()+PE),(t||new kc).__init(e.readInt32(e.position())+e.position(),e)}guid(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}fast(){const e=this.bb.__offset(this.bb_pos,6);return e?!!this.bb.readInt8(this.bb_pos+e):!1}transform(e){const t=this.bb.__offset(this.bb_pos,8);return t?(e||new qz).__init(this.bb_pos+t,this.bb):null}dontSave(){const e=this.bb.__offset(this.bb_pos,10);return e?!!this.bb.readInt8(this.bb_pos+e):!1}static startSyncedTransformModel(e){e.startObject(4)}static addGuid(e,t){e.addFieldOffset(0,t,0)}static addFast(e,t){e.addFieldInt8(1,+t,0)}static addTransform(e,t){e.addFieldStruct(2,t,0)}static addDontSave(e,t){e.addFieldInt8(3,+t,0)}static endSyncedTransformModel(e){return e.endObject()}static finishSyncedTransformModelBuffer(e,t){e.finish(t)}static finishSizePrefixedSyncedTransformModelBuffer(e,t){e.finish(t,void 0,!0)}}var sr=(i=>(i[i.Average=0]="Average",i[i.Multiply=1]="Multiply",i[i.Minimum=2]="Minimum",i[i.Maximum=3]="Maximum",i))(sr||{}),F_=(i=>(i[i.Discrete=0]="Discrete",i[i.Continuous=1]="Continuous",i))(F_||{}),Es=(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))(Es||{}),Af=(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))(Af||{});const Sr=function(i,e){return function(t,s,r){Pse(t,s,r,i,e)}};function Pse(i,e,t,s,r){if(!r&&!s&&!i.onValidate)return;if(t!==void 0){console.error("Invalid usage of validate decorator. Only fields can be validated.",i,e,t),ms("Invalid usage of validate decorator. Only fields can be validated. Property: "+e,Eo.Error);return}let n="";if(typeof e=="string"?n=e:n=e.name,i.__internalAwake){const o=Symbol(n),a=i.__internalAwake;i.__internalAwake=function(){var l;if(!this.onValidate){wt()&&console.warn('Usage of @validate decorate detected but there is no onValidate method in your class: "'+((l=i.constructor)==null?void 0:l.name)+'"');return}if(this[o]===void 0){this[o]=this[n];const c=this[n];if(c instanceof ee||c instanceof w||c instanceof tt||c instanceof Ie){const u=this[n];H0(u,()=>{this.onValidate(n)})}Object.defineProperty(this,n,{set:function(u){var d;if(this[uE]===!0)this[o]=u;else{s?.call(this,u);const p=this[o];this[o]=u,(d=this.onValidate)==null||d.call(this,n,p)}},get:function(){return r?.call(this),this[o]}})}a.call(this)}}}const Bse=function(i){return function(e,t,s){let r="";typeof t=="string"?r=t:r=t.name;const n=i.prototype,o=Object.getOwnPropertyDescriptor(n,r);if(!(o!=null&&o.value)){console.warn("Can not apply prefix: type does not have method named",t,i);return}const a=o.value,l=e[r];Object.defineProperty(n,r,{value:function(...c){const u=l?.call(this,...c);if(u instanceof Promise){u.then(d=>{if(d!==!1)return a.call(this,...c)});return}if(u!==!1)return a.call(this,...c)}})}};var Dse=Object.defineProperty,kse=Object.getOwnPropertyDescriptor,No=(i,e,t,s)=>{for(var r=s>1?void 0:s?kse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Dse(e,t,r),r};class Ose{constructor(e,t){h(this,"positionChanged",!1),h(this,"rotationChanged",!1),h(this,"position"),h(this,"quaternion"),h(this,"_positionKeys",["x","y","z"]),h(this,"_quaternionKeys",["_x","_y","_z","_w"]),h(this,"mute",!1),h(this,"context"),h(this,"obj"),h(this,"_positionWatch"),h(this,"_rotationWatch"),this.context=t,this.obj=e}get isDirty(){return this.positionChanged||this.rotationChanged}reset(e=!1){if(this.positionChanged=!1,this.rotationChanged=!1,this.mute=!1,e){if(this.position)for(const t of this._positionKeys)delete this.position[t];if(this.quaternion)for(const t of this._quaternionKeys)delete this.quaternion[t]}}syncValues(){for(const e of this._positionKeys)this.position[e]=this.obj.position[e];for(const e of this._quaternionKeys)this.quaternion[e]=this.obj.quaternion[e]}applyValues(){if(this.positionChanged&&this.position)for(const e of this._positionKeys){const t=this.position[e];t!==void 0&&(this.obj.position[e]=t)}if(this.rotationChanged&&this.quaternion)for(const e of this._quaternionKeys){const t=this.quaternion[e];t!==void 0&&(this.obj.quaternion[e]=t)}}start(e,t){this.reset(),e&&(this._positionWatch||(this._positionWatch=new Bc(this.obj.position,["x","y","z"])),this._positionWatch.apply(),this.position={},this._positionWatch.subscribeWrite((n,o)=>{var a;if((a=this.context.physics.engine)!=null&&a.isUpdating||this.mute)return;const l=this.position[o];Math.abs(l-n)<1e-5||(this.position[o]=n,this.positionChanged=!0)})),t&&(this._rotationWatch||(this._rotationWatch=new Bc(this.obj.quaternion,["_x","_y","_z","_w"])),this._rotationWatch.apply(),this.quaternion={},this._rotationWatch.subscribeWrite((n,o)=>{var a;if((a=this.context.physics.engine)!=null&&a.isUpdating||this.mute)return;const l=this.quaternion[o];Math.abs(l-n)<1e-5||(this.quaternion[o]=n,this.rotationChanged=!0)}));const s=this.obj.matrixWorld.multiplyMatrices.bind(this.obj.matrixWorld),r=new Te;this.obj.matrixWorld.multiplyMatrices=(n,o)=>{var a;return(a=this.context.physics.engine)!=null&&a.isUpdating||this.mute||r.equals(n)||(this.positionChanged=!0,this.rotationChanged=!0,r.copy(n)),s(n,o)}}stop(){var e,t;(e=this._positionWatch)==null||e.revoke(),(t=this._rotationWatch)==null||t.revoke()}}var lI;const cI=(lI=class extends Pe{constructor(){super(...arguments),h(this,"autoMass",!0),h(this,"_mass",0),h(this,"useGravity",!0),h(this,"constraints",Es.None),h(this,"isKinematic",!1),h(this,"drag",0),h(this,"angularDrag",1),h(this,"detectCollisions",!0),h(this,"sleepThreshold",.01),h(this,"collisionDetectionMode",F_.Discrete),h(this,"_gravityScale",1),h(this,"dominanceGroup",0),h(this,"_propertiesChanged",!1),h(this,"_currentVelocity",new w),h(this,"_smoothedVelocity",new w),h(this,"_smoothedVelocityGetter",new w),h(this,"_lastPosition",new w),h(this,"_watch")}set mass(i){i!==this._mass&&(this._mass=i,this._propertiesChanged=!0,this.__didAwake&&(this.autoMass=!1))}get mass(){var i,e;return this.autoMass?((e=(i=this.context.physics.engine)==null?void 0:i.getBody(this))==null?void 0:e.mass())??-1:this._mass}get lockPositionX(){return(this.constraints&Es.FreezePositionX)!==0}get lockPositionY(){return(this.constraints&Es.FreezePositionY)!==0}get lockPositionZ(){return(this.constraints&Es.FreezePositionZ)!==0}get lockRotationX(){return(this.constraints&Es.FreezeRotationX)!==0}get lockRotationY(){return(this.constraints&Es.FreezeRotationY)!==0}get lockRotationZ(){return(this.constraints&Es.FreezeRotationZ)!==0}set lockPositionX(i){i?this.constraints|=Es.FreezePositionX:this.constraints&=~Es.FreezePositionX}set lockPositionY(i){i?this.constraints|=Es.FreezePositionY:this.constraints&=~Es.FreezePositionY}set lockPositionZ(i){i?this.constraints|=Es.FreezePositionZ:this.constraints&=~Es.FreezePositionZ}set lockRotationX(i){i?this.constraints|=Es.FreezeRotationX:this.constraints&=~Es.FreezeRotationX}set lockRotationY(i){i?this.constraints|=Es.FreezeRotationY:this.constraints&=~Es.FreezeRotationY}set lockRotationZ(i){i?this.constraints|=Es.FreezeRotationZ:this.constraints&=~Es.FreezeRotationZ}set gravityScale(i){this._gravityScale=i}get gravityScale(){return this._gravityScale}awake(){this._watch=void 0,this._propertiesChanged=!1}onEnable(){this._watch||(this._watch=new Ose(this.gameObject,this.context)),this._watch.start(!0,!0),this.startCoroutine(this.beforePhysics(),ks.LateUpdate)}onDisable(){var i,e;(i=this._watch)==null||i.stop(),(e=this.context.physics.engine)==null||e.removeBody(this)}onDestroy(){var i;(i=this.context.physics.engine)==null||i.removeBody(this)}onValidate(){this._propertiesChanged=!0}*beforePhysics(){for(var i,e,t,s;;)this._propertiesChanged&&(this._propertiesChanged=!1,(i=this.context.physics.engine)==null||i.updateProperties(this)),(e=this._watch)!=null&&e.isDirty?(this._watch.mute=!0,this._watch.applyValues(),(t=this.context.physics.engine)==null||t.updateBody(this,this._watch.positionChanged,this._watch.rotationChanged),this._watch.reset()):(s=this._watch)==null||s.syncValues(),this.captureVelocity(),yield}teleport(i,e=!0){var t;(t=this._watch)==null||t.reset(!0),e?this.gameObject.position.set(i.x,i.y,i.z):this.setWorldPosition(i.x,i.y,i.z),this.resetForcesAndTorques(),this.resetVelocities()}resetForces(i=!0){var e;(e=this.context.physics.engine)==null||e.resetForces(this,i)}resetTorques(i=!0){var e;(e=this.context.physics.engine)==null||e.resetTorques(this,i)}resetVelocities(){this.setVelocity(0,0,0),this.setAngularVelocity(0,0,0)}resetForcesAndTorques(){this.resetForces(),this.resetTorques()}wakeUp(){var i;(i=this.context.physics.engine)==null||i.wakeup(this)}get isSleeping(){var i;return(i=this.context.physics.engine)==null?void 0:i.isSleeping(this)}updateProperties(){var i;return this._propertiesChanged=!1,(i=this.context.physics.engine)==null?void 0:i.updateProperties(this)}applyForce(i,e,t=!0){var s;this._propertiesChanged&&this.updateProperties(),(s=this.context.physics.engine)==null||s.addForce(this,i,t)}applyImpulse(i,e=!0){var t;this._propertiesChanged&&this.updateProperties(),(t=this.context.physics.engine)==null||t.applyImpulse(this,i,e)}setForce(i,e,t,s=!0){var r,n,o;(r=this.context.physics.engine)==null||r.resetForces(this,s),typeof i=="number"?(e??(e=0),t??(t=0),(n=this.context.physics.engine)==null||n.addForce(this,{x:i,y:e,z:t},s)):(o=this.context.physics.engine)==null||o.addForce(this,i,s)}getVelocity(){var i;const e=(i=this.context.physics.engine)==null?void 0:i.getLinearVelocity(this);return e?(this._currentVelocity.x=e.x,this._currentVelocity.y=e.y,this._currentVelocity.z=e.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setVelocity(i,e,t,s=!0){var r,n;if(i instanceof w){const o=i;(r=this.context.physics.engine)==null||r.setLinearVelocity(this,o,s);return}e===void 0||t===void 0||(n=this.context.physics.engine)==null||n.setLinearVelocity(this,{x:i,y:e,z:t},s)}getAngularVelocity(){var i;const e=(i=this.context.physics.engine)==null?void 0:i.getAngularVelocity(this);return e?(this._currentVelocity.x=e.x,this._currentVelocity.y=e.y,this._currentVelocity.z=e.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setAngularVelocity(i,e,t,s=!0){var r,n;if(i instanceof w){const o=i;(r=this.context.physics.engine)==null||r.setAngularVelocity(this,o,s);return}e===void 0||t===void 0||(n=this.context.physics.engine)==null||n.setAngularVelocity(this,{x:i,y:e,z:t},s)}setTorque(i,e,t){this.setAngularVelocity(i,e,t)}get smoothedVelocity(){return this._smoothedVelocityGetter.copy(this._smoothedVelocity),this._smoothedVelocityGetter.multiplyScalar(1/this.context.time.deltaTime)}setBodyFromGameObject(i=null){}captureVelocity(){const i=Rt(this.gameObject);cI.tempPosition.copy(i);const e=i.sub(this._lastPosition);this._lastPosition.copy(cI.tempPosition),this._smoothedVelocity.lerp(e,this.context.time.deltaTime/.1)}},h(lI,"tempPosition",new w),lI);let Ni=cI;No([Sr()],Ni.prototype,"autoMass",2),No([x()],Ni.prototype,"mass",1),No([Sr(),x()],Ni.prototype,"useGravity",2),No([Sr(),x()],Ni.prototype,"constraints",2),No([Sr(),x()],Ni.prototype,"isKinematic",2),No([Sr(),x()],Ni.prototype,"drag",2),No([Sr(),x()],Ni.prototype,"angularDrag",2),No([Sr(),x()],Ni.prototype,"detectCollisions",2),No([Sr(),x()],Ni.prototype,"sleepThreshold",2),No([Sr(),x()],Ni.prototype,"collisionDetectionMode",2),No([Sr()],Ni.prototype,"_gravityScale",2),No([Sr()],Ni.prototype,"dominanceGroup",2);const pc=te("debugsync"),xv="STRS";kE(xv,kc.getRootAsSyncedTransformModel);const $a=new ey;function Yz(i,e,t=!0){$a.clear();const s=$a.createString(i);kc.startSyncedTransformModel($a),kc.addGuid($a,s),kc.addFast($a,t);const r=e.worldPosition,n=e.worldEuler,o=e.gameObject.scale;kc.addTransform($a,qz.createTransform($a,r.x,r.y,r.z,n.x,n.y,n.z,o.x,o.y,o.z));const a=kc.endSyncedTransformModel($a);return $a.finish(a,xv),$a.asUint8Array()}let hI=0,wv=0;Xz(i=>{var e;const t=(e=i.connection.currentServerUrl)!=null&&e.includes("glitch")?10:40;wv=Math.floor(hI/t),hI=0,pc&&wv>0&&console.log("Sync Transform Fast Interval",wv)});class Eh extends Pe{constructor(){super(...arguments),h(this,"overridePhysics",!0),h(this,"interpolatePosition",!0),h(this,"interpolateRotation",!0),h(this,"fastMode",!1),h(this,"syncDestroy",!1),h(this,"_model",null),h(this,"_needsUpdate",!0),h(this,"rb",null),h(this,"_wasKinematic",!1),h(this,"_receivedDataBefore",!1),h(this,"_targetPosition"),h(this,"_targetRotation"),h(this,"_receivedFastUpdate",!1),h(this,"_shouldRequestOwnership",!1),h(this,"joinedRoomCallback",null),h(this,"receivedDataCallback",null),h(this,"tempEuler",new Ur),h(this,"receivedUpdate",!1),h(this,"lastWorldPos"),h(this,"lastWorldRotation")}requestOwnership(){pc&&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(){pc&&console.log("new instance",this.guid,this),this._receivedDataBefore=!1,this._targetPosition=new w,this._targetRotation=new Ie,this.lastWorldPos=new w,this.lastWorldRotation=new Ie,this.rb=oe.getComponentInChildren(this.gameObject,Ni),this.rb&&(this._wasKinematic=this.rb.isKinematic),this.receivedUpdate=!0,this._model=new ZE(this.context.connection,this.guid),this.context.connection.isConnected&&this.tryGetLastState(),this.joinedRoomCallback=this.tryGetLastState.bind(this),this.context.connection.beginListen(di.JoinedRoom,this.joinedRoomCallback),this.receivedDataCallback=this.onReceivedData.bind(this),this.context.connection.beginListenBinary(xv,this.receivedDataCallback)}onDestroy(){this.syncDestroy&&r3(this.guid,this.context.connection),this._model=null,this.context.connection.stopListen(di.JoinedRoom,this.joinedRoomCallback),this.context.connection.stopListenBinary(xv,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){pc&&console.log("new data",this.context.connection.connectionId,this.context.time.frameCount,this.guid,e),this.receivedUpdate=!0,this._receivedFastUpdate=e.fast();const s=e.transform();if(s){Pa.markDirty(this.gameObject,!0);const r=s.position();r&&(this.interpolatePosition&&((t=this._targetPosition)==null||t.set(r.x(),r.y(),r.z())),(!this.interpolatePosition||!this._receivedDataBefore)&&this.setWorldPosition(r.x(),r.y(),r.z()));const n=s.rotation();n&&(this.tempEuler.set(n.x(),n.y(),n.z()),this.interpolateRotation&&this._targetRotation.setFromEuler(this.tempEuler),(!this.interpolateRotation||!this._receivedDataBefore)&&JM(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){pc&&console.log("no model or room",this.name,this.guid,this.context.connection.isInRoom);return}this._shouldRequestOwnership&&(this._shouldRequestOwnership=!1,this._model.requestOwnership());const e=this.worldPosition,t=this.worldQuaternion;if(this._model.isOwned&&!this.receivedUpdate){const n=e.distanceTo(this.lastWorldPos),o=t.angleTo(this.lastWorldRotation),a=this._model.hasOwnership||this.fastMode?1e-4:.001;(n>a||o>a)&&(this._model.hasOwnership?this._needsUpdate=!0:(pc&&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),Pa.markDirty(this.gameObject,!0),this._needsUpdate=!1))}if(this._model&&!this._model.hasOwnership&&this._model.isOwned&&this._receivedDataBefore){const n=this._receivedFastUpdate||this.fastMode?.5:.3;let o=!1;if(this.interpolatePosition&&this._targetPosition){const a=this.worldPosition;a.lerp(this._targetPosition,n),this.worldPosition=a,o=!0}if(this.interpolateRotation&&this._targetRotation){const a=this.worldQuaternion;a.slerp(this._targetRotation,n),this.worldQuaternion=a,o=!0}o&&Pa.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&&(pc&&console.log("reset kinematic",this.rb.name,this._wasKinematic),this.rb.isKinematic=this._wasKinematic),this.gameObject.position.distanceTo(new w(0,0,0))>1e3&&(pc&&console.log("RESET",this.name),this.gameObject.position.set(0,1,0),this.rb.setVelocity(0,0,0)));const s=10,r=this.rb||this.fastMode;if(this._needsUpdate&&(this.context.time.frameCount%s===0||r)){if(hI++,r&&wv>0&&this.context.time.frameCount%wv!==0)return;pc&&console.log("send update",this.context.connection.connectionId,this.guid,this.gameObject.name,this.gameObject.guid),this.overridePhysics&&this.rb,this._needsUpdate=!1;const n=Yz(this.guid,this,!!r);this.context.connection.sendBinary(n)}}}const Lse=te("debugshadowcomponents");jM.prototype.interactable={get(){return this.interactive},set(i){this.interactable=i}};const zo=Symbol("shadowDomOwner");class Ra extends Pe{constructor(){super(...arguments),h(this,"_shadowComponent",null),h(this,"_controlsChildLayout",!0),h(this,"_root"),h(this,"_parentComponent")}isRoot(){var e;return((e=this.Root)==null?void 0:e.gameObject)===this.gameObject}get canvas(){const e=this.Root;return e!=null&&e.isCanvas?e:null}get Canvas(){return this.canvas}markDirty(){jo.markUIDirty(this.context)}get shadowComponent(){return this._shadowComponent}set shadowComponent(e){this._shadowComponent=e}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(e){this._controlsChildLayout=e,this.shadowComponent&&(this.shadowComponent.autoLayout=e)}get Root(){return this._root===void 0&&(this._root=oe.getComponentInParent(this.gameObject,Sv)),this._root}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this.shadowComponent=null,this._root=void 0,this._parentComponent=void 0}onEnable(){super.onEnable()}addShadowComponent(e,t){var s;this.removeShadowComponent();const r=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=oe.getComponentInParent(r,Ra),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}e.name=this.name+" ("+(this.constructor.name??"UI")+")",e.autoLayout=this._parentComponent.controlsChildLayout,e[zo]=this,this.setShadowComponentOwner(e);let n=!1;if(((s=this.Root)==null?void 0:s.gameObject)===this.gameObject)this.gameObject.add(e);else{const o=this._parentComponent.shadowComponent;o&&(o?.add(e),n=!0)}this.shadowComponent=e,t&&t.shadowComponent&&this.shadowComponent&&t.shadowComponent.add(this.shadowComponent),xg&&e.add(new wo(.5)),this.onAfterAddedToScene(),n&&SN(),Lse&&console.log(this.shadowComponent)}setShadowComponentOwner(e){if(e&&(e[zo]===void 0||e[zo]===this)&&(e[zo]=this,e.children))for(const t of e.children)this.setShadowComponentOwner(t)}traverseOwnedShadowComponents(e,t,s){if(e&&e[zo]===t){s(e);for(const r of e.children)this.traverseOwnedShadowComponents(r,t,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(e){this.shadowComponent&&(this.shadowComponent.interactable=e)}}class Sv extends Ra{awake(){super.awake()}}class cm{constructor(e,t){h(this,"event"),h(this,"button"),h(this,"buttonName"),h(this,"_used",!1),h(this,"_propagationStopped",!1),h(this,"z__pointer_ctured",!1),h(this,"z__pointer_cture_rleased",!1),h(this,"inputSource"),h(this,"object"),h(this,"point"),h(this,"normal"),h(this,"face"),h(this,"distance"),h(this,"instanceId"),h(this,"isDown"),h(this,"isUp"),h(this,"isPressed"),h(this,"isClick"),h(this,"isDoubleClick"),h(this,"input"),this.event=t,this.input=e,this.button=t.button}get deviceIndex(){return this.event.deviceIndex}get pointerId(){return this.event.pointerId}get pressure(){return this.event.pressure}get used(){return this._used}use(){this._used||(this._used=!0,this.pointerId!==void 0&&this.input.setPointerUsed(this.pointerId))}get propagationStopped(){return this._propagationStopped}stopPropagation(){this._propagationStopped=!0,this.event.stopImmediatePropagation()}stopImmediatePropagation(){this._propagationStopped=!0,this.event.stopImmediatePropagation()}setPointerCapture(){this.z__pointer_ctured=!0}releasePointerCapture(){this.z__pointer_cture_rleased=!0}get mode(){return this.event.mode}clone(){const e=new cm(this.input,this.event);return Object.assign(e,this),e}Use(){this.use()}StopPropagation(){this.event.stopImmediatePropagation()}}function uI(i,e){return oe.foreachComponent(i,t=>{if(!t.enabled)return;const s=t;if(e)switch(e){case"pointerdown":if(s.onPointerDown)return!0;break;case"pointerup":if(s.onPointerUp||s.onPointerClick)return!0;break;case"pointermove":if(s.onPointerEnter||s.onPointerExit||s.onPointerMove)return!0;break}else if(s.onPointerDown||s.onPointerUp||s.onPointerEnter||s.onPointerExit||s.onPointerClick)return!0},!1)===!0}var Use=Object.defineProperty,Fse=Object.getOwnPropertyDescriptor,Nse=(i,e,t,s)=>{for(var r=s>1?void 0:s?Fse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Use(e,t,r),r};class Cv extends Pe{awake(){jo.createIfNoneExists(this.context)}onEnable(){var e;(e=jo.get(this.context))==null||e.register(this)}onDisable(){var e;(e=jo.get(this.context))==null||e.unregister(this)}}class to extends Cv{constructor(){super(...arguments),h(this,"targets",null),h(this,"raycastHits",[]),h(this,"ignoreSkinnedMeshes",!1)}start(){this.targets=[this.gameObject]}performRaycast(e=null){if(!this.targets)return null;e??(e=new Oo),e.targets=this.targets,e.results=this.raycastHits;const t=e.testObject;this.ignoreSkinnedMeshes&&(e.testObject=r=>r instanceof oa?"continue in children":t?t(r):!0);const s=this.context.physics.raycast(e);return e.testObject=t,s}}Nse([x()],to.prototype,"ignoreSkinnedMeshes",2);class N_ extends to{constructor(){super(),this.ignoreSkinnedMeshes=!0}}class Ev extends Cv{performRaycast(e){if(!vt.active||!(e!=null&&e.ray))return null;const t=e.ray.origin,s=.01;return this.context.physics.sphereOverlap(t,s)}}class z_{static getObject(e){const t=e[zo];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const s=this.tryFindCanvasGroup(e);if(s?.isCanvasGroup===!0&&(t&&(t.canvasGroup=s),s.blocksRaycasts===!1||s.interactable===!1))return!1;const r=qu(e,n=>{if(n.isGraphic===!0)return n},!1);return t&&r?.isGraphic===!0&&(t.graphic=r),!(r?.raycastTarget===!1||r?.layer===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=qu(e,s=>{const r=s;if(r.blocksRaycasts!==void 0&&r.interactable!==void 0)return r},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}function dI(i){return i[zo]||(i.parent?dI(i.parent):null)}function zse(i){return i.isUI===!0||typeof i[zo]=="object"}function j_(i,e){if(!i)return;const t=i.material;if(t?.isMaterial===!0){const s=i.parent;s&&s.isText,t.side=e.doubleSided??!0?fi:ur,t.shadowSide=e.doubleSided?fi:ur,i.castShadow=e.castShadows?e.castShadows:!1,i.receiveShadow=e.receiveShadows?e.receiveShadows:!1}for(const s of i.children)j_(s,e)}function yf(i,e,t){i[e]===void 0&&console.warn("Field",e,"is undefined on",i);const s=Proxy.revocable(i[e],{set(o,a,l,c){const u=o[a],d=Reflect.set(o,a,l,c);return t(l,u),d}}),r=s.revoke,n=i[e];return s.revoke=()=>{i[e]=n,r()},i[e]=s.proxy,s}const Jz=Symbol("Scheduled action");function jse(i,e,t=ks.OnBeforeRender){let s=i[Jz];s||(s=i[Jz]={});const r=e.name;s[t]||(s[t]={});const n=s[t];if(n[r])return;function*o(){e?.call(i),n[r]=null}const a=i.startCoroutine(o(),t);n[r]=a}const fc=te("debugeventsystem");var pI=(i=>(i.BeforeHandleInput="BeforeHandleInput",i.AfterHandleInput="AfterHandleInput",i))(pI||{});const mc=class extends Pe{constructor(){super(),h(this,"raycaster",[]),h(this,"_handleInputFn"),h(this,"pressedByID",new Map),h(this,"hoveredByID",new Map),h(this,"_sortedHits",[]),h(this,"_testObjectsCache",new Map),h(this,"_currentlyActiveRaycaster",null),h(this,"_currentPointerEventName",null),h(this,"shouldRaycastObject",i=>{var e;let t=null;if(zse(i)&&(t=(e=i[zo])==null?void 0:e.gameObject),this._testObjectsCache.has(i)||t&&this._testObjectsCache.has(t))return this._testObjectsCache.get(i)===!1?"continue in children":!0;{let s=uI(i,this._currentPointerEventName);if(!s&&t&&(s=uI(t,this._currentPointerEventName)),s){this._testObjectsCache.set(i,!0);for(const r of i.children)this.shouldRaycastObject_AddToYesCache(r);return!0}return this._testObjectsCache.set(i,!1),"continue in children"}}),h(this,"_sortingBuffer",[]),h(this,"_noDepthTestingResults",[]),h(this,"out",{}),h(this,"_capturedPointer",{}),h(this,"pointerEnterSymbol",Symbol("pointerEnter")),h(this,"pointerExitSymbol",Symbol("pointerExit")),h(this,"currentActiveMeshUIComponents",[]),mc.systems.push(this)}static createIfNoneExists(i){this.didSearchEventSystem||(this.didSearchEventSystem=!0,mc.systems.length<=0&&mc.systems.push(...oe.findObjectsOfType(mc,i)));for(const t of mc.systems)if(t.context===i)return;const e=new ye;oe.addNewComponent(e,mc),i.scene.add(e)}static get systems(){const i=kt.Current;return this._eventSystemMap.has(i)||this._eventSystemMap.set(i,[]),this._eventSystemMap.get(i)}static get(i){const e=this._eventSystemMap.get(i);return e&&e.length>0?e[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(i,e,t=!1){Mh.update(i,e,t)}static markUIDirty(i){Mh.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.hoveredByID.size>0}onDestroy(){mc.systems.splice(mc.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!oe.findObjectOfType(Cv,this.context)){const i=oe.addNewComponent(this.context.scene,to);this.raycaster.push(i),(wt()||fc)&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found.")}}register(i){var e;i&&this.raycaster&&!this.raycaster.includes(i)&&((e=this.raycaster)==null||e.push(i))}unregister(i){var e,t;const s=(e=this.raycaster)==null?void 0:e.indexOf(i);s!==void 0&&s!==-1&&((t=this.raycaster)==null||t.splice(s,1))}onEnable(){this._handleInputFn??(this._handleInputFn=this.onPointerEvent.bind(this)),this.context.input.addEventListener(Xi.PointerDown,this._handleInputFn),this.context.input.addEventListener(Xi.PointerUp,this._handleInputFn),this.context.input.addEventListener(Xi.PointerMove,this._handleInputFn)}onDisable(){this.context.input.removeEventListener(Xi.PointerDown,this._handleInputFn),this.context.input.removeEventListener(Xi.PointerUp,this._handleInputFn),this.context.input.removeEventListener(Xi.PointerMove,this._handleInputFn)}onBeforeRender(){this.resetMeshUIStates()}onPointerEvent(i){if(i===void 0||i.propagationStopped)return;const e=new cm(this.context.input,i);this._currentPointerEventName=i.type,e.inputSource=this.context.input,e.isClick=i.isClick,e.isDoubleClick=i.isDoubleClick,e.isDown=i.type==Xi.PointerDown,e.isUp=i.type==Xi.PointerUp,e.isPressed=this.context.input.getPointerPressed(i.pointerId),fc&&(e.isDown?console.log("DOWN",e.pointerId):e.isUp&&console.log("UP",e.pointerId),e.isClick&&console.log("CLICK",e.pointerId));const t=new Oo;i.ray?t.ray=i.ray:t.screenPoint=this.context.input.getPointerPositionRC(i.pointerId);const s=this.performRaycast(t);fc&&e.isClick&&ms("EventSystem: "+e.pointerId+" - "+this.context.time.frame+" - Up:"+e.isUp+", Down:"+e.isDown);const r={sender:this,args:e,hasActiveUI:this.currentActiveMeshUIComponents.length>0};this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:r})),this.handleIntersections(s,e),this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:r}))}shouldRaycastObject_AddToYesCache(i){this._testObjectsCache.set(i,!0);for(const e of i.children)this.shouldRaycastObject_AddToYesCache(e)}performRaycast(i){if(!this.raycaster)return null;this._testObjectsCache.clear(),this._sortedHits.length=0,i||(i=new Oo),i.testObject=this.shouldRaycastObject;for(const e of this.raycaster){if(!e.activeAndEnabled)continue;this._currentlyActiveRaycaster=e;const t=e.performRaycast(i);this._currentlyActiveRaycaster=null,t&&t.length>0&&this._sortedHits.push(...t)}return this._sortedHits.sort((e,t)=>e.distance-t.distance),this._sortedHits}assignHitInformation(i,e){e?(i.point=e.point,i.normal=e.normal,i.face=e.face,i.distance=e.distance,i.instanceId=e.instanceId):(i.point=void 0,i.normal=void 0,i.face=void 0,i.distance=void 0,i.instanceId=void 0)}handleIntersections(i,e){var t;if(i!=null&&i.length){i=this.sortCandidates(i);for(const r of i){if(e.event.immediatePropagationStopped)return!1;if(this.assignHitInformation(e,r),this.handleEventOnObject(r.object,e))return!0}}this.assignHitInformation(e,i?.[0]),this.invokePointerCapture(e);const s=this.hoveredByID.get(e.pointerId);return s&&this.propagatePointerExit(s.obj,s.data,null),this.hoveredByID.delete(e.pointerId),e.isUp&&((t=this.pressedByID.get(e.pointerId))==null||t.handlers.forEach(r=>this.invokeOnPointerUp(e,r)),this.pressedByID.delete(e.pointerId)),!1}sortCandidates(i){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let e=0;e<i.length;e++){const t=i[e],s=t.object;if(s.material&&s.material.depthTest===!1){this._noDepthTestingResults.push(t);continue}this._sortingBuffer.push(t)}for(const e of this._sortingBuffer)this._noDepthTestingResults.push(e);return this._noDepthTestingResults}handleEventOnObject(i,e){if(!this.testIsVisible(i))return e.isClick&&fc&&console.log("not allowed",i),!1;if(e.pointerId===void 0)return fc&&console.error("Event without pointer can't be handled",e),!1;e.object=i;const t=i.parent;let s=!1;const r=e.isClick??!1;let n=null;if(t&&t.isUI){const c=(e.isPressed||e.isClick)??!1;if(t[zo]){const u=t[zo].gameObject;if(u){if(!z_.isInteractable(u,this.out))return!1;n=this.out.canvasGroup??null,this.handleMeshUIIntersection(i,c),i=u,s=!0}}if(!s&&this.handleMeshUiObjectWithoutShadowDom(t,c))return!0}r&&fc&&console.log(this.context.time.frame,i);const o=this.hoveredByID.get(e.pointerId),a=o?.obj;a!==i&&a&&this.propagatePointerExit(a,o.data,i);const l=this.hoveredByID.get(e.pointerId);if(l?(l.obj=i,l.data=e):this.hoveredByID.set(e.pointerId,{obj:i,data:e}),e.isDown){const c=this.pressedByID.get(e.pointerId);c?(c.obj=i,c.data=e):this.pressedByID.set(e.pointerId,{obj:i,data:e,handlers:new Set})}return(n===null||n.interactable)&&this.handleMainInteraction(i,e,a??null),!0}propagate(i,e){for(;i;)oe.foreachComponent(i,t=>{e(t)},!1),i=i.parent}handleMainInteraction(i,e,t){const s=this.pressedByID.get(e.pointerId),r=t!==i;let n=!0;switch(e.event.pointerType){case"mouse":case"touch":const o=this.context.input.getPointerPositionLastFrame(e.pointerId),a=this.context.input.getPointerPosition(e.pointerId);n=o&&!st.approximately(o,a);break}this.propagate(i,o=>{const a=o;a.interactable!==!1&&(!a.activeAndEnabled||!a.enabled||(a.onPointerEnter&&r&&this.handlePointerEnter(a,e),e.isDown&&a.onPointerDown&&(a.onPointerDown(e),s?.handlers.add(a),this.handlePointerCapture(e,a)),a.onPointerMove&&(n&&a.onPointerMove(e),this.handlePointerCapture(e,a)),e.isUp&&a.onPointerUp&&(this.invokeOnPointerUp(e,a),s?.handlers.delete(a)),e.isClick&&a.onPointerClick&&a.onPointerClick(e)))}),e.isUp&&(s?.handlers.forEach(o=>{this.invokeOnPointerUp(e,o)}),this.pressedByID.delete(e.pointerId))}propagatePointerExit(i,e,t){this.propagate(i,s=>{if(!s.gameObject||s.destroyed)return;const r=s;if(r.onPointerExit){if(t&&this.isChild(t,s.gameObject))return;this.handlePointerExit(r,e)}})}invokeOnPointerUp(i,e){var t;(t=e.onPointerUp)==null||t.call(e,i),this.releasePointerCapture(i,e)}handlePointerEnter(i,e){i.onPointerEnter&&this.updatePointerState(i,e.pointerId,this.pointerEnterSymbol,!0)&&i.onPointerEnter(e),this.updatePointerState(i,e.pointerId,this.pointerExitSymbol,!1)}handlePointerExit(i,e){i.onPointerExit&&this.updatePointerState(i,e.pointerId,this.pointerExitSymbol,!0)&&i.onPointerExit(e),this.updatePointerState(i,e.pointerId,this.pointerEnterSymbol,!1)}updatePointerState(i,e,t,s){let r=i[t];if(s)return r&&r.includes(e)?!1:(r=r||[],r.push(e),i[t]=r,!0);{if(!r||!r.includes(e))return!1;const n=r.indexOf(e);return n!==-1&&r.splice(n,1),!0}}handlePointerCapture(i,e){if(i.z__pointer_ctured){i.z__pointer_ctured=!1;const t=i.pointerId;if(e.onPointerMove){const s=this._capturedPointer[t]||[];s.push(e),this._capturedPointer[t]=s}else wt()&&!e.z__warned_no_pointermove&&(e.z__warned_no_pointermove=!0,console.warn("PointerCapture was requested but the component doesn't implement onPointerMove. It will not receive any pointer events"))}else i.z__pointer_cture_rleased&&(i.z__pointer_cture_rleased=!1,this.releasePointerCapture(i,e))}releasePointerCapture(i,e){const t=i.pointerId;if(this._capturedPointer[t]){const s=this._capturedPointer[t].indexOf(e);s!==-1&&(this._capturedPointer[t].splice(s,1),fc&&console.log("released pointer capture",t,e,this._capturedPointer))}}invokePointerCapture(i){var e;if(i.event.type===Xi.PointerMove){const t=i.pointerId,s=this._capturedPointer[t];if(s){fc&&console.log("Captured",t,s);for(let r=0;r<s.length;r++){const n=s[r];if(n.destroyed){s.splice(r,1),r--;continue}(e=n.onPointerMove)==null||e.call(n,i)}}}}isChild(i,e){return!i||!e?!1:i===e?!0:i.parent?this.isChild(i.parent,e):!1}handleMeshUiObjectWithoutShadowDom(i,e){return!i||!i.isUI?!0:this.handleMeshUIIntersection(i,e)}handleMeshUIIntersection(i,e){const t=Mh.updateState(i,e);return t&&this.currentActiveMeshUIComponents.push(t),t!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&Mh.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let i=0;i<this.currentActiveMeshUIComponents.length;i++){const e=this.currentActiveMeshUIComponents[i];Mh.resetState(e)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(i){return i?oe.isActiveSelf(i)?this.testIsVisible(i.parent):!1:!0}};let jo=mc;h(jo,"_eventSystemMap",new Map),h(jo,"didSearchEventSystem",!1);class Mh{static markDirty(){this.needsUpdate=!0}static update(e,t,s=!1){if(s){e.update();return}const r=t.time.frameCount;for(const n of this.lastUpdateFrame)if(n.context===t){if(r===n.frame)return;n.frame=r;let o=this.needsUpdate||r<1;n.nextUpdate===t.time.frameCount&&(o=!0),o&&(fc&&console.log("Update threemeshui"),this.needsUpdate=!1,e.update());return}this.lastUpdateFrame=[{context:t,frame:r,nextUpdate:r}],e.update()}static updateState(e,t){let s=null;if(e&&(s=this.findBlockInParent(e),s&&s!==this.lastSelected)){if(s.interactable===!1)return null;this.needsUpdate=!0}return s}static resetLastSelected(){const e=this.lastSelected;e&&(this.lastSelected=null,this.resetState(e))}static resetState(e){e&&(this.needsUpdate=!0)}static findBlockInParent(e){return e?e.isBlock?e:this.findBlockInParent(e.parent):null}}h(Mh,"lastSelected",null),h(Mh,"lastUpdateFrame",[]),h(Mh,"needsUpdate",!1);var Gse=Object.defineProperty,Qse=Object.getOwnPropertyDescriptor,Cr=(i,e,t,s)=>{for(var r=s>1?void 0:s?Qse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Gse(e,t,r),r};const Vse=te("debugorbit"),G_=te("freecam"),Mv=te("debugcamerafit"),Q_=te("smoothcam"),Hse={LEFT:"",UP:"",RIGHT:"",BOTTOM:""};let fI;class Tv extends CustomEvent{constructor(e,t){super("target-reached",{detail:{controls:e,type:t}})}}class zi extends Pe{constructor(){super(...arguments),h(this,"autoFit",!1),h(this,"enableRotate",!0),h(this,"autoRotate",!1),h(this,"autoRotateSpeed",1),h(this,"enableKeys",!0),h(this,"enableDamping",!0),h(this,"dampingFactor",.1),h(this,"enableZoom",!0),h(this,"minZoom",0),h(this,"maxZoom",1/0),h(this,"enablePan",!0),h(this,"lookAtConstraint",null),h(this,"lookAtConstraint01",1),h(this,"allowInterrupt",!0),h(this,"middleClickToFocus",!0),h(this,"doubleClickToFocus",!0),h(this,"useSlerp",!0),h(this,"debugLog",!1),h(this,"targetLerpDuration",1),h(this,"autoTarget",!0),h(this,"_controls",null),h(this,"_cameraObject",null),h(this,"_lookTargetLerpActive",!1),h(this,"_lookTargetStartPosition",new w),h(this,"_lookTargetEndPosition",new w),h(this,"_lookTargetLerp01",0),h(this,"_lookTargetLerpDuration",0),h(this,"_cameraLerpActive",!1),h(this,"_cameraStartPosition",new w),h(this,"_cameraEndPosition",new w),h(this,"_cameraLerp01",0),h(this,"_cameraLerpDuration",0),h(this,"_inputs",0),h(this,"_enableTime",0),h(this,"_startedListeningToKeyEvents",!1),h(this,"_eventSystem"),h(this,"_afterHandleInputFn"),h(this,"_camera",null),h(this,"_syncedTransform"),h(this,"_didStart",!1),h(this,"targetElement",null),h(this,"onControlsChangeStarted",()=>{this._syncedTransform&&this._syncedTransform.requestOwnership()}),h(this,"_shouldDisable",!1),h(this,"_haveAttachedKeyboardEvents",!1)}get isCameraController(){return!0}get controls(){return this._controls}get controllerObject(){return this._cameraObject}onStartInteraction(e){var t;(t=this.controls)==null||t.addEventListener("start",e)}get targetLerpSpeed(){return 5}set targetLerpSpeed(e){this.targetLerpDuration=1/e}awake(){this._didStart=!1,this._startedListeningToKeyEvents=!1}start(){if(this._didStart=!0,this.autoTarget&&this._controls){const e=oe.getComponent(this.gameObject,ji);if(e&&!this.setLookTargetFromConstraint()){this.debugLog&&console.log("NO TARGET");const t=Rt(e.cam).length(),s=new w(0,0,-t).applyMatrix4(e.cam.matrixWorld);this.setLookTargetPosition(s,!0)}if(this.autoTarget&&!this.setLookTargetFromConstraint()){const t=new Oo;t.screenPoint=new ee(0,0),t.lineThreshold=.1;const s=this.context.physics.raycast(t);s.length>0&&this.setLookTargetPosition(s[0].point,!0),Mv&&console.log("OrbitControls hits",...s)}this.autoFit&&this.fitCamera()}this._eventSystem=jo.get(this.context)??void 0,this._eventSystem&&(this._afterHandleInputFn=this.afterHandleInput.bind(this),this._eventSystem.addEventListener(pI.AfterHandleInput,this._afterHandleInputFn))}onDestroy(){var e,t;(e=this._controls)==null||e.dispose(),(t=this._eventSystem)==null||t.removeEventListener(pI.AfterHandleInput,this._afterHandleInputFn)}onEnable(){this._enableTime=this.context.time.time;const e=oe.getComponent(this.gameObject,ji);this._camera=e;const t=e?.cam;if(t&&Hz(t,this,!0),!this._controls){if(!t){console.warn("OrbitControls: Requires a Camera component on the same object as this component.");return}t&&(this._cameraObject=t);const s=this.targetElement??this.context.renderer.domElement,r=t?.quaternion.clone();this._controls=new xse(t,s),t?.quaternion.copy(r),fI===void 0&&(fI={...this._controls.keys})}this._controls&&(G_&&(this.enablePan=!0,this.enableZoom=!0,this.middleClickToFocus=!0,ja()&&(this.doubleClickToFocus=!0)),this._controls.addEventListener("start",this.onControlsChangeStarted),t?.type==="PerspectiveCamera"?G_||(this._controls.minDistance=this.minZoom,this._controls.maxDistance=this.maxZoom):G_||(this._controls.minZoom=this.minZoom,this._controls.maxZoom=this.maxZoom),this._startedListeningToKeyEvents||(this._startedListeningToKeyEvents=!0,this._controls.listenToKeyEvents(window.document.body))),this._syncedTransform=oe.getComponent(this.gameObject,Eh)??void 0}onDisable(){var e;(e=this._camera)!=null&&e.cam&&Hz(this._camera.cam,this,!1),this._controls&&(this._controls.enabled=!1,this._controls.autoRotate=!1,this._controls.removeEventListener("start",this.onControlsChangeStarted))}afterHandleInput(e){e.detail.args.pointerId===0&&(e.detail.args.isDown?this._controls&&this._eventSystem&&(this._shouldDisable=this._eventSystem.hasActiveUI):(!e.detail.args.isPressed||e.detail.args.isUp)&&(this._shouldDisable=!1))}onBeforeRender(){var e,t;if(!this._controls||this._cameraObject!==this.context.mainCamera)return;(this.context.input.getPointerDown(1)||this.context.input.getPointerDown(2)||this.context.input.mouseWheelChanged||this.context.input.getPointerPressed(0)&&(e=this.context.input.getPointerPositionDelta(0))!=null&&e.length()||0>.1)&&(this._inputs+=1),this._inputs>0&&this.allowInterrupt&&(this.enableRotate&&(this.autoRotate=!1),this._cameraLerpActive=!1,this._lookTargetLerpActive=!1),this._inputs=0;let s=this.middleClickToFocus&&this.context.input.getPointerClicked(1);if(s||(s=this.doubleClickToFocus&&this.context.input.getPointerDoubleClicked(0)&&this.context.time.time-this._enableTime>.3),s&&this.setTargetFromRaycast(),this._lookTargetLerpActive||this._cameraLerpActive){if(this._cameraLerpActive&&this._cameraObject)if(this._cameraLerp01+=this.context.time.deltaTime/this._cameraLerpDuration,this._cameraLerp01>=1)this._cameraObject.position.copy(this._cameraEndPosition),this._cameraLerpActive=!1,this.dispatchEvent(new Tv(this,"camera"));else{const r=st.easeInOutCubic(this._cameraLerp01);this._cameraObject.position.lerpVectors(this._cameraStartPosition,this._cameraEndPosition,r)}if(this._lookTargetLerpActive)if(this._lookTargetLerp01+=this.context.time.deltaTime/this._lookTargetLerpDuration,this._lookTargetLerp01>=1)this._controls.target.copy(this._lookTargetEndPosition),this._lookTargetLerpActive=!1,this.dispatchEvent(new Tv(this,"lookat"));else{const r=st.easeInOutCubic(this._lookTargetLerp01);this._controls.target.lerpVectors(this._lookTargetStartPosition,this._lookTargetEndPosition,r)}}if(this._controls){if(this.debugLog&&(this._controls.domElement=this.context.renderer.domElement),this._controls.enabled=!this._shouldDisable&&this._camera===this.context.mainCameraComponent&&!this.context.isInXR,this._controls.keys=this.enableKeys?fI:Hse,this._controls.autoRotate=this.autoRotate,this._controls.autoRotateSpeed=this.autoRotateSpeed,this._controls.enableZoom=this.enableZoom,this._controls.enableDamping=this.enableDamping,this._controls.dampingFactor=this.dampingFactor,this._controls.enablePan=this.enablePan,this._controls.enableRotate=this.enableRotate,typeof Q_=="number"||Q_===!0){this._controls.enableDamping=!0;const r=typeof Q_=="number"?Q_:.99;this._controls.dampingFactor=Math.max(.001,1-Math.min(1,r))}this.allowInterrupt||(this._lookTargetLerpActive&&(this._controls.enablePan=!1),this._cameraLerpActive&&(this._controls.enableRotate=!1,this._controls.autoRotate=!1),(this._lookTargetLerpActive||this._cameraLerpActive)&&(this._controls.enableZoom=!1)),this.context.isInXR||(!G_&&(t=this.lookAtConstraint)!=null&&t.locked&&this.setLookTargetFromConstraint(0,this.lookAtConstraint01),this._controls.update(),Vse&&Pt.DrawWireSphere(this._controls.target,.1,65280))}}setCameraAndLookTarget(e){if(!e||!(e instanceof ye))return;const t=Rt(e),s=qM(e);this.setTargetFromRaycast(new Wn(t,s)),this.setCameraTargetPosition(t)}setCameraTargetPosition(e,t=!1){var s,r;e&&(e instanceof ye&&(e=Rt(e)),this._cameraEndPosition||(this._cameraEndPosition=new w),this._cameraEndPosition.copy(e),t===!0?(this._cameraLerpActive=!1,(s=this.controllerObject)==null||s.position.copy(this._cameraEndPosition)):this._cameraObject&&(this._cameraLerpActive=!0,this._cameraLerp01=0,this._cameraStartPosition.copy((r=this._cameraObject)==null?void 0:r.position),typeof t=="number"?this._cameraLerpDuration=t:this._cameraLerpDuration=this.targetLerpDuration))}get cameraLerpActive(){return this._cameraLerpActive}stopCameraLerp(){this._cameraLerpActive=!1}setLookTargetPosition(e=null,t=!1){this._controls&&e&&(e instanceof ye&&(e=Rt(e)),this._lookTargetEndPosition.copy(e),t===!0?this._controls.target.copy(this._lookTargetEndPosition):(this._lookTargetLerpActive=!0,this._lookTargetLerp01=0,this._lookTargetStartPosition.copy(this._controls.target),typeof t=="number"?this._lookTargetLerpDuration=t:this._lookTargetLerpDuration=this.targetLerpDuration))}get lookTargetLerpActive(){return this._lookTargetLerpActive}stopLookTargetLerp(){this._lookTargetLerpActive=!1}setLookTargetFromConstraint(e=0,t=1){var s;if(!this._controls)return!1;const r=(s=this.lookAtConstraint)==null?void 0:s.sources;if(r&&r.length>0){const n=r[e];if(n)return n.getWorldPosition(this._lookTargetEndPosition),this.lerpLookTarget(this._lookTargetEndPosition,t),!0}return!1}lerpTarget(e,t){return this.lerpLookTarget(e,t)}lerpLookTarget(e,t){this._controls&&(t>=1?this._controls.target.copy(e):this._controls.target.lerp(e,t))}setTargetFromRaycast(e){var t,s;if(!this.controls)return;const r=e?this.context.physics.raycastFromRay(e):this.context.physics.raycast();for(const n of r)if(n.distance>0&&oe.isActiveInHierarchy(n.object)){const o=dI(n.object);if(o){const a=o.canvas;if(a!=null&&a.screenspace)break}if(this.setLookTargetPosition(n.point),this.context.mainCamera){const a=Rt(this.context.mainCamera).clone().sub(this.controls.target).add(this._lookTargetEndPosition);(s=(t=this._cameraObject)==null?void 0:t.parent)==null||s.worldToLocal(a),this.setCameraTargetPosition(a)}break}}fitCamera(e,t=1.1,s=!0){const r=this._cameraObject,n=this._controls;if(e!=null&&e.length||(e=this.context.scene.children),e.length<=0||!r||!n)return;const o=new w,a=new w,l=new Mi;l.makeEmpty();const c=[];function u(v){let b=!0;if(v.visible&&Sse(v)!==!1&&!(v.type==="TransformControlsGizmo"||v.type==="TransformControlsPlane")&&(v instanceof mC&&(b=!1),v instanceof N0&&(b=!1),v instanceof Vz&&(b=!1),v.material instanceof E0&&(b=!1),v instanceof ve||(b=!1),v!==r&&v.isUI!==!0)){if(b){Mv&&console.log(v.name,v.type,v);const _=v.children;v.children=c;const S=v.position,M=v.scale;if(Number.isNaN(S.x)||Number.isNaN(S.y)||Number.isNaN(S.z)){console.warn(`Object "${v.name}" has NaN values in position or scale.... will ignore it`,S,M);return}l.expandByObject(v,!0),v.children=_}for(const _ of v.children)u(_)}}for(const v of e)v.updateMatrixWorld(),u(v);if(r.updateMatrixWorld(),r.updateProjectionMatrix(),l.getCenter(a),l.applyMatrix4(r.matrixWorldInverse),l.getSize(o),l.setFromCenterAndSize(a,o),Number.isNaN(o.x)||Number.isNaN(o.y)||Number.isNaN(o.z)){console.warn("Camera fit size resultet in NaN",r,l,[...e]);return}if(o.length()<=1e-10){Mv&&console.warn("Camera fit size is zero",l,[...e]);return}const d=r.fov,p=2*Math.atan(Math.tan(d*Math.PI/360/2)*r.aspect)/Math.PI*360,f=o.y/(2*Math.atan(Math.PI*d/360)),m=o.x/(2*Math.atan(Math.PI*p/360)),A=t*Math.max(f,m)+o.z/2;Mv&&console.log("Fit camera to objects",f,m,"distance",A);const y=Rt(r),g=n.target.clone().sub(y).normalize().multiplyScalar(A);if(n.maxDistance=A*10,n.minDistance=A*.01,this.setLookTargetPosition(a,s),this.autoTarget=!1,r.near=A/1e3,r.far=A*100,r.updateMatrixWorld(),r.updateProjectionMatrix(),r.parent){const v=r.parent.worldToLocal(n.target.clone().sub(g));this.setCameraTargetPosition(v,s)}else console.error(`Can not fit camera ${r.name} because it has no parent`);if(Mv){const v=new mC(l);this.context.scene.add(v),KM(v,Jg(r)),this._haveAttachedKeyboardEvents||(this._haveAttachedKeyboardEvents=!0,document.body.addEventListener("keydown",b=>{b.code==="KeyF"&&this.fitCamera(e)}))}n.update()}}Cr([x()],zi.prototype,"autoFit",2),Cr([x()],zi.prototype,"enableRotate",2),Cr([x()],zi.prototype,"autoRotate",2),Cr([x()],zi.prototype,"autoRotateSpeed",2),Cr([x()],zi.prototype,"enableKeys",2),Cr([x()],zi.prototype,"enableDamping",2),Cr([x()],zi.prototype,"dampingFactor",2),Cr([x()],zi.prototype,"enableZoom",2),Cr([x()],zi.prototype,"minZoom",2),Cr([x()],zi.prototype,"maxZoom",2),Cr([x()],zi.prototype,"enablePan",2),Cr([x(_v)],zi.prototype,"lookAtConstraint",2),Cr([x()],zi.prototype,"lookAtConstraint01",2),Cr([x()],zi.prototype,"allowInterrupt",2),Cr([x()],zi.prototype,"middleClickToFocus",2),Cr([x()],zi.prototype,"doubleClickToFocus",2),Cr([x()],zi.prototype,"targetLerpDuration",2);var Wse=Object.defineProperty,Xse=Object.getOwnPropertyDescriptor,io=(i,e,t,s)=>{for(var r=s>1?void 0:s?Xse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Wse(e,t,r),r},sd=(i=>(i[i.Skybox=1]="Skybox",i[i.SolidColor=2]="SolidColor",i[i.Uninitialized=4]="Uninitialized",i))(sd||{});const rd=te("debugcam"),Kz=te("debugscreenpointtoray");var V_;const Iv=(V_=class extends Pe{constructor(){super(...arguments),h(this,"_nearClipPlane",.1),h(this,"_farClipPlane",1e3),h(this,"orthographic",!1),h(this,"orthographicSize",5),h(this,"ARBackgroundAlpha",0),h(this,"_cullingMask",4294967295),h(this,"_backgroundBlurriness"),h(this,"_backgroundIntensity"),h(this,"_environmentIntensity"),h(this,"_targetTexture",null),h(this,"_backgroundColor"),h(this,"_fov"),h(this,"_cam",null),h(this,"_clearFlags",2),h(this,"_skybox")}get isCamera(){return!0}get aspect(){return this._cam instanceof Ht?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._cam instanceof Ht?this._cam.fov:this._fov}set fieldOfView(i){const e=this.fieldOfView!=i;if(this._fov=i,e&&this._cam&&this._cam instanceof Ht){if(this._fov===void 0){console.warn("Can not set undefined fov on PerspectiveCamera");return}this._cam.fov=this._fov,this._cam.updateProjectionMatrix()}}get nearClipPlane(){return this._nearClipPlane}set nearClipPlane(i){const e=this._nearClipPlane!=i;this._nearClipPlane=i,this._cam&&e&&(this._cam.near=i,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(i){const e=this._farClipPlane!=i;this._farClipPlane=i,this._cam&&e&&(this._cam.far=i,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(i){i!==this._clearFlags&&(this._clearFlags=i,this.applyClearFlagsIfIsActiveCamera())}set cullingMask(i){this._cullingMask=i,this._cam&&(this._cam.layers.mask=i)}get cullingMask(){return this._cam?this._cam.layers.mask:this._cullingMask}set cullingLayer(i){this.cullingMask=(1<<i|0)>>>0}set backgroundBlurriness(i){i!==this._backgroundBlurriness&&(i===void 0?this._backgroundBlurriness=void 0:this._backgroundBlurriness=Math.min(Math.max(i,0),1),this.applyClearFlagsIfIsActiveCamera())}get backgroundBlurriness(){return this._backgroundBlurriness}set backgroundIntensity(i){i!==this._backgroundIntensity&&(i===void 0?this._backgroundIntensity=void 0:this._backgroundIntensity=Math.min(Math.max(i,0),10),this.applyClearFlagsIfIsActiveCamera())}get backgroundIntensity(){return this._backgroundIntensity}set environmentIntensity(i){this._environmentIntensity=i}get environmentIntensity(){return this._environmentIntensity}get backgroundColor(){return this._backgroundColor??null}set backgroundColor(i){if(i){if(this._backgroundColor)this._backgroundColor.copy(i);else{if(!i.clone)return;this._backgroundColor=i.clone()}i.alpha===void 0&&(this._backgroundColor.alpha=1),this.applyClearFlagsIfIsActiveCamera()}}set targetTexture(i){this._targetTexture=i}get targetTexture(){return this._targetTexture}get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}screenPointToRay(i,e,t){const s=this.cam,r=Iv._origin;r.set(i,e,-1),this.context.input.convertScreenspaceToRaycastSpace(r),Kz&&console.log("screenPointToRay",i.toFixed(2),e.toFixed(2),"now:",r.x.toFixed(2),r.y.toFixed(2),"isInXR:"+this.context.isInXR),r.z=-1,r.unproject(s);const n=Iv._direction.set(r.x,r.y,r.z),o=Rt(s);return n.sub(o),n.normalize(),t?(t.set(o,n),t):new Wn(o.clone(),n.clone())}awake(){Kz&&window.addEventListener("pointerdown",i=>{const e=i.clientX,t=i.clientY;console.log("touch",e.toFixed(2),t.toFixed(2));const s=this.screenPointToRay(e,t),r="#"+Math.floor(Math.random()*16777215).toString(16);Pt.DrawRay(s.origin,s.direction,r,10)})}onEnable(){rd&&console.log(`Camera enabled: "${this.name}". ClearFlags=${sd[this._clearFlags]}`,this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&(this.context.setCurrentCamera(this),Yse(this)),this.applyClearFlagsIfIsActiveCamera()}onDisable(){this.context.removeCamera(this)}onBeforeRender(){if(this._cam&&(this._clearFlags===2&&this.applyClearFlagsIfIsActiveCamera(),this._targetTexture)){this.context.isManagedExternally&&(this._warnedAboutExternalRenderer||(this._warnedAboutExternalRenderer=!0,console.warn("Rendering with external renderer is not supported yet. This may not work or throw errors. Please remove the the target texture from your camera: "+this.name,this.targetTexture))),this.context.composer;const i=this.context.renderer;if(i){const e=this.context.mainCameraComponent;this.applyClearFlags(),this._targetTexture.render(this.context.scene,this._cam,i),e?.applyClearFlags()}}}buildCamera(){if(this._cam)return;const i=this.gameObject.isCamera;let e=null;if(i?(e=this.gameObject,e?.layers.enableAll(),e instanceof Ht&&(this._fov=e.fov)):e=this.gameObject.children[0],e&&e.isCamera)e instanceof Ht&&(this._fov&&(e.fov=this._fov),e.near=this._nearClipPlane,e.far=this._farClipPlane,e.updateProjectionMatrix());else if(!this.orthographic)e=new Ht(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),this.fieldOfView&&(e.fov=this.fieldOfView),this.gameObject.add(e);else{const t=this.orthographicSize*100;e=new Ul(window.innerWidth/-t,window.innerWidth/t,window.innerHeight/t,window.innerHeight/-t,this._nearClipPlane,this._farClipPlane),this.gameObject.add(e)}this._cam=e,this._cam.layers.mask=this._cullingMask,this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){this.context.mainCameraComponent===this&&this.applyClearFlags()}applyClearFlags(){if(!this._cam){rd&&console.log("Camera does not exist (apply clear flags)");return}if(this.fieldOfView=this._fov,rd){const i=`Camera "${this.name}" clear flags: ${sd[this._clearFlags]}`;console.log(i)}switch(this._clearFlags){case 1:if(Iv.backgroundShouldBeTransparent(this.context)&&(!this.ARBackgroundAlpha||this.ARBackgroundAlpha<.001)){this.context.scene.background=null,this.context.renderer.setClearColor(0,0);return}this.enableSkybox(),this._backgroundBlurriness!==void 0&&(this.context.scene.backgroundBlurriness=this._backgroundBlurriness),this._backgroundIntensity!==void 0&&(this.context.scene.backgroundIntensity=this._backgroundIntensity);break;case 2:if(this._backgroundColor){let i=this._backgroundColor.alpha;Iv.backgroundShouldBeTransparent(this.context)&&(i=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,i)}else rd&&console.warn(`Camera "${this.name}" has no background color`,this);break;case 4:this.context.scene.background=null,this.context.renderer.setClearColor(0,0);break}}enableSkybox(){this._skybox||(this._skybox=new qse(this)),this._skybox.enable()}static backgroundShouldBeTransparent(i){var e,t,s,r;const n=(e=i.renderer.xr)==null?void 0:e.getSession();if(!n)return!1;if(typeof n._transparent=="boolean")return n._transparent;const o=n.environmentBlendMode;rd&&ms("Environment blend mode: "+o+" on "+navigator.userAgent);let a=o==="additive"||o==="alpha-blend";return i.isInAR&&o==="opaque"&&((t=navigator.userAgent)!=null&&t.includes("OculusBrowser")||(s=navigator.userAgent)!=null&&s.includes("Mozilla")&&(r=navigator.userAgent)!=null&&r.includes("Mobile WebXRViewer/v2"))&&(a=!0),n._transparent=a,a}},h(V_,"_origin",new w),h(V_,"_direction",new w),V_);let ji=Iv;io([x()],ji.prototype,"fieldOfView",1),io([x()],ji.prototype,"nearClipPlane",1),io([x()],ji.prototype,"farClipPlane",1),io([x()],ji.prototype,"clearFlags",1),io([x()],ji.prototype,"orthographic",2),io([x()],ji.prototype,"orthographicSize",2),io([x()],ji.prototype,"ARBackgroundAlpha",2),io([x()],ji.prototype,"cullingMask",1),io([x()],ji.prototype,"backgroundBlurriness",1),io([x()],ji.prototype,"backgroundIntensity",1),io([x()],ji.prototype,"environmentIntensity",1),io([x(Si)],ji.prototype,"backgroundColor",1),io([x(cf)],ji.prototype,"targetTexture",1);class qse{constructor(e){h(this,"_camera"),h(this,"_skybox"),this._camera=e}get context(){var e;return(e=this._camera)==null?void 0:e.context}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?this.context.scene.background!==this._skybox&&(rd&&console.log(`Camera "${this._camera.name}" set skybox`,this._camera,this._skybox),this._skybox.colorSpace=Gt,this._skybox.mapping=bo,this.context.scene.background=this._skybox):(this._did_log_failed_to_find_skybox||(this._did_log_failed_to_find_skybox=!0,console.warn(`Camera "${this._camera.name}" failed to load/find skybox texture`,this._camera.sourceId,this.context.lightmaps,"Current background: ",this.context.scene.background)),(rd||wt())&&is(`Camera "${this._camera.name}" has no skybox texture`))}}function Yse(i){te("freecam")&&i.context.mainCameraComponent===i&&oe.getOrAddComponent(i.gameObject,zi)}class Th extends Pe{constructor(){super(...arguments),h(this,"_listener",null)}get listener(){return this._listener==null&&(this._listener=new nk),this._listener}awake(){vs.registerWaitForAllowAudio(()=>{if(this.destroyed)return;const e=this.listener;if(e==null||e.parent)return;const t=this.context.mainCameraComponent||oe.getComponentInParent(this.gameObject,ji);t!=null&&t.cam?t.cam.add(e):this.gameObject.add(e)})}}var Jse=Object.defineProperty,Kse=Object.getOwnPropertyDescriptor,H_=(i,e,t,s)=>{for(var r=s>1?void 0:s?Kse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Jse(e,t,r),r};const Zse=te("debugsignals");class Rv{constructor(){h(this,"guid")}}H_([x()],Rv.prototype,"guid",2);class bf{constructor(){h(this,"signal"),h(this,"reaction")}}H_([x(Rv)],bf.prototype,"signal",2),H_([x(tr)],bf.prototype,"reaction",2);var mI;const gc=(mI=class extends Pe{constructor(){super(...arguments),h(this,"events")}static invoke(i){if(gc.receivers[i]){const e=gc.receivers[i];if(!e)return;for(const t of e)t.invoke(i)}}awake(){Zse&&console.log("SignalReceiver awake",this)}onEnable(){if(this.events)for(const i of this.events)gc.receivers[i.signal.guid]||(gc.receivers[i.signal.guid]=[]),gc.receivers[i.signal.guid].push(this)}onDisable(){if(this.events){for(const i of this.events)if(gc.receivers[i.signal.guid]){const e=gc.receivers[i.signal.guid].indexOf(this);e>=0&&gc.receivers[i.signal.guid].splice(e,1)}}}invoke(i){if(!this.events||!Array.isArray(this.events))return;const e=typeof i=="object"?i.guid:i;for(const t of this.events)if(t.signal.guid===e)try{if(t.reaction){if(!t.reaction.invoke){console.warn("Missing invoke - possibly a serialization error",t,this);continue}}else{console.warn("Missing reaction for signal",t,this);continue}t.reaction.invoke()}catch(s){console.error(s)}}},h(mI,"receivers",{}),mI);let _f=gc;H_([x(bf)],_f.prototype,"events",2);var so=(i=>(i.Activation="ActivationTrack",i.Animation="AnimationTrack",i.Audio="AudioTrack",i.Control="ControlTrack",i.Marker="MarkerTrack",i.Signal="SignalTrack",i))(so||{}),el=(i=>(i[i.None=0]="None",i[i.Hold=1]="Hold",i[i.Loop=2]="Loop",i[i.PingPong=3]="PingPong",i[i.Continue=4]="Continue",i))(el||{}),gI=(i=>(i.Signal="SignalEmitter",i))(gI||{});const tl=te("debugtimeline");class Pv{constructor(){h(this,"director"),h(this,"track")}get muted(){return this.track.muted}set muted(e){var t;e!==this.track.muted&&(this.track.muted=e,(t=this.onMuteChanged)==null||t.call(this))}*forEachClip(e=!1){var t;if((t=this.track)!=null&&t.clips)if(e)for(let s=this.track.clips.length-1;s>=0;s--)yield this.track.clips[s];else for(const s of this.track.clips)yield s}getClipTime(e,t){return t.clipIn+(e-t.start)*t.timeScale}getClipTimeNormalized(e,t){return(e-t.start)/t.duration}evaluateWeight(e,t,s,r=!0){if(t<0||t>=s.length)return 0;const n=s[t];if(r||e>=n.start&&e<=n.end){let o=1;const a=!1;if(n.easeInDuration>0){const l=Math.min((e-n.start)/n.easeInDuration,1);o*=l}if(n.easeOutDuration>0&&!a){const l=Math.min((n.end-e)/n.easeOutDuration,1);o*=l}return o}return 0}}class $se{constructor(e){h(this,"clip"),h(this,"rootPositionOffset"),h(this,"rootQuaternionOffset"),h(this,"rootStartPosition"),h(this,"rootEndPosition"),h(this,"rootStartQuaternion"),h(this,"rootEndQuaternion");const t=e.getClip();this.clip=t;const s=e.getRoot(),r=s.name+".position",n=s.name+".quaternion";tl&&console.log(t.name,t.tracks,r);for(const o of t.tracks)if(!(o.times.length<=0)){if(o.name.endsWith(r))this.rootStartPosition=new w().fromArray(o.values,0),this.rootEndPosition=new w().fromArray(o.values,o.values.length-3),this.rootPositionOffset=this.rootEndPosition.clone().sub(this.rootStartPosition),tl&&console.log(this.rootPositionOffset);else if(o.name.endsWith(n)&&(this.rootStartQuaternion=new Ie().fromArray(o.values,0),this.rootEndQuaternion=new Ie().fromArray(o.values,o.values.length-4),this.rootQuaternionOffset=this.rootEndQuaternion.clone().multiply(this.rootStartQuaternion),tl)){const a=new Ur().setFromQuaternion(this.rootQuaternionOffset);console.log("ROT",a)}}}get hasOffsets(){return this.rootPositionOffset!==void 0||this.rootQuaternionOffset!==void 0}}class W_ extends Pv{constructor(){super(...arguments),h(this,"models",[]),h(this,"trackOffset"),h(this,"target"),h(this,"mixer"),h(this,"clips",[]),h(this,"actions",[]),h(this,"_actionOffsets",[]),h(this,"_didBind",!1),h(this,"_animator",null),h(this,"_useclipOffsets",!0),h(this,"_totalOffsetPosition",new w),h(this,"_totalOffsetRotation",new Ie),h(this,"_totalOffsetPosition2",new w),h(this,"_totalOffsetRotation2",new Ie),h(this,"_summedPos",new w),h(this,"_tempPos",new w),h(this,"_summedRot",new Ie),h(this,"_tempRot",new Ie),h(this,"_clipRotQuat",new Ie)}onStateChanged(){this._animator&&Zz(this._animator.gameObject,this,this.director.isPlaying)}createHooks(e,t){var s,r;if(((s=t.tracks)==null?void 0:s.length)<=0){console.warn("No tracks in AnimationClip",t);return}const n=t.tracks[0].name.split("."),o=n[n.length-2],a=o+".position",l=o+".quaternion";let c=!1,u=!1;for(const d of t.tracks)d.name.endsWith(a)?(c=!0,this.createPositionInterpolant(t,e,d)):d.name.endsWith(l)&&(u=!0,this.createRotationInterpolant(t,e,d));if(!c||!u){const d=(r=this.mixer)==null?void 0:r.getRoot(),p=t.tracks[0],f=p.name.lastIndexOf("."),m=p.name.substring(0,f),A=m.substring(m.lastIndexOf(".")+1),y=d.getObjectByName(A);if(y)if(c){if(!u){const g=t.tracks[0].name.substring(0,f)+".quaternion";tl&&console.warn("Create quaternion track",A,y);const v=y.quaternion,b=new Na(g,[0,t.duration],[v.x,v.y,v.z,v.w,v.x,v.y,v.z,v.w]);t.tracks.push(b),this.createRotationInterpolant(t,e,b)}}else{const g=m+".position";tl&&console.warn("Create position track",A,y);const v=y.position,b=new Nl(g,[0,t.duration],[v.x,v.y,v.z,v.x,v.y,v.z]);t.tracks.push(b),this.createPositionInterpolant(t,e,b)}}}bind(){if(!this._didBind){this._didBind=!0,tl&&console.log(this.models),this.mixer?this.target=this.mixer.getRoot():console.warn("No mixer was assigned to animation track");for(const e of this.actions){const t=new $se(e);this._actionOffsets.push(t)}this.target&&(this._animator=oe.getComponent(this.target,Er)??null,this._animator&&Zz(this._animator.gameObject,this,!0));for(const e of this.models){const t=e.asset,s=t.position,r=t.rotation;s&&s.x!==void 0&&(s.isVector3||(t.position=new w(s.x,s.y,s.z)),r.isQuaternion||(t.rotation=new Ie(r.x,r.y,r.z,r.w)))}this.ensureTrackOffsets()}}ensureTrackOffsets(){if(this.trackOffset){const e=this.trackOffset.position;e&&(e.isVector3||(this.trackOffset.position=new w(e.x,e.y,e.z)));const t=this.trackOffset.rotation;t&&(t.isQuaternion||(this.trackOffset.rotation=new Ie(t.x,t.y,t.z,t.w)))}}evaluate(e){var t,s,r,n,o,a,l;if(this.track.muted||!this.mixer)return;this.bind(),this._totalOffsetPosition.set(0,0,0),this._totalOffsetRotation.set(0,0,0,1),this._totalOffsetPosition2.set(0,0,0),this._totalOffsetRotation2.set(0,0,0,1);let c=0,u=0,d=!1,p=!1,f=0;for(let m=0;m<this.clips.length;m++){const A=this.models[m],y=this.actions[m],g=A.asset;y.weight=0;const v=e>=A.start&&e<=A.end,b=A.preExtrapolationMode,_=A.postExtrapolationMode,S=m<this.clips.length-1?this.models[m+1]:null;let M=v,C=!1;if(!M&&!d&&A.end<e&&_!==el.None?(!S||S.start>e)&&(M=!0,d=!0):m==0&&!M&&!p&&A.start>e&&b!==el.None&&(!S||S.start<e)&&(M=!0,C=!0,p=!0),M){let R=1;R*=this.evaluateWeight(e,m,this.models,M),R*=this.director.weight;let I=v;if(C)switch(b){case el.Hold:break;case el.Loop:e+=A.start,I=!0;break;default:e+=A.start,I=!0;break}let E=this.getClipTime(e,A),z=0;const F=g.duration;if(C&&b===el.Hold&&(E=0),I){if(g.loop)for(z+=Math.floor(E/(F+1e-6));E>F;)E-=F}else if(!v&&d)switch(_){case el.Hold:E=this.getClipTime(A.end,A);break;case el.Loop:E%=F;break;case el.PingPong:const N=Math.floor(E/F)%2!==0;E%=F,N&&(E=F-E);break}A.reversed===!0?y.time=y.getClip().duration-E:y.time=E,y.timeScale=0;const q=Math.max(0,R);if(y.weight=q,f+=q,y.clampWhenFinished=!1,y.isRunning()||y.play(),this._useclipOffsets){const N=c==0?this._totalOffsetPosition:this._totalOffsetPosition2,H=c==0?this._totalOffsetRotation:this._totalOffsetRotation2;c<1&&(u=1-R),c+=1;const L=this._summedPos.set(0,0,0),j=this._tempPos.set(0,0,0),Q=this._summedRot.identity(),$=this._tempRot.identity(),Z=g.rotation;Z&&(this._clipRotQuat.identity(),this._clipRotQuat.slerp(Z,R));const se=this._actionOffsets[m];if(se.hasOffsets)for(let Ae=0;Ae<z;Ae++)se.rootPositionOffset?j.copy(se.rootPositionOffset):j.set(0,0,0),j.applyQuaternion(Q),this._clipRotQuat&&j.applyQuaternion(this._clipRotQuat),se.rootQuaternionOffset&&($.copy(se.rootQuaternionOffset),Q.multiply($)),L.add(j);this._clipRotQuat&&H.multiply(this._clipRotQuat),H.multiply(Q),g.position&&L.add(g.position),N.add(L)}}}if(this._useclipOffsets&&(this._totalOffsetPosition.lerp(this._totalOffsetPosition2,u),this._totalOffsetRotation.slerp(this._totalOffsetRotation2,u)),this.__mixerError===void 0&&(tl||wt())&&(s=(t=this._animator)==null?void 0:t.runtimeAnimatorController)!=null&&s.mixer&&this.mixer!==((n=(r=this._animator)==null?void 0:r.runtimeAnimatorController)==null?void 0:n.mixer)&&(this.__mixerError=!0,console.error("AnimationTrack mixer is not shared with the animator controller - this might result in the timeline to not animate properly. Please report a bug to the Needle Engine team!",this)),(o=this._animator)!=null&&o.runtimeAnimatorController){const m=Math.max(0,1-f);(l=(a=this._animator)==null?void 0:a.runtimeAnimatorController)==null||l.update(m)}else this.mixer.update(e)}createRotationInterpolant(e,t,s){var r;const n=s.createInterpolant.bind(s),o=new Ie;this.ensureTrackOffsets();const a=(r=this.trackOffset)==null?void 0:r.rotation;s.createInterpolant=()=>{const l=n(),c=l.evaluate.bind(l);return l.evaluate=u=>{var d;const p=c(u);if(o.set(p[0],p[1],p[2],p[3]),o.premultiply(this._totalOffsetRotation),a&&o.premultiply(a),this.director.animationCallbackReceivers)for(const f of this.director.animationCallbackReceivers)(d=f?.onTimelineRotation)==null||d.call(f,this.director,this.target,u,o);return p[0]=o.x,p[1]=o.y,p[2]=o.z,p[3]=o.w,p},l}}createPositionInterpolant(e,t,s){var r,n;const o=s.createInterpolant.bind(s),a=new w;this.ensureTrackOffsets();const l=(r=this.trackOffset)==null?void 0:r.rotation,c=(n=this.trackOffset)==null?void 0:n.position;let u;s.createInterpolant=()=>{const d=o(),p=d.evaluate.bind(d);return d.evaluate=f=>{var m,A,y;const g=p(f);if(a.set(g[0],g[1],g[2]),t.removeStartOffset&&(u===void 0?(u=null,u=(A=(m=this._actionOffsets.find(v=>v.clip===e))==null?void 0:m.rootStartPosition)==null?void 0:A.clone()):u!=null&&u.isVector3&&a.sub(u)),a.applyQuaternion(this._totalOffsetRotation),a.add(this._totalOffsetPosition),l&&a.applyQuaternion(l),c&&(a.x-=c.x,a.y+=c.y,a.z+=c.z),this.director.animationCallbackReceivers)for(const v of this.director.animationCallbackReceivers)(y=v?.onTimelinePosition)==null||y.call(v,this.director,this.target,f,a);return g[0]=a.x,g[1]=a.y,g[2]=a.z,g},d}}}const ere=te("mutetimeline"),Bv=class extends Pv{constructor(){super(...arguments),h(this,"models",[]),h(this,"listener"),h(this,"audio",[]),h(this,"audioContextTimeOffset",[]),h(this,"lastTime",0),h(this,"audioSource"),h(this,"_audioLoader",null),h(this,"_playableDirectorResumed",!1)}getAudioFilePath(i){const e=this.director.sourceId;return sh(e,i)}onAllowAudioChanged(i){for(let e=0;e<this.models.length;e++){const t=this.models[e];this.audio[e].setVolume(i?t.asset.volume:0)}}addModel(i){const e=new aC(this.listener);this.audio.push(e);const t=i;t._didTriggerPlay=!1,this.models.push(t)}onDisable(){for(const i of this.audio)i.isPlaying&&i.stop();for(const i of this.models)i._didTriggerPlay=!1}onDestroy(){for(const i of this.audio)i.source&&i?.disconnect();this.audio.length=0}onMuteChanged(){if(this.muted)for(let i=0;i<this.audio.length;i++){const e=this.audio[i];e!=null&&e.isPlaying&&e.stop()}}stop(){for(let i=0;i<this.audio.length;i++){const e=this.audio[i];e!=null&&e.isPlaying&&e.stop()}for(const i of this.models)i._didTriggerPlay=!1}onPauseChanged(){for(let i=0;i<this.audio.length;i++){const e=this.audio[i];e!=null&&e.isPlaying&&e.stop()}this._playableDirectorResumed=this.director.isPlaying}evaluate(i){if(ere||this.track.muted||this.director.speed<0)return;const e=this.director.context.application.muted,t=this._playableDirectorResumed;this._playableDirectorResumed=!1;const s=e?.1:0;for(let r=0;r<this.models.length;r++){const n=this.models[r],o=this.audio[r],a=n.asset;if((!o||!o.buffer)&&this.isInTimeRange(n,i-1,i+1)&&this.handleAudioLoading(n,o),vs.userInteractionRegistered!==!1&&!(o===null||!o.buffer))if(o.playbackRate=this.director.context.time.timeScale*this.director.speed,o.loop=a.loop,i>=n.start&&i<=n.end&&i<this.director.duration){if(!o.isPlaying||!this.director.isPlaying)(t||!n._didTriggerPlay&&this.lastTime<i)&&(n.duration*n.timeScale>.3?o.offset=n.clipIn+(i-n.start)*n.timeScale:o.offset=0,tl&&console.log("Timeline Audio ("+this.track.name+") play with offset "+o.offset+" - "+n.asset.clip),o.play(s),n._didTriggerPlay=!0);else{const c=n.clipIn+(i-n.start)*n.timeScale,u=o.context.currentTime-o._startedAt+o.offset;Math.abs(c-u)>.3&&(o.offset=c,o.stop(),o.play(s))}let l=a.volume;if(this.track.volume!==void 0&&(l*=this.track.volume),e&&(l=0),n.easeInDuration>0){const c=Math.min((i-n.start)/n.easeInDuration,1);l*=c}if(n.easeOutDuration>0){const c=Math.min((n.end-i)/n.easeOutDuration,1);l*=c}o.setVolume(l*this.director.weight)}else n._didTriggerPlay=!1,this.director.isPlaying&&o.isPlaying&&o.stop()}this.lastTime=i}loadAudio(i,e=0,t=0){let s=null;const r=i-t,n=i+e;for(const o of this.models)if(this.isInTimeRange(o,r,n)){const a=this.audio[this.models.indexOf(o)],l=this.handleAudioLoading(o,a);l!==null&&(s===null&&(s=[]),s.push(l))}return s!==null?Promise.all(s):null}isInTimeRange(i,e,t){return e<=i.start&&t>=i.end||e>=i.start&&e<=i.end||t>=i.start&&t<=i.end}static dispose(){Bv._audioBuffers.clear()}handleAudioLoading(i,e){this._audioLoader||(this._audioLoader=new k0);const t=this.getAudioFilePath(i.asset.clip);if(Bv._audioBuffers.get(t)){const r=Bv._audioBuffers.get(t);return r.then(n=>{n&&e.setBuffer(n)}),r}tl&&console.warn("LOAD audio track",t,this.director.sourceId);const s=new Promise((r,n)=>{this._audioLoader.load(t,o=>{e.setBuffer(o),r(o)},void 0,o=>{console.error("Error loading audio",o),r(null)})});return Bv._audioBuffers.set(t,s),s}};let Dv=Bv;h(Dv,"_audioBuffers",new Map);class kv extends Pv{constructor(){super(...arguments),h(this,"models",[]),h(this,"didTrigger",[]),h(this,"receivers",[])}evaluate(e){var t;if(this.track.muted)return;const s=this.director.context.time.deltaTime*1.5;for(let r=0;r<this.models.length;r++){const n=this.models[r],o=this.didTrigger[r],a=n.time-e;let l=!1;if(n.retroActive)l=a<=1e-6;else{const c=Math.abs(a);(c===0||c>=1e-5&&c<s)&&(l=!0)}if(l){if(!o)if(tl&&console.log("Trigger signal",e,n.time,n),this.didTrigger[r]=!0,((t=this.receivers)==null?void 0:t.length)<=0)_f.invoke(n.asset);else for(const c of this.receivers)c&&c.invoke(n.asset)}else n.emitOnce||(this.didTrigger[r]=!1)}}}class X_ extends Pv{constructor(){super(...arguments),h(this,"models",[]),h(this,"timelines",[]),h(this,"_previousActiveModel",null)}resolveSourceObjects(e){for(let t=this.models.length-1;t>=0;t--){const s=this.models[t].asset;if(!s.sourceObject||typeof s.sourceObject!="object"){console.log("no source object, removing model",t,s),this.models.splice(t,1);continue}else{const r=oe.getComponent(s.sourceObject,nd);this.timelines.push(r),r&&s.updateDirector&&(r.playOnAwake=!1)}}}evaluate(e){var t;this._previousActiveModel=null;for(let s=0;s<this.models.length;s++){const r=this.models[s],n=r.asset;if(e>=r.start&&e<=r.end){this._previousActiveModel=r;const o=this.getClipTime(e,r);if(n.controlActivation){const a=n.sourceObject;a.visible=!0}if(n.updateDirector){const a=this.timelines[s];a&&(a.isPlaying&&a.pause(),a.time=o,a.evaluate())}}else{const o=(t=this._previousActiveModel)==null?void 0:t.asset;if(n.controlActivation){const a=n.sourceObject;o?.sourceObject!==a&&(a.visible=!1)}}}}}const xf=te("debugtimeline"),vI=class extends Pe{constructor(){super(...arguments),h(this,"playableAsset"),h(this,"playOnAwake"),h(this,"extrapolationMode",1),h(this,"waitForAudio",!0),h(this,"_visibilityChangeEvt"),h(this,"_clonedPlayableAsset",!1),h(this,"_speed",1),h(this,"_guidsMap"),h(this,"_isPlaying",!1),h(this,"_internalUpdateRoutine"),h(this,"_isPaused",!1),h(this,"_isStopping",!1),h(this,"_time",0),h(this,"_duration",0),h(this,"_weight",1),h(this,"_animationTracks",[]),h(this,"_audioTracks",[]),h(this,"_signalTracks",[]),h(this,"_controlTracks",[]),h(this,"_customTracks",[]),h(this,"_allTracks",[this._animationTracks,this._audioTracks,this._signalTracks,this._controlTracks,this._customTracks]),h(this,"animationCallbackReceivers",[])}static registerCreateTrack(i,e){this.createTrackFunctions[i]=e}get isPlaying(){return this._isPlaying}get isPaused(){return this._isPaused}get time(){return this._time}set time(i){typeof i=="number"&&!Number.isNaN(i)?this._time=i:(xf||un())&&console.error("INVALID TIMELINE.TIME VALUE",i,this.name)}get duration(){return this._duration}set duration(i){this._duration=i}get weight(){return this._weight}set weight(i){this._weight=i}get speed(){return this._speed}set speed(i){this._speed=i}awake(){var i,e,t;xf&&console.log(this,(i=this.playableAsset)==null?void 0:i.tracks),this.rebuildGraph(),this.isValid()||console.warn("PlayableDirector is not valid",this.playableAsset,(e=this.playableAsset)==null?void 0:e.tracks,Array.isArray((t=this.playableAsset)==null?void 0:t.tracks),this)}onEnable(){var i,e,t;for(const s of this._audioTracks)(i=s.onEnable)==null||i.call(s);for(const s of this._customTracks)(e=s.onEnable)==null||e.call(s);for(const s of this._animationTracks)(t=s.onEnable)==null||t.call(s);this.playOnAwake&&this.play(),this._visibilityChangeEvt||(this._visibilityChangeEvt=()=>{switch(document.visibilityState){case"hidden":this.setAudioTracksAllowPlaying(!1);break;case"visible":this.setAudioTracksAllowPlaying(!0);break}}),window.addEventListener("visibilitychange",this._visibilityChangeEvt)}onDisable(){var i,e,t;this.stop();for(const s of this._audioTracks)(i=s.onDisable)==null||i.call(s);for(const s of this._customTracks)(e=s.onDisable)==null||e.call(s);for(const s of this._animationTracks)(t=s.onDisable)==null||t.call(s);this._visibilityChangeEvt&&window.removeEventListener("visibilitychange",this._visibilityChangeEvt)}onDestroy(){var i;for(const e of this._allTracks)for(const t of e)(i=t.onDestroy)==null||i.call(t)}rebuildGraph(){this.isValid()&&(this.resolveBindings(),this.updateTimelineDuration(),this.setupAndCreateTrackHandlers())}async play(){if(!this.isValid())return;const i=this._isPaused==!0;if(this._isPaused=!1,!this._isPlaying){if(this._isPlaying=!0,i&&this.invokePauseChangedMethodsOnTracks(),this.waitForAudio){const e=[];for(const t of this._audioTracks){const s=t.loadAudio(this._time,1,0);s&&e.push(s)}if(e.length>0&&(await Promise.all(e),!this._isPlaying))return;for(;this._audioTracks.length>0&&this._isPlaying&&!vs.userInteractionRegistered&&this.waitForAudio;)await Co(200)}this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine=this.startCoroutine(this.internalUpdate(),ks.LateUpdate)}}pause(){this.isValid()&&(this._isPlaying=!1,!this._isPaused&&(this._isPaused=!0,this.internalEvaluate(),this.invokePauseChangedMethodsOnTracks(),this.invokeStateChangedMethodsOnTracks()))}stop(){this._isStopping=!0;for(const t of this._audioTracks)t.stop();const i=this._isPaused==!0,e=this._isPlaying;this._isPlaying&&(this._time=0,this._isPlaying=!1,this._isPaused=!1,this.internalEvaluate(),i&&this.invokePauseChangedMethodsOnTracks()),this._isPlaying=!1,this._isPaused=!1,i&&!e&&this.invokePauseChangedMethodsOnTracks(),e&&this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine&&this.stopCoroutine(this._internalUpdateRoutine),this._internalUpdateRoutine=null,this._isStopping=!1}evaluate(){this.internalEvaluate(!0)}isValid(){return this.playableAsset&&this.playableAsset.tracks&&Array.isArray(this.playableAsset.tracks)}*forEachTrack(){for(const i of this._allTracks)for(const e of i)yield e}get audioTracks(){return this._audioTracks}resolveGuids(i){this._guidsMap=i}invokePauseChangedMethodsOnTracks(){var i;for(const e of this.forEachTrack())(i=e.onPauseChanged)==null||i.call(e)}invokeStateChangedMethodsOnTracks(){var i;for(const e of this.forEachTrack())(i=e.onStateChanged)==null||i.call(e,this._isPlaying)}*internalUpdate(){for(;this._isPlaying&&this.activeAndEnabled;)!this._isPaused&&this._isPlaying&&(this._time+=this.context.time.deltaTime*this.speed,this.internalEvaluate()),yield}internalEvaluate(i=!1){if(!this.isValid())return;let e=this._time;switch(this.extrapolationMode){case 0:this._speed>0?e=Math.min(e,this._duration):this._speed<0&&(e=Math.max(e,0)),this._time=e;break;case 1:e%=this._duration,this._time=e;break;case 2:if(e>this._duration){this.stop();return}break}const t=this._time;for(const s of this.playableAsset.tracks)if(!s.muted)switch(s.type){case so.Activation:if(!i&&!this._isPlaying)continue;for(let r=0;r<s.outputs.length;r++){const n=s.outputs[r];if(typeof n=="object"){let o=!1;if(s.clips)for(const l of s.clips)l.start<=t&&t<=l.end&&(o=!0);const a=n;a.visible!==void 0&&a.visible!==o&&(a.visible=o,xf&&console.warn(this.name,"set ActivationTrack-"+r,a.name,o,t))}}break}if(!this._isStopping)for(const s of this._animationTracks)s.evaluate(t);for(const s of this._audioTracks)s.evaluate(t);for(const s of this._signalTracks)s.evaluate(t);for(const s of this._controlTracks)s.evaluate(t);for(const s of this._customTracks)s.evaluate(t)}resolveBindings(){if(this._clonedPlayableAsset||(this._clonedPlayableAsset=!0,this.playableAsset=og(this.playableAsset)),!this.playableAsset||!this.playableAsset.tracks)return;const i=this.findRoot(this.gameObject);for(const e of this.playableAsset.tracks){for(let t=e.outputs.length-1;t>=0;t--){let s=e.outputs[t];if(typeof s=="string"){this._guidsMap&&this._guidsMap[s]&&(s=this._guidsMap[s]);const r=oe.findByGuid(s,i);r===null||typeof r!="object"?(e.outputs.splice(t,1),console.warn("Failed to resolve binding",s,e.name,e.type)):(xf&&console.log("Resolved binding",s,"to",r),e.outputs[t]=r)}else if(s===null){if(e.outputs.splice(t,1),vI.createTrackFunctions[e.type])continue;e.type!==so.Audio&&e.type!==so.Control&&e.type!==so.Marker&&e.type!==so.Signal&&console.warn("Missing binding",s,e.name,e.type,this.name,this.playableAsset.name)}}if(e.type===so.Control&&e.clips)for(let t=0;t<e.clips.length;t++){const s=e.clips[t];let r=s.asset.sourceObject;if(typeof r=="string"){this._guidsMap&&this._guidsMap[r]&&(r=this._guidsMap[r]);const n=oe.findByGuid(r,i);n===null||typeof n!="object"?console.warn("Failed to resolve sourceObject binding",r,e.name,s):(xf&&console.log("Resolved binding",r,"to",n),s.asset.sourceObject=n)}}}}findRoot(i){return i.parent?this.findRoot(i.parent):i}updateTimelineDuration(){if(this._duration=0,!(!this.playableAsset||!this.playableAsset.tracks)){for(const i of this.playableAsset.tracks)if(i.muted!==!0){if(i.clips)for(const e of i.clips)e.end>this._duration&&(this._duration=e.end);if(i.markers)for(const e of i.markers)e.time>this._duration&&(this._duration=e.time+.001)}}}setupAndCreateTrackHandlers(){var i,e,t;if(this._animationTracks.length=0,this._audioTracks.length=0,this._signalTracks.length=0,!this.playableAsset)return;let s=oe.findObjectOfType(Th,this.context);for(const r of this.playableAsset.tracks){const n=r.type,o=vI.createTrackFunctions[n];if(o!=null){const a=o(this,r);if(typeof a.evaluate=="function"){a.director=this,a.track=r,this._customTracks.push(a);continue}}if(r.type===so.Animation){if(!r.clips||r.clips.length<=0){xf&&console.warn("Animation track has no clips",r);continue}for(let a=r.outputs.length-1;a>=0;a--){let l=r.outputs[a];if(l instanceof ye){const u=oe.getOrAddComponent(l,Er);u&&(l=u)}const c=(i=l?.gameObject)==null?void 0:i.animations;if(c){const u=new W_;u.trackOffset=r.trackOffset,u.director=this,u.track=r;for(let d=0;d<r.clips.length;d++){const p=r.clips[d],f=p.asset;if(!f){console.error(`Timeline ${this.name}: clip #${d} on track "${r.name}" has no animation data`);continue}const m=f.clip;let A=m;if((typeof A=="string"||typeof A=="number")&&(A=c.find(g=>g.name===m)),!A){console.warn("Could not find animationClip for model",p,r.name,this.name,(e=this.playableAsset)==null?void 0:e.name);continue}l instanceof Er&&l.runtimeAnimatorController&&(l.__internalDidAwakeAndStart||l.initializeRuntimeAnimatorController(),l.runtimeAnimatorController.mixer||l.runtimeAnimatorController.bind(l),u.mixer=l.runtimeAnimatorController.mixer),u.mixer||(u.mixer=new O0(l.gameObject)),u.clips.push(A),u.mixer.uncacheAction(A),u.createHooks(p.asset,A);const y=u.mixer.clipAction(A);u.actions.push(y),u.models.push(p)}this._animationTracks.push(u)}}}else if(r.type===so.Audio){if(!r.clips||r.clips.length<=0)continue;const a=new Dv;a.director=this,a.track=r,a.audioSource=r.outputs.find(l=>l instanceof vs),this._audioTracks.push(a),s||(s=(t=this.context.mainCameraComponent)==null?void 0:t.gameObject.addNewComponent(Th)),a.listener=s.listener;for(let l=0;l<r.clips.length;l++){const c=r.clips[l];a.addModel(c)}}else if(r.type===so.Marker){const a=new kv;if(a.director=this,a.track=r,r.markers)for(const l of r.markers)switch(l.type){case gI.Signal:a.models.push(l),a.didTrigger.push(!1);break}if(a!==null&&a.models.length>0){const l=oe.getComponent(this.gameObject,_f);l&&(a.receivers.push(l),this._signalTracks.push(a))}}else if(r.type===so.Signal){const a=new kv;if(a.director=this,a.track=r,r.markers)for(const l of r.markers)a.models.push(l),a.didTrigger.push(!1);for(const l of r.outputs)a.receivers.push(l);this._signalTracks.push(a)}else if(r.type===so.Control){const a=new X_;if(a.director=this,a.track=r,r.clips)for(const l of r.clips)a.models.push(l);a.resolveSourceObjects(this.context),this._controlTracks.push(a)}}}setAudioTracksAllowPlaying(i){for(const e of this._audioTracks)e.onAllowAudioChanged(i)}registerAnimationCallback(i){this.animationCallbackReceivers.push(i)}unregisterAnimationCallback(i){const e=this.animationCallbackReceivers.indexOf(i);e!==-1&&this.animationCallbackReceivers.splice(e,1)}};let nd=vI;h(nd,"createTrackFunctions",{});const q_=Symbol("objectIsAnimatedData");function Zz(i,e,t){if(!i)return;if(i[q_]===void 0){if(!t)return;i[q_]=new Set}const s=i[q_];t?s.add(e):s.has(e)&&s.delete(e)}function tre(i){if(!i)return!1;const e=i[q_];return e!==void 0&&e.size>0}Ti.registerCallback(Hs.ContextCreated,i=>{const e=i.context.domElement.getAttribute("autoplay");if(e!==void 0&&(e===""||e==="true")&&i.files)for(const t of i.files)oe.foreachComponent(t.file.scene,s=>{if(s.enabled!==!1){if(s instanceof eo&&s.playAutomatically||s instanceof Er||s instanceof nd&&s.playOnAwake===!0)return!0;if(s instanceof eo)return s.playAutomatically=!0,!0;if(s instanceof nd)return s.playOnAwake=!0,!0}},!0)!==!0&&ire(t.file)});function ire(i){if(!i||!i.animations)return;for(let t=0;t<i.animations.length;t++){const s=i.animations[t];if(!(!s.tracks||s.tracks.length<=0))for(const r in s.tracks){const n=s.tracks[r],o=n.__objectName??n.name.substring(0,n.name.indexOf("."));let a=i.scene.getObjectByName(o);if(!a&&(a=i.scene.getObjectByProperty("uuid",o),!a))continue;let l=e(a);l||(l=Ah(i.scene,new eo));const c=l.animations=l.animations||[];s.name_animator=l.name,c.indexOf(s)<0&&c.push(s)}}function e(t){var s;if(!t)return;const r=(s=t.userData)==null?void 0:s.components;if(r&&r.length>0)for(let n=0;n<r.length;n++){const o=r[n];if(o instanceof Er||o instanceof eo)return t}return e(t.parent)}}class sre{constructor(){h(this,"_context")}get context(){return this._context??kt.Current}get isStateMachineBehaviour(){return!0}}class Y_{constructor(e,t,s,r){h(this,"_name"),h(this,"_nameHash"),h(this,"_normalizedTime"),h(this,"_length"),h(this,"_speed"),this._name=e.name,this._nameHash=e.hash,this._normalizedTime=t,this._length=s,this._speed=r}get name(){return this._name}get nameHash(){return this._nameHash}get normalizedTime(){return this._normalizedTime}get length(){return this._length}get speed(){return this._speed}}function $z(i,e){return{name:"",isLooping:!1,guid:e?.generateUUID()??js.generateUUID(),index:-1,clip:new Ln(i,1,[])}}var Ih=(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))(Ih||{}),AI=(i=>(i[i.Float=1]="Float",i[i.Int=3]="Int",i[i.Bool=4]="Bool",i[i.Trigger=9]="Trigger",i))(AI||{});const yn=te("debuganimatorcontroller"),J_=te("debugrootmotion");class vo{constructor(e){h(this,"normalizedStartOffset",0),h(this,"_speed",1),h(this,"animator"),h(this,"model"),h(this,"_mixer"),h(this,"_activeState"),h(this,"_activeStates",[]),h(this,"rootMotionHandler"),this.model=e,yn&&console.log(this)}static createFromClips(e,t={looping:!1,autoTransition:!0,transitionDuration:0}){const s=[];for(let n=0;n<e.length;n++){const o=e[n],a=[];if(t.autoTransition!==!1){const c=t.transitionDuration??0,u=c/o.duration;let d=n;(t.autoTransition===void 0||t.autoTransition===!0)&&(d=(n+1)%e.length),a.push({exitTime:1-u,offset:0,duration:c,hasExitTime:!0,destinationState:d,conditions:[]})}const l={name:o.name,hash:n,motion:{name:o.name,clip:o,isLooping:t?.looping??!1},transitions:a,behaviours:[]};s.push(l)}const r={name:"AnimatorController",guid:new cr(Date.now()).generateUUID(),parameters:[],layers:[{name:"Base Layer",stateMachine:{defaultState:0,states:s}}]};return new vo(r)}play(e,t=-1,s=Number.NEGATIVE_INFINITY,r=0){if(t<0)t=0;else if(t>=this.model.layers.length){console.warn("invalid layer");return}const n=this.model.layers[t].stateMachine;for(const o of n.states)if(o.name===e||o.hash===e){yn&&console.log("transition to ",o),this.transitionTo(o,r,s);return}console.warn("Could not find "+e+" to play")}reset(){this.setStartTransition()}setBool(e,t){var s,r;const n=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[n]===e).forEach(o=>o.value=t)}getBool(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??!1}setFloat(e,t){var s,r;const n=typeof e=="string"?"name":"hash",o=(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(a=>a[n]===e);return o.forEach(a=>a.value=t),o?.length>0}getFloat(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??0}setInteger(e,t){var s,r;const n=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[n]===e).forEach(o=>o.value=t)}getInteger(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??0}setTrigger(e){var t,s;yn&&console.log("SET TRIGGER",e);const r=typeof e=="string"?"name":"hash";return(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.filter(n=>n[r]===e).forEach(n=>n.value=!0)}resetTrigger(e){var t,s;const r=typeof e=="string"?"name":"hash";return(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.filter(n=>n[r]===e).forEach(n=>n.value=!1)}getTrigger(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??!1}isInTransition(){return this._activeStates.length>1}setSpeed(e){this._speed=e}FindState(e){return this.findState(e)}findState(e){if(!e)return null;if(Array.isArray(this.model.layers)){for(const t of this.model.layers)for(const s of t.stateMachine.states)if(s.name===e||s.hash==e)return s}return null}get context(){var e;return(e=this.animator)==null?void 0:e.context}get mixer(){return this._mixer}bind(e){e?this.animator!==e&&(this.animator=e,this._mixer=new O0(this.animator.gameObject),this.createActions(this.animator)):console.error("AnimatorController.bind: animator is null")}clone(){if(typeof this.model=="string")return console.warn("AnimatorController has not been resolved, can not create model from string",this.model),null;yn&&console.warn("AnimatorController clone()",this.model);const e=og(this.model,(t,s,r)=>r==null?!0:!(r.type==="Object3D"||r.isObject3D===!0||BN(r)||r.tracks!==void 0||r instanceof vo));return console.assert(e!==this.model),new vo(e)}update(e){var t,s;if(!this.animator)return;this.evaluateTransitions(),this.updateActiveStates(e);const r=this.animator.context.time.deltaTime;this.animator.applyRootMotion&&((t=this.rootMotionHandler)==null||t.onBeforeUpdate(e)),this._mixer.update(r),this.animator.applyRootMotion&&((s=this.rootMotionHandler)==null||s.onAfterUpdate(e))}get activeState(){return this._activeState}updateActiveStates(e){for(let t=0;t<this._activeStates.length;t++){const s=this._activeStates[t],r=s.motion;if(!r.action)this._activeStates.splice(t,1),t--;else{const n=r.action;n.weight=e,n.getEffectiveWeight()<=0&&!n.isRunning()&&(yn&&console.debug("REMOVE",s.name,n.getEffectiveWeight(),n.isRunning(),n.isScheduled()),this._activeStates.splice(t,1),t--)}}}setStartTransition(){for(const e of this.model.layers){const t=e.stateMachine;t.defaultState===void 0&&(yn&&console.warn("AnimatorController default state is undefined, will assign state 0 as default",e),t.defaultState=0);const s=t.states[t.defaultState];this.transitionTo(s,0,this.normalizedStartOffset)}}evaluateTransitions(){var e;let t=!1;if(!this._activeState){if(this.setStartTransition(),!this._activeState)return;t=!0}const s=this._activeState,r=s.motion.action;for(const o of s.transitions){if(!o.hasExitTime&&o.conditions.length<=0)continue;let a=!0;for(const l of o.conditions)if(!this.evaluateCondition(l)){a=!1;break}if(a)if(r){const l=s.motion.clip.duration,c=l<=0?1:Math.abs(r.time/l);let u=!1;if(o.hasExitTime?r.timeScale>0?u=c>=o.exitTime:r.timeScale<0&&(u=1-c>=o.exitTime):u=!0,u){for(const d of o.conditions){const p=this.model.parameters.find(f=>f.name===d.parameter);p?.type===AI.Trigger&&p.value&&(p.value=!1)}r.clampWhenFinished=!0,yn&&console.log("transition to "+o.destinationState,o,c,o.exitTime,o.hasExitTime),this.transitionTo(o.destinationState,o.duration,o.offset);return}}else{this.transitionTo(o.destinationState,o.duration,o.offset);return}}if(r){let o=s.speed??1;s.speedParameter&&(o*=this.getFloat(s.speedParameter)),o!==void 0&&(r.timeScale=o*this._speed)}let n=!1;if(s.motion.isLooping&&r&&(r.time>=r.getClip().duration?(n=!0,r.reset(),r.time=0,r.play()):r.time<=0&&r.timeScale<0&&(n=!0,r.reset(),r.time=r.getClip().duration,r.play())),!n&&s&&!t&&r&&this.animator&&s.behaviours){const o=r?.getClip().duration,a=r.time/o,l=new Y_(this._activeState,a,o,this._speed);for(const c of s.behaviours)c.instance&&((e=c.instance.onStateUpdate)==null||e.call(c.instance,this.animator,l,0))}}getState(e,t){return typeof e=="number"&&(e==-1&&(e=this.model.layers[t].stateMachine.defaultState,e===void 0&&(yn&&console.warn("AnimatorController default state is undefined: ",this.model,"Layer: "+t),e=0)),e=this.model.layers[t].stateMachine.states[e]),e}transitionTo(e,t,s){var r,n,o,a,l,c,u,d;if(!this.animator)return;const p=0;if(e=this.getState(e,p),!(e!=null&&e.motion)||!e.motion.clip||!(e.motion.clip instanceof Ln))return;const f=this._activeState===e;if(f){const g=e.motion;if(!g.action_loopback&&g.clip){const v=this.rootMotionHandler?this.animator.gameObject.matrix.clone():null;this._mixer.uncacheAction(g.clip,this.animator.gameObject),v&&v.decompose(this.animator.gameObject.position,this.animator.gameObject.quaternion,this.animator.gameObject.scale),g.action_loopback=this.createAction(g.clip)}}if((r=this._activeState)!=null&&r.behaviours&&this._activeState.motion.action){const g=(n=this._activeState)==null?void 0:n.motion.clip.duration,v=this._activeState.motion.action.time/g,b=new Y_(this._activeState,v,g,this._speed);for(const _ of this._activeState.behaviours)(a=(o=_.instance)==null?void 0:o.onStateExit)==null||a.call(_.instance,this.animator,b,p)}const m=(l=this._activeState)==null?void 0:l.motion.action;m&&m.fadeOut(t),f&&(e.motion.action=e.motion.action_loopback,e.motion.action_loopback=m);const A=this._activeState;this._activeState=e;const y=(c=e.motion)==null?void 0:c.action;if(y){if(s=Math.max(0,Math.min(1,s)),e.cycleOffsetParameter){let v=this.getFloat(e.cycleOffsetParameter);typeof v=="number"?(v<0&&(v+=1),s+=v,s%=1):yn&&console.warn("AnimatorController cycle offset parameter is not a number",e.cycleOffsetParameter)}else typeof e.cycleOffset=="number"&&(s+=e.cycleOffset,s%=1);y.isRunning()&&y.stop(),y.reset(),y.enabled=!0;const g=e.motion.clip.duration;if(y.time=f?0:s*g,y.timeScale<0&&(y.time=g-y.time),y.clampWhenFinished=!0,y.setLoop(xm,0),t>0?y.fadeIn(t):y.weight=1,y.play(),this.rootMotionHandler&&this.rootMotionHandler.onStart(y),this._activeStates.includes(e)||this._activeStates.push(e),this._activeState.behaviours){const v=new Y_(e,s,g,this._speed);for(const b of this._activeState.behaviours)(d=(u=b.instance)==null?void 0:u.onStateEnter)==null||d.call(b.instance,this.animator,v,p)}}else yn&&(e.__warned_no_motion||(e.__warned_no_motion=!0,console.warn("No action",e.motion,this)));yn&&console.log("TRANSITION FROM "+A?.name+" TO "+e.name,t,m,y,y?.getEffectiveTimeScale(),y?.getEffectiveWeight(),y?.isRunning(),y?.isScheduled(),y?.paused)}createAction(e){var t,s;if(this._mixer.existingAction(e)&&this._mixer.uncacheAction(e,(t=this.animator)==null?void 0:t.gameObject),(s=this.animator)!=null&&s.applyRootMotion){this.rootMotionHandler||(this.rootMotionHandler=new rre(this));const r=this.animator.gameObject;return this.rootMotionHandler.createClip(this._mixer,r,e)}else return this._mixer.clipAction(e)}evaluateCondition(e){const t=this.model.parameters.find(s=>s.name===e.parameter);if(!t)return!1;switch(e.mode){case Ih.If:return t.value===!0;case Ih.IfNot:return t.value===!1;case Ih.Greater:return t.value>e.threshold;case Ih.Less:return t.value<e.threshold;case Ih.Equals:return t.value===e.threshold;case Ih.NotEqual:return t.value!==e.threshold}return!1}createActions(e){var t,s,r,n;yn&&console.log("AnimatorController createActions",this.model);for(const o of this.model.layers){const a=o.stateMachine;for(let l=0;l<a.states.length;l++){const c=a.states[l];c.transitions||(c.transitions=[]);for(const u of c.transitions)u.conditions||(u.conditions=[]);if(c.motion||(c.motion=$z(c.name)),this.animator&&c.motion.clips){const u=(t=c.motion.clips)==null?void 0:t.find(d=>{var p,f;return d.node.name===((f=(p=this.animator)==null?void 0:p.gameObject)==null?void 0:f.name)});u?c.motion.clip=u.clip:(yn||wt())&&console.warn('Could not find clip for animator "'+((r=(s=this.animator)==null?void 0:s.gameObject)==null?void 0:r.name)+'"',c.motion.clips.map(d=>d.node.name))}if(!c.motion.clip){const u=new Ln(void 0,void 0,[]);c.motion.clip=u}if((n=c.motion)!=null&&n.clip){const u=c.motion.clip;if(u instanceof Ln){const d=this.createAction(u);c.motion.action=d}else(yn||wt())&&console.warn("No valid animationclip assigned",c)}if(c.behaviours&&Array.isArray(c.behaviours))for(const u of c.behaviours){if(!(u!=null&&u.typeName))continue;const d=J.get(u.typeName),p=new d;p.isStateMachineBehaviour&&(p._context=this.context??void 0,zp(p,u.properties),u.instance=p),yn&&console.log("Created animator controller behaviour",c.name,u.typeName,u.properties,p)}}}}*enumerateActions(){if(this.model.layers)for(const e of this.model.layers){const t=e.stateMachine;for(let s=0;s<t.states.length;s++){const r=t.states[s];r!=null&&r.motion&&(r.motion.action&&(yield r.motion.action),r.motion.action_loopback&&(yield r.motion.action_loopback))}}}}class ej{constructor(e,t){h(this,"track"),h(this,"createdInterpolant"),h(this,"originalEvaluate"),h(this,"customEvaluate"),this.track=e;const s=e,r=s.createInterpolant.bind(e);s.createInterpolant=()=>(s.createInterpolant=r,this.createdInterpolant=r(),this.originalEvaluate=this.createdInterpolant.evaluate.bind(this.createdInterpolant),this.customEvaluate=n=>{if(!this.originalEvaluate)return;const o=this.originalEvaluate(n);return t(n,o)},this.createdInterpolant.evaluate=this.customEvaluate,this.createdInterpolant)}dispose(){this.createdInterpolant&&this.originalEvaluate&&(this.createdInterpolant.evaluate=this.originalEvaluate),this.track=void 0,this.createdInterpolant=null,this.originalEvaluate=void 0,this.customEvaluate=void 0}}const rr=class{constructor(i,e,t,s,r){if(h(this,"_action"),h(this,"root"),h(this,"clip"),h(this,"positionWrapper",null),h(this,"rotationWrapper",null),h(this,"context"),h(this,"positionChange",new w),h(this,"rotationChange",new Ie),h(this,"_prevTime",0),this.context=i,this.root=e,this.clip=t,rr.firstKeyframeRotation[this.cacheId]||(rr.firstKeyframeRotation[this.cacheId]=new Ie),r){const n=r.values;rr.firstKeyframeRotation[this.cacheId].set(n[0],n[1],n[2],n[3])}rr.spaceRotation[this.cacheId]||(rr.spaceRotation[this.cacheId]=new Ie),rr.effectiveSpaceRotation[this.cacheId]||(rr.effectiveSpaceRotation[this.cacheId]=new Ie),rr.clipOffsetRotation[this.cacheId]=new Ie,r&&rr.clipOffsetRotation[this.cacheId].set(r.values[0],r.values[1],r.values[2],r.values[3]).invert(),this.handlePosition(t,s),this.handleRotation(t,r)}set action(i){this._action=i}get action(){return this._action}get cacheId(){return this.root.uuid}onStart(i){if(i.getClip()!==this.clip)return;rr.lastObjRotation[this.cacheId]||(rr.lastObjRotation[this.cacheId]=this.root.quaternion.clone());const e=rr.lastObjRotation[this.cacheId];if(rr.spaceRotation[this.cacheId].copy(e),J_){const t=new Ur().setFromQuaternion(e);console.log("START",this.clip.name,st.toDegrees(t.y),this.root.position.z)}}getClipRotationOffset(){return rr.clipOffsetRotation[this.cacheId]}handlePosition(i,e){if(e){const t=this.root;J_&&t.add(new wo),rr.lastObjPosition[this.cacheId]||(rr.lastObjPosition[this.cacheId]=this.root.position.clone());const s=new w,r=new w;this.positionWrapper=new ej(e,(n,o)=>{const a=this.action.getEffectiveWeight();return J_&&t.position.length()>8&&t.position.set(0,t.position.y,0),n>this._prevTime&&(s.set(o[0],o[1],o[2]),s.sub(r),s.multiplyScalar(a),s.applyQuaternion(this.getClipRotationOffset()),s.applyQuaternion(t.quaternion),this.positionChange.copy(s)),r.fromArray(o),this._prevTime=n,o[0]=0,o[1]=0,o[2]=0,o})}}handleRotation(i,e){if(e){if(J_){const n=e.values,o=new Ur().setFromQuaternion(new Ie(n[0],n[1],n[2],n[3]));console.log(i.name,e.name,"FIRST ROTATION IN TRACK",st.toDegrees(o.y));const a=e.values.length-4,l=new Ie().set(n[a],n[a+1],n[a+2],n[a+3]),c=new Ur().setFromQuaternion(l);console.log(i.name,e.name,"LAST ROTATION IN TRACK",st.toDegrees(c.y))}let t=0;const s=new Ie,r=new Ie;this.rotationWrapper=new ej(e,(n,o)=>(n>t&&(r.set(o[0],o[1],o[2],o[3]),s.invert(),r.multiply(s),this.rotationChange.copy(r)),s.fromArray(o),t=n,o[0]=0,o[1]=0,o[2]=0,o[3]=1,o))}}onBeforeUpdate(i){this.positionChange.set(0,0,0),this.rotationChange.set(0,0,0,1)}onAfterUpdate(i){return!this.action||(i*=this.action.getEffectiveWeight(),i<=0)?!1:(this.positionChange.multiplyScalar(i),this.rotationChange.slerp(rr.identityQuaternion,1-i),!0)}};let Rh=rr;h(Rh,"lastObjPosition",{}),h(Rh,"lastObjRotation",{}),h(Rh,"firstKeyframeRotation",{}),h(Rh,"spaceRotation",{}),h(Rh,"effectiveSpaceRotation",{}),h(Rh,"clipOffsetRotation",{}),h(Rh,"identityQuaternion",new Ie);class rre{constructor(e){h(this,"controller"),h(this,"handler",[]),h(this,"root"),h(this,"basePosition",new w),h(this,"baseQuaternion",new Ie),h(this,"baseRotation",new Ur),h(this,"summedPosition",new w),h(this,"summedRotation",new Ie),this.controller=e}createClip(e,t,s){this.root=t,t&&"name"in t&&t.name;const r=this.findRootTrack(s,".position"),n=this.findRootTrack(s,".quaternion"),o=new Rh(this.controller.context,t,s,r,n);this.handler.push(o);const a=e.clipAction(s);return o.action=a,a}onStart(e){for(const t of this.handler)t.onStart(e)}onBeforeUpdate(e){this.basePosition.copy(this.root.position),this.baseQuaternion.copy(this.root.quaternion);for(const t of this.handler)t.onBeforeUpdate(e)}onAfterUpdate(e){if(!(e<=0)){this.root.position.copy(this.basePosition),this.root.quaternion.copy(this.baseQuaternion),this.summedPosition.set(0,0,0),this.summedRotation.set(0,0,0,1);for(const t of this.handler)t.onAfterUpdate(e)&&(this.summedPosition.add(t.positionChange),this.summedRotation.multiply(t.rotationChange));this.root.position.add(this.summedPosition),this.root.quaternion.multiply(this.summedRotation)}}findRootTrack(e,t){const s=e.tracks;if(!s)return null;for(const r of s)if(r.name.endsWith(t))return r;return null}}class nre extends Kl{onSerialize(e,t){}onDeserialize(e,t){if(t.type===vo&&e?.__type==="AnimatorController")return new vo(e)}}new nre(vo);var ore=Object.defineProperty,are=Object.getOwnPropertyDescriptor,K_=(i,e,t,s)=>{for(var r=s>1?void 0:s?are(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&ore(e,t,r),r};const Go=te("debuganimator");class Er extends Pe{constructor(){super(...arguments),h(this,"applyRootMotion",!1),h(this,"hasRootMotion",!1),h(this,"keepAnimatorControllerStateOnDisable",!1),h(this,"_parametersAreDirty",!1),h(this,"_isDirty",!1),h(this,"speed",1),h(this,"normalizedStartOffset",0),h(this,"_animatorController",null),h(this,"_initializeWithRuntimeAnimatorController")}set runtimeAnimatorController(e){var t;this._animatorController&&this._animatorController.model===e||(e?e instanceof vo?(e.animator&&e.animator!==this&&(console.warn("AnimatorController can not be bound to multiple animators",(t=e.model)==null?void 0:t.name),e.model||console.error("AnimatorController has no model"),e=new vo(e.model)),this._animatorController=e,this._animatorController.bind(this)):(Go&&console.log("Assign animator controller",e,this),this._animatorController=new vo(e),this.__didAwake&&this._animatorController.bind(this)):this._animatorController=null)}get runtimeAnimatorController(){return this._animatorController}get parametersAreDirty(){return this._parametersAreDirty}get isDirty(){return this._isDirty}Play(e,t=-1,s=Number.NEGATIVE_INFINITY,r=0){this.play(e,t,s,r)}play(e,t=-1,s=Number.NEGATIVE_INFINITY,r=0){var n;(n=this.runtimeAnimatorController)==null||n.play(e,t,s,r),this._isDirty=!0}Reset(){this.reset()}reset(){var e;(e=this._animatorController)==null||e.reset(),this._isDirty=!0}SetBool(e,t){this.setBool(e,t)}setBool(e,t){var s,r;Go&&console.log("setBool",e,t),((s=this.runtimeAnimatorController)==null?void 0:s.getBool(e))!==t&&(this._parametersAreDirty=!0),(r=this.runtimeAnimatorController)==null||r.setBool(e,t)}GetBool(e){return this.getBool(e)}getBool(e){var t;const s=((t=this.runtimeAnimatorController)==null?void 0:t.getBool(e))??!1;return Go&&console.log("getBool",e,s),s}toggleBool(e){this.setBool(e,!this.getBool(e))}SetFloat(e,t){this.setFloat(e,t)}setFloat(e,t){var s,r;((s=this.runtimeAnimatorController)==null?void 0:s.getFloat(e))!==t&&(this._parametersAreDirty=!0),Go&&console.log("setFloat",e,t),(r=this.runtimeAnimatorController)==null||r.setFloat(e,t)}GetFloat(e){return this.getFloat(e)}getFloat(e){var t;const s=((t=this.runtimeAnimatorController)==null?void 0:t.getFloat(e))??-1;return Go&&console.log("getFloat",e,s),s}SetInteger(e,t){this.setInteger(e,t)}setInteger(e,t){var s,r;((s=this.runtimeAnimatorController)==null?void 0:s.getInteger(e))!==t&&(this._parametersAreDirty=!0),Go&&console.log("setInteger",e,t),(r=this.runtimeAnimatorController)==null||r.setInteger(e,t)}GetInteger(e){return this.getInteger(e)}getInteger(e){var t;const s=((t=this.runtimeAnimatorController)==null?void 0:t.getInteger(e))??-1;return Go&&console.log("getInteger",e,s),s}SetTrigger(e){this.setTrigger(e)}setTrigger(e){var t;this._parametersAreDirty=!0,Go&&console.log("setTrigger",e),(t=this.runtimeAnimatorController)==null||t.setTrigger(e)}ResetTrigger(e){this.resetTrigger(e)}resetTrigger(e){var t;this._parametersAreDirty=!0,Go&&console.log("resetTrigger",e),(t=this.runtimeAnimatorController)==null||t.resetTrigger(e)}GetTrigger(e){this.getTrigger(e)}getTrigger(e){var t;const s=(t=this.runtimeAnimatorController)==null?void 0:t.getTrigger(e);return Go&&console.log("getTrigger",e,s),s}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&&(Go&&console.log("setSpeed",e),this.speed=e,(t=this._animatorController)==null||t.setSpeed(e))}set minMaxSpeed(e){this.speed=st.lerp(e.x,e.y,Math.random())}set minMaxOffsetNormalized(e){this.normalizedStartOffset=st.lerp(e.x,e.y,Math.random()),this.runtimeAnimatorController&&(this.runtimeAnimatorController.normalizedStartOffset=this.normalizedStartOffset)}awake(){Go&&console.log("ANIMATOR",this.name,this),this.gameObject&&this.initializeRuntimeAnimatorController()}initializeRuntimeAnimatorController(e=!1){const t=e||this.runtimeAnimatorController!==this._initializeWithRuntimeAnimatorController;if(this.runtimeAnimatorController&&t){const s=this.runtimeAnimatorController.clone();this._initializeWithRuntimeAnimatorController=s,s?(console.assert(this.runtimeAnimatorController!==s),this.runtimeAnimatorController=s,console.assert(this.runtimeAnimatorController===s),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._isDirty=!1,this._parametersAreDirty=!1,!tre(this.gameObject)&&this._animatorController&&this._animatorController.update(1)}}K_([x()],Er.prototype,"applyRootMotion",2),K_([x()],Er.prototype,"hasRootMotion",2),K_([x()],Er.prototype,"keepAnimatorControllerStateOnDisable",2),K_([x()],Er.prototype,"runtimeAnimatorController",1);const wf=te("debugusdzanimation"),yI=te("debugusdzanimationserialization");class Z_{constructor(e,t,s){h(this,"_start"),h(this,"ext"),h(this,"root"),h(this,"clip"),this.ext=e,this.root=t,this.clip=s}get start(){return this._start===void 0&&(this._start=this.ext.getStartTime01(this.root,this.clip)),this._start}get duration(){return this.clip.duration}}class Qo{constructor(e,t,s){h(this,"clip"),h(this,"pos"),h(this,"rot"),h(this,"scale"),h(this,"root"),h(this,"target"),h(this,"duration",0),h(this,"useRootMotion",!1),this.root=e,this.target=t,this.clip=s,s?this.duration=s.duration:this.duration=1/this.frameRate;const r=oe.getComponent(e,Er);r&&(this.useRootMotion=r.applyRootMotion)}get frameRate(){return 60}addTrack(e){if(!this.clip){console.error("This is a rest clip but you're trying to add tracks to it \u2013 this is likely a bug");return}e.name.endsWith("position")&&(this.pos=e),e.name.endsWith("quaternion")&&(this.rot=e),e.name.endsWith("scale")&&(this.scale=e)}getFrames(){var e,t,s,r,n,o;return this.clip?Math.max(((t=(e=this.pos)==null?void 0:e.times)==null?void 0:t.length)??0,((r=(s=this.rot)==null?void 0:s.times)==null?void 0:r.length)??0,((o=(n=this.scale)==null?void 0:n.times)==null?void 0:o.length)??0):2}getDuration(){return this.duration}getSortedTimesArray(e=!0,t=!0,s=!0){var r,n,o;if(!this.clip)return[0,this.duration];const a=(r=this.pos)==null?void 0:r.times,l=(n=this.rot)==null?void 0:n.times,c=(o=this.scale)==null?void 0:o.times,u=[];if(e&&a)for(const d of a)u.push(d);if(t&&l)for(const d of l)u.push(d);if(s&&c)for(const d of c)u.push(d);return u.includes(0)||u.push(0),u.sort((d,p)=>d-p),[...new Set(u)]}*getValues(e,t=!0,s=!0,r=!0){var n,o,a;const l=new w,c=new Ie,u=new w(1,1,1),d=this.target,p=t?(n=this.pos)==null?void 0:n.createInterpolant():void 0,f=s?(o=this.rot)==null?void 0:o.createInterpolant():void 0,m=r?(a=this.scale)==null?void 0:a.createInterpolant():void 0;p||l.set(d.position.x,d.position.y,d.position.z),f||c.set(d.quaternion.x,d.quaternion.y,d.quaternion.z,d.quaternion.w),m||u.set(d.scale.x,d.scale.y,d.scale.z);for(let A=0;A<e.length;A++){const y=e[A];if(p){const g=p.evaluate(y);l.set(g[0],g[1],g[2])}if(f){const g=f.evaluate(y);c.set(g[0],g[1],g[2],g[3])}if(m){const g=m.evaluate(y);u.set(g[0],g[1],g[2])}if(this.useRootMotion&&d===this.root){const g=new Te;g.compose(l,c,u),g.multiply(d.matrix),g.decompose(l,c,u)}yield{time:y,translation:l,rotation:c,scale:u,index:A}}}}h(Qo,"animationDurationPadding",1);class Ov{constructor(e){h(this,"dict",new Map),h(this,"rootTargetMap",new Map),h(this,"rootAndClipToRegisteredAnimationMap",new Map),h(this,"rootToRegisteredClipCount",new Map),h(this,"serializers",[]),h(this,"injectRestPoses",!1),h(this,"injectImplicitBehaviours",!1),this.injectRestPoses=e,this.injectImplicitBehaviours=e}get extensionName(){return"animation"}getClipCount(e){let t=this.rootToRegisteredClipCount.get(e);return this.injectRestPoses&&(t=t?t-1:0),t??0}getStartTime01(e,t){const s=this.rootTargetMap.get(e);if(!s)return 0;const r=this.dict.get(s[0]);if(!r)return console.error("Trying to get start time for root that has no animation data",e,t,...this.dict),0;let n=0;for(let o=0;o<r.length&&r[o].clip!==t;o++)n+=r[o].getDuration()+Qo.animationDurationPadding;return n}registerAnimation(e,t){if(!t||!e)return null;this.rootTargetMap.has(e)||this.rootTargetMap.set(e,[]);const s=e.uuid+t.uuid;if(this.rootAndClipToRegisteredAnimationMap.has(s))return this.rootAndClipToRegisteredAnimationMap.get(s);wf&&console.log("registerAnimation",e,t);const r=this.injectRestPoses?1:0,n=this.rootToRegisteredClipCount.get(e)??r,o=this.rootTargetMap.get(e),a=new Set(o);if(t.tracks)for(const c of t.tracks){const u=Xt.parseTrackName(c.name),d=Xt.findNode(e,u.nodeName);if(!d){console.warn("no object found for track",c.name,"using "+e.name+" instead");continue}this.dict.has(d)||this.dict.set(d,[]);const p=this.dict.get(d);if(!p)continue;if(a.delete(d),this.injectRestPoses&&!p[0]){const m=new Qo(null,d,void 0);p[0]=m}let f=p[n];f||(f=new Qo(e,d,t),p[n]=f),f.addTrack(c),o!=null&&o.includes(d)||o==null||o.push(d)}for(const c of a){const u=this.dict.get(c);if(!u)continue;if(this.injectRestPoses&&!u[0]){const p=new Qo(null,c,void 0);u[0]=p}let d=u[n];d||(wf&&console.log("Adding padding clip for ",c,t),d=new Qo(e,c,t),u[n]=d)}const l=new Z_(this,e,t);return this.rootAndClipToRegisteredAnimationMap.set(s,l),this.rootToRegisteredClipCount.set(e,n+1),l}onAfterHierarchy(e){wf&&console.log("Animation clips per animation target node",this.dict)}onAfterBuildDocument(e){var t,s;for(const r of this.serializers){const n=(t=r.model)==null?void 0:t.parent,o=n?.isDynamic===!0;yI&&console.log(o,(s=r.model)==null?void 0:s.parent),o&&r.registerCallback(n)}}onExportObject(e,t,s){oe.foreachComponent(e,n=>{const o=n;typeof o.createAnimation=="function"&&o.createAnimation(this,t,s)},!1);const r=new lre(e,this.dict);this.serializers.push(r),r.registerCallback(t)}}class lre{constructor(e,t){h(this,"object"),h(this,"dict"),h(this,"model"),h(this,"callback"),this.object=e,this.dict=t}registerCallback(e){this.model&&this.callback&&this.model.removeEventListener("serialize",this.callback),this.callback||(this.callback=this.onSerialize.bind(this)),yI&&console.log("REPARENT",e),this.model=e,this.model.addEventListener("serialize",this.callback)}skinnedMeshExport(e,t){const s=this.model,r=this.dict;if(s&&s.skinnedMesh){let n=function(C){const R=[];for(const[I,E]of C){let z=`${I} : [`;const F=[];for(const q of E)F.push(`(${ir(q.x)}, ${ir(q.y)}, ${ir(q.z)})`);z=z.concat(F.join(", ")),z=z.concat("],"),R.push(z)}return R},o=function(C){const R=[];for(const[I,E]of C){let z=`${I} : [`;const F=[];for(const q of E)F.push(`(${ir(q.w)}, ${ir(q.x)}, ${ir(q.y)}, ${ir(q.z)})`);z=z.concat(F.join(", ")),z=z.concat("],"),R.push(z)}return R},a=function(C){let R=!0,I;for(const[z,F]of C)if(I===void 0&&(I=F.length),I!==F.length){R=!1;break}wf&&console.log("Bone count: ",C.size,"TransformData entries per bone: ",I),console.assert(R,"All bones should have the same number of TransformData entries",C);const E=[];for(const[z,F]of C){const q=new Array;let N=0;for(let H=0;H<F.length;H++)q.push(N),N+=F[H].getDuration()+Qo.animationDurationPadding;for(let H=0;H<F.length;H++){const L=F[H],j=q[H];E.length<=H&&E.push({pos:[],rot:[],scale:[],timeOffset:j});const Q=E[H];Q.pos.push(...L.getSortedTimesArray(!0,!1,!1)),Q.rot.push(...L.getSortedTimesArray(!1,!0,!1)),Q.scale.push(...L.getSortedTimesArray(!1,!1,!0))}}for(const z of E)z.pos.sort((F,q)=>F-q),z.rot.sort((F,q)=>F-q),z.scale.sort((F,q)=>F-q),z.pos=[...new Set(z.pos)],z.rot=[...new Set(z.rot)],z.scale=[...new Set(z.scale)];return E},l=function(C,R,I){const E=new Map,z=new Map,F=new Map,q=R.length;for(const N of I){const H=C.get(N);let L;H?console.assert(H.length===q,"We should have the same number of TransformData entries for each bone",H,R):L=new Qo(null,N,void 0);for(let j=0;j<q;j++){const Q=H?H[j]:L,$=R[j];for(const{time:Z,translation:se}of Q.getValues($.pos,!0,!1,!1)){const Ae=(Z+$.timeOffset)*60;E.has(Ae)||E.set(Ae,new Array),E.get(Ae).push(se.clone())}for(const{time:Z,rotation:se}of Q.getValues($.rot,!1,!0,!1)){const Ae=(Z+$.timeOffset)*60;z.has(Ae)||z.set(Ae,new Array),z.get(Ae).push(se.clone())}for(const{time:Z,scale:se}of Q.getValues($.scale,!1,!1,!0)){const Ae=(Z+$.timeOffset)*60;F.has(Ae)||F.set(Ae,new Array),F.get(Ae).push(se.clone())}}}return{position:E.size==0?void 0:E,quaternion:z.size==0?void 0:z,scale:F.size==0?void 0:F}},c=function(C){const R=[];for(const I of C)R.push(`(${ir(I.x)}, ${ir(I.y)}, ${ir(I.z)})`);return R.join(", ")},u=function(C){const R=[];for(const I of C)R.push(`(${ir(I.w)}, ${ir(I.x)}, ${ir(I.y)}, ${ir(I.z)})`);return R.join(", ")},d=function(C){const R=new Map;if(wf){const I=new Array;for(const[E,z]of r)I.push(E.uuid+": "+z.length+" "+z.map(F=>{var q;return(q=F.clip)==null?void 0:q.uuid.substring(0,6)}).join(" "));console.log(`getPerBoneTransformData
|
|
5410
|
+
Using the assigned clip instead:`,this.clip),i=this.clip);let r=!this.sound||i&&i!==this.clip;if(typeof i=="string"&&!this.audioLoader&&(r=!0),(i instanceof MediaStream||typeof i=="string")&&(this.clip=i),r){this.shouldPlay=!0,this.onNewClip(i);return}if(this.shouldPlay=!0,this._hasEnded=!1,$r&&console.log("play",(e=this.sound)==null?void 0:e.getVolume(),this.sound),this.sound&&!this.sound.isPlaying){const n=this.context.application.muted;n&&this.sound.setVolume(0),(t=this.gameObject)==null||t.add(this.sound),this.clip instanceof MediaStream?(this.sound.setMediaStreamSource(this.clip),this._audioElement||(this._audioElement=document.createElement("audio"),this._audioElement.style.display="none"),this._audioElement.parentNode||(s=this.context.domElement.shadowRoot)==null||s.append(this._audioElement),this._audioElement.srcObject=this.clip,this._audioElement.autoplay=!1):(this._audioElement&&this._audioElement.remove(),this.sound.play(n?.1:0))}}pause(){var i,e;$r&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.isPlaying&&this.sound.source&&(this._lastContextTime=(i=this.sound)==null?void 0:i.context.currentTime,this.sound.pause()),(e=this._audioElement)==null||e.remove()}stop(){var i,e;$r&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.source&&(this._lastContextTime=(i=this.sound)==null?void 0:i.context.currentTime,$r&&console.log(this._lastContextTime),this.sound.stop()),(e=this._audioElement)==null||e.remove()}get isPlaying(){var i;return((i=this.sound)==null?void 0:i.isPlaying)??!1}set isPlaying(i){}get time(){var i,e;return(i=this.sound)!=null&&i.source?((e=this.sound.source)==null?void 0:e.context.currentTime)-this._lastContextTime+this.sound.offset:0}set time(i){if(this.sound){if(i===this.sound.offset)return;const e=this.isPlaying;this.stop(),this.sound.offset=i,e&&this.play()}}update(){this.helper&&(this.isPlaying&&this.helper.update(),this.helper.visible=this.isPlaying),this._needUpdateSpatialDistanceSettings&&this.applySpatialDistanceSettings(),this.sound&&!this.sound.isPlaying&&this.shouldPlay&&!this._hasEnded&&(this._hasEnded=!0,$r&&console.log("Audio clip ended",this.clip),this.dispatchEvent(new CustomEvent("ended",{detail:this})))}};let vs=Ch;Za([x(URL)],vs.prototype,"clip",2),Za([x()],vs.prototype,"playOnAwake",2),Za([x()],vs.prototype,"preload",2),Za([x()],vs.prototype,"loop",1),Za([x()],vs.prototype,"spatialBlend",1),Za([x()],vs.prototype,"minDistance",1),Za([x()],vs.prototype,"maxDistance",1),Za([x()],vs.prototype,"volume",1),Za([x()],vs.prototype,"rollOffMode",2),Za([x()],vs.prototype,"playInBackground",2);const jz={type:"change"},aI={type:"start"},Gz={type:"end"},L_=new Wn,Qz=new ln,_se=Math.cos(70*js.DEG2RAD);let xse=class extends Ks{constructor(i,e){super(),this.object=i,this.domElement=e,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new w,this.cursor=new w,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=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.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:tu.ROTATE,MIDDLE:tu.DOLLY,RIGHT:tu.PAN},this.touches={ONE:iu.ROTATE,TWO:iu.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return o.phi},this.getAzimuthalAngle=function(){return o.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(W){W.addEventListener("keydown",nt),this._domElementKeyEvents=W},this.stopListenToKeyEvents=function(){this._domElementKeyEvents.removeEventListener("keydown",nt),this._domElementKeyEvents=null},this.saveState=function(){t.target0.copy(t.target),t.position0.copy(t.object.position),t.zoom0=t.object.zoom},this.reset=function(){t.target.copy(t.target0),t.object.position.copy(t.position0),t.object.zoom=t.zoom0,t.object.updateProjectionMatrix(),t.dispatchEvent(jz),t.update(),r=s.NONE},this.update=function(){const W=new w,T=new Ie().setFromUnitVectors(i.up,new w(0,1,0)),B=T.clone().invert(),G=new w,V=new Ie,k=new w,Y=2*Math.PI;return function(ce=null){const me=t.object.getWorldPosition(i.position);W.copy(me).sub(t.target),W.applyQuaternion(T),o.setFromVector3(W),t.autoRotate&&r===s.NONE&&F(E(ce)),t.enableDamping?(o.theta+=a.theta*t.dampingFactor,o.phi+=a.phi*t.dampingFactor):(o.theta+=a.theta,o.phi+=a.phi);let ge=t.minAzimuthAngle,be=t.maxAzimuthAngle;isFinite(ge)&&isFinite(be)&&(ge<-Math.PI?ge+=Y:ge>Math.PI&&(ge-=Y),be<-Math.PI?be+=Y:be>Math.PI&&(be-=Y),ge<=be?o.theta=Math.max(ge,Math.min(be,o.theta)):o.theta=o.theta>(ge+be)/2?Math.max(ge,o.theta):Math.min(be,o.theta)),o.phi=Math.max(t.minPolarAngle,Math.min(t.maxPolarAngle,o.phi)),o.makeSafe(),t.enableDamping===!0?t.target.addScaledVector(u,t.dampingFactor):t.target.add(u),t.target.sub(t.cursor),t.target.clampLength(t.minTargetRadius,t.maxTargetRadius),t.target.add(t.cursor),t.zoomToCursor&&M||t.object.isOrthographicCamera?o.radius=Z(o.radius):(t.enableDamping?c=js.lerp(c,l,t.dampingFactor):c=l,o.radius=Z(o.radius*c)),W.setFromSpherical(o),W.applyQuaternion(B),me.copy(t.target).add(W),t.object.parent?t.object.parent.worldToLocal(me):t.object.position.copy(me),t.object.lookAt(t.target),t.enableDamping===!0?(a.theta*=1-t.dampingFactor,a.phi*=1-t.dampingFactor,u.multiplyScalar(1-t.dampingFactor)):(a.set(0,0,0),u.set(0,0,0));let Re=!1;if(t.zoomToCursor&&M){let Ve=null;if(t.object.isPerspectiveCamera){const qe=W.length();Ve=Z(qe*l);const Ye=qe-Ve;t.object.position.addScaledVector(_,Ye),t.object.updateMatrixWorld()}else if(t.object.isOrthographicCamera){const qe=new w(S.x,S.y,0);qe.unproject(t.object),t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom/l)),t.object.updateProjectionMatrix(),Re=!0;const Ye=new w(S.x,S.y,0);Ye.unproject(t.object),t.object.position.sub(Ye).add(qe),t.object.updateMatrixWorld(),Ve=W.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),t.zoomToCursor=!1;Ve!==null&&(this.screenSpacePanning?t.target.set(0,0,-1).transformDirection(t.object.matrix).multiplyScalar(Ve).add(t.object.position):(L_.origin.copy(t.object.position),L_.direction.set(0,0,-1).transformDirection(t.object.matrix),Math.abs(t.object.up.dot(L_.direction))<_se?i.lookAt(t.target):(Qz.setFromNormalAndCoplanarPoint(t.object.up,t.target),L_.intersectPlane(Qz,t.target))))}else t.object.isOrthographicCamera&&(Re=l!==1,Re&&(t.object.zoom=Math.max(t.minZoom,Math.min(t.maxZoom,t.object.zoom/l)),t.object.updateProjectionMatrix()));return l=1,M=!1,Re||G.distanceToSquared(t.object.position)>n||8*(1-V.dot(t.object.quaternion))>n||k.distanceToSquared(t.target)>0?(t.dispatchEvent(jz),G.copy(t.object.position),V.copy(t.object.quaternion),k.copy(t.target),!0):!1}}(),this.dispose=function(){t.domElement.removeEventListener("contextmenu",Ot),t.domElement.removeEventListener("pointerdown",U),t.domElement.removeEventListener("pointercancel",ne),t.domElement.removeEventListener("wheel",Le),t.domElement.removeEventListener("pointermove",P),window.removeEventListener("pointerup",ne),t._domElementKeyEvents!==null&&(t._domElementKeyEvents.removeEventListener("keydown",nt),t._domElementKeyEvents=null)};const t=this,s={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let r=s.NONE;const n=1e-6,o=new uC,a=new uC;let l=1,c=1;const u=new w,d=new ee,p=new ee,f=new ee,m=new ee,A=new ee,y=new ee,g=new ee,v=new ee,b=new ee,_=new w,S=new ee;let M=!1;const C=[],R={};let I=!1;function E(W){return W!==null?2*Math.PI/60*t.autoRotateSpeed*W:2*Math.PI/60/60*t.autoRotateSpeed}function z(W){const T=Math.abs(W*.01);return Math.pow(.95,t.zoomSpeed*T)}function F(W){a.theta-=W}function q(W){a.phi-=W}const N=function(){const W=new w;return function(T,B){W.setFromMatrixColumn(B,0),W.multiplyScalar(-T),u.add(W)}}(),H=function(){const W=new w;return function(T,B){t.screenSpacePanning===!0?W.setFromMatrixColumn(B,1):(W.setFromMatrixColumn(B,0),W.crossVectors(t.object.up,W)),W.multiplyScalar(T),u.add(W)}}(),L=function(){const W=new w,T=new w;return function(B,G){const V=t.domElement;if(t.object.isPerspectiveCamera){t.object.getWorldPosition(T),W.copy(T).sub(t.target);let k=W.length();k*=Math.tan(t.object.fov/2*Math.PI/180),N(2*B*k/V.clientHeight,t.object.matrixWorld),H(2*G*k/V.clientHeight,t.object.matrixWorld)}else t.object.isOrthographicCamera?(N(B*(t.object.right-t.object.left)/t.object.zoom/V.clientWidth,t.object.matrixWorld),H(G*(t.object.top-t.object.bottom)/t.object.zoom/V.clientHeight,t.object.matrixWorld)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),t.enablePan=!1)}}();function j(W){t.object.isPerspectiveCamera||t.object.isOrthographicCamera?l/=W:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function Q(W){t.object.isPerspectiveCamera||t.object.isOrthographicCamera?l*=W:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),t.enableZoom=!1)}function $(W,T){if(!t.zoomToCursor)return;M=!0;const B=t.domElement.getBoundingClientRect(),G=W-B.left,V=T-B.top,k=B.width,Y=B.height;S.x=G/k*2-1,S.y=-(V/Y)*2+1,_.set(S.x,S.y,1).unproject(t.object).sub(t.object.position).normalize()}function Z(W){return Math.max(t.minDistance,Math.min(t.maxDistance,W))}function se(W){d.set(W.clientX,W.clientY)}function Ae(W){$(W.clientX,W.clientX),g.set(W.clientX,W.clientY)}function Ue(W){m.set(W.clientX,W.clientY)}function Qe(W){p.set(W.clientX,W.clientY),f.subVectors(p,d).multiplyScalar(t.rotateSpeed);const T=t.domElement;F(2*Math.PI*f.x/T.clientHeight),q(2*Math.PI*f.y/T.clientHeight),d.copy(p),t.update()}function Ke(W){v.set(W.clientX,W.clientY),b.subVectors(v,g),b.y>0?j(z(b.y)):b.y<0&&Q(z(b.y)),g.copy(v),t.update()}function ae(W){A.set(W.clientX,W.clientY),y.subVectors(A,m).multiplyScalar(t.panSpeed),L(y.x,y.y),m.copy(A),t.update()}function Ee(W){$(W.clientX,W.clientY),W.deltaY<0?Q(z(W.deltaY)):W.deltaY>0&&j(z(W.deltaY)),t.update()}function He(W){let T=!1;switch(W.code){case t.keys.UP:W.ctrlKey||W.metaKey||W.shiftKey?q(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):L(0,t.keyPanSpeed),T=!0;break;case t.keys.BOTTOM:W.ctrlKey||W.metaKey||W.shiftKey?q(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):L(0,-t.keyPanSpeed),T=!0;break;case t.keys.LEFT:W.ctrlKey||W.metaKey||W.shiftKey?F(2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):L(t.keyPanSpeed,0),T=!0;break;case t.keys.RIGHT:W.ctrlKey||W.metaKey||W.shiftKey?F(-2*Math.PI*t.rotateSpeed/t.domElement.clientHeight):L(-t.keyPanSpeed,0),T=!0;break}T&&(W.preventDefault(),t.update())}function Fe(W){if(C.length===1)d.set(W.pageX,W.pageY);else{const T=ut(W),B=.5*(W.pageX+T.x),G=.5*(W.pageY+T.y);d.set(B,G)}}function We(W){if(C.length===1)m.set(W.pageX,W.pageY);else{const T=ut(W),B=.5*(W.pageX+T.x),G=.5*(W.pageY+T.y);m.set(B,G)}}function le(W){const T=ut(W),B=W.pageX-T.x,G=W.pageY-T.y,V=Math.sqrt(B*B+G*G);g.set(0,V)}function Ne(W){t.enableZoom&&le(W),t.enablePan&&We(W)}function X(W){t.enableZoom&&le(W),t.enableRotate&&Fe(W)}function Se(W){if(C.length==1)p.set(W.pageX,W.pageY);else{const B=ut(W),G=.5*(W.pageX+B.x),V=.5*(W.pageY+B.y);p.set(G,V)}f.subVectors(p,d).multiplyScalar(t.rotateSpeed);const T=t.domElement;F(2*Math.PI*f.x/T.clientHeight),q(2*Math.PI*f.y/T.clientHeight),d.copy(p)}function _e(W){if(C.length===1)A.set(W.pageX,W.pageY);else{const T=ut(W),B=.5*(W.pageX+T.x),G=.5*(W.pageY+T.y);A.set(B,G)}y.subVectors(A,m).multiplyScalar(t.panSpeed),L(y.x,y.y),m.copy(A)}function Ge(W){const T=ut(W),B=W.pageX-T.x,G=W.pageY-T.y,V=Math.sqrt(B*B+G*G);v.set(0,V),b.set(0,Math.pow(v.y/g.y,t.zoomSpeed)),j(b.y),g.copy(v);const k=(W.pageX+T.x)*.5,Y=(W.pageY+T.y)*.5;$(k,Y)}function ue(W){t.enableZoom&&Ge(W),t.enablePan&&_e(W)}function dt(W){t.enableZoom&&Ge(W),t.enableRotate&&Se(W)}function U(W){t.enabled!==!1&&(C.length===0&&(t.domElement.addEventListener("pointermove",P),window.addEventListener("pointerup",ne)),lt(W),W.pointerType==="touch"?bt(W):ke(W))}function P(W){t.enabled!==!1&&(W.pointerType==="touch"?De(W):Ce(W))}function ne(W){switch(ht(W),C.length){case 0:t.domElement.removeEventListener("pointermove",P),t.domElement.removeEventListener("pointerup",ne),t.dispatchEvent(Gz),r=s.NONE;break;case 1:const T=C[0],B=R[T];bt({pointerId:T,pageX:B.x,pageY:B.y});break}}function ke(W){let T;switch(W.button){case 0:T=t.mouseButtons.LEFT;break;case 1:T=t.mouseButtons.MIDDLE;break;case 2:T=t.mouseButtons.RIGHT;break;default:T=-1}switch(T){case tu.DOLLY:if(t.enableZoom===!1)return;Ae(W),r=s.DOLLY;break;case tu.ROTATE:if(W.ctrlKey||W.metaKey||W.shiftKey){if(t.enablePan===!1)return;Ue(W),r=s.PAN}else{if(t.enableRotate===!1)return;se(W),r=s.ROTATE}break;case tu.PAN:if(W.ctrlKey||W.metaKey||W.shiftKey){if(t.enableRotate===!1)return;se(W),r=s.ROTATE}else{if(t.enablePan===!1)return;Ue(W),r=s.PAN}break;default:r=s.NONE}r!==s.NONE&&t.dispatchEvent(aI)}function Ce(W){switch(r){case s.ROTATE:if(t.enableRotate===!1)return;Qe(W);break;case s.DOLLY:if(t.enableZoom===!1)return;Ke(W);break;case s.PAN:if(t.enablePan===!1)return;ae(W);break}}function Le(W){t.enabled===!1||t.enableZoom===!1||r!==s.NONE||(W.preventDefault(),t.dispatchEvent(aI),Ee(it(W)),t.dispatchEvent(Gz))}function it(W){const T=W.deltaMode,B={clientX:W.clientX,clientY:W.clientY,deltaY:W.deltaY};switch(T){case 1:B.deltaY*=16;break;case 2:B.deltaY*=100;break}return W.ctrlKey&&!I&&(B.deltaY*=10),B}function ze(W){W.key==="Control"&&(I=!0,t.domElement.getRootNode().addEventListener("keyup",Je,{passive:!0,capture:!0}))}function Je(W){W.key==="Control"&&(I=!1,t.domElement.getRootNode().removeEventListener("keyup",Je,{passive:!0,capture:!0}))}function nt(W){t.enabled===!1||t.enablePan===!1||He(W)}function bt(W){switch(we(W),C.length){case 1:switch(t.touches.ONE){case iu.ROTATE:if(t.enableRotate===!1)return;Fe(W),r=s.TOUCH_ROTATE;break;case iu.PAN:if(t.enablePan===!1)return;We(W),r=s.TOUCH_PAN;break;default:r=s.NONE}break;case 2:switch(t.touches.TWO){case iu.DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;Ne(W),r=s.TOUCH_DOLLY_PAN;break;case iu.DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;X(W),r=s.TOUCH_DOLLY_ROTATE;break;default:r=s.NONE}break;default:r=s.NONE}r!==s.NONE&&t.dispatchEvent(aI)}function De(W){switch(we(W),r){case s.TOUCH_ROTATE:if(t.enableRotate===!1)return;Se(W),t.update();break;case s.TOUCH_PAN:if(t.enablePan===!1)return;_e(W),t.update();break;case s.TOUCH_DOLLY_PAN:if(t.enableZoom===!1&&t.enablePan===!1)return;ue(W),t.update();break;case s.TOUCH_DOLLY_ROTATE:if(t.enableZoom===!1&&t.enableRotate===!1)return;dt(W),t.update();break;default:r=s.NONE}}function Ot(W){t.enabled!==!1&&W.preventDefault()}function lt(W){C.push(W.pointerId)}function ht(W){delete R[W.pointerId];for(let T=0;T<C.length;T++)if(C[T]==W.pointerId){C.splice(T,1);return}}function we(W){let T=R[W.pointerId];T===void 0&&(T=new ee,R[W.pointerId]=T),T.set(W.pageX,W.pageY)}function ut(W){const T=W.pointerId===C[0]?C[1]:C[0];return R[T]}t.domElement.addEventListener("contextmenu",Ot),t.domElement.addEventListener("pointerdown",U),t.domElement.addEventListener("pointercancel",ne),t.domElement.addEventListener("wheel",Le,{passive:!1}),t.domElement.getRootNode().addEventListener("keydown",ze,{passive:!0,capture:!0}),this.update()}};class Vz extends ve{constructor(e,t,s,r=128){if(t<=0||s<=0||r<=0)throw new Error("GroundedSkybox height, radius, and resolution must be positive.");const n=new Ta(s,2*r,r);n.scale(1,1,-1);const o=n.getAttribute("position"),a=new w;for(let l=0;l<o.count;++l)if(a.fromBufferAttribute(o,l),a.y<0){const c=-t*3/2,u=a.y<c?-t/a.y:1-a.y*a.y/(3*c*c);a.multiplyScalar(u),a.toArray(o.array,3*l)}o.needsUpdate=!0,super(n,new ri({map:e,depthWrite:!1}))}}const U_=Symbol("cameraController");function wse(i){return i[U_]}function Hz(i,e,t){t?i[U_]=e:i[U_]===e&&(i[U_]=null)}const Wz=Symbol("camera autofit");function Sse(i){return i[Wz]===void 0?!0:i[Wz]!==!1}var Cse=Object.defineProperty,Ese=Object.getOwnPropertyDescriptor,Mse=(i,e,t,s)=>{for(var r=s>1?void 0:s?Ese(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Cse(e,t,r),r};class _v extends Pe{constructor(){super(...arguments),h(this,"constraintActive",!0),h(this,"locked",!1),h(this,"sources",[])}}Mse([x(ye)],_v.prototype,"sources",2);function Tse(i){Eg(i,Hs.ContextCreated)}function Ise(i){Eg(i,ks.Start)}function Xz(i){Eg(i,ks.Update)}function Rse(i){Eg(i,ks.OnBeforeRender)}class id{constructor(){h(this,"bb",null),h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}static sizeOf(){return 12}static createVec3(e,t,s,r){return e.prep(4,12),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(t),e.offset()}}class qz{constructor(){h(this,"bb",null),h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}position(e){return(e||new id).__init(this.bb_pos,this.bb)}rotation(e){return(e||new id).__init(this.bb_pos+12,this.bb)}scale(e){return(e||new id).__init(this.bb_pos+24,this.bb)}static sizeOf(){return 36}static createTransform(e,t,s,r,n,o,a,l,c,u){return e.prep(4,36),e.prep(4,12),e.writeFloat32(u),e.writeFloat32(c),e.writeFloat32(l),e.prep(4,12),e.writeFloat32(a),e.writeFloat32(o),e.writeFloat32(n),e.prep(4,12),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(t),e.offset()}}class kc{constructor(){h(this,"bb",null),h(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsSyncedTransformModel(e,t){return(t||new kc).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSyncedTransformModel(e,t){return e.setPosition(e.position()+PE),(t||new kc).__init(e.readInt32(e.position())+e.position(),e)}guid(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}fast(){const e=this.bb.__offset(this.bb_pos,6);return e?!!this.bb.readInt8(this.bb_pos+e):!1}transform(e){const t=this.bb.__offset(this.bb_pos,8);return t?(e||new qz).__init(this.bb_pos+t,this.bb):null}dontSave(){const e=this.bb.__offset(this.bb_pos,10);return e?!!this.bb.readInt8(this.bb_pos+e):!1}static startSyncedTransformModel(e){e.startObject(4)}static addGuid(e,t){e.addFieldOffset(0,t,0)}static addFast(e,t){e.addFieldInt8(1,+t,0)}static addTransform(e,t){e.addFieldStruct(2,t,0)}static addDontSave(e,t){e.addFieldInt8(3,+t,0)}static endSyncedTransformModel(e){return e.endObject()}static finishSyncedTransformModelBuffer(e,t){e.finish(t)}static finishSizePrefixedSyncedTransformModelBuffer(e,t){e.finish(t,void 0,!0)}}var sr=(i=>(i[i.Average=0]="Average",i[i.Multiply=1]="Multiply",i[i.Minimum=2]="Minimum",i[i.Maximum=3]="Maximum",i))(sr||{}),F_=(i=>(i[i.Discrete=0]="Discrete",i[i.Continuous=1]="Continuous",i))(F_||{}),Es=(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))(Es||{}),Af=(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))(Af||{});const Sr=function(i,e){return function(t,s,r){Pse(t,s,r,i,e)}};function Pse(i,e,t,s,r){if(!r&&!s&&!i.onValidate)return;if(t!==void 0){console.error("Invalid usage of validate decorator. Only fields can be validated.",i,e,t),ms("Invalid usage of validate decorator. Only fields can be validated. Property: "+e,Eo.Error);return}let n="";if(typeof e=="string"?n=e:n=e.name,i.__internalAwake){const o=Symbol(n),a=i.__internalAwake;i.__internalAwake=function(){var l;if(!this.onValidate){wt()&&console.warn('Usage of @validate decorate detected but there is no onValidate method in your class: "'+((l=i.constructor)==null?void 0:l.name)+'"');return}if(this[o]===void 0){this[o]=this[n];const c=this[n];if(c instanceof ee||c instanceof w||c instanceof tt||c instanceof Ie){const u=this[n];H0(u,()=>{this.onValidate(n)})}Object.defineProperty(this,n,{set:function(u){var d;if(this[uE]===!0)this[o]=u;else{s?.call(this,u);const p=this[o];this[o]=u,(d=this.onValidate)==null||d.call(this,n,p)}},get:function(){return r?.call(this),this[o]}})}a.call(this)}}}const Bse=function(i){return function(e,t,s){let r="";typeof t=="string"?r=t:r=t.name;const n=i.prototype,o=Object.getOwnPropertyDescriptor(n,r);if(!(o!=null&&o.value)){console.warn("Can not apply prefix: type does not have method named",t,i);return}const a=o.value,l=e[r];Object.defineProperty(n,r,{value:function(...c){const u=l?.call(this,...c);if(u instanceof Promise){u.then(d=>{if(d!==!1)return a.call(this,...c)});return}if(u!==!1)return a.call(this,...c)}})}};var Dse=Object.defineProperty,kse=Object.getOwnPropertyDescriptor,No=(i,e,t,s)=>{for(var r=s>1?void 0:s?kse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Dse(e,t,r),r};class Ose{constructor(e,t){h(this,"positionChanged",!1),h(this,"rotationChanged",!1),h(this,"position"),h(this,"quaternion"),h(this,"_positionKeys",["x","y","z"]),h(this,"_quaternionKeys",["_x","_y","_z","_w"]),h(this,"mute",!1),h(this,"context"),h(this,"obj"),h(this,"_positionWatch"),h(this,"_rotationWatch"),this.context=t,this.obj=e}get isDirty(){return this.positionChanged||this.rotationChanged}reset(e=!1){if(this.positionChanged=!1,this.rotationChanged=!1,this.mute=!1,e){if(this.position)for(const t of this._positionKeys)delete this.position[t];if(this.quaternion)for(const t of this._quaternionKeys)delete this.quaternion[t]}}syncValues(){for(const e of this._positionKeys)this.position[e]=this.obj.position[e];for(const e of this._quaternionKeys)this.quaternion[e]=this.obj.quaternion[e]}applyValues(){if(this.positionChanged&&this.position)for(const e of this._positionKeys){const t=this.position[e];t!==void 0&&(this.obj.position[e]=t)}if(this.rotationChanged&&this.quaternion)for(const e of this._quaternionKeys){const t=this.quaternion[e];t!==void 0&&(this.obj.quaternion[e]=t)}}start(e,t){this.reset(),e&&(this._positionWatch||(this._positionWatch=new Bc(this.obj.position,["x","y","z"])),this._positionWatch.apply(),this.position={},this._positionWatch.subscribeWrite((n,o)=>{var a;if((a=this.context.physics.engine)!=null&&a.isUpdating||this.mute)return;const l=this.position[o];Math.abs(l-n)<1e-5||(this.position[o]=n,this.positionChanged=!0)})),t&&(this._rotationWatch||(this._rotationWatch=new Bc(this.obj.quaternion,["_x","_y","_z","_w"])),this._rotationWatch.apply(),this.quaternion={},this._rotationWatch.subscribeWrite((n,o)=>{var a;if((a=this.context.physics.engine)!=null&&a.isUpdating||this.mute)return;const l=this.quaternion[o];Math.abs(l-n)<1e-5||(this.quaternion[o]=n,this.rotationChanged=!0)}));const s=this.obj.matrixWorld.multiplyMatrices.bind(this.obj.matrixWorld),r=new Te;this.obj.matrixWorld.multiplyMatrices=(n,o)=>{var a;return(a=this.context.physics.engine)!=null&&a.isUpdating||this.mute||r.equals(n)||(this.positionChanged=!0,this.rotationChanged=!0,r.copy(n)),s(n,o)}}stop(){var e,t;(e=this._positionWatch)==null||e.revoke(),(t=this._rotationWatch)==null||t.revoke()}}var lI;const cI=(lI=class extends Pe{constructor(){super(...arguments),h(this,"autoMass",!0),h(this,"_mass",0),h(this,"useGravity",!0),h(this,"constraints",Es.None),h(this,"isKinematic",!1),h(this,"drag",0),h(this,"angularDrag",1),h(this,"detectCollisions",!0),h(this,"sleepThreshold",.01),h(this,"collisionDetectionMode",F_.Discrete),h(this,"_gravityScale",1),h(this,"dominanceGroup",0),h(this,"_propertiesChanged",!1),h(this,"_currentVelocity",new w),h(this,"_smoothedVelocity",new w),h(this,"_smoothedVelocityGetter",new w),h(this,"_lastPosition",new w),h(this,"_watch")}set mass(i){i!==this._mass&&(this._mass=i,this._propertiesChanged=!0,this.__didAwake&&(this.autoMass=!1))}get mass(){var i,e;return this.autoMass?((e=(i=this.context.physics.engine)==null?void 0:i.getBody(this))==null?void 0:e.mass())??-1:this._mass}get lockPositionX(){return(this.constraints&Es.FreezePositionX)!==0}get lockPositionY(){return(this.constraints&Es.FreezePositionY)!==0}get lockPositionZ(){return(this.constraints&Es.FreezePositionZ)!==0}get lockRotationX(){return(this.constraints&Es.FreezeRotationX)!==0}get lockRotationY(){return(this.constraints&Es.FreezeRotationY)!==0}get lockRotationZ(){return(this.constraints&Es.FreezeRotationZ)!==0}set lockPositionX(i){i?this.constraints|=Es.FreezePositionX:this.constraints&=~Es.FreezePositionX}set lockPositionY(i){i?this.constraints|=Es.FreezePositionY:this.constraints&=~Es.FreezePositionY}set lockPositionZ(i){i?this.constraints|=Es.FreezePositionZ:this.constraints&=~Es.FreezePositionZ}set lockRotationX(i){i?this.constraints|=Es.FreezeRotationX:this.constraints&=~Es.FreezeRotationX}set lockRotationY(i){i?this.constraints|=Es.FreezeRotationY:this.constraints&=~Es.FreezeRotationY}set lockRotationZ(i){i?this.constraints|=Es.FreezeRotationZ:this.constraints&=~Es.FreezeRotationZ}set gravityScale(i){this._gravityScale=i}get gravityScale(){return this._gravityScale}awake(){this._watch=void 0,this._propertiesChanged=!1}onEnable(){this._watch||(this._watch=new Ose(this.gameObject,this.context)),this._watch.start(!0,!0),this.startCoroutine(this.beforePhysics(),ks.LateUpdate)}onDisable(){var i,e;(i=this._watch)==null||i.stop(),(e=this.context.physics.engine)==null||e.removeBody(this)}onDestroy(){var i;(i=this.context.physics.engine)==null||i.removeBody(this)}onValidate(){this._propertiesChanged=!0}*beforePhysics(){for(var i,e,t,s;;)this._propertiesChanged&&(this._propertiesChanged=!1,(i=this.context.physics.engine)==null||i.updateProperties(this)),(e=this._watch)!=null&&e.isDirty?(this._watch.mute=!0,this._watch.applyValues(),(t=this.context.physics.engine)==null||t.updateBody(this,this._watch.positionChanged,this._watch.rotationChanged),this._watch.reset()):(s=this._watch)==null||s.syncValues(),this.captureVelocity(),yield}teleport(i,e=!0){var t;(t=this._watch)==null||t.reset(!0),e?this.gameObject.position.set(i.x,i.y,i.z):this.setWorldPosition(i.x,i.y,i.z),this.resetForcesAndTorques(),this.resetVelocities()}resetForces(i=!0){var e;(e=this.context.physics.engine)==null||e.resetForces(this,i)}resetTorques(i=!0){var e;(e=this.context.physics.engine)==null||e.resetTorques(this,i)}resetVelocities(){this.setVelocity(0,0,0),this.setAngularVelocity(0,0,0)}resetForcesAndTorques(){this.resetForces(),this.resetTorques()}wakeUp(){var i;(i=this.context.physics.engine)==null||i.wakeup(this)}get isSleeping(){var i;return(i=this.context.physics.engine)==null?void 0:i.isSleeping(this)}updateProperties(){var i;return this._propertiesChanged=!1,(i=this.context.physics.engine)==null?void 0:i.updateProperties(this)}applyForce(i,e,t=!0){var s;this._propertiesChanged&&this.updateProperties(),(s=this.context.physics.engine)==null||s.addForce(this,i,t)}applyImpulse(i,e=!0){var t;this._propertiesChanged&&this.updateProperties(),(t=this.context.physics.engine)==null||t.applyImpulse(this,i,e)}setForce(i,e,t,s=!0){var r,n,o;(r=this.context.physics.engine)==null||r.resetForces(this,s),typeof i=="number"?(e??(e=0),t??(t=0),(n=this.context.physics.engine)==null||n.addForce(this,{x:i,y:e,z:t},s)):(o=this.context.physics.engine)==null||o.addForce(this,i,s)}getVelocity(){var i;const e=(i=this.context.physics.engine)==null?void 0:i.getLinearVelocity(this);return e?(this._currentVelocity.x=e.x,this._currentVelocity.y=e.y,this._currentVelocity.z=e.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setVelocity(i,e,t,s=!0){var r,n;if(i instanceof w){const o=i;(r=this.context.physics.engine)==null||r.setLinearVelocity(this,o,s);return}e===void 0||t===void 0||(n=this.context.physics.engine)==null||n.setLinearVelocity(this,{x:i,y:e,z:t},s)}getAngularVelocity(){var i;const e=(i=this.context.physics.engine)==null?void 0:i.getAngularVelocity(this);return e?(this._currentVelocity.x=e.x,this._currentVelocity.y=e.y,this._currentVelocity.z=e.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setAngularVelocity(i,e,t,s=!0){var r,n;if(i instanceof w){const o=i;(r=this.context.physics.engine)==null||r.setAngularVelocity(this,o,s);return}e===void 0||t===void 0||(n=this.context.physics.engine)==null||n.setAngularVelocity(this,{x:i,y:e,z:t},s)}setTorque(i,e,t){this.setAngularVelocity(i,e,t)}get smoothedVelocity(){return this._smoothedVelocityGetter.copy(this._smoothedVelocity),this._smoothedVelocityGetter.multiplyScalar(1/this.context.time.deltaTime)}setBodyFromGameObject(i=null){}captureVelocity(){const i=Rt(this.gameObject);cI.tempPosition.copy(i);const e=i.sub(this._lastPosition);this._lastPosition.copy(cI.tempPosition),this._smoothedVelocity.lerp(e,this.context.time.deltaTime/.1)}},h(lI,"tempPosition",new w),lI);let Ni=cI;No([Sr()],Ni.prototype,"autoMass",2),No([x()],Ni.prototype,"mass",1),No([Sr(),x()],Ni.prototype,"useGravity",2),No([Sr(),x()],Ni.prototype,"constraints",2),No([Sr(),x()],Ni.prototype,"isKinematic",2),No([Sr(),x()],Ni.prototype,"drag",2),No([Sr(),x()],Ni.prototype,"angularDrag",2),No([Sr(),x()],Ni.prototype,"detectCollisions",2),No([Sr(),x()],Ni.prototype,"sleepThreshold",2),No([Sr(),x()],Ni.prototype,"collisionDetectionMode",2),No([Sr()],Ni.prototype,"_gravityScale",2),No([Sr()],Ni.prototype,"dominanceGroup",2);const pc=te("debugsync"),xv="STRS";kE(xv,kc.getRootAsSyncedTransformModel);const $a=new ey;function Yz(i,e,t=!0){$a.clear();const s=$a.createString(i);kc.startSyncedTransformModel($a),kc.addGuid($a,s),kc.addFast($a,t);const r=e.worldPosition,n=e.worldEuler,o=e.gameObject.scale;kc.addTransform($a,qz.createTransform($a,r.x,r.y,r.z,n.x,n.y,n.z,o.x,o.y,o.z));const a=kc.endSyncedTransformModel($a);return $a.finish(a,xv),$a.asUint8Array()}let hI=0,wv=0;Xz(i=>{var e;const t=(e=i.connection.currentServerUrl)!=null&&e.includes("glitch")?10:40;wv=Math.floor(hI/t),hI=0,pc&&wv>0&&console.log("Sync Transform Fast Interval",wv)});class Eh extends Pe{constructor(){super(...arguments),h(this,"overridePhysics",!0),h(this,"interpolatePosition",!0),h(this,"interpolateRotation",!0),h(this,"fastMode",!1),h(this,"syncDestroy",!1),h(this,"_model",null),h(this,"_needsUpdate",!0),h(this,"rb",null),h(this,"_wasKinematic",!1),h(this,"_receivedDataBefore",!1),h(this,"_targetPosition"),h(this,"_targetRotation"),h(this,"_receivedFastUpdate",!1),h(this,"_shouldRequestOwnership",!1),h(this,"joinedRoomCallback",null),h(this,"receivedDataCallback",null),h(this,"tempEuler",new Ur),h(this,"receivedUpdate",!1),h(this,"lastWorldPos"),h(this,"lastWorldRotation")}requestOwnership(){pc&&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(){pc&&console.log("new instance",this.guid,this),this._receivedDataBefore=!1,this._targetPosition=new w,this._targetRotation=new Ie,this.lastWorldPos=new w,this.lastWorldRotation=new Ie,this.rb=oe.getComponentInChildren(this.gameObject,Ni),this.rb&&(this._wasKinematic=this.rb.isKinematic),this.receivedUpdate=!0,this._model=new ZE(this.context.connection,this.guid),this.context.connection.isConnected&&this.tryGetLastState(),this.joinedRoomCallback=this.tryGetLastState.bind(this),this.context.connection.beginListen(di.JoinedRoom,this.joinedRoomCallback),this.receivedDataCallback=this.onReceivedData.bind(this),this.context.connection.beginListenBinary(xv,this.receivedDataCallback)}onDestroy(){this.syncDestroy&&r3(this.guid,this.context.connection),this._model=null,this.context.connection.stopListen(di.JoinedRoom,this.joinedRoomCallback),this.context.connection.stopListenBinary(xv,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){pc&&console.log("new data",this.context.connection.connectionId,this.context.time.frameCount,this.guid,e),this.receivedUpdate=!0,this._receivedFastUpdate=e.fast();const s=e.transform();if(s){Pa.markDirty(this.gameObject,!0);const r=s.position();r&&(this.interpolatePosition&&((t=this._targetPosition)==null||t.set(r.x(),r.y(),r.z())),(!this.interpolatePosition||!this._receivedDataBefore)&&this.setWorldPosition(r.x(),r.y(),r.z()));const n=s.rotation();n&&(this.tempEuler.set(n.x(),n.y(),n.z()),this.interpolateRotation&&this._targetRotation.setFromEuler(this.tempEuler),(!this.interpolateRotation||!this._receivedDataBefore)&&JM(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){pc&&console.log("no model or room",this.name,this.guid,this.context.connection.isInRoom);return}this._shouldRequestOwnership&&(this._shouldRequestOwnership=!1,this._model.requestOwnership());const e=this.worldPosition,t=this.worldQuaternion;if(this._model.isOwned&&!this.receivedUpdate){const n=e.distanceTo(this.lastWorldPos),o=t.angleTo(this.lastWorldRotation),a=this._model.hasOwnership||this.fastMode?1e-4:.001;(n>a||o>a)&&(this._model.hasOwnership?this._needsUpdate=!0:(pc&&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),Pa.markDirty(this.gameObject,!0),this._needsUpdate=!1))}if(this._model&&!this._model.hasOwnership&&this._model.isOwned&&this._receivedDataBefore){const n=this._receivedFastUpdate||this.fastMode?.5:.3;let o=!1;if(this.interpolatePosition&&this._targetPosition){const a=this.worldPosition;a.lerp(this._targetPosition,n),this.worldPosition=a,o=!0}if(this.interpolateRotation&&this._targetRotation){const a=this.worldQuaternion;a.slerp(this._targetRotation,n),this.worldQuaternion=a,o=!0}o&&Pa.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&&(pc&&console.log("reset kinematic",this.rb.name,this._wasKinematic),this.rb.isKinematic=this._wasKinematic),this.gameObject.position.distanceTo(new w(0,0,0))>1e3&&(pc&&console.log("RESET",this.name),this.gameObject.position.set(0,1,0),this.rb.setVelocity(0,0,0)));const s=10,r=this.rb||this.fastMode;if(this._needsUpdate&&(this.context.time.frameCount%s===0||r)){if(hI++,r&&wv>0&&this.context.time.frameCount%wv!==0)return;pc&&console.log("send update",this.context.connection.connectionId,this.guid,this.gameObject.name,this.gameObject.guid),this.overridePhysics&&this.rb,this._needsUpdate=!1;const n=Yz(this.guid,this,!!r);this.context.connection.sendBinary(n)}}}const Lse=te("debugshadowcomponents");jM.prototype.interactable={get(){return this.interactive},set(i){this.interactable=i}};const zo=Symbol("shadowDomOwner");class Ra extends Pe{constructor(){super(...arguments),h(this,"_shadowComponent",null),h(this,"_controlsChildLayout",!0),h(this,"_root"),h(this,"_parentComponent")}isRoot(){var e;return((e=this.Root)==null?void 0:e.gameObject)===this.gameObject}get canvas(){const e=this.Root;return e!=null&&e.isCanvas?e:null}get Canvas(){return this.canvas}markDirty(){jo.markUIDirty(this.context)}get shadowComponent(){return this._shadowComponent}set shadowComponent(e){this._shadowComponent=e}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(e){this._controlsChildLayout=e,this.shadowComponent&&(this.shadowComponent.autoLayout=e)}get Root(){return this._root===void 0&&(this._root=oe.getComponentInParent(this.gameObject,Sv)),this._root}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this.shadowComponent=null,this._root=void 0,this._parentComponent=void 0}onEnable(){super.onEnable()}addShadowComponent(e,t){var s;this.removeShadowComponent();const r=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=oe.getComponentInParent(r,Ra),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}e.name=this.name+" ("+(this.constructor.name??"UI")+")",e.autoLayout=this._parentComponent.controlsChildLayout,e[zo]=this,this.setShadowComponentOwner(e);let n=!1;if(((s=this.Root)==null?void 0:s.gameObject)===this.gameObject)this.gameObject.add(e);else{const o=this._parentComponent.shadowComponent;o&&(o?.add(e),n=!0)}this.shadowComponent=e,t&&t.shadowComponent&&this.shadowComponent&&t.shadowComponent.add(this.shadowComponent),xg&&e.add(new wo(.5)),this.onAfterAddedToScene(),n&&SN(),Lse&&console.log(this.shadowComponent)}setShadowComponentOwner(e){if(e&&(e[zo]===void 0||e[zo]===this)&&(e[zo]=this,e.children))for(const t of e.children)this.setShadowComponentOwner(t)}traverseOwnedShadowComponents(e,t,s){if(e&&e[zo]===t){s(e);for(const r of e.children)this.traverseOwnedShadowComponents(r,t,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(e){this.shadowComponent&&(this.shadowComponent.interactable=e)}}class Sv extends Ra{awake(){super.awake()}}class cm{constructor(e,t){h(this,"event"),h(this,"button"),h(this,"buttonName"),h(this,"_used",!1),h(this,"_propagationStopped",!1),h(this,"z__pointer_ctured",!1),h(this,"z__pointer_cture_rleased",!1),h(this,"inputSource"),h(this,"object"),h(this,"point"),h(this,"normal"),h(this,"face"),h(this,"distance"),h(this,"instanceId"),h(this,"isDown"),h(this,"isUp"),h(this,"isPressed"),h(this,"isClick"),h(this,"isDoubleClick"),h(this,"input"),this.event=t,this.input=e,this.button=t.button}get deviceIndex(){return this.event.deviceIndex}get pointerId(){return this.event.pointerId}get pressure(){return this.event.pressure}get used(){return this._used}use(){this._used||(this._used=!0,this.pointerId!==void 0&&this.input.setPointerUsed(this.pointerId))}get propagationStopped(){return this._propagationStopped}stopPropagation(){this._propagationStopped=!0,this.event.stopImmediatePropagation()}stopImmediatePropagation(){this._propagationStopped=!0,this.event.stopImmediatePropagation()}setPointerCapture(){this.z__pointer_ctured=!0}releasePointerCapture(){this.z__pointer_cture_rleased=!0}get mode(){return this.event.mode}clone(){const e=new cm(this.input,this.event);return Object.assign(e,this),e}Use(){this.use()}StopPropagation(){this.event.stopImmediatePropagation()}}function uI(i,e){return oe.foreachComponent(i,t=>{if(!t.enabled)return;const s=t;if(e)switch(e){case"pointerdown":if(s.onPointerDown)return!0;break;case"pointerup":if(s.onPointerUp||s.onPointerClick)return!0;break;case"pointermove":if(s.onPointerEnter||s.onPointerExit||s.onPointerMove)return!0;break}else if(s.onPointerDown||s.onPointerUp||s.onPointerEnter||s.onPointerExit||s.onPointerClick)return!0},!1)===!0}var Use=Object.defineProperty,Fse=Object.getOwnPropertyDescriptor,Nse=(i,e,t,s)=>{for(var r=s>1?void 0:s?Fse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Use(e,t,r),r};class Cv extends Pe{awake(){jo.createIfNoneExists(this.context)}onEnable(){var e;(e=jo.get(this.context))==null||e.register(this)}onDisable(){var e;(e=jo.get(this.context))==null||e.unregister(this)}}class to extends Cv{constructor(){super(...arguments),h(this,"targets",null),h(this,"raycastHits",[]),h(this,"ignoreSkinnedMeshes",!1)}start(){this.targets=[this.gameObject]}performRaycast(e=null){if(!this.targets)return null;e??(e=new Oo),e.targets=this.targets,e.results=this.raycastHits;const t=e.testObject;this.ignoreSkinnedMeshes&&(e.testObject=r=>r instanceof oa?"continue in children":t?t(r):!0);const s=this.context.physics.raycast(e);return e.testObject=t,s}}Nse([x()],to.prototype,"ignoreSkinnedMeshes",2);class N_ extends to{constructor(){super(),this.ignoreSkinnedMeshes=!0}}class Ev extends Cv{performRaycast(e){if(!vt.active||!(e!=null&&e.ray))return null;const t=e.ray.origin,s=.01;return this.context.physics.sphereOverlap(t,s)}}class z_{static getObject(e){const t=e[zo];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const s=this.tryFindCanvasGroup(e);if(s?.isCanvasGroup===!0&&(t&&(t.canvasGroup=s),s.blocksRaycasts===!1||s.interactable===!1))return!1;const r=qu(e,n=>{if(n.isGraphic===!0)return n},!1);return t&&r?.isGraphic===!0&&(t.graphic=r),!(r?.raycastTarget===!1||r?.layer===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=qu(e,s=>{const r=s;if(r.blocksRaycasts!==void 0&&r.interactable!==void 0)return r},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}function dI(i){return i[zo]||(i.parent?dI(i.parent):null)}function zse(i){return i.isUI===!0||typeof i[zo]=="object"}function j_(i,e){if(!i)return;const t=i.material;if(t?.isMaterial===!0){const s=i.parent;s&&s.isText,t.side=e.doubleSided??!0?fi:ur,t.shadowSide=e.doubleSided?fi:ur,i.castShadow=e.castShadows?e.castShadows:!1,i.receiveShadow=e.receiveShadows?e.receiveShadows:!1}for(const s of i.children)j_(s,e)}function yf(i,e,t){i[e]===void 0&&console.warn("Field",e,"is undefined on",i);const s=Proxy.revocable(i[e],{set(o,a,l,c){const u=o[a],d=Reflect.set(o,a,l,c);return t(l,u),d}}),r=s.revoke,n=i[e];return s.revoke=()=>{i[e]=n,r()},i[e]=s.proxy,s}const Jz=Symbol("Scheduled action");function jse(i,e,t=ks.OnBeforeRender){let s=i[Jz];s||(s=i[Jz]={});const r=e.name;s[t]||(s[t]={});const n=s[t];if(n[r])return;function*o(){e?.call(i),n[r]=null}const a=i.startCoroutine(o(),t);n[r]=a}const fc=te("debugeventsystem");var pI=(i=>(i.BeforeHandleInput="BeforeHandleInput",i.AfterHandleInput="AfterHandleInput",i))(pI||{});const mc=class extends Pe{constructor(){super(),h(this,"raycaster",[]),h(this,"_handleInputFn"),h(this,"pressedByID",new Map),h(this,"hoveredByID",new Map),h(this,"_sortedHits",[]),h(this,"_testObjectsCache",new Map),h(this,"_currentlyActiveRaycaster",null),h(this,"_currentPointerEventName",null),h(this,"shouldRaycastObject",i=>{var e;let t=null;if(zse(i)&&(t=(e=i[zo])==null?void 0:e.gameObject),this._testObjectsCache.has(i)||t&&this._testObjectsCache.has(t))return this._testObjectsCache.get(i)===!1?"continue in children":!0;{let s=uI(i,this._currentPointerEventName);if(!s&&t&&(s=uI(t,this._currentPointerEventName)),s){this._testObjectsCache.set(i,!0);for(const r of i.children)this.shouldRaycastObject_AddToYesCache(r);return!0}return this._testObjectsCache.set(i,!1),"continue in children"}}),h(this,"_sortingBuffer",[]),h(this,"_noDepthTestingResults",[]),h(this,"out",{}),h(this,"_capturedPointer",{}),h(this,"pointerEnterSymbol",Symbol("pointerEnter")),h(this,"pointerExitSymbol",Symbol("pointerExit")),h(this,"currentActiveMeshUIComponents",[]),mc.systems.push(this)}static createIfNoneExists(i){this.didSearchEventSystem||(this.didSearchEventSystem=!0,mc.systems.length<=0&&mc.systems.push(...oe.findObjectsOfType(mc,i)));for(const t of mc.systems)if(t.context===i)return;const e=new ye;oe.addNewComponent(e,mc),i.scene.add(e)}static get systems(){const i=kt.Current;return this._eventSystemMap.has(i)||this._eventSystemMap.set(i,[]),this._eventSystemMap.get(i)}static get(i){const e=this._eventSystemMap.get(i);return e&&e.length>0?e[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(i,e,t=!1){Mh.update(i,e,t)}static markUIDirty(i){Mh.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.hoveredByID.size>0}onDestroy(){mc.systems.splice(mc.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!oe.findObjectOfType(Cv,this.context)){const i=oe.addNewComponent(this.context.scene,to);this.raycaster.push(i),(wt()||fc)&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found.")}}register(i){var e;i&&this.raycaster&&!this.raycaster.includes(i)&&((e=this.raycaster)==null||e.push(i))}unregister(i){var e,t;const s=(e=this.raycaster)==null?void 0:e.indexOf(i);s!==void 0&&s!==-1&&((t=this.raycaster)==null||t.splice(s,1))}onEnable(){this._handleInputFn??(this._handleInputFn=this.onPointerEvent.bind(this)),this.context.input.addEventListener(Xi.PointerDown,this._handleInputFn),this.context.input.addEventListener(Xi.PointerUp,this._handleInputFn),this.context.input.addEventListener(Xi.PointerMove,this._handleInputFn)}onDisable(){this.context.input.removeEventListener(Xi.PointerDown,this._handleInputFn),this.context.input.removeEventListener(Xi.PointerUp,this._handleInputFn),this.context.input.removeEventListener(Xi.PointerMove,this._handleInputFn)}onBeforeRender(){this.resetMeshUIStates()}onPointerEvent(i){if(i===void 0||i.propagationStopped)return;const e=new cm(this.context.input,i);this._currentPointerEventName=i.type,e.inputSource=this.context.input,e.isClick=i.isClick,e.isDoubleClick=i.isDoubleClick,e.isDown=i.type==Xi.PointerDown,e.isUp=i.type==Xi.PointerUp,e.isPressed=this.context.input.getPointerPressed(i.pointerId),fc&&(e.isDown?console.log("DOWN",e.pointerId):e.isUp&&console.log("UP",e.pointerId),e.isClick&&console.log("CLICK",e.pointerId));const t=new Oo;i.ray?t.ray=i.ray:t.screenPoint=this.context.input.getPointerPositionRC(i.pointerId);const s=this.performRaycast(t);fc&&e.isClick&&ms("EventSystem: "+e.pointerId+" - "+this.context.time.frame+" - Up:"+e.isUp+", Down:"+e.isDown);const r={sender:this,args:e,hasActiveUI:this.currentActiveMeshUIComponents.length>0};this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:r})),this.handleIntersections(s,e),this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:r}))}shouldRaycastObject_AddToYesCache(i){this._testObjectsCache.set(i,!0);for(const e of i.children)this.shouldRaycastObject_AddToYesCache(e)}performRaycast(i){if(!this.raycaster)return null;this._testObjectsCache.clear(),this._sortedHits.length=0,i||(i=new Oo),i.testObject=this.shouldRaycastObject;for(const e of this.raycaster){if(!e.activeAndEnabled)continue;this._currentlyActiveRaycaster=e;const t=e.performRaycast(i);this._currentlyActiveRaycaster=null,t&&t.length>0&&this._sortedHits.push(...t)}return this._sortedHits.sort((e,t)=>e.distance-t.distance),this._sortedHits}assignHitInformation(i,e){e?(i.point=e.point,i.normal=e.normal,i.face=e.face,i.distance=e.distance,i.instanceId=e.instanceId):(i.point=void 0,i.normal=void 0,i.face=void 0,i.distance=void 0,i.instanceId=void 0)}handleIntersections(i,e){var t;if(i!=null&&i.length){i=this.sortCandidates(i);for(const r of i){if(e.event.immediatePropagationStopped)return!1;if(this.assignHitInformation(e,r),this.handleEventOnObject(r.object,e))return!0}}this.assignHitInformation(e,i?.[0]),this.invokePointerCapture(e);const s=this.hoveredByID.get(e.pointerId);return s&&this.propagatePointerExit(s.obj,s.data,null),this.hoveredByID.delete(e.pointerId),e.isUp&&((t=this.pressedByID.get(e.pointerId))==null||t.handlers.forEach(r=>this.invokeOnPointerUp(e,r)),this.pressedByID.delete(e.pointerId)),!1}sortCandidates(i){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let e=0;e<i.length;e++){const t=i[e],s=t.object;if(s.material&&s.material.depthTest===!1){this._noDepthTestingResults.push(t);continue}this._sortingBuffer.push(t)}for(const e of this._sortingBuffer)this._noDepthTestingResults.push(e);return this._noDepthTestingResults}handleEventOnObject(i,e){if(!this.testIsVisible(i))return e.isClick&&fc&&console.log("not allowed",i),!1;if(e.pointerId===void 0)return fc&&console.error("Event without pointer can't be handled",e),!1;e.object=i;const t=i.parent;let s=!1;const r=e.isClick??!1;let n=null;if(t&&t.isUI){const c=(e.isPressed||e.isClick)??!1;if(t[zo]){const u=t[zo].gameObject;if(u){if(!z_.isInteractable(u,this.out))return!1;n=this.out.canvasGroup??null,this.handleMeshUIIntersection(i,c),i=u,s=!0}}if(!s&&this.handleMeshUiObjectWithoutShadowDom(t,c))return!0}r&&fc&&console.log(this.context.time.frame,i);const o=this.hoveredByID.get(e.pointerId),a=o?.obj;a!==i&&a&&this.propagatePointerExit(a,o.data,i);const l=this.hoveredByID.get(e.pointerId);if(l?(l.obj=i,l.data=e):this.hoveredByID.set(e.pointerId,{obj:i,data:e}),e.isDown){const c=this.pressedByID.get(e.pointerId);c?(c.obj=i,c.data=e):this.pressedByID.set(e.pointerId,{obj:i,data:e,handlers:new Set})}return(n===null||n.interactable)&&this.handleMainInteraction(i,e,a??null),!0}propagate(i,e){for(;i;)oe.foreachComponent(i,t=>{e(t)},!1),i=i.parent}handleMainInteraction(i,e,t){const s=this.pressedByID.get(e.pointerId),r=t!==i;let n=!0;switch(e.event.pointerType){case"mouse":case"touch":const o=this.context.input.getPointerPositionLastFrame(e.pointerId),a=this.context.input.getPointerPosition(e.pointerId);n=o&&!st.approximately(o,a);break}this.propagate(i,o=>{const a=o;a.interactable!==!1&&(!a.activeAndEnabled||!a.enabled||(a.onPointerEnter&&r&&this.handlePointerEnter(a,e),e.isDown&&a.onPointerDown&&(a.onPointerDown(e),s?.handlers.add(a),this.handlePointerCapture(e,a)),a.onPointerMove&&(n&&a.onPointerMove(e),this.handlePointerCapture(e,a)),e.isUp&&a.onPointerUp&&(this.invokeOnPointerUp(e,a),s?.handlers.delete(a)),e.isClick&&a.onPointerClick&&a.onPointerClick(e)))}),e.isUp&&(s?.handlers.forEach(o=>{this.invokeOnPointerUp(e,o)}),this.pressedByID.delete(e.pointerId))}propagatePointerExit(i,e,t){this.propagate(i,s=>{if(!s.gameObject||s.destroyed)return;const r=s;if(r.onPointerExit){if(t&&this.isChild(t,s.gameObject))return;this.handlePointerExit(r,e)}})}invokeOnPointerUp(i,e){var t;(t=e.onPointerUp)==null||t.call(e,i),this.releasePointerCapture(i,e)}handlePointerEnter(i,e){i.onPointerEnter&&this.updatePointerState(i,e.pointerId,this.pointerEnterSymbol,!0)&&i.onPointerEnter(e),this.updatePointerState(i,e.pointerId,this.pointerExitSymbol,!1)}handlePointerExit(i,e){i.onPointerExit&&this.updatePointerState(i,e.pointerId,this.pointerExitSymbol,!0)&&i.onPointerExit(e),this.updatePointerState(i,e.pointerId,this.pointerEnterSymbol,!1)}updatePointerState(i,e,t,s){let r=i[t];if(s)return r&&r.includes(e)?!1:(r=r||[],r.push(e),i[t]=r,!0);{if(!r||!r.includes(e))return!1;const n=r.indexOf(e);return n!==-1&&r.splice(n,1),!0}}handlePointerCapture(i,e){if(i.z__pointer_ctured){i.z__pointer_ctured=!1;const t=i.pointerId;if(e.onPointerMove){const s=this._capturedPointer[t]||[];s.push(e),this._capturedPointer[t]=s}else wt()&&!e.z__warned_no_pointermove&&(e.z__warned_no_pointermove=!0,console.warn("PointerCapture was requested but the component doesn't implement onPointerMove. It will not receive any pointer events"))}else i.z__pointer_cture_rleased&&(i.z__pointer_cture_rleased=!1,this.releasePointerCapture(i,e))}releasePointerCapture(i,e){const t=i.pointerId;if(this._capturedPointer[t]){const s=this._capturedPointer[t].indexOf(e);s!==-1&&(this._capturedPointer[t].splice(s,1),fc&&console.log("released pointer capture",t,e,this._capturedPointer))}}invokePointerCapture(i){var e;if(i.event.type===Xi.PointerMove){const t=i.pointerId,s=this._capturedPointer[t];if(s){fc&&console.log("Captured",t,s);for(let r=0;r<s.length;r++){const n=s[r];if(n.destroyed){s.splice(r,1),r--;continue}(e=n.onPointerMove)==null||e.call(n,i)}}}}isChild(i,e){return!i||!e?!1:i===e?!0:i.parent?this.isChild(i.parent,e):!1}handleMeshUiObjectWithoutShadowDom(i,e){return!i||!i.isUI?!0:this.handleMeshUIIntersection(i,e)}handleMeshUIIntersection(i,e){const t=Mh.updateState(i,e);return t&&this.currentActiveMeshUIComponents.push(t),t!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&Mh.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let i=0;i<this.currentActiveMeshUIComponents.length;i++){const e=this.currentActiveMeshUIComponents[i];Mh.resetState(e)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(i){return i?oe.isActiveSelf(i)?this.testIsVisible(i.parent):!1:!0}};let jo=mc;h(jo,"_eventSystemMap",new Map),h(jo,"didSearchEventSystem",!1);class Mh{static markDirty(){this.needsUpdate=!0}static update(e,t,s=!1){if(s){e.update();return}const r=t.time.frameCount;for(const n of this.lastUpdateFrame)if(n.context===t){if(r===n.frame)return;n.frame=r;let o=this.needsUpdate||r<1;n.nextUpdate===t.time.frameCount&&(o=!0),o&&(fc&&console.log("Update threemeshui"),this.needsUpdate=!1,e.update());return}this.lastUpdateFrame=[{context:t,frame:r,nextUpdate:r}],e.update()}static updateState(e,t){let s=null;if(e&&(s=this.findBlockInParent(e),s&&s!==this.lastSelected)){if(s.interactable===!1)return null;this.needsUpdate=!0}return s}static resetLastSelected(){const e=this.lastSelected;e&&(this.lastSelected=null,this.resetState(e))}static resetState(e){e&&(this.needsUpdate=!0)}static findBlockInParent(e){return e?e.isBlock?e:this.findBlockInParent(e.parent):null}}h(Mh,"lastSelected",null),h(Mh,"lastUpdateFrame",[]),h(Mh,"needsUpdate",!1);var Gse=Object.defineProperty,Qse=Object.getOwnPropertyDescriptor,Cr=(i,e,t,s)=>{for(var r=s>1?void 0:s?Qse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Gse(e,t,r),r};const Vse=te("debugorbit"),G_=te("freecam"),Mv=te("debugcamerafit"),Q_=te("smoothcam"),Hse={LEFT:"",UP:"",RIGHT:"",BOTTOM:""};let fI;class Tv extends CustomEvent{constructor(e,t){super("target-reached",{detail:{controls:e,type:t}})}}class zi extends Pe{constructor(){super(...arguments),h(this,"autoFit",!1),h(this,"enableRotate",!0),h(this,"autoRotate",!1),h(this,"autoRotateSpeed",1),h(this,"enableKeys",!0),h(this,"enableDamping",!0),h(this,"dampingFactor",.1),h(this,"enableZoom",!0),h(this,"minZoom",0),h(this,"maxZoom",1/0),h(this,"enablePan",!0),h(this,"lookAtConstraint",null),h(this,"lookAtConstraint01",1),h(this,"allowInterrupt",!0),h(this,"middleClickToFocus",!0),h(this,"doubleClickToFocus",!0),h(this,"useSlerp",!0),h(this,"debugLog",!1),h(this,"targetLerpDuration",1),h(this,"autoTarget",!0),h(this,"_controls",null),h(this,"_cameraObject",null),h(this,"_lookTargetLerpActive",!1),h(this,"_lookTargetStartPosition",new w),h(this,"_lookTargetEndPosition",new w),h(this,"_lookTargetLerp01",0),h(this,"_lookTargetLerpDuration",0),h(this,"_cameraLerpActive",!1),h(this,"_cameraStartPosition",new w),h(this,"_cameraEndPosition",new w),h(this,"_cameraLerp01",0),h(this,"_cameraLerpDuration",0),h(this,"_inputs",0),h(this,"_enableTime",0),h(this,"_startedListeningToKeyEvents",!1),h(this,"_eventSystem"),h(this,"_afterHandleInputFn"),h(this,"_camera",null),h(this,"_syncedTransform"),h(this,"_didStart",!1),h(this,"targetElement",null),h(this,"onControlsChangeStarted",()=>{this._syncedTransform&&this._syncedTransform.requestOwnership()}),h(this,"_shouldDisable",!1),h(this,"_haveAttachedKeyboardEvents",!1)}get isCameraController(){return!0}get controls(){return this._controls}get controllerObject(){return this._cameraObject}onStartInteraction(e){var t;(t=this.controls)==null||t.addEventListener("start",e)}get targetLerpSpeed(){return 5}set targetLerpSpeed(e){this.targetLerpDuration=1/e}awake(){this._didStart=!1,this._startedListeningToKeyEvents=!1}start(){if(this._didStart=!0,this.autoTarget&&this._controls){const e=oe.getComponent(this.gameObject,ji);if(e&&!this.setLookTargetFromConstraint()){this.debugLog&&console.log("NO TARGET");const t=Rt(e.cam).length(),s=new w(0,0,-t).applyMatrix4(e.cam.matrixWorld);this.setLookTargetPosition(s,!0)}if(this.autoTarget&&!this.setLookTargetFromConstraint()){const t=new Oo;t.screenPoint=new ee(0,0),t.lineThreshold=.1;const s=this.context.physics.raycast(t);s.length>0&&this.setLookTargetPosition(s[0].point,!0),Mv&&console.log("OrbitControls hits",...s)}this.autoFit&&this.fitCamera()}this._eventSystem=jo.get(this.context)??void 0,this._eventSystem&&(this._afterHandleInputFn=this.afterHandleInput.bind(this),this._eventSystem.addEventListener(pI.AfterHandleInput,this._afterHandleInputFn))}onDestroy(){var e,t;(e=this._controls)==null||e.dispose(),(t=this._eventSystem)==null||t.removeEventListener(pI.AfterHandleInput,this._afterHandleInputFn)}onEnable(){this._enableTime=this.context.time.time;const e=oe.getComponent(this.gameObject,ji);this._camera=e;const t=e?.cam;if(t&&Hz(t,this,!0),!this._controls){if(!t){console.warn("OrbitControls: Requires a Camera component on the same object as this component.");return}t&&(this._cameraObject=t);const s=this.targetElement??this.context.renderer.domElement,r=t?.quaternion.clone();this._controls=new xse(t,s),t?.quaternion.copy(r),fI===void 0&&(fI={...this._controls.keys})}this._controls&&(G_&&(this.enablePan=!0,this.enableZoom=!0,this.middleClickToFocus=!0,ja()&&(this.doubleClickToFocus=!0)),this._controls.addEventListener("start",this.onControlsChangeStarted),t?.type==="PerspectiveCamera"?G_||(this._controls.minDistance=this.minZoom,this._controls.maxDistance=this.maxZoom):G_||(this._controls.minZoom=this.minZoom,this._controls.maxZoom=this.maxZoom),this._startedListeningToKeyEvents||(this._startedListeningToKeyEvents=!0,this._controls.listenToKeyEvents(window.document.body))),this._syncedTransform=oe.getComponent(this.gameObject,Eh)??void 0}onDisable(){var e;(e=this._camera)!=null&&e.cam&&Hz(this._camera.cam,this,!1),this._controls&&(this._controls.enabled=!1,this._controls.autoRotate=!1,this._controls.removeEventListener("start",this.onControlsChangeStarted))}afterHandleInput(e){e.detail.args.pointerId===0&&(e.detail.args.isDown?this._controls&&this._eventSystem&&(this._shouldDisable=this._eventSystem.hasActiveUI):(!e.detail.args.isPressed||e.detail.args.isUp)&&(this._shouldDisable=!1))}onBeforeRender(){var e,t;if(!this._controls||this._cameraObject!==this.context.mainCamera)return;(this.context.input.getPointerDown(1)||this.context.input.getPointerDown(2)||this.context.input.mouseWheelChanged||this.context.input.getPointerPressed(0)&&(e=this.context.input.getPointerPositionDelta(0))!=null&&e.length()||0>.1)&&(this._inputs+=1),this._inputs>0&&this.allowInterrupt&&(this.enableRotate&&(this.autoRotate=!1),this._cameraLerpActive=!1,this._lookTargetLerpActive=!1),this._inputs=0;let s=this.middleClickToFocus&&this.context.input.getPointerClicked(1);if(s||(s=this.doubleClickToFocus&&this.context.input.getPointerDoubleClicked(0)&&this.context.time.time-this._enableTime>.3),s&&this.setTargetFromRaycast(),this._lookTargetLerpActive||this._cameraLerpActive){if(this._cameraLerpActive&&this._cameraObject)if(this._cameraLerp01+=this.context.time.deltaTime/this._cameraLerpDuration,this._cameraLerp01>=1)this._cameraObject.position.copy(this._cameraEndPosition),this._cameraLerpActive=!1,this.dispatchEvent(new Tv(this,"camera"));else{const r=st.easeInOutCubic(this._cameraLerp01);this._cameraObject.position.lerpVectors(this._cameraStartPosition,this._cameraEndPosition,r)}if(this._lookTargetLerpActive)if(this._lookTargetLerp01+=this.context.time.deltaTime/this._lookTargetLerpDuration,this._lookTargetLerp01>=1)this._controls.target.copy(this._lookTargetEndPosition),this._lookTargetLerpActive=!1,this.dispatchEvent(new Tv(this,"lookat"));else{const r=st.easeInOutCubic(this._lookTargetLerp01);this._controls.target.lerpVectors(this._lookTargetStartPosition,this._lookTargetEndPosition,r)}}if(this._controls){if(this.debugLog&&(this._controls.domElement=this.context.renderer.domElement),this._controls.enabled=!this._shouldDisable&&this._camera===this.context.mainCameraComponent&&!this.context.isInXR,this._controls.keys=this.enableKeys?fI:Hse,this._controls.autoRotate=this.autoRotate,this._controls.autoRotateSpeed=this.autoRotateSpeed,this._controls.enableZoom=this.enableZoom,this._controls.enableDamping=this.enableDamping,this._controls.dampingFactor=this.dampingFactor,this._controls.enablePan=this.enablePan,this._controls.enableRotate=this.enableRotate,typeof Q_=="number"||Q_===!0){this._controls.enableDamping=!0;const r=typeof Q_=="number"?Q_:.99;this._controls.dampingFactor=Math.max(.001,1-Math.min(1,r))}this.allowInterrupt||(this._lookTargetLerpActive&&(this._controls.enablePan=!1),this._cameraLerpActive&&(this._controls.enableRotate=!1,this._controls.autoRotate=!1),(this._lookTargetLerpActive||this._cameraLerpActive)&&(this._controls.enableZoom=!1)),this.context.isInXR||(!G_&&(t=this.lookAtConstraint)!=null&&t.locked&&this.setLookTargetFromConstraint(0,this.lookAtConstraint01),this._controls.update(),Vse&&Pt.DrawWireSphere(this._controls.target,.1,65280))}}setCameraAndLookTarget(e){if(!e||!(e instanceof ye))return;const t=Rt(e),s=qM(e);this.setTargetFromRaycast(new Wn(t,s)),this.setCameraTargetPosition(t)}setCameraTargetPosition(e,t=!1){var s,r;e&&(e instanceof ye&&(e=Rt(e)),this._cameraEndPosition||(this._cameraEndPosition=new w),this._cameraEndPosition.copy(e),t===!0?(this._cameraLerpActive=!1,(s=this.controllerObject)==null||s.position.copy(this._cameraEndPosition)):this._cameraObject&&(this._cameraLerpActive=!0,this._cameraLerp01=0,this._cameraStartPosition.copy((r=this._cameraObject)==null?void 0:r.position),typeof t=="number"?this._cameraLerpDuration=t:this._cameraLerpDuration=this.targetLerpDuration))}get cameraLerpActive(){return this._cameraLerpActive}stopCameraLerp(){this._cameraLerpActive=!1}setLookTargetPosition(e=null,t=!1){this._controls&&e&&(e instanceof ye&&(e=Rt(e)),this._lookTargetEndPosition.copy(e),t===!0?this._controls.target.copy(this._lookTargetEndPosition):(this._lookTargetLerpActive=!0,this._lookTargetLerp01=0,this._lookTargetStartPosition.copy(this._controls.target),typeof t=="number"?this._lookTargetLerpDuration=t:this._lookTargetLerpDuration=this.targetLerpDuration))}get lookTargetLerpActive(){return this._lookTargetLerpActive}stopLookTargetLerp(){this._lookTargetLerpActive=!1}setLookTargetFromConstraint(e=0,t=1){var s;if(!this._controls)return!1;const r=(s=this.lookAtConstraint)==null?void 0:s.sources;if(r&&r.length>0){const n=r[e];if(n)return n.getWorldPosition(this._lookTargetEndPosition),this.lerpLookTarget(this._lookTargetEndPosition,t),!0}return!1}lerpTarget(e,t){return this.lerpLookTarget(e,t)}lerpLookTarget(e,t){this._controls&&(t>=1?this._controls.target.copy(e):this._controls.target.lerp(e,t))}setTargetFromRaycast(e){var t,s;if(!this.controls)return;const r=e?this.context.physics.raycastFromRay(e):this.context.physics.raycast();for(const n of r)if(n.distance>0&&oe.isActiveInHierarchy(n.object)){const o=dI(n.object);if(o){const a=o.canvas;if(a!=null&&a.screenspace)break}if(this.setLookTargetPosition(n.point),this.context.mainCamera){const a=Rt(this.context.mainCamera).clone().sub(this.controls.target).add(this._lookTargetEndPosition);(s=(t=this._cameraObject)==null?void 0:t.parent)==null||s.worldToLocal(a),this.setCameraTargetPosition(a)}break}}fitCamera(e,t=1.1,s=!0){const r=this._cameraObject,n=this._controls;if(e!=null&&e.length||(e=this.context.scene.children),e.length<=0||!r||!n)return;const o=new w,a=new w,l=new Mi;l.makeEmpty();const c=[];function u(v){let b=!0;if(v.visible&&Sse(v)!==!1&&!(v.type==="TransformControlsGizmo"||v.type==="TransformControlsPlane")&&(v instanceof mC&&(b=!1),v instanceof N0&&(b=!1),v instanceof Vz&&(b=!1),v.material instanceof E0&&(b=!1),v instanceof ve||(b=!1),v!==r&&v.isUI!==!0)){if(b){Mv&&console.log(v.name,v.type,v);const _=v.children;v.children=c;const S=v.position,M=v.scale;if(Number.isNaN(S.x)||Number.isNaN(S.y)||Number.isNaN(S.z)){console.warn(`Object "${v.name}" has NaN values in position or scale.... will ignore it`,S,M);return}l.expandByObject(v,!0),v.children=_}for(const _ of v.children)u(_)}}for(const v of e)v.updateMatrixWorld(),u(v);if(r.updateMatrixWorld(),r.updateProjectionMatrix(),l.getCenter(a),l.applyMatrix4(r.matrixWorldInverse),l.getSize(o),l.setFromCenterAndSize(a,o),Number.isNaN(o.x)||Number.isNaN(o.y)||Number.isNaN(o.z)){console.warn("Camera fit size resultet in NaN",r,l,[...e]);return}if(o.length()<=1e-10){Mv&&console.warn("Camera fit size is zero",l,[...e]);return}const d=r.fov,p=2*Math.atan(Math.tan(d*Math.PI/360/2)*r.aspect)/Math.PI*360,f=o.y/(2*Math.atan(Math.PI*d/360)),m=o.x/(2*Math.atan(Math.PI*p/360)),A=t*Math.max(f,m)+o.z/2;Mv&&console.log("Fit camera to objects",f,m,"distance",A);const y=Rt(r),g=n.target.clone().sub(y).normalize().multiplyScalar(A);if(n.maxDistance=A*10,n.minDistance=A*.01,this.setLookTargetPosition(a,s),this.autoTarget=!1,r.near=A/1e3,r.far=A*100,r.updateMatrixWorld(),r.updateProjectionMatrix(),r.parent){const v=r.parent.worldToLocal(n.target.clone().sub(g));this.setCameraTargetPosition(v,s)}else console.error(`Can not fit camera ${r.name} because it has no parent`);if(Mv){const v=new mC(l);this.context.scene.add(v),KM(v,Jg(r)),this._haveAttachedKeyboardEvents||(this._haveAttachedKeyboardEvents=!0,document.body.addEventListener("keydown",b=>{b.code==="KeyF"&&this.fitCamera(e)}))}n.update()}}Cr([x()],zi.prototype,"autoFit",2),Cr([x()],zi.prototype,"enableRotate",2),Cr([x()],zi.prototype,"autoRotate",2),Cr([x()],zi.prototype,"autoRotateSpeed",2),Cr([x()],zi.prototype,"enableKeys",2),Cr([x()],zi.prototype,"enableDamping",2),Cr([x()],zi.prototype,"dampingFactor",2),Cr([x()],zi.prototype,"enableZoom",2),Cr([x()],zi.prototype,"minZoom",2),Cr([x()],zi.prototype,"maxZoom",2),Cr([x()],zi.prototype,"enablePan",2),Cr([x(_v)],zi.prototype,"lookAtConstraint",2),Cr([x()],zi.prototype,"lookAtConstraint01",2),Cr([x()],zi.prototype,"allowInterrupt",2),Cr([x()],zi.prototype,"middleClickToFocus",2),Cr([x()],zi.prototype,"doubleClickToFocus",2),Cr([x()],zi.prototype,"targetLerpDuration",2);var Wse=Object.defineProperty,Xse=Object.getOwnPropertyDescriptor,io=(i,e,t,s)=>{for(var r=s>1?void 0:s?Xse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Wse(e,t,r),r},sd=(i=>(i[i.Skybox=1]="Skybox",i[i.SolidColor=2]="SolidColor",i[i.Uninitialized=4]="Uninitialized",i))(sd||{});const rd=te("debugcam"),Kz=te("debugscreenpointtoray");var V_;const Iv=(V_=class extends Pe{constructor(){super(...arguments),h(this,"_nearClipPlane",.1),h(this,"_farClipPlane",1e3),h(this,"orthographic",!1),h(this,"orthographicSize",5),h(this,"ARBackgroundAlpha",0),h(this,"_cullingMask",4294967295),h(this,"_backgroundBlurriness"),h(this,"_backgroundIntensity"),h(this,"_environmentIntensity"),h(this,"_targetTexture",null),h(this,"_backgroundColor"),h(this,"_fov"),h(this,"_cam",null),h(this,"_clearFlags",2),h(this,"_skybox")}get isCamera(){return!0}get aspect(){return this._cam instanceof Ht?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._cam instanceof Ht?this._cam.fov:this._fov}set fieldOfView(i){const e=this.fieldOfView!=i;if(this._fov=i,e&&this._cam&&this._cam instanceof Ht){if(this._fov===void 0){console.warn("Can not set undefined fov on PerspectiveCamera");return}this._cam.fov=this._fov,this._cam.updateProjectionMatrix()}}get nearClipPlane(){return this._nearClipPlane}set nearClipPlane(i){const e=this._nearClipPlane!=i;this._nearClipPlane=i,this._cam&&e&&(this._cam.near=i,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(i){const e=this._farClipPlane!=i;this._farClipPlane=i,this._cam&&e&&(this._cam.far=i,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(i){i!==this._clearFlags&&(this._clearFlags=i,this.applyClearFlagsIfIsActiveCamera())}set cullingMask(i){this._cullingMask=i,this._cam&&(this._cam.layers.mask=i)}get cullingMask(){return this._cam?this._cam.layers.mask:this._cullingMask}set cullingLayer(i){this.cullingMask=(1<<i|0)>>>0}set backgroundBlurriness(i){i!==this._backgroundBlurriness&&(i===void 0?this._backgroundBlurriness=void 0:this._backgroundBlurriness=Math.min(Math.max(i,0),1),this.applyClearFlagsIfIsActiveCamera())}get backgroundBlurriness(){return this._backgroundBlurriness}set backgroundIntensity(i){i!==this._backgroundIntensity&&(i===void 0?this._backgroundIntensity=void 0:this._backgroundIntensity=Math.min(Math.max(i,0),10),this.applyClearFlagsIfIsActiveCamera())}get backgroundIntensity(){return this._backgroundIntensity}set environmentIntensity(i){this._environmentIntensity=i}get environmentIntensity(){return this._environmentIntensity}get backgroundColor(){return this._backgroundColor??null}set backgroundColor(i){if(i){if(this._backgroundColor)this._backgroundColor.copy(i);else{if(!i.clone)return;this._backgroundColor=i.clone()}i.alpha===void 0&&(this._backgroundColor.alpha=1),this.applyClearFlagsIfIsActiveCamera()}}set targetTexture(i){this._targetTexture=i}get targetTexture(){return this._targetTexture}get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}screenPointToRay(i,e,t){const s=this.cam,r=Iv._origin;r.set(i,e,-1),this.context.input.convertScreenspaceToRaycastSpace(r),Kz&&console.log("screenPointToRay",i.toFixed(2),e.toFixed(2),"now:",r.x.toFixed(2),r.y.toFixed(2),"isInXR:"+this.context.isInXR),r.z=-1,r.unproject(s);const n=Iv._direction.set(r.x,r.y,r.z),o=Rt(s);return n.sub(o),n.normalize(),t?(t.set(o,n),t):new Wn(o.clone(),n.clone())}awake(){Kz&&window.addEventListener("pointerdown",i=>{const e=i.clientX,t=i.clientY;console.log("touch",e.toFixed(2),t.toFixed(2));const s=this.screenPointToRay(e,t),r="#"+Math.floor(Math.random()*16777215).toString(16);Pt.DrawRay(s.origin,s.direction,r,10)})}onEnable(){rd&&console.log(`Camera enabled: "${this.name}". ClearFlags=${sd[this._clearFlags]}`,this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&(this.context.setCurrentCamera(this),Yse(this)),this.applyClearFlagsIfIsActiveCamera()}onDisable(){this.context.removeCamera(this)}onBeforeRender(){if(this._cam&&(this._clearFlags===2&&this.applyClearFlagsIfIsActiveCamera(),this._targetTexture)){this.context.isManagedExternally&&(this._warnedAboutExternalRenderer||(this._warnedAboutExternalRenderer=!0,console.warn("Rendering with external renderer is not supported yet. This may not work or throw errors. Please remove the the target texture from your camera: "+this.name,this.targetTexture))),this.context.composer;const i=this.context.renderer;if(i){const e=this.context.mainCameraComponent;this.applyClearFlags(),this._targetTexture.render(this.context.scene,this._cam,i),e?.applyClearFlags()}}}buildCamera(){if(this._cam)return;const i=this.gameObject.isCamera;let e=null;if(i?(e=this.gameObject,e?.layers.enableAll(),e instanceof Ht&&(this._fov=e.fov)):e=this.gameObject.children[0],e&&e.isCamera)e instanceof Ht&&(this._fov&&(e.fov=this._fov),e.near=this._nearClipPlane,e.far=this._farClipPlane,e.updateProjectionMatrix());else if(!this.orthographic)e=new Ht(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),this.fieldOfView&&(e.fov=this.fieldOfView),this.gameObject.add(e);else{const t=this.orthographicSize*100;e=new Ul(window.innerWidth/-t,window.innerWidth/t,window.innerHeight/t,window.innerHeight/-t,this._nearClipPlane,this._farClipPlane),this.gameObject.add(e)}this._cam=e,this._cam.layers.mask=this._cullingMask,this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){this.context.mainCameraComponent===this&&this.applyClearFlags()}applyClearFlags(){if(!this._cam){rd&&console.log("Camera does not exist (apply clear flags)");return}if(this.fieldOfView=this._fov,rd){const i=`Camera "${this.name}" clear flags: ${sd[this._clearFlags]}`;console.log(i)}switch(this._clearFlags){case 1:if(Iv.backgroundShouldBeTransparent(this.context)&&(!this.ARBackgroundAlpha||this.ARBackgroundAlpha<.001)){this.context.scene.background=null,this.context.renderer.setClearColor(0,0);return}this.enableSkybox(),this._backgroundBlurriness!==void 0&&(this.context.scene.backgroundBlurriness=this._backgroundBlurriness),this._backgroundIntensity!==void 0&&(this.context.scene.backgroundIntensity=this._backgroundIntensity);break;case 2:if(this._backgroundColor){let i=this._backgroundColor.alpha;Iv.backgroundShouldBeTransparent(this.context)&&(i=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,i)}else rd&&console.warn(`Camera "${this.name}" has no background color`,this);break;case 4:this.context.scene.background=null,this.context.renderer.setClearColor(0,0);break}}enableSkybox(){this._skybox||(this._skybox=new qse(this)),this._skybox.enable()}static backgroundShouldBeTransparent(i){var e,t,s,r;const n=(e=i.renderer.xr)==null?void 0:e.getSession();if(!n)return!1;if(typeof n._transparent=="boolean")return n._transparent;const o=n.environmentBlendMode;rd&&ms("Environment blend mode: "+o+" on "+navigator.userAgent);let a=o==="additive"||o==="alpha-blend";return i.isInAR&&o==="opaque"&&((t=navigator.userAgent)!=null&&t.includes("OculusBrowser")||(s=navigator.userAgent)!=null&&s.includes("Mozilla")&&(r=navigator.userAgent)!=null&&r.includes("Mobile WebXRViewer/v2"))&&(a=!0),n._transparent=a,a}},h(V_,"_origin",new w),h(V_,"_direction",new w),V_);let ji=Iv;io([x()],ji.prototype,"fieldOfView",1),io([x()],ji.prototype,"nearClipPlane",1),io([x()],ji.prototype,"farClipPlane",1),io([x()],ji.prototype,"clearFlags",1),io([x()],ji.prototype,"orthographic",2),io([x()],ji.prototype,"orthographicSize",2),io([x()],ji.prototype,"ARBackgroundAlpha",2),io([x()],ji.prototype,"cullingMask",1),io([x()],ji.prototype,"backgroundBlurriness",1),io([x()],ji.prototype,"backgroundIntensity",1),io([x()],ji.prototype,"environmentIntensity",1),io([x(Si)],ji.prototype,"backgroundColor",1),io([x(cf)],ji.prototype,"targetTexture",1);class qse{constructor(e){h(this,"_camera"),h(this,"_skybox"),this._camera=e}get context(){var e;return(e=this._camera)==null?void 0:e.context}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?this.context.scene.background!==this._skybox&&(rd&&console.log(`Camera "${this._camera.name}" set skybox`,this._camera,this._skybox),this._skybox.colorSpace=Gt,this._skybox.mapping=bo,this.context.scene.background=this._skybox):(this._did_log_failed_to_find_skybox||(this._did_log_failed_to_find_skybox=!0,console.warn(`Camera "${this._camera.name}" failed to load/find skybox texture`,this._camera.sourceId,this.context.lightmaps,"Current background: ",this.context.scene.background)),(rd||wt())&&is(`Camera "${this._camera.name}" has no skybox texture`))}}function Yse(i){te("freecam")&&i.context.mainCameraComponent===i&&oe.getOrAddComponent(i.gameObject,zi)}class Th extends Pe{constructor(){super(...arguments),h(this,"_listener",null)}get listener(){return this._listener==null&&(this._listener=new nk),this._listener}awake(){vs.registerWaitForAllowAudio(()=>{if(this.destroyed)return;const e=this.listener;if(e==null||e.parent)return;const t=this.context.mainCameraComponent||oe.getComponentInParent(this.gameObject,ji);t!=null&&t.cam?t.cam.add(e):this.gameObject.add(e)})}}var Jse=Object.defineProperty,Kse=Object.getOwnPropertyDescriptor,H_=(i,e,t,s)=>{for(var r=s>1?void 0:s?Kse(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Jse(e,t,r),r};const Zse=te("debugsignals");class Rv{constructor(){h(this,"guid")}}H_([x()],Rv.prototype,"guid",2);class bf{constructor(){h(this,"signal"),h(this,"reaction")}}H_([x(Rv)],bf.prototype,"signal",2),H_([x(tr)],bf.prototype,"reaction",2);var mI;const gc=(mI=class extends Pe{constructor(){super(...arguments),h(this,"events")}static invoke(i){if(gc.receivers[i]){const e=gc.receivers[i];if(!e)return;for(const t of e)t.invoke(i)}}awake(){Zse&&console.log("SignalReceiver awake",this)}onEnable(){if(this.events)for(const i of this.events)gc.receivers[i.signal.guid]||(gc.receivers[i.signal.guid]=[]),gc.receivers[i.signal.guid].push(this)}onDisable(){if(this.events){for(const i of this.events)if(gc.receivers[i.signal.guid]){const e=gc.receivers[i.signal.guid].indexOf(this);e>=0&&gc.receivers[i.signal.guid].splice(e,1)}}}invoke(i){if(!this.events||!Array.isArray(this.events))return;const e=typeof i=="object"?i.guid:i;for(const t of this.events)if(t.signal.guid===e)try{if(t.reaction){if(!t.reaction.invoke){console.warn("Missing invoke - possibly a serialization error",t,this);continue}}else{console.warn("Missing reaction for signal",t,this);continue}t.reaction.invoke()}catch(s){console.error(s)}}},h(mI,"receivers",{}),mI);let _f=gc;H_([x(bf)],_f.prototype,"events",2);var so=(i=>(i.Activation="ActivationTrack",i.Animation="AnimationTrack",i.Audio="AudioTrack",i.Control="ControlTrack",i.Marker="MarkerTrack",i.Signal="SignalTrack",i))(so||{}),el=(i=>(i[i.None=0]="None",i[i.Hold=1]="Hold",i[i.Loop=2]="Loop",i[i.PingPong=3]="PingPong",i[i.Continue=4]="Continue",i))(el||{}),gI=(i=>(i.Signal="SignalEmitter",i))(gI||{});const tl=te("debugtimeline");class Pv{constructor(){h(this,"director"),h(this,"track")}get muted(){return this.track.muted}set muted(e){var t;e!==this.track.muted&&(this.track.muted=e,(t=this.onMuteChanged)==null||t.call(this))}*forEachClip(e=!1){var t;if((t=this.track)!=null&&t.clips)if(e)for(let s=this.track.clips.length-1;s>=0;s--)yield this.track.clips[s];else for(const s of this.track.clips)yield s}getClipTime(e,t){return t.clipIn+(e-t.start)*t.timeScale}getClipTimeNormalized(e,t){return(e-t.start)/t.duration}evaluateWeight(e,t,s,r=!0){if(t<0||t>=s.length)return 0;const n=s[t];if(r||e>=n.start&&e<=n.end){let o=1;const a=!1;if(n.easeInDuration>0){const l=Math.min((e-n.start)/n.easeInDuration,1);o*=l}if(n.easeOutDuration>0&&!a){const l=Math.min((n.end-e)/n.easeOutDuration,1);o*=l}return o}return 0}}class $se{constructor(e){h(this,"clip"),h(this,"rootPositionOffset"),h(this,"rootQuaternionOffset"),h(this,"rootStartPosition"),h(this,"rootEndPosition"),h(this,"rootStartQuaternion"),h(this,"rootEndQuaternion");const t=e.getClip();this.clip=t;const s=e.getRoot(),r=s.name+".position",n=s.name+".quaternion";tl&&console.log(t.name,t.tracks,r);for(const o of t.tracks)if(!(o.times.length<=0)){if(o.name.endsWith(r))this.rootStartPosition=new w().fromArray(o.values,0),this.rootEndPosition=new w().fromArray(o.values,o.values.length-3),this.rootPositionOffset=this.rootEndPosition.clone().sub(this.rootStartPosition),tl&&console.log(this.rootPositionOffset);else if(o.name.endsWith(n)&&(this.rootStartQuaternion=new Ie().fromArray(o.values,0),this.rootEndQuaternion=new Ie().fromArray(o.values,o.values.length-4),this.rootQuaternionOffset=this.rootEndQuaternion.clone().multiply(this.rootStartQuaternion),tl)){const a=new Ur().setFromQuaternion(this.rootQuaternionOffset);console.log("ROT",a)}}}get hasOffsets(){return this.rootPositionOffset!==void 0||this.rootQuaternionOffset!==void 0}}class W_ extends Pv{constructor(){super(...arguments),h(this,"models",[]),h(this,"trackOffset"),h(this,"target"),h(this,"mixer"),h(this,"clips",[]),h(this,"actions",[]),h(this,"_actionOffsets",[]),h(this,"_didBind",!1),h(this,"_animator",null),h(this,"_useclipOffsets",!0),h(this,"_totalOffsetPosition",new w),h(this,"_totalOffsetRotation",new Ie),h(this,"_totalOffsetPosition2",new w),h(this,"_totalOffsetRotation2",new Ie),h(this,"_summedPos",new w),h(this,"_tempPos",new w),h(this,"_summedRot",new Ie),h(this,"_tempRot",new Ie),h(this,"_clipRotQuat",new Ie)}onStateChanged(){this._animator&&Zz(this._animator.gameObject,this,this.director.isPlaying)}createHooks(e,t){var s,r;if(((s=t.tracks)==null?void 0:s.length)<=0){console.warn("No tracks in AnimationClip",t);return}const n=t.tracks[0].name.split("."),o=n[n.length-2],a=o+".position",l=o+".quaternion";let c=!1,u=!1;for(const d of t.tracks)d.name.endsWith(a)?(c=!0,this.createPositionInterpolant(t,e,d)):d.name.endsWith(l)&&(u=!0,this.createRotationInterpolant(t,e,d));if(!c||!u){const d=(r=this.mixer)==null?void 0:r.getRoot(),p=t.tracks[0],f=p.name.lastIndexOf("."),m=p.name.substring(0,f),A=m.substring(m.lastIndexOf(".")+1),y=d.getObjectByName(A);if(y)if(c){if(!u){const g=t.tracks[0].name.substring(0,f)+".quaternion";tl&&console.warn("Create quaternion track",A,y);const v=y.quaternion,b=new Na(g,[0,t.duration],[v.x,v.y,v.z,v.w,v.x,v.y,v.z,v.w]);t.tracks.push(b),this.createRotationInterpolant(t,e,b)}}else{const g=m+".position";tl&&console.warn("Create position track",A,y);const v=y.position,b=new Nl(g,[0,t.duration],[v.x,v.y,v.z,v.x,v.y,v.z]);t.tracks.push(b),this.createPositionInterpolant(t,e,b)}}}bind(){if(!this._didBind){this._didBind=!0,tl&&console.log(this.models),this.mixer?this.target=this.mixer.getRoot():console.warn("No mixer was assigned to animation track");for(const e of this.actions){const t=new $se(e);this._actionOffsets.push(t)}this.target&&(this._animator=oe.getComponent(this.target,Er)??null,this._animator&&Zz(this._animator.gameObject,this,!0));for(const e of this.models){const t=e.asset,s=t.position,r=t.rotation;s&&s.x!==void 0&&(s.isVector3||(t.position=new w(s.x,s.y,s.z)),r.isQuaternion||(t.rotation=new Ie(r.x,r.y,r.z,r.w)))}this.ensureTrackOffsets()}}ensureTrackOffsets(){if(this.trackOffset){const e=this.trackOffset.position;e&&(e.isVector3||(this.trackOffset.position=new w(e.x,e.y,e.z)));const t=this.trackOffset.rotation;t&&(t.isQuaternion||(this.trackOffset.rotation=new Ie(t.x,t.y,t.z,t.w)))}}evaluate(e){var t,s,r,n,o,a,l;if(this.track.muted||!this.mixer)return;this.bind(),this._totalOffsetPosition.set(0,0,0),this._totalOffsetRotation.set(0,0,0,1),this._totalOffsetPosition2.set(0,0,0),this._totalOffsetRotation2.set(0,0,0,1);let c=0,u=0,d=!1,p=!1,f=0;for(let m=0;m<this.clips.length;m++){const A=this.models[m],y=this.actions[m],g=A.asset;y.weight=0;const v=e>=A.start&&e<=A.end,b=A.preExtrapolationMode,_=A.postExtrapolationMode,S=m<this.clips.length-1?this.models[m+1]:null;let M=v,C=!1;if(!M&&!d&&A.end<e&&_!==el.None?(!S||S.start>e)&&(M=!0,d=!0):m==0&&!M&&!p&&A.start>e&&b!==el.None&&(!S||S.start<e)&&(M=!0,C=!0,p=!0),M){let R=1;R*=this.evaluateWeight(e,m,this.models,M),R*=this.director.weight;let I=v;if(C)switch(b){case el.Hold:break;case el.Loop:e+=A.start,I=!0;break;default:e+=A.start,I=!0;break}let E=this.getClipTime(e,A),z=0;const F=g.duration;if(C&&b===el.Hold&&(E=0),I){if(g.loop)for(z+=Math.floor(E/(F+1e-6));E>F;)E-=F}else if(!v&&d)switch(_){case el.Hold:E=this.getClipTime(A.end,A);break;case el.Loop:E%=F;break;case el.PingPong:const N=Math.floor(E/F)%2!==0;E%=F,N&&(E=F-E);break}A.reversed===!0?y.time=y.getClip().duration-E:y.time=E,y.timeScale=0;const q=Math.max(0,R);if(y.weight=q,f+=q,y.clampWhenFinished=!1,y.isRunning()||y.play(),this._useclipOffsets){const N=c==0?this._totalOffsetPosition:this._totalOffsetPosition2,H=c==0?this._totalOffsetRotation:this._totalOffsetRotation2;c<1&&(u=1-R),c+=1;const L=this._summedPos.set(0,0,0),j=this._tempPos.set(0,0,0),Q=this._summedRot.identity(),$=this._tempRot.identity(),Z=g.rotation;Z&&(this._clipRotQuat.identity(),this._clipRotQuat.slerp(Z,R));const se=this._actionOffsets[m];if(se.hasOffsets)for(let Ae=0;Ae<z;Ae++)se.rootPositionOffset?j.copy(se.rootPositionOffset):j.set(0,0,0),j.applyQuaternion(Q),this._clipRotQuat&&j.applyQuaternion(this._clipRotQuat),se.rootQuaternionOffset&&($.copy(se.rootQuaternionOffset),Q.multiply($)),L.add(j);this._clipRotQuat&&H.multiply(this._clipRotQuat),H.multiply(Q),g.position&&L.add(g.position),N.add(L)}}}if(this._useclipOffsets&&(this._totalOffsetPosition.lerp(this._totalOffsetPosition2,u),this._totalOffsetRotation.slerp(this._totalOffsetRotation2,u)),this.__mixerError===void 0&&(tl||wt())&&(s=(t=this._animator)==null?void 0:t.runtimeAnimatorController)!=null&&s.mixer&&this.mixer!==((n=(r=this._animator)==null?void 0:r.runtimeAnimatorController)==null?void 0:n.mixer)&&(this.__mixerError=!0,console.error("AnimationTrack mixer is not shared with the animator controller - this might result in the timeline to not animate properly. Please report a bug to the Needle Engine team!",this)),(o=this._animator)!=null&&o.runtimeAnimatorController){const m=Math.max(0,1-f);(l=(a=this._animator)==null?void 0:a.runtimeAnimatorController)==null||l.update(m)}else this.mixer.update(e)}createRotationInterpolant(e,t,s){var r;const n=s.createInterpolant.bind(s),o=new Ie;this.ensureTrackOffsets();const a=(r=this.trackOffset)==null?void 0:r.rotation;s.createInterpolant=()=>{const l=n(),c=l.evaluate.bind(l);return l.evaluate=u=>{var d;const p=c(u);if(o.set(p[0],p[1],p[2],p[3]),o.premultiply(this._totalOffsetRotation),a&&o.premultiply(a),this.director.animationCallbackReceivers)for(const f of this.director.animationCallbackReceivers)(d=f?.onTimelineRotation)==null||d.call(f,this.director,this.target,u,o);return p[0]=o.x,p[1]=o.y,p[2]=o.z,p[3]=o.w,p},l}}createPositionInterpolant(e,t,s){var r,n;const o=s.createInterpolant.bind(s),a=new w;this.ensureTrackOffsets();const l=(r=this.trackOffset)==null?void 0:r.rotation,c=(n=this.trackOffset)==null?void 0:n.position;let u;s.createInterpolant=()=>{const d=o(),p=d.evaluate.bind(d);return d.evaluate=f=>{var m,A,y;const g=p(f);if(a.set(g[0],g[1],g[2]),t.removeStartOffset&&(u===void 0?(u=null,u=(A=(m=this._actionOffsets.find(v=>v.clip===e))==null?void 0:m.rootStartPosition)==null?void 0:A.clone()):u!=null&&u.isVector3&&a.sub(u)),a.applyQuaternion(this._totalOffsetRotation),a.add(this._totalOffsetPosition),l&&a.applyQuaternion(l),c&&(a.x-=c.x,a.y+=c.y,a.z+=c.z),this.director.animationCallbackReceivers)for(const v of this.director.animationCallbackReceivers)(y=v?.onTimelinePosition)==null||y.call(v,this.director,this.target,f,a);return g[0]=a.x,g[1]=a.y,g[2]=a.z,g},d}}}const ere=te("mutetimeline"),Bv=class extends Pv{constructor(){super(...arguments),h(this,"models",[]),h(this,"listener"),h(this,"audio",[]),h(this,"audioContextTimeOffset",[]),h(this,"lastTime",0),h(this,"audioSource"),h(this,"_audioLoader",null),h(this,"_playableDirectorResumed",!1)}getAudioFilePath(i){const e=this.director.sourceId;return sh(e,i)}onAllowAudioChanged(i){for(let e=0;e<this.models.length;e++){const t=this.models[e];this.audio[e].setVolume(i?t.asset.volume:0)}}addModel(i){const e=new aC(this.listener);this.audio.push(e);const t=i;t._didTriggerPlay=!1,this.models.push(t)}onDisable(){for(const i of this.audio)i.isPlaying&&i.stop();for(const i of this.models)i._didTriggerPlay=!1}onDestroy(){for(const i of this.audio)i.source&&i?.disconnect();this.audio.length=0}onMuteChanged(){if(this.muted)for(let i=0;i<this.audio.length;i++){const e=this.audio[i];e!=null&&e.isPlaying&&e.stop()}}stop(){for(let i=0;i<this.audio.length;i++){const e=this.audio[i];e!=null&&e.isPlaying&&e.stop()}for(const i of this.models)i._didTriggerPlay=!1}onPauseChanged(){for(let i=0;i<this.audio.length;i++){const e=this.audio[i];e!=null&&e.isPlaying&&e.stop()}this._playableDirectorResumed=this.director.isPlaying}evaluate(i){if(ere||this.track.muted||this.director.speed<0)return;const e=this.director.context.application.muted,t=this._playableDirectorResumed;this._playableDirectorResumed=!1;const s=e?.1:0;for(let r=0;r<this.models.length;r++){const n=this.models[r],o=this.audio[r],a=n.asset;if((!o||!o.buffer)&&this.isInTimeRange(n,i-1,i+1)&&this.handleAudioLoading(n,o),vs.userInteractionRegistered!==!1&&!(o===null||!o.buffer))if(o.playbackRate=this.director.context.time.timeScale*this.director.speed,o.loop=a.loop,i>=n.start&&i<=n.end&&i<this.director.duration){if(!o.isPlaying||!this.director.isPlaying)(t||!n._didTriggerPlay&&this.lastTime<i)&&(n.duration*n.timeScale>.3?o.offset=n.clipIn+(i-n.start)*n.timeScale:o.offset=0,tl&&console.log("Timeline Audio ("+this.track.name+") play with offset "+o.offset+" - "+n.asset.clip),o.play(s),n._didTriggerPlay=!0);else{const c=n.clipIn+(i-n.start)*n.timeScale,u=o.context.currentTime-o._startedAt+o.offset;Math.abs(c-u)>.3&&(o.offset=c,o.stop(),o.play(s))}let l=a.volume;if(this.track.volume!==void 0&&(l*=this.track.volume),e&&(l=0),n.easeInDuration>0){const c=Math.min((i-n.start)/n.easeInDuration,1);l*=c}if(n.easeOutDuration>0){const c=Math.min((n.end-i)/n.easeOutDuration,1);l*=c}o.setVolume(l*this.director.weight)}else n._didTriggerPlay=!1,this.director.isPlaying&&o.isPlaying&&o.stop()}this.lastTime=i}loadAudio(i,e=0,t=0){let s=null;const r=i-t,n=i+e;for(const o of this.models)if(this.isInTimeRange(o,r,n)){const a=this.audio[this.models.indexOf(o)],l=this.handleAudioLoading(o,a);l!==null&&(s===null&&(s=[]),s.push(l))}return s!==null?Promise.all(s):null}isInTimeRange(i,e,t){return e<=i.start&&t>=i.end||e>=i.start&&e<=i.end||t>=i.start&&t<=i.end}static dispose(){Bv._audioBuffers.clear()}handleAudioLoading(i,e){this._audioLoader||(this._audioLoader=new k0);const t=this.getAudioFilePath(i.asset.clip);if(Bv._audioBuffers.get(t)){const r=Bv._audioBuffers.get(t);return r.then(n=>{n&&e.setBuffer(n)}),r}tl&&console.warn("LOAD audio track",t,this.director.sourceId);const s=new Promise((r,n)=>{this._audioLoader.load(t,o=>{e.setBuffer(o),r(o)},void 0,o=>{console.error("Error loading audio",o),r(null)})});return Bv._audioBuffers.set(t,s),s}};let Dv=Bv;h(Dv,"_audioBuffers",new Map);class kv extends Pv{constructor(){super(...arguments),h(this,"models",[]),h(this,"didTrigger",[]),h(this,"receivers",[])}evaluate(e){var t;if(this.track.muted)return;const s=this.director.context.time.deltaTime*1.5;for(let r=0;r<this.models.length;r++){const n=this.models[r],o=this.didTrigger[r],a=n.time-e;let l=!1;if(n.retroActive)l=a<=1e-6;else{const c=Math.abs(a);(c===0||c>=1e-5&&c<s)&&(l=!0)}if(l){if(!o)if(tl&&console.log("Trigger signal",e,n.time,n),this.didTrigger[r]=!0,((t=this.receivers)==null?void 0:t.length)<=0)_f.invoke(n.asset);else for(const c of this.receivers)c&&c.invoke(n.asset)}else n.emitOnce||(this.didTrigger[r]=!1)}}}class X_ extends Pv{constructor(){super(...arguments),h(this,"models",[]),h(this,"timelines",[]),h(this,"_previousActiveModel",null)}resolveSourceObjects(e){for(let t=this.models.length-1;t>=0;t--){const s=this.models[t].asset;if(!s.sourceObject||typeof s.sourceObject!="object"){console.log("no source object, removing model",t,s),this.models.splice(t,1);continue}else{const r=oe.getComponent(s.sourceObject,nd);this.timelines.push(r),r&&s.updateDirector&&(r.playOnAwake=!1)}}}evaluate(e){var t;this._previousActiveModel=null;for(let s=0;s<this.models.length;s++){const r=this.models[s],n=r.asset;if(e>=r.start&&e<=r.end){this._previousActiveModel=r;const o=this.getClipTime(e,r);if(n.controlActivation){const a=n.sourceObject;a.visible=!0}if(n.updateDirector){const a=this.timelines[s];a&&(a.isPlaying&&a.pause(),a.time=o,a.evaluate())}}else{const o=(t=this._previousActiveModel)==null?void 0:t.asset;if(n.controlActivation){const a=n.sourceObject;o?.sourceObject!==a&&(a.visible=!1)}}}}}const xf=te("debugtimeline"),vI=class extends Pe{constructor(){super(...arguments),h(this,"playableAsset"),h(this,"playOnAwake"),h(this,"extrapolationMode",1),h(this,"waitForAudio",!0),h(this,"_visibilityChangeEvt"),h(this,"_clonedPlayableAsset",!1),h(this,"_speed",1),h(this,"_guidsMap"),h(this,"_isPlaying",!1),h(this,"_internalUpdateRoutine"),h(this,"_isPaused",!1),h(this,"_isStopping",!1),h(this,"_time",0),h(this,"_duration",0),h(this,"_weight",1),h(this,"_animationTracks",[]),h(this,"_audioTracks",[]),h(this,"_signalTracks",[]),h(this,"_controlTracks",[]),h(this,"_customTracks",[]),h(this,"_allTracks",[this._animationTracks,this._audioTracks,this._signalTracks,this._controlTracks,this._customTracks]),h(this,"animationCallbackReceivers",[])}static registerCreateTrack(i,e){this.createTrackFunctions[i]=e}get isPlaying(){return this._isPlaying}get isPaused(){return this._isPaused}get time(){return this._time}set time(i){typeof i=="number"&&!Number.isNaN(i)?this._time=i:(xf||un())&&console.error("INVALID TIMELINE.TIME VALUE",i,this.name)}get duration(){return this._duration}set duration(i){this._duration=i}get weight(){return this._weight}set weight(i){this._weight=i}get speed(){return this._speed}set speed(i){this._speed=i}awake(){var i,e,t;xf&&console.log(this,(i=this.playableAsset)==null?void 0:i.tracks),this.rebuildGraph(),this.isValid()||console.warn("PlayableDirector is not valid",this.playableAsset,(e=this.playableAsset)==null?void 0:e.tracks,Array.isArray((t=this.playableAsset)==null?void 0:t.tracks),this)}onEnable(){var i,e,t;for(const s of this._audioTracks)(i=s.onEnable)==null||i.call(s);for(const s of this._customTracks)(e=s.onEnable)==null||e.call(s);for(const s of this._animationTracks)(t=s.onEnable)==null||t.call(s);this.playOnAwake&&this.play(),this._visibilityChangeEvt||(this._visibilityChangeEvt=()=>{switch(document.visibilityState){case"hidden":this.setAudioTracksAllowPlaying(!1);break;case"visible":this.setAudioTracksAllowPlaying(!0);break}}),window.addEventListener("visibilitychange",this._visibilityChangeEvt)}onDisable(){var i,e,t;this.stop();for(const s of this._audioTracks)(i=s.onDisable)==null||i.call(s);for(const s of this._customTracks)(e=s.onDisable)==null||e.call(s);for(const s of this._animationTracks)(t=s.onDisable)==null||t.call(s);this._visibilityChangeEvt&&window.removeEventListener("visibilitychange",this._visibilityChangeEvt)}onDestroy(){var i;for(const e of this._allTracks)for(const t of e)(i=t.onDestroy)==null||i.call(t)}rebuildGraph(){this.isValid()&&(this.resolveBindings(),this.updateTimelineDuration(),this.setupAndCreateTrackHandlers())}async play(){if(!this.isValid())return;const i=this._isPaused==!0;if(this._isPaused=!1,!this._isPlaying){if(this._isPlaying=!0,i&&this.invokePauseChangedMethodsOnTracks(),this.waitForAudio){const e=[];for(const t of this._audioTracks){const s=t.loadAudio(this._time,1,0);s&&e.push(s)}if(e.length>0&&(await Promise.all(e),!this._isPlaying))return;for(;this._audioTracks.length>0&&this._isPlaying&&!vs.userInteractionRegistered&&this.waitForAudio;)await Co(200)}this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine=this.startCoroutine(this.internalUpdate(),ks.LateUpdate)}}pause(){this.isValid()&&(this._isPlaying=!1,!this._isPaused&&(this._isPaused=!0,this.internalEvaluate(),this.invokePauseChangedMethodsOnTracks(),this.invokeStateChangedMethodsOnTracks()))}stop(){this._isStopping=!0;for(const t of this._audioTracks)t.stop();const i=this._isPaused==!0,e=this._isPlaying;this._isPlaying&&(this._time=0,this._isPlaying=!1,this._isPaused=!1,this.internalEvaluate(),i&&this.invokePauseChangedMethodsOnTracks()),this._isPlaying=!1,this._isPaused=!1,i&&!e&&this.invokePauseChangedMethodsOnTracks(),e&&this.invokeStateChangedMethodsOnTracks(),this._internalUpdateRoutine&&this.stopCoroutine(this._internalUpdateRoutine),this._internalUpdateRoutine=null,this._isStopping=!1}evaluate(){this.internalEvaluate(!0)}isValid(){return this.playableAsset&&this.playableAsset.tracks&&Array.isArray(this.playableAsset.tracks)}*forEachTrack(){for(const i of this._allTracks)for(const e of i)yield e}get audioTracks(){return this._audioTracks}resolveGuids(i){this._guidsMap=i}invokePauseChangedMethodsOnTracks(){var i;for(const e of this.forEachTrack())(i=e.onPauseChanged)==null||i.call(e)}invokeStateChangedMethodsOnTracks(){var i;for(const e of this.forEachTrack())(i=e.onStateChanged)==null||i.call(e,this._isPlaying)}*internalUpdate(){for(;this._isPlaying&&this.activeAndEnabled;)!this._isPaused&&this._isPlaying&&(this._time+=this.context.time.deltaTime*this.speed,this.internalEvaluate()),yield}internalEvaluate(i=!1){if(!this.isValid())return;let e=this._time;switch(this.extrapolationMode){case 0:this._speed>0?e=Math.min(e,this._duration):this._speed<0&&(e=Math.max(e,0)),this._time=e;break;case 1:e%=this._duration,this._time=e;break;case 2:if(e>this._duration){this.stop();return}break}const t=this._time;for(const s of this.playableAsset.tracks)if(!s.muted)switch(s.type){case so.Activation:if(!i&&!this._isPlaying)continue;for(let r=0;r<s.outputs.length;r++){const n=s.outputs[r];if(typeof n=="object"){let o=!1;if(s.clips)for(const l of s.clips)l.start<=t&&t<=l.end&&(o=!0);const a=n;a.visible!==void 0&&a.visible!==o&&(a.visible=o,xf&&console.warn(this.name,"set ActivationTrack-"+r,a.name,o,t))}}break}if(!this._isStopping)for(const s of this._animationTracks)s.evaluate(t);for(const s of this._audioTracks)s.evaluate(t);for(const s of this._signalTracks)s.evaluate(t);for(const s of this._controlTracks)s.evaluate(t);for(const s of this._customTracks)s.evaluate(t)}resolveBindings(){if(this._clonedPlayableAsset||(this._clonedPlayableAsset=!0,this.playableAsset=og(this.playableAsset)),!this.playableAsset||!this.playableAsset.tracks)return;const i=this.findRoot(this.gameObject);for(const e of this.playableAsset.tracks){for(let t=e.outputs.length-1;t>=0;t--){let s=e.outputs[t];if(typeof s=="string"){this._guidsMap&&this._guidsMap[s]&&(s=this._guidsMap[s]);const r=oe.findByGuid(s,i);r===null||typeof r!="object"?(e.outputs.splice(t,1),console.warn("Failed to resolve binding",s,e.name,e.type)):(xf&&console.log("Resolved binding",s,"to",r),e.outputs[t]=r)}else if(s===null){if(e.outputs.splice(t,1),vI.createTrackFunctions[e.type])continue;e.type!==so.Audio&&e.type!==so.Control&&e.type!==so.Marker&&e.type!==so.Signal&&console.warn("Missing binding",s,e.name,e.type,this.name,this.playableAsset.name)}}if(e.type===so.Control&&e.clips)for(let t=0;t<e.clips.length;t++){const s=e.clips[t];let r=s.asset.sourceObject;if(typeof r=="string"){this._guidsMap&&this._guidsMap[r]&&(r=this._guidsMap[r]);const n=oe.findByGuid(r,i);n===null||typeof n!="object"?console.warn("Failed to resolve sourceObject binding",r,e.name,s):(xf&&console.log("Resolved binding",r,"to",n),s.asset.sourceObject=n)}}}}findRoot(i){return i.parent?this.findRoot(i.parent):i}updateTimelineDuration(){if(this._duration=0,!(!this.playableAsset||!this.playableAsset.tracks)){for(const i of this.playableAsset.tracks)if(i.muted!==!0){if(i.clips)for(const e of i.clips)e.end>this._duration&&(this._duration=e.end);if(i.markers)for(const e of i.markers)e.time>this._duration&&(this._duration=e.time+.001)}}}setupAndCreateTrackHandlers(){var i,e,t;if(this._animationTracks.length=0,this._audioTracks.length=0,this._signalTracks.length=0,!this.playableAsset)return;let s=oe.findObjectOfType(Th,this.context);for(const r of this.playableAsset.tracks){const n=r.type,o=vI.createTrackFunctions[n];if(o!=null){const a=o(this,r);if(typeof a.evaluate=="function"){a.director=this,a.track=r,this._customTracks.push(a);continue}}if(r.type===so.Animation){if(!r.clips||r.clips.length<=0){xf&&console.warn("Animation track has no clips",r);continue}for(let a=r.outputs.length-1;a>=0;a--){let l=r.outputs[a];if(l instanceof ye){const u=oe.getOrAddComponent(l,Er);u&&(l=u)}const c=(i=l?.gameObject)==null?void 0:i.animations;if(c){const u=new W_;u.trackOffset=r.trackOffset,u.director=this,u.track=r;for(let d=0;d<r.clips.length;d++){const p=r.clips[d],f=p.asset;if(!f){console.error(`Timeline ${this.name}: clip #${d} on track "${r.name}" has no animation data`);continue}const m=f.clip;let A=m;if((typeof A=="string"||typeof A=="number")&&(A=c.find(g=>g.name===m)),!A){console.warn("Could not find animationClip for model",p,r.name,this.name,(e=this.playableAsset)==null?void 0:e.name);continue}l instanceof Er&&l.runtimeAnimatorController&&(l.__internalDidAwakeAndStart||l.initializeRuntimeAnimatorController(),l.runtimeAnimatorController.mixer||l.runtimeAnimatorController.bind(l),u.mixer=l.runtimeAnimatorController.mixer),u.mixer||(u.mixer=new O0(l.gameObject)),u.clips.push(A),u.mixer.uncacheAction(A),u.createHooks(p.asset,A);const y=u.mixer.clipAction(A);u.actions.push(y),u.models.push(p)}this._animationTracks.push(u)}}}else if(r.type===so.Audio){if(!r.clips||r.clips.length<=0)continue;const a=new Dv;a.director=this,a.track=r,a.audioSource=r.outputs.find(l=>l instanceof vs),this._audioTracks.push(a),s||(s=(t=this.context.mainCameraComponent)==null?void 0:t.gameObject.addNewComponent(Th)),a.listener=s.listener;for(let l=0;l<r.clips.length;l++){const c=r.clips[l];a.addModel(c)}}else if(r.type===so.Marker){const a=new kv;if(a.director=this,a.track=r,r.markers)for(const l of r.markers)switch(l.type){case gI.Signal:a.models.push(l),a.didTrigger.push(!1);break}if(a!==null&&a.models.length>0){const l=oe.getComponent(this.gameObject,_f);l&&(a.receivers.push(l),this._signalTracks.push(a))}}else if(r.type===so.Signal){const a=new kv;if(a.director=this,a.track=r,r.markers)for(const l of r.markers)a.models.push(l),a.didTrigger.push(!1);for(const l of r.outputs)a.receivers.push(l);this._signalTracks.push(a)}else if(r.type===so.Control){const a=new X_;if(a.director=this,a.track=r,r.clips)for(const l of r.clips)a.models.push(l);a.resolveSourceObjects(this.context),this._controlTracks.push(a)}}}setAudioTracksAllowPlaying(i){for(const e of this._audioTracks)e.onAllowAudioChanged(i)}registerAnimationCallback(i){this.animationCallbackReceivers.push(i)}unregisterAnimationCallback(i){const e=this.animationCallbackReceivers.indexOf(i);e!==-1&&this.animationCallbackReceivers.splice(e,1)}};let nd=vI;h(nd,"createTrackFunctions",{});const q_=Symbol("objectIsAnimatedData");function Zz(i,e,t){if(!i)return;if(i[q_]===void 0){if(!t)return;i[q_]=new Set}const s=i[q_];t?s.add(e):s.has(e)&&s.delete(e)}function tre(i){if(!i)return!1;const e=i[q_];return e!==void 0&&e.size>0}Ti.registerCallback(Hs.ContextCreated,i=>{const e=i.context.domElement.getAttribute("autoplay");if(e!==void 0&&(e===""||e==="true")&&i.files)for(const t of i.files)oe.foreachComponent(t.file.scene,s=>{if(s.enabled!==!1){if(s instanceof eo&&s.playAutomatically||s instanceof Er||s instanceof nd&&s.playOnAwake===!0)return!0;if(s instanceof eo)return s.playAutomatically=!0,!0;if(s instanceof nd)return s.playOnAwake=!0,!0}},!0)!==!0&&ire(t.file)});function ire(i){if(!i||!i.animations)return;for(let t=0;t<i.animations.length;t++){const s=i.animations[t];if(!(!s.tracks||s.tracks.length<=0))for(const r in s.tracks){const n=s.tracks[r],o=n.__objectName??n.name.substring(0,n.name.indexOf("."));let a=i.scene.getObjectByName(o);if(!a&&(a=i.scene.getObjectByProperty("uuid",o),!a))continue;let l=e(a);l||(l=Ah(i.scene,new eo));const c=l.animations=l.animations||[];s.name_animator=l.name,c.indexOf(s)<0&&c.push(s)}}function e(t){var s;if(!t)return;const r=(s=t.userData)==null?void 0:s.components;if(r&&r.length>0)for(let n=0;n<r.length;n++){const o=r[n];if(o instanceof Er||o instanceof eo)return t}return e(t.parent)}}class sre{constructor(){h(this,"_context")}get context(){return this._context??kt.Current}get isStateMachineBehaviour(){return!0}}class Y_{constructor(e,t,s,r){h(this,"_name"),h(this,"_nameHash"),h(this,"_normalizedTime"),h(this,"_length"),h(this,"_speed"),this._name=e.name,this._nameHash=e.hash,this._normalizedTime=t,this._length=s,this._speed=r}get name(){return this._name}get nameHash(){return this._nameHash}get normalizedTime(){return this._normalizedTime}get length(){return this._length}get speed(){return this._speed}}function $z(i,e){return{name:"",isLooping:!1,guid:e?.generateUUID()??js.generateUUID(),index:-1,clip:new Ln(i,1,[])}}var Ih=(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))(Ih||{}),AI=(i=>(i[i.Float=1]="Float",i[i.Int=3]="Int",i[i.Bool=4]="Bool",i[i.Trigger=9]="Trigger",i))(AI||{});const yn=te("debuganimatorcontroller"),J_=te("debugrootmotion");class vo{constructor(e){h(this,"normalizedStartOffset",0),h(this,"_speed",1),h(this,"animator"),h(this,"model"),h(this,"_mixer"),h(this,"_activeState"),h(this,"_activeStates",[]),h(this,"rootMotionHandler"),this.model=e,yn&&console.log(this)}static createFromClips(e,t={looping:!1,autoTransition:!0,transitionDuration:0}){const s=[];for(let n=0;n<e.length;n++){const o=e[n],a=[];if(t.autoTransition!==!1){const c=t.transitionDuration??0,u=c/o.duration;let d=n;(t.autoTransition===void 0||t.autoTransition===!0)&&(d=(n+1)%e.length),a.push({exitTime:1-u,offset:0,duration:c,hasExitTime:!0,destinationState:d,conditions:[]})}const l={name:o.name,hash:n,motion:{name:o.name,clip:o,isLooping:t?.looping??!1},transitions:a,behaviours:[]};s.push(l)}const r={name:"AnimatorController",guid:new cr(Date.now()).generateUUID(),parameters:[],layers:[{name:"Base Layer",stateMachine:{defaultState:0,states:s}}]};return new vo(r)}play(e,t=-1,s=Number.NEGATIVE_INFINITY,r=0){if(t<0)t=0;else if(t>=this.model.layers.length){console.warn("invalid layer");return}const n=this.model.layers[t].stateMachine;for(const o of n.states)if(o.name===e||o.hash===e){yn&&console.log("transition to ",o),this.transitionTo(o,r,s);return}console.warn("Could not find "+e+" to play")}reset(){this.setStartTransition()}setBool(e,t){var s,r;const n=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[n]===e).forEach(o=>o.value=t)}getBool(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??!1}setFloat(e,t){var s,r;const n=typeof e=="string"?"name":"hash",o=(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(a=>a[n]===e);return o.forEach(a=>a.value=t),o?.length>0}getFloat(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??0}setInteger(e,t){var s,r;const n=typeof e=="string"?"name":"hash";return(r=(s=this.model)==null?void 0:s.parameters)==null?void 0:r.filter(o=>o[n]===e).forEach(o=>o.value=t)}getInteger(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??0}setTrigger(e){var t,s;yn&&console.log("SET TRIGGER",e);const r=typeof e=="string"?"name":"hash";return(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.filter(n=>n[r]===e).forEach(n=>n.value=!0)}resetTrigger(e){var t,s;const r=typeof e=="string"?"name":"hash";return(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.filter(n=>n[r]===e).forEach(n=>n.value=!1)}getTrigger(e){var t,s,r;const n=typeof e=="string"?"name":"hash";return((r=(s=(t=this.model)==null?void 0:t.parameters)==null?void 0:s.find(o=>o[n]===e))==null?void 0:r.value)??!1}isInTransition(){return this._activeStates.length>1}setSpeed(e){this._speed=e}FindState(e){return this.findState(e)}findState(e){if(!e)return null;if(Array.isArray(this.model.layers)){for(const t of this.model.layers)for(const s of t.stateMachine.states)if(s.name===e||s.hash==e)return s}return null}get context(){var e;return(e=this.animator)==null?void 0:e.context}get mixer(){return this._mixer}bind(e){e?this.animator!==e&&(this.animator=e,this._mixer=new O0(this.animator.gameObject),this.createActions(this.animator)):console.error("AnimatorController.bind: animator is null")}clone(){if(typeof this.model=="string")return console.warn("AnimatorController has not been resolved, can not create model from string",this.model),null;yn&&console.warn("AnimatorController clone()",this.model);const e=og(this.model,(t,s,r)=>r==null?!0:!(r.type==="Object3D"||r.isObject3D===!0||BN(r)||r.tracks!==void 0||r instanceof vo));return console.assert(e!==this.model),new vo(e)}update(e){var t,s;if(!this.animator)return;this.evaluateTransitions(),this.updateActiveStates(e);const r=this.animator.context.time.deltaTime;this.animator.applyRootMotion&&((t=this.rootMotionHandler)==null||t.onBeforeUpdate(e)),this._mixer.update(r),this.animator.applyRootMotion&&((s=this.rootMotionHandler)==null||s.onAfterUpdate(e))}get activeState(){return this._activeState}updateActiveStates(e){for(let t=0;t<this._activeStates.length;t++){const s=this._activeStates[t],r=s.motion;if(!r.action)this._activeStates.splice(t,1),t--;else{const n=r.action;n.weight=e,n.getEffectiveWeight()<=0&&!n.isRunning()&&(yn&&console.debug("REMOVE",s.name,n.getEffectiveWeight(),n.isRunning(),n.isScheduled()),this._activeStates.splice(t,1),t--)}}}setStartTransition(){for(const e of this.model.layers){const t=e.stateMachine;t.defaultState===void 0&&(yn&&console.warn("AnimatorController default state is undefined, will assign state 0 as default",e),t.defaultState=0);const s=t.states[t.defaultState];this.transitionTo(s,0,this.normalizedStartOffset)}}evaluateTransitions(){var e;let t=!1;if(!this._activeState){if(this.setStartTransition(),!this._activeState)return;t=!0}const s=this._activeState,r=s.motion.action;for(const o of s.transitions){if(!o.hasExitTime&&o.conditions.length<=0)continue;let a=!0;for(const l of o.conditions)if(!this.evaluateCondition(l)){a=!1;break}if(a)if(r){const l=s.motion.clip.duration,c=l<=0?1:Math.abs(r.time/l);let u=!1;if(o.hasExitTime?r.timeScale>0?u=c>=o.exitTime:r.timeScale<0&&(u=1-c>=o.exitTime):u=!0,u){for(const d of o.conditions){const p=this.model.parameters.find(f=>f.name===d.parameter);p?.type===AI.Trigger&&p.value&&(p.value=!1)}r.clampWhenFinished=!0,yn&&console.log("transition to "+o.destinationState,o,c,o.exitTime,o.hasExitTime),this.transitionTo(o.destinationState,o.duration,o.offset);return}}else{this.transitionTo(o.destinationState,o.duration,o.offset);return}}if(r){let o=s.speed??1;s.speedParameter&&(o*=this.getFloat(s.speedParameter)),o!==void 0&&(r.timeScale=o*this._speed)}let n=!1;if(s.motion.isLooping&&r&&(r.time>=r.getClip().duration?(n=!0,r.reset(),r.time=0,r.play()):r.time<=0&&r.timeScale<0&&(n=!0,r.reset(),r.time=r.getClip().duration,r.play())),!n&&s&&!t&&r&&this.animator&&s.behaviours){const o=r?.getClip().duration,a=r.time/o,l=new Y_(this._activeState,a,o,this._speed);for(const c of s.behaviours)c.instance&&((e=c.instance.onStateUpdate)==null||e.call(c.instance,this.animator,l,0))}}getState(e,t){return typeof e=="number"&&(e==-1&&(e=this.model.layers[t].stateMachine.defaultState,e===void 0&&(yn&&console.warn("AnimatorController default state is undefined: ",this.model,"Layer: "+t),e=0)),e=this.model.layers[t].stateMachine.states[e]),e}transitionTo(e,t,s){var r,n,o,a,l,c,u,d;if(!this.animator)return;const p=0;if(e=this.getState(e,p),!(e!=null&&e.motion)||!e.motion.clip||!(e.motion.clip instanceof Ln))return;const f=this._activeState===e;if(f){const g=e.motion;if(!g.action_loopback&&g.clip){const v=this.rootMotionHandler?this.animator.gameObject.matrix.clone():null;this._mixer.uncacheAction(g.clip,this.animator.gameObject),v&&v.decompose(this.animator.gameObject.position,this.animator.gameObject.quaternion,this.animator.gameObject.scale),g.action_loopback=this.createAction(g.clip)}}if((r=this._activeState)!=null&&r.behaviours&&this._activeState.motion.action){const g=(n=this._activeState)==null?void 0:n.motion.clip.duration,v=this._activeState.motion.action.time/g,b=new Y_(this._activeState,v,g,this._speed);for(const _ of this._activeState.behaviours)(a=(o=_.instance)==null?void 0:o.onStateExit)==null||a.call(_.instance,this.animator,b,p)}const m=(l=this._activeState)==null?void 0:l.motion.action;m&&m.fadeOut(t),f&&(e.motion.action=e.motion.action_loopback,e.motion.action_loopback=m);const A=this._activeState;this._activeState=e;const y=(c=e.motion)==null?void 0:c.action;if(y){if(s=Math.max(0,Math.min(1,s)),e.cycleOffsetParameter){let v=this.getFloat(e.cycleOffsetParameter);typeof v=="number"?(v<0&&(v+=1),s+=v,s%=1):yn&&console.warn("AnimatorController cycle offset parameter is not a number",e.cycleOffsetParameter)}else typeof e.cycleOffset=="number"&&(s+=e.cycleOffset,s%=1);y.isRunning()&&y.stop(),y.reset(),y.enabled=!0;const g=e.motion.clip.duration;if(y.time=f?0:s*g,y.timeScale<0&&(y.time=g-y.time),y.clampWhenFinished=!0,y.setLoop(xm,0),t>0?y.fadeIn(t):y.weight=1,y.play(),this.rootMotionHandler&&this.rootMotionHandler.onStart(y),this._activeStates.includes(e)||this._activeStates.push(e),this._activeState.behaviours){const v=new Y_(e,s,g,this._speed);for(const b of this._activeState.behaviours)(d=(u=b.instance)==null?void 0:u.onStateEnter)==null||d.call(b.instance,this.animator,v,p)}}else yn&&(e.__warned_no_motion||(e.__warned_no_motion=!0,console.warn("No action",e.motion,this)));yn&&console.log("TRANSITION FROM "+A?.name+" TO "+e.name,t,m,y,y?.getEffectiveTimeScale(),y?.getEffectiveWeight(),y?.isRunning(),y?.isScheduled(),y?.paused)}createAction(e){var t,s;if(this._mixer.existingAction(e)&&this._mixer.uncacheAction(e,(t=this.animator)==null?void 0:t.gameObject),(s=this.animator)!=null&&s.applyRootMotion){this.rootMotionHandler||(this.rootMotionHandler=new rre(this));const r=this.animator.gameObject;return this.rootMotionHandler.createClip(this._mixer,r,e)}else return this._mixer.clipAction(e)}evaluateCondition(e){const t=this.model.parameters.find(s=>s.name===e.parameter);if(!t)return!1;switch(e.mode){case Ih.If:return t.value===!0;case Ih.IfNot:return t.value===!1;case Ih.Greater:return t.value>e.threshold;case Ih.Less:return t.value<e.threshold;case Ih.Equals:return t.value===e.threshold;case Ih.NotEqual:return t.value!==e.threshold}return!1}createActions(e){var t,s,r,n;yn&&console.log("AnimatorController createActions",this.model);for(const o of this.model.layers){const a=o.stateMachine;for(let l=0;l<a.states.length;l++){const c=a.states[l];c.transitions||(c.transitions=[]);for(const u of c.transitions)u.conditions||(u.conditions=[]);if(c.motion||(c.motion=$z(c.name)),this.animator&&c.motion.clips){const u=(t=c.motion.clips)==null?void 0:t.find(d=>{var p,f;return d.node.name===((f=(p=this.animator)==null?void 0:p.gameObject)==null?void 0:f.name)});u?c.motion.clip=u.clip:(yn||wt())&&console.warn('Could not find clip for animator "'+((r=(s=this.animator)==null?void 0:s.gameObject)==null?void 0:r.name)+'"',c.motion.clips.map(d=>d.node.name))}if(!c.motion.clip){const u=new Ln(void 0,void 0,[]);c.motion.clip=u}if((n=c.motion)!=null&&n.clip){const u=c.motion.clip;if(u instanceof Ln){const d=this.createAction(u);c.motion.action=d}else(yn||wt())&&console.warn("No valid animationclip assigned",c)}if(c.behaviours&&Array.isArray(c.behaviours))for(const u of c.behaviours){if(!(u!=null&&u.typeName))continue;const d=J.get(u.typeName),p=new d;p.isStateMachineBehaviour&&(p._context=this.context??void 0,zp(p,u.properties),u.instance=p),yn&&console.log("Created animator controller behaviour",c.name,u.typeName,u.properties,p)}}}}*enumerateActions(){if(this.model.layers)for(const e of this.model.layers){const t=e.stateMachine;for(let s=0;s<t.states.length;s++){const r=t.states[s];r!=null&&r.motion&&(r.motion.action&&(yield r.motion.action),r.motion.action_loopback&&(yield r.motion.action_loopback))}}}}class ej{constructor(e,t){h(this,"track"),h(this,"createdInterpolant"),h(this,"originalEvaluate"),h(this,"customEvaluate"),this.track=e;const s=e,r=s.createInterpolant.bind(e);s.createInterpolant=()=>(s.createInterpolant=r,this.createdInterpolant=r(),this.originalEvaluate=this.createdInterpolant.evaluate.bind(this.createdInterpolant),this.customEvaluate=n=>{if(!this.originalEvaluate)return;const o=this.originalEvaluate(n);return t(n,o)},this.createdInterpolant.evaluate=this.customEvaluate,this.createdInterpolant)}dispose(){this.createdInterpolant&&this.originalEvaluate&&(this.createdInterpolant.evaluate=this.originalEvaluate),this.track=void 0,this.createdInterpolant=null,this.originalEvaluate=void 0,this.customEvaluate=void 0}}const rr=class{constructor(i,e,t,s,r){if(h(this,"_action"),h(this,"root"),h(this,"clip"),h(this,"positionWrapper",null),h(this,"rotationWrapper",null),h(this,"context"),h(this,"positionChange",new w),h(this,"rotationChange",new Ie),h(this,"_prevTime",0),this.context=i,this.root=e,this.clip=t,rr.firstKeyframeRotation[this.cacheId]||(rr.firstKeyframeRotation[this.cacheId]=new Ie),r){const n=r.values;rr.firstKeyframeRotation[this.cacheId].set(n[0],n[1],n[2],n[3])}rr.spaceRotation[this.cacheId]||(rr.spaceRotation[this.cacheId]=new Ie),rr.effectiveSpaceRotation[this.cacheId]||(rr.effectiveSpaceRotation[this.cacheId]=new Ie),rr.clipOffsetRotation[this.cacheId]=new Ie,r&&rr.clipOffsetRotation[this.cacheId].set(r.values[0],r.values[1],r.values[2],r.values[3]).invert(),this.handlePosition(t,s),this.handleRotation(t,r)}set action(i){this._action=i}get action(){return this._action}get cacheId(){return this.root.uuid}onStart(i){if(i.getClip()!==this.clip)return;rr.lastObjRotation[this.cacheId]||(rr.lastObjRotation[this.cacheId]=this.root.quaternion.clone());const e=rr.lastObjRotation[this.cacheId];if(rr.spaceRotation[this.cacheId].copy(e),J_){const t=new Ur().setFromQuaternion(e);console.log("START",this.clip.name,st.toDegrees(t.y),this.root.position.z)}}getClipRotationOffset(){return rr.clipOffsetRotation[this.cacheId]}handlePosition(i,e){if(e){const t=this.root;J_&&t.add(new wo),rr.lastObjPosition[this.cacheId]||(rr.lastObjPosition[this.cacheId]=this.root.position.clone());const s=new w,r=new w;this.positionWrapper=new ej(e,(n,o)=>{const a=this.action.getEffectiveWeight();return J_&&t.position.length()>8&&t.position.set(0,t.position.y,0),n>this._prevTime&&(s.set(o[0],o[1],o[2]),s.sub(r),s.multiplyScalar(a),s.applyQuaternion(this.getClipRotationOffset()),s.applyQuaternion(t.quaternion),this.positionChange.copy(s)),r.fromArray(o),this._prevTime=n,o[0]=0,o[1]=0,o[2]=0,o})}}handleRotation(i,e){if(e){if(J_){const n=e.values,o=new Ur().setFromQuaternion(new Ie(n[0],n[1],n[2],n[3]));console.log(i.name,e.name,"FIRST ROTATION IN TRACK",st.toDegrees(o.y));const a=e.values.length-4,l=new Ie().set(n[a],n[a+1],n[a+2],n[a+3]),c=new Ur().setFromQuaternion(l);console.log(i.name,e.name,"LAST ROTATION IN TRACK",st.toDegrees(c.y))}let t=0;const s=new Ie,r=new Ie;this.rotationWrapper=new ej(e,(n,o)=>(n>t&&(r.set(o[0],o[1],o[2],o[3]),s.invert(),r.multiply(s),this.rotationChange.copy(r)),s.fromArray(o),t=n,o[0]=0,o[1]=0,o[2]=0,o[3]=1,o))}}onBeforeUpdate(i){this.positionChange.set(0,0,0),this.rotationChange.set(0,0,0,1)}onAfterUpdate(i){return!this.action||(i*=this.action.getEffectiveWeight(),i<=0)?!1:(this.positionChange.multiplyScalar(i),this.rotationChange.slerp(rr.identityQuaternion,1-i),!0)}};let Rh=rr;h(Rh,"lastObjPosition",{}),h(Rh,"lastObjRotation",{}),h(Rh,"firstKeyframeRotation",{}),h(Rh,"spaceRotation",{}),h(Rh,"effectiveSpaceRotation",{}),h(Rh,"clipOffsetRotation",{}),h(Rh,"identityQuaternion",new Ie);class rre{constructor(e){h(this,"controller"),h(this,"handler",[]),h(this,"root"),h(this,"basePosition",new w),h(this,"baseQuaternion",new Ie),h(this,"baseRotation",new Ur),h(this,"summedPosition",new w),h(this,"summedRotation",new Ie),this.controller=e}createClip(e,t,s){this.root=t,t&&"name"in t&&t.name;const r=this.findRootTrack(s,".position"),n=this.findRootTrack(s,".quaternion"),o=new Rh(this.controller.context,t,s,r,n);this.handler.push(o);const a=e.clipAction(s);return o.action=a,a}onStart(e){for(const t of this.handler)t.onStart(e)}onBeforeUpdate(e){this.basePosition.copy(this.root.position),this.baseQuaternion.copy(this.root.quaternion);for(const t of this.handler)t.onBeforeUpdate(e)}onAfterUpdate(e){if(!(e<=0)){this.root.position.copy(this.basePosition),this.root.quaternion.copy(this.baseQuaternion),this.summedPosition.set(0,0,0),this.summedRotation.set(0,0,0,1);for(const t of this.handler)t.onAfterUpdate(e)&&(this.summedPosition.add(t.positionChange),this.summedRotation.multiply(t.rotationChange));this.root.position.add(this.summedPosition),this.root.quaternion.multiply(this.summedRotation)}}findRootTrack(e,t){const s=e.tracks;if(!s)return null;for(const r of s)if(r.name.endsWith(t))return r;return null}}class nre extends Kl{onSerialize(e,t){}onDeserialize(e,t){if(t.type===vo&&e?.__type==="AnimatorController")return new vo(e)}}new nre(vo);var ore=Object.defineProperty,are=Object.getOwnPropertyDescriptor,K_=(i,e,t,s)=>{for(var r=s>1?void 0:s?are(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&ore(e,t,r),r};const Go=te("debuganimator");class Er extends Pe{constructor(){super(...arguments),h(this,"applyRootMotion",!1),h(this,"hasRootMotion",!1),h(this,"keepAnimatorControllerStateOnDisable",!1),h(this,"_parametersAreDirty",!1),h(this,"_isDirty",!1),h(this,"speed",1),h(this,"normalizedStartOffset",0),h(this,"_animatorController",null),h(this,"_initializeWithRuntimeAnimatorController")}set runtimeAnimatorController(e){var t;this._animatorController&&this._animatorController.model===e||(e?e instanceof vo?(e.animator&&e.animator!==this&&(console.warn("AnimatorController can not be bound to multiple animators",(t=e.model)==null?void 0:t.name),e.model||console.error("AnimatorController has no model"),e=new vo(e.model)),this._animatorController=e,this._animatorController.bind(this)):(Go&&console.log("Assign animator controller",e,this),this._animatorController=new vo(e),this.__didAwake&&this._animatorController.bind(this)):this._animatorController=null)}get runtimeAnimatorController(){return this._animatorController}get parametersAreDirty(){return this._parametersAreDirty}get isDirty(){return this._isDirty}Play(e,t=-1,s=Number.NEGATIVE_INFINITY,r=0){this.play(e,t,s,r)}play(e,t=-1,s=Number.NEGATIVE_INFINITY,r=0){var n;(n=this.runtimeAnimatorController)==null||n.play(e,t,s,r),this._isDirty=!0}Reset(){this.reset()}reset(){var e;(e=this._animatorController)==null||e.reset(),this._isDirty=!0}SetBool(e,t){this.setBool(e,t)}setBool(e,t){var s,r;Go&&console.log("setBool",e,t),((s=this.runtimeAnimatorController)==null?void 0:s.getBool(e))!==t&&(this._parametersAreDirty=!0),(r=this.runtimeAnimatorController)==null||r.setBool(e,t)}GetBool(e){return this.getBool(e)}getBool(e){var t;const s=((t=this.runtimeAnimatorController)==null?void 0:t.getBool(e))??!1;return Go&&console.log("getBool",e,s),s}toggleBool(e){this.setBool(e,!this.getBool(e))}SetFloat(e,t){this.setFloat(e,t)}setFloat(e,t){var s,r;((s=this.runtimeAnimatorController)==null?void 0:s.getFloat(e))!==t&&(this._parametersAreDirty=!0),Go&&console.log("setFloat",e,t),(r=this.runtimeAnimatorController)==null||r.setFloat(e,t)}GetFloat(e){return this.getFloat(e)}getFloat(e){var t;const s=((t=this.runtimeAnimatorController)==null?void 0:t.getFloat(e))??-1;return Go&&console.log("getFloat",e,s),s}SetInteger(e,t){this.setInteger(e,t)}setInteger(e,t){var s,r;((s=this.runtimeAnimatorController)==null?void 0:s.getInteger(e))!==t&&(this._parametersAreDirty=!0),Go&&console.log("setInteger",e,t),(r=this.runtimeAnimatorController)==null||r.setInteger(e,t)}GetInteger(e){return this.getInteger(e)}getInteger(e){var t;const s=((t=this.runtimeAnimatorController)==null?void 0:t.getInteger(e))??-1;return Go&&console.log("getInteger",e,s),s}SetTrigger(e){this.setTrigger(e)}setTrigger(e){var t;this._parametersAreDirty=!0,Go&&console.log("setTrigger",e),(t=this.runtimeAnimatorController)==null||t.setTrigger(e)}ResetTrigger(e){this.resetTrigger(e)}resetTrigger(e){var t;this._parametersAreDirty=!0,Go&&console.log("resetTrigger",e),(t=this.runtimeAnimatorController)==null||t.resetTrigger(e)}GetTrigger(e){this.getTrigger(e)}getTrigger(e){var t;const s=(t=this.runtimeAnimatorController)==null?void 0:t.getTrigger(e);return Go&&console.log("getTrigger",e,s),s}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&&(Go&&console.log("setSpeed",e),this.speed=e,(t=this._animatorController)==null||t.setSpeed(e))}set minMaxSpeed(e){this.speed=st.lerp(e.x,e.y,Math.random())}set minMaxOffsetNormalized(e){this.normalizedStartOffset=st.lerp(e.x,e.y,Math.random()),this.runtimeAnimatorController&&(this.runtimeAnimatorController.normalizedStartOffset=this.normalizedStartOffset)}awake(){Go&&console.log("ANIMATOR",this.name,this),this.gameObject&&this.initializeRuntimeAnimatorController()}initializeRuntimeAnimatorController(e=!1){const t=e||this.runtimeAnimatorController!==this._initializeWithRuntimeAnimatorController;if(this.runtimeAnimatorController&&t){const s=this.runtimeAnimatorController.clone();this._initializeWithRuntimeAnimatorController=s,s?(console.assert(this.runtimeAnimatorController!==s),this.runtimeAnimatorController=s,console.assert(this.runtimeAnimatorController===s),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._isDirty=!1,this._parametersAreDirty=!1,!tre(this.gameObject)&&this._animatorController&&this._animatorController.update(1)}}K_([x()],Er.prototype,"applyRootMotion",2),K_([x()],Er.prototype,"hasRootMotion",2),K_([x()],Er.prototype,"keepAnimatorControllerStateOnDisable",2),K_([x()],Er.prototype,"runtimeAnimatorController",1);const wf=te("debugusdzanimation"),yI=te("debugusdzanimationserialization");class Z_{constructor(e,t,s){h(this,"_start"),h(this,"ext"),h(this,"root"),h(this,"clip"),this.ext=e,this.root=t,this.clip=s}get start(){return this._start===void 0&&(this._start=this.ext.getStartTime01(this.root,this.clip)),this._start}get duration(){return this.clip.duration}}class Qo{constructor(e,t,s){h(this,"clip"),h(this,"pos"),h(this,"rot"),h(this,"scale"),h(this,"root"),h(this,"target"),h(this,"duration",0),h(this,"useRootMotion",!1),this.root=e,this.target=t,this.clip=s,s?this.duration=s.duration:this.duration=1/this.frameRate;const r=oe.getComponent(e,Er);r&&(this.useRootMotion=r.applyRootMotion)}get frameRate(){return 60}addTrack(e){if(!this.clip){console.error("This is a rest clip but you're trying to add tracks to it \u2013 this is likely a bug");return}e.name.endsWith("position")&&(this.pos=e),e.name.endsWith("quaternion")&&(this.rot=e),e.name.endsWith("scale")&&(this.scale=e)}getFrames(){var e,t,s,r,n,o;return this.clip?Math.max(((t=(e=this.pos)==null?void 0:e.times)==null?void 0:t.length)??0,((r=(s=this.rot)==null?void 0:s.times)==null?void 0:r.length)??0,((o=(n=this.scale)==null?void 0:n.times)==null?void 0:o.length)??0):2}getDuration(){return this.duration}getSortedTimesArray(e=!0,t=!0,s=!0){var r,n,o;if(!this.clip)return[0,this.duration];const a=(r=this.pos)==null?void 0:r.times,l=(n=this.rot)==null?void 0:n.times,c=(o=this.scale)==null?void 0:o.times,u=[];if(e&&a)for(const d of a)u.push(d);if(t&&l)for(const d of l)u.push(d);if(s&&c)for(const d of c)u.push(d);return u.includes(0)||u.push(0),u.sort((d,p)=>d-p),[...new Set(u)]}*getValues(e,t=!0,s=!0,r=!0){var n,o,a;const l=new w,c=new Ie,u=new w(1,1,1),d=this.target,p=t?(n=this.pos)==null?void 0:n.createInterpolant():void 0,f=s?(o=this.rot)==null?void 0:o.createInterpolant():void 0,m=r?(a=this.scale)==null?void 0:a.createInterpolant():void 0;p||l.set(d.position.x,d.position.y,d.position.z),f||c.set(d.quaternion.x,d.quaternion.y,d.quaternion.z,d.quaternion.w),m||u.set(d.scale.x,d.scale.y,d.scale.z);for(let A=0;A<e.length;A++){const y=e[A];if(p){const g=p.evaluate(y);l.set(g[0],g[1],g[2])}if(f){const g=f.evaluate(y);c.set(g[0],g[1],g[2],g[3])}if(m){const g=m.evaluate(y);u.set(g[0],g[1],g[2])}if(this.useRootMotion&&d===this.root){const g=new Te;g.compose(l,c,u),g.multiply(d.matrix),g.decompose(l,c,u)}yield{time:y,translation:l,rotation:c,scale:u,index:A}}}}h(Qo,"animationDurationPadding",1);class Ov{constructor(e){h(this,"dict",new Map),h(this,"rootTargetMap",new Map),h(this,"rootAndClipToRegisteredAnimationMap",new Map),h(this,"rootToRegisteredClipCount",new Map),h(this,"serializers",[]),h(this,"injectRestPoses",!1),h(this,"injectImplicitBehaviours",!1),this.injectRestPoses=e,this.injectImplicitBehaviours=e}get extensionName(){return"animation"}getClipCount(e){let t=this.rootToRegisteredClipCount.get(e);return this.injectRestPoses&&(t=t?t-1:0),t??0}getStartTime01(e,t){const s=this.rootTargetMap.get(e);if(!s)return 0;const r=this.dict.get(s[0]);if(!r)return console.error("Trying to get start time for root that has no animation data",e,t,...this.dict),0;let n=0;for(let o=0;o<r.length&&r[o].clip!==t;o++)n+=r[o].getDuration()+Qo.animationDurationPadding;return n}registerAnimation(e,t){if(!t||!e)return null;this.rootTargetMap.has(e)||this.rootTargetMap.set(e,[]);const s=e.uuid+t.uuid;if(this.rootAndClipToRegisteredAnimationMap.has(s))return this.rootAndClipToRegisteredAnimationMap.get(s);wf&&console.log("registerAnimation",e,t);const r=this.injectRestPoses?1:0,n=this.rootToRegisteredClipCount.get(e)??r,o=this.rootTargetMap.get(e),a=new Set(o);if(t.tracks)for(const c of t.tracks){const u=Xt.parseTrackName(c.name),d=Xt.findNode(e,u.nodeName);if(!d){console.warn("no object found for track",c.name,"using "+e.name+" instead");continue}this.dict.has(d)||this.dict.set(d,[]);const p=this.dict.get(d);if(!p)continue;if(a.delete(d),this.injectRestPoses&&!p[0]){const m=new Qo(null,d,void 0);p[0]=m}let f=p[n];f||(f=new Qo(e,d,t),p[n]=f),f.addTrack(c),o!=null&&o.includes(d)||o==null||o.push(d)}for(const c of a){const u=this.dict.get(c);if(!u)continue;if(this.injectRestPoses&&!u[0]){const p=new Qo(null,c,void 0);u[0]=p}let d=u[n];d||(wf&&console.log("Adding padding clip for ",c,t),d=new Qo(e,c,t),u[n]=d)}const l=new Z_(this,e,t);return this.rootAndClipToRegisteredAnimationMap.set(s,l),this.rootToRegisteredClipCount.set(e,n+1),l}onAfterHierarchy(e){wf&&console.log("Animation clips per animation target node",this.dict)}onAfterBuildDocument(e){var t,s;for(const r of this.serializers){const n=(t=r.model)==null?void 0:t.parent,o=n?.isDynamic===!0;yI&&console.log(o,(s=r.model)==null?void 0:s.parent),o&&r.registerCallback(n)}}onExportObject(e,t,s){oe.foreachComponent(e,n=>{const o=n;typeof o.createAnimation=="function"&&o.createAnimation(this,t,s)},!1);const r=new lre(e,this.dict);this.serializers.push(r),r.registerCallback(t)}}class lre{constructor(e,t){h(this,"object"),h(this,"dict"),h(this,"model"),h(this,"callback"),this.object=e,this.dict=t}registerCallback(e){this.model&&this.callback&&this.model.removeEventListener("serialize",this.callback),this.callback||(this.callback=this.onSerialize.bind(this)),yI&&console.log("REPARENT",e),this.model=e,this.model.addEventListener("serialize",this.callback)}skinnedMeshExport(e,t){const s=this.model,r=this.dict;if(s&&s.skinnedMesh){let n=function(C){const R=[];for(const[I,E]of C){let z=`${I} : [`;const F=[];for(const q of E)F.push(`(${ir(q.x)}, ${ir(q.y)}, ${ir(q.z)})`);z=z.concat(F.join(", ")),z=z.concat("],"),R.push(z)}return R},o=function(C){const R=[];for(const[I,E]of C){let z=`${I} : [`;const F=[];for(const q of E)F.push(`(${ir(q.w)}, ${ir(q.x)}, ${ir(q.y)}, ${ir(q.z)})`);z=z.concat(F.join(", ")),z=z.concat("],"),R.push(z)}return R},a=function(C){let R=!0,I;for(const[z,F]of C)if(I===void 0&&(I=F.length),I!==F.length){R=!1;break}wf&&console.log("Bone count: ",C.size,"TransformData entries per bone: ",I),console.assert(R,"All bones should have the same number of TransformData entries",C);const E=[];for(const[z,F]of C){const q=new Array;let N=0;for(let H=0;H<F.length;H++)q.push(N),N+=F[H].getDuration()+Qo.animationDurationPadding;for(let H=0;H<F.length;H++){const L=F[H],j=q[H];E.length<=H&&E.push({pos:[],rot:[],scale:[],timeOffset:j});const Q=E[H];Q.pos.push(...L.getSortedTimesArray(!0,!1,!1)),Q.rot.push(...L.getSortedTimesArray(!1,!0,!1)),Q.scale.push(...L.getSortedTimesArray(!1,!1,!0))}}for(const z of E)z.pos.sort((F,q)=>F-q),z.rot.sort((F,q)=>F-q),z.scale.sort((F,q)=>F-q),z.pos=[...new Set(z.pos)],z.rot=[...new Set(z.rot)],z.scale=[...new Set(z.scale)];return E},l=function(C,R,I){const E=new Map,z=new Map,F=new Map,q=R.length;for(const N of I){const H=C.get(N);let L;H?console.assert(H.length===q,"We should have the same number of TransformData entries for each bone",H,R):L=new Qo(null,N,void 0);for(let j=0;j<q;j++){const Q=H?H[j]:L,$=R[j];for(const{time:Z,translation:se}of Q.getValues($.pos,!0,!1,!1)){const Ae=(Z+$.timeOffset)*60;E.has(Ae)||E.set(Ae,new Array),E.get(Ae).push(se.clone())}for(const{time:Z,rotation:se}of Q.getValues($.rot,!1,!0,!1)){const Ae=(Z+$.timeOffset)*60;z.has(Ae)||z.set(Ae,new Array),z.get(Ae).push(se.clone())}for(const{time:Z,scale:se}of Q.getValues($.scale,!1,!1,!0)){const Ae=(Z+$.timeOffset)*60;F.has(Ae)||F.set(Ae,new Array),F.get(Ae).push(se.clone())}}}return{position:E.size==0?void 0:E,quaternion:z.size==0?void 0:z,scale:F.size==0?void 0:F}},c=function(C){const R=[];for(const I of C)R.push(`(${ir(I.x)}, ${ir(I.y)}, ${ir(I.z)})`);return R.join(", ")},u=function(C){const R=[];for(const I of C)R.push(`(${ir(I.w)}, ${ir(I.x)}, ${ir(I.y)}, ${ir(I.z)})`);return R.join(", ")},d=function(C){const R=new Map;if(wf){const I=new Array;for(const[E,z]of r)I.push(E.uuid+": "+z.length+" "+z.map(F=>{var q;return(q=F.clip)==null?void 0:q.uuid.substring(0,6)}).join(" "));console.log(`getPerBoneTransformData
|
|
5409
5411
|
`+I.join(`
|
|
5410
|
-
`))}for(const I of C){const E=r.get(I);E&&R.set(I,E)}return R},p=function(C){const R=d(C),I=a(R);return l(R,I,C)};const f=s.skinnedMesh.skeleton,m=new Array;for(const C in f.bones){const R=f.bones[C],I=f.boneInverses[C];m.push({bone:R,inverse:I})}for(const C of Sz(f.bones))m.push({bone:C,inverse:C.matrixWorld.clone().invert()});const A=m[0].bone.parent;A||console.error("No bone parent found for skinned mesh during USDZ export",s.skinnedMesh),m.sort((C,R)=>ff(C.bone,A)>ff(R.bone,A)?1:-1);const y=[],g=[],v=[],b=[];for(const{bone:C}of m)y.push(C.matrix.clone()),g.push(C.position),v.push(C.quaternion),b.push(C.scale);const _=m.map(C=>'"'+ff(C.bone,A)+'"').join(", "),S=m.map(C=>mf(C.inverse.clone().invert())).join(", ");e.beginBlock('def Skeleton "Rig"'),e.appendLine(`uniform matrix4d[] bindTransforms = [${S}]`),e.appendLine(`uniform token[] joints = [${_}]`),e.appendLine('uniform token purpose = "guide"'),e.appendLine(`uniform matrix4d[] restTransforms = [${y.map(C=>mf(C)).join(", ")}]`),e.appendLine(`matrix4d xformOp:transform = ${mf(new Te)}`),e.appendLine('uniform token[] xformOpOrder = ["xformOp:transform"]');const M=p(m.map(C=>C.bone));if(e.beginBlock('def SkelAnimation "_anim"'),e.appendLine(`uniform token[] joints = [${_}]`),e.appendLine(`quatf[] rotations = [${u(v)}]`),M&&M.quaternion){e.beginBlock("quatf[] rotations.timeSamples = {","");const C=o(M.quaternion);for(const R of C)e.appendLine(R);e.closeBlock()}if(e.appendLine(`half3[] scales = [${c(b)}]`),M&&M.scale){e.beginBlock("half3[] scales.timeSamples = {","");const C=n(M.scale);for(const R of C)e.appendLine(R);e.closeBlock()}if(e.appendLine(`float3[] translations = [${c(g)}]`),M&&M.position){e.beginBlock("float3[] translations.timeSamples = {","");const C=n(M.position);for(const R of C)e.appendLine(R);e.closeBlock()}e.closeBlock(),e.closeBlock()}}onSerialize(e,t){var s;if(!this.model)return;this.skinnedMeshExport(e,t);const r=this.object,n=this.dict.get(r);if(!n||r.isSkinnedMesh)return;yI&&console.log("SERIALIZE",this.model.name,this.object.type,n);const o=new Te;e.appendLine("matrix4d xformOp:transform.timeSamples = {"),e.indent++;const a=new Array;let l=0;for(let c=0;c<n.length;c++)a.push(l),l+=n[c].getDuration()+Qo.animationDurationPadding;for(let c=0;c<n.length;c++){const u=n[c];if(!u)continue;const d=a[c];{const p=u.getSortedTimesArray();if(!p||p.length===0){console.error("got an animated object but no time values?",r,u);continue}if(wf){const f=((s=u.clip)==null?void 0:s.name)??"rest",m=u.getDuration();console.log("Write .timeSamples:",f,d,m,n),e.appendLine("# "+f+": start="+(d*u.frameRate).toFixed(3)+", length="+(m*u.frameRate).toFixed(3)+", frames="+u.getFrames())}for(const{time:f,translation:m,rotation:A,scale:y}of u.getValues(p)){o.compose(m,A,y);const g=`${(d+f)*u.frameRate}: ${mf(o)},`;e.appendLine(g)}}}e.indent--,e.appendLine("}")}}var cre=Object.defineProperty,hre=Object.getOwnPropertyDescriptor,tj=(i,e,t,s)=>{for(var r=s>1?void 0:s?hre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&cre(e,t,r),r};const ij=te("debugpost");class Bt{constructor(e){h(this,"_active",!0),h(this,"_value"),h(this,"_valueRaw"),h(this,"_defaultValue"),h(this,"valueProcessor"),h(this,"onValueChanged"),this._value=e,this._defaultValue=e,this._valueRaw=e}get overrideState(){return this._active}set overrideState(e){if(this._active===e)return;this._active=e;const t=e?this._valueRaw:this._defaultValue;this.processValue(t,!0)}get value(){return this._valueRaw}set value(e){this.processValue(e,!1)}set defaultValue(e){this._defaultValue=e}__init(){this.processValue(this._valueRaw,!0)}processValue(e,t){if(e==null||!t&&this.testIfValueChanged(e)===!1)return;const s=this._value;ij&&console.log("VolumeParameter: value changed from",s,"to",e),!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,e=this._defaultValue,this._valueRaw=e):(this._valueRaw=e,this._active&&this.valueProcessor&&(e=this.valueProcessor(e)),this._value=e),this.onValueChanged?this.onValueChanged(e,s,this):ij&&console.log("VolumeParameter: onValueChanged not set")}testIfValueChanged(e){return this._valueRaw!==e}}tj([x()],Bt.prototype,"overrideState",1),tj([x()],Bt.prototype,"value",1);var ure=Object.defineProperty,dre=Object.getOwnPropertyDescriptor,pre=(i,e,t,s)=>{for(var r=s>1?void 0:s?dre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&ure(e,t,r),r};const fre=te("debugpost");class en extends Pe{constructor(e=void 0){if(super(),h(this,"active",!0),h(this,"_result"),h(this,"_didCreateVolumeParameters",!1),e){this.ensureVolumeParameters();for(const t of Object.keys(e)){const s=e[t],r=this[t];r instanceof Bt&&(r.value=s)}}}onEnable(){this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){this.active=!1}init(){}apply(){var e;return this.ensureVolumeParameters(),this._result||(this._result=(e=this.onCreateEffect)==null?void 0:e.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){fre&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(e=>e.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const e=Object.keys(this);for(const t of e){const s=this[t];s instanceof Bt&&s.__init()}}onAfterDeserialize(e,t){if(typeof e=="object"){const s=this.$serializedTypes;if(s){for(const r of Object.keys(s))if(s[r]===Bt){const n=e[r];if(n!==void 0){const o=this[r];o.value=n}}}}}onEditorModification(e){const t=e.propertyName;if(this[t]instanceof Bt){const s=e.value;return this[t].value=s,!0}}ensureVolumeParameters(){if(this._didCreateVolumeParameters)return;this._didCreateVolumeParameters=!0;const e=this.$serializedTypes;if(e)for(const t of Object.keys(e))e[t]===Bt&&(this[t]||(this[t]=new Bt))}}pre([x()],en.prototype,"active",2);var mre=Object.defineProperty,gre=Object.getOwnPropertyDescriptor,vre=(i,e,t,s)=>{for(var r=s>1?void 0:s?gre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&mre(e,t,r),r};const Are=te("debugpost"),bI={};function Vo(i,e){bI[i]=e}function yre(i){return i.__type in bI?bI[i.__type]:(Are&&i.__type&&console.warn("Unknown postprocessing type",i.__type,i),en)}class Lv{constructor(){h(this,"components",[])}init(){var e;(e=this.components)==null||e.forEach(t=>t.init())}}vre([nf([i=>yre(i),en])],Lv.prototype,"components",2);var bre=Object.defineProperty,_re=Object.getOwnPropertyDescriptor,xre=(i,e,t,s)=>{for(var r=s>1?void 0:s?_re(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&bre(e,t,r),r};class Uv extends en{constructor(){super(...arguments),h(this,"preset")}get typeName(){return"Antialiasing"}onCreateEffect(){const e=new y7({preset:Up.HIGH,edgeDetectionMode:ZC.DEPTH});return this.preset.onValueChanged=t=>{e.applyPreset(t)},e}}xre([x(Bt)],Uv.prototype,"preset",2),Vo("Antialiasing",Uv);class $_{constructor(){h(this,"files",[])}get extensionName(){return"Audio"}onExportObject(e,t,s){const r=oe.getComponents(e,vs);if(r.length)for(const n of r){if(!n.clip||typeof n.clip!="string"||!n.playOnAwake)continue;const o=n.clip.split("/").pop();this.files.includes(n.clip)||this.files.push(n.clip),t.addEventListener("serialize",(a,l)=>{a.appendLine(),a.beginBlock(`def SpatialAudio "${t.name}"`),a.appendLine(`uniform asset filePath = @audio/${o}@`),a.appendLine(`uniform token auralMode = "${n.spatialBlend>0?"spatial":"nonSpatial"}"`),a.appendLine(`uniform token playbackMode = "${n.loop?"loopFromStage":"onceFromStart"}"`),a.appendLine(`uniform float gain = ${n.volume}`),a.closeBlock()})}}async onAfterSerialize(e){for(const t of this.files){const s=t.split("/").pop(),r=await(await(await fetch(t)).blob()).arrayBuffer(),n=new Uint8Array(r);e.files["audio/"+s]=n}}}const od=te("debugautosync"),_I=Symbol("syncerId");class wre{constructor(){h(this,"_syncers",{})}getOrCreateSyncer(e){if(!e.guid)return null;if(this._syncers[e.guid])return this._syncers[e.guid];const t=new Sre(e);return t[_I]=e.guid,this._syncers[t[_I]]=t,t}removeSyncer(e){delete this._syncers[e[_I]]}}const xI=new wre;class Sre{constructor(e){h(this,"comp"),h(this,"hasChanges",!1),h(this,"changedProperties",{}),h(this,"data",{}),h(this,"_boundEvent"),h(this,"_handleReceivingMethod"),h(this,"_isReceiving",!1),h(this,"_isInit",!1),this.comp=e}get networkingKey(){return this.comp.guid}init(e){if(this._isInit)return;this._isInit=!0,this.comp=e,this._boundEvent=this.onHandleSending.bind(this),this.comp.context.post_render_callbacks.push(this._boundEvent),this._handleReceivingMethod=this.onHandleReceiving.bind(this),this.comp.context.connection.beginListen(this.networkingKey,this._handleReceivingMethod);const t=this.comp.context.connection.tryGetState(this.comp.guid);t&&this.onHandleReceiving(t)}destroy(){this._isInit&&(this._boundEvent&&this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this._boundEvent),1),this._handleReceivingMethod&&this.comp.context.connection.stopListen(this.networkingKey,this._handleReceivingMethod),this.comp=null,this._isInit=!1)}notifyChanged(e,t){this._isReceiving||(od&&console.log("Property changed: "+e,t),this.hasChanges=!0,this.changedProperties[e]=t)}onHandleSending(){if(!this.hasChanges)return;this.hasChanges=!1;const e=this.comp.context.connection;if(!e||!e.isConnected){for(const t in this.changedProperties)delete this.changedProperties[t];return}for(const t in this.data)delete this.data[t];this.data.guid=this.comp.guid;for(const t in this.changedProperties){const s=this.changedProperties[t];delete this.changedProperties[t],this.data[t]=s}e.send(this.networkingKey,this.data)}onHandleReceiving(e){if(od&&console.log("RECEIVE",this.comp.name,this.comp.guid,e),!this._isInit||!this.comp)return;const t=e.guid;if(!(t&&t!==this.comp.guid)){od&&console.log("RECEIVED",this.comp.name,this.comp.guid,e);try{this._isReceiving=!0;for(const s in e){if(s==="guid")continue;const r=e[s];this.comp[s]=r,od&&console.log("SET",s,r)}}catch(s){console.error(s)}finally{this._isReceiving=!1}}}}function Cre(i,e){let t=e!==i;return!t&&i&&e&&(Array.isArray(i)&&Array.isArray(e)||typeof i=="object"&&typeof e=="object")&&(t=!0),t}const Fv=Symbol("AutoSyncHandler");function Ere(i){if(i[Fv])return i[Fv];const e=xI.getOrCreateSyncer(i);return e?.init(i),i[Fv]=e,e}function Mre(i){const e=i[Fv];e&&(xI.removeSyncer(e),e.destroy(),delete i[Fv])}const wI=function(i){return function(e,t){var s;let r="";typeof t=="string"?r=t:r=t.name;let n=null,o;typeof i=="string"?o=e[i]:typeof i=="function"&&(o=i);const a=e,l=a.__internalAwake;if(typeof l!="function"){(od||wt())&&console.error('@syncField can currently only used on Needle Engine Components, custom object of type "'+((s=e?.constructor)==null?void 0:s.name)+'" is not supported',e);return}od&&console.log(r);const c=Symbol(r);a.__internalAwake=function(){if(this[c]!==void 0)return;this[c]=this[r],n=xI.getOrCreateSyncer(this);const d=Object.getOwnPropertyDescriptor(this,r);if(d?.set===void 0){let p=!1;Object.defineProperty(this,r,{set:function(f){var m;const A=this[c];if(this[c]=f,p){wt()&&console.warn("Recursive call detected",r);return}p=!0;try{const y=Cre(f,A);od&&console.log("SyncField assignment",r,"changed?",y,f),y&&o?.call(this,f,A)!==!1&&((m=Ere(this))==null||m.notifyChanged(r,f))}finally{p=!1}},get:function(){return this[c]},configurable:!0,enumerable:!0})}n?.init(this),l.call(this)};const u=a.__internalDestroy;a.__internalDestroy=function(){Mre(this),u.call(this)}}};var Tre=Object.defineProperty,Ire=Object.getOwnPropertyDescriptor,ex=(i,e,t,s)=>{for(var r=s>1?void 0:s?Ire(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Tre(e,t,r),r};const Ho=te("debugplayersync");class Sf extends Pe{constructor(){super(...arguments),h(this,"autoSync",!0),h(this,"asset"),h(this,"onPlayerSpawned"),h(this,"_localInstance"),h(this,"onJoinedRoom",()=>{Ho&&console.log("PlayerSync.joinedRoom. autoSync is set to "+this.autoSync),this.autoSync&&this.getInstance()})}awake(){this.watchTabVisible(),this.onPlayerSpawned||(this.onPlayerSpawned=new tr)}onEnable(){this.context.connection.beginListen(di.RoomStateSent,this.onJoinedRoom),this.context.connection.beginListen(di.JoinedRoom,this.onJoinedRoom),this.context.connection.isInRoom&&this.onJoinedRoom()}onDisable(){this.context.connection.stopListen(di.RoomStateSent,this.onJoinedRoom),this.context.connection.stopListen(di.JoinedRoom,this.onJoinedRoom)}async getInstance(){var e,t,s,r,n,o;if(this._localInstance)return this._localInstance;if(Ho&&console.log("PlayerSync.createInstance",(e=this.asset)==null?void 0:e.uri),!((t=this.asset)!=null&&t.asset)&&!((s=this.asset)!=null&&s.uri))return console.error('PlayerSync: can not create an instance because "asset" is not set!'),null;this._localInstance=(r=this.asset)==null?void 0:r.instantiateSynced({parent:this.gameObject},!0);const a=await this._localInstance;if(a){const l=oe.getComponent(a,Wo);l?(l.owner=this.context.connection.connectionId,(n=this.onPlayerSpawned)==null||n.invoke(a)):(this._localInstance=void 0,console.error("<strong>Failed finding PlayerState on "+((o=this.asset)==null?void 0:o.uri)+"</strong>: please make sure the asset has a PlayerState component!"),oe.destroySynced(a))}else this._localInstance=void 0,console.warn("PlayerSync: failed instantiating asset!");return this._localInstance}destroyInstance(){var e;(e=this._localInstance)==null||e.then(t=>(Ho&&console.log("PlayerSync.destroyInstance",t),oe.destroySynced(t))),this._localInstance=void 0}watchTabVisible(){window.addEventListener("visibilitychange",e=>{if(document.visibilityState==="visible")for(let t=Wo.all.length-1;t>=0;t--){const s=Wo.all[t];(!s.owner||!this.context.connection.userIsInRoom(s.owner))&&s.doDestroy()}})}}ex([x()],Sf.prototype,"autoSync",2),ex([x(ni)],Sf.prototype,"asset",2),ex([x(tr)],Sf.prototype,"onPlayerSpawned",2);var sj=(i=>(i.OwnerChanged="ownerChanged",i))(sj||{}),Nv;const Mr=(Nv=class extends Pe{constructor(){super(...arguments),h(this,"onOwnerChangeEvent",new tr),h(this,"onFirstOwnerChangeEvent",new tr),h(this,"hasOwner",!1),h(this,"owner"),h(this,"dontDestroy",!1),h(this,"onUserLeftRoom",i=>{if(i.userId===this.owner){Ho&&console.log("PLAYERSYNC LEFT",this.owner),this.doDestroy();return}})}static get all(){return Mr._all}static get local(){return Mr._local}static getFor(i){if(i instanceof ye)return oe.getComponentInParent(i,Mr);if(i instanceof Pe)return oe.getComponentInParent(i.gameObject,Mr)}static isLocalPlayer(i){const e=Mr.getFor(i);return e?.isLocalPlayer??!1}static addEventListener(i,e){return this._callbacks[i]||(this._callbacks[i]=[]),this._callbacks[i].push(e),e}static removeEventListener(i,e){if(!this._callbacks[i])return;const t=this._callbacks[i].indexOf(e);t>=0&&this._callbacks[i].splice(t,1)}static dispatchEvent(i,e){if(this._callbacks[i])for(const t of this._callbacks[i])t(e)}get isLocalPlayer(){return this.owner===this.context.connection.connectionId}onOwnerChange(i,e){var t,s;Ho&&console.log("PlayerSync.onOwnerChange",this,"newOwner",i,"oldOwner",e);const r=Mr._local.indexOf(this);r>=0&&Mr._local.splice(r,1);const n={playerState:this,oldValue:e,newValue:i};if(this.hasOwner||(this.hasOwner=!0,(t=this.onFirstOwnerChangeEvent)==null||t.invoke(n)),(s=this.onOwnerChangeEvent)==null||s.invoke(n),this.owner===this.context.connection.connectionId){Mr._local.push(this);const a=new CustomEvent("local-owner-changed",{detail:n});this.dispatchEvent(a)}const o=new CustomEvent("owner-changed",{detail:n});this.dispatchEvent(o),Mr.dispatchEvent("ownerChanged",o)}awake(){Mr.all.push(this),Ho&&console.log("Registered new PlayerState",this.guid,Mr.all.length-1,Mr.all),this.context.connection.beginListen(di.UserLeftRoom,this.onUserLeftRoom)}async start(){Ho&&console.log("PLAYERSTATE.START, owner: "+this.owner,this.context.connection.usersInRoom([])),this.owner?(this.context.connection.isInRoom||await Co(300),this.context.connection.userIsInRoom(this.owner)==!1&&(Ho&&console.log(`PlayerSync.start \u2192 doDestroy "${this.name}" because user "${this.owner}" is not in room anymore...`,"Currently in room:",...this.context.connection.usersInRoom()),this.doDestroy())):this.owner||(Ho&&console.warn("PlayerState.start \u2192 owner is undefined!",this.name),setTimeout(()=>{!this.destroyed&&!this.owner?this.dontDestroy?Ho&&console.warn("PlayerState.start \u2192 owner is still undefined but dontDestroy is set to true",this.name):(Ho&&console.warn(`PlayerState.start \u2192 owner is still undefined: destroying "${this.name}" instance now`),this.doDestroy()):console.log("PlayerState.start \u2192 owner is assigned",this.owner)},2e3))}doDestroy(){Ho&&console.log("PlayerSync.doDestroy \u2192 syncDestroy",this.name),c_(this.gameObject,this.context.connection)}onDestroy(){if(this.context.connection.stopListen(di.UserLeftRoom,this.onUserLeftRoom),Mr.all.splice(Mr.all.indexOf(this),1),this.isLocalPlayer){const i=Mr._local.indexOf(this);i>=0&&Mr._local.splice(i,1)}}},h(Nv,"_all",[]),h(Nv,"_local",[]),h(Nv,"_callbacks",{}),Nv);let Wo=Mr;ex([wI(Wo.prototype.onOwnerChange)],Wo.prototype,"owner",2);const Rre=te("debugavatar"),il=class extends Pe{constructor(){super(...arguments),h(this,"connectionId"),h(this,"avatar")}static getAvatar(i){return i>=0&&i<il.instances.length?il.instances[i]:null}static onAvatarMarkerCreated(i){return il._onNewAvatarMarkerAdded.push(i),i}static onAvatarMarkerDestroyed(i){return il._onAvatarMarkerDestroyed.push(i),i}awake(){il.instances.push(this),Rre&&console.log(this);for(const i of il._onNewAvatarMarkerAdded)i({avatarMarker:this,gameObject:this.gameObject})}onDestroy(){il.instances.splice(il.instances.indexOf(this),1);for(const i of il._onAvatarMarkerDestroyed)i({avatarMarker:this,gameObject:this.gameObject})}isLocalAvatar(){return this.connectionId===this.context.connection.connectionId}};let Tr=il;h(Tr,"instances",[]),h(Tr,"_onNewAvatarMarkerAdded",[]),h(Tr,"_onAvatarMarkerDestroyed",[]);var Pre=Object.defineProperty,Bre=Object.getOwnPropertyDescriptor,Dre=(i,e,t,s)=>{for(var r=s>1?void 0:s?Bre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Pre(e,t,r),r};const Cf=te("debugxrflags"),rj=te("disablexrflags");rj&&console.warn("XRFlags are disabled");var sl=(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))(sl||{});const nj=class{constructor(){h(this,"Mask",17)}Has(i){return(this.Mask&i)!==0}Set(i){Cf&&console.warn("Set XR flag state to",i),this.Mask=i,ro.Apply()}Enable(i){this.Mask|=i,ro.Apply()}Disable(i){this.Mask&=~i,ro.Apply()}Toggle(i){this.Mask^=i,ro.Apply()}EnableAll(){this.Mask=-1,ro.Apply()}DisableAll(){this.Mask=0,ro.Apply()}};let bn=nj;h(bn,"Global",new nj);var zv;const vc=(zv=class extends Pe{constructor(){super(...arguments),h(this,"visibleIn")}static Apply(){for(const i of this.registry)i.UpdateVisible(bn.Global)}awake(){vc.registry.push(this)}onEnable(){vc.firstApply?this.UpdateVisible(bn.Global):(vc.firstApply=!0,vc.Apply())}onDestroy(){const i=vc.registry.indexOf(this);i>=0&&vc.registry.splice(i,1)}get isOn(){return this.gameObject.visible}UpdateVisible(i=null){if(rj)return;let e;const t=i;if(t&&typeof t=="number"&&(console.assert(typeof t=="number","XRFlag.UpdateVisible: state must be a number",t),Cf&&console.log(t),vc.buffer.Mask=t,i=vc.buffer),i instanceof bn?(Cf&&console.warn(this.name,"use passed in mask",i.Mask,this.visibleIn),e=i.Has(this.visibleIn)):(Cf&&console.log(this.name,"use global mask"),bn.Global.Has(this.visibleIn)),e!==void 0)if(e)Cf&&console.log(this.name,"is visible",this.gameObject.uuid),oe.setActive(this.gameObject,!0);else{if(Cf&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},h(zv,"registry",[]),h(zv,"firstApply"),h(zv,"buffer",new bn),zv);let ro=vc;Dre([x()],ro.prototype,"visibleIn",2);var kre=Object.defineProperty,Ore=Object.getOwnPropertyDescriptor,SI=(i,e,t,s)=>{for(var r=s>1?void 0:s?Ore(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&kre(e,t,r),r};const jv=te("debugwebxr"),oj=new Ie().setFromAxisAngle(new w(0,1,0),Math.PI);class ad extends Pe{constructor(){super(...arguments),h(this,"head"),h(this,"leftHand"),h(this,"rightHand"),h(this,"_syncTransforms")}async onEnterXR(e){if(!this.activeAndEnabled)return;jv&&console.warn("AVATAR ENTER XR",this.guid,this.sourceId,this,this.activeAndEnabled),this._syncTransforms&&(this._syncTransforms.length=0),await this.prepareAvatar();const t=Wo.getFor(this);if(t!=null&&t.owner){const s=this.gameObject.addNewComponent(Tr);s.avatar=this.gameObject,s.connectionId=t.owner}else this.context.connection.isConnected?console.error("No player state found for avatar",this):t&&!this.context.connection.isConnected&&(t.dontDestroy=!0)}onLeaveXR(e){const t=this.gameObject.getComponent(Tr);t&&t.destroy()}onUpdateXR(e){var t,s;if(!this.activeAndEnabled)return;const r=Wo.isLocalPlayer(this);if(!r)return;const n=e.xr;if(n.rig&&n.rig.gameObject!==this.gameObject.parent&&(this.gameObject.position.set(0,0,0),this.gameObject.rotation.set(0,0,0),this.gameObject.scale.set(1,1,1),n.rig.gameObject.add(this.gameObject)),this._syncTransforms&&r)for(const c of this._syncTransforms)c.fastMode=!0,c.isOwned()||c.requestOwnership();if(this.head&&this.context.mainCamera){const c=this.head.asset;if(c.position.copy(this.context.mainCamera.position),c.quaternion.copy(this.context.mainCamera.quaternion),c.quaternion.x*=-1,this.context.time.frameCount%10===0){const u=oe.getComponentsInChildren(this.head.asset,ro);for(const d of u)d.enabled=!1,d.gameObject.visible=!1}}const o=e.xr.leftController,a=(t=this.leftHand)==null?void 0:t.asset;o&&a&&(a.position.copy(o.gripPosition),a.quaternion.copy(o.gripQuaternion),a.quaternion.multiply(oj),a.visible=o.isTracking);const l=e.xr.rightController;if(l&&(s=this.rightHand)!=null&&s.asset){const c=this.rightHand.asset;c.position.copy(l.gripPosition),c.quaternion.copy(l.gripQuaternion),c.quaternion.multiply(oj),c.visible=l.isTracking}}onBeforeRender(){this.context.time.frame%10===0&&this.updateRemoteAvatarVisibility()}updateRemoteAvatarVisibility(){var e,t,s;if(this.context.connection.isConnected){const r=Wo.getFor(this);if(r&&r.isLocalPlayer==!1){const n=vt.getXRSync(this.context);if(n&&n.hasState(r.owner)){this.tryFindAvatarObjectsIfMissing();const o=(e=this.leftHand)==null?void 0:e.asset;o&&(o.visible=n?.isTracking(r.owner,"left")??!1);const a=(t=this.rightHand)==null?void 0:t.asset;a&&(a.visible=n?.isTracking(r.owner,"right")??!1)}if((s=this.head)!=null&&s.asset){const o=oe.getComponentsInChildren(this.head.asset,ro);for(const a of o)a.enabled=!1,a.gameObject.visible=!0}}}}tryFindAvatarObjectsIfMissing(){if(!this.head||!this.leftHand||!this.rightHand){const e={head:this.head,leftHand:this.leftHand,rightHand:this.rightHand};zN.tryFindAvatarObjects(this.gameObject,this.sourceId||"",e),e.head&&(this.head=e.head),e.leftHand&&(this.leftHand=e.leftHand),e.rightHand&&(this.rightHand=e.rightHand)}}async prepareAvatar(){if(this.tryFindAvatarObjectsIfMissing(),this.head)this.head instanceof ye&&(this.head=new ni("",this.sourceId,this.head));else{const e=new ye;e.name="Head";const t=Yp.createPrimitive(Hu.Cube);e.add(t),this.gameObject.add(e),this.head=new ni("",this.sourceId,e),jv&&console.log("Create head",e)}if(this.rightHand)this.rightHand instanceof ye&&(this.rightHand=new ni("",this.sourceId,this.rightHand));else{const e=new ye;e.name="Right Hand",this.gameObject.add(e),this.rightHand=new ni("",this.sourceId,e),jv&&console.log("Create right hand",e)}if(this.leftHand)this.leftHand instanceof ye&&(this.leftHand=new ni("",this.sourceId,this.leftHand));else{const e=new ye;e.name="Left Hand",this.gameObject.add(e),this.leftHand=new ni("",this.sourceId,e),jv&&console.log("Create left hand",e)}await this.loadAvatarObjects(this.head,this.leftHand,this.rightHand),Wo.isLocalPlayer(this.gameObject)&&(this._syncTransforms=oe.getComponentsInChildren(this.gameObject,Eh))}async loadAvatarObjects(e,t,s){const r=e.loadAssetAsync(),n=t.loadAssetAsync(),o=s.loadAssetAsync(),a=new Array;r&&a.push(r),n&&a.push(n),o&&a.push(o);const l=await lg(a);jv&&console.log("Avatar loaded results:",l)}}SI([x(ni)],ad.prototype,"head",2),SI([x(ni)],ad.prototype,"leftHand",2),SI([x(ni)],ad.prototype,"rightHand",2);class rl{static Add(e,t,s=null){if(t){for(const r of this.Pois)if(r.obj===t)return;this.Pois.push({obj:t,avatar:s}),this.LastChangeTime=e.time.time}}static Remove(e,t){var s;if(t){for(const r of this.Pois)if(r.obj===t){this.Pois.splice(this.Pois.indexOf(r),1),this.LastChangeTime=e?.time.time??((s=kt.Current)==null?void 0:s.time.time);return}}}}h(rl,"Pois",[]),h(rl,"LastChangeTime",0);class Lre{constructor(){h(this,"guid"),h(this,"position",new w)}}class Gv extends Pe{constructor(){super(...arguments),h(this,"target",null),h(this,"avatar",null),h(this,"_model",null),h(this,"_targetModel",new Lre),h(this,"_currentTargetObject",null),h(this,"_lastUpdateTime",0),h(this,"_lookDuration",0),h(this,"_lastPoiChangedTime",0)}set controlledTarget(e){this.target=e;const t=J.get("MoveRandom");if(t&&this.target){const s=oe.getComponent(this.target,t);s&&s.destroy()}}awake(){if(this.avatar=oe.getComponentInParent(this.gameObject,Tr),this.avatar){const e=oe.getComponentInParent(this.gameObject,Tr);this._model=new ZE(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)&&Kr(this.target,e.position)})}update(){var e;if((!this.context.connection.isConnected||(e=this._model)!=null&&e.hasOwnership)&&(rl.LastChangeTime!==this._lastPoiChangedTime&&(this._lastPoiChangedTime=rl.LastChangeTime,this._lookDuration=0),this.selectTarget(),this._currentTargetObject&&this.context.time.frameCount%10===0&&this.target)){const t=Rt(this._currentTargetObject);Kr(this.target,t),this.context.connection.isConnected&&this.avatar&&(this.context.connection.send("avatar-look-target-changed",this._targetModel),this._targetModel.guid=this.avatar.guid,this._targetModel.position.copy(t))}}selectTarget(){if(this.context.time.time-this._lastUpdateTime>this._lookDuration){this._lastUpdateTime=this.context.time.time,this._lookDuration=Math.random()*.5+.2;const e=rl.Pois;if(e.length>0){const t=e[Math.floor(Math.random()*e.length)];if(t&&t.obj){if(t.avatar&&t.avatar===this.avatar)return;this._currentTargetObject=t.obj}}}}}const Ef=te("debugnetworkingstreams");var nl=(i=>(i.Connected="peer-user-connected",i.StreamReceived="receive-stream",i.StreamEnded="call-ended",i.Disconnected="peer-user-disconnected",i.UserJoined="user-joined",i))(nl||{});class aj{constructor(e,t){h(this,"type","call-ended"),h(this,"userId"),h(this,"direction"),this.userId=e,this.direction=t}}class lj{constructor(e,t){h(this,"type","receive-stream"),h(this,"stream"),h(this,"target"),this.stream=e,this.target=t}}class Ure{constructor(e,t){h(this,"guid"),h(this,"peerId"),h(this,"dontSave",!0),this.guid=e.id,this.peerId=t}}var cj=(i=>(i.Incoming="incoming",i.Outgoing="outgoing",i))(cj||{});class Fre extends Ks{constructor(e,t,s){super(),h(this,"userId"),h(this,"direction"),h(this,"call"),h(this,"_stream",null),h(this,"_isDisposed",!1),this.userId=e,this.call=t,this.direction=s,this._stream=null,t.on("stream",r=>{if(Ef&&console.log("Receive video",r.getAudioTracks(),r.getVideoTracks()),this._stream=r,s==="incoming"){const n=new lj(r,this);this.dispatchEvent(n)}}),t.on("close",()=>{this.dispatchEvent(new aj(e,s))})}get stream(){return this._stream}close(){this._isDisposed||(this._isDisposed=!0,this.call.close(),Ac(this._stream))}get isOpen(){var e;return((e=this.call.peerConnection)==null?void 0:e.connectionState)==="connected"}get isOpening(){var e;return((e=this.call.peerConnection)==null?void 0:e.connectionState)==="connecting"}get isClosed(){return!this.isOpen}}const Qv=class extends Ks{constructor(i,e){super(),h(this,"id"),h(this,"context"),h(this,"_peer"),h(this,"_incomingCalls",[]),h(this,"_outgoingCalls",[]),h(this,"_enabled",!1),h(this,"_enabledPeer",!1),h(this,"onConnectRoomFn",this.onConnectRoom.bind(this)),h(this,"onPeerConnectFn",this.onPeerConnect.bind(this)),h(this,"onPeerReceiveCallFn",this.onPeerReceivingCall.bind(this)),this.context=i,this.id=e,this.setupPeer(),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia}static getOrCreate(i,e){if(Qv.instances.has(e))return Qv.instances.get(e);const t=new Qv(i,e);return Qv.instances.set(e,t),t}getMyPeerId(){if(this.context.connection.connectionId)return this.getPeerIdFromUserId(this.context.connection.connectionId)}getPeerIdFromUserId(i){return this.id+"-"+i}getUserIdFromPeerId(i){return i.substring(this.id.length+1)}makeCall(i,e){var t;const s={metadata:{userId:this.context.connection.connectionId}},r=(t=this._peer)==null?void 0:t.call(i,e,s);if(r)return this.registerCall(r,"outgoing")}get peer(){return this._peer}enable(){this._enabled||(this._enabled=!0,this.context.connection.beginListen(di.JoinedRoom,this.onConnectRoomFn),this.subscribePeerEvents())}disable(){this._enabled&&(this._enabled=!1,this.context.connection.stopListen(di.JoinedRoom,this.onConnectRoomFn),this.unsubscribePeerEvents())}onConnectRoom(){this.setupPeer()}setupPeer(){if(this.context.connection.connectionId&&!this._enabledPeer){if(this._enabledPeer=!0,!this._peer){const i=this.getMyPeerId();i?this._peer=UU(i):console.error("Failed to setup peerjs because we dont have a connection id",this.context.connection.connectionId)}this._enabled&&this.subscribePeerEvents()}}subscribePeerEvents(){this._peer&&(this._peer.on("open",this.onPeerConnectFn),this._peer.on("call",this.onPeerReceiveCallFn))}unsubscribePeerEvents(){this._peer&&(this._peer.off("open",this.onPeerConnectFn),this._peer.off("call",this.onPeerReceiveCallFn))}onPeerConnect(i){Ef&&console.log("Peer connected as",i),this.context.connection.send("peer-user-connected",new Ure(this,i))}onPeerReceivingCall(i){i.answer(),this.registerCall(i,"incoming")}registerCall(i,e){const t=i.metadata;(!t||!t.userId)&&console.error("Missing call metadata",i);const s=t.userId;e==="incoming"&&Ef?console.log("Receive call from",i.metadata):Ef&&console.log("Make call to",i.metadata);const r=e==="incoming"?this._incomingCalls:this._outgoingCalls,n=new Fre(s,i,e);return r.push(n),i.on("error",o=>{console.error("Call error",o)}),i.on("close",()=>{Ef&&console.log("Call ended",i.metadata),i.close();const o=r.indexOf(n);o!==-1&&r.splice(o,1)}),n.addEventListener("call-ended",o=>{this.dispatchEvent(o)}),e==="incoming"&&(n.addEventListener("receive-stream",o=>{this.dispatchEvent(o)}),i.on("stream",()=>{let o=0;const a=setInterval(()=>{const l=o===0;!n.isOpen&&l&&(o+=1,clearInterval(a),n.close())},2e3)})),n}};let tx=Qv;h(tx,"instances",new Map);class ty extends Ks{constructor(e,t){super(),h(this,"context"),h(this,"peer"),h(this,"_sendingStreams",new Map),h(this,"debug",!1),h(this,"onJoinedRoom",s=>{this.debug&&console.log(`${s.userId} joined room and I'm currently sending ${this._sendingStreams.size} streams`),this._sendingStreams.size>0&&this.updateSendingCalls()}),h(this,"onReceiveStream",s=>{this.debug&&console.log("RECEIVE STREAM",s),this.dispatchEvent({type:"receive-stream",target:this,stream:s.stream,userId:s.userId})}),h(this,"onCallEnded",s=>{this.dispatchEvent(s)}),h(this,"onUserConnected",s=>{if(this.peer.id===s.guid){this.debug&&console.log("USER CONNECTED",s.guid,s);const r=this._sendingStreams.keys().next().value;this.peer.makeCall(s.peerId,r)}}),h(this,"onUserLeft",s=>{this.stopCallsToUsersThatAreNotInTheRoomAnymore()}),this.context=e,this.peer=t,Ef&&(this.debug=!0)}static create(e){const t=tx.getOrCreate(e.context,e.context.connection.connectionId);return new ty(e.context,t)}startSendingStream(e){this._sendingStreams.has(e)?console.warn("Received start sending stream with stream that is already being sent"):(this._sendingStreams.set(e,[]),this.updateSendingCalls())}stopSendingStream(e){if(e){const t=this._sendingStreams.get(e);if(t){this.debug&&console.log("Closing calls",t);for(const s of t)s.close()}this._sendingStreams.delete(e),t&&this.debug&&console.log("Currently sending",this._sendingStreams)}}enable(){this.peer.enable(),this.peer.addEventListener("receive-stream",this.onReceiveStream),this.peer.addEventListener("call-ended",this.onCallEnded),this.context.connection.beginListen("peer-user-connected",this.onUserConnected),this.context.connection.beginListen(di.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(di.UserJoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(di.UserLeftRoom,this.onUserLeft)}disable(){this.peer.disable(),this.peer.removeEventListener("receive-stream",this.onReceiveStream),this.peer.removeEventListener("call-ended",this.onCallEnded),this.context.connection.stopListen("peer-user-connected",this.onUserConnected),this.context.connection.stopListen(di.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(di.UserJoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(di.UserLeftRoom,this.onUserLeft)}updateSendingCalls(){var e;let t=!1;const s=this.context.connection.connectionId;for(const r of this._sendingStreams.keys()){const n=this._sendingStreams.get(r)||[];for(const o of this.context.connection.usersInRoom()){if(o===s)continue;const a=n.find(l=>l.userId===o);if(!a||((e=a.stream)==null?void 0:e.active)===!1){this.debug&&console.log("Starting call to",o,s);const l=this.peer.makeCall(this.peer.getPeerIdFromUserId(o),r);l&&(t=!0,n.push(l))}}this._sendingStreams.set(r,n)}this.stopCallsToUsersThatAreNotInTheRoomAnymore(),t&&this.debug&&console.log("Currently sending",this._sendingStreams)}stopCallsToUsersThatAreNotInTheRoomAnymore(){for(const e of this._sendingStreams.keys()){const t=this._sendingStreams.get(e);if(t)for(let s=t.length-1;s>=0;s--){const r=t[s];this.context.connection.userIsInRoom(r.userId)||(r.close(),t.splice(s,1))}}}}function Ac(i){if(i&&i instanceof MediaStream)for(const e of i.getTracks())e.stop()}var Nre=Object.defineProperty,zre=Object.getOwnPropertyDescriptor,hj=(i,e,t,s)=>{for(var r=s>1?void 0:s?zre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Nre(e,t,r),r};const jre="noVoip",Gre=te("debugvoip");class ld extends Pe{constructor(){super(...arguments),h(this,"autoConnect",!1),h(this,"runInBackground",!0),h(this,"debug",!1),h(this,"_net"),h(this,"_outputStream",null),h(this,"onJoinedRoom",async()=>{await Co(300),this.autoConnect&&!this.isSending&&this.connect()}),h(this,"_incomingStreams",new Map),h(this,"onReceiveStream",e=>{const t=e.target.userId,s=e.stream,r=this._incomingStreams.get(t);if(r)r.srcObject=s,r.setAttribute("autoplay","true");else{const n=new Audio;this._incomingStreams.set(t,n),n.setAttribute("autoplay","true"),n.srcObject=s}}),h(this,"onStreamEnded",e=>{const t=this._incomingStreams.get(e.userId);Ac(t?.srcObject),this._incomingStreams.delete(e.userId)}),h(this,"onEnabledChanged",()=>{for(const e of this._incomingStreams){const t=e[1];t.muted=!this.enabled}}),h(this,"onVisibilityChanged",()=>{if(this.runInBackground)return;const e=document.visibilityState!=="visible";this.setMuted(e);for(const t of this._incomingStreams){const s=t[1];s.muted=e}})}awake(){Gre&&(this.debug=!0),this.debug&&window.addEventListener("keydown",async e=>{e.key==="v"&&(console.log("MUTE?",!this.isMuted),this.setMuted(!this.isMuted))})}onEnable(){this._net||(this._net=ty.create(this)),this._net.addEventListener(nl.StreamReceived,this.onReceiveStream),this._net.addEventListener(nl.StreamEnded,this.onStreamEnded),this._net.enable(),this.autoConnect&&(this.context.connection.isConnected?this.connect():this.context.connection.beginListen(di.JoinedRoom,this.onJoinedRoom)),this.onEnabledChanged(),window.addEventListener("visibilitychange",this.onVisibilityChanged)}onDisable(){var e;this._net.stopSendingStream(this._outputStream),this._net.removeEventListener(nl.StreamReceived,this.onReceiveStream),this._net.removeEventListener(nl.StreamEnded,this.onStreamEnded),(e=this._net)==null||e.disable(),this.context.connection.stopListen(di.JoinedRoom,this.onJoinedRoom),this.onEnabledChanged(),window.removeEventListener("visibilitychange",this.onVisibilityChanged)}get isSending(){return this._outputStream!=null&&this._outputStream.active}async connect(e){if(this.context.connection.isConnected){if(!await wC())return console.error("Cannot connect to voice chat - microphone permissions not granted"),!1}else return console.error("Cannot connect to voice chat - not connected to server"),!1;return this._net.stopSendingStream(this._outputStream),Ac(this._outputStream),this._outputStream=await this.getAudioStream(e),this._outputStream?(this._net.startSendingStream(this._outputStream),!0):(await wC()?console.error("VOIP: Could not get audio stream - please make sure to connect an audio device and grant microphone permissions"):Xk("Microphone permissions not granted: Please grant microphone permissions to use voice chat"),!1)}disconnect(){this._net.stopSendingStream(this._outputStream),Ac(this._outputStream),this._outputStream=null}setMuted(e){var t;const s=(t=this._outputStream)==null?void 0:t.getAudioTracks();if(s)for(const r of s)r.enabled=!e}get isMuted(){var e;if(this._outputStream===null)return!1;const t=(e=this._outputStream)==null?void 0:e.getAudioTracks();if(t){for(const s of t)if(!s.enabled)return!0}return!1}getFrequency(e){return this.unsupported_getfrequency||(this.unsupported_getfrequency=!0,wt()&&is("VOIP: getFrequency is currently not supported"),console.warn("VOIP: getFrequency is currently not supported")),null}async getAudioStream(e){return navigator.mediaDevices.getUserMedia?await navigator.mediaDevices.getUserMedia({audio:e??!0,video:!1}).catch(t=>(console.warn("VOIP failed getting audio stream",t),null)):(console.error("No getDisplayMedia support"),null)}}hj([x()],ld.prototype,"autoConnect",2),hj([x()],ld.prototype,"runInBackground",2);var Qre=Object.defineProperty,Vre=Object.getOwnPropertyDescriptor,uj=(i,e,t,s)=>{for(var r=s>1?void 0:s?Vre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Qre(e,t,r),r};const Hre=te("debugmouth");class Vv extends Pe{constructor(){super(...arguments),h(this,"idle",[]),h(this,"talking",[]),h(this,"marker",null),h(this,"voip",null),h(this,"lastMouthChangeTime",0),h(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=oe.findObjectOfType(ld,this.context),this.marker||(this.marker=oe.getComponentInParent(this.gameObject,Tr))},3e3)}update(){var e;if(!this.voip||this.context.time.frameCount%10!==0)return;let t=((e=this.marker)==null?void 0:e.connectionId)??null;if(!t){Hre&&(t=null);return}const s=this.voip.getFrequency(t)??0;this.updateLips(s)}updateLips(e){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&e>30){this.lastMouthChangeTime=this.context.time.time;const t=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,t)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const t=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,t)}}}setMouthShapeActive(e,t){if(e){e!=this.idle?this.idle.map(s=>s.visible=!1):this.talking.map(s=>s.visible=!1);for(let s=0;s<e.length;s++){const r=e[s];r&&(r.visible=s===t)}}}}uj([x(ye)],Vv.prototype,"idle",2),uj([x(ye)],Vv.prototype,"talking",2);class CI extends Pe{constructor(){super(...arguments),h(this,"voip",null),h(this,"marker",null),h(this,"_startPosition",null)}awake(){this.voip=oe.findObjectOfType(ld,this.context),this.marker=oe.getComponentInParent(this.gameObject,Tr)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const e=this.marker.connectionId,t=this.voip.getFrequency(e);if(t==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const s=t/100;this.gameObject.position.y=this._startPosition.y+s*.07}}var Wre=Object.defineProperty,Xre=Object.getOwnPropertyDescriptor,ix=(i,e,t,s)=>{for(var r=s>1?void 0:s?Xre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Wre(e,t,r),r};class cd extends Pe{constructor(){super(...arguments),h(this,"eyes",[]),h(this,"lastBlinkTime",0),h(this,"blinkLength",0),h(this,"eyesOpen",!0),h(this,"state",null)}awake(){this.state=oe.getComponentInParent(this.gameObject,ro)}update(){if(!(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)&&this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const e of this.eyes)e&&(e.visible=this.eyesOpen)}}}ix([x(ye)],cd.prototype,"eyes",2),ix([x()],cd.prototype,"lastBlinkTime",2),ix([x()],cd.prototype,"blinkLength",2),ix([x()],cd.prototype,"eyesOpen",2);var qre=Object.defineProperty,Yre=Object.getOwnPropertyDescriptor,EI=(i,e,t,s)=>{for(var r=s>1?void 0:s?Yre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&qre(e,t,r),r},MI;const dj=(MI=class extends Pe{constructor(){super(...arguments),h(this,"head",null),h(this,"eyes",null),h(this,"target",null),h(this,"brain",null),h(this,"vec",new w),h(this,"currentTargetPoint",new w)}awake(){this.brain||(this.brain=oe.getComponentInParent(this.gameObject,Gv)),this.brain||(console.log("No look at brain found, adding it now"),this.brain=oe.addNewComponent(this.gameObject,Gv)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const i=this.target;if(i&&this.head){const e=this.eyes;if(e){const t=Rt(i);this.currentTargetPoint.lerp(t,this.context.time.deltaTime/.1);const s=Rt(this.head),r=this.vec.copy(this.currentTargetPoint).sub(s).normalize();if(r.length()<.1)return;const n=dj.forward;if(n.set(0,0,1),n.applyQuaternion(Ii(this.head)),n.dot(r)>.45)for(let o=0;o<e.length;o++)e[o].lookAt(this.currentTargetPoint)}}}},h(MI,"forward",new w(0,0,1)),MI);let Mf=dj;EI([x(ye)],Mf.prototype,"head",2),EI([x(ye)],Mf.prototype,"eyes",2),EI([x(ye)],Mf.prototype,"target",2);const Hv=te("debugavatar");class sx{constructor(e,t,s,r){h(this,"root"),h(this,"head"),h(this,"leftHand"),h(this,"rigthHand");var n;this.root=e,this.head=t,this.leftHand=s,this.rigthHand=r,(n=this.root)==null||n.traverse(o=>o.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class TI{constructor(){h(this,"avatarRegistryUrl",null)}async getOrCreateNewAvatarInstance(e,t){if(!t)return console.error("Can not create avatar: failed to provide id or root object"),null;let s=null;if(typeof t=="string"){if(s=await this.loadAvatar(e,t),!s){const n=new Ia;s=oe.instantiate(Ip(t,e.scene),n)}}else s=t;if(!s)return null;const r=this.findAvatar(s);return r.isValid?(Hv&&console.log("[Custom Avatar] valid config",t,Hv?r:""),r):(console.warn("[Custom Avatar] config isn't valid",t,Hv?r:""),null)}async loadAvatar(e,t){if(console.assert(t!=null&&typeof t=="string","Avatar id must not be null"),t.length<=0||!t)return null;if(Hv&&console.log("[Custom Avatar] "+t+", loading..."),t.endsWith(".glb")||(t+=".glb"),this.avatarRegistryUrl===null){const r=await fetch("./"+t);let n=null;if(r.ok){const a=await r.blob();a&&(n=await a.arrayBuffer())}if(!n&&(n=await mE(t,t,0,"no url here go away",!0),!n))return null;const o=await ta().parseSync(e,n,null,0);return o?.scene??null}const s=new sf;return dv(s,e),new Promise((r,n)=>{const o=this.avatarRegistryUrl+"/"+t;s.load(o,async a=>{await ta().createBuiltinComponents(e,o,a,null,void 0),r(a.scene)},a=>{Hv&&console.log("[Custom Avatar] "+a.loaded/a.total*100+"% loaded of "+a.total/1024+"kB")},a=>{console.error("[Custom Avatar] Error when loading: "+a),r(null)})})}cacheModel(e,t){}findAvatar(e){const t=e;let s=t;s.children.length==1&&(s=e.children[0]);let r=this.findAvatarPart(s,["head"]);const n=this.findAvatarPart(s,["left","hand"]),o=this.findAvatarPart(s,["right","hand"]);if(!r){r=t;const a=new w;new Mi().setFromObject(r).getSize(a);const l=Math.max(a.x,a.y,a.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+l+" meters! Should be < 0.3m"),l>.3&&r.scale.multiplyScalar(1/l*.3)}return new sx(t,r,n,o)}findAvatarPart(e,t){const s=e.name.toLowerCase();let r=!0;for(const n of t){if(!r)break;s.indexOf(n)===-1&&(r=!1)}if(r)return e;if(e.children)for(const n of e.children){const o=this.findAvatarPart(n,t);if(o)return o}return null}handleCustomAvatarErrors(e){if(!e.ok)throw Error(e.statusText);return e}}var Jre=Object.defineProperty,Kre=Object.getOwnPropertyDescriptor,II=(i,e,t,s)=>{for(var r=s>1?void 0:s?Kre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Jre(e,t,r),r};class Tf extends Pe{constructor(){super(...arguments),h(this,"length",1),h(this,"depthTest",!0),h(this,"isGizmo",!0),h(this,"_axes",null)}onEnable(){if(this.isGizmo&&!xg)return;this._axes||(this._axes=new wo(this.length)),this._axes.layers.disableAll(),this._axes.layers.set(this.layer),this.gameObject.add(this._axes);const e=this._axes.material;e&&e.depthTest!==void 0&&(e.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}II([x()],Tf.prototype,"length",2),II([x()],Tf.prototype,"depthTest",2),II([x()],Tf.prototype,"isGizmo",2);class RI extends Pe{constructor(){super(...arguments),h(this,"from"),h(this,"to"),h(this,"hint"),h(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const e=Rt(this.to).clone(),t=Rt(this.from).clone(),s=e.distanceTo(t),r=e.clone();r.sub(t);const n=t.clone();n.add(e),n.multiplyScalar(.5);const o=Rt(this.hint).clone();o.sub(n);const a=new w;a.crossVectors(o,r),a.crossVectors(r,a),a.normalize();const l=s*.5,c=Math.max(this.desiredDistance,l),u=Math.sqrt(c*c-l*l),d=a.clone();d.multiplyScalar(u),d.add(n),Kr(this.gameObject,d);const p=n.clone();p.sub(a),this.gameObject.lookAt(p)}}const Zre=te("debugusdz");class rx{constructor(){h(this,"behaviours",[]),h(this,"behaviourComponents",[]),h(this,"behaviourComponentsCopy",[])}get extensionName(){return"Behaviour"}addBehavior(e){this.behaviours.push(e)}onBeforeBuildDocument(e){const t=[];return e.root.traverse(s=>{oe.foreachComponent(s,r=>{var n;const o=r;if(typeof o.createBehaviours=="function"||typeof o.beforeCreateDocument=="function"||typeof o.afterCreateDocument=="function"||typeof o.afterSerialize=="function"){this.behaviourComponents.push(o);const a=(n=o.beforeCreateDocument)==null?void 0:n.call(o,this,e);a instanceof Promise&&t.push(a)}},!1)}),Promise.all(t)}onExportObject(e,t,s){var r;for(const n of this.behaviourComponents)(r=n.createBehaviours)==null||r.call(n,this,t,s)}onAfterBuildDocument(e){for(const t of this.behaviourComponents)typeof t.afterCreateDocument=="function"&&t.afterCreateDocument(this,e);this.behaviourComponentsCopy=this.behaviourComponents.slice(),this.behaviourComponents.length=0}onAfterHierarchy(e,t){var s;if((s=this.behaviours)!=null&&s.length){t.beginBlock('def Scope "Behaviors"');for(const r of this.behaviours)r.writeTo(this,e.document,t);t.closeBlock()}}async onAfterSerialize(e){Zre&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const t of this.behaviourComponentsCopy)typeof t.afterSerialize=="function"&&(t.afterSerialize.constructor.name==="AsyncFunction"?await t.afterSerialize(this,e):t.afterSerialize(this,e));this.behaviours.length=0}}var $re=Object.defineProperty,ene=Object.getOwnPropertyDescriptor,PI=(i,e,t,s)=>{for(var r=s>1?void 0:s?ene(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&$re(e,t,r),r};class hd extends en{constructor(){super(...arguments),h(this,"threshold"),h(this,"intensity"),h(this,"scatter"),h(this,"selectiveBloom",!0)}get typeName(){return"Bloom"}init(){this.threshold.defaultValue=1,this.intensity.defaultValue=0,this.scatter.defaultValue=.2,this.selectiveBloom?(this.threshold.valueProcessor=e=>e,this.intensity.valueProcessor=e=>e,this.scatter.valueProcessor=e=>1*Math.PI*(1-e)):(this.threshold.valueProcessor=e=>e,this.intensity.valueProcessor=e=>e,this.scatter.valueProcessor=e=>100*(1-e))}onCreateEffect(){let e;if(this.selectiveBloom){const t=e=new FO(this.context.scene,this.context.mainCamera,{blendFunction:Wt.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,intensity:this.intensity.value});t.inverted=!0}else e=new rE;return this.intensity.onValueChanged=t=>{e.intensity=t},this.threshold.onValueChanged=t=>{e.luminanceMaterial.threshold=t},this.scatter.onValueChanged=t=>{e.luminancePass.enabled=!0,e.luminanceMaterial.smoothing=t},e}}PI([x(Bt)],hd.prototype,"threshold",2),PI([x(Bt)],hd.prototype,"intensity",2),PI([x(Bt)],hd.prototype,"scatter",2),Vo("Bloom",hd);var tne=Object.defineProperty,ine=Object.getOwnPropertyDescriptor,jn=(i,e,t,s)=>{for(var r=s>1?void 0:s?ine(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&tne(e,t,r),r};class Xo extends Pe{constructor(){super(...arguments),h(this,"attachedRigidbody",null),h(this,"isTrigger",!1),h(this,"sharedMaterial"),h(this,"membership",[0]),h(this,"filter"),h(this,"updateProperties",()=>{var e;(e=this.context.physics.engine)==null||e.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ni))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ni))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ni))}onDisable(){var e;(e=this.context.physics.engine)==null||e.removeBody(this)}get body(){var e;return(e=this.context.physics.engine)==null?void 0:e.getBody(this)}updatePhysicsMaterial(){var e;(e=this.context.physics.engine)==null||e.updatePhysicsMaterial(this)}}jn([x(Ni)],Xo.prototype,"attachedRigidbody",2),jn([x()],Xo.prototype,"isTrigger",2),jn([x()],Xo.prototype,"sharedMaterial",2),jn([x()],Xo.prototype,"membership",2),jn([x()],Xo.prototype,"filter",2);class Wv extends Xo{constructor(){super(...arguments),h(this,"radius",.5),h(this,"center",new w(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addSphereCollider(this),H0(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),xC(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}jn([Sr(),x()],Wv.prototype,"radius",2),jn([x(w)],Wv.prototype,"center",2);class Xv extends Xo{constructor(){super(...arguments),h(this,"size",new w(1,1,1)),h(this,"center",new w(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addBoxCollider(this,this.size),H0(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),xC(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}jn([Sr(),x(w)],Xv.prototype,"size",2),jn([x(w)],Xv.prototype,"center",2);class If extends Xo{constructor(){super(...arguments),h(this,"sharedMesh"),h(this,"convex",!1)}onEnable(){var e,t,s,r,n;if(super.onEnable(),(e=this.sharedMesh)!=null&&e.isMesh||this.gameObject instanceof ve&&(this.sharedMesh=this.gameObject),(t=this.sharedMesh)!=null&&t.isMesh)(s=this.context.physics.engine)==null||s.addMeshCollider(this,this.sharedMesh,this.convex,ss(this.gameObject));else{const o=this.sharedMesh;if(o!=null&&o.isGroup){console.warn(`MeshCollider mesh is a group "${((r=this.sharedMesh)==null?void 0:r.name)||this.gameObject.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);for(const a in o.children){const l=o.children[a];l.isMesh&&((n=this.context.physics.engine)==null||n.addMeshCollider(this,l,this.convex,ss(this.gameObject)))}}}}}jn([x()],If.prototype,"sharedMesh",2),jn([x()],If.prototype,"convex",2);class Ph extends Xo{constructor(){super(...arguments),h(this,"center",new w(0,0,0)),h(this,"radius",.5),h(this,"height",2)}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addCapsuleCollider(this,this.height,this.radius)}}jn([x(w)],Ph.prototype,"center",2),jn([x()],Ph.prototype,"radius",2),jn([x()],Ph.prototype,"height",2);var sne=Object.defineProperty,rne=Object.getOwnPropertyDescriptor,BI=(i,e,t,s)=>{for(var r=s>1?void 0:s?rne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&sne(e,t,r),r};class ud extends Pe{constructor(){super(...arguments),h(this,"objectBounds",!1),h(this,"color"),h(this,"isGizmo",!0),h(this,"_gizmoObject",null),h(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!xg||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new fC(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=iT(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),ks.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){for(var e;this._boxHelper;)(e=this._boxHelper)==null||e.update(),yield}}BI([x()],ud.prototype,"objectBounds",2),BI([x(xe)],ud.prototype,"color",2),BI([x()],ud.prototype,"isGizmo",2);class nne extends wN{constructor(e,t={}){super(e),e._simpleState__activeStates=[],e._simpleState__normalStyles={},e._simpleState__states=t,e._simpleState__statesProperties={};for(const s in t)for(const r in t[s])e._simpleState__statesProperties[r]||(e._simpleState__statesProperties[r]=[]),e._simpleState__statesProperties[r].push(s);for(const s of e._components)e._simpleState__statesProperties[s.id]&&(e._simpleState__normalStyles[s.id]=s.inline?s.inline:s._value);e.__overridedSet=e.set,e.set=this.storeSet.bind(e),e.renderStates=this.renderStates.bind(e),e.setupState=this.setupState.bind(e),e.setState=this.setState.bind(e),e.activatePseudoState=this.activatePseudoState.bind(e),e.deactivatePseudoState=this.deactivatePseudoState.bind(e),e.togglePseudoState=this.togglePseudoState.bind(e)}act(){}attach(){}detach(){}setupState(e,t){this._simpleState__states[e]=t;const s=[];for(const r in t)this._simpleState__statesProperties[r]||(this._simpleState__statesProperties[r]=[],s.push(r)),this._simpleState__statesProperties[r].push(e);for(const r of this._components)s.indexOf(r.id)>-1&&(this._simpleState__normalStyles[r.id]=r.inline?r.inline:r._value)}renderStates(){let e={...this._simpleState__normalStyles};for(const t in this._simpleState__states)this._simpleState__activeStates.indexOf(t)>-1&&(e={...e,...this._simpleState__states[t]});this.set(e,!1)}storeSet(e,t=!0){if(t)for(const s in e)this._simpleState__statesProperties[s]&&(this._simpleState__normalStyles[s]=e[s]);this.__overridedSet(e)}activatePseudoState(e){this._simpleState__activeStates.indexOf(e)===-1&&(this._simpleState__activeStates.push(e),this.renderStates())}deactivatePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1&&(this._simpleState__activeStates.splice(t,1),this.renderStates())}togglePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1?this._simpleState__activeStates.splice(t,1):this._simpleState__activeStates.push(e),this.renderStates()}setState(e){Array.isArray(e)?this._simpleState__activeStates=e:this._simpleState__activeStates=[e],this.renderStates()}}var one=Object.defineProperty,ane=Object.getOwnPropertyDescriptor,pj=(i,e,t,s)=>{for(var r=s>1?void 0:s?ane(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&one(e,t,r),r};class Rf extends Pe{constructor(){super(...arguments),h(this,"effectColor"),h(this,"effectDistance")}}pj([x(Si)],Rf.prototype,"effectColor",2),pj([x(ee)],Rf.prototype,"effectDistance",2);var lne=Object.defineProperty,cne=Object.getOwnPropertyDescriptor,qv=(i,e,t,s)=>{for(var r=s>1?void 0:s?cne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&lne(e,t,r),r};const DI=te("debugui"),kI=te("debuguilayout");class OI{constructor(){h(this,"width"),h(this,"height")}}class LI{constructor(){h(this,"x"),h(this,"y"),h(this,"width"),h(this,"height")}}const wa=new w,Yv=new Te,nx=new Ie,fj=class extends Ra{constructor(){super(...arguments),h(this,"_anchoredPosition"),h(this,"sizeDelta",new ee(100,100)),h(this,"pivot",new ee(.5,.5)),h(this,"anchorMin",new ee(0,0)),h(this,"anchorMax",new ee(1,1)),h(this,"minWidth"),h(this,"minHeight"),h(this,"lastMatrix"),h(this,"rectBlock"),h(this,"_transformNeedsUpdate",!1),h(this,"_initialPosition"),h(this,"_parentRectTransform"),h(this,"_lastUpdateFrame",-1),h(this,"_lastAnchoring"),h(this,"_createdBlocks",[]),h(this,"_createdTextBlocks",[])}get parent(){return this._parentRectTransform}get translation(){return this.gameObject.position}get rotation(){return this.gameObject.quaternion}get scale(){return this.gameObject.scale}get anchoredPosition(){return this._anchoredPosition||(this._anchoredPosition=new ee),this._anchoredPosition}set anchoredPosition(i){this._anchoredPosition=i}get width(){let i=this.sizeDelta.x;if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const e=this._parentRectTransform.width,t=this.anchorMax.x-this.anchorMin.x;i=e*t,i+=this.sizeDelta.x}return this.minWidth!==void 0&&i<this.minWidth?this.minWidth:i}get height(){let i=this.sizeDelta.y;if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const e=this._parentRectTransform.height,t=this.anchorMax.y-this.anchorMin.y;i=e*t,i+=this.sizeDelta.y}return this.minHeight!==void 0&&i<this.minHeight?this.minHeight:i}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new ee),this.lastMatrix=new Te,this.rectBlock=new ye,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,yf(this,"_anchoredPosition",()=>{this.markDirty()}),yf(this,"sizeDelta",()=>{this.markDirty()}),yf(this,"pivot",()=>{this.markDirty()}),yf(this,"anchorMin",()=>{this.markDirty()}),yf(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var i;super.onEnable(),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(i=this.Canvas)==null||i.registerTransform(this)}onDisable(){var i;super.onDisable(),this.removeShadowComponent(),(i=this.Canvas)==null||i.unregisterTransform(this)}onParentRectTransformChanged(i){this._transformNeedsUpdate||this.onApplyTransform(kI?`${i.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(kI&&console.warn("RectTransform markDirty()",this.name),this._transformNeedsUpdate=!0,this._lastUpdateFrame=-1)}updateTransform(){(this._transformNeedsUpdate||!this.lastMatrix.equals(this.gameObject.matrix))&&this.canUpdate()&&this.onApplyTransform(this._transformNeedsUpdate?"Marked dirty":"Matrix changed")}canUpdate(){return this._transformNeedsUpdate&&this.activeAndEnabled&&this._lastUpdateFrame!==this.context.time.frame}onApplyTransform(i){var e;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const t=this.shadowComponent;if(!t)return;this.gameObject.parent?this._parentRectTransform=oe.getComponentInParent(this.gameObject.parent,fj):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,kI&&console.warn("RectTransform \u2192 ApplyTransform",this.name+" because "+i),this.isRoot()?this.Root.screenspace||(t.rotation.y=Math.PI):(t.matrix.identity(),t.matrixAutoUpdate=!1,wa.set(0,0,0),this.applyPivot(wa),t.matrix.setPosition(wa.x,wa.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(nx.copy(this.gameObject.quaternion),nx.x*=-1,nx.z*=-1,Yv.makeRotationFromQuaternion(nx),t.matrix.premultiply(Yv)),wa.set(0,0,0),this.applyAnchoring(wa),(e=this.Canvas)!=null&&e.screenspace?wa.z+=.1:wa.z+=.01,Yv.identity(),Yv.setPosition(wa.x,wa.y,wa.z),t.matrix.premultiply(Yv),t.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const s=!0;for(const r of hT(this.gameObject,Ra,s,1)){if(r===this||!r.activeAndEnabled)continue;const n=r;n.onParentRectTransformChanged&&n.onParentRectTransformChanged(this)}}applyAnchoring(i){this._lastAnchoring||(this._lastAnchoring=new ee);const e=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=e.x,this.gameObject.position.y+=e.y,this._lastAnchoring.copy(this._anchoredPosition),i.x+=this._initialPosition.x-this.gameObject.position.x,i.y+=this._initialPosition.y-this.gameObject.position.y,i.z+=this._initialPosition.z-this.gameObject.position.z;const t=this._parentRectTransform;if(t){let s=0;const r=1-this.anchorMax.y-this.anchorMin.y;s-=t.height*.5*r,i.y+=s;let n=0;const o=1-this.anchorMax.x-this.anchorMin.x;n-=t.width*.5*o,i.x+=n}}applyPivot(i){if(this.pivot&&!this.isRoot()){const e=this.pivot.x-.5;i.x-=e*this.sizeDelta.x*this.gameObject.scale.x;const t=this.pivot.y-.5;i.y-=t*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const i={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(i),i}ensureValidSize(i,e=1e-4){return i.width<=0&&(i.width=e),i.height<=0&&(i.height=1e-4),i}createNewBlock(i){i={...this.getBasicOptions(),...i},DI&&console.log(this.name,i);const e=new jM(i);return this._createdBlocks.push(e),e}createNewText(i){DI&&console.log(i),i={...this.getBasicOptions(),...i},DI&&console.log(this.name,i);const e=new QM(i);return this._createdTextBlocks.push(e),e}};let _n=fj;qv([x(ee)],_n.prototype,"anchoredPosition",1),qv([x(ee)],_n.prototype,"sizeDelta",2),qv([x(ee)],_n.prototype,"pivot",2),qv([x(ee)],_n.prototype,"anchorMin",2),qv([x(ee)],_n.prototype,"anchorMax",2);var hne=Object.defineProperty,une=Object.getOwnPropertyDescriptor,mj=(i,e,t,s)=>{for(var r=s>1?void 0:s?une(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&hne(e,t,r),r};const ox={backgroundColor:new xe(1,1,1),backgroundOpacity:1,borderColor:new xe(1,1,1),borderOpacity:1};var UI;const ax=(UI=class extends Ra{constructor(){super(...arguments),h(this,"_alphaFactor",1),h(this,"sRGBColor",new xe(1,0,1)),h(this,"raycastTarget",!0),h(this,"uiObject",null),h(this,"_color",null),h(this,"_rect",null),h(this,"_stateManager",null),h(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new Si(1,1,1,1)),this._color}set color(i){(!this._color||this._color.r!==i.r||this._color.g!==i.g||this._color.b!==i.b||this._color.alpha!==i.alpha)&&(this._color||(this._color=new Si(1,1,1,1)),this._color.copy(i),this.onColorChanged())}setAlphaFactor(i){this._alphaFactor=i,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(this.sRGBColor.copy(this._color),this.sRGBColor.convertLinearToSRGB(),ox.backgroundColor=this.sRGBColor,ox.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(ox,this._alphaFactor),this.uiObject.set(ox),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=oe.getComponent(this.gameObject,_n)),!this._rect)throw new Error("Not Supported: Make sure to add a RectTransform component before adding a UI Graphic component.");return this._rect}onParentRectTransformChanged(){var i;(i=this.uiObject)==null||i.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone())}setState(i){this.makePanel(),this.uiObject&&(this.uiObject.setState(i),this==null||this.markDirty())}setupState(i){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new nne(this.uiObject)),this.uiObject.setupState(i.state,i.attributes))}setOptions(i){this.makePanel(),this.uiObject&&this.uiObject.set(i)}awake(){super.awake(),this.makePanel(),yf(this,"_color",()=>jse(this,this.onColorChanged))}onEnable(){var i;super.onEnable(),this.uiObject&&((i=this.rectTransform.shadowComponent)==null||i.add(this.uiObject),this.addShadowComponent(this.uiObject,this.rectTransform))}onDisable(){super.onDisable(),this.uiObject&&this.removeShadowComponent()}makePanel(){if(this.uiObject||this._currentlyCreatingPanel)return;this._currentlyCreatingPanel=!0;const i=.015,e={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:i};this.onBeforeCreate(e),this.applyEffects(e),this.onCreate(e),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated(),this.onColorChanged()}onBeforeCreate(i){}onCreate(i){this.uiObject=this.rectTransform.createNewBlock(i),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(i,e=1){var t;const s=(t=this.gameObject)==null?void 0:t.getComponent(Rf);s&&(s.effectDistance&&(i.borderWidth=Math.max(Math.abs(s.effectDistance.x),Math.abs(s.effectDistance.y))),s.effectColor&&(i.borderColor=s.effectColor,i.borderOpacity=s.effectColor.alpha*e))}async setTexture(i){if(this.setOptions({backgroundOpacity:0}),i){if(ax.textureCache.has(i))i=ax.textureCache.get(i);else if(!i.isRenderTargetTexture){const e=i.clone();e.colorSpace=Ei,ax.textureCache.set(i,e),i=e}this.setOptions({backgroundImage:i,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"})}else this.setOptions({backgroundImage:null,borderRadius:0,backgroundOpacity:this.color.alpha});this.markDirty()}onAfterAddedToScene(){super.onAfterAddedToScene(),this.shadowComponent&&(this.shadowComponent.offset=this.shadowComponent.position.z)}},h(UI,"textureCache",new Map),UI);let dd=ax;mj([x(Si)],dd.prototype,"color",1),mj([x()],dd.prototype,"raycastTarget",2);class Jv extends dd{constructor(){super(...arguments),h(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var dne=Object.defineProperty,pne=Object.getOwnPropertyDescriptor,lx=(i,e,t,s)=>{for(var r=s>1?void 0:s?pne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&dne(e,t,r),r};let FI=class{constructor(){h(this,"texture",null),h(this,"rect")}};lx([x(Nt)],FI.prototype,"texture",2);let Pf=class extends Jv{constructor(){super(...arguments),h(this,"_sprite"),h(this,"pixelsPerUnitMultiplier",1)}set image(i){this.sprite||(this.sprite=new FI),this.sprite.texture=i,this.onAfterCreated()}get image(){return this.sprite?this.sprite.texture:null}get sprite(){return this._sprite}set sprite(i){this._sprite!==i&&(this._sprite=i,this.onAfterCreated())}isBuiltinSprite(){var i,e,t,s,r,n,o,a,l,c,u;switch((e=(i=this.sprite)==null?void 0:i.texture)==null?void 0:e.name){case"InputFieldBackground":case"UISprite":case"Background":case"Knob":return!0}return!((r=(s=(t=this.sprite)==null?void 0:t.texture)==null?void 0:s.name)!=null&&r.length)&&((a=(o=(n=this.sprite)==null?void 0:n.texture)==null?void 0:o.image)==null?void 0:a.width)===32&&((u=(c=(l=this.sprite)==null?void 0:l.texture)==null?void 0:c.image)==null?void 0:u.height)===32}onBeforeCreate(i){var e,t;super.onBeforeCreate(i),this.isBuiltinSprite()&&(i.borderRadius=5/this.pixelsPerUnitMultiplier,((t=(e=this.sprite)==null?void 0:e.texture)==null?void 0:t.name)==="Knob"&&(i.borderRadius=999))}onAfterCreated(){var i;this.__didAwake&&(super.onAfterCreated(),!this.isBuiltinSprite()&&this.setTexture((i=this.sprite)==null?void 0:i.texture))}};lx([x(FI)],Pf.prototype,"sprite",1),lx([x()],Pf.prototype,"pixelsPerUnitMultiplier",2);class cx extends Jv{constructor(){super(...arguments),h(this,"_mainTexture")}get mainTexture(){return this._mainTexture}set mainTexture(e){this._mainTexture!==e&&(this._mainTexture=e,this.onAfterCreated())}onAfterCreated(){this.__didAwake&&(super.onAfterCreated(),this.setTexture(this.mainTexture))}}lx([x(Nt)],cx.prototype,"mainTexture",1);var fne=Object.defineProperty,mne=Object.getOwnPropertyDescriptor,no=(i,e,t,s)=>{for(var r=s>1?void 0:s?mne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&fne(e,t,r),r};const pd=te("debugbutton");class fd{constructor(){h(this,"colorMultiplier"),h(this,"disabledColor"),h(this,"fadeDuration"),h(this,"highlightedColor"),h(this,"normalColor"),h(this,"pressedColor"),h(this,"selectedColor")}}no([x()],fd.prototype,"colorMultiplier",2),no([x(Si)],fd.prototype,"disabledColor",2),no([x()],fd.prototype,"fadeDuration",2),no([x(Si)],fd.prototype,"highlightedColor",2),no([x(Si)],fd.prototype,"normalColor",2),no([x(Si)],fd.prototype,"pressedColor",2),no([x(Si)],fd.prototype,"selectedColor",2);class yc extends Pe{constructor(){super(...arguments),h(this,"onClick"),h(this,"_isHovered",0),h(this,"colors"),h(this,"transition"),h(this,"animationTriggers"),h(this,"animator"),h(this,"_interactable",!0),h(this,"_requestedAnimatorTrigger"),h(this,"_isInit",!1),h(this,"_image")}onPointerEnter(e){var t,s;this._isHovered+=1,pd&&console.warn("Button Enter",this._isHovered,(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.highlightedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("hovered")),this.context.input.setCursorPointer())}onPointerExit(){var e,t;this._isHovered-=1,pd&&console.log("Button Exit",this._isHovered,(e=this.animationTriggers)==null?void 0:e.highlightedTrigger,this.animator),this.interactable&&(this._isHovered>0||(this._isHovered=0,this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((t=this._image)==null||t.setState("normal")),this.context.input.setCursorNormal()))}onPointerDown(e){var t,s;pd&&console.log("Button Down",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.pressedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("pressed")))}onPointerUp(e){var t,s;pd&&console.warn("Button Up",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator,this._isHovered),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this._isHovered?this.animationTriggers.highlightedTrigger:this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState(this._isHovered?"hovered":"normal")))}onPointerClick(e){if(this.interactable&&!(e.button!==0&&e.event.pointerType===vE.Mouse)&&(pd&&(console.warn("Button Click",this.onClick),ms("CLICKED button "+this.name+" at "+this.context.time.frameCount)),this.onClick&&this.onClick.listenerCount>0&&(this.onClick.invoke(),e.use(),pd))){const t=this.gameObject.worldPosition;t.add(this.gameObject.worldUp.multiplyScalar(1+Math.random()*.5)),Pt.DrawLabel(t,"CLICK:"+Date.now(),.1,1+Math.random()*.5)}}set interactable(e){this._interactable=e,this._image&&(this._image.setInteractable(e),e?this._image.setState("normal"):this._image.setState("disabled"))}get interactable(){return this._interactable}set_interactable(e){this.interactable=e}awake(){super.awake(),pd&&console.log(this),this._isInit=!1,this.init()}start(){var e;(e=this._image)==null||e.setInteractable(this.interactable),this.gameObject.getComponentInParent(Cv)||this.gameObject.addComponent(N_)}onEnable(){super.onEnable()}onDestroy(){this._isHovered&&this.context.input.setCursorNormal()}*setAnimatorTriggerAtEndOfFrame(e){var t;this._requestedAnimatorTrigger=e,yield,yield,this._requestedAnimatorTrigger==e&&((t=this.animator)==null||t.SetTrigger(e))}init(){this._isInit||(this._isInit=!0,this._image=oe.getComponent(this.gameObject,Pf),this._image&&(this.stateSetup(this._image),this.interactable?this._image.setState("normal"):this._image.setState("disabled")))}stateSetup(e){var t,s,r,n,o;e.setInteractable(this.interactable);const a=this.getFinalColor(e.color,(t=this.colors)==null?void 0:t.normalColor),l={state:"normal",attributes:{backgroundColor:a,backgroundOpacity:a.alpha}};e.setupState(l);const c=this.getFinalColor(e.color,(s=this.colors)==null?void 0:s.highlightedColor),u={state:"hovered",attributes:{backgroundColor:c,backgroundOpacity:c.alpha}};e.setupState(u);const d=this.getFinalColor(e.color,(r=this.colors)==null?void 0:r.pressedColor),p={state:"pressed",attributes:{backgroundColor:d,backgroundOpacity:d.alpha}};e.setupState(p);const f=this.getFinalColor(e.color,(n=this.colors)==null?void 0:n.selectedColor),m={state:"selected",attributes:{backgroundColor:f,backgroundOpacity:f.alpha}};e.setupState(m);const A=this.getFinalColor(e.color,(o=this.colors)==null?void 0:o.disabledColor),y={state:"disabled",attributes:{backgroundColor:A,backgroundOpacity:A.alpha}};e.setupState(y)}getFinalColor(e,t){return t?e.clone().multiply(t).convertLinearToSRGB():e.clone().convertLinearToSRGB()}}no([x(tr)],yc.prototype,"onClick",2),no([x()],yc.prototype,"colors",2),no([x()],yc.prototype,"transition",2),no([x()],yc.prototype,"animationTriggers",2),no([x(Er)],yc.prototype,"animator",2),no([x()],yc.prototype,"interactable",1);var gne=Object.defineProperty,vne=Object.getOwnPropertyDescriptor,Os=(i,e,t,s)=>{for(var r=s>1?void 0:s?vne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&gne(e,t,r),r};const gj=te("debuguilayout");class Bh{constructor(){h(this,"left",0),h(this,"right",0),h(this,"top",0),h(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Os([x()],Bh.prototype,"left",2),Os([x()],Bh.prototype,"right",2),Os([x()],Bh.prototype,"top",2),Os([x()],Bh.prototype,"bottom",2);class oo extends Pe{constructor(){super(...arguments),h(this,"_rectTransform",null),h(this,"_needsUpdate",!1),h(this,"childAlignment",0),h(this,"reverseArrangement",!1),h(this,"spacing",0),h(this,"padding"),h(this,"minWidth",0),h(this,"minHeight",0),h(this,"flexibleHeight",0),h(this,"flexibleWidth",0),h(this,"preferredHeight",0),h(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(e){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(gj&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){gj&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(_n);const e=this.gameObject.getComponentInParent(Ir);e&&e.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const e=this.gameObject.getComponentInParent(Ir);e&&e.unregisterLayoutGroup(this)}set m_Spacing(e){e!==this.spacing&&(this._needsUpdate=!0,this.spacing=e)}get m_Spacing(){return this.spacing}}Os([x()],oo.prototype,"childAlignment",2),Os([x()],oo.prototype,"reverseArrangement",2),Os([x()],oo.prototype,"spacing",2),Os([x(Bh)],oo.prototype,"padding",2),Os([x()],oo.prototype,"minWidth",2),Os([x()],oo.prototype,"minHeight",2),Os([x()],oo.prototype,"flexibleHeight",2),Os([x()],oo.prototype,"flexibleWidth",2),Os([x()],oo.prototype,"preferredHeight",2),Os([x()],oo.prototype,"preferredWidth",2);class Dh extends oo{constructor(){super(...arguments),h(this,"childControlHeight",!0),h(this,"childControlWidth",!0),h(this,"childForceExpandHeight",!1),h(this,"childForceExpandWidth",!1),h(this,"childScaleHeight",!1),h(this,"childScaleWidth",!1)}onCalculateLayout(e){var t;const s=this.primaryAxis,r=e.width;let n=r;const o=e.height;let a=o;n-=this.padding.horizontal,a-=this.padding.vertical,s==="x"?this.padding.horizontal:this.padding.vertical;const l=s==="x",c=l?"y":"x",u=l?this.childControlWidth:this.childControlHeight,d=l?this.childControlHeight:this.childControlWidth,p=l?this.childForceExpandWidth:this.childForceExpandHeight,f=l?this.childForceExpandHeight:this.childForceExpandWidth,m=l?a:n,A=l?r:o,y=.5*(l?this.childAlignment%3:Math.floor(this.childAlignment/3));let g=0;l?g+=this.padding.left:g+=this.padding.top;let v=0,b=0;for(let R=0;R<this.gameObject.children.length;R++){const I=this.gameObject.children[R],E=oe.getComponent(I,_n);E!=null&&E.activeAndEnabled&&(b+=1,l?v+=E.width:v+=E.height)}let _=0;const S=this.spacing*(b-1);if(p||u){let R=0;l?R=n-=S:R=a-=S,b>0&&(_=R/b)}let M=0;M+=this.padding.left,M-=this.padding.right,y!==0&&(g=A-v,g*=y,g-=S*y,l?(g-=this.padding.right*y,g+=this.padding.left*(1-y),g<this.padding.left&&(g=this.padding.left)):(g-=this.padding.bottom*y,g+=this.padding.top*(1-y),g<this.padding.top&&(g=this.padding.top)));let C=1;for(let R=0;R<this.gameObject.children.length;R++){const I=this.gameObject.children[R],E=oe.getComponent(I,_n);if(E!=null&&E.activeAndEnabled){(t=E.pivot)==null||t.set(.5,.5),E.anchorMin.set(0,1),E.anchorMax.set(0,1);const z=r*.5+M*.5;E.anchoredPosition.x!==z&&(E.anchoredPosition.x=z);const F=o*-.5;E.anchoredPosition.y!==F&&(E.anchoredPosition.y=F),f&&d&&E.sizeDelta[c]!==m&&(E.sizeDelta[c]=m),p&&u&&E.sizeDelta[s]!==_&&(E.sizeDelta[s]=_);const q=l?E.width:E.height,N=q*.5;if(g+=N,p){const L=_*C-_*.5;L>g&&(g=L-_*.5+q+this.padding.left,g-=N)}let H=g;s==="y"&&(H=-H),E.anchoredPosition[s]!==H&&(E.anchoredPosition[s]=H),g+=N,g+=this.spacing,C+=1}}}}Os([x()],Dh.prototype,"childControlHeight",2),Os([x()],Dh.prototype,"childControlWidth",2),Os([x()],Dh.prototype,"childForceExpandHeight",2),Os([x()],Dh.prototype,"childForceExpandWidth",2),Os([x()],Dh.prototype,"childScaleHeight",2),Os([x()],Dh.prototype,"childScaleWidth",2);class NI extends Dh{get primaryAxis(){return"y"}}class zI extends Dh{get primaryAxis(){return"x"}}class jI extends oo{onCalculateLayout(){}}var Ane=Object.defineProperty,yne=Object.getOwnPropertyDescriptor,ol=(i,e,t,s)=>{for(var r=s>1?void 0:s?yne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Ane(e,t,r),r},vj=(i=>(i[i.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",i[i.ScreenSpaceCamera=1]="ScreenSpaceCamera",i[i.WorldSpace=2]="WorldSpace",i[i.Undefined=-1]="Undefined",i))(vj||{});const GI=te("debuguilayout"),Aj=class extends Sv{constructor(){super(...arguments),h(this,"_renderOnTop"),h(this,"_depthWrite",!1),h(this,"_doubleSided",!0),h(this,"_castShadows",!1),h(this,"_receiveShadows",!1),h(this,"_renderMode",-1),h(this,"_rootCanvas"),h(this,"_scaleFactor",1),h(this,"worldCamera"),h(this,"planeDistance",-1),h(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this)),h(this,"previousParent",null),h(this,"_lastMatrixWorld",null),h(this,"_rectTransforms",[]),h(this,"_layoutGroups",new Map),h(this,"_receivers",[]),h(this,"onBeforeRenderRoutine",()=>{var i,e,t,s;if(this.previousParent=this.gameObject.parent,((i=this.context.xr)!=null&&i.isVR||(e=this.context.xr)!=null&&e.isPassThrough)&&this.screenspace){this.gameObject.visible=!1,this.gameObject.removeFromParent();return}this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(t=this.shadowComponent)==null||t.updateMatrixWorld(!0),(s=this.shadowComponent)==null||s.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),jo.ensureUpdateMeshUI(CN,this.context))}),h(this,"onAfterRenderRoutine",()=>{var i,e,t,s,r;if(((i=this.context.xr)!=null&&i.isVR||(e=this.context.xr)!=null&&e.isPassThrough)&&this.screenspace){(t=this.previousParent)==null||t.add(this.gameObject);return}if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const a=this.context.mainCamera;a?.add(this.gameObject)}else this.previousParent.add(this.gameObject);const n=this.context.renderer.autoClear,o=this.context.renderer.autoClearColor;this.context.renderer.autoClear=!1,this.context.renderer.autoClearColor=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(s=this.shadowComponent)==null||s.updateMatrixWorld(!0),this.invokeBeforeRenderEvents(),jo.ensureUpdateMeshUI(CN,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=n,this.context.renderer.autoClearColor=o,this.previousParent.add(this.gameObject)}(r=this._lastMatrixWorld)==null||r.copy(this.gameObject.matrixWorld)}),h(this,"_updateRenderSettingsRoutine"),h(this,"_activeRenderMode",-1),h(this,"_lastWidth",-1),h(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(i){i!==this._renderOnTop&&(this._renderOnTop=i,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(i){this._depthWrite!==i&&(this._depthWrite=i,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(i){this._doubleSided!==i&&(this._doubleSided=i,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(i){this._castShadows!==i&&(this._castShadows=i,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(i){this._receiveShadows!==i&&(this._receiveShadows=i,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(i){this._renderMode!==i&&(this._renderMode=i,this.onRenderSettingsChanged())}set rootCanvas(i){this._rootCanvas instanceof Aj||(this._rootCanvas=i)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(i){this._scaleFactor=i}awake(){var i;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,GI&&console.log("Canvas.Awake()",((i=this.previousParent)==null?void 0:i.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new Te,this.onUpdateRenderMode(),document.addEventListener("resize",this._boundRenderSettingsChanged),this.context.pre_render_callbacks.push(this.onBeforeRenderRoutine),this.context.post_render_callbacks.push(this.onAfterRenderRoutine)}onDisable(){super.onDisable(),document.removeEventListener("resize",this._boundRenderSettingsChanged);const i=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);i!==-1&&this.context.pre_render_callbacks.splice(i,1);const e=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);e!==-1&&this.context.post_render_callbacks.splice(e,1)}registerTransform(i){this._rectTransforms.push(i)}unregisterTransform(i){const e=this._rectTransforms.indexOf(i);e!==-1&&this._rectTransforms.splice(e,1)}registerLayoutGroup(i){const e=i.gameObject;this._layoutGroups.set(e,i)}unregisterLayoutGroup(i){const e=i.gameObject;this._layoutGroups.delete(e)}registerEventReceiver(i){this._receivers.push(i)}unregisterEventReceiver(i){const e=this._receivers.indexOf(i);e!==-1&&this._receivers.splice(e,1)}async onEnterXR(i){this.screenspace?(i.xr.isVR||i.xr.isPassThrough)&&(this.gameObject.visible=!1):(this.gameObject.visible=!1,await Pk(1).then(()=>{this.gameObject.visible=!0}))}onLeaveXR(i){this.screenspace&&(i.xr.isVR||i.xr.isPassThrough)&&(this.gameObject.visible=!0)}invokeBeforeRenderEvents(){var i;for(const e of this._receivers)(i=e.onBeforeCanvasRender)==null||i.call(e,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new Te);const i=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);GI&&i&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const e=!1;for(const t of this._rectTransforms){i&&t.markDirty();let s=this._layoutGroups.get(t.gameObject);t.isDirty&&!s&&(s=t.gameObject.getComponentInParent(oo)),(t.isDirty||s!=null&&s.isDirty)&&(GI&&!e&&console.log("CANVAS UPDATE ### "+t.name+" ##################################### "+this.context.time.frame),s?.updateLayout(),t.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),ks.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),j_(this.shadowComponent,this);for(const i of oe.getComponentsInChildren(this.gameObject,Ra))j_(i.shadowComponent,this)}}onUpdateRenderMode(i=!1){if(!i&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let e=this.context.mainCameraComponent,t=10;switch(e&&e.nearClipPlane>0&&e.farClipPlane>0&&(t=st.lerp(e.nearClipPlane,e.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(e=this.worldCamera),this.planeDistance>0&&(t=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!e)return;const s=t+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-s,this.gameObject.quaternion.identity();const r=this.gameObject.getComponent(_n);let n=!1;r.sizeDelta.x!==this.context.domWidth&&(n=!0),r.sizeDelta.y!==this.context.domHeight&&(n=!0);const o=e.fieldOfView*Math.PI/180,a=2*Math.tan(o/2)*Math.abs(s);this.gameObject.scale.x=a/this.context.domHeight,this.gameObject.scale.y=a/this.context.domHeight,this.gameObject.scale.z=.01,n&&(r.sizeDelta.x=this.context.domWidth,r.sizeDelta.y=this.context.domHeight,r?.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let Ir=Aj;ol([x()],Ir.prototype,"renderOnTop",1),ol([x()],Ir.prototype,"depthWrite",1),ol([x()],Ir.prototype,"doubleSided",1),ol([x()],Ir.prototype,"castShadows",1),ol([x()],Ir.prototype,"receiveShadows",1),ol([x()],Ir.prototype,"renderMode",1),ol([x(Ir)],Ir.prototype,"rootCanvas",1),ol([x()],Ir.prototype,"scaleFactor",1),ol([x(ji)],Ir.prototype,"worldCamera",2),ol([x()],Ir.prototype,"planeDistance",2);var bne=Object.defineProperty,_ne=Object.getOwnPropertyDescriptor,QI=(i,e,t,s)=>{for(var r=s>1?void 0:s?_ne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&bne(e,t,r),r};class kh extends Pe{constructor(){super(...arguments),h(this,"_alpha",1),h(this,"interactable",!0),h(this,"blocksRaycasts",!0),h(this,"_isDirty",!1),h(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(e){e!==this._alpha&&(this._alpha=e,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),ks.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){for(const e of oe.getComponentsInChildren(this.gameObject,Ra,this._buffer)){const t=e;t.setAlphaFactor&&t.setAlphaFactor(this._alpha)}}}QI([x()],kh.prototype,"alpha",1),QI([x()],kh.prototype,"interactable",2),QI([x()],kh.prototype,"blocksRaycasts",2);var xne=Object.defineProperty,wne=Object.getOwnPropertyDescriptor,rs=(i,e,t,s)=>{for(var r=s>1?void 0:s?wne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&xne(e,t,r),r};function Kv(i){i&&(i.getComponentInParent(Cv)||(wt()&&console.warn("Create Raycaster on "+i.name+" because no raycaster was found in the hierarchy"),i.addNewComponent(to)))}class md extends Pe{constructor(){super(...arguments),h(this,"object"),h(this,"target"),h(this,"duration",1),h(this,"relativeMotion",!1),h(this,"coroutine",null),h(this,"targetPos",new w),h(this,"targetRot",new Ie),h(this,"targetScale",new w)}start(){Kv(this.gameObject)}onPointerClick(e){e.use(),this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}*moveToTarget(){if(!this.target||!this.object)return;const e=Rt(this.object).clone(),t=Rt(this.target).clone(),s=Ii(this.object).clone(),r=Ii(this.target).clone(),n=ss(this.object).clone(),o=ss(this.target).clone(),a=e.distanceTo(t),l=s.angleTo(r),c=n.distanceTo(o);if(a<.01&&l<.01&&c<.01){Kr(this.object,t),ko(this.object,r),Yg(this.object,o),this.coroutine=null;return}let u=0,d=0;for(;u<1;)u+=this.context.time.deltaTime/this.duration,u>1&&(u=1),d=u<.5?4*u*u*u:1-Math.pow(-2*u+2,3)/2,this.targetPos.lerpVectors(e,t,d),this.targetRot.slerpQuaternions(s,r,d),this.targetScale.lerpVectors(n,o,d),Kr(this.object,this.targetPos),ko(this.object,this.targetRot),Yg(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const e=this.object.position.clone(),t=this.object.quaternion.clone(),s=this.object.scale.clone(),r=this.target.position.clone(),n=this.target.quaternion.clone(),o=this.target.scale.clone();r.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(r),this.targetRot.copy(this.object.quaternion).multiply(n),this.targetScale.copy(this.object.scale).multiply(o);let a=0,l=0;for(;a<1;)a+=this.context.time.deltaTime/this.duration,a>1&&(a=1),l=a<.5?4*a*a*a:1-Math.pow(-2*a+2,3)/2,this.object.position.lerpVectors(e,this.targetPos,l),this.object.quaternion.slerpQuaternions(t,this.targetRot,l),this.object.scale.lerpVectors(s,this.targetScale,l),yield;this.coroutine=null}beforeCreateDocument(e){var t;if(this.target&&this.object&&this.gameObject){const s=new xr("Move to "+((t=this.target)==null?void 0:t.name),wr.tapTrigger(this.gameObject),ui.transformAction(this.object,this.target,this.duration,this.relativeMotion?eI.Relative:eI.Absolute));e.addBehavior(s)}}}rs([x(ye)],md.prototype,"object",2),rs([x(ye)],md.prototype,"target",2),rs([x()],md.prototype,"duration",2),rs([x()],md.prototype,"relativeMotion",2);var hx;const bc=(hx=class extends Pe{constructor(){super(...arguments),h(this,"materialToSwitch"),h(this,"variantMaterial"),h(this,"fadeDuration",0),h(this,"_objectsWithThisMaterial",[]),h(this,"selfModel"),h(this,"targetModels")}awake(){if(this.variantMaterial&&this.materialToSwitch){const i=oe.findObjectsOfType(gs);for(const e of i)for(let t=0;t<e.sharedMaterials.length;t++){const s=e.sharedMaterials[t];if(s===this.materialToSwitch){if(e.gameObject instanceof ve)this._objectsWithThisMaterial.push(e.gameObject);else if(e.gameObject instanceof cn)for(const r of e.gameObject.children)r instanceof ve&&r.material===s&&this._objectsWithThisMaterial.push(r);break}}}}start(){Kv(this.gameObject)}onPointerClick(i){if(i.use(),!!this.variantMaterial)for(let e=0;e<this._objectsWithThisMaterial.length;e++){const t=this._objectsWithThisMaterial[e];t.material=this.variantMaterial}}async beforeCreateDocument(i,e){this.targetModels=[],bc._materialTriggersPerId={},bc.variantSwitchIndex=0,this.materialToSwitch&&await ba.assignTextureLOD(this.context,this.sourceId,this.materialToSwitch,0),this.variantMaterial&&await ba.assignTextureLOD(this.context,this.sourceId,this.variantMaterial,0)}createBehaviours(i,e,t){this._objectsWithThisMaterial.find(s=>s.uuid===e.uuid)&&this.targetModels.push(e),this.gameObject.uuid===e.uuid&&(this.selfModel=e,this.materialToSwitch&&(bc._materialTriggersPerId[this.materialToSwitch.uuid]||(bc._materialTriggersPerId[this.materialToSwitch.uuid]=[]),bc._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(i,e){if(!this.materialToSwitch)return;const t=bc._materialTriggersPerId[this.materialToSwitch.uuid];if(t){const s={};for(const r of t){const n=r.createVariants();n&&n.length>0&&(s[r.selfModel.uuid]=n)}for(const r of t){const n=[];for(const o in s)o!==r.selfModel.uuid&&n.push(...s[o]);r.createAndAttachBehaviors(i,s[r.selfModel.uuid],n)}}delete bc._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(i,e,t){const s=[],r=[],n=Math.max(0,this.fadeDuration);r.push(ui.fadeAction([...this.targetModels,...t],n,!1)),s.push(ui.fadeAction(e,n,!1)),r.push(ui.fadeAction(e,n,!0)),i.addBehavior(new xr("Select_"+this.selfModel.name,wr.tapTrigger(this.selfModel),ui.parallel(...r))),i.addBehavior(new xr("StartHidden_"+this.selfModel.name,wr.sceneStartTrigger(),ui.parallel(...s)))}createVariants(){if(!this.variantMaterial)return null;const i=[];for(const e of this.targetModels){const t=e.clone();t.name+=" variant_"+this.variantMaterial.name+"_"+bc.variantSwitchIndex++,t.name=t.name.replace(/\s/g,"_"),t.material=this.variantMaterial,t.geometry=e.geometry,t.matrix=e.matrix,(!e.parent||!e.parent.isEmpty())&&Fo.createEmptyParent(e),e.parent&&e.parent.add(t),i.push(t)}return i}},h(hx,"_materialTriggersPerId",{}),h(hx,"variantSwitchIndex",0),hx);let Bf=bc;rs([x(Lt)],Bf.prototype,"materialToSwitch",2),rs([x(Lt)],Bf.prototype,"variantMaterial",2),rs([x()],Bf.prototype,"fadeDuration",2);var Df;const ns=(Df=class extends Pe{constructor(){super(...arguments),h(this,"target"),h(this,"toggleOnClick",!1),h(this,"targetState",!0),h(this,"hideSelf",!0),h(this,"selfModel"),h(this,"selfModelClone"),h(this,"targetModel"),h(this,"toggleModel"),h(this,"stateBeforeCreatingDocument",!1),h(this,"targetStateBeforeCreatingDocument",!1)}start(){Kv(this.gameObject)}onPointerClick(i){i.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(i,e,t){e.uuid===this.gameObject.uuid&&(this.selfModel=e,this.selfModelClone=e.clone())}beforeCreateDocument(){this.target&&(this.gameObject[ns.wasVisible]===void 0&&(this.gameObject[ns.wasVisible]=this.gameObject.activeSelf),this.target[ns.wasVisible]===void 0&&(this.target[ns.wasVisible]=this.target.activeSelf),this.stateBeforeCreatingDocument=this.gameObject[ns.wasVisible],this.targetStateBeforeCreatingDocument=this.target[ns.wasVisible],this.gameObject.visible=!0,this.target.visible=!0)}afterCreateDocument(i,e){if(!this.target)return;this.targetModel=e.document.findById(this.target.uuid);const t=this.selfModel;if(this.selfModel&&this.targetModel){let s=this.selfModel,r=this.targetState;if(this.toggleOnClick)if(r=!this.targetStateBeforeCreatingDocument,!this.selfModelClone.geometry)(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&Cz.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.deepClone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel);else{if(!this.gameObject[ns.toggleClone]){const a=this.selfModelClone.clone();a.matrix.identity(),a.name+="_toggle"+ns.clonedToggleIndex++,t.add(a),this.gameObject[ns.toggleClone]=a,console.warn("USDZExport: Toggle "+this.gameObject.name+" doesn't have geometry. It will be deep cloned and nested behaviours will likely not work.")}const o=this.gameObject[ns.toggleClone];if(!this.gameObject[ns.reverseToggleClone]){const a=this.selfModelClone.clone();a.matrix.identity(),a.name+="_toggleReverse"+ns.clonedToggleIndex++,t.add(a),this.gameObject[ns.reverseToggleClone]=a}this.toggleModel=this.gameObject[ns.reverseToggleClone],(!this.toggleModel.geometry||!o.geometry)&&console.error("triggers without childs and without geometry won't work!",this,t.geometry),s=o,t.geometry=null,t.material=null}if(this.toggleModel){if(this.toggleOnClick){const o=[];o.push(ui.fadeAction(s,0,!1)),o.push(ui.fadeAction(this.toggleModel,0,!0)),o.push(ui.fadeAction(this.targetModel,0,r)),i.addBehavior(new xr("Toggle_"+s.name+"_toggleTo"+(r?"On":"Off"),wr.tapTrigger(s),ui.parallel(...o)));const a=[];a.push(ui.fadeAction(this.toggleModel,0,!1)),a.push(ui.fadeAction(s,0,!0)),a.push(ui.fadeAction(this.targetModel,0,!r)),i.addBehavior(new xr("Toggle_"+s.name+"_toggleTo"+(r?"Off":"On"),wr.tapTrigger(this.toggleModel),ui.parallel(...a)))}}else{const o=[];this.hideSelf&&o.push(ui.fadeAction(s,0,!1)),o.push(ui.fadeAction(this.targetModel,0,r)),i.addBehavior(new xr("Toggle_"+s.name+"_toggleTo"+(r?"On":"Off"),wr.tapTrigger(s),ui.parallel(...o)))}const n=new Array;this.targetStateBeforeCreatingDocument||n.push(this.targetModel),this.stateBeforeCreatingDocument||n.push(t),this.toggleModel&&n.push(this.toggleModel),i.addBehavior(new xr("HideOnStart_"+this.gameObject.name,wr.sceneStartTrigger(),ui.fadeAction(n,0,!1)))}}afterSerialize(i,e){this.gameObject[ns.wasVisible]!==void 0&&(this.gameObject.visible=this.gameObject[ns.wasVisible],delete this.gameObject[ns.wasVisible]),this.target&&this.target[ns.wasVisible]!==void 0&&(this.target.visible=this.target[ns.wasVisible],delete this.target[ns.wasVisible]),delete this.gameObject[ns.toggleClone],delete this.gameObject[ns.reverseToggleClone]}},h(Df,"clonedToggleIndex",0),h(Df,"wasVisible",Symbol("usdz_SetActiveOnClick_wasVisible")),h(Df,"toggleClone",Symbol("clone for toggling")),h(Df,"reverseToggleClone",Symbol("clone for reverse toggling")),Df);let gd=ns;rs([x(ye)],gd.prototype,"target",2),rs([x()],gd.prototype,"toggleOnClick",2),rs([x()],gd.prototype,"targetState",2),rs([x()],gd.prototype,"hideSelf",2);class VI extends Pe{start(){this.gameObject.visible=!1}createBehaviours(e,t,s){t.uuid===this.gameObject.uuid&&e.addBehavior(new xr("HideOnStart_"+this.gameObject.name,wr.sceneStartTrigger(),ui.fadeAction(t,0,!1)))}beforeCreateDocument(){this.gameObject.visible=!0}afterCreateDocument(){this.gameObject.visible=!1}}class kf extends Pe{constructor(){super(...arguments),h(this,"target"),h(this,"duration",.5),h(this,"motionType",$T.bounce)}beforeCreateDocument(){}createBehaviours(e,t,s){if(this.target&&t.uuid===this.gameObject.uuid){const r=new xr("emphasize "+this.name,wr.tapTrigger(this.gameObject),ui.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));e.addBehavior(r)}}afterCreateDocument(e,t){}}rs([x()],kf.prototype,"target",2),rs([x()],kf.prototype,"duration",2),rs([x()],kf.prototype,"motionType",2);class Of extends Pe{constructor(){super(...arguments),h(this,"target"),h(this,"clip",""),h(this,"toggleOnClick",!1)}start(){Kv(this.gameObject)}ensureAudioSource(){if(!this.target){const e=this.gameObject.addNewComponent(vs);e&&(this.target=e,e.spatialBlend=1,e.volume=1,e.loop=!1)}}onPointerClick(e){var t;e.use(),!(!((t=this.target)!=null&&t.clip)&&!this.clip)&&(this.ensureAudioSource(),this.target&&(this.target.isPlaying&&this.toggleOnClick?this.target.stop():(!this.toggleOnClick&&this.target.isPlaying&&this.target.stop(),this.clip?this.target.play(this.clip):this.target.play())))}createBehaviours(e,t,s){if(!(!this.target&&!this.clip)&&t.uuid===this.gameObject.uuid){const r=this.clip?this.clip:this.target?this.target.clip:void 0;if(!r||typeof r!="string")return;const n=this.target?this.target.gameObject:this.gameObject,o=r.split("/").pop(),a=this.target?this.target.volume:1,l=this.target&&this.target.spatialBlend==0?sI.NonSpatial:sI.Spatial;{let c=ui.playAudioAction(n,"audio/"+o,iI.Play,a,l);this.toggleOnClick&&(c.multiplePerformOperation=Nz.Stop),this.target&&this.target.loop&&(c=ui.sequence(c).makeLooping());const u=new xr("playAudio "+this.name,wr.tapTrigger(this.gameObject),c);e.addBehavior(u)}if(this.target&&this.target.playOnAwake&&this.target.enabled){let c=ui.playAudioAction(n,"audio/"+o,iI.Play,a,l);this.target.loop&&(c=ui.sequence(c).makeLooping());const u=new xr("playAudioOnStart "+this.name,wr.sceneStartTrigger(),c);e.addBehavior(u)}}}async afterSerialize(e,t){if(!this.target&&!this.clip)return;const s=this.clip?this.clip:this.target?this.target.clip:void 0;if(!s||typeof s!="string")return;const r=s.split("/").pop(),n=await(await(await fetch(s)).blob()).arrayBuffer(),o=new Uint8Array(n);t.files["audio/"+r]=o}}rs([x(vs)],Of.prototype,"target",2),rs([x(URL)],Of.prototype,"clip",2),rs([x()],Of.prototype,"toggleOnClick",2);var ux;const Oh=(ux=class extends Pe{constructor(){super(...arguments),h(this,"animator"),h(this,"stateName"),h(this,"trigger","tap"),h(this,"selfModel"),h(this,"stateAnimationModel"),h(this,"animationSequence",new Array),h(this,"animationLoopAfterSequence",new Array)}get target(){var i;return(i=this.animator)==null?void 0:i.gameObject}start(){Kv(this.gameObject)}onPointerClick(i){var e;i.use(),this.target&&this.stateName&&((e=this.animator)==null||e.play(this.stateName,0,0,.1))}createBehaviours(i,e,t){e.uuid===this.gameObject.uuid&&(this.selfModel=e)}afterSerialize(){if(Oh.rootsWithExclusivePlayback.size>1){const i='Multiple root objects targeted by more than one animation. To work around QuickLook bug FB13410767, animations will be set as "exclusive" and activating them will stop other animations being marked as exclusive.';wt()&&is(i),console.warn(i,...Oh.rootsWithExclusivePlayback)}Oh.animationActions=[],Oh.rootsWithExclusivePlayback=new Set}afterCreateDocument(i,e){if(!this.animationSequence||!this.stateAnimationModel||!this.target)return;const t=e.document,s=e.extensions.find(o=>o instanceof Ov);if(!s)return;const r=s.getClipCount(this.target)>1;r&&(wt()&&console.warn("Setting exclusive playback for "+this.target.name+"@"+this.stateName+" because it has "+s.getClipCount(this.target)+" animations. This works around QuickLook bug FB13410767."),Oh.rootsWithExclusivePlayback.add(this.target));const n=(o,a)=>{let l=Oh.animationActions.find(c=>c.affectedObjects==o&&c.start==a.start&&c.duration==a.duration);return l||(l=ui.startAnimationAction(o,a.start,a.duration),Oh.animationActions.push(l)),l};t.traverse(o=>{var a,l;if(o.uuid===((a=this.target)==null?void 0:a.uuid)){const c=ui.sequence();if(this.animationSequence!==void 0)for(const d of this.animationSequence)c.addAction(n(o,d));if(this.animationLoopAfterSequence!==void 0){const d=c.actions.length==0?c:ui.sequence();for(const p of this.animationLoopAfterSequence)d.addAction(n(o,p));d.makeLooping(),c!==d&&c.addAction(d)}const u=new xr("tap "+this.name+" for "+this.stateName+" on "+((l=this.target)==null?void 0:l.name),this.trigger=="tap"?wr.tapTrigger(this.selfModel):wr.sceneStartTrigger(),c);r&&u.makeExclusive(!0),i.addBehavior(u)}})}createAnimation(i,e,t){var s,r,n,o;if(!this.target||!this.animator)return;const a=(s=this.animator)==null?void 0:s.runtimeAnimatorController;let l=a?.findState(this.stateName),c=[],u=[];if(a&&l){const d=new Array;d.push(l);let p=!1;for(;d.length<100;){if(!l||l===null||!l.transitions||l.transitions.length===0){(r=l.motion)!=null&&r.isLooping&&(p=!0);break}const f=l.transitions.find(A=>A.conditions.length===0),m=f?a.getState(f.destinationState,0):null;if(m&&d.includes(m)){l=m,p=!0;break}else if(f){if(l=m,!l)break;d.push(l)}else{p=((n=l.motion)==null?void 0:n.isLooping)??!1;break}}if(p&&l){const f=d.indexOf(l);c=d.slice(0,f),u=d.slice(f),console.log("found loop from "+this.stateName,"states until loop",c,"states looping",u)}else c=d,u=[],console.log("found no loop from "+this.stateName,"states",c)}if(c=c.filter(d=>{var p,f,m;return((p=d.motion)==null?void 0:p.clip)&&((m=(f=d.motion)==null?void 0:f.clip.tracks)==null?void 0:m.length)>0}),u=u.filter(d=>{var p,f,m;return((p=d.motion)==null?void 0:p.clip)&&((m=(f=d.motion)==null?void 0:f.clip.tracks)==null?void 0:m.length)>0}),c.length===0&&u.length===0){console.warn("No clips found for state "+this.stateName+" on "+((o=this.animator)==null?void 0:o.name)+", can't export animation data");return}if(this.stateAnimationModel=e,c.length>0){this.animationSequence=new Array;for(const d of c)this.animationSequence.push(i.registerAnimation(this.target,d.motion.clip))}if(u.length>0){this.animationLoopAfterSequence=new Array;for(const d of u)this.animationLoopAfterSequence.push(i.registerAnimation(this.target,d.motion.clip))}}},h(ux,"animationActions",[]),h(ux,"rootsWithExclusivePlayback",new Set),ux);let Lf=Oh;rs([x(Er)],Lf.prototype,"animator",2),rs([x()],Lf.prototype,"stateName",2);class Uf extends Pe{constructor(){super(...arguments),h(this,"target")}getType(){}getDuration(){}}rs([x(ye)],Uf.prototype,"target",2);class Zv extends Pe{constructor(){super(...arguments),h(this,"target")}}rs([x(Uf)],Zv.prototype,"target",2);class $v extends Uf{constructor(){super(...arguments),h(this,"type",1),h(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}rs([x()],$v.prototype,"type",2),rs([x()],$v.prototype,"duration",2);class HI extends Zv{}var Sne=Object.defineProperty,Cne=Object.getOwnPropertyDescriptor,_c=(i,e,t,s)=>{for(var r=s>1?void 0:s?Cne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Sne(e,t,r),r};const yj=te("debugcharactercontroller");class vd extends Pe{constructor(){super(...arguments),h(this,"center",new w(0,0,0)),h(this,"radius",.5),h(this,"height",2),h(this,"_rigidbody",null),h(this,"_activeGroundCollisions"),h(this,"_contactVelocity",new w)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(Ni),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(Ni)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const e=this.rigidbody;let t=this.gameObject.getComponent(Ph);t||(t=this.gameObject.addNewComponent(Ph)),t.center.copy(this.center),t.radius=this.radius,t.height=this.height;const s=new w(0,0,1),r=new w(1,0,0),n=new w(0,1,0),o=this.gameObject.getWorldDirection(new w);o.y=0;const a=r.dot(o)<0?-1:1,l=s.angleTo(o)*a;this.gameObject.setRotationFromAxisAngle(n,l),e.lockRotationX=!0,e.lockRotationY=!0,e.lockRotationZ=!0}move(e){this.gameObject.position.add(e)}onCollisionEnter(e){(e.contacts.length==0||e.contacts.some(t=>t.normal.y>.2))&&(this._activeGroundCollisions.add(e),yj&&console.log(`Collision(${this._activeGroundCollisions.size}): ${e.contacts.map(t=>t.normal.y.toFixed(2)).join(", ")} - ${this.isGrounded}`))}onCollisionExit(e){this._activeGroundCollisions.delete(e),yj&&console.log(`Collision(${this._activeGroundCollisions.size}) - ${this.isGrounded}`)}get isGrounded(){return this._activeGroundCollisions.size>0}get contactVelocity(){var e;this._contactVelocity.set(0,0,0);for(const t of this._activeGroundCollisions){const s=(e=this.context.physics.engine)==null?void 0:e.getLinearVelocity(t.collider);s&&(this._contactVelocity.x+=s.x,this._contactVelocity.y+=s.y,this._contactVelocity.z+=s.z)}return this._contactVelocity}}_c([x(w)],vd.prototype,"center",2),_c([x()],vd.prototype,"radius",2),_c([x()],vd.prototype,"height",2);class xc extends Pe{constructor(){super(...arguments),h(this,"controller"),h(this,"movementSpeed",2),h(this,"rotationSpeed",2),h(this,"jumpForce",1),h(this,"doubleJumpForce",2),h(this,"animator"),h(this,"lookForward",!0),h(this,"lookInput",new ee(0,0)),h(this,"moveInput",new ee(0,0)),h(this,"jumpInput",!1),h(this,"_currentSpeed",new w(0,0,0)),h(this,"_currentAngularSpeed",new w(0,0,0)),h(this,"_temp",new w(0,0,0)),h(this,"_jumpCount",0),h(this,"_currentRotation"),h(this,"_raycastOptions",new Oo)}awake(){this._currentRotation=new Ie}update(){const e=this.context.input;e.isKeyPressed("KeyW")?this.moveInput.y+=1:e.isKeyPressed("KeyS")&&(this.moveInput.y-=1),e.isKeyPressed("KeyD")?this.lookInput.x+=1:e.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=e.isKeyDown("Space"))}move(e){this.moveInput.add(e)}look(e){this.lookInput.add(e)}jump(){this.jumpInput=!0}onBeforeRender(){this.handleInput(this.moveInput,this.lookInput,this.jumpInput),this.lookInput.set(0,0),this.moveInput.set(0,0),this.jumpInput=!1}handleInput(e,t,s){var r,n,o,a,l,c,u,d,p,f,m;if((r=this.controller)!=null&&r.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((n=this.animator)==null||n.setBool("doubleJump",!1))),this._currentSpeed.z+=e.y*this.movementSpeed*this.context.time.deltaTime,(o=this.animator)==null||o.setBool("running",e.length()>.01),(l=this.animator)==null||l.setBool("jumping",((a=this.controller)==null?void 0:a.isGrounded)===!0&&s),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp),this._currentAngularSpeed.y+=st.toRadians(-t.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const A=this.context.mainCameraComponent.forward;A.y=0,A.normalize(),this._currentRotation.setFromUnitVectors(new w(0,0,1),A),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&s&&this.jumpForce>0){let A=(c=this.controller)==null?void 0:c.isGrounded;if(this.doubleJumpForce>0&&!((u=this.controller)!=null&&u.isGrounded)&&this._jumpCount===1&&(A=!0,(d=this.animator)==null||d.setBool("doubleJump",!0)),A){this._jumpCount+=1;const y=this.controller.rigidbody,g=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;y.applyImpulse(new w(0,1,0).multiplyScalar(g))}}if(this.controller){const A=(p=this.controller)==null?void 0:p.rigidbody.getVelocity().y;if(A<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new Wn),this._raycastOptions.ray.origin.copy(Rt(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const y=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const g=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(y),(g.length&&g[0].distance>2||A<-10)&&((f=this.animator)==null||f.setBool("falling",!0))}else(m=this.animator)==null||m.setBool("falling",!1)}}}_c([x(vd)],xc.prototype,"controller",2),_c([x()],xc.prototype,"movementSpeed",2),_c([x()],xc.prototype,"rotationSpeed",2),_c([x()],xc.prototype,"jumpForce",2),_c([x()],xc.prototype,"doubleJumpForce",2),_c([x(Er)],xc.prototype,"animator",2);var Ene=Object.defineProperty,Mne=Object.getOwnPropertyDescriptor,Tne=(i,e,t,s)=>{for(var r=s>1?void 0:s?Mne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Ene(e,t,r),r};class eA extends en{constructor(){super(...arguments),h(this,"intensity")}get typeName(){return"ChromaticAberration"}init(){this.intensity.defaultValue=0}onCreateEffect(){const e=new kO;return e.offset=new ee(0,0),e.radialModulation=!0,e.modulationOffset=.15,this.intensity.valueProcessor=t=>t*.02,this.intensity.onValueChanged=t=>{e.offset.x=-t,e.offset.y=t},e}}Tne([x(Bt)],eA.prototype,"intensity",2),Vo("ChromaticAberration",eA);var Ine=Object.defineProperty,Rne=Object.getOwnPropertyDescriptor,dx=(i,e,t,s)=>{for(var r=s>1?void 0:s?Rne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Ine(e,t,r),r};class Lh extends en{constructor(){super(...arguments),h(this,"postExposure"),h(this,"contrast"),h(this,"hueShift"),h(this,"saturation")}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=e=>(e=Math.pow(2,e),e),this.postExposure.defaultValue=0,this.contrast.valueProcessor=e=>{let t=1;return e>0?t=200:e<0&&(t=100),e/t},this.contrast.defaultValue=0,this.hueShift.valueProcessor=e=>Math.PI*e/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=e=>e<0?e/100:e/(100*Math.PI),this.saturation.defaultValue=0}unapply(){this.context.renderer.toneMappingExposure=1}onCreateEffect(){this.context.renderer.toneMapping===Pn&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=vm);const e=new DO;this.postExposure.onValueChanged=s=>{this.context.renderer.toneMapping===Pn&&(this.context.renderer.toneMapping=vm),this.postExposure.overrideState&&(this.context.renderer.toneMappingExposure=s)},this.contrast.onValueChanged=s=>{e.contrast=s};const t=new LO;return this.hueShift.onValueChanged=s=>t.hue=s,this.saturation.onValueChanged=s=>t.saturation=s,[t,e]}}dx([x(Bt)],Lh.prototype,"postExposure",2),dx([x(Bt)],Lh.prototype,"contrast",2),dx([x(Bt)],Lh.prototype,"hueShift",2),dx([x(Bt)],Lh.prototype,"saturation",2),Vo("ColorAdjustments",Lh);const Pne=(Math.sqrt(5)-1)/4,Rr=(5-Math.sqrt(5))/20,px=i=>Math.floor(i)|0,fx=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function Bne(i=Math.random){const e=Dne(i),t=new Float64Array(e).map(o=>fx[o%32*4]),s=new Float64Array(e).map(o=>fx[o%32*4+1]),r=new Float64Array(e).map(o=>fx[o%32*4+2]),n=new Float64Array(e).map(o=>fx[o%32*4+3]);return function(o,a,l,c){let u,d,p,f,m;const A=(o+a+l+c)*Pne,y=px(o+A),g=px(a+A),v=px(l+A),b=px(c+A),_=(y+g+v+b)*Rr,S=y-_,M=g-_,C=v-_,R=b-_,I=o-S,E=a-M,z=l-C,F=c-R;let q=0,N=0,H=0,L=0;I>E?q++:N++,I>z?q++:H++,I>F?q++:L++,E>z?N++:H++,E>F?N++:L++,z>F?H++:L++;const j=q>=3?1:0,Q=N>=3?1:0,$=H>=3?1:0,Z=L>=3?1:0,se=q>=2?1:0,Ae=N>=2?1:0,Ue=H>=2?1:0,Qe=L>=2?1:0,Ke=q>=1?1:0,ae=N>=1?1:0,Ee=H>=1?1:0,He=L>=1?1:0,Fe=I-j+Rr,We=E-Q+Rr,le=z-$+Rr,Ne=F-Z+Rr,X=I-se+2*Rr,Se=E-Ae+2*Rr,_e=z-Ue+2*Rr,Ge=F-Qe+2*Rr,ue=I-Ke+3*Rr,dt=E-ae+3*Rr,U=z-Ee+3*Rr,P=F-He+3*Rr,ne=I-1+4*Rr,ke=E-1+4*Rr,Ce=z-1+4*Rr,Le=F-1+4*Rr,it=y&255,ze=g&255,Je=v&255,nt=b&255;let bt=.6-I*I-E*E-z*z-F*F;if(bt<0)u=0;else{const we=it+e[ze+e[Je+e[nt]]];bt*=bt,u=bt*bt*(t[we]*I+s[we]*E+r[we]*z+n[we]*F)}let De=.6-Fe*Fe-We*We-le*le-Ne*Ne;if(De<0)d=0;else{const we=it+j+e[ze+Q+e[Je+$+e[nt+Z]]];De*=De,d=De*De*(t[we]*Fe+s[we]*We+r[we]*le+n[we]*Ne)}let Ot=.6-X*X-Se*Se-_e*_e-Ge*Ge;if(Ot<0)p=0;else{const we=it+se+e[ze+Ae+e[Je+Ue+e[nt+Qe]]];Ot*=Ot,p=Ot*Ot*(t[we]*X+s[we]*Se+r[we]*_e+n[we]*Ge)}let lt=.6-ue*ue-dt*dt-U*U-P*P;if(lt<0)f=0;else{const we=it+Ke+e[ze+ae+e[Je+Ee+e[nt+He]]];lt*=lt,f=lt*lt*(t[we]*ue+s[we]*dt+r[we]*U+n[we]*P)}let ht=.6-ne*ne-ke*ke-Ce*Ce-Le*Le;if(ht<0)m=0;else{const we=it+1+e[ze+1+e[Je+1+e[nt+1]]];ht*=ht,m=ht*ht*(t[we]*ne+s[we]*ke+r[we]*Ce+n[we]*Le)}return 27*(u+d+p+f+m)}}function Dne(i){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const s=t+~~(i()*(256-t)),r=e[t];e[t]=e[s],e[s]=r}for(let t=256;t<512;t++)e[t]=e[t-256];return e}var kne=Object.defineProperty,One=Object.getOwnPropertyDescriptor,ie=(i,e,t,s)=>{for(var r=s>1?void 0:s?One(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&kne(e,t,r),r};const mx=te("debugparticles");var wc=(i=>(i[i.Billboard=0]="Billboard",i[i.Stretch=1]="Stretch",i[i.HorizontalBillboard=2]="HorizontalBillboard",i[i.VerticalBillboard=3]="VerticalBillboard",i[i.Mesh=4]="Mesh",i))(wc||{});let Uh=class{constructor(){h(this,"alphaKeys"),h(this,"colorKeys")}get duration(){return 1}evaluate(i,e){let t,s=0,r=null,n=0;for(let o=0;o<this.alphaKeys.length;o++){const a=this.alphaKeys[o];(a.time<i||!t)&&(t=a,s=o)}for(let o=0;o<this.colorKeys.length;o++){const a=this.colorKeys[o];(a.time<i||!r)&&(r=a,n=o)}if(r)if(n+1<this.colorKeys.length){const o=this.colorKeys[n+1],a=st.remap(i,r.time,o.time,0,1);e.r=st.lerp(r.color.r,o.color.r,a),e.g=st.lerp(r.color.g,o.color.g,a),e.b=st.lerp(r.color.b,o.color.b,a)}else e.r=r.color.r,e.g=r.color.g,e.b=r.color.b;if(t)if(s+1<this.alphaKeys.length){const o=this.alphaKeys[s+1],a=st.remap(i,t.time,o.time,0,1);e.alpha=st.lerp(t.alpha,o.alpha,a)}else e.alpha=t.alpha;return e}};ie([x()],Uh.prototype,"alphaKeys",2),ie([x()],Uh.prototype,"colorKeys",2);var tA=(i=>(i[i.Local=0]="Local",i[i.World=1]="World",i[i.Custom=2]="Custom",i))(tA||{}),gx=(i=>(i[i.Sphere=0]="Sphere",i[i.SphereShell=1]="SphereShell",i[i.Hemisphere=2]="Hemisphere",i[i.HemisphereShell=3]="HemisphereShell",i[i.Cone=4]="Cone",i[i.Box=5]="Box",i[i.Mesh=6]="Mesh",i[i.ConeShell=7]="ConeShell",i[i.ConeVolume=8]="ConeVolume",i[i.ConeVolumeShell=9]="ConeVolumeShell",i[i.Circle=10]="Circle",i[i.CircleEdge=11]="CircleEdge",i[i.SingleSidedEdge=12]="SingleSidedEdge",i[i.MeshRenderer=13]="MeshRenderer",i[i.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",i[i.BoxShell=15]="BoxShell",i[i.BoxEdge=16]="BoxEdge",i[i.Donut=17]="Donut",i[i.Rectangle=18]="Rectangle",i[i.Sprite=19]="Sprite",i[i.SpriteRenderer=20]="SpriteRenderer",i))(gx||{});const bj=class{constructor(){h(this,"mode"),h(this,"constant"),h(this,"constantMin"),h(this,"constantMax"),h(this,"curve"),h(this,"curveMin"),h(this,"curveMax"),h(this,"curveMultiplier")}clone(){var i,e,t;const s=new bj;return s.mode=this.mode,s.constant=this.constant,s.constantMin=this.constantMin,s.constantMax=this.constantMax,s.curve=(i=this.curve)==null?void 0:i.clone(),s.curveMin=(e=this.curveMin)==null?void 0:e.clone(),s.curveMax=(t=this.curveMax)==null?void 0:t.clone(),s.curveMultiplier=this.curveMultiplier,s}evaluate(i,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.constant;case 1:return i=st.clamp01(i),this.curve.evaluate(i)*this.curveMultiplier;case 2:const s=i*this.curveMin.duration,r=i*this.curveMax.duration;return st.lerp(this.curveMin.evaluate(s),this.curveMax.evaluate(r),t%1)*this.curveMultiplier;case 3:return st.lerp(this.constantMin,this.constantMax,t%1);default:this.curveMax.evaluate(i)*this.curveMultiplier;break}return 0}getMax(){switch(this.mode){case 0:return this.constant;case 1:return this.getMaxFromCurve(this.curve)*this.curveMultiplier;case 2:return Math.max(this.getMaxFromCurve(this.curveMin),this.getMaxFromCurve(this.curveMax))*this.curveMultiplier;case 3:return Math.max(this.constantMin,this.constantMax);default:return 0}}getMaxFromCurve(i){if(!i)return 0;let e=Number.MIN_VALUE;for(let t=0;t<i.keys.length;t++){const s=i.keys[t];s.value>e&&(e=s.value)}return e}};let ct=bj;ie([x()],ct.prototype,"mode",2),ie([x()],ct.prototype,"constant",2),ie([x()],ct.prototype,"constantMin",2),ie([x()],ct.prototype,"constantMax",2),ie([x(td)],ct.prototype,"curve",2),ie([x(td)],ct.prototype,"curveMin",2),ie([x(td)],ct.prototype,"curveMax",2),ie([x()],ct.prototype,"curveMultiplier",2);var vx;const Sa=(vx=class{constructor(){h(this,"mode"),h(this,"color"),h(this,"colorMin"),h(this,"colorMax"),h(this,"gradient"),h(this,"gradientMin"),h(this,"gradientMax")}evaluate(i,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.color;case 1:return this.gradient.evaluate(i,Sa._temp),Sa._temp;case 2:return Sa._temp.lerpColors(this.colorMin,this.colorMax,t);case 3:return this.gradientMin.evaluate(i,Sa._temp),this.gradientMax.evaluate(i,Sa._temp2),Sa._temp.lerp(Sa._temp2,t)}return Sa._temp.set(16711935),Sa._temp.alpha=1,Sa._temp}},h(vx,"_temp",new Si(0,0,0,1)),h(vx,"_temp2",new Si(0,0,0,1)),vx);let Gn=Sa;ie([x(Si)],Gn.prototype,"color",2),ie([x(Si)],Gn.prototype,"colorMin",2),ie([x(Si)],Gn.prototype,"colorMax",2),ie([x(Uh)],Gn.prototype,"gradient",2),ie([x(Uh)],Gn.prototype,"gradientMin",2),ie([x(Uh)],Gn.prototype,"gradientMax",2);var WI=(i=>(i[i.Hierarchy=0]="Hierarchy",i[i.Local=1]="Local",i[i.Shape=2]="Shape",i))(WI||{});class Pr{constructor(){h(this,"cullingMode"),h(this,"duration"),h(this,"emitterVelocityMode"),h(this,"flipRotation"),h(this,"gravityModifier"),h(this,"gravityModifierMultiplier"),h(this,"loop"),h(this,"maxParticles"),h(this,"playOnAwake"),h(this,"prewarm"),h(this,"ringBufferLoopRange"),h(this,"ringBufferMode"),h(this,"scalingMode"),h(this,"simulationSpace"),h(this,"simulationSpeed"),h(this,"startColor"),h(this,"startDelay"),h(this,"startDelayMultiplier"),h(this,"startLifetime"),h(this,"startLifetimeMultiplier"),h(this,"startRotation"),h(this,"startRotationMultiplier"),h(this,"startRotation3D"),h(this,"startRotationX"),h(this,"startRotationXMultiplier"),h(this,"startRotationY"),h(this,"startRotationYMultiplier"),h(this,"startRotationZ"),h(this,"startRotationZMultiplier"),h(this,"startSize"),h(this,"startSize3D"),h(this,"startSizeMultiplier"),h(this,"startSizeX"),h(this,"startSizeXMultiplier"),h(this,"startSizeY"),h(this,"startSizeYMultiplier"),h(this,"startSizeZ"),h(this,"startSizeZMultiplier"),h(this,"startSpeed"),h(this,"startSpeedMultiplier"),h(this,"stopAction"),h(this,"useUnscaledTime")}}ie([x(ct)],Pr.prototype,"gravityModifier",2),ie([x(Gn)],Pr.prototype,"startColor",2),ie([x(ct)],Pr.prototype,"startDelay",2),ie([x(ct)],Pr.prototype,"startLifetime",2),ie([x(ct)],Pr.prototype,"startRotation",2),ie([x(ct)],Pr.prototype,"startRotationX",2),ie([x(ct)],Pr.prototype,"startRotationY",2),ie([x(ct)],Pr.prototype,"startRotationZ",2),ie([x(ct)],Pr.prototype,"startSize",2),ie([x(ct)],Pr.prototype,"startSizeX",2),ie([x(ct)],Pr.prototype,"startSizeY",2),ie([x(ct)],Pr.prototype,"startSizeZ",2),ie([x(ct)],Pr.prototype,"startSpeed",2);class iA{constructor(){h(this,"cycleCount"),h(this,"maxCount"),h(this,"minCount"),h(this,"probability"),h(this,"repeatInterval"),h(this,"time"),h(this,"count"),h(this,"_performed",0)}reset(){this._performed=0}run(e){if(e<=this.time)return 0;let t=0;if(this.cycleCount===0||this._performed<this.cycleCount){const s=this.time+this.repeatInterval*this._performed;if(e>=s&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:t=this.count.constant;break;case 3:t=st.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:t=this.count.curve.evaluate(Math.random());break;case 2:const r=Math.random();t=st.lerp(this.count.curveMin.evaluate(r),this.count.curveMax.evaluate(r),Math.random());break}}return t}}class al{constructor(){h(this,"enabled"),h(this,"bursts"),h(this,"rateOverTime"),h(this,"rateOverTimeMultiplier"),h(this,"rateOverDistance"),h(this,"rateOverDistanceMultiplier"),h(this,"system")}get burstCount(){var e;return((e=this.bursts)==null?void 0:e.length)??0}reset(){var e;(e=this.bursts)==null||e.forEach(t=>t.reset())}getBurst(){let e=0;if(this.burstCount>0)for(let t=0;t<this.burstCount;t++){const s=this.bursts[t];this.system.main.loop&&s.time>=this.system.time&&s.reset(),e+=Math.round(s.run(this.system.time))}return e}}ie([x()],al.prototype,"enabled",2),ie([x()],al.prototype,"bursts",2),ie([x(ct)],al.prototype,"rateOverTime",2),ie([x()],al.prototype,"rateOverTimeMultiplier",2),ie([x(ct)],al.prototype,"rateOverDistance",2),ie([x()],al.prototype,"rateOverDistanceMultiplier",2);class sA{constructor(){h(this,"enabled"),h(this,"color")}}ie([x(Gn)],sA.prototype,"color",2);class Fh{constructor(){h(this,"enabled"),h(this,"separateAxes"),h(this,"size"),h(this,"sizeMultiplier"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier"),h(this,"_time",0),h(this,"_temp",new w)}evaluate(e,t,s){if(t||(t=this._temp),!this.enabled)return t.x=t.y=t.z=1,t;if(this.separateAxes)t.x=this.x.evaluate(e,s)*this.xMultiplier,t.y=this.y.evaluate(e,s)*this.yMultiplier,t.z=this.z.evaluate(e,s)*this.zMultiplier;else{const r=this.size.evaluate(e,s)*this.sizeMultiplier;t.x=r}return t}}ie([x(ct)],Fh.prototype,"size",2),ie([x(ct)],Fh.prototype,"x",2),ie([x(ct)],Fh.prototype,"y",2),ie([x(ct)],Fh.prototype,"z",2);var Ax;const rA=(Ax=class{constructor(){h(this,"shapeType",5),h(this,"enabled",!0),h(this,"alignToDirection",!1),h(this,"angle",0),h(this,"arc",360),h(this,"arcSpread"),h(this,"arcSpeedMultiplier"),h(this,"arcMode"),h(this,"boxThickness"),h(this,"position"),h(this,"rotation"),h(this,"_rotation",new Ur),h(this,"scale"),h(this,"radius"),h(this,"radiusThickness"),h(this,"sphericalDirectionAmount"),h(this,"randomDirectionAmount"),h(this,"randomPositionAmount"),h(this,"meshShapeType"),h(this,"meshRenderer"),h(this,"_meshObj"),h(this,"_meshGeometry"),h(this,"system"),h(this,"_space"),h(this,"_worldSpaceMatrix",new Te),h(this,"_worldSpaceMatrixInverse",new Te),h(this,"_vector",new w(0,0,0)),h(this,"_temp",new w(0,0,0)),h(this,"_triangle",new In),h(this,"_dir",new w),h(this,"_loopTime",0),h(this,"_loopDirection",1),mx&&console.log(this)}get type(){return gx[this.shapeType]}initialize(i){this.onInitialize(i),i.position.copy(this._vector)}toJSON(){return this}clone(){return new rA}setMesh(i){this.meshRenderer=i,i?(this._meshObj=i.sharedMeshes[Math.floor(Math.random()*i.sharedMeshes.length)],this._meshGeometry=this._meshObj.geometry):(this._meshObj=void 0,this._meshGeometry=void 0)}update(i,e,t,s){this.system=i,this._space=t,t===1&&(this._worldSpaceMatrix.copy(s.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(i){const e=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return e&&(this._rotation.x=st.toRadians(this.rotation.x),this._rotation.y=st.toRadians(this.rotation.y),this._rotation.z=st.toRadians(this.rotation.z),this._rotation.order="ZYX",i.applyEuler(this._rotation)),e}onInitialize(i){this._vector.set(0,0,0),i.mesh=void 0,i.mesh_geometry=void 0;const e=this._temp.copy(this.position),t=this._space===1;t&&e.applyQuaternion(this.system.worldQuaternion);let s=this.radius;if(t&&(s*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:mx&&Pt.DrawWireBox(this.position,this.scale,14540253,1),this._vector.x=Math.random()*this.scale.x-this.scale.x/2,this._vector.y=Math.random()*this.scale.y-this.scale.y/2,this._vector.z=Math.random()*this.scale.z-this.scale.z/2,this._vector.add(e);break;case 4:this.randomConePoint(this.position,this.angle,s,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,s,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,s,this.radiusThickness,this.arc,this._vector);break;case 13:const r=this.meshRenderer;r?.destroyed==!1&&this.setMesh(r);const n=i.mesh=this._meshObj,o=i.mesh_geometry=this._meshGeometry;if(n&&o)switch(this.meshShapeType){case 0:{const a=o.getAttribute("position"),l=Math.floor(Math.random()*a.count);this._vector.fromBufferAttribute(a,l),this._vector.applyMatrix4(n.matrixWorld),i.mesh_normal=l}break;case 1:break;case 2:{const a=o.index;if(a){let l=Math.random(),c=Math.random();l+c>1&&(l=1-l,c=1-c);const u=Math.floor(Math.random()*(a.count/3));let d=u*3,p=u*3+1,f=u*3+2;d=a.getX(d),p=a.getX(p),f=a.getX(f);const m=o.getAttribute("position");this._triangle.a.fromBufferAttribute(m,d),this._triangle.b.fromBufferAttribute(m,p),this._triangle.c.fromBufferAttribute(m,f),this._vector.set(0,0,0).addScaledVector(this._triangle.a,l).addScaledVector(this._triangle.b,c).addScaledVector(this._triangle.c,1-(l+c)),this._vector.applyMatrix4(n.matrixWorld),i.mesh_normal=u}}break}break;default:this._vector.set(0,0,0),wt()&&!globalThis.__particlesystem_shapetype_unsupported&&(console.warn("ParticleSystem ShapeType is not supported:",gx[this.shapeType]),globalThis.__particlesystem_shapetype_unsupported=!0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),t&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),mx&&Pt.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(i,e){var t;if(!this.enabled)return this._dir.set(0,0,1),this._dir;switch(this.shapeType){case 5:this._dir.set(0,0,1);break;case 4:this._dir.set(0,0,1);break;case 10:case 0:const s=e.x,r=e.y,n=e.z;this._dir.set(s,r,n),(t=this.system)!=null&&t.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;case 13:const o=i.mesh,a=i.mesh_geometry;if(o&&a)switch(this.meshShapeType){case 0:{const l=a.getAttribute("normal"),c=i.mesh_normal;this._dir.fromBufferAttribute(l,c)}break;case 1:break;case 2:{const l=a.index;if(l){const c=i.mesh_normal,u=l.getX(c*3),d=l.getX(c*3+1),p=l.getX(c*3+2),f=a.getAttribute("position"),m=Bs(),A=Bs(),y=Bs();m.fromBufferAttribute(f,u),A.fromBufferAttribute(f,d),y.fromBufferAttribute(f,p),m.sub(A),y.sub(A),m.cross(y),this._dir.copy(m).multiplyScalar(-1);const g=Ii(o);this._dir.applyQuaternion(g)}}break}break;default:this._dir.set(0,0,1);break}return this._space===1&&this._dir.applyQuaternion(this.system.worldQuaternion),this.applyRotation(this._dir),this._dir.normalize(),this.spherizeDirection(this._dir,this.sphericalDirectionAmount),this.randomizeDirection(this._dir,this.randomDirectionAmount),mx&&(Pt.DrawSphere(e,.01,8925952,.5,!0),Pt.DrawDirection(e,this._dir,8925952,.5,!0)),this._dir}randomizePosition(i,e){if(e<=0)return;const t=rA._tempVec;t.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),t.x*=e*this.scale.x,t.y*=e*this.scale.y,t.z*=e*this.scale.z,i.add(t)}randomizeDirection(i,e){if(e===0)return;const t=rA._randomQuat,s=rA._tempVec;s.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),t.setFromAxisAngle(s,e*Math.random()*Math.PI),i.applyQuaternion(t)}spherizeDirection(i,e){if(e===0)return;const t=Math.random()*Math.PI*2,s=Math.acos(1-Math.random()*2),r=Math.sin(s)*Math.cos(t),n=Math.sin(s)*Math.sin(t),o=Math.cos(s),a=new w(r,n,o);i.lerp(a,e)}randomSpherePoint(i,e,t,s,r){const n=Math.random(),o=Math.random(),a=2*Math.PI*n*(s/360),l=Math.acos(2*o-1),c=st.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,u=i.x+this.scale.x*(-c*Math.sin(l)*Math.cos(a)),d=i.y+this.scale.y*(c*Math.sin(l)*Math.sin(a)),p=i.z+this.scale.z*(c*Math.cos(l));r.x=u,r.y=d,r.z=p}randomCirclePoint(i,e,t,s,r){const n=Math.random(),o=2*Math.PI*n*(s/360),a=st.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,l=i.x+this.scale.x*a*Math.cos(o),c=i.y+this.scale.y*a*Math.sin(o),u=i.z;r.x=l,r.y=c,r.z=u}randomConePoint(i,e,t,s,r,n,o){let a=0,l=0;switch(n){case 0:a=Math.random(),l=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:a=.5,l=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let c=2*Math.PI*a*(r/360);switch(n){case 2:case 1:c+=Math.PI+.5,c+=this._loopTime*Math.PI*2,c%=st.toRadians(r);break}const u=Math.acos(2*l-1),d=st.lerp(1,1-Math.pow(1-Math.random(),Math.PI),s)*t,p=i.x+-d*Math.sin(u)*Math.cos(c),f=i.y+d*Math.sin(u)*Math.sin(c),m=i.z;o.x=p*this.scale.x,o.y=f*this.scale.y,o.z=m*this.scale.z}},h(Ax,"_randomQuat",new Ie),h(Ax,"_tempVec",new w),Ax);let os=rA;ie([x()],os.prototype,"shapeType",2),ie([x()],os.prototype,"enabled",2),ie([x()],os.prototype,"alignToDirection",2),ie([x()],os.prototype,"angle",2),ie([x()],os.prototype,"arc",2),ie([x()],os.prototype,"arcSpread",2),ie([x()],os.prototype,"arcSpeedMultiplier",2),ie([x()],os.prototype,"arcMode",2),ie([x(w)],os.prototype,"boxThickness",2),ie([x(w)],os.prototype,"position",2),ie([x(w)],os.prototype,"rotation",2),ie([x(w)],os.prototype,"scale",2),ie([x()],os.prototype,"radius",2),ie([x()],os.prototype,"radiusThickness",2),ie([x()],os.prototype,"sphericalDirectionAmount",2),ie([x()],os.prototype,"randomDirectionAmount",2),ie([x()],os.prototype,"randomPositionAmount",2),ie([x()],os.prototype,"meshShapeType",2),ie([x(Av)],os.prototype,"meshRenderer",2);class Ci{constructor(){h(this,"damping"),h(this,"enabled"),h(this,"frequency"),h(this,"octaveCount"),h(this,"octaveMultiplier"),h(this,"octaveScale"),h(this,"positionAmount"),h(this,"quality"),h(this,"remap"),h(this,"remapEnabled"),h(this,"remapMultiplier"),h(this,"remapX"),h(this,"remapXMultiplier"),h(this,"remapY"),h(this,"remapYMultiplier"),h(this,"remapZ"),h(this,"remapZMultiplier"),h(this,"scrollSpeedMultiplier"),h(this,"separateAxes"),h(this,"strengthMultiplier"),h(this,"strengthX"),h(this,"strengthXMultiplier"),h(this,"strengthY"),h(this,"strengthYMultiplier"),h(this,"strengthZ"),h(this,"strengthZMultiplier"),h(this,"_noise"),h(this,"_time",0),h(this,"_temp",new w)}update(e){this._time+=e.time.deltaTime*this.scrollSpeedMultiplier}apply(e,t,s,r,n,o){if(!this.enabled)return;this._noise||(this._noise=Bne(()=>0));const a=this._temp.set(t.x,t.y,t.z).multiplyScalar(this.frequency),l=this._noise(a.x,a.y,a.z,this._time),c=this._noise(a.x,a.y,a.z,this._time+1e3*this.frequency),u=this._noise(a.x,a.y,a.z,this._time+2e3*this.frequency);this._temp.set(l,c,u).normalize();const d=n/o;let p=this.positionAmount.evaluate(d);this.separateAxes?(this._temp.x*=p*this.strengthXMultiplier,this._temp.y*=p*this.strengthYMultiplier,this._temp.z*=p*this.strengthZMultiplier):(this.strengthX&&(p*=this.strengthX.evaluate(d)*1.5),this._temp.multiplyScalar(p)),s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z}}ie([x()],Ci.prototype,"damping",2),ie([x()],Ci.prototype,"enabled",2),ie([x()],Ci.prototype,"frequency",2),ie([x()],Ci.prototype,"octaveCount",2),ie([x()],Ci.prototype,"octaveMultiplier",2),ie([x()],Ci.prototype,"octaveScale",2),ie([x(ct)],Ci.prototype,"positionAmount",2),ie([x()],Ci.prototype,"quality",2),ie([x(ct)],Ci.prototype,"remap",2),ie([x()],Ci.prototype,"remapEnabled",2),ie([x()],Ci.prototype,"remapMultiplier",2),ie([x(ct)],Ci.prototype,"remapX",2),ie([x()],Ci.prototype,"remapXMultiplier",2),ie([x(ct)],Ci.prototype,"remapY",2),ie([x()],Ci.prototype,"remapYMultiplier",2),ie([x(ct)],Ci.prototype,"remapZ",2),ie([x()],Ci.prototype,"remapZMultiplier",2),ie([x()],Ci.prototype,"scrollSpeedMultiplier",2),ie([x()],Ci.prototype,"separateAxes",2),ie([x()],Ci.prototype,"strengthMultiplier",2),ie([x(ct)],Ci.prototype,"strengthX",2),ie([x()],Ci.prototype,"strengthXMultiplier",2),ie([x(ct)],Ci.prototype,"strengthY",2),ie([x()],Ci.prototype,"strengthYMultiplier",2),ie([x(ct)],Ci.prototype,"strengthZ",2),ie([x()],Ci.prototype,"strengthZMultiplier",2);class Ki{constructor(){h(this,"enabled"),h(this,"attachRibbonToTransform",!1),h(this,"colorOverLifetime"),h(this,"colorOverTrail"),h(this,"dieWithParticles",!0),h(this,"inheritParticleColor",!0),h(this,"lifetime"),h(this,"lifetimeMultiplier"),h(this,"minVertexDistance",.2),h(this,"mode",0),h(this,"ratio",1),h(this,"ribbonCount",1),h(this,"shadowBias",0),h(this,"sizeAffectsLifetime",!1),h(this,"sizeAffectsWidth",!1),h(this,"splitSubEmitterRibbons",!1),h(this,"textureMode",0),h(this,"widthOverTrail"),h(this,"widthOverTrailMultiplier"),h(this,"worldSpace",!1)}getWidth(e,t,s,r){const n=this.widthOverTrail.evaluate(s,r);return e*=n,e}getColor(e,t,s){const r=this.colorOverTrail.evaluate(s),n=this.colorOverLifetime.evaluate(t);e.x*=r.r*n.r,e.y*=r.g*n.g,e.z*=r.b*n.b,e.w*=r.alpha*n.alpha}}ie([x()],Ki.prototype,"enabled",2),ie([x()],Ki.prototype,"attachRibbonToTransform",2),ie([x(Gn)],Ki.prototype,"colorOverLifetime",2),ie([x(Gn)],Ki.prototype,"colorOverTrail",2),ie([x()],Ki.prototype,"dieWithParticles",2),ie([x()],Ki.prototype,"inheritParticleColor",2),ie([x(ct)],Ki.prototype,"lifetime",2),ie([x()],Ki.prototype,"lifetimeMultiplier",2),ie([x()],Ki.prototype,"minVertexDistance",2),ie([x()],Ki.prototype,"mode",2),ie([x()],Ki.prototype,"ratio",2),ie([x()],Ki.prototype,"ribbonCount",2),ie([x()],Ki.prototype,"shadowBias",2),ie([x()],Ki.prototype,"sizeAffectsLifetime",2),ie([x()],Ki.prototype,"sizeAffectsWidth",2),ie([x()],Ki.prototype,"splitSubEmitterRibbons",2),ie([x()],Ki.prototype,"textureMode",2),ie([x(ct)],Ki.prototype,"widthOverTrail",2),ie([x()],Ki.prototype,"widthOverTrailMultiplier",2),ie([x()],Ki.prototype,"worldSpace",2);class as{constructor(){h(this,"enabled"),h(this,"space",0),h(this,"orbitalX"),h(this,"orbitalY"),h(this,"orbitalZ"),h(this,"orbitalXMultiplier"),h(this,"orbitalYMultiplier"),h(this,"orbitalZMultiplier"),h(this,"orbitalOffsetX"),h(this,"orbitalOffsetY"),h(this,"orbitalOffsetZ"),h(this,"speedModifier"),h(this,"speedModifierMultiplier"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier"),h(this,"_system"),h(this,"_temp",new w),h(this,"_temp2",new w),h(this,"_temp3",new w),h(this,"_hasOrbital",!1),h(this,"_index",0),h(this,"_orbitalMatrix",new Te)}update(e){this._system=e}init(e){this._index==0&&(e.debug=!0),this._index+=1,e.orbitx=this.orbitalX.evaluate(Math.random()),e.orbity=this.orbitalY.evaluate(Math.random()),e.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=e.orbitx!=0||e.orbity!=0||e.orbitz!=0}apply(e,t,s,r,n,o,a){var l;if(!this.enabled)return;const c=o/a,u=this.speedModifier.evaluate(c)*this.speedModifierMultiplier,d=this.x.evaluate(c),p=this.y.evaluate(c),f=this.z.evaluate(c);if(this._temp.set(-d,p,f),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((l=this._system)==null?void 0:l.worldPos)){const m=this._temp2.set(s.x,s.y,s.z),A=this.orbitalXMultiplier,y=this.orbitalYMultiplier,g=this.orbitalZMultiplier,v=u*Math.PI*2*10,b=Math.cos(v*A),_=Math.sin(v*A),S=Math.cos(v*y),M=Math.sin(v*y),C=Math.cos(v*g),R=Math.sin(v*g),I=m.x*(S*C)+m.y*(S*R)+m.z*-M,E=m.x*(_*M*C-b*R)+m.y*(_*M*R+b*C)+m.z*(_*S),z=m.x*(b*M*C+_*R)+m.y*(b*M*R-_*C)+m.z*(b*S),F=this._temp3.set(m.x-I,m.y-E,m.z-z);F.normalize(),F.multiplyScalar(.2/n*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),r.x+=F.x,r.y+=F.y,r.z+=F.z}r.x+=this._temp.x,r.y+=this._temp.y,r.z+=this._temp.z,r.x*=u,r.y*=u,r.z*=u}}ie([x()],as.prototype,"enabled",2),ie([x()],as.prototype,"space",2),ie([x(ct)],as.prototype,"orbitalX",2),ie([x(ct)],as.prototype,"orbitalY",2),ie([x(ct)],as.prototype,"orbitalZ",2),ie([x()],as.prototype,"orbitalXMultiplier",2),ie([x()],as.prototype,"orbitalYMultiplier",2),ie([x()],as.prototype,"orbitalZMultiplier",2),ie([x()],as.prototype,"orbitalOffsetX",2),ie([x()],as.prototype,"orbitalOffsetY",2),ie([x()],as.prototype,"orbitalOffsetZ",2),ie([x(ct)],as.prototype,"speedModifier",2),ie([x()],as.prototype,"speedModifierMultiplier",2),ie([x(ct)],as.prototype,"x",2),ie([x()],as.prototype,"xMultiplier",2),ie([x(ct)],as.prototype,"y",2),ie([x()],as.prototype,"yMultiplier",2),ie([x(ct)],as.prototype,"z",2),ie([x()],as.prototype,"zMultiplier",2);class Br{constructor(){h(this,"animation"),h(this,"enabled"),h(this,"cycleCount"),h(this,"frameOverTime"),h(this,"frameOverTimeMultiplier"),h(this,"numTilesX"),h(this,"numTilesY"),h(this,"startFrame"),h(this,"startFrameMultiplier"),h(this,"rowMode"),h(this,"rowIndex"),h(this,"spriteCount"),h(this,"timeMode")}sampleOnceAtStart(){if(this.timeMode===0)switch(this.frameOverTime.mode){case 0:case 3:case 2:case 1:return!0}return!1}getStartIndex(){return this.sampleOnceAtStart()?Math.random()*(this.numTilesX*this.numTilesY):0}evaluate(e){if(!this.sampleOnceAtStart())return this.getIndex(e)}getIndex(e){const t=this.numTilesX*this.numTilesY;e=e*this.cycleCount;let s=this.frameOverTime.evaluate(e%1);return s*=this.frameOverTimeMultiplier,s*=t,s=s%t,s=Math.floor(s),s}}ie([x()],Br.prototype,"animation",2),ie([x()],Br.prototype,"enabled",2),ie([x()],Br.prototype,"cycleCount",2),ie([x(ct)],Br.prototype,"frameOverTime",2),ie([x()],Br.prototype,"frameOverTimeMultiplier",2),ie([x()],Br.prototype,"numTilesX",2),ie([x()],Br.prototype,"numTilesY",2),ie([x(ct)],Br.prototype,"startFrame",2),ie([x()],Br.prototype,"startFrameMultiplier",2),ie([x()],Br.prototype,"rowMode",2),ie([x()],Br.prototype,"rowIndex",2),ie([x()],Br.prototype,"spriteCount",2),ie([x()],Br.prototype,"timeMode",2);class qo{constructor(){h(this,"enabled"),h(this,"separateAxes"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier")}evaluate(e,t){return this.enabled?this.separateAxes?0:this.z.evaluate(e,t)*-1:0}}ie([x()],qo.prototype,"enabled",2),ie([x()],qo.prototype,"separateAxes",2),ie([x(ct)],qo.prototype,"x",2),ie([x()],qo.prototype,"xMultiplier",2),ie([x(ct)],qo.prototype,"y",2),ie([x()],qo.prototype,"yMultiplier",2),ie([x(ct)],qo.prototype,"z",2),ie([x()],qo.prototype,"zMultiplier",2);class ao{constructor(){h(this,"enabled"),h(this,"range"),h(this,"separateAxes"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier")}evaluate(e,t){if(!this.enabled)return 0;if(!this.separateAxes){const s=st.lerp(this.range.x,this.range.y,t);return this.z.evaluate(s)*-1}return 0}}ie([x()],ao.prototype,"enabled",2),ie([x()],ao.prototype,"range",2),ie([x()],ao.prototype,"separateAxes",2),ie([x(ct)],ao.prototype,"x",2),ie([x()],ao.prototype,"xMultiplier",2),ie([x(ct)],ao.prototype,"y",2),ie([x()],ao.prototype,"yMultiplier",2),ie([x(ct)],ao.prototype,"z",2),ie([x()],ao.prototype,"zMultiplier",2);class Ls{constructor(){h(this,"enabled"),h(this,"dampen"),h(this,"drag"),h(this,"dragMultiplier"),h(this,"limit"),h(this,"limitMultiplier"),h(this,"separateAxes"),h(this,"limitX"),h(this,"limitXMultiplier"),h(this,"limitY"),h(this,"limitYMultiplier"),h(this,"limitZ"),h(this,"limitZMultiplier"),h(this,"multiplyDragByParticleSize",!1),h(this,"multiplyDragByParticleVelocity",!1),h(this,"space"),h(this,"_temp",new w),h(this,"_temp2",new w)}apply(e,t,s,r,n,o,a){if(this.enabled){const l=this.limit.evaluate(n)*this.limitMultiplier;if(t.length()>l){this._temp.copy(t).normalize().multiplyScalar(l);const c=this.dampen*.5;t.x=st.lerp(t.x,this._temp.x,c),t.y=st.lerp(t.y,this._temp.y,c),t.z=st.lerp(t.z,this._temp.z,c),s.x=st.lerp(s.x,this._temp.x,c),s.y=st.lerp(s.y,this._temp.y,c),s.z=st.lerp(s.z,this._temp.z,c)}}}}ie([x()],Ls.prototype,"enabled",2),ie([x()],Ls.prototype,"dampen",2),ie([x(ct)],Ls.prototype,"drag",2),ie([x()],Ls.prototype,"dragMultiplier",2),ie([x(ct)],Ls.prototype,"limit",2),ie([x()],Ls.prototype,"limitMultiplier",2),ie([x()],Ls.prototype,"separateAxes",2),ie([x(ct)],Ls.prototype,"limitX",2),ie([x()],Ls.prototype,"limitXMultiplier",2),ie([x(ct)],Ls.prototype,"limitY",2),ie([x()],Ls.prototype,"limitYMultiplier",2),ie([x(ct)],Ls.prototype,"limitZ",2),ie([x()],Ls.prototype,"limitZMultiplier",2),ie([x()],Ls.prototype,"multiplyDragByParticleSize",2),ie([x()],Ls.prototype,"multiplyDragByParticleVelocity",2),ie([x()],Ls.prototype,"space",2);const _j=class{constructor(){h(this,"enabled"),h(this,"curve"),h(this,"curveMultiplier"),h(this,"mode"),h(this,"system"),h(this,"_temp",new w),h(this,"_firstUpdate",!0),h(this,"_frames",0)}clone(){var i;const e=new _j;return e.enabled=this.enabled,e.curve=(i=this.curve)==null?void 0:i.clone(),e.curveMultiplier=this.curveMultiplier,e.mode=this.mode,e}get _lastWorldPosition(){return this.system._iv_lastWorldPosition||(this.system._iv_lastWorldPosition=new w),this.system._iv_lastWorldPosition}get _velocity(){return this.system._iv_velocity||(this.system._iv_velocity=new w),this.system._iv_velocity}awake(i){this.system=i,this.reset()}reset(){this._firstUpdate=!0}update(i){this.enabled&&this.system.worldspace!==!1&&(this._firstUpdate?(this._firstUpdate=!1,this._velocity.set(0,0,0),this._lastWorldPosition.copy(this.system.worldPos)):this._lastWorldPosition&&(this._velocity.copy(this.system.worldPos).sub(this._lastWorldPosition).multiplyScalar(1/this.system.deltaTime),this._lastWorldPosition.copy(this.system.worldPos)))}applyInitial(i){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const e=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(e),i.add(this._temp)}}applyCurrent(i,e,t){if(this.enabled&&this.system&&this.system.worldspace!==!1&&this.mode===1){const s=this.curve.evaluate(e,t);this._temp.copy(this._velocity).multiplyScalar(s),i.add(this._temp)}}};let Nh=_j;ie([x()],Nh.prototype,"enabled",2),ie([x(ct)],Nh.prototype,"curve",2),ie([x()],Nh.prototype,"curveMultiplier",2),ie([x()],Nh.prototype,"mode",2);class xn{constructor(){h(this,"enabled"),h(this,"range"),h(this,"separateAxes"),h(this,"size"),h(this,"sizeMultiplier"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier")}evaluate(e,t,s,r){const n=e.length(),o=st.remap(n,this.range.x,this.range.y,0,1),a=this.size.evaluate(o,s);return r*a}}ie([x()],xn.prototype,"enabled",2),ie([x(ee)],xn.prototype,"range",2),ie([x()],xn.prototype,"separateAxes",2),ie([x(ct)],xn.prototype,"size",2),ie([x()],xn.prototype,"sizeMultiplier",2),ie([x(ct)],xn.prototype,"x",2),ie([x()],xn.prototype,"xMultiplier",2),ie([x(ct)],xn.prototype,"y",2),ie([x()],xn.prototype,"yMultiplier",2),ie([x(ct)],xn.prototype,"z",2),ie([x()],xn.prototype,"zMultiplier",2);class Ad{constructor(){h(this,"enabled"),h(this,"range"),h(this,"color")}evaluate(e,t,s){const r=e.length(),n=st.remap(r,this.range.x,this.range.y,0,1),o=this.color.evaluate(n,t);s.x*=o.r,s.y*=o.g,s.z*=o.b,s.w*=o.alpha}}ie([x()],Ad.prototype,"enabled",2),ie([x(ee)],Ad.prototype,"range",2),ie([x(Gn)],Ad.prototype,"color",2);const Lne={name:"HorizontalBlurShader",uniforms:{tDiffuse:{value:null},h:{value:1/512}},vertexShader:`
|
|
5412
|
+
`))}for(const I of C){const E=r.get(I);E&&R.set(I,E)}return R},p=function(C){const R=d(C),I=a(R);return l(R,I,C)};const f=s.skinnedMesh.skeleton,m=new Array;for(const C in f.bones){const R=f.bones[C],I=f.boneInverses[C];m.push({bone:R,inverse:I})}for(const C of Sz(f.bones))m.push({bone:C,inverse:C.matrixWorld.clone().invert()});const A=m[0].bone.parent;A||console.error("No bone parent found for skinned mesh during USDZ export",s.skinnedMesh),m.sort((C,R)=>ff(C.bone,A)>ff(R.bone,A)?1:-1);const y=[],g=[],v=[],b=[];for(const{bone:C}of m)y.push(C.matrix.clone()),g.push(C.position),v.push(C.quaternion),b.push(C.scale);const _=m.map(C=>'"'+ff(C.bone,A)+'"').join(", "),S=m.map(C=>mf(C.inverse.clone().invert())).join(", ");e.beginBlock('def Skeleton "Rig"'),e.appendLine(`uniform matrix4d[] bindTransforms = [${S}]`),e.appendLine(`uniform token[] joints = [${_}]`),e.appendLine('uniform token purpose = "guide"'),e.appendLine(`uniform matrix4d[] restTransforms = [${y.map(C=>mf(C)).join(", ")}]`),e.appendLine(`matrix4d xformOp:transform = ${mf(new Te)}`),e.appendLine('uniform token[] xformOpOrder = ["xformOp:transform"]');const M=p(m.map(C=>C.bone));if(e.beginBlock('def SkelAnimation "_anim"'),e.appendLine(`uniform token[] joints = [${_}]`),e.appendLine(`quatf[] rotations = [${u(v)}]`),M&&M.quaternion){e.beginBlock("quatf[] rotations.timeSamples = {","");const C=o(M.quaternion);for(const R of C)e.appendLine(R);e.closeBlock()}if(e.appendLine(`half3[] scales = [${c(b)}]`),M&&M.scale){e.beginBlock("half3[] scales.timeSamples = {","");const C=n(M.scale);for(const R of C)e.appendLine(R);e.closeBlock()}if(e.appendLine(`float3[] translations = [${c(g)}]`),M&&M.position){e.beginBlock("float3[] translations.timeSamples = {","");const C=n(M.position);for(const R of C)e.appendLine(R);e.closeBlock()}e.closeBlock(),e.closeBlock()}}onSerialize(e,t){var s;if(!this.model)return;this.skinnedMeshExport(e,t);const r=this.object,n=this.dict.get(r);if(!n||r.isSkinnedMesh)return;yI&&console.log("SERIALIZE",this.model.name,this.object.type,n);const o=new Te;e.appendLine("matrix4d xformOp:transform.timeSamples = {"),e.indent++;const a=new Array;let l=0;for(let c=0;c<n.length;c++)a.push(l),l+=n[c].getDuration()+Qo.animationDurationPadding;for(let c=0;c<n.length;c++){const u=n[c];if(!u)continue;const d=a[c];{const p=u.getSortedTimesArray();if(!p||p.length===0){console.error("got an animated object but no time values?",r,u);continue}if(wf){const f=((s=u.clip)==null?void 0:s.name)??"rest",m=u.getDuration();console.log("Write .timeSamples:",f,d,m,n),e.appendLine("# "+f+": start="+(d*u.frameRate).toFixed(3)+", length="+(m*u.frameRate).toFixed(3)+", frames="+u.getFrames())}for(const{time:f,translation:m,rotation:A,scale:y}of u.getValues(p)){o.compose(m,A,y);const g=`${(d+f)*u.frameRate}: ${mf(o)},`;e.appendLine(g)}}}e.indent--,e.appendLine("}")}}var cre=Object.defineProperty,hre=Object.getOwnPropertyDescriptor,tj=(i,e,t,s)=>{for(var r=s>1?void 0:s?hre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&cre(e,t,r),r};const ij=te("debugpost");class Bt{constructor(e){h(this,"_active",!0),h(this,"_value"),h(this,"_valueRaw"),h(this,"_defaultValue"),h(this,"valueProcessor"),h(this,"onValueChanged"),this._value=e,this._defaultValue=e,this._valueRaw=e}get overrideState(){return this._active}set overrideState(e){if(this._active===e)return;this._active=e;const t=e?this._valueRaw:this._defaultValue;this.processValue(t,!0)}get value(){return this._valueRaw}set value(e){this.processValue(e,!1)}set defaultValue(e){this._defaultValue=e}__init(){this.processValue(this._valueRaw,!0)}processValue(e,t){if(e==null||!t&&this.testIfValueChanged(e)===!1)return;const s=this._value;ij&&console.log("VolumeParameter: value changed from",s,"to",e),!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,e=this._defaultValue,this._valueRaw=e):(this._valueRaw=e,this._active&&this.valueProcessor&&(e=this.valueProcessor(e)),this._value=e),this.onValueChanged?this.onValueChanged(e,s,this):ij&&console.log("VolumeParameter: onValueChanged not set")}testIfValueChanged(e){return this._valueRaw!==e}}tj([x()],Bt.prototype,"overrideState",1),tj([x()],Bt.prototype,"value",1);var ure=Object.defineProperty,dre=Object.getOwnPropertyDescriptor,pre=(i,e,t,s)=>{for(var r=s>1?void 0:s?dre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&ure(e,t,r),r};const fre=te("debugpost");class en extends Pe{constructor(e=void 0){if(super(),h(this,"active",!0),h(this,"_result"),h(this,"_didCreateVolumeParameters",!1),e){this.ensureVolumeParameters();for(const t of Object.keys(e)){const s=e[t],r=this[t];r instanceof Bt&&(r.value=s)}}}onEnable(){this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){this.active=!1}init(){}apply(){var e;return this.ensureVolumeParameters(),this._result||(this._result=(e=this.onCreateEffect)==null?void 0:e.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){fre&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(e=>e.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const e=Object.keys(this);for(const t of e){const s=this[t];s instanceof Bt&&s.__init()}}onAfterDeserialize(e,t){if(typeof e=="object"){const s=this.$serializedTypes;if(s){for(const r of Object.keys(s))if(s[r]===Bt){const n=e[r];if(n!==void 0){const o=this[r];o.value=n}}}}}onEditorModification(e){const t=e.propertyName;if(this[t]instanceof Bt){const s=e.value;return this[t].value=s,!0}}ensureVolumeParameters(){if(this._didCreateVolumeParameters)return;this._didCreateVolumeParameters=!0;const e=this.$serializedTypes;if(e)for(const t of Object.keys(e))e[t]===Bt&&(this[t]||(this[t]=new Bt))}}pre([x()],en.prototype,"active",2);var mre=Object.defineProperty,gre=Object.getOwnPropertyDescriptor,vre=(i,e,t,s)=>{for(var r=s>1?void 0:s?gre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&mre(e,t,r),r};const Are=te("debugpost"),bI={};function Vo(i,e){bI[i]=e}function yre(i){return i.__type in bI?bI[i.__type]:(Are&&i.__type&&console.warn("Unknown postprocessing type",i.__type,i),en)}class Lv{constructor(){h(this,"components",[])}init(){var e;(e=this.components)==null||e.forEach(t=>t.init())}}vre([nf([i=>yre(i),en])],Lv.prototype,"components",2);var bre=Object.defineProperty,_re=Object.getOwnPropertyDescriptor,xre=(i,e,t,s)=>{for(var r=s>1?void 0:s?_re(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&bre(e,t,r),r};class Uv extends en{constructor(){super(...arguments),h(this,"preset")}get typeName(){return"Antialiasing"}onCreateEffect(){const e=new y7({preset:Up.HIGH,edgeDetectionMode:ZC.DEPTH});return this.preset.onValueChanged=t=>{e.applyPreset(t)},e}}xre([x(Bt)],Uv.prototype,"preset",2),Vo("Antialiasing",Uv);class $_{constructor(){h(this,"files",[])}get extensionName(){return"Audio"}onExportObject(e,t,s){const r=oe.getComponents(e,vs);if(r.length)for(const n of r){if(!n.clip||typeof n.clip!="string"||!n.playOnAwake)continue;const o=n.clip.split("/").pop();this.files.includes(n.clip)||this.files.push(n.clip),t.addEventListener("serialize",(a,l)=>{a.appendLine(),a.beginBlock(`def SpatialAudio "${t.name}"`),a.appendLine(`uniform asset filePath = @audio/${o}@`),a.appendLine(`uniform token auralMode = "${n.spatialBlend>0?"spatial":"nonSpatial"}"`),a.appendLine(`uniform token playbackMode = "${n.loop?"loopFromStage":"onceFromStart"}"`),a.appendLine(`uniform float gain = ${n.volume}`),a.closeBlock()})}}async onAfterSerialize(e){for(const t of this.files){const s=t.split("/").pop(),r=await(await(await fetch(t)).blob()).arrayBuffer(),n=new Uint8Array(r);e.files["audio/"+s]=n}}}const od=te("debugautosync"),_I=Symbol("syncerId");class wre{constructor(){h(this,"_syncers",{})}getOrCreateSyncer(e){if(!e.guid)return null;if(this._syncers[e.guid])return this._syncers[e.guid];const t=new Sre(e);return t[_I]=e.guid,this._syncers[t[_I]]=t,t}removeSyncer(e){delete this._syncers[e[_I]]}}const xI=new wre;class Sre{constructor(e){h(this,"comp"),h(this,"hasChanges",!1),h(this,"changedProperties",{}),h(this,"data",{}),h(this,"_boundEvent"),h(this,"_handleReceivingMethod"),h(this,"_isReceiving",!1),h(this,"_isInit",!1),this.comp=e}get networkingKey(){return this.comp.guid}init(e){if(this._isInit)return;this._isInit=!0,this.comp=e,this._boundEvent=this.onHandleSending.bind(this),this.comp.context.post_render_callbacks.push(this._boundEvent),this._handleReceivingMethod=this.onHandleReceiving.bind(this),this.comp.context.connection.beginListen(this.networkingKey,this._handleReceivingMethod);const t=this.comp.context.connection.tryGetState(this.comp.guid);t&&this.onHandleReceiving(t)}destroy(){this._isInit&&(this._boundEvent&&this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this._boundEvent),1),this._handleReceivingMethod&&this.comp.context.connection.stopListen(this.networkingKey,this._handleReceivingMethod),this.comp=null,this._isInit=!1)}notifyChanged(e,t){this._isReceiving||(od&&console.log("Property changed: "+e,t),this.hasChanges=!0,this.changedProperties[e]=t)}onHandleSending(){if(!this.hasChanges)return;this.hasChanges=!1;const e=this.comp.context.connection;if(!e||!e.isConnected){for(const t in this.changedProperties)delete this.changedProperties[t];return}for(const t in this.data)delete this.data[t];this.data.guid=this.comp.guid;for(const t in this.changedProperties){const s=this.changedProperties[t];delete this.changedProperties[t],this.data[t]=s}e.send(this.networkingKey,this.data)}onHandleReceiving(e){if(od&&console.log("RECEIVE",this.comp.name,this.comp.guid,e),!this._isInit||!this.comp)return;const t=e.guid;if(!(t&&t!==this.comp.guid)){od&&console.log("RECEIVED",this.comp.name,this.comp.guid,e);try{this._isReceiving=!0;for(const s in e){if(s==="guid")continue;const r=e[s];this.comp[s]=r,od&&console.log("SET",s,r)}}catch(s){console.error(s)}finally{this._isReceiving=!1}}}}function Cre(i,e){let t=e!==i;return!t&&i&&e&&(Array.isArray(i)&&Array.isArray(e)||typeof i=="object"&&typeof e=="object")&&(t=!0),t}const Fv=Symbol("AutoSyncHandler");function Ere(i){if(i[Fv])return i[Fv];const e=xI.getOrCreateSyncer(i);return e?.init(i),i[Fv]=e,e}function Mre(i){const e=i[Fv];e&&(xI.removeSyncer(e),e.destroy(),delete i[Fv])}const wI=function(i){return function(e,t){var s;let r="";typeof t=="string"?r=t:r=t.name;let n=null,o;typeof i=="string"?o=e[i]:typeof i=="function"&&(o=i);const a=e,l=a.__internalAwake;if(typeof l!="function"){(od||wt())&&console.error('@syncField can currently only used on Needle Engine Components, custom object of type "'+((s=e?.constructor)==null?void 0:s.name)+'" is not supported',e);return}od&&console.log(r);const c=Symbol(r);a.__internalAwake=function(){if(this[c]!==void 0)return;this[c]=this[r],n=xI.getOrCreateSyncer(this);const d=Object.getOwnPropertyDescriptor(this,r);if(d?.set===void 0){let p=!1;Object.defineProperty(this,r,{set:function(f){var m;const A=this[c];if(this[c]=f,p){wt()&&console.warn("Recursive call detected",r);return}p=!0;try{const y=Cre(f,A);od&&console.log("SyncField assignment",r,"changed?",y,f),y&&o?.call(this,f,A)!==!1&&((m=Ere(this))==null||m.notifyChanged(r,f))}finally{p=!1}},get:function(){return this[c]},configurable:!0,enumerable:!0})}n?.init(this),l.call(this)};const u=a.__internalDestroy;a.__internalDestroy=function(){Mre(this),u.call(this)}}};var Tre=Object.defineProperty,Ire=Object.getOwnPropertyDescriptor,ex=(i,e,t,s)=>{for(var r=s>1?void 0:s?Ire(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Tre(e,t,r),r};const Ho=te("debugplayersync");class Sf extends Pe{constructor(){super(...arguments),h(this,"autoSync",!0),h(this,"asset"),h(this,"onPlayerSpawned"),h(this,"_localInstance"),h(this,"onJoinedRoom",()=>{Ho&&console.log("PlayerSync.joinedRoom. autoSync is set to "+this.autoSync),this.autoSync&&this.getInstance()})}awake(){this.watchTabVisible(),this.onPlayerSpawned||(this.onPlayerSpawned=new tr)}onEnable(){this.context.connection.beginListen(di.RoomStateSent,this.onJoinedRoom),this.context.connection.beginListen(di.JoinedRoom,this.onJoinedRoom),this.context.connection.isInRoom&&this.onJoinedRoom()}onDisable(){this.context.connection.stopListen(di.RoomStateSent,this.onJoinedRoom),this.context.connection.stopListen(di.JoinedRoom,this.onJoinedRoom)}async getInstance(){var e,t,s,r,n,o;if(this._localInstance)return this._localInstance;if(Ho&&console.log("PlayerSync.createInstance",(e=this.asset)==null?void 0:e.uri),!((t=this.asset)!=null&&t.asset)&&!((s=this.asset)!=null&&s.uri))return console.error('PlayerSync: can not create an instance because "asset" is not set!'),null;this._localInstance=(r=this.asset)==null?void 0:r.instantiateSynced({parent:this.gameObject},!0);const a=await this._localInstance;if(a){const l=oe.getComponent(a,Wo);l?(l.owner=this.context.connection.connectionId,(n=this.onPlayerSpawned)==null||n.invoke(a)):(this._localInstance=void 0,console.error("<strong>Failed finding PlayerState on "+((o=this.asset)==null?void 0:o.uri)+"</strong>: please make sure the asset has a PlayerState component!"),oe.destroySynced(a))}else this._localInstance=void 0,console.warn("PlayerSync: failed instantiating asset!");return this._localInstance}destroyInstance(){var e;(e=this._localInstance)==null||e.then(t=>(Ho&&console.log("PlayerSync.destroyInstance",t),oe.destroySynced(t))),this._localInstance=void 0}watchTabVisible(){window.addEventListener("visibilitychange",e=>{if(document.visibilityState==="visible")for(let t=Wo.all.length-1;t>=0;t--){const s=Wo.all[t];(!s.owner||!this.context.connection.userIsInRoom(s.owner))&&s.doDestroy()}})}}ex([x()],Sf.prototype,"autoSync",2),ex([x(ni)],Sf.prototype,"asset",2),ex([x(tr)],Sf.prototype,"onPlayerSpawned",2);var sj=(i=>(i.OwnerChanged="ownerChanged",i))(sj||{}),Nv;const Mr=(Nv=class extends Pe{constructor(){super(...arguments),h(this,"onOwnerChangeEvent",new tr),h(this,"onFirstOwnerChangeEvent",new tr),h(this,"hasOwner",!1),h(this,"owner"),h(this,"dontDestroy",!1),h(this,"onUserLeftRoom",i=>{if(i.userId===this.owner){Ho&&console.log("PLAYERSYNC LEFT",this.owner),this.doDestroy();return}})}static get all(){return Mr._all}static get local(){return Mr._local}static getFor(i){if(i instanceof ye)return oe.getComponentInParent(i,Mr);if(i instanceof Pe)return oe.getComponentInParent(i.gameObject,Mr)}static isLocalPlayer(i){const e=Mr.getFor(i);return e?.isLocalPlayer??!1}static addEventListener(i,e){return this._callbacks[i]||(this._callbacks[i]=[]),this._callbacks[i].push(e),e}static removeEventListener(i,e){if(!this._callbacks[i])return;const t=this._callbacks[i].indexOf(e);t>=0&&this._callbacks[i].splice(t,1)}static dispatchEvent(i,e){if(this._callbacks[i])for(const t of this._callbacks[i])t(e)}get isLocalPlayer(){return this.owner===this.context.connection.connectionId}onOwnerChange(i,e){var t,s;Ho&&console.log("PlayerSync.onOwnerChange",this,"newOwner",i,"oldOwner",e);const r=Mr._local.indexOf(this);r>=0&&Mr._local.splice(r,1);const n={playerState:this,oldValue:e,newValue:i};if(this.hasOwner||(this.hasOwner=!0,(t=this.onFirstOwnerChangeEvent)==null||t.invoke(n)),(s=this.onOwnerChangeEvent)==null||s.invoke(n),this.owner===this.context.connection.connectionId){Mr._local.push(this);const a=new CustomEvent("local-owner-changed",{detail:n});this.dispatchEvent(a)}const o=new CustomEvent("owner-changed",{detail:n});this.dispatchEvent(o),Mr.dispatchEvent("ownerChanged",o)}awake(){Mr.all.push(this),Ho&&console.log("Registered new PlayerState",this.guid,Mr.all.length-1,Mr.all),this.context.connection.beginListen(di.UserLeftRoom,this.onUserLeftRoom)}async start(){Ho&&console.log("PLAYERSTATE.START, owner: "+this.owner,this.context.connection.usersInRoom([])),this.owner?(this.context.connection.isInRoom||await Co(300),this.context.connection.userIsInRoom(this.owner)==!1&&(Ho&&console.log(`PlayerSync.start \u2192 doDestroy "${this.name}" because user "${this.owner}" is not in room anymore...`,"Currently in room:",...this.context.connection.usersInRoom()),this.doDestroy())):this.owner||(Ho&&console.warn("PlayerState.start \u2192 owner is undefined!",this.name),setTimeout(()=>{!this.destroyed&&!this.owner?this.dontDestroy?Ho&&console.warn("PlayerState.start \u2192 owner is still undefined but dontDestroy is set to true",this.name):(Ho&&console.warn(`PlayerState.start \u2192 owner is still undefined: destroying "${this.name}" instance now`),this.doDestroy()):console.log("PlayerState.start \u2192 owner is assigned",this.owner)},2e3))}doDestroy(){Ho&&console.log("PlayerSync.doDestroy \u2192 syncDestroy",this.name),c_(this.gameObject,this.context.connection)}onDestroy(){if(this.context.connection.stopListen(di.UserLeftRoom,this.onUserLeftRoom),Mr.all.splice(Mr.all.indexOf(this),1),this.isLocalPlayer){const i=Mr._local.indexOf(this);i>=0&&Mr._local.splice(i,1)}}},h(Nv,"_all",[]),h(Nv,"_local",[]),h(Nv,"_callbacks",{}),Nv);let Wo=Mr;ex([wI(Wo.prototype.onOwnerChange)],Wo.prototype,"owner",2);const Rre=te("debugavatar"),il=class extends Pe{constructor(){super(...arguments),h(this,"connectionId"),h(this,"avatar")}static getAvatar(i){return i>=0&&i<il.instances.length?il.instances[i]:null}static onAvatarMarkerCreated(i){return il._onNewAvatarMarkerAdded.push(i),i}static onAvatarMarkerDestroyed(i){return il._onAvatarMarkerDestroyed.push(i),i}awake(){il.instances.push(this),Rre&&console.log(this);for(const i of il._onNewAvatarMarkerAdded)i({avatarMarker:this,gameObject:this.gameObject})}onDestroy(){il.instances.splice(il.instances.indexOf(this),1);for(const i of il._onAvatarMarkerDestroyed)i({avatarMarker:this,gameObject:this.gameObject})}isLocalAvatar(){return this.connectionId===this.context.connection.connectionId}};let Tr=il;h(Tr,"instances",[]),h(Tr,"_onNewAvatarMarkerAdded",[]),h(Tr,"_onAvatarMarkerDestroyed",[]);var Pre=Object.defineProperty,Bre=Object.getOwnPropertyDescriptor,Dre=(i,e,t,s)=>{for(var r=s>1?void 0:s?Bre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Pre(e,t,r),r};const Cf=te("debugxrflags"),rj=te("disablexrflags");rj&&console.warn("XRFlags are disabled");var sl=(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))(sl||{});const nj=class{constructor(){h(this,"Mask",17)}Has(i){return(this.Mask&i)!==0}Set(i){Cf&&console.warn("Set XR flag state to",i),this.Mask=i,ro.Apply()}Enable(i){this.Mask|=i,ro.Apply()}Disable(i){this.Mask&=~i,ro.Apply()}Toggle(i){this.Mask^=i,ro.Apply()}EnableAll(){this.Mask=-1,ro.Apply()}DisableAll(){this.Mask=0,ro.Apply()}};let bn=nj;h(bn,"Global",new nj);var zv;const vc=(zv=class extends Pe{constructor(){super(...arguments),h(this,"visibleIn")}static Apply(){for(const i of this.registry)i.UpdateVisible(bn.Global)}awake(){vc.registry.push(this)}onEnable(){vc.firstApply?this.UpdateVisible(bn.Global):(vc.firstApply=!0,vc.Apply())}onDestroy(){const i=vc.registry.indexOf(this);i>=0&&vc.registry.splice(i,1)}get isOn(){return this.gameObject.visible}UpdateVisible(i=null){if(rj)return;let e;const t=i;if(t&&typeof t=="number"&&(console.assert(typeof t=="number","XRFlag.UpdateVisible: state must be a number",t),Cf&&console.log(t),vc.buffer.Mask=t,i=vc.buffer),i instanceof bn?(Cf&&console.warn(this.name,"use passed in mask",i.Mask,this.visibleIn),e=i.Has(this.visibleIn)):(Cf&&console.log(this.name,"use global mask"),bn.Global.Has(this.visibleIn)),e!==void 0)if(e)Cf&&console.log(this.name,"is visible",this.gameObject.uuid),oe.setActive(this.gameObject,!0);else{if(Cf&&console.log(this.name,"is not visible",this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},h(zv,"registry",[]),h(zv,"firstApply"),h(zv,"buffer",new bn),zv);let ro=vc;Dre([x()],ro.prototype,"visibleIn",2);var kre=Object.defineProperty,Ore=Object.getOwnPropertyDescriptor,SI=(i,e,t,s)=>{for(var r=s>1?void 0:s?Ore(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&kre(e,t,r),r};const jv=te("debugwebxr"),oj=new Ie().setFromAxisAngle(new w(0,1,0),Math.PI);class ad extends Pe{constructor(){super(...arguments),h(this,"head"),h(this,"leftHand"),h(this,"rightHand"),h(this,"_syncTransforms")}async onEnterXR(e){if(!this.activeAndEnabled)return;jv&&console.warn("AVATAR ENTER XR",this.guid,this.sourceId,this,this.activeAndEnabled),this._syncTransforms&&(this._syncTransforms.length=0),await this.prepareAvatar();const t=Wo.getFor(this);if(t!=null&&t.owner){const s=this.gameObject.addNewComponent(Tr);s.avatar=this.gameObject,s.connectionId=t.owner}else this.context.connection.isConnected?console.error("No player state found for avatar",this):t&&!this.context.connection.isConnected&&(t.dontDestroy=!0)}onLeaveXR(e){const t=this.gameObject.getComponent(Tr);t&&t.destroy()}onUpdateXR(e){var t,s;if(!this.activeAndEnabled)return;const r=Wo.isLocalPlayer(this);if(!r)return;const n=e.xr;if(n.rig&&n.rig.gameObject!==this.gameObject.parent&&(this.gameObject.position.set(0,0,0),this.gameObject.rotation.set(0,0,0),this.gameObject.scale.set(1,1,1),n.rig.gameObject.add(this.gameObject)),this._syncTransforms&&r)for(const c of this._syncTransforms)c.fastMode=!0,c.isOwned()||c.requestOwnership();if(this.head&&this.context.mainCamera){const c=this.head.asset;if(c.position.copy(this.context.mainCamera.position),c.quaternion.copy(this.context.mainCamera.quaternion),c.quaternion.x*=-1,this.context.time.frameCount%10===0){const u=oe.getComponentsInChildren(this.head.asset,ro);for(const d of u)d.enabled=!1,d.gameObject.visible=!1}}const o=e.xr.leftController,a=(t=this.leftHand)==null?void 0:t.asset;o&&a&&(a.position.copy(o.gripPosition),a.quaternion.copy(o.gripQuaternion),a.quaternion.multiply(oj),a.visible=o.isTracking);const l=e.xr.rightController;if(l&&(s=this.rightHand)!=null&&s.asset){const c=this.rightHand.asset;c.position.copy(l.gripPosition),c.quaternion.copy(l.gripQuaternion),c.quaternion.multiply(oj),c.visible=l.isTracking}}onBeforeRender(){this.context.time.frame%10===0&&this.updateRemoteAvatarVisibility()}updateRemoteAvatarVisibility(){var e,t,s;if(this.context.connection.isConnected){const r=Wo.getFor(this);if(r&&r.isLocalPlayer==!1){const n=vt.getXRSync(this.context);if(n&&n.hasState(r.owner)){this.tryFindAvatarObjectsIfMissing();const o=(e=this.leftHand)==null?void 0:e.asset;o&&(o.visible=n?.isTracking(r.owner,"left")??!1);const a=(t=this.rightHand)==null?void 0:t.asset;a&&(a.visible=n?.isTracking(r.owner,"right")??!1)}if((s=this.head)!=null&&s.asset){const o=oe.getComponentsInChildren(this.head.asset,ro);for(const a of o)a.enabled=!1,a.gameObject.visible=!0}}}}tryFindAvatarObjectsIfMissing(){if(!this.head||!this.leftHand||!this.rightHand){const e={head:this.head,leftHand:this.leftHand,rightHand:this.rightHand};zN.tryFindAvatarObjects(this.gameObject,this.sourceId||"",e),e.head&&(this.head=e.head),e.leftHand&&(this.leftHand=e.leftHand),e.rightHand&&(this.rightHand=e.rightHand)}}async prepareAvatar(){if(this.tryFindAvatarObjectsIfMissing(),this.head)this.head instanceof ye&&(this.head=new ni("",this.sourceId,this.head));else{const e=new ye;e.name="Head";const t=Yp.createPrimitive(Hu.Cube);e.add(t),this.gameObject.add(e),this.head=new ni("",this.sourceId,e),jv&&console.log("Create head",e)}if(this.rightHand)this.rightHand instanceof ye&&(this.rightHand=new ni("",this.sourceId,this.rightHand));else{const e=new ye;e.name="Right Hand",this.gameObject.add(e),this.rightHand=new ni("",this.sourceId,e),jv&&console.log("Create right hand",e)}if(this.leftHand)this.leftHand instanceof ye&&(this.leftHand=new ni("",this.sourceId,this.leftHand));else{const e=new ye;e.name="Left Hand",this.gameObject.add(e),this.leftHand=new ni("",this.sourceId,e),jv&&console.log("Create left hand",e)}await this.loadAvatarObjects(this.head,this.leftHand,this.rightHand),Wo.isLocalPlayer(this.gameObject)&&(this._syncTransforms=oe.getComponentsInChildren(this.gameObject,Eh))}async loadAvatarObjects(e,t,s){const r=e.loadAssetAsync(),n=t.loadAssetAsync(),o=s.loadAssetAsync(),a=new Array;r&&a.push(r),n&&a.push(n),o&&a.push(o);const l=await lg(a);jv&&console.log("Avatar loaded results:",l)}}SI([x(ni)],ad.prototype,"head",2),SI([x(ni)],ad.prototype,"leftHand",2),SI([x(ni)],ad.prototype,"rightHand",2);class rl{static Add(e,t,s=null){if(t){for(const r of this.Pois)if(r.obj===t)return;this.Pois.push({obj:t,avatar:s}),this.LastChangeTime=e.time.time}}static Remove(e,t){var s;if(t){for(const r of this.Pois)if(r.obj===t){this.Pois.splice(this.Pois.indexOf(r),1),this.LastChangeTime=e?.time.time??((s=kt.Current)==null?void 0:s.time.time);return}}}}h(rl,"Pois",[]),h(rl,"LastChangeTime",0);class Lre{constructor(){h(this,"guid"),h(this,"position",new w)}}class Gv extends Pe{constructor(){super(...arguments),h(this,"target",null),h(this,"avatar",null),h(this,"_model",null),h(this,"_targetModel",new Lre),h(this,"_currentTargetObject",null),h(this,"_lastUpdateTime",0),h(this,"_lookDuration",0),h(this,"_lastPoiChangedTime",0)}set controlledTarget(e){this.target=e;const t=J.get("MoveRandom");if(t&&this.target){const s=oe.getComponent(this.target,t);s&&s.destroy()}}awake(){if(this.avatar=oe.getComponentInParent(this.gameObject,Tr),this.avatar){const e=oe.getComponentInParent(this.gameObject,Tr);this._model=new ZE(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)&&Kr(this.target,e.position)})}update(){var e;if((!this.context.connection.isConnected||(e=this._model)!=null&&e.hasOwnership)&&(rl.LastChangeTime!==this._lastPoiChangedTime&&(this._lastPoiChangedTime=rl.LastChangeTime,this._lookDuration=0),this.selectTarget(),this._currentTargetObject&&this.context.time.frameCount%10===0&&this.target)){const t=Rt(this._currentTargetObject);Kr(this.target,t),this.context.connection.isConnected&&this.avatar&&(this.context.connection.send("avatar-look-target-changed",this._targetModel),this._targetModel.guid=this.avatar.guid,this._targetModel.position.copy(t))}}selectTarget(){if(this.context.time.time-this._lastUpdateTime>this._lookDuration){this._lastUpdateTime=this.context.time.time,this._lookDuration=Math.random()*.5+.2;const e=rl.Pois;if(e.length>0){const t=e[Math.floor(Math.random()*e.length)];if(t&&t.obj){if(t.avatar&&t.avatar===this.avatar)return;this._currentTargetObject=t.obj}}}}}const Ef=te("debugnetworkingstreams");var nl=(i=>(i.Connected="peer-user-connected",i.StreamReceived="receive-stream",i.StreamEnded="call-ended",i.Disconnected="peer-user-disconnected",i.UserJoined="user-joined",i))(nl||{});class aj{constructor(e,t){h(this,"type","call-ended"),h(this,"userId"),h(this,"direction"),this.userId=e,this.direction=t}}class lj{constructor(e,t){h(this,"type","receive-stream"),h(this,"stream"),h(this,"target"),this.stream=e,this.target=t}}class Ure{constructor(e,t){h(this,"guid"),h(this,"peerId"),h(this,"dontSave",!0),this.guid=e.id,this.peerId=t}}var cj=(i=>(i.Incoming="incoming",i.Outgoing="outgoing",i))(cj||{});class Fre extends Ks{constructor(e,t,s){super(),h(this,"userId"),h(this,"direction"),h(this,"call"),h(this,"_stream",null),h(this,"_isDisposed",!1),this.userId=e,this.call=t,this.direction=s,this._stream=null,t.on("stream",r=>{if(Ef&&console.log("Receive video",r.getAudioTracks(),r.getVideoTracks()),this._stream=r,s==="incoming"){const n=new lj(r,this);this.dispatchEvent(n)}}),t.on("close",()=>{this.dispatchEvent(new aj(e,s))})}get stream(){return this._stream}close(){this._isDisposed||(this._isDisposed=!0,this.call.close(),Ac(this._stream))}get isOpen(){var e;return((e=this.call.peerConnection)==null?void 0:e.connectionState)==="connected"}get isOpening(){var e;return((e=this.call.peerConnection)==null?void 0:e.connectionState)==="connecting"}get isClosed(){return!this.isOpen}}const Qv=class extends Ks{constructor(i,e){super(),h(this,"id"),h(this,"context"),h(this,"_peer"),h(this,"_incomingCalls",[]),h(this,"_outgoingCalls",[]),h(this,"_enabled",!1),h(this,"_enabledPeer",!1),h(this,"onConnectRoomFn",this.onConnectRoom.bind(this)),h(this,"onPeerConnectFn",this.onPeerConnect.bind(this)),h(this,"onPeerReceiveCallFn",this.onPeerReceivingCall.bind(this)),this.context=i,this.id=e,this.setupPeer(),navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia}static getOrCreate(i,e){if(Qv.instances.has(e))return Qv.instances.get(e);const t=new Qv(i,e);return Qv.instances.set(e,t),t}getMyPeerId(){if(this.context.connection.connectionId)return this.getPeerIdFromUserId(this.context.connection.connectionId)}getPeerIdFromUserId(i){return this.id+"-"+i}getUserIdFromPeerId(i){return i.substring(this.id.length+1)}makeCall(i,e){var t;const s={metadata:{userId:this.context.connection.connectionId}},r=(t=this._peer)==null?void 0:t.call(i,e,s);if(r)return this.registerCall(r,"outgoing")}get peer(){return this._peer}enable(){this._enabled||(this._enabled=!0,this.context.connection.beginListen(di.JoinedRoom,this.onConnectRoomFn),this.subscribePeerEvents())}disable(){this._enabled&&(this._enabled=!1,this.context.connection.stopListen(di.JoinedRoom,this.onConnectRoomFn),this.unsubscribePeerEvents())}onConnectRoom(){this.setupPeer()}setupPeer(){if(this.context.connection.connectionId&&!this._enabledPeer){if(this._enabledPeer=!0,!this._peer){const i=this.getMyPeerId();i?this._peer=UU(i):console.error("Failed to setup peerjs because we dont have a connection id",this.context.connection.connectionId)}this._enabled&&this.subscribePeerEvents()}}subscribePeerEvents(){this._peer&&(this._peer.on("open",this.onPeerConnectFn),this._peer.on("call",this.onPeerReceiveCallFn))}unsubscribePeerEvents(){this._peer&&(this._peer.off("open",this.onPeerConnectFn),this._peer.off("call",this.onPeerReceiveCallFn))}onPeerConnect(i){Ef&&console.log("Peer connected as",i),this.context.connection.send("peer-user-connected",new Ure(this,i))}onPeerReceivingCall(i){i.answer(),this.registerCall(i,"incoming")}registerCall(i,e){const t=i.metadata;(!t||!t.userId)&&console.error("Missing call metadata",i);const s=t.userId;e==="incoming"&&Ef?console.log("Receive call from",i.metadata):Ef&&console.log("Make call to",i.metadata);const r=e==="incoming"?this._incomingCalls:this._outgoingCalls,n=new Fre(s,i,e);return r.push(n),i.on("error",o=>{console.error("Call error",o)}),i.on("close",()=>{Ef&&console.log("Call ended",i.metadata),i.close();const o=r.indexOf(n);o!==-1&&r.splice(o,1)}),n.addEventListener("call-ended",o=>{this.dispatchEvent(o)}),e==="incoming"&&(n.addEventListener("receive-stream",o=>{this.dispatchEvent(o)}),i.on("stream",()=>{let o=0;const a=setInterval(()=>{const l=o===0;!n.isOpen&&l&&(o+=1,clearInterval(a),n.close())},2e3)})),n}};let tx=Qv;h(tx,"instances",new Map);class ty extends Ks{constructor(e,t){super(),h(this,"context"),h(this,"peer"),h(this,"_sendingStreams",new Map),h(this,"debug",!1),h(this,"onJoinedRoom",s=>{this.debug&&console.log(`${s.userId} joined room and I'm currently sending ${this._sendingStreams.size} streams`),this._sendingStreams.size>0&&this.updateSendingCalls()}),h(this,"onReceiveStream",s=>{this.debug&&console.log("RECEIVE STREAM",s),this.dispatchEvent({type:"receive-stream",target:this,stream:s.stream,userId:s.userId})}),h(this,"onCallEnded",s=>{this.dispatchEvent(s)}),h(this,"onUserConnected",s=>{if(this.peer.id===s.guid){this.debug&&console.log("USER CONNECTED",s.guid,s);const r=this._sendingStreams.keys().next().value;this.peer.makeCall(s.peerId,r)}}),h(this,"onUserLeft",s=>{this.stopCallsToUsersThatAreNotInTheRoomAnymore()}),this.context=e,this.peer=t,Ef&&(this.debug=!0)}static create(e){const t=tx.getOrCreate(e.context,e.context.connection.connectionId);return new ty(e.context,t)}startSendingStream(e){this._sendingStreams.has(e)?console.warn("Received start sending stream with stream that is already being sent"):(this._sendingStreams.set(e,[]),this.updateSendingCalls())}stopSendingStream(e){if(e){const t=this._sendingStreams.get(e);if(t){this.debug&&console.log("Closing calls",t);for(const s of t)s.close()}this._sendingStreams.delete(e),t&&this.debug&&console.log("Currently sending",this._sendingStreams)}}enable(){this.peer.enable(),this.peer.addEventListener("receive-stream",this.onReceiveStream),this.peer.addEventListener("call-ended",this.onCallEnded),this.context.connection.beginListen("peer-user-connected",this.onUserConnected),this.context.connection.beginListen(di.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(di.UserJoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(di.UserLeftRoom,this.onUserLeft)}disable(){this.peer.disable(),this.peer.removeEventListener("receive-stream",this.onReceiveStream),this.peer.removeEventListener("call-ended",this.onCallEnded),this.context.connection.stopListen("peer-user-connected",this.onUserConnected),this.context.connection.stopListen(di.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(di.UserJoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(di.UserLeftRoom,this.onUserLeft)}updateSendingCalls(){var e;let t=!1;const s=this.context.connection.connectionId;for(const r of this._sendingStreams.keys()){const n=this._sendingStreams.get(r)||[];for(const o of this.context.connection.usersInRoom()){if(o===s)continue;const a=n.find(l=>l.userId===o);if(!a||((e=a.stream)==null?void 0:e.active)===!1){this.debug&&console.log("Starting call to",o,s);const l=this.peer.makeCall(this.peer.getPeerIdFromUserId(o),r);l&&(t=!0,n.push(l))}}this._sendingStreams.set(r,n)}this.stopCallsToUsersThatAreNotInTheRoomAnymore(),t&&this.debug&&console.log("Currently sending",this._sendingStreams)}stopCallsToUsersThatAreNotInTheRoomAnymore(){for(const e of this._sendingStreams.keys()){const t=this._sendingStreams.get(e);if(t)for(let s=t.length-1;s>=0;s--){const r=t[s];this.context.connection.userIsInRoom(r.userId)||(r.close(),t.splice(s,1))}}}}function Ac(i){if(i&&i instanceof MediaStream)for(const e of i.getTracks())e.stop()}var Nre=Object.defineProperty,zre=Object.getOwnPropertyDescriptor,hj=(i,e,t,s)=>{for(var r=s>1?void 0:s?zre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Nre(e,t,r),r};const jre="noVoip",Gre=te("debugvoip");class ld extends Pe{constructor(){super(...arguments),h(this,"autoConnect",!1),h(this,"runInBackground",!0),h(this,"debug",!1),h(this,"_net"),h(this,"_outputStream",null),h(this,"onJoinedRoom",async()=>{await Co(300),this.autoConnect&&!this.isSending&&this.connect()}),h(this,"_incomingStreams",new Map),h(this,"onReceiveStream",e=>{const t=e.target.userId,s=e.stream,r=this._incomingStreams.get(t);if(r)r.srcObject=s,r.setAttribute("autoplay","true");else{const n=new Audio;this._incomingStreams.set(t,n),n.setAttribute("autoplay","true"),n.srcObject=s}}),h(this,"onStreamEnded",e=>{const t=this._incomingStreams.get(e.userId);Ac(t?.srcObject),this._incomingStreams.delete(e.userId)}),h(this,"onEnabledChanged",()=>{for(const e of this._incomingStreams){const t=e[1];t.muted=!this.enabled}}),h(this,"onVisibilityChanged",()=>{if(this.runInBackground)return;const e=document.visibilityState!=="visible";this.setMuted(e);for(const t of this._incomingStreams){const s=t[1];s.muted=e}})}awake(){Gre&&(this.debug=!0),this.debug&&window.addEventListener("keydown",async e=>{e.key==="v"&&(console.log("MUTE?",!this.isMuted),this.setMuted(!this.isMuted))})}onEnable(){this._net||(this._net=ty.create(this)),this._net.addEventListener(nl.StreamReceived,this.onReceiveStream),this._net.addEventListener(nl.StreamEnded,this.onStreamEnded),this._net.enable(),this.autoConnect&&(this.context.connection.isConnected?this.connect():this.context.connection.beginListen(di.JoinedRoom,this.onJoinedRoom)),this.onEnabledChanged(),window.addEventListener("visibilitychange",this.onVisibilityChanged)}onDisable(){var e;this._net.stopSendingStream(this._outputStream),this._net.removeEventListener(nl.StreamReceived,this.onReceiveStream),this._net.removeEventListener(nl.StreamEnded,this.onStreamEnded),(e=this._net)==null||e.disable(),this.context.connection.stopListen(di.JoinedRoom,this.onJoinedRoom),this.onEnabledChanged(),window.removeEventListener("visibilitychange",this.onVisibilityChanged)}get isSending(){return this._outputStream!=null&&this._outputStream.active}async connect(e){if(this.context.connection.isConnected){if(!await wC())return console.error("Cannot connect to voice chat - microphone permissions not granted"),!1}else return console.error("Cannot connect to voice chat - not connected to server"),!1;return this._net.stopSendingStream(this._outputStream),Ac(this._outputStream),this._outputStream=await this.getAudioStream(e),this._outputStream?(this._net.startSendingStream(this._outputStream),!0):(await wC()?console.error("VOIP: Could not get audio stream - please make sure to connect an audio device and grant microphone permissions"):Xk("Microphone permissions not granted: Please grant microphone permissions to use voice chat"),!1)}disconnect(){this._net.stopSendingStream(this._outputStream),Ac(this._outputStream),this._outputStream=null}setMuted(e){var t;const s=(t=this._outputStream)==null?void 0:t.getAudioTracks();if(s)for(const r of s)r.enabled=!e}get isMuted(){var e;if(this._outputStream===null)return!1;const t=(e=this._outputStream)==null?void 0:e.getAudioTracks();if(t){for(const s of t)if(!s.enabled)return!0}return!1}getFrequency(e){return this.unsupported_getfrequency||(this.unsupported_getfrequency=!0,wt()&&is("VOIP: getFrequency is currently not supported"),console.warn("VOIP: getFrequency is currently not supported")),null}async getAudioStream(e){return navigator.mediaDevices.getUserMedia?await navigator.mediaDevices.getUserMedia({audio:e??!0,video:!1}).catch(t=>(console.warn("VOIP failed getting audio stream",t),null)):(console.error("No getDisplayMedia support"),null)}}hj([x()],ld.prototype,"autoConnect",2),hj([x()],ld.prototype,"runInBackground",2);var Qre=Object.defineProperty,Vre=Object.getOwnPropertyDescriptor,uj=(i,e,t,s)=>{for(var r=s>1?void 0:s?Vre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Qre(e,t,r),r};const Hre=te("debugmouth");class Vv extends Pe{constructor(){super(...arguments),h(this,"idle",[]),h(this,"talking",[]),h(this,"marker",null),h(this,"voip",null),h(this,"lastMouthChangeTime",0),h(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=oe.findObjectOfType(ld,this.context),this.marker||(this.marker=oe.getComponentInParent(this.gameObject,Tr))},3e3)}update(){var e;if(!this.voip||this.context.time.frameCount%10!==0)return;let t=((e=this.marker)==null?void 0:e.connectionId)??null;if(!t){Hre&&(t=null);return}const s=this.voip.getFrequency(t)??0;this.updateLips(s)}updateLips(e){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&e>30){this.lastMouthChangeTime=this.context.time.time;const t=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,t)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const t=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,t)}}}setMouthShapeActive(e,t){if(e){e!=this.idle?this.idle.map(s=>s.visible=!1):this.talking.map(s=>s.visible=!1);for(let s=0;s<e.length;s++){const r=e[s];r&&(r.visible=s===t)}}}}uj([x(ye)],Vv.prototype,"idle",2),uj([x(ye)],Vv.prototype,"talking",2);class CI extends Pe{constructor(){super(...arguments),h(this,"voip",null),h(this,"marker",null),h(this,"_startPosition",null)}awake(){this.voip=oe.findObjectOfType(ld,this.context),this.marker=oe.getComponentInParent(this.gameObject,Tr)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const e=this.marker.connectionId,t=this.voip.getFrequency(e);if(t==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());const s=t/100;this.gameObject.position.y=this._startPosition.y+s*.07}}var Wre=Object.defineProperty,Xre=Object.getOwnPropertyDescriptor,ix=(i,e,t,s)=>{for(var r=s>1?void 0:s?Xre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Wre(e,t,r),r};class cd extends Pe{constructor(){super(...arguments),h(this,"eyes",[]),h(this,"lastBlinkTime",0),h(this,"blinkLength",0),h(this,"eyesOpen",!0),h(this,"state",null)}awake(){this.state=oe.getComponentInParent(this.gameObject,ro)}update(){if(!(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)&&this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const e of this.eyes)e&&(e.visible=this.eyesOpen)}}}ix([x(ye)],cd.prototype,"eyes",2),ix([x()],cd.prototype,"lastBlinkTime",2),ix([x()],cd.prototype,"blinkLength",2),ix([x()],cd.prototype,"eyesOpen",2);var qre=Object.defineProperty,Yre=Object.getOwnPropertyDescriptor,EI=(i,e,t,s)=>{for(var r=s>1?void 0:s?Yre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&qre(e,t,r),r},MI;const dj=(MI=class extends Pe{constructor(){super(...arguments),h(this,"head",null),h(this,"eyes",null),h(this,"target",null),h(this,"brain",null),h(this,"vec",new w),h(this,"currentTargetPoint",new w)}awake(){this.brain||(this.brain=oe.getComponentInParent(this.gameObject,Gv)),this.brain||(console.log("No look at brain found, adding it now"),this.brain=oe.addNewComponent(this.gameObject,Gv)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const i=this.target;if(i&&this.head){const e=this.eyes;if(e){const t=Rt(i);this.currentTargetPoint.lerp(t,this.context.time.deltaTime/.1);const s=Rt(this.head),r=this.vec.copy(this.currentTargetPoint).sub(s).normalize();if(r.length()<.1)return;const n=dj.forward;if(n.set(0,0,1),n.applyQuaternion(Ii(this.head)),n.dot(r)>.45)for(let o=0;o<e.length;o++)e[o].lookAt(this.currentTargetPoint)}}}},h(MI,"forward",new w(0,0,1)),MI);let Mf=dj;EI([x(ye)],Mf.prototype,"head",2),EI([x(ye)],Mf.prototype,"eyes",2),EI([x(ye)],Mf.prototype,"target",2);const Hv=te("debugavatar");class sx{constructor(e,t,s,r){h(this,"root"),h(this,"head"),h(this,"leftHand"),h(this,"rigthHand");var n;this.root=e,this.head=t,this.leftHand=s,this.rigthHand=r,(n=this.root)==null||n.traverse(o=>o.layers.set(2))}get isValid(){return this.head!==null&&this.head!==void 0}}class TI{constructor(){h(this,"avatarRegistryUrl",null)}async getOrCreateNewAvatarInstance(e,t){if(!t)return console.error("Can not create avatar: failed to provide id or root object"),null;let s=null;if(typeof t=="string"){if(s=await this.loadAvatar(e,t),!s){const n=new Ia;s=oe.instantiate(Ip(t,e.scene),n)}}else s=t;if(!s)return null;const r=this.findAvatar(s);return r.isValid?(Hv&&console.log("[Custom Avatar] valid config",t,Hv?r:""),r):(console.warn("[Custom Avatar] config isn't valid",t,Hv?r:""),null)}async loadAvatar(e,t){if(console.assert(t!=null&&typeof t=="string","Avatar id must not be null"),t.length<=0||!t)return null;if(Hv&&console.log("[Custom Avatar] "+t+", loading..."),t.endsWith(".glb")||(t+=".glb"),this.avatarRegistryUrl===null){const r=await fetch("./"+t);let n=null;if(r.ok){const a=await r.blob();a&&(n=await a.arrayBuffer())}if(!n&&(n=await mE(t,t,0,"no url here go away",!0),!n))return null;const o=await ta().parseSync(e,n,null,0);return o?.scene??null}const s=new sf;return dv(s,e),new Promise((r,n)=>{const o=this.avatarRegistryUrl+"/"+t;s.load(o,async a=>{await ta().createBuiltinComponents(e,o,a,null,void 0),r(a.scene)},a=>{Hv&&console.log("[Custom Avatar] "+a.loaded/a.total*100+"% loaded of "+a.total/1024+"kB")},a=>{console.error("[Custom Avatar] Error when loading: "+a),r(null)})})}cacheModel(e,t){}findAvatar(e){const t=e;let s=t;s.children.length==1&&(s=e.children[0]);let r=this.findAvatarPart(s,["head"]);const n=this.findAvatarPart(s,["left","hand"]),o=this.findAvatarPart(s,["right","hand"]);if(!r){r=t;const a=new w;new Mi().setFromObject(r).getSize(a);const l=Math.max(a.x,a.y,a.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+l+" meters! Should be < 0.3m"),l>.3&&r.scale.multiplyScalar(1/l*.3)}return new sx(t,r,n,o)}findAvatarPart(e,t){const s=e.name.toLowerCase();let r=!0;for(const n of t){if(!r)break;s.indexOf(n)===-1&&(r=!1)}if(r)return e;if(e.children)for(const n of e.children){const o=this.findAvatarPart(n,t);if(o)return o}return null}handleCustomAvatarErrors(e){if(!e.ok)throw Error(e.statusText);return e}}var Jre=Object.defineProperty,Kre=Object.getOwnPropertyDescriptor,II=(i,e,t,s)=>{for(var r=s>1?void 0:s?Kre(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Jre(e,t,r),r};class Tf extends Pe{constructor(){super(...arguments),h(this,"length",1),h(this,"depthTest",!0),h(this,"isGizmo",!0),h(this,"_axes",null)}onEnable(){if(this.isGizmo&&!xg)return;this._axes||(this._axes=new wo(this.length)),this._axes.layers.disableAll(),this._axes.layers.set(this.layer),this.gameObject.add(this._axes);const e=this._axes.material;e&&e.depthTest!==void 0&&(e.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}II([x()],Tf.prototype,"length",2),II([x()],Tf.prototype,"depthTest",2),II([x()],Tf.prototype,"isGizmo",2);class RI extends Pe{constructor(){super(...arguments),h(this,"from"),h(this,"to"),h(this,"hint"),h(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;const e=Rt(this.to).clone(),t=Rt(this.from).clone(),s=e.distanceTo(t),r=e.clone();r.sub(t);const n=t.clone();n.add(e),n.multiplyScalar(.5);const o=Rt(this.hint).clone();o.sub(n);const a=new w;a.crossVectors(o,r),a.crossVectors(r,a),a.normalize();const l=s*.5,c=Math.max(this.desiredDistance,l),u=Math.sqrt(c*c-l*l),d=a.clone();d.multiplyScalar(u),d.add(n),Kr(this.gameObject,d);const p=n.clone();p.sub(a),this.gameObject.lookAt(p)}}const Zre=te("debugusdz");class rx{constructor(){h(this,"behaviours",[]),h(this,"behaviourComponents",[]),h(this,"behaviourComponentsCopy",[])}get extensionName(){return"Behaviour"}addBehavior(e){this.behaviours.push(e)}onBeforeBuildDocument(e){const t=[];return e.root.traverse(s=>{oe.foreachComponent(s,r=>{var n;const o=r;if(typeof o.createBehaviours=="function"||typeof o.beforeCreateDocument=="function"||typeof o.afterCreateDocument=="function"||typeof o.afterSerialize=="function"){this.behaviourComponents.push(o);const a=(n=o.beforeCreateDocument)==null?void 0:n.call(o,this,e);a instanceof Promise&&t.push(a)}},!1)}),Promise.all(t)}onExportObject(e,t,s){var r;for(const n of this.behaviourComponents)(r=n.createBehaviours)==null||r.call(n,this,t,s)}onAfterBuildDocument(e){for(const t of this.behaviourComponents)typeof t.afterCreateDocument=="function"&&t.afterCreateDocument(this,e);this.behaviourComponentsCopy=this.behaviourComponents.slice(),this.behaviourComponents.length=0}onAfterHierarchy(e,t){var s;if((s=this.behaviours)!=null&&s.length){t.beginBlock('def Scope "Behaviors"');for(const r of this.behaviours)r.writeTo(this,e.document,t);t.closeBlock()}}async onAfterSerialize(e){Zre&&console.log("onAfterSerialize behaviours",this.behaviourComponentsCopy);for(const t of this.behaviourComponentsCopy)typeof t.afterSerialize=="function"&&(t.afterSerialize.constructor.name==="AsyncFunction"?await t.afterSerialize(this,e):t.afterSerialize(this,e));this.behaviours.length=0}}var $re=Object.defineProperty,ene=Object.getOwnPropertyDescriptor,PI=(i,e,t,s)=>{for(var r=s>1?void 0:s?ene(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&$re(e,t,r),r};class hd extends en{constructor(){super(...arguments),h(this,"threshold"),h(this,"intensity"),h(this,"scatter"),h(this,"selectiveBloom",!0)}get typeName(){return"Bloom"}init(){this.threshold.defaultValue=1,this.intensity.defaultValue=0,this.scatter.defaultValue=.2,this.selectiveBloom?(this.threshold.valueProcessor=e=>e,this.intensity.valueProcessor=e=>e,this.scatter.valueProcessor=e=>1*Math.PI*(1-e)):(this.threshold.valueProcessor=e=>e,this.intensity.valueProcessor=e=>e,this.scatter.valueProcessor=e=>100*(1-e))}onCreateEffect(){let e;if(this.selectiveBloom){const t=e=new FO(this.context.scene,this.context.mainCamera,{blendFunction:Wt.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,intensity:this.intensity.value});t.inverted=!0}else e=new rE;return this.intensity.onValueChanged=t=>{e.intensity=t},this.threshold.onValueChanged=t=>{e.luminanceMaterial.threshold=t},this.scatter.onValueChanged=t=>{e.luminancePass.enabled=!0,e.luminanceMaterial.smoothing=t},e}}PI([x(Bt)],hd.prototype,"threshold",2),PI([x(Bt)],hd.prototype,"intensity",2),PI([x(Bt)],hd.prototype,"scatter",2),Vo("Bloom",hd);var tne=Object.defineProperty,ine=Object.getOwnPropertyDescriptor,jn=(i,e,t,s)=>{for(var r=s>1?void 0:s?ine(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&tne(e,t,r),r};class Xo extends Pe{constructor(){super(...arguments),h(this,"attachedRigidbody",null),h(this,"isTrigger",!1),h(this,"sharedMaterial"),h(this,"membership",[0]),h(this,"filter"),h(this,"updateProperties",()=>{var e;(e=this.context.physics.engine)==null||e.updateProperties(this)})}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ni))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ni))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Ni))}onDisable(){var e;(e=this.context.physics.engine)==null||e.removeBody(this)}get body(){var e;return(e=this.context.physics.engine)==null?void 0:e.getBody(this)}updatePhysicsMaterial(){var e;(e=this.context.physics.engine)==null||e.updatePhysicsMaterial(this)}}jn([x(Ni)],Xo.prototype,"attachedRigidbody",2),jn([x()],Xo.prototype,"isTrigger",2),jn([x()],Xo.prototype,"sharedMaterial",2),jn([x()],Xo.prototype,"membership",2),jn([x()],Xo.prototype,"filter",2);class Wv extends Xo{constructor(){super(...arguments),h(this,"radius",.5),h(this,"center",new w(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addSphereCollider(this),H0(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),xC(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}jn([Sr(),x()],Wv.prototype,"radius",2),jn([x(w)],Wv.prototype,"center",2);class Xv extends Xo{constructor(){super(...arguments),h(this,"size",new w(1,1,1)),h(this,"center",new w(0,0,0))}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addBoxCollider(this,this.size),H0(this.gameObject.scale,this.updateProperties)}onDisable(){super.onDisable(),xC(this.gameObject.scale,this.updateProperties)}onValidate(){this.updateProperties()}}jn([Sr(),x(w)],Xv.prototype,"size",2),jn([x(w)],Xv.prototype,"center",2);class If extends Xo{constructor(){super(...arguments),h(this,"sharedMesh"),h(this,"convex",!1)}onEnable(){var e,t,s,r,n;if(super.onEnable(),(e=this.sharedMesh)!=null&&e.isMesh||this.gameObject instanceof ve&&(this.sharedMesh=this.gameObject),(t=this.sharedMesh)!=null&&t.isMesh)(s=this.context.physics.engine)==null||s.addMeshCollider(this,this.sharedMesh,this.convex,ss(this.gameObject));else{const o=this.sharedMesh;if(o!=null&&o.isGroup){console.warn(`MeshCollider mesh is a group "${((r=this.sharedMesh)==null?void 0:r.name)||this.gameObject.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);for(const a in o.children){const l=o.children[a];l.isMesh&&((n=this.context.physics.engine)==null||n.addMeshCollider(this,l,this.convex,ss(this.gameObject)))}}}}}jn([x()],If.prototype,"sharedMesh",2),jn([x()],If.prototype,"convex",2);class Ph extends Xo{constructor(){super(...arguments),h(this,"center",new w(0,0,0)),h(this,"radius",.5),h(this,"height",2)}onEnable(){var e;super.onEnable(),(e=this.context.physics.engine)==null||e.addCapsuleCollider(this,this.height,this.radius)}}jn([x(w)],Ph.prototype,"center",2),jn([x()],Ph.prototype,"radius",2),jn([x()],Ph.prototype,"height",2);var sne=Object.defineProperty,rne=Object.getOwnPropertyDescriptor,BI=(i,e,t,s)=>{for(var r=s>1?void 0:s?rne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&sne(e,t,r),r};class ud extends Pe{constructor(){super(...arguments),h(this,"objectBounds",!1),h(this,"color"),h(this,"isGizmo",!0),h(this,"_gizmoObject",null),h(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!xg||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new fC(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=iT(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),ks.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){for(var e;this._boxHelper;)(e=this._boxHelper)==null||e.update(),yield}}BI([x()],ud.prototype,"objectBounds",2),BI([x(xe)],ud.prototype,"color",2),BI([x()],ud.prototype,"isGizmo",2);class nne extends wN{constructor(e,t={}){super(e),e._simpleState__activeStates=[],e._simpleState__normalStyles={},e._simpleState__states=t,e._simpleState__statesProperties={};for(const s in t)for(const r in t[s])e._simpleState__statesProperties[r]||(e._simpleState__statesProperties[r]=[]),e._simpleState__statesProperties[r].push(s);for(const s of e._components)e._simpleState__statesProperties[s.id]&&(e._simpleState__normalStyles[s.id]=s.inline?s.inline:s._value);e.__overridedSet=e.set,e.set=this.storeSet.bind(e),e.renderStates=this.renderStates.bind(e),e.setupState=this.setupState.bind(e),e.setState=this.setState.bind(e),e.activatePseudoState=this.activatePseudoState.bind(e),e.deactivatePseudoState=this.deactivatePseudoState.bind(e),e.togglePseudoState=this.togglePseudoState.bind(e)}act(){}attach(){}detach(){}setupState(e,t){this._simpleState__states[e]=t;const s=[];for(const r in t)this._simpleState__statesProperties[r]||(this._simpleState__statesProperties[r]=[],s.push(r)),this._simpleState__statesProperties[r].push(e);for(const r of this._components)s.indexOf(r.id)>-1&&(this._simpleState__normalStyles[r.id]=r.inline?r.inline:r._value)}renderStates(){let e={...this._simpleState__normalStyles};for(const t in this._simpleState__states)this._simpleState__activeStates.indexOf(t)>-1&&(e={...e,...this._simpleState__states[t]});this.set(e,!1)}storeSet(e,t=!0){if(t)for(const s in e)this._simpleState__statesProperties[s]&&(this._simpleState__normalStyles[s]=e[s]);this.__overridedSet(e)}activatePseudoState(e){this._simpleState__activeStates.indexOf(e)===-1&&(this._simpleState__activeStates.push(e),this.renderStates())}deactivatePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1&&(this._simpleState__activeStates.splice(t,1),this.renderStates())}togglePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1?this._simpleState__activeStates.splice(t,1):this._simpleState__activeStates.push(e),this.renderStates()}setState(e){Array.isArray(e)?this._simpleState__activeStates=e:this._simpleState__activeStates=[e],this.renderStates()}}var one=Object.defineProperty,ane=Object.getOwnPropertyDescriptor,pj=(i,e,t,s)=>{for(var r=s>1?void 0:s?ane(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&one(e,t,r),r};class Rf extends Pe{constructor(){super(...arguments),h(this,"effectColor"),h(this,"effectDistance")}}pj([x(Si)],Rf.prototype,"effectColor",2),pj([x(ee)],Rf.prototype,"effectDistance",2);var lne=Object.defineProperty,cne=Object.getOwnPropertyDescriptor,qv=(i,e,t,s)=>{for(var r=s>1?void 0:s?cne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&lne(e,t,r),r};const DI=te("debugui"),kI=te("debuguilayout");class OI{constructor(){h(this,"width"),h(this,"height")}}class LI{constructor(){h(this,"x"),h(this,"y"),h(this,"width"),h(this,"height")}}const wa=new w,Yv=new Te,nx=new Ie,fj=class extends Ra{constructor(){super(...arguments),h(this,"_anchoredPosition"),h(this,"sizeDelta",new ee(100,100)),h(this,"pivot",new ee(.5,.5)),h(this,"anchorMin",new ee(0,0)),h(this,"anchorMax",new ee(1,1)),h(this,"minWidth"),h(this,"minHeight"),h(this,"lastMatrix"),h(this,"rectBlock"),h(this,"_transformNeedsUpdate",!1),h(this,"_initialPosition"),h(this,"_parentRectTransform"),h(this,"_lastUpdateFrame",-1),h(this,"_lastAnchoring"),h(this,"_createdBlocks",[]),h(this,"_createdTextBlocks",[])}get parent(){return this._parentRectTransform}get translation(){return this.gameObject.position}get rotation(){return this.gameObject.quaternion}get scale(){return this.gameObject.scale}get anchoredPosition(){return this._anchoredPosition||(this._anchoredPosition=new ee),this._anchoredPosition}set anchoredPosition(i){this._anchoredPosition=i}get width(){let i=this.sizeDelta.x;if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const e=this._parentRectTransform.width,t=this.anchorMax.x-this.anchorMin.x;i=e*t,i+=this.sizeDelta.x}return this.minWidth!==void 0&&i<this.minWidth?this.minWidth:i}get height(){let i=this.sizeDelta.y;if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const e=this._parentRectTransform.height,t=this.anchorMax.y-this.anchorMin.y;i=e*t,i+=this.sizeDelta.y}return this.minHeight!==void 0&&i<this.minHeight?this.minHeight:i}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new ee),this.lastMatrix=new Te,this.rectBlock=new ye,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,yf(this,"_anchoredPosition",()=>{this.markDirty()}),yf(this,"sizeDelta",()=>{this.markDirty()}),yf(this,"pivot",()=>{this.markDirty()}),yf(this,"anchorMin",()=>{this.markDirty()}),yf(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var i;super.onEnable(),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(i=this.Canvas)==null||i.registerTransform(this)}onDisable(){var i;super.onDisable(),this.removeShadowComponent(),(i=this.Canvas)==null||i.unregisterTransform(this)}onParentRectTransformChanged(i){this._transformNeedsUpdate||this.onApplyTransform(kI?`${i.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(kI&&console.warn("RectTransform markDirty()",this.name),this._transformNeedsUpdate=!0,this._lastUpdateFrame=-1)}updateTransform(){(this._transformNeedsUpdate||!this.lastMatrix.equals(this.gameObject.matrix))&&this.canUpdate()&&this.onApplyTransform(this._transformNeedsUpdate?"Marked dirty":"Matrix changed")}canUpdate(){return this._transformNeedsUpdate&&this.activeAndEnabled&&this._lastUpdateFrame!==this.context.time.frame}onApplyTransform(i){var e;if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const t=this.shadowComponent;if(!t)return;this.gameObject.parent?this._parentRectTransform=oe.getComponentInParent(this.gameObject.parent,fj):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,kI&&console.warn("RectTransform \u2192 ApplyTransform",this.name+" because "+i),this.isRoot()?this.Root.screenspace||(t.rotation.y=Math.PI):(t.matrix.identity(),t.matrixAutoUpdate=!1,wa.set(0,0,0),this.applyPivot(wa),t.matrix.setPosition(wa.x,wa.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(nx.copy(this.gameObject.quaternion),nx.x*=-1,nx.z*=-1,Yv.makeRotationFromQuaternion(nx),t.matrix.premultiply(Yv)),wa.set(0,0,0),this.applyAnchoring(wa),(e=this.Canvas)!=null&&e.screenspace?wa.z+=.1:wa.z+=.01,Yv.identity(),Yv.setPosition(wa.x,wa.y,wa.z),t.matrix.premultiply(Yv),t.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const s=!0;for(const r of hT(this.gameObject,Ra,s,1)){if(r===this||!r.activeAndEnabled)continue;const n=r;n.onParentRectTransformChanged&&n.onParentRectTransformChanged(this)}}applyAnchoring(i){this._lastAnchoring||(this._lastAnchoring=new ee);const e=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=e.x,this.gameObject.position.y+=e.y,this._lastAnchoring.copy(this._anchoredPosition),i.x+=this._initialPosition.x-this.gameObject.position.x,i.y+=this._initialPosition.y-this.gameObject.position.y,i.z+=this._initialPosition.z-this.gameObject.position.z;const t=this._parentRectTransform;if(t){let s=0;const r=1-this.anchorMax.y-this.anchorMin.y;s-=t.height*.5*r,i.y+=s;let n=0;const o=1-this.anchorMax.x-this.anchorMin.x;n-=t.width*.5*o,i.x+=n}}applyPivot(i){if(this.pivot&&!this.isRoot()){const e=this.pivot.x-.5;i.x-=e*this.sizeDelta.x*this.gameObject.scale.x;const t=this.pivot.y-.5;i.y-=t*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const i={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:0,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(i),i}ensureValidSize(i,e=1e-4){return i.width<=0&&(i.width=e),i.height<=0&&(i.height=1e-4),i}createNewBlock(i){i={...this.getBasicOptions(),...i},DI&&console.log(this.name,i);const e=new jM(i);return this._createdBlocks.push(e),e}createNewText(i){DI&&console.log(i),i={...this.getBasicOptions(),...i},DI&&console.log(this.name,i);const e=new QM(i);return this._createdTextBlocks.push(e),e}};let _n=fj;qv([x(ee)],_n.prototype,"anchoredPosition",1),qv([x(ee)],_n.prototype,"sizeDelta",2),qv([x(ee)],_n.prototype,"pivot",2),qv([x(ee)],_n.prototype,"anchorMin",2),qv([x(ee)],_n.prototype,"anchorMax",2);var hne=Object.defineProperty,une=Object.getOwnPropertyDescriptor,mj=(i,e,t,s)=>{for(var r=s>1?void 0:s?une(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&hne(e,t,r),r};const ox={backgroundColor:new xe(1,1,1),backgroundOpacity:1,borderColor:new xe(1,1,1),borderOpacity:1};var UI;const ax=(UI=class extends Ra{constructor(){super(...arguments),h(this,"_alphaFactor",1),h(this,"sRGBColor",new xe(1,0,1)),h(this,"raycastTarget",!0),h(this,"uiObject",null),h(this,"_color",null),h(this,"_rect",null),h(this,"_stateManager",null),h(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new Si(1,1,1,1)),this._color}set color(i){(!this._color||this._color.r!==i.r||this._color.g!==i.g||this._color.b!==i.b||this._color.alpha!==i.alpha)&&(this._color||(this._color=new Si(1,1,1,1)),this._color.copy(i),this.onColorChanged())}setAlphaFactor(i){this._alphaFactor=i,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(this.sRGBColor.copy(this._color),this.sRGBColor.convertLinearToSRGB(),ox.backgroundColor=this.sRGBColor,ox.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(ox,this._alphaFactor),this.uiObject.set(ox),this.markDirty())}get m_Color(){return this._color}get rectTransform(){if(this._rect||(this._rect=oe.getComponent(this.gameObject,_n)),!this._rect)throw new Error("Not Supported: Make sure to add a RectTransform component before adding a UI Graphic component.");return this._rect}onParentRectTransformChanged(){var i;(i=this.uiObject)==null||i.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone())}setState(i){this.makePanel(),this.uiObject&&(this.uiObject.setState(i),this==null||this.markDirty())}setupState(i){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new nne(this.uiObject)),this.uiObject.setupState(i.state,i.attributes))}setOptions(i){this.makePanel(),this.uiObject&&this.uiObject.set(i)}awake(){super.awake(),this.makePanel(),yf(this,"_color",()=>jse(this,this.onColorChanged))}onEnable(){var i;super.onEnable(),this.uiObject&&((i=this.rectTransform.shadowComponent)==null||i.add(this.uiObject),this.addShadowComponent(this.uiObject,this.rectTransform))}onDisable(){super.onDisable(),this.uiObject&&this.removeShadowComponent()}makePanel(){if(this.uiObject||this._currentlyCreatingPanel)return;this._currentlyCreatingPanel=!0;const i=.015,e={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:i};this.onBeforeCreate(e),this.applyEffects(e),this.onCreate(e),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated(),this.onColorChanged()}onBeforeCreate(i){}onCreate(i){this.uiObject=this.rectTransform.createNewBlock(i),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(i,e=1){var t;const s=(t=this.gameObject)==null?void 0:t.getComponent(Rf);s&&(s.effectDistance&&(i.borderWidth=Math.max(Math.abs(s.effectDistance.x),Math.abs(s.effectDistance.y))),s.effectColor&&(i.borderColor=s.effectColor,i.borderOpacity=s.effectColor.alpha*e))}async setTexture(i){if(this.setOptions({backgroundOpacity:0}),i){if(ax.textureCache.has(i))i=ax.textureCache.get(i);else if(!i.isRenderTargetTexture){const e=i.clone();e.colorSpace=Ei,ax.textureCache.set(i,e),i=e}this.setOptions({backgroundImage:i,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"})}else this.setOptions({backgroundImage:null,borderRadius:0,backgroundOpacity:this.color.alpha});this.markDirty()}onAfterAddedToScene(){super.onAfterAddedToScene(),this.shadowComponent&&(this.shadowComponent.offset=this.shadowComponent.position.z)}},h(UI,"textureCache",new Map),UI);let dd=ax;mj([x(Si)],dd.prototype,"color",1),mj([x()],dd.prototype,"raycastTarget",2);class Jv extends dd{constructor(){super(...arguments),h(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var dne=Object.defineProperty,pne=Object.getOwnPropertyDescriptor,lx=(i,e,t,s)=>{for(var r=s>1?void 0:s?pne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&dne(e,t,r),r};let FI=class{constructor(){h(this,"texture",null),h(this,"rect")}};lx([x(Nt)],FI.prototype,"texture",2);let Pf=class extends Jv{constructor(){super(...arguments),h(this,"_sprite"),h(this,"pixelsPerUnitMultiplier",1)}set image(i){this.sprite||(this.sprite=new FI),this.sprite.texture=i,this.onAfterCreated()}get image(){return this.sprite?this.sprite.texture:null}get sprite(){return this._sprite}set sprite(i){this._sprite!==i&&(this._sprite=i,this.onAfterCreated())}isBuiltinSprite(){var i,e,t,s,r,n,o,a,l,c,u;switch((e=(i=this.sprite)==null?void 0:i.texture)==null?void 0:e.name){case"InputFieldBackground":case"UISprite":case"Background":case"Knob":return!0}return!((r=(s=(t=this.sprite)==null?void 0:t.texture)==null?void 0:s.name)!=null&&r.length)&&((a=(o=(n=this.sprite)==null?void 0:n.texture)==null?void 0:o.image)==null?void 0:a.width)===32&&((u=(c=(l=this.sprite)==null?void 0:l.texture)==null?void 0:c.image)==null?void 0:u.height)===32}onBeforeCreate(i){var e,t;super.onBeforeCreate(i),this.isBuiltinSprite()&&(i.borderRadius=5/this.pixelsPerUnitMultiplier,((t=(e=this.sprite)==null?void 0:e.texture)==null?void 0:t.name)==="Knob"&&(i.borderRadius=999))}onAfterCreated(){var i;this.__didAwake&&(super.onAfterCreated(),!this.isBuiltinSprite()&&this.setTexture((i=this.sprite)==null?void 0:i.texture))}};lx([x(FI)],Pf.prototype,"sprite",1),lx([x()],Pf.prototype,"pixelsPerUnitMultiplier",2);class cx extends Jv{constructor(){super(...arguments),h(this,"_mainTexture")}get mainTexture(){return this._mainTexture}set mainTexture(e){this._mainTexture!==e&&(this._mainTexture=e,this.onAfterCreated())}onAfterCreated(){this.__didAwake&&(super.onAfterCreated(),this.setTexture(this.mainTexture))}}lx([x(Nt)],cx.prototype,"mainTexture",1);var fne=Object.defineProperty,mne=Object.getOwnPropertyDescriptor,no=(i,e,t,s)=>{for(var r=s>1?void 0:s?mne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&fne(e,t,r),r};const pd=te("debugbutton");class fd{constructor(){h(this,"colorMultiplier"),h(this,"disabledColor"),h(this,"fadeDuration"),h(this,"highlightedColor"),h(this,"normalColor"),h(this,"pressedColor"),h(this,"selectedColor")}}no([x()],fd.prototype,"colorMultiplier",2),no([x(Si)],fd.prototype,"disabledColor",2),no([x()],fd.prototype,"fadeDuration",2),no([x(Si)],fd.prototype,"highlightedColor",2),no([x(Si)],fd.prototype,"normalColor",2),no([x(Si)],fd.prototype,"pressedColor",2),no([x(Si)],fd.prototype,"selectedColor",2);class yc extends Pe{constructor(){super(...arguments),h(this,"onClick"),h(this,"_isHovered",0),h(this,"colors"),h(this,"transition"),h(this,"animationTriggers"),h(this,"animator"),h(this,"_interactable",!0),h(this,"_requestedAnimatorTrigger"),h(this,"_isInit",!1),h(this,"_image")}onPointerEnter(e){var t,s;this._isHovered+=1,pd&&console.warn("Button Enter",this._isHovered,(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.highlightedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("hovered")),this.context.input.setCursorPointer())}onPointerExit(){var e,t;this._isHovered-=1,pd&&console.log("Button Exit",this._isHovered,(e=this.animationTriggers)==null?void 0:e.highlightedTrigger,this.animator),this.interactable&&(this._isHovered>0||(this._isHovered=0,this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((t=this._image)==null||t.setState("normal")),this.context.input.setCursorNormal()))}onPointerDown(e){var t,s;pd&&console.log("Button Down",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.pressedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("pressed")))}onPointerUp(e){var t,s;pd&&console.warn("Button Up",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator,this._isHovered),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this._isHovered?this.animationTriggers.highlightedTrigger:this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState(this._isHovered?"hovered":"normal")))}onPointerClick(e){if(this.interactable&&!(e.button!==0&&e.event.pointerType===vE.Mouse)&&(pd&&(console.warn("Button Click",this.onClick),ms("CLICKED button "+this.name+" at "+this.context.time.frameCount)),this.onClick&&this.onClick.listenerCount>0&&(this.onClick.invoke(),e.use(),pd))){const t=this.gameObject.worldPosition;t.add(this.gameObject.worldUp.multiplyScalar(1+Math.random()*.5)),Pt.DrawLabel(t,"CLICK:"+Date.now(),.1,1+Math.random()*.5)}}set interactable(e){this._interactable=e,this._image&&(this._image.setInteractable(e),e?this._image.setState("normal"):this._image.setState("disabled"))}get interactable(){return this._interactable}set_interactable(e){this.interactable=e}awake(){super.awake(),pd&&console.log(this),this._isInit=!1,this.init()}start(){var e;(e=this._image)==null||e.setInteractable(this.interactable),this.gameObject.getComponentInParent(Cv)||this.gameObject.addComponent(N_)}onEnable(){super.onEnable()}onDestroy(){this._isHovered&&this.context.input.setCursorNormal()}*setAnimatorTriggerAtEndOfFrame(e){var t;this._requestedAnimatorTrigger=e,yield,yield,this._requestedAnimatorTrigger==e&&((t=this.animator)==null||t.SetTrigger(e))}init(){this._isInit||(this._isInit=!0,this._image=oe.getComponent(this.gameObject,Pf),this._image&&(this.stateSetup(this._image),this.interactable?this._image.setState("normal"):this._image.setState("disabled")))}stateSetup(e){var t,s,r,n,o;e.setInteractable(this.interactable);const a=this.getFinalColor(e.color,(t=this.colors)==null?void 0:t.normalColor),l={state:"normal",attributes:{backgroundColor:a,backgroundOpacity:a.alpha}};e.setupState(l);const c=this.getFinalColor(e.color,(s=this.colors)==null?void 0:s.highlightedColor),u={state:"hovered",attributes:{backgroundColor:c,backgroundOpacity:c.alpha}};e.setupState(u);const d=this.getFinalColor(e.color,(r=this.colors)==null?void 0:r.pressedColor),p={state:"pressed",attributes:{backgroundColor:d,backgroundOpacity:d.alpha}};e.setupState(p);const f=this.getFinalColor(e.color,(n=this.colors)==null?void 0:n.selectedColor),m={state:"selected",attributes:{backgroundColor:f,backgroundOpacity:f.alpha}};e.setupState(m);const A=this.getFinalColor(e.color,(o=this.colors)==null?void 0:o.disabledColor),y={state:"disabled",attributes:{backgroundColor:A,backgroundOpacity:A.alpha}};e.setupState(y)}getFinalColor(e,t){return t?e.clone().multiply(t).convertLinearToSRGB():e.clone().convertLinearToSRGB()}}no([x(tr)],yc.prototype,"onClick",2),no([x()],yc.prototype,"colors",2),no([x()],yc.prototype,"transition",2),no([x()],yc.prototype,"animationTriggers",2),no([x(Er)],yc.prototype,"animator",2),no([x()],yc.prototype,"interactable",1);var gne=Object.defineProperty,vne=Object.getOwnPropertyDescriptor,Os=(i,e,t,s)=>{for(var r=s>1?void 0:s?vne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&gne(e,t,r),r};const gj=te("debuguilayout");class Bh{constructor(){h(this,"left",0),h(this,"right",0),h(this,"top",0),h(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Os([x()],Bh.prototype,"left",2),Os([x()],Bh.prototype,"right",2),Os([x()],Bh.prototype,"top",2),Os([x()],Bh.prototype,"bottom",2);class oo extends Pe{constructor(){super(...arguments),h(this,"_rectTransform",null),h(this,"_needsUpdate",!1),h(this,"childAlignment",0),h(this,"reverseArrangement",!1),h(this,"spacing",0),h(this,"padding"),h(this,"minWidth",0),h(this,"minHeight",0),h(this,"flexibleHeight",0),h(this,"flexibleWidth",0),h(this,"preferredHeight",0),h(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(e){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(gj&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){gj&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(_n);const e=this.gameObject.getComponentInParent(Ir);e&&e.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const e=this.gameObject.getComponentInParent(Ir);e&&e.unregisterLayoutGroup(this)}set m_Spacing(e){e!==this.spacing&&(this._needsUpdate=!0,this.spacing=e)}get m_Spacing(){return this.spacing}}Os([x()],oo.prototype,"childAlignment",2),Os([x()],oo.prototype,"reverseArrangement",2),Os([x()],oo.prototype,"spacing",2),Os([x(Bh)],oo.prototype,"padding",2),Os([x()],oo.prototype,"minWidth",2),Os([x()],oo.prototype,"minHeight",2),Os([x()],oo.prototype,"flexibleHeight",2),Os([x()],oo.prototype,"flexibleWidth",2),Os([x()],oo.prototype,"preferredHeight",2),Os([x()],oo.prototype,"preferredWidth",2);class Dh extends oo{constructor(){super(...arguments),h(this,"childControlHeight",!0),h(this,"childControlWidth",!0),h(this,"childForceExpandHeight",!1),h(this,"childForceExpandWidth",!1),h(this,"childScaleHeight",!1),h(this,"childScaleWidth",!1)}onCalculateLayout(e){var t;const s=this.primaryAxis,r=e.width;let n=r;const o=e.height;let a=o;n-=this.padding.horizontal,a-=this.padding.vertical,s==="x"?this.padding.horizontal:this.padding.vertical;const l=s==="x",c=l?"y":"x",u=l?this.childControlWidth:this.childControlHeight,d=l?this.childControlHeight:this.childControlWidth,p=l?this.childForceExpandWidth:this.childForceExpandHeight,f=l?this.childForceExpandHeight:this.childForceExpandWidth,m=l?a:n,A=l?r:o,y=.5*(l?this.childAlignment%3:Math.floor(this.childAlignment/3));let g=0;l?g+=this.padding.left:g+=this.padding.top;let v=0,b=0;for(let R=0;R<this.gameObject.children.length;R++){const I=this.gameObject.children[R],E=oe.getComponent(I,_n);E!=null&&E.activeAndEnabled&&(b+=1,l?v+=E.width:v+=E.height)}let _=0;const S=this.spacing*(b-1);if(p||u){let R=0;l?R=n-=S:R=a-=S,b>0&&(_=R/b)}let M=0;M+=this.padding.left,M-=this.padding.right,y!==0&&(g=A-v,g*=y,g-=S*y,l?(g-=this.padding.right*y,g+=this.padding.left*(1-y),g<this.padding.left&&(g=this.padding.left)):(g-=this.padding.bottom*y,g+=this.padding.top*(1-y),g<this.padding.top&&(g=this.padding.top)));let C=1;for(let R=0;R<this.gameObject.children.length;R++){const I=this.gameObject.children[R],E=oe.getComponent(I,_n);if(E!=null&&E.activeAndEnabled){(t=E.pivot)==null||t.set(.5,.5),E.anchorMin.set(0,1),E.anchorMax.set(0,1);const z=r*.5+M*.5;E.anchoredPosition.x!==z&&(E.anchoredPosition.x=z);const F=o*-.5;E.anchoredPosition.y!==F&&(E.anchoredPosition.y=F),f&&d&&E.sizeDelta[c]!==m&&(E.sizeDelta[c]=m),p&&u&&E.sizeDelta[s]!==_&&(E.sizeDelta[s]=_);const q=l?E.width:E.height,N=q*.5;if(g+=N,p){const L=_*C-_*.5;L>g&&(g=L-_*.5+q+this.padding.left,g-=N)}let H=g;s==="y"&&(H=-H),E.anchoredPosition[s]!==H&&(E.anchoredPosition[s]=H),g+=N,g+=this.spacing,C+=1}}}}Os([x()],Dh.prototype,"childControlHeight",2),Os([x()],Dh.prototype,"childControlWidth",2),Os([x()],Dh.prototype,"childForceExpandHeight",2),Os([x()],Dh.prototype,"childForceExpandWidth",2),Os([x()],Dh.prototype,"childScaleHeight",2),Os([x()],Dh.prototype,"childScaleWidth",2);class NI extends Dh{get primaryAxis(){return"y"}}class zI extends Dh{get primaryAxis(){return"x"}}class jI extends oo{onCalculateLayout(){}}var Ane=Object.defineProperty,yne=Object.getOwnPropertyDescriptor,ol=(i,e,t,s)=>{for(var r=s>1?void 0:s?yne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Ane(e,t,r),r},vj=(i=>(i[i.ScreenSpaceOverlay=0]="ScreenSpaceOverlay",i[i.ScreenSpaceCamera=1]="ScreenSpaceCamera",i[i.WorldSpace=2]="WorldSpace",i[i.Undefined=-1]="Undefined",i))(vj||{});const GI=te("debuguilayout"),Aj=class extends Sv{constructor(){super(...arguments),h(this,"_renderOnTop"),h(this,"_depthWrite",!1),h(this,"_doubleSided",!0),h(this,"_castShadows",!1),h(this,"_receiveShadows",!1),h(this,"_renderMode",-1),h(this,"_rootCanvas"),h(this,"_scaleFactor",1),h(this,"worldCamera"),h(this,"planeDistance",-1),h(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this)),h(this,"previousParent",null),h(this,"_lastMatrixWorld",null),h(this,"_rectTransforms",[]),h(this,"_layoutGroups",new Map),h(this,"_receivers",[]),h(this,"onBeforeRenderRoutine",()=>{var i,e,t,s;if(this.previousParent=this.gameObject.parent,((i=this.context.xr)!=null&&i.isVR||(e=this.context.xr)!=null&&e.isPassThrough)&&this.screenspace){this.gameObject.visible=!1,this.gameObject.removeFromParent();return}this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(t=this.shadowComponent)==null||t.updateMatrixWorld(!0),(s=this.shadowComponent)==null||s.updateWorldMatrix(!0,!0),this.invokeBeforeRenderEvents(),jo.ensureUpdateMeshUI(CN,this.context))}),h(this,"onAfterRenderRoutine",()=>{var i,e,t,s,r;if(((i=this.context.xr)!=null&&i.isVR||(e=this.context.xr)!=null&&e.isPassThrough)&&this.screenspace){(t=this.previousParent)==null||t.add(this.gameObject);return}if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const a=this.context.mainCamera;a?.add(this.gameObject)}else this.previousParent.add(this.gameObject);const n=this.context.renderer.autoClear,o=this.context.renderer.autoClearColor;this.context.renderer.autoClear=!1,this.context.renderer.autoClearColor=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(s=this.shadowComponent)==null||s.updateMatrixWorld(!0),this.invokeBeforeRenderEvents(),jo.ensureUpdateMeshUI(CN,this.context,!0),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=n,this.context.renderer.autoClearColor=o,this.previousParent.add(this.gameObject)}(r=this._lastMatrixWorld)==null||r.copy(this.gameObject.matrixWorld)}),h(this,"_updateRenderSettingsRoutine"),h(this,"_activeRenderMode",-1),h(this,"_lastWidth",-1),h(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(i){i!==this._renderOnTop&&(this._renderOnTop=i,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(i){this._depthWrite!==i&&(this._depthWrite=i,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(i){this._doubleSided!==i&&(this._doubleSided=i,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(i){this._castShadows!==i&&(this._castShadows=i,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(i){this._receiveShadows!==i&&(this._receiveShadows=i,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(i){this._renderMode!==i&&(this._renderMode=i,this.onRenderSettingsChanged())}set rootCanvas(i){this._rootCanvas instanceof Aj||(this._rootCanvas=i)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(i){this._scaleFactor=i}awake(){var i;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,GI&&console.log("Canvas.Awake()",((i=this.previousParent)==null?void 0:i.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new Te,this.onUpdateRenderMode(),document.addEventListener("resize",this._boundRenderSettingsChanged),this.context.pre_render_callbacks.push(this.onBeforeRenderRoutine),this.context.post_render_callbacks.push(this.onAfterRenderRoutine)}onDisable(){super.onDisable(),document.removeEventListener("resize",this._boundRenderSettingsChanged);const i=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);i!==-1&&this.context.pre_render_callbacks.splice(i,1);const e=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);e!==-1&&this.context.post_render_callbacks.splice(e,1)}registerTransform(i){this._rectTransforms.push(i)}unregisterTransform(i){const e=this._rectTransforms.indexOf(i);e!==-1&&this._rectTransforms.splice(e,1)}registerLayoutGroup(i){const e=i.gameObject;this._layoutGroups.set(e,i)}unregisterLayoutGroup(i){const e=i.gameObject;this._layoutGroups.delete(e)}registerEventReceiver(i){this._receivers.push(i)}unregisterEventReceiver(i){const e=this._receivers.indexOf(i);e!==-1&&this._receivers.splice(e,1)}async onEnterXR(i){this.screenspace?(i.xr.isVR||i.xr.isPassThrough)&&(this.gameObject.visible=!1):(this.gameObject.visible=!1,await Pk(1).then(()=>{this.gameObject.visible=!0}))}onLeaveXR(i){this.screenspace&&(i.xr.isVR||i.xr.isPassThrough)&&(this.gameObject.visible=!0)}invokeBeforeRenderEvents(){var i;for(const e of this._receivers)(i=e.onBeforeCanvasRender)==null||i.call(e,this)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new Te);const i=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);GI&&i&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);const e=!1;for(const t of this._rectTransforms){i&&t.markDirty();let s=this._layoutGroups.get(t.gameObject);t.isDirty&&!s&&(s=t.gameObject.getComponentInParent(oo)),(t.isDirty||s!=null&&s.isDirty)&&(GI&&!e&&console.log("CANVAS UPDATE ### "+t.name+" ##################################### "+this.context.time.frame),s?.updateLayout(),t.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),ks.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),j_(this.shadowComponent,this);for(const i of oe.getComponentsInChildren(this.gameObject,Ra))j_(i.shadowComponent,this)}}onUpdateRenderMode(i=!1){if(!i&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let e=this.context.mainCameraComponent,t=10;switch(e&&e.nearClipPlane>0&&e.farClipPlane>0&&(t=st.lerp(e.nearClipPlane,e.farClipPlane,.01)),this._renderMode===1&&(this.worldCamera&&(e=this.worldCamera),this.planeDistance>0&&(t=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!e)return;const s=t+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-s,this.gameObject.quaternion.identity();const r=this.gameObject.getComponent(_n);let n=!1;r.sizeDelta.x!==this.context.domWidth&&(n=!0),r.sizeDelta.y!==this.context.domHeight&&(n=!0);const o=e.fieldOfView*Math.PI/180,a=2*Math.tan(o/2)*Math.abs(s);this.gameObject.scale.x=a/this.context.domHeight,this.gameObject.scale.y=a/this.context.domHeight,this.gameObject.scale.z=.01,n&&(r.sizeDelta.x=this.context.domWidth,r.sizeDelta.y=this.context.domHeight,r?.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let Ir=Aj;ol([x()],Ir.prototype,"renderOnTop",1),ol([x()],Ir.prototype,"depthWrite",1),ol([x()],Ir.prototype,"doubleSided",1),ol([x()],Ir.prototype,"castShadows",1),ol([x()],Ir.prototype,"receiveShadows",1),ol([x()],Ir.prototype,"renderMode",1),ol([x(Ir)],Ir.prototype,"rootCanvas",1),ol([x()],Ir.prototype,"scaleFactor",1),ol([x(ji)],Ir.prototype,"worldCamera",2),ol([x()],Ir.prototype,"planeDistance",2);var bne=Object.defineProperty,_ne=Object.getOwnPropertyDescriptor,QI=(i,e,t,s)=>{for(var r=s>1?void 0:s?_ne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&bne(e,t,r),r};class kh extends Pe{constructor(){super(...arguments),h(this,"_alpha",1),h(this,"interactable",!0),h(this,"blocksRaycasts",!0),h(this,"_isDirty",!1),h(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(e){e!==this._alpha&&(this._alpha=e,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),ks.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){this._buffer.length=0;for(const e of oe.getComponentsInChildren(this.gameObject,Ra,this._buffer)){const t=e;t.setAlphaFactor&&t.setAlphaFactor(this._alpha)}}}QI([x()],kh.prototype,"alpha",1),QI([x()],kh.prototype,"interactable",2),QI([x()],kh.prototype,"blocksRaycasts",2);var xne=Object.defineProperty,wne=Object.getOwnPropertyDescriptor,rs=(i,e,t,s)=>{for(var r=s>1?void 0:s?wne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&xne(e,t,r),r};function Kv(i){i&&(i.getComponentInParent(Cv)||(wt()&&console.warn("Create Raycaster on "+i.name+" because no raycaster was found in the hierarchy"),i.addNewComponent(to)))}class md extends Pe{constructor(){super(...arguments),h(this,"object"),h(this,"target"),h(this,"duration",1),h(this,"relativeMotion",!1),h(this,"coroutine",null),h(this,"targetPos",new w),h(this,"targetRot",new Ie),h(this,"targetScale",new w)}start(){Kv(this.gameObject)}onPointerClick(e){e.use(),this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}*moveToTarget(){if(!this.target||!this.object)return;const e=Rt(this.object).clone(),t=Rt(this.target).clone(),s=Ii(this.object).clone(),r=Ii(this.target).clone(),n=ss(this.object).clone(),o=ss(this.target).clone(),a=e.distanceTo(t),l=s.angleTo(r),c=n.distanceTo(o);if(a<.01&&l<.01&&c<.01){Kr(this.object,t),ko(this.object,r),Yg(this.object,o),this.coroutine=null;return}let u=0,d=0;for(;u<1;)u+=this.context.time.deltaTime/this.duration,u>1&&(u=1),d=u<.5?4*u*u*u:1-Math.pow(-2*u+2,3)/2,this.targetPos.lerpVectors(e,t,d),this.targetRot.slerpQuaternions(s,r,d),this.targetScale.lerpVectors(n,o,d),Kr(this.object,this.targetPos),ko(this.object,this.targetRot),Yg(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const e=this.object.position.clone(),t=this.object.quaternion.clone(),s=this.object.scale.clone(),r=this.target.position.clone(),n=this.target.quaternion.clone(),o=this.target.scale.clone();r.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(r),this.targetRot.copy(this.object.quaternion).multiply(n),this.targetScale.copy(this.object.scale).multiply(o);let a=0,l=0;for(;a<1;)a+=this.context.time.deltaTime/this.duration,a>1&&(a=1),l=a<.5?4*a*a*a:1-Math.pow(-2*a+2,3)/2,this.object.position.lerpVectors(e,this.targetPos,l),this.object.quaternion.slerpQuaternions(t,this.targetRot,l),this.object.scale.lerpVectors(s,this.targetScale,l),yield;this.coroutine=null}beforeCreateDocument(e){var t;if(this.target&&this.object&&this.gameObject){const s=new xr("Move to "+((t=this.target)==null?void 0:t.name),wr.tapTrigger(this.gameObject),ui.transformAction(this.object,this.target,this.duration,this.relativeMotion?eI.Relative:eI.Absolute));e.addBehavior(s)}}}rs([x(ye)],md.prototype,"object",2),rs([x(ye)],md.prototype,"target",2),rs([x()],md.prototype,"duration",2),rs([x()],md.prototype,"relativeMotion",2);var hx;const bc=(hx=class extends Pe{constructor(){super(...arguments),h(this,"materialToSwitch"),h(this,"variantMaterial"),h(this,"fadeDuration",0),h(this,"_objectsWithThisMaterial",[]),h(this,"selfModel"),h(this,"targetModels")}awake(){if(this.variantMaterial&&this.materialToSwitch){const i=oe.findObjectsOfType(gs);for(const e of i)for(let t=0;t<e.sharedMaterials.length;t++){const s=e.sharedMaterials[t];if(s===this.materialToSwitch){if(e.gameObject instanceof ve)this._objectsWithThisMaterial.push(e.gameObject);else if(e.gameObject instanceof cn)for(const r of e.gameObject.children)r instanceof ve&&r.material===s&&this._objectsWithThisMaterial.push(r);break}}}}start(){Kv(this.gameObject)}onPointerClick(i){if(i.use(),!!this.variantMaterial)for(let e=0;e<this._objectsWithThisMaterial.length;e++){const t=this._objectsWithThisMaterial[e];t.material=this.variantMaterial}}async beforeCreateDocument(i,e){this.targetModels=[],bc._materialTriggersPerId={},bc.variantSwitchIndex=0,this.materialToSwitch&&await ba.assignTextureLOD(this.context,this.sourceId,this.materialToSwitch,0),this.variantMaterial&&await ba.assignTextureLOD(this.context,this.sourceId,this.variantMaterial,0)}createBehaviours(i,e,t){this._objectsWithThisMaterial.find(s=>s.uuid===e.uuid)&&this.targetModels.push(e),this.gameObject.uuid===e.uuid&&(this.selfModel=e,this.materialToSwitch&&(bc._materialTriggersPerId[this.materialToSwitch.uuid]||(bc._materialTriggersPerId[this.materialToSwitch.uuid]=[]),bc._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(i,e){if(!this.materialToSwitch)return;const t=bc._materialTriggersPerId[this.materialToSwitch.uuid];if(t){const s={};for(const r of t){const n=r.createVariants();n&&n.length>0&&(s[r.selfModel.uuid]=n)}for(const r of t){const n=[];for(const o in s)o!==r.selfModel.uuid&&n.push(...s[o]);r.createAndAttachBehaviors(i,s[r.selfModel.uuid],n)}}delete bc._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(i,e,t){const s=[],r=[],n=Math.max(0,this.fadeDuration);r.push(ui.fadeAction([...this.targetModels,...t],n,!1)),s.push(ui.fadeAction(e,n,!1)),r.push(ui.fadeAction(e,n,!0)),i.addBehavior(new xr("Select_"+this.selfModel.name,wr.tapTrigger(this.selfModel),ui.parallel(...r))),i.addBehavior(new xr("StartHidden_"+this.selfModel.name,wr.sceneStartTrigger(),ui.parallel(...s)))}createVariants(){if(!this.variantMaterial)return null;const i=[];for(const e of this.targetModels){const t=e.clone();t.name+=" variant_"+this.variantMaterial.name+"_"+bc.variantSwitchIndex++,t.name=t.name.replace(/\s/g,"_"),t.material=this.variantMaterial,t.geometry=e.geometry,t.matrix=e.matrix,(!e.parent||!e.parent.isEmpty())&&Fo.createEmptyParent(e),e.parent&&e.parent.add(t),i.push(t)}return i}},h(hx,"_materialTriggersPerId",{}),h(hx,"variantSwitchIndex",0),hx);let Bf=bc;rs([x(Lt)],Bf.prototype,"materialToSwitch",2),rs([x(Lt)],Bf.prototype,"variantMaterial",2),rs([x()],Bf.prototype,"fadeDuration",2);var Df;const ns=(Df=class extends Pe{constructor(){super(...arguments),h(this,"target"),h(this,"toggleOnClick",!1),h(this,"targetState",!0),h(this,"hideSelf",!0),h(this,"selfModel"),h(this,"selfModelClone"),h(this,"targetModel"),h(this,"toggleModel"),h(this,"stateBeforeCreatingDocument",!1),h(this,"targetStateBeforeCreatingDocument",!1)}start(){Kv(this.gameObject)}onPointerClick(i){i.use(),!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(i,e,t){e.uuid===this.gameObject.uuid&&(this.selfModel=e,this.selfModelClone=e.clone())}beforeCreateDocument(){this.target&&(this.gameObject[ns.wasVisible]===void 0&&(this.gameObject[ns.wasVisible]=this.gameObject.activeSelf),this.target[ns.wasVisible]===void 0&&(this.target[ns.wasVisible]=this.target.activeSelf),this.stateBeforeCreatingDocument=this.gameObject[ns.wasVisible],this.targetStateBeforeCreatingDocument=this.target[ns.wasVisible],this.gameObject.visible=!0,this.target.visible=!0)}afterCreateDocument(i,e){if(!this.target)return;this.targetModel=e.document.findById(this.target.uuid);const t=this.selfModel;if(this.selfModel&&this.targetModel){let s=this.selfModel,r=this.targetState;if(this.toggleOnClick)if(r=!this.targetStateBeforeCreatingDocument,!this.selfModelClone.geometry)(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&Cz.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.deepClone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel);else{if(!this.gameObject[ns.toggleClone]){const a=this.selfModelClone.clone();a.matrix.identity(),a.name+="_toggle"+ns.clonedToggleIndex++,t.add(a),this.gameObject[ns.toggleClone]=a,console.warn("USDZExport: Toggle "+this.gameObject.name+" doesn't have geometry. It will be deep cloned and nested behaviours will likely not work.")}const o=this.gameObject[ns.toggleClone];if(!this.gameObject[ns.reverseToggleClone]){const a=this.selfModelClone.clone();a.matrix.identity(),a.name+="_toggleReverse"+ns.clonedToggleIndex++,t.add(a),this.gameObject[ns.reverseToggleClone]=a}this.toggleModel=this.gameObject[ns.reverseToggleClone],(!this.toggleModel.geometry||!o.geometry)&&console.error("triggers without childs and without geometry won't work!",this,t.geometry),s=o,t.geometry=null,t.material=null}if(this.toggleModel){if(this.toggleOnClick){const o=[];o.push(ui.fadeAction(s,0,!1)),o.push(ui.fadeAction(this.toggleModel,0,!0)),o.push(ui.fadeAction(this.targetModel,0,r)),i.addBehavior(new xr("Toggle_"+s.name+"_toggleTo"+(r?"On":"Off"),wr.tapTrigger(s),ui.parallel(...o)));const a=[];a.push(ui.fadeAction(this.toggleModel,0,!1)),a.push(ui.fadeAction(s,0,!0)),a.push(ui.fadeAction(this.targetModel,0,!r)),i.addBehavior(new xr("Toggle_"+s.name+"_toggleTo"+(r?"Off":"On"),wr.tapTrigger(this.toggleModel),ui.parallel(...a)))}}else{const o=[];this.hideSelf&&o.push(ui.fadeAction(s,0,!1)),o.push(ui.fadeAction(this.targetModel,0,r)),i.addBehavior(new xr("Toggle_"+s.name+"_toggleTo"+(r?"On":"Off"),wr.tapTrigger(s),ui.parallel(...o)))}const n=new Array;this.targetStateBeforeCreatingDocument||n.push(this.targetModel),this.stateBeforeCreatingDocument||n.push(t),this.toggleModel&&n.push(this.toggleModel),i.addBehavior(new xr("HideOnStart_"+this.gameObject.name,wr.sceneStartTrigger(),ui.fadeAction(n,0,!1)))}}afterSerialize(i,e){this.gameObject[ns.wasVisible]!==void 0&&(this.gameObject.visible=this.gameObject[ns.wasVisible],delete this.gameObject[ns.wasVisible]),this.target&&this.target[ns.wasVisible]!==void 0&&(this.target.visible=this.target[ns.wasVisible],delete this.target[ns.wasVisible]),delete this.gameObject[ns.toggleClone],delete this.gameObject[ns.reverseToggleClone]}},h(Df,"clonedToggleIndex",0),h(Df,"wasVisible",Symbol("usdz_SetActiveOnClick_wasVisible")),h(Df,"toggleClone",Symbol("clone for toggling")),h(Df,"reverseToggleClone",Symbol("clone for reverse toggling")),Df);let gd=ns;rs([x(ye)],gd.prototype,"target",2),rs([x()],gd.prototype,"toggleOnClick",2),rs([x()],gd.prototype,"targetState",2),rs([x()],gd.prototype,"hideSelf",2);class VI extends Pe{start(){this.gameObject.visible=!1}createBehaviours(e,t,s){t.uuid===this.gameObject.uuid&&e.addBehavior(new xr("HideOnStart_"+this.gameObject.name,wr.sceneStartTrigger(),ui.fadeAction(t,0,!1)))}beforeCreateDocument(){this.gameObject.visible=!0}afterCreateDocument(){this.gameObject.visible=!1}}class kf extends Pe{constructor(){super(...arguments),h(this,"target"),h(this,"duration",.5),h(this,"motionType",$T.bounce)}beforeCreateDocument(){}createBehaviours(e,t,s){if(this.target&&t.uuid===this.gameObject.uuid){const r=new xr("emphasize "+this.name,wr.tapTrigger(this.gameObject),ui.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));e.addBehavior(r)}}afterCreateDocument(e,t){}}rs([x()],kf.prototype,"target",2),rs([x()],kf.prototype,"duration",2),rs([x()],kf.prototype,"motionType",2);class Of extends Pe{constructor(){super(...arguments),h(this,"target"),h(this,"clip",""),h(this,"toggleOnClick",!1)}start(){Kv(this.gameObject)}ensureAudioSource(){if(!this.target){const e=this.gameObject.addNewComponent(vs);e&&(this.target=e,e.spatialBlend=1,e.volume=1,e.loop=!1)}}onPointerClick(e){var t;e.use(),!(!((t=this.target)!=null&&t.clip)&&!this.clip)&&(this.ensureAudioSource(),this.target&&(this.target.isPlaying&&this.toggleOnClick?this.target.stop():(!this.toggleOnClick&&this.target.isPlaying&&this.target.stop(),this.clip?this.target.play(this.clip):this.target.play())))}createBehaviours(e,t,s){if(!(!this.target&&!this.clip)&&t.uuid===this.gameObject.uuid){const r=this.clip?this.clip:this.target?this.target.clip:void 0;if(!r||typeof r!="string")return;const n=this.target?this.target.gameObject:this.gameObject,o=r.split("/").pop(),a=this.target?this.target.volume:1,l=this.target&&this.target.spatialBlend==0?sI.NonSpatial:sI.Spatial;{let c=ui.playAudioAction(n,"audio/"+o,iI.Play,a,l);this.toggleOnClick&&(c.multiplePerformOperation=Nz.Stop),this.target&&this.target.loop&&(c=ui.sequence(c).makeLooping());const u=new xr("playAudio "+this.name,wr.tapTrigger(this.gameObject),c);e.addBehavior(u)}if(this.target&&this.target.playOnAwake&&this.target.enabled){let c=ui.playAudioAction(n,"audio/"+o,iI.Play,a,l);this.target.loop&&(c=ui.sequence(c).makeLooping());const u=new xr("playAudioOnStart "+this.name,wr.sceneStartTrigger(),c);e.addBehavior(u)}}}async afterSerialize(e,t){if(!this.target&&!this.clip)return;const s=this.clip?this.clip:this.target?this.target.clip:void 0;if(!s||typeof s!="string")return;const r=s.split("/").pop(),n=await(await(await fetch(s)).blob()).arrayBuffer(),o=new Uint8Array(n);t.files["audio/"+r]=o}}rs([x(vs)],Of.prototype,"target",2),rs([x(URL)],Of.prototype,"clip",2),rs([x()],Of.prototype,"toggleOnClick",2);var ux;const Oh=(ux=class extends Pe{constructor(){super(...arguments),h(this,"animator"),h(this,"stateName"),h(this,"trigger","tap"),h(this,"selfModel"),h(this,"stateAnimationModel"),h(this,"animationSequence",new Array),h(this,"animationLoopAfterSequence",new Array)}get target(){var i;return(i=this.animator)==null?void 0:i.gameObject}start(){Kv(this.gameObject)}onPointerClick(i){var e;i.use(),this.target&&this.stateName&&((e=this.animator)==null||e.play(this.stateName,0,0,.1))}createBehaviours(i,e,t){e.uuid===this.gameObject.uuid&&(this.selfModel=e)}afterSerialize(){if(Oh.rootsWithExclusivePlayback.size>1){const i='Multiple root objects targeted by more than one animation. To work around QuickLook bug FB13410767, animations will be set as "exclusive" and activating them will stop other animations being marked as exclusive.';wt()&&is(i),console.warn(i,...Oh.rootsWithExclusivePlayback)}Oh.animationActions=[],Oh.rootsWithExclusivePlayback=new Set}afterCreateDocument(i,e){if(!this.animationSequence||!this.stateAnimationModel||!this.target)return;const t=e.document,s=e.extensions.find(o=>o instanceof Ov);if(!s)return;const r=s.getClipCount(this.target)>1;r&&(wt()&&console.warn("Setting exclusive playback for "+this.target.name+"@"+this.stateName+" because it has "+s.getClipCount(this.target)+" animations. This works around QuickLook bug FB13410767."),Oh.rootsWithExclusivePlayback.add(this.target));const n=(o,a)=>{let l=Oh.animationActions.find(c=>c.affectedObjects==o&&c.start==a.start&&c.duration==a.duration);return l||(l=ui.startAnimationAction(o,a.start,a.duration),Oh.animationActions.push(l)),l};t.traverse(o=>{var a,l;if(o.uuid===((a=this.target)==null?void 0:a.uuid)){const c=ui.sequence();if(this.animationSequence!==void 0)for(const d of this.animationSequence)c.addAction(n(o,d));if(this.animationLoopAfterSequence!==void 0){const d=c.actions.length==0?c:ui.sequence();for(const p of this.animationLoopAfterSequence)d.addAction(n(o,p));d.makeLooping(),c!==d&&c.addAction(d)}const u=new xr("tap "+this.name+" for "+this.stateName+" on "+((l=this.target)==null?void 0:l.name),this.trigger=="tap"?wr.tapTrigger(this.selfModel):wr.sceneStartTrigger(),c);r&&u.makeExclusive(!0),i.addBehavior(u)}})}createAnimation(i,e,t){var s,r,n,o;if(!this.target||!this.animator)return;const a=(s=this.animator)==null?void 0:s.runtimeAnimatorController;let l=a?.findState(this.stateName),c=[],u=[];if(a&&l){const d=new Array;d.push(l);let p=!1;for(;d.length<100;){if(!l||l===null||!l.transitions||l.transitions.length===0){(r=l.motion)!=null&&r.isLooping&&(p=!0);break}const f=l.transitions.find(A=>A.conditions.length===0),m=f?a.getState(f.destinationState,0):null;if(m&&d.includes(m)){l=m,p=!0;break}else if(f){if(l=m,!l)break;d.push(l)}else{p=((n=l.motion)==null?void 0:n.isLooping)??!1;break}}if(p&&l){const f=d.indexOf(l);c=d.slice(0,f),u=d.slice(f),console.log("found loop from "+this.stateName,"states until loop",c,"states looping",u)}else c=d,u=[],console.log("found no loop from "+this.stateName,"states",c)}if(c=c.filter(d=>{var p,f,m;return((p=d.motion)==null?void 0:p.clip)&&((m=(f=d.motion)==null?void 0:f.clip.tracks)==null?void 0:m.length)>0}),u=u.filter(d=>{var p,f,m;return((p=d.motion)==null?void 0:p.clip)&&((m=(f=d.motion)==null?void 0:f.clip.tracks)==null?void 0:m.length)>0}),c.length===0&&u.length===0){console.warn("No clips found for state "+this.stateName+" on "+((o=this.animator)==null?void 0:o.name)+", can't export animation data");return}if(this.stateAnimationModel=e,c.length>0){this.animationSequence=new Array;for(const d of c)this.animationSequence.push(i.registerAnimation(this.target,d.motion.clip))}if(u.length>0){this.animationLoopAfterSequence=new Array;for(const d of u)this.animationLoopAfterSequence.push(i.registerAnimation(this.target,d.motion.clip))}}},h(ux,"animationActions",[]),h(ux,"rootsWithExclusivePlayback",new Set),ux);let Lf=Oh;rs([x(Er)],Lf.prototype,"animator",2),rs([x()],Lf.prototype,"stateName",2);class Uf extends Pe{constructor(){super(...arguments),h(this,"target")}getType(){}getDuration(){}}rs([x(ye)],Uf.prototype,"target",2);class Zv extends Pe{constructor(){super(...arguments),h(this,"target")}}rs([x(Uf)],Zv.prototype,"target",2);class $v extends Uf{constructor(){super(...arguments),h(this,"type",1),h(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}rs([x()],$v.prototype,"type",2),rs([x()],$v.prototype,"duration",2);class HI extends Zv{}var Sne=Object.defineProperty,Cne=Object.getOwnPropertyDescriptor,_c=(i,e,t,s)=>{for(var r=s>1?void 0:s?Cne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Sne(e,t,r),r};const yj=te("debugcharactercontroller");class vd extends Pe{constructor(){super(...arguments),h(this,"center",new w(0,0,0)),h(this,"radius",.5),h(this,"height",2),h(this,"_rigidbody",null),h(this,"_activeGroundCollisions"),h(this,"_contactVelocity",new w)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(Ni),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(Ni)),this.rigidbody)}awake(){this._activeGroundCollisions=new Set}onEnable(){const e=this.rigidbody;let t=this.gameObject.getComponent(Ph);t||(t=this.gameObject.addNewComponent(Ph)),t.center.copy(this.center),t.radius=this.radius,t.height=this.height;const s=new w(0,0,1),r=new w(1,0,0),n=new w(0,1,0),o=this.gameObject.getWorldDirection(new w);o.y=0;const a=r.dot(o)<0?-1:1,l=s.angleTo(o)*a;this.gameObject.setRotationFromAxisAngle(n,l),e.lockRotationX=!0,e.lockRotationY=!0,e.lockRotationZ=!0}move(e){this.gameObject.position.add(e)}onCollisionEnter(e){(e.contacts.length==0||e.contacts.some(t=>t.normal.y>.2))&&(this._activeGroundCollisions.add(e),yj&&console.log(`Collision(${this._activeGroundCollisions.size}): ${e.contacts.map(t=>t.normal.y.toFixed(2)).join(", ")} - ${this.isGrounded}`))}onCollisionExit(e){this._activeGroundCollisions.delete(e),yj&&console.log(`Collision(${this._activeGroundCollisions.size}) - ${this.isGrounded}`)}get isGrounded(){return this._activeGroundCollisions.size>0}get contactVelocity(){var e;this._contactVelocity.set(0,0,0);for(const t of this._activeGroundCollisions){const s=(e=this.context.physics.engine)==null?void 0:e.getLinearVelocity(t.collider);s&&(this._contactVelocity.x+=s.x,this._contactVelocity.y+=s.y,this._contactVelocity.z+=s.z)}return this._contactVelocity}}_c([x(w)],vd.prototype,"center",2),_c([x()],vd.prototype,"radius",2),_c([x()],vd.prototype,"height",2);class xc extends Pe{constructor(){super(...arguments),h(this,"controller"),h(this,"movementSpeed",2),h(this,"rotationSpeed",2),h(this,"jumpForce",1),h(this,"doubleJumpForce",2),h(this,"animator"),h(this,"lookForward",!0),h(this,"lookInput",new ee(0,0)),h(this,"moveInput",new ee(0,0)),h(this,"jumpInput",!1),h(this,"_currentSpeed",new w(0,0,0)),h(this,"_currentAngularSpeed",new w(0,0,0)),h(this,"_temp",new w(0,0,0)),h(this,"_jumpCount",0),h(this,"_currentRotation"),h(this,"_raycastOptions",new Oo)}awake(){this._currentRotation=new Ie}update(){const e=this.context.input;e.isKeyPressed("KeyW")?this.moveInput.y+=1:e.isKeyPressed("KeyS")&&(this.moveInput.y-=1),e.isKeyPressed("KeyD")?this.lookInput.x+=1:e.isKeyPressed("KeyA")&&(this.lookInput.x-=1),this.jumpInput||(this.jumpInput=e.isKeyDown("Space"))}move(e){this.moveInput.add(e)}look(e){this.lookInput.add(e)}jump(){this.jumpInput=!0}onBeforeRender(){this.handleInput(this.moveInput,this.lookInput,this.jumpInput),this.lookInput.set(0,0),this.moveInput.set(0,0),this.jumpInput=!1}handleInput(e,t,s){var r,n,o,a,l,c,u,d,p,f,m;if((r=this.controller)!=null&&r.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((n=this.animator)==null||n.setBool("doubleJump",!1))),this._currentSpeed.z+=e.y*this.movementSpeed*this.context.time.deltaTime,(o=this.animator)==null||o.setBool("running",e.length()>.01),(l=this.animator)==null||l.setBool("jumping",((a=this.controller)==null?void 0:a.isGrounded)===!0&&s),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp),this._currentAngularSpeed.y+=st.toRadians(-t.x*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const A=this.context.mainCameraComponent.forward;A.y=0,A.normalize(),this._currentRotation.setFromUnitVectors(new w(0,0,1),A),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&s&&this.jumpForce>0){let A=(c=this.controller)==null?void 0:c.isGrounded;if(this.doubleJumpForce>0&&!((u=this.controller)!=null&&u.isGrounded)&&this._jumpCount===1&&(A=!0,(d=this.animator)==null||d.setBool("doubleJump",!0)),A){this._jumpCount+=1;const y=this.controller.rigidbody,g=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;y.applyImpulse(new w(0,1,0).multiplyScalar(g))}}if(this.controller){const A=(p=this.controller)==null?void 0:p.rigidbody.getVelocity().y;if(A<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new Wn),this._raycastOptions.ray.origin.copy(Rt(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const y=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const g=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(y),(g.length&&g[0].distance>2||A<-10)&&((f=this.animator)==null||f.setBool("falling",!0))}else(m=this.animator)==null||m.setBool("falling",!1)}}}_c([x(vd)],xc.prototype,"controller",2),_c([x()],xc.prototype,"movementSpeed",2),_c([x()],xc.prototype,"rotationSpeed",2),_c([x()],xc.prototype,"jumpForce",2),_c([x()],xc.prototype,"doubleJumpForce",2),_c([x(Er)],xc.prototype,"animator",2);var Ene=Object.defineProperty,Mne=Object.getOwnPropertyDescriptor,Tne=(i,e,t,s)=>{for(var r=s>1?void 0:s?Mne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Ene(e,t,r),r};class eA extends en{constructor(){super(...arguments),h(this,"intensity")}get typeName(){return"ChromaticAberration"}init(){this.intensity.defaultValue=0}onCreateEffect(){const e=new kO;return e.offset=new ee(0,0),e.radialModulation=!0,e.modulationOffset=.15,this.intensity.valueProcessor=t=>t*.02,this.intensity.onValueChanged=t=>{e.offset.x=-t,e.offset.y=t},e}}Tne([x(Bt)],eA.prototype,"intensity",2),Vo("ChromaticAberration",eA);var Ine=Object.defineProperty,Rne=Object.getOwnPropertyDescriptor,dx=(i,e,t,s)=>{for(var r=s>1?void 0:s?Rne(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Ine(e,t,r),r};class Lh extends en{constructor(){super(...arguments),h(this,"postExposure"),h(this,"contrast"),h(this,"hueShift"),h(this,"saturation")}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=e=>(e=Math.pow(2,e),e),this.postExposure.defaultValue=0,this.contrast.valueProcessor=e=>{let t=1;return e>0?t=200:e<0&&(t=100),e/t},this.contrast.defaultValue=0,this.hueShift.valueProcessor=e=>Math.PI*e/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=e=>e<0?e/100:e/(100*Math.PI),this.saturation.defaultValue=0}unapply(){this.context.renderer.toneMappingExposure=1}onCreateEffect(){this.context.renderer.toneMapping===Pn&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=vm);const e=new DO;this.postExposure.onValueChanged=s=>{this.context.renderer.toneMapping===Pn&&(this.context.renderer.toneMapping=vm),this.postExposure.overrideState&&(this.context.renderer.toneMappingExposure=s)},this.contrast.onValueChanged=s=>{e.contrast=s};const t=new LO;return this.hueShift.onValueChanged=s=>t.hue=s,this.saturation.onValueChanged=s=>t.saturation=s,[t,e]}}dx([x(Bt)],Lh.prototype,"postExposure",2),dx([x(Bt)],Lh.prototype,"contrast",2),dx([x(Bt)],Lh.prototype,"hueShift",2),dx([x(Bt)],Lh.prototype,"saturation",2),Vo("ColorAdjustments",Lh);const Pne=(Math.sqrt(5)-1)/4,Rr=(5-Math.sqrt(5))/20,px=i=>Math.floor(i)|0,fx=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function Bne(i=Math.random){const e=Dne(i),t=new Float64Array(e).map(o=>fx[o%32*4]),s=new Float64Array(e).map(o=>fx[o%32*4+1]),r=new Float64Array(e).map(o=>fx[o%32*4+2]),n=new Float64Array(e).map(o=>fx[o%32*4+3]);return function(o,a,l,c){let u,d,p,f,m;const A=(o+a+l+c)*Pne,y=px(o+A),g=px(a+A),v=px(l+A),b=px(c+A),_=(y+g+v+b)*Rr,S=y-_,M=g-_,C=v-_,R=b-_,I=o-S,E=a-M,z=l-C,F=c-R;let q=0,N=0,H=0,L=0;I>E?q++:N++,I>z?q++:H++,I>F?q++:L++,E>z?N++:H++,E>F?N++:L++,z>F?H++:L++;const j=q>=3?1:0,Q=N>=3?1:0,$=H>=3?1:0,Z=L>=3?1:0,se=q>=2?1:0,Ae=N>=2?1:0,Ue=H>=2?1:0,Qe=L>=2?1:0,Ke=q>=1?1:0,ae=N>=1?1:0,Ee=H>=1?1:0,He=L>=1?1:0,Fe=I-j+Rr,We=E-Q+Rr,le=z-$+Rr,Ne=F-Z+Rr,X=I-se+2*Rr,Se=E-Ae+2*Rr,_e=z-Ue+2*Rr,Ge=F-Qe+2*Rr,ue=I-Ke+3*Rr,dt=E-ae+3*Rr,U=z-Ee+3*Rr,P=F-He+3*Rr,ne=I-1+4*Rr,ke=E-1+4*Rr,Ce=z-1+4*Rr,Le=F-1+4*Rr,it=y&255,ze=g&255,Je=v&255,nt=b&255;let bt=.6-I*I-E*E-z*z-F*F;if(bt<0)u=0;else{const we=it+e[ze+e[Je+e[nt]]];bt*=bt,u=bt*bt*(t[we]*I+s[we]*E+r[we]*z+n[we]*F)}let De=.6-Fe*Fe-We*We-le*le-Ne*Ne;if(De<0)d=0;else{const we=it+j+e[ze+Q+e[Je+$+e[nt+Z]]];De*=De,d=De*De*(t[we]*Fe+s[we]*We+r[we]*le+n[we]*Ne)}let Ot=.6-X*X-Se*Se-_e*_e-Ge*Ge;if(Ot<0)p=0;else{const we=it+se+e[ze+Ae+e[Je+Ue+e[nt+Qe]]];Ot*=Ot,p=Ot*Ot*(t[we]*X+s[we]*Se+r[we]*_e+n[we]*Ge)}let lt=.6-ue*ue-dt*dt-U*U-P*P;if(lt<0)f=0;else{const we=it+Ke+e[ze+ae+e[Je+Ee+e[nt+He]]];lt*=lt,f=lt*lt*(t[we]*ue+s[we]*dt+r[we]*U+n[we]*P)}let ht=.6-ne*ne-ke*ke-Ce*Ce-Le*Le;if(ht<0)m=0;else{const we=it+1+e[ze+1+e[Je+1+e[nt+1]]];ht*=ht,m=ht*ht*(t[we]*ne+s[we]*ke+r[we]*Ce+n[we]*Le)}return 27*(u+d+p+f+m)}}function Dne(i){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const s=t+~~(i()*(256-t)),r=e[t];e[t]=e[s],e[s]=r}for(let t=256;t<512;t++)e[t]=e[t-256];return e}var kne=Object.defineProperty,One=Object.getOwnPropertyDescriptor,ie=(i,e,t,s)=>{for(var r=s>1?void 0:s?One(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&kne(e,t,r),r};const mx=te("debugparticles");var wc=(i=>(i[i.Billboard=0]="Billboard",i[i.Stretch=1]="Stretch",i[i.HorizontalBillboard=2]="HorizontalBillboard",i[i.VerticalBillboard=3]="VerticalBillboard",i[i.Mesh=4]="Mesh",i))(wc||{});let Uh=class{constructor(){h(this,"alphaKeys"),h(this,"colorKeys")}get duration(){return 1}evaluate(i,e){let t,s=0,r=null,n=0;for(let o=0;o<this.alphaKeys.length;o++){const a=this.alphaKeys[o];(a.time<i||!t)&&(t=a,s=o)}for(let o=0;o<this.colorKeys.length;o++){const a=this.colorKeys[o];(a.time<i||!r)&&(r=a,n=o)}if(r)if(n+1<this.colorKeys.length){const o=this.colorKeys[n+1],a=st.remap(i,r.time,o.time,0,1);e.r=st.lerp(r.color.r,o.color.r,a),e.g=st.lerp(r.color.g,o.color.g,a),e.b=st.lerp(r.color.b,o.color.b,a)}else e.r=r.color.r,e.g=r.color.g,e.b=r.color.b;if(t)if(s+1<this.alphaKeys.length){const o=this.alphaKeys[s+1],a=st.remap(i,t.time,o.time,0,1);e.alpha=st.lerp(t.alpha,o.alpha,a)}else e.alpha=t.alpha;return e}};ie([x()],Uh.prototype,"alphaKeys",2),ie([x()],Uh.prototype,"colorKeys",2);var tA=(i=>(i[i.Local=0]="Local",i[i.World=1]="World",i[i.Custom=2]="Custom",i))(tA||{}),gx=(i=>(i[i.Sphere=0]="Sphere",i[i.SphereShell=1]="SphereShell",i[i.Hemisphere=2]="Hemisphere",i[i.HemisphereShell=3]="HemisphereShell",i[i.Cone=4]="Cone",i[i.Box=5]="Box",i[i.Mesh=6]="Mesh",i[i.ConeShell=7]="ConeShell",i[i.ConeVolume=8]="ConeVolume",i[i.ConeVolumeShell=9]="ConeVolumeShell",i[i.Circle=10]="Circle",i[i.CircleEdge=11]="CircleEdge",i[i.SingleSidedEdge=12]="SingleSidedEdge",i[i.MeshRenderer=13]="MeshRenderer",i[i.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",i[i.BoxShell=15]="BoxShell",i[i.BoxEdge=16]="BoxEdge",i[i.Donut=17]="Donut",i[i.Rectangle=18]="Rectangle",i[i.Sprite=19]="Sprite",i[i.SpriteRenderer=20]="SpriteRenderer",i))(gx||{});const bj=class{constructor(){h(this,"mode"),h(this,"constant"),h(this,"constantMin"),h(this,"constantMax"),h(this,"curve"),h(this,"curveMin"),h(this,"curveMax"),h(this,"curveMultiplier")}clone(){var i,e,t;const s=new bj;return s.mode=this.mode,s.constant=this.constant,s.constantMin=this.constantMin,s.constantMax=this.constantMax,s.curve=(i=this.curve)==null?void 0:i.clone(),s.curveMin=(e=this.curveMin)==null?void 0:e.clone(),s.curveMax=(t=this.curveMax)==null?void 0:t.clone(),s.curveMultiplier=this.curveMultiplier,s}evaluate(i,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.constant;case 1:return i=st.clamp01(i),this.curve.evaluate(i)*this.curveMultiplier;case 2:const s=i*this.curveMin.duration,r=i*this.curveMax.duration;return st.lerp(this.curveMin.evaluate(s),this.curveMax.evaluate(r),t%1)*this.curveMultiplier;case 3:return st.lerp(this.constantMin,this.constantMax,t%1);default:this.curveMax.evaluate(i)*this.curveMultiplier;break}return 0}getMax(){switch(this.mode){case 0:return this.constant;case 1:return this.getMaxFromCurve(this.curve)*this.curveMultiplier;case 2:return Math.max(this.getMaxFromCurve(this.curveMin),this.getMaxFromCurve(this.curveMax))*this.curveMultiplier;case 3:return Math.max(this.constantMin,this.constantMax);default:return 0}}getMaxFromCurve(i){if(!i)return 0;let e=Number.MIN_VALUE;for(let t=0;t<i.keys.length;t++){const s=i.keys[t];s.value>e&&(e=s.value)}return e}};let ct=bj;ie([x()],ct.prototype,"mode",2),ie([x()],ct.prototype,"constant",2),ie([x()],ct.prototype,"constantMin",2),ie([x()],ct.prototype,"constantMax",2),ie([x(td)],ct.prototype,"curve",2),ie([x(td)],ct.prototype,"curveMin",2),ie([x(td)],ct.prototype,"curveMax",2),ie([x()],ct.prototype,"curveMultiplier",2);var vx;const Sa=(vx=class{constructor(){h(this,"mode"),h(this,"color"),h(this,"colorMin"),h(this,"colorMax"),h(this,"gradient"),h(this,"gradientMin"),h(this,"gradientMax")}evaluate(i,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.color;case 1:return this.gradient.evaluate(i,Sa._temp),Sa._temp;case 2:return Sa._temp.lerpColors(this.colorMin,this.colorMax,t);case 3:return this.gradientMin.evaluate(i,Sa._temp),this.gradientMax.evaluate(i,Sa._temp2),Sa._temp.lerp(Sa._temp2,t)}return Sa._temp.set(16711935),Sa._temp.alpha=1,Sa._temp}},h(vx,"_temp",new Si(0,0,0,1)),h(vx,"_temp2",new Si(0,0,0,1)),vx);let Gn=Sa;ie([x(Si)],Gn.prototype,"color",2),ie([x(Si)],Gn.prototype,"colorMin",2),ie([x(Si)],Gn.prototype,"colorMax",2),ie([x(Uh)],Gn.prototype,"gradient",2),ie([x(Uh)],Gn.prototype,"gradientMin",2),ie([x(Uh)],Gn.prototype,"gradientMax",2);var WI=(i=>(i[i.Hierarchy=0]="Hierarchy",i[i.Local=1]="Local",i[i.Shape=2]="Shape",i))(WI||{});class Pr{constructor(){h(this,"cullingMode"),h(this,"duration"),h(this,"emitterVelocityMode"),h(this,"flipRotation"),h(this,"gravityModifier"),h(this,"gravityModifierMultiplier"),h(this,"loop"),h(this,"maxParticles"),h(this,"playOnAwake"),h(this,"prewarm"),h(this,"ringBufferLoopRange"),h(this,"ringBufferMode"),h(this,"scalingMode"),h(this,"simulationSpace"),h(this,"simulationSpeed"),h(this,"startColor"),h(this,"startDelay"),h(this,"startDelayMultiplier"),h(this,"startLifetime"),h(this,"startLifetimeMultiplier"),h(this,"startRotation"),h(this,"startRotationMultiplier"),h(this,"startRotation3D"),h(this,"startRotationX"),h(this,"startRotationXMultiplier"),h(this,"startRotationY"),h(this,"startRotationYMultiplier"),h(this,"startRotationZ"),h(this,"startRotationZMultiplier"),h(this,"startSize"),h(this,"startSize3D"),h(this,"startSizeMultiplier"),h(this,"startSizeX"),h(this,"startSizeXMultiplier"),h(this,"startSizeY"),h(this,"startSizeYMultiplier"),h(this,"startSizeZ"),h(this,"startSizeZMultiplier"),h(this,"startSpeed"),h(this,"startSpeedMultiplier"),h(this,"stopAction"),h(this,"useUnscaledTime")}}ie([x(ct)],Pr.prototype,"gravityModifier",2),ie([x(Gn)],Pr.prototype,"startColor",2),ie([x(ct)],Pr.prototype,"startDelay",2),ie([x(ct)],Pr.prototype,"startLifetime",2),ie([x(ct)],Pr.prototype,"startRotation",2),ie([x(ct)],Pr.prototype,"startRotationX",2),ie([x(ct)],Pr.prototype,"startRotationY",2),ie([x(ct)],Pr.prototype,"startRotationZ",2),ie([x(ct)],Pr.prototype,"startSize",2),ie([x(ct)],Pr.prototype,"startSizeX",2),ie([x(ct)],Pr.prototype,"startSizeY",2),ie([x(ct)],Pr.prototype,"startSizeZ",2),ie([x(ct)],Pr.prototype,"startSpeed",2);class iA{constructor(){h(this,"cycleCount"),h(this,"maxCount"),h(this,"minCount"),h(this,"probability"),h(this,"repeatInterval"),h(this,"time"),h(this,"count"),h(this,"_performed",0)}reset(){this._performed=0}run(e){if(e<=this.time)return 0;let t=0;if(this.cycleCount===0||this._performed<this.cycleCount){const s=this.time+this.repeatInterval*this._performed;if(e>=s&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:t=this.count.constant;break;case 3:t=st.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:t=this.count.curve.evaluate(Math.random());break;case 2:const r=Math.random();t=st.lerp(this.count.curveMin.evaluate(r),this.count.curveMax.evaluate(r),Math.random());break}}return t}}class al{constructor(){h(this,"enabled"),h(this,"bursts"),h(this,"rateOverTime"),h(this,"rateOverTimeMultiplier"),h(this,"rateOverDistance"),h(this,"rateOverDistanceMultiplier"),h(this,"system")}get burstCount(){var e;return((e=this.bursts)==null?void 0:e.length)??0}reset(){var e;(e=this.bursts)==null||e.forEach(t=>t.reset())}getBurst(){let e=0;if(this.burstCount>0)for(let t=0;t<this.burstCount;t++){const s=this.bursts[t];this.system.main.loop&&s.time>=this.system.time&&s.reset(),e+=Math.round(s.run(this.system.time))}return e}}ie([x()],al.prototype,"enabled",2),ie([x()],al.prototype,"bursts",2),ie([x(ct)],al.prototype,"rateOverTime",2),ie([x()],al.prototype,"rateOverTimeMultiplier",2),ie([x(ct)],al.prototype,"rateOverDistance",2),ie([x()],al.prototype,"rateOverDistanceMultiplier",2);class sA{constructor(){h(this,"enabled"),h(this,"color")}}ie([x(Gn)],sA.prototype,"color",2);class Fh{constructor(){h(this,"enabled"),h(this,"separateAxes"),h(this,"size"),h(this,"sizeMultiplier"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier"),h(this,"_time",0),h(this,"_temp",new w)}evaluate(e,t,s){if(t||(t=this._temp),!this.enabled)return t.x=t.y=t.z=1,t;if(this.separateAxes)t.x=this.x.evaluate(e,s)*this.xMultiplier,t.y=this.y.evaluate(e,s)*this.yMultiplier,t.z=this.z.evaluate(e,s)*this.zMultiplier;else{const r=this.size.evaluate(e,s)*this.sizeMultiplier;t.x=r}return t}}ie([x(ct)],Fh.prototype,"size",2),ie([x(ct)],Fh.prototype,"x",2),ie([x(ct)],Fh.prototype,"y",2),ie([x(ct)],Fh.prototype,"z",2);var Ax;const rA=(Ax=class{constructor(){h(this,"shapeType",5),h(this,"enabled",!0),h(this,"alignToDirection",!1),h(this,"angle",0),h(this,"arc",360),h(this,"arcSpread"),h(this,"arcSpeedMultiplier"),h(this,"arcMode"),h(this,"boxThickness"),h(this,"position"),h(this,"rotation"),h(this,"_rotation",new Ur),h(this,"scale"),h(this,"radius"),h(this,"radiusThickness"),h(this,"sphericalDirectionAmount"),h(this,"randomDirectionAmount"),h(this,"randomPositionAmount"),h(this,"meshShapeType"),h(this,"meshRenderer"),h(this,"_meshObj"),h(this,"_meshGeometry"),h(this,"system"),h(this,"_space"),h(this,"_worldSpaceMatrix",new Te),h(this,"_worldSpaceMatrixInverse",new Te),h(this,"_vector",new w(0,0,0)),h(this,"_temp",new w(0,0,0)),h(this,"_triangle",new In),h(this,"_dir",new w),h(this,"_loopTime",0),h(this,"_loopDirection",1),mx&&console.log(this)}get type(){return gx[this.shapeType]}initialize(i){this.onInitialize(i),i.position.copy(this._vector)}toJSON(){return this}clone(){return new rA}setMesh(i){this.meshRenderer=i,i?(this._meshObj=i.sharedMeshes[Math.floor(Math.random()*i.sharedMeshes.length)],this._meshGeometry=this._meshObj.geometry):(this._meshObj=void 0,this._meshGeometry=void 0)}update(i,e,t,s){this.system=i,this._space=t,t===1&&(this._worldSpaceMatrix.copy(s.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(i){const e=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return e&&(this._rotation.x=st.toRadians(this.rotation.x),this._rotation.y=st.toRadians(this.rotation.y),this._rotation.z=st.toRadians(this.rotation.z),this._rotation.order="ZYX",i.applyEuler(this._rotation)),e}onInitialize(i){this._vector.set(0,0,0),i.mesh=void 0,i.mesh_geometry=void 0;const e=this._temp.copy(this.position),t=this._space===1;t&&e.applyQuaternion(this.system.worldQuaternion);let s=this.radius;if(t&&(s*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:mx&&Pt.DrawWireBox(this.position,this.scale,14540253,1),this._vector.x=Math.random()*this.scale.x-this.scale.x/2,this._vector.y=Math.random()*this.scale.y-this.scale.y/2,this._vector.z=Math.random()*this.scale.z-this.scale.z/2,this._vector.add(e);break;case 4:this.randomConePoint(this.position,this.angle,s,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,s,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,s,this.radiusThickness,this.arc,this._vector);break;case 13:const r=this.meshRenderer;r?.destroyed==!1&&this.setMesh(r);const n=i.mesh=this._meshObj,o=i.mesh_geometry=this._meshGeometry;if(n&&o)switch(this.meshShapeType){case 0:{const a=o.getAttribute("position"),l=Math.floor(Math.random()*a.count);this._vector.fromBufferAttribute(a,l),this._vector.applyMatrix4(n.matrixWorld),i.mesh_normal=l}break;case 1:break;case 2:{const a=o.index;if(a){let l=Math.random(),c=Math.random();l+c>1&&(l=1-l,c=1-c);const u=Math.floor(Math.random()*(a.count/3));let d=u*3,p=u*3+1,f=u*3+2;d=a.getX(d),p=a.getX(p),f=a.getX(f);const m=o.getAttribute("position");this._triangle.a.fromBufferAttribute(m,d),this._triangle.b.fromBufferAttribute(m,p),this._triangle.c.fromBufferAttribute(m,f),this._vector.set(0,0,0).addScaledVector(this._triangle.a,l).addScaledVector(this._triangle.b,c).addScaledVector(this._triangle.c,1-(l+c)),this._vector.applyMatrix4(n.matrixWorld),i.mesh_normal=u}}break}break;default:this._vector.set(0,0,0),wt()&&!globalThis.__particlesystem_shapetype_unsupported&&(console.warn("ParticleSystem ShapeType is not supported:",gx[this.shapeType]),globalThis.__particlesystem_shapetype_unsupported=!0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),t&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),mx&&Pt.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(i,e){var t;if(!this.enabled)return this._dir.set(0,0,1),this._dir;switch(this.shapeType){case 5:this._dir.set(0,0,1);break;case 4:this._dir.set(0,0,1);break;case 10:case 0:const s=e.x,r=e.y,n=e.z;this._dir.set(s,r,n),(t=this.system)!=null&&t.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;case 13:const o=i.mesh,a=i.mesh_geometry;if(o&&a)switch(this.meshShapeType){case 0:{const l=a.getAttribute("normal"),c=i.mesh_normal;this._dir.fromBufferAttribute(l,c)}break;case 1:break;case 2:{const l=a.index;if(l){const c=i.mesh_normal,u=l.getX(c*3),d=l.getX(c*3+1),p=l.getX(c*3+2),f=a.getAttribute("position"),m=Bs(),A=Bs(),y=Bs();m.fromBufferAttribute(f,u),A.fromBufferAttribute(f,d),y.fromBufferAttribute(f,p),m.sub(A),y.sub(A),m.cross(y),this._dir.copy(m).multiplyScalar(-1);const g=Ii(o);this._dir.applyQuaternion(g)}}break}break;default:this._dir.set(0,0,1);break}return this._space===1&&this._dir.applyQuaternion(this.system.worldQuaternion),this.applyRotation(this._dir),this._dir.normalize(),this.spherizeDirection(this._dir,this.sphericalDirectionAmount),this.randomizeDirection(this._dir,this.randomDirectionAmount),mx&&(Pt.DrawSphere(e,.01,8925952,.5,!0),Pt.DrawDirection(e,this._dir,8925952,.5,!0)),this._dir}randomizePosition(i,e){if(e<=0)return;const t=rA._tempVec;t.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),t.x*=e*this.scale.x,t.y*=e*this.scale.y,t.z*=e*this.scale.z,i.add(t)}randomizeDirection(i,e){if(e===0)return;const t=rA._randomQuat,s=rA._tempVec;s.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),t.setFromAxisAngle(s,e*Math.random()*Math.PI),i.applyQuaternion(t)}spherizeDirection(i,e){if(e===0)return;const t=Math.random()*Math.PI*2,s=Math.acos(1-Math.random()*2),r=Math.sin(s)*Math.cos(t),n=Math.sin(s)*Math.sin(t),o=Math.cos(s),a=new w(r,n,o);i.lerp(a,e)}randomSpherePoint(i,e,t,s,r){const n=Math.random(),o=Math.random(),a=2*Math.PI*n*(s/360),l=Math.acos(2*o-1),c=st.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,u=i.x+this.scale.x*(-c*Math.sin(l)*Math.cos(a)),d=i.y+this.scale.y*(c*Math.sin(l)*Math.sin(a)),p=i.z+this.scale.z*(c*Math.cos(l));r.x=u,r.y=d,r.z=p}randomCirclePoint(i,e,t,s,r){const n=Math.random(),o=2*Math.PI*n*(s/360),a=st.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,l=i.x+this.scale.x*a*Math.cos(o),c=i.y+this.scale.y*a*Math.sin(o),u=i.z;r.x=l,r.y=c,r.z=u}randomConePoint(i,e,t,s,r,n,o){let a=0,l=0;switch(n){case 0:a=Math.random(),l=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:a=.5,l=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let c=2*Math.PI*a*(r/360);switch(n){case 2:case 1:c+=Math.PI+.5,c+=this._loopTime*Math.PI*2,c%=st.toRadians(r);break}const u=Math.acos(2*l-1),d=st.lerp(1,1-Math.pow(1-Math.random(),Math.PI),s)*t,p=i.x+-d*Math.sin(u)*Math.cos(c),f=i.y+d*Math.sin(u)*Math.sin(c),m=i.z;o.x=p*this.scale.x,o.y=f*this.scale.y,o.z=m*this.scale.z}},h(Ax,"_randomQuat",new Ie),h(Ax,"_tempVec",new w),Ax);let os=rA;ie([x()],os.prototype,"shapeType",2),ie([x()],os.prototype,"enabled",2),ie([x()],os.prototype,"alignToDirection",2),ie([x()],os.prototype,"angle",2),ie([x()],os.prototype,"arc",2),ie([x()],os.prototype,"arcSpread",2),ie([x()],os.prototype,"arcSpeedMultiplier",2),ie([x()],os.prototype,"arcMode",2),ie([x(w)],os.prototype,"boxThickness",2),ie([x(w)],os.prototype,"position",2),ie([x(w)],os.prototype,"rotation",2),ie([x(w)],os.prototype,"scale",2),ie([x()],os.prototype,"radius",2),ie([x()],os.prototype,"radiusThickness",2),ie([x()],os.prototype,"sphericalDirectionAmount",2),ie([x()],os.prototype,"randomDirectionAmount",2),ie([x()],os.prototype,"randomPositionAmount",2),ie([x()],os.prototype,"meshShapeType",2),ie([x(Av)],os.prototype,"meshRenderer",2);class Ci{constructor(){h(this,"damping"),h(this,"enabled"),h(this,"frequency"),h(this,"octaveCount"),h(this,"octaveMultiplier"),h(this,"octaveScale"),h(this,"positionAmount"),h(this,"quality"),h(this,"remap"),h(this,"remapEnabled"),h(this,"remapMultiplier"),h(this,"remapX"),h(this,"remapXMultiplier"),h(this,"remapY"),h(this,"remapYMultiplier"),h(this,"remapZ"),h(this,"remapZMultiplier"),h(this,"scrollSpeedMultiplier"),h(this,"separateAxes"),h(this,"strengthMultiplier"),h(this,"strengthX"),h(this,"strengthXMultiplier"),h(this,"strengthY"),h(this,"strengthYMultiplier"),h(this,"strengthZ"),h(this,"strengthZMultiplier"),h(this,"_noise"),h(this,"_time",0),h(this,"_temp",new w)}update(e){this._time+=e.time.deltaTime*this.scrollSpeedMultiplier}apply(e,t,s,r,n,o){if(!this.enabled)return;this._noise||(this._noise=Bne(()=>0));const a=this._temp.set(t.x,t.y,t.z).multiplyScalar(this.frequency),l=this._noise(a.x,a.y,a.z,this._time),c=this._noise(a.x,a.y,a.z,this._time+1e3*this.frequency),u=this._noise(a.x,a.y,a.z,this._time+2e3*this.frequency);this._temp.set(l,c,u).normalize();const d=n/o;let p=this.positionAmount.evaluate(d);this.separateAxes?(this._temp.x*=p*this.strengthXMultiplier,this._temp.y*=p*this.strengthYMultiplier,this._temp.z*=p*this.strengthZMultiplier):(this.strengthX&&(p*=this.strengthX.evaluate(d)*1.5),this._temp.multiplyScalar(p)),s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z}}ie([x()],Ci.prototype,"damping",2),ie([x()],Ci.prototype,"enabled",2),ie([x()],Ci.prototype,"frequency",2),ie([x()],Ci.prototype,"octaveCount",2),ie([x()],Ci.prototype,"octaveMultiplier",2),ie([x()],Ci.prototype,"octaveScale",2),ie([x(ct)],Ci.prototype,"positionAmount",2),ie([x()],Ci.prototype,"quality",2),ie([x(ct)],Ci.prototype,"remap",2),ie([x()],Ci.prototype,"remapEnabled",2),ie([x()],Ci.prototype,"remapMultiplier",2),ie([x(ct)],Ci.prototype,"remapX",2),ie([x()],Ci.prototype,"remapXMultiplier",2),ie([x(ct)],Ci.prototype,"remapY",2),ie([x()],Ci.prototype,"remapYMultiplier",2),ie([x(ct)],Ci.prototype,"remapZ",2),ie([x()],Ci.prototype,"remapZMultiplier",2),ie([x()],Ci.prototype,"scrollSpeedMultiplier",2),ie([x()],Ci.prototype,"separateAxes",2),ie([x()],Ci.prototype,"strengthMultiplier",2),ie([x(ct)],Ci.prototype,"strengthX",2),ie([x()],Ci.prototype,"strengthXMultiplier",2),ie([x(ct)],Ci.prototype,"strengthY",2),ie([x()],Ci.prototype,"strengthYMultiplier",2),ie([x(ct)],Ci.prototype,"strengthZ",2),ie([x()],Ci.prototype,"strengthZMultiplier",2);class Ki{constructor(){h(this,"enabled"),h(this,"attachRibbonToTransform",!1),h(this,"colorOverLifetime"),h(this,"colorOverTrail"),h(this,"dieWithParticles",!0),h(this,"inheritParticleColor",!0),h(this,"lifetime"),h(this,"lifetimeMultiplier"),h(this,"minVertexDistance",.2),h(this,"mode",0),h(this,"ratio",1),h(this,"ribbonCount",1),h(this,"shadowBias",0),h(this,"sizeAffectsLifetime",!1),h(this,"sizeAffectsWidth",!1),h(this,"splitSubEmitterRibbons",!1),h(this,"textureMode",0),h(this,"widthOverTrail"),h(this,"widthOverTrailMultiplier"),h(this,"worldSpace",!1)}getWidth(e,t,s,r){const n=this.widthOverTrail.evaluate(s,r);return e*=n,e}getColor(e,t,s){const r=this.colorOverTrail.evaluate(s),n=this.colorOverLifetime.evaluate(t);e.x*=r.r*n.r,e.y*=r.g*n.g,e.z*=r.b*n.b,e.w*=r.alpha*n.alpha}}ie([x()],Ki.prototype,"enabled",2),ie([x()],Ki.prototype,"attachRibbonToTransform",2),ie([x(Gn)],Ki.prototype,"colorOverLifetime",2),ie([x(Gn)],Ki.prototype,"colorOverTrail",2),ie([x()],Ki.prototype,"dieWithParticles",2),ie([x()],Ki.prototype,"inheritParticleColor",2),ie([x(ct)],Ki.prototype,"lifetime",2),ie([x()],Ki.prototype,"lifetimeMultiplier",2),ie([x()],Ki.prototype,"minVertexDistance",2),ie([x()],Ki.prototype,"mode",2),ie([x()],Ki.prototype,"ratio",2),ie([x()],Ki.prototype,"ribbonCount",2),ie([x()],Ki.prototype,"shadowBias",2),ie([x()],Ki.prototype,"sizeAffectsLifetime",2),ie([x()],Ki.prototype,"sizeAffectsWidth",2),ie([x()],Ki.prototype,"splitSubEmitterRibbons",2),ie([x()],Ki.prototype,"textureMode",2),ie([x(ct)],Ki.prototype,"widthOverTrail",2),ie([x()],Ki.prototype,"widthOverTrailMultiplier",2),ie([x()],Ki.prototype,"worldSpace",2);class as{constructor(){h(this,"enabled"),h(this,"space",0),h(this,"orbitalX"),h(this,"orbitalY"),h(this,"orbitalZ"),h(this,"orbitalXMultiplier"),h(this,"orbitalYMultiplier"),h(this,"orbitalZMultiplier"),h(this,"orbitalOffsetX"),h(this,"orbitalOffsetY"),h(this,"orbitalOffsetZ"),h(this,"speedModifier"),h(this,"speedModifierMultiplier"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier"),h(this,"_system"),h(this,"_temp",new w),h(this,"_temp2",new w),h(this,"_temp3",new w),h(this,"_hasOrbital",!1),h(this,"_index",0),h(this,"_orbitalMatrix",new Te)}update(e){this._system=e}init(e){this._index==0&&(e.debug=!0),this._index+=1,e.orbitx=this.orbitalX.evaluate(Math.random()),e.orbity=this.orbitalY.evaluate(Math.random()),e.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=e.orbitx!=0||e.orbity!=0||e.orbitz!=0}apply(e,t,s,r,n,o,a){var l;if(!this.enabled)return;const c=o/a,u=this.speedModifier.evaluate(c)*this.speedModifierMultiplier,d=this.x.evaluate(c),p=this.y.evaluate(c),f=this.z.evaluate(c);if(this._temp.set(-d,p,f),this._system&&this._system.main.simulationSpace===1&&this._temp.applyQuaternion(this._system.worldQuaternion),this._hasOrbital&&((l=this._system)==null?void 0:l.worldPos)){const m=this._temp2.set(s.x,s.y,s.z),A=this.orbitalXMultiplier,y=this.orbitalYMultiplier,g=this.orbitalZMultiplier,v=u*Math.PI*2*10,b=Math.cos(v*A),_=Math.sin(v*A),S=Math.cos(v*y),M=Math.sin(v*y),C=Math.cos(v*g),R=Math.sin(v*g),I=m.x*(S*C)+m.y*(S*R)+m.z*-M,E=m.x*(_*M*C-b*R)+m.y*(_*M*R+b*C)+m.z*(_*S),z=m.x*(b*M*C+_*R)+m.y*(b*M*R-_*C)+m.z*(b*S),F=this._temp3.set(m.x-I,m.y-E,m.z-z);F.normalize(),F.multiplyScalar(.2/n*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),r.x+=F.x,r.y+=F.y,r.z+=F.z}r.x+=this._temp.x,r.y+=this._temp.y,r.z+=this._temp.z,r.x*=u,r.y*=u,r.z*=u}}ie([x()],as.prototype,"enabled",2),ie([x()],as.prototype,"space",2),ie([x(ct)],as.prototype,"orbitalX",2),ie([x(ct)],as.prototype,"orbitalY",2),ie([x(ct)],as.prototype,"orbitalZ",2),ie([x()],as.prototype,"orbitalXMultiplier",2),ie([x()],as.prototype,"orbitalYMultiplier",2),ie([x()],as.prototype,"orbitalZMultiplier",2),ie([x()],as.prototype,"orbitalOffsetX",2),ie([x()],as.prototype,"orbitalOffsetY",2),ie([x()],as.prototype,"orbitalOffsetZ",2),ie([x(ct)],as.prototype,"speedModifier",2),ie([x()],as.prototype,"speedModifierMultiplier",2),ie([x(ct)],as.prototype,"x",2),ie([x()],as.prototype,"xMultiplier",2),ie([x(ct)],as.prototype,"y",2),ie([x()],as.prototype,"yMultiplier",2),ie([x(ct)],as.prototype,"z",2),ie([x()],as.prototype,"zMultiplier",2);class Br{constructor(){h(this,"animation"),h(this,"enabled"),h(this,"cycleCount"),h(this,"frameOverTime"),h(this,"frameOverTimeMultiplier"),h(this,"numTilesX"),h(this,"numTilesY"),h(this,"startFrame"),h(this,"startFrameMultiplier"),h(this,"rowMode"),h(this,"rowIndex"),h(this,"spriteCount"),h(this,"timeMode")}sampleOnceAtStart(){if(this.timeMode===0)switch(this.frameOverTime.mode){case 0:case 3:case 2:case 1:return!0}return!1}getStartIndex(){return this.sampleOnceAtStart()?Math.random()*(this.numTilesX*this.numTilesY):0}evaluate(e){if(!this.sampleOnceAtStart())return this.getIndex(e)}getIndex(e){const t=this.numTilesX*this.numTilesY;e=e*this.cycleCount;let s=this.frameOverTime.evaluate(e%1);return s*=this.frameOverTimeMultiplier,s*=t,s=s%t,s=Math.floor(s),s}}ie([x()],Br.prototype,"animation",2),ie([x()],Br.prototype,"enabled",2),ie([x()],Br.prototype,"cycleCount",2),ie([x(ct)],Br.prototype,"frameOverTime",2),ie([x()],Br.prototype,"frameOverTimeMultiplier",2),ie([x()],Br.prototype,"numTilesX",2),ie([x()],Br.prototype,"numTilesY",2),ie([x(ct)],Br.prototype,"startFrame",2),ie([x()],Br.prototype,"startFrameMultiplier",2),ie([x()],Br.prototype,"rowMode",2),ie([x()],Br.prototype,"rowIndex",2),ie([x()],Br.prototype,"spriteCount",2),ie([x()],Br.prototype,"timeMode",2);class qo{constructor(){h(this,"enabled"),h(this,"separateAxes"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier")}evaluate(e,t){return this.enabled?this.separateAxes?0:this.z.evaluate(e,t)*-1:0}}ie([x()],qo.prototype,"enabled",2),ie([x()],qo.prototype,"separateAxes",2),ie([x(ct)],qo.prototype,"x",2),ie([x()],qo.prototype,"xMultiplier",2),ie([x(ct)],qo.prototype,"y",2),ie([x()],qo.prototype,"yMultiplier",2),ie([x(ct)],qo.prototype,"z",2),ie([x()],qo.prototype,"zMultiplier",2);class ao{constructor(){h(this,"enabled"),h(this,"range"),h(this,"separateAxes"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier")}evaluate(e,t){if(!this.enabled)return 0;if(!this.separateAxes){const s=st.lerp(this.range.x,this.range.y,t);return this.z.evaluate(s)*-1}return 0}}ie([x()],ao.prototype,"enabled",2),ie([x()],ao.prototype,"range",2),ie([x()],ao.prototype,"separateAxes",2),ie([x(ct)],ao.prototype,"x",2),ie([x()],ao.prototype,"xMultiplier",2),ie([x(ct)],ao.prototype,"y",2),ie([x()],ao.prototype,"yMultiplier",2),ie([x(ct)],ao.prototype,"z",2),ie([x()],ao.prototype,"zMultiplier",2);class Ls{constructor(){h(this,"enabled"),h(this,"dampen"),h(this,"drag"),h(this,"dragMultiplier"),h(this,"limit"),h(this,"limitMultiplier"),h(this,"separateAxes"),h(this,"limitX"),h(this,"limitXMultiplier"),h(this,"limitY"),h(this,"limitYMultiplier"),h(this,"limitZ"),h(this,"limitZMultiplier"),h(this,"multiplyDragByParticleSize",!1),h(this,"multiplyDragByParticleVelocity",!1),h(this,"space"),h(this,"_temp",new w),h(this,"_temp2",new w)}apply(e,t,s,r,n,o,a){if(this.enabled){const l=this.limit.evaluate(n)*this.limitMultiplier;if(t.length()>l){this._temp.copy(t).normalize().multiplyScalar(l);const c=this.dampen*.5;t.x=st.lerp(t.x,this._temp.x,c),t.y=st.lerp(t.y,this._temp.y,c),t.z=st.lerp(t.z,this._temp.z,c),s.x=st.lerp(s.x,this._temp.x,c),s.y=st.lerp(s.y,this._temp.y,c),s.z=st.lerp(s.z,this._temp.z,c)}}}}ie([x()],Ls.prototype,"enabled",2),ie([x()],Ls.prototype,"dampen",2),ie([x(ct)],Ls.prototype,"drag",2),ie([x()],Ls.prototype,"dragMultiplier",2),ie([x(ct)],Ls.prototype,"limit",2),ie([x()],Ls.prototype,"limitMultiplier",2),ie([x()],Ls.prototype,"separateAxes",2),ie([x(ct)],Ls.prototype,"limitX",2),ie([x()],Ls.prototype,"limitXMultiplier",2),ie([x(ct)],Ls.prototype,"limitY",2),ie([x()],Ls.prototype,"limitYMultiplier",2),ie([x(ct)],Ls.prototype,"limitZ",2),ie([x()],Ls.prototype,"limitZMultiplier",2),ie([x()],Ls.prototype,"multiplyDragByParticleSize",2),ie([x()],Ls.prototype,"multiplyDragByParticleVelocity",2),ie([x()],Ls.prototype,"space",2);const _j=class{constructor(){h(this,"enabled"),h(this,"curve"),h(this,"curveMultiplier"),h(this,"mode"),h(this,"system"),h(this,"_temp",new w),h(this,"_firstUpdate",!0),h(this,"_frames",0)}clone(){var i;const e=new _j;return e.enabled=this.enabled,e.curve=(i=this.curve)==null?void 0:i.clone(),e.curveMultiplier=this.curveMultiplier,e.mode=this.mode,e}get _lastWorldPosition(){return this.system._iv_lastWorldPosition||(this.system._iv_lastWorldPosition=new w),this.system._iv_lastWorldPosition}get _velocity(){return this.system._iv_velocity||(this.system._iv_velocity=new w),this.system._iv_velocity}awake(i){this.system=i,this.reset()}reset(){this._firstUpdate=!0}update(i){this.enabled&&this.system.worldspace!==!1&&(this._firstUpdate?(this._firstUpdate=!1,this._velocity.set(0,0,0),this._lastWorldPosition.copy(this.system.worldPos)):this._lastWorldPosition&&(this._velocity.copy(this.system.worldPos).sub(this._lastWorldPosition).multiplyScalar(1/this.system.deltaTime),this._lastWorldPosition.copy(this.system.worldPos)))}applyInitial(i){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const e=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(e),i.add(this._temp)}}applyCurrent(i,e,t){if(this.enabled&&this.system&&this.system.worldspace!==!1&&this.mode===1){const s=this.curve.evaluate(e,t);this._temp.copy(this._velocity).multiplyScalar(s),i.add(this._temp)}}};let Nh=_j;ie([x()],Nh.prototype,"enabled",2),ie([x(ct)],Nh.prototype,"curve",2),ie([x()],Nh.prototype,"curveMultiplier",2),ie([x()],Nh.prototype,"mode",2);class xn{constructor(){h(this,"enabled"),h(this,"range"),h(this,"separateAxes"),h(this,"size"),h(this,"sizeMultiplier"),h(this,"x"),h(this,"xMultiplier"),h(this,"y"),h(this,"yMultiplier"),h(this,"z"),h(this,"zMultiplier")}evaluate(e,t,s,r){const n=e.length(),o=st.remap(n,this.range.x,this.range.y,0,1),a=this.size.evaluate(o,s);return r*a}}ie([x()],xn.prototype,"enabled",2),ie([x(ee)],xn.prototype,"range",2),ie([x()],xn.prototype,"separateAxes",2),ie([x(ct)],xn.prototype,"size",2),ie([x()],xn.prototype,"sizeMultiplier",2),ie([x(ct)],xn.prototype,"x",2),ie([x()],xn.prototype,"xMultiplier",2),ie([x(ct)],xn.prototype,"y",2),ie([x()],xn.prototype,"yMultiplier",2),ie([x(ct)],xn.prototype,"z",2),ie([x()],xn.prototype,"zMultiplier",2);class Ad{constructor(){h(this,"enabled"),h(this,"range"),h(this,"color")}evaluate(e,t,s){const r=e.length(),n=st.remap(r,this.range.x,this.range.y,0,1),o=this.color.evaluate(n,t);s.x*=o.r,s.y*=o.g,s.z*=o.b,s.w*=o.alpha}}ie([x()],Ad.prototype,"enabled",2),ie([x(ee)],Ad.prototype,"range",2),ie([x(Gn)],Ad.prototype,"color",2);const Lne={name:"HorizontalBlurShader",uniforms:{tDiffuse:{value:null},h:{value:1/512}},vertexShader:`
|
|
5411
5413
|
|
|
5412
5414
|
varying vec2 vUv;
|
|
5413
5415
|
|