Threejs WebXR controller detect hand

Viewed 704

First of all, I'm a complete noob in three.js and currently struggled with detecting the hand of the controller. I want to achieve something like that:

for (let i = 0; i < 2; ++i) {
  const controller = renderer.xr.getController(i);
  console.debug(controller.hand); // 'left', 'right' ??
  scene.add(controller);
} 

What is the best way to do this?

1 Answers

You can use XRInputSource.handedness. From the specification:

The handedness attribute describes which hand the XR input source is associated with, if any.

In three.js, input sources are mapped to controllers. Meaning you can evaluate the handedness like so:

controller.addEventListener( 'connected', ( event ) => {

    console.log( event.data.handedness );

} );

three.js r116

Related