Skip to content

Commit 1e3b35c

Browse files
authored
Merge pull request #54 from De-Panther/hololens_bug_inputPose
check if inputPose is defined. Hololens 2 bug...
2 parents c0423ce + be8b9e3 commit 1e3b35c

File tree

3 files changed

+207
-204
lines changed

3 files changed

+207
-204
lines changed

Assets/WebGLTemplates/WebXR/webxr.js

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -344,77 +344,78 @@
344344
// Show the input source if it has a grip space
345345
if (inputSource.gripSpace) {
346346
let inputPose = frame.getPose(inputSource.gripSpace, refSpace);
347-
348-
var position = inputPose.transform.position;
349-
var orientation = inputPose.transform.orientation;
350-
var hand = 0;
351-
var controller = xrData.controllerA;
352-
if (inputSource.handedness == 'left') {
353-
hand = 1;
354-
controller = xrData.controllerB;
355-
} else if (inputSource.handedness == 'right') {
356-
hand = 2;
357-
}
358-
359-
controller.enabled = 1;
360-
controller.hand = hand;
361-
362-
controller.positionX = position.x;
363-
controller.positionY = position.y;
364-
controller.positionZ = -position.z;
365-
366-
controller.rotationX = -orientation.x;
367-
controller.rotationY = -orientation.y;
368-
controller.rotationZ = orientation.z;
369-
controller.rotationW = orientation.w;
370-
371-
// if there's gamepad, use the xr-standard mapping
372-
// TODO: check for profiles
373-
if (inputSource.gamepad) {
374-
for (var j = 0; j < inputSource.gamepad.buttons.length; j++) {
375-
switch (j) {
376-
case 0:
377-
controller.trigger = inputSource.gamepad.buttons[j].value;
378-
break;
379-
case 1:
380-
controller.squeeze = inputSource.gamepad.buttons[j].value;
381-
break;
382-
case 2:
383-
controller.touchpad = inputSource.gamepad.buttons[j].value;
384-
break;
385-
case 3:
386-
controller.thumbstick = inputSource.gamepad.buttons[j].value;
387-
break;
388-
case 4:
389-
controller.buttonA = inputSource.gamepad.buttons[j].value;
390-
break;
391-
case 5:
392-
controller.buttonB = inputSource.gamepad.buttons[j].value;
393-
break;
394-
}
347+
if (inputPose) {
348+
var position = inputPose.transform.position;
349+
var orientation = inputPose.transform.orientation;
350+
var hand = 0;
351+
var controller = xrData.controllerA;
352+
if (inputSource.handedness == 'left') {
353+
hand = 1;
354+
controller = xrData.controllerB;
355+
} else if (inputSource.handedness == 'right') {
356+
hand = 2;
395357
}
396-
for (var j = 0; j < inputSource.gamepad.axes.length; j++) {
397-
switch (j) {
398-
case 0:
399-
controller.touchpadX = inputSource.gamepad.axes[j];
400-
break;
401-
case 1:
402-
controller.touchpadY = inputSource.gamepad.axes[j];
403-
break;
404-
case 2:
405-
controller.thumbstickX = inputSource.gamepad.axes[j];
406-
break;
407-
case 3:
408-
controller.thumbstickY = inputSource.gamepad.axes[j];
409-
break;
358+
359+
controller.enabled = 1;
360+
controller.hand = hand;
361+
362+
controller.positionX = position.x;
363+
controller.positionY = position.y;
364+
controller.positionZ = -position.z;
365+
366+
controller.rotationX = -orientation.x;
367+
controller.rotationY = -orientation.y;
368+
controller.rotationZ = orientation.z;
369+
controller.rotationW = orientation.w;
370+
371+
// if there's gamepad, use the xr-standard mapping
372+
// TODO: check for profiles
373+
if (inputSource.gamepad) {
374+
for (var j = 0; j < inputSource.gamepad.buttons.length; j++) {
375+
switch (j) {
376+
case 0:
377+
controller.trigger = inputSource.gamepad.buttons[j].value;
378+
break;
379+
case 1:
380+
controller.squeeze = inputSource.gamepad.buttons[j].value;
381+
break;
382+
case 2:
383+
controller.touchpad = inputSource.gamepad.buttons[j].value;
384+
break;
385+
case 3:
386+
controller.thumbstick = inputSource.gamepad.buttons[j].value;
387+
break;
388+
case 4:
389+
controller.buttonA = inputSource.gamepad.buttons[j].value;
390+
break;
391+
case 5:
392+
controller.buttonB = inputSource.gamepad.buttons[j].value;
393+
break;
394+
}
395+
}
396+
for (var j = 0; j < inputSource.gamepad.axes.length; j++) {
397+
switch (j) {
398+
case 0:
399+
controller.touchpadX = inputSource.gamepad.axes[j];
400+
break;
401+
case 1:
402+
controller.touchpadY = inputSource.gamepad.axes[j];
403+
break;
404+
case 2:
405+
controller.thumbstickX = inputSource.gamepad.axes[j];
406+
break;
407+
case 3:
408+
controller.thumbstickY = inputSource.gamepad.axes[j];
409+
break;
410+
}
410411
}
411412
}
412-
}
413-
414-
if (hand == 0 || hand == 2) {
415-
xrData.controllerA = controller;
416-
} else {
417-
xrData.controllerB = controller;
413+
414+
if (hand == 0 || hand == 2) {
415+
xrData.controllerA = controller;
416+
} else {
417+
xrData.controllerB = controller;
418+
}
418419
}
419420
}
420421
}

Assets/WebGLTemplates/WebXRFullView/webxr.js

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -344,77 +344,78 @@
344344
// Show the input source if it has a grip space
345345
if (inputSource.gripSpace) {
346346
let inputPose = frame.getPose(inputSource.gripSpace, refSpace);
347-
348-
var position = inputPose.transform.position;
349-
var orientation = inputPose.transform.orientation;
350-
var hand = 0;
351-
var controller = xrData.controllerA;
352-
if (inputSource.handedness == 'left') {
353-
hand = 1;
354-
controller = xrData.controllerB;
355-
} else if (inputSource.handedness == 'right') {
356-
hand = 2;
357-
}
358-
359-
controller.enabled = 1;
360-
controller.hand = hand;
361-
362-
controller.positionX = position.x;
363-
controller.positionY = position.y;
364-
controller.positionZ = -position.z;
365-
366-
controller.rotationX = -orientation.x;
367-
controller.rotationY = -orientation.y;
368-
controller.rotationZ = orientation.z;
369-
controller.rotationW = orientation.w;
370-
371-
// if there's gamepad, use the xr-standard mapping
372-
// TODO: check for profiles
373-
if (inputSource.gamepad) {
374-
for (var j = 0; j < inputSource.gamepad.buttons.length; j++) {
375-
switch (j) {
376-
case 0:
377-
controller.trigger = inputSource.gamepad.buttons[j].value;
378-
break;
379-
case 1:
380-
controller.squeeze = inputSource.gamepad.buttons[j].value;
381-
break;
382-
case 2:
383-
controller.touchpad = inputSource.gamepad.buttons[j].value;
384-
break;
385-
case 3:
386-
controller.thumbstick = inputSource.gamepad.buttons[j].value;
387-
break;
388-
case 4:
389-
controller.buttonA = inputSource.gamepad.buttons[j].value;
390-
break;
391-
case 5:
392-
controller.buttonB = inputSource.gamepad.buttons[j].value;
393-
break;
394-
}
347+
if (inputPose) {
348+
var position = inputPose.transform.position;
349+
var orientation = inputPose.transform.orientation;
350+
var hand = 0;
351+
var controller = xrData.controllerA;
352+
if (inputSource.handedness == 'left') {
353+
hand = 1;
354+
controller = xrData.controllerB;
355+
} else if (inputSource.handedness == 'right') {
356+
hand = 2;
395357
}
396-
for (var j = 0; j < inputSource.gamepad.axes.length; j++) {
397-
switch (j) {
398-
case 0:
399-
controller.touchpadX = inputSource.gamepad.axes[j];
400-
break;
401-
case 1:
402-
controller.touchpadY = inputSource.gamepad.axes[j];
403-
break;
404-
case 2:
405-
controller.thumbstickX = inputSource.gamepad.axes[j];
406-
break;
407-
case 3:
408-
controller.thumbstickY = inputSource.gamepad.axes[j];
409-
break;
358+
359+
controller.enabled = 1;
360+
controller.hand = hand;
361+
362+
controller.positionX = position.x;
363+
controller.positionY = position.y;
364+
controller.positionZ = -position.z;
365+
366+
controller.rotationX = -orientation.x;
367+
controller.rotationY = -orientation.y;
368+
controller.rotationZ = orientation.z;
369+
controller.rotationW = orientation.w;
370+
371+
// if there's gamepad, use the xr-standard mapping
372+
// TODO: check for profiles
373+
if (inputSource.gamepad) {
374+
for (var j = 0; j < inputSource.gamepad.buttons.length; j++) {
375+
switch (j) {
376+
case 0:
377+
controller.trigger = inputSource.gamepad.buttons[j].value;
378+
break;
379+
case 1:
380+
controller.squeeze = inputSource.gamepad.buttons[j].value;
381+
break;
382+
case 2:
383+
controller.touchpad = inputSource.gamepad.buttons[j].value;
384+
break;
385+
case 3:
386+
controller.thumbstick = inputSource.gamepad.buttons[j].value;
387+
break;
388+
case 4:
389+
controller.buttonA = inputSource.gamepad.buttons[j].value;
390+
break;
391+
case 5:
392+
controller.buttonB = inputSource.gamepad.buttons[j].value;
393+
break;
394+
}
395+
}
396+
for (var j = 0; j < inputSource.gamepad.axes.length; j++) {
397+
switch (j) {
398+
case 0:
399+
controller.touchpadX = inputSource.gamepad.axes[j];
400+
break;
401+
case 1:
402+
controller.touchpadY = inputSource.gamepad.axes[j];
403+
break;
404+
case 2:
405+
controller.thumbstickX = inputSource.gamepad.axes[j];
406+
break;
407+
case 3:
408+
controller.thumbstickY = inputSource.gamepad.axes[j];
409+
break;
410+
}
410411
}
411412
}
412-
}
413-
414-
if (hand == 0 || hand == 2) {
415-
xrData.controllerA = controller;
416-
} else {
417-
xrData.controllerB = controller;
413+
414+
if (hand == 0 || hand == 2) {
415+
xrData.controllerA = controller;
416+
} else {
417+
xrData.controllerB = controller;
418+
}
418419
}
419420
}
420421
}

0 commit comments

Comments
 (0)