Skip to content

Commit 49c347c

Browse files
author
Avaer Kazmer
authored
Merge pull request #984 from dmarcos/controllerID
Return appropriate gamepad id depending on headset vendor
2 parents 5f0c5e1 + 5e010a5 commit 49c347c

File tree

4 files changed

+57
-18
lines changed

4 files changed

+57
-18
lines changed

deps/oculus-mobile/include/oculus-mobile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ extern JNIEnv *androidJniEnv;
2323

2424
namespace oculusmobile {
2525

26+
extern ovrJava java;
27+
2628
extern Nan::Persistent<v8::Function> oculusMobileContextConstructor;
2729
extern Nan::Persistent<v8::Object> oculusMobileContext;
2830

2931
/// inline IVRSystem *OculusMobile_Init( EVRInitError *peError, EVRApplicationType eApplicationType );
3032
NAN_METHOD(OculusMobile_Init);
3133
NAN_METHOD(OculusMobile_IsHmdPresent);
34+
NAN_METHOD(OculusMobile_GetDeviceType);
3235

3336
}
3437

deps/oculus-mobile/src/oculus-mobile.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ NAN_METHOD(OculusMobile_IsHmdPresent) {
5555
info.GetReturnValue().Set(Nan::New<Boolean>(true));
5656
}
5757

58+
NAN_METHOD(OculusMobile_GetDeviceType) {
59+
std::cout << "OculusMobile_GetDeviceType" << std::endl;
60+
const char* id;
61+
Local<String> result;
62+
int deviceType = vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_DEVICE_TYPE);
63+
if (deviceType >= VRAPI_DEVICE_TYPE_GEARVR_START && deviceType <= VRAPI_DEVICE_TYPE_GEARVR_END) {
64+
id = "GearVR";
65+
}
66+
if (deviceType >= VRAPI_DEVICE_TYPE_OCULUSGO_START && deviceType <= VRAPI_DEVICE_TYPE_OCULUSGO_END) {
67+
id = "OculusGo";
68+
}
69+
if (deviceType >= VRAPI_DEVICE_TYPE_OCULUSQUEST_START && deviceType <= VRAPI_DEVICE_TYPE_OCULUSQUEST_END) {
70+
id = "OculusQuest";
71+
}
72+
73+
info.GetReturnValue().Set(Nan::New<String>(id).ToLocalChecked());
74+
}
75+
5876
}
5977

6078
Local<Object> makeOculusMobileVr() {
@@ -65,6 +83,7 @@ Local<Object> makeOculusMobileVr() {
6583
exports->Set(Nan::New("OculusMobile_Init").ToLocalChecked(), Nan::New<v8::FunctionTemplate>(oculusmobile::OculusMobile_Init)->GetFunction());
6684
exports->Set(Nan::New("OculusMobile_Shutdown").ToLocalChecked(), Nan::New<v8::FunctionTemplate>(oculusmobile::OculusMobile_Shutdown)->GetFunction());
6785
exports->Set(Nan::New("OculusMobile_IsHmdPresent").ToLocalChecked(), Nan::New<v8::FunctionTemplate>(oculusmobile::OculusMobile_IsHmdPresent)->GetFunction());
86+
exports->Set(Nan::New("OculusMobile_GetDeviceType").ToLocalChecked(), Nan::New<v8::FunctionTemplate>(oculusmobile::OculusMobile_GetDeviceType)->GetFunction());
6887

6988
return scope.Escape(exports);
7089
}

src/VR.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -610,37 +610,53 @@ class FakeVRDisplay extends VRDisplay {
610610
const createVRDisplay = () => new FakeVRDisplay();
611611

612612
const controllerIDs = {
613-
oculusVRIDLeft: 'Oculus Touch (Left)',
614-
oculusVRIDRight: 'Oculus Touch (Right)',
615-
oculusMobileVRIDLeft: 'Oculus Touch (Left)',
616-
oculusMobileVRIDRight: 'Oculus Touch (Right)',
617-
openVRID: 'OpenVR Gamepad',
618-
openVRTrackerID: 'OpenVR Tracker'
613+
OculusVRLeft: 'Oculus Touch (Left)',
614+
OculusVRRight: 'Oculus Touch (Right)',
615+
OculusQuestLeft: 'Oculus Touch (Left)',
616+
OculusQuestRight: 'Oculus Touch (Right)',
617+
OculusGo: 'Oculus Go',
618+
GearVR: 'Gear VR',
619+
OpenVR: 'OpenVR Gamepad',
620+
OpenVRTrackerID: 'Tracker'
619621
};
620622

623+
function getControllerID(vrDisplay, hand) {
624+
if (vrDisplay.id === 'OpenVR' ||
625+
vrDisplay.id === 'GearVR' ||
626+
vrDisplay.id === 'OculusGo') {
627+
return controllerIDs[vrDisplay.id];
628+
}
629+
return controllerIDs[vrDisplay.id + hand.charAt(0).toUpperCase() + hand.slice(1)];
630+
}
631+
621632
let gamepads = null;
622633
function getGamepads(window) {
623634
const {oculusVRDisplay, openVRDisplay, oculusMobileVrDisplay, magicLeapARDisplay} = window[symbols.mrDisplaysSymbol];
624-
if (
625-
GlobalContext.fakeVrDisplayEnabled ||
626-
oculusVRDisplay.isPresenting ||
627-
openVRDisplay.isPresenting ||
628-
oculusMobileVrDisplay.isPresenting ||
629-
magicLeapARDisplay.isPresenting
630-
) {
635+
const presentingDisplay =
636+
(GlobalContext.fakeVrDisplayEnabled && GlobalContext.fakePresentState.fakeVrDisplay) ||
637+
(oculusVRDisplay.isPresenting && oculusVRDisplay) ||
638+
(openVRDisplay.isPresenting && openVRDisplay) ||
639+
(oculusMobileVrDisplay.isPresenting && oculusMobileVrDisplay) ||
640+
(magicLeapARDisplay.isPresenting && magicLeapARDisplay);
641+
642+
if (presentingDisplay) {
631643
if (!gamepads) {
632-
gamepads = Array(2 + maxNumTrackers);
644+
const numGamepads = 2;
645+
if (presentingDisplay === openVRDisplay) {
646+
numGamepads += maxNumTrackers;
647+
}
648+
gamepads = Array(numGamepads);
633649
for (let i = 0; i < gamepads.length; i++) {
634650
let hand, id;
635651
if (i === 0) {
636652
hand = 'left';
637-
id = openVRDisplay.isPresenting ? controllerIDs.openVRID : controllerIDs.oculusVRIDLeft;
653+
id = getControllerID(presentingDisplay, hand);
638654
} else if (i === 1) {
639655
hand = 'right';
640-
id = openVRDisplay.isPresenting ? controllerIDs.openVRID : controllerIDs.oculusVRIDRight;
656+
id = getControllerID(presentingDisplay, hand);
641657
} else {
642658
hand = null;
643-
id = controllerIDs.openVRTrackerID;
659+
id = controllerIDs.OpenVRTrackerID;
644660
}
645661
gamepads[i] = new Gamepad(hand, i, id);
646662
}

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ if (nativeBindings.nativeOculusMobileVr) {
793793
// fps = VR_FPS;
794794

795795
const vrContext = oculusMobileVrPresentState.vrContext = oculusMobileVrPresentState.vrContext || nativeBindings.nativeOculusMobileVr.OculusMobile_Init(context.getWindowHandle());
796-
796+
const {oculusMobileVrDisplay} = window[symbols.mrDisplaysSymbol];
797+
oculusMobileVrDisplay.id = nativeBindings.nativeOculusMobileVr.OculusMobile_GetDeviceType();
797798
const {width: halfWidth, height} = vrContext.GetRecommendedRenderTargetSize();
798799
const MAX_TEXTURE_SIZE = 4096;
799800
const MAX_TEXTURE_SIZE_HALF = MAX_TEXTURE_SIZE/2;

0 commit comments

Comments
 (0)