mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-21 23:20:25 +01:00
basic grab mode
This commit is contained in:
parent
031a48ffdc
commit
b4df1ff599
6 changed files with 74 additions and 4 deletions
|
@ -1,8 +1,14 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/openvr_overlay/OverlayInstance.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://overlays/MainOverlay.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://overlay_manager.gd" type="Script" id=6]
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
|
||||
[node name="OverlayManager" type="Node" parent="."]
|
||||
script = ExtResource( 6 )
|
||||
|
||||
[node name="OverlayInstance" parent="OverlayManager" instance=ExtResource( 1 )]
|
||||
overlay_scene = ExtResource( 2 )
|
||||
add_cursor = true
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
extends Node
|
||||
|
||||
|
||||
var is_moving := false
|
||||
|
||||
var _pre_move_target = ""# what offset is being changed
|
||||
var _mover_hand_name = ""# left or right, which hand is grabbing (/active controller)
|
||||
var _mover_hand_offsets = {"pos": Vector3(), "rot": Quat()} # original offsets for grabbing hand
|
||||
|
@ -16,13 +18,26 @@ onready var tracker_nodes = {
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
get_parent().connect("trigger_on", self, "_trigger_on")
|
||||
get_parent().connect("trigger_off", self, "_trigger_off")
|
||||
|
||||
|
||||
func _trigger_on():
|
||||
if Settings.s.grab_mode:
|
||||
begin_move()
|
||||
|
||||
|
||||
func _trigger_off():
|
||||
finish_move()
|
||||
|
||||
|
||||
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
|
||||
is_moving = true
|
||||
_interaction.pause_triggers = true
|
||||
# store current states to revert after move
|
||||
_pre_move_target = _overlay.current_target
|
||||
|
@ -41,6 +56,9 @@ func begin_move():
|
|||
|
||||
|
||||
func finish_move():
|
||||
if not is_moving:
|
||||
return
|
||||
is_moving = false
|
||||
# calculate and apply the new offsets
|
||||
var new_target_t = tracker_nodes[_pre_move_target].transform
|
||||
var ovelay_t = _interaction._overlay_area.global_transform
|
||||
|
|
|
@ -2,6 +2,7 @@ extends Node
|
|||
|
||||
signal settings_saved
|
||||
signal settings_loaded # emitted when settings are loaded from file, needs to be connected in _init()
|
||||
signal settings_changed # has to be manually called by the modifying script
|
||||
|
||||
var DEBUG_SETTINGS = false
|
||||
var SETTINGS_PATH = "user://overlay_data.json"
|
||||
|
|
|
@ -16,7 +16,8 @@ func _load_overlays():
|
|||
for key in Settings.s.overlays:
|
||||
# TODO remove this check, settings should always contain "type"
|
||||
if Settings.s.overlays[key].has("type"):
|
||||
add_overlay(Settings.s.overlays[key].type, key)
|
||||
if not Settings.s.overlays[key].type == "MainOverlay":
|
||||
add_overlay(Settings.s.overlays[key].type, key)
|
||||
else:
|
||||
print("No type defined for overlay ", key)
|
||||
|
||||
|
@ -24,7 +25,7 @@ func _load_overlays():
|
|||
func add_overlay(type, name):
|
||||
var scene = load("res://overlays/" + type + ".tscn")
|
||||
if scene == null:
|
||||
print("Unknown overlay type; ", type, ". Skipping overlay \"", name, "\"")
|
||||
print("Unknown overlay type: ", type, ". Skipping overlay \"", name, "\"")
|
||||
return
|
||||
var instance = preload("res://addons/openvr_overlay/OverlayInstance.tscn").instance()
|
||||
instance.name = name
|
||||
|
|
10
ovr-utils/overlay_scripts/main_menu.gd
Normal file
10
ovr-utils/overlay_scripts/main_menu.gd
Normal file
|
@ -0,0 +1,10 @@
|
|||
extends Control
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_GrabMode_toggled(state: bool) -> void:
|
||||
Settings.s.grab_mode = state
|
||||
Settings.emit_signal("settings_changed")
|
34
ovr-utils/overlays/MainOverlay.tscn
Normal file
34
ovr-utils/overlays/MainOverlay.tscn
Normal file
|
@ -0,0 +1,34 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://overlay_scripts/main_menu.gd" type="Script" id=1]
|
||||
[ext_resource path="res://fonts/OpenSans-Bold.ttf" type="DynamicFontData" id=2]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 64
|
||||
font_data = ExtResource( 2 )
|
||||
|
||||
[node name="MainOverlay" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_top = -99.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="GrabMode" type="Button" parent="HBoxContainer"]
|
||||
margin_right = 366.0
|
||||
margin_bottom = 99.0
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
toggle_mode = true
|
||||
text = "Grab mode"
|
||||
|
||||
[connection signal="toggled" from="HBoxContainer/GrabMode" to="." method="_on_GrabMode_toggled"]
|
Loading…
Reference in a new issue