plugin: add cursor that updates when a controller i touching an overlay

This commit is contained in:
Crispy 2021-05-19 22:17:26 +02:00
parent 131a8aa798
commit e28a1573d0
7 changed files with 126 additions and 38 deletions

View file

@ -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 )]

View file

@ -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
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

View file

@ -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

View file

@ -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")

View file

@ -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()

View file

@ -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 )