From e28a1573d030d62a1e8bdd1d01facb1b0a5fb0d7 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Wed, 19 May 2021 22:17:26 +0200 Subject: [PATCH] plugin: add cursor that updates when a controller i touching an overlay --- ovr-utils/Main.tscn | 30 +------------ .../openvr_overlay/interaction/Cursor.tscn | 19 +++++++++ .../openvr_overlay/interaction/cursor.png | Bin 0 -> 90 bytes .../interaction/cursor.png.import | 34 +++++++++++++++ .../interaction/overlay_interaction.gd | 40 ++++++++++++++---- .../addons/openvr_overlay/overlay_instance.gd | 2 +- ovr-utils/overlays/xyz_widget/XYZ Widget.tscn | 39 +++++++++++++++++ 7 files changed, 126 insertions(+), 38 deletions(-) create mode 100644 ovr-utils/addons/openvr_overlay/interaction/Cursor.tscn create mode 100644 ovr-utils/addons/openvr_overlay/interaction/cursor.png create mode 100644 ovr-utils/addons/openvr_overlay/interaction/cursor.png.import create mode 100644 ovr-utils/overlays/xyz_widget/XYZ Widget.tscn diff --git a/ovr-utils/Main.tscn b/ovr-utils/Main.tscn index 7624d1b..615c274 100644 --- a/ovr-utils/Main.tscn +++ b/ovr-utils/Main.tscn @@ -1,11 +1,9 @@ -[gd_scene load_steps=10 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] [ext_resource path="res://overlays/TimeOverlay.tscn" type="PackedScene" id=3] [ext_resource path="res://temp.gd" type="Script" id=4] -[ext_resource path="res://overlays/xyz_widget/zx.tscn" type="PackedScene" id=5] -[ext_resource path="res://overlays/xyz_widget/yz.tscn" type="PackedScene" id=6] [ext_resource path="res://overlays/BatteryOverlay.tscn" type="PackedScene" id=7] [ext_resource path="res://addons/openvr_overlay/interaction/OverlayInteraction.tscn" type="PackedScene" id=8] @@ -31,7 +29,7 @@ offset_pos = Vector3( 0.05, -0.01, 0.15 ) offset_rot = Vector3( -135, 90, 0 ) [node name="OverlayInstance Time" parent="." instance=ExtResource( 1 )] -target = 1 +target = 3 overlay_scene = ExtResource( 3 ) offset_pos = Vector3( -0.05, 0.02, 0.15 ) offset_rot = Vector3( -135, 90, 0 ) @@ -39,31 +37,7 @@ width_meters = 0.1 [node name="OverlayInteraction" parent="OverlayInstance Time" instance=ExtResource( 8 )] -[node name="XYZ Widget" type="Node" parent="."] - -[node name="YZ" parent="XYZ Widget" instance=ExtResource( 1 )] -target = 1 -overlay_scene = ExtResource( 6 ) -offset_pos = Vector3( 0, 0, 0 ) -offset_rot = Vector3( 0, 90, 0 ) - -[node name="OverlayInteraction" parent="XYZ Widget/YZ" instance=ExtResource( 8 )] - -[node name="ZX" parent="XYZ Widget" instance=ExtResource( 1 )] -target = 1 -overlay_scene = ExtResource( 5 ) -offset_pos = Vector3( 0, 0, 0 ) -offset_rot = Vector3( -90, 0, 0 ) - -[node name="OverlayInteraction" parent="XYZ Widget/ZX" instance=ExtResource( 8 )] - [node name="Spatial" type="Spatial" parent="."] [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/Cursor.tscn b/ovr-utils/addons/openvr_overlay/interaction/Cursor.tscn new file mode 100644 index 0000000..fbbba79 --- /dev/null +++ b/ovr-utils/addons/openvr_overlay/interaction/Cursor.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/openvr_overlay/interaction/cursor.png" type="Texture" id=1] + +[node name="Cursor" type="Control"] +margin_right = 1024.0 +margin_bottom = 600.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="TextureRect" type="TextureRect" parent="."] +margin_right = 70.0 +margin_bottom = 70.0 +texture = ExtResource( 1 ) +expand = true +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/ovr-utils/addons/openvr_overlay/interaction/cursor.png b/ovr-utils/addons/openvr_overlay/interaction/cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..a40d298992c4a714bb4ad96c53a54e1287e12783 GIT binary patch literal 90 zcmeAS@N?(olHy`uVBq!ia0vp^>>$j+0wnXI=SKi3MNb#U5RRG231IN!zr2&N;Q|H| jJ!Kb3Wn~{r&ML+iH#u1D&8@BlDrWF>^>bP0l+XkKJ*E}@ literal 0 HcmV?d00001 diff --git a/ovr-utils/addons/openvr_overlay/interaction/cursor.png.import b/ovr-utils/addons/openvr_overlay/interaction/cursor.png.import new file mode 100644 index 0000000..9834421 --- /dev/null +++ b/ovr-utils/addons/openvr_overlay/interaction/cursor.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/cursor.png-7f24cea8864d49e2d004ac92503853e7.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/openvr_overlay/interaction/cursor.png" +dest_files=[ "res://.import/cursor.png-7f24cea8864d49e2d004ac92503853e7.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +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=true +svg/scale=1.0 diff --git a/ovr-utils/addons/openvr_overlay/interaction/overlay_interaction.gd b/ovr-utils/addons/openvr_overlay/interaction/overlay_interaction.gd index 0eccf1b..4f99953 100644 --- a/ovr-utils/addons/openvr_overlay/interaction/overlay_interaction.gd +++ b/ovr-utils/addons/openvr_overlay/interaction/overlay_interaction.gd @@ -9,14 +9,14 @@ export var active_theme: Theme export var normal_theme: Theme export var touching_theme: Theme -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 # 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 +# reference to the area node thats used for touch +var _overlay_area = preload("res://addons/openvr_overlay/interaction/OverlayArea.tscn").instance() +var _cursor_node = preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance() var _right_is_activator = false var _left_is_activator = false @@ -25,11 +25,8 @@ onready var panel = get_node("../OverlayViewport/PanelContainer") func _ready() -> void: - # TEMP - _right_is_activator = true - ############### - _overlay_area = OVERLAY_AREA.instance() add_child(_overlay_area) + get_node("../OverlayViewport").add_child(_cursor_node) _overlay_area.connect("body_entered", self, "_on_OverlayArea_entered") _overlay_area.connect("body_exited", self, "_on_OverlayArea_exited") @@ -43,7 +40,30 @@ func _ready() -> void: func _process(delta: float) -> void: - pass + _update_cursor() + + +#get canvas position of active controller +func get_canvas_pos() -> Vector2: + if _active_controller == null: + return Vector2(-1000, 1000) # offscreen + + var controller_local_pos = _overlay_area.global_transform.xform_inv(\ + _active_controller.global_transform.origin) + var pos = Vector2(controller_local_pos.x, controller_local_pos.y) + + var overlay_size = OverlayInit.ovr_interface.get_render_targetsize() + # scale to pixels + pos *= overlay_size.x + pos /= 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 _trigger_on(controller): @@ -55,7 +75,6 @@ func _trigger_on(controller): func _trigger_off(): - _active_controller = null _trigger_state = false _update_selection() emit_signal("trigger_off") @@ -65,13 +84,16 @@ func _on_OverlayArea_entered(body: Node) -> void: if body.get_parent().get_parent() != self: return _touch_state = true + _active_controller = body.get_parent() _update_selection() + _update_cursor() emit_signal("touch_on") func _on_OverlayArea_exited(body: Node) -> void: if body.get_parent().get_parent() != self: return + _active_controller = null # TODO revert to other controller if both were touching (edge case) _touch_state = false _update_selection() emit_signal("touch_off") diff --git a/ovr-utils/addons/openvr_overlay/overlay_instance.gd b/ovr-utils/addons/openvr_overlay/overlay_instance.gd index c5b69cd..c1a5951 100644 --- a/ovr-utils/addons/openvr_overlay/overlay_instance.gd +++ b/ovr-utils/addons/openvr_overlay/overlay_instance.gd @@ -101,7 +101,7 @@ func _set_width_meters(width: float): func _set_overlay_scene(scene: PackedScene): overlay_scene = scene if not container: - print("container missing") + print("container does not exist yet [overlay_instance.set_overlay_scene]") return if container.get_child_count() > 0: container.get_child(0).queue_free() diff --git a/ovr-utils/overlays/xyz_widget/XYZ Widget.tscn b/ovr-utils/overlays/xyz_widget/XYZ Widget.tscn new file mode 100644 index 0000000..49380b3 --- /dev/null +++ b/ovr-utils/overlays/xyz_widget/XYZ Widget.tscn @@ -0,0 +1,39 @@ +[gd_scene load_steps=10 format=2] + +[ext_resource path="res://addons/openvr_overlay/styles/normal.theme" type="Theme" id=1] +[ext_resource path="res://overlays/xyz_widget/zx.tscn" type="PackedScene" id=2] +[ext_resource path="res://addons/openvr_overlay/overlay_instance.gd" type="Script" id=3] +[ext_resource path="res://addons/openvr_overlay/styles/active.theme" type="Theme" id=4] +[ext_resource path="res://addons/openvr_overlay/interaction/overlay_interaction.gd" type="Script" id=5] +[ext_resource path="res://addons/openvr_overlay/styles/touching.theme" type="Theme" id=6] +[ext_resource path="res://overlays/xyz_widget/yz.tscn" type="PackedScene" id=7] +[ext_resource path="res://addons/openvr_overlay/interaction/OverlayInteraction.tscn" type="PackedScene" id=8] +[ext_resource path="res://addons/openvr_overlay/OverlayInstance.tscn" type="PackedScene" id=9] + +[node name="XYZ Widget" type="Node"] + +[node name="YZ" type="Node" parent="." instance=ExtResource( 9 )] +script = ExtResource( 3 ) +target = 1 +overlay_scene = ExtResource( 7 ) +offset_pos = Vector3( 0, 0, 0 ) +offset_rot = Vector3( 0, 90, 0 ) + +[node name="OverlayInteraction" type="ARVROrigin" parent="YZ" instance=ExtResource( 8 )] +script = ExtResource( 5 ) +active_theme = ExtResource( 4 ) +normal_theme = ExtResource( 1 ) +touching_theme = ExtResource( 6 ) + +[node name="ZX" type="Node" parent="." instance=ExtResource( 9 )] +script = ExtResource( 3 ) +target = 1 +overlay_scene = ExtResource( 2 ) +offset_pos = Vector3( 0, 0, 0 ) +offset_rot = Vector3( -90, 0, 0 ) + +[node name="OverlayInteraction" type="ARVROrigin" parent="ZX" instance=ExtResource( 8 )] +script = ExtResource( 5 ) +active_theme = ExtResource( 4 ) +normal_theme = ExtResource( 1 ) +touching_theme = ExtResource( 6 )