Skip to content

Commit eae4b7f

Browse files
Improve pico-controls on third-party browsers such as Wolvic (#5534)
* Improve pico-controls on third-party browsers such as Wolvic It appears that Pico Browser applies some adjustments on controllers to somewhat mimic an Oculus controller. On a neutral browser such as Wolvic, these adjustments are not applied. The end result is that turning and gestures do not work on Wolvic when using hand-controls. The following changes make the mappings on a pico controller more similar to those on the oculus controller, which seems to improve the situation. * Apply a PI/4 offset on the hands models when using pico4 controller * Refactor logics to determine hand model offset It will now happen when controller is connected, rather than at model load. This allows to apply controller-specific offsets, as the actual model is known.
1 parent 1d5cf31 commit eae4b7f

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/components/hand-controls.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,28 @@ module.exports.Component = registerComponent('hand-controls', {
112112
mesh.mixer.update(delta / 1000);
113113
},
114114

115-
onControllerConnected: function () {
116-
this.el.object3D.visible = true;
115+
onControllerConnected: function (evt) {
116+
var el = this.el;
117+
var hand = this.data.hand;
118+
var mesh = this.el.getObject3D('mesh');
119+
120+
el.object3D.visible = true;
121+
122+
var handModelOrientationZ = hand === 'left' ? Math.PI / 2 : -Math.PI / 2;
123+
// The WebXR standard defines the grip space such that a cylinder held in a closed hand points
124+
// along the Z axis. The models currently have such a cylinder point along the X-Axis.
125+
var handModelOrientationX = el.sceneEl.hasWebXR ? -Math.PI / 2 : 0;
126+
127+
// Pico4, at least on Wolvic, needs a different rotation offset
128+
// for the hand model. Pico Browser claims to use oculus
129+
// controllers instead; will load oculus-touch-controls and does
130+
// not require this adjustment.
131+
if (evt.detail.name === 'pico-controls') {
132+
handModelOrientationX += Math.PI / 4;
133+
}
134+
135+
mesh.position.set(0, 0, 0);
136+
mesh.rotation.set(handModelOrientationX, 0, handModelOrientationZ);
117137
},
118138

119139
onControllerDisconnected: function () {
@@ -199,19 +219,13 @@ module.exports.Component = registerComponent('hand-controls', {
199219
var handmodelUrl = MODEL_URLS[handModelStyle + hand.charAt(0).toUpperCase() + hand.slice(1)];
200220
this.loader.load(handmodelUrl, function (gltf) {
201221
var mesh = gltf.scene.children[0];
202-
var handModelOrientationZ = hand === 'left' ? Math.PI / 2 : -Math.PI / 2;
203-
// The WebXR standard defines the grip space such that a cylinder held in a closed hand points
204-
// along the Z axis. The models currently have such a cylinder point along the X-Axis.
205-
var handModelOrientationX = el.sceneEl.hasWebXR ? -Math.PI / 2 : 0;
206222
mesh.mixer = new THREE.AnimationMixer(mesh);
207223
self.clips = gltf.animations;
208224
el.setObject3D('mesh', mesh);
209225
mesh.traverse(function (object) {
210226
if (!object.isMesh) { return; }
211227
object.material.color = new THREE.Color(handColor);
212228
});
213-
mesh.position.set(0, 0, 0);
214-
mesh.rotation.set(handModelOrientationX, 0, handModelOrientationZ);
215229
el.setAttribute('magicleap-controls', controlConfiguration);
216230
el.setAttribute('vive-controls', controlConfiguration);
217231
el.setAttribute('oculus-touch-controls', controlConfiguration);

src/components/pico-controls.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ var PICO_MODEL_GLB_BASE_URL = AFRAME_CDN_ROOT + 'controllers/pico/pico4/';
2626
*/
2727
var INPUT_MAPPING_WEBXR = {
2828
left: {
29-
axes: {touchpad: [2, 3]},
30-
buttons: ['trigger', 'squeeze', 'none', 'thumbstick', 'xbutton', 'ybutton']
29+
axes: {thumbstick: [2, 3]},
30+
buttons: ['trigger', 'grip', 'none', 'thumbstick', 'xbutton', 'ybutton']
3131
},
3232
right: {
33-
axes: {touchpad: [2, 3]},
34-
buttons: ['trigger', 'squeeze', 'none', 'thumbstick', 'abutton', 'bbutton']
33+
axes: {thumbstick: [2, 3]},
34+
buttons: ['trigger', 'grip', 'none', 'thumbstick', 'abutton', 'bbutton']
3535
}
3636
};
3737

@@ -118,6 +118,7 @@ module.exports.Component = registerComponent('pico-controls', {
118118
hand: data.hand,
119119
controller: this.controllerIndex
120120
});
121+
121122
// Load model.
122123
if (!this.data.model) { return; }
123124
this.el.setAttribute('gltf-model', PICO_MODEL_GLB_BASE_URL + this.data.hand + '.glb');
@@ -161,6 +162,6 @@ module.exports.Component = registerComponent('pico-controls', {
161162
},
162163

163164
onAxisMoved: function (evt) {
164-
emitIfAxesChanged(this, this.mapping.axes, evt);
165+
emitIfAxesChanged(this, this.mapping[this.data.hand].axes, evt);
165166
}
166167
});

0 commit comments

Comments
 (0)