mirror of
https://github.com/CrispyPin/ovr-utils.git
synced 2024-11-12 19:40:26 +01:00
cleanup
This commit is contained in:
parent
ddb59ed697
commit
54f9e4f85c
5 changed files with 38 additions and 38 deletions
|
@ -25,6 +25,9 @@ overlay_scene = ExtResource( 5 )
|
||||||
|
|
||||||
[node name="OverlayInteraction" parent="OverlayInstance UI demo" instance=ExtResource( 8 )]
|
[node name="OverlayInteraction" parent="OverlayInstance UI demo" instance=ExtResource( 8 )]
|
||||||
|
|
||||||
|
[node name="head" parent="OverlayInstance UI demo/OverlayInteraction/VR" index="2"]
|
||||||
|
current = true
|
||||||
|
|
||||||
[node name="XYZ Widget" parent="." instance=ExtResource( 4 )]
|
[node name="XYZ Widget" parent="." instance=ExtResource( 4 )]
|
||||||
|
|
||||||
[node name="OverlayInstance Battery" parent="." instance=ExtResource( 1 )]
|
[node name="OverlayInstance Battery" parent="." instance=ExtResource( 1 )]
|
||||||
|
|
|
@ -5,21 +5,22 @@ signal touch_off # a controller exited
|
||||||
signal trigger_on # trigger pushed while touching
|
signal trigger_on # trigger pushed while touching
|
||||||
signal trigger_off # trigger released
|
signal trigger_off # trigger released
|
||||||
|
|
||||||
var _touch_state = false setget ,get_touch_state
|
var _touch_state = false
|
||||||
var _trigger_state = false setget ,get_trigger_state
|
var _trigger_state = false
|
||||||
|
|
||||||
# controller that currently the trigger down
|
# controller that currently the trigger down
|
||||||
var _active_controller: ARVRController setget ,get_active_controller
|
var _active_controller: ARVRController setget ,get_active_controller
|
||||||
# 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 _overlay_area = preload("res://addons/openvr_overlay/interaction/OverlayArea.tscn").instance()
|
||||||
var _cursor_node = preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance()
|
var _cursor_node = preload("res://addons/openvr_overlay/interaction/Cursor.tscn").instance()
|
||||||
var _right_is_activator = false
|
var _right_is_activator = false
|
||||||
var _left_is_activator = false
|
var _left_is_activator = false
|
||||||
|
|
||||||
var is_moving := false
|
var is_moving := false
|
||||||
var _pre_move_target = ""# what offset is being changed
|
var _pre_move_target = ""# what offset is being changed
|
||||||
var _mover_hand_name = ""# left or right, which hand is grabbing (/active controller)
|
var _mover_hand_name = ""# left or right, which hand is grabbing (/active controller)
|
||||||
var _mover_hand_offsets = {"pos": Vector3(), "rot": Vector3()} # original offsets for grabbing hand
|
var _mover_hand_offsets = {"pos": Vector3(), "rot": Quat()} # original offsets for grabbing hand
|
||||||
|
|
||||||
|
|
||||||
onready var viewport: Viewport = get_node("../OverlayViewport")
|
onready var viewport: Viewport = get_node("../OverlayViewport")
|
||||||
onready var tracker_nodes = {
|
onready var tracker_nodes = {
|
||||||
|
@ -31,8 +32,9 @@ onready var tracker_nodes = {
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
viewport.add_child(_cursor_node)
|
||||||
|
|
||||||
add_child(_overlay_area)
|
add_child(_overlay_area)
|
||||||
get_node("../OverlayViewport").add_child(_cursor_node)
|
|
||||||
_overlay_area.connect("body_entered", self, "_on_OverlayArea_entered")
|
_overlay_area.connect("body_entered", self, "_on_OverlayArea_entered")
|
||||||
_overlay_area.connect("body_exited", self, "_on_OverlayArea_exited")
|
_overlay_area.connect("body_exited", self, "_on_OverlayArea_exited")
|
||||||
|
|
||||||
|
@ -54,33 +56,41 @@ func begin_move():
|
||||||
print("Could not begin moving overlay, no controller active. ", get_parent().name)
|
print("Could not begin moving overlay, no controller active. ", get_parent().name)
|
||||||
return
|
return
|
||||||
is_moving = true
|
is_moving = true
|
||||||
|
# store current states to revert after move
|
||||||
_pre_move_target = get_parent().current_target
|
_pre_move_target = get_parent().current_target
|
||||||
_mover_hand_name = _active_controller.name
|
_mover_hand_name = _active_controller.name
|
||||||
_mover_hand_offsets.pos = get_parent().translation
|
_mover_hand_offsets.pos = get_parent().offsets[_mover_hand_name].pos
|
||||||
_mover_hand_offsets.rot = get_parent().rotation
|
_mover_hand_offsets.rot = get_parent().offsets[_mover_hand_name].rot
|
||||||
|
|
||||||
# offset from active controller to overlay
|
# calculate offsets from active controller to overlay
|
||||||
var global_rot = _overlay_area.global_transform.basis.get_rotation_quat()
|
var controller_t = _active_controller.transform
|
||||||
var hand_rot = _active_controller.transform.basis.get_rotation_quat()
|
var overlay_t = _overlay_area.global_transform
|
||||||
get_parent().offsets[_mover_hand_name].rot = hand_rot.inverse() * global_rot
|
|
||||||
|
|
||||||
get_parent().offsets[_mover_hand_name].pos = _active_controller.transform.xform_inv(_overlay_area.global_transform.origin)
|
get_parent().offsets[_mover_hand_name].rot = Quat(controller_t.basis).inverse() * Quat(overlay_t.basis)
|
||||||
|
get_parent().offsets[_mover_hand_name].pos = controller_t.xform_inv(overlay_t.origin)
|
||||||
|
|
||||||
get_parent().current_target = _mover_hand_name
|
get_parent().current_target = _mover_hand_name
|
||||||
|
|
||||||
|
|
||||||
func finish_move():
|
func finish_move():
|
||||||
is_moving = false
|
# calculate and apply the new offsets
|
||||||
var new_pos = tracker_nodes[_pre_move_target].transform.xform_inv(_overlay_area.global_transform.origin)
|
var new_target_t = tracker_nodes[_pre_move_target].transform
|
||||||
|
var ovelay_t = _overlay_area.global_transform
|
||||||
|
|
||||||
var new_rot = tracker_nodes[_pre_move_target].transform.basis.get_rotation_quat().inverse() * _overlay_area.global_transform.basis.get_rotation_quat()
|
var new_pos = new_target_t.xform_inv(ovelay_t.origin)
|
||||||
|
var new_rot = Quat(new_target_t.basis).inverse() * Quat(ovelay_t.basis)
|
||||||
|
get_parent().offsets[_pre_move_target].pos = new_pos
|
||||||
|
get_parent().offsets[_pre_move_target].rot = new_rot
|
||||||
|
|
||||||
|
# revert the grabbing hands offsets in case it's used as a fallback
|
||||||
|
get_parent().offsets[_mover_hand_name].pos = _mover_hand_offsets.pos
|
||||||
|
get_parent().offsets[_mover_hand_name].rot = _mover_hand_offsets.rot
|
||||||
|
|
||||||
|
# reset current_target (parent handles fallback)
|
||||||
get_parent().update_current_target()
|
get_parent().update_current_target()
|
||||||
get_parent().update_tracker_id()
|
|
||||||
get_parent().offsets[get_parent().current_target].pos = new_pos
|
|
||||||
get_parent().offsets[get_parent().current_target].rot = new_rot
|
|
||||||
get_parent().update_offset()
|
|
||||||
_update_target()
|
_update_target()
|
||||||
|
is_moving = false
|
||||||
|
|
||||||
|
|
||||||
#get canvas position of active controller
|
#get canvas position of active controller
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
var ihandler
|
var ihandler
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
@ -8,10 +7,8 @@ func _ready() -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_DragButton_button_down() -> void:
|
func _on_DragButton_button_down() -> void:
|
||||||
if ihandler:
|
ihandler.begin_move()
|
||||||
ihandler.begin_move()
|
|
||||||
|
|
||||||
|
|
||||||
func _on_DragButton_button_up() -> void:
|
func _on_DragButton_button_up() -> void:
|
||||||
if ihandler:
|
ihandler.finish_move()
|
||||||
ihandler.finish_move()
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
class_name OverlayInstance
|
|
||||||
extends Spatial
|
extends Spatial
|
||||||
|
|
||||||
signal width_changed
|
signal width_changed
|
||||||
|
@ -7,6 +6,7 @@ signal target_changed
|
||||||
|
|
||||||
const TARGETS = ["head", "left", "right", "world"]
|
const TARGETS = ["head", "left", "right", "world"]
|
||||||
export (String, "head", "left", "right", "world") var target = "left" setget set_target
|
export (String, "head", "left", "right", "world") var target = "left" setget set_target
|
||||||
|
|
||||||
export var overlay_scene =\
|
export var overlay_scene =\
|
||||||
preload("res://addons/openvr_overlay/MissingOverlay.tscn") setget set_overlay_scene
|
preload("res://addons/openvr_overlay/MissingOverlay.tscn") setget set_overlay_scene
|
||||||
export var width_meters = 0.4 setget set_width_in_meters
|
export var width_meters = 0.4 setget set_width_in_meters
|
||||||
|
@ -17,7 +17,6 @@ export var offsets:Dictionary = {
|
||||||
"right": {"pos": Vector3(), "rot": Quat()},
|
"right": {"pos": Vector3(), "rot": Quat()},
|
||||||
"world": {"pos": Vector3(), "rot": Quat()}
|
"world": {"pos": Vector3(), "rot": Quat()}
|
||||||
}
|
}
|
||||||
# also contains temp offset that is created when dragged
|
|
||||||
|
|
||||||
# what's actually tracking
|
# what's actually tracking
|
||||||
var current_target = target setget _set_current_target# most of the time the actual target, but will fall back
|
var current_target = target setget _set_current_target# most of the time the actual target, but will fall back
|
||||||
|
@ -75,10 +74,11 @@ func update_offset() -> void:
|
||||||
|
|
||||||
|
|
||||||
func update_current_target():
|
func update_current_target():
|
||||||
current_target = target
|
_set_current_target(target)
|
||||||
# TODO fallback if not found
|
# TODO fallback if not found
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _tracker_changed(tracker_name: String, type: int, id: int):
|
func _tracker_changed(tracker_name: String, type: int, id: int):
|
||||||
update_tracker_id()
|
update_tracker_id()
|
||||||
update_offset()
|
update_offset()
|
||||||
|
|
|
@ -8,16 +8,6 @@
|
||||||
|
|
||||||
config_version=4
|
config_version=4
|
||||||
|
|
||||||
_global_script_classes=[ {
|
|
||||||
"base": "Spatial",
|
|
||||||
"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"
|
||||||
|
|
Loading…
Reference in a new issue