cleanup, made overlayInteraction a node so it doesn't inherit the offset

This commit is contained in:
Crispy 2021-05-20 17:36:48 +02:00
parent be6173ba83
commit 9f74010bc9
12 changed files with 52 additions and 54 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://addons/openvr_overlay/OverlayInstance.tscn" type="PackedScene" id=1]
[ext_resource path="res://overlays/FPSOverlay.tscn" type="PackedScene" id=2]
@ -8,10 +8,6 @@
[ext_resource path="res://overlays/BatteryOverlay.tscn" type="PackedScene" id=7]
[ext_resource path="res://addons/openvr_overlay/OverlayInteraction.tscn" type="PackedScene" id=8]
[sub_resource type="Environment" id=1]
background_mode = 1
background_color = Color( 0.113725, 0.0705882, 0.196078, 1 )
[node name="Overlays" type="Node"]
[node name="OverlayInstance FPS" parent="." instance=ExtResource( 1 )]
@ -27,16 +23,13 @@ width_meters = 0.1
[node name="OverlayInteraction" parent="OverlayInstance Time" instance=ExtResource( 8 )]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 1 )
[node name="OverlayInstance Battery" parent="." instance=ExtResource( 1 )]
transform = Transform( -4.37114e-08, -0.707107, -0.707107, 0, -0.707107, 0.707107, -1, 3.09086e-08, 3.09086e-08, -0.12, 0, 0.1 )
target = 1
overlay_scene = ExtResource( 7 )
[node name="OverlayInstance UI demo" parent="." instance=ExtResource( 1 )]
transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, -0.2 )
transform = Transform( -4.37114e-08, -1, -4.37114e-08, 0, -4.37114e-08, 1, -1, 4.37114e-08, 1.91069e-15, 0, 0, -0.25 )
target = 1
overlay_scene = ExtResource( 5 )

View file

@ -1,8 +1,7 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/openvr_overlay/overlay_instance.gd" type="Script" id=1]
[ext_resource path="res://addons/godot-openvr/OpenVROverlay.gdns" type="Script" id=3]
[ext_resource path="res://addons/openvr_overlay/styles/normal.theme" type="Theme" id=5]
[node name="OverlayInstance" type="Spatial"]
script = ExtResource( 1 )
@ -20,7 +19,6 @@ render_target_update_mode = 3
script = ExtResource( 3 )
overlay_width_in_meters = 0.4
[node name="PanelContainer" type="PanelContainer" parent="OverlayViewport"]
[node name="Container" type="Control" parent="OverlayViewport"]
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 5 )

View file

@ -3,22 +3,24 @@
[ext_resource path="res://addons/openvr_overlay/interaction/overlay_interaction.gd" type="Script" id=1]
[ext_resource path="res://addons/openvr_overlay/interaction/OverlayActivator.tscn" type="PackedScene" id=6]
[node name="OverlayInteraction" type="ARVROrigin"]
[node name="OverlayInteraction" type="Node"]
script = ExtResource( 1 )
[node name="LeftHand" type="ARVRController" parent="."]
[node name="VR" type="ARVROrigin" parent="."]
[node name="OverlayActivator" parent="LeftHand" instance=ExtResource( 6 )]
[node name="LeftHand" type="ARVRController" parent="VR"]
[node name="RightHand" type="ARVRController" parent="."]
[node name="OverlayActivator" parent="VR/LeftHand" instance=ExtResource( 6 )]
[node name="RightHand" type="ARVRController" parent="VR"]
controller_id = 2
[node name="OverlayActivator" parent="RightHand" instance=ExtResource( 6 )]
[node name="OverlayActivator" parent="VR/RightHand" instance=ExtResource( 6 )]
[node name="Head" type="ARVRCamera" parent="."]
[node name="Head" type="ARVRCamera" parent="VR"]
visible = false
[connection signal="button_pressed" from="LeftHand" to="." method="_on_LeftHand_button_pressed"]
[connection signal="button_release" from="LeftHand" to="." method="_on_LeftHand_button_release"]
[connection signal="button_pressed" from="RightHand" to="." method="_on_RightHand_button_pressed"]
[connection signal="button_release" from="RightHand" to="." method="_on_RightHand_button_release"]
[connection signal="button_pressed" from="VR/LeftHand" to="." method="_on_LeftHand_button_pressed"]
[connection signal="button_release" from="VR/LeftHand" to="." method="_on_LeftHand_button_release"]
[connection signal="button_pressed" from="VR/RightHand" to="." method="_on_RightHand_button_pressed"]
[connection signal="button_release" from="VR/RightHand" to="." method="_on_RightHand_button_release"]

View file

@ -1,4 +1,4 @@
extends ARVROrigin
extends Node
signal touch_on # a controller entered
signal touch_off # a controller exited
@ -17,7 +17,6 @@ var _right_is_activator = false
var _left_is_activator = false
onready var viewport: Viewport = get_node("../OverlayViewport")
onready var panel: PanelContainer = get_node("../OverlayViewport/PanelContainer")
func _ready() -> void:
@ -85,7 +84,7 @@ func _trigger_off():
func _on_OverlayArea_entered(body: Node) -> void:
if body.get_parent().get_parent() != self:
if body.get_node("../../..") != self:
return
_touch_state = true
_active_controller = body.get_parent()
@ -93,7 +92,7 @@ func _on_OverlayArea_entered(body: Node) -> void:
func _on_OverlayArea_exited(body: Node) -> void:
if body.get_parent().get_parent() != self:
if body.get_node("../../..") != self:
return
_active_controller = null # TODO revert to other controller if both were touching (edge case)
_touch_state = false
@ -116,38 +115,38 @@ func _update_target():
_overlay_area.get_parent().remove_child(_overlay_area)
match get_parent().target:
OverlayInstance.TARGETS.head:
$Head.add_child(_overlay_area)
$VR/Head.add_child(_overlay_area)
OverlayInstance.TARGETS.left:
$LeftHand.add_child(_overlay_area)
$VR/LeftHand.add_child(_overlay_area)
OverlayInstance.TARGETS.right:
$RightHand.add_child(_overlay_area)
$VR/RightHand.add_child(_overlay_area)
OverlayInstance.TARGETS.world:
add_child(_overlay_area)
$VR.add_child(_overlay_area)
_left_is_activator = get_parent().target != OverlayInstance.TARGETS.left
_right_is_activator = get_parent().target != OverlayInstance.TARGETS.right
# toggle appropriate colliders
$LeftHand/OverlayActivator/Collision.disabled = !_left_is_activator
$RightHand/OverlayActivator/Collision.disabled = !_right_is_activator
$VR/LeftHand/OverlayActivator/Collision.disabled = !_left_is_activator
$VR/RightHand/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($RightHand)
_trigger_on($VR/RightHand)
func _on_RightHand_button_release(button: int) -> void:
if button == JOY_VR_TRIGGER and _active_controller == $RightHand:
if button == JOY_VR_TRIGGER and _active_controller == $VR/RightHand:
_trigger_off()
func _on_LeftHand_button_pressed(button: int) -> void:
if button == JOY_VR_TRIGGER and _left_is_activator:
_trigger_on($LeftHand)
_trigger_on($VR/LeftHand)
func _on_LeftHand_button_release(button: int) -> void:
if button == JOY_VR_TRIGGER and _active_controller == $LeftHand:
if button == JOY_VR_TRIGGER and _active_controller == $VR/LeftHand:
_trigger_off()

View file

@ -28,7 +28,7 @@ func _tracker_changed(tracker_name: String, type: int, id: int):
func update_hand_ids():
for i in ARVRServer.get_tracker_count():
var tracker = ARVRServer.get_tracker(i)
print(tracker.get_name(), ": hand ", tracker.get_hand())
# print(tracker.get_name(), ": hand ", tracker.get_hand())
var tracking_id = tracker.get_name().split("_")[-1]
if tracker.get_hand() == 1:

View file

@ -6,7 +6,7 @@ signal offset_changed
signal target_changed
enum TARGETS { head, left, right, world }
export (TARGETS) var target = TARGETS.head setget _set_target
export (TARGETS) var target = TARGETS.head setget set_target
export var overlay_scene = preload("res://addons/openvr_overlay/MissingOverlay.tscn")\
setget set_overlay_scene
export var width_meters = 0.4 setget set_width_in_meters
@ -15,7 +15,7 @@ export var fallback_to_hmd = false # fallback is only applied if tracker is not
var _tracker_id: int = 0
onready var container = $OverlayViewport/PanelContainer
onready var container = $OverlayViewport/Container
func _ready() -> void:
@ -32,15 +32,8 @@ func _ready() -> void:
set_notify_transform(true)
func _notification(what: int) -> void:
if what == NOTIFICATION_TRANSFORM_CHANGED:
update_offset()
emit_signal("offset_changed")
func update_tracker_id() -> void:
_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)
@ -75,7 +68,7 @@ func get_tracker_id() -> int:
return _tracker_id
func _set_target(new: int):
func set_target(new: int):
target = new
update_tracker_id()
call_deferred("update_offset")
@ -97,3 +90,9 @@ func set_overlay_scene(scene: PackedScene):
container.get_child(0).queue_free()
container.add_child(overlay_scene.instance())
func _notification(what: int) -> void:
if what == NOTIFICATION_TRANSFORM_CHANGED:
update_offset()
emit_signal("offset_changed")

View file

@ -1,14 +1,21 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://fonts/OpenSans-Regular.ttf" type="DynamicFontData" id=2]
[ext_resource path="res://addons/openvr_overlay/styles/active.stylebox" type="StyleBox" id=3]
[sub_resource type="DynamicFont" id=2]
[sub_resource type="DynamicFont" id=1]
size = 100
font_data = ExtResource( 2 )
[sub_resource type="Theme" id=3]
default_font = SubResource( 2 )
[sub_resource type="Theme" id=2]
default_font = SubResource( 1 )
[sub_resource type="StyleBoxFlat" id=3]
border_width_left = 16
border_width_top = 16
border_width_right = 16
border_width_bottom = 16
border_color = Color( 0, 0.505882, 1, 1 )
corner_detail = 1
[node name="Control" type="Control"]
anchor_right = 1.0
@ -20,7 +27,7 @@ __meta__ = {
[node name="OptionButton" type="OptionButton" parent="."]
margin_right = 111.0
margin_bottom = 41.0
theme = SubResource( 3 )
theme = SubResource( 2 )
text = "Item 0"
items = [ "Item 0", null, false, 0, null, "Item 1", null, false, 1, null, "Item 2", null, false, 2, null, "Item 3", null, false, 3, null ]
selected = 0
@ -32,7 +39,7 @@ __meta__ = {
margin_top = 600.0
margin_right = 315.0
margin_bottom = 778.0
custom_styles/pressed = ExtResource( 3 )
custom_styles/pressed = SubResource( 3 )
toggle_mode = true
__meta__ = {
"_edit_use_anchors_": false