Browse Source

WebXRManager: Fix for hand controllers (#23830)

* Fix for hand controllers

* Address review comment
Rik Cabanier 3 năm trước cách đây
mục cha
commit
d0dc0801fc

+ 3 - 0
examples/jsm/webxr/XRHandModelFactory.js

@@ -83,10 +83,13 @@ class XRHandModelFactory {
 
 			}
 
+			controller.visible = true;
+
 		} );
 
 		controller.addEventListener( 'disconnected', () => {
 
+			controller.visible = false;
 			// handModel.motionController = null;
 			// handModel.remove( scene );
 			// scene = null;

+ 10 - 5
src/renderers/webxr/WebXRManager.js

@@ -327,11 +327,12 @@ class WebXRManager extends EventDispatcher {
 
 			const inputSources = session.inputSources;
 
-			// Assign inputSources to available controllers
+			// Assign controllers to available inputSources
 
-			for ( let i = 0; i < controllers.length; i ++ ) {
+			for ( let i = 0; i < inputSources.length; i ++ ) {
 
-				inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
+				const index = inputSources[ i ].handedness === 'right' ? 1 : 0;
+				inputSourcesMap.set( inputSources[ i ], controllers[ index ] );
 
 			}
 
@@ -641,10 +642,14 @@ class WebXRManager extends EventDispatcher {
 
 			for ( let i = 0; i < controllers.length; i ++ ) {
 
-				const controller = controllers[ i ];
 				const inputSource = inputSources[ i ];
+				const controller = inputSourcesMap.get( inputSource );
+
+				if ( controller !== undefined ) {
 
-				controller.update( inputSource, frame, referenceSpace );
+					controller.update( inputSource, frame, referenceSpace );
+
+				}
 
 			}