Skip to content

Commit 62a05e4

Browse files
committed
WebXRManager: Refactored inputPose handling code.
1 parent 633eee4 commit 62a05e4

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/renderers/webvr/WebXRManager.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ function WebXRManager( renderer ) {
1616
var session = null;
1717

1818
var frameOfRef = null;
19-
var inputSources = [];
2019

2120
var pose = null;
22-
var controllers = {};
21+
22+
var controllers = [];
23+
var inputSources = [];
2324

2425
function isPresenting() {
2526

@@ -54,6 +55,7 @@ function WebXRManager( renderer ) {
5455

5556
controller = new Group();
5657
controller.matrixAutoUpdate = false;
58+
controller.visible = false;
5759

5860
controllers[ id ] = controller;
5961

@@ -227,19 +229,30 @@ function WebXRManager( renderer ) {
227229

228230
//
229231

230-
for ( var i = 0; i < inputSources.length; i ++ ) {
232+
for ( var i = 0; i < controllers.length; i ++ ) {
233+
234+
var controller = controllers[ i ];
231235

232236
var inputSource = inputSources[ i ];
233-
var inputPose = frame.getInputPose( inputSource, frameOfRef );
234237

235-
if ( inputPose !== null && controllers[ i ] ) {
238+
if ( inputSource ) {
239+
240+
var inputPose = frame.getInputPose( inputSource, frameOfRef );
236241

237-
var controller = controllers[ i ];
238-
controller.matrix.elements = inputPose.gripMatrix;
239-
controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
242+
if ( inputPose !== null ) {
243+
244+
controller.matrix.elements = inputPose.gripMatrix;
245+
controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
246+
controller.visible = true;
247+
248+
continue;
249+
250+
}
240251

241252
}
242253

254+
controller.visible = false;
255+
243256
}
244257

245258
if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );

0 commit comments

Comments
 (0)