Filter out HTC OpenXR paths based on extension

This commit is contained in:
Bastiaan Olij 2022-10-17 20:35:18 +11:00
parent 28a4eec9a7
commit 19f9fe1dec
4 changed files with 51 additions and 21 deletions

View File

@ -69,6 +69,34 @@ bool OpenXRHTCViveTrackerExtension::on_event_polled(const XrEventDataBuffer &eve
bool OpenXRHTCViveTrackerExtension::is_path_supported(const String &p_path) {
if (p_path == "/interaction_profiles/htc/vive_tracker_htcx") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/handheld_object") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/left_foot") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/right_foot") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/left_shoulder") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/right_shoulder") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/left_elbow") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/right_elbow") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/left_knee") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/right_knee") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/waist") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/chest") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/chest") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/camera") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/keyboard") {
return available;
}
// Not a path under this extensions control, so we return true;

View File

@ -84,8 +84,6 @@ private:
bool ext_vive_focus3_available = false;
bool ext_huawei_controller_available = false;
bool is_path_supported(const String &p_path);
// composition layer providers
Vector<OpenXRCompositionLayerProvider *> composition_layer_providers;
@ -302,6 +300,7 @@ public:
void parse_velocities(const XrSpaceVelocity &p_velocity, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity);
bool xr_result(XrResult result, const char *format, Array args = Array()) const;
bool is_path_supported(const String &p_path);
static bool openxr_is_enabled(bool p_check_run_in_editor = true);
static OpenXRAPI *get_singleton();

View File

@ -154,24 +154,25 @@ void OpenXRInterface::_load_action_map() {
Ref<OpenXRAction> xr_action = actions[j];
PackedStringArray toplevel_paths = xr_action->get_toplevel_paths();
Vector<Tracker *> trackers_new;
Vector<Tracker *> trackers_for_action;
for (int k = 0; k < toplevel_paths.size(); k++) {
Tracker *tracker = find_tracker(toplevel_paths[k], true);
if (tracker) {
trackers_new.push_back(tracker);
// Only check for our tracker if our path is supported.
if (openxr_api->is_path_supported(toplevel_paths[k])) {
Tracker *tracker = find_tracker(toplevel_paths[k], true);
if (tracker) {
trackers_for_action.push_back(tracker);
}
}
}
Action *action = create_action(action_set, xr_action->get_name(), xr_action->get_localized_name(), xr_action->get_action_type(), trackers);
if (action) {
// we link our actions back to our trackers so we know which actions to check when we're processing our trackers
for (int t = 0; t < trackers_new.size(); t++) {
link_action_to_tracker(trackers_new[t], action);
// Only add our action if we have atleast one valid toplevel path
if (trackers_for_action.size() > 0) {
Action *action = create_action(action_set, xr_action->get_name(), xr_action->get_localized_name(), xr_action->get_action_type(), trackers_for_action);
if (action) {
// add this to our map for creating our interaction profiles
xr_actions[xr_action] = action;
}
// add this to our map for creating our interaction profiles
xr_actions[xr_action] = action;
}
}
}
@ -289,6 +290,13 @@ OpenXRInterface::Action *OpenXRInterface::create_action(ActionSet *p_action_set,
action->action_rid = openxr_api->action_create(p_action_set->action_set_rid, p_action_name, p_localized_name, p_action_type, tracker_rids);
p_action_set->actions.push_back(action);
// we link our actions back to our trackers so we know which actions to check when we're processing our trackers
for (int i = 0; i < p_trackers.size(); i++) {
if (p_trackers[i]->actions.find(action) == -1) {
p_trackers[i]->actions.push_back(action);
}
}
return action;
}
@ -337,6 +345,8 @@ OpenXRInterface::Tracker *OpenXRInterface::find_tracker(const String &p_tracker_
return nullptr;
}
ERR_FAIL_COND_V(!openxr_api->is_path_supported(p_tracker_name), nullptr);
// Create our RID
RID tracker_rid = openxr_api->tracker_create(p_tracker_name);
ERR_FAIL_COND_V(tracker_rid.is_null(), nullptr);
@ -396,12 +406,6 @@ void OpenXRInterface::tracker_profile_changed(RID p_tracker, RID p_interaction_p
}
}
void OpenXRInterface::link_action_to_tracker(Tracker *p_tracker, Action *p_action) {
if (p_tracker->actions.find(p_action) == -1) {
p_tracker->actions.push_back(p_action);
}
}
void OpenXRInterface::handle_tracker(Tracker *p_tracker) {
ERR_FAIL_NULL(openxr_api);
ERR_FAIL_COND(p_tracker->positional_tracker.is_null());

View File

@ -91,7 +91,6 @@ private:
void free_actions(ActionSet *p_action_set);
Tracker *find_tracker(const String &p_tracker_name, bool p_create = false);
void link_action_to_tracker(Tracker *p_tracker, Action *p_action);
void handle_tracker(Tracker *p_tracker);
void free_trackers();