mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-22 23:50:25 +01:00
switch to tab indentation
This commit is contained in:
parent
31b6e199ff
commit
3d3c13869b
8 changed files with 139 additions and 139 deletions
|
@ -3,8 +3,8 @@ extends EditorPlugin
|
||||||
|
|
||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
add_autoload_singleton("OverlayInit", "res://addons/openvr_overlay/overlay_init.gd")
|
add_autoload_singleton("OverlayInit", "res://addons/openvr_overlay/overlay_init.gd")
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree() -> void:
|
func _exit_tree() -> void:
|
||||||
remove_autoload_singleton("OverlayInit")
|
remove_autoload_singleton("OverlayInit")
|
||||||
|
|
|
@ -4,18 +4,18 @@ var ovr_interface: ARVRInterface
|
||||||
|
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
var ovr_config = preload("res://addons/godot-openvr/OpenVRConfig.gdns").new()
|
var ovr_config = preload("res://addons/godot-openvr/OpenVRConfig.gdns").new()
|
||||||
ovr_config.set_application_type(2) # Set to OVERLAY MODE = 2, NORMAL MODE = 1
|
ovr_config.set_application_type(2) # Set to OVERLAY MODE = 2, NORMAL MODE = 1
|
||||||
ovr_config.set_tracking_universe(1) # Set to SEATED MODE = 0, STANDING MODE = 1, RAW MODE = 2
|
ovr_config.set_tracking_universe(1) # Set to SEATED MODE = 0, STANDING MODE = 1, RAW MODE = 2
|
||||||
|
|
||||||
# Find the OpenVR interface and initialise it
|
# Find the OpenVR interface and initialise it
|
||||||
ovr_interface = ARVRServer.find_interface("OpenVR")
|
ovr_interface = ARVRServer.find_interface("OpenVR")
|
||||||
if ovr_interface and ovr_interface.initialize():
|
if ovr_interface and ovr_interface.initialize():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
for i in ARVRServer.get_tracker_count():
|
for i in ARVRServer.get_tracker_count():
|
||||||
var tracker = ARVRServer.get_tracker(i)
|
var tracker = ARVRServer.get_tracker(i)
|
||||||
print(tracker.get_name(), ": hand ", tracker.get_hand())
|
print(tracker.get_name(), ": hand ", tracker.get_hand())
|
||||||
|
|
||||||
|
|
|
@ -12,16 +12,16 @@ var _tracker_id: int = 0 setget ,get_tracker_id
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
ARVRServer.connect("tracker_added", self, "_tracker_changed")
|
ARVRServer.connect("tracker_added", self, "_tracker_changed")
|
||||||
ARVRServer.connect("tracker_removed", self, "_tracker_changed")
|
ARVRServer.connect("tracker_removed", self, "_tracker_changed")
|
||||||
|
|
||||||
$OverlayViewport.overlay_width_in_meters = width_meters
|
$OverlayViewport.overlay_width_in_meters = width_meters
|
||||||
$OverlayViewport.size = OverlayInit.ovr_interface.get_render_targetsize()
|
$OverlayViewport.size = OverlayInit.ovr_interface.get_render_targetsize()
|
||||||
if overlay_scene:
|
if overlay_scene:
|
||||||
$OverlayViewport.add_child(overlay_scene.instance())
|
$OverlayViewport.add_child(overlay_scene.instance())
|
||||||
|
|
||||||
update_tracker_id()
|
update_tracker_id()
|
||||||
update_offset()
|
update_offset()
|
||||||
|
|
||||||
|
|
||||||
#func _process(_delta: float) -> void:
|
#func _process(_delta: float) -> void:
|
||||||
|
@ -29,59 +29,59 @@ func _ready() -> void:
|
||||||
|
|
||||||
|
|
||||||
func update_tracker_id() -> void:
|
func update_tracker_id() -> void:
|
||||||
_tracker_id = -1
|
_tracker_id = -1
|
||||||
|
|
||||||
if target in [TARGETS.left, TARGETS.right]: # target is a controller
|
if target in [TARGETS.left, TARGETS.right]: # target is a controller
|
||||||
for i in ARVRServer.get_tracker_count():
|
for i in ARVRServer.get_tracker_count():
|
||||||
var tracker = ARVRServer.get_tracker(i)
|
var tracker = ARVRServer.get_tracker(i)
|
||||||
if tracker.get_hand() == target:
|
if tracker.get_hand() == target:
|
||||||
_tracker_id = int(tracker.get_name().split("_")[-1])
|
_tracker_id = int(tracker.get_name().split("_")[-1])
|
||||||
|
|
||||||
if _tracker_id == -1:
|
if _tracker_id == -1:
|
||||||
# could not find controller, overlay will revert to fallback
|
# could not find controller, overlay will revert to fallback
|
||||||
# only happens if controller is missing on startup, otherwise it will register as being at origin
|
# only happens if controller is missing on startup, otherwise it will register as being at origin
|
||||||
if fallback_to_hmd:
|
if fallback_to_hmd:
|
||||||
_tracker_id = 0 # HMD
|
_tracker_id = 0 # HMD
|
||||||
else:
|
else:
|
||||||
_tracker_id = 63 # World origin
|
_tracker_id = 63 # World origin
|
||||||
|
|
||||||
|
|
||||||
func update_offset() -> void:
|
func update_offset() -> void:
|
||||||
$Offset.translation = offset_pos
|
$Offset.translation = offset_pos
|
||||||
$Offset.rotation_degrees = offset_rot
|
$Offset.rotation_degrees = offset_rot
|
||||||
print(_tracker_id)
|
print(_tracker_id)
|
||||||
match target:
|
match target:
|
||||||
TARGETS.head:
|
TARGETS.head:
|
||||||
$OverlayViewport.track_relative_to_device(0, $Offset.transform)
|
$OverlayViewport.track_relative_to_device(0, $Offset.transform)
|
||||||
TARGETS.world:
|
TARGETS.world:
|
||||||
$OverlayViewport.overlay_position_absolute($Offset.transform)
|
$OverlayViewport.overlay_position_absolute($Offset.transform)
|
||||||
_:
|
_:
|
||||||
$OverlayViewport.track_relative_to_device(_tracker_id, $Offset.transform)
|
$OverlayViewport.track_relative_to_device(_tracker_id, $Offset.transform)
|
||||||
|
|
||||||
|
|
||||||
func _tracker_changed(tracker_name: String, type: int, id: int):
|
func _tracker_changed(tracker_name: String, type: int, id: int):
|
||||||
print("tracker changed: ", tracker_name)
|
print("tracker changed: ", tracker_name)
|
||||||
update_tracker_id()
|
update_tracker_id()
|
||||||
update_offset()
|
update_offset()
|
||||||
|
|
||||||
|
|
||||||
func get_tracker_id() -> int:
|
func get_tracker_id() -> int:
|
||||||
return _tracker_id
|
return _tracker_id
|
||||||
|
|
||||||
|
|
||||||
func _set_offset_pos(pos: Vector3):
|
func _set_offset_pos(pos: Vector3):
|
||||||
offset_pos = pos
|
offset_pos = pos
|
||||||
update_offset()
|
update_offset()
|
||||||
|
|
||||||
|
|
||||||
func _set_offset_rot(rot: Vector3):
|
func _set_offset_rot(rot: Vector3):
|
||||||
offset_rot = rot
|
offset_rot = rot
|
||||||
update_offset()
|
update_offset()
|
||||||
|
|
||||||
|
|
||||||
func _set_overlay_scene(scene: PackedScene):
|
func _set_overlay_scene(scene: PackedScene):
|
||||||
overlay_scene = scene
|
overlay_scene = scene
|
||||||
if $OverlayViewport.get_children():
|
if $OverlayViewport.get_children():
|
||||||
$OverlayViewport.get_child(0).queue_free()
|
$OverlayViewport.get_child(0).queue_free()
|
||||||
$OverlayViewport.add_child(overlay_scene.instance())
|
$OverlayViewport.add_child(overlay_scene.instance())
|
||||||
|
|
||||||
|
|
|
@ -6,102 +6,102 @@ signal settings_loaded # emitted when settings are loaded from file, needs to be
|
||||||
const DEBUG_SETTINGS = true
|
const DEBUG_SETTINGS = true
|
||||||
const SETTINGS_PATH = "user://settings.json"
|
const SETTINGS_PATH = "user://settings.json"
|
||||||
const SETTINGS_DEF = {
|
const SETTINGS_DEF = {
|
||||||
"example_1": {
|
"example_1": {
|
||||||
"name": "Example Toggle",
|
"name": "Example Toggle",
|
||||||
"description": "resets every restart", # optional
|
"description": "resets every restart", # optional
|
||||||
"flags": ["no_save"], # optional
|
"flags": ["no_save"], # optional
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"example_2": {
|
"example_2": {
|
||||||
"name": "Example Number",
|
"name": "Example Number",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": 42,
|
"default": 42,
|
||||||
"min": 1, # optional
|
"min": 1, # optional
|
||||||
"max": 100, # optional
|
"max": 100, # optional
|
||||||
"step": 4 # optional
|
"step": 4 # optional
|
||||||
},
|
},
|
||||||
"example_3": {
|
"example_3": {
|
||||||
"name": "Example text",
|
"name": "Example text",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "hello world"
|
"default": "hello world"
|
||||||
},
|
},
|
||||||
"example_4": {
|
"example_4": {
|
||||||
"name": "Example Vector3",
|
"name": "Example Vector3",
|
||||||
"type": "Vector3",
|
"type": "Vector3",
|
||||||
"default": [1, 2, 3]
|
"default": [1, 2, 3]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _settings = {}
|
var _settings = {}
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_init_settings()
|
_init_settings()
|
||||||
load_settings()
|
load_settings()
|
||||||
emit_signal("settings_loaded")
|
emit_signal("settings_loaded")
|
||||||
save_settings()
|
save_settings()
|
||||||
|
|
||||||
|
|
||||||
func get_setting(key):
|
func get_setting(key):
|
||||||
return _settings[key]
|
return _settings[key]
|
||||||
|
|
||||||
|
|
||||||
func set_setting(key, val):
|
func set_setting(key, val):
|
||||||
if _settings[key] == val:
|
if _settings[key] == val:
|
||||||
return
|
return
|
||||||
_settings[key] = val
|
_settings[key] = val
|
||||||
|
|
||||||
emit_signal("setting_changed", key, val)
|
emit_signal("setting_changed", key, val)
|
||||||
save_settings()
|
save_settings()
|
||||||
|
|
||||||
if DEBUG_SETTINGS:
|
if DEBUG_SETTINGS:
|
||||||
print("Settings changed: ", key, " -> ", val)
|
print("Settings changed: ", key, " -> ", val)
|
||||||
|
|
||||||
|
|
||||||
func _init_settings():
|
func _init_settings():
|
||||||
for key in SETTINGS_DEF:
|
for key in SETTINGS_DEF:
|
||||||
_settings[key] = SETTINGS_DEF[key].default
|
_settings[key] = SETTINGS_DEF[key].default
|
||||||
if DEBUG_SETTINGS:
|
if DEBUG_SETTINGS:
|
||||||
print("Default settings: ", _settings)
|
print("Default settings: ", _settings)
|
||||||
|
|
||||||
|
|
||||||
func save_settings():
|
func save_settings():
|
||||||
var to_save = {}
|
var to_save = {}
|
||||||
for key in _settings:
|
for key in _settings:
|
||||||
if not (SETTINGS_DEF[key].has("flags") and "no_save" in SETTINGS_DEF[key].flags):
|
if not (SETTINGS_DEF[key].has("flags") and "no_save" in SETTINGS_DEF[key].flags):
|
||||||
to_save[key] = _settings[key]
|
to_save[key] = _settings[key]
|
||||||
|
|
||||||
var file = File.new()
|
var file = File.new()
|
||||||
file.open(SETTINGS_PATH, File.WRITE)
|
file.open(SETTINGS_PATH, File.WRITE)
|
||||||
file.store_line(to_json(to_save))
|
file.store_line(to_json(to_save))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
func load_settings() -> void:
|
func load_settings() -> void:
|
||||||
var file = File.new()
|
var file = File.new()
|
||||||
|
|
||||||
if not file.file_exists(SETTINGS_PATH):
|
if not file.file_exists(SETTINGS_PATH):
|
||||||
if DEBUG_SETTINGS:
|
if DEBUG_SETTINGS:
|
||||||
print("No settings file exists, using defaults")
|
print("No settings file exists, using defaults")
|
||||||
return
|
return
|
||||||
|
|
||||||
file.open(SETTINGS_PATH, File.READ)
|
file.open(SETTINGS_PATH, File.READ)
|
||||||
var new_settings = parse_json(file.get_as_text())
|
var new_settings = parse_json(file.get_as_text())
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
# in case the settings format has changed, this is better than just clonging blindly
|
# in case the settings format has changed, this is better than just clonging blindly
|
||||||
for key in new_settings:
|
for key in new_settings:
|
||||||
if _settings.has(key):
|
if _settings.has(key):
|
||||||
var value = new_settings[key]
|
var value = new_settings[key]
|
||||||
match SETTINGS_DEF[key].type:
|
match SETTINGS_DEF[key].type:
|
||||||
["Vector2", "vector2"]:
|
["Vector2", "vector2"]:
|
||||||
_settings[key] = Vector2(value[0], value[1])
|
_settings[key] = Vector2(value[0], value[1])
|
||||||
["Vector3", "vector3"]:
|
["Vector3", "vector3"]:
|
||||||
_settings[key] = Vector3(value[0], value[1], value[2])
|
_settings[key] = Vector3(value[0], value[1], value[2])
|
||||||
_:
|
_:
|
||||||
_settings[key] = value
|
_settings[key] = value
|
||||||
|
|
||||||
if DEBUG_SETTINGS:
|
if DEBUG_SETTINGS:
|
||||||
print("Loaded settings from file")
|
print("Loaded settings from file")
|
||||||
print(_settings)
|
print(_settings)
|
||||||
|
|
|
@ -3,8 +3,8 @@ extends EditorPlugin
|
||||||
|
|
||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
add_autoload_singleton("Settings", "res://addons/settings-manager/settings.gd")
|
add_autoload_singleton("Settings", "res://addons/settings-manager/settings.gd")
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree() -> void:
|
func _exit_tree() -> void:
|
||||||
remove_autoload_singleton("Settings")
|
remove_autoload_singleton("Settings")
|
||||||
|
|
|
@ -2,8 +2,8 @@ extends Label
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
if delta > 0:
|
if delta > 0:
|
||||||
text = "Overlay FPS: " + str(round(1/delta))
|
text = "Overlay FPS: " + str(round(1/delta))
|
||||||
|
|
|
@ -2,16 +2,16 @@ extends Label
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
_update_time()
|
_update_time()
|
||||||
|
|
||||||
|
|
||||||
func _update_time():
|
func _update_time():
|
||||||
var h = str(OS.get_time().hour)
|
var h = str(OS.get_time().hour)
|
||||||
var m = str(OS.get_time().minute)
|
var m = str(OS.get_time().minute)
|
||||||
h = h if len(h) == 2 else "0" + h
|
h = h if len(h) == 2 else "0" + h
|
||||||
m = m if len(m) == 2 else "0" + m
|
m = m if len(m) == 2 else "0" + m
|
||||||
text = h + ":" + m
|
text = h + ":" + m
|
||||||
|
|
|
@ -2,4 +2,4 @@ extends Node
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
OS.window_size = Vector2(16, 16)
|
OS.window_size = Vector2(16, 16)
|
||||||
|
|
Loading…
Reference in a new issue