Exploring my three.js apps on the new Oculus Go has led me to question whether I can interact with the controller solely through the GamePad API supported by major browsers. Although Oculus documentation suggests using OVRManager in Unity or Unreal Blueprints, I prefer avoiding additional learning curves and bloating my apps unnecessarily.
As a VR novice, I am inclined to pursue a simpler approach by utilizing the Gamepad API, despite facing challenges such as breaking the app when transitioning into VR mode. The following snippet outlines my initial attempt:
var gamePadState = {
lastButtons: {},
lastAxes: {}
};
function onGamePad(){
Array.prototype.forEach.call( navigator.getGamepads(), function (activePad, padIndex){
if ( activePad.connected ) {
if (activePad.id.includes("Oculus Go")) {
// Handling buttons and axes for the Gear VR touch panel
activePad.buttons.forEach( function ( gamepadButton, buttonIndex ){
if ( buttonIndex === 0 && gamepadButton.pressed && !lastButtons[buttonIndex]){
// Managing tap action
dollyCam.translateZ( -0.01 );
}
gamePadState.lastButtons[buttonIndex] = gamepadButton.pressed;
});
activePad.axes.forEach( function (axisValue, axisIndex ) {
if (axisIndex === 0 && axisValue < 0 && lastAxes[axisIndex] >= 0 ){
// Swipe right
} else if (axisIndex === 0 && axisValue > 0 && lastAxes[axisIndex] <= 0) {
// Swipe left
} else if (axisIndex === 1 && axisValue < 0 && lastAxes[axisIndex] >= 0) {
// Swipe up
} else if (axisIndex === 1 && axisValue > 0 && lastAxes[axisIndex] <= 0) {
// Swipe down
}
gamePadState.lastAxes[axisIndex] = axisValue;
});
} else {
// Supporting connected Bluetooth gamepad for VR experience
}
}
});
}
In a related inquiry raised on Stack Overflow, I was recommended to incorporate Unity build in my app for desired outcomes. While I'm open to it, I'd prefer not to delve into that realm unless absolutely necessary.
My goal is to establish support for various controllers using logics similar to the one above. However, my current focus lies on getting the Oculus Go controller to work effectively.
Hence, my query revolves around the possibility of interfacing with the Oculus Go controller through the Gamepad API, particularly concerning device properties like buttons, axes, orientation, and associated gamepad events.
Your insights are greatly appreciated.