grab.min.js 2.1 KB

1
  1. !function t(i,n,e){function s(o,h){if(!n[o]){if(!i[o]){var p="function"==typeof require&&require;if(!h&&p)return p(o,!0);if(r)return r(o,!0);var a=new Error("Cannot find module '"+o+"'");throw a.code="MODULE_NOT_FOUND",a}var d=n[o]={exports:{}};i[o][0].call(d.exports,function(t){var n=i[o][1][t];return s(n||t)},d,d.exports,t,i,n,e)}return n[o].exports}for(var r="function"==typeof require&&require,o=0;o<e.length;o++)s(e[o]);return s}({1:[function(t,i,n){"use strict";t("./src/misc/grab")},{"./src/misc/grab":2}],2:[function(t,i,n){"use strict";i.exports=AFRAME.registerComponent("grab",{init:function(){this.system=this.el.sceneEl.systems.physics,this.GRABBED_STATE="grabbed",this.grabbing=!1,this.hitEl=null,this.physics=this.el.sceneEl.systems.physics,this.constraint=null,this.onHit=this.onHit.bind(this),this.onGripOpen=this.onGripOpen.bind(this),this.onGripClose=this.onGripClose.bind(this)},play:function(){var t=this.el;t.addEventListener("hit",this.onHit),t.addEventListener("gripdown",this.onGripClose),t.addEventListener("gripup",this.onGripOpen),t.addEventListener("trackpaddown",this.onGripClose),t.addEventListener("trackpadup",this.onGripOpen),t.addEventListener("triggerdown",this.onGripClose),t.addEventListener("triggerup",this.onGripOpen)},pause:function(){var t=this.el;t.removeEventListener("hit",this.onHit),t.removeEventListener("gripdown",this.onGripClose),t.removeEventListener("gripup",this.onGripOpen),t.removeEventListener("trackpaddown",this.onGripClose),t.removeEventListener("trackpadup",this.onGripOpen),t.removeEventListener("triggerdown",this.onGripClose),t.removeEventListener("triggerup",this.onGripOpen)},onGripClose:function(){this.grabbing=!0},onGripOpen:function(){var t=this.hitEl;this.grabbing=!1,t&&(t.removeState(this.GRABBED_STATE),this.hitEl=void 0,this.system.removeConstraint(this.constraint),this.constraint=null)},onHit:function(t){var i=t.detail.el;i&&!i.is(this.GRABBED_STATE)&&this.grabbing&&!this.hitEl&&(i.addState(this.GRABBED_STATE),this.hitEl=i,this.constraint=new CANNON.LockConstraint(this.el.body,i.body),this.system.addConstraint(this.constraint))}})},{}]},{},[1]);