forked from colinfizgig/aframe_Components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaframe-teleport-controls.min.js
1 lines (1 loc) · 12.5 KB
/
aframe-teleport-controls.min.js
1
!function(t){function e(n){if(i[n])return i[n].exports;var r=i[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){function n(t){var e="line"===t.type?2:t.curveNumberPoints;return new a(e,t.curveLineWidth)}function r(t){var e,i,n;return i=document.createElement("a-entity"),i.className="hitEntity",n=document.createElement("a-entity"),n.setAttribute("geometry",{primitive:"torus",radius:t.hitCylinderRadius,radiusTubular:.01}),n.setAttribute("rotation",{x:90,y:0,z:0}),n.setAttribute("material",{shader:"flat",color:t.hitCylinderColor,side:"double",depthTest:!1}),i.appendChild(n),e=document.createElement("a-entity"),e.setAttribute("position",{x:0,y:t.hitCylinderHeight/2,z:0}),e.setAttribute("geometry",{primitive:"cylinder",segmentsHeight:1,radius:t.hitCylinderRadius,height:t.hitCylinderHeight,openEnded:!0}),e.setAttribute("material",{shader:"flat",color:t.hitCylinderColor,side:"double",src:s,transparent:!0,depthTest:!1}),i.appendChild(e),i}function o(t){var e,i;return e=new THREE.PlaneBufferGeometry(100,100),e.rotateX(-Math.PI/2),i=new THREE.MeshBasicMaterial({color:16776960}),new THREE.Mesh(e,i)}var s=i(3),l=i(1),a=i(2);if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(t){for(var e=(this.document||this.ownerDocument).querySelectorAll(t),i=e.length;--i>=0&&e.item(i)!==this;);return i>-1}),AFRAME.registerComponent("teleport-controls",{schema:{type:{default:"parabolic",oneOf:["parabolic","line"]},aimEvent:{default:"aim"},teleportEvent:{default:"teleport"},collisionEntities:{default:""},hitEntity:{type:"selector"},cameraRig:{type:"selector"},hitCylinderColor:{type:"color",default:"#99ff99"},hitCylinderRadius:{default:.25,min:0},hitCylinderHeight:{default:.3,min:0},maxLength:{default:10,min:0,if:{type:["line"]}},curveNumberPoints:{default:30,min:2,if:{type:["parabolic"]}},curveLineWidth:{default:.025},curveHitColor:{type:"color",default:"#99ff99"},curveMissColor:{type:"color",default:"#ff0000"},curveShootingSpeed:{default:5,min:0,if:{type:["parabolic"]}},defaultPlaneSize:{default:100},landingNormal:{type:"vec3",default:"0 1 0"},landingMaxAngle:{default:"45",min:0,max:360}},init:function(){var t,e=this.data,i=this.el;this.active=!1,this.obj=i.object3D,this.hitPoint=new THREE.Vector3,this.hit=!1,this.prevHeightDiff=0,this.referenceNormal=new THREE.Vector3,this.curveMissColor=new THREE.Color,this.curveHitColor=new THREE.Color,this.raycaster=new THREE.Raycaster,this.defaultPlane=o(e.defaultPlaneSize),t=this.teleportEntity=document.createElement("a-entity"),t.classList.add("teleportRay"),t.setAttribute("visible",!1),i.sceneEl.appendChild(this.teleportEntity),this.onAim=this.onAim.bind(this),this.onTeleport=this.onTeleport.bind(this),this.queryCollisionEntities()},update:function(t){var e=this.data,i=this.el,o=AFRAME.utils.diff(e,t);this.referenceNormal.copy(e.landingNormal),this.curveMissColor.set(e.curveMissColor),this.curveHitColor.set(e.curveHitColor),(!this.line||"curveLineWidth"in o||"curveNumberPoints"in o||"type"in o)&&(this.line=n(e),this.teleportEntity.setObject3D("mesh",this.line.mesh)),e.hitEntity?this.hitEntity=e.hitEntity:(!this.hitEntity||"hitCylinderColor"in o||"hitCylinderHeight"in o||"hitCylinderRadius"in o)&&(this.hitEntity&&this.hitEntity.parentNode.removeChild(this.hitEntity),this.hitEntity=r(e),i.sceneEl.appendChild(this.hitEntity)),this.hitEntity.setAttribute("visible",!1),t.aimEvent!==e.aimEvent&&(i.removeEventListener(t.aimEvent,this.onAim),i.addEventListener(e.aimEvent,this.onAim)),t.teleportEvent!==e.teleportEvent&&(i.removeEventListener(t.teleportEvent,this.onTeleport),i.addEventListener(e.teleportEvent,this.onTeleport)),"collisionEntities"in o&&this.queryCollisionEntities()},remove:function(){var t=this.el,e=this.hitEntity,i=this.teleportEntity;e&&e.parentNode.removeChild(e),i&&i.parentNode.removeChild(i),t.sceneEl.removeEventListener("child-attached",this.childAttachHandler),t.sceneEl.removeEventListener("child-detached",this.childDetachHandler)},tick:function(){var t=new THREE.Vector3,e=new THREE.Quaternion,i=new THREE.Vector3,n=new THREE.Vector3,r=new THREE.Vector3,o=new THREE.Vector3;return function(s,a){if(this.active){var h=this.obj.matrixWorld;h.decompose(i,e,n);var c=r.set(0,0,-1).applyQuaternion(e).normalize();this.line.setDirection(c.clone()),t.copy(this.obj.getWorldPosition());var d,u=t.clone();if(this.teleportEntity.setAttribute("visible",!0),this.line.material.color.set(this.curveMissColor),this.hitEntity.setAttribute("visible",!1),this.hit=!1,"parabolic"===this.data.type)for(var A=c.clone().multiplyScalar(this.data.curveShootingSpeed),E=-9.8,p=new THREE.Vector3(0,E,0),y=0;y<this.line.numPoints;y++){var m=y/(this.line.numPoints-1);d=l(t,A,p,m);var v=o.copy(d).sub(u).normalize();if(this.raycaster.far=v.length(),this.raycaster.set(u,v),this.checkMeshCollisions(y,d))break;u.copy(d)}else"line"===this.data.type&&(d=u.add(c.clone().multiplyScalar(this.data.maxLength)),this.raycaster.far=this.data.maxLength,this.raycaster.set(t,c),this.line.setPoint(0,t),this.checkMeshCollisions(1,d))}}}(),queryCollisionEntities:function(){var t,e=this.data,i=this.el;return e.collisionEntities?(t=[].slice.call(i.sceneEl.querySelectorAll(e.collisionEntities)),this.collisionEntities=t,this.childAttachHandler=function(i){i.detail.el.matches(e.collisionEntities)&&t.push(i.detail.el)},i.sceneEl.addEventListener("child-attached",this.childAttachHandler),this.childDetachHandler=function(i){var n;i.detail.el.matches(e.collisionEntities)&&(n=t.indexOf(i.detail.el),n!==-1&&t.splice(n,1))},void i.sceneEl.addEventListener("child-detached",this.childDetachHandler)):void(this.collisionEntities=[])},onAim:function(){this.active=!0},onTeleport:function(t){if(this.active&&(this.active=!1,this.hitEntity.setAttribute("visible",!1),this.teleportEntity.setAttribute("visible",!1),this.hit)){if(this.data.cameraRig){var e=(new THREE.Vector3).copy(this.data.cameraRig.getAttribute("position")),i=e.y+this.hitPoint.y-this.prevHeightDiff,n=new THREE.Vector3(this.hitPoint.x,i,this.hitPoint.z);this.prevHeightDiff=this.hitPoint.y,this.data.cameraRig.setAttribute("position",n)}else{var r=this.el.sceneEl.camera.el,o=(new THREE.Vector3).copy(r.getAttribute("position")),s=o.y+this.hitPoint.y-this.prevHeightDiff,l=new THREE.Vector3(this.hitPoint.x,s,this.hitPoint.z);this.prevHeightDiff=this.hitPoint.y,r.setAttribute("position",l);for(var a=document.querySelectorAll("a-entity[tracked-controls]"),h=0;h<a.length;h++){var c=a[h].getAttribute("position"),d=(new THREE.Vector3).copy(c),u=o.clone().sub(d),A=l.clone().sub(u);a[h].setAttribute("position",A)}}this.el.emit("teleport",{oldPosition:o,newPosition:l,hitPoint:this.hitPoint})}},checkMeshCollisions:function(t,e){var i,n;if(n=this.collisionEntities.map(function(t){return t.getObject3D("mesh")}).filter(function(t){return t}),n=n.length?n:[this.defaultPlane],i=this.raycaster.intersectObjects(n,!0),i.length>0&&!this.hit&&this.isValidNormalsAngle(i[0].face.normal)){var r=i[0].point;this.line.material.color.set(this.curveHitColor),this.hitEntity.setAttribute("position",r),this.hitEntity.setAttribute("visible",!0),this.hit=!0,this.hitPoint.copy(i[0].point);for(var o=t;o<this.line.numPoints;o++)this.line.setPoint(o,this.hitPoint);return!0}return this.line.setPoint(t,e),!1},isValidNormalsAngle:function(t){var e=this.referenceNormal.angleTo(t);return THREE.Math.RAD2DEG*e<=this.data.landingMaxAngle}})},function(t,e){function i(t,e,i,n){return t+e*n+.5*i*n*n}function n(t,e,n,r){var o=new THREE.Vector3;return o.x=i(t.x,e.x,n.x,r),o.y=i(t.y,e.y,n.y,r),o.z=i(t.z,e.z,n.z,r),o}t.exports=n},function(t,e){var i=function(t,e){this.geometry=new THREE.BufferGeometry,this.vertices=new Float32Array(3*t*2),this.uvs=new Float32Array(2*t*2),this.width=e,this.geometry.addAttribute("position",new THREE.BufferAttribute(this.vertices,3).setDynamic(!0)),this.material=new THREE.MeshBasicMaterial({side:THREE.DoubleSide,color:16711680}),this.mesh=new THREE.Mesh(this.geometry,this.material),this.mesh.drawMode=THREE.TriangleStripDrawMode,this.mesh.frustumCulled=!1,this.mesh.vertices=this.vertices,this.direction=new THREE.Vector3,this.numPoints=t};i.prototype={setDirection:function(t){var e=new THREE.Vector3(0,1,0);this.direction.copy(t).cross(e).normalize().multiplyScalar(this.width/2)},setWidth:function(t){this.width=t},setPoint:function(){var t=new THREE.Vector3,e=new THREE.Vector3;return function(i,n){t.copy(n).add(this.direction),e.copy(n).sub(this.direction);var r=6*i;this.vertices[r++]=t.x,this.vertices[r++]=t.y,this.vertices[r++]=t.z,this.vertices[r++]=e.x,this.vertices[r++]=e.y,this.vertices[r++]=e.z,this.geometry.attributes.position.needsUpdate=!0}}()},t.exports=i},function(t,e){t.exports="url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAQCAYAAADXnxW3AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJ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