Skip to content

Commit

Permalink
Support built-in controls. Fix gamepad initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpeiris committed Sep 22, 2016
1 parent 33a33df commit 947afd2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Note that when running in Altspace, the scene will not be synchronized between u
| `verticalAlign` | Puts the scene origin at the bottom, middle, or top of the Altspace enclosure. If your scene seems to be floating in midair, try setting this to 'bottom'. | `middle`

### Usage
Add the "altspace" parameter on your `<a-scene>` like so: `<a-scene altspace>`

Add the "altspace" attribute on your `<a-scene>` like so: `<a-scene altspace>`

#### Example

Expand All @@ -34,3 +34,16 @@ Install and use by directly including the [browser files](dist):
</a-scene>
</body>
```

## altspace-tracked-controls

This library also includes an `altspace-tracked-controls` component that enables tracked control support for A-Frame
applications that use the built-in `tracked-controls`, `vive-controls` or `hand-controls` components.

### Usage

Add the "altspace-tracked-controls" attribute to your tracked entity. For example:

```html
<a-entity hand-controls="right" altspace-tracked-controls></a-entity>
```
31 changes: 27 additions & 4 deletions dist/aframe-altspace-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,34 @@
});

AFRAME.registerComponent('altspace-tracked-controls', {
update: function () {
if (window.altspace && altspace.getGamepads) {
init: function () {
this.gamepadIndex = null;
this.trackedControlsSystem = document.querySelector('a-scene').systems['tracked-controls'];
this.systemGamepads = 0;
altspace.getGamepads();
},
tick: function () {
if (
this.trackedControlsSystem &&
this.systemGamepads !== this.trackedControlsSystem.controllers.length &&
window.altspace && altspace.getGamepads && altspace.getGamepads().length
) {
var components = this.el.components;
if (components['paint-controls']) {
this.gamepadIndex = components['paint-controls'].data.hand === 'left' ? 2 : 1;
}
if (this.gamepadIndex === null && components['hand-controls']) {
this.gamepadIndex = components['hand-controls'].data === 'left' ? 2 : 1;
}
if (this.gamepadIndex === null && components['vive-controls']) {
this.gamepadIndex = components['vive-controls'].data.hand === 'left' ? 2 : 1;
}
if (this.gamepadIndex === null && components['tracked-controls']) {
this.gamepadIndex = components['tracked-controls'].data.controller;
}
this.el.setAttribute('tracked-controls', 'id', altspace.getGamepads()[this.gamepadIndex].id);
this.el.setAttribute('tracked-controls', 'controller', 0);
var gamepadIndex = this.el.components['hand-controls'].data === 'left' ? 2 : 1;
this.el.setAttribute('tracked-controls', 'id', altspace.getGamepads()[gamepadIndex].id);
this.systemGamepads = this.trackedControlsSystem.controllers.length;
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion dist/aframe-altspace-component.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 27 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,34 @@ AFRAME.registerComponent('altspace', {
});

AFRAME.registerComponent('altspace-tracked-controls', {
update: function () {
if (window.altspace && altspace.getGamepads) {
init: function () {
this.gamepadIndex = null;
this.trackedControlsSystem = document.querySelector('a-scene').systems['tracked-controls'];
this.systemGamepads = 0;
altspace.getGamepads();
},
tick: function () {
if (
this.trackedControlsSystem &&
this.systemGamepads !== this.trackedControlsSystem.controllers.length &&
window.altspace && altspace.getGamepads && altspace.getGamepads().length
) {
var components = this.el.components;
if (components['paint-controls']) {
this.gamepadIndex = components['paint-controls'].data.hand === 'left' ? 2 : 1;
}
if (this.gamepadIndex === null && components['hand-controls']) {
this.gamepadIndex = components['hand-controls'].data === 'left' ? 2 : 1;
}
if (this.gamepadIndex === null && components['vive-controls']) {
this.gamepadIndex = components['vive-controls'].data.hand === 'left' ? 2 : 1;
}
if (this.gamepadIndex === null && components['tracked-controls']) {
this.gamepadIndex = components['tracked-controls'].data.controller;
}
this.el.setAttribute('tracked-controls', 'id', altspace.getGamepads()[this.gamepadIndex].id);
this.el.setAttribute('tracked-controls', 'controller', 0);
var gamepadIndex = this.el.components['hand-controls'].data === 'left' ? 2 : 1;
this.el.setAttribute('tracked-controls', 'id', altspace.getGamepads()[gamepadIndex].id);
this.systemGamepads = this.trackedControlsSystem.controllers.length;
}
}
});

0 comments on commit 947afd2

Please sign in to comment.