From f7df6ac9ad8ef9c02298f85f12b019f8d3538183 Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Fri, 2 Jul 2021 03:47:34 +0200 Subject: [PATCH 1/9] head hitbox bugfix --- README.md | 2 +- dist/a-game.js | 13 +++++++------ dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 4 ++-- src/components/grabbing.js | 9 +++++---- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index d383968..4856257 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 471f9d9..0e2f942 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.14.0", + "version": "0.14.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": [ @@ -104,8 +104,7 @@ AFRAME.registerComponent("grabbing", { this[_hand].hand.addEventListener("buttonchanged", this._enableHands) } - this._head.glove.ensure(".hitbox", "a-sphere", { class: "hitbox", radius: 0.5 }) - this._head.glove.setAttribute("body", "type:kinematic;") + this._head.glove.ensure(".hitbox", "a-sphere", { class: "hitbox", body: "type:kinematic;", radius: 0.25 }) this._head.ray = this._head.glove.ensure(".grabbing-ray", "a-entity", { class: "grabbing-ray", position: "0 -0.125 0", raycaster: { @@ -299,7 +298,8 @@ AFRAME.registerComponent("grabbing", { } if (this.data.hideOnGrab) this[_hand].glove.setAttribute("visible", false) - this[_hand].glove.setAttribute("body", "collidesWith", 0) + if (this[_hand].glove.getAttribute("body")) + this[_hand].glove.setAttribute("body", "collidesWith", 0) this.emit("grab", this[_hand].glove, this[_hand].grabbed) this.el.addState("grabbing") this[_hand].grabbed.addState("grabbed") @@ -320,7 +320,8 @@ AFRAME.registerComponent("grabbing", { this[_hand].anchor.removeAttribute("joint__grab") }, 32) setTimeout(() => { - this[_hand].glove.setAttribute("body", "collidesWith", 1) + if (this[_hand].glove.getAttribute("body")) + this[_hand].glove.setAttribute("body", "collidesWith", 1) }, 1024) this.emit("drop", this[_hand].glove, this[_hand].grabbed) this.el.removeState("grabbing") diff --git a/dist/a-game.min.js b/dist/a-game.min.js index 8b49c9a..8b9fbcd 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.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._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,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.glove.ensure(".hitbox","a-sphere",{class:"hitbox",radius:.5}),this._head.glove.setAttribute("body","type:kinematic;"),this._head.ray=this._head.glove.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!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),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp);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),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp);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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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")}),32),setTimeout((()=>{this[e].glove.setAttribute("body","collidesWith",1)}),1024),this.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_onKeyDown(t){"e"===t.key&&this.toggleGrab()},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.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._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,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.glove.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._head.ray=this._head.glove.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!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),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp);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),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp);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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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")}),32),setTimeout((()=>{this[e].glove.getAttribute("body")&&this[e].glove.setAttribute("body","collidesWith",1)}),1024),this.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_onKeyDown(t){"e"===t.key&&this.toggleGrab()},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index d6e6b8c..2d7905d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.14.0", + "version": "0.14.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 47492e6..b8dc562 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.14.0", + "version": "0.14.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.js b/src/components/grabbing.js index fe963d5..216d946 100644 --- a/src/components/grabbing.js +++ b/src/components/grabbing.js @@ -36,8 +36,7 @@ AFRAME.registerComponent("grabbing", { this[_hand].hand.addEventListener("buttonchanged", this._enableHands) } - this._head.glove.ensure(".hitbox", "a-sphere", { class: "hitbox", radius: 0.5 }) - this._head.glove.setAttribute("body", "type:kinematic;") + this._head.glove.ensure(".hitbox", "a-sphere", { class: "hitbox", body: "type:kinematic;", radius: 0.25 }) this._head.ray = this._head.glove.ensure(".grabbing-ray", "a-entity", { class: "grabbing-ray", position: "0 -0.125 0", raycaster: { @@ -231,7 +230,8 @@ AFRAME.registerComponent("grabbing", { } if (this.data.hideOnGrab) this[_hand].glove.setAttribute("visible", false) - this[_hand].glove.setAttribute("body", "collidesWith", 0) + if (this[_hand].glove.getAttribute("body")) + this[_hand].glove.setAttribute("body", "collidesWith", 0) this.emit("grab", this[_hand].glove, this[_hand].grabbed) this.el.addState("grabbing") this[_hand].grabbed.addState("grabbed") @@ -252,7 +252,8 @@ AFRAME.registerComponent("grabbing", { this[_hand].anchor.removeAttribute("joint__grab") }, 32) setTimeout(() => { - this[_hand].glove.setAttribute("body", "collidesWith", 1) + if (this[_hand].glove.getAttribute("body")) + this[_hand].glove.setAttribute("body", "collidesWith", 1) }, 1024) this.emit("drop", this[_hand].glove, this[_hand].grabbed) this.el.removeState("grabbing") From bd82ff44b768db6282170ed7de17f59a23410f06 Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Fri, 2 Jul 2021 04:54:47 +0200 Subject: [PATCH 2/9] Move/rotate non-VR hand --- dist/a-game.js | 45 +++++++++++++++++++++++++++++++++++--- dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- src/components/grabbing.js | 43 ++++++++++++++++++++++++++++++++++-- src/components/grabbing.md | 20 +++++++++-------- 6 files changed, 97 insertions(+), 17 deletions(-) diff --git a/dist/a-game.js b/dist/a-game.js index 0e2f942..17ce28b 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.14.1", + "version": "0.14.2", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -77,14 +77,17 @@ AFRAME.registerComponent("grabbing", { 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._hands = ["head", "left", "right"] this._head = {} @@ -126,8 +129,10 @@ AFRAME.registerComponent("grabbing", { 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 hand of [this._left.hand, this._right.hand]) { // hand.addEventListener("buttonchanged", this._enableHands) hand.addEventListener("buttonchanged", this._onButtonChanged) @@ -138,8 +143,10 @@ AFRAME.registerComponent("grabbing", { 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 hand of [this._left.hand, this._right.hand]) { // hand.removeEventListener("buttonchanged", this._enableHands) hand.removeEventListener("buttonchanged", this._onButtonChanged) @@ -168,6 +175,17 @@ AFRAME.registerComponent("grabbing", { if ((gamepad.buttons[6].pressed || gamepad.buttons[7].pressed) && !this._useBtn0) this.useDown() if ((gamepad.buttons[0].pressed) && !this._useBtn1) this.useDown("head", 1) if ((gamepad.buttons[1].pressed) && !this._useBtn2) this.useDown("head", 2) + if (gamepad.buttons[2].pressed) { + if (gamepad.buttons[12].pressed) this.moveHeadHand(0, -0.03125) + if (gamepad.buttons[13].pressed) this.moveHeadHand(0, 0.03125) + if (gamepad.buttons[14].pressed) this.moveHeadHand(0, 0, -0.03125) + if (gamepad.buttons[15].pressed) this.moveHeadHand(0, 0, 0.03125) + } else { + if (gamepad.buttons[12].pressed) this.moveHeadHand(-0.03125) + if (gamepad.buttons[13].pressed) this.moveHeadHand(0.03125) + if (gamepad.buttons[14].pressed) this.moveHeadHand(0, 0, 0, 0.03125) + if (gamepad.buttons[15].pressed) this.moveHeadHand(0, 0, 0, -0.03125) + } } } this._grabBtn = false @@ -318,7 +336,9 @@ AFRAME.registerComponent("grabbing", { this[_hand].glove.setAttribute("visible", true) setTimeout(() => { this[_hand].anchor.removeAttribute("joint__grab") - }, 32) + this[_hand].anchor.setAttribute("position", "0 0 0") + this[_hand].anchor.setAttribute("rotation", "0 0 0") + }, 64) setTimeout(() => { if (this[_hand].glove.getAttribute("body")) this[_hand].glove.setAttribute("body", "collidesWith", 1) @@ -353,6 +373,11 @@ AFRAME.registerComponent("grabbing", { let _hand = "_" + hand this.emit("useup", this[_hand].glove, this[_hand].grabbed, { button: button }) }, + moveHeadHand(pz = 0, rx = 0, ry = 0, rz = 0) { + this._head.anchor.object3D.position.z = Math.min(Math.max(-1.5, this._head.anchor.object3D.position.z + pz), -0.125) + let quat = THREE.Quaternion.temp().set(rx, ry, rz, 1).normalize() + this._head.anchor.object3D.quaternion.premultiply(quat) + }, emit(eventtype, glove, grabbed, e = {}) { e.grabbing = this.el @@ -476,11 +501,25 @@ AFRAME.registerComponent("grabbing", { } }, - _onKeyDown(e) { if (e.key === "e") this.toggleGrab() }, + _onKeyDown(e) { + this._keysDown[e.code] = true + if (e.key === "e") this.toggleGrab() + }, + _onKeyUp(e) { this._keysDown[e.code] = false }, _onMouseDown(e) { let btn = e.button this.useDown("head", btn ? ((btn % 2) ? btn + 1 : btn - 1) : btn) }, + _onWheel(e) { + if (this._keysDown["KeyX"] && e.deltaY > 0) return this.moveHeadHand(0, 0.125) + if (this._keysDown["KeyX"] && e.deltaY < 0) return this.moveHeadHand(0, -0.125) + if (this._keysDown["KeyY"] && e.deltaY > 0) return this.moveHeadHand(0, 0, -0.125) + if (this._keysDown["KeyY"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0.125) + if (this._keysDown["KeyZ"] && e.deltaY > 0) return this.moveHeadHand(0, 0, 0, -0.125) + if (this._keysDown["KeyZ"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0, 0.125) + if (e.deltaY > 0) return this.moveHeadHand(0.125) + if (e.deltaY < 0) return this.moveHeadHand(-0.125) + }, _onMouseUp(e) { let btn = e.button this.useUp("head", btn ? ((btn % 2) ? btn + 1 : btn - 1) : btn) diff --git a/dist/a-game.min.js b/dist/a-game.min.js index 8b9fbcd..eb864ad 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.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._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,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.glove.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._head.ray=this._head.glove.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!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),this.el.sceneEl.canvas.addEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.addEventListener("mouseup",this._onMouseUp);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),this.el.sceneEl.canvas.removeEventListener("mousedown",this._onMouseDown),this.el.sceneEl.canvas.removeEventListener("mouseup",this._onMouseUp);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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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")}),32),setTimeout((()=>{this[e].glove.getAttribute("body")&&this[e].glove.setAttribute("body","collidesWith",1)}),1024),this.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_onKeyDown(t){"e"===t.key&&this.toggleGrab()},_onMouseDown(t){let e=t.button;this.useDown("head",e?e%2?e+1:e-1:e)},_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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,i,s){function o(a,r){if(!i[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 d=i[a]={exports:{}};e[a][0].call(d.exports,(function(t){return o(e[a][1][t]||t)}),d,d.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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,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.glove.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._head.ray=this._head.glove.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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")}),64),setTimeout((()=>{this[e].glove.getAttribute("body")&&this[e].glove.setAttribute("body","collidesWith",1)}),1024),this.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):this._keysDown.KeyY&&t.deltaY>0?this.moveHeadHand(0,0,-.125):this._keysDown.KeyY&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyZ&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):this._keysDown.KeyZ&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 2d7905d..1428346 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.14.1", + "version": "0.14.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b8dc562..d4a402a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.14.1", + "version": "0.14.2", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", diff --git a/src/components/grabbing.js b/src/components/grabbing.js index 216d946..5d80f32 100644 --- a/src/components/grabbing.js +++ b/src/components/grabbing.js @@ -9,14 +9,17 @@ AFRAME.registerComponent("grabbing", { 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._hands = ["head", "left", "right"] this._head = {} @@ -58,8 +61,10 @@ AFRAME.registerComponent("grabbing", { 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 hand of [this._left.hand, this._right.hand]) { // hand.addEventListener("buttonchanged", this._enableHands) hand.addEventListener("buttonchanged", this._onButtonChanged) @@ -70,8 +75,10 @@ AFRAME.registerComponent("grabbing", { 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 hand of [this._left.hand, this._right.hand]) { // hand.removeEventListener("buttonchanged", this._enableHands) hand.removeEventListener("buttonchanged", this._onButtonChanged) @@ -100,6 +107,17 @@ AFRAME.registerComponent("grabbing", { if ((gamepad.buttons[6].pressed || gamepad.buttons[7].pressed) && !this._useBtn0) this.useDown() if ((gamepad.buttons[0].pressed) && !this._useBtn1) this.useDown("head", 1) if ((gamepad.buttons[1].pressed) && !this._useBtn2) this.useDown("head", 2) + if (gamepad.buttons[2].pressed) { + if (gamepad.buttons[12].pressed) this.moveHeadHand(0, -0.03125) + if (gamepad.buttons[13].pressed) this.moveHeadHand(0, 0.03125) + if (gamepad.buttons[14].pressed) this.moveHeadHand(0, 0, -0.03125) + if (gamepad.buttons[15].pressed) this.moveHeadHand(0, 0, 0.03125) + } else { + if (gamepad.buttons[12].pressed) this.moveHeadHand(-0.03125) + if (gamepad.buttons[13].pressed) this.moveHeadHand(0.03125) + if (gamepad.buttons[14].pressed) this.moveHeadHand(0, 0, 0, 0.03125) + if (gamepad.buttons[15].pressed) this.moveHeadHand(0, 0, 0, -0.03125) + } } } this._grabBtn = false @@ -250,7 +268,9 @@ AFRAME.registerComponent("grabbing", { this[_hand].glove.setAttribute("visible", true) setTimeout(() => { this[_hand].anchor.removeAttribute("joint__grab") - }, 32) + this[_hand].anchor.setAttribute("position", "0 0 0") + this[_hand].anchor.setAttribute("rotation", "0 0 0") + }, 64) setTimeout(() => { if (this[_hand].glove.getAttribute("body")) this[_hand].glove.setAttribute("body", "collidesWith", 1) @@ -285,6 +305,11 @@ AFRAME.registerComponent("grabbing", { let _hand = "_" + hand this.emit("useup", this[_hand].glove, this[_hand].grabbed, { button: button }) }, + moveHeadHand(pz = 0, rx = 0, ry = 0, rz = 0) { + this._head.anchor.object3D.position.z = Math.min(Math.max(-1.5, this._head.anchor.object3D.position.z + pz), -0.125) + let quat = THREE.Quaternion.temp().set(rx, ry, rz, 1).normalize() + this._head.anchor.object3D.quaternion.premultiply(quat) + }, emit(eventtype, glove, grabbed, e = {}) { e.grabbing = this.el @@ -408,11 +433,25 @@ AFRAME.registerComponent("grabbing", { } }, - _onKeyDown(e) { if (e.key === "e") this.toggleGrab() }, + _onKeyDown(e) { + this._keysDown[e.code] = true + if (e.key === "e") this.toggleGrab() + }, + _onKeyUp(e) { this._keysDown[e.code] = false }, _onMouseDown(e) { let btn = e.button this.useDown("head", btn ? ((btn % 2) ? btn + 1 : btn - 1) : btn) }, + _onWheel(e) { + if (this._keysDown["KeyX"] && e.deltaY > 0) return this.moveHeadHand(0, 0.125) + if (this._keysDown["KeyX"] && e.deltaY < 0) return this.moveHeadHand(0, -0.125) + if (this._keysDown["KeyY"] && e.deltaY > 0) return this.moveHeadHand(0, 0, -0.125) + if (this._keysDown["KeyY"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0.125) + if (this._keysDown["KeyZ"] && e.deltaY > 0) return this.moveHeadHand(0, 0, 0, -0.125) + if (this._keysDown["KeyZ"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0, 0.125) + if (e.deltaY > 0) return this.moveHeadHand(0.125) + if (e.deltaY < 0) return this.moveHeadHand(-0.125) + }, _onMouseUp(e) { let btn = e.button this.useUp("head", btn ? ((btn % 2) ? btn + 1 : btn - 1) : btn) diff --git a/src/components/grabbing.md b/src/components/grabbing.md index 2fda4fd..99fa420 100644 --- a/src/components/grabbing.md +++ b/src/components/grabbing.md @@ -16,6 +16,7 @@ This makes it possible to grab and use grabbable objects using the following con | Primary use | Trigger | Left click | Tap | | Secondary | A | Right click | | Tertiary | B | Middle click | +| Move hand | X, D-pad | X,Y,Z,scroll | ## Properties @@ -31,15 +32,16 @@ This makes it possible to grab and use grabbable objects using the following con `hand` parameter is either `"head"`(default), `"left"` or `"right"`. `button` parameter is 0 - 2, where 0 is the primary use button. -| Method | Description | -| --------------------- | ----------------------------------------------------- | -| toggleGrab(hand) | Drop if holding something, attempt to grab otherwise. | -| grab(hand) | Attempt to grab something. | -| use(hand, button) | Shortly use grabbable. | -| useDown(hand, button) | Start using grabbable. | -| useUp(hand, button) | Stop using grabbable. | -| drop(hand) | Drop grabbable. | -| dropObject(el) | Drop specified grabbable if held. | +| Method | Description | +| ------------------------- | ----------------------------------------------------- | +| toggleGrab(hand) | Drop if holding something, attempt to grab otherwise. | +| grab(hand) | Attempt to grab something. | +| use(hand, button) | Shortly use grabbable. | +| useDown(hand, button) | Start using grabbable. | +| useUp(hand, button) | Stop using grabbable. | +| drop(hand) | Drop grabbable. | +| dropObject(el) | Drop specified grabbable if held. | +| moveHeadHand(pz,rx,ry,rz) | Move/rotate non-VR hand. | ## Events From e96d4f010ddd5294149183911e73678ce08d6dfd Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Fri, 2 Jul 2021 05:11:37 +0200 Subject: [PATCH 3/9] other bindings --- dist/a-game.js | 12 ++++++------ dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- src/components/grabbing.js | 10 +++++----- src/components/grabbing.md | 14 +++++++------- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/dist/a-game.js b/dist/a-game.js index 17ce28b..d461162 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.14.2", + "version": "0.14.3", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -338,7 +338,7 @@ AFRAME.registerComponent("grabbing", { this[_hand].anchor.removeAttribute("joint__grab") this[_hand].anchor.setAttribute("position", "0 0 0") this[_hand].anchor.setAttribute("rotation", "0 0 0") - }, 64) + }, 32) setTimeout(() => { if (this[_hand].glove.getAttribute("body")) this[_hand].glove.setAttribute("body", "collidesWith", 1) @@ -511,12 +511,12 @@ AFRAME.registerComponent("grabbing", { this.useDown("head", btn ? ((btn % 2) ? btn + 1 : btn - 1) : btn) }, _onWheel(e) { + if (e.shiftKey && this._keysDown["KeyX"] && e.deltaY > 0) return this.moveHeadHand(0, 0, 0, -0.125) + if (e.shiftKey && this._keysDown["KeyX"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0, 0.125) + if (e.shiftKey && e.deltaY > 0) return this.moveHeadHand(0, 0, -0.125) + if (e.shiftKey && e.deltaY < 0) return this.moveHeadHand(0, 0, 0.125) if (this._keysDown["KeyX"] && e.deltaY > 0) return this.moveHeadHand(0, 0.125) if (this._keysDown["KeyX"] && e.deltaY < 0) return this.moveHeadHand(0, -0.125) - if (this._keysDown["KeyY"] && e.deltaY > 0) return this.moveHeadHand(0, 0, -0.125) - if (this._keysDown["KeyY"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0.125) - if (this._keysDown["KeyZ"] && e.deltaY > 0) return this.moveHeadHand(0, 0, 0, -0.125) - if (this._keysDown["KeyZ"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0, 0.125) if (e.deltaY > 0) return this.moveHeadHand(0.125) if (e.deltaY < 0) return this.moveHeadHand(-0.125) }, diff --git a/dist/a-game.min.js b/dist/a-game.min.js index eb864ad..c551d61 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,i,s){function o(a,r){if(!i[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 d=i[a]={exports:{}};e[a][0].call(d.exports,(function(t){return o(e[a][1][t]||t)}),d,d.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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,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.glove.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._head.ray=this._head.glove.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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")}),64),setTimeout((()=>{this[e].glove.getAttribute("body")&&this[e].glove.setAttribute("body","collidesWith",1)}),1024),this.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):this._keysDown.KeyY&&t.deltaY>0?this.moveHeadHand(0,0,-.125):this._keysDown.KeyY&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyZ&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):this._keysDown.KeyZ&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,i,s){function o(a,r){if(!i[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 d=i[a]={exports:{}};e[a][0].call(d.exports,(function(t){return o(e[a][1][t]||t)}),d,d.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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,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.glove.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._head.ray=this._head.glove.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.getAttribute("body")&&this[e].glove.setAttribute("body","collidesWith",1)}),1024),this.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 1428346..5aa2aa7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.14.2", + "version": "0.14.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d4a402a..306499d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.14.2", + "version": "0.14.3", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", diff --git a/src/components/grabbing.js b/src/components/grabbing.js index 5d80f32..97b31a0 100644 --- a/src/components/grabbing.js +++ b/src/components/grabbing.js @@ -270,7 +270,7 @@ AFRAME.registerComponent("grabbing", { this[_hand].anchor.removeAttribute("joint__grab") this[_hand].anchor.setAttribute("position", "0 0 0") this[_hand].anchor.setAttribute("rotation", "0 0 0") - }, 64) + }, 32) setTimeout(() => { if (this[_hand].glove.getAttribute("body")) this[_hand].glove.setAttribute("body", "collidesWith", 1) @@ -443,12 +443,12 @@ AFRAME.registerComponent("grabbing", { this.useDown("head", btn ? ((btn % 2) ? btn + 1 : btn - 1) : btn) }, _onWheel(e) { + if (e.shiftKey && this._keysDown["KeyX"] && e.deltaY > 0) return this.moveHeadHand(0, 0, 0, -0.125) + if (e.shiftKey && this._keysDown["KeyX"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0, 0.125) + if (e.shiftKey && e.deltaY > 0) return this.moveHeadHand(0, 0, -0.125) + if (e.shiftKey && e.deltaY < 0) return this.moveHeadHand(0, 0, 0.125) if (this._keysDown["KeyX"] && e.deltaY > 0) return this.moveHeadHand(0, 0.125) if (this._keysDown["KeyX"] && e.deltaY < 0) return this.moveHeadHand(0, -0.125) - if (this._keysDown["KeyY"] && e.deltaY > 0) return this.moveHeadHand(0, 0, -0.125) - if (this._keysDown["KeyY"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0.125) - if (this._keysDown["KeyZ"] && e.deltaY > 0) return this.moveHeadHand(0, 0, 0, -0.125) - if (this._keysDown["KeyZ"] && e.deltaY < 0) return this.moveHeadHand(0, 0, 0, 0.125) if (e.deltaY > 0) return this.moveHeadHand(0.125) if (e.deltaY < 0) return this.moveHeadHand(-0.125) }, diff --git a/src/components/grabbing.md b/src/components/grabbing.md index 99fa420..1e6c96c 100644 --- a/src/components/grabbing.md +++ b/src/components/grabbing.md @@ -10,13 +10,13 @@ Add the `grabbing` component to your player rig like so: This makes it possible to grab and use grabbable objects using the following controls. -| Action | Controller | Desktop | Touch | -| ----------- | -------------------- | ------------ | -------- | -| Grab/drop | Grip/shoulder Button | E | Long tap | -| Primary use | Trigger | Left click | Tap | -| Secondary | A | Right click | -| Tertiary | B | Middle click | -| Move hand | X, D-pad | X,Y,Z,scroll | +| Action | Controller | Desktop | Touch | +| ----------- | -------------------- | ---------------- | -------- | +| Grab/drop | Grip/shoulder Button | E | Long tap | +| Primary use | Trigger | Left click | Tap | +| Secondary | A | Right click | +| Tertiary | B | Middle click | +| Move hand | X, D-pad | Shift, X, scroll | ## Properties From b496ce3f425ebf121ff217373536263597cd74c7 Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Fri, 2 Jul 2021 16:06:49 +0200 Subject: [PATCH 4/9] I like this solution better --- dist/a-game.js | 15 +++++++-------- dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- src/components/grabbing.js | 13 ++++++------- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/dist/a-game.js b/dist/a-game.js index d461162..b3b3513 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.14.3", + "version": "0.14.4", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -96,7 +96,7 @@ AFRAME.registerComponent("grabbing", { 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 + this._head.glove = this._head.hand.ensure(".hitbox", "a-sphere", { class: "hitbox", body: "type:kinematic;", radius: 0.25 }) this._left.glove = this._ensureGlove(this._left.hand) this._right.glove = this._ensureGlove(this._right.hand) @@ -107,8 +107,7 @@ AFRAME.registerComponent("grabbing", { this[_hand].hand.addEventListener("buttonchanged", this._enableHands) } - this._head.glove.ensure(".hitbox", "a-sphere", { class: "hitbox", body: "type:kinematic;", radius: 0.25 }) - this._head.ray = this._head.glove.ensure(".grabbing-ray", "a-entity", { + this._head.ray = this._head.hand.ensure(".grabbing-ray", "a-entity", { class: "grabbing-ray", position: "0 -0.125 0", raycaster: { objects: "[wall], [grabbable]", @@ -316,8 +315,8 @@ AFRAME.registerComponent("grabbing", { } if (this.data.hideOnGrab) this[_hand].glove.setAttribute("visible", false) - if (this[_hand].glove.getAttribute("body")) - this[_hand].glove.setAttribute("body", "collidesWith", 0) + // if (this[_hand].glove.getAttribute("body")) + this[_hand].glove.setAttribute("body", "collidesWith", 0) this.emit("grab", this[_hand].glove, this[_hand].grabbed) this.el.addState("grabbing") this[_hand].grabbed.addState("grabbed") @@ -340,8 +339,8 @@ AFRAME.registerComponent("grabbing", { this[_hand].anchor.setAttribute("rotation", "0 0 0") }, 32) setTimeout(() => { - if (this[_hand].glove.getAttribute("body")) - this[_hand].glove.setAttribute("body", "collidesWith", 1) + // if (this[_hand].glove.getAttribute("body")) + this[_hand].glove.setAttribute("body", "collidesWith", 1) }, 1024) this.emit("drop", this[_hand].glove, this[_hand].grabbed) this.el.removeState("grabbing") diff --git a/dist/a-game.min.js b/dist/a-game.min.js index c551d61..d205183 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,i,s){function o(a,r){if(!i[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 d=i[a]={exports:{}};e[a][0].call(d.exports,(function(t){return o(e[a][1][t]||t)}),d,d.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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,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.glove.ensure(".hitbox","a-sphere",{class:"hitbox",body:"type:kinematic;",radius:.25}),this._head.ray=this._head.glove.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0 -0.125 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.getAttribute("body")&&this[e].glove.setAttribute("body","collidesWith",1)}),1024),this.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,i,s){function o(a,r){if(!i[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 d=i[a]={exports:{}};e[a][0].call(d.exports,(function(t){return o(e[a][1][t]||t)}),d,d.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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.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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 5aa2aa7..8492683 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.14.3", + "version": "0.14.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 306499d..76188d4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.14.3", + "version": "0.14.4", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", diff --git a/src/components/grabbing.js b/src/components/grabbing.js index 97b31a0..9824c3c 100644 --- a/src/components/grabbing.js +++ b/src/components/grabbing.js @@ -28,7 +28,7 @@ AFRAME.registerComponent("grabbing", { 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 + this._head.glove = this._head.hand.ensure(".hitbox", "a-sphere", { class: "hitbox", body: "type:kinematic;", radius: 0.25 }) this._left.glove = this._ensureGlove(this._left.hand) this._right.glove = this._ensureGlove(this._right.hand) @@ -39,8 +39,7 @@ AFRAME.registerComponent("grabbing", { this[_hand].hand.addEventListener("buttonchanged", this._enableHands) } - this._head.glove.ensure(".hitbox", "a-sphere", { class: "hitbox", body: "type:kinematic;", radius: 0.25 }) - this._head.ray = this._head.glove.ensure(".grabbing-ray", "a-entity", { + this._head.ray = this._head.hand.ensure(".grabbing-ray", "a-entity", { class: "grabbing-ray", position: "0 -0.125 0", raycaster: { objects: "[wall], [grabbable]", @@ -248,8 +247,8 @@ AFRAME.registerComponent("grabbing", { } if (this.data.hideOnGrab) this[_hand].glove.setAttribute("visible", false) - if (this[_hand].glove.getAttribute("body")) - this[_hand].glove.setAttribute("body", "collidesWith", 0) + // if (this[_hand].glove.getAttribute("body")) + this[_hand].glove.setAttribute("body", "collidesWith", 0) this.emit("grab", this[_hand].glove, this[_hand].grabbed) this.el.addState("grabbing") this[_hand].grabbed.addState("grabbed") @@ -272,8 +271,8 @@ AFRAME.registerComponent("grabbing", { this[_hand].anchor.setAttribute("rotation", "0 0 0") }, 32) setTimeout(() => { - if (this[_hand].glove.getAttribute("body")) - this[_hand].glove.setAttribute("body", "collidesWith", 1) + // if (this[_hand].glove.getAttribute("body")) + this[_hand].glove.setAttribute("body", "collidesWith", 1) }, 1024) this.emit("drop", this[_hand].glove, this[_hand].grabbed) this.el.removeState("grabbing") From 08653cc907b379887a794df9c856a8e063e784c1 Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Fri, 2 Jul 2021 17:44:38 +0200 Subject: [PATCH 5/9] grabbing reticle --- dist/a-game.js | 11 ++++++++++- dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- src/components/grabbing.js | 9 +++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/dist/a-game.js b/dist/a-game.js index b3b3513..182237a 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.14.4", + "version": "0.14.5", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -115,6 +115,12 @@ AFRAME.registerComponent("grabbing", { // showLine: true, } }) + this._head.reticle = this._head.ray.ensure(".reticle", "a-sphere", { + class: "reticle", + radius: 0.015625, + // color: "black", + position: "0 0 -1" + }, ``) this._head.anchor = this._head.ray.ensure(".grabbing-anchor", "a-entity", { class: "grabbing-anchor", visible: false, body: "type:kinematic;autoShape:false;" }) }, @@ -238,6 +244,7 @@ AFRAME.registerComponent("grabbing", { if (this[_hand].grabbed) { // if (!this[_hand].isPhysical) this[_hand].grabbed.copyWorldPosRot(this[_hand].anchor) + if (this[_hand].reticle) this[_hand].reticle.object3D.position.z = 1 } else if (this[_hand].ray) { let ray = this[_hand].ray.components.raycaster ray.refreshObjects() @@ -249,10 +256,12 @@ AFRAME.registerComponent("grabbing", { this[_hand]._lastHit = hit.el this.emit("reachable", this[_hand].glove, this[_hand]._lastHit) } + if (this[_hand].reticle) this[_hand].reticle.object3D.position.z = -hit.distance } else { if (this[_hand]._lastHit) this.emit("unreachable", this[_hand].glove, this[_hand]._lastHit) this[_hand]._lastHit = null + if (this[_hand].reticle) this[_hand].reticle.object3D.position.z = 1 } } } diff --git a/dist/a-game.min.js b/dist/a-game.min.js index d205183..ce8a9a9 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,i,s){function o(a,r){if(!i[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 d=i[a]={exports:{}};e[a][0].call(d.exports,(function(t){return o(e[a][1][t]||t)}),d,d.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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.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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 8492683..6d5de1e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.14.4", + "version": "0.14.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 76188d4..62ffa13 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.14.4", + "version": "0.14.5", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", diff --git a/src/components/grabbing.js b/src/components/grabbing.js index 9824c3c..0a02701 100644 --- a/src/components/grabbing.js +++ b/src/components/grabbing.js @@ -47,6 +47,12 @@ AFRAME.registerComponent("grabbing", { // showLine: true, } }) + this._head.reticle = this._head.ray.ensure(".reticle", "a-sphere", { + class: "reticle", + radius: 0.015625, + // color: "black", + position: "0 0 -1" + }, ``) this._head.anchor = this._head.ray.ensure(".grabbing-anchor", "a-entity", { class: "grabbing-anchor", visible: false, body: "type:kinematic;autoShape:false;" }) }, @@ -170,6 +176,7 @@ AFRAME.registerComponent("grabbing", { if (this[_hand].grabbed) { // if (!this[_hand].isPhysical) this[_hand].grabbed.copyWorldPosRot(this[_hand].anchor) + if (this[_hand].reticle) this[_hand].reticle.object3D.position.z = 1 } else if (this[_hand].ray) { let ray = this[_hand].ray.components.raycaster ray.refreshObjects() @@ -181,10 +188,12 @@ AFRAME.registerComponent("grabbing", { this[_hand]._lastHit = hit.el this.emit("reachable", this[_hand].glove, this[_hand]._lastHit) } + if (this[_hand].reticle) this[_hand].reticle.object3D.position.z = -hit.distance } else { if (this[_hand]._lastHit) this.emit("unreachable", this[_hand].glove, this[_hand]._lastHit) this[_hand]._lastHit = null + if (this[_hand].reticle) this[_hand].reticle.object3D.position.z = 1 } } } From 048e6a54b748390836c104d3c11349df23ee0be3 Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Sat, 3 Jul 2021 02:24:52 +0200 Subject: [PATCH 6/9] making sure hand anchors don't cross walls --- dist/a-game.js | 10 ++++++++-- dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- src/components/grabbing.js | 8 +++++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/dist/a-game.js b/dist/a-game.js index 182237a..778cc53 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.14.5", + "version": "0.14.6", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -242,7 +242,13 @@ AFRAME.registerComponent("grabbing", { } if (this[_hand].grabbed) { - // if (!this[_hand].isPhysical) + let ray = this[_hand].ray.components.raycaster + ray.refreshObjects() + for (let hit of ray.intersections) { + if (hit && hit.el.getAttribute("wall") != null && hit.distance < -this[_hand].anchor.object3D.position.z) { + this.moveHeadHand(0.125) + } + } this[_hand].grabbed.copyWorldPosRot(this[_hand].anchor) if (this[_hand].reticle) this[_hand].reticle.object3D.position.z = 1 } else if (this[_hand].ray) { diff --git a/dist/a-game.min.js b/dist/a-game.min.js index ce8a9a9..f3b7dd7 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 6d5de1e..3ba7ef0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.14.5", + "version": "0.14.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 62ffa13..8e3e759 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.14.5", + "version": "0.14.6", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", diff --git a/src/components/grabbing.js b/src/components/grabbing.js index 0a02701..0f0e609 100644 --- a/src/components/grabbing.js +++ b/src/components/grabbing.js @@ -174,7 +174,13 @@ AFRAME.registerComponent("grabbing", { } if (this[_hand].grabbed) { - // if (!this[_hand].isPhysical) + let ray = this[_hand].ray.components.raycaster + ray.refreshObjects() + for (let hit of ray.intersections) { + if (hit && hit.el.getAttribute("wall") != null && hit.distance < -this[_hand].anchor.object3D.position.z) { + this.moveHeadHand(0.125) + } + } this[_hand].grabbed.copyWorldPosRot(this[_hand].anchor) if (this[_hand].reticle) this[_hand].reticle.object3D.position.z = 1 } else if (this[_hand].ray) { From 2caa214d2ced6a67cc2f4199d0b34f1fae61e370 Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Sat, 3 Jul 2021 19:59:31 +0200 Subject: [PATCH 7/9] any hand, not just head --- dist/a-game.js | 4 ++-- dist/a-game.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- src/components/grabbing.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/a-game.js b/dist/a-game.js index 778cc53..c0c1121 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.14.6", + "version": "0.14.8", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -246,7 +246,7 @@ AFRAME.registerComponent("grabbing", { ray.refreshObjects() for (let hit of ray.intersections) { if (hit && hit.el.getAttribute("wall") != null && hit.distance < -this[_hand].anchor.object3D.position.z) { - this.moveHeadHand(0.125) + this[_hand].anchor.object3D.position.multiplyScalar(0.5) } } this[_hand].grabbed.copyWorldPosRot(this[_hand].anchor) diff --git a/dist/a-game.min.js b/dist/a-game.min.js index f3b7dd7..7e9dfaf 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 3ba7ef0..18f5ada 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.14.6", + "version": "0.14.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8e3e759..89bc42a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.14.6", + "version": "0.14.8", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", diff --git a/src/components/grabbing.js b/src/components/grabbing.js index 0f0e609..bdb44a8 100644 --- a/src/components/grabbing.js +++ b/src/components/grabbing.js @@ -178,7 +178,7 @@ AFRAME.registerComponent("grabbing", { ray.refreshObjects() for (let hit of ray.intersections) { if (hit && hit.el.getAttribute("wall") != null && hit.distance < -this[_hand].anchor.object3D.position.z) { - this.moveHeadHand(0.125) + this[_hand].anchor.object3D.position.multiplyScalar(0.5) } } this[_hand].grabbed.copyWorldPosRot(this[_hand].anchor) From 5202e4d9726770242759eea300607fc908a7c5da Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Sun, 4 Jul 2021 14:48:57 +0200 Subject: [PATCH 8/9] `climbable` component --- README.md | 1 + dist/a-game.js | 163 ++++++++++++++++++++------- dist/a-game.min.js | 2 +- dist/scenes/demo.html | 6 +- package-lock.json | 2 +- package.json | 2 +- src/components/grabbing.js | 13 ++- src/components/grabbing.md | 3 +- src/components/grabbing/climbable.js | 68 +++++++++++ src/components/grabbing/climbable.md | 30 +++++ src/components/locomotion.js | 26 +++-- src/components/locomotion.md | 3 + src/components/locomotion/wall.md | 7 ++ 13 files changed, 268 insertions(+), 58 deletions(-) create mode 100644 src/components/grabbing/climbable.js create mode 100644 src/components/grabbing/climbable.md diff --git a/README.md b/README.md index 4856257..45f7e71 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Essential game components for [A-Frame](https://aframe.io/)! ## Components - [grabbing](./src/components/grabbing.md) + - [climbable](./src/components/grabbing/climbable.md) - [fingerflex](./src/components/grabbing/fingerflex.md) - [grabbable](./src/components/grabbing/grabbable.md) - [receptacle](./src/components/grabbing/receptacle.md) diff --git a/dist/a-game.js b/dist/a-game.js index c0c1121..673b786 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.14.8", + "version": "0.14.9", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", @@ -65,7 +65,7 @@ require("./primitives/a-player") const pkg = require("../package") console.log(`${pkg.title} Version ${pkg.version} by ${pkg.author}\n(${pkg.homepage})`) -},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],3:[function(require,module,exports){ +},{"../package":1,"./components/grabbing":3,"./components/include":8,"./components/injectplayer":9,"./components/locomotion":10,"./components/onevent":14,"./components/onstate":15,"./components/physics":16,"./components/trigger":20,"./libs/betterRaycaster":21,"./libs/copyWorldPosRot":23,"./libs/ensureElement":24,"./libs/pools":25,"./libs/touchGestures":26,"./primitives/a-hand":27,"./primitives/a-main":28,"./primitives/a-player":29}],3:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("grabbing", { @@ -121,7 +121,7 @@ AFRAME.registerComponent("grabbing", { // color: "black", position: "0 0 -1" }, ``) - this._head.anchor = this._head.ray.ensure(".grabbing-anchor", "a-entity", { class: "grabbing-anchor", visible: false, body: "type:kinematic;autoShape:false;" }) + this._head.anchor = this._head.ray.ensure(".grabbing.anchor", "a-entity", { class: "grabbing anchor", visible: false, body: "type:kinematic;autoShape:false;" }) }, update(oldData) { @@ -332,7 +332,7 @@ AFRAME.registerComponent("grabbing", { this[_hand].glove.setAttribute("visible", false) // if (this[_hand].glove.getAttribute("body")) this[_hand].glove.setAttribute("body", "collidesWith", 0) - this.emit("grab", this[_hand].glove, this[_hand].grabbed) + this.emit("grab", this[_hand].glove, this[_hand].grabbed, { intersection: hit }) this.el.addState("grabbing") this[_hand].grabbed.addState("grabbed") this.sticky = true @@ -398,7 +398,7 @@ AFRAME.registerComponent("grabbing", { e.grabbedElement = grabbed e.gloveElement = glove for (let _hand of this._hands) { - if (this["_" + _hand].hand === glove) e.hand = _hand + if (this["_" + _hand].glove === glove) e.hand = _hand } glove.emit(eventtype, e) if (grabbed) grabbed.emit(eventtype, e) @@ -440,8 +440,8 @@ AFRAME.registerComponent("grabbing", { // showLine: true, } }) - this._left.anchor = this._left.ray.ensure(".grabbing-anchor", "a-entity", { class: "grabbing-anchor", visible: "false", body: "type:kinematic;autoShape:false;" }) - this._right.anchor = this._right.ray.ensure(".grabbing-anchor", "a-entity", { class: "grabbing-anchor", visible: "false", body: "type:kinematic;autoShape:false;" }) + this._left.anchor = this._left.ray.ensure(".grabbing.anchor", "a-entity", { class: "grabbing anchor", visible: "false", body: "type:kinematic;autoShape:false;" }) + this._right.anchor = this._right.ray.ensure(".grabbing.anchor", "a-entity", { class: "grabbing anchor", visible: "false", body: "type:kinematic;autoShape:false;" }) this._left.glove.setAttribute("visible", true) this._right.glove.setAttribute("visible", true) @@ -586,11 +586,82 @@ AFRAME.registerComponent("grabbing", { }, }) -require("./grabbing/grabbable") +require("./grabbing/climbable") require("./grabbing/fingerflex") +require("./grabbing/grabbable") require("./grabbing/receptacle") -},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(require,module,exports){ +},{"./grabbing/climbable":4,"./grabbing/fingerflex":5,"./grabbing/grabbable":6,"./grabbing/receptacle":7}],4:[function(require,module,exports){ +/* global AFRAME, THREE */ + +AFRAME.registerComponent("climbable", { + dependencies: ["wall"], + schema: { + }, + + init() { + this.el.setAttribute("grabbable", "physics:false; kinematicGrab:false;") + this._player = this.el.sceneEl.querySelector("[locomotion") + this._quat = new THREE.Quaternion() + this._lpos = new THREE.Vector3() + this._wpos = new THREE.Vector3() + this._handpos = new THREE.Vector3() + + this._onBump = this._onBump.bind(this) + + setTimeout(() => { + 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) + }, + pause() { + this._player.removeEventListener("bump", this._onBump) + }, + + tick() { + if (!this._climbing) return + let delta = THREE.Vector3.temp() + this._hand.object3D.getWorldPosition(delta) + delta.sub(this._handpos).multiplyScalar(-1) + if (this._handName === "head") { + delta.y = 0 + delta.y = delta.length() + this._handpos.y += delta.y + } + this._player.components.locomotion.stopFall() + this._player.components.locomotion.move(delta) + if (this._handpos.y - this._wpos.y > this._top) this._onBump() + + this.el.object3D.quaternion.copy(this._quat) + this.el.object3D.position.copy(this._lpos) + }, + + events: { + grab(e) { + this._climbing = true + this._handName = e.detail.hand + this._hand = e.detail.gloveElement.parentNode//.querySelector(".anchor") + this._hand.object3D.getWorldPosition(this._handpos) + if (e.detail.intersection.distance > (this._handName === "head" ? 0.5 : 0.25)) setTimeout(this._onBump, 260) + else this._player.components.locomotion.jump() + }, + drop(e) { + this._climbing = false + }, + }, + + _onBump(e) { + this._player.components.grabbing.dropObject(this.el) + } +}) + +},{}],5:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("fingerflex", { @@ -632,7 +703,7 @@ AFRAME.registerComponent("fingerflex", { } }) -},{}],5:[function(require,module,exports){ +},{}],6:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("grabbable", { @@ -657,7 +728,7 @@ AFRAME.registerComponent("grabbable", { } }) -},{}],6:[function(require,module,exports){ +},{}],7:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("receptacle", { @@ -799,7 +870,7 @@ AFRAME.registerComponent("receptacle", { }) -},{}],7:[function(require,module,exports){ +},{}],8:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("include", { @@ -832,7 +903,7 @@ AFRAME.registerComponent("include", { } }) -},{}],8:[function(require,module,exports){ +},{}],9:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("injectplayer", { @@ -847,7 +918,7 @@ AFRAME.registerComponent("injectplayer", { } }) -},{}],9:[function(require,module,exports){ +},{}],10:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("locomotion", { @@ -1017,7 +1088,7 @@ AFRAME.registerComponent("locomotion", { if (this.currentFloor === hit.el) { let delta = THREE.Vector3.temp() delta.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition) - this._move(delta) + this.move(delta) this.lastStep.add(delta) delta.y = 0 this._legs.object3D.position.add(delta) @@ -1025,13 +1096,13 @@ AFRAME.registerComponent("locomotion", { if (this.currentFloor) this.currentFloor.emit("leave") hit.el.emit("enter") } - this._move(THREE.Vector3.temp().set(0, 0.5 - hit.distance, 0)) + this.move(THREE.Vector3.temp().set(0, 0.5 - hit.distance, 0)) this.currentFloor = hit.el this.currentFloorPosition.copy(this.currentFloor.object3D.position) } else { if (this.currentFloor) this.currentFloor.emit("leave") this._vertVelocity -= this.data.gravity * timeDelta - this._move(THREE.Vector3.temp().set(0, Math.max(-0.5, this._vertVelocity * timeDelta), 0)) + this.move(THREE.Vector3.temp().set(0, Math.max(-0.5, this._vertVelocity * timeDelta), 0)) this.currentFloor = null } } @@ -1072,7 +1143,7 @@ AFRAME.registerComponent("locomotion", { teleport(pos, force) { let delta = THREE.Vector3.temp() delta.copy(pos).sub(this.feetPos) - this._move(delta) + this.move(delta) 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 @@ -1088,6 +1159,11 @@ AFRAME.registerComponent("locomotion", { 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(reset) { let head2toe = this.headPos.y - this.feetPos.y @@ -1114,13 +1190,14 @@ AFRAME.registerComponent("locomotion", { } }, - _move(delta) { + move(delta) { this.el.object3D.position.add(delta) this.centerPos.add(delta) this.headPos.add(delta) this._legs.object3D.position.y += delta.y this.feetPos.y += delta.y }, + _bump(pos, bumper) { let matrix = THREE.Matrix3.temp() let delta = THREE.Vector3.temp() @@ -1143,7 +1220,7 @@ AFRAME.registerComponent("locomotion", { .normalize() .multiplyScalar(dist + 0.125) let feety = this._legs.object3D.position.y - this._move(delta) + this.move(delta) bumper.object3D.position.add(delta) if (this._legs.object3D.position.y !== feety) { if (bumper === this._headBumper) this._headBumper.object3D.position.copy(this._legBumper.object3D.position) @@ -1157,6 +1234,12 @@ AFRAME.registerComponent("locomotion", { this._caution = 4 this._bumpOverload++ this._vertVelocity = Math.min(0, this._vertVelocity) + let detail = { + player: this.el, + object: hit.el + } + this.el.emit("bump", detail) + hit.el.emit("bump", detail) } else if (this._caution) { this._caution-- } else { @@ -1220,7 +1303,7 @@ AFRAME.registerComponent("locomotion", { delta.set(0, 0, 0) } } - this._move(delta) + this.move(delta) }, _callAuxStick() { @@ -1503,7 +1586,7 @@ require("./locomotion/floor") require("./locomotion/wall") require("./locomotion/start") -},{"./locomotion/floor":10,"./locomotion/start":11,"./locomotion/wall":12}],10:[function(require,module,exports){ +},{"./locomotion/floor":11,"./locomotion/start":12,"./locomotion/wall":13}],11:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("floor", { @@ -1516,7 +1599,7 @@ AFRAME.registerComponent("floor", { } }) -},{}],11:[function(require,module,exports){ +},{}],12:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("start", { @@ -1537,7 +1620,7 @@ AFRAME.registerComponent("start", { } }) -},{}],12:[function(require,module,exports){ +},{}],13:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("wall", { @@ -1550,7 +1633,7 @@ AFRAME.registerComponent("wall", { } }) -},{}],13:[function(require,module,exports){ +},{}],14:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("onevent", { @@ -1593,7 +1676,7 @@ AFRAME.registerComponent("onevent", { } }) -},{}],14:[function(require,module,exports){ +},{}],15:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("onstate", { @@ -1637,7 +1720,7 @@ AFRAME.registerComponent("onstate", { } }) -},{}],15:[function(require,module,exports){ +},{}],16:[function(require,module,exports){ /* global AFRAME, THREE */ const cmd = require("../libs/cmdCodec") @@ -1752,7 +1835,7 @@ require("./physics/body") require("./physics/shape") require("./physics/joint") -},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(require,module,exports){ +},{"../../package":1,"../libs/cmdCodec":22,"./physics/body":17,"./physics/joint":18,"./physics/shape":19}],17:[function(require,module,exports){ /* global AFRAME, THREE */ const cmd = require("../../libs/cmdCodec") @@ -1967,7 +2050,7 @@ AFRAME.registerComponent("body", { }) -},{"../../libs/cmdCodec":21}],17:[function(require,module,exports){ +},{"../../libs/cmdCodec":22}],18:[function(require,module,exports){ /* global AFRAME, THREE */ const cmd = require("../../libs/cmdCodec") @@ -2051,7 +2134,7 @@ AFRAME.registerComponent("joint", { }) -},{"../../libs/cmdCodec":21}],18:[function(require,module,exports){ +},{"../../libs/cmdCodec":22}],19:[function(require,module,exports){ /* global AFRAME, THREE */ const cmd = require("../../libs/cmdCodec") @@ -2132,7 +2215,7 @@ AFRAME.registerComponent("shape", { }) -},{"../../libs/cmdCodec":21}],19:[function(require,module,exports){ +},{"../../libs/cmdCodec":22}],20:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerComponent("trigger", { @@ -2216,7 +2299,7 @@ AFRAME.registerComponent("trigger", { }) -},{}],20:[function(require,module,exports){ +},{}],21:[function(require,module,exports){ /* global AFRAME, THREE */ const _update = AFRAME.components.raycaster.Component.prototype.update @@ -2244,7 +2327,7 @@ function deepMatch(selector) { let deep = (selector + ", ").replaceAll(",", " *,") return deep + selector } -},{}],21:[function(require,module,exports){ +},{}],22:[function(require,module,exports){ module.exports = { parse(cmd) { let words = cmd.split(" ") @@ -2265,7 +2348,7 @@ module.exports = { return JSON.stringify(val).replaceAll(" ", "\\u0020").replaceAll("\"_", "\"") } } -},{}],22:[function(require,module,exports){ +},{}],23:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.AEntity.prototype.copyWorldPosRot = function (srcEl) { @@ -2283,7 +2366,7 @@ AFRAME.AEntity.prototype.copyWorldPosRot = function (srcEl) { src.getWorldQuaternion(quat) dest.quaternion.multiply(quat.normalize()) } -},{}],23:[function(require,module,exports){ +},{}],24:[function(require,module,exports){ Element.prototype.ensure = function (selector, name = selector, attrs = {}, innerHTML = "") { let _childEl, attr, val _childEl = this.querySelector(selector) @@ -2298,7 +2381,7 @@ Element.prototype.ensure = function (selector, name = selector, attrs = {}, inne } return _childEl } -},{}],24:[function(require,module,exports){ +},{}],25:[function(require,module,exports){ /* global AFRAME, THREE */ function makePool(Class) { @@ -2324,7 +2407,7 @@ makePool(THREE.Quaternion) makePool(THREE.Matrix3) makePool(THREE.Matrix4) -},{}],25:[function(require,module,exports){ +},{}],26:[function(require,module,exports){ let _addEventListener = Element.prototype.addEventListener let _removeEventListener = Element.prototype.removeEventListener let init = el => { @@ -2418,7 +2501,7 @@ Element.prototype.removeEventListener = function (eventtype, handler) { } } -},{}],26:[function(require,module,exports){ +},{}],27:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerPrimitive("a-hand", { @@ -2427,11 +2510,11 @@ AFRAME.registerPrimitive("a-hand", { } }) -},{}],27:[function(require,module,exports){ +},{}],28:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerPrimitive("a-main", {}) -},{}],28:[function(require,module,exports){ +},{}],29:[function(require,module,exports){ /* global AFRAME, THREE */ AFRAME.registerPrimitive("a-player", { diff --git a/dist/a-game.min.js b/dist/a-game.min.js index 7e9dfaf..f75a43b 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":7,"./components/injectplayer":8,"./components/locomotion":9,"./components/onevent":13,"./components/onstate":14,"./components/physics":15,"./components/trigger":19,"./libs/betterRaycaster":20,"./libs/copyWorldPosRot":22,"./libs/ensureElement":23,"./libs/pools":24,"./libs/touchGestures":25,"./primitives/a-hand":26,"./primitives/a-main":27,"./primitives/a-player":28}],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._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.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].hand===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing-anchor","a-entity",{class:"grabbing-anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/grabbable"),t("./grabbing/fingerflex"),t("./grabbing/receptacle")},{"./grabbing/fingerflex":4,"./grabbing/grabbable":5,"./grabbing/receptacle":6}],4:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],5:[function(t,e,i){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")}}})},{}],6:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],7:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],8:[function(t,e,i){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"})}})},{}],9:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this._move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this._move(i),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)},toggleCrouch(t){let e,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this._move(s),e.object3D.position.add(s),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(s),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)}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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],12:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],13:[function(t,e,i){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)}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":21,"./physics/body":16,"./physics/joint":17,"./physics/shape":18}],16:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":21}],17:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],18:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":21}],19:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],21:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],22:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],23:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],24:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],25:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],26:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":8,"./components/injectplayer":9,"./components/locomotion":10,"./components/onevent":14,"./components/onstate":15,"./components/physics":16,"./components/trigger":20,"./libs/betterRaycaster":21,"./libs/copyWorldPosRot":23,"./libs/ensureElement":24,"./libs/pools":25,"./libs/touchGestures":26,"./primitives/a-hand":27,"./primitives/a-main":28,"./primitives/a-player":29}],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._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.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/climbable":4,"./grabbing/fingerflex":5,"./grabbing/grabbable":6,"./grabbing/receptacle":7}],4:[function(t,e,i){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion"),this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._onBump=this._onBump.bind(this),setTimeout((()=>{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)},pause(){this._player.removeEventListener("bump",this._onBump)},tick(){if(!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._onBump(),this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos)},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()},drop(t){this._climbing=!1}},_onBump(t){this._player.components.grabbing.dropObject(this.el)}})},{}],5:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],6:[function(t,e,i){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")}}})},{}],7:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],8:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],9:[function(t,e,i){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"})}})},{}],10:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this.move(i),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,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(s),e.object3D.position.add(s),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(s),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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],13:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){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)}})},{}],16:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":22,"./physics/body":17,"./physics/joint":18,"./physics/shape":19}],17:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":22}],18:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":22}],19:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":22}],20:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],22:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],23:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],24:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],25:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],26:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],29:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/dist/scenes/demo.html b/dist/scenes/demo.html index 1ed025c..39e7d3d 100644 --- a/dist/scenes/demo.html +++ b/dist/scenes/demo.html @@ -1,6 +1,6 @@ - + + + @@ -55,6 +57,8 @@ + + diff --git a/package-lock.json b/package-lock.json index 18f5ada..6dddc0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.14.8", + "version": "0.14.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 89bc42a..7ea39a4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.14.8", + "version": "0.14.9", "description": "game components for A-Frame", "homepage": "https://github.com/poeticAndroid/a-game/blob/master/README.md", "main": "index.js", diff --git a/src/components/grabbing.js b/src/components/grabbing.js index bdb44a8..158308c 100644 --- a/src/components/grabbing.js +++ b/src/components/grabbing.js @@ -53,7 +53,7 @@ AFRAME.registerComponent("grabbing", { // color: "black", position: "0 0 -1" }, ``) - this._head.anchor = this._head.ray.ensure(".grabbing-anchor", "a-entity", { class: "grabbing-anchor", visible: false, body: "type:kinematic;autoShape:false;" }) + this._head.anchor = this._head.ray.ensure(".grabbing.anchor", "a-entity", { class: "grabbing anchor", visible: false, body: "type:kinematic;autoShape:false;" }) }, update(oldData) { @@ -264,7 +264,7 @@ AFRAME.registerComponent("grabbing", { this[_hand].glove.setAttribute("visible", false) // if (this[_hand].glove.getAttribute("body")) this[_hand].glove.setAttribute("body", "collidesWith", 0) - this.emit("grab", this[_hand].glove, this[_hand].grabbed) + this.emit("grab", this[_hand].glove, this[_hand].grabbed, { intersection: hit }) this.el.addState("grabbing") this[_hand].grabbed.addState("grabbed") this.sticky = true @@ -330,7 +330,7 @@ AFRAME.registerComponent("grabbing", { e.grabbedElement = grabbed e.gloveElement = glove for (let _hand of this._hands) { - if (this["_" + _hand].hand === glove) e.hand = _hand + if (this["_" + _hand].glove === glove) e.hand = _hand } glove.emit(eventtype, e) if (grabbed) grabbed.emit(eventtype, e) @@ -372,8 +372,8 @@ AFRAME.registerComponent("grabbing", { // showLine: true, } }) - this._left.anchor = this._left.ray.ensure(".grabbing-anchor", "a-entity", { class: "grabbing-anchor", visible: "false", body: "type:kinematic;autoShape:false;" }) - this._right.anchor = this._right.ray.ensure(".grabbing-anchor", "a-entity", { class: "grabbing-anchor", visible: "false", body: "type:kinematic;autoShape:false;" }) + this._left.anchor = this._left.ray.ensure(".grabbing.anchor", "a-entity", { class: "grabbing anchor", visible: "false", body: "type:kinematic;autoShape:false;" }) + this._right.anchor = this._right.ray.ensure(".grabbing.anchor", "a-entity", { class: "grabbing anchor", visible: "false", body: "type:kinematic;autoShape:false;" }) this._left.glove.setAttribute("visible", true) this._right.glove.setAttribute("visible", true) @@ -518,6 +518,7 @@ AFRAME.registerComponent("grabbing", { }, }) -require("./grabbing/grabbable") +require("./grabbing/climbable") require("./grabbing/fingerflex") +require("./grabbing/grabbable") require("./grabbing/receptacle") diff --git a/src/components/grabbing.md b/src/components/grabbing.md index 1e6c96c..1f3104e 100644 --- a/src/components/grabbing.md +++ b/src/components/grabbing.md @@ -61,6 +61,7 @@ These events are emitted by both the glove and the `grabbable` that it's grabbin ## Related components + - [climbable](./grabbing/climbable.md) + - [fingerflex](./grabbing/fingerflex.md) - [grabbable](./grabbing/grabbable.md) - [receptacle](./grabbing/receptacle.md) - - [fingerflex](./grabbing/fingerflex.md) diff --git a/src/components/grabbing/climbable.js b/src/components/grabbing/climbable.js new file mode 100644 index 0000000..fa9084b --- /dev/null +++ b/src/components/grabbing/climbable.js @@ -0,0 +1,68 @@ +/* global AFRAME, THREE */ + +AFRAME.registerComponent("climbable", { + dependencies: ["wall"], + schema: { + }, + + init() { + this.el.setAttribute("grabbable", "physics:false; kinematicGrab:false;") + this._player = this.el.sceneEl.querySelector("[locomotion") + this._quat = new THREE.Quaternion() + this._lpos = new THREE.Vector3() + this._wpos = new THREE.Vector3() + this._handpos = new THREE.Vector3() + + this._onBump = this._onBump.bind(this) + + setTimeout(() => { + 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) + }, + pause() { + this._player.removeEventListener("bump", this._onBump) + }, + + tick() { + if (!this._climbing) return + let delta = THREE.Vector3.temp() + this._hand.object3D.getWorldPosition(delta) + delta.sub(this._handpos).multiplyScalar(-1) + if (this._handName === "head") { + delta.y = 0 + delta.y = delta.length() + this._handpos.y += delta.y + } + this._player.components.locomotion.stopFall() + this._player.components.locomotion.move(delta) + if (this._handpos.y - this._wpos.y > this._top) this._onBump() + + this.el.object3D.quaternion.copy(this._quat) + this.el.object3D.position.copy(this._lpos) + }, + + events: { + grab(e) { + this._climbing = true + this._handName = e.detail.hand + this._hand = e.detail.gloveElement.parentNode//.querySelector(".anchor") + this._hand.object3D.getWorldPosition(this._handpos) + if (e.detail.intersection.distance > (this._handName === "head" ? 0.5 : 0.25)) setTimeout(this._onBump, 260) + else this._player.components.locomotion.jump() + }, + drop(e) { + this._climbing = false + }, + }, + + _onBump(e) { + this._player.components.grabbing.dropObject(this.el) + } +}) diff --git a/src/components/grabbing/climbable.md b/src/components/grabbing/climbable.md new file mode 100644 index 0000000..ef11b8b --- /dev/null +++ b/src/components/grabbing/climbable.md @@ -0,0 +1,30 @@ +# climbable + +Add the `climbable` component to any object you want the player to be able to pick up. + +```html + +``` + + +## Properties + +| Property | Description | Default | +| ------------- | -------------------------------------------------------------------------- | ------- | +| physics | Whether or not to add physics body automatically. | true | +| kinematicGrab | Whether or not to make physics kinematic during grab. | true | +| fixed | If `true` the object will have a fixed position and rotation when grabbed. | false | +| fixedPosition | Relative position in hand, if `fixed` is `true`. | 0 0 0 | + + +## Events + +| Event | Description | +| ----------- | -------------------------- | +| reachable | climbable is within reach. | +| unreachable | climbable is out of reach. | +| grab | grabbing. | +| usedown | use-button is pressed. | +| useup | use-button is released. | +| drop | dropping. | +| fingerflex | a finger is flexing. | diff --git a/src/components/locomotion.js b/src/components/locomotion.js index d6973e9..0845ded 100644 --- a/src/components/locomotion.js +++ b/src/components/locomotion.js @@ -167,7 +167,7 @@ AFRAME.registerComponent("locomotion", { if (this.currentFloor === hit.el) { let delta = THREE.Vector3.temp() delta.copy(this.currentFloor.object3D.position).sub(this.currentFloorPosition) - this._move(delta) + this.move(delta) this.lastStep.add(delta) delta.y = 0 this._legs.object3D.position.add(delta) @@ -175,13 +175,13 @@ AFRAME.registerComponent("locomotion", { if (this.currentFloor) this.currentFloor.emit("leave") hit.el.emit("enter") } - this._move(THREE.Vector3.temp().set(0, 0.5 - hit.distance, 0)) + this.move(THREE.Vector3.temp().set(0, 0.5 - hit.distance, 0)) this.currentFloor = hit.el this.currentFloorPosition.copy(this.currentFloor.object3D.position) } else { if (this.currentFloor) this.currentFloor.emit("leave") this._vertVelocity -= this.data.gravity * timeDelta - this._move(THREE.Vector3.temp().set(0, Math.max(-0.5, this._vertVelocity * timeDelta), 0)) + this.move(THREE.Vector3.temp().set(0, Math.max(-0.5, this._vertVelocity * timeDelta), 0)) this.currentFloor = null } } @@ -222,7 +222,7 @@ AFRAME.registerComponent("locomotion", { teleport(pos, force) { let delta = THREE.Vector3.temp() delta.copy(pos).sub(this.feetPos) - this._move(delta) + this.move(delta) 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 @@ -238,6 +238,11 @@ AFRAME.registerComponent("locomotion", { 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(reset) { let head2toe = this.headPos.y - this.feetPos.y @@ -264,13 +269,14 @@ AFRAME.registerComponent("locomotion", { } }, - _move(delta) { + move(delta) { this.el.object3D.position.add(delta) this.centerPos.add(delta) this.headPos.add(delta) this._legs.object3D.position.y += delta.y this.feetPos.y += delta.y }, + _bump(pos, bumper) { let matrix = THREE.Matrix3.temp() let delta = THREE.Vector3.temp() @@ -293,7 +299,7 @@ AFRAME.registerComponent("locomotion", { .normalize() .multiplyScalar(dist + 0.125) let feety = this._legs.object3D.position.y - this._move(delta) + this.move(delta) bumper.object3D.position.add(delta) if (this._legs.object3D.position.y !== feety) { if (bumper === this._headBumper) this._headBumper.object3D.position.copy(this._legBumper.object3D.position) @@ -307,6 +313,12 @@ AFRAME.registerComponent("locomotion", { this._caution = 4 this._bumpOverload++ this._vertVelocity = Math.min(0, this._vertVelocity) + let detail = { + player: this.el, + object: hit.el + } + this.el.emit("bump", detail) + hit.el.emit("bump", detail) } else if (this._caution) { this._caution-- } else { @@ -370,7 +382,7 @@ AFRAME.registerComponent("locomotion", { delta.set(0, 0, 0) } } - this._move(delta) + this.move(delta) }, _callAuxStick() { diff --git a/src/components/locomotion.md b/src/components/locomotion.md index 773b595..1bc7ecc 100644 --- a/src/components/locomotion.md +++ b/src/components/locomotion.md @@ -37,8 +37,10 @@ This makes it possible to move around the using the following controls. | Method | Description | | -------------------- | ------------------------------------------------------------------------------------------------------ | | teleport(pos, force) | Teleport to given position. if `force` is `true`, player will pass through walls/floors along the way. | +| move(delta) | Move by given vector. | | toggleCrouch(reset) | Toggle crouch mode. if `reset` is `true`, player height will be reset to default. | | jump() | Make the player jump if possible. | +| stopFall() | Stop the fall momentarily. | ## Events @@ -46,6 +48,7 @@ This makes it possible to move around the using the following controls. | Event | Description | | ----- | -------------------------------------------- | | step | Every time the player takes a simulated step | +| bump | Player bumps into wall | ## Related components diff --git a/src/components/locomotion/wall.md b/src/components/locomotion/wall.md index 76ae8f0..478e1cc 100644 --- a/src/components/locomotion/wall.md +++ b/src/components/locomotion/wall.md @@ -12,3 +12,10 @@ Add the `wall` component to any object you want the player not to be able to wal | Property | Description | Default | | ---------- | ------------------------------------------------------------ | ------- | | physics | Whether or not to add physics components automatically. | true | + + +## Events + +| Event | Description | +| ----- | ---------------------- | +| bump | Player bumps into wall | From df0c851bccf102c4ed6e246e75577249934ab2ef Mon Sep 17 00:00:00 2001 From: poeticAndroid Date: Sun, 4 Jul 2021 18:33:00 +0200 Subject: [PATCH 9/9] v0.15.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 673b786..722815e 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.14.9", + "version": "0.15.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 f75a43b..464296f 100644 --- a/dist/a-game.min.js +++ b/dist/a-game.min.js @@ -1 +1 @@ -!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":8,"./components/injectplayer":9,"./components/locomotion":10,"./components/onevent":14,"./components/onstate":15,"./components/physics":16,"./components/trigger":20,"./libs/betterRaycaster":21,"./libs/copyWorldPosRot":23,"./libs/ensureElement":24,"./libs/pools":25,"./libs/touchGestures":26,"./primitives/a-hand":27,"./primitives/a-main":28,"./primitives/a-player":29}],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._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.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/climbable":4,"./grabbing/fingerflex":5,"./grabbing/grabbable":6,"./grabbing/receptacle":7}],4:[function(t,e,i){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion"),this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._onBump=this._onBump.bind(this),setTimeout((()=>{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)},pause(){this._player.removeEventListener("bump",this._onBump)},tick(){if(!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._onBump(),this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos)},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()},drop(t){this._climbing=!1}},_onBump(t){this._player.components.grabbing.dropObject(this.el)}})},{}],5:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],6:[function(t,e,i){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")}}})},{}],7:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],8:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],9:[function(t,e,i){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"})}})},{}],10:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this.move(i),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,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(s),e.object3D.position.add(s),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(s),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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],13:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){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)}})},{}],16:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":22,"./physics/body":17,"./physics/joint":18,"./physics/shape":19}],17:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":22}],18:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":22}],19:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":22}],20:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],22:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],23:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],24:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],25:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],26:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],29:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); +!function t(e,i,s){function o(a,r){if(!i[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=i[a]={exports:{}};e[a][0].call(c.exports,(function(t){return o(e[a][1][t]||t)}),c,c.exports,t,e,i,s)}return i[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,i){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/trigger"),t("./primitives/a-hand"),t("./primitives/a-main"),t("./primitives/a-player");const s=t("../package");console.log(`${s.title} Version ${s.version} by ${s.author}\n(${s.homepage})`)},{"../package":1,"./components/grabbing":3,"./components/include":8,"./components/injectplayer":9,"./components/locomotion":10,"./components/onevent":14,"./components/onstate":15,"./components/physics":16,"./components/trigger":20,"./libs/betterRaycaster":21,"./libs/copyWorldPosRot":23,"./libs/ensureElement":24,"./libs/pools":25,"./libs/touchGestures":26,"./primitives/a-hand":27,"./primitives/a-main":28,"./primitives/a-player":29}],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._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.reticle=this._head.ray.ensure(".reticle","a-sphere",{class:"reticle",radius:.015625,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 i=.25;for(let s=0;s<5;s++)this.emit("fingerflex",this[e].glove,this[e].grabbed,{hand:t,finger:s,flex:i})}},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.emit("drop",this[e].glove,this[e].grabbed),this.el.removeState("grabbing"),this[e].grabbed&&(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 i="_"+t;this.emit("usedown",this[i].glove,this[i].grabbed,{button:e})},useUp(t="head",e=0){let i="_"+t;this.emit("useup",this[i].glove,this[i].grabbed,{button:e})},moveHeadHand(t=0,e=0,i=0,s=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,i,s,1).normalize();this._head.anchor.object3D.quaternion.premultiply(o)},emit(t,e,i,s={}){s.grabbing=this.el,s.grabbedElement=i,s.gloveElement=e;for(let t of this._hands)this["_"+t].glove===e&&(s.hand=t);e.emit(t,s),i&&i.emit(t,s)},_enableHands(){for(let t of this._hands){let e="_"+t;this[e].hand.removeEventListener("buttonchanged",this._enableHands);let i=.0625;this[e].glove.ensure(".hitbox","a-box",{class:"hitbox",visible:!1,position:"0 0 0.03125",width:i/2,height:i,depth:2*i}),this[e].glove.setAttribute("body","type:kinematic;"),"head"!==t&&(this[e]._occlusionRay=this.el.sceneEl.ensure(".occlusion-ray."+t,"a-entity",{class:"occlusion-ray "+t,raycaster:{objects:"[wall]",autoRefresh:!1}}))}let t=this._left.glove.querySelector(".palm")||this._left.glove;this._left.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"-0.0625 0 0.0625",rotation:"0 -45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),t=this._right.glove.querySelector(".palm")||this._right.glove,this._right.ray=t.ensure(".grabbing-ray","a-entity",{class:"grabbing-ray",position:"0.0625 0 0.0625",rotation:"0 45 0",raycaster:{objects:"[wall], [grabbable]",autoRefresh:!1}}),this._left.anchor=this._left.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._right.anchor=this._right.ray.ensure(".grabbing.anchor","a-entity",{class:"grabbing anchor",visible:"false",body:"type:kinematic;autoShape:false;"}),this._left.glove.setAttribute("visible",!0),this._right.glove.setAttribute("visible",!0),this._head.ray=null,this.update()},_ensureGlove(t){let e=t.getAttribute("side"),i=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,i){let s="_"+t;if(e<5)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i});else for(e-=5;e<5;e++)this.emit("fingerflex",this[s].glove,this[s].grabbed,{hand:t,finger:e,flex:i})},_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){return t.shiftKey&&this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,0,0,-.125):t.shiftKey&&this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,0,0,.125):t.shiftKey&&t.deltaY>0?this.moveHeadHand(0,0,-.125):t.shiftKey&&t.deltaY<0?this.moveHeadHand(0,0,.125):this._keysDown.KeyX&&t.deltaY>0?this.moveHeadHand(0,.125):this._keysDown.KeyX&&t.deltaY<0?this.moveHeadHand(0,-.125):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,i=-1,s=0;switch(t.detail.state.touched&&(s=.5),t.detail.state.pressed&&(s=1),t.detail.state.value&&(s=.5+t.detail.state.value/2),this._btnFlex[e+t.detail.id]=s,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,s=Math.max(this._btnFlex[e+3]||0,this._btnFlex[e+4]||0,this._btnFlex[e+5]||0);break;case 4:i=0,s=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,s=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&&(i=5,s=0),this._flexFinger(e,i,s)}}),t("./grabbing/climbable"),t("./grabbing/fingerflex"),t("./grabbing/grabbable"),t("./grabbing/receptacle")},{"./grabbing/climbable":4,"./grabbing/fingerflex":5,"./grabbing/grabbable":6,"./grabbing/receptacle":7}],4:[function(t,e,i){AFRAME.registerComponent("climbable",{dependencies:["wall"],schema:{},init(){this.el.setAttribute("grabbable","physics:false; kinematicGrab:false;"),this._player=this.el.sceneEl.querySelector("[locomotion"),this._quat=new THREE.Quaternion,this._lpos=new THREE.Vector3,this._wpos=new THREE.Vector3,this._handpos=new THREE.Vector3,this._onBump=this._onBump.bind(this),setTimeout((()=>{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)},pause(){this._player.removeEventListener("bump",this._onBump)},tick(){if(!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._onBump(),this.el.object3D.quaternion.copy(this._quat),this.el.object3D.position.copy(this._lpos)},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()},drop(t){this._climbing=!1}},_onBump(t){this._player.components.grabbing.dropObject(this.el)}})},{}],5:[function(t,e,i){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],i=this._currentFlex[t],s=this._targetFlex[t];i+=Math.random()*Math.random()*(s-i);let o=this.data.min+i*(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]=i}},events:{fingerflex(t){this._targetFlex[t.detail.finger]=t.detail.flex}}})},{}],6:[function(t,e,i){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")}}})},{}],7:[function(t,e,i){AFRAME.registerComponent("receptacle",{schema:{objects:{type:"string",default:"[grabbable]"},radius:{type:"number",default:.125}},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):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.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.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(),i=THREE.Vector3.temp(),s=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(i.set(0,0,0)),s.copy(i).sub(e),t>s.length()&&(t=s.length(),this.nearest=o)})))}})},{}],8:[function(t,e,i){AFRAME.registerComponent("include",{schema:{type:"string"},init:async function(){if(this.data&&!this.el.sceneEl._including_){this.el.sceneEl._including_=!0;let t=this.el.outerHTML,e=t.indexOf(" "),i=t.indexOf(" include="),s=t.substr(e,i-e);e=t.indexOf('"',i+10)+1,i=t.indexOf(">"),s+=t.substr(e,i-e);let o=await fetch(this.data);o.status>=200&&o.status<300?this.el.outerHTML=await(await o.text()).replace(">"," >").replace(" "," "+s+" "):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()}}})},{}],9:[function(t,e,i){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"})}})},{}],10:[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 i=THREE.Vector3.temp().copy(this.headPos).sub(this.feetPos);if(i.y=0,(i.length()>.5||!this.currentFloor)&&(this.currentFloor&&i.multiplyScalar(.1),this._legs.object3D.position.add(i),this.feetPos.add(i)),!this._godMode&&!this._caution){let t=this._legs.components.raycaster;t.refreshObjects();let i=t.intersections[0];if(i&&this._vertVelocity<=0){if(this._vertVelocity=0,this.currentFloor===i.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"),i.el.emit("enter");this.move(THREE.Vector3.temp().set(0,.5-i.distance,0)),this.currentFloor=i.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 s=THREE.Vector3.temp();if(s.copy(this.feetPos).sub(this.lastStep),s.length()>this.data.stepLength)for(this.currentFloor&&(this.el.emit("step"),this.currentFloor.emit("step"));s.length()>this.data.stepLength;)s.multiplyScalar(this.data.stepLength/s.length()),this.lastStep.add(s),s.copy(this.feetPos).sub(this.lastStep)},teleport(t,e){let i=THREE.Vector3.temp();i.copy(t).sub(this.feetPos),this.move(i),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,i=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=i>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 i=THREE.Matrix3.temp(),s=THREE.Vector3.temp();s.copy(t),s.sub(e.object3D.position);let o=s.length();if(o){e.setAttribute("raycaster","far",o+.125),e.setAttribute("raycaster","direction",`${s.x} ${s.y} ${s.z}`);let n=e.components.raycaster;n.refreshObjects();let a=n.intersections[0];if(a){this.el.removeAttribute("animation"),i.getNormalMatrix(a.el.object3D.matrixWorld),s.copy(a.face.normal).applyMatrix3(i).normalize().multiplyScalar(o+.125);let t=this._legs.object3D.position.y;this.move(s),e.object3D.position.add(s),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(s),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 i=THREE.Vector2.temp().set(this.headDir.z,-this.headDir.x).angle()-Math.PI,s=Math.cos(i)*e.x-Math.sin(i)*e.y,o=Math.sin(i)*e.x+Math.cos(i)*e.y,n=THREE.Vector3.temp().set(s,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(),i=0;if(this.quantizeRotation?Math.round(e.x)?this._rotating||(this._rotating=!0,i=-Math.round(e.x)*Math.PI/4):this._rotating=!1:i=-e.x*this.data.rotationSpeed*t,i){let t=THREE.Vector2.temp(),e=THREE.Vector2.temp(),s=THREE.Vector3.temp();t.set(this.feetPos.x,this.feetPos.z),e.set(this.centerPos.x,this.centerPos.z),t.rotateAround(e,-i),s.set(this.feetPos.x-t.x,0,this.feetPos.z-t.y),this.el.object3D.rotateY(i),this.el.object3D.position.add(s),this.centerPos.add(s)}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(),i=THREE.Vector3.temp(),s=THREE.Matrix3.temp();i.copy(hit.point).sub(this.feetPos),i.y>1.5&&i.multiplyScalar(0),i.length()>this.data.teleportDistance&&i.normalize().multiplyScalar(this.data.teleportDistance),i.add(this.feetPos),this._teleportCursor.object3D.position.copy(i),this._teleportCursor.object3D.parent.worldToLocal(this._teleportCursor.object3D.position),s.getNormalMatrix(hit.el.object3D.matrixWorld),i.copy(hit.face.normal).applyMatrix3(s).normalize(),i.applyQuaternion(t.copy(this.el.object3D.quaternion).conjugate()),e.set(0,1,0),t.setFromUnitVectors(e,i),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 i=0;ie/2&&(this._rightTouchId=s.identifier,this._rightTouchCenter.set(s.clientX,s.clientY))}t.preventDefault()},_onTouchMove(t){for(let e=0;e32&&(o.multiplyScalar((o.length()-32)/o.length()),s.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)}})},{}],13:[function(t,e,i){AFRAME.registerComponent("wall",{schema:{physics:{type:"boolean",default:!0}},update(){this.data.physics&&!this.el.getAttribute("body")&&this.el.setAttribute("body","type:static")}})},{}],14:[function(t,e,i){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)}})},{}],15:[function(t,e,i){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)}})},{}],16:[function(t,e,i){const s=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 "+s.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 = "+s.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 i=this.buffers.shift();if(i.length<8*this.movingBodies.length){let t=i.length;for(;t<8*this.movingBodies.length;)t*=2;let e=this.movingBodies;i=new Float64Array(t),i.fill(NaN);let s=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(),i=this.bodies[e];i&&i.components.body.command(t)}},eval(t){this.worker.postMessage("world eval "+s.stringifyParam(t))}}),t("./physics/body"),t("./physics/shape"),t("./physics/joint")},{"../../package":1,"../libs/cmdCodec":22,"./physics/body":17,"./physics/joint":18,"./physics/shape":19}],17:[function(t,e,i){const s=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,i=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=i.indexOf(null),this.mid<0&&(this.mid=i.length),i[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 "+s.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 = "+s.stringifyParam(n.position)),t.postMessage("world body "+this.id+" quaternion = "+s.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 = "+s.stringifyParam(this.data.type)),this.data.mass!==t.mass&&e.postMessage("world body "+this.id+" mass = "+s.stringifyParam(this.data.mass)),this.data.friction!==t.friction&&e.postMessage("world body "+this.id+" friction = "+s.stringifyParam(this.data.friction)),this.data.restitution!==t.restitution&&e.postMessage("world body "+this.id+" restitution = "+s.stringifyParam(this.data.restitution)),this.data.belongsTo!==t.belongsTo&&e.postMessage("world body "+this.id+" belongsTo = "+s.stringifyParam(this.data.belongsTo)),this.data.collidesWith!==t.collidesWith&&e.postMessage("world body "+this.id+" collidesWith = "+s.stringifyParam(this.data.collidesWith)),this.data.emitsWith!==t.emitsWith&&e.postMessage("world body "+this.id+" emitsWith = "+s.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,i=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 s=this.el.querySelectorAll("[shape]");s&&s.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&&(i[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 i=this.el.object3D.localToWorld(THREE.Vector3.temp().set(0,0,0));e[t++]=i.x,e[t++]=i.y,e[t++]=i.z,this.sleeping=!!e[t++];let s=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());e[t++]=s.x,e[t++]=s.y,e[t++]=s.z,e[t++]=s.w}else if(e[t+1]){let i=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(i),this.el.object3D.quaternion.multiply(i.conjugate().normalize()),i.set(e[t++],e[t++],e[t++],e[t++]),this.el.object3D.quaternion.multiply(i.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 "+s.stringifyParam(t))},commit(){let t=this.el.sceneEl.systems.physics.worker,e=THREE.Vector3.temp(),i=THREE.Quaternion.temp();this.el.object3D.localToWorld(e.set(0,0,0)),t.postMessage("world body "+this.id+" position "+s.stringifyParam(e)),this.el.object3D.getWorldQuaternion(i),t.postMessage("world body "+this.id+" quaternion "+s.stringifyParam(i))}})},{"../../libs/cmdCodec":22}],18:[function(t,e,i){const s=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 i={};i.type=this.data.type,i.body1=this.data.body1?this.data.body1.components.body.id:this.el.components.body.id,i.body2=this.data.body2.components.body.id,i.pivot1=THREE.Vector3.temp().copy(this.data.pivot1),i.pivot2=THREE.Vector3.temp().copy(this.data.pivot2),i.axis1=this.data.axis1,i.axis2=this.data.axis2,i.min=this.data.min,i.max=this.data.max,i.collision=this.data.collision;let o=this.el.object3D.getWorldScale(THREE.Vector3.temp());i.pivot1.multiply(o),i.pivot2.multiply(o),t.postMessage("world joint "+this._id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":22}],19:[function(t,e,i){const s=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 i={};i.position=this.el.object3D.getWorldPosition(THREE.Vector3.temp()),this.body.object3D.worldToLocal(i.position),i.quaternion=this.el.object3D.getWorldQuaternion(THREE.Quaternion.temp());let o=this.body.object3D.getWorldQuaternion(THREE.Quaternion.temp());switch(i.quaternion.multiply(o.conjugate().normalize()).normalize(),i.size=THREE.Vector3.temp().set(1,1,1),this.el.tagName.toLowerCase()){case"a-sphere":i.type="sphere",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1));break;case"a-cylinder":i.type="cylinder",i.size.multiplyScalar(2*parseFloat(this.el.getAttribute("radius")||1)).y=parseFloat(this.el.getAttribute("height")||1);break;case"a-box":i.type="box",i.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());i.size.multiply(n),i.position.multiply(n),t.postMessage("world body "+this.bodyId+" shape "+this.id+" create "+s.stringifyParam(i))},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 "+s.stringifyParam(t))}})},{"../../libs/cmdCodec":22}],20:[function(t,e,i){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(),i=parseFloat(this.el.getAttribute("width")||1),s=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)}}},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),s.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}},{}],22:[function(t,e,i){e.exports={parse(t){let e=t.split(" "),i=[];for(let t of e)if(t)try{i.push(JSON.parse(t))}catch(e){"="!==t&&i.push(t)}return i},stringifyParam:t=>JSON.stringify(t).replaceAll(" ","\\u0020").replaceAll('"_','"')}},{}],23:[function(t,e,i){AFRAME.AEntity.prototype.copyWorldPosRot=function(t){let e=THREE.Quaternion.temp(),i=t.object3D,s=this.object3D;i&&s&&s.parent&&(i.localToWorld(s.position.set(0,0,0)),s.parent.worldToLocal(s.position),s.getWorldQuaternion(e),s.quaternion.multiply(e.conjugate().normalize()),i.getWorldQuaternion(e),s.quaternion.multiply(e.normalize()))}},{}],24:[function(t,e,i){Element.prototype.ensure=function(t,e=t,i={},s=""){let o,n,a;if(o=this.querySelector(t),!o){for(n in o=document.createElement(e),this.appendChild(o),i)a=i[n],o.setAttribute(n,a);o.innerHTML=s}return o}},{}],25:[function(t,e,i){function s(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}}s(THREE.Vector2),s(THREE.Vector3),s(THREE.Quaternion),s(THREE.Matrix3),s(THREE.Matrix4)},{}],26:[function(t,e,i){let s=Element.prototype.addEventListener,o=Element.prototype.removeEventListener,n=t=>{if(t._tgest)return t._tgest;let e,i,s,o;t._tgest={handlers:{swipeup:[],swipedown:[],swipeleft:[],swiperight:[],tap:[],hold:[]}};let n=(e,i)=>{if(t._tgest.handlers[e])for(let s of t._tgest.handlers[e])s(i);else console.log(e,t._tgest.handlers[e])};return t.addEventListener("touchstart",(t=>{e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY,o=!1,s=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(i-r,2))>32){if(clearTimeout(s),o)return;Math.abs(e-a)>Math.abs(i-r)?n(a{clearTimeout(s);let a=t.changedTouches[0].screenX,r=t.changedTouches[0].screenY;if(Math.sqrt(Math.pow(e-a,2)+Math.pow(i-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 s.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 i=n(this),s=i.handlers[t].indexOf(e);s>=0&&i.handlers[t].splice(s,1);break;default:return o.call(this,t,e)}}},{}],27:[function(t,e,i){AFRAME.registerPrimitive("a-hand",{mappings:{side:"tracked-controls.hand"}})},{}],28:[function(t,e,i){AFRAME.registerPrimitive("a-main",{})},{}],29:[function(t,e,i){AFRAME.registerPrimitive("a-player",{defaultComponents:{injectplayer:{}}})},{}]},{},[2]); diff --git a/package-lock.json b/package-lock.json index 6dddc0e..556929f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "a-game", - "version": "0.14.9", + "version": "0.15.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7ea39a4..73237d1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "a-game", "title": "A-Game", - "version": "0.14.9", + "version": "0.15.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": [