Skip to content

Commit 3e6cb79

Browse files
machenmusikdmarcos
authored andcommitted
Refactor hand controls, oculus touch support (#2132)
* use Oculus Touch support in Chromium builds using vive-controls and tracked-controls fixes to make Vive work as expected (including hand model rotation) fix various verification issues (whitespace, quotes, eqeqeq) first pass at hand controls refactor refactor working with Touch better explanatory comments; renamed modeled-controllers to auto-detect-controllers for clarity FIXME: need models for Oculus Touch fix lint issues that local git commit hook didn't flag automated tests fail unless tracked-controls id default is 'OpenVR Gamepad' :-/ since each hand named differently, avoid enumeration limit controller list rebuilds to roughly 1 second intervals show that multiple specification works as well as auto-detection allow multiple specification - don't inject tracked-controls if controller not in getGamepads() - don't attach listeners unless controller present - poll for presence at roughly 1 second intervals if no gamepad connection events received per discussion on #2132 remove auto-detect-controllers from core for now (it can be used as external component) per discussion on #2132 remove auto-detect-controllers from core for now (it can be used as external component) per discussion on #2132 tidy up and move enumerateGamepads into utils per further discussion on #2132 change name of Touch thumbstick events and prepare for multiple-event button mappings introduce namespaced vendor-specific events, and hand-specific mappings (since button names differ between hands) per discussion on #2132 use a common controlConfiguration object change start/stopListening to add/removeEventListeners per discussion on #2132 (review) emit event others can listen for on tick use controller list built by system tick rather than re-enumerating instead of having another tick method, listen for system tick distinguish between enumerateGamepads and enumerateControllers - enumerateGamepads interrogates gamepad API - enumerateControllers uses system tick-generated controller list loosen throttle on tick since pose updates at that frequency for consistency with vive-controls, default rotationOffset to 0; where hand rotation is necessary, do it there (e.g. hand-controls) make removeTrackedControlsTickListener accessible ignore undefined button mapping ignore undefined buttonMeshes bind this pointer for gamepad event handlers * updated to use models from @tbalouet fix regression that broke rotationOffset support surface button * use new oculus touch compatible hand models; TODO: emit events for animations/poses change processAnimation() to animate() and simplify flow, and remove superfluous comment, per discussion on #2132 system button never seen/sent; move menu button mapping per discussion on #2132 change member idPrefix to const (and also model URLs) per discussion on #2132 move model selection into addModel per discussion on #2132 refactor to use utils function isControllerPresent per discussion on #2132 emit hand events like original version did original vive-specific events used gripclose/open, not gripup/down remove tracked-controls dependency, since that can apparently cause blank tracked-controls which won't work; synthesize fake touch events for Oculus Touch trigger and grip, since current browser builds appear to have them stuck touched; make hand-controls process and use trigger and grip touches refactor systems/tracked-controls so rebuildControllerList() is available outside tick; explicitly rebuildControllerList if none in isControllerPresent() to avoid race where gamepadconnected event triggers isControllerPresent() before tick rebuilds list add support for Vive touchpad touchstart/end remove enumerateControllers and change enumerateGamepads to getGamepadsByPrefix per discussion on #2132 remove obsoleted lines per discussion on #2132 use models from a-frame cdn once aframevr/assets#4 is merged remove obsoleted comment various code cleanup as requested per discussion on #2132 one more bit of cleanup per discussion on #2132 another round of code cleanup per discussion on #2132 accommodate renaming in aframevr/assets@66314f8 additional code cleanup per discussion on #2132 clean up animation usage remove oculus-touch namespace prefix from Oculus Touch-specific buttons/events refactor into gestures with animation and legacy event mappings, and some cleanup per discussion on #2132 for capacitive tracking, don't use menu button label, use B-or-Y, since at some point we will hopefully get access to the true menu buttons explicitly listen for A, B, X and Y touch events separately (gesture handling still uses AorX and BorY internally) remove A-or-X and B-or-Y event mapping move persisting gesture and change detection into handleButton; animateGesture and emitGestureEvents are now explicitly passed arguments minor code cleanup per discussion on #2132 one-liner cleanup code cleanup as per discussion on #2132 code cleanup and fake touch simplification whitespace cleanup * disable unhooking on gamepad connected/disconnected events for now, as it is causing issues with Nightly added comment on Nightly workaround
1 parent ae69e1d commit 3e6cb79

File tree

17 files changed

+1039
-79
lines changed

17 files changed

+1039
-79
lines changed

‎docs/components/hand-controls.md‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ parent_section: components
77

88
[tracked]: ./tracked-controls.md
99
[vive]: ./vive-controls.md
10+
[oculustouch]: ./oculus-touch-controls.md
1011

1112
The hand-controls gives tracked hands (using a prescribed model) with animated
12-
gestures. It wraps the [vive-controls component][vive], which wraps the
13-
[tracked-controls component][tracked]. It adds extra semantically-named events
14-
and handles hand animations.
13+
gestures. hand-controls wraps the [vive-controls][vive] and
14+
[oculus-touch-controls][oculustouch] components, which in turn wrap the
15+
[tracked-controls component][tracked]. The component gives extra events and
16+
handles hand animations and poses.
1517

1618
## Example
1719

@@ -29,16 +31,20 @@ and handles hand animations.
2931

3032
## Events
3133

32-
| Event Name | Description |
33-
| ---------- | ----------- |
34-
| gripclose | Grip buttons pressed. Hand is closed. |
35-
| gripopen | Grip buttons released. Hand is open. |
36-
| pointup | Trigger button pressed. Index finger pointing up. |
37-
| pointdown | Trigger button released. Index finger pointing down. |
38-
| thumbup | Thumbpad pressed. Thumb is pointing up. |
39-
| thumbdown | Thumbpad released. Thumb is pointing down. |
34+
| Event Name | Description |
35+
| ---------- | ----------- |
36+
| gripclose | The hand is closed into a fist without thumb raised. |
37+
| gripopen | The hand is no longer closed into a fist without thumb raised. |
38+
| pointup | The hand is touching or pressing the trigger only. |
39+
| pointdown | The hand is no longer touching or pressing the trigger only. |
40+
| thumbup | The hand is closed into a fist with thumb raised. |
41+
| thumbdown | The hand is no longer closed into a fist with thumb raised. |
42+
| pointingstart | The hand is pointing with index finger without thumb raised. |
43+
| pointingend | The hand is no longer pointing without thumb raised. |
44+
| pistolstart | The hand is pointing with index finger and thumb raised. |
45+
| pistolend | The hand is no longer pointing with thumb raised. |
4046

4147
## Assets
4248

43-
- [Left hand model](https://media.aframe.io/controllers/hands/leftHand.json)
44-
- [Right hand model](https://media.aframe.io/controllers/hands/rightHand.json)
49+
- [Left hand model](https://cdn.aframe.io/controllers/oculus-hands/leftHand.json)
50+
- [Right hand model](https://cdn.aframe.io/controllers/oculus-hands/rightHand.json)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: oculus-touch-controls
3+
type: components
4+
layout: docs
5+
parent_section: components
6+
---
7+
8+
[trackedcontrols]: ./tracked-controls.md
9+
10+
The oculus-touch-controls component interfaces with the Oculus Touch controllers. It
11+
wraps the [tracked-controls component][trackedcontrols] while adding button
12+
mappings, events, and a Touch controller model.
13+
14+
## Example
15+
16+
```html
17+
<a-entity oculus-touch-controls="hand: left"></a-entity>
18+
<a-entity oculus-touch-controls="hand: right"></a-entity>
19+
```
20+
21+
## Value
22+
23+
| Property | Description | Default Value |
24+
|----------------------|----------------------------------------------------|----------------------|
25+
| hand | The hand that will be tracked (i.e., right, left). | left |
26+
| model | Whether the Touch controller model is loaded. | true |
27+
| rotationOffset | Offset to apply to model rotation. | 0 |
28+
29+
## Events
30+
31+
| Event Name | Description |
32+
| ---------- | ----------- |
33+
| triggerdown | Trigger pressed. |
34+
| triggerup | Trigger released. |
35+
| triggertouchstart | Trigger touched. |
36+
| triggertouchend | Trigger no longer touched. |
37+
| thumbstickdown | Thumbstick pressed. |
38+
| thumbstickup | Thumbstick released. |
39+
| thumbsticktouchstart | Thumbstick touched. |
40+
| thumbsticktouchend | Thumbstick no longer touched. |
41+
| gripdown | Grip button pressed. |
42+
| gripup | Grip button released. |
43+
| griptouchstart | Grip button touched. |
44+
| griptouchend | Grip button no longer touched. |
45+
| Adown | A button pressed. |
46+
| Aup | A button released. |
47+
| Atouchstart | A button touched. |
48+
| Atouchend | A button no longer touched. |
49+
| Bdown | B button pressed. |
50+
| Bup | B button released. |
51+
| Btouchstart | B button touched. |
52+
| Btouchend | B button no longer touched. |
53+
| Xdown | X button pressed. |
54+
| Xup | X button released. |
55+
| Xtouchstart | X button touched. |
56+
| Xtouchend | X button no longer touched. |
57+
| Ydown | Y button pressed. |
58+
| Yup | Y button released. |
59+
| Ytouchstart | Y button touched. |
60+
| Ytouchend | Y button no longer touched. |
61+
| menudown | Menu button pressed. |
62+
| menuup | Menu button released. |
63+
| systemdown | System button pressed. |
64+
| systemup | System button released. |
65+
66+
## Assets
67+
68+
- [Left Controller OBJ](https://cdn.aframe.io/controllers/oculus/oculus-touch-controller-left.obj)
69+
- [Left Controller MTL](https://cdn.aframe.io/controllers/oculus/oculus-touch-controller-left.mtl)
70+
- [Right Controller OBJ](https://cdn.aframe.io/controllers/oculus/oculus-touch-controller-right.obj)
71+
- [Right Controller MTL](https://cdn.aframe.io/controllers/oculus/oculus-touch-controller-right.mtl)

‎docs/components/tracked-controls.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ parent_section: components
66
---
77

88
[handcontrols]: ./hand-controls.md
9+
[oculustouchcontrols]: ./oculus-touch-controls.md
910
[vivecontrols]: ./vive-controls.md
1011

11-
The tracked-controls component interfaces with tracked controllers. The component uses
12-
the Gamepad API to handle tracked controllers. This component choose the
13-
appropriate controller, applies pose to the entity, observes buttons state and
14-
emits appropriate events.
15-
16-
The [hand-controls component][handcontrols] and the [vive-controls
17-
component][vivecontrols] abstract the tracked-controls component further.
12+
The tracked-controls component interfaces with tracked controllers.
13+
tracked-controls uses the Gamepad API to handle tracked controllers, and is
14+
abstracted by the [hand-controls component][handcontrols] as well as the
15+
[vive-controls][vivecontrols] and [oculus-touch-controls][oculustouchcontrols]
16+
components. This component elects the appropriate controller, applies pose to
17+
the entity, observes buttons state and emits appropriate events.
1818

1919
## Example
2020

‎docs/components/vive-controls.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ buttons (trigger, grip, menu, system) and trackpad.
2727
| buttonHighlightColor | Button colors when pressed and active. | #22D1EE (light blue) |
2828
| hand | The hand that will be tracked (i.e., right, left). | left |
2929
| model | Whether the Vive controller model is loaded. | true |
30+
| rotationOffset | Offset to apply to model rotation. | 0 |
3031

3132
## Events
3233

@@ -42,3 +43,9 @@ buttons (trigger, grip, menu, system) and trackpad.
4243
| trackpadup | Trackpad released. |
4344
| triggerdown | Trigger pressed. |
4445
| triggerup | Trigger released. |
46+
47+
## Assets
48+
49+
- [Controller OBJ](https://cdn.aframe.io/controllers/vive/vr_controller_vive.obj)
50+
- [Controller MTL](https://cdn.aframe.io/controllers/vive/vr_controller_vive.mtl)
51+

‎examples/showcase/tracked-controls/components/grab.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ AFRAME.registerComponent('grab', {
6464
var position;
6565
if (!hitEl) { return; }
6666
this.updateDelta();
67-
position = hitEl.getComputedAttribute('position');
67+
position = hitEl.getAttribute('position');
6868
hitEl.setAttribute('position', {
6969
x: position.x + this.deltaPosition.x,
7070
y: position.y + this.deltaPosition.y,
@@ -73,7 +73,7 @@ AFRAME.registerComponent('grab', {
7373
},
7474

7575
updateDelta: function () {
76-
var currentPosition = this.el.getComputedAttribute('position');
76+
var currentPosition = this.el.getAttribute('position');
7777
var previousPosition = this.previousPosition || currentPosition;
7878
var deltaPosition = {
7979
x: currentPosition.x - previousPosition.x,

‎examples/showcase/tracked-controls/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<a-entity hand-controls="right" aabb-collider="objects: .cube;" grab></a-entity>
2727

2828
<!-- A-Frame cubes -->
29-
<a-entity position="0 0 -1">
29+
<a-entity position="0 0 -0.5">
3030
<a-entity class="cube" mixin="cube" position="0.30 1.65 0"></a-entity>
3131
<a-entity class="cube" mixin="cube" position="0 1.95 0"></a-entity>
3232
<a-entity class="cube" mixin="cube" position="-0.30 1.65 0"></a-entity>

0 commit comments

Comments
 (0)