Bug 1624240 - Valve Index controller support for WebXR. r=kip

MozReview-Commit-ID: 6rLxOyCQexw

Differential Revision: https://phabricator.services.mozilla.com/D68268

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daosheng Mu 2020-04-02 16:25:35 +00:00
Родитель 2af4d3bbd9
Коммит cf3d5a82b6
5 изменённых файлов: 111 добавлений и 2 удалений

Просмотреть файл

@ -238,6 +238,26 @@ void VRDisplayClient::GamepadMappingForWebVR(
aControllerState.numButtons = 6;
aControllerState.numAxes = 2;
break;
case VRControllerType::ValveIndex:
aControllerState.buttonPressed =
ShiftButtonBitForNewSlot(1, 0) | ShiftButtonBitForNewSlot(2, 1) |
ShiftButtonBitForNewSlot(0, 2) | ShiftButtonBitForNewSlot(5, 3) |
ShiftButtonBitForNewSlot(3, 4) | ShiftButtonBitForNewSlot(4, 5) |
ShiftButtonBitForNewSlot(6, 6) | ShiftButtonBitForNewSlot(7, 7) |
ShiftButtonBitForNewSlot(8, 8) | ShiftButtonBitForNewSlot(9, 9);
aControllerState.buttonTouched = ShiftButtonBitForNewSlot(1, 0, true) |
ShiftButtonBitForNewSlot(2, 1, true) |
ShiftButtonBitForNewSlot(0, 2, true) |
ShiftButtonBitForNewSlot(5, 3, true) |
ShiftButtonBitForNewSlot(3, 4, true) |
ShiftButtonBitForNewSlot(4, 5, true) |
ShiftButtonBitForNewSlot(6, 6, true) |
ShiftButtonBitForNewSlot(7, 7, true) |
ShiftButtonBitForNewSlot(8, 8, true) |
ShiftButtonBitForNewSlot(9, 9, true);
aControllerState.numButtons = 10;
aControllerState.numAxes = 4;
break;
case VRControllerType::PicoGaze:
aControllerState.buttonPressed = ShiftButtonBitForNewSlot(0, 0);
aControllerState.buttonTouched = ShiftButtonBitForNewSlot(0, 0, true);

Просмотреть файл

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "OpenVRKnucklesMapper.h"
#include "moz_external_vr.h"
#include "VRSession.h"
namespace mozilla::gfx {
void OpenVRKnucklesMapper::UpdateButtons(VRControllerState& aControllerState,
ControllerInfo& aControllerInfo) {
mNumButtons = mNumAxes = 0;
// Button 0: Trigger
GetTriggerValueFromAction(aControllerState,
aControllerInfo.mActionTrigger_Value);
// Button 1: Grip
GetButtonValueFromAction(aControllerState,
aControllerInfo.mActionGrip_Pressed,
aControllerInfo.mActionGrip_Touched);
// Button 2: Touchpad.
GetButtonValueFromAction(aControllerState,
aControllerInfo.mActionTrackpad_Pressed,
aControllerInfo.mActionTrackpad_Touched);
// Button 3: Thumbstick
GetButtonValueFromAction(aControllerState,
aControllerInfo.mActionThumbstick_Pressed,
aControllerInfo.mActionThumbstick_Touched);
// Button 4: A
GetButtonValueFromAction(aControllerState, aControllerInfo.mActionA_Pressed,
aControllerInfo.mActionA_Touched);
// Button 5: B
GetButtonValueFromAction(aControllerState, aControllerInfo.mActionB_Pressed,
aControllerInfo.mActionB_Touched);
// Button 6: Finger index
GetTriggerValueFromAction(aControllerState,
aControllerInfo.mActionFingerIndex_Value);
// Button 7: Finger middle
GetTriggerValueFromAction(aControllerState,
aControllerInfo.mActionFingerMiddle_Value);
// Button 8: Finger ring
GetTriggerValueFromAction(aControllerState,
aControllerInfo.mActionFingerRing_Value);
// Button 9: Finger pinky
GetTriggerValueFromAction(aControllerState,
aControllerInfo.mActionFingerPinky_Value);
// Axis 0, 1: Touchpad
GetAxisValueFromAction(aControllerState,
aControllerInfo.mActionTrackpad_Analog);
// Axis 2, 3: Thumbstick
GetAxisValueFromAction(aControllerState,
aControllerInfo.mActionThumbstick_Analog);
aControllerState.numButtons = mNumButtons;
aControllerState.numAxes = mNumAxes;
}
} // namespace mozilla::gfx

Просмотреть файл

@ -0,0 +1,26 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef GFX_VR_SERVICE_OPENVRKNUCKLESMAPPER_H
#define GFX_VR_SERVICE_OPENVRKNUCKLESMAPPER_H
#include "OpenVRControllerMapper.h"
namespace mozilla {
namespace gfx {
class OpenVRKnucklesMapper : public OpenVRControllerMapper {
public:
OpenVRKnucklesMapper() = default;
virtual ~OpenVRKnucklesMapper() = default;
virtual void UpdateButtons(VRControllerState& aControllerState,
ControllerInfo& aControllerInfo);
};
} // namespace gfx
} // namespace mozilla
#endif // GFX_VR_SERVICE_OPENVRKNUCKLESMAPPER_H

Просмотреть файл

@ -30,6 +30,7 @@
#include "binding/OpenVRViveBinding.h"
#include "OpenVRCosmosMapper.h"
#include "OpenVRDefaultMapper.h"
#include "OpenVRKnucklesMapper.h"
#include "OpenVRViveMapper.h"
#if defined(XP_WIN) // Windows Mixed Reality is only available in Windows.
# include "OpenVRWMRMapper.h"
@ -1023,8 +1024,7 @@ void OpenVRSession::EnumerateControllers(VRSystemState& aState) {
break;
#endif
case VRControllerType::ValveIndex:
// TODO: Replace Knuckles with Valve Index.
mControllerMapper = MakeUnique<OpenVRDefaultMapper>();
mControllerMapper = MakeUnique<OpenVRKnucklesMapper>();
break;
default:
mControllerMapper = MakeUnique<OpenVRDefaultMapper>();

Просмотреть файл

@ -43,6 +43,7 @@ if CONFIG['OS_TARGET'] in ('WINNT', 'Linux', 'Darwin'):
'OpenVRControllerMapper.cpp',
'OpenVRCosmosMapper.cpp',
'OpenVRDefaultMapper.cpp',
'OpenVRKnucklesMapper.cpp',
'OpenVRSession.cpp',
'OpenVRViveMapper.cpp',
]