Skip to content

Commit

Permalink
Adding a runtime selection dropdown into the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed Feb 25, 2021
1 parent 874372c commit aec9a11
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 15 deletions.
15 changes: 0 additions & 15 deletions demo/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )]
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
53 changes: 53 additions & 0 deletions demo/addons/godot-openxr/editor/OpenXRRunSelect.gd
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions demo/addons/godot-openxr/editor/OpenXRRunSelect.tscn
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 7 additions & 0 deletions demo/addons/godot-openxr/plugin.cfg
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 15 additions & 0 deletions demo/addons/godot-openxr/plugin.gd
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions demo/addons/godot-openxr/runtimes.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
4 changes: 4 additions & 0 deletions demo/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
1 change: 1 addition & 0 deletions src/godot_openxr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit aec9a11

Please sign in to comment.