basic support for triggering overlays (highlights + signal), updates properly when properties change

This commit is contained in:
Crispy 2021-05-19 00:15:53 +02:00
parent 3e2a6096bf
commit 131a8aa798
7 changed files with 150 additions and 53 deletions

View file

@ -61,3 +61,9 @@ offset_rot = Vector3( -90, 0, 0 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="."] [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 1 ) 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,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 )

View file

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

View file

@ -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/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/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/normal.theme" type="Theme" id=3]
[ext_resource path="res://addons/openvr_overlay/styles/touching.theme" type="Theme" id=4] [ext_resource path="res://addons/openvr_overlay/styles/touching.theme" type="Theme" id=4]
[ext_resource path="res://addons/openvr_overlay/interaction/OverlayActivator.tscn" type="PackedScene" id=6]
[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
[node name="OverlayInteraction" type="ARVROrigin"] [node name="OverlayInteraction" type="ARVROrigin"]
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -20,23 +14,16 @@ touching_theme = ExtResource( 4 )
[node name="LeftHand" type="ARVRController" parent="."] [node name="LeftHand" type="ARVRController" parent="."]
[node name="Area" type="Area" parent="LeftHand"] [node name="OverlayActivator" parent="LeftHand" instance=ExtResource( 6 )]
[node name="CollisionShape" type="CollisionShape" parent="LeftHand/Area"]
shape = SubResource( 1 )
[node name="RightHand" type="ARVRController" parent="."] [node name="RightHand" type="ARVRController" parent="."]
controller_id = 2 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"] [node name="Head" type="ARVRCamera" parent="."]
shape = SubResource( 2 )
[node name="ARVRCamera" type="ARVRCamera" parent="."] [connection signal="button_pressed" from="LeftHand" to="." method="_on_LeftHand_button_pressed"]
[connection signal="button_release" from="LeftHand" to="." method="_on_LeftHand_button_release"]
[node name="Offset" type="RemoteTransform" parent="."] [connection signal="button_pressed" from="RightHand" to="." method="_on_RightHand_button_pressed"]
update_scale = false [connection signal="button_release" from="RightHand" to="." method="_on_RightHand_button_release"]
[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"]

View file

@ -9,64 +9,132 @@ export var active_theme: Theme
export var normal_theme: Theme export var normal_theme: Theme
export var touching_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 _touch_state = false setget ,get_touch_state
var _trigger_state = false setget ,get_trigger_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") onready var panel = get_node("../OverlayViewport/PanelContainer")
func _ready() -> void: func _ready() -> void:
get_parent().connect("width_changed", self, "_on_width_changed") # TEMP
_on_width_changed(get_parent().width_meters) _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() get_parent().connect("width_changed", self, "_update_width")
$Offset.remote_path = $LeftHand/Area.get_path() 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: func _process(delta: float) -> void:
pass
func _trigger_on(controller):
if _touch_state: if _touch_state:
if not _trigger_state: _active_controller = controller
_get_trigger_down() _trigger_state = true
else: _update_selection()
_get_trigger_up()
func _get_trigger_down():
for c in active_controllers:
if c.is_button_pressed(JOY_VR_TRIGGER):
_active_controller = c
emit_signal("trigger_on") emit_signal("trigger_on")
return
func _get_trigger_up(): func _trigger_off():
if not _active_controller.is_button_pressed(JOY_VR_TRIGGER):
_active_controller = null _active_controller = null
_trigger_state = false
_update_selection()
emit_signal("trigger_off") 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: if body.get_parent().get_parent() != self:
return return
panel.theme = active_theme
_touch_state = true _touch_state = true
_update_selection()
emit_signal("touch_on") 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: if body.get_parent().get_parent() != self:
return return
panel.theme = normal_theme
_touch_state = false _touch_state = false
_update_selection()
emit_signal("touch_off") 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() 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(): func get_touch_state():

View file

@ -1,10 +1,14 @@
class_name OverlayInstance
extends Node extends Node
signal width_changed signal width_changed
signal offset_changed
signal target_changed
enum TARGETS { head, left, right, world } 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 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_pos := Vector3(0, 0, -1) setget _set_offset_pos
export var offset_rot: Vector3 setget _set_offset_rot export var offset_rot: Vector3 setget _set_offset_rot
export var width_meters = 0.4 setget _set_width_meters 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): func _tracker_changed(tracker_name: String, type: int, id: int):
# print("tracker changed: ", tracker_name)
update_tracker_id() update_tracker_id()
update_offset() update_offset()
@ -74,22 +77,25 @@ func _set_target(new: int):
target = new target = new
update_tracker_id() update_tracker_id()
update_offset() update_offset()
emit_signal("target_changed")
func _set_offset_pos(pos: Vector3): func _set_offset_pos(pos: Vector3):
offset_pos = pos offset_pos = pos
update_offset() update_offset()
emit_signal("offset_changed")
func _set_offset_rot(rot: Vector3): func _set_offset_rot(rot: Vector3):
offset_rot = rot offset_rot = rot
update_offset() update_offset()
emit_signal("offset_changed")
func _set_width_meters(width: float): func _set_width_meters(width: float):
width_meters = width width_meters = width
$OverlayViewport.overlay_width_in_meters = width_meters $OverlayViewport.overlay_width_in_meters = width_meters
emit_signal("width_changed", width) emit_signal("width_changed")
func _set_overlay_scene(scene: PackedScene): func _set_overlay_scene(scene: PackedScene):

View file

@ -8,6 +8,16 @@
config_version=4 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] [application]
config/name="ovr-utils" config/name="ovr-utils"