From a304d1e64193a1be7124134f9e067bdec185e29e Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Mon, 12 Jul 2021 14:58:13 +0200 Subject: [PATCH 1/4] minor correction --- README.md | 2 +- dist/a-game.js | 4 ++-- dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 4 ++-- src/components/grabbing/fingerflex.md | 9 ++++----- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4ffc577..f8bc897 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Essential game components for [A-Frame](https://aframe.io/)! - + diff --git a/dist/a-game.js b/dist/a-game.js index 7e47182..8596656 100644 --- a/dist/a-game.js +++ b/dist/a-game.js @@ -2,7 +2,7 @@ module.exports={ "name": "a-game", "title": "A-Game", - "version": "0.17.0", + "version": "0.17.1", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -11,7 +11,7 @@ module.exports={ "build": "foreach -g src/*.js -x \"browserify #{path} -o dist/#{name}.js\" && npm run minify", "watch": "foreach -g src/*.js -C -x \"watchify #{path} -d -o dist/#{name}.js\"", "minify": "touch dist/foo.min.js && rm dist/*.min.js && foreach -g dist/*.js -C -x \"minify #{path} > dist/#{name}.min.js\"", - "bump": "npm version minor --no-git-tag-version", + "bump": "npm version patch --no-git-tag-version", "gitadd": "git add package*.json dist/*.js" }, "pre-commit": [ diff --git a/dist/a-game.min.js b/dist/a-game.min.js index 46f88d2..bfded73 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,s,i){function o(a,r){if(!s[a]){if(!e[a]){var h="function"==typeof require&&require;if(!r&&h)return h(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=s[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,s,i)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;a dist/#{name}.min.js"',bump:"npm version minor --no-git-tag-version",gitadd:"git add package*.json dist/*.js"},"pre-commit":["bump","build","gitadd"],keywords:["aframe","webvr","webxr","gamedev"],author:"poeticAndroid",license:"MIT",devDependencies:{browserify:"^17.0.0","foreach-cli":"^1.8.1",minify:"^7.0.1","pre-commit":"^1.2.2",watchify:"^4.0.0"}}},{}],2:[function(t,e,s){t("./libs/pools"),t("./libs/copyWorldPosRot"),t("./libs/ensureElement"),t("./libs/touchGestures"),t("./libs/betterRaycaster"),setTimeout((()=>{document.body.addEventListener("swipeup",(t=>{document.body.requestFullscreen()}))})),t("./components/grabbing"),t("./components/include"),t("./components/injectplayer"),t("./components/locomotion"),t("./components/onevent"),t("./components/onstate"),t("./components/physics"),t("./components/script"),t("./components/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const i=t("../package");console.log(`${i.title} Version ${i.version} by ${i.author}\n(${i.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":9,"./components/injectplayer":10,"./components/locomotion":11,"./components/onevent":15,"./components/onstate":16,"./components/physics":17,"./components/script":21,"./components/trigger":22,"./libs/betterRaycaster":23,"./libs/copyWorldPosRot":25,"./libs/ensureElement":26,"./libs/pools":27,"./libs/touchGestures":28,"./primitives/a-hand":29,"./primitives/a-main":30,"./primitives/a-player":31}],3:[function(t,e,s){AFRAME.registerComponent("grabbing",{schema:{hideOnGrab:{type:"boolean",default:!0},grabDistance:{type:"number",default:1}},init(){this._enableHands=this._enableHands.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onWheel=this._onWheel.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchTap=this._onTouchTap.bind(this),this._onTouchHold=this._onTouchHold.bind(this),this._btnPress={},this._btnFlex={},this._keysDown={},this._grabCount=0,this._hands=["head","left","right"],this._head={},this._left={},this._right={},this._head.hand=this.el.querySelector("a-camera"),this._left.hand=this.el.querySelector('a-hand[side="left"]'),this._right.hand=this.el.querySelector('a-hand[side="right"]'),this._head.glove=this._head.hand.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._left.glove=this._ensureGlove(this._left.hand),this._right.glove=this._ensureGlove(this._right.hand),this._left.glove.setAttribute("visible",!1),this._right.glove.setAttribute("visible",!1);for(let t of this._hands){this["_"+t].hand.addEventListener("buttonchanged",this._enableHands)}this._head.ray=this._head.hand.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._head.buttonRay=this._head.hand.ensure(".button.ray","a-entity",{class:"button ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [button]",far:1,autoRefresh:!1}}),this._head.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,position:"0 0 -1"},''),this._head.buttonReticle=this._head.buttonRay.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,color:"black",position:"0 0 -1"},''),this._head.anchor=this._head.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:!1,body:"type:kinematic;autoShape:false;"})},update(t){for(let t of this._hands){let e="_"+t;this[e].ray&&this[e].ray.setAttribute("raycaster","far",this.data.grabDistance+("head"===t?1:.1875))}},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.addEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.addEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.addEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.addEventListener("hold",this._onTouchHold)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.removeEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.removeEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.removeEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.removeEventListener("hold",this._onTouchHold)},remove(){for(let t of this._hands){let e="_"+t;this.drop(t),this[e].glove.copyWorldPosRot(this[e].hand);let s=.25;for(let i=0;i<5;i++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:i,flex:s})}},tick(t,e){for(i=0,len=navigator.getGamepads().length;i{this.sticky=!1,this._flexFinger(t,5,.5)}),256)}},drop(t="head"){let e="_"+t;this.sticky||(this[e].anchor.removeAttribute("animation__rot"),this[e].anchor.removeAttribute("animation__pos"),this[e].glove.setAttribute("visible",!0),setTimeout((()=>{this[e].anchor.removeAttribute("joint__grab"),this[e].anchor.setAttribute("position","0 0 0"),this[e].anchor.setAttribute("rotation","0 0 0")}),32),setTimeout((()=>{this[e].glove.setAttribute("body","collidesWith",1)}),1024),this[e].grabbed&&(this.emit("drop",this[e].glove,this[e].grabbed),this._grabCount=Math.max(0,this._grabCount-1),this._grabCount||this.el.removeState("grabbing"),this._flexFinger(t,5,0),this[e].grabbed.removeState("grabbed"),this[e].grabbed=null))},dropObject(t){for(let e of this._hands){this["_"+e].grabbed===t&&this.drop(e)}},use(t="head",e=0){this.useDown(t,e),setTimeout((()=>{this.useUp(t,e)}),32)},useDown(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("usedown",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastButton&&(this[s]._lastClick=this[s]._lastButton,this.emit("press",this[s].glove,this[s]._lastClick,{button:e}),this[s]._lastClick.addState("pressed"))},useUp(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("useup",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastClick&&(this.emit("unpress",this[s].glove,this[s]._lastClick),this[s]._lastClick.removeState("pressed"),this[s]._lastClick=null)},moveHeadHand(t=0,e=0,s=0,i=0){this._head.anchor.object3D.position.z=Math.min(Math.max(-1.5,this._head.anchor.object3D.position.z+t),-.125);let o=THREE.Quaternion.temp().set(e,s,i,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,s,i={}){i.grabbing=this.el,i.grabbedElement=s,i.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(i.hand=t);e.emit(t,i),s&&s.emit(t,i)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let s=.0625;if(this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:s/2,height:s,depth:2*s}),this[e].glove.setAttribute("body","type:kinematic;"),"head"===t)continue;this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}});let i=this[e].glove.querySelector(".palm")||this[e].glove;this[e].ray=i.ensure(".grabbing.ray","a-entity",{class:"grabbing ray",position:"left"===t?"-0.0625 0 0.0625":"0.0625 0 0.0625",rotation:"left"===t?"0 -45 0":"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this[e].buttonRay=i.ensure(".button.ray","a-entity",{class:"button ray",position:"0 0.03125 0",rotation:"left"===t?"0 -8 0":"0 8 0",raycaster:{objects:"[wall], [button]",far:.5,autoRefresh:!1}}),this[e].anchor=this[e].ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this[e].glove.setAttribute("visible",!0)}this._head.ray=null,this._head.buttonRay=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),s=t.getAttribute("color")||"lightblue";return t.ensure(".glove","a-entity",{class:"glove",fingerflex:{min:"left"===e?-10:10,max:"left"===e?-90:90}},`\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n `)},_flexFinger(t,e,s){let i="_"+t;if(e<5)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s});else for(e-=5;e<5;e++)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s})},_onKeyDown(t){this._keysDown[t.code]=!0,"e"===t.key&&this.toggleGrab()},_onKeyUp(t){this._keysDown[t.code]=!1},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_onWheel(t){let e=0,s=0,i=0;return this._keysDown.Digit3&&t.deltaY>0&&(i+=-.125),this._keysDown.Digit3&&t.deltaY<0&&(i+=.125),this._keysDown.Digit2&&t.deltaY>0&&(s+=-.125),this._keysDown.Digit2&&t.deltaY<0&&(s+=.125),this._keysDown.Digit1&&t.deltaY>0&&(e+=.125),this._keysDown.Digit1&&t.deltaY<0&&(e+=-.125),e||s||i?this.moveHeadHand(0,e,s,i):t.deltaY>0?this.moveHeadHand(.125):t.deltaY<0?this.moveHeadHand(-.125):void 0},_onMouseUp(t){let e=t.button;this.useUp("head",e?e%2?e+1:e-1:e)},_onTouchTap(t){this.use()},_onTouchHold(t){this.toggleGrab()},_onButtonChanged(t){let e=t.srcElement.getAttribute("tracked-controls").hand,s="_"+e,i=-1,o=0;switch(t.detail.state.touched&&(o=.5),t.detail.state.pressed&&(o=1),t.detail.state.value&&(o=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=o,t.detail.id){case 0:i=1,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e);break;case 1:i=7,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.grab(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.drop(e);break;case 3:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,1),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,1);break;case 5:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,2),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,2)}this._btnPress[e+t.detail.id]=t.detail.state.pressed,(this.sticky||this[s]._lastButton)&&0!==i||this._flexFinger(e,i,o)}}),t("./grabbing/button"),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/button":4,"./grabbing/climbable":5,"./grabbing/fingerflex":6,"./grabbing/grabbable":7,"./grabbing/receptacle":8}],4:[function(t,e,s){AFRAME.registerComponent("button",{schema:{}})},{}],5:[function(t,e,s){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion]"),this._onBump=this._onBump.bind(this),this._onBumpThis=this._onBumpThis.bind(this),this._autoGrab=!0,setTimeout((()=>{this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._quat.copy(this.el.object3D.quaternion),this._lpos.copy(this.el.object3D.position),this.el.object3D.getWorldPosition(this._wpos),this._top=parseFloat(this.el.getAttribute("height")||1)/2+2}),256)},play(){this._player.addEventListener("bump",this._onBump),this.el.addEventListener("bump",this._onBumpThis)},pause(){this._player.removeEventListener("bump",this._onBump),this.el.removeEventListener("bump",this._onBumpThis),this._climbing=!1},tick(){if(!this._lpos)return;if(this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos),!this._climbing)return;let t=THREE.Vector3.temp();this._hand.object3D.getWorldPosition(t),t.sub(this._handpos).multiplyScalar(-1),"head"===this._handName&&(t.y=0,t.y=t.length(),this._handpos.y+=t.y),this._player.components.locomotion.stopFall(),this._player.components.locomotion.move(t),this._handpos.y-this._wpos.y>this._top&&this._player.components.grabbing.dropObject(this.el)},events:{grab(t){this._climbing=!0,this._handName=t.detail.hand,this._hand=t.detail.gloveElement.parentNode,this._hand.object3D.getWorldPosition(this._handpos),t.detail.intersection.distance>("head"===this._handName?.5:.25)?setTimeout(this._onBump,260):this._player.components.locomotion.jump(),clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.copy(this._player.components.locomotion.headPos)}),1024)},drop(t){this._climbing=!1,clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this._player.components.locomotion.toggleCrouch(!0),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.add(this._player.components.locomotion.centerPos).sub(this._player.components.locomotion.feetPos)}),512)}),256)}},_onBump(t){this._autoGrab||(this._player.components.grabbing.dropObject(this.el),clearTimeout(this._autoGrabTO),this._autoGrabTO=setTimeout((()=>{this._autoGrab=!0}),4096))},_onBumpThis(t){this._autoGrab&&(this._player.components.grabbing.grab(),this._autoGrab=!1)}})},{}],6:[function(t,e,s){AFRAME.registerComponent("fingerflex",{schema:{min:{type:"number",default:10},max:{type:"number",default:90}},init(){this._fingers=["thumb","index","middle","ring","little"],this._currentFlex=[0,0,0,0,0],this._targetFlex=[0,0,0,0,0]},tick(t,e){for(let t=0;t<5;t++){let e=this._fingers[t],s=this._currentFlex[t],i=this._targetFlex[t];s+=Math.random()*Math.random()*(i-s);let o=this.data.min+s*(this.data.max-this.data.min),n=this.el.querySelector(".bend."+e);for(;n;){let t=n.getAttribute("rotation");t.y=o,n.setAttribute("rotation",t),n=n.querySelector(".bend")}this._currentFlex[t]=s}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],7:[function(t,e,s){AFRAME.registerComponent("grabbable",{schema:{physics:{type:"boolean",default:!0},kinematicGrab:{type:"boolean",default:!0},fixed:{type:"boolean",default:!1},fixedPosition:{type:"vec3",default:{x:0,y:0,z:0}}},init(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:dynamic;")},events:{grab(){this.data.kinematicGrab&&this.el.setAttribute("body","type","kinematic")},drop(){this.data.physics&&this.el.setAttribute("body","type","dynamic")}}})},{}],8:[function(t,e,s){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125},onlyGrabbed:{type:"boolean",default:!1}},init(){this._anchor=this.el.ensure(".receptacle.anchor","a-entity",{class:"receptacle anchor",body:"type:kinematic;autoShape:false;"}),this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.nearest)return this.refreshObjects();let t=THREE.Vector3.temp(),e=THREE.Vector3.temp();this.el.object3D.localToWorld(t.set(0,0,0)),this.nearest.object3D.localToWorld(e.set(0,0,0)),e.sub(t),this._lastNearest&&this._lastNearest!==this.nearest?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this._lastNearest.removeState("put"),this.el.emit("take",{grabbable:this._lastNearest}),this._lastNearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this._lastNearest}),this._lastNearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):e.length()>this.data.radius?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this.nearest.removeState("put"),this.el.emit("take",{grabbable:this.nearest}),this.nearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this.nearest}),this.nearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):this.nearest.is("grabbed")||!this._hover?(this._hover||(this.el.emit("hover",{grabbable:this.nearest}),this.nearest.emit("hover",{receptacle:this.el})),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this._anchor.copyWorldPosRot(this.nearest),this._hover=!0,this.nearest.is("grabbed")&&(this._grabbed=!0)):!this._grabbed&&this.data.onlyGrabbed||(this.el.is("filled")||(this._anchor.copyWorldPosRot(this.nearest),this._anchor.components.body.commit(),this.nearest.components.body&&this._anchor.setAttribute("joint__put",{body2:this.nearest,type:"lock"}),this.el.addState("filled"),this.nearest.addState("put"),this.el.emit("put",{grabbable:this.nearest}),this.nearest.emit("put",{receptacle:this.el})),this._anchor.getAttribute("animation__pos")||(this._anchor.setAttribute("animation__pos",{property:"position",to:{x:0,y:0,z:0},dur:256}),this._anchor.setAttribute("animation__rot",{property:"rotation",to:{x:0,y:0,z:0},dur:256})),this.nearest.copyWorldPosRot(this._anchor),this._hover=!0),this._lastNearest=this.nearest},refreshObjects(){let t=1/0,e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Vector3.temp(),o=this.el.sceneEl.querySelectorAll(this.data.objects);this.nearest=null,o&&(this.el.object3D.localToWorld(e.set(0,0,0)),o.forEach((o=>{o.object3D.localToWorld(s.set(0,0,0)),i.copy(s).sub(e),t>i.length()&&(t=i.length(),this.nearest=o)})))}})},{}],9:[function(t,e,s){AFRAME.registerComponent("include",{schema:{type:"string"},async init(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),s=t.indexOf(" include="),i=t.substr(e,s-e);e=t.indexOf('"',s+10)+1,s=t.indexOf(">"),i+=t.substr(e,s-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+i+" "):this.el.removeAttribute("include"),this.el.sceneEl._including_=!1;let n=this.el.sceneEl.querySelector("[include]");n&&n.components&&n.components.include&&n.components.include.init()}}})},{}],10:[function(t,e,s){AFRAME.registerComponent("injectplayer",{init(){this.el.ensure("a-camera","a-camera",{"look-controls":{pointerLockEnabled:!0,touchEnabled:!1},"wasd-controls":{enabled:!1}}),this.el.ensure('a-hand[side="left"]',"a-hand",{side:"left"}),this.el.ensure('a-hand[side="right"]',"a-hand",{side:"right"})}})},{}],11:[function(t,e,s){AFRAME.registerComponent("locomotion",{dependencies:["position","injectplayer"],schema:{speed:{type:"number",default:4},stepLength:{type:"number",default:1},rotationSpeed:{type:"number",default:1},teleportDistance:{type:"number",default:5},jumpForce:{type:"number",default:4},gravity:{type:"number",default:10},godMode:{type:"boolean",default:!1}},init(){this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onAxisMove=this._onAxisMove.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onEnterVR=this._onEnterVR.bind(this),this._onExitVR=this._onExitVR.bind(this),this._keysDown={},this._kbStick=new THREE.Vector2,this._axes=[0,0,0,0],this._leftTouchCenter=new THREE.Vector2,this._leftTouchDir=new THREE.Vector2,this._rightTouchCenter=new THREE.Vector2,this._rightTouchDir=new THREE.Vector2,this._teleporting=!0,this._bumpOverload=0,this._vertVelocity=1,this.currentFloorPosition=new THREE.Vector3,this.centerPos=new THREE.Vector3,this.headPos=new THREE.Vector3,this.headDir=new THREE.Vector3,this.feetPos=new THREE.Vector3,this.lastStep=new THREE.Vector3,this._config={quantizeMovement:!1,quantizeRotation:!1,quantizeMovementVR:!!this.el.sceneEl.isMobile,quantizeRotationVR:!0},this.el.sceneEl.is("vr-mode")?this._onEnterVR():this._onExitVR(),this._camera=this.el.querySelector("a-camera"),this._leftHand=this.el.querySelector('a-hand[side="left"]'),this._rightHand=this.el.querySelector('a-hand[side="right"]'),this._legs=this.el.sceneEl.ensure(".legs","a-entity",{class:"legs",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[floor]",direction:"0 -1 0",far:.625}}),this._legBumper=this.el.sceneEl.ensure(".leg-bumper","a-entity",{class:"leg-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._headBumper=this.el.sceneEl.ensure(".head-bumper","a-entity",{class:"head-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportBeam=this._camera.ensure(".teleport-ray","a-entity",{class:"teleport-ray",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportCursor=this.el.ensure(".teleport-cursor","a-cylinder",{class:"teleport-cursor",radius:.5,height:.0625,material:"opacity:0.5;"}),this._teleportCursor.setAttribute("visible",!1)},update(t){this._godMode=this.data.godMode},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._leftHand.addEventListener("axismove",this._onAxisMove),this._rightHand.addEventListener("axismove",this._onAxisMove),this._leftHand.addEventListener("buttonchanged",this._onButtonChanged),this._rightHand.addEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.addEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.addEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.addEventListener("touchend",this._onTouchEnd),this.el.sceneEl.addEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.addEventListener("exit-vr",this._onExitVR)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this._leftHand.removeEventListener("axismove",this._onAxisMove),this._rightHand.removeEventListener("axismove",this._onAxisMove),this._leftHand.removeEventListener("buttonchanged",this._onButtonChanged),this._rightHand.removeEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.removeEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.removeEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.removeEventListener("touchend",this._onTouchEnd),this.el.sceneEl.removeEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.removeEventListener("exit-vr",this._onExitVR)},remove(){this.el.sceneEl.removeChild(this._legs),this.el.sceneEl.removeChild(this._legBumper),this.el.sceneEl.removeChild(this._headBumper)},tick(t,e){e/=1e3,this.el.object3D.localToWorld(this.centerPos.set(0,0,0)),this.headPos.copy(this._camera.object3D.position),this._camera.object3D.parent.localToWorld(this.headPos),this.headDir.set(0,0,-1).applyQuaternion(this._camera.object3D.quaternion).applyQuaternion(this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp())),this._legs.object3D.localToWorld(this.feetPos.set(0,0,0)),this.feetPos.y-=.5,this._applyButtons(e),this._applyMoveStick(e),this._applyAuxStick(e);let s=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(s.y=0,(s.length()>.5||!this.currentFloor)&&(this.currentFloor&&s.multiplyScalar(.1),this._legs.object3D.position.add(s),this.feetPos.add(s)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let s=t.intersections[0];if(s&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===s.el){let t=THREE.Vector3.temp();t.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition),this.move(t),this.lastStep.add(t),t.y=0,this._legs.object3D.position.add(t)}else this.currentFloor&&this.currentFloor.emit("leave"),s.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-s.distance,0)),this.currentFloor=s.el,this.currentFloorPosition.copy(this.currentFloor.object3D.position)}else this.currentFloor&&this.currentFloor.emit("leave"),this._vertVelocity-=this.data.gravity*e,this.move(THREE.Vector3.temp().set(0,Math.max(-.5,this._vertVelocity*e),0)),this.currentFloor=null}if(this._godMode)this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position);else if(this._bumpOverload>4||Math.abs(this.headPos.y-this.feetPos.y)>3)this.feetPos.y=this.centerPos.y,this._legs.object3D.position.y=this.feetPos.y+.5,this.teleport(this._legBumper.object3D.position,!0),this._bumpOverload&&this._bumpOverload--;else{let t=THREE.Vector3.temp();t.copy(this.feetPos).y+=.5,this._bump(t,this._legBumper),t.copy(this.headPos),this._bump(t,this._headBumper)}let i=THREE.Vector3.temp();if(i.copy(this.feetPos).sub(this.lastStep),i.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));i.length()>this.data.stepLength;)i.multiplyScalar(this.data.stepLength/i.length()),this.lastStep.add(i),i.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let s=THREE.Vector3.temp();s.copy(t).sub(this.feetPos),this.move(s),this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._caution=8,e&&(this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position))},jump(){this.currentFloor&&(this._vertVelocity=this.data.jumpForce)},stopFall(){this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._vertVelocity=Math.max(this._vertVelocity,0)},toggleCrouch(t){let e,s=this.headPos.y-this.feetPos.y;clearTimeout(this._crouchResetTO),this._crouchResetTO=null,Math.abs(this.centerPos.y-this.feetPos.y)>.03125?e=this.feetPos.y-this.centerPos.y:t||(e=s>1?-1:1),this.el.removeAttribute("animation"),e&&this.el.setAttribute("animation",{property:"object3D.position.y",to:this.el.object3D.position.y+e,dur:256})},move(t){this.el.object3D.position.add(t),this.centerPos.add(t),this.headPos.add(t),this._legs.object3D.position.y+=t.y,this.feetPos.y+=t.y},_bump(t,e){let s=THREE.Matrix3.temp(),i=THREE.Vector3.temp();i.copy(t),i.sub(e.object3D.position);let o=i.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${i.x} ${i.y} ${i.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),s.getNormalMatrix(a.el.object3D.matrixWorld),i.copy(a.face.normal).applyMatrix3(s).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(i),e.object3D.position.add(i),this._legs.object3D.position.y!==t&&(e===this._headBumper&&this._headBumper.object3D.position.copy(this._legBumper.object3D.position),clearTimeout(this._crouchResetTO),this._crouchResetTO=setTimeout((()=>{this.toggleCrouch(!0)}),4096)),this._legs.object3D.position.add(i),this._legs.object3D.position.y=Math.max(t,this.headPos.y-1.5),this._caution=4,this._bumpOverload++,this._vertVelocity=Math.min(0,this._vertVelocity);let n={player:this.el,object:a.el};this.el.emit("bump",n),a.el.emit("bump",n)}else this._caution?this._caution--:(this._bumpOverload&&this._bumpOverload--,e.object3D.position.lerp(t,.25))}},_callMoveStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.KeyA&&e.x--,this._keysDown.KeyD&&e.x++,(this._keysDown.KeyW||this._keysDown.ArrowUp)&&e.y--,(this._keysDown.KeyS||this._keysDown.ArrowDown)&&e.y++,this._kbStick.length()>.1?this._kbStick.multiplyScalar((this._kbStick.length()-.1)/this._kbStick.length()):this._kbStick.set(0,0),this._kbStick.add(e.multiplyScalar(.2)),this._kbStick.length()>1&&this._kbStick.normalize(),this._kbStick.length()>t.length()&&t.copy(this._kbStick),this._deadZone(e.set(this._axes[0],this._axes[1])),e.length()>t.length()&&t.copy(e),e.copy(this._leftTouchDir),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyMoveStick(t){let e=this._callMoveStick();e.multiplyScalar(this.data.speed),e.multiplyScalar(t);let s=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,i=Math.cos(s)*e.x-Math.sin(s)*e.y,o=Math.sin(s)*e.x+Math.cos(s)*e.y,n=THREE.Vector3.temp().set(i,0,o);this.quantizeMovement&&(this._quantTime=this._quantTime||0,this._quantDelta=this._quantDelta||new THREE.Vector3,this._quantTime+=t,this._quantDelta.add(n),this._quantTime>.25?(this._quantTime-=.25,n.copy(this._quantDelta),this._quantDelta.set(0,0,0)):n.set(0,0,0)),this.move(n)},_callAuxStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.ArrowLeft&&e.x--,this._keysDown.ArrowRight&&e.x++,this._keysDown.KeyQ&&e.y--,this._keysDown.KeyC&&e.y++,e.length()>t.length()&&t.copy(e),this._fourWay(this._deadZone(e.set(this._axes[2],this._axes[3]))),e.length()>t.length()&&t.copy(e),this._fourWay(e.copy(this._rightTouchDir)),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyAuxStick(t){let e=this._callAuxStick(),s=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,s=-Math.round(e.x)*Math.PI/4):this._rotating=!1:s=-e.x*this.data.rotationSpeed*t,s){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),i=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-s),i.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(s),this.el.object3D.position.add(i),this.centerPos.add(i)}if(this._godMode)this.el.object3D.position.y+=-e.y*this.data.speed*t,this._legs.object3D.position.y+=-e.y*this.data.speed*t;else if(Math.round(e.y)>0?this._crouching||(this._crouching=!0,this.toggleCrouch()):this._crouching=!1,Math.round(e.y)<0){!this._teleporting&&this.data.teleportDistance&&(this._teleportCursor.setAttribute("visible",!0),this._teleporting=!0);let t=THREE.Quaternion.temp();if(this._teleportCursor.object3D.getWorldQuaternion(t),this._teleportCursor.object3D.quaternion.multiply(t.conjugate().normalize()).multiply(t.copy(this.el.object3D.quaternion).multiply(this._camera.object3D.quaternion)),this._teleportCursor.object3D.quaternion.x=0,this._teleportCursor.object3D.quaternion.z=0,this._teleportCursor.object3D.quaternion.normalize(),ray=this._teleportBeam.components.raycaster,ray.refreshObjects(),hit=ray.intersections[0],hit&&null!=hit.el.getAttribute("floor")){let e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Matrix3.temp();s.copy(hit.point).sub(this.feetPos),s.y>1.5&&s.multiplyScalar(0),s.length()>this.data.teleportDistance&&s.normalize().multiplyScalar(this.data.teleportDistance),s.add(this.feetPos),this._teleportCursor.object3D.position.copy(s),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),i.getNormalMatrix(hit.el.object3D.matrixWorld),s.copy(hit.face.normal).applyMatrix3(i).normalize(),s.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,s),this._teleportCursor.object3D.quaternion.premultiply(t)}else this._teleportCursor.object3D.position.copy(this.feetPos),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position)}else if(this._teleporting){let t=THREE.Vector3.temp();this._teleportCursor.object3D.localToWorld(t.set(0,0,0)),this.teleport(t),this._teleportCursor.setAttribute("visible",!1),this._teleportCursor.setAttribute("position","0 0 0"),this._teleporting=!1}},_callButtons(){let t=0;for(this._keysDown.Space&&(t|=1),this._keysDown.KeyG&&(t|=2),this._vrRightClick&&(t|=1),this._vrLeftClick&&(t|=2),i=0,len=navigator.getGamepads().length;i(t.length()>e?t.multiplyScalar((t.length()-e)/(1-e)/t.length()):t.set(0,0),t),_fourWay(t){let e=t.length();return Math.abs(t.x)>Math.abs(t.y)?t.y=0:t.x=0,t.multiplyScalar(e/t.length()),t},_onKeyDown(t){this._keysDown[t.code]=!0},_onKeyUp(t){this._keysDown[t.code]=!1},_onAxisMove(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?(this._axes[0]=t.detail.axis[2],this._axes[1]=t.detail.axis[3]):(this._axes[2]=t.detail.axis[2],this._axes[3]=t.detail.axis[3]),this._handEnabled||(this._teleportBeam.parentElement.removeChild(this._teleportBeam),this._teleportBeam=this._rightHand.ensure(".teleportBeam","a-entity",{class:"teleportBeam",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._handEnabled=!0)},_onButtonChanged(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?3==t.detail.id&&(this._vrLeftClick=t.detail.state.pressed):3==t.detail.id&&(this._vrRightClick=t.detail.state.pressed)},_onTouchStart(t){let e=this.el.sceneEl.canvas.clientWidth;for(let s=0;se/2&&(this._rightTouchId=i.identifier,this._rightTouchCenter.set(i.clientX,i.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),i.add(o),o.multiplyScalar(32/o.length())),o.divideScalar(32))}t.preventDefault()},_onTouchEnd(t){for(let e=0;e{this.init()}),256);let e=new THREE.Vector3;setTimeout((()=>{this.el.object3D.localToWorld(e.set(0,0,0)),t.teleport(e,!0),setTimeout((()=>{t.toggleCrouch(!0)}),256)}),256)}})},{}],14:[function(t,e,s){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],15:[function(t,e,s){AFRAME.registerComponent("onevent",{multiple:!0,schema:{event:{type:"string"},entity:{type:"selector"},property:{type:"string"},value:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this.pause(),this._event=this.data.event||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._value=this.data.value||"",this.el.isPlaying&&this.play()},play(){this._event&&this.el.addEventListener(this._event,this.trigger)},pause(){this._event&&this.el.removeEventListener(this._event,this.trigger)},trigger(t){let e=this._property.split(".");e.push(this._value),this._entity.setAttribute(...e)}})},{}],16:[function(t,e,s){AFRAME.registerComponent("onstate",{multiple:!0,schema:{state:{type:"string"},entity:{type:"selector"},property:{type:"string"},on:{type:"string"},off:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this._state=this.data.state||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._on=this.data.on||"",this._off=this.data.off||""},play(){this.trigger(),this.el.addEventListener("stateadded",this.trigger),this.el.addEventListener("stateremoved",this.trigger)},pause(){this.el.removeEventListener("stateadded",this.trigger),this.el.removeEventListener("stateremoved",this.trigger)},trigger(t){if(t&&t.detail!==this._state)return;let e=this._property.split(".");e.push(this.el.is(this._state)?this._on:this._off),this._entity.setAttribute(...e)}})},{}],17:[function(t,e,s){const i=t("../libs/cmdCodec"),o=t("../../package");AFRAME.registerSystem("physics",{schema:{workerUrl:{type:"string",default:`https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v${o.version}/dist/cannonWorker.min.js`},gravity:{type:"vec3",default:{x:0,y:-10,z:0}},debug:{type:"boolean",default:!1}},update(){if(this.data.workerUrl){if(!this.worker){if(this.data.workerUrl.includes("//")){let t=`importScripts(${JSON.stringify(this.data.workerUrl)})`;this.worker=new Worker(`data:text/javascript;base64,${btoa(t)}`)}else this.worker=new Worker(this.data.workerUrl);this.worker.postMessage("log "+i.stringifyParam("Physics worker ready!")),this.worker.addEventListener("message",this.onMessage.bind(this))}this.bodies=this.bodies||[],this.movingBodies=this.movingBodies||[],this.joints=this.joints||[],this.buffers=[new Float64Array(8),new Float64Array(8)],this.worker.postMessage("world gravity = "+i.stringifyParam(this.data.gravity)),this._debug=this.data.debug}else this.remove()},remove(){this.worker&&this.worker.terminate(),this.worker=null,this.bodies=[],this.movingBodies=[]},tick(t,e){if(!this.worker)return;if(this.buffers.length<2)return;let s=this.buffers.shift();if(s.length<8*this.movingBodies.length){let t=s.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;s=new Float64Array(t),s.fill(NaN);let i=THREE.Vector3.temp(),o=THREE.Quaternion.temp();for(let t=0;t2;)this.buffers.shift()},command(t){switch("number"==typeof t[0]&&t.shift(),t.shift()){case"body":let e=t.shift(),s=this.bodies[e];s&&s.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+i.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":24,"./physics/body":18,"./physics/joint":19,"./physics/shape":20}],18:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("body",{dependencies:["position","rotation","scale"],schema:{type:{type:"string",default:"dynamic"},mass:{type:"number",default:1},friction:{type:"number",default:.3},restitution:{type:"number",default:.3},belongsTo:{type:"int",default:1},collidesWith:{type:"int",default:1},emitsWith:{type:"int",default:0},sleeping:{type:"boolean",default:!1},autoShape:{type:"boolean",default:!0}},init(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies,o=this.el.sceneEl.systems.physics.buffers[0];if(!t)return;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el,"static"!==this.data.type?(this.mid=s.indexOf(null),this.mid<0&&(this.mid=s.length),s[this.mid]=this.el):this.mid=null;let n={mid:this.mid};if(n.type=this.data.type,n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),null!==this.mid){let t=8*this.mid;o[t++]=n.position.x,o[t++]=n.position.y,o[t++]=n.position.z,o[t++]=this.data.sleeping,o[t++]=n.quaternion.x,o[t++]=n.quaternion.y,o[t++]=n.quaternion.z,o[t++]=n.quaternion.w}if(this.shapes=[],this.sleeping=!0,t.postMessage("world body "+this.id+" create "+i.stringifyParam(n)),setTimeout((()=>{n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),t.postMessage("world body "+this.id+" position = "+i.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+i.stringifyParam(n.quaternion)),this.el.components.shape&&this.el.components.shape.play();let e=this.el.querySelectorAll("[shape]");e&&e.forEach((t=>{t.components.shape&&t.components.shape.play()})),this.el.components.joint&&this.el.components.joint.play();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].play()})),this.data.autoShape&&!this.el.getAttribute("shape"))if(this.el.firstElementChild){let t=this.el.querySelectorAll("a-box, a-sphere, a-cylinder");t&&t.forEach((t=>{t.getAttribute("shape")||t.setAttribute("shape",!0)}))}else this.el.setAttribute("shape",!0);this._initiated=!0},play(){this._initiated||(this.init(),this.update({}))},update(t){let e=this.el.sceneEl.systems.physics.worker;e&&(this.data.type!==t.type&&e.postMessage("world body "+this.id+" type = "+i.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+i.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+i.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+i.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+i.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+i.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+i.stringifyParam(this.data.emitsWith)),setTimeout((()=>{e.postMessage("world body "+this.id+" sleeping = "+!!this.data.sleeping)})))},sleep(){let t=this.el.sceneEl.systems.physics.worker;t&&(t.postMessage("world body "+this.id+" sleeping = true"),this.sleeping=!0)},pause(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies;if(!t)return;this.el.components.joint&&this.el.components.joint.pause();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].pause();let i=this.el.querySelectorAll("[shape]");i&&i.forEach((t=>{t.components.shape&&t.components.shape.pause()})),this.el.components.shape&&this.el.components.shape.pause(),e[this.id]=null,null!==this.mid&&(s[this.mid]=null),t.postMessage("world body "+this.id+" remove"),this._initiated=!1},tick(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.buffers[0];if(t&&null!==this.mid){let t=8*this.mid;if(e.length<=t)return;if("kinematic"===this.data.type){let s=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,this.sleeping=!!e[t++];let i=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,e[t++]=i.w}else if(e[t+1]){let s=THREE.Quaternion.temp();this.el.object3D.position.set(e[t++],e[t++],e[t++]),this.el.object3D.parent.worldToLocal(this.el.object3D.position),this.sleeping=!!e[t++],this.el.object3D.getWorldQuaternion(s),this.el.object3D.quaternion.multiply(s.conjugate().normalize()),s.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(s.normalize())}}},command(t){switch(t.shift()){case"emits":let e=t.shift();switch(e.event){case"collision":let t=this.el.sceneEl.systems.physics.bodies;if(e.body1=t[e.body1],e.body2=t[e.body2],!e.body1||!e.body2)return;e.shape1=e.body1.components.body.shapes[e.shape1],e.shape2=e.body2.components.body.shapes[e.shape2]}this.el.emit(e.event,e)}},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.id+" eval "+i.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),s=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+i.stringifyParam(e)),this.el.object3D.getWorldQuaternion(s),t.postMessage("world body "+this.id+" quaternion "+i.stringifyParam(s))}})},{"../../libs/cmdCodec":24}],19:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("joint",{multiple:!0,schema:{type:{type:"string",default:"ball"},body1:{type:"selector"},body2:{type:"selector"},pivot1:{type:"vec3",default:{x:0,y:0,z:0}},pivot2:{type:"vec3",default:{x:0,y:0,z:0}},axis1:{type:"vec3",default:{x:0,y:1,z:0}},axis2:{type:"vec3",default:{x:0,y:1,z:0}},min:{type:"number",default:0},max:{type:"number",default:1},collision:{type:"boolean",default:!0}},play(){if(null!=this._id)return;let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;if(!t)return;if(!this.data.body1.components.body)return this._retry=setTimeout((()=>{this.play()}),256);if(!this.data.body2.components.body)return this._retry=setTimeout((()=>{this.play()}),256);this._id=e.indexOf(null),this._id<0&&(this._id=e.length),e[this._id]=this.el;let s={};s.type=this.data.type,s.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,s.body2=this.data.body2.components.body.id,s.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),s.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),s.axis1=this.data.axis1,s.axis2=this.data.axis2,s.min=this.data.min,s.max=this.data.max,s.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.pivot1.multiply(o),s.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+i.stringifyParam(s))},update(t){this.el.sceneEl.systems.physics.worker&&(this.data.body1=this.data.body1||this.el)},pause(){clearTimeout(this._retry);let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;t&&(e[this._id]=null,t.postMessage("world joint "+this._id+" remove"),this._id=null)},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world joint "+this._id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],20:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("shape",{schema:{},play(){if(null!=this.id)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;for(this.body=this.el;this.body&&!this.body.matches("[body]");)this.body=this.body.parentElement;if(!this.body)return this._retry=setTimeout((()=>{this.play()}),256);this.bodyId=this.body.components.body.id;let e=this.body.components.body.shapes;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el;let s={};s.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(s.position),s.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(s.quaternion.multiply(o.conjugate().normalize()).normalize(),s.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":s.type="sphere",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":s.type="cylinder",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":s.type="box",s.size.set(parseFloat(this.el.getAttribute("width")||1),parseFloat(this.el.getAttribute("height")||1),parseFloat(this.el.getAttribute("depth")||1))}let n=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.size.multiply(n),s.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+i.stringifyParam(s))},pause(){if(clearTimeout(this._retry),!this.body)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;let e=this.body.components.body.shapes;t.postMessage("world body "+this.bodyId+" shape "+this.id+" remove"),e[this.id]=null,this.id=null},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.bodyId+" shape "+this.id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],21:[function(require,module,exports){AFRAME.registerComponent("script",{schema:{src:{type:"string"},call:{type:"string"},args:{type:"array"}},async update(oldData){if(this.data.src!==oldData.src){this.script&&(this.el.isPlaying&&this.script.pause?.(),this.script.remove?.()),this.script=null;let response=await fetch(this.data.src);if(response.status>=200&&response.status<300){if(this.script=eval(await await response.text()),this.script.el=this.el,this.script.events)for(let t in this.script.events)this.script.events[t]=this.script.events[t].bind(this.script)}else console.error("Could not load",this.data.src);this.script.init?.(),this.el.isPlaying&&this.script.play?.()}this.script&&this.data.call?.trim()&&(this.script[this.data.call.trim()](...this.data.args),this.el.setAttribute("script","call",""))},remove(){this.script&&this.script.remove?.(...arguments)},tick(){this.script&&this.script.tick?.(...arguments)},tock(){this.script&&this.script.tock?.(...arguments)},play(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.addEventListener(t,this.script.events[t]);this.script.play?.(...arguments)}},pause(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.removeEventListener(t,this.script.events[t]);this.script.pause?.(...arguments)}}})},{}],22:[function(t,e,s){AFRAME.registerComponent("trigger",{schema:{objects:{type:"string",default:"[camera]"}},init(){this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){this.objects||this.refreshObjects();let t,e=THREE.Vector3.temp(),s=parseFloat(this.el.getAttribute("width")||1),i=parseFloat(this.el.getAttribute("height")||1),o=parseFloat(this.el.getAttribute("depth")||1),n=parseFloat(this.el.getAttribute("radius")||1);for(let a of this.objects){switch(a.object3D.localToWorld(e.set(0,0,0)),this.el.object3D.worldToLocal(e),this.el.tagName.toLowerCase()){case"a-sphere":t=e.length()=0){let t={trigger:this.el,object:a};this.el.emit("untrigger",t),a.emit("untrigger",t),this.triggered.splice(this.triggered.indexOf(a),1),this.triggered.length||this.el.removeState("triggered")}}},refreshObjects(){this.objects=this.objects||[],this.triggered=this.triggered||[],this.objects.splice(0,this.objects.length);let t=this.el.sceneEl.querySelectorAll(this.data.objects);if(t){t.forEach((t=>{this.objects.push(t)}));for(let t=0;t=0)return t;return(t+", ").replaceAll(","," *,")+t}AFRAME.components.raycaster.Component.prototype.update=function(){return this._matchSelector=this.data.objects,this.data.objects=n(this.data.objects),i.apply(this,arguments)},AFRAME.components.raycaster.Component.prototype.refreshObjects=function(){let t=o.apply(this,arguments),e=this.intersections;for(let t of e)for(t.el=t.object.el;t.el&&!t.el.matches(this._matchSelector);)t.el=t.el.parentNode;return t}},{}],24:[function(t,e,s){e.exports={parse(t){let e=t.split(" "),s=[];for(let t of e)if(t)try{s.push(JSON.parse(t))}catch(e){"="!==t&&s.push(t)}return s},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],25:[function(t,e,s){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),s=t.object3D,i=this.object3D;s&&i&&i.parent&&(s.localToWorld(i.position.set(0,0,0)),i.parent.worldToLocal(i.position),i.getWorldQuaternion(e),i.quaternion.multiply(e.conjugate().normalize()),s.getWorldQuaternion(e),i.quaternion.multiply(e.normalize()))}},{}],26:[function(t,e,s){Element.prototype.ensure=function(t,e=t,s={},i=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),s)a=s[n],o.setAttribute(n,a);o.innerHTML=i}return o}},{}],27:[function(t,e,s){function i(t){t._pool=[],t._inUse=[],t.temp=function(){let e=t._pool.pop()||new t;return t._inUse.push(e),t._gc||(t._gc=setTimeout(t._recycle)),e},t._recycle=function(){for(;t._inUse.length;)t._pool.push(t._inUse.pop());t._gc=!1}}i(THREE.Vector2),i(THREE.Vector3),i(THREE.Quaternion),i(THREE.Matrix3),i(THREE.Matrix4)},{}],28:[function(t,e,s){let i=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,s,i,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,s)=>{if(t._tgest.handlers[e])for(let i of t._tgest.handlers[e])i(s);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,s=t.changedTouches[0].screenY,o=!1,i=setTimeout((()=>{o=!0,n("hold",t)}),512)})),t.addEventListener("touchmove",(t=>{let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))>32){if(clearTimeout(i),o)return;Math.abs(e-a)>Math.abs(s-r)?n(a{clearTimeout(i);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))<32){if(o)return;n("tap",t)}})),t._tgest};Element.prototype.addEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":n(this).handlers[t].push(e);break;default:return i.call(this,t,e)}},Element.prototype.removeEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":let s=n(this),i=s.handlers[t].indexOf(e);i>=0&&s.handlers[t].splice(i,1);break;default:return o.call(this,t,e)}}},{}],29:[function(t,e,s){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],30:[function(t,e,s){AFRAME.registerPrimitive("a-main",{})},{}],31:[function(t,e,s){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,s,i){function o(a,r){if(!s[a]){if(!e[a]){var h="function"==typeof require&&require;if(!r&&h)return h(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=s[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,s,i)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;a dist/#{name}.min.js"',bump:"npm version patch --no-git-tag-version",gitadd:"git add package*.json dist/*.js"},"pre-commit":["bump","build","gitadd"],keywords:["aframe","webvr","webxr","gamedev"],author:"poeticAndroid",license:"MIT",devDependencies:{browserify:"^17.0.0","foreach-cli":"^1.8.1",minify:"^7.0.1","pre-commit":"^1.2.2",watchify:"^4.0.0"}}},{}],2:[function(t,e,s){t("./libs/pools"),t("./libs/copyWorldPosRot"),t("./libs/ensureElement"),t("./libs/touchGestures"),t("./libs/betterRaycaster"),setTimeout((()=>{document.body.addEventListener("swipeup",(t=>{document.body.requestFullscreen()}))})),t("./components/grabbing"),t("./components/include"),t("./components/injectplayer"),t("./components/locomotion"),t("./components/onevent"),t("./components/onstate"),t("./components/physics"),t("./components/script"),t("./components/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const i=t("../package");console.log(`${i.title} Version ${i.version} by ${i.author}\n(${i.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":9,"./components/injectplayer":10,"./components/locomotion":11,"./components/onevent":15,"./components/onstate":16,"./components/physics":17,"./components/script":21,"./components/trigger":22,"./libs/betterRaycaster":23,"./libs/copyWorldPosRot":25,"./libs/ensureElement":26,"./libs/pools":27,"./libs/touchGestures":28,"./primitives/a-hand":29,"./primitives/a-main":30,"./primitives/a-player":31}],3:[function(t,e,s){AFRAME.registerComponent("grabbing",{schema:{hideOnGrab:{type:"boolean",default:!0},grabDistance:{type:"number",default:1}},init(){this._enableHands=this._enableHands.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onWheel=this._onWheel.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchTap=this._onTouchTap.bind(this),this._onTouchHold=this._onTouchHold.bind(this),this._btnPress={},this._btnFlex={},this._keysDown={},this._grabCount=0,this._hands=["head","left","right"],this._head={},this._left={},this._right={},this._head.hand=this.el.querySelector("a-camera"),this._left.hand=this.el.querySelector('a-hand[side="left"]'),this._right.hand=this.el.querySelector('a-hand[side="right"]'),this._head.glove=this._head.hand.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._left.glove=this._ensureGlove(this._left.hand),this._right.glove=this._ensureGlove(this._right.hand),this._left.glove.setAttribute("visible",!1),this._right.glove.setAttribute("visible",!1);for(let t of this._hands){this["_"+t].hand.addEventListener("buttonchanged",this._enableHands)}this._head.ray=this._head.hand.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._head.buttonRay=this._head.hand.ensure(".button.ray","a-entity",{class:"button ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [button]",far:1,autoRefresh:!1}}),this._head.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,position:"0 0 -1"},''),this._head.buttonReticle=this._head.buttonRay.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,color:"black",position:"0 0 -1"},''),this._head.anchor=this._head.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:!1,body:"type:kinematic;autoShape:false;"})},update(t){for(let t of this._hands){let e="_"+t;this[e].ray&&this[e].ray.setAttribute("raycaster","far",this.data.grabDistance+("head"===t?1:.1875))}},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.addEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.addEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.addEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.addEventListener("hold",this._onTouchHold)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.removeEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.removeEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.removeEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.removeEventListener("hold",this._onTouchHold)},remove(){for(let t of this._hands){let e="_"+t;this.drop(t),this[e].glove.copyWorldPosRot(this[e].hand);let s=.25;for(let i=0;i<5;i++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:i,flex:s})}},tick(t,e){for(i=0,len=navigator.getGamepads().length;i{this.sticky=!1,this._flexFinger(t,5,.5)}),256)}},drop(t="head"){let e="_"+t;this.sticky||(this[e].anchor.removeAttribute("animation__rot"),this[e].anchor.removeAttribute("animation__pos"),this[e].glove.setAttribute("visible",!0),setTimeout((()=>{this[e].anchor.removeAttribute("joint__grab"),this[e].anchor.setAttribute("position","0 0 0"),this[e].anchor.setAttribute("rotation","0 0 0")}),32),setTimeout((()=>{this[e].glove.setAttribute("body","collidesWith",1)}),1024),this[e].grabbed&&(this.emit("drop",this[e].glove,this[e].grabbed),this._grabCount=Math.max(0,this._grabCount-1),this._grabCount||this.el.removeState("grabbing"),this._flexFinger(t,5,0),this[e].grabbed.removeState("grabbed"),this[e].grabbed=null))},dropObject(t){for(let e of this._hands){this["_"+e].grabbed===t&&this.drop(e)}},use(t="head",e=0){this.useDown(t,e),setTimeout((()=>{this.useUp(t,e)}),32)},useDown(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("usedown",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastButton&&(this[s]._lastClick=this[s]._lastButton,this.emit("press",this[s].glove,this[s]._lastClick,{button:e}),this[s]._lastClick.addState("pressed"))},useUp(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("useup",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastClick&&(this.emit("unpress",this[s].glove,this[s]._lastClick),this[s]._lastClick.removeState("pressed"),this[s]._lastClick=null)},moveHeadHand(t=0,e=0,s=0,i=0){this._head.anchor.object3D.position.z=Math.min(Math.max(-1.5,this._head.anchor.object3D.position.z+t),-.125);let o=THREE.Quaternion.temp().set(e,s,i,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,s,i={}){i.grabbing=this.el,i.grabbedElement=s,i.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(i.hand=t);e.emit(t,i),s&&s.emit(t,i)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let s=.0625;if(this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:s/2,height:s,depth:2*s}),this[e].glove.setAttribute("body","type:kinematic;"),"head"===t)continue;this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}});let i=this[e].glove.querySelector(".palm")||this[e].glove;this[e].ray=i.ensure(".grabbing.ray","a-entity",{class:"grabbing ray",position:"left"===t?"-0.0625 0 0.0625":"0.0625 0 0.0625",rotation:"left"===t?"0 -45 0":"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this[e].buttonRay=i.ensure(".button.ray","a-entity",{class:"button ray",position:"0 0.03125 0",rotation:"left"===t?"0 -8 0":"0 8 0",raycaster:{objects:"[wall], [button]",far:.5,autoRefresh:!1}}),this[e].anchor=this[e].ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this[e].glove.setAttribute("visible",!0)}this._head.ray=null,this._head.buttonRay=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),s=t.getAttribute("color")||"lightblue";return t.ensure(".glove","a-entity",{class:"glove",fingerflex:{min:"left"===e?-10:10,max:"left"===e?-90:90}},`\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n `)},_flexFinger(t,e,s){let i="_"+t;if(e<5)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s});else for(e-=5;e<5;e++)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s})},_onKeyDown(t){this._keysDown[t.code]=!0,"e"===t.key&&this.toggleGrab()},_onKeyUp(t){this._keysDown[t.code]=!1},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_onWheel(t){let e=0,s=0,i=0;return this._keysDown.Digit3&&t.deltaY>0&&(i+=-.125),this._keysDown.Digit3&&t.deltaY<0&&(i+=.125),this._keysDown.Digit2&&t.deltaY>0&&(s+=-.125),this._keysDown.Digit2&&t.deltaY<0&&(s+=.125),this._keysDown.Digit1&&t.deltaY>0&&(e+=.125),this._keysDown.Digit1&&t.deltaY<0&&(e+=-.125),e||s||i?this.moveHeadHand(0,e,s,i):t.deltaY>0?this.moveHeadHand(.125):t.deltaY<0?this.moveHeadHand(-.125):void 0},_onMouseUp(t){let e=t.button;this.useUp("head",e?e%2?e+1:e-1:e)},_onTouchTap(t){this.use()},_onTouchHold(t){this.toggleGrab()},_onButtonChanged(t){let e=t.srcElement.getAttribute("tracked-controls").hand,s="_"+e,i=-1,o=0;switch(t.detail.state.touched&&(o=.5),t.detail.state.pressed&&(o=1),t.detail.state.value&&(o=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=o,t.detail.id){case 0:i=1,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e);break;case 1:i=7,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.grab(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.drop(e);break;case 3:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,1),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,1);break;case 5:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,2),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,2)}this._btnPress[e+t.detail.id]=t.detail.state.pressed,(this.sticky||this[s]._lastButton)&&0!==i||this._flexFinger(e,i,o)}}),t("./grabbing/button"),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/button":4,"./grabbing/climbable":5,"./grabbing/fingerflex":6,"./grabbing/grabbable":7,"./grabbing/receptacle":8}],4:[function(t,e,s){AFRAME.registerComponent("button",{schema:{}})},{}],5:[function(t,e,s){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion]"),this._onBump=this._onBump.bind(this),this._onBumpThis=this._onBumpThis.bind(this),this._autoGrab=!0,setTimeout((()=>{this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._quat.copy(this.el.object3D.quaternion),this._lpos.copy(this.el.object3D.position),this.el.object3D.getWorldPosition(this._wpos),this._top=parseFloat(this.el.getAttribute("height")||1)/2+2}),256)},play(){this._player.addEventListener("bump",this._onBump),this.el.addEventListener("bump",this._onBumpThis)},pause(){this._player.removeEventListener("bump",this._onBump),this.el.removeEventListener("bump",this._onBumpThis),this._climbing=!1},tick(){if(!this._lpos)return;if(this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos),!this._climbing)return;let t=THREE.Vector3.temp();this._hand.object3D.getWorldPosition(t),t.sub(this._handpos).multiplyScalar(-1),"head"===this._handName&&(t.y=0,t.y=t.length(),this._handpos.y+=t.y),this._player.components.locomotion.stopFall(),this._player.components.locomotion.move(t),this._handpos.y-this._wpos.y>this._top&&this._player.components.grabbing.dropObject(this.el)},events:{grab(t){this._climbing=!0,this._handName=t.detail.hand,this._hand=t.detail.gloveElement.parentNode,this._hand.object3D.getWorldPosition(this._handpos),t.detail.intersection.distance>("head"===this._handName?.5:.25)?setTimeout(this._onBump,260):this._player.components.locomotion.jump(),clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.copy(this._player.components.locomotion.headPos)}),1024)},drop(t){this._climbing=!1,clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this._player.components.locomotion.toggleCrouch(!0),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.add(this._player.components.locomotion.centerPos).sub(this._player.components.locomotion.feetPos)}),512)}),256)}},_onBump(t){this._autoGrab||(this._player.components.grabbing.dropObject(this.el),clearTimeout(this._autoGrabTO),this._autoGrabTO=setTimeout((()=>{this._autoGrab=!0}),4096))},_onBumpThis(t){this._autoGrab&&(this._player.components.grabbing.grab(),this._autoGrab=!1)}})},{}],6:[function(t,e,s){AFRAME.registerComponent("fingerflex",{schema:{min:{type:"number",default:10},max:{type:"number",default:90}},init(){this._fingers=["thumb","index","middle","ring","little"],this._currentFlex=[0,0,0,0,0],this._targetFlex=[0,0,0,0,0]},tick(t,e){for(let t=0;t<5;t++){let e=this._fingers[t],s=this._currentFlex[t],i=this._targetFlex[t];s+=Math.random()*Math.random()*(i-s);let o=this.data.min+s*(this.data.max-this.data.min),n=this.el.querySelector(".bend."+e);for(;n;){let t=n.getAttribute("rotation");t.y=o,n.setAttribute("rotation",t),n=n.querySelector(".bend")}this._currentFlex[t]=s}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],7:[function(t,e,s){AFRAME.registerComponent("grabbable",{schema:{physics:{type:"boolean",default:!0},kinematicGrab:{type:"boolean",default:!0},fixed:{type:"boolean",default:!1},fixedPosition:{type:"vec3",default:{x:0,y:0,z:0}}},init(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:dynamic;")},events:{grab(){this.data.kinematicGrab&&this.el.setAttribute("body","type","kinematic")},drop(){this.data.physics&&this.el.setAttribute("body","type","dynamic")}}})},{}],8:[function(t,e,s){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125},onlyGrabbed:{type:"boolean",default:!1}},init(){this._anchor=this.el.ensure(".receptacle.anchor","a-entity",{class:"receptacle anchor",body:"type:kinematic;autoShape:false;"}),this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.nearest)return this.refreshObjects();let t=THREE.Vector3.temp(),e=THREE.Vector3.temp();this.el.object3D.localToWorld(t.set(0,0,0)),this.nearest.object3D.localToWorld(e.set(0,0,0)),e.sub(t),this._lastNearest&&this._lastNearest!==this.nearest?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this._lastNearest.removeState("put"),this.el.emit("take",{grabbable:this._lastNearest}),this._lastNearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this._lastNearest}),this._lastNearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):e.length()>this.data.radius?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this.nearest.removeState("put"),this.el.emit("take",{grabbable:this.nearest}),this.nearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this.nearest}),this.nearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):this.nearest.is("grabbed")||!this._hover?(this._hover||(this.el.emit("hover",{grabbable:this.nearest}),this.nearest.emit("hover",{receptacle:this.el})),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this._anchor.copyWorldPosRot(this.nearest),this._hover=!0,this.nearest.is("grabbed")&&(this._grabbed=!0)):!this._grabbed&&this.data.onlyGrabbed||(this.el.is("filled")||(this._anchor.copyWorldPosRot(this.nearest),this._anchor.components.body.commit(),this.nearest.components.body&&this._anchor.setAttribute("joint__put",{body2:this.nearest,type:"lock"}),this.el.addState("filled"),this.nearest.addState("put"),this.el.emit("put",{grabbable:this.nearest}),this.nearest.emit("put",{receptacle:this.el})),this._anchor.getAttribute("animation__pos")||(this._anchor.setAttribute("animation__pos",{property:"position",to:{x:0,y:0,z:0},dur:256}),this._anchor.setAttribute("animation__rot",{property:"rotation",to:{x:0,y:0,z:0},dur:256})),this.nearest.copyWorldPosRot(this._anchor),this._hover=!0),this._lastNearest=this.nearest},refreshObjects(){let t=1/0,e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Vector3.temp(),o=this.el.sceneEl.querySelectorAll(this.data.objects);this.nearest=null,o&&(this.el.object3D.localToWorld(e.set(0,0,0)),o.forEach((o=>{o.object3D.localToWorld(s.set(0,0,0)),i.copy(s).sub(e),t>i.length()&&(t=i.length(),this.nearest=o)})))}})},{}],9:[function(t,e,s){AFRAME.registerComponent("include",{schema:{type:"string"},async init(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),s=t.indexOf(" include="),i=t.substr(e,s-e);e=t.indexOf('"',s+10)+1,s=t.indexOf(">"),i+=t.substr(e,s-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+i+" "):this.el.removeAttribute("include"),this.el.sceneEl._including_=!1;let n=this.el.sceneEl.querySelector("[include]");n&&n.components&&n.components.include&&n.components.include.init()}}})},{}],10:[function(t,e,s){AFRAME.registerComponent("injectplayer",{init(){this.el.ensure("a-camera","a-camera",{"look-controls":{pointerLockEnabled:!0,touchEnabled:!1},"wasd-controls":{enabled:!1}}),this.el.ensure('a-hand[side="left"]',"a-hand",{side:"left"}),this.el.ensure('a-hand[side="right"]',"a-hand",{side:"right"})}})},{}],11:[function(t,e,s){AFRAME.registerComponent("locomotion",{dependencies:["position","injectplayer"],schema:{speed:{type:"number",default:4},stepLength:{type:"number",default:1},rotationSpeed:{type:"number",default:1},teleportDistance:{type:"number",default:5},jumpForce:{type:"number",default:4},gravity:{type:"number",default:10},godMode:{type:"boolean",default:!1}},init(){this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onAxisMove=this._onAxisMove.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onEnterVR=this._onEnterVR.bind(this),this._onExitVR=this._onExitVR.bind(this),this._keysDown={},this._kbStick=new THREE.Vector2,this._axes=[0,0,0,0],this._leftTouchCenter=new THREE.Vector2,this._leftTouchDir=new THREE.Vector2,this._rightTouchCenter=new THREE.Vector2,this._rightTouchDir=new THREE.Vector2,this._teleporting=!0,this._bumpOverload=0,this._vertVelocity=1,this.currentFloorPosition=new THREE.Vector3,this.centerPos=new THREE.Vector3,this.headPos=new THREE.Vector3,this.headDir=new THREE.Vector3,this.feetPos=new THREE.Vector3,this.lastStep=new THREE.Vector3,this._config={quantizeMovement:!1,quantizeRotation:!1,quantizeMovementVR:!!this.el.sceneEl.isMobile,quantizeRotationVR:!0},this.el.sceneEl.is("vr-mode")?this._onEnterVR():this._onExitVR(),this._camera=this.el.querySelector("a-camera"),this._leftHand=this.el.querySelector('a-hand[side="left"]'),this._rightHand=this.el.querySelector('a-hand[side="right"]'),this._legs=this.el.sceneEl.ensure(".legs","a-entity",{class:"legs",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[floor]",direction:"0 -1 0",far:.625}}),this._legBumper=this.el.sceneEl.ensure(".leg-bumper","a-entity",{class:"leg-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._headBumper=this.el.sceneEl.ensure(".head-bumper","a-entity",{class:"head-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportBeam=this._camera.ensure(".teleport-ray","a-entity",{class:"teleport-ray",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportCursor=this.el.ensure(".teleport-cursor","a-cylinder",{class:"teleport-cursor",radius:.5,height:.0625,material:"opacity:0.5;"}),this._teleportCursor.setAttribute("visible",!1)},update(t){this._godMode=this.data.godMode},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._leftHand.addEventListener("axismove",this._onAxisMove),this._rightHand.addEventListener("axismove",this._onAxisMove),this._leftHand.addEventListener("buttonchanged",this._onButtonChanged),this._rightHand.addEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.addEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.addEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.addEventListener("touchend",this._onTouchEnd),this.el.sceneEl.addEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.addEventListener("exit-vr",this._onExitVR)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this._leftHand.removeEventListener("axismove",this._onAxisMove),this._rightHand.removeEventListener("axismove",this._onAxisMove),this._leftHand.removeEventListener("buttonchanged",this._onButtonChanged),this._rightHand.removeEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.removeEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.removeEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.removeEventListener("touchend",this._onTouchEnd),this.el.sceneEl.removeEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.removeEventListener("exit-vr",this._onExitVR)},remove(){this.el.sceneEl.removeChild(this._legs),this.el.sceneEl.removeChild(this._legBumper),this.el.sceneEl.removeChild(this._headBumper)},tick(t,e){e/=1e3,this.el.object3D.localToWorld(this.centerPos.set(0,0,0)),this.headPos.copy(this._camera.object3D.position),this._camera.object3D.parent.localToWorld(this.headPos),this.headDir.set(0,0,-1).applyQuaternion(this._camera.object3D.quaternion).applyQuaternion(this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp())),this._legs.object3D.localToWorld(this.feetPos.set(0,0,0)),this.feetPos.y-=.5,this._applyButtons(e),this._applyMoveStick(e),this._applyAuxStick(e);let s=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(s.y=0,(s.length()>.5||!this.currentFloor)&&(this.currentFloor&&s.multiplyScalar(.1),this._legs.object3D.position.add(s),this.feetPos.add(s)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let s=t.intersections[0];if(s&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===s.el){let t=THREE.Vector3.temp();t.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition),this.move(t),this.lastStep.add(t),t.y=0,this._legs.object3D.position.add(t)}else this.currentFloor&&this.currentFloor.emit("leave"),s.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-s.distance,0)),this.currentFloor=s.el,this.currentFloorPosition.copy(this.currentFloor.object3D.position)}else this.currentFloor&&this.currentFloor.emit("leave"),this._vertVelocity-=this.data.gravity*e,this.move(THREE.Vector3.temp().set(0,Math.max(-.5,this._vertVelocity*e),0)),this.currentFloor=null}if(this._godMode)this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position);else if(this._bumpOverload>4||Math.abs(this.headPos.y-this.feetPos.y)>3)this.feetPos.y=this.centerPos.y,this._legs.object3D.position.y=this.feetPos.y+.5,this.teleport(this._legBumper.object3D.position,!0),this._bumpOverload&&this._bumpOverload--;else{let t=THREE.Vector3.temp();t.copy(this.feetPos).y+=.5,this._bump(t,this._legBumper),t.copy(this.headPos),this._bump(t,this._headBumper)}let i=THREE.Vector3.temp();if(i.copy(this.feetPos).sub(this.lastStep),i.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));i.length()>this.data.stepLength;)i.multiplyScalar(this.data.stepLength/i.length()),this.lastStep.add(i),i.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let s=THREE.Vector3.temp();s.copy(t).sub(this.feetPos),this.move(s),this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._caution=8,e&&(this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position))},jump(){this.currentFloor&&(this._vertVelocity=this.data.jumpForce)},stopFall(){this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._vertVelocity=Math.max(this._vertVelocity,0)},toggleCrouch(t){let e,s=this.headPos.y-this.feetPos.y;clearTimeout(this._crouchResetTO),this._crouchResetTO=null,Math.abs(this.centerPos.y-this.feetPos.y)>.03125?e=this.feetPos.y-this.centerPos.y:t||(e=s>1?-1:1),this.el.removeAttribute("animation"),e&&this.el.setAttribute("animation",{property:"object3D.position.y",to:this.el.object3D.position.y+e,dur:256})},move(t){this.el.object3D.position.add(t),this.centerPos.add(t),this.headPos.add(t),this._legs.object3D.position.y+=t.y,this.feetPos.y+=t.y},_bump(t,e){let s=THREE.Matrix3.temp(),i=THREE.Vector3.temp();i.copy(t),i.sub(e.object3D.position);let o=i.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${i.x} ${i.y} ${i.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),s.getNormalMatrix(a.el.object3D.matrixWorld),i.copy(a.face.normal).applyMatrix3(s).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(i),e.object3D.position.add(i),this._legs.object3D.position.y!==t&&(e===this._headBumper&&this._headBumper.object3D.position.copy(this._legBumper.object3D.position),clearTimeout(this._crouchResetTO),this._crouchResetTO=setTimeout((()=>{this.toggleCrouch(!0)}),4096)),this._legs.object3D.position.add(i),this._legs.object3D.position.y=Math.max(t,this.headPos.y-1.5),this._caution=4,this._bumpOverload++,this._vertVelocity=Math.min(0,this._vertVelocity);let n={player:this.el,object:a.el};this.el.emit("bump",n),a.el.emit("bump",n)}else this._caution?this._caution--:(this._bumpOverload&&this._bumpOverload--,e.object3D.position.lerp(t,.25))}},_callMoveStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.KeyA&&e.x--,this._keysDown.KeyD&&e.x++,(this._keysDown.KeyW||this._keysDown.ArrowUp)&&e.y--,(this._keysDown.KeyS||this._keysDown.ArrowDown)&&e.y++,this._kbStick.length()>.1?this._kbStick.multiplyScalar((this._kbStick.length()-.1)/this._kbStick.length()):this._kbStick.set(0,0),this._kbStick.add(e.multiplyScalar(.2)),this._kbStick.length()>1&&this._kbStick.normalize(),this._kbStick.length()>t.length()&&t.copy(this._kbStick),this._deadZone(e.set(this._axes[0],this._axes[1])),e.length()>t.length()&&t.copy(e),e.copy(this._leftTouchDir),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyMoveStick(t){let e=this._callMoveStick();e.multiplyScalar(this.data.speed),e.multiplyScalar(t);let s=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,i=Math.cos(s)*e.x-Math.sin(s)*e.y,o=Math.sin(s)*e.x+Math.cos(s)*e.y,n=THREE.Vector3.temp().set(i,0,o);this.quantizeMovement&&(this._quantTime=this._quantTime||0,this._quantDelta=this._quantDelta||new THREE.Vector3,this._quantTime+=t,this._quantDelta.add(n),this._quantTime>.25?(this._quantTime-=.25,n.copy(this._quantDelta),this._quantDelta.set(0,0,0)):n.set(0,0,0)),this.move(n)},_callAuxStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.ArrowLeft&&e.x--,this._keysDown.ArrowRight&&e.x++,this._keysDown.KeyQ&&e.y--,this._keysDown.KeyC&&e.y++,e.length()>t.length()&&t.copy(e),this._fourWay(this._deadZone(e.set(this._axes[2],this._axes[3]))),e.length()>t.length()&&t.copy(e),this._fourWay(e.copy(this._rightTouchDir)),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyAuxStick(t){let e=this._callAuxStick(),s=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,s=-Math.round(e.x)*Math.PI/4):this._rotating=!1:s=-e.x*this.data.rotationSpeed*t,s){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),i=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-s),i.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(s),this.el.object3D.position.add(i),this.centerPos.add(i)}if(this._godMode)this.el.object3D.position.y+=-e.y*this.data.speed*t,this._legs.object3D.position.y+=-e.y*this.data.speed*t;else if(Math.round(e.y)>0?this._crouching||(this._crouching=!0,this.toggleCrouch()):this._crouching=!1,Math.round(e.y)<0){!this._teleporting&&this.data.teleportDistance&&(this._teleportCursor.setAttribute("visible",!0),this._teleporting=!0);let t=THREE.Quaternion.temp();if(this._teleportCursor.object3D.getWorldQuaternion(t),this._teleportCursor.object3D.quaternion.multiply(t.conjugate().normalize()).multiply(t.copy(this.el.object3D.quaternion).multiply(this._camera.object3D.quaternion)),this._teleportCursor.object3D.quaternion.x=0,this._teleportCursor.object3D.quaternion.z=0,this._teleportCursor.object3D.quaternion.normalize(),ray=this._teleportBeam.components.raycaster,ray.refreshObjects(),hit=ray.intersections[0],hit&&null!=hit.el.getAttribute("floor")){let e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Matrix3.temp();s.copy(hit.point).sub(this.feetPos),s.y>1.5&&s.multiplyScalar(0),s.length()>this.data.teleportDistance&&s.normalize().multiplyScalar(this.data.teleportDistance),s.add(this.feetPos),this._teleportCursor.object3D.position.copy(s),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),i.getNormalMatrix(hit.el.object3D.matrixWorld),s.copy(hit.face.normal).applyMatrix3(i).normalize(),s.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,s),this._teleportCursor.object3D.quaternion.premultiply(t)}else this._teleportCursor.object3D.position.copy(this.feetPos),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position)}else if(this._teleporting){let t=THREE.Vector3.temp();this._teleportCursor.object3D.localToWorld(t.set(0,0,0)),this.teleport(t),this._teleportCursor.setAttribute("visible",!1),this._teleportCursor.setAttribute("position","0 0 0"),this._teleporting=!1}},_callButtons(){let t=0;for(this._keysDown.Space&&(t|=1),this._keysDown.KeyG&&(t|=2),this._vrRightClick&&(t|=1),this._vrLeftClick&&(t|=2),i=0,len=navigator.getGamepads().length;i(t.length()>e?t.multiplyScalar((t.length()-e)/(1-e)/t.length()):t.set(0,0),t),_fourWay(t){let e=t.length();return Math.abs(t.x)>Math.abs(t.y)?t.y=0:t.x=0,t.multiplyScalar(e/t.length()),t},_onKeyDown(t){this._keysDown[t.code]=!0},_onKeyUp(t){this._keysDown[t.code]=!1},_onAxisMove(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?(this._axes[0]=t.detail.axis[2],this._axes[1]=t.detail.axis[3]):(this._axes[2]=t.detail.axis[2],this._axes[3]=t.detail.axis[3]),this._handEnabled||(this._teleportBeam.parentElement.removeChild(this._teleportBeam),this._teleportBeam=this._rightHand.ensure(".teleportBeam","a-entity",{class:"teleportBeam",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._handEnabled=!0)},_onButtonChanged(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?3==t.detail.id&&(this._vrLeftClick=t.detail.state.pressed):3==t.detail.id&&(this._vrRightClick=t.detail.state.pressed)},_onTouchStart(t){let e=this.el.sceneEl.canvas.clientWidth;for(let s=0;se/2&&(this._rightTouchId=i.identifier,this._rightTouchCenter.set(i.clientX,i.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),i.add(o),o.multiplyScalar(32/o.length())),o.divideScalar(32))}t.preventDefault()},_onTouchEnd(t){for(let e=0;e{this.init()}),256);let e=new THREE.Vector3;setTimeout((()=>{this.el.object3D.localToWorld(e.set(0,0,0)),t.teleport(e,!0),setTimeout((()=>{t.toggleCrouch(!0)}),256)}),256)}})},{}],14:[function(t,e,s){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],15:[function(t,e,s){AFRAME.registerComponent("onevent",{multiple:!0,schema:{event:{type:"string"},entity:{type:"selector"},property:{type:"string"},value:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this.pause(),this._event=this.data.event||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._value=this.data.value||"",this.el.isPlaying&&this.play()},play(){this._event&&this.el.addEventListener(this._event,this.trigger)},pause(){this._event&&this.el.removeEventListener(this._event,this.trigger)},trigger(t){let e=this._property.split(".");e.push(this._value),this._entity.setAttribute(...e)}})},{}],16:[function(t,e,s){AFRAME.registerComponent("onstate",{multiple:!0,schema:{state:{type:"string"},entity:{type:"selector"},property:{type:"string"},on:{type:"string"},off:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this._state=this.data.state||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._on=this.data.on||"",this._off=this.data.off||""},play(){this.trigger(),this.el.addEventListener("stateadded",this.trigger),this.el.addEventListener("stateremoved",this.trigger)},pause(){this.el.removeEventListener("stateadded",this.trigger),this.el.removeEventListener("stateremoved",this.trigger)},trigger(t){if(t&&t.detail!==this._state)return;let e=this._property.split(".");e.push(this.el.is(this._state)?this._on:this._off),this._entity.setAttribute(...e)}})},{}],17:[function(t,e,s){const i=t("../libs/cmdCodec"),o=t("../../package");AFRAME.registerSystem("physics",{schema:{workerUrl:{type:"string",default:`https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v${o.version}/dist/cannonWorker.min.js`},gravity:{type:"vec3",default:{x:0,y:-10,z:0}},debug:{type:"boolean",default:!1}},update(){if(this.data.workerUrl){if(!this.worker){if(this.data.workerUrl.includes("//")){let t=`importScripts(${JSON.stringify(this.data.workerUrl)})`;this.worker=new Worker(`data:text/javascript;base64,${btoa(t)}`)}else this.worker=new Worker(this.data.workerUrl);this.worker.postMessage("log "+i.stringifyParam("Physics worker ready!")),this.worker.addEventListener("message",this.onMessage.bind(this))}this.bodies=this.bodies||[],this.movingBodies=this.movingBodies||[],this.joints=this.joints||[],this.buffers=[new Float64Array(8),new Float64Array(8)],this.worker.postMessage("world gravity = "+i.stringifyParam(this.data.gravity)),this._debug=this.data.debug}else this.remove()},remove(){this.worker&&this.worker.terminate(),this.worker=null,this.bodies=[],this.movingBodies=[]},tick(t,e){if(!this.worker)return;if(this.buffers.length<2)return;let s=this.buffers.shift();if(s.length<8*this.movingBodies.length){let t=s.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;s=new Float64Array(t),s.fill(NaN);let i=THREE.Vector3.temp(),o=THREE.Quaternion.temp();for(let t=0;t2;)this.buffers.shift()},command(t){switch("number"==typeof t[0]&&t.shift(),t.shift()){case"body":let e=t.shift(),s=this.bodies[e];s&&s.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+i.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":24,"./physics/body":18,"./physics/joint":19,"./physics/shape":20}],18:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("body",{dependencies:["position","rotation","scale"],schema:{type:{type:"string",default:"dynamic"},mass:{type:"number",default:1},friction:{type:"number",default:.3},restitution:{type:"number",default:.3},belongsTo:{type:"int",default:1},collidesWith:{type:"int",default:1},emitsWith:{type:"int",default:0},sleeping:{type:"boolean",default:!1},autoShape:{type:"boolean",default:!0}},init(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies,o=this.el.sceneEl.systems.physics.buffers[0];if(!t)return;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el,"static"!==this.data.type?(this.mid=s.indexOf(null),this.mid<0&&(this.mid=s.length),s[this.mid]=this.el):this.mid=null;let n={mid:this.mid};if(n.type=this.data.type,n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),null!==this.mid){let t=8*this.mid;o[t++]=n.position.x,o[t++]=n.position.y,o[t++]=n.position.z,o[t++]=this.data.sleeping,o[t++]=n.quaternion.x,o[t++]=n.quaternion.y,o[t++]=n.quaternion.z,o[t++]=n.quaternion.w}if(this.shapes=[],this.sleeping=!0,t.postMessage("world body "+this.id+" create "+i.stringifyParam(n)),setTimeout((()=>{n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),t.postMessage("world body "+this.id+" position = "+i.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+i.stringifyParam(n.quaternion)),this.el.components.shape&&this.el.components.shape.play();let e=this.el.querySelectorAll("[shape]");e&&e.forEach((t=>{t.components.shape&&t.components.shape.play()})),this.el.components.joint&&this.el.components.joint.play();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].play()})),this.data.autoShape&&!this.el.getAttribute("shape"))if(this.el.firstElementChild){let t=this.el.querySelectorAll("a-box, a-sphere, a-cylinder");t&&t.forEach((t=>{t.getAttribute("shape")||t.setAttribute("shape",!0)}))}else this.el.setAttribute("shape",!0);this._initiated=!0},play(){this._initiated||(this.init(),this.update({}))},update(t){let e=this.el.sceneEl.systems.physics.worker;e&&(this.data.type!==t.type&&e.postMessage("world body "+this.id+" type = "+i.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+i.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+i.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+i.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+i.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+i.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+i.stringifyParam(this.data.emitsWith)),setTimeout((()=>{e.postMessage("world body "+this.id+" sleeping = "+!!this.data.sleeping)})))},sleep(){let t=this.el.sceneEl.systems.physics.worker;t&&(t.postMessage("world body "+this.id+" sleeping = true"),this.sleeping=!0)},pause(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies;if(!t)return;this.el.components.joint&&this.el.components.joint.pause();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].pause();let i=this.el.querySelectorAll("[shape]");i&&i.forEach((t=>{t.components.shape&&t.components.shape.pause()})),this.el.components.shape&&this.el.components.shape.pause(),e[this.id]=null,null!==this.mid&&(s[this.mid]=null),t.postMessage("world body "+this.id+" remove"),this._initiated=!1},tick(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.buffers[0];if(t&&null!==this.mid){let t=8*this.mid;if(e.length<=t)return;if("kinematic"===this.data.type){let s=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,this.sleeping=!!e[t++];let i=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,e[t++]=i.w}else if(e[t+1]){let s=THREE.Quaternion.temp();this.el.object3D.position.set(e[t++],e[t++],e[t++]),this.el.object3D.parent.worldToLocal(this.el.object3D.position),this.sleeping=!!e[t++],this.el.object3D.getWorldQuaternion(s),this.el.object3D.quaternion.multiply(s.conjugate().normalize()),s.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(s.normalize())}}},command(t){switch(t.shift()){case"emits":let e=t.shift();switch(e.event){case"collision":let t=this.el.sceneEl.systems.physics.bodies;if(e.body1=t[e.body1],e.body2=t[e.body2],!e.body1||!e.body2)return;e.shape1=e.body1.components.body.shapes[e.shape1],e.shape2=e.body2.components.body.shapes[e.shape2]}this.el.emit(e.event,e)}},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.id+" eval "+i.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),s=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+i.stringifyParam(e)),this.el.object3D.getWorldQuaternion(s),t.postMessage("world body "+this.id+" quaternion "+i.stringifyParam(s))}})},{"../../libs/cmdCodec":24}],19:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("joint",{multiple:!0,schema:{type:{type:"string",default:"ball"},body1:{type:"selector"},body2:{type:"selector"},pivot1:{type:"vec3",default:{x:0,y:0,z:0}},pivot2:{type:"vec3",default:{x:0,y:0,z:0}},axis1:{type:"vec3",default:{x:0,y:1,z:0}},axis2:{type:"vec3",default:{x:0,y:1,z:0}},min:{type:"number",default:0},max:{type:"number",default:1},collision:{type:"boolean",default:!0}},play(){if(null!=this._id)return;let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;if(!t)return;if(!this.data.body1.components.body)return this._retry=setTimeout((()=>{this.play()}),256);if(!this.data.body2.components.body)return this._retry=setTimeout((()=>{this.play()}),256);this._id=e.indexOf(null),this._id<0&&(this._id=e.length),e[this._id]=this.el;let s={};s.type=this.data.type,s.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,s.body2=this.data.body2.components.body.id,s.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),s.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),s.axis1=this.data.axis1,s.axis2=this.data.axis2,s.min=this.data.min,s.max=this.data.max,s.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.pivot1.multiply(o),s.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+i.stringifyParam(s))},update(t){this.el.sceneEl.systems.physics.worker&&(this.data.body1=this.data.body1||this.el)},pause(){clearTimeout(this._retry);let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;t&&(e[this._id]=null,t.postMessage("world joint "+this._id+" remove"),this._id=null)},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world joint "+this._id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],20:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("shape",{schema:{},play(){if(null!=this.id)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;for(this.body=this.el;this.body&&!this.body.matches("[body]");)this.body=this.body.parentElement;if(!this.body)return this._retry=setTimeout((()=>{this.play()}),256);this.bodyId=this.body.components.body.id;let e=this.body.components.body.shapes;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el;let s={};s.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(s.position),s.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(s.quaternion.multiply(o.conjugate().normalize()).normalize(),s.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":s.type="sphere",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":s.type="cylinder",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":s.type="box",s.size.set(parseFloat(this.el.getAttribute("width")||1),parseFloat(this.el.getAttribute("height")||1),parseFloat(this.el.getAttribute("depth")||1))}let n=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.size.multiply(n),s.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+i.stringifyParam(s))},pause(){if(clearTimeout(this._retry),!this.body)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;let e=this.body.components.body.shapes;t.postMessage("world body "+this.bodyId+" shape "+this.id+" remove"),e[this.id]=null,this.id=null},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.bodyId+" shape "+this.id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],21:[function(require,module,exports){AFRAME.registerComponent("script",{schema:{src:{type:"string"},call:{type:"string"},args:{type:"array"}},async update(oldData){if(this.data.src!==oldData.src){this.script&&(this.el.isPlaying&&this.script.pause?.(),this.script.remove?.()),this.script=null;let response=await fetch(this.data.src);if(response.status>=200&&response.status<300){if(this.script=eval(await await response.text()),this.script.el=this.el,this.script.events)for(let t in this.script.events)this.script.events[t]=this.script.events[t].bind(this.script)}else console.error("Could not load",this.data.src);this.script.init?.(),this.el.isPlaying&&this.script.play?.()}this.script&&this.data.call?.trim()&&(this.script[this.data.call.trim()](...this.data.args),this.el.setAttribute("script","call",""))},remove(){this.script&&this.script.remove?.(...arguments)},tick(){this.script&&this.script.tick?.(...arguments)},tock(){this.script&&this.script.tock?.(...arguments)},play(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.addEventListener(t,this.script.events[t]);this.script.play?.(...arguments)}},pause(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.removeEventListener(t,this.script.events[t]);this.script.pause?.(...arguments)}}})},{}],22:[function(t,e,s){AFRAME.registerComponent("trigger",{schema:{objects:{type:"string",default:"[camera]"}},init(){this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){this.objects||this.refreshObjects();let t,e=THREE.Vector3.temp(),s=parseFloat(this.el.getAttribute("width")||1),i=parseFloat(this.el.getAttribute("height")||1),o=parseFloat(this.el.getAttribute("depth")||1),n=parseFloat(this.el.getAttribute("radius")||1);for(let a of this.objects){switch(a.object3D.localToWorld(e.set(0,0,0)),this.el.object3D.worldToLocal(e),this.el.tagName.toLowerCase()){case"a-sphere":t=e.length()=0){let t={trigger:this.el,object:a};this.el.emit("untrigger",t),a.emit("untrigger",t),this.triggered.splice(this.triggered.indexOf(a),1),this.triggered.length||this.el.removeState("triggered")}}},refreshObjects(){this.objects=this.objects||[],this.triggered=this.triggered||[],this.objects.splice(0,this.objects.length);let t=this.el.sceneEl.querySelectorAll(this.data.objects);if(t){t.forEach((t=>{this.objects.push(t)}));for(let t=0;t=0)return t;return(t+", ").replaceAll(","," *,")+t}AFRAME.components.raycaster.Component.prototype.update=function(){return this._matchSelector=this.data.objects,this.data.objects=n(this.data.objects),i.apply(this,arguments)},AFRAME.components.raycaster.Component.prototype.refreshObjects=function(){let t=o.apply(this,arguments),e=this.intersections;for(let t of e)for(t.el=t.object.el;t.el&&!t.el.matches(this._matchSelector);)t.el=t.el.parentNode;return t}},{}],24:[function(t,e,s){e.exports={parse(t){let e=t.split(" "),s=[];for(let t of e)if(t)try{s.push(JSON.parse(t))}catch(e){"="!==t&&s.push(t)}return s},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],25:[function(t,e,s){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),s=t.object3D,i=this.object3D;s&&i&&i.parent&&(s.localToWorld(i.position.set(0,0,0)),i.parent.worldToLocal(i.position),i.getWorldQuaternion(e),i.quaternion.multiply(e.conjugate().normalize()),s.getWorldQuaternion(e),i.quaternion.multiply(e.normalize()))}},{}],26:[function(t,e,s){Element.prototype.ensure=function(t,e=t,s={},i=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),s)a=s[n],o.setAttribute(n,a);o.innerHTML=i}return o}},{}],27:[function(t,e,s){function i(t){t._pool=[],t._inUse=[],t.temp=function(){let e=t._pool.pop()||new t;return t._inUse.push(e),t._gc||(t._gc=setTimeout(t._recycle)),e},t._recycle=function(){for(;t._inUse.length;)t._pool.push(t._inUse.pop());t._gc=!1}}i(THREE.Vector2),i(THREE.Vector3),i(THREE.Quaternion),i(THREE.Matrix3),i(THREE.Matrix4)},{}],28:[function(t,e,s){let i=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,s,i,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,s)=>{if(t._tgest.handlers[e])for(let i of t._tgest.handlers[e])i(s);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,s=t.changedTouches[0].screenY,o=!1,i=setTimeout((()=>{o=!0,n("hold",t)}),512)})),t.addEventListener("touchmove",(t=>{let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))>32){if(clearTimeout(i),o)return;Math.abs(e-a)>Math.abs(s-r)?n(a{clearTimeout(i);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))<32){if(o)return;n("tap",t)}})),t._tgest};Element.prototype.addEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":n(this).handlers[t].push(e);break;default:return i.call(this,t,e)}},Element.prototype.removeEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":let s=n(this),i=s.handlers[t].indexOf(e);i>=0&&s.handlers[t].splice(i,1);break;default:return o.call(this,t,e)}}},{}],29:[function(t,e,s){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],30:[function(t,e,s){AFRAME.registerPrimitive("a-main",{})},{}],31:[function(t,e,s){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 14e0021..68852e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.17.0", + "version": "0.17.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e615733..a28d58b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.17.0", + "version": "0.17.1", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -10,7 +10,7 @@ "build": "foreach -g src/*.js -x \"browserify #{path} -o dist/#{name}.js\" && npm run minify", "watch": "foreach -g src/*.js -C -x \"watchify #{path} -d -o dist/#{name}.js\"", "minify": "touch dist/foo.min.js && rm dist/*.min.js && foreach -g dist/*.js -C -x \"minify #{path} > dist/#{name}.min.js\"", - "bump": "npm version minor --no-git-tag-version", + "bump": "npm version patch --no-git-tag-version", "gitadd": "git add package*.json dist/*.js" }, "pre-commit": [ diff --git a/src/components/grabbing/fingerflex.md b/src/components/grabbing/fingerflex.md index c969ee0..6c00f86 100644 --- a/src/components/grabbing/fingerflex.md +++ b/src/components/grabbing/fingerflex.md @@ -5,14 +5,13 @@ The `fingerflex` component "bends" fingers on a glove object according to `finge E.g. if the glove recieves an event with `event.detail.finger == 1` (index finger), then the component will find the entity matching `.bend.index` selector, rotate it around the Y-axis between `min` and `max` property values according to `event.detail.flex`.. It will then do the same with any descendant `.bend` entity.. ```html - + - + - + - - + From d630a6b63f3ec7fc28f79fe0c88e2d420f4cddea Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Mon, 12 Jul 2021 15:27:47 +0200 Subject: [PATCH 2/4] I just published to npm --- .gitignore | 3 --- dist/a-game.js | 3 ++- dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 3 ++- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 661faa0..adb2c19 100644 --- a/.gitignore +++ b/.gitignore @@ -101,6 +101,3 @@ typings/ # TernJS port file .tern-port - - -_/ \ No newline at end of file diff --git a/dist/a-game.js b/dist/a-game.js index 8596656..7f860d7 100644 --- a/dist/a-game.js +++ b/dist/a-game.js @@ -2,7 +2,7 @@ module.exports={ "name": "a-game", "title": "A-Game", - "version": "0.17.1", + "version": "0.17.2", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -21,6 +21,7 @@ module.exports={ ], "keywords": [ "aframe", + "aframe-component", "webvr", "webxr", "gamedev" diff --git a/dist/a-game.min.js b/dist/a-game.min.js index bfded73..b633732 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,s,i){function o(a,r){if(!s[a]){if(!e[a]){var h="function"==typeof require&&require;if(!r&&h)return h(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=s[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,s,i)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;a dist/#{name}.min.js"',bump:"npm version patch --no-git-tag-version",gitadd:"git add package*.json dist/*.js"},"pre-commit":["bump","build","gitadd"],keywords:["aframe","webvr","webxr","gamedev"],author:"poeticAndroid",license:"MIT",devDependencies:{browserify:"^17.0.0","foreach-cli":"^1.8.1",minify:"^7.0.1","pre-commit":"^1.2.2",watchify:"^4.0.0"}}},{}],2:[function(t,e,s){t("./libs/pools"),t("./libs/copyWorldPosRot"),t("./libs/ensureElement"),t("./libs/touchGestures"),t("./libs/betterRaycaster"),setTimeout((()=>{document.body.addEventListener("swipeup",(t=>{document.body.requestFullscreen()}))})),t("./components/grabbing"),t("./components/include"),t("./components/injectplayer"),t("./components/locomotion"),t("./components/onevent"),t("./components/onstate"),t("./components/physics"),t("./components/script"),t("./components/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const i=t("../package");console.log(`${i.title} Version ${i.version} by ${i.author}\n(${i.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":9,"./components/injectplayer":10,"./components/locomotion":11,"./components/onevent":15,"./components/onstate":16,"./components/physics":17,"./components/script":21,"./components/trigger":22,"./libs/betterRaycaster":23,"./libs/copyWorldPosRot":25,"./libs/ensureElement":26,"./libs/pools":27,"./libs/touchGestures":28,"./primitives/a-hand":29,"./primitives/a-main":30,"./primitives/a-player":31}],3:[function(t,e,s){AFRAME.registerComponent("grabbing",{schema:{hideOnGrab:{type:"boolean",default:!0},grabDistance:{type:"number",default:1}},init(){this._enableHands=this._enableHands.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onWheel=this._onWheel.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchTap=this._onTouchTap.bind(this),this._onTouchHold=this._onTouchHold.bind(this),this._btnPress={},this._btnFlex={},this._keysDown={},this._grabCount=0,this._hands=["head","left","right"],this._head={},this._left={},this._right={},this._head.hand=this.el.querySelector("a-camera"),this._left.hand=this.el.querySelector('a-hand[side="left"]'),this._right.hand=this.el.querySelector('a-hand[side="right"]'),this._head.glove=this._head.hand.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._left.glove=this._ensureGlove(this._left.hand),this._right.glove=this._ensureGlove(this._right.hand),this._left.glove.setAttribute("visible",!1),this._right.glove.setAttribute("visible",!1);for(let t of this._hands){this["_"+t].hand.addEventListener("buttonchanged",this._enableHands)}this._head.ray=this._head.hand.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._head.buttonRay=this._head.hand.ensure(".button.ray","a-entity",{class:"button ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [button]",far:1,autoRefresh:!1}}),this._head.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,position:"0 0 -1"},''),this._head.buttonReticle=this._head.buttonRay.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,color:"black",position:"0 0 -1"},''),this._head.anchor=this._head.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:!1,body:"type:kinematic;autoShape:false;"})},update(t){for(let t of this._hands){let e="_"+t;this[e].ray&&this[e].ray.setAttribute("raycaster","far",this.data.grabDistance+("head"===t?1:.1875))}},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.addEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.addEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.addEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.addEventListener("hold",this._onTouchHold)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.removeEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.removeEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.removeEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.removeEventListener("hold",this._onTouchHold)},remove(){for(let t of this._hands){let e="_"+t;this.drop(t),this[e].glove.copyWorldPosRot(this[e].hand);let s=.25;for(let i=0;i<5;i++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:i,flex:s})}},tick(t,e){for(i=0,len=navigator.getGamepads().length;i{this.sticky=!1,this._flexFinger(t,5,.5)}),256)}},drop(t="head"){let e="_"+t;this.sticky||(this[e].anchor.removeAttribute("animation__rot"),this[e].anchor.removeAttribute("animation__pos"),this[e].glove.setAttribute("visible",!0),setTimeout((()=>{this[e].anchor.removeAttribute("joint__grab"),this[e].anchor.setAttribute("position","0 0 0"),this[e].anchor.setAttribute("rotation","0 0 0")}),32),setTimeout((()=>{this[e].glove.setAttribute("body","collidesWith",1)}),1024),this[e].grabbed&&(this.emit("drop",this[e].glove,this[e].grabbed),this._grabCount=Math.max(0,this._grabCount-1),this._grabCount||this.el.removeState("grabbing"),this._flexFinger(t,5,0),this[e].grabbed.removeState("grabbed"),this[e].grabbed=null))},dropObject(t){for(let e of this._hands){this["_"+e].grabbed===t&&this.drop(e)}},use(t="head",e=0){this.useDown(t,e),setTimeout((()=>{this.useUp(t,e)}),32)},useDown(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("usedown",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastButton&&(this[s]._lastClick=this[s]._lastButton,this.emit("press",this[s].glove,this[s]._lastClick,{button:e}),this[s]._lastClick.addState("pressed"))},useUp(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("useup",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastClick&&(this.emit("unpress",this[s].glove,this[s]._lastClick),this[s]._lastClick.removeState("pressed"),this[s]._lastClick=null)},moveHeadHand(t=0,e=0,s=0,i=0){this._head.anchor.object3D.position.z=Math.min(Math.max(-1.5,this._head.anchor.object3D.position.z+t),-.125);let o=THREE.Quaternion.temp().set(e,s,i,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,s,i={}){i.grabbing=this.el,i.grabbedElement=s,i.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(i.hand=t);e.emit(t,i),s&&s.emit(t,i)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let s=.0625;if(this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:s/2,height:s,depth:2*s}),this[e].glove.setAttribute("body","type:kinematic;"),"head"===t)continue;this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}});let i=this[e].glove.querySelector(".palm")||this[e].glove;this[e].ray=i.ensure(".grabbing.ray","a-entity",{class:"grabbing ray",position:"left"===t?"-0.0625 0 0.0625":"0.0625 0 0.0625",rotation:"left"===t?"0 -45 0":"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this[e].buttonRay=i.ensure(".button.ray","a-entity",{class:"button ray",position:"0 0.03125 0",rotation:"left"===t?"0 -8 0":"0 8 0",raycaster:{objects:"[wall], [button]",far:.5,autoRefresh:!1}}),this[e].anchor=this[e].ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this[e].glove.setAttribute("visible",!0)}this._head.ray=null,this._head.buttonRay=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),s=t.getAttribute("color")||"lightblue";return t.ensure(".glove","a-entity",{class:"glove",fingerflex:{min:"left"===e?-10:10,max:"left"===e?-90:90}},`\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n `)},_flexFinger(t,e,s){let i="_"+t;if(e<5)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s});else for(e-=5;e<5;e++)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s})},_onKeyDown(t){this._keysDown[t.code]=!0,"e"===t.key&&this.toggleGrab()},_onKeyUp(t){this._keysDown[t.code]=!1},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_onWheel(t){let e=0,s=0,i=0;return this._keysDown.Digit3&&t.deltaY>0&&(i+=-.125),this._keysDown.Digit3&&t.deltaY<0&&(i+=.125),this._keysDown.Digit2&&t.deltaY>0&&(s+=-.125),this._keysDown.Digit2&&t.deltaY<0&&(s+=.125),this._keysDown.Digit1&&t.deltaY>0&&(e+=.125),this._keysDown.Digit1&&t.deltaY<0&&(e+=-.125),e||s||i?this.moveHeadHand(0,e,s,i):t.deltaY>0?this.moveHeadHand(.125):t.deltaY<0?this.moveHeadHand(-.125):void 0},_onMouseUp(t){let e=t.button;this.useUp("head",e?e%2?e+1:e-1:e)},_onTouchTap(t){this.use()},_onTouchHold(t){this.toggleGrab()},_onButtonChanged(t){let e=t.srcElement.getAttribute("tracked-controls").hand,s="_"+e,i=-1,o=0;switch(t.detail.state.touched&&(o=.5),t.detail.state.pressed&&(o=1),t.detail.state.value&&(o=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=o,t.detail.id){case 0:i=1,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e);break;case 1:i=7,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.grab(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.drop(e);break;case 3:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,1),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,1);break;case 5:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,2),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,2)}this._btnPress[e+t.detail.id]=t.detail.state.pressed,(this.sticky||this[s]._lastButton)&&0!==i||this._flexFinger(e,i,o)}}),t("./grabbing/button"),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/button":4,"./grabbing/climbable":5,"./grabbing/fingerflex":6,"./grabbing/grabbable":7,"./grabbing/receptacle":8}],4:[function(t,e,s){AFRAME.registerComponent("button",{schema:{}})},{}],5:[function(t,e,s){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion]"),this._onBump=this._onBump.bind(this),this._onBumpThis=this._onBumpThis.bind(this),this._autoGrab=!0,setTimeout((()=>{this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._quat.copy(this.el.object3D.quaternion),this._lpos.copy(this.el.object3D.position),this.el.object3D.getWorldPosition(this._wpos),this._top=parseFloat(this.el.getAttribute("height")||1)/2+2}),256)},play(){this._player.addEventListener("bump",this._onBump),this.el.addEventListener("bump",this._onBumpThis)},pause(){this._player.removeEventListener("bump",this._onBump),this.el.removeEventListener("bump",this._onBumpThis),this._climbing=!1},tick(){if(!this._lpos)return;if(this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos),!this._climbing)return;let t=THREE.Vector3.temp();this._hand.object3D.getWorldPosition(t),t.sub(this._handpos).multiplyScalar(-1),"head"===this._handName&&(t.y=0,t.y=t.length(),this._handpos.y+=t.y),this._player.components.locomotion.stopFall(),this._player.components.locomotion.move(t),this._handpos.y-this._wpos.y>this._top&&this._player.components.grabbing.dropObject(this.el)},events:{grab(t){this._climbing=!0,this._handName=t.detail.hand,this._hand=t.detail.gloveElement.parentNode,this._hand.object3D.getWorldPosition(this._handpos),t.detail.intersection.distance>("head"===this._handName?.5:.25)?setTimeout(this._onBump,260):this._player.components.locomotion.jump(),clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.copy(this._player.components.locomotion.headPos)}),1024)},drop(t){this._climbing=!1,clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this._player.components.locomotion.toggleCrouch(!0),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.add(this._player.components.locomotion.centerPos).sub(this._player.components.locomotion.feetPos)}),512)}),256)}},_onBump(t){this._autoGrab||(this._player.components.grabbing.dropObject(this.el),clearTimeout(this._autoGrabTO),this._autoGrabTO=setTimeout((()=>{this._autoGrab=!0}),4096))},_onBumpThis(t){this._autoGrab&&(this._player.components.grabbing.grab(),this._autoGrab=!1)}})},{}],6:[function(t,e,s){AFRAME.registerComponent("fingerflex",{schema:{min:{type:"number",default:10},max:{type:"number",default:90}},init(){this._fingers=["thumb","index","middle","ring","little"],this._currentFlex=[0,0,0,0,0],this._targetFlex=[0,0,0,0,0]},tick(t,e){for(let t=0;t<5;t++){let e=this._fingers[t],s=this._currentFlex[t],i=this._targetFlex[t];s+=Math.random()*Math.random()*(i-s);let o=this.data.min+s*(this.data.max-this.data.min),n=this.el.querySelector(".bend."+e);for(;n;){let t=n.getAttribute("rotation");t.y=o,n.setAttribute("rotation",t),n=n.querySelector(".bend")}this._currentFlex[t]=s}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],7:[function(t,e,s){AFRAME.registerComponent("grabbable",{schema:{physics:{type:"boolean",default:!0},kinematicGrab:{type:"boolean",default:!0},fixed:{type:"boolean",default:!1},fixedPosition:{type:"vec3",default:{x:0,y:0,z:0}}},init(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:dynamic;")},events:{grab(){this.data.kinematicGrab&&this.el.setAttribute("body","type","kinematic")},drop(){this.data.physics&&this.el.setAttribute("body","type","dynamic")}}})},{}],8:[function(t,e,s){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125},onlyGrabbed:{type:"boolean",default:!1}},init(){this._anchor=this.el.ensure(".receptacle.anchor","a-entity",{class:"receptacle anchor",body:"type:kinematic;autoShape:false;"}),this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.nearest)return this.refreshObjects();let t=THREE.Vector3.temp(),e=THREE.Vector3.temp();this.el.object3D.localToWorld(t.set(0,0,0)),this.nearest.object3D.localToWorld(e.set(0,0,0)),e.sub(t),this._lastNearest&&this._lastNearest!==this.nearest?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this._lastNearest.removeState("put"),this.el.emit("take",{grabbable:this._lastNearest}),this._lastNearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this._lastNearest}),this._lastNearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):e.length()>this.data.radius?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this.nearest.removeState("put"),this.el.emit("take",{grabbable:this.nearest}),this.nearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this.nearest}),this.nearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):this.nearest.is("grabbed")||!this._hover?(this._hover||(this.el.emit("hover",{grabbable:this.nearest}),this.nearest.emit("hover",{receptacle:this.el})),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this._anchor.copyWorldPosRot(this.nearest),this._hover=!0,this.nearest.is("grabbed")&&(this._grabbed=!0)):!this._grabbed&&this.data.onlyGrabbed||(this.el.is("filled")||(this._anchor.copyWorldPosRot(this.nearest),this._anchor.components.body.commit(),this.nearest.components.body&&this._anchor.setAttribute("joint__put",{body2:this.nearest,type:"lock"}),this.el.addState("filled"),this.nearest.addState("put"),this.el.emit("put",{grabbable:this.nearest}),this.nearest.emit("put",{receptacle:this.el})),this._anchor.getAttribute("animation__pos")||(this._anchor.setAttribute("animation__pos",{property:"position",to:{x:0,y:0,z:0},dur:256}),this._anchor.setAttribute("animation__rot",{property:"rotation",to:{x:0,y:0,z:0},dur:256})),this.nearest.copyWorldPosRot(this._anchor),this._hover=!0),this._lastNearest=this.nearest},refreshObjects(){let t=1/0,e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Vector3.temp(),o=this.el.sceneEl.querySelectorAll(this.data.objects);this.nearest=null,o&&(this.el.object3D.localToWorld(e.set(0,0,0)),o.forEach((o=>{o.object3D.localToWorld(s.set(0,0,0)),i.copy(s).sub(e),t>i.length()&&(t=i.length(),this.nearest=o)})))}})},{}],9:[function(t,e,s){AFRAME.registerComponent("include",{schema:{type:"string"},async init(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),s=t.indexOf(" include="),i=t.substr(e,s-e);e=t.indexOf('"',s+10)+1,s=t.indexOf(">"),i+=t.substr(e,s-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+i+" "):this.el.removeAttribute("include"),this.el.sceneEl._including_=!1;let n=this.el.sceneEl.querySelector("[include]");n&&n.components&&n.components.include&&n.components.include.init()}}})},{}],10:[function(t,e,s){AFRAME.registerComponent("injectplayer",{init(){this.el.ensure("a-camera","a-camera",{"look-controls":{pointerLockEnabled:!0,touchEnabled:!1},"wasd-controls":{enabled:!1}}),this.el.ensure('a-hand[side="left"]',"a-hand",{side:"left"}),this.el.ensure('a-hand[side="right"]',"a-hand",{side:"right"})}})},{}],11:[function(t,e,s){AFRAME.registerComponent("locomotion",{dependencies:["position","injectplayer"],schema:{speed:{type:"number",default:4},stepLength:{type:"number",default:1},rotationSpeed:{type:"number",default:1},teleportDistance:{type:"number",default:5},jumpForce:{type:"number",default:4},gravity:{type:"number",default:10},godMode:{type:"boolean",default:!1}},init(){this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onAxisMove=this._onAxisMove.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onEnterVR=this._onEnterVR.bind(this),this._onExitVR=this._onExitVR.bind(this),this._keysDown={},this._kbStick=new THREE.Vector2,this._axes=[0,0,0,0],this._leftTouchCenter=new THREE.Vector2,this._leftTouchDir=new THREE.Vector2,this._rightTouchCenter=new THREE.Vector2,this._rightTouchDir=new THREE.Vector2,this._teleporting=!0,this._bumpOverload=0,this._vertVelocity=1,this.currentFloorPosition=new THREE.Vector3,this.centerPos=new THREE.Vector3,this.headPos=new THREE.Vector3,this.headDir=new THREE.Vector3,this.feetPos=new THREE.Vector3,this.lastStep=new THREE.Vector3,this._config={quantizeMovement:!1,quantizeRotation:!1,quantizeMovementVR:!!this.el.sceneEl.isMobile,quantizeRotationVR:!0},this.el.sceneEl.is("vr-mode")?this._onEnterVR():this._onExitVR(),this._camera=this.el.querySelector("a-camera"),this._leftHand=this.el.querySelector('a-hand[side="left"]'),this._rightHand=this.el.querySelector('a-hand[side="right"]'),this._legs=this.el.sceneEl.ensure(".legs","a-entity",{class:"legs",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[floor]",direction:"0 -1 0",far:.625}}),this._legBumper=this.el.sceneEl.ensure(".leg-bumper","a-entity",{class:"leg-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._headBumper=this.el.sceneEl.ensure(".head-bumper","a-entity",{class:"head-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportBeam=this._camera.ensure(".teleport-ray","a-entity",{class:"teleport-ray",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportCursor=this.el.ensure(".teleport-cursor","a-cylinder",{class:"teleport-cursor",radius:.5,height:.0625,material:"opacity:0.5;"}),this._teleportCursor.setAttribute("visible",!1)},update(t){this._godMode=this.data.godMode},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._leftHand.addEventListener("axismove",this._onAxisMove),this._rightHand.addEventListener("axismove",this._onAxisMove),this._leftHand.addEventListener("buttonchanged",this._onButtonChanged),this._rightHand.addEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.addEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.addEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.addEventListener("touchend",this._onTouchEnd),this.el.sceneEl.addEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.addEventListener("exit-vr",this._onExitVR)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this._leftHand.removeEventListener("axismove",this._onAxisMove),this._rightHand.removeEventListener("axismove",this._onAxisMove),this._leftHand.removeEventListener("buttonchanged",this._onButtonChanged),this._rightHand.removeEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.removeEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.removeEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.removeEventListener("touchend",this._onTouchEnd),this.el.sceneEl.removeEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.removeEventListener("exit-vr",this._onExitVR)},remove(){this.el.sceneEl.removeChild(this._legs),this.el.sceneEl.removeChild(this._legBumper),this.el.sceneEl.removeChild(this._headBumper)},tick(t,e){e/=1e3,this.el.object3D.localToWorld(this.centerPos.set(0,0,0)),this.headPos.copy(this._camera.object3D.position),this._camera.object3D.parent.localToWorld(this.headPos),this.headDir.set(0,0,-1).applyQuaternion(this._camera.object3D.quaternion).applyQuaternion(this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp())),this._legs.object3D.localToWorld(this.feetPos.set(0,0,0)),this.feetPos.y-=.5,this._applyButtons(e),this._applyMoveStick(e),this._applyAuxStick(e);let s=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(s.y=0,(s.length()>.5||!this.currentFloor)&&(this.currentFloor&&s.multiplyScalar(.1),this._legs.object3D.position.add(s),this.feetPos.add(s)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let s=t.intersections[0];if(s&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===s.el){let t=THREE.Vector3.temp();t.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition),this.move(t),this.lastStep.add(t),t.y=0,this._legs.object3D.position.add(t)}else this.currentFloor&&this.currentFloor.emit("leave"),s.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-s.distance,0)),this.currentFloor=s.el,this.currentFloorPosition.copy(this.currentFloor.object3D.position)}else this.currentFloor&&this.currentFloor.emit("leave"),this._vertVelocity-=this.data.gravity*e,this.move(THREE.Vector3.temp().set(0,Math.max(-.5,this._vertVelocity*e),0)),this.currentFloor=null}if(this._godMode)this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position);else if(this._bumpOverload>4||Math.abs(this.headPos.y-this.feetPos.y)>3)this.feetPos.y=this.centerPos.y,this._legs.object3D.position.y=this.feetPos.y+.5,this.teleport(this._legBumper.object3D.position,!0),this._bumpOverload&&this._bumpOverload--;else{let t=THREE.Vector3.temp();t.copy(this.feetPos).y+=.5,this._bump(t,this._legBumper),t.copy(this.headPos),this._bump(t,this._headBumper)}let i=THREE.Vector3.temp();if(i.copy(this.feetPos).sub(this.lastStep),i.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));i.length()>this.data.stepLength;)i.multiplyScalar(this.data.stepLength/i.length()),this.lastStep.add(i),i.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let s=THREE.Vector3.temp();s.copy(t).sub(this.feetPos),this.move(s),this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._caution=8,e&&(this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position))},jump(){this.currentFloor&&(this._vertVelocity=this.data.jumpForce)},stopFall(){this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._vertVelocity=Math.max(this._vertVelocity,0)},toggleCrouch(t){let e,s=this.headPos.y-this.feetPos.y;clearTimeout(this._crouchResetTO),this._crouchResetTO=null,Math.abs(this.centerPos.y-this.feetPos.y)>.03125?e=this.feetPos.y-this.centerPos.y:t||(e=s>1?-1:1),this.el.removeAttribute("animation"),e&&this.el.setAttribute("animation",{property:"object3D.position.y",to:this.el.object3D.position.y+e,dur:256})},move(t){this.el.object3D.position.add(t),this.centerPos.add(t),this.headPos.add(t),this._legs.object3D.position.y+=t.y,this.feetPos.y+=t.y},_bump(t,e){let s=THREE.Matrix3.temp(),i=THREE.Vector3.temp();i.copy(t),i.sub(e.object3D.position);let o=i.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${i.x} ${i.y} ${i.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),s.getNormalMatrix(a.el.object3D.matrixWorld),i.copy(a.face.normal).applyMatrix3(s).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(i),e.object3D.position.add(i),this._legs.object3D.position.y!==t&&(e===this._headBumper&&this._headBumper.object3D.position.copy(this._legBumper.object3D.position),clearTimeout(this._crouchResetTO),this._crouchResetTO=setTimeout((()=>{this.toggleCrouch(!0)}),4096)),this._legs.object3D.position.add(i),this._legs.object3D.position.y=Math.max(t,this.headPos.y-1.5),this._caution=4,this._bumpOverload++,this._vertVelocity=Math.min(0,this._vertVelocity);let n={player:this.el,object:a.el};this.el.emit("bump",n),a.el.emit("bump",n)}else this._caution?this._caution--:(this._bumpOverload&&this._bumpOverload--,e.object3D.position.lerp(t,.25))}},_callMoveStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.KeyA&&e.x--,this._keysDown.KeyD&&e.x++,(this._keysDown.KeyW||this._keysDown.ArrowUp)&&e.y--,(this._keysDown.KeyS||this._keysDown.ArrowDown)&&e.y++,this._kbStick.length()>.1?this._kbStick.multiplyScalar((this._kbStick.length()-.1)/this._kbStick.length()):this._kbStick.set(0,0),this._kbStick.add(e.multiplyScalar(.2)),this._kbStick.length()>1&&this._kbStick.normalize(),this._kbStick.length()>t.length()&&t.copy(this._kbStick),this._deadZone(e.set(this._axes[0],this._axes[1])),e.length()>t.length()&&t.copy(e),e.copy(this._leftTouchDir),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyMoveStick(t){let e=this._callMoveStick();e.multiplyScalar(this.data.speed),e.multiplyScalar(t);let s=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,i=Math.cos(s)*e.x-Math.sin(s)*e.y,o=Math.sin(s)*e.x+Math.cos(s)*e.y,n=THREE.Vector3.temp().set(i,0,o);this.quantizeMovement&&(this._quantTime=this._quantTime||0,this._quantDelta=this._quantDelta||new THREE.Vector3,this._quantTime+=t,this._quantDelta.add(n),this._quantTime>.25?(this._quantTime-=.25,n.copy(this._quantDelta),this._quantDelta.set(0,0,0)):n.set(0,0,0)),this.move(n)},_callAuxStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.ArrowLeft&&e.x--,this._keysDown.ArrowRight&&e.x++,this._keysDown.KeyQ&&e.y--,this._keysDown.KeyC&&e.y++,e.length()>t.length()&&t.copy(e),this._fourWay(this._deadZone(e.set(this._axes[2],this._axes[3]))),e.length()>t.length()&&t.copy(e),this._fourWay(e.copy(this._rightTouchDir)),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyAuxStick(t){let e=this._callAuxStick(),s=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,s=-Math.round(e.x)*Math.PI/4):this._rotating=!1:s=-e.x*this.data.rotationSpeed*t,s){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),i=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-s),i.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(s),this.el.object3D.position.add(i),this.centerPos.add(i)}if(this._godMode)this.el.object3D.position.y+=-e.y*this.data.speed*t,this._legs.object3D.position.y+=-e.y*this.data.speed*t;else if(Math.round(e.y)>0?this._crouching||(this._crouching=!0,this.toggleCrouch()):this._crouching=!1,Math.round(e.y)<0){!this._teleporting&&this.data.teleportDistance&&(this._teleportCursor.setAttribute("visible",!0),this._teleporting=!0);let t=THREE.Quaternion.temp();if(this._teleportCursor.object3D.getWorldQuaternion(t),this._teleportCursor.object3D.quaternion.multiply(t.conjugate().normalize()).multiply(t.copy(this.el.object3D.quaternion).multiply(this._camera.object3D.quaternion)),this._teleportCursor.object3D.quaternion.x=0,this._teleportCursor.object3D.quaternion.z=0,this._teleportCursor.object3D.quaternion.normalize(),ray=this._teleportBeam.components.raycaster,ray.refreshObjects(),hit=ray.intersections[0],hit&&null!=hit.el.getAttribute("floor")){let e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Matrix3.temp();s.copy(hit.point).sub(this.feetPos),s.y>1.5&&s.multiplyScalar(0),s.length()>this.data.teleportDistance&&s.normalize().multiplyScalar(this.data.teleportDistance),s.add(this.feetPos),this._teleportCursor.object3D.position.copy(s),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),i.getNormalMatrix(hit.el.object3D.matrixWorld),s.copy(hit.face.normal).applyMatrix3(i).normalize(),s.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,s),this._teleportCursor.object3D.quaternion.premultiply(t)}else this._teleportCursor.object3D.position.copy(this.feetPos),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position)}else if(this._teleporting){let t=THREE.Vector3.temp();this._teleportCursor.object3D.localToWorld(t.set(0,0,0)),this.teleport(t),this._teleportCursor.setAttribute("visible",!1),this._teleportCursor.setAttribute("position","0 0 0"),this._teleporting=!1}},_callButtons(){let t=0;for(this._keysDown.Space&&(t|=1),this._keysDown.KeyG&&(t|=2),this._vrRightClick&&(t|=1),this._vrLeftClick&&(t|=2),i=0,len=navigator.getGamepads().length;i(t.length()>e?t.multiplyScalar((t.length()-e)/(1-e)/t.length()):t.set(0,0),t),_fourWay(t){let e=t.length();return Math.abs(t.x)>Math.abs(t.y)?t.y=0:t.x=0,t.multiplyScalar(e/t.length()),t},_onKeyDown(t){this._keysDown[t.code]=!0},_onKeyUp(t){this._keysDown[t.code]=!1},_onAxisMove(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?(this._axes[0]=t.detail.axis[2],this._axes[1]=t.detail.axis[3]):(this._axes[2]=t.detail.axis[2],this._axes[3]=t.detail.axis[3]),this._handEnabled||(this._teleportBeam.parentElement.removeChild(this._teleportBeam),this._teleportBeam=this._rightHand.ensure(".teleportBeam","a-entity",{class:"teleportBeam",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._handEnabled=!0)},_onButtonChanged(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?3==t.detail.id&&(this._vrLeftClick=t.detail.state.pressed):3==t.detail.id&&(this._vrRightClick=t.detail.state.pressed)},_onTouchStart(t){let e=this.el.sceneEl.canvas.clientWidth;for(let s=0;se/2&&(this._rightTouchId=i.identifier,this._rightTouchCenter.set(i.clientX,i.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),i.add(o),o.multiplyScalar(32/o.length())),o.divideScalar(32))}t.preventDefault()},_onTouchEnd(t){for(let e=0;e{this.init()}),256);let e=new THREE.Vector3;setTimeout((()=>{this.el.object3D.localToWorld(e.set(0,0,0)),t.teleport(e,!0),setTimeout((()=>{t.toggleCrouch(!0)}),256)}),256)}})},{}],14:[function(t,e,s){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],15:[function(t,e,s){AFRAME.registerComponent("onevent",{multiple:!0,schema:{event:{type:"string"},entity:{type:"selector"},property:{type:"string"},value:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this.pause(),this._event=this.data.event||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._value=this.data.value||"",this.el.isPlaying&&this.play()},play(){this._event&&this.el.addEventListener(this._event,this.trigger)},pause(){this._event&&this.el.removeEventListener(this._event,this.trigger)},trigger(t){let e=this._property.split(".");e.push(this._value),this._entity.setAttribute(...e)}})},{}],16:[function(t,e,s){AFRAME.registerComponent("onstate",{multiple:!0,schema:{state:{type:"string"},entity:{type:"selector"},property:{type:"string"},on:{type:"string"},off:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this._state=this.data.state||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._on=this.data.on||"",this._off=this.data.off||""},play(){this.trigger(),this.el.addEventListener("stateadded",this.trigger),this.el.addEventListener("stateremoved",this.trigger)},pause(){this.el.removeEventListener("stateadded",this.trigger),this.el.removeEventListener("stateremoved",this.trigger)},trigger(t){if(t&&t.detail!==this._state)return;let e=this._property.split(".");e.push(this.el.is(this._state)?this._on:this._off),this._entity.setAttribute(...e)}})},{}],17:[function(t,e,s){const i=t("../libs/cmdCodec"),o=t("../../package");AFRAME.registerSystem("physics",{schema:{workerUrl:{type:"string",default:`https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v${o.version}/dist/cannonWorker.min.js`},gravity:{type:"vec3",default:{x:0,y:-10,z:0}},debug:{type:"boolean",default:!1}},update(){if(this.data.workerUrl){if(!this.worker){if(this.data.workerUrl.includes("//")){let t=`importScripts(${JSON.stringify(this.data.workerUrl)})`;this.worker=new Worker(`data:text/javascript;base64,${btoa(t)}`)}else this.worker=new Worker(this.data.workerUrl);this.worker.postMessage("log "+i.stringifyParam("Physics worker ready!")),this.worker.addEventListener("message",this.onMessage.bind(this))}this.bodies=this.bodies||[],this.movingBodies=this.movingBodies||[],this.joints=this.joints||[],this.buffers=[new Float64Array(8),new Float64Array(8)],this.worker.postMessage("world gravity = "+i.stringifyParam(this.data.gravity)),this._debug=this.data.debug}else this.remove()},remove(){this.worker&&this.worker.terminate(),this.worker=null,this.bodies=[],this.movingBodies=[]},tick(t,e){if(!this.worker)return;if(this.buffers.length<2)return;let s=this.buffers.shift();if(s.length<8*this.movingBodies.length){let t=s.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;s=new Float64Array(t),s.fill(NaN);let i=THREE.Vector3.temp(),o=THREE.Quaternion.temp();for(let t=0;t2;)this.buffers.shift()},command(t){switch("number"==typeof t[0]&&t.shift(),t.shift()){case"body":let e=t.shift(),s=this.bodies[e];s&&s.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+i.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":24,"./physics/body":18,"./physics/joint":19,"./physics/shape":20}],18:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("body",{dependencies:["position","rotation","scale"],schema:{type:{type:"string",default:"dynamic"},mass:{type:"number",default:1},friction:{type:"number",default:.3},restitution:{type:"number",default:.3},belongsTo:{type:"int",default:1},collidesWith:{type:"int",default:1},emitsWith:{type:"int",default:0},sleeping:{type:"boolean",default:!1},autoShape:{type:"boolean",default:!0}},init(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies,o=this.el.sceneEl.systems.physics.buffers[0];if(!t)return;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el,"static"!==this.data.type?(this.mid=s.indexOf(null),this.mid<0&&(this.mid=s.length),s[this.mid]=this.el):this.mid=null;let n={mid:this.mid};if(n.type=this.data.type,n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),null!==this.mid){let t=8*this.mid;o[t++]=n.position.x,o[t++]=n.position.y,o[t++]=n.position.z,o[t++]=this.data.sleeping,o[t++]=n.quaternion.x,o[t++]=n.quaternion.y,o[t++]=n.quaternion.z,o[t++]=n.quaternion.w}if(this.shapes=[],this.sleeping=!0,t.postMessage("world body "+this.id+" create "+i.stringifyParam(n)),setTimeout((()=>{n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),t.postMessage("world body "+this.id+" position = "+i.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+i.stringifyParam(n.quaternion)),this.el.components.shape&&this.el.components.shape.play();let e=this.el.querySelectorAll("[shape]");e&&e.forEach((t=>{t.components.shape&&t.components.shape.play()})),this.el.components.joint&&this.el.components.joint.play();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].play()})),this.data.autoShape&&!this.el.getAttribute("shape"))if(this.el.firstElementChild){let t=this.el.querySelectorAll("a-box, a-sphere, a-cylinder");t&&t.forEach((t=>{t.getAttribute("shape")||t.setAttribute("shape",!0)}))}else this.el.setAttribute("shape",!0);this._initiated=!0},play(){this._initiated||(this.init(),this.update({}))},update(t){let e=this.el.sceneEl.systems.physics.worker;e&&(this.data.type!==t.type&&e.postMessage("world body "+this.id+" type = "+i.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+i.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+i.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+i.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+i.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+i.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+i.stringifyParam(this.data.emitsWith)),setTimeout((()=>{e.postMessage("world body "+this.id+" sleeping = "+!!this.data.sleeping)})))},sleep(){let t=this.el.sceneEl.systems.physics.worker;t&&(t.postMessage("world body "+this.id+" sleeping = true"),this.sleeping=!0)},pause(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies;if(!t)return;this.el.components.joint&&this.el.components.joint.pause();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].pause();let i=this.el.querySelectorAll("[shape]");i&&i.forEach((t=>{t.components.shape&&t.components.shape.pause()})),this.el.components.shape&&this.el.components.shape.pause(),e[this.id]=null,null!==this.mid&&(s[this.mid]=null),t.postMessage("world body "+this.id+" remove"),this._initiated=!1},tick(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.buffers[0];if(t&&null!==this.mid){let t=8*this.mid;if(e.length<=t)return;if("kinematic"===this.data.type){let s=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,this.sleeping=!!e[t++];let i=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,e[t++]=i.w}else if(e[t+1]){let s=THREE.Quaternion.temp();this.el.object3D.position.set(e[t++],e[t++],e[t++]),this.el.object3D.parent.worldToLocal(this.el.object3D.position),this.sleeping=!!e[t++],this.el.object3D.getWorldQuaternion(s),this.el.object3D.quaternion.multiply(s.conjugate().normalize()),s.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(s.normalize())}}},command(t){switch(t.shift()){case"emits":let e=t.shift();switch(e.event){case"collision":let t=this.el.sceneEl.systems.physics.bodies;if(e.body1=t[e.body1],e.body2=t[e.body2],!e.body1||!e.body2)return;e.shape1=e.body1.components.body.shapes[e.shape1],e.shape2=e.body2.components.body.shapes[e.shape2]}this.el.emit(e.event,e)}},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.id+" eval "+i.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),s=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+i.stringifyParam(e)),this.el.object3D.getWorldQuaternion(s),t.postMessage("world body "+this.id+" quaternion "+i.stringifyParam(s))}})},{"../../libs/cmdCodec":24}],19:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("joint",{multiple:!0,schema:{type:{type:"string",default:"ball"},body1:{type:"selector"},body2:{type:"selector"},pivot1:{type:"vec3",default:{x:0,y:0,z:0}},pivot2:{type:"vec3",default:{x:0,y:0,z:0}},axis1:{type:"vec3",default:{x:0,y:1,z:0}},axis2:{type:"vec3",default:{x:0,y:1,z:0}},min:{type:"number",default:0},max:{type:"number",default:1},collision:{type:"boolean",default:!0}},play(){if(null!=this._id)return;let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;if(!t)return;if(!this.data.body1.components.body)return this._retry=setTimeout((()=>{this.play()}),256);if(!this.data.body2.components.body)return this._retry=setTimeout((()=>{this.play()}),256);this._id=e.indexOf(null),this._id<0&&(this._id=e.length),e[this._id]=this.el;let s={};s.type=this.data.type,s.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,s.body2=this.data.body2.components.body.id,s.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),s.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),s.axis1=this.data.axis1,s.axis2=this.data.axis2,s.min=this.data.min,s.max=this.data.max,s.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.pivot1.multiply(o),s.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+i.stringifyParam(s))},update(t){this.el.sceneEl.systems.physics.worker&&(this.data.body1=this.data.body1||this.el)},pause(){clearTimeout(this._retry);let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;t&&(e[this._id]=null,t.postMessage("world joint "+this._id+" remove"),this._id=null)},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world joint "+this._id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],20:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("shape",{schema:{},play(){if(null!=this.id)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;for(this.body=this.el;this.body&&!this.body.matches("[body]");)this.body=this.body.parentElement;if(!this.body)return this._retry=setTimeout((()=>{this.play()}),256);this.bodyId=this.body.components.body.id;let e=this.body.components.body.shapes;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el;let s={};s.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(s.position),s.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(s.quaternion.multiply(o.conjugate().normalize()).normalize(),s.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":s.type="sphere",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":s.type="cylinder",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":s.type="box",s.size.set(parseFloat(this.el.getAttribute("width")||1),parseFloat(this.el.getAttribute("height")||1),parseFloat(this.el.getAttribute("depth")||1))}let n=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.size.multiply(n),s.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+i.stringifyParam(s))},pause(){if(clearTimeout(this._retry),!this.body)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;let e=this.body.components.body.shapes;t.postMessage("world body "+this.bodyId+" shape "+this.id+" remove"),e[this.id]=null,this.id=null},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.bodyId+" shape "+this.id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],21:[function(require,module,exports){AFRAME.registerComponent("script",{schema:{src:{type:"string"},call:{type:"string"},args:{type:"array"}},async update(oldData){if(this.data.src!==oldData.src){this.script&&(this.el.isPlaying&&this.script.pause?.(),this.script.remove?.()),this.script=null;let response=await fetch(this.data.src);if(response.status>=200&&response.status<300){if(this.script=eval(await await response.text()),this.script.el=this.el,this.script.events)for(let t in this.script.events)this.script.events[t]=this.script.events[t].bind(this.script)}else console.error("Could not load",this.data.src);this.script.init?.(),this.el.isPlaying&&this.script.play?.()}this.script&&this.data.call?.trim()&&(this.script[this.data.call.trim()](...this.data.args),this.el.setAttribute("script","call",""))},remove(){this.script&&this.script.remove?.(...arguments)},tick(){this.script&&this.script.tick?.(...arguments)},tock(){this.script&&this.script.tock?.(...arguments)},play(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.addEventListener(t,this.script.events[t]);this.script.play?.(...arguments)}},pause(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.removeEventListener(t,this.script.events[t]);this.script.pause?.(...arguments)}}})},{}],22:[function(t,e,s){AFRAME.registerComponent("trigger",{schema:{objects:{type:"string",default:"[camera]"}},init(){this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){this.objects||this.refreshObjects();let t,e=THREE.Vector3.temp(),s=parseFloat(this.el.getAttribute("width")||1),i=parseFloat(this.el.getAttribute("height")||1),o=parseFloat(this.el.getAttribute("depth")||1),n=parseFloat(this.el.getAttribute("radius")||1);for(let a of this.objects){switch(a.object3D.localToWorld(e.set(0,0,0)),this.el.object3D.worldToLocal(e),this.el.tagName.toLowerCase()){case"a-sphere":t=e.length()=0){let t={trigger:this.el,object:a};this.el.emit("untrigger",t),a.emit("untrigger",t),this.triggered.splice(this.triggered.indexOf(a),1),this.triggered.length||this.el.removeState("triggered")}}},refreshObjects(){this.objects=this.objects||[],this.triggered=this.triggered||[],this.objects.splice(0,this.objects.length);let t=this.el.sceneEl.querySelectorAll(this.data.objects);if(t){t.forEach((t=>{this.objects.push(t)}));for(let t=0;t=0)return t;return(t+", ").replaceAll(","," *,")+t}AFRAME.components.raycaster.Component.prototype.update=function(){return this._matchSelector=this.data.objects,this.data.objects=n(this.data.objects),i.apply(this,arguments)},AFRAME.components.raycaster.Component.prototype.refreshObjects=function(){let t=o.apply(this,arguments),e=this.intersections;for(let t of e)for(t.el=t.object.el;t.el&&!t.el.matches(this._matchSelector);)t.el=t.el.parentNode;return t}},{}],24:[function(t,e,s){e.exports={parse(t){let e=t.split(" "),s=[];for(let t of e)if(t)try{s.push(JSON.parse(t))}catch(e){"="!==t&&s.push(t)}return s},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],25:[function(t,e,s){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),s=t.object3D,i=this.object3D;s&&i&&i.parent&&(s.localToWorld(i.position.set(0,0,0)),i.parent.worldToLocal(i.position),i.getWorldQuaternion(e),i.quaternion.multiply(e.conjugate().normalize()),s.getWorldQuaternion(e),i.quaternion.multiply(e.normalize()))}},{}],26:[function(t,e,s){Element.prototype.ensure=function(t,e=t,s={},i=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),s)a=s[n],o.setAttribute(n,a);o.innerHTML=i}return o}},{}],27:[function(t,e,s){function i(t){t._pool=[],t._inUse=[],t.temp=function(){let e=t._pool.pop()||new t;return t._inUse.push(e),t._gc||(t._gc=setTimeout(t._recycle)),e},t._recycle=function(){for(;t._inUse.length;)t._pool.push(t._inUse.pop());t._gc=!1}}i(THREE.Vector2),i(THREE.Vector3),i(THREE.Quaternion),i(THREE.Matrix3),i(THREE.Matrix4)},{}],28:[function(t,e,s){let i=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,s,i,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,s)=>{if(t._tgest.handlers[e])for(let i of t._tgest.handlers[e])i(s);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,s=t.changedTouches[0].screenY,o=!1,i=setTimeout((()=>{o=!0,n("hold",t)}),512)})),t.addEventListener("touchmove",(t=>{let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))>32){if(clearTimeout(i),o)return;Math.abs(e-a)>Math.abs(s-r)?n(a{clearTimeout(i);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))<32){if(o)return;n("tap",t)}})),t._tgest};Element.prototype.addEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":n(this).handlers[t].push(e);break;default:return i.call(this,t,e)}},Element.prototype.removeEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":let s=n(this),i=s.handlers[t].indexOf(e);i>=0&&s.handlers[t].splice(i,1);break;default:return o.call(this,t,e)}}},{}],29:[function(t,e,s){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],30:[function(t,e,s){AFRAME.registerPrimitive("a-main",{})},{}],31:[function(t,e,s){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,s,i){function o(a,r){if(!s[a]){if(!e[a]){var h="function"==typeof require&&require;if(!r&&h)return h(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=s[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,s,i)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;a dist/#{name}.min.js"',bump:"npm version patch --no-git-tag-version",gitadd:"git add package*.json dist/*.js"},"pre-commit":["bump","build","gitadd"],keywords:["aframe","aframe-component","webvr","webxr","gamedev"],author:"poeticAndroid",license:"MIT",devDependencies:{browserify:"^17.0.0","foreach-cli":"^1.8.1",minify:"^7.0.1","pre-commit":"^1.2.2",watchify:"^4.0.0"}}},{}],2:[function(t,e,s){t("./libs/pools"),t("./libs/copyWorldPosRot"),t("./libs/ensureElement"),t("./libs/touchGestures"),t("./libs/betterRaycaster"),setTimeout((()=>{document.body.addEventListener("swipeup",(t=>{document.body.requestFullscreen()}))})),t("./components/grabbing"),t("./components/include"),t("./components/injectplayer"),t("./components/locomotion"),t("./components/onevent"),t("./components/onstate"),t("./components/physics"),t("./components/script"),t("./components/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const i=t("../package");console.log(`${i.title} Version ${i.version} by ${i.author}\n(${i.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":9,"./components/injectplayer":10,"./components/locomotion":11,"./components/onevent":15,"./components/onstate":16,"./components/physics":17,"./components/script":21,"./components/trigger":22,"./libs/betterRaycaster":23,"./libs/copyWorldPosRot":25,"./libs/ensureElement":26,"./libs/pools":27,"./libs/touchGestures":28,"./primitives/a-hand":29,"./primitives/a-main":30,"./primitives/a-player":31}],3:[function(t,e,s){AFRAME.registerComponent("grabbing",{schema:{hideOnGrab:{type:"boolean",default:!0},grabDistance:{type:"number",default:1}},init(){this._enableHands=this._enableHands.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onWheel=this._onWheel.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchTap=this._onTouchTap.bind(this),this._onTouchHold=this._onTouchHold.bind(this),this._btnPress={},this._btnFlex={},this._keysDown={},this._grabCount=0,this._hands=["head","left","right"],this._head={},this._left={},this._right={},this._head.hand=this.el.querySelector("a-camera"),this._left.hand=this.el.querySelector('a-hand[side="left"]'),this._right.hand=this.el.querySelector('a-hand[side="right"]'),this._head.glove=this._head.hand.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._left.glove=this._ensureGlove(this._left.hand),this._right.glove=this._ensureGlove(this._right.hand),this._left.glove.setAttribute("visible",!1),this._right.glove.setAttribute("visible",!1);for(let t of this._hands){this["_"+t].hand.addEventListener("buttonchanged",this._enableHands)}this._head.ray=this._head.hand.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._head.buttonRay=this._head.hand.ensure(".button.ray","a-entity",{class:"button ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [button]",far:1,autoRefresh:!1}}),this._head.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,position:"0 0 -1"},''),this._head.buttonReticle=this._head.buttonRay.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,color:"black",position:"0 0 -1"},''),this._head.anchor=this._head.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:!1,body:"type:kinematic;autoShape:false;"})},update(t){for(let t of this._hands){let e="_"+t;this[e].ray&&this[e].ray.setAttribute("raycaster","far",this.data.grabDistance+("head"===t?1:.1875))}},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.addEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.addEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.addEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.addEventListener("hold",this._onTouchHold)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.removeEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.removeEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.removeEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.removeEventListener("hold",this._onTouchHold)},remove(){for(let t of this._hands){let e="_"+t;this.drop(t),this[e].glove.copyWorldPosRot(this[e].hand);let s=.25;for(let i=0;i<5;i++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:i,flex:s})}},tick(t,e){for(i=0,len=navigator.getGamepads().length;i{this.sticky=!1,this._flexFinger(t,5,.5)}),256)}},drop(t="head"){let e="_"+t;this.sticky||(this[e].anchor.removeAttribute("animation__rot"),this[e].anchor.removeAttribute("animation__pos"),this[e].glove.setAttribute("visible",!0),setTimeout((()=>{this[e].anchor.removeAttribute("joint__grab"),this[e].anchor.setAttribute("position","0 0 0"),this[e].anchor.setAttribute("rotation","0 0 0")}),32),setTimeout((()=>{this[e].glove.setAttribute("body","collidesWith",1)}),1024),this[e].grabbed&&(this.emit("drop",this[e].glove,this[e].grabbed),this._grabCount=Math.max(0,this._grabCount-1),this._grabCount||this.el.removeState("grabbing"),this._flexFinger(t,5,0),this[e].grabbed.removeState("grabbed"),this[e].grabbed=null))},dropObject(t){for(let e of this._hands){this["_"+e].grabbed===t&&this.drop(e)}},use(t="head",e=0){this.useDown(t,e),setTimeout((()=>{this.useUp(t,e)}),32)},useDown(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("usedown",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastButton&&(this[s]._lastClick=this[s]._lastButton,this.emit("press",this[s].glove,this[s]._lastClick,{button:e}),this[s]._lastClick.addState("pressed"))},useUp(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("useup",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastClick&&(this.emit("unpress",this[s].glove,this[s]._lastClick),this[s]._lastClick.removeState("pressed"),this[s]._lastClick=null)},moveHeadHand(t=0,e=0,s=0,i=0){this._head.anchor.object3D.position.z=Math.min(Math.max(-1.5,this._head.anchor.object3D.position.z+t),-.125);let o=THREE.Quaternion.temp().set(e,s,i,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,s,i={}){i.grabbing=this.el,i.grabbedElement=s,i.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(i.hand=t);e.emit(t,i),s&&s.emit(t,i)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let s=.0625;if(this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:s/2,height:s,depth:2*s}),this[e].glove.setAttribute("body","type:kinematic;"),"head"===t)continue;this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}});let i=this[e].glove.querySelector(".palm")||this[e].glove;this[e].ray=i.ensure(".grabbing.ray","a-entity",{class:"grabbing ray",position:"left"===t?"-0.0625 0 0.0625":"0.0625 0 0.0625",rotation:"left"===t?"0 -45 0":"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this[e].buttonRay=i.ensure(".button.ray","a-entity",{class:"button ray",position:"0 0.03125 0",rotation:"left"===t?"0 -8 0":"0 8 0",raycaster:{objects:"[wall], [button]",far:.5,autoRefresh:!1}}),this[e].anchor=this[e].ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this[e].glove.setAttribute("visible",!0)}this._head.ray=null,this._head.buttonRay=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),s=t.getAttribute("color")||"lightblue";return t.ensure(".glove","a-entity",{class:"glove",fingerflex:{min:"left"===e?-10:10,max:"left"===e?-90:90}},`\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n `)},_flexFinger(t,e,s){let i="_"+t;if(e<5)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s});else for(e-=5;e<5;e++)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s})},_onKeyDown(t){this._keysDown[t.code]=!0,"e"===t.key&&this.toggleGrab()},_onKeyUp(t){this._keysDown[t.code]=!1},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_onWheel(t){let e=0,s=0,i=0;return this._keysDown.Digit3&&t.deltaY>0&&(i+=-.125),this._keysDown.Digit3&&t.deltaY<0&&(i+=.125),this._keysDown.Digit2&&t.deltaY>0&&(s+=-.125),this._keysDown.Digit2&&t.deltaY<0&&(s+=.125),this._keysDown.Digit1&&t.deltaY>0&&(e+=.125),this._keysDown.Digit1&&t.deltaY<0&&(e+=-.125),e||s||i?this.moveHeadHand(0,e,s,i):t.deltaY>0?this.moveHeadHand(.125):t.deltaY<0?this.moveHeadHand(-.125):void 0},_onMouseUp(t){let e=t.button;this.useUp("head",e?e%2?e+1:e-1:e)},_onTouchTap(t){this.use()},_onTouchHold(t){this.toggleGrab()},_onButtonChanged(t){let e=t.srcElement.getAttribute("tracked-controls").hand,s="_"+e,i=-1,o=0;switch(t.detail.state.touched&&(o=.5),t.detail.state.pressed&&(o=1),t.detail.state.value&&(o=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=o,t.detail.id){case 0:i=1,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e);break;case 1:i=7,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.grab(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.drop(e);break;case 3:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,1),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,1);break;case 5:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,2),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,2)}this._btnPress[e+t.detail.id]=t.detail.state.pressed,(this.sticky||this[s]._lastButton)&&0!==i||this._flexFinger(e,i,o)}}),t("./grabbing/button"),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/button":4,"./grabbing/climbable":5,"./grabbing/fingerflex":6,"./grabbing/grabbable":7,"./grabbing/receptacle":8}],4:[function(t,e,s){AFRAME.registerComponent("button",{schema:{}})},{}],5:[function(t,e,s){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion]"),this._onBump=this._onBump.bind(this),this._onBumpThis=this._onBumpThis.bind(this),this._autoGrab=!0,setTimeout((()=>{this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._quat.copy(this.el.object3D.quaternion),this._lpos.copy(this.el.object3D.position),this.el.object3D.getWorldPosition(this._wpos),this._top=parseFloat(this.el.getAttribute("height")||1)/2+2}),256)},play(){this._player.addEventListener("bump",this._onBump),this.el.addEventListener("bump",this._onBumpThis)},pause(){this._player.removeEventListener("bump",this._onBump),this.el.removeEventListener("bump",this._onBumpThis),this._climbing=!1},tick(){if(!this._lpos)return;if(this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos),!this._climbing)return;let t=THREE.Vector3.temp();this._hand.object3D.getWorldPosition(t),t.sub(this._handpos).multiplyScalar(-1),"head"===this._handName&&(t.y=0,t.y=t.length(),this._handpos.y+=t.y),this._player.components.locomotion.stopFall(),this._player.components.locomotion.move(t),this._handpos.y-this._wpos.y>this._top&&this._player.components.grabbing.dropObject(this.el)},events:{grab(t){this._climbing=!0,this._handName=t.detail.hand,this._hand=t.detail.gloveElement.parentNode,this._hand.object3D.getWorldPosition(this._handpos),t.detail.intersection.distance>("head"===this._handName?.5:.25)?setTimeout(this._onBump,260):this._player.components.locomotion.jump(),clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.copy(this._player.components.locomotion.headPos)}),1024)},drop(t){this._climbing=!1,clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this._player.components.locomotion.toggleCrouch(!0),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.add(this._player.components.locomotion.centerPos).sub(this._player.components.locomotion.feetPos)}),512)}),256)}},_onBump(t){this._autoGrab||(this._player.components.grabbing.dropObject(this.el),clearTimeout(this._autoGrabTO),this._autoGrabTO=setTimeout((()=>{this._autoGrab=!0}),4096))},_onBumpThis(t){this._autoGrab&&(this._player.components.grabbing.grab(),this._autoGrab=!1)}})},{}],6:[function(t,e,s){AFRAME.registerComponent("fingerflex",{schema:{min:{type:"number",default:10},max:{type:"number",default:90}},init(){this._fingers=["thumb","index","middle","ring","little"],this._currentFlex=[0,0,0,0,0],this._targetFlex=[0,0,0,0,0]},tick(t,e){for(let t=0;t<5;t++){let e=this._fingers[t],s=this._currentFlex[t],i=this._targetFlex[t];s+=Math.random()*Math.random()*(i-s);let o=this.data.min+s*(this.data.max-this.data.min),n=this.el.querySelector(".bend."+e);for(;n;){let t=n.getAttribute("rotation");t.y=o,n.setAttribute("rotation",t),n=n.querySelector(".bend")}this._currentFlex[t]=s}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],7:[function(t,e,s){AFRAME.registerComponent("grabbable",{schema:{physics:{type:"boolean",default:!0},kinematicGrab:{type:"boolean",default:!0},fixed:{type:"boolean",default:!1},fixedPosition:{type:"vec3",default:{x:0,y:0,z:0}}},init(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:dynamic;")},events:{grab(){this.data.kinematicGrab&&this.el.setAttribute("body","type","kinematic")},drop(){this.data.physics&&this.el.setAttribute("body","type","dynamic")}}})},{}],8:[function(t,e,s){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125},onlyGrabbed:{type:"boolean",default:!1}},init(){this._anchor=this.el.ensure(".receptacle.anchor","a-entity",{class:"receptacle anchor",body:"type:kinematic;autoShape:false;"}),this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.nearest)return this.refreshObjects();let t=THREE.Vector3.temp(),e=THREE.Vector3.temp();this.el.object3D.localToWorld(t.set(0,0,0)),this.nearest.object3D.localToWorld(e.set(0,0,0)),e.sub(t),this._lastNearest&&this._lastNearest!==this.nearest?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this._lastNearest.removeState("put"),this.el.emit("take",{grabbable:this._lastNearest}),this._lastNearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this._lastNearest}),this._lastNearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):e.length()>this.data.radius?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this.nearest.removeState("put"),this.el.emit("take",{grabbable:this.nearest}),this.nearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this.nearest}),this.nearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):this.nearest.is("grabbed")||!this._hover?(this._hover||(this.el.emit("hover",{grabbable:this.nearest}),this.nearest.emit("hover",{receptacle:this.el})),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this._anchor.copyWorldPosRot(this.nearest),this._hover=!0,this.nearest.is("grabbed")&&(this._grabbed=!0)):!this._grabbed&&this.data.onlyGrabbed||(this.el.is("filled")||(this._anchor.copyWorldPosRot(this.nearest),this._anchor.components.body.commit(),this.nearest.components.body&&this._anchor.setAttribute("joint__put",{body2:this.nearest,type:"lock"}),this.el.addState("filled"),this.nearest.addState("put"),this.el.emit("put",{grabbable:this.nearest}),this.nearest.emit("put",{receptacle:this.el})),this._anchor.getAttribute("animation__pos")||(this._anchor.setAttribute("animation__pos",{property:"position",to:{x:0,y:0,z:0},dur:256}),this._anchor.setAttribute("animation__rot",{property:"rotation",to:{x:0,y:0,z:0},dur:256})),this.nearest.copyWorldPosRot(this._anchor),this._hover=!0),this._lastNearest=this.nearest},refreshObjects(){let t=1/0,e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Vector3.temp(),o=this.el.sceneEl.querySelectorAll(this.data.objects);this.nearest=null,o&&(this.el.object3D.localToWorld(e.set(0,0,0)),o.forEach((o=>{o.object3D.localToWorld(s.set(0,0,0)),i.copy(s).sub(e),t>i.length()&&(t=i.length(),this.nearest=o)})))}})},{}],9:[function(t,e,s){AFRAME.registerComponent("include",{schema:{type:"string"},async init(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),s=t.indexOf(" include="),i=t.substr(e,s-e);e=t.indexOf('"',s+10)+1,s=t.indexOf(">"),i+=t.substr(e,s-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+i+" "):this.el.removeAttribute("include"),this.el.sceneEl._including_=!1;let n=this.el.sceneEl.querySelector("[include]");n&&n.components&&n.components.include&&n.components.include.init()}}})},{}],10:[function(t,e,s){AFRAME.registerComponent("injectplayer",{init(){this.el.ensure("a-camera","a-camera",{"look-controls":{pointerLockEnabled:!0,touchEnabled:!1},"wasd-controls":{enabled:!1}}),this.el.ensure('a-hand[side="left"]',"a-hand",{side:"left"}),this.el.ensure('a-hand[side="right"]',"a-hand",{side:"right"})}})},{}],11:[function(t,e,s){AFRAME.registerComponent("locomotion",{dependencies:["position","injectplayer"],schema:{speed:{type:"number",default:4},stepLength:{type:"number",default:1},rotationSpeed:{type:"number",default:1},teleportDistance:{type:"number",default:5},jumpForce:{type:"number",default:4},gravity:{type:"number",default:10},godMode:{type:"boolean",default:!1}},init(){this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onAxisMove=this._onAxisMove.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onEnterVR=this._onEnterVR.bind(this),this._onExitVR=this._onExitVR.bind(this),this._keysDown={},this._kbStick=new THREE.Vector2,this._axes=[0,0,0,0],this._leftTouchCenter=new THREE.Vector2,this._leftTouchDir=new THREE.Vector2,this._rightTouchCenter=new THREE.Vector2,this._rightTouchDir=new THREE.Vector2,this._teleporting=!0,this._bumpOverload=0,this._vertVelocity=1,this.currentFloorPosition=new THREE.Vector3,this.centerPos=new THREE.Vector3,this.headPos=new THREE.Vector3,this.headDir=new THREE.Vector3,this.feetPos=new THREE.Vector3,this.lastStep=new THREE.Vector3,this._config={quantizeMovement:!1,quantizeRotation:!1,quantizeMovementVR:!!this.el.sceneEl.isMobile,quantizeRotationVR:!0},this.el.sceneEl.is("vr-mode")?this._onEnterVR():this._onExitVR(),this._camera=this.el.querySelector("a-camera"),this._leftHand=this.el.querySelector('a-hand[side="left"]'),this._rightHand=this.el.querySelector('a-hand[side="right"]'),this._legs=this.el.sceneEl.ensure(".legs","a-entity",{class:"legs",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[floor]",direction:"0 -1 0",far:.625}}),this._legBumper=this.el.sceneEl.ensure(".leg-bumper","a-entity",{class:"leg-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._headBumper=this.el.sceneEl.ensure(".head-bumper","a-entity",{class:"head-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportBeam=this._camera.ensure(".teleport-ray","a-entity",{class:"teleport-ray",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportCursor=this.el.ensure(".teleport-cursor","a-cylinder",{class:"teleport-cursor",radius:.5,height:.0625,material:"opacity:0.5;"}),this._teleportCursor.setAttribute("visible",!1)},update(t){this._godMode=this.data.godMode},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._leftHand.addEventListener("axismove",this._onAxisMove),this._rightHand.addEventListener("axismove",this._onAxisMove),this._leftHand.addEventListener("buttonchanged",this._onButtonChanged),this._rightHand.addEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.addEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.addEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.addEventListener("touchend",this._onTouchEnd),this.el.sceneEl.addEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.addEventListener("exit-vr",this._onExitVR)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this._leftHand.removeEventListener("axismove",this._onAxisMove),this._rightHand.removeEventListener("axismove",this._onAxisMove),this._leftHand.removeEventListener("buttonchanged",this._onButtonChanged),this._rightHand.removeEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.removeEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.removeEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.removeEventListener("touchend",this._onTouchEnd),this.el.sceneEl.removeEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.removeEventListener("exit-vr",this._onExitVR)},remove(){this.el.sceneEl.removeChild(this._legs),this.el.sceneEl.removeChild(this._legBumper),this.el.sceneEl.removeChild(this._headBumper)},tick(t,e){e/=1e3,this.el.object3D.localToWorld(this.centerPos.set(0,0,0)),this.headPos.copy(this._camera.object3D.position),this._camera.object3D.parent.localToWorld(this.headPos),this.headDir.set(0,0,-1).applyQuaternion(this._camera.object3D.quaternion).applyQuaternion(this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp())),this._legs.object3D.localToWorld(this.feetPos.set(0,0,0)),this.feetPos.y-=.5,this._applyButtons(e),this._applyMoveStick(e),this._applyAuxStick(e);let s=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(s.y=0,(s.length()>.5||!this.currentFloor)&&(this.currentFloor&&s.multiplyScalar(.1),this._legs.object3D.position.add(s),this.feetPos.add(s)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let s=t.intersections[0];if(s&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===s.el){let t=THREE.Vector3.temp();t.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition),this.move(t),this.lastStep.add(t),t.y=0,this._legs.object3D.position.add(t)}else this.currentFloor&&this.currentFloor.emit("leave"),s.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-s.distance,0)),this.currentFloor=s.el,this.currentFloorPosition.copy(this.currentFloor.object3D.position)}else this.currentFloor&&this.currentFloor.emit("leave"),this._vertVelocity-=this.data.gravity*e,this.move(THREE.Vector3.temp().set(0,Math.max(-.5,this._vertVelocity*e),0)),this.currentFloor=null}if(this._godMode)this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position);else if(this._bumpOverload>4||Math.abs(this.headPos.y-this.feetPos.y)>3)this.feetPos.y=this.centerPos.y,this._legs.object3D.position.y=this.feetPos.y+.5,this.teleport(this._legBumper.object3D.position,!0),this._bumpOverload&&this._bumpOverload--;else{let t=THREE.Vector3.temp();t.copy(this.feetPos).y+=.5,this._bump(t,this._legBumper),t.copy(this.headPos),this._bump(t,this._headBumper)}let i=THREE.Vector3.temp();if(i.copy(this.feetPos).sub(this.lastStep),i.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));i.length()>this.data.stepLength;)i.multiplyScalar(this.data.stepLength/i.length()),this.lastStep.add(i),i.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let s=THREE.Vector3.temp();s.copy(t).sub(this.feetPos),this.move(s),this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._caution=8,e&&(this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position))},jump(){this.currentFloor&&(this._vertVelocity=this.data.jumpForce)},stopFall(){this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._vertVelocity=Math.max(this._vertVelocity,0)},toggleCrouch(t){let e,s=this.headPos.y-this.feetPos.y;clearTimeout(this._crouchResetTO),this._crouchResetTO=null,Math.abs(this.centerPos.y-this.feetPos.y)>.03125?e=this.feetPos.y-this.centerPos.y:t||(e=s>1?-1:1),this.el.removeAttribute("animation"),e&&this.el.setAttribute("animation",{property:"object3D.position.y",to:this.el.object3D.position.y+e,dur:256})},move(t){this.el.object3D.position.add(t),this.centerPos.add(t),this.headPos.add(t),this._legs.object3D.position.y+=t.y,this.feetPos.y+=t.y},_bump(t,e){let s=THREE.Matrix3.temp(),i=THREE.Vector3.temp();i.copy(t),i.sub(e.object3D.position);let o=i.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${i.x} ${i.y} ${i.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),s.getNormalMatrix(a.el.object3D.matrixWorld),i.copy(a.face.normal).applyMatrix3(s).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(i),e.object3D.position.add(i),this._legs.object3D.position.y!==t&&(e===this._headBumper&&this._headBumper.object3D.position.copy(this._legBumper.object3D.position),clearTimeout(this._crouchResetTO),this._crouchResetTO=setTimeout((()=>{this.toggleCrouch(!0)}),4096)),this._legs.object3D.position.add(i),this._legs.object3D.position.y=Math.max(t,this.headPos.y-1.5),this._caution=4,this._bumpOverload++,this._vertVelocity=Math.min(0,this._vertVelocity);let n={player:this.el,object:a.el};this.el.emit("bump",n),a.el.emit("bump",n)}else this._caution?this._caution--:(this._bumpOverload&&this._bumpOverload--,e.object3D.position.lerp(t,.25))}},_callMoveStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.KeyA&&e.x--,this._keysDown.KeyD&&e.x++,(this._keysDown.KeyW||this._keysDown.ArrowUp)&&e.y--,(this._keysDown.KeyS||this._keysDown.ArrowDown)&&e.y++,this._kbStick.length()>.1?this._kbStick.multiplyScalar((this._kbStick.length()-.1)/this._kbStick.length()):this._kbStick.set(0,0),this._kbStick.add(e.multiplyScalar(.2)),this._kbStick.length()>1&&this._kbStick.normalize(),this._kbStick.length()>t.length()&&t.copy(this._kbStick),this._deadZone(e.set(this._axes[0],this._axes[1])),e.length()>t.length()&&t.copy(e),e.copy(this._leftTouchDir),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyMoveStick(t){let e=this._callMoveStick();e.multiplyScalar(this.data.speed),e.multiplyScalar(t);let s=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,i=Math.cos(s)*e.x-Math.sin(s)*e.y,o=Math.sin(s)*e.x+Math.cos(s)*e.y,n=THREE.Vector3.temp().set(i,0,o);this.quantizeMovement&&(this._quantTime=this._quantTime||0,this._quantDelta=this._quantDelta||new THREE.Vector3,this._quantTime+=t,this._quantDelta.add(n),this._quantTime>.25?(this._quantTime-=.25,n.copy(this._quantDelta),this._quantDelta.set(0,0,0)):n.set(0,0,0)),this.move(n)},_callAuxStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.ArrowLeft&&e.x--,this._keysDown.ArrowRight&&e.x++,this._keysDown.KeyQ&&e.y--,this._keysDown.KeyC&&e.y++,e.length()>t.length()&&t.copy(e),this._fourWay(this._deadZone(e.set(this._axes[2],this._axes[3]))),e.length()>t.length()&&t.copy(e),this._fourWay(e.copy(this._rightTouchDir)),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyAuxStick(t){let e=this._callAuxStick(),s=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,s=-Math.round(e.x)*Math.PI/4):this._rotating=!1:s=-e.x*this.data.rotationSpeed*t,s){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),i=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-s),i.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(s),this.el.object3D.position.add(i),this.centerPos.add(i)}if(this._godMode)this.el.object3D.position.y+=-e.y*this.data.speed*t,this._legs.object3D.position.y+=-e.y*this.data.speed*t;else if(Math.round(e.y)>0?this._crouching||(this._crouching=!0,this.toggleCrouch()):this._crouching=!1,Math.round(e.y)<0){!this._teleporting&&this.data.teleportDistance&&(this._teleportCursor.setAttribute("visible",!0),this._teleporting=!0);let t=THREE.Quaternion.temp();if(this._teleportCursor.object3D.getWorldQuaternion(t),this._teleportCursor.object3D.quaternion.multiply(t.conjugate().normalize()).multiply(t.copy(this.el.object3D.quaternion).multiply(this._camera.object3D.quaternion)),this._teleportCursor.object3D.quaternion.x=0,this._teleportCursor.object3D.quaternion.z=0,this._teleportCursor.object3D.quaternion.normalize(),ray=this._teleportBeam.components.raycaster,ray.refreshObjects(),hit=ray.intersections[0],hit&&null!=hit.el.getAttribute("floor")){let e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Matrix3.temp();s.copy(hit.point).sub(this.feetPos),s.y>1.5&&s.multiplyScalar(0),s.length()>this.data.teleportDistance&&s.normalize().multiplyScalar(this.data.teleportDistance),s.add(this.feetPos),this._teleportCursor.object3D.position.copy(s),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),i.getNormalMatrix(hit.el.object3D.matrixWorld),s.copy(hit.face.normal).applyMatrix3(i).normalize(),s.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,s),this._teleportCursor.object3D.quaternion.premultiply(t)}else this._teleportCursor.object3D.position.copy(this.feetPos),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position)}else if(this._teleporting){let t=THREE.Vector3.temp();this._teleportCursor.object3D.localToWorld(t.set(0,0,0)),this.teleport(t),this._teleportCursor.setAttribute("visible",!1),this._teleportCursor.setAttribute("position","0 0 0"),this._teleporting=!1}},_callButtons(){let t=0;for(this._keysDown.Space&&(t|=1),this._keysDown.KeyG&&(t|=2),this._vrRightClick&&(t|=1),this._vrLeftClick&&(t|=2),i=0,len=navigator.getGamepads().length;i(t.length()>e?t.multiplyScalar((t.length()-e)/(1-e)/t.length()):t.set(0,0),t),_fourWay(t){let e=t.length();return Math.abs(t.x)>Math.abs(t.y)?t.y=0:t.x=0,t.multiplyScalar(e/t.length()),t},_onKeyDown(t){this._keysDown[t.code]=!0},_onKeyUp(t){this._keysDown[t.code]=!1},_onAxisMove(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?(this._axes[0]=t.detail.axis[2],this._axes[1]=t.detail.axis[3]):(this._axes[2]=t.detail.axis[2],this._axes[3]=t.detail.axis[3]),this._handEnabled||(this._teleportBeam.parentElement.removeChild(this._teleportBeam),this._teleportBeam=this._rightHand.ensure(".teleportBeam","a-entity",{class:"teleportBeam",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._handEnabled=!0)},_onButtonChanged(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?3==t.detail.id&&(this._vrLeftClick=t.detail.state.pressed):3==t.detail.id&&(this._vrRightClick=t.detail.state.pressed)},_onTouchStart(t){let e=this.el.sceneEl.canvas.clientWidth;for(let s=0;se/2&&(this._rightTouchId=i.identifier,this._rightTouchCenter.set(i.clientX,i.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),i.add(o),o.multiplyScalar(32/o.length())),o.divideScalar(32))}t.preventDefault()},_onTouchEnd(t){for(let e=0;e{this.init()}),256);let e=new THREE.Vector3;setTimeout((()=>{this.el.object3D.localToWorld(e.set(0,0,0)),t.teleport(e,!0),setTimeout((()=>{t.toggleCrouch(!0)}),256)}),256)}})},{}],14:[function(t,e,s){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],15:[function(t,e,s){AFRAME.registerComponent("onevent",{multiple:!0,schema:{event:{type:"string"},entity:{type:"selector"},property:{type:"string"},value:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this.pause(),this._event=this.data.event||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._value=this.data.value||"",this.el.isPlaying&&this.play()},play(){this._event&&this.el.addEventListener(this._event,this.trigger)},pause(){this._event&&this.el.removeEventListener(this._event,this.trigger)},trigger(t){let e=this._property.split(".");e.push(this._value),this._entity.setAttribute(...e)}})},{}],16:[function(t,e,s){AFRAME.registerComponent("onstate",{multiple:!0,schema:{state:{type:"string"},entity:{type:"selector"},property:{type:"string"},on:{type:"string"},off:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this._state=this.data.state||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._on=this.data.on||"",this._off=this.data.off||""},play(){this.trigger(),this.el.addEventListener("stateadded",this.trigger),this.el.addEventListener("stateremoved",this.trigger)},pause(){this.el.removeEventListener("stateadded",this.trigger),this.el.removeEventListener("stateremoved",this.trigger)},trigger(t){if(t&&t.detail!==this._state)return;let e=this._property.split(".");e.push(this.el.is(this._state)?this._on:this._off),this._entity.setAttribute(...e)}})},{}],17:[function(t,e,s){const i=t("../libs/cmdCodec"),o=t("../../package");AFRAME.registerSystem("physics",{schema:{workerUrl:{type:"string",default:`https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v${o.version}/dist/cannonWorker.min.js`},gravity:{type:"vec3",default:{x:0,y:-10,z:0}},debug:{type:"boolean",default:!1}},update(){if(this.data.workerUrl){if(!this.worker){if(this.data.workerUrl.includes("//")){let t=`importScripts(${JSON.stringify(this.data.workerUrl)})`;this.worker=new Worker(`data:text/javascript;base64,${btoa(t)}`)}else this.worker=new Worker(this.data.workerUrl);this.worker.postMessage("log "+i.stringifyParam("Physics worker ready!")),this.worker.addEventListener("message",this.onMessage.bind(this))}this.bodies=this.bodies||[],this.movingBodies=this.movingBodies||[],this.joints=this.joints||[],this.buffers=[new Float64Array(8),new Float64Array(8)],this.worker.postMessage("world gravity = "+i.stringifyParam(this.data.gravity)),this._debug=this.data.debug}else this.remove()},remove(){this.worker&&this.worker.terminate(),this.worker=null,this.bodies=[],this.movingBodies=[]},tick(t,e){if(!this.worker)return;if(this.buffers.length<2)return;let s=this.buffers.shift();if(s.length<8*this.movingBodies.length){let t=s.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;s=new Float64Array(t),s.fill(NaN);let i=THREE.Vector3.temp(),o=THREE.Quaternion.temp();for(let t=0;t2;)this.buffers.shift()},command(t){switch("number"==typeof t[0]&&t.shift(),t.shift()){case"body":let e=t.shift(),s=this.bodies[e];s&&s.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+i.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":24,"./physics/body":18,"./physics/joint":19,"./physics/shape":20}],18:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("body",{dependencies:["position","rotation","scale"],schema:{type:{type:"string",default:"dynamic"},mass:{type:"number",default:1},friction:{type:"number",default:.3},restitution:{type:"number",default:.3},belongsTo:{type:"int",default:1},collidesWith:{type:"int",default:1},emitsWith:{type:"int",default:0},sleeping:{type:"boolean",default:!1},autoShape:{type:"boolean",default:!0}},init(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies,o=this.el.sceneEl.systems.physics.buffers[0];if(!t)return;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el,"static"!==this.data.type?(this.mid=s.indexOf(null),this.mid<0&&(this.mid=s.length),s[this.mid]=this.el):this.mid=null;let n={mid:this.mid};if(n.type=this.data.type,n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),null!==this.mid){let t=8*this.mid;o[t++]=n.position.x,o[t++]=n.position.y,o[t++]=n.position.z,o[t++]=this.data.sleeping,o[t++]=n.quaternion.x,o[t++]=n.quaternion.y,o[t++]=n.quaternion.z,o[t++]=n.quaternion.w}if(this.shapes=[],this.sleeping=!0,t.postMessage("world body "+this.id+" create "+i.stringifyParam(n)),setTimeout((()=>{n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),t.postMessage("world body "+this.id+" position = "+i.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+i.stringifyParam(n.quaternion)),this.el.components.shape&&this.el.components.shape.play();let e=this.el.querySelectorAll("[shape]");e&&e.forEach((t=>{t.components.shape&&t.components.shape.play()})),this.el.components.joint&&this.el.components.joint.play();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].play()})),this.data.autoShape&&!this.el.getAttribute("shape"))if(this.el.firstElementChild){let t=this.el.querySelectorAll("a-box, a-sphere, a-cylinder");t&&t.forEach((t=>{t.getAttribute("shape")||t.setAttribute("shape",!0)}))}else this.el.setAttribute("shape",!0);this._initiated=!0},play(){this._initiated||(this.init(),this.update({}))},update(t){let e=this.el.sceneEl.systems.physics.worker;e&&(this.data.type!==t.type&&e.postMessage("world body "+this.id+" type = "+i.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+i.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+i.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+i.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+i.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+i.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+i.stringifyParam(this.data.emitsWith)),setTimeout((()=>{e.postMessage("world body "+this.id+" sleeping = "+!!this.data.sleeping)})))},sleep(){let t=this.el.sceneEl.systems.physics.worker;t&&(t.postMessage("world body "+this.id+" sleeping = true"),this.sleeping=!0)},pause(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies;if(!t)return;this.el.components.joint&&this.el.components.joint.pause();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].pause();let i=this.el.querySelectorAll("[shape]");i&&i.forEach((t=>{t.components.shape&&t.components.shape.pause()})),this.el.components.shape&&this.el.components.shape.pause(),e[this.id]=null,null!==this.mid&&(s[this.mid]=null),t.postMessage("world body "+this.id+" remove"),this._initiated=!1},tick(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.buffers[0];if(t&&null!==this.mid){let t=8*this.mid;if(e.length<=t)return;if("kinematic"===this.data.type){let s=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,this.sleeping=!!e[t++];let i=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,e[t++]=i.w}else if(e[t+1]){let s=THREE.Quaternion.temp();this.el.object3D.position.set(e[t++],e[t++],e[t++]),this.el.object3D.parent.worldToLocal(this.el.object3D.position),this.sleeping=!!e[t++],this.el.object3D.getWorldQuaternion(s),this.el.object3D.quaternion.multiply(s.conjugate().normalize()),s.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(s.normalize())}}},command(t){switch(t.shift()){case"emits":let e=t.shift();switch(e.event){case"collision":let t=this.el.sceneEl.systems.physics.bodies;if(e.body1=t[e.body1],e.body2=t[e.body2],!e.body1||!e.body2)return;e.shape1=e.body1.components.body.shapes[e.shape1],e.shape2=e.body2.components.body.shapes[e.shape2]}this.el.emit(e.event,e)}},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.id+" eval "+i.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),s=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+i.stringifyParam(e)),this.el.object3D.getWorldQuaternion(s),t.postMessage("world body "+this.id+" quaternion "+i.stringifyParam(s))}})},{"../../libs/cmdCodec":24}],19:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("joint",{multiple:!0,schema:{type:{type:"string",default:"ball"},body1:{type:"selector"},body2:{type:"selector"},pivot1:{type:"vec3",default:{x:0,y:0,z:0}},pivot2:{type:"vec3",default:{x:0,y:0,z:0}},axis1:{type:"vec3",default:{x:0,y:1,z:0}},axis2:{type:"vec3",default:{x:0,y:1,z:0}},min:{type:"number",default:0},max:{type:"number",default:1},collision:{type:"boolean",default:!0}},play(){if(null!=this._id)return;let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;if(!t)return;if(!this.data.body1.components.body)return this._retry=setTimeout((()=>{this.play()}),256);if(!this.data.body2.components.body)return this._retry=setTimeout((()=>{this.play()}),256);this._id=e.indexOf(null),this._id<0&&(this._id=e.length),e[this._id]=this.el;let s={};s.type=this.data.type,s.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,s.body2=this.data.body2.components.body.id,s.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),s.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),s.axis1=this.data.axis1,s.axis2=this.data.axis2,s.min=this.data.min,s.max=this.data.max,s.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.pivot1.multiply(o),s.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+i.stringifyParam(s))},update(t){this.el.sceneEl.systems.physics.worker&&(this.data.body1=this.data.body1||this.el)},pause(){clearTimeout(this._retry);let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;t&&(e[this._id]=null,t.postMessage("world joint "+this._id+" remove"),this._id=null)},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world joint "+this._id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],20:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("shape",{schema:{},play(){if(null!=this.id)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;for(this.body=this.el;this.body&&!this.body.matches("[body]");)this.body=this.body.parentElement;if(!this.body)return this._retry=setTimeout((()=>{this.play()}),256);this.bodyId=this.body.components.body.id;let e=this.body.components.body.shapes;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el;let s={};s.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(s.position),s.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(s.quaternion.multiply(o.conjugate().normalize()).normalize(),s.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":s.type="sphere",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":s.type="cylinder",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":s.type="box",s.size.set(parseFloat(this.el.getAttribute("width")||1),parseFloat(this.el.getAttribute("height")||1),parseFloat(this.el.getAttribute("depth")||1))}let n=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.size.multiply(n),s.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+i.stringifyParam(s))},pause(){if(clearTimeout(this._retry),!this.body)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;let e=this.body.components.body.shapes;t.postMessage("world body "+this.bodyId+" shape "+this.id+" remove"),e[this.id]=null,this.id=null},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.bodyId+" shape "+this.id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],21:[function(require,module,exports){AFRAME.registerComponent("script",{schema:{src:{type:"string"},call:{type:"string"},args:{type:"array"}},async update(oldData){if(this.data.src!==oldData.src){this.script&&(this.el.isPlaying&&this.script.pause?.(),this.script.remove?.()),this.script=null;let response=await fetch(this.data.src);if(response.status>=200&&response.status<300){if(this.script=eval(await await response.text()),this.script.el=this.el,this.script.events)for(let t in this.script.events)this.script.events[t]=this.script.events[t].bind(this.script)}else console.error("Could not load",this.data.src);this.script.init?.(),this.el.isPlaying&&this.script.play?.()}this.script&&this.data.call?.trim()&&(this.script[this.data.call.trim()](...this.data.args),this.el.setAttribute("script","call",""))},remove(){this.script&&this.script.remove?.(...arguments)},tick(){this.script&&this.script.tick?.(...arguments)},tock(){this.script&&this.script.tock?.(...arguments)},play(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.addEventListener(t,this.script.events[t]);this.script.play?.(...arguments)}},pause(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.removeEventListener(t,this.script.events[t]);this.script.pause?.(...arguments)}}})},{}],22:[function(t,e,s){AFRAME.registerComponent("trigger",{schema:{objects:{type:"string",default:"[camera]"}},init(){this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){this.objects||this.refreshObjects();let t,e=THREE.Vector3.temp(),s=parseFloat(this.el.getAttribute("width")||1),i=parseFloat(this.el.getAttribute("height")||1),o=parseFloat(this.el.getAttribute("depth")||1),n=parseFloat(this.el.getAttribute("radius")||1);for(let a of this.objects){switch(a.object3D.localToWorld(e.set(0,0,0)),this.el.object3D.worldToLocal(e),this.el.tagName.toLowerCase()){case"a-sphere":t=e.length()=0){let t={trigger:this.el,object:a};this.el.emit("untrigger",t),a.emit("untrigger",t),this.triggered.splice(this.triggered.indexOf(a),1),this.triggered.length||this.el.removeState("triggered")}}},refreshObjects(){this.objects=this.objects||[],this.triggered=this.triggered||[],this.objects.splice(0,this.objects.length);let t=this.el.sceneEl.querySelectorAll(this.data.objects);if(t){t.forEach((t=>{this.objects.push(t)}));for(let t=0;t=0)return t;return(t+", ").replaceAll(","," *,")+t}AFRAME.components.raycaster.Component.prototype.update=function(){return this._matchSelector=this.data.objects,this.data.objects=n(this.data.objects),i.apply(this,arguments)},AFRAME.components.raycaster.Component.prototype.refreshObjects=function(){let t=o.apply(this,arguments),e=this.intersections;for(let t of e)for(t.el=t.object.el;t.el&&!t.el.matches(this._matchSelector);)t.el=t.el.parentNode;return t}},{}],24:[function(t,e,s){e.exports={parse(t){let e=t.split(" "),s=[];for(let t of e)if(t)try{s.push(JSON.parse(t))}catch(e){"="!==t&&s.push(t)}return s},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],25:[function(t,e,s){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),s=t.object3D,i=this.object3D;s&&i&&i.parent&&(s.localToWorld(i.position.set(0,0,0)),i.parent.worldToLocal(i.position),i.getWorldQuaternion(e),i.quaternion.multiply(e.conjugate().normalize()),s.getWorldQuaternion(e),i.quaternion.multiply(e.normalize()))}},{}],26:[function(t,e,s){Element.prototype.ensure=function(t,e=t,s={},i=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),s)a=s[n],o.setAttribute(n,a);o.innerHTML=i}return o}},{}],27:[function(t,e,s){function i(t){t._pool=[],t._inUse=[],t.temp=function(){let e=t._pool.pop()||new t;return t._inUse.push(e),t._gc||(t._gc=setTimeout(t._recycle)),e},t._recycle=function(){for(;t._inUse.length;)t._pool.push(t._inUse.pop());t._gc=!1}}i(THREE.Vector2),i(THREE.Vector3),i(THREE.Quaternion),i(THREE.Matrix3),i(THREE.Matrix4)},{}],28:[function(t,e,s){let i=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,s,i,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,s)=>{if(t._tgest.handlers[e])for(let i of t._tgest.handlers[e])i(s);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,s=t.changedTouches[0].screenY,o=!1,i=setTimeout((()=>{o=!0,n("hold",t)}),512)})),t.addEventListener("touchmove",(t=>{let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))>32){if(clearTimeout(i),o)return;Math.abs(e-a)>Math.abs(s-r)?n(a{clearTimeout(i);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))<32){if(o)return;n("tap",t)}})),t._tgest};Element.prototype.addEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":n(this).handlers[t].push(e);break;default:return i.call(this,t,e)}},Element.prototype.removeEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":let s=n(this),i=s.handlers[t].indexOf(e);i>=0&&s.handlers[t].splice(i,1);break;default:return o.call(this,t,e)}}},{}],29:[function(t,e,s){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],30:[function(t,e,s){AFRAME.registerPrimitive("a-main",{})},{}],31:[function(t,e,s){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 68852e9..076090a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.17.1", + "version": "0.17.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a28d58b..dad06af 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.17.1", + "version": "0.17.2", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -20,6 +20,7 @@ ], "keywords": [ "aframe", + "aframe-component", "webvr", "webxr", "gamedev" From f0e9bb1e266a82bac28022fd24cdb6336b50b36a Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Thu, 15 Jul 2021 23:23:58 +0200 Subject: [PATCH 3/4] postponing `refreshObjects` for a single frame.. --- dist/a-game.js | 6 +- dist/a-game.min.js | 2 +- dist/scenes/ballmachine.html | 2 + dist/scenes/chairs.html | 2 + dist/scenes/demo.html | 7 ++ dist/scenes/hello.html | 2 + dist/scenes/ragdoll.html | 2 + package-lock.json | 215 +++++++++++++++++------------------ package.json | 4 +- src/components/trigger.js | 2 +- 10 files changed, 125 insertions(+), 119 deletions(-) diff --git a/dist/a-game.js b/dist/a-game.js index 7f860d7..c0013b6 100644 --- a/dist/a-game.js +++ b/dist/a-game.js @@ -2,7 +2,7 @@ module.exports={ "name": "a-game", "title": "A-Game", - "version": "0.17.2", + "version": "0.17.3", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -31,7 +31,7 @@ module.exports={ "devDependencies": { "browserify": "^17.0.0", "foreach-cli": "^1.8.1", - "minify": "^7.0.1", + "minify": "^7.0.2", "pre-commit": "^1.2.2", "watchify": "^4.0.0" } @@ -2433,7 +2433,7 @@ AFRAME.registerComponent("trigger", { }, tick() { - if (!this.objects) this.refreshObjects() + if (!this.objects) return this.refreshObjects() let local = THREE.Vector3.temp() let width = parseFloat(this.el.getAttribute("width") || 1) let height = parseFloat(this.el.getAttribute("height") || 1) diff --git a/dist/a-game.min.js b/dist/a-game.min.js index b633732..1086796 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,s,i){function o(a,r){if(!s[a]){if(!e[a]){var h="function"==typeof require&&require;if(!r&&h)return h(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=s[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,s,i)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;a dist/#{name}.min.js"',bump:"npm version patch --no-git-tag-version",gitadd:"git add package*.json dist/*.js"},"pre-commit":["bump","build","gitadd"],keywords:["aframe","aframe-component","webvr","webxr","gamedev"],author:"poeticAndroid",license:"MIT",devDependencies:{browserify:"^17.0.0","foreach-cli":"^1.8.1",minify:"^7.0.1","pre-commit":"^1.2.2",watchify:"^4.0.0"}}},{}],2:[function(t,e,s){t("./libs/pools"),t("./libs/copyWorldPosRot"),t("./libs/ensureElement"),t("./libs/touchGestures"),t("./libs/betterRaycaster"),setTimeout((()=>{document.body.addEventListener("swipeup",(t=>{document.body.requestFullscreen()}))})),t("./components/grabbing"),t("./components/include"),t("./components/injectplayer"),t("./components/locomotion"),t("./components/onevent"),t("./components/onstate"),t("./components/physics"),t("./components/script"),t("./components/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const i=t("../package");console.log(`${i.title} Version ${i.version} by ${i.author}\n(${i.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":9,"./components/injectplayer":10,"./components/locomotion":11,"./components/onevent":15,"./components/onstate":16,"./components/physics":17,"./components/script":21,"./components/trigger":22,"./libs/betterRaycaster":23,"./libs/copyWorldPosRot":25,"./libs/ensureElement":26,"./libs/pools":27,"./libs/touchGestures":28,"./primitives/a-hand":29,"./primitives/a-main":30,"./primitives/a-player":31}],3:[function(t,e,s){AFRAME.registerComponent("grabbing",{schema:{hideOnGrab:{type:"boolean",default:!0},grabDistance:{type:"number",default:1}},init(){this._enableHands=this._enableHands.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onWheel=this._onWheel.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchTap=this._onTouchTap.bind(this),this._onTouchHold=this._onTouchHold.bind(this),this._btnPress={},this._btnFlex={},this._keysDown={},this._grabCount=0,this._hands=["head","left","right"],this._head={},this._left={},this._right={},this._head.hand=this.el.querySelector("a-camera"),this._left.hand=this.el.querySelector('a-hand[side="left"]'),this._right.hand=this.el.querySelector('a-hand[side="right"]'),this._head.glove=this._head.hand.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._left.glove=this._ensureGlove(this._left.hand),this._right.glove=this._ensureGlove(this._right.hand),this._left.glove.setAttribute("visible",!1),this._right.glove.setAttribute("visible",!1);for(let t of this._hands){this["_"+t].hand.addEventListener("buttonchanged",this._enableHands)}this._head.ray=this._head.hand.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._head.buttonRay=this._head.hand.ensure(".button.ray","a-entity",{class:"button ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [button]",far:1,autoRefresh:!1}}),this._head.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,position:"0 0 -1"},''),this._head.buttonReticle=this._head.buttonRay.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,color:"black",position:"0 0 -1"},''),this._head.anchor=this._head.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:!1,body:"type:kinematic;autoShape:false;"})},update(t){for(let t of this._hands){let e="_"+t;this[e].ray&&this[e].ray.setAttribute("raycaster","far",this.data.grabDistance+("head"===t?1:.1875))}},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.addEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.addEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.addEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.addEventListener("hold",this._onTouchHold)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.removeEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.removeEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.removeEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.removeEventListener("hold",this._onTouchHold)},remove(){for(let t of this._hands){let e="_"+t;this.drop(t),this[e].glove.copyWorldPosRot(this[e].hand);let s=.25;for(let i=0;i<5;i++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:i,flex:s})}},tick(t,e){for(i=0,len=navigator.getGamepads().length;i{this.sticky=!1,this._flexFinger(t,5,.5)}),256)}},drop(t="head"){let e="_"+t;this.sticky||(this[e].anchor.removeAttribute("animation__rot"),this[e].anchor.removeAttribute("animation__pos"),this[e].glove.setAttribute("visible",!0),setTimeout((()=>{this[e].anchor.removeAttribute("joint__grab"),this[e].anchor.setAttribute("position","0 0 0"),this[e].anchor.setAttribute("rotation","0 0 0")}),32),setTimeout((()=>{this[e].glove.setAttribute("body","collidesWith",1)}),1024),this[e].grabbed&&(this.emit("drop",this[e].glove,this[e].grabbed),this._grabCount=Math.max(0,this._grabCount-1),this._grabCount||this.el.removeState("grabbing"),this._flexFinger(t,5,0),this[e].grabbed.removeState("grabbed"),this[e].grabbed=null))},dropObject(t){for(let e of this._hands){this["_"+e].grabbed===t&&this.drop(e)}},use(t="head",e=0){this.useDown(t,e),setTimeout((()=>{this.useUp(t,e)}),32)},useDown(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("usedown",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastButton&&(this[s]._lastClick=this[s]._lastButton,this.emit("press",this[s].glove,this[s]._lastClick,{button:e}),this[s]._lastClick.addState("pressed"))},useUp(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("useup",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastClick&&(this.emit("unpress",this[s].glove,this[s]._lastClick),this[s]._lastClick.removeState("pressed"),this[s]._lastClick=null)},moveHeadHand(t=0,e=0,s=0,i=0){this._head.anchor.object3D.position.z=Math.min(Math.max(-1.5,this._head.anchor.object3D.position.z+t),-.125);let o=THREE.Quaternion.temp().set(e,s,i,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,s,i={}){i.grabbing=this.el,i.grabbedElement=s,i.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(i.hand=t);e.emit(t,i),s&&s.emit(t,i)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let s=.0625;if(this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:s/2,height:s,depth:2*s}),this[e].glove.setAttribute("body","type:kinematic;"),"head"===t)continue;this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}});let i=this[e].glove.querySelector(".palm")||this[e].glove;this[e].ray=i.ensure(".grabbing.ray","a-entity",{class:"grabbing ray",position:"left"===t?"-0.0625 0 0.0625":"0.0625 0 0.0625",rotation:"left"===t?"0 -45 0":"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this[e].buttonRay=i.ensure(".button.ray","a-entity",{class:"button ray",position:"0 0.03125 0",rotation:"left"===t?"0 -8 0":"0 8 0",raycaster:{objects:"[wall], [button]",far:.5,autoRefresh:!1}}),this[e].anchor=this[e].ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this[e].glove.setAttribute("visible",!0)}this._head.ray=null,this._head.buttonRay=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),s=t.getAttribute("color")||"lightblue";return t.ensure(".glove","a-entity",{class:"glove",fingerflex:{min:"left"===e?-10:10,max:"left"===e?-90:90}},`\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n `)},_flexFinger(t,e,s){let i="_"+t;if(e<5)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s});else for(e-=5;e<5;e++)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s})},_onKeyDown(t){this._keysDown[t.code]=!0,"e"===t.key&&this.toggleGrab()},_onKeyUp(t){this._keysDown[t.code]=!1},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_onWheel(t){let e=0,s=0,i=0;return this._keysDown.Digit3&&t.deltaY>0&&(i+=-.125),this._keysDown.Digit3&&t.deltaY<0&&(i+=.125),this._keysDown.Digit2&&t.deltaY>0&&(s+=-.125),this._keysDown.Digit2&&t.deltaY<0&&(s+=.125),this._keysDown.Digit1&&t.deltaY>0&&(e+=.125),this._keysDown.Digit1&&t.deltaY<0&&(e+=-.125),e||s||i?this.moveHeadHand(0,e,s,i):t.deltaY>0?this.moveHeadHand(.125):t.deltaY<0?this.moveHeadHand(-.125):void 0},_onMouseUp(t){let e=t.button;this.useUp("head",e?e%2?e+1:e-1:e)},_onTouchTap(t){this.use()},_onTouchHold(t){this.toggleGrab()},_onButtonChanged(t){let e=t.srcElement.getAttribute("tracked-controls").hand,s="_"+e,i=-1,o=0;switch(t.detail.state.touched&&(o=.5),t.detail.state.pressed&&(o=1),t.detail.state.value&&(o=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=o,t.detail.id){case 0:i=1,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e);break;case 1:i=7,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.grab(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.drop(e);break;case 3:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,1),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,1);break;case 5:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,2),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,2)}this._btnPress[e+t.detail.id]=t.detail.state.pressed,(this.sticky||this[s]._lastButton)&&0!==i||this._flexFinger(e,i,o)}}),t("./grabbing/button"),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/button":4,"./grabbing/climbable":5,"./grabbing/fingerflex":6,"./grabbing/grabbable":7,"./grabbing/receptacle":8}],4:[function(t,e,s){AFRAME.registerComponent("button",{schema:{}})},{}],5:[function(t,e,s){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion]"),this._onBump=this._onBump.bind(this),this._onBumpThis=this._onBumpThis.bind(this),this._autoGrab=!0,setTimeout((()=>{this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._quat.copy(this.el.object3D.quaternion),this._lpos.copy(this.el.object3D.position),this.el.object3D.getWorldPosition(this._wpos),this._top=parseFloat(this.el.getAttribute("height")||1)/2+2}),256)},play(){this._player.addEventListener("bump",this._onBump),this.el.addEventListener("bump",this._onBumpThis)},pause(){this._player.removeEventListener("bump",this._onBump),this.el.removeEventListener("bump",this._onBumpThis),this._climbing=!1},tick(){if(!this._lpos)return;if(this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos),!this._climbing)return;let t=THREE.Vector3.temp();this._hand.object3D.getWorldPosition(t),t.sub(this._handpos).multiplyScalar(-1),"head"===this._handName&&(t.y=0,t.y=t.length(),this._handpos.y+=t.y),this._player.components.locomotion.stopFall(),this._player.components.locomotion.move(t),this._handpos.y-this._wpos.y>this._top&&this._player.components.grabbing.dropObject(this.el)},events:{grab(t){this._climbing=!0,this._handName=t.detail.hand,this._hand=t.detail.gloveElement.parentNode,this._hand.object3D.getWorldPosition(this._handpos),t.detail.intersection.distance>("head"===this._handName?.5:.25)?setTimeout(this._onBump,260):this._player.components.locomotion.jump(),clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.copy(this._player.components.locomotion.headPos)}),1024)},drop(t){this._climbing=!1,clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this._player.components.locomotion.toggleCrouch(!0),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.add(this._player.components.locomotion.centerPos).sub(this._player.components.locomotion.feetPos)}),512)}),256)}},_onBump(t){this._autoGrab||(this._player.components.grabbing.dropObject(this.el),clearTimeout(this._autoGrabTO),this._autoGrabTO=setTimeout((()=>{this._autoGrab=!0}),4096))},_onBumpThis(t){this._autoGrab&&(this._player.components.grabbing.grab(),this._autoGrab=!1)}})},{}],6:[function(t,e,s){AFRAME.registerComponent("fingerflex",{schema:{min:{type:"number",default:10},max:{type:"number",default:90}},init(){this._fingers=["thumb","index","middle","ring","little"],this._currentFlex=[0,0,0,0,0],this._targetFlex=[0,0,0,0,0]},tick(t,e){for(let t=0;t<5;t++){let e=this._fingers[t],s=this._currentFlex[t],i=this._targetFlex[t];s+=Math.random()*Math.random()*(i-s);let o=this.data.min+s*(this.data.max-this.data.min),n=this.el.querySelector(".bend."+e);for(;n;){let t=n.getAttribute("rotation");t.y=o,n.setAttribute("rotation",t),n=n.querySelector(".bend")}this._currentFlex[t]=s}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],7:[function(t,e,s){AFRAME.registerComponent("grabbable",{schema:{physics:{type:"boolean",default:!0},kinematicGrab:{type:"boolean",default:!0},fixed:{type:"boolean",default:!1},fixedPosition:{type:"vec3",default:{x:0,y:0,z:0}}},init(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:dynamic;")},events:{grab(){this.data.kinematicGrab&&this.el.setAttribute("body","type","kinematic")},drop(){this.data.physics&&this.el.setAttribute("body","type","dynamic")}}})},{}],8:[function(t,e,s){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125},onlyGrabbed:{type:"boolean",default:!1}},init(){this._anchor=this.el.ensure(".receptacle.anchor","a-entity",{class:"receptacle anchor",body:"type:kinematic;autoShape:false;"}),this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.nearest)return this.refreshObjects();let t=THREE.Vector3.temp(),e=THREE.Vector3.temp();this.el.object3D.localToWorld(t.set(0,0,0)),this.nearest.object3D.localToWorld(e.set(0,0,0)),e.sub(t),this._lastNearest&&this._lastNearest!==this.nearest?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this._lastNearest.removeState("put"),this.el.emit("take",{grabbable:this._lastNearest}),this._lastNearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this._lastNearest}),this._lastNearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):e.length()>this.data.radius?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this.nearest.removeState("put"),this.el.emit("take",{grabbable:this.nearest}),this.nearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this.nearest}),this.nearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):this.nearest.is("grabbed")||!this._hover?(this._hover||(this.el.emit("hover",{grabbable:this.nearest}),this.nearest.emit("hover",{receptacle:this.el})),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this._anchor.copyWorldPosRot(this.nearest),this._hover=!0,this.nearest.is("grabbed")&&(this._grabbed=!0)):!this._grabbed&&this.data.onlyGrabbed||(this.el.is("filled")||(this._anchor.copyWorldPosRot(this.nearest),this._anchor.components.body.commit(),this.nearest.components.body&&this._anchor.setAttribute("joint__put",{body2:this.nearest,type:"lock"}),this.el.addState("filled"),this.nearest.addState("put"),this.el.emit("put",{grabbable:this.nearest}),this.nearest.emit("put",{receptacle:this.el})),this._anchor.getAttribute("animation__pos")||(this._anchor.setAttribute("animation__pos",{property:"position",to:{x:0,y:0,z:0},dur:256}),this._anchor.setAttribute("animation__rot",{property:"rotation",to:{x:0,y:0,z:0},dur:256})),this.nearest.copyWorldPosRot(this._anchor),this._hover=!0),this._lastNearest=this.nearest},refreshObjects(){let t=1/0,e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Vector3.temp(),o=this.el.sceneEl.querySelectorAll(this.data.objects);this.nearest=null,o&&(this.el.object3D.localToWorld(e.set(0,0,0)),o.forEach((o=>{o.object3D.localToWorld(s.set(0,0,0)),i.copy(s).sub(e),t>i.length()&&(t=i.length(),this.nearest=o)})))}})},{}],9:[function(t,e,s){AFRAME.registerComponent("include",{schema:{type:"string"},async init(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),s=t.indexOf(" include="),i=t.substr(e,s-e);e=t.indexOf('"',s+10)+1,s=t.indexOf(">"),i+=t.substr(e,s-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+i+" "):this.el.removeAttribute("include"),this.el.sceneEl._including_=!1;let n=this.el.sceneEl.querySelector("[include]");n&&n.components&&n.components.include&&n.components.include.init()}}})},{}],10:[function(t,e,s){AFRAME.registerComponent("injectplayer",{init(){this.el.ensure("a-camera","a-camera",{"look-controls":{pointerLockEnabled:!0,touchEnabled:!1},"wasd-controls":{enabled:!1}}),this.el.ensure('a-hand[side="left"]',"a-hand",{side:"left"}),this.el.ensure('a-hand[side="right"]',"a-hand",{side:"right"})}})},{}],11:[function(t,e,s){AFRAME.registerComponent("locomotion",{dependencies:["position","injectplayer"],schema:{speed:{type:"number",default:4},stepLength:{type:"number",default:1},rotationSpeed:{type:"number",default:1},teleportDistance:{type:"number",default:5},jumpForce:{type:"number",default:4},gravity:{type:"number",default:10},godMode:{type:"boolean",default:!1}},init(){this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onAxisMove=this._onAxisMove.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onEnterVR=this._onEnterVR.bind(this),this._onExitVR=this._onExitVR.bind(this),this._keysDown={},this._kbStick=new THREE.Vector2,this._axes=[0,0,0,0],this._leftTouchCenter=new THREE.Vector2,this._leftTouchDir=new THREE.Vector2,this._rightTouchCenter=new THREE.Vector2,this._rightTouchDir=new THREE.Vector2,this._teleporting=!0,this._bumpOverload=0,this._vertVelocity=1,this.currentFloorPosition=new THREE.Vector3,this.centerPos=new THREE.Vector3,this.headPos=new THREE.Vector3,this.headDir=new THREE.Vector3,this.feetPos=new THREE.Vector3,this.lastStep=new THREE.Vector3,this._config={quantizeMovement:!1,quantizeRotation:!1,quantizeMovementVR:!!this.el.sceneEl.isMobile,quantizeRotationVR:!0},this.el.sceneEl.is("vr-mode")?this._onEnterVR():this._onExitVR(),this._camera=this.el.querySelector("a-camera"),this._leftHand=this.el.querySelector('a-hand[side="left"]'),this._rightHand=this.el.querySelector('a-hand[side="right"]'),this._legs=this.el.sceneEl.ensure(".legs","a-entity",{class:"legs",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[floor]",direction:"0 -1 0",far:.625}}),this._legBumper=this.el.sceneEl.ensure(".leg-bumper","a-entity",{class:"leg-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._headBumper=this.el.sceneEl.ensure(".head-bumper","a-entity",{class:"head-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportBeam=this._camera.ensure(".teleport-ray","a-entity",{class:"teleport-ray",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportCursor=this.el.ensure(".teleport-cursor","a-cylinder",{class:"teleport-cursor",radius:.5,height:.0625,material:"opacity:0.5;"}),this._teleportCursor.setAttribute("visible",!1)},update(t){this._godMode=this.data.godMode},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._leftHand.addEventListener("axismove",this._onAxisMove),this._rightHand.addEventListener("axismove",this._onAxisMove),this._leftHand.addEventListener("buttonchanged",this._onButtonChanged),this._rightHand.addEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.addEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.addEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.addEventListener("touchend",this._onTouchEnd),this.el.sceneEl.addEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.addEventListener("exit-vr",this._onExitVR)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this._leftHand.removeEventListener("axismove",this._onAxisMove),this._rightHand.removeEventListener("axismove",this._onAxisMove),this._leftHand.removeEventListener("buttonchanged",this._onButtonChanged),this._rightHand.removeEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.removeEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.removeEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.removeEventListener("touchend",this._onTouchEnd),this.el.sceneEl.removeEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.removeEventListener("exit-vr",this._onExitVR)},remove(){this.el.sceneEl.removeChild(this._legs),this.el.sceneEl.removeChild(this._legBumper),this.el.sceneEl.removeChild(this._headBumper)},tick(t,e){e/=1e3,this.el.object3D.localToWorld(this.centerPos.set(0,0,0)),this.headPos.copy(this._camera.object3D.position),this._camera.object3D.parent.localToWorld(this.headPos),this.headDir.set(0,0,-1).applyQuaternion(this._camera.object3D.quaternion).applyQuaternion(this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp())),this._legs.object3D.localToWorld(this.feetPos.set(0,0,0)),this.feetPos.y-=.5,this._applyButtons(e),this._applyMoveStick(e),this._applyAuxStick(e);let s=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(s.y=0,(s.length()>.5||!this.currentFloor)&&(this.currentFloor&&s.multiplyScalar(.1),this._legs.object3D.position.add(s),this.feetPos.add(s)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let s=t.intersections[0];if(s&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===s.el){let t=THREE.Vector3.temp();t.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition),this.move(t),this.lastStep.add(t),t.y=0,this._legs.object3D.position.add(t)}else this.currentFloor&&this.currentFloor.emit("leave"),s.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-s.distance,0)),this.currentFloor=s.el,this.currentFloorPosition.copy(this.currentFloor.object3D.position)}else this.currentFloor&&this.currentFloor.emit("leave"),this._vertVelocity-=this.data.gravity*e,this.move(THREE.Vector3.temp().set(0,Math.max(-.5,this._vertVelocity*e),0)),this.currentFloor=null}if(this._godMode)this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position);else if(this._bumpOverload>4||Math.abs(this.headPos.y-this.feetPos.y)>3)this.feetPos.y=this.centerPos.y,this._legs.object3D.position.y=this.feetPos.y+.5,this.teleport(this._legBumper.object3D.position,!0),this._bumpOverload&&this._bumpOverload--;else{let t=THREE.Vector3.temp();t.copy(this.feetPos).y+=.5,this._bump(t,this._legBumper),t.copy(this.headPos),this._bump(t,this._headBumper)}let i=THREE.Vector3.temp();if(i.copy(this.feetPos).sub(this.lastStep),i.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));i.length()>this.data.stepLength;)i.multiplyScalar(this.data.stepLength/i.length()),this.lastStep.add(i),i.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let s=THREE.Vector3.temp();s.copy(t).sub(this.feetPos),this.move(s),this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._caution=8,e&&(this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position))},jump(){this.currentFloor&&(this._vertVelocity=this.data.jumpForce)},stopFall(){this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._vertVelocity=Math.max(this._vertVelocity,0)},toggleCrouch(t){let e,s=this.headPos.y-this.feetPos.y;clearTimeout(this._crouchResetTO),this._crouchResetTO=null,Math.abs(this.centerPos.y-this.feetPos.y)>.03125?e=this.feetPos.y-this.centerPos.y:t||(e=s>1?-1:1),this.el.removeAttribute("animation"),e&&this.el.setAttribute("animation",{property:"object3D.position.y",to:this.el.object3D.position.y+e,dur:256})},move(t){this.el.object3D.position.add(t),this.centerPos.add(t),this.headPos.add(t),this._legs.object3D.position.y+=t.y,this.feetPos.y+=t.y},_bump(t,e){let s=THREE.Matrix3.temp(),i=THREE.Vector3.temp();i.copy(t),i.sub(e.object3D.position);let o=i.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${i.x} ${i.y} ${i.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),s.getNormalMatrix(a.el.object3D.matrixWorld),i.copy(a.face.normal).applyMatrix3(s).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(i),e.object3D.position.add(i),this._legs.object3D.position.y!==t&&(e===this._headBumper&&this._headBumper.object3D.position.copy(this._legBumper.object3D.position),clearTimeout(this._crouchResetTO),this._crouchResetTO=setTimeout((()=>{this.toggleCrouch(!0)}),4096)),this._legs.object3D.position.add(i),this._legs.object3D.position.y=Math.max(t,this.headPos.y-1.5),this._caution=4,this._bumpOverload++,this._vertVelocity=Math.min(0,this._vertVelocity);let n={player:this.el,object:a.el};this.el.emit("bump",n),a.el.emit("bump",n)}else this._caution?this._caution--:(this._bumpOverload&&this._bumpOverload--,e.object3D.position.lerp(t,.25))}},_callMoveStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.KeyA&&e.x--,this._keysDown.KeyD&&e.x++,(this._keysDown.KeyW||this._keysDown.ArrowUp)&&e.y--,(this._keysDown.KeyS||this._keysDown.ArrowDown)&&e.y++,this._kbStick.length()>.1?this._kbStick.multiplyScalar((this._kbStick.length()-.1)/this._kbStick.length()):this._kbStick.set(0,0),this._kbStick.add(e.multiplyScalar(.2)),this._kbStick.length()>1&&this._kbStick.normalize(),this._kbStick.length()>t.length()&&t.copy(this._kbStick),this._deadZone(e.set(this._axes[0],this._axes[1])),e.length()>t.length()&&t.copy(e),e.copy(this._leftTouchDir),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyMoveStick(t){let e=this._callMoveStick();e.multiplyScalar(this.data.speed),e.multiplyScalar(t);let s=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,i=Math.cos(s)*e.x-Math.sin(s)*e.y,o=Math.sin(s)*e.x+Math.cos(s)*e.y,n=THREE.Vector3.temp().set(i,0,o);this.quantizeMovement&&(this._quantTime=this._quantTime||0,this._quantDelta=this._quantDelta||new THREE.Vector3,this._quantTime+=t,this._quantDelta.add(n),this._quantTime>.25?(this._quantTime-=.25,n.copy(this._quantDelta),this._quantDelta.set(0,0,0)):n.set(0,0,0)),this.move(n)},_callAuxStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.ArrowLeft&&e.x--,this._keysDown.ArrowRight&&e.x++,this._keysDown.KeyQ&&e.y--,this._keysDown.KeyC&&e.y++,e.length()>t.length()&&t.copy(e),this._fourWay(this._deadZone(e.set(this._axes[2],this._axes[3]))),e.length()>t.length()&&t.copy(e),this._fourWay(e.copy(this._rightTouchDir)),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyAuxStick(t){let e=this._callAuxStick(),s=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,s=-Math.round(e.x)*Math.PI/4):this._rotating=!1:s=-e.x*this.data.rotationSpeed*t,s){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),i=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-s),i.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(s),this.el.object3D.position.add(i),this.centerPos.add(i)}if(this._godMode)this.el.object3D.position.y+=-e.y*this.data.speed*t,this._legs.object3D.position.y+=-e.y*this.data.speed*t;else if(Math.round(e.y)>0?this._crouching||(this._crouching=!0,this.toggleCrouch()):this._crouching=!1,Math.round(e.y)<0){!this._teleporting&&this.data.teleportDistance&&(this._teleportCursor.setAttribute("visible",!0),this._teleporting=!0);let t=THREE.Quaternion.temp();if(this._teleportCursor.object3D.getWorldQuaternion(t),this._teleportCursor.object3D.quaternion.multiply(t.conjugate().normalize()).multiply(t.copy(this.el.object3D.quaternion).multiply(this._camera.object3D.quaternion)),this._teleportCursor.object3D.quaternion.x=0,this._teleportCursor.object3D.quaternion.z=0,this._teleportCursor.object3D.quaternion.normalize(),ray=this._teleportBeam.components.raycaster,ray.refreshObjects(),hit=ray.intersections[0],hit&&null!=hit.el.getAttribute("floor")){let e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Matrix3.temp();s.copy(hit.point).sub(this.feetPos),s.y>1.5&&s.multiplyScalar(0),s.length()>this.data.teleportDistance&&s.normalize().multiplyScalar(this.data.teleportDistance),s.add(this.feetPos),this._teleportCursor.object3D.position.copy(s),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),i.getNormalMatrix(hit.el.object3D.matrixWorld),s.copy(hit.face.normal).applyMatrix3(i).normalize(),s.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,s),this._teleportCursor.object3D.quaternion.premultiply(t)}else this._teleportCursor.object3D.position.copy(this.feetPos),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position)}else if(this._teleporting){let t=THREE.Vector3.temp();this._teleportCursor.object3D.localToWorld(t.set(0,0,0)),this.teleport(t),this._teleportCursor.setAttribute("visible",!1),this._teleportCursor.setAttribute("position","0 0 0"),this._teleporting=!1}},_callButtons(){let t=0;for(this._keysDown.Space&&(t|=1),this._keysDown.KeyG&&(t|=2),this._vrRightClick&&(t|=1),this._vrLeftClick&&(t|=2),i=0,len=navigator.getGamepads().length;i(t.length()>e?t.multiplyScalar((t.length()-e)/(1-e)/t.length()):t.set(0,0),t),_fourWay(t){let e=t.length();return Math.abs(t.x)>Math.abs(t.y)?t.y=0:t.x=0,t.multiplyScalar(e/t.length()),t},_onKeyDown(t){this._keysDown[t.code]=!0},_onKeyUp(t){this._keysDown[t.code]=!1},_onAxisMove(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?(this._axes[0]=t.detail.axis[2],this._axes[1]=t.detail.axis[3]):(this._axes[2]=t.detail.axis[2],this._axes[3]=t.detail.axis[3]),this._handEnabled||(this._teleportBeam.parentElement.removeChild(this._teleportBeam),this._teleportBeam=this._rightHand.ensure(".teleportBeam","a-entity",{class:"teleportBeam",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._handEnabled=!0)},_onButtonChanged(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?3==t.detail.id&&(this._vrLeftClick=t.detail.state.pressed):3==t.detail.id&&(this._vrRightClick=t.detail.state.pressed)},_onTouchStart(t){let e=this.el.sceneEl.canvas.clientWidth;for(let s=0;se/2&&(this._rightTouchId=i.identifier,this._rightTouchCenter.set(i.clientX,i.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),i.add(o),o.multiplyScalar(32/o.length())),o.divideScalar(32))}t.preventDefault()},_onTouchEnd(t){for(let e=0;e{this.init()}),256);let e=new THREE.Vector3;setTimeout((()=>{this.el.object3D.localToWorld(e.set(0,0,0)),t.teleport(e,!0),setTimeout((()=>{t.toggleCrouch(!0)}),256)}),256)}})},{}],14:[function(t,e,s){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],15:[function(t,e,s){AFRAME.registerComponent("onevent",{multiple:!0,schema:{event:{type:"string"},entity:{type:"selector"},property:{type:"string"},value:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this.pause(),this._event=this.data.event||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._value=this.data.value||"",this.el.isPlaying&&this.play()},play(){this._event&&this.el.addEventListener(this._event,this.trigger)},pause(){this._event&&this.el.removeEventListener(this._event,this.trigger)},trigger(t){let e=this._property.split(".");e.push(this._value),this._entity.setAttribute(...e)}})},{}],16:[function(t,e,s){AFRAME.registerComponent("onstate",{multiple:!0,schema:{state:{type:"string"},entity:{type:"selector"},property:{type:"string"},on:{type:"string"},off:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this._state=this.data.state||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._on=this.data.on||"",this._off=this.data.off||""},play(){this.trigger(),this.el.addEventListener("stateadded",this.trigger),this.el.addEventListener("stateremoved",this.trigger)},pause(){this.el.removeEventListener("stateadded",this.trigger),this.el.removeEventListener("stateremoved",this.trigger)},trigger(t){if(t&&t.detail!==this._state)return;let e=this._property.split(".");e.push(this.el.is(this._state)?this._on:this._off),this._entity.setAttribute(...e)}})},{}],17:[function(t,e,s){const i=t("../libs/cmdCodec"),o=t("../../package");AFRAME.registerSystem("physics",{schema:{workerUrl:{type:"string",default:`https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v${o.version}/dist/cannonWorker.min.js`},gravity:{type:"vec3",default:{x:0,y:-10,z:0}},debug:{type:"boolean",default:!1}},update(){if(this.data.workerUrl){if(!this.worker){if(this.data.workerUrl.includes("//")){let t=`importScripts(${JSON.stringify(this.data.workerUrl)})`;this.worker=new Worker(`data:text/javascript;base64,${btoa(t)}`)}else this.worker=new Worker(this.data.workerUrl);this.worker.postMessage("log "+i.stringifyParam("Physics worker ready!")),this.worker.addEventListener("message",this.onMessage.bind(this))}this.bodies=this.bodies||[],this.movingBodies=this.movingBodies||[],this.joints=this.joints||[],this.buffers=[new Float64Array(8),new Float64Array(8)],this.worker.postMessage("world gravity = "+i.stringifyParam(this.data.gravity)),this._debug=this.data.debug}else this.remove()},remove(){this.worker&&this.worker.terminate(),this.worker=null,this.bodies=[],this.movingBodies=[]},tick(t,e){if(!this.worker)return;if(this.buffers.length<2)return;let s=this.buffers.shift();if(s.length<8*this.movingBodies.length){let t=s.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;s=new Float64Array(t),s.fill(NaN);let i=THREE.Vector3.temp(),o=THREE.Quaternion.temp();for(let t=0;t2;)this.buffers.shift()},command(t){switch("number"==typeof t[0]&&t.shift(),t.shift()){case"body":let e=t.shift(),s=this.bodies[e];s&&s.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+i.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":24,"./physics/body":18,"./physics/joint":19,"./physics/shape":20}],18:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("body",{dependencies:["position","rotation","scale"],schema:{type:{type:"string",default:"dynamic"},mass:{type:"number",default:1},friction:{type:"number",default:.3},restitution:{type:"number",default:.3},belongsTo:{type:"int",default:1},collidesWith:{type:"int",default:1},emitsWith:{type:"int",default:0},sleeping:{type:"boolean",default:!1},autoShape:{type:"boolean",default:!0}},init(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies,o=this.el.sceneEl.systems.physics.buffers[0];if(!t)return;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el,"static"!==this.data.type?(this.mid=s.indexOf(null),this.mid<0&&(this.mid=s.length),s[this.mid]=this.el):this.mid=null;let n={mid:this.mid};if(n.type=this.data.type,n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),null!==this.mid){let t=8*this.mid;o[t++]=n.position.x,o[t++]=n.position.y,o[t++]=n.position.z,o[t++]=this.data.sleeping,o[t++]=n.quaternion.x,o[t++]=n.quaternion.y,o[t++]=n.quaternion.z,o[t++]=n.quaternion.w}if(this.shapes=[],this.sleeping=!0,t.postMessage("world body "+this.id+" create "+i.stringifyParam(n)),setTimeout((()=>{n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),t.postMessage("world body "+this.id+" position = "+i.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+i.stringifyParam(n.quaternion)),this.el.components.shape&&this.el.components.shape.play();let e=this.el.querySelectorAll("[shape]");e&&e.forEach((t=>{t.components.shape&&t.components.shape.play()})),this.el.components.joint&&this.el.components.joint.play();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].play()})),this.data.autoShape&&!this.el.getAttribute("shape"))if(this.el.firstElementChild){let t=this.el.querySelectorAll("a-box, a-sphere, a-cylinder");t&&t.forEach((t=>{t.getAttribute("shape")||t.setAttribute("shape",!0)}))}else this.el.setAttribute("shape",!0);this._initiated=!0},play(){this._initiated||(this.init(),this.update({}))},update(t){let e=this.el.sceneEl.systems.physics.worker;e&&(this.data.type!==t.type&&e.postMessage("world body "+this.id+" type = "+i.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+i.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+i.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+i.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+i.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+i.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+i.stringifyParam(this.data.emitsWith)),setTimeout((()=>{e.postMessage("world body "+this.id+" sleeping = "+!!this.data.sleeping)})))},sleep(){let t=this.el.sceneEl.systems.physics.worker;t&&(t.postMessage("world body "+this.id+" sleeping = true"),this.sleeping=!0)},pause(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies;if(!t)return;this.el.components.joint&&this.el.components.joint.pause();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].pause();let i=this.el.querySelectorAll("[shape]");i&&i.forEach((t=>{t.components.shape&&t.components.shape.pause()})),this.el.components.shape&&this.el.components.shape.pause(),e[this.id]=null,null!==this.mid&&(s[this.mid]=null),t.postMessage("world body "+this.id+" remove"),this._initiated=!1},tick(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.buffers[0];if(t&&null!==this.mid){let t=8*this.mid;if(e.length<=t)return;if("kinematic"===this.data.type){let s=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,this.sleeping=!!e[t++];let i=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,e[t++]=i.w}else if(e[t+1]){let s=THREE.Quaternion.temp();this.el.object3D.position.set(e[t++],e[t++],e[t++]),this.el.object3D.parent.worldToLocal(this.el.object3D.position),this.sleeping=!!e[t++],this.el.object3D.getWorldQuaternion(s),this.el.object3D.quaternion.multiply(s.conjugate().normalize()),s.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(s.normalize())}}},command(t){switch(t.shift()){case"emits":let e=t.shift();switch(e.event){case"collision":let t=this.el.sceneEl.systems.physics.bodies;if(e.body1=t[e.body1],e.body2=t[e.body2],!e.body1||!e.body2)return;e.shape1=e.body1.components.body.shapes[e.shape1],e.shape2=e.body2.components.body.shapes[e.shape2]}this.el.emit(e.event,e)}},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.id+" eval "+i.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),s=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+i.stringifyParam(e)),this.el.object3D.getWorldQuaternion(s),t.postMessage("world body "+this.id+" quaternion "+i.stringifyParam(s))}})},{"../../libs/cmdCodec":24}],19:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("joint",{multiple:!0,schema:{type:{type:"string",default:"ball"},body1:{type:"selector"},body2:{type:"selector"},pivot1:{type:"vec3",default:{x:0,y:0,z:0}},pivot2:{type:"vec3",default:{x:0,y:0,z:0}},axis1:{type:"vec3",default:{x:0,y:1,z:0}},axis2:{type:"vec3",default:{x:0,y:1,z:0}},min:{type:"number",default:0},max:{type:"number",default:1},collision:{type:"boolean",default:!0}},play(){if(null!=this._id)return;let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;if(!t)return;if(!this.data.body1.components.body)return this._retry=setTimeout((()=>{this.play()}),256);if(!this.data.body2.components.body)return this._retry=setTimeout((()=>{this.play()}),256);this._id=e.indexOf(null),this._id<0&&(this._id=e.length),e[this._id]=this.el;let s={};s.type=this.data.type,s.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,s.body2=this.data.body2.components.body.id,s.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),s.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),s.axis1=this.data.axis1,s.axis2=this.data.axis2,s.min=this.data.min,s.max=this.data.max,s.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.pivot1.multiply(o),s.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+i.stringifyParam(s))},update(t){this.el.sceneEl.systems.physics.worker&&(this.data.body1=this.data.body1||this.el)},pause(){clearTimeout(this._retry);let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;t&&(e[this._id]=null,t.postMessage("world joint "+this._id+" remove"),this._id=null)},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world joint "+this._id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],20:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("shape",{schema:{},play(){if(null!=this.id)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;for(this.body=this.el;this.body&&!this.body.matches("[body]");)this.body=this.body.parentElement;if(!this.body)return this._retry=setTimeout((()=>{this.play()}),256);this.bodyId=this.body.components.body.id;let e=this.body.components.body.shapes;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el;let s={};s.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(s.position),s.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(s.quaternion.multiply(o.conjugate().normalize()).normalize(),s.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":s.type="sphere",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":s.type="cylinder",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":s.type="box",s.size.set(parseFloat(this.el.getAttribute("width")||1),parseFloat(this.el.getAttribute("height")||1),parseFloat(this.el.getAttribute("depth")||1))}let n=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.size.multiply(n),s.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+i.stringifyParam(s))},pause(){if(clearTimeout(this._retry),!this.body)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;let e=this.body.components.body.shapes;t.postMessage("world body "+this.bodyId+" shape "+this.id+" remove"),e[this.id]=null,this.id=null},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.bodyId+" shape "+this.id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],21:[function(require,module,exports){AFRAME.registerComponent("script",{schema:{src:{type:"string"},call:{type:"string"},args:{type:"array"}},async update(oldData){if(this.data.src!==oldData.src){this.script&&(this.el.isPlaying&&this.script.pause?.(),this.script.remove?.()),this.script=null;let response=await fetch(this.data.src);if(response.status>=200&&response.status<300){if(this.script=eval(await await response.text()),this.script.el=this.el,this.script.events)for(let t in this.script.events)this.script.events[t]=this.script.events[t].bind(this.script)}else console.error("Could not load",this.data.src);this.script.init?.(),this.el.isPlaying&&this.script.play?.()}this.script&&this.data.call?.trim()&&(this.script[this.data.call.trim()](...this.data.args),this.el.setAttribute("script","call",""))},remove(){this.script&&this.script.remove?.(...arguments)},tick(){this.script&&this.script.tick?.(...arguments)},tock(){this.script&&this.script.tock?.(...arguments)},play(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.addEventListener(t,this.script.events[t]);this.script.play?.(...arguments)}},pause(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.removeEventListener(t,this.script.events[t]);this.script.pause?.(...arguments)}}})},{}],22:[function(t,e,s){AFRAME.registerComponent("trigger",{schema:{objects:{type:"string",default:"[camera]"}},init(){this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){this.objects||this.refreshObjects();let t,e=THREE.Vector3.temp(),s=parseFloat(this.el.getAttribute("width")||1),i=parseFloat(this.el.getAttribute("height")||1),o=parseFloat(this.el.getAttribute("depth")||1),n=parseFloat(this.el.getAttribute("radius")||1);for(let a of this.objects){switch(a.object3D.localToWorld(e.set(0,0,0)),this.el.object3D.worldToLocal(e),this.el.tagName.toLowerCase()){case"a-sphere":t=e.length()=0){let t={trigger:this.el,object:a};this.el.emit("untrigger",t),a.emit("untrigger",t),this.triggered.splice(this.triggered.indexOf(a),1),this.triggered.length||this.el.removeState("triggered")}}},refreshObjects(){this.objects=this.objects||[],this.triggered=this.triggered||[],this.objects.splice(0,this.objects.length);let t=this.el.sceneEl.querySelectorAll(this.data.objects);if(t){t.forEach((t=>{this.objects.push(t)}));for(let t=0;t=0)return t;return(t+", ").replaceAll(","," *,")+t}AFRAME.components.raycaster.Component.prototype.update=function(){return this._matchSelector=this.data.objects,this.data.objects=n(this.data.objects),i.apply(this,arguments)},AFRAME.components.raycaster.Component.prototype.refreshObjects=function(){let t=o.apply(this,arguments),e=this.intersections;for(let t of e)for(t.el=t.object.el;t.el&&!t.el.matches(this._matchSelector);)t.el=t.el.parentNode;return t}},{}],24:[function(t,e,s){e.exports={parse(t){let e=t.split(" "),s=[];for(let t of e)if(t)try{s.push(JSON.parse(t))}catch(e){"="!==t&&s.push(t)}return s},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],25:[function(t,e,s){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),s=t.object3D,i=this.object3D;s&&i&&i.parent&&(s.localToWorld(i.position.set(0,0,0)),i.parent.worldToLocal(i.position),i.getWorldQuaternion(e),i.quaternion.multiply(e.conjugate().normalize()),s.getWorldQuaternion(e),i.quaternion.multiply(e.normalize()))}},{}],26:[function(t,e,s){Element.prototype.ensure=function(t,e=t,s={},i=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),s)a=s[n],o.setAttribute(n,a);o.innerHTML=i}return o}},{}],27:[function(t,e,s){function i(t){t._pool=[],t._inUse=[],t.temp=function(){let e=t._pool.pop()||new t;return t._inUse.push(e),t._gc||(t._gc=setTimeout(t._recycle)),e},t._recycle=function(){for(;t._inUse.length;)t._pool.push(t._inUse.pop());t._gc=!1}}i(THREE.Vector2),i(THREE.Vector3),i(THREE.Quaternion),i(THREE.Matrix3),i(THREE.Matrix4)},{}],28:[function(t,e,s){let i=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,s,i,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,s)=>{if(t._tgest.handlers[e])for(let i of t._tgest.handlers[e])i(s);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,s=t.changedTouches[0].screenY,o=!1,i=setTimeout((()=>{o=!0,n("hold",t)}),512)})),t.addEventListener("touchmove",(t=>{let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))>32){if(clearTimeout(i),o)return;Math.abs(e-a)>Math.abs(s-r)?n(a{clearTimeout(i);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))<32){if(o)return;n("tap",t)}})),t._tgest};Element.prototype.addEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":n(this).handlers[t].push(e);break;default:return i.call(this,t,e)}},Element.prototype.removeEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":let s=n(this),i=s.handlers[t].indexOf(e);i>=0&&s.handlers[t].splice(i,1);break;default:return o.call(this,t,e)}}},{}],29:[function(t,e,s){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],30:[function(t,e,s){AFRAME.registerPrimitive("a-main",{})},{}],31:[function(t,e,s){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,s,i){function o(a,r){if(!s[a]){if(!e[a]){var h="function"==typeof require&&require;if(!r&&h)return h(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=s[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,s,i)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;a dist/#{name}.min.js"',bump:"npm version patch --no-git-tag-version",gitadd:"git add package*.json dist/*.js"},"pre-commit":["bump","build","gitadd"],keywords:["aframe","aframe-component","webvr","webxr","gamedev"],author:"poeticAndroid",license:"MIT",devDependencies:{browserify:"^17.0.0","foreach-cli":"^1.8.1",minify:"^7.0.2","pre-commit":"^1.2.2",watchify:"^4.0.0"}}},{}],2:[function(t,e,s){t("./libs/pools"),t("./libs/copyWorldPosRot"),t("./libs/ensureElement"),t("./libs/touchGestures"),t("./libs/betterRaycaster"),setTimeout((()=>{document.body.addEventListener("swipeup",(t=>{document.body.requestFullscreen()}))})),t("./components/grabbing"),t("./components/include"),t("./components/injectplayer"),t("./components/locomotion"),t("./components/onevent"),t("./components/onstate"),t("./components/physics"),t("./components/script"),t("./components/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const i=t("../package");console.log(`${i.title} Version ${i.version} by ${i.author}\n(${i.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":9,"./components/injectplayer":10,"./components/locomotion":11,"./components/onevent":15,"./components/onstate":16,"./components/physics":17,"./components/script":21,"./components/trigger":22,"./libs/betterRaycaster":23,"./libs/copyWorldPosRot":25,"./libs/ensureElement":26,"./libs/pools":27,"./libs/touchGestures":28,"./primitives/a-hand":29,"./primitives/a-main":30,"./primitives/a-player":31}],3:[function(t,e,s){AFRAME.registerComponent("grabbing",{schema:{hideOnGrab:{type:"boolean",default:!0},grabDistance:{type:"number",default:1}},init(){this._enableHands=this._enableHands.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onWheel=this._onWheel.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchTap=this._onTouchTap.bind(this),this._onTouchHold=this._onTouchHold.bind(this),this._btnPress={},this._btnFlex={},this._keysDown={},this._grabCount=0,this._hands=["head","left","right"],this._head={},this._left={},this._right={},this._head.hand=this.el.querySelector("a-camera"),this._left.hand=this.el.querySelector('a-hand[side="left"]'),this._right.hand=this.el.querySelector('a-hand[side="right"]'),this._head.glove=this._head.hand.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._left.glove=this._ensureGlove(this._left.hand),this._right.glove=this._ensureGlove(this._right.hand),this._left.glove.setAttribute("visible",!1),this._right.glove.setAttribute("visible",!1);for(let t of this._hands){this["_"+t].hand.addEventListener("buttonchanged",this._enableHands)}this._head.ray=this._head.hand.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._head.buttonRay=this._head.hand.ensure(".button.ray","a-entity",{class:"button ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [button]",far:1,autoRefresh:!1}}),this._head.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,position:"0 0 -1"},''),this._head.buttonReticle=this._head.buttonRay.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,color:"black",position:"0 0 -1"},''),this._head.anchor=this._head.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:!1,body:"type:kinematic;autoShape:false;"})},update(t){for(let t of this._hands){let e="_"+t;this[e].ray&&this[e].ray.setAttribute("raycaster","far",this.data.grabDistance+("head"===t?1:.1875))}},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.addEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.addEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.addEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.addEventListener("hold",this._onTouchHold)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.removeEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.removeEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.removeEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.removeEventListener("hold",this._onTouchHold)},remove(){for(let t of this._hands){let e="_"+t;this.drop(t),this[e].glove.copyWorldPosRot(this[e].hand);let s=.25;for(let i=0;i<5;i++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:i,flex:s})}},tick(t,e){for(i=0,len=navigator.getGamepads().length;i{this.sticky=!1,this._flexFinger(t,5,.5)}),256)}},drop(t="head"){let e="_"+t;this.sticky||(this[e].anchor.removeAttribute("animation__rot"),this[e].anchor.removeAttribute("animation__pos"),this[e].glove.setAttribute("visible",!0),setTimeout((()=>{this[e].anchor.removeAttribute("joint__grab"),this[e].anchor.setAttribute("position","0 0 0"),this[e].anchor.setAttribute("rotation","0 0 0")}),32),setTimeout((()=>{this[e].glove.setAttribute("body","collidesWith",1)}),1024),this[e].grabbed&&(this.emit("drop",this[e].glove,this[e].grabbed),this._grabCount=Math.max(0,this._grabCount-1),this._grabCount||this.el.removeState("grabbing"),this._flexFinger(t,5,0),this[e].grabbed.removeState("grabbed"),this[e].grabbed=null))},dropObject(t){for(let e of this._hands){this["_"+e].grabbed===t&&this.drop(e)}},use(t="head",e=0){this.useDown(t,e),setTimeout((()=>{this.useUp(t,e)}),32)},useDown(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("usedown",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastButton&&(this[s]._lastClick=this[s]._lastButton,this.emit("press",this[s].glove,this[s]._lastClick,{button:e}),this[s]._lastClick.addState("pressed"))},useUp(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("useup",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastClick&&(this.emit("unpress",this[s].glove,this[s]._lastClick),this[s]._lastClick.removeState("pressed"),this[s]._lastClick=null)},moveHeadHand(t=0,e=0,s=0,i=0){this._head.anchor.object3D.position.z=Math.min(Math.max(-1.5,this._head.anchor.object3D.position.z+t),-.125);let o=THREE.Quaternion.temp().set(e,s,i,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,s,i={}){i.grabbing=this.el,i.grabbedElement=s,i.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(i.hand=t);e.emit(t,i),s&&s.emit(t,i)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let s=.0625;if(this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:s/2,height:s,depth:2*s}),this[e].glove.setAttribute("body","type:kinematic;"),"head"===t)continue;this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}});let i=this[e].glove.querySelector(".palm")||this[e].glove;this[e].ray=i.ensure(".grabbing.ray","a-entity",{class:"grabbing ray",position:"left"===t?"-0.0625 0 0.0625":"0.0625 0 0.0625",rotation:"left"===t?"0 -45 0":"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this[e].buttonRay=i.ensure(".button.ray","a-entity",{class:"button ray",position:"0 0.03125 0",rotation:"left"===t?"0 -8 0":"0 8 0",raycaster:{objects:"[wall], [button]",far:.5,autoRefresh:!1}}),this[e].anchor=this[e].ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this[e].glove.setAttribute("visible",!0)}this._head.ray=null,this._head.buttonRay=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),s=t.getAttribute("color")||"lightblue";return t.ensure(".glove","a-entity",{class:"glove",fingerflex:{min:"left"===e?-10:10,max:"left"===e?-90:90}},`\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n `)},_flexFinger(t,e,s){let i="_"+t;if(e<5)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s});else for(e-=5;e<5;e++)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s})},_onKeyDown(t){this._keysDown[t.code]=!0,"e"===t.key&&this.toggleGrab()},_onKeyUp(t){this._keysDown[t.code]=!1},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_onWheel(t){let e=0,s=0,i=0;return this._keysDown.Digit3&&t.deltaY>0&&(i+=-.125),this._keysDown.Digit3&&t.deltaY<0&&(i+=.125),this._keysDown.Digit2&&t.deltaY>0&&(s+=-.125),this._keysDown.Digit2&&t.deltaY<0&&(s+=.125),this._keysDown.Digit1&&t.deltaY>0&&(e+=.125),this._keysDown.Digit1&&t.deltaY<0&&(e+=-.125),e||s||i?this.moveHeadHand(0,e,s,i):t.deltaY>0?this.moveHeadHand(.125):t.deltaY<0?this.moveHeadHand(-.125):void 0},_onMouseUp(t){let e=t.button;this.useUp("head",e?e%2?e+1:e-1:e)},_onTouchTap(t){this.use()},_onTouchHold(t){this.toggleGrab()},_onButtonChanged(t){let e=t.srcElement.getAttribute("tracked-controls").hand,s="_"+e,i=-1,o=0;switch(t.detail.state.touched&&(o=.5),t.detail.state.pressed&&(o=1),t.detail.state.value&&(o=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=o,t.detail.id){case 0:i=1,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e);break;case 1:i=7,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.grab(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.drop(e);break;case 3:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,1),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,1);break;case 5:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,2),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,2)}this._btnPress[e+t.detail.id]=t.detail.state.pressed,(this.sticky||this[s]._lastButton)&&0!==i||this._flexFinger(e,i,o)}}),t("./grabbing/button"),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/button":4,"./grabbing/climbable":5,"./grabbing/fingerflex":6,"./grabbing/grabbable":7,"./grabbing/receptacle":8}],4:[function(t,e,s){AFRAME.registerComponent("button",{schema:{}})},{}],5:[function(t,e,s){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion]"),this._onBump=this._onBump.bind(this),this._onBumpThis=this._onBumpThis.bind(this),this._autoGrab=!0,setTimeout((()=>{this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._quat.copy(this.el.object3D.quaternion),this._lpos.copy(this.el.object3D.position),this.el.object3D.getWorldPosition(this._wpos),this._top=parseFloat(this.el.getAttribute("height")||1)/2+2}),256)},play(){this._player.addEventListener("bump",this._onBump),this.el.addEventListener("bump",this._onBumpThis)},pause(){this._player.removeEventListener("bump",this._onBump),this.el.removeEventListener("bump",this._onBumpThis),this._climbing=!1},tick(){if(!this._lpos)return;if(this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos),!this._climbing)return;let t=THREE.Vector3.temp();this._hand.object3D.getWorldPosition(t),t.sub(this._handpos).multiplyScalar(-1),"head"===this._handName&&(t.y=0,t.y=t.length(),this._handpos.y+=t.y),this._player.components.locomotion.stopFall(),this._player.components.locomotion.move(t),this._handpos.y-this._wpos.y>this._top&&this._player.components.grabbing.dropObject(this.el)},events:{grab(t){this._climbing=!0,this._handName=t.detail.hand,this._hand=t.detail.gloveElement.parentNode,this._hand.object3D.getWorldPosition(this._handpos),t.detail.intersection.distance>("head"===this._handName?.5:.25)?setTimeout(this._onBump,260):this._player.components.locomotion.jump(),clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.copy(this._player.components.locomotion.headPos)}),1024)},drop(t){this._climbing=!1,clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this._player.components.locomotion.toggleCrouch(!0),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.add(this._player.components.locomotion.centerPos).sub(this._player.components.locomotion.feetPos)}),512)}),256)}},_onBump(t){this._autoGrab||(this._player.components.grabbing.dropObject(this.el),clearTimeout(this._autoGrabTO),this._autoGrabTO=setTimeout((()=>{this._autoGrab=!0}),4096))},_onBumpThis(t){this._autoGrab&&(this._player.components.grabbing.grab(),this._autoGrab=!1)}})},{}],6:[function(t,e,s){AFRAME.registerComponent("fingerflex",{schema:{min:{type:"number",default:10},max:{type:"number",default:90}},init(){this._fingers=["thumb","index","middle","ring","little"],this._currentFlex=[0,0,0,0,0],this._targetFlex=[0,0,0,0,0]},tick(t,e){for(let t=0;t<5;t++){let e=this._fingers[t],s=this._currentFlex[t],i=this._targetFlex[t];s+=Math.random()*Math.random()*(i-s);let o=this.data.min+s*(this.data.max-this.data.min),n=this.el.querySelector(".bend."+e);for(;n;){let t=n.getAttribute("rotation");t.y=o,n.setAttribute("rotation",t),n=n.querySelector(".bend")}this._currentFlex[t]=s}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],7:[function(t,e,s){AFRAME.registerComponent("grabbable",{schema:{physics:{type:"boolean",default:!0},kinematicGrab:{type:"boolean",default:!0},fixed:{type:"boolean",default:!1},fixedPosition:{type:"vec3",default:{x:0,y:0,z:0}}},init(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:dynamic;")},events:{grab(){this.data.kinematicGrab&&this.el.setAttribute("body","type","kinematic")},drop(){this.data.physics&&this.el.setAttribute("body","type","dynamic")}}})},{}],8:[function(t,e,s){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125},onlyGrabbed:{type:"boolean",default:!1}},init(){this._anchor=this.el.ensure(".receptacle.anchor","a-entity",{class:"receptacle anchor",body:"type:kinematic;autoShape:false;"}),this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.nearest)return this.refreshObjects();let t=THREE.Vector3.temp(),e=THREE.Vector3.temp();this.el.object3D.localToWorld(t.set(0,0,0)),this.nearest.object3D.localToWorld(e.set(0,0,0)),e.sub(t),this._lastNearest&&this._lastNearest!==this.nearest?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this._lastNearest.removeState("put"),this.el.emit("take",{grabbable:this._lastNearest}),this._lastNearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this._lastNearest}),this._lastNearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):e.length()>this.data.radius?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this.nearest.removeState("put"),this.el.emit("take",{grabbable:this.nearest}),this.nearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this.nearest}),this.nearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):this.nearest.is("grabbed")||!this._hover?(this._hover||(this.el.emit("hover",{grabbable:this.nearest}),this.nearest.emit("hover",{receptacle:this.el})),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this._anchor.copyWorldPosRot(this.nearest),this._hover=!0,this.nearest.is("grabbed")&&(this._grabbed=!0)):!this._grabbed&&this.data.onlyGrabbed||(this.el.is("filled")||(this._anchor.copyWorldPosRot(this.nearest),this._anchor.components.body.commit(),this.nearest.components.body&&this._anchor.setAttribute("joint__put",{body2:this.nearest,type:"lock"}),this.el.addState("filled"),this.nearest.addState("put"),this.el.emit("put",{grabbable:this.nearest}),this.nearest.emit("put",{receptacle:this.el})),this._anchor.getAttribute("animation__pos")||(this._anchor.setAttribute("animation__pos",{property:"position",to:{x:0,y:0,z:0},dur:256}),this._anchor.setAttribute("animation__rot",{property:"rotation",to:{x:0,y:0,z:0},dur:256})),this.nearest.copyWorldPosRot(this._anchor),this._hover=!0),this._lastNearest=this.nearest},refreshObjects(){let t=1/0,e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Vector3.temp(),o=this.el.sceneEl.querySelectorAll(this.data.objects);this.nearest=null,o&&(this.el.object3D.localToWorld(e.set(0,0,0)),o.forEach((o=>{o.object3D.localToWorld(s.set(0,0,0)),i.copy(s).sub(e),t>i.length()&&(t=i.length(),this.nearest=o)})))}})},{}],9:[function(t,e,s){AFRAME.registerComponent("include",{schema:{type:"string"},async init(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),s=t.indexOf(" include="),i=t.substr(e,s-e);e=t.indexOf('"',s+10)+1,s=t.indexOf(">"),i+=t.substr(e,s-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+i+" "):this.el.removeAttribute("include"),this.el.sceneEl._including_=!1;let n=this.el.sceneEl.querySelector("[include]");n&&n.components&&n.components.include&&n.components.include.init()}}})},{}],10:[function(t,e,s){AFRAME.registerComponent("injectplayer",{init(){this.el.ensure("a-camera","a-camera",{"look-controls":{pointerLockEnabled:!0,touchEnabled:!1},"wasd-controls":{enabled:!1}}),this.el.ensure('a-hand[side="left"]',"a-hand",{side:"left"}),this.el.ensure('a-hand[side="right"]',"a-hand",{side:"right"})}})},{}],11:[function(t,e,s){AFRAME.registerComponent("locomotion",{dependencies:["position","injectplayer"],schema:{speed:{type:"number",default:4},stepLength:{type:"number",default:1},rotationSpeed:{type:"number",default:1},teleportDistance:{type:"number",default:5},jumpForce:{type:"number",default:4},gravity:{type:"number",default:10},godMode:{type:"boolean",default:!1}},init(){this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onAxisMove=this._onAxisMove.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onEnterVR=this._onEnterVR.bind(this),this._onExitVR=this._onExitVR.bind(this),this._keysDown={},this._kbStick=new THREE.Vector2,this._axes=[0,0,0,0],this._leftTouchCenter=new THREE.Vector2,this._leftTouchDir=new THREE.Vector2,this._rightTouchCenter=new THREE.Vector2,this._rightTouchDir=new THREE.Vector2,this._teleporting=!0,this._bumpOverload=0,this._vertVelocity=1,this.currentFloorPosition=new THREE.Vector3,this.centerPos=new THREE.Vector3,this.headPos=new THREE.Vector3,this.headDir=new THREE.Vector3,this.feetPos=new THREE.Vector3,this.lastStep=new THREE.Vector3,this._config={quantizeMovement:!1,quantizeRotation:!1,quantizeMovementVR:!!this.el.sceneEl.isMobile,quantizeRotationVR:!0},this.el.sceneEl.is("vr-mode")?this._onEnterVR():this._onExitVR(),this._camera=this.el.querySelector("a-camera"),this._leftHand=this.el.querySelector('a-hand[side="left"]'),this._rightHand=this.el.querySelector('a-hand[side="right"]'),this._legs=this.el.sceneEl.ensure(".legs","a-entity",{class:"legs",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[floor]",direction:"0 -1 0",far:.625}}),this._legBumper=this.el.sceneEl.ensure(".leg-bumper","a-entity",{class:"leg-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._headBumper=this.el.sceneEl.ensure(".head-bumper","a-entity",{class:"head-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportBeam=this._camera.ensure(".teleport-ray","a-entity",{class:"teleport-ray",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportCursor=this.el.ensure(".teleport-cursor","a-cylinder",{class:"teleport-cursor",radius:.5,height:.0625,material:"opacity:0.5;"}),this._teleportCursor.setAttribute("visible",!1)},update(t){this._godMode=this.data.godMode},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._leftHand.addEventListener("axismove",this._onAxisMove),this._rightHand.addEventListener("axismove",this._onAxisMove),this._leftHand.addEventListener("buttonchanged",this._onButtonChanged),this._rightHand.addEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.addEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.addEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.addEventListener("touchend",this._onTouchEnd),this.el.sceneEl.addEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.addEventListener("exit-vr",this._onExitVR)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this._leftHand.removeEventListener("axismove",this._onAxisMove),this._rightHand.removeEventListener("axismove",this._onAxisMove),this._leftHand.removeEventListener("buttonchanged",this._onButtonChanged),this._rightHand.removeEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.removeEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.removeEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.removeEventListener("touchend",this._onTouchEnd),this.el.sceneEl.removeEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.removeEventListener("exit-vr",this._onExitVR)},remove(){this.el.sceneEl.removeChild(this._legs),this.el.sceneEl.removeChild(this._legBumper),this.el.sceneEl.removeChild(this._headBumper)},tick(t,e){e/=1e3,this.el.object3D.localToWorld(this.centerPos.set(0,0,0)),this.headPos.copy(this._camera.object3D.position),this._camera.object3D.parent.localToWorld(this.headPos),this.headDir.set(0,0,-1).applyQuaternion(this._camera.object3D.quaternion).applyQuaternion(this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp())),this._legs.object3D.localToWorld(this.feetPos.set(0,0,0)),this.feetPos.y-=.5,this._applyButtons(e),this._applyMoveStick(e),this._applyAuxStick(e);let s=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(s.y=0,(s.length()>.5||!this.currentFloor)&&(this.currentFloor&&s.multiplyScalar(.1),this._legs.object3D.position.add(s),this.feetPos.add(s)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let s=t.intersections[0];if(s&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===s.el){let t=THREE.Vector3.temp();t.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition),this.move(t),this.lastStep.add(t),t.y=0,this._legs.object3D.position.add(t)}else this.currentFloor&&this.currentFloor.emit("leave"),s.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-s.distance,0)),this.currentFloor=s.el,this.currentFloorPosition.copy(this.currentFloor.object3D.position)}else this.currentFloor&&this.currentFloor.emit("leave"),this._vertVelocity-=this.data.gravity*e,this.move(THREE.Vector3.temp().set(0,Math.max(-.5,this._vertVelocity*e),0)),this.currentFloor=null}if(this._godMode)this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position);else if(this._bumpOverload>4||Math.abs(this.headPos.y-this.feetPos.y)>3)this.feetPos.y=this.centerPos.y,this._legs.object3D.position.y=this.feetPos.y+.5,this.teleport(this._legBumper.object3D.position,!0),this._bumpOverload&&this._bumpOverload--;else{let t=THREE.Vector3.temp();t.copy(this.feetPos).y+=.5,this._bump(t,this._legBumper),t.copy(this.headPos),this._bump(t,this._headBumper)}let i=THREE.Vector3.temp();if(i.copy(this.feetPos).sub(this.lastStep),i.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));i.length()>this.data.stepLength;)i.multiplyScalar(this.data.stepLength/i.length()),this.lastStep.add(i),i.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let s=THREE.Vector3.temp();s.copy(t).sub(this.feetPos),this.move(s),this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._caution=8,e&&(this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position))},jump(){this.currentFloor&&(this._vertVelocity=this.data.jumpForce)},stopFall(){this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._vertVelocity=Math.max(this._vertVelocity,0)},toggleCrouch(t){let e,s=this.headPos.y-this.feetPos.y;clearTimeout(this._crouchResetTO),this._crouchResetTO=null,Math.abs(this.centerPos.y-this.feetPos.y)>.03125?e=this.feetPos.y-this.centerPos.y:t||(e=s>1?-1:1),this.el.removeAttribute("animation"),e&&this.el.setAttribute("animation",{property:"object3D.position.y",to:this.el.object3D.position.y+e,dur:256})},move(t){this.el.object3D.position.add(t),this.centerPos.add(t),this.headPos.add(t),this._legs.object3D.position.y+=t.y,this.feetPos.y+=t.y},_bump(t,e){let s=THREE.Matrix3.temp(),i=THREE.Vector3.temp();i.copy(t),i.sub(e.object3D.position);let o=i.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${i.x} ${i.y} ${i.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),s.getNormalMatrix(a.el.object3D.matrixWorld),i.copy(a.face.normal).applyMatrix3(s).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(i),e.object3D.position.add(i),this._legs.object3D.position.y!==t&&(e===this._headBumper&&this._headBumper.object3D.position.copy(this._legBumper.object3D.position),clearTimeout(this._crouchResetTO),this._crouchResetTO=setTimeout((()=>{this.toggleCrouch(!0)}),4096)),this._legs.object3D.position.add(i),this._legs.object3D.position.y=Math.max(t,this.headPos.y-1.5),this._caution=4,this._bumpOverload++,this._vertVelocity=Math.min(0,this._vertVelocity);let n={player:this.el,object:a.el};this.el.emit("bump",n),a.el.emit("bump",n)}else this._caution?this._caution--:(this._bumpOverload&&this._bumpOverload--,e.object3D.position.lerp(t,.25))}},_callMoveStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.KeyA&&e.x--,this._keysDown.KeyD&&e.x++,(this._keysDown.KeyW||this._keysDown.ArrowUp)&&e.y--,(this._keysDown.KeyS||this._keysDown.ArrowDown)&&e.y++,this._kbStick.length()>.1?this._kbStick.multiplyScalar((this._kbStick.length()-.1)/this._kbStick.length()):this._kbStick.set(0,0),this._kbStick.add(e.multiplyScalar(.2)),this._kbStick.length()>1&&this._kbStick.normalize(),this._kbStick.length()>t.length()&&t.copy(this._kbStick),this._deadZone(e.set(this._axes[0],this._axes[1])),e.length()>t.length()&&t.copy(e),e.copy(this._leftTouchDir),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyMoveStick(t){let e=this._callMoveStick();e.multiplyScalar(this.data.speed),e.multiplyScalar(t);let s=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,i=Math.cos(s)*e.x-Math.sin(s)*e.y,o=Math.sin(s)*e.x+Math.cos(s)*e.y,n=THREE.Vector3.temp().set(i,0,o);this.quantizeMovement&&(this._quantTime=this._quantTime||0,this._quantDelta=this._quantDelta||new THREE.Vector3,this._quantTime+=t,this._quantDelta.add(n),this._quantTime>.25?(this._quantTime-=.25,n.copy(this._quantDelta),this._quantDelta.set(0,0,0)):n.set(0,0,0)),this.move(n)},_callAuxStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.ArrowLeft&&e.x--,this._keysDown.ArrowRight&&e.x++,this._keysDown.KeyQ&&e.y--,this._keysDown.KeyC&&e.y++,e.length()>t.length()&&t.copy(e),this._fourWay(this._deadZone(e.set(this._axes[2],this._axes[3]))),e.length()>t.length()&&t.copy(e),this._fourWay(e.copy(this._rightTouchDir)),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyAuxStick(t){let e=this._callAuxStick(),s=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,s=-Math.round(e.x)*Math.PI/4):this._rotating=!1:s=-e.x*this.data.rotationSpeed*t,s){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),i=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-s),i.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(s),this.el.object3D.position.add(i),this.centerPos.add(i)}if(this._godMode)this.el.object3D.position.y+=-e.y*this.data.speed*t,this._legs.object3D.position.y+=-e.y*this.data.speed*t;else if(Math.round(e.y)>0?this._crouching||(this._crouching=!0,this.toggleCrouch()):this._crouching=!1,Math.round(e.y)<0){!this._teleporting&&this.data.teleportDistance&&(this._teleportCursor.setAttribute("visible",!0),this._teleporting=!0);let t=THREE.Quaternion.temp();if(this._teleportCursor.object3D.getWorldQuaternion(t),this._teleportCursor.object3D.quaternion.multiply(t.conjugate().normalize()).multiply(t.copy(this.el.object3D.quaternion).multiply(this._camera.object3D.quaternion)),this._teleportCursor.object3D.quaternion.x=0,this._teleportCursor.object3D.quaternion.z=0,this._teleportCursor.object3D.quaternion.normalize(),ray=this._teleportBeam.components.raycaster,ray.refreshObjects(),hit=ray.intersections[0],hit&&null!=hit.el.getAttribute("floor")){let e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Matrix3.temp();s.copy(hit.point).sub(this.feetPos),s.y>1.5&&s.multiplyScalar(0),s.length()>this.data.teleportDistance&&s.normalize().multiplyScalar(this.data.teleportDistance),s.add(this.feetPos),this._teleportCursor.object3D.position.copy(s),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),i.getNormalMatrix(hit.el.object3D.matrixWorld),s.copy(hit.face.normal).applyMatrix3(i).normalize(),s.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,s),this._teleportCursor.object3D.quaternion.premultiply(t)}else this._teleportCursor.object3D.position.copy(this.feetPos),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position)}else if(this._teleporting){let t=THREE.Vector3.temp();this._teleportCursor.object3D.localToWorld(t.set(0,0,0)),this.teleport(t),this._teleportCursor.setAttribute("visible",!1),this._teleportCursor.setAttribute("position","0 0 0"),this._teleporting=!1}},_callButtons(){let t=0;for(this._keysDown.Space&&(t|=1),this._keysDown.KeyG&&(t|=2),this._vrRightClick&&(t|=1),this._vrLeftClick&&(t|=2),i=0,len=navigator.getGamepads().length;i(t.length()>e?t.multiplyScalar((t.length()-e)/(1-e)/t.length()):t.set(0,0),t),_fourWay(t){let e=t.length();return Math.abs(t.x)>Math.abs(t.y)?t.y=0:t.x=0,t.multiplyScalar(e/t.length()),t},_onKeyDown(t){this._keysDown[t.code]=!0},_onKeyUp(t){this._keysDown[t.code]=!1},_onAxisMove(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?(this._axes[0]=t.detail.axis[2],this._axes[1]=t.detail.axis[3]):(this._axes[2]=t.detail.axis[2],this._axes[3]=t.detail.axis[3]),this._handEnabled||(this._teleportBeam.parentElement.removeChild(this._teleportBeam),this._teleportBeam=this._rightHand.ensure(".teleportBeam","a-entity",{class:"teleportBeam",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._handEnabled=!0)},_onButtonChanged(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?3==t.detail.id&&(this._vrLeftClick=t.detail.state.pressed):3==t.detail.id&&(this._vrRightClick=t.detail.state.pressed)},_onTouchStart(t){let e=this.el.sceneEl.canvas.clientWidth;for(let s=0;se/2&&(this._rightTouchId=i.identifier,this._rightTouchCenter.set(i.clientX,i.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),i.add(o),o.multiplyScalar(32/o.length())),o.divideScalar(32))}t.preventDefault()},_onTouchEnd(t){for(let e=0;e{this.init()}),256);let e=new THREE.Vector3;setTimeout((()=>{this.el.object3D.localToWorld(e.set(0,0,0)),t.teleport(e,!0),setTimeout((()=>{t.toggleCrouch(!0)}),256)}),256)}})},{}],14:[function(t,e,s){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],15:[function(t,e,s){AFRAME.registerComponent("onevent",{multiple:!0,schema:{event:{type:"string"},entity:{type:"selector"},property:{type:"string"},value:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this.pause(),this._event=this.data.event||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._value=this.data.value||"",this.el.isPlaying&&this.play()},play(){this._event&&this.el.addEventListener(this._event,this.trigger)},pause(){this._event&&this.el.removeEventListener(this._event,this.trigger)},trigger(t){let e=this._property.split(".");e.push(this._value),this._entity.setAttribute(...e)}})},{}],16:[function(t,e,s){AFRAME.registerComponent("onstate",{multiple:!0,schema:{state:{type:"string"},entity:{type:"selector"},property:{type:"string"},on:{type:"string"},off:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this._state=this.data.state||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._on=this.data.on||"",this._off=this.data.off||""},play(){this.trigger(),this.el.addEventListener("stateadded",this.trigger),this.el.addEventListener("stateremoved",this.trigger)},pause(){this.el.removeEventListener("stateadded",this.trigger),this.el.removeEventListener("stateremoved",this.trigger)},trigger(t){if(t&&t.detail!==this._state)return;let e=this._property.split(".");e.push(this.el.is(this._state)?this._on:this._off),this._entity.setAttribute(...e)}})},{}],17:[function(t,e,s){const i=t("../libs/cmdCodec"),o=t("../../package");AFRAME.registerSystem("physics",{schema:{workerUrl:{type:"string",default:`https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v${o.version}/dist/cannonWorker.min.js`},gravity:{type:"vec3",default:{x:0,y:-10,z:0}},debug:{type:"boolean",default:!1}},update(){if(this.data.workerUrl){if(!this.worker){if(this.data.workerUrl.includes("//")){let t=`importScripts(${JSON.stringify(this.data.workerUrl)})`;this.worker=new Worker(`data:text/javascript;base64,${btoa(t)}`)}else this.worker=new Worker(this.data.workerUrl);this.worker.postMessage("log "+i.stringifyParam("Physics worker ready!")),this.worker.addEventListener("message",this.onMessage.bind(this))}this.bodies=this.bodies||[],this.movingBodies=this.movingBodies||[],this.joints=this.joints||[],this.buffers=[new Float64Array(8),new Float64Array(8)],this.worker.postMessage("world gravity = "+i.stringifyParam(this.data.gravity)),this._debug=this.data.debug}else this.remove()},remove(){this.worker&&this.worker.terminate(),this.worker=null,this.bodies=[],this.movingBodies=[]},tick(t,e){if(!this.worker)return;if(this.buffers.length<2)return;let s=this.buffers.shift();if(s.length<8*this.movingBodies.length){let t=s.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;s=new Float64Array(t),s.fill(NaN);let i=THREE.Vector3.temp(),o=THREE.Quaternion.temp();for(let t=0;t2;)this.buffers.shift()},command(t){switch("number"==typeof t[0]&&t.shift(),t.shift()){case"body":let e=t.shift(),s=this.bodies[e];s&&s.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+i.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":24,"./physics/body":18,"./physics/joint":19,"./physics/shape":20}],18:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("body",{dependencies:["position","rotation","scale"],schema:{type:{type:"string",default:"dynamic"},mass:{type:"number",default:1},friction:{type:"number",default:.3},restitution:{type:"number",default:.3},belongsTo:{type:"int",default:1},collidesWith:{type:"int",default:1},emitsWith:{type:"int",default:0},sleeping:{type:"boolean",default:!1},autoShape:{type:"boolean",default:!0}},init(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies,o=this.el.sceneEl.systems.physics.buffers[0];if(!t)return;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el,"static"!==this.data.type?(this.mid=s.indexOf(null),this.mid<0&&(this.mid=s.length),s[this.mid]=this.el):this.mid=null;let n={mid:this.mid};if(n.type=this.data.type,n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),null!==this.mid){let t=8*this.mid;o[t++]=n.position.x,o[t++]=n.position.y,o[t++]=n.position.z,o[t++]=this.data.sleeping,o[t++]=n.quaternion.x,o[t++]=n.quaternion.y,o[t++]=n.quaternion.z,o[t++]=n.quaternion.w}if(this.shapes=[],this.sleeping=!0,t.postMessage("world body "+this.id+" create "+i.stringifyParam(n)),setTimeout((()=>{n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),t.postMessage("world body "+this.id+" position = "+i.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+i.stringifyParam(n.quaternion)),this.el.components.shape&&this.el.components.shape.play();let e=this.el.querySelectorAll("[shape]");e&&e.forEach((t=>{t.components.shape&&t.components.shape.play()})),this.el.components.joint&&this.el.components.joint.play();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].play()})),this.data.autoShape&&!this.el.getAttribute("shape"))if(this.el.firstElementChild){let t=this.el.querySelectorAll("a-box, a-sphere, a-cylinder");t&&t.forEach((t=>{t.getAttribute("shape")||t.setAttribute("shape",!0)}))}else this.el.setAttribute("shape",!0);this._initiated=!0},play(){this._initiated||(this.init(),this.update({}))},update(t){let e=this.el.sceneEl.systems.physics.worker;e&&(this.data.type!==t.type&&e.postMessage("world body "+this.id+" type = "+i.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+i.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+i.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+i.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+i.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+i.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+i.stringifyParam(this.data.emitsWith)),setTimeout((()=>{e.postMessage("world body "+this.id+" sleeping = "+!!this.data.sleeping)})))},sleep(){let t=this.el.sceneEl.systems.physics.worker;t&&(t.postMessage("world body "+this.id+" sleeping = true"),this.sleeping=!0)},pause(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies;if(!t)return;this.el.components.joint&&this.el.components.joint.pause();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].pause();let i=this.el.querySelectorAll("[shape]");i&&i.forEach((t=>{t.components.shape&&t.components.shape.pause()})),this.el.components.shape&&this.el.components.shape.pause(),e[this.id]=null,null!==this.mid&&(s[this.mid]=null),t.postMessage("world body "+this.id+" remove"),this._initiated=!1},tick(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.buffers[0];if(t&&null!==this.mid){let t=8*this.mid;if(e.length<=t)return;if("kinematic"===this.data.type){let s=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,this.sleeping=!!e[t++];let i=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,e[t++]=i.w}else if(e[t+1]){let s=THREE.Quaternion.temp();this.el.object3D.position.set(e[t++],e[t++],e[t++]),this.el.object3D.parent.worldToLocal(this.el.object3D.position),this.sleeping=!!e[t++],this.el.object3D.getWorldQuaternion(s),this.el.object3D.quaternion.multiply(s.conjugate().normalize()),s.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(s.normalize())}}},command(t){switch(t.shift()){case"emits":let e=t.shift();switch(e.event){case"collision":let t=this.el.sceneEl.systems.physics.bodies;if(e.body1=t[e.body1],e.body2=t[e.body2],!e.body1||!e.body2)return;e.shape1=e.body1.components.body.shapes[e.shape1],e.shape2=e.body2.components.body.shapes[e.shape2]}this.el.emit(e.event,e)}},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.id+" eval "+i.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),s=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+i.stringifyParam(e)),this.el.object3D.getWorldQuaternion(s),t.postMessage("world body "+this.id+" quaternion "+i.stringifyParam(s))}})},{"../../libs/cmdCodec":24}],19:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("joint",{multiple:!0,schema:{type:{type:"string",default:"ball"},body1:{type:"selector"},body2:{type:"selector"},pivot1:{type:"vec3",default:{x:0,y:0,z:0}},pivot2:{type:"vec3",default:{x:0,y:0,z:0}},axis1:{type:"vec3",default:{x:0,y:1,z:0}},axis2:{type:"vec3",default:{x:0,y:1,z:0}},min:{type:"number",default:0},max:{type:"number",default:1},collision:{type:"boolean",default:!0}},play(){if(null!=this._id)return;let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;if(!t)return;if(!this.data.body1.components.body)return this._retry=setTimeout((()=>{this.play()}),256);if(!this.data.body2.components.body)return this._retry=setTimeout((()=>{this.play()}),256);this._id=e.indexOf(null),this._id<0&&(this._id=e.length),e[this._id]=this.el;let s={};s.type=this.data.type,s.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,s.body2=this.data.body2.components.body.id,s.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),s.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),s.axis1=this.data.axis1,s.axis2=this.data.axis2,s.min=this.data.min,s.max=this.data.max,s.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.pivot1.multiply(o),s.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+i.stringifyParam(s))},update(t){this.el.sceneEl.systems.physics.worker&&(this.data.body1=this.data.body1||this.el)},pause(){clearTimeout(this._retry);let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;t&&(e[this._id]=null,t.postMessage("world joint "+this._id+" remove"),this._id=null)},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world joint "+this._id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],20:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("shape",{schema:{},play(){if(null!=this.id)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;for(this.body=this.el;this.body&&!this.body.matches("[body]");)this.body=this.body.parentElement;if(!this.body)return this._retry=setTimeout((()=>{this.play()}),256);this.bodyId=this.body.components.body.id;let e=this.body.components.body.shapes;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el;let s={};s.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(s.position),s.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(s.quaternion.multiply(o.conjugate().normalize()).normalize(),s.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":s.type="sphere",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":s.type="cylinder",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":s.type="box",s.size.set(parseFloat(this.el.getAttribute("width")||1),parseFloat(this.el.getAttribute("height")||1),parseFloat(this.el.getAttribute("depth")||1))}let n=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.size.multiply(n),s.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+i.stringifyParam(s))},pause(){if(clearTimeout(this._retry),!this.body)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;let e=this.body.components.body.shapes;t.postMessage("world body "+this.bodyId+" shape "+this.id+" remove"),e[this.id]=null,this.id=null},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.bodyId+" shape "+this.id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],21:[function(require,module,exports){AFRAME.registerComponent("script",{schema:{src:{type:"string"},call:{type:"string"},args:{type:"array"}},async update(oldData){if(this.data.src!==oldData.src){this.script&&(this.el.isPlaying&&this.script.pause?.(),this.script.remove?.()),this.script=null;let response=await fetch(this.data.src);if(response.status>=200&&response.status<300){if(this.script=eval(await await response.text()),this.script.el=this.el,this.script.events)for(let t in this.script.events)this.script.events[t]=this.script.events[t].bind(this.script)}else console.error("Could not load",this.data.src);this.script.init?.(),this.el.isPlaying&&this.script.play?.()}this.script&&this.data.call?.trim()&&(this.script[this.data.call.trim()](...this.data.args),this.el.setAttribute("script","call",""))},remove(){this.script&&this.script.remove?.(...arguments)},tick(){this.script&&this.script.tick?.(...arguments)},tock(){this.script&&this.script.tock?.(...arguments)},play(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.addEventListener(t,this.script.events[t]);this.script.play?.(...arguments)}},pause(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.removeEventListener(t,this.script.events[t]);this.script.pause?.(...arguments)}}})},{}],22:[function(t,e,s){AFRAME.registerComponent("trigger",{schema:{objects:{type:"string",default:"[camera]"}},init(){this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.objects)return this.refreshObjects();let t,e=THREE.Vector3.temp(),s=parseFloat(this.el.getAttribute("width")||1),i=parseFloat(this.el.getAttribute("height")||1),o=parseFloat(this.el.getAttribute("depth")||1),n=parseFloat(this.el.getAttribute("radius")||1);for(let a of this.objects){switch(a.object3D.localToWorld(e.set(0,0,0)),this.el.object3D.worldToLocal(e),this.el.tagName.toLowerCase()){case"a-sphere":t=e.length()=0){let t={trigger:this.el,object:a};this.el.emit("untrigger",t),a.emit("untrigger",t),this.triggered.splice(this.triggered.indexOf(a),1),this.triggered.length||this.el.removeState("triggered")}}},refreshObjects(){this.objects=this.objects||[],this.triggered=this.triggered||[],this.objects.splice(0,this.objects.length);let t=this.el.sceneEl.querySelectorAll(this.data.objects);if(t){t.forEach((t=>{this.objects.push(t)}));for(let t=0;t=0)return t;return(t+", ").replaceAll(","," *,")+t}AFRAME.components.raycaster.Component.prototype.update=function(){return this._matchSelector=this.data.objects,this.data.objects=n(this.data.objects),i.apply(this,arguments)},AFRAME.components.raycaster.Component.prototype.refreshObjects=function(){let t=o.apply(this,arguments),e=this.intersections;for(let t of e)for(t.el=t.object.el;t.el&&!t.el.matches(this._matchSelector);)t.el=t.el.parentNode;return t}},{}],24:[function(t,e,s){e.exports={parse(t){let e=t.split(" "),s=[];for(let t of e)if(t)try{s.push(JSON.parse(t))}catch(e){"="!==t&&s.push(t)}return s},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],25:[function(t,e,s){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),s=t.object3D,i=this.object3D;s&&i&&i.parent&&(s.localToWorld(i.position.set(0,0,0)),i.parent.worldToLocal(i.position),i.getWorldQuaternion(e),i.quaternion.multiply(e.conjugate().normalize()),s.getWorldQuaternion(e),i.quaternion.multiply(e.normalize()))}},{}],26:[function(t,e,s){Element.prototype.ensure=function(t,e=t,s={},i=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),s)a=s[n],o.setAttribute(n,a);o.innerHTML=i}return o}},{}],27:[function(t,e,s){function i(t){t._pool=[],t._inUse=[],t.temp=function(){let e=t._pool.pop()||new t;return t._inUse.push(e),t._gc||(t._gc=setTimeout(t._recycle)),e},t._recycle=function(){for(;t._inUse.length;)t._pool.push(t._inUse.pop());t._gc=!1}}i(THREE.Vector2),i(THREE.Vector3),i(THREE.Quaternion),i(THREE.Matrix3),i(THREE.Matrix4)},{}],28:[function(t,e,s){let i=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,s,i,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,s)=>{if(t._tgest.handlers[e])for(let i of t._tgest.handlers[e])i(s);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,s=t.changedTouches[0].screenY,o=!1,i=setTimeout((()=>{o=!0,n("hold",t)}),512)})),t.addEventListener("touchmove",(t=>{let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))>32){if(clearTimeout(i),o)return;Math.abs(e-a)>Math.abs(s-r)?n(a{clearTimeout(i);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))<32){if(o)return;n("tap",t)}})),t._tgest};Element.prototype.addEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":n(this).handlers[t].push(e);break;default:return i.call(this,t,e)}},Element.prototype.removeEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":let s=n(this),i=s.handlers[t].indexOf(e);i>=0&&s.handlers[t].splice(i,1);break;default:return o.call(this,t,e)}}},{}],29:[function(t,e,s){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],30:[function(t,e,s){AFRAME.registerPrimitive("a-main",{})},{}],31:[function(t,e,s){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/dist/scenes/ballmachine.html b/dist/scenes/ballmachine.html index 82ae229..c4717ce 100644 --- a/dist/scenes/ballmachine.html +++ b/dist/scenes/ballmachine.html @@ -1,5 +1,7 @@ + diff --git a/dist/scenes/chairs.html b/dist/scenes/chairs.html index e9d5527..628aa0c 100644 --- a/dist/scenes/chairs.html +++ b/dist/scenes/chairs.html @@ -1,5 +1,7 @@ + diff --git a/dist/scenes/demo.html b/dist/scenes/demo.html index 75a5342..9ae90e2 100644 --- a/dist/scenes/demo.html +++ b/dist/scenes/demo.html @@ -62,6 +62,13 @@ + + + + + diff --git a/dist/scenes/ragdoll.html b/dist/scenes/ragdoll.html index eeeef52..ddcd18d 100644 --- a/dist/scenes/ragdoll.html +++ b/dist/scenes/ragdoll.html @@ -1,5 +1,7 @@ + diff --git a/package-lock.json b/package-lock.json index 076090a..759e1fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.17.2", + "version": "0.17.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -84,21 +84,15 @@ "dev": true }, "anymatch": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", - "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", "dev": true, "requires": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" } }, - "array-filter": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/array-filter/-/array-filter-1.0.0.tgz", - "integrity": "sha1-uveeYubvTCpMC4MSMtr/7CUfnYM=", - "dev": true - }, "asn1.js": { "version": "5.4.1", "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz", @@ -147,18 +141,15 @@ } }, "available-typed-arrays": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.2.tgz", - "integrity": "sha512-XWX3OX8Onv97LMk/ftVyBibpGwY5a8SmuxZPzeOxqmuEqUCOM9ZE+uIaD1VNJ5QnvU2UQusvmKbuM1FR8QWGfQ==", - "dev": true, - "requires": { - "array-filter": "^1.0.0" - } + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.4.tgz", + "integrity": "sha512-SA5mXJWrId1TaQjfxUYghbqQ/hYioKmLJvPJyDuYRtXXenFNMjj4hSSt1Cf1xsuXSXrtxrVC5Ot4eU6cOtBDdA==", + "dev": true }, "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, "base64-js": { @@ -455,19 +446,19 @@ "dev": true }, "chokidar": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz", - "integrity": "sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==", + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz", + "integrity": "sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==", "dev": true, "requires": { - "anymatch": "~3.1.1", + "anymatch": "~3.1.2", "braces": "~3.0.2", - "fsevents": "~2.3.1", - "glob-parent": "~5.1.0", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", "normalize-path": "~3.0.0", - "readdirp": "~3.5.0" + "readdirp": "~3.6.0" } }, "cipher-base": { @@ -481,9 +472,9 @@ } }, "clean-css": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-5.1.2.tgz", - "integrity": "sha512-QcaGg9OuMo+0Ds933yLOY+gHPWbxhxqF0HDexmToPf8pczvmvZGYzd+QqWp9/mkucAOKViI+dSFOqoZIvXbeBw==", + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-5.1.3.tgz", + "integrity": "sha512-qGXzUCDpLwAlPx0kYeU4QXjzQIcIYZbJjD4FNm7NnSjoP0hYMVZhHOpUYJ6AwfkMX2cceLRq54MeCgHy/va1cA==", "dev": true, "requires": { "source-map": "~0.6.0" @@ -717,9 +708,9 @@ "dev": true }, "debug": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", - "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", + "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", "dev": true, "requires": { "ms": "2.1.2" @@ -847,9 +838,9 @@ } }, "es-abstract": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0.tgz", - "integrity": "sha512-LJzK7MrQa8TS0ja2w3YNLzUgJCGPdPOV1yVvezjNnS89D+VR08+Szt2mz3YB2Dck/+w5tfIq/RoUAFqJJGM2yw==", + "version": "1.18.3", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.3.tgz", + "integrity": "sha512-nQIr12dxV7SSxE6r6f1l3DtAeEYdsGpps13dR0TwJg1S8gyp4ZPgy3FZcHBgbiQqnoqSTb+oC+kO4UQ0C/J8vw==", "dev": true, "requires": { "call-bind": "^1.0.2", @@ -860,14 +851,14 @@ "has-symbols": "^1.0.2", "is-callable": "^1.2.3", "is-negative-zero": "^2.0.1", - "is-regex": "^1.1.2", - "is-string": "^1.0.5", - "object-inspect": "^1.9.0", + "is-regex": "^1.1.3", + "is-string": "^1.0.6", + "object-inspect": "^1.10.3", "object-keys": "^1.1.1", "object.assign": "^4.1.2", "string.prototype.trimend": "^1.0.4", "string.prototype.trimstart": "^1.0.4", - "unbox-primitive": "^1.0.0" + "unbox-primitive": "^1.0.1" } }, "es-to-primitive": { @@ -910,9 +901,9 @@ "dev": true }, "fast-safe-stringify": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz", - "integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==", + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.8.tgz", + "integrity": "sha512-lXatBjf3WPjmWD6DpIZxkeSsCOwqI0maYMpgDlx8g4U2qi4lbjA9oH/HD2a87G+KfsUmo5WbJFmqBZlPxtptag==", "dev": true }, "figures": { @@ -1015,9 +1006,9 @@ } }, "glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "version": "7.1.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", + "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -1255,9 +1246,9 @@ } }, "is-bigint": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.1.tgz", - "integrity": "sha512-J0ELF4yHFxHy0cmSxZuheDOz2luOdVvqjwmEcj8H/L1JHeuEDSDbeRP+Dk9kFVk5RTFzbucJ2Kb9F7ixY2QaCg==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.2.tgz", + "integrity": "sha512-0JV5+SOCQkIdzjBK9buARcV804Ddu7A0Qet6sHi3FimE9ne6m4BGQZfRn+NZiXbBk4F4XmHfDZIipLj9pX8dSA==", "dev": true }, "is-binary-path": { @@ -1270,12 +1261,12 @@ } }, "is-boolean-object": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.0.tgz", - "integrity": "sha512-a7Uprx8UtD+HWdyYwnD1+ExtTgqQtD2k/1yJgtXP6wnMm8byhkoTZRl+95LLThpzNZJ5aEvi46cdH+ayMFRwmA==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.1.tgz", + "integrity": "sha512-bXdQWkECBUIAcCkeH1unwJLIpZYaa5VvuygSyS/c2lf719mTKZDU5UdDRlpd01UjADgmW8RfqaP+mRaVPdr/Ng==", "dev": true, "requires": { - "call-bind": "^1.0.0" + "call-bind": "^1.0.2" } }, "is-buffer": { @@ -1291,18 +1282,18 @@ "dev": true }, "is-core-module": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.2.0.tgz", - "integrity": "sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.4.0.tgz", + "integrity": "sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A==", "dev": true, "requires": { "has": "^1.0.3" } }, "is-date-object": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", - "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.4.tgz", + "integrity": "sha512-/b4ZVsG7Z5XVtIxs/h9W8nvfLgSAyKYdtGWQLbqy6jA1icmgjf8WCoTKgeS4wy5tYaPePouzFMANbnj94c2Z+A==", "dev": true }, "is-extglob": { @@ -1327,9 +1318,9 @@ } }, "is-generator-function": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.8.tgz", - "integrity": "sha512-2Omr/twNtufVZFr1GhxjOMFPAj2sjc/dKaIqBhvo4qciXfJmITGH6ZGd8eZYNHza8t1y0e01AuqRhJwfWp26WQ==", + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.9.tgz", + "integrity": "sha512-ZJ34p1uvIfptHCN7sFTjGibB9/oBg17sHqzDLfuwhvmN/qLVvIQXRQ8licZQ35WJ8KuEQt/etnnzQFI9C9Ue/A==", "dev": true }, "is-glob": { @@ -1354,9 +1345,9 @@ "dev": true }, "is-number-object": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.4.tgz", - "integrity": "sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.5.tgz", + "integrity": "sha512-RU0lI/n95pMoUKu9v1BZP5MBcZuNSVJkMkAG2dJqC4z2GlkGUNeH68SuHuBKBD/XFe+LHZ+f9BKkLET60Niedw==", "dev": true }, "is-promise": { @@ -1366,13 +1357,13 @@ "dev": true }, "is-regex": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.2.tgz", - "integrity": "sha512-axvdhb5pdhEVThqJzYXwMlVuZwC+FF2DpcOhTS+y/8jVq4trxyPgfcwIxIKiyeuLlSQYKkmUaPQJ8ZE4yNKXDg==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.3.tgz", + "integrity": "sha512-qSVXFz28HM7y+IWX6vLCsexdlvzT1PJNFSBuaQLQ5o0IEw8UDYW6/2+eCMVyIsbM8CNLX2a/QWmSpyxYEHY7CQ==", "dev": true, "requires": { "call-bind": "^1.0.2", - "has-symbols": "^1.0.1" + "has-symbols": "^1.0.2" } }, "is-stream": { @@ -1382,18 +1373,18 @@ "dev": true }, "is-string": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.5.tgz", - "integrity": "sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.6.tgz", + "integrity": "sha512-2gdzbKUuqtQ3lYNrUTQYoClPhm7oQu4UdpSZMp1/DGgkHBT8E2Z1l0yMdb6D4zNAxwDiMv8MdulKROJGNl0Q0w==", "dev": true }, "is-symbol": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", - "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", + "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", "dev": true, "requires": { - "has-symbols": "^1.0.1" + "has-symbols": "^1.0.2" } }, "is-typed-array": { @@ -1531,9 +1522,9 @@ } }, "minify": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/minify/-/minify-7.0.1.tgz", - "integrity": "sha512-U3CjnPKRjPu3DxZX7NsB833r2ijbw9af3fHsaChn6o7BHKvaT/zxYDQ8Q/3W7VFXGDrnkAx6XBx3ggEf5KJm7A==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/minify/-/minify-7.0.2.tgz", + "integrity": "sha512-qWFzieSULBAKTLbTqaXY5OLFbFNuEa1b0M+piLkpgJ6pHrMyvvCw6H7WM5/d+HJIwgUCLMI0uEAAyhawAF6cbA==", "dev": true, "requires": { "clean-css": "^5.0.1", @@ -1645,9 +1636,9 @@ "dev": true }, "object-inspect": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz", - "integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw==", + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.10.3.tgz", + "integrity": "sha512-e5mCJlSH7poANfC8z8S9s9S2IN5/4Zb3aZ33f5s8YqoazCFzNLloLU8r5VCG+G7WoqLvAAZoVMcy3tp/3X0Plw==", "dev": true }, "object-keys": { @@ -1786,9 +1777,9 @@ "dev": true }, "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, "path-platform": { @@ -1798,9 +1789,9 @@ "dev": true }, "pbkdf2": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.1.tgz", - "integrity": "sha512-4Ejy1OPxi9f2tt1rRV7Go7zmfDQ+ZectEQz3VGUQhgq62HtIRPDyG/JtnwIxs6x3uNMwo2V7q1fMvKjb+Tnpqg==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.2.tgz", + "integrity": "sha512-iuh7L6jA7JEGu2WxDwtQP1ddOpaJNC4KlDEFfdQajSGgGPNi4OyDc2R7QnbY2bR9QjBVGwgvTdNJZoE7RaxUMA==", "dev": true, "requires": { "create-hash": "^1.1.2", @@ -1811,9 +1802,9 @@ } }, "picomatch": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", - "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", + "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", "dev": true }, "pre-commit": { @@ -1946,9 +1937,9 @@ } }, "readdirp": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz", - "integrity": "sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "dev": true, "requires": { "picomatch": "^2.2.1" @@ -2131,9 +2122,9 @@ } }, "stream-http": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/stream-http/-/stream-http-3.1.1.tgz", - "integrity": "sha512-S7OqaYu0EkFpgeGFb/NPOoPLxFko7TPqtEeFg5DXPB4v/KETHG0Ln6fRFrNezoelpaDKmycEmmZ81cC9DAwgYg==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/stream-http/-/stream-http-3.2.0.tgz", + "integrity": "sha512-Oq1bLqisTyK3TSCXpPbT4sdeYNdmyZJv1LxpEm2vu1ZhK89kSE5YXwZc3cWk0MagGaKriBh9mCFbVGtO+vY29A==", "dev": true, "requires": { "builtin-status-codes": "^3.0.0", @@ -2245,9 +2236,9 @@ } }, "terser": { - "version": "5.6.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.6.1.tgz", - "integrity": "sha512-yv9YLFQQ+3ZqgWCUk+pvNJwgUTdlIxUk1WTN+RnaFJe2L7ipG2csPT0ra2XRm7Cs8cxN7QXmK1rFzEwYEQkzXw==", + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.7.1.tgz", + "integrity": "sha512-b3e+d5JbHAe/JSjwsC3Zn55wsBIM7AsHLjKxT31kGCldgbpFePaFo+PiddtO6uwRZWRw7sPXmAN8dTW61xmnSg==", "dev": true, "requires": { "commander": "^2.20.0", @@ -2310,9 +2301,9 @@ "dev": true }, "tslib": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz", - "integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==", "dev": true }, "tty-browserify": { @@ -2334,15 +2325,15 @@ "dev": true }, "unbox-primitive": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.0.tgz", - "integrity": "sha512-P/51NX+JXyxK/aigg1/ZgyccdAxm5K1+n8+tvqSntjOivPt19gvm1VC49RWYetsiub8WViUchdxl/KWHHB0kzA==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", + "integrity": "sha512-tZU/3NqK3dA5gpE1KtyiJUrEB0lxnGkMFHptJ7q6ewdZ8s12QrODwNbhIJStmJkd1QDXa1NRA8aF2A1zk/Ypyw==", "dev": true, "requires": { "function-bind": "^1.1.1", - "has-bigints": "^1.0.0", - "has-symbols": "^1.0.0", - "which-boxed-primitive": "^1.0.1" + "has-bigints": "^1.0.1", + "has-symbols": "^1.0.2", + "which-boxed-primitive": "^1.0.2" } }, "undeclared-identifiers": { @@ -2377,9 +2368,9 @@ } }, "util": { - "version": "0.12.3", - "resolved": "https://registry.npmjs.org/util/-/util-0.12.3.tgz", - "integrity": "sha512-I8XkoQwE+fPQEhy9v012V+TSdH2kp9ts29i20TaaDUXsg7x/onePbhFJUExBfv/2ay1ZOp/Vsm3nDlmnFGSAog==", + "version": "0.12.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.4.tgz", + "integrity": "sha512-bxZ9qtSlGUWSOy9Qa9Xgk11kSslpuZwaxCg4sNIDj6FLucDab2JxnHwyNTCpHMtK1MjoQiWQ6DiUMZYbSrO+Sw==", "dev": true, "requires": { "inherits": "^2.0.3", diff --git a/package.json b/package.json index dad06af..f672dbc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.17.2", + "version": "0.17.3", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -30,7 +30,7 @@ "devDependencies": { "browserify": "^17.0.0", "foreach-cli": "^1.8.1", - "minify": "^7.0.1", + "minify": "^7.0.2", "pre-commit": "^1.2.2", "watchify": "^4.0.0" } diff --git a/src/components/trigger.js b/src/components/trigger.js index 2d05bd4..7f38adf 100644 --- a/src/components/trigger.js +++ b/src/components/trigger.js @@ -14,7 +14,7 @@ AFRAME.registerComponent("trigger", { }, tick() { - if (!this.objects) this.refreshObjects() + if (!this.objects) return this.refreshObjects() let local = THREE.Vector3.temp() let width = parseFloat(this.el.getAttribute("width") || 1) let height = parseFloat(this.el.getAttribute("height") || 1) From 83e21a9a4f6d971e55caeeb70bb455bc53c32ee1 Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Thu, 15 Jul 2021 23:24:38 +0200 Subject: [PATCH 4/4] v0.18.0 --- dist/a-game.js | 4 ++-- dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/a-game.js b/dist/a-game.js index c0013b6..c4ff33d 100644 --- a/dist/a-game.js +++ b/dist/a-game.js @@ -2,7 +2,7 @@ module.exports={ "name": "a-game", "title": "A-Game", - "version": "0.17.3", + "version": "0.18.0", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -11,7 +11,7 @@ module.exports={ "build": "foreach -g src/*.js -x \"browserify #{path} -o dist/#{name}.js\" && npm run minify", "watch": "foreach -g src/*.js -C -x \"watchify #{path} -d -o dist/#{name}.js\"", "minify": "touch dist/foo.min.js && rm dist/*.min.js && foreach -g dist/*.js -C -x \"minify #{path} > dist/#{name}.min.js\"", - "bump": "npm version patch --no-git-tag-version", + "bump": "npm version minor --no-git-tag-version", "gitadd": "git add package*.json dist/*.js" }, "pre-commit": [ diff --git a/dist/a-game.min.js b/dist/a-game.min.js index 1086796..589edd3 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,s,i){function o(a,r){if(!s[a]){if(!e[a]){var h="function"==typeof require&&require;if(!r&&h)return h(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=s[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,s,i)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;a dist/#{name}.min.js"',bump:"npm version patch --no-git-tag-version",gitadd:"git add package*.json dist/*.js"},"pre-commit":["bump","build","gitadd"],keywords:["aframe","aframe-component","webvr","webxr","gamedev"],author:"poeticAndroid",license:"MIT",devDependencies:{browserify:"^17.0.0","foreach-cli":"^1.8.1",minify:"^7.0.2","pre-commit":"^1.2.2",watchify:"^4.0.0"}}},{}],2:[function(t,e,s){t("./libs/pools"),t("./libs/copyWorldPosRot"),t("./libs/ensureElement"),t("./libs/touchGestures"),t("./libs/betterRaycaster"),setTimeout((()=>{document.body.addEventListener("swipeup",(t=>{document.body.requestFullscreen()}))})),t("./components/grabbing"),t("./components/include"),t("./components/injectplayer"),t("./components/locomotion"),t("./components/onevent"),t("./components/onstate"),t("./components/physics"),t("./components/script"),t("./components/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const i=t("../package");console.log(`${i.title} Version ${i.version} by ${i.author}\n(${i.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":9,"./components/injectplayer":10,"./components/locomotion":11,"./components/onevent":15,"./components/onstate":16,"./components/physics":17,"./components/script":21,"./components/trigger":22,"./libs/betterRaycaster":23,"./libs/copyWorldPosRot":25,"./libs/ensureElement":26,"./libs/pools":27,"./libs/touchGestures":28,"./primitives/a-hand":29,"./primitives/a-main":30,"./primitives/a-player":31}],3:[function(t,e,s){AFRAME.registerComponent("grabbing",{schema:{hideOnGrab:{type:"boolean",default:!0},grabDistance:{type:"number",default:1}},init(){this._enableHands=this._enableHands.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onWheel=this._onWheel.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchTap=this._onTouchTap.bind(this),this._onTouchHold=this._onTouchHold.bind(this),this._btnPress={},this._btnFlex={},this._keysDown={},this._grabCount=0,this._hands=["head","left","right"],this._head={},this._left={},this._right={},this._head.hand=this.el.querySelector("a-camera"),this._left.hand=this.el.querySelector('a-hand[side="left"]'),this._right.hand=this.el.querySelector('a-hand[side="right"]'),this._head.glove=this._head.hand.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._left.glove=this._ensureGlove(this._left.hand),this._right.glove=this._ensureGlove(this._right.hand),this._left.glove.setAttribute("visible",!1),this._right.glove.setAttribute("visible",!1);for(let t of this._hands){this["_"+t].hand.addEventListener("buttonchanged",this._enableHands)}this._head.ray=this._head.hand.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._head.buttonRay=this._head.hand.ensure(".button.ray","a-entity",{class:"button ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [button]",far:1,autoRefresh:!1}}),this._head.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,position:"0 0 -1"},''),this._head.buttonReticle=this._head.buttonRay.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,color:"black",position:"0 0 -1"},''),this._head.anchor=this._head.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:!1,body:"type:kinematic;autoShape:false;"})},update(t){for(let t of this._hands){let e="_"+t;this[e].ray&&this[e].ray.setAttribute("raycaster","far",this.data.grabDistance+("head"===t?1:.1875))}},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.addEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.addEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.addEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.addEventListener("hold",this._onTouchHold)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.removeEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.removeEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.removeEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.removeEventListener("hold",this._onTouchHold)},remove(){for(let t of this._hands){let e="_"+t;this.drop(t),this[e].glove.copyWorldPosRot(this[e].hand);let s=.25;for(let i=0;i<5;i++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:i,flex:s})}},tick(t,e){for(i=0,len=navigator.getGamepads().length;i{this.sticky=!1,this._flexFinger(t,5,.5)}),256)}},drop(t="head"){let e="_"+t;this.sticky||(this[e].anchor.removeAttribute("animation__rot"),this[e].anchor.removeAttribute("animation__pos"),this[e].glove.setAttribute("visible",!0),setTimeout((()=>{this[e].anchor.removeAttribute("joint__grab"),this[e].anchor.setAttribute("position","0 0 0"),this[e].anchor.setAttribute("rotation","0 0 0")}),32),setTimeout((()=>{this[e].glove.setAttribute("body","collidesWith",1)}),1024),this[e].grabbed&&(this.emit("drop",this[e].glove,this[e].grabbed),this._grabCount=Math.max(0,this._grabCount-1),this._grabCount||this.el.removeState("grabbing"),this._flexFinger(t,5,0),this[e].grabbed.removeState("grabbed"),this[e].grabbed=null))},dropObject(t){for(let e of this._hands){this["_"+e].grabbed===t&&this.drop(e)}},use(t="head",e=0){this.useDown(t,e),setTimeout((()=>{this.useUp(t,e)}),32)},useDown(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("usedown",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastButton&&(this[s]._lastClick=this[s]._lastButton,this.emit("press",this[s].glove,this[s]._lastClick,{button:e}),this[s]._lastClick.addState("pressed"))},useUp(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("useup",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastClick&&(this.emit("unpress",this[s].glove,this[s]._lastClick),this[s]._lastClick.removeState("pressed"),this[s]._lastClick=null)},moveHeadHand(t=0,e=0,s=0,i=0){this._head.anchor.object3D.position.z=Math.min(Math.max(-1.5,this._head.anchor.object3D.position.z+t),-.125);let o=THREE.Quaternion.temp().set(e,s,i,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,s,i={}){i.grabbing=this.el,i.grabbedElement=s,i.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(i.hand=t);e.emit(t,i),s&&s.emit(t,i)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let s=.0625;if(this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:s/2,height:s,depth:2*s}),this[e].glove.setAttribute("body","type:kinematic;"),"head"===t)continue;this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}});let i=this[e].glove.querySelector(".palm")||this[e].glove;this[e].ray=i.ensure(".grabbing.ray","a-entity",{class:"grabbing ray",position:"left"===t?"-0.0625 0 0.0625":"0.0625 0 0.0625",rotation:"left"===t?"0 -45 0":"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this[e].buttonRay=i.ensure(".button.ray","a-entity",{class:"button ray",position:"0 0.03125 0",rotation:"left"===t?"0 -8 0":"0 8 0",raycaster:{objects:"[wall], [button]",far:.5,autoRefresh:!1}}),this[e].anchor=this[e].ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this[e].glove.setAttribute("visible",!0)}this._head.ray=null,this._head.buttonRay=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),s=t.getAttribute("color")||"lightblue";return t.ensure(".glove","a-entity",{class:"glove",fingerflex:{min:"left"===e?-10:10,max:"left"===e?-90:90}},`\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n `)},_flexFinger(t,e,s){let i="_"+t;if(e<5)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s});else for(e-=5;e<5;e++)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s})},_onKeyDown(t){this._keysDown[t.code]=!0,"e"===t.key&&this.toggleGrab()},_onKeyUp(t){this._keysDown[t.code]=!1},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_onWheel(t){let e=0,s=0,i=0;return this._keysDown.Digit3&&t.deltaY>0&&(i+=-.125),this._keysDown.Digit3&&t.deltaY<0&&(i+=.125),this._keysDown.Digit2&&t.deltaY>0&&(s+=-.125),this._keysDown.Digit2&&t.deltaY<0&&(s+=.125),this._keysDown.Digit1&&t.deltaY>0&&(e+=.125),this._keysDown.Digit1&&t.deltaY<0&&(e+=-.125),e||s||i?this.moveHeadHand(0,e,s,i):t.deltaY>0?this.moveHeadHand(.125):t.deltaY<0?this.moveHeadHand(-.125):void 0},_onMouseUp(t){let e=t.button;this.useUp("head",e?e%2?e+1:e-1:e)},_onTouchTap(t){this.use()},_onTouchHold(t){this.toggleGrab()},_onButtonChanged(t){let e=t.srcElement.getAttribute("tracked-controls").hand,s="_"+e,i=-1,o=0;switch(t.detail.state.touched&&(o=.5),t.detail.state.pressed&&(o=1),t.detail.state.value&&(o=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=o,t.detail.id){case 0:i=1,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e);break;case 1:i=7,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.grab(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.drop(e);break;case 3:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,1),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,1);break;case 5:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,2),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,2)}this._btnPress[e+t.detail.id]=t.detail.state.pressed,(this.sticky||this[s]._lastButton)&&0!==i||this._flexFinger(e,i,o)}}),t("./grabbing/button"),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/button":4,"./grabbing/climbable":5,"./grabbing/fingerflex":6,"./grabbing/grabbable":7,"./grabbing/receptacle":8}],4:[function(t,e,s){AFRAME.registerComponent("button",{schema:{}})},{}],5:[function(t,e,s){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion]"),this._onBump=this._onBump.bind(this),this._onBumpThis=this._onBumpThis.bind(this),this._autoGrab=!0,setTimeout((()=>{this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._quat.copy(this.el.object3D.quaternion),this._lpos.copy(this.el.object3D.position),this.el.object3D.getWorldPosition(this._wpos),this._top=parseFloat(this.el.getAttribute("height")||1)/2+2}),256)},play(){this._player.addEventListener("bump",this._onBump),this.el.addEventListener("bump",this._onBumpThis)},pause(){this._player.removeEventListener("bump",this._onBump),this.el.removeEventListener("bump",this._onBumpThis),this._climbing=!1},tick(){if(!this._lpos)return;if(this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos),!this._climbing)return;let t=THREE.Vector3.temp();this._hand.object3D.getWorldPosition(t),t.sub(this._handpos).multiplyScalar(-1),"head"===this._handName&&(t.y=0,t.y=t.length(),this._handpos.y+=t.y),this._player.components.locomotion.stopFall(),this._player.components.locomotion.move(t),this._handpos.y-this._wpos.y>this._top&&this._player.components.grabbing.dropObject(this.el)},events:{grab(t){this._climbing=!0,this._handName=t.detail.hand,this._hand=t.detail.gloveElement.parentNode,this._hand.object3D.getWorldPosition(this._handpos),t.detail.intersection.distance>("head"===this._handName?.5:.25)?setTimeout(this._onBump,260):this._player.components.locomotion.jump(),clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.copy(this._player.components.locomotion.headPos)}),1024)},drop(t){this._climbing=!1,clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this._player.components.locomotion.toggleCrouch(!0),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.add(this._player.components.locomotion.centerPos).sub(this._player.components.locomotion.feetPos)}),512)}),256)}},_onBump(t){this._autoGrab||(this._player.components.grabbing.dropObject(this.el),clearTimeout(this._autoGrabTO),this._autoGrabTO=setTimeout((()=>{this._autoGrab=!0}),4096))},_onBumpThis(t){this._autoGrab&&(this._player.components.grabbing.grab(),this._autoGrab=!1)}})},{}],6:[function(t,e,s){AFRAME.registerComponent("fingerflex",{schema:{min:{type:"number",default:10},max:{type:"number",default:90}},init(){this._fingers=["thumb","index","middle","ring","little"],this._currentFlex=[0,0,0,0,0],this._targetFlex=[0,0,0,0,0]},tick(t,e){for(let t=0;t<5;t++){let e=this._fingers[t],s=this._currentFlex[t],i=this._targetFlex[t];s+=Math.random()*Math.random()*(i-s);let o=this.data.min+s*(this.data.max-this.data.min),n=this.el.querySelector(".bend."+e);for(;n;){let t=n.getAttribute("rotation");t.y=o,n.setAttribute("rotation",t),n=n.querySelector(".bend")}this._currentFlex[t]=s}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],7:[function(t,e,s){AFRAME.registerComponent("grabbable",{schema:{physics:{type:"boolean",default:!0},kinematicGrab:{type:"boolean",default:!0},fixed:{type:"boolean",default:!1},fixedPosition:{type:"vec3",default:{x:0,y:0,z:0}}},init(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:dynamic;")},events:{grab(){this.data.kinematicGrab&&this.el.setAttribute("body","type","kinematic")},drop(){this.data.physics&&this.el.setAttribute("body","type","dynamic")}}})},{}],8:[function(t,e,s){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125},onlyGrabbed:{type:"boolean",default:!1}},init(){this._anchor=this.el.ensure(".receptacle.anchor","a-entity",{class:"receptacle anchor",body:"type:kinematic;autoShape:false;"}),this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.nearest)return this.refreshObjects();let t=THREE.Vector3.temp(),e=THREE.Vector3.temp();this.el.object3D.localToWorld(t.set(0,0,0)),this.nearest.object3D.localToWorld(e.set(0,0,0)),e.sub(t),this._lastNearest&&this._lastNearest!==this.nearest?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this._lastNearest.removeState("put"),this.el.emit("take",{grabbable:this._lastNearest}),this._lastNearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this._lastNearest}),this._lastNearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):e.length()>this.data.radius?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this.nearest.removeState("put"),this.el.emit("take",{grabbable:this.nearest}),this.nearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this.nearest}),this.nearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):this.nearest.is("grabbed")||!this._hover?(this._hover||(this.el.emit("hover",{grabbable:this.nearest}),this.nearest.emit("hover",{receptacle:this.el})),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this._anchor.copyWorldPosRot(this.nearest),this._hover=!0,this.nearest.is("grabbed")&&(this._grabbed=!0)):!this._grabbed&&this.data.onlyGrabbed||(this.el.is("filled")||(this._anchor.copyWorldPosRot(this.nearest),this._anchor.components.body.commit(),this.nearest.components.body&&this._anchor.setAttribute("joint__put",{body2:this.nearest,type:"lock"}),this.el.addState("filled"),this.nearest.addState("put"),this.el.emit("put",{grabbable:this.nearest}),this.nearest.emit("put",{receptacle:this.el})),this._anchor.getAttribute("animation__pos")||(this._anchor.setAttribute("animation__pos",{property:"position",to:{x:0,y:0,z:0},dur:256}),this._anchor.setAttribute("animation__rot",{property:"rotation",to:{x:0,y:0,z:0},dur:256})),this.nearest.copyWorldPosRot(this._anchor),this._hover=!0),this._lastNearest=this.nearest},refreshObjects(){let t=1/0,e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Vector3.temp(),o=this.el.sceneEl.querySelectorAll(this.data.objects);this.nearest=null,o&&(this.el.object3D.localToWorld(e.set(0,0,0)),o.forEach((o=>{o.object3D.localToWorld(s.set(0,0,0)),i.copy(s).sub(e),t>i.length()&&(t=i.length(),this.nearest=o)})))}})},{}],9:[function(t,e,s){AFRAME.registerComponent("include",{schema:{type:"string"},async init(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),s=t.indexOf(" include="),i=t.substr(e,s-e);e=t.indexOf('"',s+10)+1,s=t.indexOf(">"),i+=t.substr(e,s-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+i+" "):this.el.removeAttribute("include"),this.el.sceneEl._including_=!1;let n=this.el.sceneEl.querySelector("[include]");n&&n.components&&n.components.include&&n.components.include.init()}}})},{}],10:[function(t,e,s){AFRAME.registerComponent("injectplayer",{init(){this.el.ensure("a-camera","a-camera",{"look-controls":{pointerLockEnabled:!0,touchEnabled:!1},"wasd-controls":{enabled:!1}}),this.el.ensure('a-hand[side="left"]',"a-hand",{side:"left"}),this.el.ensure('a-hand[side="right"]',"a-hand",{side:"right"})}})},{}],11:[function(t,e,s){AFRAME.registerComponent("locomotion",{dependencies:["position","injectplayer"],schema:{speed:{type:"number",default:4},stepLength:{type:"number",default:1},rotationSpeed:{type:"number",default:1},teleportDistance:{type:"number",default:5},jumpForce:{type:"number",default:4},gravity:{type:"number",default:10},godMode:{type:"boolean",default:!1}},init(){this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onAxisMove=this._onAxisMove.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onEnterVR=this._onEnterVR.bind(this),this._onExitVR=this._onExitVR.bind(this),this._keysDown={},this._kbStick=new THREE.Vector2,this._axes=[0,0,0,0],this._leftTouchCenter=new THREE.Vector2,this._leftTouchDir=new THREE.Vector2,this._rightTouchCenter=new THREE.Vector2,this._rightTouchDir=new THREE.Vector2,this._teleporting=!0,this._bumpOverload=0,this._vertVelocity=1,this.currentFloorPosition=new THREE.Vector3,this.centerPos=new THREE.Vector3,this.headPos=new THREE.Vector3,this.headDir=new THREE.Vector3,this.feetPos=new THREE.Vector3,this.lastStep=new THREE.Vector3,this._config={quantizeMovement:!1,quantizeRotation:!1,quantizeMovementVR:!!this.el.sceneEl.isMobile,quantizeRotationVR:!0},this.el.sceneEl.is("vr-mode")?this._onEnterVR():this._onExitVR(),this._camera=this.el.querySelector("a-camera"),this._leftHand=this.el.querySelector('a-hand[side="left"]'),this._rightHand=this.el.querySelector('a-hand[side="right"]'),this._legs=this.el.sceneEl.ensure(".legs","a-entity",{class:"legs",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[floor]",direction:"0 -1 0",far:.625}}),this._legBumper=this.el.sceneEl.ensure(".leg-bumper","a-entity",{class:"leg-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._headBumper=this.el.sceneEl.ensure(".head-bumper","a-entity",{class:"head-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportBeam=this._camera.ensure(".teleport-ray","a-entity",{class:"teleport-ray",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportCursor=this.el.ensure(".teleport-cursor","a-cylinder",{class:"teleport-cursor",radius:.5,height:.0625,material:"opacity:0.5;"}),this._teleportCursor.setAttribute("visible",!1)},update(t){this._godMode=this.data.godMode},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._leftHand.addEventListener("axismove",this._onAxisMove),this._rightHand.addEventListener("axismove",this._onAxisMove),this._leftHand.addEventListener("buttonchanged",this._onButtonChanged),this._rightHand.addEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.addEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.addEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.addEventListener("touchend",this._onTouchEnd),this.el.sceneEl.addEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.addEventListener("exit-vr",this._onExitVR)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this._leftHand.removeEventListener("axismove",this._onAxisMove),this._rightHand.removeEventListener("axismove",this._onAxisMove),this._leftHand.removeEventListener("buttonchanged",this._onButtonChanged),this._rightHand.removeEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.removeEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.removeEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.removeEventListener("touchend",this._onTouchEnd),this.el.sceneEl.removeEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.removeEventListener("exit-vr",this._onExitVR)},remove(){this.el.sceneEl.removeChild(this._legs),this.el.sceneEl.removeChild(this._legBumper),this.el.sceneEl.removeChild(this._headBumper)},tick(t,e){e/=1e3,this.el.object3D.localToWorld(this.centerPos.set(0,0,0)),this.headPos.copy(this._camera.object3D.position),this._camera.object3D.parent.localToWorld(this.headPos),this.headDir.set(0,0,-1).applyQuaternion(this._camera.object3D.quaternion).applyQuaternion(this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp())),this._legs.object3D.localToWorld(this.feetPos.set(0,0,0)),this.feetPos.y-=.5,this._applyButtons(e),this._applyMoveStick(e),this._applyAuxStick(e);let s=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(s.y=0,(s.length()>.5||!this.currentFloor)&&(this.currentFloor&&s.multiplyScalar(.1),this._legs.object3D.position.add(s),this.feetPos.add(s)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let s=t.intersections[0];if(s&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===s.el){let t=THREE.Vector3.temp();t.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition),this.move(t),this.lastStep.add(t),t.y=0,this._legs.object3D.position.add(t)}else this.currentFloor&&this.currentFloor.emit("leave"),s.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-s.distance,0)),this.currentFloor=s.el,this.currentFloorPosition.copy(this.currentFloor.object3D.position)}else this.currentFloor&&this.currentFloor.emit("leave"),this._vertVelocity-=this.data.gravity*e,this.move(THREE.Vector3.temp().set(0,Math.max(-.5,this._vertVelocity*e),0)),this.currentFloor=null}if(this._godMode)this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position);else if(this._bumpOverload>4||Math.abs(this.headPos.y-this.feetPos.y)>3)this.feetPos.y=this.centerPos.y,this._legs.object3D.position.y=this.feetPos.y+.5,this.teleport(this._legBumper.object3D.position,!0),this._bumpOverload&&this._bumpOverload--;else{let t=THREE.Vector3.temp();t.copy(this.feetPos).y+=.5,this._bump(t,this._legBumper),t.copy(this.headPos),this._bump(t,this._headBumper)}let i=THREE.Vector3.temp();if(i.copy(this.feetPos).sub(this.lastStep),i.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));i.length()>this.data.stepLength;)i.multiplyScalar(this.data.stepLength/i.length()),this.lastStep.add(i),i.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let s=THREE.Vector3.temp();s.copy(t).sub(this.feetPos),this.move(s),this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._caution=8,e&&(this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position))},jump(){this.currentFloor&&(this._vertVelocity=this.data.jumpForce)},stopFall(){this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._vertVelocity=Math.max(this._vertVelocity,0)},toggleCrouch(t){let e,s=this.headPos.y-this.feetPos.y;clearTimeout(this._crouchResetTO),this._crouchResetTO=null,Math.abs(this.centerPos.y-this.feetPos.y)>.03125?e=this.feetPos.y-this.centerPos.y:t||(e=s>1?-1:1),this.el.removeAttribute("animation"),e&&this.el.setAttribute("animation",{property:"object3D.position.y",to:this.el.object3D.position.y+e,dur:256})},move(t){this.el.object3D.position.add(t),this.centerPos.add(t),this.headPos.add(t),this._legs.object3D.position.y+=t.y,this.feetPos.y+=t.y},_bump(t,e){let s=THREE.Matrix3.temp(),i=THREE.Vector3.temp();i.copy(t),i.sub(e.object3D.position);let o=i.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${i.x} ${i.y} ${i.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),s.getNormalMatrix(a.el.object3D.matrixWorld),i.copy(a.face.normal).applyMatrix3(s).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(i),e.object3D.position.add(i),this._legs.object3D.position.y!==t&&(e===this._headBumper&&this._headBumper.object3D.position.copy(this._legBumper.object3D.position),clearTimeout(this._crouchResetTO),this._crouchResetTO=setTimeout((()=>{this.toggleCrouch(!0)}),4096)),this._legs.object3D.position.add(i),this._legs.object3D.position.y=Math.max(t,this.headPos.y-1.5),this._caution=4,this._bumpOverload++,this._vertVelocity=Math.min(0,this._vertVelocity);let n={player:this.el,object:a.el};this.el.emit("bump",n),a.el.emit("bump",n)}else this._caution?this._caution--:(this._bumpOverload&&this._bumpOverload--,e.object3D.position.lerp(t,.25))}},_callMoveStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.KeyA&&e.x--,this._keysDown.KeyD&&e.x++,(this._keysDown.KeyW||this._keysDown.ArrowUp)&&e.y--,(this._keysDown.KeyS||this._keysDown.ArrowDown)&&e.y++,this._kbStick.length()>.1?this._kbStick.multiplyScalar((this._kbStick.length()-.1)/this._kbStick.length()):this._kbStick.set(0,0),this._kbStick.add(e.multiplyScalar(.2)),this._kbStick.length()>1&&this._kbStick.normalize(),this._kbStick.length()>t.length()&&t.copy(this._kbStick),this._deadZone(e.set(this._axes[0],this._axes[1])),e.length()>t.length()&&t.copy(e),e.copy(this._leftTouchDir),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyMoveStick(t){let e=this._callMoveStick();e.multiplyScalar(this.data.speed),e.multiplyScalar(t);let s=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,i=Math.cos(s)*e.x-Math.sin(s)*e.y,o=Math.sin(s)*e.x+Math.cos(s)*e.y,n=THREE.Vector3.temp().set(i,0,o);this.quantizeMovement&&(this._quantTime=this._quantTime||0,this._quantDelta=this._quantDelta||new THREE.Vector3,this._quantTime+=t,this._quantDelta.add(n),this._quantTime>.25?(this._quantTime-=.25,n.copy(this._quantDelta),this._quantDelta.set(0,0,0)):n.set(0,0,0)),this.move(n)},_callAuxStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.ArrowLeft&&e.x--,this._keysDown.ArrowRight&&e.x++,this._keysDown.KeyQ&&e.y--,this._keysDown.KeyC&&e.y++,e.length()>t.length()&&t.copy(e),this._fourWay(this._deadZone(e.set(this._axes[2],this._axes[3]))),e.length()>t.length()&&t.copy(e),this._fourWay(e.copy(this._rightTouchDir)),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyAuxStick(t){let e=this._callAuxStick(),s=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,s=-Math.round(e.x)*Math.PI/4):this._rotating=!1:s=-e.x*this.data.rotationSpeed*t,s){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),i=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-s),i.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(s),this.el.object3D.position.add(i),this.centerPos.add(i)}if(this._godMode)this.el.object3D.position.y+=-e.y*this.data.speed*t,this._legs.object3D.position.y+=-e.y*this.data.speed*t;else if(Math.round(e.y)>0?this._crouching||(this._crouching=!0,this.toggleCrouch()):this._crouching=!1,Math.round(e.y)<0){!this._teleporting&&this.data.teleportDistance&&(this._teleportCursor.setAttribute("visible",!0),this._teleporting=!0);let t=THREE.Quaternion.temp();if(this._teleportCursor.object3D.getWorldQuaternion(t),this._teleportCursor.object3D.quaternion.multiply(t.conjugate().normalize()).multiply(t.copy(this.el.object3D.quaternion).multiply(this._camera.object3D.quaternion)),this._teleportCursor.object3D.quaternion.x=0,this._teleportCursor.object3D.quaternion.z=0,this._teleportCursor.object3D.quaternion.normalize(),ray=this._teleportBeam.components.raycaster,ray.refreshObjects(),hit=ray.intersections[0],hit&&null!=hit.el.getAttribute("floor")){let e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Matrix3.temp();s.copy(hit.point).sub(this.feetPos),s.y>1.5&&s.multiplyScalar(0),s.length()>this.data.teleportDistance&&s.normalize().multiplyScalar(this.data.teleportDistance),s.add(this.feetPos),this._teleportCursor.object3D.position.copy(s),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),i.getNormalMatrix(hit.el.object3D.matrixWorld),s.copy(hit.face.normal).applyMatrix3(i).normalize(),s.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,s),this._teleportCursor.object3D.quaternion.premultiply(t)}else this._teleportCursor.object3D.position.copy(this.feetPos),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position)}else if(this._teleporting){let t=THREE.Vector3.temp();this._teleportCursor.object3D.localToWorld(t.set(0,0,0)),this.teleport(t),this._teleportCursor.setAttribute("visible",!1),this._teleportCursor.setAttribute("position","0 0 0"),this._teleporting=!1}},_callButtons(){let t=0;for(this._keysDown.Space&&(t|=1),this._keysDown.KeyG&&(t|=2),this._vrRightClick&&(t|=1),this._vrLeftClick&&(t|=2),i=0,len=navigator.getGamepads().length;i(t.length()>e?t.multiplyScalar((t.length()-e)/(1-e)/t.length()):t.set(0,0),t),_fourWay(t){let e=t.length();return Math.abs(t.x)>Math.abs(t.y)?t.y=0:t.x=0,t.multiplyScalar(e/t.length()),t},_onKeyDown(t){this._keysDown[t.code]=!0},_onKeyUp(t){this._keysDown[t.code]=!1},_onAxisMove(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?(this._axes[0]=t.detail.axis[2],this._axes[1]=t.detail.axis[3]):(this._axes[2]=t.detail.axis[2],this._axes[3]=t.detail.axis[3]),this._handEnabled||(this._teleportBeam.parentElement.removeChild(this._teleportBeam),this._teleportBeam=this._rightHand.ensure(".teleportBeam","a-entity",{class:"teleportBeam",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._handEnabled=!0)},_onButtonChanged(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?3==t.detail.id&&(this._vrLeftClick=t.detail.state.pressed):3==t.detail.id&&(this._vrRightClick=t.detail.state.pressed)},_onTouchStart(t){let e=this.el.sceneEl.canvas.clientWidth;for(let s=0;se/2&&(this._rightTouchId=i.identifier,this._rightTouchCenter.set(i.clientX,i.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),i.add(o),o.multiplyScalar(32/o.length())),o.divideScalar(32))}t.preventDefault()},_onTouchEnd(t){for(let e=0;e{this.init()}),256);let e=new THREE.Vector3;setTimeout((()=>{this.el.object3D.localToWorld(e.set(0,0,0)),t.teleport(e,!0),setTimeout((()=>{t.toggleCrouch(!0)}),256)}),256)}})},{}],14:[function(t,e,s){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],15:[function(t,e,s){AFRAME.registerComponent("onevent",{multiple:!0,schema:{event:{type:"string"},entity:{type:"selector"},property:{type:"string"},value:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this.pause(),this._event=this.data.event||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._value=this.data.value||"",this.el.isPlaying&&this.play()},play(){this._event&&this.el.addEventListener(this._event,this.trigger)},pause(){this._event&&this.el.removeEventListener(this._event,this.trigger)},trigger(t){let e=this._property.split(".");e.push(this._value),this._entity.setAttribute(...e)}})},{}],16:[function(t,e,s){AFRAME.registerComponent("onstate",{multiple:!0,schema:{state:{type:"string"},entity:{type:"selector"},property:{type:"string"},on:{type:"string"},off:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this._state=this.data.state||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._on=this.data.on||"",this._off=this.data.off||""},play(){this.trigger(),this.el.addEventListener("stateadded",this.trigger),this.el.addEventListener("stateremoved",this.trigger)},pause(){this.el.removeEventListener("stateadded",this.trigger),this.el.removeEventListener("stateremoved",this.trigger)},trigger(t){if(t&&t.detail!==this._state)return;let e=this._property.split(".");e.push(this.el.is(this._state)?this._on:this._off),this._entity.setAttribute(...e)}})},{}],17:[function(t,e,s){const i=t("../libs/cmdCodec"),o=t("../../package");AFRAME.registerSystem("physics",{schema:{workerUrl:{type:"string",default:`https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v${o.version}/dist/cannonWorker.min.js`},gravity:{type:"vec3",default:{x:0,y:-10,z:0}},debug:{type:"boolean",default:!1}},update(){if(this.data.workerUrl){if(!this.worker){if(this.data.workerUrl.includes("//")){let t=`importScripts(${JSON.stringify(this.data.workerUrl)})`;this.worker=new Worker(`data:text/javascript;base64,${btoa(t)}`)}else this.worker=new Worker(this.data.workerUrl);this.worker.postMessage("log "+i.stringifyParam("Physics worker ready!")),this.worker.addEventListener("message",this.onMessage.bind(this))}this.bodies=this.bodies||[],this.movingBodies=this.movingBodies||[],this.joints=this.joints||[],this.buffers=[new Float64Array(8),new Float64Array(8)],this.worker.postMessage("world gravity = "+i.stringifyParam(this.data.gravity)),this._debug=this.data.debug}else this.remove()},remove(){this.worker&&this.worker.terminate(),this.worker=null,this.bodies=[],this.movingBodies=[]},tick(t,e){if(!this.worker)return;if(this.buffers.length<2)return;let s=this.buffers.shift();if(s.length<8*this.movingBodies.length){let t=s.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;s=new Float64Array(t),s.fill(NaN);let i=THREE.Vector3.temp(),o=THREE.Quaternion.temp();for(let t=0;t2;)this.buffers.shift()},command(t){switch("number"==typeof t[0]&&t.shift(),t.shift()){case"body":let e=t.shift(),s=this.bodies[e];s&&s.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+i.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":24,"./physics/body":18,"./physics/joint":19,"./physics/shape":20}],18:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("body",{dependencies:["position","rotation","scale"],schema:{type:{type:"string",default:"dynamic"},mass:{type:"number",default:1},friction:{type:"number",default:.3},restitution:{type:"number",default:.3},belongsTo:{type:"int",default:1},collidesWith:{type:"int",default:1},emitsWith:{type:"int",default:0},sleeping:{type:"boolean",default:!1},autoShape:{type:"boolean",default:!0}},init(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies,o=this.el.sceneEl.systems.physics.buffers[0];if(!t)return;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el,"static"!==this.data.type?(this.mid=s.indexOf(null),this.mid<0&&(this.mid=s.length),s[this.mid]=this.el):this.mid=null;let n={mid:this.mid};if(n.type=this.data.type,n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),null!==this.mid){let t=8*this.mid;o[t++]=n.position.x,o[t++]=n.position.y,o[t++]=n.position.z,o[t++]=this.data.sleeping,o[t++]=n.quaternion.x,o[t++]=n.quaternion.y,o[t++]=n.quaternion.z,o[t++]=n.quaternion.w}if(this.shapes=[],this.sleeping=!0,t.postMessage("world body "+this.id+" create "+i.stringifyParam(n)),setTimeout((()=>{n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),t.postMessage("world body "+this.id+" position = "+i.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+i.stringifyParam(n.quaternion)),this.el.components.shape&&this.el.components.shape.play();let e=this.el.querySelectorAll("[shape]");e&&e.forEach((t=>{t.components.shape&&t.components.shape.play()})),this.el.components.joint&&this.el.components.joint.play();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].play()})),this.data.autoShape&&!this.el.getAttribute("shape"))if(this.el.firstElementChild){let t=this.el.querySelectorAll("a-box, a-sphere, a-cylinder");t&&t.forEach((t=>{t.getAttribute("shape")||t.setAttribute("shape",!0)}))}else this.el.setAttribute("shape",!0);this._initiated=!0},play(){this._initiated||(this.init(),this.update({}))},update(t){let e=this.el.sceneEl.systems.physics.worker;e&&(this.data.type!==t.type&&e.postMessage("world body "+this.id+" type = "+i.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+i.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+i.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+i.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+i.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+i.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+i.stringifyParam(this.data.emitsWith)),setTimeout((()=>{e.postMessage("world body "+this.id+" sleeping = "+!!this.data.sleeping)})))},sleep(){let t=this.el.sceneEl.systems.physics.worker;t&&(t.postMessage("world body "+this.id+" sleeping = true"),this.sleeping=!0)},pause(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies;if(!t)return;this.el.components.joint&&this.el.components.joint.pause();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].pause();let i=this.el.querySelectorAll("[shape]");i&&i.forEach((t=>{t.components.shape&&t.components.shape.pause()})),this.el.components.shape&&this.el.components.shape.pause(),e[this.id]=null,null!==this.mid&&(s[this.mid]=null),t.postMessage("world body "+this.id+" remove"),this._initiated=!1},tick(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.buffers[0];if(t&&null!==this.mid){let t=8*this.mid;if(e.length<=t)return;if("kinematic"===this.data.type){let s=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,this.sleeping=!!e[t++];let i=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,e[t++]=i.w}else if(e[t+1]){let s=THREE.Quaternion.temp();this.el.object3D.position.set(e[t++],e[t++],e[t++]),this.el.object3D.parent.worldToLocal(this.el.object3D.position),this.sleeping=!!e[t++],this.el.object3D.getWorldQuaternion(s),this.el.object3D.quaternion.multiply(s.conjugate().normalize()),s.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(s.normalize())}}},command(t){switch(t.shift()){case"emits":let e=t.shift();switch(e.event){case"collision":let t=this.el.sceneEl.systems.physics.bodies;if(e.body1=t[e.body1],e.body2=t[e.body2],!e.body1||!e.body2)return;e.shape1=e.body1.components.body.shapes[e.shape1],e.shape2=e.body2.components.body.shapes[e.shape2]}this.el.emit(e.event,e)}},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.id+" eval "+i.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),s=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+i.stringifyParam(e)),this.el.object3D.getWorldQuaternion(s),t.postMessage("world body "+this.id+" quaternion "+i.stringifyParam(s))}})},{"../../libs/cmdCodec":24}],19:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("joint",{multiple:!0,schema:{type:{type:"string",default:"ball"},body1:{type:"selector"},body2:{type:"selector"},pivot1:{type:"vec3",default:{x:0,y:0,z:0}},pivot2:{type:"vec3",default:{x:0,y:0,z:0}},axis1:{type:"vec3",default:{x:0,y:1,z:0}},axis2:{type:"vec3",default:{x:0,y:1,z:0}},min:{type:"number",default:0},max:{type:"number",default:1},collision:{type:"boolean",default:!0}},play(){if(null!=this._id)return;let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;if(!t)return;if(!this.data.body1.components.body)return this._retry=setTimeout((()=>{this.play()}),256);if(!this.data.body2.components.body)return this._retry=setTimeout((()=>{this.play()}),256);this._id=e.indexOf(null),this._id<0&&(this._id=e.length),e[this._id]=this.el;let s={};s.type=this.data.type,s.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,s.body2=this.data.body2.components.body.id,s.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),s.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),s.axis1=this.data.axis1,s.axis2=this.data.axis2,s.min=this.data.min,s.max=this.data.max,s.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.pivot1.multiply(o),s.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+i.stringifyParam(s))},update(t){this.el.sceneEl.systems.physics.worker&&(this.data.body1=this.data.body1||this.el)},pause(){clearTimeout(this._retry);let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;t&&(e[this._id]=null,t.postMessage("world joint "+this._id+" remove"),this._id=null)},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world joint "+this._id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],20:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("shape",{schema:{},play(){if(null!=this.id)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;for(this.body=this.el;this.body&&!this.body.matches("[body]");)this.body=this.body.parentElement;if(!this.body)return this._retry=setTimeout((()=>{this.play()}),256);this.bodyId=this.body.components.body.id;let e=this.body.components.body.shapes;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el;let s={};s.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(s.position),s.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(s.quaternion.multiply(o.conjugate().normalize()).normalize(),s.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":s.type="sphere",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":s.type="cylinder",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":s.type="box",s.size.set(parseFloat(this.el.getAttribute("width")||1),parseFloat(this.el.getAttribute("height")||1),parseFloat(this.el.getAttribute("depth")||1))}let n=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.size.multiply(n),s.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+i.stringifyParam(s))},pause(){if(clearTimeout(this._retry),!this.body)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;let e=this.body.components.body.shapes;t.postMessage("world body "+this.bodyId+" shape "+this.id+" remove"),e[this.id]=null,this.id=null},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.bodyId+" shape "+this.id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],21:[function(require,module,exports){AFRAME.registerComponent("script",{schema:{src:{type:"string"},call:{type:"string"},args:{type:"array"}},async update(oldData){if(this.data.src!==oldData.src){this.script&&(this.el.isPlaying&&this.script.pause?.(),this.script.remove?.()),this.script=null;let response=await fetch(this.data.src);if(response.status>=200&&response.status<300){if(this.script=eval(await await response.text()),this.script.el=this.el,this.script.events)for(let t in this.script.events)this.script.events[t]=this.script.events[t].bind(this.script)}else console.error("Could not load",this.data.src);this.script.init?.(),this.el.isPlaying&&this.script.play?.()}this.script&&this.data.call?.trim()&&(this.script[this.data.call.trim()](...this.data.args),this.el.setAttribute("script","call",""))},remove(){this.script&&this.script.remove?.(...arguments)},tick(){this.script&&this.script.tick?.(...arguments)},tock(){this.script&&this.script.tock?.(...arguments)},play(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.addEventListener(t,this.script.events[t]);this.script.play?.(...arguments)}},pause(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.removeEventListener(t,this.script.events[t]);this.script.pause?.(...arguments)}}})},{}],22:[function(t,e,s){AFRAME.registerComponent("trigger",{schema:{objects:{type:"string",default:"[camera]"}},init(){this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.objects)return this.refreshObjects();let t,e=THREE.Vector3.temp(),s=parseFloat(this.el.getAttribute("width")||1),i=parseFloat(this.el.getAttribute("height")||1),o=parseFloat(this.el.getAttribute("depth")||1),n=parseFloat(this.el.getAttribute("radius")||1);for(let a of this.objects){switch(a.object3D.localToWorld(e.set(0,0,0)),this.el.object3D.worldToLocal(e),this.el.tagName.toLowerCase()){case"a-sphere":t=e.length()=0){let t={trigger:this.el,object:a};this.el.emit("untrigger",t),a.emit("untrigger",t),this.triggered.splice(this.triggered.indexOf(a),1),this.triggered.length||this.el.removeState("triggered")}}},refreshObjects(){this.objects=this.objects||[],this.triggered=this.triggered||[],this.objects.splice(0,this.objects.length);let t=this.el.sceneEl.querySelectorAll(this.data.objects);if(t){t.forEach((t=>{this.objects.push(t)}));for(let t=0;t=0)return t;return(t+", ").replaceAll(","," *,")+t}AFRAME.components.raycaster.Component.prototype.update=function(){return this._matchSelector=this.data.objects,this.data.objects=n(this.data.objects),i.apply(this,arguments)},AFRAME.components.raycaster.Component.prototype.refreshObjects=function(){let t=o.apply(this,arguments),e=this.intersections;for(let t of e)for(t.el=t.object.el;t.el&&!t.el.matches(this._matchSelector);)t.el=t.el.parentNode;return t}},{}],24:[function(t,e,s){e.exports={parse(t){let e=t.split(" "),s=[];for(let t of e)if(t)try{s.push(JSON.parse(t))}catch(e){"="!==t&&s.push(t)}return s},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],25:[function(t,e,s){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),s=t.object3D,i=this.object3D;s&&i&&i.parent&&(s.localToWorld(i.position.set(0,0,0)),i.parent.worldToLocal(i.position),i.getWorldQuaternion(e),i.quaternion.multiply(e.conjugate().normalize()),s.getWorldQuaternion(e),i.quaternion.multiply(e.normalize()))}},{}],26:[function(t,e,s){Element.prototype.ensure=function(t,e=t,s={},i=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),s)a=s[n],o.setAttribute(n,a);o.innerHTML=i}return o}},{}],27:[function(t,e,s){function i(t){t._pool=[],t._inUse=[],t.temp=function(){let e=t._pool.pop()||new t;return t._inUse.push(e),t._gc||(t._gc=setTimeout(t._recycle)),e},t._recycle=function(){for(;t._inUse.length;)t._pool.push(t._inUse.pop());t._gc=!1}}i(THREE.Vector2),i(THREE.Vector3),i(THREE.Quaternion),i(THREE.Matrix3),i(THREE.Matrix4)},{}],28:[function(t,e,s){let i=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,s,i,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,s)=>{if(t._tgest.handlers[e])for(let i of t._tgest.handlers[e])i(s);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,s=t.changedTouches[0].screenY,o=!1,i=setTimeout((()=>{o=!0,n("hold",t)}),512)})),t.addEventListener("touchmove",(t=>{let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))>32){if(clearTimeout(i),o)return;Math.abs(e-a)>Math.abs(s-r)?n(a{clearTimeout(i);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))<32){if(o)return;n("tap",t)}})),t._tgest};Element.prototype.addEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":n(this).handlers[t].push(e);break;default:return i.call(this,t,e)}},Element.prototype.removeEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":let s=n(this),i=s.handlers[t].indexOf(e);i>=0&&s.handlers[t].splice(i,1);break;default:return o.call(this,t,e)}}},{}],29:[function(t,e,s){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],30:[function(t,e,s){AFRAME.registerPrimitive("a-main",{})},{}],31:[function(t,e,s){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,s,i){function o(a,r){if(!s[a]){if(!e[a]){var h="function"==typeof require&&require;if(!r&&h)return h(a,!0);if(n)return n(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=s[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,s,i)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;a dist/#{name}.min.js"',bump:"npm version minor --no-git-tag-version",gitadd:"git add package*.json dist/*.js"},"pre-commit":["bump","build","gitadd"],keywords:["aframe","aframe-component","webvr","webxr","gamedev"],author:"poeticAndroid",license:"MIT",devDependencies:{browserify:"^17.0.0","foreach-cli":"^1.8.1",minify:"^7.0.2","pre-commit":"^1.2.2",watchify:"^4.0.0"}}},{}],2:[function(t,e,s){t("./libs/pools"),t("./libs/copyWorldPosRot"),t("./libs/ensureElement"),t("./libs/touchGestures"),t("./libs/betterRaycaster"),setTimeout((()=>{document.body.addEventListener("swipeup",(t=>{document.body.requestFullscreen()}))})),t("./components/grabbing"),t("./components/include"),t("./components/injectplayer"),t("./components/locomotion"),t("./components/onevent"),t("./components/onstate"),t("./components/physics"),t("./components/script"),t("./components/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const i=t("../package");console.log(`${i.title} Version ${i.version} by ${i.author}\n(${i.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":9,"./components/injectplayer":10,"./components/locomotion":11,"./components/onevent":15,"./components/onstate":16,"./components/physics":17,"./components/script":21,"./components/trigger":22,"./libs/betterRaycaster":23,"./libs/copyWorldPosRot":25,"./libs/ensureElement":26,"./libs/pools":27,"./libs/touchGestures":28,"./primitives/a-hand":29,"./primitives/a-main":30,"./primitives/a-player":31}],3:[function(t,e,s){AFRAME.registerComponent("grabbing",{schema:{hideOnGrab:{type:"boolean",default:!0},grabDistance:{type:"number",default:1}},init(){this._enableHands=this._enableHands.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onWheel=this._onWheel.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchTap=this._onTouchTap.bind(this),this._onTouchHold=this._onTouchHold.bind(this),this._btnPress={},this._btnFlex={},this._keysDown={},this._grabCount=0,this._hands=["head","left","right"],this._head={},this._left={},this._right={},this._head.hand=this.el.querySelector("a-camera"),this._left.hand=this.el.querySelector('a-hand[side="left"]'),this._right.hand=this.el.querySelector('a-hand[side="right"]'),this._head.glove=this._head.hand.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._left.glove=this._ensureGlove(this._left.hand),this._right.glove=this._ensureGlove(this._right.hand),this._left.glove.setAttribute("visible",!1),this._right.glove.setAttribute("visible",!1);for(let t of this._hands){this["_"+t].hand.addEventListener("buttonchanged",this._enableHands)}this._head.ray=this._head.hand.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._head.buttonRay=this._head.hand.ensure(".button.ray","a-entity",{class:"button ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [button]",far:1,autoRefresh:!1}}),this._head.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,position:"0 0 -1"},''),this._head.buttonReticle=this._head.buttonRay.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,color:"black",position:"0 0 -1"},''),this._head.anchor=this._head.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:!1,body:"type:kinematic;autoShape:false;"})},update(t){for(let t of this._hands){let e="_"+t;this[e].ray&&this[e].ray.setAttribute("raycaster","far",this.data.grabDistance+("head"===t?1:.1875))}},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.addEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.addEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.addEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.addEventListener("hold",this._onTouchHold)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp),this.el.sceneEl.canvas.removeEventListener("wheel",this._onWheel);for(let t of[this._left.hand,this._right.hand])t.removeEventListener("buttonchanged",this._onButtonChanged);this.el.sceneEl.canvas.removeEventListener("tap",this._onTouchTap),this.el.sceneEl.canvas.removeEventListener("hold",this._onTouchHold)},remove(){for(let t of this._hands){let e="_"+t;this.drop(t),this[e].glove.copyWorldPosRot(this[e].hand);let s=.25;for(let i=0;i<5;i++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:i,flex:s})}},tick(t,e){for(i=0,len=navigator.getGamepads().length;i{this.sticky=!1,this._flexFinger(t,5,.5)}),256)}},drop(t="head"){let e="_"+t;this.sticky||(this[e].anchor.removeAttribute("animation__rot"),this[e].anchor.removeAttribute("animation__pos"),this[e].glove.setAttribute("visible",!0),setTimeout((()=>{this[e].anchor.removeAttribute("joint__grab"),this[e].anchor.setAttribute("position","0 0 0"),this[e].anchor.setAttribute("rotation","0 0 0")}),32),setTimeout((()=>{this[e].glove.setAttribute("body","collidesWith",1)}),1024),this[e].grabbed&&(this.emit("drop",this[e].glove,this[e].grabbed),this._grabCount=Math.max(0,this._grabCount-1),this._grabCount||this.el.removeState("grabbing"),this._flexFinger(t,5,0),this[e].grabbed.removeState("grabbed"),this[e].grabbed=null))},dropObject(t){for(let e of this._hands){this["_"+e].grabbed===t&&this.drop(e)}},use(t="head",e=0){this.useDown(t,e),setTimeout((()=>{this.useUp(t,e)}),32)},useDown(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("usedown",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastButton&&(this[s]._lastClick=this[s]._lastButton,this.emit("press",this[s].glove,this[s]._lastClick,{button:e}),this[s]._lastClick.addState("pressed"))},useUp(t="head",e=0){let s="_"+t;this[s].grabbed?this.emit("useup",this[s].glove,this[s].grabbed,{button:e}):this[s]._lastClick&&(this.emit("unpress",this[s].glove,this[s]._lastClick),this[s]._lastClick.removeState("pressed"),this[s]._lastClick=null)},moveHeadHand(t=0,e=0,s=0,i=0){this._head.anchor.object3D.position.z=Math.min(Math.max(-1.5,this._head.anchor.object3D.position.z+t),-.125);let o=THREE.Quaternion.temp().set(e,s,i,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,s,i={}){i.grabbing=this.el,i.grabbedElement=s,i.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(i.hand=t);e.emit(t,i),s&&s.emit(t,i)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let s=.0625;if(this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:s/2,height:s,depth:2*s}),this[e].glove.setAttribute("body","type:kinematic;"),"head"===t)continue;this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}});let i=this[e].glove.querySelector(".palm")||this[e].glove;this[e].ray=i.ensure(".grabbing.ray","a-entity",{class:"grabbing ray",position:"left"===t?"-0.0625 0 0.0625":"0.0625 0 0.0625",rotation:"left"===t?"0 -45 0":"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this[e].buttonRay=i.ensure(".button.ray","a-entity",{class:"button ray",position:"0 0.03125 0",rotation:"left"===t?"0 -8 0":"0 8 0",raycaster:{objects:"[wall], [button]",far:.5,autoRefresh:!1}}),this[e].anchor=this[e].ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this[e].glove.setAttribute("visible",!0)}this._head.ray=null,this._head.buttonRay=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),s=t.getAttribute("color")||"lightblue";return t.ensure(".glove","a-entity",{class:"glove",fingerflex:{min:"left"===e?-10:10,max:"left"===e?-90:90}},`\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n `)},_flexFinger(t,e,s){let i="_"+t;if(e<5)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s});else for(e-=5;e<5;e++)this.emit("fingerflex",this[i].glove,this[i].grabbed,{hand:t,finger:e,flex:s})},_onKeyDown(t){this._keysDown[t.code]=!0,"e"===t.key&&this.toggleGrab()},_onKeyUp(t){this._keysDown[t.code]=!1},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_onWheel(t){let e=0,s=0,i=0;return this._keysDown.Digit3&&t.deltaY>0&&(i+=-.125),this._keysDown.Digit3&&t.deltaY<0&&(i+=.125),this._keysDown.Digit2&&t.deltaY>0&&(s+=-.125),this._keysDown.Digit2&&t.deltaY<0&&(s+=.125),this._keysDown.Digit1&&t.deltaY>0&&(e+=.125),this._keysDown.Digit1&&t.deltaY<0&&(e+=-.125),e||s||i?this.moveHeadHand(0,e,s,i):t.deltaY>0?this.moveHeadHand(.125):t.deltaY<0?this.moveHeadHand(-.125):void 0},_onMouseUp(t){let e=t.button;this.useUp("head",e?e%2?e+1:e-1:e)},_onTouchTap(t){this.use()},_onTouchHold(t){this.toggleGrab()},_onButtonChanged(t){let e=t.srcElement.getAttribute("tracked-controls").hand,s="_"+e,i=-1,o=0;switch(t.detail.state.touched&&(o=.5),t.detail.state.pressed&&(o=1),t.detail.state.value&&(o=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=o,t.detail.id){case 0:i=1,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e);break;case 1:i=7,t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.grab(e),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.drop(e);break;case 3:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,1),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,1);break;case 5:i=0,o=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0),t.detail.state.pressed&&!this._btnPress[e+t.detail.id]&&this.useDown(e,2),!t.detail.state.pressed&&this._btnPress[e+t.detail.id]&&this.useUp(e,2)}this._btnPress[e+t.detail.id]=t.detail.state.pressed,(this.sticky||this[s]._lastButton)&&0!==i||this._flexFinger(e,i,o)}}),t("./grabbing/button"),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/button":4,"./grabbing/climbable":5,"./grabbing/fingerflex":6,"./grabbing/grabbable":7,"./grabbing/receptacle":8}],4:[function(t,e,s){AFRAME.registerComponent("button",{schema:{}})},{}],5:[function(t,e,s){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion]"),this._onBump=this._onBump.bind(this),this._onBumpThis=this._onBumpThis.bind(this),this._autoGrab=!0,setTimeout((()=>{this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._quat.copy(this.el.object3D.quaternion),this._lpos.copy(this.el.object3D.position),this.el.object3D.getWorldPosition(this._wpos),this._top=parseFloat(this.el.getAttribute("height")||1)/2+2}),256)},play(){this._player.addEventListener("bump",this._onBump),this.el.addEventListener("bump",this._onBumpThis)},pause(){this._player.removeEventListener("bump",this._onBump),this.el.removeEventListener("bump",this._onBumpThis),this._climbing=!1},tick(){if(!this._lpos)return;if(this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos),!this._climbing)return;let t=THREE.Vector3.temp();this._hand.object3D.getWorldPosition(t),t.sub(this._handpos).multiplyScalar(-1),"head"===this._handName&&(t.y=0,t.y=t.length(),this._handpos.y+=t.y),this._player.components.locomotion.stopFall(),this._player.components.locomotion.move(t),this._handpos.y-this._wpos.y>this._top&&this._player.components.grabbing.dropObject(this.el)},events:{grab(t){this._climbing=!0,this._handName=t.detail.hand,this._hand=t.detail.gloveElement.parentNode,this._hand.object3D.getWorldPosition(this._handpos),t.detail.intersection.distance>("head"===this._handName?.5:.25)?setTimeout(this._onBump,260):this._player.components.locomotion.jump(),clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.copy(this._player.components.locomotion.headPos)}),1024)},drop(t){this._climbing=!1,clearTimeout(this._autoCrouchTO),this._autoCrouchTO=setTimeout((()=>{this._player.components.locomotion.toggleCrouch(!0),this._autoCrouchTO=setTimeout((()=>{this.el.sceneEl.querySelector(".legs")?.object3D.position.add(this._player.components.locomotion.centerPos).sub(this._player.components.locomotion.feetPos)}),512)}),256)}},_onBump(t){this._autoGrab||(this._player.components.grabbing.dropObject(this.el),clearTimeout(this._autoGrabTO),this._autoGrabTO=setTimeout((()=>{this._autoGrab=!0}),4096))},_onBumpThis(t){this._autoGrab&&(this._player.components.grabbing.grab(),this._autoGrab=!1)}})},{}],6:[function(t,e,s){AFRAME.registerComponent("fingerflex",{schema:{min:{type:"number",default:10},max:{type:"number",default:90}},init(){this._fingers=["thumb","index","middle","ring","little"],this._currentFlex=[0,0,0,0,0],this._targetFlex=[0,0,0,0,0]},tick(t,e){for(let t=0;t<5;t++){let e=this._fingers[t],s=this._currentFlex[t],i=this._targetFlex[t];s+=Math.random()*Math.random()*(i-s);let o=this.data.min+s*(this.data.max-this.data.min),n=this.el.querySelector(".bend."+e);for(;n;){let t=n.getAttribute("rotation");t.y=o,n.setAttribute("rotation",t),n=n.querySelector(".bend")}this._currentFlex[t]=s}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],7:[function(t,e,s){AFRAME.registerComponent("grabbable",{schema:{physics:{type:"boolean",default:!0},kinematicGrab:{type:"boolean",default:!0},fixed:{type:"boolean",default:!1},fixedPosition:{type:"vec3",default:{x:0,y:0,z:0}}},init(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:dynamic;")},events:{grab(){this.data.kinematicGrab&&this.el.setAttribute("body","type","kinematic")},drop(){this.data.physics&&this.el.setAttribute("body","type","dynamic")}}})},{}],8:[function(t,e,s){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125},onlyGrabbed:{type:"boolean",default:!1}},init(){this._anchor=this.el.ensure(".receptacle.anchor","a-entity",{class:"receptacle anchor",body:"type:kinematic;autoShape:false;"}),this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.nearest)return this.refreshObjects();let t=THREE.Vector3.temp(),e=THREE.Vector3.temp();this.el.object3D.localToWorld(t.set(0,0,0)),this.nearest.object3D.localToWorld(e.set(0,0,0)),e.sub(t),this._lastNearest&&this._lastNearest!==this.nearest?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this._lastNearest.removeState("put"),this.el.emit("take",{grabbable:this._lastNearest}),this._lastNearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this._lastNearest}),this._lastNearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):e.length()>this.data.radius?(this.el.is("filled")&&(this._anchor.removeAttribute("joint__put"),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this.el.removeState("filled"),this.nearest.removeState("put"),this.el.emit("take",{grabbable:this.nearest}),this.nearest.emit("take",{receptacle:this.el})),this._hover&&(this.el.emit("unhover",{grabbable:this.nearest}),this.nearest.emit("unhover",{receptacle:this.el})),this._hover=!1,this._grabbed=!1):this.nearest.is("grabbed")||!this._hover?(this._hover||(this.el.emit("hover",{grabbable:this.nearest}),this.nearest.emit("hover",{receptacle:this.el})),this._anchor.removeAttribute("animation__pos"),this._anchor.removeAttribute("animation__rot"),this._anchor.copyWorldPosRot(this.nearest),this._hover=!0,this.nearest.is("grabbed")&&(this._grabbed=!0)):!this._grabbed&&this.data.onlyGrabbed||(this.el.is("filled")||(this._anchor.copyWorldPosRot(this.nearest),this._anchor.components.body.commit(),this.nearest.components.body&&this._anchor.setAttribute("joint__put",{body2:this.nearest,type:"lock"}),this.el.addState("filled"),this.nearest.addState("put"),this.el.emit("put",{grabbable:this.nearest}),this.nearest.emit("put",{receptacle:this.el})),this._anchor.getAttribute("animation__pos")||(this._anchor.setAttribute("animation__pos",{property:"position",to:{x:0,y:0,z:0},dur:256}),this._anchor.setAttribute("animation__rot",{property:"rotation",to:{x:0,y:0,z:0},dur:256})),this.nearest.copyWorldPosRot(this._anchor),this._hover=!0),this._lastNearest=this.nearest},refreshObjects(){let t=1/0,e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Vector3.temp(),o=this.el.sceneEl.querySelectorAll(this.data.objects);this.nearest=null,o&&(this.el.object3D.localToWorld(e.set(0,0,0)),o.forEach((o=>{o.object3D.localToWorld(s.set(0,0,0)),i.copy(s).sub(e),t>i.length()&&(t=i.length(),this.nearest=o)})))}})},{}],9:[function(t,e,s){AFRAME.registerComponent("include",{schema:{type:"string"},async init(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),s=t.indexOf(" include="),i=t.substr(e,s-e);e=t.indexOf('"',s+10)+1,s=t.indexOf(">"),i+=t.substr(e,s-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+i+" "):this.el.removeAttribute("include"),this.el.sceneEl._including_=!1;let n=this.el.sceneEl.querySelector("[include]");n&&n.components&&n.components.include&&n.components.include.init()}}})},{}],10:[function(t,e,s){AFRAME.registerComponent("injectplayer",{init(){this.el.ensure("a-camera","a-camera",{"look-controls":{pointerLockEnabled:!0,touchEnabled:!1},"wasd-controls":{enabled:!1}}),this.el.ensure('a-hand[side="left"]',"a-hand",{side:"left"}),this.el.ensure('a-hand[side="right"]',"a-hand",{side:"right"})}})},{}],11:[function(t,e,s){AFRAME.registerComponent("locomotion",{dependencies:["position","injectplayer"],schema:{speed:{type:"number",default:4},stepLength:{type:"number",default:1},rotationSpeed:{type:"number",default:1},teleportDistance:{type:"number",default:5},jumpForce:{type:"number",default:4},gravity:{type:"number",default:10},godMode:{type:"boolean",default:!1}},init(){this._onKeyDown=this._onKeyDown.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onAxisMove=this._onAxisMove.bind(this),this._onButtonChanged=this._onButtonChanged.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onEnterVR=this._onEnterVR.bind(this),this._onExitVR=this._onExitVR.bind(this),this._keysDown={},this._kbStick=new THREE.Vector2,this._axes=[0,0,0,0],this._leftTouchCenter=new THREE.Vector2,this._leftTouchDir=new THREE.Vector2,this._rightTouchCenter=new THREE.Vector2,this._rightTouchDir=new THREE.Vector2,this._teleporting=!0,this._bumpOverload=0,this._vertVelocity=1,this.currentFloorPosition=new THREE.Vector3,this.centerPos=new THREE.Vector3,this.headPos=new THREE.Vector3,this.headDir=new THREE.Vector3,this.feetPos=new THREE.Vector3,this.lastStep=new THREE.Vector3,this._config={quantizeMovement:!1,quantizeRotation:!1,quantizeMovementVR:!!this.el.sceneEl.isMobile,quantizeRotationVR:!0},this.el.sceneEl.is("vr-mode")?this._onEnterVR():this._onExitVR(),this._camera=this.el.querySelector("a-camera"),this._leftHand=this.el.querySelector('a-hand[side="left"]'),this._rightHand=this.el.querySelector('a-hand[side="right"]'),this._legs=this.el.sceneEl.ensure(".legs","a-entity",{class:"legs",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[floor]",direction:"0 -1 0",far:.625}}),this._legBumper=this.el.sceneEl.ensure(".leg-bumper","a-entity",{class:"leg-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._headBumper=this.el.sceneEl.ensure(".head-bumper","a-entity",{class:"head-bumper",position:"0 0.5 0",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportBeam=this._camera.ensure(".teleport-ray","a-entity",{class:"teleport-ray",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._teleportCursor=this.el.ensure(".teleport-cursor","a-cylinder",{class:"teleport-cursor",radius:.5,height:.0625,material:"opacity:0.5;"}),this._teleportCursor.setAttribute("visible",!1)},update(t){this._godMode=this.data.godMode},play(){document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._leftHand.addEventListener("axismove",this._onAxisMove),this._rightHand.addEventListener("axismove",this._onAxisMove),this._leftHand.addEventListener("buttonchanged",this._onButtonChanged),this._rightHand.addEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.addEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.addEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.addEventListener("touchend",this._onTouchEnd),this.el.sceneEl.addEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.addEventListener("exit-vr",this._onExitVR)},pause(){document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),this._leftHand.removeEventListener("axismove",this._onAxisMove),this._rightHand.removeEventListener("axismove",this._onAxisMove),this._leftHand.removeEventListener("buttonchanged",this._onButtonChanged),this._rightHand.removeEventListener("buttonchanged",this._onButtonChanged),this.el.sceneEl.canvas.removeEventListener("touchstart",this._onTouchStart),this.el.sceneEl.canvas.removeEventListener("touchmove",this._onTouchMove),this.el.sceneEl.canvas.removeEventListener("touchend",this._onTouchEnd),this.el.sceneEl.removeEventListener("enter-vr",this._onEnterVR),this.el.sceneEl.removeEventListener("exit-vr",this._onExitVR)},remove(){this.el.sceneEl.removeChild(this._legs),this.el.sceneEl.removeChild(this._legBumper),this.el.sceneEl.removeChild(this._headBumper)},tick(t,e){e/=1e3,this.el.object3D.localToWorld(this.centerPos.set(0,0,0)),this.headPos.copy(this._camera.object3D.position),this._camera.object3D.parent.localToWorld(this.headPos),this.headDir.set(0,0,-1).applyQuaternion(this._camera.object3D.quaternion).applyQuaternion(this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp())),this._legs.object3D.localToWorld(this.feetPos.set(0,0,0)),this.feetPos.y-=.5,this._applyButtons(e),this._applyMoveStick(e),this._applyAuxStick(e);let s=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(s.y=0,(s.length()>.5||!this.currentFloor)&&(this.currentFloor&&s.multiplyScalar(.1),this._legs.object3D.position.add(s),this.feetPos.add(s)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let s=t.intersections[0];if(s&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===s.el){let t=THREE.Vector3.temp();t.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition),this.move(t),this.lastStep.add(t),t.y=0,this._legs.object3D.position.add(t)}else this.currentFloor&&this.currentFloor.emit("leave"),s.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-s.distance,0)),this.currentFloor=s.el,this.currentFloorPosition.copy(this.currentFloor.object3D.position)}else this.currentFloor&&this.currentFloor.emit("leave"),this._vertVelocity-=this.data.gravity*e,this.move(THREE.Vector3.temp().set(0,Math.max(-.5,this._vertVelocity*e),0)),this.currentFloor=null}if(this._godMode)this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position);else if(this._bumpOverload>4||Math.abs(this.headPos.y-this.feetPos.y)>3)this.feetPos.y=this.centerPos.y,this._legs.object3D.position.y=this.feetPos.y+.5,this.teleport(this._legBumper.object3D.position,!0),this._bumpOverload&&this._bumpOverload--;else{let t=THREE.Vector3.temp();t.copy(this.feetPos).y+=.5,this._bump(t,this._legBumper),t.copy(this.headPos),this._bump(t,this._headBumper)}let i=THREE.Vector3.temp();if(i.copy(this.feetPos).sub(this.lastStep),i.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));i.length()>this.data.stepLength;)i.multiplyScalar(this.data.stepLength/i.length()),this.lastStep.add(i),i.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let s=THREE.Vector3.temp();s.copy(t).sub(this.feetPos),this.move(s),this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._caution=8,e&&(this._legBumper.object3D.position.copy(this._legs.object3D.position),this._headBumper.object3D.position.copy(this._legs.object3D.position))},jump(){this.currentFloor&&(this._vertVelocity=this.data.jumpForce)},stopFall(){this._legs.object3D.position.x=this.feetPos.x=this.headPos.x,this._legs.object3D.position.z=this.feetPos.z=this.headPos.z,this._vertVelocity=Math.max(this._vertVelocity,0)},toggleCrouch(t){let e,s=this.headPos.y-this.feetPos.y;clearTimeout(this._crouchResetTO),this._crouchResetTO=null,Math.abs(this.centerPos.y-this.feetPos.y)>.03125?e=this.feetPos.y-this.centerPos.y:t||(e=s>1?-1:1),this.el.removeAttribute("animation"),e&&this.el.setAttribute("animation",{property:"object3D.position.y",to:this.el.object3D.position.y+e,dur:256})},move(t){this.el.object3D.position.add(t),this.centerPos.add(t),this.headPos.add(t),this._legs.object3D.position.y+=t.y,this.feetPos.y+=t.y},_bump(t,e){let s=THREE.Matrix3.temp(),i=THREE.Vector3.temp();i.copy(t),i.sub(e.object3D.position);let o=i.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${i.x} ${i.y} ${i.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),s.getNormalMatrix(a.el.object3D.matrixWorld),i.copy(a.face.normal).applyMatrix3(s).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(i),e.object3D.position.add(i),this._legs.object3D.position.y!==t&&(e===this._headBumper&&this._headBumper.object3D.position.copy(this._legBumper.object3D.position),clearTimeout(this._crouchResetTO),this._crouchResetTO=setTimeout((()=>{this.toggleCrouch(!0)}),4096)),this._legs.object3D.position.add(i),this._legs.object3D.position.y=Math.max(t,this.headPos.y-1.5),this._caution=4,this._bumpOverload++,this._vertVelocity=Math.min(0,this._vertVelocity);let n={player:this.el,object:a.el};this.el.emit("bump",n),a.el.emit("bump",n)}else this._caution?this._caution--:(this._bumpOverload&&this._bumpOverload--,e.object3D.position.lerp(t,.25))}},_callMoveStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.KeyA&&e.x--,this._keysDown.KeyD&&e.x++,(this._keysDown.KeyW||this._keysDown.ArrowUp)&&e.y--,(this._keysDown.KeyS||this._keysDown.ArrowDown)&&e.y++,this._kbStick.length()>.1?this._kbStick.multiplyScalar((this._kbStick.length()-.1)/this._kbStick.length()):this._kbStick.set(0,0),this._kbStick.add(e.multiplyScalar(.2)),this._kbStick.length()>1&&this._kbStick.normalize(),this._kbStick.length()>t.length()&&t.copy(this._kbStick),this._deadZone(e.set(this._axes[0],this._axes[1])),e.length()>t.length()&&t.copy(e),e.copy(this._leftTouchDir),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyMoveStick(t){let e=this._callMoveStick();e.multiplyScalar(this.data.speed),e.multiplyScalar(t);let s=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,i=Math.cos(s)*e.x-Math.sin(s)*e.y,o=Math.sin(s)*e.x+Math.cos(s)*e.y,n=THREE.Vector3.temp().set(i,0,o);this.quantizeMovement&&(this._quantTime=this._quantTime||0,this._quantDelta=this._quantDelta||new THREE.Vector3,this._quantTime+=t,this._quantDelta.add(n),this._quantTime>.25?(this._quantTime-=.25,n.copy(this._quantDelta),this._quantDelta.set(0,0,0)):n.set(0,0,0)),this.move(n)},_callAuxStick(){let t=THREE.Vector2.temp().set(0,0),e=THREE.Vector2.temp();for(e.set(0,0),this._keysDown.ArrowLeft&&e.x--,this._keysDown.ArrowRight&&e.x++,this._keysDown.KeyQ&&e.y--,this._keysDown.KeyC&&e.y++,e.length()>t.length()&&t.copy(e),this._fourWay(this._deadZone(e.set(this._axes[2],this._axes[3]))),e.length()>t.length()&&t.copy(e),this._fourWay(e.copy(this._rightTouchDir)),e.length()>t.length()&&t.copy(e),i=0,len=navigator.getGamepads().length;it.length()&&t.copy(e));return t.length()>1&&t.normalize(),(this._keysDown.ShiftLeft||this._keysDown.ShiftRight)&&t.multiplyScalar(.25),t},_applyAuxStick(t){let e=this._callAuxStick(),s=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,s=-Math.round(e.x)*Math.PI/4):this._rotating=!1:s=-e.x*this.data.rotationSpeed*t,s){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),i=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-s),i.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(s),this.el.object3D.position.add(i),this.centerPos.add(i)}if(this._godMode)this.el.object3D.position.y+=-e.y*this.data.speed*t,this._legs.object3D.position.y+=-e.y*this.data.speed*t;else if(Math.round(e.y)>0?this._crouching||(this._crouching=!0,this.toggleCrouch()):this._crouching=!1,Math.round(e.y)<0){!this._teleporting&&this.data.teleportDistance&&(this._teleportCursor.setAttribute("visible",!0),this._teleporting=!0);let t=THREE.Quaternion.temp();if(this._teleportCursor.object3D.getWorldQuaternion(t),this._teleportCursor.object3D.quaternion.multiply(t.conjugate().normalize()).multiply(t.copy(this.el.object3D.quaternion).multiply(this._camera.object3D.quaternion)),this._teleportCursor.object3D.quaternion.x=0,this._teleportCursor.object3D.quaternion.z=0,this._teleportCursor.object3D.quaternion.normalize(),ray=this._teleportBeam.components.raycaster,ray.refreshObjects(),hit=ray.intersections[0],hit&&null!=hit.el.getAttribute("floor")){let e=THREE.Vector3.temp(),s=THREE.Vector3.temp(),i=THREE.Matrix3.temp();s.copy(hit.point).sub(this.feetPos),s.y>1.5&&s.multiplyScalar(0),s.length()>this.data.teleportDistance&&s.normalize().multiplyScalar(this.data.teleportDistance),s.add(this.feetPos),this._teleportCursor.object3D.position.copy(s),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),i.getNormalMatrix(hit.el.object3D.matrixWorld),s.copy(hit.face.normal).applyMatrix3(i).normalize(),s.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,s),this._teleportCursor.object3D.quaternion.premultiply(t)}else this._teleportCursor.object3D.position.copy(this.feetPos),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position)}else if(this._teleporting){let t=THREE.Vector3.temp();this._teleportCursor.object3D.localToWorld(t.set(0,0,0)),this.teleport(t),this._teleportCursor.setAttribute("visible",!1),this._teleportCursor.setAttribute("position","0 0 0"),this._teleporting=!1}},_callButtons(){let t=0;for(this._keysDown.Space&&(t|=1),this._keysDown.KeyG&&(t|=2),this._vrRightClick&&(t|=1),this._vrLeftClick&&(t|=2),i=0,len=navigator.getGamepads().length;i(t.length()>e?t.multiplyScalar((t.length()-e)/(1-e)/t.length()):t.set(0,0),t),_fourWay(t){let e=t.length();return Math.abs(t.x)>Math.abs(t.y)?t.y=0:t.x=0,t.multiplyScalar(e/t.length()),t},_onKeyDown(t){this._keysDown[t.code]=!0},_onKeyUp(t){this._keysDown[t.code]=!1},_onAxisMove(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?(this._axes[0]=t.detail.axis[2],this._axes[1]=t.detail.axis[3]):(this._axes[2]=t.detail.axis[2],this._axes[3]=t.detail.axis[3]),this._handEnabled||(this._teleportBeam.parentElement.removeChild(this._teleportBeam),this._teleportBeam=this._rightHand.ensure(".teleportBeam","a-entity",{class:"teleportBeam",raycaster:{autoRefresh:!1,objects:"[wall]"}}),this._handEnabled=!0)},_onButtonChanged(t){"left"===t.srcElement.getAttribute("tracked-controls").hand?3==t.detail.id&&(this._vrLeftClick=t.detail.state.pressed):3==t.detail.id&&(this._vrRightClick=t.detail.state.pressed)},_onTouchStart(t){let e=this.el.sceneEl.canvas.clientWidth;for(let s=0;se/2&&(this._rightTouchId=i.identifier,this._rightTouchCenter.set(i.clientX,i.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),i.add(o),o.multiplyScalar(32/o.length())),o.divideScalar(32))}t.preventDefault()},_onTouchEnd(t){for(let e=0;e{this.init()}),256);let e=new THREE.Vector3;setTimeout((()=>{this.el.object3D.localToWorld(e.set(0,0,0)),t.teleport(e,!0),setTimeout((()=>{t.toggleCrouch(!0)}),256)}),256)}})},{}],14:[function(t,e,s){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],15:[function(t,e,s){AFRAME.registerComponent("onevent",{multiple:!0,schema:{event:{type:"string"},entity:{type:"selector"},property:{type:"string"},value:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this.pause(),this._event=this.data.event||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._value=this.data.value||"",this.el.isPlaying&&this.play()},play(){this._event&&this.el.addEventListener(this._event,this.trigger)},pause(){this._event&&this.el.removeEventListener(this._event,this.trigger)},trigger(t){let e=this._property.split(".");e.push(this._value),this._entity.setAttribute(...e)}})},{}],16:[function(t,e,s){AFRAME.registerComponent("onstate",{multiple:!0,schema:{state:{type:"string"},entity:{type:"selector"},property:{type:"string"},on:{type:"string"},off:{type:"string"}},init(){this.trigger=this.trigger.bind(this)},update(t){this._state=this.data.state||this.id||"",this._entity=this.data.entity||this.el,this._property=this.data.property||"",this._on=this.data.on||"",this._off=this.data.off||""},play(){this.trigger(),this.el.addEventListener("stateadded",this.trigger),this.el.addEventListener("stateremoved",this.trigger)},pause(){this.el.removeEventListener("stateadded",this.trigger),this.el.removeEventListener("stateremoved",this.trigger)},trigger(t){if(t&&t.detail!==this._state)return;let e=this._property.split(".");e.push(this.el.is(this._state)?this._on:this._off),this._entity.setAttribute(...e)}})},{}],17:[function(t,e,s){const i=t("../libs/cmdCodec"),o=t("../../package");AFRAME.registerSystem("physics",{schema:{workerUrl:{type:"string",default:`https://cdn.jsdelivr.net/gh/poeticAndroid/a-game@v${o.version}/dist/cannonWorker.min.js`},gravity:{type:"vec3",default:{x:0,y:-10,z:0}},debug:{type:"boolean",default:!1}},update(){if(this.data.workerUrl){if(!this.worker){if(this.data.workerUrl.includes("//")){let t=`importScripts(${JSON.stringify(this.data.workerUrl)})`;this.worker=new Worker(`data:text/javascript;base64,${btoa(t)}`)}else this.worker=new Worker(this.data.workerUrl);this.worker.postMessage("log "+i.stringifyParam("Physics worker ready!")),this.worker.addEventListener("message",this.onMessage.bind(this))}this.bodies=this.bodies||[],this.movingBodies=this.movingBodies||[],this.joints=this.joints||[],this.buffers=[new Float64Array(8),new Float64Array(8)],this.worker.postMessage("world gravity = "+i.stringifyParam(this.data.gravity)),this._debug=this.data.debug}else this.remove()},remove(){this.worker&&this.worker.terminate(),this.worker=null,this.bodies=[],this.movingBodies=[]},tick(t,e){if(!this.worker)return;if(this.buffers.length<2)return;let s=this.buffers.shift();if(s.length<8*this.movingBodies.length){let t=s.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;s=new Float64Array(t),s.fill(NaN);let i=THREE.Vector3.temp(),o=THREE.Quaternion.temp();for(let t=0;t2;)this.buffers.shift()},command(t){switch("number"==typeof t[0]&&t.shift(),t.shift()){case"body":let e=t.shift(),s=this.bodies[e];s&&s.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+i.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":24,"./physics/body":18,"./physics/joint":19,"./physics/shape":20}],18:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("body",{dependencies:["position","rotation","scale"],schema:{type:{type:"string",default:"dynamic"},mass:{type:"number",default:1},friction:{type:"number",default:.3},restitution:{type:"number",default:.3},belongsTo:{type:"int",default:1},collidesWith:{type:"int",default:1},emitsWith:{type:"int",default:0},sleeping:{type:"boolean",default:!1},autoShape:{type:"boolean",default:!0}},init(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies,o=this.el.sceneEl.systems.physics.buffers[0];if(!t)return;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el,"static"!==this.data.type?(this.mid=s.indexOf(null),this.mid<0&&(this.mid=s.length),s[this.mid]=this.el):this.mid=null;let n={mid:this.mid};if(n.type=this.data.type,n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),null!==this.mid){let t=8*this.mid;o[t++]=n.position.x,o[t++]=n.position.y,o[t++]=n.position.z,o[t++]=this.data.sleeping,o[t++]=n.quaternion.x,o[t++]=n.quaternion.y,o[t++]=n.quaternion.z,o[t++]=n.quaternion.w}if(this.shapes=[],this.sleeping=!0,t.postMessage("world body "+this.id+" create "+i.stringifyParam(n)),setTimeout((()=>{n.position=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0)),n.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp()),t.postMessage("world body "+this.id+" position = "+i.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+i.stringifyParam(n.quaternion)),this.el.components.shape&&this.el.components.shape.play();let e=this.el.querySelectorAll("[shape]");e&&e.forEach((t=>{t.components.shape&&t.components.shape.play()})),this.el.components.joint&&this.el.components.joint.play();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].play()})),this.data.autoShape&&!this.el.getAttribute("shape"))if(this.el.firstElementChild){let t=this.el.querySelectorAll("a-box, a-sphere, a-cylinder");t&&t.forEach((t=>{t.getAttribute("shape")||t.setAttribute("shape",!0)}))}else this.el.setAttribute("shape",!0);this._initiated=!0},play(){this._initiated||(this.init(),this.update({}))},update(t){let e=this.el.sceneEl.systems.physics.worker;e&&(this.data.type!==t.type&&e.postMessage("world body "+this.id+" type = "+i.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+i.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+i.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+i.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+i.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+i.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+i.stringifyParam(this.data.emitsWith)),setTimeout((()=>{e.postMessage("world body "+this.id+" sleeping = "+!!this.data.sleeping)})))},sleep(){let t=this.el.sceneEl.systems.physics.worker;t&&(t.postMessage("world body "+this.id+" sleeping = true"),this.sleeping=!0)},pause(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.bodies,s=this.el.sceneEl.systems.physics.movingBodies;if(!t)return;this.el.components.joint&&this.el.components.joint.pause();for(let t in this.el.components)"joint__"===t.substr(0,7)&&this.el.components[t].pause();let i=this.el.querySelectorAll("[shape]");i&&i.forEach((t=>{t.components.shape&&t.components.shape.pause()})),this.el.components.shape&&this.el.components.shape.pause(),e[this.id]=null,null!==this.mid&&(s[this.mid]=null),t.postMessage("world body "+this.id+" remove"),this._initiated=!1},tick(){let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.buffers[0];if(t&&null!==this.mid){let t=8*this.mid;if(e.length<=t)return;if("kinematic"===this.data.type){let s=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,this.sleeping=!!e[t++];let i=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,e[t++]=i.w}else if(e[t+1]){let s=THREE.Quaternion.temp();this.el.object3D.position.set(e[t++],e[t++],e[t++]),this.el.object3D.parent.worldToLocal(this.el.object3D.position),this.sleeping=!!e[t++],this.el.object3D.getWorldQuaternion(s),this.el.object3D.quaternion.multiply(s.conjugate().normalize()),s.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(s.normalize())}}},command(t){switch(t.shift()){case"emits":let e=t.shift();switch(e.event){case"collision":let t=this.el.sceneEl.systems.physics.bodies;if(e.body1=t[e.body1],e.body2=t[e.body2],!e.body1||!e.body2)return;e.shape1=e.body1.components.body.shapes[e.shape1],e.shape2=e.body2.components.body.shapes[e.shape2]}this.el.emit(e.event,e)}},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.id+" eval "+i.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),s=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+i.stringifyParam(e)),this.el.object3D.getWorldQuaternion(s),t.postMessage("world body "+this.id+" quaternion "+i.stringifyParam(s))}})},{"../../libs/cmdCodec":24}],19:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("joint",{multiple:!0,schema:{type:{type:"string",default:"ball"},body1:{type:"selector"},body2:{type:"selector"},pivot1:{type:"vec3",default:{x:0,y:0,z:0}},pivot2:{type:"vec3",default:{x:0,y:0,z:0}},axis1:{type:"vec3",default:{x:0,y:1,z:0}},axis2:{type:"vec3",default:{x:0,y:1,z:0}},min:{type:"number",default:0},max:{type:"number",default:1},collision:{type:"boolean",default:!0}},play(){if(null!=this._id)return;let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;if(!t)return;if(!this.data.body1.components.body)return this._retry=setTimeout((()=>{this.play()}),256);if(!this.data.body2.components.body)return this._retry=setTimeout((()=>{this.play()}),256);this._id=e.indexOf(null),this._id<0&&(this._id=e.length),e[this._id]=this.el;let s={};s.type=this.data.type,s.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,s.body2=this.data.body2.components.body.id,s.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),s.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),s.axis1=this.data.axis1,s.axis2=this.data.axis2,s.min=this.data.min,s.max=this.data.max,s.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.pivot1.multiply(o),s.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+i.stringifyParam(s))},update(t){this.el.sceneEl.systems.physics.worker&&(this.data.body1=this.data.body1||this.el)},pause(){clearTimeout(this._retry);let t=this.el.sceneEl.systems.physics.worker,e=this.el.sceneEl.systems.physics.joints;t&&(e[this._id]=null,t.postMessage("world joint "+this._id+" remove"),this._id=null)},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world joint "+this._id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],20:[function(t,e,s){const i=t("../../libs/cmdCodec");AFRAME.registerComponent("shape",{schema:{},play(){if(null!=this.id)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;for(this.body=this.el;this.body&&!this.body.matches("[body]");)this.body=this.body.parentElement;if(!this.body)return this._retry=setTimeout((()=>{this.play()}),256);this.bodyId=this.body.components.body.id;let e=this.body.components.body.shapes;this.id=e.indexOf(null),this.id<0&&(this.id=e.length),e[this.id]=this.el;let s={};s.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(s.position),s.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(s.quaternion.multiply(o.conjugate().normalize()).normalize(),s.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":s.type="sphere",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":s.type="cylinder",s.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":s.type="box",s.size.set(parseFloat(this.el.getAttribute("width")||1),parseFloat(this.el.getAttribute("height")||1),parseFloat(this.el.getAttribute("depth")||1))}let n=this.el.object3D.getWorldScale(THREE.Vector3.temp());s.size.multiply(n),s.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+i.stringifyParam(s))},pause(){if(clearTimeout(this._retry),!this.body)return;let t=this.el.sceneEl.systems.physics.worker;if(!t)return;let e=this.body.components.body.shapes;t.postMessage("world body "+this.bodyId+" shape "+this.id+" remove"),e[this.id]=null,this.id=null},eval(t){this.el.sceneEl.systems.physics.worker.postMessage("world body "+this.bodyId+" shape "+this.id+" eval "+i.stringifyParam(t))}})},{"../../libs/cmdCodec":24}],21:[function(require,module,exports){AFRAME.registerComponent("script",{schema:{src:{type:"string"},call:{type:"string"},args:{type:"array"}},async update(oldData){if(this.data.src!==oldData.src){this.script&&(this.el.isPlaying&&this.script.pause?.(),this.script.remove?.()),this.script=null;let response=await fetch(this.data.src);if(response.status>=200&&response.status<300){if(this.script=eval(await await response.text()),this.script.el=this.el,this.script.events)for(let t in this.script.events)this.script.events[t]=this.script.events[t].bind(this.script)}else console.error("Could not load",this.data.src);this.script.init?.(),this.el.isPlaying&&this.script.play?.()}this.script&&this.data.call?.trim()&&(this.script[this.data.call.trim()](...this.data.args),this.el.setAttribute("script","call",""))},remove(){this.script&&this.script.remove?.(...arguments)},tick(){this.script&&this.script.tick?.(...arguments)},tock(){this.script&&this.script.tock?.(...arguments)},play(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.addEventListener(t,this.script.events[t]);this.script.play?.(...arguments)}},pause(){if(this.script){if(this.script.events)for(let t in this.script.events)this.el.removeEventListener(t,this.script.events[t]);this.script.pause?.(...arguments)}}})},{}],22:[function(t,e,s){AFRAME.registerComponent("trigger",{schema:{objects:{type:"string",default:"[camera]"}},init(){this._refreshTO=setInterval(this.refreshObjects.bind(this),1024)},remove(){clearInterval(this._refreshTO)},tick(){if(!this.objects)return this.refreshObjects();let t,e=THREE.Vector3.temp(),s=parseFloat(this.el.getAttribute("width")||1),i=parseFloat(this.el.getAttribute("height")||1),o=parseFloat(this.el.getAttribute("depth")||1),n=parseFloat(this.el.getAttribute("radius")||1);for(let a of this.objects){switch(a.object3D.localToWorld(e.set(0,0,0)),this.el.object3D.worldToLocal(e),this.el.tagName.toLowerCase()){case"a-sphere":t=e.length()=0){let t={trigger:this.el,object:a};this.el.emit("untrigger",t),a.emit("untrigger",t),this.triggered.splice(this.triggered.indexOf(a),1),this.triggered.length||this.el.removeState("triggered")}}},refreshObjects(){this.objects=this.objects||[],this.triggered=this.triggered||[],this.objects.splice(0,this.objects.length);let t=this.el.sceneEl.querySelectorAll(this.data.objects);if(t){t.forEach((t=>{this.objects.push(t)}));for(let t=0;t=0)return t;return(t+", ").replaceAll(","," *,")+t}AFRAME.components.raycaster.Component.prototype.update=function(){return this._matchSelector=this.data.objects,this.data.objects=n(this.data.objects),i.apply(this,arguments)},AFRAME.components.raycaster.Component.prototype.refreshObjects=function(){let t=o.apply(this,arguments),e=this.intersections;for(let t of e)for(t.el=t.object.el;t.el&&!t.el.matches(this._matchSelector);)t.el=t.el.parentNode;return t}},{}],24:[function(t,e,s){e.exports={parse(t){let e=t.split(" "),s=[];for(let t of e)if(t)try{s.push(JSON.parse(t))}catch(e){"="!==t&&s.push(t)}return s},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],25:[function(t,e,s){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),s=t.object3D,i=this.object3D;s&&i&&i.parent&&(s.localToWorld(i.position.set(0,0,0)),i.parent.worldToLocal(i.position),i.getWorldQuaternion(e),i.quaternion.multiply(e.conjugate().normalize()),s.getWorldQuaternion(e),i.quaternion.multiply(e.normalize()))}},{}],26:[function(t,e,s){Element.prototype.ensure=function(t,e=t,s={},i=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),s)a=s[n],o.setAttribute(n,a);o.innerHTML=i}return o}},{}],27:[function(t,e,s){function i(t){t._pool=[],t._inUse=[],t.temp=function(){let e=t._pool.pop()||new t;return t._inUse.push(e),t._gc||(t._gc=setTimeout(t._recycle)),e},t._recycle=function(){for(;t._inUse.length;)t._pool.push(t._inUse.pop());t._gc=!1}}i(THREE.Vector2),i(THREE.Vector3),i(THREE.Quaternion),i(THREE.Matrix3),i(THREE.Matrix4)},{}],28:[function(t,e,s){let i=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,s,i,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,s)=>{if(t._tgest.handlers[e])for(let i of t._tgest.handlers[e])i(s);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,s=t.changedTouches[0].screenY,o=!1,i=setTimeout((()=>{o=!0,n("hold",t)}),512)})),t.addEventListener("touchmove",(t=>{let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))>32){if(clearTimeout(i),o)return;Math.abs(e-a)>Math.abs(s-r)?n(a{clearTimeout(i);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(s-r,2))<32){if(o)return;n("tap",t)}})),t._tgest};Element.prototype.addEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":n(this).handlers[t].push(e);break;default:return i.call(this,t,e)}},Element.prototype.removeEventListener=function(t,e){switch(t){case"swipeup":case"swipedown":case"swipeleft":case"swiperight":case"tap":case"hold":let s=n(this),i=s.handlers[t].indexOf(e);i>=0&&s.handlers[t].splice(i,1);break;default:return o.call(this,t,e)}}},{}],29:[function(t,e,s){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],30:[function(t,e,s){AFRAME.registerPrimitive("a-main",{})},{}],31:[function(t,e,s){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 759e1fd..e73e665 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.17.3", + "version": "0.18.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f672dbc..a911c1c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.17.3", + "version": "0.18.0", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -10,7 +10,7 @@ "build": "foreach -g src/*.js -x \"browserify #{path} -o dist/#{name}.js\" && npm run minify", "watch": "foreach -g src/*.js -C -x \"watchify #{path} -d -o dist/#{name}.js\"", "minify": "touch dist/foo.min.js && rm dist/*.min.js && foreach -g dist/*.js -C -x \"minify #{path} > dist/#{name}.min.js\"", - "bump": "npm version patch --no-git-tag-version", + "bump": "npm version minor --no-git-tag-version", "gitadd": "git add package*.json dist/*.js" }, "pre-commit": [