mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2025-01-18 21:04:24 +01:00
plugin: add touch support (finally)
This commit is contained in:
parent
2bac6afcdc
commit
ef744db9ae
8 changed files with 62 additions and 21 deletions
|
@ -1,3 +1,6 @@
|
|||
[gd_scene format=2]
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
__meta__ = {
|
||||
"_editor_description_": "Everything is loaded using autoloads so this scene is just a dummy"
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ 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
|
||||
|
|
7
src/addons/openvr_overlay/OverlayTouchCursor.tscn
Normal file
7
src/addons/openvr_overlay/OverlayTouchCursor.tscn
Normal file
|
@ -0,0 +1,7 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/openvr_overlay/interaction/overlay_cursor.gd" type="Script" id=1]
|
||||
|
||||
[node name="OverlayTouchCursor" type="Node"]
|
||||
script = ExtResource( 1 )
|
||||
is_touch = true
|
|
@ -1,5 +1,6 @@
|
|||
extends Node
|
||||
|
||||
export var is_touch := false
|
||||
|
||||
onready var viewport: Viewport = get_node("../../OverlayViewport")
|
||||
onready var _i = get_parent()
|
||||
|
@ -22,21 +23,38 @@ var cursor_nodes := {
|
|||
"right": preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance(),
|
||||
"left": preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance(),
|
||||
}
|
||||
|
||||
var temp = 0
|
||||
var tstate = true
|
||||
|
||||
func _ready() -> void:
|
||||
viewport.add_child(cursor_nodes.right)
|
||||
viewport.add_child(cursor_nodes.left)
|
||||
if is_touch:
|
||||
get_parent().connect("touch_on", self, "_trigger_on")
|
||||
get_parent().connect("touch_off", self, "_trigger_off")
|
||||
else:
|
||||
get_parent().connect("trigger_on", self, "_trigger_on")
|
||||
get_parent().connect("trigger_off", self, "_trigger_off")
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
cursor_pos.right= get_canvas_pos("right")
|
||||
cursor_pos.left= get_canvas_pos("left")
|
||||
func _process(delta: float) -> void:
|
||||
cursor_pos.right = get_canvas_pos("right")
|
||||
cursor_pos.left = get_canvas_pos("left")
|
||||
_update_cursors()
|
||||
_send_move_event()
|
||||
#_send_move_event()
|
||||
prev_pos = cursor_pos.duplicate(true)
|
||||
# if is_touch:
|
||||
# temp += delta
|
||||
# if temp > 0.5:
|
||||
# temp = 0
|
||||
# var click_event = InputEventMouseButton.new()
|
||||
# click_event.position = Vector2(240, 340)
|
||||
# click_event.pressed = tstate
|
||||
# tstate = !tstate
|
||||
# click_event.button_index = 1
|
||||
# viewport.input(click_event)
|
||||
# print("SENT EVENT ", click_event.position, " -- ", click_event.pressed)
|
||||
## viewport.
|
||||
|
||||
|
||||
#get canvas position of controller
|
||||
|
@ -83,6 +101,7 @@ func _send_click_event(state: bool, controller: String):
|
|||
click_event.pressed = state
|
||||
click_event.button_index = 1
|
||||
viewport.input(click_event)
|
||||
# print("SENT EVENT ", click_event.position, " -- ", click_event.pressed)
|
||||
|
||||
|
||||
func _trigger_on(controller):
|
||||
|
|
|
@ -62,11 +62,13 @@ func _ready() -> void:
|
|||
func _trigger_on(controller):
|
||||
if state[controller].near:
|
||||
state[controller].trigger = true
|
||||
# print("TRIGGER ON ", controller)
|
||||
emit_signal("trigger_on", controller)
|
||||
|
||||
|
||||
func _trigger_off(controller):
|
||||
state[controller].trigger = false
|
||||
# print("TRIGGER OFF ", controller)
|
||||
emit_signal("trigger_off", controller)
|
||||
|
||||
|
||||
|
@ -76,6 +78,7 @@ func _on_Near_entered(body: Node) -> void:
|
|||
var hand = body.get_groups()[0]
|
||||
state[hand].near = true
|
||||
update_selection()
|
||||
# print("NEAR ON ", hand)
|
||||
emit_signal("near_on")
|
||||
|
||||
|
||||
|
@ -85,6 +88,7 @@ func _on_Near_exited(body: Node) -> void:
|
|||
var hand = body.get_groups()[0]
|
||||
state[hand].near = false
|
||||
|
||||
# print("NEAR OFF ", hand)
|
||||
update_selection()
|
||||
emit_signal("near_off")
|
||||
|
||||
|
@ -95,7 +99,8 @@ func _on_Touch_entered(body: Node) -> void:
|
|||
var hand = body.get_groups()[0]
|
||||
state[hand].touch = true
|
||||
update_selection()
|
||||
emit_signal("touch_on")
|
||||
# print("TOUCH ON ", hand)
|
||||
emit_signal("touch_on", hand)
|
||||
|
||||
|
||||
func _on_Touch_exited(body: Node) -> void:
|
||||
|
@ -103,9 +108,9 @@ func _on_Touch_exited(body: Node) -> void:
|
|||
return
|
||||
var hand = body.get_groups()[0]
|
||||
state[hand].touch = false
|
||||
|
||||
update_selection()
|
||||
emit_signal("touch_off")
|
||||
# print("TOUCH OFF ", hand)
|
||||
emit_signal("touch_off", hand)
|
||||
|
||||
|
||||
func update_selection():
|
||||
|
@ -160,6 +165,10 @@ func spawn_modules():
|
|||
var module = preload("res://addons/openvr_overlay/OverlayCursor.tscn")
|
||||
add_child(module.instance())
|
||||
|
||||
# cursor module
|
||||
if get_parent().get_property("has_touch"):
|
||||
var module = preload("res://addons/openvr_overlay/OverlayTouchCursor.tscn")
|
||||
add_child(module.instance())
|
||||
|
||||
|
||||
func _on_RightHand_button_pressed(button: int) -> void:
|
||||
|
|
|
@ -35,6 +35,7 @@ func _ready() -> void:
|
|||
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):
|
||||
|
|
|
@ -12,7 +12,7 @@ var oinst
|
|||
|
||||
func _ready() -> void:
|
||||
oinst = get_viewport().get_parent()
|
||||
clicker = get_viewport().get_node("../OverlayInteraction/OverlayCursor")
|
||||
clicker = get_viewport().get_node("../OverlayInteraction/OverlayTouchCursor")
|
||||
grabber = get_viewport().get_node("../OverlayInteraction/OverlayGrab")
|
||||
for t in oinst.TARGETS:
|
||||
$OptionButton.add_item(t)
|
||||
|
|
|
@ -12,6 +12,10 @@ font_data = ExtResource( 2 )
|
|||
[sub_resource type="Theme" id=2]
|
||||
default_font = SubResource( 1 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=5]
|
||||
size = 64
|
||||
font_data = ExtResource( 3 )
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=3]
|
||||
bg_color = Color( 0.419608, 0.419608, 0.419608, 1 )
|
||||
border_width_left = 16
|
||||
|
@ -23,10 +27,6 @@ corner_detail = 1
|
|||
|
||||
[sub_resource type="StyleBoxFlat" id=4]
|
||||
|
||||
[sub_resource type="DynamicFont" id=5]
|
||||
size = 64
|
||||
font_data = ExtResource( 3 )
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
@ -57,10 +57,10 @@ __meta__ = {
|
|||
margin_left = 335.0
|
||||
margin_right = 650.0
|
||||
margin_bottom = 143.0
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
custom_fonts/font = SubResource( 5 )
|
||||
custom_styles/pressed = SubResource( 3 )
|
||||
custom_styles/normal = SubResource( 4 )
|
||||
custom_fonts/font = SubResource( 5 )
|
||||
custom_colors/font_color = Color( 0, 0, 0, 1 )
|
||||
text = "Drag"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
|
@ -86,6 +86,9 @@ margin_top = 242.452
|
|||
margin_right = 1051.0
|
||||
margin_bottom = 433.452
|
||||
text = "aaaaa"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Button4" type="Button" parent="."]
|
||||
margin_left = 650.0
|
||||
|
|
Loading…
Reference in a new issue