Skip to content

Commit 29dd217

Browse files
author
Tianrui "Felix" Zhang
authored
Fixing Oculus hands rendering broken by recent WebXR Hands API change (#21712)
* Adding advanced hand examples * Update samples with ECSY implementation * Fix hands examples broken by the recent oculus WebXR Hands API change * Replace fbx hand models with glb * Generate screenshots for new examples * Clean up in Text2D.js * Clean up in Text2D.js * Update XRHandModelFactory and OculusHandModel to fetch hand model from webxr input profile cdn
1 parent 49b9c25 commit 29dd217

22 files changed

+1902
-160
lines changed

examples/files.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@
342342
"webxr_vr_handinput",
343343
"webxr_vr_handinput_cubes",
344344
"webxr_vr_handinput_profiles",
345+
"webxr_vr_handinput_pointerclick",
346+
"webxr_vr_handinput_pointerdrag",
347+
"webxr_vr_handinput_pressbutton",
345348
"webxr_vr_haptics",
346349
"webxr_vr_lorenzattractor",
347350
"webxr_vr_panorama",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Object3D, Sphere, Box3 } from "../../../build/three.module.js";
2+
import { fetchProfile } from '../libs/motion-controllers.module.js';
3+
import { XRHandMeshModel } from "./XRHandMeshModel.js";
4+
5+
const DEFAULT_PROFILES_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/[email protected]/dist/profiles';
6+
const DEFAULT_PROFILE = 'generic-hand';
7+
8+
class OculusHandModel extends Object3D {
9+
constructor(controller) {
10+
super();
11+
12+
this.controller = controller;
13+
this.motionController = null;
14+
this.envMap = null;
15+
16+
this.mesh = null;
17+
18+
controller.addEventListener("connected", (event) => {
19+
const xrInputSource = event.data;
20+
if (xrInputSource.hand && !this.motionController) {
21+
this.visible = true;
22+
this.xrInputSource = xrInputSource;
23+
fetchProfile(xrInputSource, DEFAULT_PROFILES_PATH, DEFAULT_PROFILE).then(({ profile, assetPath }) => {
24+
this.motionController = new XRHandMeshModel(
25+
this,
26+
controller,
27+
assetPath
28+
);
29+
}).catch((err) => {
30+
console.warn(err);
31+
});
32+
}
33+
});
34+
35+
controller.addEventListener("disconnected", () => {
36+
this.clear();
37+
this.motionController = null;
38+
})
39+
}
40+
41+
updateMatrixWorld(force) {
42+
super.updateMatrixWorld(force);
43+
44+
if (this.motionController) {
45+
this.motionController.updateMesh();
46+
}
47+
}
48+
49+
getPointerPosition() {
50+
let indexFingerTip = this.controller.joints[POINTING_JOINT];
51+
if (indexFingerTip) {
52+
return indexFingerTip.position;
53+
} else {
54+
return null;
55+
}
56+
}
57+
58+
intersectBoxObject(boxObject) {
59+
let pointerPosition = this.getPointerPosition();
60+
if (pointerPosition) {
61+
let indexSphere = new Sphere(pointerPosition, TOUCH_RADIUS);
62+
let box = new Box3().setFromObject(boxObject);
63+
return indexSphere.intersectsBox(box);
64+
} else {
65+
return false;
66+
}
67+
}
68+
69+
checkButton(button) {
70+
if (this.intersectBoxObject(button)) {
71+
button.onPress();
72+
} else {
73+
button.onClear();
74+
}
75+
76+
if (button.isPressed()) {
77+
button.whilePressed();
78+
}
79+
}
80+
}
81+
82+
export { OculusHandModel };

0 commit comments

Comments
 (0)