Skip to content

Commit d1fc39c

Browse files
cabanierabernier
authored andcommitted
WebXRManager: Fix for hand controllers (mrdoob#23830)
* Fix for hand controllers * Address review comment
1 parent 28fea61 commit d1fc39c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

examples/jsm/webxr/XRHandModelFactory.js

+3
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@ class XRHandModelFactory {
8383

8484
}
8585

86+
controller.visible = true;
87+
8688
} );
8789

8890
controller.addEventListener( 'disconnected', () => {
8991

92+
controller.visible = false;
9093
// handModel.motionController = null;
9194
// handModel.remove( scene );
9295
// scene = null;

src/renderers/webxr/WebXRManager.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,12 @@ class WebXRManager extends EventDispatcher {
327327

328328
const inputSources = session.inputSources;
329329

330-
// Assign inputSources to available controllers
330+
// Assign controllers to available inputSources
331331

332-
for ( let i = 0; i < controllers.length; i ++ ) {
332+
for ( let i = 0; i < inputSources.length; i ++ ) {
333333

334-
inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
334+
const index = inputSources[ i ].handedness === 'right' ? 1 : 0;
335+
inputSourcesMap.set( inputSources[ i ], controllers[ index ] );
335336

336337
}
337338

@@ -641,10 +642,14 @@ class WebXRManager extends EventDispatcher {
641642

642643
for ( let i = 0; i < controllers.length; i ++ ) {
643644

644-
const controller = controllers[ i ];
645645
const inputSource = inputSources[ i ];
646+
const controller = inputSourcesMap.get( inputSource );
647+
648+
if ( controller !== undefined ) {
646649

647-
controller.update( inputSource, frame, referenceSpace );
650+
controller.update( inputSource, frame, referenceSpace );
651+
652+
}
648653

649654
}
650655

0 commit comments

Comments
 (0)