1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
- 'use strict';
- require('./src/misc/grab');
- },{"./src/misc/grab":2}],2:[function(require,module,exports){
- 'use strict';
- /* global CANNON */
- /**
- * Based on aframe/examples/showcase/tracked-controls.
- *
- * Handles events coming from the hand-controls.
- * Determines if the entity is grabbed or released.
- * Updates its position to move along the controller.
- */
- module.exports = AFRAME.registerComponent('grab', {
- init: function init() {
- this.system = this.el.sceneEl.systems.physics;
- this.GRABBED_STATE = 'grabbed';
- this.grabbing = false;
- this.hitEl = /** @type {AFRAME.Element} */null;
- this.physics = /** @type {AFRAME.System} */this.el.sceneEl.systems.physics;
- this.constraint = /** @type {CANNON.Constraint} */null;
- // Bind event handlers
- this.onHit = this.onHit.bind(this);
- this.onGripOpen = this.onGripOpen.bind(this);
- this.onGripClose = this.onGripClose.bind(this);
- },
- play: function play() {
- var el = this.el;
- el.addEventListener('hit', this.onHit);
- el.addEventListener('gripdown', this.onGripClose);
- el.addEventListener('gripup', this.onGripOpen);
- el.addEventListener('trackpaddown', this.onGripClose);
- el.addEventListener('trackpadup', this.onGripOpen);
- el.addEventListener('triggerdown', this.onGripClose);
- el.addEventListener('triggerup', this.onGripOpen);
- },
- pause: function pause() {
- var el = this.el;
- el.removeEventListener('hit', this.onHit);
- el.removeEventListener('gripdown', this.onGripClose);
- el.removeEventListener('gripup', this.onGripOpen);
- el.removeEventListener('trackpaddown', this.onGripClose);
- el.removeEventListener('trackpadup', this.onGripOpen);
- el.removeEventListener('triggerdown', this.onGripClose);
- el.removeEventListener('triggerup', this.onGripOpen);
- },
- onGripClose: function onGripClose() {
- this.grabbing = true;
- },
- onGripOpen: function onGripOpen() {
- var hitEl = this.hitEl;
- this.grabbing = false;
- if (!hitEl) {
- return;
- }
- hitEl.removeState(this.GRABBED_STATE);
- this.hitEl = undefined;
- this.system.removeConstraint(this.constraint);
- this.constraint = null;
- },
- onHit: function onHit(evt) {
- var hitEl = evt.detail.el;
- // If the element is already grabbed (it could be grabbed by another controller).
- // If the hand is not grabbing the element does not stick.
- // If we're already grabbing something you can't grab again.
- if (!hitEl || hitEl.is(this.GRABBED_STATE) || !this.grabbing || this.hitEl) {
- return;
- }
- hitEl.addState(this.GRABBED_STATE);
- this.hitEl = hitEl;
- this.constraint = new CANNON.LockConstraint(this.el.body, hitEl.body);
- this.system.addConstraint(this.constraint);
- }
- });
- },{}]},{},[1]);
|