Skip to content

Commit bbe6f8c

Browse files
authored
Migrate WebXR Hands to new Specs (playcanvas#2880)
* migrate WebXR Hands to new Specs * update docs
1 parent d803564 commit bbe6f8c

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/xr/xr-hand.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ var vecC = new Vec3();
1515

1616
if (window.XRHand) {
1717
fingerJointIds = [
18-
[XRHand.THUMB_METACARPAL, XRHand.THUMB_PHALANX_PROXIMAL, XRHand.THUMB_PHALANX_DISTAL, XRHand.THUMB_PHALANX_TIP],
19-
[XRHand.INDEX_METACARPAL, XRHand.INDEX_PHALANX_PROXIMAL, XRHand.INDEX_PHALANX_INTERMEDIATE, XRHand.INDEX_PHALANX_DISTAL, XRHand.INDEX_PHALANX_TIP],
20-
[XRHand.MIDDLE_METACARPAL, XRHand.MIDDLE_PHALANX_PROXIMAL, XRHand.MIDDLE_PHALANX_INTERMEDIATE, XRHand.MIDDLE_PHALANX_DISTAL, XRHand.MIDDLE_PHALANX_TIP],
21-
[XRHand.RING_METACARPAL, XRHand.RING_PHALANX_PROXIMAL, XRHand.RING_PHALANX_INTERMEDIATE, XRHand.RING_PHALANX_DISTAL, XRHand.RING_PHALANX_TIP],
22-
[XRHand.LITTLE_METACARPAL, XRHand.LITTLE_PHALANX_PROXIMAL, XRHand.LITTLE_PHALANX_INTERMEDIATE, XRHand.LITTLE_PHALANX_DISTAL, XRHand.LITTLE_PHALANX_TIP]
18+
['thumb-metacarpal', 'thumb-phalanx-proximal', 'thumb-phalanx-distal', 'thumb-tip'],
19+
['index-finger-metacarpal', 'index-finger-phalanx-proximal', 'index-finger-phalanx-intermediate', 'index-finger-phalanx-distal', 'index-finger-tip'],
20+
['middle-finger-metacarpal', 'middle-finger-phalanx-proximal', 'middle-finger-phalanx-intermediate', 'middle-finger-phalanx-distal', 'middle-finger-tip'],
21+
['ring-finger-metacarpal', 'ring-finger-phalanx-proximal', 'ring-finger-phalanx-intermediate', 'ring-finger-phalanx-distal', 'ring-finger-tip'],
22+
['pinky-finger-metacarpal', 'pinky-finger-phalanx-proximal', 'pinky-finger-phalanx-intermediate', 'pinky-finger-phalanx-distal', 'pinky-finger-tip']
2323
];
2424
}
2525

@@ -53,15 +53,15 @@ class XrHand extends EventHandler {
5353

5454
this._wrist = null;
5555

56-
if (xrHand[XRHand.WRIST])
57-
this._wrist = new XrJoint(0, XRHand.WRIST, this, null);
56+
if (xrHand.get('wrist'))
57+
this._wrist = new XrJoint(0, 'wrist', this, null);
5858

5959
for (var f = 0; f < fingerJointIds.length; f++) {
6060
var finger = new XrFinger(f, this);
6161

6262
for (var j = 0; j < fingerJointIds[f].length; j++) {
6363
var jointId = fingerJointIds[f][j];
64-
if (! xrHand[jointId]) continue;
64+
if (! xrHand.get(jointId)) continue;
6565
new XrJoint(j, jointId, this, finger);
6666
}
6767
}
@@ -85,7 +85,7 @@ class XrHand extends EventHandler {
8585
// joints
8686
for (var j = 0; j < this._joints.length; j++) {
8787
var joint = this._joints[j];
88-
var jointSpace = xrInputSource.hand[joint._id];
88+
var jointSpace = xrInputSource.hand.get(joint._id);
8989
if (jointSpace) {
9090
var pose = frame.getJointPose(jointSpace, this._manager._referenceSpace);
9191
if (pose) {
@@ -107,12 +107,12 @@ class XrHand extends EventHandler {
107107
}
108108
}
109109

110-
var j1 = this._jointsById[XRHand.THUMB_METACARPAL];
111-
var j4 = this._jointsById[XRHand.THUMB_PHALANX_TIP];
112-
var j6 = this._jointsById[XRHand.INDEX_PHALANX_PROXIMAL];
113-
var j9 = this._jointsById[XRHand.INDEX_PHALANX_TIP];
114-
var j16 = this._jointsById[XRHand.RING_PHALANX_PROXIMAL];
115-
var j21 = this._jointsById[XRHand.LITTLE_PHALANX_PROXIMAL];
110+
var j1 = this._jointsById['thumb-metacarpal'];
111+
var j4 = this._jointsById['thumb-tip'];
112+
var j6 = this._jointsById['index-finger-phalanx-proximal'];
113+
var j9 = this._jointsById['index-finger-tip'];
114+
var j16 = this._jointsById['ring-finger-phalanx-proximal'];
115+
var j21 = this._jointsById['pinky-finger-phalanx-proximal'];
116116

117117
// ray
118118
if (j1 && j4 && j6 && j9 && j16 && j21) {
@@ -179,7 +179,7 @@ class XrHand extends EventHandler {
179179
* @function
180180
* @name XrHand#getJointById
181181
* @description Returns joint by XRHand id from list in specs: https://immersive-web.github.io/webxr-hand-input/
182-
* @param {number} id - id of a joint based on specs ID's in XRHand: https://immersive-web.github.io/webxr-hand-input/
182+
* @param {string} id - id of a joint based on specs ID's in XRHand: https://immersive-web.github.io/webxr-hand-input/
183183
* @returns {XrJoint|null} Joint or null if not available
184184
*/
185185
getJointById(id) {

src/xr/xr-joint.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { Quat } from '../math/quat.js';
33
import { Vec3 } from '../math/vec3.js';
44

55
var tipJointIds = window.XRHand ? [
6-
XRHand.THUMB_PHALANX_TIP,
7-
XRHand.INDEX_PHALANX_TIP,
8-
XRHand.MIDDLE_PHALANX_TIP,
9-
XRHand.RING_PHALANX_TIP,
10-
XRHand.LITTLE_PHALANX_TIP
6+
'thumb-tip',
7+
'index-finger-tip',
8+
'middle-finger-tip',
9+
'ring-finger-tip',
10+
'pinky-finger-tip'
1111
] : [];
1212

1313
var tipJointIdsIndex = {};
@@ -22,7 +22,7 @@ for (var i = 0; i < tipJointIds.length; i++) {
2222
* @classdesc Represents joint of a finger
2323
* @description Represents joint of a finger
2424
* @param {number} index - Index of a joint within a finger
25-
* @param {number} id - Id of a joint based on XRHand specs
25+
* @param {string} id - Id of a joint based on WebXR Hand Input Specs
2626
* @param {XrHand} hand - Hand that joint relates to
2727
* @param {XrFinger} [finger] - Finger that joint is related to, can be null in case of wrist joint
2828
* @property {number} index Index of a joint within a finger, starting from 0 (root of a finger) all the way to tip of the finger
@@ -44,7 +44,7 @@ class XrJoint {
4444
this._finger = finger;
4545
if (this._finger) this._finger._joints.push(this);
4646

47-
this._wrist = id === XRHand.WRIST;
47+
this._wrist = id === 'wrist';
4848
if (this._wrist) this._hand._wrist = this;
4949

5050
this._tip = this._finger && !! tipJointIdsIndex[id];

0 commit comments

Comments
 (0)