Skip to content
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
3 changes: 2 additions & 1 deletion docs/components/hand-controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ handles hand animations and poses.
| color | Color of hand material. | white |
| hand | Associated controller. Can be `left` or `right`. | left |
| handModelStyle | Style of the hand 3D model loaded. Can be `lowPoly`, `highPoly` or `toon`. | lowPoly |

| offSetRotation | Rotation offset for the hand model. Default value aligned with Meta Quest controllers. | 45 0 90 |
| offSetPosition | Position offset for the hand model. Default value aligned with Meta Quest controllers. | 0 0 0.02 |

## Events

Expand Down
24 changes: 11 additions & 13 deletions src/components/hand-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export var Component = registerComponent('hand-controls', {
schema: {
color: {default: 'white', type: 'color'},
hand: { default: 'left' },
handModelStyle: {default: 'lowPoly', oneOf: ['lowPoly', 'highPoly', 'toon']}
handModelStyle: {default: 'lowPoly', oneOf: ['lowPoly', 'highPoly', 'toon']},
// Default rotation and position is aligned with Meta Quest Controllers in the Meta Horizon Browser
offSetRotation: {default: {x: '45', y: '0', z: '90'}, type: 'vec3'},
offSetPosition: {default: {x: '0', y: '0', z: '0.02'}, type: 'vec3'}
},

after: ['tracked-controls'],
Expand Down Expand Up @@ -117,24 +120,19 @@ export var Component = registerComponent('hand-controls', {
var el = this.el;
var hand = this.data.hand;
var mesh = this.el.getObject3D('mesh');
var offSetRotation = this.data.offSetRotation;
var offSetPosition = this.data.offSetPosition;

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 meta-touch-controls and does
// not require this adjustment.
if (evt.detail.name === 'pico-controls') {
handModelOrientationX += Math.PI / 4;
}
var handModelOrientationX = el.sceneEl.hasWebXR ? -THREE.MathUtils.degToRad(offSetRotation.x) : 0;
var handModelOrientationY = THREE.MathUtils.degToRad(offSetRotation.y);
var handModelOrientationZ = hand === 'left' ? THREE.MathUtils.degToRad(offSetRotation.z) : -THREE.MathUtils.degToRad(offSetRotation.z);

mesh.position.set(0, 0, 0);
mesh.rotation.set(handModelOrientationX, 0, handModelOrientationZ);
mesh.position.set(offSetPosition.x, offSetPosition.y, offSetPosition.z);
mesh.rotation.set(handModelOrientationX, handModelOrientationY, handModelOrientationZ);
},

onControllerDisconnected: function () {
Expand Down