Compare commits

..

No commits in common. "main" and "v0.2.2" have entirely different histories.
main ... v0.2.2

202 changed files with 2922 additions and 2446 deletions

View file

@ -11,6 +11,3 @@ A cross-platform SteamVR overlay application that aims to have many useful tools
* Click `add` and then `add selected programs`
* You should now be able to start it from steam (favourite it for easier access)
## Usage
At the moment all interacions are done with the trigger buttons, this will use steamvr actions and be configurable in the future.

View file

@ -1,35 +0,0 @@
# WIP documentation
## Hierarchy
```
OverlayManager
- MyOverlayInstance
- [...]
- OverlayViewport
- Container
- MyOverlay
- [...]
- OverlayInteraction
- VR
- [colliders for vr trackers etc]
- Grabbable
- Clickable
- Touchable
```
## overlay interaction types
Each overlay instance has a OverlayInteraction node, which spawns the different interaction modules depending on what is defined in the OVERLAY_PROPERTIES.
The modules/interaction types are:
- Grabbable
- Touchable
- Clickable
These modules connect signals from different places to the interaction manager (`OverlayInteraction`)
Touchable connects collision signals to mouse inputs (potentially logic between to help prevent double presses)
Clickable connects vr button signals to mouse inputs
Grabbable connects vr button signals to grab logic, while telling the interaction manager to pause normal interaction

3
ovr-utils/Main.tscn Normal file
View file

@ -0,0 +1,3 @@
[gd_scene format=2]
[node name="Main" type="Node"]

View file

@ -1,12 +1,12 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://ui/MainOverlay.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/openvr_overlay/OverlayInstance.tscn" type="PackedScene" id=2]
[ext_resource path="res://OverlaySettingsSync.tscn" type="PackedScene" id=3]
[ext_resource path="res://overlay_manager.gd" type="Script" id=4]
[node name="OverlayManager" type="Node"]
script = ExtResource( 4 )
[node name="MainOverlay" parent="." instance=ExtResource( 2 )]
[node name="OverlaySettingsSync" parent="MainOverlay" instance=ExtResource( 3 )]
overlay_scene = ExtResource( 1 )
add_cursor = true

Binary file not shown.

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View file

@ -0,0 +1,5 @@
The resources here are taken from: `Steam\steamapps\common\SteamVR\resources\rendermodels\vr_glove\`
To save space in the repository only the slim models are included while the texture maps have been taken from the full versions.
See `../scenes/ovr_left_hand.tscn` and `../scenes/ovr_right_hand.tscn` for implementation details

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 MiB

After

Width:  |  Height:  |  Size: 21 MiB

View file

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="StreamTexture"
path.s3tc="res://.import/hands_albedo.png-149a10baba7906560a9f9eab8fadf1d8.s3tc.stex"
path.etc2="res://.import/hands_albedo.png-149a10baba7906560a9f9eab8fadf1d8.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://addons/godot-openvr/meshes/hands_albedo.png"
dest_files=[ "res://.import/hands_albedo.png-149a10baba7906560a9f9eab8fadf1d8.s3tc.stex", "res://.import/hands_albedo.png-149a10baba7906560a9f9eab8fadf1d8.etc2.stex" ]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=true
flags/filter=true
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=1
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 MiB

View file

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="StreamTexture"
path.s3tc="res://.import/hands_normal.png-eab7a86e959f13e1294e8f67904a8873.s3tc.stex"
path.etc2="res://.import/hands_normal.png-eab7a86e959f13e1294e8f67904a8873.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://addons/godot-openvr/meshes/hands_normal.png"
dest_files=[ "res://.import/hands_normal.png-eab7a86e959f13e1294e8f67904a8873.s3tc.stex", "res://.import/hands_normal.png-eab7a86e959f13e1294e8f67904a8873.etc2.stex" ]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=1
flags/repeat=true
flags/filter=true
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,42 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://addons/godot-openvr/meshes/vr_glove_left_model_slim.glb" type="PackedScene" id=1]
[ext_resource path="res://addons/godot-openvr/meshes/models_hands_vr_glove_vmat.material" type="Material" id=2]
[ext_resource path="res://addons/godot-openvr/OpenVRPose.gdns" type="Script" id=3]
[ext_resource path="res://addons/godot-openvr/OpenVRSkeleton.gdns" type="Script" id=4]
[node name="ovr_left_hand" instance=ExtResource( 1 )]
script = ExtResource( 3 )
action = "/actions/godot/in/left_hand"
[node name="Skeleton" parent="RootNode" index="0"]
bones/5/bound_children = [ NodePath("Thumb") ]
bones/10/bound_children = [ NodePath("Index") ]
bones/15/bound_children = [ NodePath("Middle") ]
bones/20/bound_children = [ NodePath("Ring") ]
bones/25/bound_children = [ NodePath("Pinky") ]
script = ExtResource( 4 )
action = "/actions/godot/in/left_hand"
[node name="vr_glove_left_slim" parent="RootNode/Skeleton" index="0"]
material/0 = ExtResource( 2 )
[node name="Thumb" type="BoneAttachment" parent="RootNode/Skeleton" index="1"]
transform = Transform( -0.347509, 0.0284256, 0.937246, -0.13095, -0.991217, -0.0184906, 0.928488, -0.129158, 0.348178, -0.0498674, 0.056092, 0.112777 )
bone_name = "finger_thumb_l_end"
[node name="Index" type="BoneAttachment" parent="RootNode/Skeleton" index="2"]
transform = Transform( -0.717079, -0.669965, 0.19221, -0.076153, -0.19881, -0.977075, 0.69282, -0.715277, 0.0915429, -0.0345977, 0.0355404, 0.164767 )
bone_name = "finger_index_l_end"
[node name="Middle" type="BoneAttachment" parent="RootNode/Skeleton" index="3"]
transform = Transform( -0.755126, -0.650532, 0.0812012, -0.0513261, -0.064817, -0.996576, 0.653568, -0.756708, 0.0155557, -0.0321126, 0.00654218, 0.171613 )
bone_name = "finger_middle_l_end"
[node name="Ring" type="BoneAttachment" parent="RootNode/Skeleton" index="4"]
transform = Transform( -0.749612, -0.661178, -0.0304372, -0.0961052, 0.154228, -0.98335, 0.654864, -0.734206, -0.179154, -0.0346831, -0.0253934, 0.156924 )
bone_name = "finger_ring_l_end"
[node name="Pinky" type="BoneAttachment" parent="RootNode/Skeleton" index="5"]
transform = Transform( -0.615435, -0.749373, -0.244295, -0.0354297, 0.335934, -0.941219, 0.787391, -0.570604, -0.233296, -0.0270969, -0.0462902, 0.133467 )
bone_name = "finger_pinky_l_end"

View file

@ -0,0 +1,42 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://addons/godot-openvr/meshes/vr_glove_right_model_slim.glb" type="PackedScene" id=1]
[ext_resource path="res://addons/godot-openvr/meshes/models_hands_vr_glove_vmat.material" type="Material" id=2]
[ext_resource path="res://addons/godot-openvr/OpenVRPose.gdns" type="Script" id=3]
[ext_resource path="res://addons/godot-openvr/OpenVRSkeleton.gdns" type="Script" id=4]
[node name="ovr_right_hand" instance=ExtResource( 1 )]
script = ExtResource( 3 )
action = "/actions/godot/in/right_hand"
[node name="Skeleton" parent="RootNode" index="0"]
bones/5/bound_children = [ NodePath("Thumb") ]
bones/10/bound_children = [ NodePath("Index") ]
bones/15/bound_children = [ NodePath("Middle") ]
bones/20/bound_children = [ NodePath("Ring") ]
bones/25/bound_children = [ NodePath("Pinky") ]
script = ExtResource( 4 )
action = "/actions/godot/in/right_hand"
[node name="vr_glove_right_slim" parent="RootNode/Skeleton" index="0"]
material/0 = ExtResource( 2 )
[node name="Thumb" type="BoneAttachment" parent="RootNode/Skeleton" index="1"]
transform = Transform( -0.347509, 0.0284256, 0.937246, 0.130949, 0.991217, 0.0184906, -0.928488, 0.129158, -0.348179, 0.0498674, 0.0560921, 0.112777 )
bone_name = "finger_thumb_r_end"
[node name="Index" type="BoneAttachment" parent="RootNode/Skeleton" index="2"]
transform = Transform( -0.717079, -0.669965, 0.19221, 0.0761528, 0.19881, 0.977075, -0.69282, 0.715277, -0.0915429, 0.0345977, 0.0355405, 0.164767 )
bone_name = "finger_index_r_end"
[node name="Middle" type="BoneAttachment" parent="RootNode/Skeleton" index="3"]
transform = Transform( -0.755126, -0.650532, 0.0812013, 0.0513261, 0.064817, 0.996577, -0.653568, 0.756708, -0.0155557, 0.0321126, 0.00654219, 0.171613 )
bone_name = "finger_middle_r_end"
[node name="Ring" type="BoneAttachment" parent="RootNode/Skeleton" index="4"]
transform = Transform( -0.749612, -0.661178, -0.0304372, 0.0961052, -0.154228, 0.98335, -0.654864, 0.734206, 0.179154, 0.0346831, -0.0253934, 0.156924 )
bone_name = "finger_ring_r_end"
[node name="Pinky" type="BoneAttachment" parent="RootNode/Skeleton" index="5"]
transform = Transform( -0.615435, -0.749373, -0.244295, 0.0354297, -0.335934, 0.941219, -0.787391, 0.570604, 0.233296, 0.0270969, -0.0462902, 0.133467 )
bone_name = "finger_pinky_r_end"

View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/openvr_overlay/interaction/overlay_cursor.gd" type="Script" id=1]
[node name="OverlayCursor" type="Node"]
script = ExtResource( 1 )

View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/openvr_overlay/interaction/overlay_grab.gd" type="Script" id=1]
[node name="OverlayGrab" type="Node"]
script = ExtResource( 1 )

View file

@ -1,7 +1,6 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://addons/openvr_overlay/overlay_instance.gd" type="Script" id=1]
[ext_resource path="res://addons/openvr_overlay/OverlayInteraction.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/godot-openvr/OpenVROverlay.gdns" type="Script" id=3]
[sub_resource type="StyleBoxFlat" id=1]
@ -22,6 +21,7 @@ script = ExtResource( 1 )
[node name="OverlayViewport" type="Viewport" parent="."]
size = Vector2( 2048, 2048 )
transparent_bg = true
handle_input_locally = false
hdr = false
disable_3d = true
usage = 0
@ -57,12 +57,17 @@ shadow_atlas_quad_3 = 0
script = ExtResource( 3 )
overlay_width_in_meters = 0.4
[node name="TextureRect" type="TextureRect" parent="VROverlayViewport"]
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="VROverlayViewport"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TextureRect" type="TextureRect" parent="VROverlayViewport/AspectRatioContainer"]
margin_right = 100.0
margin_bottom = 100.0
texture = SubResource( 2 )
expand = true
stretch_mode = 5
flip_v = true
[node name="OverlayInteraction" parent="." instance=ExtResource( 2 )]

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/openvr_overlay/interaction/overlay_interaction.gd" type="Script" id=1]
[ext_resource path="res://addons/openvr_overlay/interaction/OverlayArea.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/openvr_overlay/interaction/OverlayActivator.tscn" type="PackedScene" id=6]
[node name="OverlayInteraction" type="Node"]
script = ExtResource( 1 )
@ -10,14 +10,16 @@ script = ExtResource( 1 )
[node name="left" type="ARVRController" parent="VR"]
[node name="OverlayActivator" parent="VR/left" instance=ExtResource( 6 )]
[node name="right" type="ARVRController" parent="VR"]
controller_id = 2
[node name="OverlayActivator" parent="VR/right" instance=ExtResource( 6 )]
[node name="head" type="ARVRCamera" parent="VR"]
visible = false
[node name="OverlayArea" parent="." instance=ExtResource( 2 )]
[connection signal="button_pressed" from="VR/left" to="." method="_on_LeftHand_button_pressed"]
[connection signal="button_release" from="VR/left" to="." method="_on_LeftHand_button_release"]
[connection signal="button_pressed" from="VR/right" to="." method="_on_RightHand_button_pressed"]

View file

@ -4,10 +4,7 @@
margin = 0.001
radius = 0.01
[node name="HandCollider" type="Area"]
monitoring = false
collision_layer = 30
collision_mask = 0
[node name="OverlayActivator" type="StaticBody"]
[node name="Collision" type="CollisionShape" parent="."]
shape = SubResource( 1 )

View file

@ -0,0 +1,10 @@
[gd_scene load_steps=2 format=2]
[sub_resource type="BoxShape" id=1]
resource_local_to_scene = true
extents = Vector3( 0.2, 0.2, 0.01 )
[node name="OverlayArea" type="Area"]
[node name="CollisionShape" type="CollisionShape" parent="."]
shape = SubResource( 1 )

View file

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 90 B

View file

@ -0,0 +1,56 @@
extends Node
var cursor_node = preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance()
onready var viewport: Viewport = get_node("../../OverlayViewport")
onready var _i = get_parent()
func _ready() -> void:
viewport.add_child(cursor_node)
get_parent().connect("trigger_on", self, "_trigger_on")
get_parent().connect("trigger_off", self, "_trigger_off")
func _process(_delta: float) -> void:
_update_cursor()
#get canvas position of active controller
func get_canvas_pos() -> Vector2:
if not _i.active_controller:
return Vector2(-1000, 1000) # offscreen
var controller_local_pos = _i._overlay_area.global_transform.xform_inv(\
_i.tracker_nodes[_i.active_controller].translation)
var pos = Vector2(controller_local_pos.x, controller_local_pos.y)
# var overlay_size = OverlayInit.ovr_interface.get_render_targetsize()
var overlay_size = Vector2(2048, 2048)
# scale to pixels
pos *= overlay_size.x
pos /= _i.get_parent().width_meters
# adjust to center
pos.y *= -1
pos += overlay_size * 0.5
return pos
func _update_cursor():
cursor_node.rect_position = get_canvas_pos()
func _send_click_event(state: bool):
var click_event = InputEventMouseButton.new()
click_event.position = get_canvas_pos()
click_event.pressed = state
click_event.button_index = 1
viewport.input(click_event)
func _trigger_on():
_send_click_event(true)
func _trigger_off():
_send_click_event(false)

View file

@ -22,18 +22,18 @@ func _ready() -> void:
get_parent().connect("trigger_off", self, "_trigger_off")
func _trigger_on(controller):
func _trigger_on():
if Settings.s.grab_mode or _interaction.grab_mode:
begin_move(controller)
begin_move()
func _trigger_off(_controller):
func _trigger_off():
finish_move()
func begin_move(controller="right"):
if not _interaction.state[controller].near:
print("Could not begin moving overlay, " + controller + " controller is not touching overlay. <", _overlay.name, ">")
func begin_move():
if not _interaction.active_controller:
print("Could not begin moving overlay, no controller is touching overlay. <", _overlay.name, ">")
return
if is_moving:
return
@ -41,7 +41,7 @@ func begin_move(controller="right"):
_interaction.pause_triggers = true
# store current states to revert after move
_pre_move_target = _overlay.current_target
_mover_hand_name = controller
_mover_hand_name = _interaction.active_controller
_mover_hand_offsets = _overlay.get_offset(_mover_hand_name)
# calculate offsets from active controller to overlay
@ -73,6 +73,7 @@ func finish_move():
# revert target
_overlay.update_current_target()
_overlay.save_settings()
_interaction._update_target()
_interaction.pause_triggers = false

View file

@ -0,0 +1,114 @@
extends Node
signal touch_on # a controller entered
signal touch_off # a controller exited
signal trigger_on # trigger pushed while touching
signal trigger_off# trigger released
var touch_state := false
var trigger_state := false
var grab_mode := false
# controller that currently the trigger down
var active_controller := ""
# reference to the area node thats used for touch
var _overlay_area = preload("res://addons/openvr_overlay/interaction/OverlayArea.tscn").instance()
var _right_is_activator := false # this hand has a collider on it to trigger things on the overlay
var _left_is_activator := false
var pause_triggers := false # disable triggers updating
onready var tracker_nodes = {
"head": $VR/head,
"left": $VR/left,
"right": $VR/right,
"world": $VR
}
func _ready() -> void:
add_child(_overlay_area)
_overlay_area.connect("body_entered", self, "_on_OverlayArea_entered")
_overlay_area.connect("body_exited", self, "_on_OverlayArea_exited")
get_parent().connect("width_changed", self, "_update_width")
get_parent().connect("offset_changed", self, "_update_offset")
get_parent().connect("target_changed", self, "_update_target")
_update_width()
_update_offset()
_update_target()
func _trigger_on(controller):
if touch_state:
active_controller = controller
trigger_state = true
emit_signal("trigger_on")
func _trigger_off():
trigger_state = false
emit_signal("trigger_off")
func _on_OverlayArea_entered(body: Node) -> void:
if body.get_node("../../..") != self or pause_triggers or !get_parent().overlay_visible:
return
touch_state = true
active_controller = body.get_parent().name
get_parent().get_node("OverlayViewport/Selected").visible = Settings.s.grab_mode or grab_mode
emit_signal("touch_on")
func _on_OverlayArea_exited(body: Node) -> void:
if body.get_node("../../..") != self or pause_triggers or !get_parent().overlay_visible:
return
# TODO revert to other controller if both were touching (edge case)
active_controller = ""
touch_state = false
get_parent().get_node("OverlayViewport/Selected").visible = false
emit_signal("touch_off")
func _update_width():
var ratio = OverlayInit.ovr_interface.get_render_targetsize()
var extents = get_parent().width_meters * 0.5
_overlay_area.get_child(0).shape.set_extents(Vector3(extents, extents * ratio.y/ratio.x, 0.05))
func _update_offset():
_overlay_area.translation = get_parent().translation
_overlay_area.rotation = get_parent().rotation
func _update_target():
# reparent _overlay_area
_overlay_area.get_parent().remove_child(_overlay_area)
tracker_nodes[get_parent().current_target].add_child(_overlay_area)
_left_is_activator = get_parent().current_target != "left"
_right_is_activator = get_parent().current_target != "right"
# toggle appropriate colliders
$VR/left/OverlayActivator/Collision.disabled = !_left_is_activator
$VR/right/OverlayActivator/Collision.disabled = !_right_is_activator
func _on_RightHand_button_pressed(button: int) -> void:
if button == JOY_VR_TRIGGER and _right_is_activator:
_trigger_on("right")
func _on_RightHand_button_release(button: int) -> void:
if button == JOY_VR_TRIGGER and active_controller == "right":
_trigger_off()
func _on_LeftHand_button_pressed(button: int) -> void:
if button == JOY_VR_TRIGGER and _left_is_activator:
_trigger_on("left")
func _on_LeftHand_button_release(button: int) -> void:
if button == JOY_VR_TRIGGER and active_controller == "left":
_trigger_off()

View file

@ -4,9 +4,7 @@ extends EditorPlugin
func _enter_tree() -> void:
add_autoload_singleton("OverlayInit", "res://addons/openvr_overlay/overlay_init.gd")
add_autoload_singleton("OverlayInteractionRoot", "res://addons/openvr_overlay/OverlayInteractionRoot.tscn")
func _exit_tree() -> void:
remove_autoload_singleton("OverlayInit")
remove_autoload_singleton("OverlayInteractionRoot")

View file

@ -1,14 +1,5 @@
extends Node
const OVERLAY_PROPERTIES_DEFAULT = {
"allow_delete": true,
"allow_hide": true,
"clickable": false,
"touchable": false,
"grabbable": true,
}
var ovr_interface: ARVRInterface
var ovr_config := preload("res://addons/godot-openvr/OpenVRConfig.gdns").new()
@ -20,7 +11,9 @@ var trackers = {
}
func _init() -> void:
ovr_config.set_application_type(2) # Set to OVERLAY MODE
OS.window_minimized = true
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
@ -30,14 +23,9 @@ func _init() -> void:
func _ready() -> void:
OS.window_size = Vector2(16, 16)
OS.window_position = Vector2(32, 32)
OS.window_minimized = true
ARVRServer.connect("tracker_added", self, "_tracker_added")
ARVRServer.connect("tracker_removed", self, "_tracker_removed")
update_hand_ids()
#Input.set_use_accumulated_input(true)
func _tracker_added(tracker_name: String, type: int, id: int):

View file

@ -1,23 +1,22 @@
extends Spatial
#signal path_changed
signal overlay_visible_changed
signal width_changed
signal alpha_changed
signal target_changed
signal fallback_changed
signal offset_changed
signal target_changed
signal overlay_visibility_changed
const TARGETS = ["head", "left", "right", "world"]
export (String, "head", "left", "right", "world") var target = "left" setget set_target
export var overlay_scene: PackedScene = \
preload("res://addons/openvr_overlay/MissingOverlay.tscn") setget set_overlay_scene
export var width_meters := 0.4 setget set_width_in_meters
export var alpha := 1.0 setget set_alpha
export var add_grabbing := true # add grabbing module
export var add_cursor := false # add cursor module
var _tracker_id := 0
var _offsets:Dictionary = {
"head": {"pos": Vector3(0, 0, -0.35), "rot": Quat()},
"head": {"pos": Vector3(0, 0, -0.5), "rot": Quat()},
"left": {"pos": Vector3(), "rot": Quat()},
"right": {"pos": Vector3(), "rot": Quat()},
"world": {"pos": Vector3(0,1,0), "rot": Quat()},
@ -28,17 +27,12 @@ var current_target: String = "world" setget _set_current_target
var fallback = ["left", "right", "head"] # TODO setget that updates tracking (not important)
var interaction_handler: Node
var overlay_visible := true setget set_overlay_visible
var path : String = "res://special_overlays/MainOverlay.tscn"# setget set_path
var path_invalid := false
var OVERLAY_PROPERTIES: Dictionary # defined in overlay root script (optional)
var type := "main"
onready var container = $OverlayViewport/Container
var overlay_scene: Node
func _ready() -> void:
container = $OverlayViewport/Container
load_overlay()
current_target = target
ARVRServer.connect("tracker_added", self, "_tracker_changed")
@ -47,27 +41,64 @@ func _ready() -> void:
$VROverlayViewport.size = OverlayInit.ovr_interface.get_render_targetsize()
set_notify_transform(true)
load_settings()
if add_cursor or add_grabbing:
interaction_handler = load("res://addons/openvr_overlay/OverlayInteraction.tscn").instance()
add_child(interaction_handler)
if add_cursor:
add_cursor()
if add_grabbing:
add_grab()
if overlay_scene:
container.add_child(overlay_scene.instance())
update_tracker_id()
call_deferred("update_offset")
func load_overlay() -> void:
path_invalid = false
var packed_overlay = load(path)
if not packed_overlay:
path_invalid = true
overlay_scene = load("res://special_overlays/UnknownType.tscn").instance()
func add_cursor():
interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayCursor.tscn").instance())
func add_grab():
interaction_handler.add_child(load("res://addons/openvr_overlay/OverlayGrab.tscn").instance())
func load_settings():
if Settings.s.overlays.has(name):
var loaded = Settings.s.overlays[name]
if loaded.has("fallback"):
fallback = loaded.fallback
set_target(loaded.target)
set_width_in_meters(loaded.width)
for t_key in loaded.offsets:
var t_offset = loaded.offsets[t_key]
_offsets[t_key].pos = t_offset.pos
_offsets[t_key].rot = t_offset.rot
update_offset()
if loaded.has("visible"):
set_overlay_visible(loaded.visible)
else:
overlay_scene = packed_overlay.instance()
save_settings()
if overlay_scene.get("OVERLAY_PROPERTIES") != null:
OVERLAY_PROPERTIES = overlay_scene.OVERLAY_PROPERTIES
$OverlayInteraction.spawn_modules()
func save_settings():
if not Settings.s.overlays.has(name):
Settings.s.overlays[name] = {}
Settings.s.overlays[name].target = target
Settings.s.overlays[name].width = width_meters
Settings.s.overlays[name].fallback = fallback
Settings.s.overlays[name].type = type
if not Settings.s.overlays[name].has("offsets"):
Settings.s.overlays[name]["offsets"] = {}
for t_key in TARGETS:
Settings.s.overlays[name].offsets[t_key] = _offsets[t_key]
Settings.save_settings()
if container.get_child_count() > 0:
container.get_child(0).queue_free()
container.add_child(overlay_scene)
func update_tracker_id():
_tracker_id = -1
@ -81,7 +112,7 @@ func update_tracker_id():
if _tracker_id == -1:
# could not find controller, fallback
# print("Missing controller ", current_target, " ", target, " ", fallback, " - ", name)
print("Missing controller ", current_target, " ", target, " ", fallback, " - ", name)
_tracker_id = 63 # highest tracker id (unused, at origin)
@ -112,7 +143,9 @@ func update_current_target():
func set_overlay_visible(state: bool):
overlay_visible = state
$VROverlayViewport.overlay_visible = state
emit_signal("overlay_visible_changed", state)
Settings.s.overlays[name].visible = state
emit_signal("overlay_visibility_changed", state)
save_settings()
func _tracker_changed(tracker_name: String, type: int, id: int):
@ -149,10 +182,13 @@ func set_width_in_meters(width: float) -> void:
emit_signal("width_changed")
func set_alpha(val: float):
alpha = val
$VROverlayViewport/TextureRect.modulate.a = val
emit_signal("alpha_changed")
func set_overlay_scene(scene: PackedScene) -> void:
overlay_scene = scene
if not container:
return
if container.get_child_count() > 0:
container.get_child(0).queue_free()
container.add_child(overlay_scene.instance())
func reset_offset() -> void:
@ -161,15 +197,10 @@ func reset_offset() -> void:
if current_target == "head":
_offsets[current_target].pos.z = -0.5
update_offset()
save_settings()
func _notification(what: int) -> void:
if what == NOTIFICATION_TRANSFORM_CHANGED:
update_offset()
emit_signal("offset_changed")
func get_property(p_name: String):
if OVERLAY_PROPERTIES.has(p_name):
return OVERLAY_PROPERTIES[p_name]
return OverlayInit.OVERLAY_PROPERTIES_DEFAULT[p_name]

View file

@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/settings-manager/settings.gd" type="Script" id=1]
[node name="Settings" type="Node"]
script = ExtResource( 1 )
[node name="AutosaveTimer" type="Timer" parent="."]
wait_time = 300.0
autostart = true
[connection signal="timeout" from="AutosaveTimer" to="." method="_on_AutosaveTimer_timeout"]

View file

@ -4,4 +4,4 @@ name="SettingsManager"
description="Simple settings manager for godot"
author="CrispyPin"
version=""
script="settings_plugin.gd"
script="settings_manager.gd"

View file

@ -5,26 +5,16 @@ signal settings_loaded # emitted when settings are loaded from file, needs to be
signal settings_changed # has to be manually called by the modifying script
var DEBUG_SETTINGS = false
var SETTINGS_PATH = preload("res://settings_definition.gd").PATH
const SETTINGS_DEF = preload("res://settings_definition.gd").DEF
var SETTINGS_PATH = "user://overlay_data.json"
const SETTINGS_DEF = preload("res://addons/settings-manager/settings_definition.gd").DEF
var has_loaded := false
var s := {}
var _saved_hash: int
var s: Dictionary = {}
func _ready() -> void:
_init_settings()
load_settings()
force_save()
func _on_SaveTimer_timeout() -> void:
var new_h: int = s.hash()
if new_h != _saved_hash:
_saved_hash = new_h
print("Saving to ", SETTINGS_PATH)
force_save()
save_settings()
func _init_settings() -> void:
@ -47,7 +37,7 @@ func _init_sub_setting(def):
return def.default
func force_save():
func save_settings():
var to_save = {}
for key in s:
var val = _save_sub_setting(s[key], SETTINGS_DEF[key])
@ -90,7 +80,6 @@ func _save_sub_setting(val, def):
func load_settings() -> void:
var file = File.new()
var validator: Script = preload("res://settings_validator.gd")
if not file.file_exists(SETTINGS_PATH):
if DEBUG_SETTINGS:
@ -101,16 +90,13 @@ func load_settings() -> void:
var new_settings = parse_json(file.get_as_text())
file.close()
if validator.is_valid(new_settings):
for key in new_settings:
s[key] = _load_sub_setting(new_settings[key], SETTINGS_DEF[key])
else:
print("Invalid or outdated config file, using defaults")
for key in new_settings:
s[key] = _load_sub_setting(new_settings[key], SETTINGS_DEF[key])
emit_signal("settings_loaded")
if DEBUG_SETTINGS:
print("Loaded settings from file")
emit_signal("settings_loaded")
has_loaded = true
# print(s)
func _load_sub_setting(val, def):
@ -125,10 +111,8 @@ func _load_sub_setting(val, def):
var _s = {}
var resize = has_flag(def, "resize")
for key in val:
if resize:
_s[key] = _load_sub_setting(val[key], def.definition)
elif def.definition.has(key):
_s[key] = _load_sub_setting(val[key], def.definition[key])
var subdef = def.definition if resize else def.definition[key]
_s[key] = _load_sub_setting(val[key], subdef)
return _s
_:
return val
@ -139,4 +123,10 @@ func has_flag(def, flag):
func _exit_tree() -> void:
force_save()
# save on quit
save_settings()
func _on_AutosaveTimer_timeout() -> void:
# auto saves every 5 minutes, saving should also be done manually
save_settings()

View file

@ -1,14 +1,6 @@
extends Node
const VERSION = 1
const PATH = "user://overlay_data.json"
const DEF = {
"version": {
"name": "Version of save file",
"type": "int",
"default": VERSION
},
"grab_mode": {
"name": "Grab mode",
"description": "Grab and drag around any overlay",
@ -23,10 +15,10 @@ const DEF = {
"definition": {
"type": "dict",
"definition": {
"path": {
"name": "Overlay scene path",
"type": {
"name": "Overlay type",
"type": "string",
"default": "res://special_overlays/UnknownType.tscn"
"default": "UI_demo"
},
"visible": {
"name": "Overlay Visible",
@ -35,14 +27,9 @@ const DEF = {
},
"width": {
"name": "Width (m)",
"type": "float",
"type": "number",
"default": 0.4
},
"alpha": {
"name": "Alpha",
"type": "float",
"default": 1.0
},
"target": {
"name": "Tracking target",
"type": "string",
@ -78,20 +65,19 @@ const DEF = {
},
"default": {
"MainOverlay": {
"path": "res://special_overlays/MainOverlay.tscn",
"type": "MainOverlay",
"visible": true,
"width": 0.4,
"alpha": 1.0,
"target": "left",
"fallback": ["left", "right", "head"],
"offsets": {
"left": {
"pos": Vector3(0.15, 0.05, 0),
"rot": Quat(-0.653928, -0.023545, 0.008617, 0.756141),
"pos": Vector3(),
"rot": Quat(),
},
"right": {
"pos": Vector3(-0.15, 0.05, 0),
"rot": Quat(-0.653928, -0.023545, 0.008617, 0.756141),
"pos": Vector3(),
"rot": Quat(),
},
"head": {
"pos": Vector3(0,0,-0.5),

View file

@ -5,7 +5,7 @@ platform="Linux/X11"
runnable=true
custom_features=""
export_filter="all_resources"
include_filter="*.json"
include_filter=""
exclude_filter=""
export_path="../builds/linux/ovr-utils.x86_64"
script_export_mode=1

View file

Before

Width:  |  Height:  |  Size: 149 B

After

Width:  |  Height:  |  Size: 149 B

View file

Before

Width:  |  Height:  |  Size: 286 B

After

Width:  |  Height:  |  Size: 286 B

View file

Before

Width:  |  Height:  |  Size: 380 B

After

Width:  |  Height:  |  Size: 380 B

View file

@ -2,15 +2,15 @@
importer="texture"
type="StreamTexture"
path="res://.import/alpha.svg-22384cad50da35235f001642b0f4e493.stex"
path="res://.import/hand_r.svg-acd4ed4e6db8416fe852bbec606de215.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icons/alpha.svg"
dest_files=[ "res://.import/alpha.svg-22384cad50da35235f001642b0f4e493.stex" ]
source_file="res://icons/hand_r.svg"
dest_files=[ "res://.import/hand_r.svg-acd4ed4e6db8416fe852bbec606de215.stex" ]
[params]

Some files were not shown because too many files have changed in this diff Show more