From a7ce6b8d7c30768d064638c42fd06d6f909fafdf Mon Sep 17 00:00:00 2001 From: Bastiaan Olij Date: Thu, 18 Feb 2021 14:05:42 +1100 Subject: [PATCH] Adding a runtime selection dropdown into the editor --- demo/Main.tscn | 15 ------ .../godot-openxr/OpenXRRuntimeSelect.gdns | 8 +++ .../godot-openxr/editor/OpenXRRunSelect.gd | 53 +++++++++++++++++++ .../godot-openxr/editor/OpenXRRunSelect.tscn | 14 +++++ demo/addons/godot-openxr/plugin.cfg | 7 +++ demo/addons/godot-openxr/plugin.gd | 15 ++++++ demo/addons/godot-openxr/runtimes.json | 22 ++++++++ demo/project.godot | 4 ++ src/godot_openxr.cpp | 1 + 9 files changed, 124 insertions(+), 15 deletions(-) create mode 100644 demo/addons/godot-openxr/OpenXRRuntimeSelect.gdns create mode 100644 demo/addons/godot-openxr/editor/OpenXRRunSelect.gd create mode 100644 demo/addons/godot-openxr/editor/OpenXRRunSelect.tscn create mode 100644 demo/addons/godot-openxr/plugin.cfg create mode 100644 demo/addons/godot-openxr/plugin.gd create mode 100644 demo/addons/godot-openxr/runtimes.json diff --git a/demo/Main.tscn b/demo/Main.tscn index 061886ee..9d80920c 100644 --- a/demo/Main.tscn +++ b/demo/Main.tscn @@ -55,23 +55,13 @@ visible = true [node name="Info" parent="FPSController/LeftHandController" index="0" instance=ExtResource( 8 )] transform = Transform( 1, 0, 0, 0, 0.939693, 0.34202, 0, -0.34202, 0.939693, 0.0483518, 0.0719222, 0 ) -enabled = true screen_size = Vector2( 0.16, 0.12 ) viewport_size = Vector2( 600, 400 ) -transparent = true scene = ExtResource( 9 ) collision_layer = 0 [node name="Function_Teleport" parent="FPSController/LeftHandController" index="1" instance=ExtResource( 10 )] collision_mask = 1022 -enabled = true -teleport_button = 15 -can_teleport_color = Color( 0, 1, 0, 1 ) -cant_teleport_color = Color( 1, 0, 0, 1 ) -player_height = 1.8 -player_radius = 0.4 -strength = 5.0 -max_slope = 20.0 camera = NodePath("../../ARVRCamera") [node name="Function_pointer" parent="FPSController/LeftHandController" index="2" instance=ExtResource( 13 )] @@ -85,10 +75,8 @@ visible = true [node name="Info" parent="FPSController/RightHandController" index="0" instance=ExtResource( 8 )] transform = Transform( 1, 0, 0, 0, 0.939693, 0.34202, 0, -0.34202, 0.939693, -0.0871993, 0.072, 0 ) -enabled = true screen_size = Vector2( 0.16, 0.12 ) viewport_size = Vector2( 600, 400 ) -transparent = true scene = ExtResource( 9 ) collision_layer = 0 @@ -134,10 +122,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -6 ) [node name="Screen" parent="." instance=ExtResource( 8 )] transform = Transform( 0.843251, 0, -0.53752, 0, 1, 0, 0.53752, 0, 0.843251, 1.92678, 1.5, -2.47671 ) -enabled = true -screen_size = Vector2( 3, 2 ) viewport_size = Vector2( 600, 400 ) -transparent = true scene = ExtResource( 12 ) collision_layer = 1024 diff --git a/demo/addons/godot-openxr/OpenXRRuntimeSelect.gdns b/demo/addons/godot-openxr/OpenXRRuntimeSelect.gdns new file mode 100644 index 00000000..b36afb43 --- /dev/null +++ b/demo/addons/godot-openxr/OpenXRRuntimeSelect.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://addons/godot-openxr/godot_openxr.gdnlib" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "OpenXRRuntimeSelect" +class_name = "OpenXRRuntimeSelect" +library = ExtResource( 1 ) diff --git a/demo/addons/godot-openxr/editor/OpenXRRunSelect.gd b/demo/addons/godot-openxr/editor/OpenXRRunSelect.gd new file mode 100644 index 00000000..71d242ca --- /dev/null +++ b/demo/addons/godot-openxr/editor/OpenXRRunSelect.gd @@ -0,0 +1,53 @@ +tool +extends OptionButton + +var available_runtimes : Array = Array() +onready var platform = OS.get_name() + +# Called when the node enters the scene tree for the first time. +func _ready(): + var current_runtime = 0 + + # read our json file, may have entries for multiple platforms, we'll filter them later + var f = File.new() + if (f.open("res://addons/godot-openxr/runtimes.json", File.READ)) == OK: + var json = JSON.parse(f.get_as_text()) + available_runtimes = json.result as Array + f.close() + + # check what our current value is + var current_path = OS.get_environment("XR_RUNTIME_JSON") + + if available_runtimes.size() > 0: + # reset our dropdown if applicable + clear() + add_item("Default", -1) + + # check which runtimes are actually available + var dir = Directory.new() + var index = 0 + for i in available_runtimes.size(): + var runtime = available_runtimes[i] + if dir.file_exists(runtime["path"]): + add_item(runtime["name"], i) + index = index + 1 + if available_runtimes[i]["path"] == current_path: + current_runtime = index + + selected = current_runtime + + visible = true + else: + # I guess nothing supported on this platform + visible = false + +func _on_OpenXRRunSelect_item_selected(index): + # this need latest 3.2.4 + if index == 0: + print("Returning to default") + OS.set_environment("XR_RUNTIME_JSON", "") + else: + var i = get_item_id(index) + var runtime = available_runtimes[i]["path"] + print("Switching to " + runtime) + OS.set_environment("XR_RUNTIME_JSON", runtime) diff --git a/demo/addons/godot-openxr/editor/OpenXRRunSelect.tscn b/demo/addons/godot-openxr/editor/OpenXRRunSelect.tscn new file mode 100644 index 00000000..1066f9d9 --- /dev/null +++ b/demo/addons/godot-openxr/editor/OpenXRRunSelect.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/godot-openxr/editor/OpenXRRunSelect.gd" type="Script" id=1] + +[node name="OpenXRRunSelect" type="OptionButton"] +text = "Default" +items = [ "Default", null, false, 9999, null, "SteamVR", null, false, 0, null, "Oculus", null, false, 1, null, "Microsoft MR", null, false, 2, null ] +selected = 0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[connection signal="item_selected" from="." to="." method="_on_OpenXRRunSelect_item_selected"] diff --git a/demo/addons/godot-openxr/plugin.cfg b/demo/addons/godot-openxr/plugin.cfg new file mode 100644 index 00000000..9d57b2b1 --- /dev/null +++ b/demo/addons/godot-openxr/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Godot OpenXR" +description="Godot OpenXR plugin" +author="Christoph Haagch and Bastiaan Olij" +version="1.0.1" +script="plugin.gd" diff --git a/demo/addons/godot-openxr/plugin.gd b/demo/addons/godot-openxr/plugin.gd new file mode 100644 index 00000000..4d9cfb47 --- /dev/null +++ b/demo/addons/godot-openxr/plugin.gd @@ -0,0 +1,15 @@ +tool +extends EditorPlugin + +var openxr_run_select = null + +func _enter_tree(): + # multiple runtimes are currently only supported on Windows + openxr_run_select = preload("res://addons/godot-openxr/editor/OpenXRRunSelect.tscn").instance() + add_control_to_container(CONTAINER_TOOLBAR, openxr_run_select) + +func _exit_tree(): + if openxr_run_select: + remove_control_from_container(EditorPlugin.CONTAINER_TOOLBAR, openxr_run_select) + openxr_run_select.queue_free() + openxr_run_select = null diff --git a/demo/addons/godot-openxr/runtimes.json b/demo/addons/godot-openxr/runtimes.json new file mode 100644 index 00000000..e3cf1398 --- /dev/null +++ b/demo/addons/godot-openxr/runtimes.json @@ -0,0 +1,22 @@ +[ + { + "name": "Monado", + "path": "/usr/share/openxr/1/openxr_monado.json" + }, + { + "name": "SteamVR", + "path": "~/.steam/steam/steamapps/common/SteamVR/steamxr_linux64.json" + }, + { + "name": "SteamVR", + "path": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\SteamVR\\steamxr_win64.json" + }, + { + "name": "Oculus", + "path": "C:\\Program Files\\Oculus\\Support\\oculus-runtime\\oculus_openxr_64.json" + }, + { + "name": "Microsoft MR", + "path": "C:\\WINDOWS\\system32\\MixedRealityRuntime.json" + } +] diff --git a/demo/project.godot b/demo/project.godot index d9cbab95..f796aa9e 100644 --- a/demo/project.godot +++ b/demo/project.godot @@ -18,6 +18,10 @@ config/icon="res://icon.png" window/vsync/use_vsync=false +[editor_plugins] + +enabled=PoolStringArray( "res://addons/godot-openxr/plugin.cfg" ) + [gdnative] singletons=[ "res://addons/godot-openxr/godot_openxr.gdnlib" ] diff --git a/src/godot_openxr.cpp b/src/godot_openxr.cpp index 7c986201..1170a171 100644 --- a/src/godot_openxr.cpp +++ b/src/godot_openxr.cpp @@ -5,6 +5,7 @@ // with loads of help from Thomas "Karroffel" Herzog #include "godot_openxr.h" + #include "openxr/OpenXRConfig.h" #include "openxr/OpenXRHand.h" #include "openxr/OpenXRPose.h"