mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-22 15:40: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:
|
||||
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:
|
||||
remove_autoload_singleton("OverlayInit")
|
||||
remove_autoload_singleton("OverlayInit")
|
||||
|
|
|
@ -4,18 +4,18 @@ var ovr_interface: ARVRInterface
|
|||
|
||||
|
||||
func _init() -> void:
|
||||
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_tracking_universe(1) # Set to SEATED MODE = 0, STANDING MODE = 1, RAW MODE = 2
|
||||
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_tracking_universe(1) # Set to SEATED MODE = 0, STANDING MODE = 1, RAW MODE = 2
|
||||
|
||||
# Find the OpenVR interface and initialise it
|
||||
ovr_interface = ARVRServer.find_interface("OpenVR")
|
||||
if ovr_interface and ovr_interface.initialize():
|
||||
pass
|
||||
# Find the OpenVR interface and initialise it
|
||||
ovr_interface = ARVRServer.find_interface("OpenVR")
|
||||
if ovr_interface and ovr_interface.initialize():
|
||||
pass
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
for i in ARVRServer.get_tracker_count():
|
||||
var tracker = ARVRServer.get_tracker(i)
|
||||
print(tracker.get_name(), ": hand ", tracker.get_hand())
|
||||
for i in ARVRServer.get_tracker_count():
|
||||
var tracker = ARVRServer.get_tracker(i)
|
||||
print(tracker.get_name(), ": hand ", tracker.get_hand())
|
||||
|
||||
|
|
|
@ -12,16 +12,16 @@ var _tracker_id: int = 0 setget ,get_tracker_id
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
ARVRServer.connect("tracker_added", self, "_tracker_changed")
|
||||
ARVRServer.connect("tracker_removed", self, "_tracker_changed")
|
||||
ARVRServer.connect("tracker_added", self, "_tracker_changed")
|
||||
ARVRServer.connect("tracker_removed", self, "_tracker_changed")
|
||||
|
||||
$OverlayViewport.overlay_width_in_meters = width_meters
|
||||
$OverlayViewport.size = OverlayInit.ovr_interface.get_render_targetsize()
|
||||
if overlay_scene:
|
||||
$OverlayViewport.add_child(overlay_scene.instance())
|
||||
$OverlayViewport.overlay_width_in_meters = width_meters
|
||||
$OverlayViewport.size = OverlayInit.ovr_interface.get_render_targetsize()
|
||||
if overlay_scene:
|
||||
$OverlayViewport.add_child(overlay_scene.instance())
|
||||
|
||||
update_tracker_id()
|
||||
update_offset()
|
||||
update_tracker_id()
|
||||
update_offset()
|
||||
|
||||
|
||||
#func _process(_delta: float) -> void:
|
||||
|
@ -29,59 +29,59 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func update_tracker_id() -> void:
|
||||
_tracker_id = -1
|
||||
_tracker_id = -1
|
||||
|
||||
if target in [TARGETS.left, TARGETS.right]: # target is a controller
|
||||
for i in ARVRServer.get_tracker_count():
|
||||
var tracker = ARVRServer.get_tracker(i)
|
||||
if tracker.get_hand() == target:
|
||||
_tracker_id = int(tracker.get_name().split("_")[-1])
|
||||
if target in [TARGETS.left, TARGETS.right]: # target is a controller
|
||||
for i in ARVRServer.get_tracker_count():
|
||||
var tracker = ARVRServer.get_tracker(i)
|
||||
if tracker.get_hand() == target:
|
||||
_tracker_id = int(tracker.get_name().split("_")[-1])
|
||||
|
||||
if _tracker_id == -1:
|
||||
# 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
|
||||
if fallback_to_hmd:
|
||||
_tracker_id = 0 # HMD
|
||||
else:
|
||||
_tracker_id = 63 # World origin
|
||||
if _tracker_id == -1:
|
||||
# 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
|
||||
if fallback_to_hmd:
|
||||
_tracker_id = 0 # HMD
|
||||
else:
|
||||
_tracker_id = 63 # World origin
|
||||
|
||||
|
||||
func update_offset() -> void:
|
||||
$Offset.translation = offset_pos
|
||||
$Offset.rotation_degrees = offset_rot
|
||||
print(_tracker_id)
|
||||
match target:
|
||||
TARGETS.head:
|
||||
$OverlayViewport.track_relative_to_device(0, $Offset.transform)
|
||||
TARGETS.world:
|
||||
$OverlayViewport.overlay_position_absolute($Offset.transform)
|
||||
_:
|
||||
$OverlayViewport.track_relative_to_device(_tracker_id, $Offset.transform)
|
||||
$Offset.translation = offset_pos
|
||||
$Offset.rotation_degrees = offset_rot
|
||||
print(_tracker_id)
|
||||
match target:
|
||||
TARGETS.head:
|
||||
$OverlayViewport.track_relative_to_device(0, $Offset.transform)
|
||||
TARGETS.world:
|
||||
$OverlayViewport.overlay_position_absolute($Offset.transform)
|
||||
_:
|
||||
$OverlayViewport.track_relative_to_device(_tracker_id, $Offset.transform)
|
||||
|
||||
|
||||
func _tracker_changed(tracker_name: String, type: int, id: int):
|
||||
print("tracker changed: ", tracker_name)
|
||||
update_tracker_id()
|
||||
update_offset()
|
||||
print("tracker changed: ", tracker_name)
|
||||
update_tracker_id()
|
||||
update_offset()
|
||||
|
||||
|
||||
func get_tracker_id() -> int:
|
||||
return _tracker_id
|
||||
return _tracker_id
|
||||
|
||||
|
||||
func _set_offset_pos(pos: Vector3):
|
||||
offset_pos = pos
|
||||
update_offset()
|
||||
offset_pos = pos
|
||||
update_offset()
|
||||
|
||||
|
||||
func _set_offset_rot(rot: Vector3):
|
||||
offset_rot = rot
|
||||
update_offset()
|
||||
offset_rot = rot
|
||||
update_offset()
|
||||
|
||||
|
||||
func _set_overlay_scene(scene: PackedScene):
|
||||
overlay_scene = scene
|
||||
if $OverlayViewport.get_children():
|
||||
$OverlayViewport.get_child(0).queue_free()
|
||||
$OverlayViewport.add_child(overlay_scene.instance())
|
||||
overlay_scene = scene
|
||||
if $OverlayViewport.get_children():
|
||||
$OverlayViewport.get_child(0).queue_free()
|
||||
$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 SETTINGS_PATH = "user://settings.json"
|
||||
const SETTINGS_DEF = {
|
||||
"example_1": {
|
||||
"name": "Example Toggle",
|
||||
"description": "resets every restart", # optional
|
||||
"flags": ["no_save"], # optional
|
||||
"type": "bool",
|
||||
"default": false
|
||||
},
|
||||
"example_2": {
|
||||
"name": "Example Number",
|
||||
"type": "number",
|
||||
"default": 42,
|
||||
"min": 1, # optional
|
||||
"max": 100, # optional
|
||||
"step": 4 # optional
|
||||
},
|
||||
"example_3": {
|
||||
"name": "Example text",
|
||||
"type": "string",
|
||||
"default": "hello world"
|
||||
},
|
||||
"example_4": {
|
||||
"name": "Example Vector3",
|
||||
"type": "Vector3",
|
||||
"default": [1, 2, 3]
|
||||
}
|
||||
"example_1": {
|
||||
"name": "Example Toggle",
|
||||
"description": "resets every restart", # optional
|
||||
"flags": ["no_save"], # optional
|
||||
"type": "bool",
|
||||
"default": false
|
||||
},
|
||||
"example_2": {
|
||||
"name": "Example Number",
|
||||
"type": "number",
|
||||
"default": 42,
|
||||
"min": 1, # optional
|
||||
"max": 100, # optional
|
||||
"step": 4 # optional
|
||||
},
|
||||
"example_3": {
|
||||
"name": "Example text",
|
||||
"type": "string",
|
||||
"default": "hello world"
|
||||
},
|
||||
"example_4": {
|
||||
"name": "Example Vector3",
|
||||
"type": "Vector3",
|
||||
"default": [1, 2, 3]
|
||||
}
|
||||
}
|
||||
|
||||
var _settings = {}
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_init_settings()
|
||||
load_settings()
|
||||
emit_signal("settings_loaded")
|
||||
save_settings()
|
||||
_init_settings()
|
||||
load_settings()
|
||||
emit_signal("settings_loaded")
|
||||
save_settings()
|
||||
|
||||
|
||||
func get_setting(key):
|
||||
return _settings[key]
|
||||
return _settings[key]
|
||||
|
||||
|
||||
func set_setting(key, val):
|
||||
if _settings[key] == val:
|
||||
return
|
||||
_settings[key] = val
|
||||
if _settings[key] == val:
|
||||
return
|
||||
_settings[key] = val
|
||||
|
||||
emit_signal("setting_changed", key, val)
|
||||
save_settings()
|
||||
emit_signal("setting_changed", key, val)
|
||||
save_settings()
|
||||
|
||||
if DEBUG_SETTINGS:
|
||||
print("Settings changed: ", key, " -> ", val)
|
||||
if DEBUG_SETTINGS:
|
||||
print("Settings changed: ", key, " -> ", val)
|
||||
|
||||
|
||||
func _init_settings():
|
||||
for key in SETTINGS_DEF:
|
||||
_settings[key] = SETTINGS_DEF[key].default
|
||||
if DEBUG_SETTINGS:
|
||||
print("Default settings: ", _settings)
|
||||
for key in SETTINGS_DEF:
|
||||
_settings[key] = SETTINGS_DEF[key].default
|
||||
if DEBUG_SETTINGS:
|
||||
print("Default settings: ", _settings)
|
||||
|
||||
|
||||
func save_settings():
|
||||
var to_save = {}
|
||||
for key in _settings:
|
||||
if not (SETTINGS_DEF[key].has("flags") and "no_save" in SETTINGS_DEF[key].flags):
|
||||
to_save[key] = _settings[key]
|
||||
var to_save = {}
|
||||
for key in _settings:
|
||||
if not (SETTINGS_DEF[key].has("flags") and "no_save" in SETTINGS_DEF[key].flags):
|
||||
to_save[key] = _settings[key]
|
||||
|
||||
var file = File.new()
|
||||
file.open(SETTINGS_PATH, File.WRITE)
|
||||
file.store_line(to_json(to_save))
|
||||
file.close()
|
||||
var file = File.new()
|
||||
file.open(SETTINGS_PATH, File.WRITE)
|
||||
file.store_line(to_json(to_save))
|
||||
file.close()
|
||||
|
||||
|
||||
func load_settings() -> void:
|
||||
var file = File.new()
|
||||
var file = File.new()
|
||||
|
||||
if not file.file_exists(SETTINGS_PATH):
|
||||
if DEBUG_SETTINGS:
|
||||
print("No settings file exists, using defaults")
|
||||
return
|
||||
if not file.file_exists(SETTINGS_PATH):
|
||||
if DEBUG_SETTINGS:
|
||||
print("No settings file exists, using defaults")
|
||||
return
|
||||
|
||||
file.open(SETTINGS_PATH, File.READ)
|
||||
var new_settings = parse_json(file.get_as_text())
|
||||
file.close()
|
||||
file.open(SETTINGS_PATH, File.READ)
|
||||
var new_settings = parse_json(file.get_as_text())
|
||||
file.close()
|
||||
|
||||
# in case the settings format has changed, this is better than just clonging blindly
|
||||
for key in new_settings:
|
||||
if _settings.has(key):
|
||||
var value = new_settings[key]
|
||||
match SETTINGS_DEF[key].type:
|
||||
["Vector2", "vector2"]:
|
||||
_settings[key] = Vector2(value[0], value[1])
|
||||
["Vector3", "vector3"]:
|
||||
_settings[key] = Vector3(value[0], value[1], value[2])
|
||||
_:
|
||||
_settings[key] = value
|
||||
# in case the settings format has changed, this is better than just clonging blindly
|
||||
for key in new_settings:
|
||||
if _settings.has(key):
|
||||
var value = new_settings[key]
|
||||
match SETTINGS_DEF[key].type:
|
||||
["Vector2", "vector2"]:
|
||||
_settings[key] = Vector2(value[0], value[1])
|
||||
["Vector3", "vector3"]:
|
||||
_settings[key] = Vector3(value[0], value[1], value[2])
|
||||
_:
|
||||
_settings[key] = value
|
||||
|
||||
if DEBUG_SETTINGS:
|
||||
print("Loaded settings from file")
|
||||
print(_settings)
|
||||
if DEBUG_SETTINGS:
|
||||
print("Loaded settings from file")
|
||||
print(_settings)
|
||||
|
|
|
@ -3,8 +3,8 @@ extends EditorPlugin
|
|||
|
||||
|
||||
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:
|
||||
remove_autoload_singleton("Settings")
|
||||
remove_autoload_singleton("Settings")
|
||||
|
|
|
@ -2,8 +2,8 @@ extends Label
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
pass
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if delta > 0:
|
||||
text = "Overlay FPS: " + str(round(1/delta))
|
||||
if delta > 0:
|
||||
text = "Overlay FPS: " + str(round(1/delta))
|
||||
|
|
|
@ -2,16 +2,16 @@ extends Label
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_update_time()
|
||||
_update_time()
|
||||
|
||||
|
||||
func _update_time():
|
||||
var h = str(OS.get_time().hour)
|
||||
var m = str(OS.get_time().minute)
|
||||
h = h if len(h) == 2 else "0" + h
|
||||
m = m if len(m) == 2 else "0" + m
|
||||
text = h + ":" + m
|
||||
var h = str(OS.get_time().hour)
|
||||
var m = str(OS.get_time().minute)
|
||||
h = h if len(h) == 2 else "0" + h
|
||||
m = m if len(m) == 2 else "0" + m
|
||||
text = h + ":" + m
|
||||
|
|
|
@ -2,4 +2,4 @@ extends Node
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
OS.window_size = Vector2(16, 16)
|
||||
OS.window_size = Vector2(16, 16)
|
||||
|
|
Loading…
Reference in a new issue