Path: blob/master/modules/openxr/editor/openxr_editor_plugin.cpp
20852 views
/**************************************************************************/1/* openxr_editor_plugin.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "openxr_editor_plugin.h"3132#include "../action_map/openxr_action_map.h"33#include "../openxr_api.h"3435#include "editor/docks/editor_dock_manager.h"36#include "editor/editor_node.h"37#include "platform/android/export/export_plugin.h"3839#include <openxr/openxr.h>4041////////////////////////////////////////////////////////////////////////////42// OpenXRExportPlugin4344bool OpenXRExportPlugin::supports_platform(const Ref<EditorExportPlatform> &p_export_platform) const {45return p_export_platform->is_class(EditorExportPlatformAndroid::get_class_static());46}4748bool OpenXRExportPlugin::is_openxr_mode() const {49// Check if OpenXR is enabled using `EditorExportPlatform::get_project_settings()` because that'll50// take into account the feature tags on the specific export preset that is being exported.51bool openxr_enabled = (bool)get_export_platform()->get_project_setting(get_export_preset(), "xr/openxr/enabled");52int xr_mode_index = get_option("xr_features/xr_mode");5354return openxr_enabled && xr_mode_index == XR_MODE_OPENXR;55}5657String OpenXRExportPlugin::_get_export_option_warning(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {58if (!supports_platform(p_export_platform)) {59return String();60}6162bool gradle_build = get_option("gradle_build/use_gradle_build");63if (is_openxr_mode() && !gradle_build) {64return "\"Use Gradle Build\" must be enabled when xr_mode is set to \"OpenXR\".";65}6667return String();68}6970PackedStringArray OpenXRExportPlugin::get_android_dependencies(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {71PackedStringArray ret;7273if (!supports_platform(p_export_platform)) {74return ret;75}7677if (is_openxr_mode()) {78// Loader is always identified by the full API version even if we're initializing for OpenXR 1.0.79int major = XR_VERSION_MAJOR(XR_CURRENT_API_VERSION);80int minor = XR_VERSION_MINOR(XR_CURRENT_API_VERSION);81int patch = XR_VERSION_PATCH(XR_CURRENT_API_VERSION);82String openxr_loader = "org.khronos.openxr:openxr_loader_for_android:" + String::num_int64(major) + "." + String::num_int64(minor) + "." + String::num_int64(patch);8384ret.push_back(openxr_loader);85}8687return ret;88}8990PackedStringArray OpenXRExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {91PackedStringArray features;9293if (!supports_platform(p_export_platform) || !is_openxr_mode()) {94return features;95}9697// Placeholder for now9899return features;100}101102String OpenXRExportPlugin::get_android_manifest_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {103String contents;104105if (!supports_platform(p_export_platform) || !is_openxr_mode()) {106return contents;107}108109contents += R"n(110<uses-permission android:name="org.khronos.openxr.permission.OPENXR" />111<uses-permission android:name="org.khronos.openxr.permission.OPENXR_SYSTEM" />112113<queries>114<provider android:authorities="org.khronos.openxr.runtime_broker;org.khronos.openxr.system_runtime_broker" />115116<intent>117<action android:name="org.khronos.openxr.OpenXRRuntimeService" />118</intent>119<intent>120<action android:name="org.khronos.openxr.OpenXRApiLayerService" />121</intent>122123</queries>124)n";125126#ifndef DISABLE_DEPRECATED127// This logic addresses the issue from https://github.com/GodotVR/godot_openxr_vendors/issues/429.128// The issue is caused by this plugin and the vendors plugin adding the same `uses-feature` tag to the generated129// manifest, causing a duplicate error at build time.130// In order to maintain backward compatibility, we fix the issue by disabling the addition of the `uses-feature`131// tag from this plugin when specific conditions are met.132bool meta_plugin_enabled = get_option("xr_features/enable_meta_plugin");133int meta_boundary_mode = get_option("meta_xr_features/boundary_mode");134if (!meta_plugin_enabled || meta_boundary_mode != 1 /* BOUNDARY_DISABLED_VALUE */) {135#endif // DISABLE_DEPRECATED136contents += " <uses-feature android:name=\"android.hardware.vr.headtracking\" android:required=\"false\" android:version=\"1\" />\n";137#ifndef DISABLE_DEPRECATED138}139#endif // DISABLE_DEPRECATED140141return contents;142}143144String OpenXRExportPlugin::get_android_manifest_activity_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {145String contents;146147if (!supports_platform(p_export_platform) || !is_openxr_mode()) {148return contents;149}150151contents += R"n(152<intent-filter>153<action android:name="android.intent.action.MAIN" />154155<category android:name="android.intent.category.DEFAULT" />156157<category android:name="org.khronos.openxr.intent.category.IMMERSIVE_HMD" />158</intent-filter>159)n";160161return contents;162}163164////////////////////////////////////////////////////////////////////////////165// OpenXREditorPlugin166167void OpenXREditorPlugin::edit(Object *p_node) {168if (action_map_editor && Object::cast_to<OpenXRActionMap>(p_node)) {169String path = Object::cast_to<OpenXRActionMap>(p_node)->get_path();170if (path.is_resource_file()) {171action_map_editor->open_action_map(path);172}173}174}175176bool OpenXREditorPlugin::handles(Object *p_node) const {177if (action_map_editor) {178return (Object::cast_to<OpenXRActionMap>(p_node) != nullptr);179}180return false;181}182183void OpenXREditorPlugin::make_visible(bool p_visible) {184}185186OpenXREditorPlugin::OpenXREditorPlugin() {187// Only add our OpenXR action map editor if OpenXR is enabled for the whole project.188if (OpenXRAPI::openxr_is_enabled(false)) {189action_map_editor = memnew(OpenXRActionMapEditor);190EditorDockManager::get_singleton()->add_dock(action_map_editor);191192binding_modifier_inspector_plugin = Ref<EditorInspectorPluginBindingModifier>(memnew(EditorInspectorPluginBindingModifier));193EditorInspector::add_inspector_plugin(binding_modifier_inspector_plugin);194195#ifndef ANDROID_ENABLED196select_runtime = memnew(OpenXRSelectRuntime);197add_control_to_container(CONTAINER_TOOLBAR, select_runtime);198#endif199}200}201202void OpenXREditorPlugin::_notification(int p_what) {203switch (p_what) {204case NOTIFICATION_ENTER_TREE: {205// Initialize our export plugin206openxr_export_plugin.instantiate();207add_export_plugin(openxr_export_plugin);208} break;209case NOTIFICATION_EXIT_TREE: {210// Clean up our export plugin211remove_export_plugin(openxr_export_plugin);212213openxr_export_plugin.unref();214}215}216}217218219