diff --git a/ovr-utils/Main.tscn b/ovr-utils/Main.tscn index 756bda6..7624d1b 100644 --- a/ovr-utils/Main.tscn +++ b/ovr-utils/Main.tscn @@ -61,3 +61,9 @@ offset_rot = Vector3( -90, 0, 0 ) [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = SubResource( 1 ) + +[node name="OverlayInstance" parent="." instance=ExtResource( 1 )] +target = 2 +offset_pos = Vector3( 0, 0, -0.2 ) + +[node name="OverlayInteraction" parent="OverlayInstance" instance=ExtResource( 8 )] diff --git a/ovr-utils/addons/openvr_overlay/interaction/OverlayActivator.tscn b/ovr-utils/addons/openvr_overlay/interaction/OverlayActivator.tscn new file mode 100644 index 0000000..d705ca9 --- /dev/null +++ b/ovr-utils/addons/openvr_overlay/interaction/OverlayActivator.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=2] + +[sub_resource type="SphereShape" id=1] +margin = 0.001 +radius = 0.01 + +[node name="OverlayActivator" type="StaticBody"] + +[node name="Collision" type="CollisionShape" parent="."] +shape = SubResource( 1 ) diff --git a/ovr-utils/addons/openvr_overlay/interaction/OverlayArea.tscn b/ovr-utils/addons/openvr_overlay/interaction/OverlayArea.tscn new file mode 100644 index 0000000..6825095 --- /dev/null +++ b/ovr-utils/addons/openvr_overlay/interaction/OverlayArea.tscn @@ -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 ) diff --git a/ovr-utils/addons/openvr_overlay/interaction/OverlayInteraction.tscn b/ovr-utils/addons/openvr_overlay/interaction/OverlayInteraction.tscn index c3138fd..c65c807 100644 --- a/ovr-utils/addons/openvr_overlay/interaction/OverlayInteraction.tscn +++ b/ovr-utils/addons/openvr_overlay/interaction/OverlayInteraction.tscn @@ -1,16 +1,10 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://addons/openvr_overlay/interaction/overlay_interaction.gd" type="Script" id=1] [ext_resource path="res://addons/openvr_overlay/styles/active.theme" type="Theme" id=2] [ext_resource path="res://addons/openvr_overlay/styles/normal.theme" type="Theme" id=3] [ext_resource path="res://addons/openvr_overlay/styles/touching.theme" type="Theme" id=4] - -[sub_resource type="BoxShape" id=1] -resource_local_to_scene = true -extents = Vector3( 0.2, 0.2, 0.01 ) - -[sub_resource type="SphereShape" id=2] -radius = 0.03 +[ext_resource path="res://addons/openvr_overlay/interaction/OverlayActivator.tscn" type="PackedScene" id=6] [node name="OverlayInteraction" type="ARVROrigin"] script = ExtResource( 1 ) @@ -20,23 +14,16 @@ touching_theme = ExtResource( 4 ) [node name="LeftHand" type="ARVRController" parent="."] -[node name="Area" type="Area" parent="LeftHand"] - -[node name="CollisionShape" type="CollisionShape" parent="LeftHand/Area"] -shape = SubResource( 1 ) +[node name="OverlayActivator" parent="LeftHand" instance=ExtResource( 6 )] [node name="RightHand" type="ARVRController" parent="."] controller_id = 2 -[node name="StaticBody" type="StaticBody" parent="RightHand"] +[node name="OverlayActivator" parent="RightHand" instance=ExtResource( 6 )] -[node name="CollisionShape" type="CollisionShape" parent="RightHand/StaticBody"] -shape = SubResource( 2 ) +[node name="Head" type="ARVRCamera" parent="."] -[node name="ARVRCamera" type="ARVRCamera" parent="."] - -[node name="Offset" type="RemoteTransform" parent="."] -update_scale = false - -[connection signal="body_entered" from="LeftHand/Area" to="." method="_on_Area_body_entered"] -[connection signal="body_exited" from="LeftHand/Area" to="." method="_on_Area_body_exited"] +[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"] diff --git a/ovr-utils/addons/openvr_overlay/interaction/overlay_interaction.gd b/ovr-utils/addons/openvr_overlay/interaction/overlay_interaction.gd index 78cb473..0eccf1b 100644 --- a/ovr-utils/addons/openvr_overlay/interaction/overlay_interaction.gd +++ b/ovr-utils/addons/openvr_overlay/interaction/overlay_interaction.gd @@ -9,64 +9,132 @@ export var active_theme: Theme export var normal_theme: Theme export var touching_theme: Theme -var active_controllers = [] +const OVERLAY_AREA = preload("res://addons/openvr_overlay/interaction/OverlayArea.tscn") var _touch_state = false setget ,get_touch_state var _trigger_state = false setget ,get_trigger_state -var _active_controller: ARVRController = null setget ,get_active_controller + +# controller that currently the trigger down +var _active_controller: ARVRController setget ,get_active_controller +var _overlay_area: Area # reference to the area node thats used for touch +var _right_is_activator = false +var _left_is_activator = false + onready var panel = get_node("../OverlayViewport/PanelContainer") func _ready() -> void: - get_parent().connect("width_changed", self, "_on_width_changed") - _on_width_changed(get_parent().width_meters) + # TEMP + _right_is_activator = true + ############### + _overlay_area = OVERLAY_AREA.instance() + add_child(_overlay_area) + _overlay_area.connect("body_entered", self, "_on_OverlayArea_entered") + _overlay_area.connect("body_exited", self, "_on_OverlayArea_exited") - get_node("../Offset").remote_path = $Offset.get_path() - $Offset.remote_path = $LeftHand/Area.get_path() + 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 _process(delta: float) -> void: + pass + + +func _trigger_on(controller): if _touch_state: - if not _trigger_state: - _get_trigger_down() - else: - _get_trigger_up() + _active_controller = controller + _trigger_state = true + _update_selection() + emit_signal("trigger_on") -func _get_trigger_down(): - for c in active_controllers: - if c.is_button_pressed(JOY_VR_TRIGGER): - _active_controller = c - emit_signal("trigger_on") - return +func _trigger_off(): + _active_controller = null + _trigger_state = false + _update_selection() + emit_signal("trigger_off") -func _get_trigger_up(): - if not _active_controller.is_button_pressed(JOY_VR_TRIGGER): - _active_controller = null - emit_signal("trigger_off") - - -func _on_Area_body_entered(body: Node) -> void: +func _on_OverlayArea_entered(body: Node) -> void: if body.get_parent().get_parent() != self: return - panel.theme = active_theme _touch_state = true + _update_selection() emit_signal("touch_on") -func _on_Area_body_exited(body: Node) -> void: +func _on_OverlayArea_exited(body: Node) -> void: if body.get_parent().get_parent() != self: return - panel.theme = normal_theme _touch_state = false + _update_selection() emit_signal("touch_off") -func _on_width_changed(width): +func _update_selection(): + if _trigger_state: + panel.theme = active_theme + elif _touch_state: + panel.theme = touching_theme + else: + panel.theme = normal_theme + + +func _update_width(): var ratio = OverlayInit.ovr_interface.get_render_targetsize() - $LeftHand/Area/CollisionShape.shape.set_extents(Vector3(0.5*width, 0.5*width * ratio.y/ratio.x, 0.01)) + var extents = get_parent().width_meters * 0.5 + _overlay_area.get_child(0).shape.set_extents(Vector3(extents, extents * ratio.y/ratio.x, 0.01)) + + +func _update_offset(): + _overlay_area.translation = get_parent().offset_pos + _overlay_area.rotation_degrees = get_parent().offset_rot + + +func _update_target(): + # move _overlay_area + _overlay_area.get_parent().remove_child(_overlay_area) + match get_parent().target: + OverlayInstance.TARGETS.head: + $Head.add_child(_overlay_area) + OverlayInstance.TARGETS.left: + $LeftHand.add_child(_overlay_area) + OverlayInstance.TARGETS.right: + $RightHand.add_child(_overlay_area) + OverlayInstance.TARGETS.world: + 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 + + +func _on_RightHand_button_pressed(button: int) -> void: + if button == JOY_VR_TRIGGER and _right_is_activator: + _trigger_on($RightHand) + + +func _on_RightHand_button_release(button: int) -> void: + if button == JOY_VR_TRIGGER and _active_controller == $RightHand: + _trigger_off() + + +func _on_LeftHand_button_pressed(button: int) -> void: + if button == JOY_VR_TRIGGER and _left_is_activator: + _trigger_on($LeftHand) + + +func _on_LeftHand_button_release(button: int) -> void: + if button == JOY_VR_TRIGGER and _active_controller == $LeftHand: + _trigger_off() func get_touch_state(): diff --git a/ovr-utils/addons/openvr_overlay/overlay_instance.gd b/ovr-utils/addons/openvr_overlay/overlay_instance.gd index a319697..c5b69cd 100644 --- a/ovr-utils/addons/openvr_overlay/overlay_instance.gd +++ b/ovr-utils/addons/openvr_overlay/overlay_instance.gd @@ -1,10 +1,14 @@ +class_name OverlayInstance extends Node signal width_changed +signal offset_changed +signal target_changed enum TARGETS { head, left, right, world } 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 overlay_scene = preload("res://addons/openvr_overlay/MissingOverlay.tscn")\ + setget _set_overlay_scene export var offset_pos := Vector3(0, 0, -1) setget _set_offset_pos export var offset_rot: Vector3 setget _set_offset_rot export var width_meters = 0.4 setget _set_width_meters @@ -61,7 +65,6 @@ func update_offset() -> void: func _tracker_changed(tracker_name: String, type: int, id: int): -# print("tracker changed: ", tracker_name) update_tracker_id() update_offset() @@ -74,22 +77,25 @@ func _set_target(new: int): target = new update_tracker_id() update_offset() + emit_signal("target_changed") func _set_offset_pos(pos: Vector3): offset_pos = pos update_offset() + emit_signal("offset_changed") func _set_offset_rot(rot: Vector3): offset_rot = rot update_offset() + emit_signal("offset_changed") func _set_width_meters(width: float): width_meters = width $OverlayViewport.overlay_width_in_meters = width_meters - emit_signal("width_changed", width) + emit_signal("width_changed") func _set_overlay_scene(scene: PackedScene): diff --git a/ovr-utils/project.godot b/ovr-utils/project.godot index b2bec3c..8076106 100644 --- a/ovr-utils/project.godot +++ b/ovr-utils/project.godot @@ -8,6 +8,16 @@ config_version=4 +_global_script_classes=[ { +"base": "Node", +"class": "OverlayInstance", +"language": "GDScript", +"path": "res://addons/openvr_overlay/overlay_instance.gd" +} ] +_global_script_class_icons={ +"OverlayInstance": "" +} + [application] config/name="ovr-utils"