Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axismove for touch and vive #2513

Merged
merged 22 commits into from
Apr 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0fb4e70
add axes mapping, axismove handler, as well as tests ... details follow
machenmusik Feb 20, 2017
24d1e72
make buttons in mapping an array
machenmusik Mar 24, 2017
03b9645
one line, per discussion on PR
machenmusik Mar 27, 2017
fa09983
fix typo, abutton -> bbutton
machenmusik Mar 28, 2017
60bbf95
fix spurious lines from rebase
machenmusik Apr 7, 2017
1c97bd5
make daydream-controls use new axis/button pattern
machenmusik Apr 7, 2017
0f2cb4f
given gamepadconnected behavior, don't use it
machenmusik Apr 12, 2017
6a030d9
isOculusTouch no longer a method to test; update tests for removed an…
machenmusik Apr 13, 2017
f204381
move isEmulatedTouchEvent to utils; add emulated touch to Vive trigger
machenmusik Apr 13, 2017
c48fe0d
Nightly will be sending touched, so don't emulate touches anymore
machenmusik Apr 14, 2017
5b8fdc5
suppress trigger touch events, since we're emulating them
machenmusik Apr 14, 2017
8b9380e
remove vive emulated touch per discussion on PR
machenmusik Apr 14, 2017
9bb1b58
remove isEmulatedTouchEvent
machenmusik Apr 14, 2017
299d2c1
minor edit per discussion
machenmusik Apr 14, 2017
41a1b55
add gearvr-controls
machenmusik Mar 31, 2017
a3e96c9
per discussion on 3DOF controllers, accept either hand by default
machenmusik Apr 11, 2017
10ae085
update docs to reflect default to either hand
machenmusik Apr 11, 2017
16ba6de
update to use proper model, thanks @mkeblx
machenmusik Apr 14, 2017
0dd0da0
bring gearvr-controls in line with #2513
machenmusik Apr 14, 2017
1f37fce
Merge branch 'master' into axismove-for-touch-and-vive
machenmusik Apr 14, 2017
2c3c3a4
refactor emitIfAxesChanged into utils
machenmusik Apr 14, 2017
4e5c303
Merge branch 'axismove-for-touch-and-vive' of github.com:chenzlabs/af…
machenmusik Apr 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions docs/components/oculus-touch-controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,43 @@ mappings, events, and a Touch controller model.
| triggerup | Trigger released. |
| triggertouchstart | Trigger touched. |
| triggertouchend | Trigger no longer touched. |
| triggerchanged | Trigger changed. |
| thumbstickdown | Thumbstick pressed. |
| thumbstickup | Thumbstick released. |
| thumbsticktouchstart | Thumbstick touched. |
| thumbsticktouchend | Thumbstick no longer touched. |
| thumbstickchanged | Thumbstick changed. |
| gripdown | Grip button pressed. |
| gripup | Grip button released. |
| griptouchstart | Grip button touched. |
| griptouchend | Grip button no longer touched. |
| Adown | A button pressed. |
| Aup | A button released. |
| Atouchstart | A button touched. |
| Atouchend | A button no longer touched. |
| Bdown | B button pressed. |
| Bup | B button released. |
| Btouchstart | B button touched. |
| Btouchend | B button no longer touched. |
| Xdown | X button pressed. |
| Xup | X button released. |
| Xtouchstart | X button touched. |
| Xtouchend | X button no longer touched. |
| Ydown | Y button pressed. |
| Yup | Y button released. |
| Ytouchstart | Y button touched. |
| Ytouchend | Y button no longer touched. |
| gripchanged | Grip button changed. |
| abuttondown | A button pressed. |
| abuttonup | A button released. |
| abuttontouchstart | A button touched. |
| abuttontouchend | A button no longer touched. |
| abuttonchanged | A button changed. |
| bbuttondown | B button pressed. |
| bbuttonup | B button released. |
| bbuttontouchstart | B button touched. |
| bbuttontouchend | B button no longer touched. |
| bbuttonchanged | B button changed. |
| xbuttondown | X button pressed. |
| xbuttonup | X button released. |
| xbuttontouchstart | X button touched. |
| xbuttontouchend | X button no longer touched. |
| xbuttonchanged | X button changed. |
| ybuttondown | Y button pressed. |
| ybuttonup | Y button released. |
| ybuttontouchstart | Y button touched. |
| ybuttontouchend | Y button no longer touched. |
| ybuttonchanged | Y button changed. |
| menudown | Menu button pressed. |
| menuup | Menu button released. |
| menuchanged | Menu button changed. |
| systemdown | System button pressed. |
| systemup | System button released. |
| systemchanged | System button changed. |

## Assets

Expand Down
29 changes: 17 additions & 12 deletions docs/components/vive-controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,23 @@ buttons (trigger, grip, menu, system) and trackpad.

## Events

| Event Name | Description |
| ---------- | ----------- |
| gripdown | Grip button pressed. |
| gripup | Grip button released. |
| menudown | Menu button pressed. |
| menuup | Menu button released. |
| systemdown | System button pressed. |
| systemup | System button released. |
| trackpaddown | Trackpad pressed. |
| trackpadup | Trackpad released. |
| triggerdown | Trigger pressed. |
| triggerup | Trigger released. |
| Event Name | Description |
| ---------- | ----------- |
| gripdown | Grip button pressed. |
| gripup | Grip button released. |
| gripchanged | Grip button changed. |
| menudown | Menu button pressed. |
| menuup | Menu button released. |
| menuchanged | Menu button changed. |
| systemdown | System button pressed. |
| systemup | System button released. |
| systemchanged | System button changed. |
| trackpaddown | Trackpad pressed. |
| trackpadup | Trackpad released. |
| trackpadchanged | Trackpad button changed. |
| triggerdown | Trigger pressed. |
| triggerup | Trigger released. |
| triggerchanged | Trigger changed. |

## Assets

Expand Down
55 changes: 24 additions & 31 deletions src/components/daydream-controls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var registerComponent = require('../core/component').registerComponent;
var bind = require('../utils/bind');
var isControllerPresent = require('../utils/tracked-controls').isControllerPresent;
var emitIfAxesChanged = require('../utils/tracked-controls').emitIfAxesChanged;

var DAYDREAM_CONTROLLER_MODEL_BASE_URL = 'https://cdn.aframe.io/controllers/google/';
var DAYDREAM_CONTROLLER_MODEL_OBJ_URL = DAYDREAM_CONTROLLER_MODEL_BASE_URL + 'vr_controller_daydream.obj';
Expand Down Expand Up @@ -29,20 +30,21 @@ module.exports.Component = registerComponent('daydream-controls', {
// 1 - menu ( never dispatched on this layer )
// 2 - system ( never dispatched on this layer )
mapping: {
axis0: 'trackpad',
axis1: 'trackpad',
button0: 'trackpad',
button1: 'menu',
button2: 'system'
axes: {'trackpad': [0, 1]},
buttons: ['trackpad', 'menu', 'system']
},

// Use these labels for detail on axis events such as thumbstickmoved.
// e.g. for thumbstickmoved detail, the first axis returned is labeled x, and the second is labeled y.
axisLabels: ['x', 'y', 'z', 'w'],

bindMethods: function () {
this.onModelLoaded = bind(this.onModelLoaded, this);
this.onControllersUpdate = bind(this.onControllersUpdate, this);
this.checkIfControllerPresent = bind(this.checkIfControllerPresent, this);
this.removeControllersUpdateListener = bind(this.removeControllersUpdateListener, this);
this.onGamepadConnected = bind(this.onGamepadConnected, this);
this.onGamepadDisconnected = bind(this.onGamepadDisconnected, this);
this.onAxisMoved = bind(this.onAxisMoved, this);
this.onGamepadConnectionEvent = bind(this.onGamepadConnectionEvent, this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of this since we can do window.addEventListener('gamepaddisconnected', this.checkIfControllerPresent, false);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below comment on the everGotGamepadEvent flag

},

init: function () {
Expand All @@ -58,6 +60,7 @@ module.exports.Component = registerComponent('daydream-controls', {
this.lastControllerCheck = 0;
this.bindMethods();
this.isControllerPresent = isControllerPresent; // to allow mock
this.emitIfAxesChanged = emitIfAxesChanged; // to allow mock
},

addEventListeners: function () {
Expand Down Expand Up @@ -87,40 +90,33 @@ module.exports.Component = registerComponent('daydream-controls', {
if (isPresent) { this.injectTrackedControls(); } // inject track-controls
},

onGamepadConnected: function (evt) {
// for now, don't disable controller update listening, due to
// apparent issue with FF Nightly only sending one event and seeing one controller;
// this.everGotGamepadEvent = true;
// this.removeControllersUpdateListener();
this.checkIfControllerPresent();
},

onGamepadDisconnected: function (evt) {
// for now, don't disable controller update listening, due to
// apparent issue with FF Nightly only sending one event and seeing one controller;
// this.everGotGamepadEvent = true;
// this.removeControllersUpdateListener();
onGamepadConnectionEvent: function (evt) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of this method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below comment on the everGotGamepadEvent flag

this.everGotGamepadEvent = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag is never checked

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can see why in the comments, but yeah we can remove them for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it is checked in onControllersUpdate (which last I recall is actually fired every tick). so the idea is that if you got gamepad connect/disconnect events, you don't always need to be checking to see when it shows up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to set the flag to false on gamepaddisconnected?

Copy link
Contributor Author

@machenmusik machenmusik Apr 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no because we expect gamepadconnected next time since we're getting events, right? so we don't need to poll every tick

// Due to an apparent bug in FF Nightly
// where only one gamepadconnected / disconnected event is fired,
// which makes it difficult to handle in individual controller entities,
// we no longer remove the controllersupdate listener as a result.
this.checkIfControllerPresent();
},

play: function () {
this.checkIfControllerPresent();
window.addEventListener('gamepadconnected', this.onGamepadConnected, false);
window.addEventListener('gamepaddisconnected', this.onGamepadDisconnected, false);
this.addControllersUpdateListener();
this.addEventListeners();
window.addEventListener('gamepadconnected', this.onGamepadConnectionEvent, false);
window.addEventListener('gamepaddisconnected', this.onGamepadConnectionEvent, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do window.addEventListener('gamepaddisconnected', this.checkIfControllerPresent, false);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below comment on the everGotGamepadEvent flag

},

pause: function () {
window.removeEventListener('gamepadconnected', this.onGamepadConnected, false);
window.removeEventListener('gamepaddisconnected', this.onGamepadDisconnected, false);
this.removeControllersUpdateListener();
this.removeEventListeners();
this.removeControllersUpdateListener();
window.removeEventListener('gamepadconnected', this.onGamepadConnectionEvent, false);
window.removeEventListener('gamepaddisconnected', this.onGamepadConnectionEvent, false);
},

injectTrackedControls: function () {
var el = this.el;
var data = this.data;
this.addEventListeners();
el.setAttribute('tracked-controls', {idPrefix: GAMEPAD_ID_PREFIX, hand: data.hand, rotationOffset: data.rotationOffset});
if (!this.data.model) { return; }
this.el.setAttribute('obj-model', {
Expand Down Expand Up @@ -155,13 +151,10 @@ module.exports.Component = registerComponent('daydream-controls', {
controllerObject3D.position.set(0, 0, -0.04);
},

onAxisMoved: function (evt) {
if (evt.detail.axis[0] === 0 && evt.detail.axis[1] === 0) { return; }
this.el.emit('trackpadmoved', { x: evt.detail.axis[0], y: evt.detail.axis[1] });
},
onAxisMoved: function (evt) { this.emitIfAxesChanged(this, this.mapping.axes, evt); },

onButtonEvent: function (id, evtName) {
var buttonName = this.mapping['button' + id];
var buttonName = this.mapping.buttons[id];
var i;
if (Array.isArray(buttonName)) {
for (i = 0; i < buttonName.length; i++) {
Expand Down
52 changes: 21 additions & 31 deletions src/components/gearvr-controls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var registerComponent = require('../core/component').registerComponent;
var bind = require('../utils/bind');
var isControllerPresent = require('../utils/tracked-controls').isControllerPresent;
var emitIfAxesChanged = require('../utils/tracked-controls').emitIfAxesChanged;

var GEARVR_CONTROLLER_MODEL_BASE_URL = 'https://cdn.aframe.io/controllers/samsung/';
var GEARVR_CONTROLLER_MODEL_OBJ_URL = GEARVR_CONTROLLER_MODEL_BASE_URL + 'gear_vr_controller.obj';
Expand Down Expand Up @@ -28,19 +29,21 @@ module.exports.Component = registerComponent('gearvr-controls', {
// 0 - trackpad
// 1 - triggeri
mapping: {
axis0: 'trackpad',
axis1: 'trackpad',
button0: 'trackpad',
button1: 'trigger'
axes: {'trackpad': [0, 1]},
buttons: ['trackpad', 'trigger']
},

// Use these labels for detail on axis events such as thumbstickmoved.
// e.g. for thumbstickmoved detail, the first axis returned is labeled x, and the second is labeled y.
axisLabels: ['x', 'y', 'z', 'w'],

bindMethods: function () {
this.onModelLoaded = bind(this.onModelLoaded, this);
this.onControllersUpdate = bind(this.onControllersUpdate, this);
this.checkIfControllerPresent = bind(this.checkIfControllerPresent, this);
this.removeControllersUpdateListener = bind(this.removeControllersUpdateListener, this);
this.onGamepadConnected = bind(this.onGamepadConnected, this);
this.onGamepadDisconnected = bind(this.onGamepadDisconnected, this);
this.onAxisMoved = bind(this.onAxisMoved, this);
this.onGamepadConnectionEvent = bind(this.onGamepadConnectionEvent, this);
},

init: function () {
Expand All @@ -56,6 +59,7 @@ module.exports.Component = registerComponent('gearvr-controls', {
this.lastControllerCheck = 0;
this.bindMethods();
this.isControllerPresent = isControllerPresent; // to allow mock
this.emitIfAxesChanged = emitIfAxesChanged; // to allow mock
},

addEventListeners: function () {
Expand Down Expand Up @@ -85,33 +89,21 @@ module.exports.Component = registerComponent('gearvr-controls', {
if (isPresent) { this.injectTrackedControls(); } // inject track-controls
},

onGamepadConnected: function (evt) {
// for now, don't disable controller update listening, due to
// apparent issue with FF Nightly only sending one event and seeing one controller;
// this.everGotGamepadEvent = true;
// this.removeControllersUpdateListener();
this.checkIfControllerPresent();
},

onGamepadDisconnected: function (evt) {
// for now, don't disable controller update listening, due to
// apparent issue with FF Nightly only sending one event and seeing one controller;
// this.everGotGamepadEvent = true;
// this.removeControllersUpdateListener();
onGamepadConnectionEvent: function (evt) {
this.checkIfControllerPresent();
},

play: function () {
this.checkIfControllerPresent();
window.addEventListener('gamepadconnected', this.onGamepadConnected, false);
window.addEventListener('gamepaddisconnected', this.onGamepadDisconnected, false);
// Note that due to gamepadconnected event propagation issues, we don't rely on events.
window.addEventListener('gamepaddisconnected', this.checkIfControllerPresent, false);
this.addControllersUpdateListener();
this.addEventListeners();
},

pause: function () {
window.removeEventListener('gamepadconnected', this.onGamepadConnected, false);
window.removeEventListener('gamepaddisconnected', this.onGamepadDisconnected, false);
// Note that due to gamepadconnected event propagation issues, we don't rely on events.
window.removeEventListener('gamepaddisconnected', this.checkIfControllerPresent, false);
this.removeControllersUpdateListener();
this.removeEventListeners();
},
Expand All @@ -136,10 +128,11 @@ module.exports.Component = registerComponent('gearvr-controls', {
},

onControllersUpdate: function () {
if (!this.everGotGamepadEvent) { this.checkIfControllerPresent(); }
// Note that due to gamepadconnected event propagation issues, we don't rely on events.
this.checkIfControllerPresent();
},

// No need for onButtonChanged, since Daydream controller has no analog buttons.
// No need for onButtonChanged, since Gear VR controller has no analog buttons.

onModelLoaded: function (evt) {
var controllerObject3D = evt.detail.model;
Expand All @@ -150,13 +143,8 @@ module.exports.Component = registerComponent('gearvr-controls', {
buttonMeshes.trackpad = controllerObject3D.getObjectByName('Touchpad');
},

onAxisMoved: function (evt) {
if (evt.detail.axis[0] === 0 && evt.detail.axis[1] === 0) { return; }
this.el.emit('trackpadmoved', { x: evt.detail.axis[0], y: evt.detail.axis[1] });
},

onButtonEvent: function (id, evtName) {
var buttonName = this.mapping['button' + id];
var buttonName = this.mapping.buttons[id];
var i;
if (Array.isArray(buttonName)) {
for (i = 0; i < buttonName.length; i++) {
Expand All @@ -168,6 +156,8 @@ module.exports.Component = registerComponent('gearvr-controls', {
this.updateModel(buttonName, evtName);
},

onAxisMoved: function (evt) { this.emitIfAxesChanged(this, this.mapping.axes, evt); },

updateModel: function (buttonName, evtName) {
var i;
if (!this.data.model) { return; }
Expand Down
32 changes: 16 additions & 16 deletions src/components/hand-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ module.exports.Component = registerComponent('hand-controls', {
el.addEventListener('griptouchend', this.onGripTouchEnd);
el.addEventListener('thumbstickdown', this.onThumbstickDown);
el.addEventListener('thumbstickup', this.onThumbstickUp);
el.addEventListener('Atouchstart', this.onAorXTouchStart);
el.addEventListener('Atouchend', this.onAorXTouchEnd);
el.addEventListener('Btouchstart', this.onBorYTouchStart);
el.addEventListener('Btouchend', this.onBorYTouchEnd);
el.addEventListener('Xtouchstart', this.onAorXTouchStart);
el.addEventListener('Xtouchend', this.onAorXTouchEnd);
el.addEventListener('Ytouchstart', this.onBorYTouchStart);
el.addEventListener('Ytouchend', this.onBorYTouchEnd);
el.addEventListener('abuttontouchstart', this.onAorXTouchStart);
el.addEventListener('abuttontouchend', this.onAorXTouchEnd);
el.addEventListener('bbuttontouchstart', this.onBorYTouchStart);
el.addEventListener('bbuttontouchend', this.onBorYTouchEnd);
el.addEventListener('xbuttontouchstart', this.onAorXTouchStart);
el.addEventListener('xbuttontouchend', this.onAorXTouchEnd);
el.addEventListener('ybuttontouchstart', this.onBorYTouchStart);
el.addEventListener('ybuttontouchend', this.onBorYTouchEnd);
el.addEventListener('surfacetouchstart', this.onSurfaceTouchStart);
el.addEventListener('surfacetouchend', this.onSurfaceTouchEnd);
},
Expand All @@ -127,14 +127,14 @@ module.exports.Component = registerComponent('hand-controls', {
el.removeEventListener('griptouchend', this.onGripTouchEnd);
el.removeEventListener('thumbstickdown', this.onThumbstickDown);
el.removeEventListener('thumbstickup', this.onThumbstickUp);
el.removeEventListener('Atouchstart', this.onAorXTouchStart);
el.removeEventListener('Atouchend', this.onAorXTouchEnd);
el.removeEventListener('Btouchstart', this.onBorYTouchStart);
el.removeEventListener('Btouchend', this.onBorYTouchEnd);
el.removeEventListener('Xtouchstart', this.onAorXTouchStart);
el.removeEventListener('Xtouchend', this.onAorXTouchEnd);
el.removeEventListener('Ytouchstart', this.onBorYTouchStart);
el.removeEventListener('Ytouchend', this.onBorYTouchEnd);
el.removeEventListener('abuttontouchstart', this.onAorXTouchStart);
el.removeEventListener('abuttontouchend', this.onAorXTouchEnd);
el.removeEventListener('bbuttontouchstart', this.onBorYTouchStart);
el.removeEventListener('bbuttontouchend', this.onBorYTouchEnd);
el.removeEventListener('xbuttontouchstart', this.onAorXTouchStart);
el.removeEventListener('xbuttontouchend', this.onAorXTouchEnd);
el.removeEventListener('ybuttontouchstart', this.onBorYTouchStart);
el.removeEventListener('ybuttontouchend', this.onBorYTouchEnd);
el.removeEventListener('surfacetouchstart', this.onSurfaceTouchStart);
el.removeEventListener('surfacetouchend', this.onSurfaceTouchEnd);
},
Expand Down
Loading