forked from bryik/aframe-controller-cursor-component
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaframe-controller-cursor-component.min.js
More file actions
1 lines (1 loc) · 2.95 KB
/
aframe-controller-cursor-component.min.js
File metadata and controls
1 lines (1 loc) · 2.95 KB
1
!function(e){function t(r){if(i[r])return i[r].exports;var n=i[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t){var i=AFRAME.utils.bind;if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");var r={CLICK:"click",MOUSEENTER:"mouseenter",MOUSEDOWN:"mousedown",MOUSELEAVE:"mouseleave",MOUSEUP:"mouseup"},n={HOVERING:"cursor-hovering",HOVERED:"cursor-hovered"};AFRAME.registerComponent("controller-cursor",{dependencies:["raycaster"],schema:{color:{default:"#74BEC1"},radius:{default:.001}},init:function(){var e=this.el,t=this.data;this.triggerDownEl=null,this.intersection=null,this.intersectedEl=null;var r=e.sceneEl.canvas;if(!r)return void e.sceneEl.addEventListener("render-target-loaded",i(this.init,this));var n=new THREE.CylinderGeometry(t.radius,t.radius,1e3,32),s=new THREE.MeshBasicMaterial({color:t.color}),o=new THREE.Mesh(n,s);o.position.z=-500,o.rotation.x=90*(Math.PI/180),e.setObject3D("cursormesh",o),e.setAttribute("raycaster",{near:.03}),this.onIntersectionBind=i(this.onIntersection,this),this.onIntersectionClearedBind=i(this.onIntersectionCleared,this),this.onTriggerDownBind=i(this.onTriggerDown,this),this.onTriggerUpBind=i(this.onTriggerUp,this)},play:function(){var e=this.el;e.addEventListener("raycaster-intersection",this.onIntersectionBind),e.addEventListener("raycaster-intersection-cleared",this.onIntersectionClearedBind),e.addEventListener("triggerdown",this.onTriggerDownBind),e.addEventListener("triggerup",this.onTriggerUpBind)},pause:function(){cursorEl.removeEventListener("raycaster-intersection",this.onIntersectionBind),cursorEl.removeEventListener("raycaster-intersection-cleared",this.onIntersectionClearedBind),cursorEl.removeEventListener("triggerdown",this.onTriggerDownBind),cursorEl.removeEventListener("triggerup",this.onTriggerUpBind)},onTriggerDown:function(e){this.twoWayEmit(r.MOUSEDOWN),this.triggerDownEl=this.intersectedEl},onTriggerUp:function(e){this.twoWayEmit(r.MOUSEUP),this.intersectedEl&&this.triggerDownEl===this.intersectedEl&&this.twoWayEmit(r.CLICK)},onIntersection:function(e){var t,i,s,o=this,a=this.el;if(t=e.detail.els[0]===a?1:0,s=e.detail.intersections[t],i=e.detail.els[t]){if(this.intersectedEl===i)return void(this.intersection=s);this.intersectedEl&&this.clearCurrentIntersection(),this.intersection=s,this.intersectedEl=i,a.addState(n.HOVERING),i.addState(n.HOVERED),o.twoWayEmit(r.MOUSEENTER)}},onIntersectionCleared:function(e){var t=this.el,i=e.detail.el;t!==i&&i===this.intersectedEl&&this.clearCurrentIntersection()},clearCurrentIntersection:function(){var e=this.el;this.intersectedEl.removeState(n.HOVERED),e.removeState(n.HOVERING),this.twoWayEmit(r.MOUSELEAVE),this.intersection=null,this.intersectedEl=null},twoWayEmit:function(e){var t=this.el,i=this.intersectedEl,r=this.intersection;t.emit(e,{intersectedEl:i,intersection:r}),i&&i.emit(e,{cursorEl:t,intersection:r})}})}]);