Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions Dependencies/xr/Source/OpenXR/XR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ namespace xr
XrCheck(xrStringToPath(instance, ActionResources.CONTROLLER_SUBACTION_PATH_PREFIXES[idx], &ActionResources.ControllerSubactionPaths[idx]));
}

std::vector<XrActionSuggestedBinding> bindings{};
std::vector<XrActionSuggestedBinding> defaultBindings{};
std::vector<XrActionSuggestedBinding> microsoftControllerBindings{};

// Create controller get grip pose action, suggested bindings, and spaces
{
Expand All @@ -678,8 +679,12 @@ namespace xr
// Create suggested binding
std::string path{ ActionResources.CONTROLLER_SUBACTION_PATH_PREFIXES[idx] };
path.append(ActionResources.CONTROLLER_GET_GRIP_POSE_PATH_SUFFIX);
bindings.push_back({ ActionResources.ControllerGetGripPoseAction });
XrCheck(xrStringToPath(instance, path.data(), &bindings.back().binding));

defaultBindings.push_back({ ActionResources.ControllerGetGripPoseAction });
XrCheck(xrStringToPath(instance, path.data(), &defaultBindings.back().binding));

microsoftControllerBindings.push_back({ ActionResources.ControllerGetGripPoseAction });
XrCheck(xrStringToPath(instance, path.data(), &microsoftControllerBindings.back().binding));

// Create subaction space
XrActionSpaceCreateInfo actionSpaceCreateInfo{ XR_TYPE_ACTION_SPACE_CREATE_INFO };
Expand All @@ -705,8 +710,12 @@ namespace xr
// Create suggested binding
std::string path{ ActionResources.CONTROLLER_SUBACTION_PATH_PREFIXES[idx] };
path.append(ActionResources.CONTROLLER_GET_AIM_POSE_PATH_SUFFIX);
bindings.push_back({ ActionResources.ControllerGetAimPoseAction });
XrCheck(xrStringToPath(instance, path.data(), &bindings.back().binding));

defaultBindings.push_back({ ActionResources.ControllerGetAimPoseAction });
XrCheck(xrStringToPath(instance, path.data(), &defaultBindings.back().binding));

microsoftControllerBindings.push_back({ ActionResources.ControllerGetAimPoseAction });
XrCheck(xrStringToPath(instance, path.data(), &microsoftControllerBindings.back().binding));

// Create subaction space
XrActionSpaceCreateInfo actionSpaceCreateInfo{ XR_TYPE_ACTION_SPACE_CREATE_INFO };
Expand All @@ -724,7 +733,7 @@ namespace xr
ActionResources.CONTROLLER_GET_TRIGGER_VALUE_ACTION_LOCALIZED_NAME,
ActionResources.CONTROLLER_GET_TRIGGER_VALUE_PATH_SUFFIX,
&ActionResources.ControllerGetTriggerValueAction,
bindings,
microsoftControllerBindings,
instance);

// Create controller get squeeze click action and suggested bindings
Expand All @@ -734,7 +743,7 @@ namespace xr
ActionResources.CONTROLLER_GET_SQUEEZE_CLICK_ACTION_LOCALIZED_NAME,
ActionResources.CONTROLLER_GET_SQUEEZE_CLICK_PATH_SUFFIX,
&ActionResources.ControllerGetSqueezeClickAction,
bindings,
microsoftControllerBindings,
instance);

// Create controller get trackpad axes action and suggested bindings
Expand All @@ -744,7 +753,7 @@ namespace xr
ActionResources.CONTROLLER_GET_TRACKPAD_AXES_ACTION_LOCALIZED_NAME,
ActionResources.CONTROLLER_GET_TRACKPAD_AXES_PATH_SUFFIX,
&ActionResources.ControllerGetTrackpadAxesAction,
bindings,
microsoftControllerBindings,
instance);

// Create controller get trackpad click action and suggested bindings
Expand All @@ -754,7 +763,7 @@ namespace xr
ActionResources.CONTROLLER_GET_TRACKPAD_CLICK_ACTION_LOCALIZED_NAME,
ActionResources.CONTROLLER_GET_TRACKPAD_CLICK_PATH_SUFFIX,
&ActionResources.ControllerGetTrackpadClickAction,
bindings,
microsoftControllerBindings,
instance);

// Create controller get trackpad touch action and suggested bindings
Expand All @@ -764,7 +773,7 @@ namespace xr
ActionResources.CONTROLLER_GET_TRACKPAD_TOUCH_ACTION_LOCALIZED_NAME,
ActionResources.CONTROLLER_GET_TRACKPAD_TOUCH_PATH_SUFFIX,
&ActionResources.ControllerGetTrackpadTouchAction,
bindings,
microsoftControllerBindings,
instance);

// Create controller get thumbstick axes action and suggested bindings
Expand All @@ -774,7 +783,7 @@ namespace xr
ActionResources.CONTROLLER_GET_THUMBSTICK_AXES_ACTION_LOCALIZED_NAME,
ActionResources.CONTROLLER_GET_THUMBSTICK_AXES_PATH_SUFFIX,
&ActionResources.ControllerGetThumbstickAxesAction,
bindings,
microsoftControllerBindings,
instance);

// Create controller get thumbstick click action and suggested bindings
Expand All @@ -784,30 +793,22 @@ namespace xr
ActionResources.CONTROLLER_GET_THUMBSTICK_CLICK_ACTION_LOCALIZED_NAME,
ActionResources.CONTROLLER_GET_THUMBSTICK_CLICK_PATH_SUFFIX,
&ActionResources.ControllerGetThumbstickClickAction,
bindings,
microsoftControllerBindings,
instance);

// Provide default suggested bindings to instance
XrInteractionProfileSuggestedBinding suggestedBindings{ XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING };
XrCheck(xrStringToPath(instance, ActionResources.DEFAULT_XR_INTERACTION_PROFILE, &suggestedBindings.interactionProfile));
suggestedBindings.suggestedBindings = defaultBindings.data();
suggestedBindings.countSuggestedBindings = (uint32_t)defaultBindings.size();
XrCheck(xrSuggestInteractionProfileBindings(instance, &suggestedBindings));

// Provide Microsoft suggested binding to instance
XrInteractionProfileSuggestedBinding microsoftSuggestedBindings{ XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING };
XrCheck(xrStringToPath(instance, ActionResources.MICROSOFT_XR_INTERACTION_PROFILE, &microsoftSuggestedBindings.interactionProfile));
microsoftSuggestedBindings.suggestedBindings = bindings.data();
microsoftSuggestedBindings.countSuggestedBindings = (uint32_t)bindings.size();

// Fallback on the default bindings if the Microsoft bindings fail
if (XR_FAILED(xrSuggestInteractionProfileBindings(instance, &microsoftSuggestedBindings)))
{
ControllerInfo.ControllerBinding = false;
}

if (!ControllerInfo.ControllerBinding)
{
// Provide default suggested bindings to instance
XrInteractionProfileSuggestedBinding suggestedBindings{ XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING };
XrCheck(xrStringToPath(instance, ActionResources.DEFAULT_XR_INTERACTION_PROFILE, &suggestedBindings.interactionProfile));
suggestedBindings.suggestedBindings = bindings.data();
suggestedBindings.countSuggestedBindings = (uint32_t)bindings.size();
XrCheck(xrSuggestInteractionProfileBindings(instance, &suggestedBindings));
}
microsoftSuggestedBindings.suggestedBindings = microsoftControllerBindings.data();
microsoftSuggestedBindings.countSuggestedBindings = (uint32_t)microsoftControllerBindings.size();
ControllerInfo.ControllerBinding = XR_SUCCEEDED(xrSuggestInteractionProfileBindings(instance, &microsoftSuggestedBindings));

XrSessionActionSetsAttachInfo attachInfo{ XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO };
attachInfo.countActionSets = 1;
Expand Down