mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-10 02:40:25 +01:00
use spatial node for overlays for easier offsets
This commit is contained in:
parent
34bf10eb18
commit
e33ea49aaf
8 changed files with 35 additions and 74 deletions
|
@ -1,8 +1,9 @@
|
|||
[gd_scene load_steps=8 format=2]
|
||||
[gd_scene load_steps=9 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://overlays/xyz_widget/XYZ Widget.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://overlays/UI_demo.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://overlays/BatteryOverlay.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://addons/openvr_overlay/OverlayInteraction.tscn" type="PackedScene" id=8]
|
||||
|
@ -14,35 +15,32 @@ background_color = Color( 0.113725, 0.0705882, 0.196078, 1 )
|
|||
[node name="Overlays" type="Node"]
|
||||
|
||||
[node name="OverlayInstance FPS" 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.05, -0.01, 0.15 )
|
||||
target = 1
|
||||
overlay_scene = ExtResource( 2 )
|
||||
offset_pos = Vector3( 0.05, -0.01, 0.15 )
|
||||
offset_rot = Vector3( -135, 90, 0 )
|
||||
|
||||
[node name="OverlayInstance Time" 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.05, 0.02, 0.15 )
|
||||
target = 1
|
||||
overlay_scene = ExtResource( 3 )
|
||||
offset_pos = Vector3( -0.05, 0.02, 0.15 )
|
||||
offset_rot = Vector3( -135, 90, 0 )
|
||||
width_meters = 0.1
|
||||
|
||||
[node name="OverlayInteraction" parent="OverlayInstance Time" instance=ExtResource( 8 )]
|
||||
|
||||
[node name="Spatial" type="Spatial" parent="."]
|
||||
|
||||
[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 )
|
||||
offset_pos = Vector3( -0.12, 0, 0.1 )
|
||||
offset_rot = Vector3( -135, 90, 0 )
|
||||
|
||||
[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 )
|
||||
target = 1
|
||||
overlay_scene = ExtResource( 5 )
|
||||
offset_pos = Vector3( 0, 0, -0.2 )
|
||||
offset_rot = Vector3( 0, 90, 0 )
|
||||
|
||||
[node name="OverlayInteraction" parent="OverlayInstance UI demo" instance=ExtResource( 8 )]
|
||||
|
||||
[node name="XYZ Widget" parent="." instance=ExtResource( 4 )]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.123379, 0, 0 )
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
[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="Node"]
|
||||
[node name="OverlayInstance" type="Spatial"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="OverlayViewport" type="Viewport" parent="."]
|
||||
|
@ -24,5 +24,3 @@ overlay_width_in_meters = 0.4
|
|||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
theme = ExtResource( 5 )
|
||||
|
||||
[node name="Offset" type="RemoteTransform" parent="."]
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=3 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]
|
||||
[ext_resource path="res://addons/openvr_overlay/interaction/OverlayActivator.tscn" type="PackedScene" id=6]
|
||||
|
||||
[node name="OverlayInteraction" type="ARVROrigin"]
|
||||
script = ExtResource( 1 )
|
||||
active_theme = ExtResource( 2 )
|
||||
normal_theme = ExtResource( 3 )
|
||||
touching_theme = ExtResource( 4 )
|
||||
|
||||
[node name="LeftHand" type="ARVRController" parent="."]
|
||||
|
||||
|
@ -22,6 +16,7 @@ controller_id = 2
|
|||
[node name="OverlayActivator" parent="RightHand" instance=ExtResource( 6 )]
|
||||
|
||||
[node name="Head" type="ARVRCamera" parent="."]
|
||||
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"]
|
||||
|
|
|
@ -107,8 +107,8 @@ func _update_width():
|
|||
|
||||
|
||||
func _update_offset():
|
||||
_overlay_area.translation = get_parent().offset_pos
|
||||
_overlay_area.rotation_degrees = get_parent().offset_rot
|
||||
_overlay_area.translation = get_parent().translation
|
||||
_overlay_area.rotation_degrees = get_parent().rotation_degrees
|
||||
|
||||
|
||||
func _update_target():
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class_name OverlayInstance
|
||||
extends Node
|
||||
extends Spatial
|
||||
|
||||
signal width_changed
|
||||
signal offset_changed
|
||||
|
@ -9,8 +9,8 @@ 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 offset_pos := Vector3(0, 0, -1) setget set_offset_pos
|
||||
export var offset_rot: Vector3 setget set_offset_rot
|
||||
#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_in_meters
|
||||
export var fallback_to_hmd = false # fallback is only applied if tracker is not present at startup
|
||||
# so this is not fully implemented
|
||||
|
@ -31,6 +31,13 @@ func _ready() -> void:
|
|||
|
||||
update_tracker_id()
|
||||
update_offset()
|
||||
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:
|
||||
|
@ -52,16 +59,13 @@ func update_tracker_id() -> void:
|
|||
|
||||
|
||||
func update_offset() -> void:
|
||||
$Offset.translation = offset_pos
|
||||
$Offset.rotation_degrees = offset_rot
|
||||
|
||||
match target:
|
||||
TARGETS.head:
|
||||
$OverlayViewport.track_relative_to_device(0, $Offset.transform)
|
||||
$OverlayViewport.track_relative_to_device(0, global_transform)
|
||||
TARGETS.world:
|
||||
$OverlayViewport.overlay_position_absolute($Offset.transform)
|
||||
$OverlayViewport.overlay_position_absolute(global_transform)
|
||||
_:
|
||||
$OverlayViewport.track_relative_to_device(_tracker_id, $Offset.transform)
|
||||
$OverlayViewport.track_relative_to_device(_tracker_id, global_transform)
|
||||
|
||||
|
||||
func _tracker_changed(tracker_name: String, type: int, id: int):
|
||||
|
@ -80,18 +84,6 @@ func _set_target(new: int):
|
|||
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_in_meters(width: float):
|
||||
width_meters = width
|
||||
$OverlayViewport.overlay_width_in_meters = width_meters
|
||||
|
|
|
@ -5,7 +5,7 @@ func _ready() -> void:
|
|||
pass
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
func _process(_delta: float) -> void:
|
||||
_update_time()
|
||||
|
||||
|
||||
|
|
|
@ -1,39 +1,17 @@
|
|||
[gd_scene load_steps=10 format=2]
|
||||
[gd_scene load_steps=4 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/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="XYZ Widget" type="Spatial"]
|
||||
|
||||
[node name="YZ" type="Node" parent="." instance=ExtResource( 9 )]
|
||||
script = ExtResource( 3 )
|
||||
[node name="YZ" parent="." instance=ExtResource( 9 )]
|
||||
transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0 )
|
||||
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 )
|
||||
[node name="ZX" parent="." instance=ExtResource( 9 )]
|
||||
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0 )
|
||||
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 )
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
config_version=4
|
||||
|
||||
_global_script_classes=[ {
|
||||
"base": "Node",
|
||||
"base": "Spatial",
|
||||
"class": "OverlayInstance",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/openvr_overlay/overlay_instance.gd"
|
||||
|
|
Loading…
Reference in a new issue