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

Improve pico-controls on third-party browsers such as Wolvic #5534

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 22 additions & 8 deletions src/components/hand-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,28 @@ module.exports.Component = registerComponent('hand-controls', {
mesh.mixer.update(delta / 1000);
},

onControllerConnected: function () {
this.el.object3D.visible = true;
onControllerConnected: function (evt) {
var el = this.el;
var hand = this.data.hand;
var mesh = this.el.getObject3D('mesh');

el.object3D.visible = true;

var handModelOrientationZ = hand === 'left' ? Math.PI / 2 : -Math.PI / 2;
// The WebXR standard defines the grip space such that a cylinder held in a closed hand points
// along the Z axis. The models currently have such a cylinder point along the X-Axis.
var handModelOrientationX = el.sceneEl.hasWebXR ? -Math.PI / 2 : 0;

// Pico4, at least on Wolvic, needs a different rotation offset
// for the hand model. Pico Browser claims to use oculus
// controllers instead; will load oculus-touch-controls and does
// not require this adjustment.
if (evt.detail.name === 'pico-controls') {
handModelOrientationX += Math.PI / 4;
}

mesh.position.set(0, 0, 0);
mesh.rotation.set(handModelOrientationX, 0, handModelOrientationZ);
},

onControllerDisconnected: function () {
Expand Down Expand Up @@ -199,19 +219,13 @@ module.exports.Component = registerComponent('hand-controls', {
var handmodelUrl = MODEL_URLS[handModelStyle + hand.charAt(0).toUpperCase() + hand.slice(1)];
this.loader.load(handmodelUrl, function (gltf) {
var mesh = gltf.scene.children[0];
var handModelOrientationZ = hand === 'left' ? Math.PI / 2 : -Math.PI / 2;
// The WebXR standard defines the grip space such that a cylinder held in a closed hand points
// along the Z axis. The models currently have such a cylinder point along the X-Axis.
var handModelOrientationX = el.sceneEl.hasWebXR ? -Math.PI / 2 : 0;
mesh.mixer = new THREE.AnimationMixer(mesh);
self.clips = gltf.animations;
el.setObject3D('mesh', mesh);
mesh.traverse(function (object) {
if (!object.isMesh) { return; }
object.material.color = new THREE.Color(handColor);
});
mesh.position.set(0, 0, 0);
mesh.rotation.set(handModelOrientationX, 0, handModelOrientationZ);
el.setAttribute('magicleap-controls', controlConfiguration);
el.setAttribute('vive-controls', controlConfiguration);
el.setAttribute('oculus-touch-controls', controlConfiguration);
Expand Down
11 changes: 6 additions & 5 deletions src/components/pico-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ var PICO_MODEL_GLB_BASE_URL = AFRAME_CDN_ROOT + 'controllers/pico/pico4/';
*/
var INPUT_MAPPING_WEBXR = {
left: {
axes: {touchpad: [2, 3]},
buttons: ['trigger', 'squeeze', 'none', 'thumbstick', 'xbutton', 'ybutton']
axes: {thumbstick: [2, 3]},
Copy link
Member

Choose a reason for hiding this comment

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

Do these apply to all the pico controllers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in my tests one would not be able to e.g. turn using the blink-controls component and perform gestures with hand-controls without these changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean using wolvic, which advertises the right controller type.

Copy link
Member

Choose a reason for hiding this comment

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

What about other browsers? The built-in one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Pico browser uses the oculus-controls component and behaves as an oculus controller. It was working properly before these changes and keeps doing so afterwards.

buttons: ['trigger', 'grip', 'none', 'thumbstick', 'xbutton', 'ybutton']
},
right: {
axes: {touchpad: [2, 3]},
buttons: ['trigger', 'squeeze', 'none', 'thumbstick', 'abutton', 'bbutton']
axes: {thumbstick: [2, 3]},
buttons: ['trigger', 'grip', 'none', 'thumbstick', 'abutton', 'bbutton']
}
};

Expand Down Expand Up @@ -120,6 +120,7 @@ module.exports.Component = registerComponent('pico-controls', {
controller: this.controllerIndex,
orientationOffset: data.orientationOffset
});

// Load model.
if (!this.data.model) { return; }
this.el.setAttribute('gltf-model', PICO_MODEL_GLB_BASE_URL + this.data.hand + '.glb');
Expand Down Expand Up @@ -163,6 +164,6 @@ module.exports.Component = registerComponent('pico-controls', {
},

onAxisMoved: function (evt) {
emitIfAxesChanged(this, this.mapping.axes, evt);
emitIfAxesChanged(this, this.mapping[this.data.hand].axes, evt);
}
});
Loading