Skip to content

Commit

Permalink
Adding VR Editor
Browse files Browse the repository at this point in the history
Fix invalid bindings for the editor action set

Configuring the VR Editor for standalone devices

Update the gradle build config to include the openxr editor apks

Configuring the VR Editor for standalone devices

Add a Meta OS splash screen for the Godot XR Editor

- Leverages the Meta OS splash screen functionality: https://developer.oculus.com/documentation/native/android/mobile-splash/
- Fix rebase merge issues

Add scrolling capability to the controller pointer

Fix issue causing tracking to break when running `DocTools::generate(...)`

The issue is caused by the creation of a second `OpenXRInterface` instance. This previously caused the `openxr_api` instance to override its `xr_interface` reference with an instance that was not completely initialized.
The fix consisted in moving the `openxr_api` instance setup within `OpenXRInterface::initialize()` ensuring that the `openxr_api` instance is configured with an initialized instance of `OpenXRInterface`.

Fix merging issues

Remove pico build logic due to inability to test & validate

Update labeling for the Godot XR Editor

Enable ability to launch the Godot Editor immersive window from the 2D project manager
  • Loading branch information
BastiaanOlij committed Sep 7, 2023
1 parent 8449592 commit 4bad053
Show file tree
Hide file tree
Showing 46 changed files with 3,144 additions and 134 deletions.
8 changes: 8 additions & 0 deletions doc/classes/XRCamera3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@
<tutorials>
<link title="XR documentation index">$DOCS_URL/tutorials/xr/index.html</link>
</tutorials>
<methods>
<method name="get_tracking_confidence">
<return type="int" enum="XRPose.TrackingConfidence" />
<description>
Returns the tracking confidence of the camera.
</description>
</method>
</methods>
</class>
6 changes: 6 additions & 0 deletions doc/classes/XRNode3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
Returns the [XRPose] containing the current state of the pose being tracked. This gives access to additional properties of this pose.
</description>
</method>
<method name="get_tracking_confidence">
<return type="int" enum="XRPose.TrackingConfidence" />
<description>
Returns the tracking confidence of this node.
</description>
</method>
<method name="trigger_haptic_pulse">
<return type="void" />
<param index="0" name="action_name" type="String" />
Expand Down
88 changes: 64 additions & 24 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5377,7 +5377,8 @@ void Node3DEditorViewportContainer::gui_input(const Ref<InputEvent> &p_event) {
} break;
case VIEW_USE_3_VIEWPORTS:
case VIEW_USE_3_VIEWPORTS_ALT:
case VIEW_USE_4_VIEWPORTS: {
case VIEW_USE_4_VIEWPORTS:
case VIEW_HIDE_ALL: {
// Do nothing.

} break;
Expand Down Expand Up @@ -5511,6 +5512,8 @@ void Node3DEditorViewportContainer::_notification(int p_what) {
}

} break;
case VIEW_HIDE_ALL: {
} break;
}
}
} break;
Expand Down Expand Up @@ -5622,6 +5625,12 @@ void Node3DEditorViewportContainer::_notification(int p_what) {
fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, mid_h + v_sep / 2), Vector2(size_right, size_bottom)));

} break;
case VIEW_HIDE_ALL: {
// Don't show any, this is used in our VR editor where the 3D environment is handled separately
for (int i = 0; i < 4; i++) {
viewports[i]->hide();
}
}
}
} break;
}
Expand Down Expand Up @@ -5856,28 +5865,30 @@ Dictionary Node3DEditor::get_state() const {

d["local_coords"] = tool_option_button[TOOL_OPT_LOCAL_COORDS]->is_pressed();

int vc = 0;
if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) {
vc = 1;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) {
vc = 2;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) {
vc = 3;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) {
vc = 4;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) {
vc = 5;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) {
vc = 6;
}

d["viewport_mode"] = vc;
Array vpdata;
for (int i = 0; i < 4; i++) {
vpdata.push_back(viewports[i]->get_state());
}
if (enable_3d_viewports) {
int vc = 0;
if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) {
vc = 1;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) {
vc = 2;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) {
vc = 3;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) {
vc = 4;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) {
vc = 5;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) {
vc = 6;
}

d["viewport_mode"] = vc;
Array vpdata;
for (int i = 0; i < 4; i++) {
vpdata.push_back(viewports[i]->get_state());
}

d["viewports"] = vpdata;
d["viewports"] = vpdata;
}

d["show_grid"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID));
d["show_origin"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN));
Expand Down Expand Up @@ -5949,7 +5960,9 @@ void Node3DEditor::set_state(const Dictionary &p_state) {
update_transform_gizmo();
}

if (d.has("viewport_mode")) {
if (!enable_3d_viewports) {
disable_3d_viewports();
} else if (d.has("viewport_mode")) {
int vc = d["viewport_mode"];

if (vc == 1) {
Expand Down Expand Up @@ -7587,7 +7600,12 @@ void Node3DEditor::_update_theme() {
void Node3DEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
_menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT);
if (enable_3d_viewports) {
_menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT);
} else {
// reissue this nor that we're ready
disable_3d_viewports();
}

_refresh_menu_icons();

Expand Down Expand Up @@ -8143,6 +8161,28 @@ void Node3DEditor::_sun_direction_angle_set() {
_preview_settings_changed();
}

void Node3DEditor::disable_3d_viewports() {
enable_3d_viewports = false;

if (is_inside_tree()) {
viewport_base->set_view(Node3DEditorViewportContainer::VIEW_HIDE_ALL);

view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), false);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), false);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), false);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false);

view_menu->get_popup()->set_item_disabled(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), true);
view_menu->get_popup()->set_item_disabled(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), true);
view_menu->get_popup()->set_item_disabled(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), true);
view_menu->get_popup()->set_item_disabled(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), true);
view_menu->get_popup()->set_item_disabled(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), true);
view_menu->get_popup()->set_item_disabled(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), true);
}
}

Node3DEditor::Node3DEditor() {
gizmo.visible = true;
gizmo.scale = 1.0;
Expand Down
4 changes: 4 additions & 0 deletions editor/plugins/node_3d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ class Node3DEditorViewportContainer : public Container {
VIEW_USE_3_VIEWPORTS,
VIEW_USE_3_VIEWPORTS_ALT,
VIEW_USE_4_VIEWPORTS,
VIEW_HIDE_ALL,
};

private:
Expand Down Expand Up @@ -595,6 +596,7 @@ class Node3DEditor : public VBoxContainer {

ToolMode tool_mode;

bool enable_3d_viewports = true; // We disable viewports in our VR editor.
RID origin;
RID origin_instance;
bool origin_enabled = false;
Expand Down Expand Up @@ -922,6 +924,8 @@ class Node3DEditor : public VBoxContainer {
void edit(Node3D *p_spatial);
void clear();

void disable_3d_viewports();

Node3DEditor();
~Node3DEditor();
};
Expand Down
36 changes: 33 additions & 3 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "servers/display_server.h"
#include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h"
#include "servers/xr_server.h"

constexpr int GODOT4_CONFIG_VERSION = 5;

Expand Down Expand Up @@ -1957,6 +1958,9 @@ void ProjectManager::_notification(int p_what) {
import_btn->set_icon(get_editor_theme_icon(SNAME("Load")));
scan_btn->set_icon(get_editor_theme_icon(SNAME("Search")));
open_btn->set_icon(get_editor_theme_icon(SNAME("Edit")));
#if defined(MODULE_VR_EDITOR_ENABLED)
open_in_xr_btn->set_icon(get_editor_theme_icon(SNAME("Edit")));
#endif
run_btn->set_icon(get_editor_theme_icon(SNAME("Play")));
rename_btn->set_icon(get_editor_theme_icon(SNAME("Rename")));
manage_tags_btn->set_icon(get_editor_theme_icon("Script"));
Expand All @@ -1971,6 +1975,9 @@ void ProjectManager::_notification(int p_what) {
import_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
scan_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
open_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
#if defined(MODULE_VR_EDITOR_ENABLED)
open_in_xr_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
#endif
run_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
rename_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
manage_tags_btn->add_theme_constant_override("h_separation", get_theme_constant(SNAME("sidebar_button_icon_separation"), SNAME("ProjectManager")));
Expand Down Expand Up @@ -2086,6 +2093,9 @@ void ProjectManager::_update_project_buttons() {

erase_btn->set_disabled(empty_selection);
open_btn->set_disabled(empty_selection || is_missing_project_selected);
#if defined(MODULE_VR_EDITOR_ENABLED)
open_in_xr_btn->set_disabled(empty_selection || is_missing_project_selected || selected_projects.size() > 1);
#endif
rename_btn->set_disabled(empty_selection || is_missing_project_selected);
manage_tags_btn->set_disabled(empty_selection || is_missing_project_selected || selected_projects.size() > 1);
run_btn->set_disabled(empty_selection || is_missing_project_selected);
Expand Down Expand Up @@ -2248,6 +2258,12 @@ void ProjectManager::_open_selected_projects() {
args.push_back(path);

args.push_back("--editor");
#if defined(MODULE_VR_EDITOR_ENABLED)
if (_open_in_xr) {
args.push_back("--xr-mode");
args.push_back("on");
}
#endif

Error err = OS::get_singleton()->create_instance(args);
ERR_FAIL_COND(err);
Expand All @@ -2259,7 +2275,10 @@ void ProjectManager::_open_selected_projects() {
get_tree()->quit();
}

void ProjectManager::_open_selected_projects_ask() {
void ProjectManager::_open_selected_projects_ask(bool p_open_in_xr) {
#if defined(MODULE_VR_EDITOR_ENABLED)
_open_in_xr = p_open_in_xr;
#endif
const HashSet<String> &selected_list = _project_list->get_selected_project_keys();

if (selected_list.size() < 1) {
Expand All @@ -2269,6 +2288,9 @@ void ProjectManager::_open_selected_projects_ask() {
const Size2i popup_min_size = Size2i(600.0 * EDSCALE, 0);

if (selected_list.size() > 1) {
if (p_open_in_xr) {
return;
}
multi_open_ask->set_text(vformat(TTR("You requested to open %d projects in parallel. Do you confirm?\nNote that usual checks for engine version compatibility will be bypassed."), selected_list.size()));
multi_open_ask->popup_centered(popup_min_size);
return;
Expand Down Expand Up @@ -2936,7 +2958,7 @@ ProjectManager::ProjectManager() {

_project_list = memnew(ProjectList);
_project_list->connect(ProjectList::SIGNAL_SELECTION_CHANGED, callable_mp(this, &ProjectManager::_update_project_buttons));
_project_list->connect(ProjectList::SIGNAL_PROJECT_ASK_OPEN, callable_mp(this, &ProjectManager::_open_selected_projects_ask));
_project_list->connect(ProjectList::SIGNAL_PROJECT_ASK_OPEN, callable_mp(this, &ProjectManager::_open_selected_projects_ask).bind(false));
_project_list->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
search_panel->add_child(_project_list);

Expand All @@ -2950,9 +2972,17 @@ ProjectManager::ProjectManager() {
open_btn = memnew(Button);
open_btn->set_text(TTR("Edit"));
open_btn->set_shortcut(ED_SHORTCUT("project_manager/edit_project", TTR("Edit Project"), KeyModifierMask::CMD_OR_CTRL | Key::E));
open_btn->connect("pressed", callable_mp(this, &ProjectManager::_open_selected_projects_ask));
open_btn->connect("pressed", callable_mp(this, &ProjectManager::_open_selected_projects_ask).bind(false));
tree_vb->add_child(open_btn);

#if defined(MODULE_VR_EDITOR_ENABLED)
open_in_xr_btn = memnew(Button);
open_in_xr_btn->set_text(TTR("Edit in XR"));
open_in_xr_btn->connect("pressed", callable_mp(this, &ProjectManager::_open_selected_projects_ask).bind(true));
open_in_xr_btn->set_visible(XRServer::get_xr_mode() != XRServer::XRMODE_ON);
tree_vb->add_child(open_in_xr_btn);
#endif

run_btn = memnew(Button);
run_btn->set_text(TTR("Run"));
run_btn->set_shortcut(ED_SHORTCUT("project_manager/run_project", TTR("Run Project"), KeyModifierMask::CMD_OR_CTRL | Key::R));
Expand Down
10 changes: 9 additions & 1 deletion editor/project_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "core/io/config_file.h"
#include "editor/editor_about.h"
#include "modules/modules_enabled.gen.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/file_dialog.h"
#include "scene/gui/scroll_container.h"
Expand Down Expand Up @@ -325,6 +326,10 @@ class ProjectList : public ScrollContainer {
class ProjectManager : public Control {
GDCLASS(ProjectManager, Control);

#if defined(MODULE_VR_EDITOR_ENABLED)
bool _open_in_xr = false;
#endif

HashMap<String, Ref<Texture2D>> icon_type_cache;
void _build_icon_type_cache(Ref<Theme> p_theme);

Expand All @@ -343,6 +348,9 @@ class ProjectManager : public Control {
Button *import_btn = nullptr;
Button *scan_btn = nullptr;
Button *open_btn = nullptr;
#if defined(MODULE_VR_EDITOR_ENABLED)
Button *open_in_xr_btn = nullptr;
#endif
Button *run_btn = nullptr;
Button *rename_btn = nullptr;
Button *manage_tags_btn = nullptr;
Expand Down Expand Up @@ -400,7 +408,7 @@ class ProjectManager : public Control {
void _run_project();
void _run_project_confirm();
void _open_selected_projects();
void _open_selected_projects_ask();
void _open_selected_projects_ask(bool p_open_in_xr = false);
void _full_convert_button_pressed();
void _perform_full_project_conversion();
void _import_project();
Expand Down
36 changes: 28 additions & 8 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@
#include "modules/gdscript/gdscript.h"
#endif

#ifdef MODULE_VR_EDITOR_ENABLED
#include "modules/vr_editor/vr_editor.h"
#include "modules/vr_editor/vr_project_manager.h"
#endif

/* Static members */

// Singletons
Expand Down Expand Up @@ -870,7 +875,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
if (I->get() == "--audio-driver" ||
I->get() == "--display-driver" ||
I->get() == "--rendering-method" ||
I->get() == "--rendering-driver") {
I->get() == "--rendering-driver" ||
I->get() == "--xr-mode") {
if (I->next()) {
forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(I->get());
forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(I->next()->get());
Expand Down Expand Up @@ -1604,7 +1610,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
if (editor) {
packed_data->set_disabled(true);
main_args.push_back("--editor");
if (!init_windowed) {
if (!init_windowed && XRServer::get_xr_mode() != XRServer::XRMODE_ON) {
init_maximized = true;
window_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
}
Expand Down Expand Up @@ -3147,8 +3153,14 @@ bool Main::start() {
EditorNode *editor_node = nullptr;
if (editor) {
OS::get_singleton()->benchmark_begin_measure("editor");
editor_node = memnew(EditorNode);
sml->get_root()->add_child(editor_node);

#ifdef MODULE_VR_EDITOR_ENABLED
editor_node = VREditor::init_editor(sml);
#endif
if (!editor_node) {
editor_node = memnew(EditorNode);
sml->get_root()->add_child(editor_node);
}

if (!_export_preset.is_empty()) {
editor_node->export_preset(_export_preset, positional_arg, export_debug, export_pack_only);
Expand Down Expand Up @@ -3340,10 +3352,18 @@ bool Main::start() {
if (project_manager) {
OS::get_singleton()->benchmark_begin_measure("project_manager");
Engine::get_singleton()->set_editor_hint(true);
ProjectManager *pmanager = memnew(ProjectManager);
ProgressDialog *progress_dialog = memnew(ProgressDialog);
pmanager->add_child(progress_dialog);
sml->get_root()->add_child(pmanager);

bool has_vr_editor = false;
#ifdef MODULE_VR_EDITOR_ENABLED
has_vr_editor = VRProjectManager::init_project_manager(sml);
#endif

if (!has_vr_editor) {
ProjectManager *pmanager = memnew(ProjectManager);
ProgressDialog *progress_dialog = memnew(ProgressDialog);
pmanager->add_child(progress_dialog);
sml->get_root()->add_child(pmanager);
}
DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_PROJECTMAN);
OS::get_singleton()->benchmark_end_measure("project_manager");
}
Expand Down
Loading

0 comments on commit 4bad053

Please sign in to comment.