Skip to content

Commit 0d1bb52

Browse files
committed
Align hp-mixed-reality-controls with actual controller orientation
1 parent bbb344f commit 0d1bb52

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/components/hp-mixed-reality-controls.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var bind = require('../utils/bind');
22
var registerComponent = require('../core/component').registerComponent;
3+
var THREE = require('../lib/three');
34

45
var trackedControlsUtils = require('../utils/tracked-controls');
56
var checkControllerPresentAndSetup = trackedControlsUtils.checkControllerPresentAndSetup;
@@ -15,16 +16,19 @@ var GAMEPAD_ID_COMPOSITE = GAMEPAD_ID_PREFIX + GAMEPAD_ID_SUFFIX;
1516

1617
var HP_MIXEDL_REALITY_MODEL_GLB_BASE_URL = 'https://cdn.aframe.io/controllers/hp/mixed-reality/';
1718

19+
var HP_MIXED_REALITY_POSITION_OFFSET = {x: 0, y: 0, z: 0.06};
20+
var HP_MIXED_REALITY_ROTATION_OFFSET = {_x: Math.PI / 4, _y: 0, _z: 0, _order: 'XYZ'};
21+
1822
/**
1923
* Button IDs:
2024
* 0 - trigger
2125
* 1 - grip
22-
* 2 - touchpad
23-
* 3 - menu (never dispatched on this layer)
26+
* 3 - X / A
27+
* 4 - Y / B
2428
*
2529
* Axis:
26-
* 0 - touchpad x axis
27-
* 1 - touchpad y axis
30+
* 2 - joystick x axis
31+
* 3 - joystick y axis
2832
*/
2933
var INPUT_MAPPING_WEBXR = {
3034
left: {
@@ -38,10 +42,7 @@ var INPUT_MAPPING_WEBXR = {
3842
};
3943

4044
/**
41-
* Magic Leap Controls
42-
* Interface with Magic Leap control and map Gamepad events to controller
43-
* buttons: trigger, grip, touchpad, and menu.
44-
* Load a controller model.
45+
* HP Mixed Reality Controls
4546
*/
4647
module.exports.Component = registerComponent('hp-mixed-reality-controls', {
4748
schema: {
@@ -150,9 +151,6 @@ module.exports.Component = registerComponent('hp-mixed-reality-controls', {
150151
this.checkIfControllerPresent();
151152
},
152153

153-
/**
154-
* Rotate the trigger button based on how hard the trigger is pressed.
155-
*/
156154
onButtonChanged: function (evt) {
157155
var button = this.mapping[this.data.hand].buttons[evt.detail.id];
158156
var analogValue;
@@ -167,7 +165,20 @@ module.exports.Component = registerComponent('hp-mixed-reality-controls', {
167165
this.el.emit(button + 'changed', evt.detail.state);
168166
},
169167

170-
onModelLoaded: function (evt) {},
168+
onModelLoaded: function (evt) {
169+
var controllerObject3D = evt.detail.model;
170+
171+
if (!this.data.model) { return; }
172+
173+
controllerObject3D.position.copy(HP_MIXED_REALITY_POSITION_OFFSET);
174+
controllerObject3D.rotation.copy(HP_MIXED_REALITY_ROTATION_OFFSET);
175+
176+
this.el.emit('controllermodelready', {
177+
name: 'hp-mixed-reality-controls',
178+
model: this.data.model,
179+
rayOrigin: new THREE.Vector3(0, 0, 0)
180+
});
181+
},
171182

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

0 commit comments

Comments
 (0)