diff --git a/demo/export_presets.cfg b/demo/export_presets.cfg index ff469fb8..1732b3ec 100644 --- a/demo/export_presets.cfg +++ b/demo/export_presets.cfg @@ -231,6 +231,7 @@ khronos_xr_features/htc/eye_tracking=0 khronos_xr_features/htc/lip_expression=0 pico_xr_features/eye_tracking=0 pico_xr_features/face_tracking=0 +khronos_xr_features/vendors=0 [preset.1] @@ -465,6 +466,7 @@ meta_xr_features/quest_pro_support=true xr_features/enable_pico_plugin=false pico_xr_features/eye_tracking=0 pico_xr_features/face_tracking=0 +khronos_xr_features/vendors=0 [preset.2] @@ -699,6 +701,7 @@ meta_xr_features/quest_pro_support=true xr_features/enable_pico_plugin=true pico_xr_features/eye_tracking=1 pico_xr_features/face_tracking=3 +khronos_xr_features/vendors=0 [preset.3] @@ -933,6 +936,7 @@ meta_xr_features/quest_pro_support=true xr_features/enable_pico_plugin=false pico_xr_features/eye_tracking=0 pico_xr_features/face_tracking=0 +khronos_xr_features/vendors=0 [preset.4] diff --git a/godotopenxr/src/main/cpp/include/register_types.h b/godotopenxr/src/main/cpp/include/register_types.h index cdf62ca1..afb80d93 100644 --- a/godotopenxr/src/main/cpp/include/register_types.h +++ b/godotopenxr/src/main/cpp/include/register_types.h @@ -35,3 +35,5 @@ using namespace godot; void initialize_plugin_module(ModuleInitializationLevel p_level); void terminate_plugin_module(ModuleInitializationLevel p_level); + +void add_plugin_project_settings(); diff --git a/godotopenxr/src/main/cpp/register_types.cpp b/godotopenxr/src/main/cpp/register_types.cpp index 72c07dfa..ea7102eb 100644 --- a/godotopenxr/src/main/cpp/register_types.cpp +++ b/godotopenxr/src/main/cpp/register_types.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -154,6 +155,8 @@ void initialize_plugin_module(ModuleInitializationLevel p_level) { break; case MODULE_INITIALIZATION_LEVEL_SCENE: { + add_plugin_project_settings(); + Engine::get_singleton()->register_singleton("OpenXRFbPassthroughExtensionWrapper", OpenXRFbPassthroughExtensionWrapper::get_singleton()); Engine::get_singleton()->register_singleton("OpenXRFbRenderModelExtensionWrapper", OpenXRFbRenderModelExtensionWrapper::get_singleton()); Engine::get_singleton()->register_singleton("OpenXRFbSceneCaptureExtensionWrapper", OpenXRFbSceneCaptureExtensionWrapper::get_singleton()); @@ -209,6 +212,30 @@ void initialize_plugin_module(ModuleInitializationLevel p_level) { void terminate_plugin_module(ModuleInitializationLevel p_level) { } +void add_plugin_project_settings() { + ProjectSettings* project_settings = ProjectSettings::get_singleton(); + if (project_settings == nullptr) { + return; + } + + { + // Add the 'automatically_request_runtime_permissions' project setting + String request_permissions_setting = "xr/openxr/extensions/automatically_request_runtime_permissions"; + if (!project_settings->has_setting(request_permissions_setting)) { + // Default value is `true` to match prior plugin behavior + project_settings->set_setting(request_permissions_setting, true); + } + + project_settings->set_initial_value(request_permissions_setting, true); + project_settings->set_as_basic(request_permissions_setting, false); + Dictionary property_info; + property_info["name"] = request_permissions_setting; + property_info["type"] = Variant::Type::BOOL; + property_info["hint"] = PROPERTY_HINT_NONE; + project_settings->add_property_info(property_info); + } +} + extern "C" { GDExtensionBool GDE_EXPORT plugin_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) { godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization); diff --git a/godotopenxr/src/main/java/org/godotengine/openxr/vendors/GodotOpenXR.kt b/godotopenxr/src/main/java/org/godotengine/openxr/vendors/GodotOpenXR.kt index b58b3f9f..6c1a8fcc 100644 --- a/godotopenxr/src/main/java/org/godotengine/openxr/vendors/GodotOpenXR.kt +++ b/godotopenxr/src/main/java/org/godotengine/openxr/vendors/GodotOpenXR.kt @@ -31,6 +31,7 @@ package org.godotengine.openxr.vendors import android.util.Log import org.godotengine.godot.Godot +import org.godotengine.godot.GodotLib import org.godotengine.godot.plugin.GodotPlugin import org.godotengine.godot.utils.PermissionsUtil @@ -56,10 +57,19 @@ abstract class GodotOpenXR(godot: Godot?) : GodotPlugin(godot) { override fun onGodotSetupCompleted() { super.onGodotSetupCompleted() - // Request plugin permissions if needed - val permissionsToRequest = getPluginPermissionsToEnable() - if (permissionsToRequest.isNotEmpty()) { - PermissionsUtil.requestPermissions(activity, permissionsToRequest) + // Check if automatic permissions request is enabled. + val automaticallyRequestPermissionsSetting = GodotLib.getGlobal("xr/openxr/extensions/automatically_request_runtime_permissions") + // We only request permissions when the project setting is enabled. + // If the project setting is not defined, we fall-back to the default behavior which is + // to automatically request permissions. + val requestPermissionsEnabled = automaticallyRequestPermissionsSetting.isNullOrEmpty() || + automaticallyRequestPermissionsSetting.toBoolean() + if (requestPermissionsEnabled) { + val permissionsToRequest = getPluginPermissionsToEnable() + if (permissionsToRequest.isNotEmpty()) { + Log.v(TAG, "Performing automatic request of runtime permissions") + PermissionsUtil.requestPermissions(activity, permissionsToRequest) + } } }