Working with Varjo and Vive Tracker
This commit is contained in:
parent
6d93630e50
commit
55004f3e60
5 changed files with 44 additions and 10 deletions
|
|
@ -12,6 +12,9 @@ var _rotor_azimuth: float = 0
|
||||||
@onready var connector: MarshConnector = $MarshConnector
|
@onready var connector: MarshConnector = $MarshConnector
|
||||||
@onready var skeleton: Skeleton3D = $"Mi-2/Armature/Skeleton3D"
|
@onready var skeleton: Skeleton3D = $"Mi-2/Armature/Skeleton3D"
|
||||||
@onready var attitude_root: Node3D = $AttitudeRoot
|
@onready var attitude_root: Node3D = $AttitudeRoot
|
||||||
|
@onready var tracker_mount: Node3D = $AttitudeRoot/PilotEyes/PilotFloor/TrackerMountChair
|
||||||
|
@onready var xr_origin: XROrigin3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D
|
||||||
|
@onready var tracker: XRController3D = $AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D/ViveTracker
|
||||||
|
|
||||||
@onready var bone_cg: int = skeleton.find_bone("BodyCG")
|
@onready var bone_cg: int = skeleton.find_bone("BodyCG")
|
||||||
@onready var bone_cyclic: int = skeleton.find_bone("Cyclic")
|
@onready var bone_cyclic: int = skeleton.find_bone("Cyclic")
|
||||||
|
|
@ -20,7 +23,7 @@ var _rotor_azimuth: float = 0
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
var target := connector.get_aircraft()
|
var target := connector.get_aircraft()
|
||||||
position = target.origin
|
position = target.origin
|
||||||
|
|
||||||
# Add the rotation to the correct bone for rotation around CG
|
# Add the rotation to the correct bone for rotation around CG
|
||||||
var rest := skeleton.get_bone_rest(bone_cg).basis.get_rotation_quaternion()
|
var rest := skeleton.get_bone_rest(bone_cg).basis.get_rotation_quaternion()
|
||||||
var attitude := target.basis.get_rotation_quaternion()
|
var attitude := target.basis.get_rotation_quaternion()
|
||||||
|
|
@ -28,14 +31,14 @@ func _process(delta: float) -> void:
|
||||||
|
|
||||||
# Rotate other children (not using BoneAttachment3D due to jitter)
|
# Rotate other children (not using BoneAttachment3D due to jitter)
|
||||||
attitude_root.rotation = target.basis.get_euler()
|
attitude_root.rotation = target.basis.get_euler()
|
||||||
|
|
||||||
# Rotate the cyclic stick bone
|
# Rotate the cyclic stick bone
|
||||||
var cyclic := connector.get_cyclic()
|
var cyclic := connector.get_cyclic()
|
||||||
var cyc_rest := skeleton.get_bone_rest(bone_cyclic).basis.get_rotation_quaternion()
|
var cyc_rest := skeleton.get_bone_rest(bone_cyclic).basis.get_rotation_quaternion()
|
||||||
var cyc_angles_rad := cyclic * deg_to_rad(range_cyclic)
|
var cyc_angles_rad := cyclic * deg_to_rad(range_cyclic)
|
||||||
var cyc_att := Quaternion.from_euler(Vector3(cyc_angles_rad.y, cyc_angles_rad.x, 0))
|
var cyc_att := Quaternion.from_euler(Vector3(cyc_angles_rad.y, cyc_angles_rad.x, 0))
|
||||||
skeleton.set_bone_pose_rotation(bone_cyclic, cyc_att * cyc_rest)
|
skeleton.set_bone_pose_rotation(bone_cyclic, cyc_att * cyc_rest)
|
||||||
|
|
||||||
# Spin the rotor only when receiving flight data
|
# Spin the rotor only when receiving flight data
|
||||||
if connector.get_model_connected():
|
if connector.get_model_connected():
|
||||||
_rotor_azimuth += rotor_rpm * 2 * PI / 60 * delta
|
_rotor_azimuth += rotor_rpm * 2 * PI / 60 * delta
|
||||||
|
|
@ -43,3 +46,8 @@ func _process(delta: float) -> void:
|
||||||
var rotor_att := Quaternion.from_euler(Vector3(0, _rotor_azimuth, 0))
|
var rotor_att := Quaternion.from_euler(Vector3(0, _rotor_azimuth, 0))
|
||||||
# Note that this is reverse order, to rotate in local bone axes
|
# Note that this is reverse order, to rotate in local bone axes
|
||||||
skeleton.set_bone_pose_rotation(bone_rotor, rotor_rest * rotor_att)
|
skeleton.set_bone_pose_rotation(bone_rotor, rotor_rest * rotor_att)
|
||||||
|
|
||||||
|
if tracker.get_has_tracking_data():
|
||||||
|
xr_origin.transform = tracker_mount.transform * tracker.transform.affine_inverse()
|
||||||
|
else:
|
||||||
|
xr_origin.transform = Transform3D.IDENTITY
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
[gd_scene load_steps=4 format=3 uid="uid://bj1s0g7ixjw71"]
|
[gd_scene load_steps=6 format=3 uid="uid://bj1s0g7ixjw71"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cx30pr7kn4c74" path="res://aircraft/aircraft.gd" id="1_l4uib"]
|
[ext_resource type="Script" uid="uid://cx30pr7kn4c74" path="res://aircraft/aircraft.gd" id="1_l4uib"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cux4tju0ovvly" path="res://assets/mi2/Mi-2.glb" id="1_mrxe8"]
|
[ext_resource type="PackedScene" uid="uid://cux4tju0ovvly" path="res://assets/mi2/Mi-2.glb" id="1_mrxe8"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://fmygcraoturj" path="res://reference_axes.tscn" id="3_2bi7g"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cis4s43ubuynp" path="res://instruments.tscn" id="3_5w717"]
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_mrxe8"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_mrxe8"]
|
||||||
|
|
||||||
|
|
@ -17,12 +19,32 @@ material_override = SubResource("StandardMaterial3D_mrxe8")
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.4, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.4, 0)
|
||||||
|
|
||||||
[node name="PilotEyes" type="Node3D" parent="AttitudeRoot"]
|
[node name="PilotEyes" type="Node3D" parent="AttitudeRoot"]
|
||||||
editor_description = "Added only to provide a convenient point to reset XROrigin3D to"
|
editor_description = "Target position for Local XR tracking"
|
||||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0.214, -0.721897, 1.53478)
|
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0.214, -0.7, 1.594)
|
||||||
|
|
||||||
[node name="XROrigin3D" type="XROrigin3D" parent="AttitudeRoot/PilotEyes"]
|
[node name="PilotFloor" type="Node3D" parent="AttitudeRoot/PilotEyes"]
|
||||||
|
editor_description = "Required for floor tracking
|
||||||
|
(Varjo can only do that)"
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.8, 0)
|
||||||
|
|
||||||
[node name="XRCamera3D" type="XRCamera3D" parent="AttitudeRoot/PilotEyes/XROrigin3D"]
|
[node name="TrackerMountChair" type="Node3D" parent="AttitudeRoot/PilotEyes/PilotFloor"]
|
||||||
|
transform = Transform3D(-1, 8.74228e-08, -3.82137e-15, 0, -4.37114e-08, -1, -8.74228e-08, -1, 4.37114e-08, 0.27, 0.4, 0)
|
||||||
|
|
||||||
|
[node name="ReferenceAxes" parent="AttitudeRoot/PilotEyes/PilotFloor/TrackerMountChair" instance=ExtResource("3_2bi7g")]
|
||||||
|
transform = Transform3D(0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 0, 0, 0)
|
||||||
|
|
||||||
|
[node name="XROrigin3D" type="XROrigin3D" parent="AttitudeRoot/PilotEyes/PilotFloor"]
|
||||||
|
|
||||||
|
[node name="XRCamera3D" type="XRCamera3D" parent="AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D"]
|
||||||
|
|
||||||
|
[node name="ViveTracker" type="XRController3D" parent="AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D"]
|
||||||
|
tracker = &"/user/vive_tracker_htcx/role/camera"
|
||||||
|
|
||||||
|
[node name="ReferenceAxes" parent="AttitudeRoot/PilotEyes/PilotFloor/XROrigin3D/ViveTracker" instance=ExtResource("3_2bi7g")]
|
||||||
|
transform = Transform3D(0.25, 0, 0, 0, 0.25, 0, 0, 0, 0.25, 0, 0, 0)
|
||||||
|
|
||||||
|
[node name="Instruments" parent="AttitudeRoot" instance=ExtResource("3_5w717")]
|
||||||
|
transform = Transform3D(-0.5, -1.27582e-08, 7.43353e-08, 4.33325e-10, 0.4923, 0.0874084, -7.5421e-08, 0.0874084, -0.4923, 0.00724897, -1.1581, 2.40391)
|
||||||
|
|
||||||
[node name="MarshConnector" type="MarshConnector" parent="."]
|
[node name="MarshConnector" type="MarshConnector" parent="."]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_scene load_steps=6 format=3 uid="uid://crq3o0eu4y8ya"]
|
[gd_scene load_steps=6 format=3 uid="uid://crq3o0eu4y8ya"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://start_vr.gd" id="1_ig7tw"]
|
[ext_resource type="Script" uid="uid://dfcjdxesyn3l0" path="res://start_vr.gd" id="1_ig7tw"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bj1s0g7ixjw71" path="res://aircraft/aircraft.tscn" id="2_0xm2m"]
|
[ext_resource type="PackedScene" uid="uid://bj1s0g7ixjw71" path="res://aircraft/aircraft.tscn" id="2_0xm2m"]
|
||||||
|
|
||||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_7dm0k"]
|
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_7dm0k"]
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,6 @@ renderer/rendering_method.mobile="gl_compatibility"
|
||||||
[xr]
|
[xr]
|
||||||
|
|
||||||
openxr/enabled=true
|
openxr/enabled=true
|
||||||
openxr/reference_space=0
|
openxr/reference_space=2
|
||||||
openxr/foveation_level=3
|
openxr/foveation_level=3
|
||||||
shaders/enabled=true
|
shaders/enabled=true
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,16 @@ func _ready() -> void:
|
||||||
xr_interface.session_focussed.connect(_on_openxr_focused_state)
|
xr_interface.session_focussed.connect(_on_openxr_focused_state)
|
||||||
xr_interface.session_stopping.connect(_on_openxr_stopping)
|
xr_interface.session_stopping.connect(_on_openxr_stopping)
|
||||||
xr_interface.pose_recentered.connect(_on_openxr_pose_recentered)
|
xr_interface.pose_recentered.connect(_on_openxr_pose_recentered)
|
||||||
|
XRServer.tracker_added.connect(_on_tracker_added)
|
||||||
else:
|
else:
|
||||||
# We couldn't start OpenXR.
|
# We couldn't start OpenXR.
|
||||||
print("OpenXR not instantiated!")
|
print("OpenXR not instantiated!")
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_tracker_added(tracker_name: StringName, type: int) -> void:
|
||||||
|
print("added tracker", tracker_name, "type", type)
|
||||||
|
|
||||||
# Handle OpenXR session ready.
|
# Handle OpenXR session ready.
|
||||||
func _on_openxr_session_begun() -> void:
|
func _on_openxr_session_begun() -> void:
|
||||||
# Get the reported refresh rate.
|
# Get the reported refresh rate.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue