Compare commits

..

5 commits

10 changed files with 83 additions and 10 deletions

5
.gitignore vendored
View file

@ -14,6 +14,11 @@ compile_commands.json
# Ignore addons files (copied from submodules), except uid created on import
/project/addons/godot-xr-tools/**
!/project/addons/godot-xr-tools/**/*.uid
/project/addons/gdcef/**
!/project/addons/gdcef/**/*.uid
# Chrome Embedded Framework binaries
/project/cef_artifacts
# Created by https://www.toptal.com/developers/gitignore/api/c++,godot,scons,python
# Edit at https://www.toptal.com/developers/gitignore?templates=c++,godot,scons,python

3
.gitmodules vendored
View file

@ -7,3 +7,6 @@
[submodule "modules/godot-xr-tools"]
path = modules/godot-xr-tools
url = https://github.com/GodotVR/godot-xr-tools.git
[submodule "modules/gdcef"]
path = modules/gdcef
url = https://github.com/Lecrapouille/gdcef.git

View file

@ -32,6 +32,7 @@ godot --dump-extension-api # after updating Godot
python update_mavlink.py # after updating MAVLink dialect
python update_addons.py # after changing any addon submodules
scons compile_commands # after modifying SConstruct
cd project/addons/gdcef; python build.py
```
### Windows setup

1
modules/gdcef Submodule

@ -0,0 +1 @@
Subproject commit 76957e99ba87af9aecbde4dddc861e98f87ec43f

View file

@ -12,6 +12,9 @@ var _rotor_azimuth: float = 0
@onready var connector: MarshConnector = $MarshConnector
@onready var skeleton: Skeleton3D = $"Mi-2/Armature/Skeleton3D"
@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_cyclic: int = skeleton.find_bone("Cyclic")
@ -20,7 +23,7 @@ var _rotor_azimuth: float = 0
func _process(delta: float) -> void:
var target := connector.get_aircraft()
position = target.origin
# Add the rotation to the correct bone for rotation around CG
var rest := skeleton.get_bone_rest(bone_cg).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)
attitude_root.rotation = target.basis.get_euler()
# Rotate the cyclic stick bone
var cyclic := connector.get_cyclic()
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_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)
# Spin the rotor only when receiving flight data
if connector.get_model_connected():
_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))
# Note that this is reverse order, to rotate in local bone axes
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

View file

@ -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="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"]
@ -17,12 +19,32 @@ material_override = SubResource("StandardMaterial3D_mrxe8")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.4, 0)
[node name="PilotEyes" type="Node3D" parent="AttitudeRoot"]
editor_description = "Added only to provide a convenient point to reset XROrigin3D to"
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0.214, -0.721897, 1.53478)
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.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="."]

View file

@ -1,6 +1,6 @@
[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"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_7dm0k"]

View file

@ -31,6 +31,6 @@ renderer/rendering_method.mobile="gl_compatibility"
[xr]
openxr/enabled=true
openxr/reference_space=0
openxr/reference_space=2
openxr/foveation_level=3
shaders/enabled=true

View file

@ -34,6 +34,7 @@ func _ready() -> void:
xr_interface.session_focussed.connect(_on_openxr_focused_state)
xr_interface.session_stopping.connect(_on_openxr_stopping)
xr_interface.pose_recentered.connect(_on_openxr_pose_recentered)
XRServer.tracker_added.connect(_on_tracker_added)
else:
# We couldn't start OpenXR.
print("OpenXR not instantiated!")
@ -41,6 +42,9 @@ func _ready() -> void:
#get_tree().quit()
func _on_tracker_added(tracker_name: StringName, type: int) -> void:
print("added tracker", tracker_name, "type", type)
# Handle OpenXR session ready.
func _on_openxr_session_begun() -> void:
# Get the reported refresh rate.

29
update_addons.py Normal file
View file

@ -0,0 +1,29 @@
from os import path
from shutil import copytree
# Add repository root path
root_path = path.abspath(path.dirname(__file__))
# Copy the addon folder from each module
copytree(
path.join(root_path, 'modules', 'gdcef', 'addons'),
path.join(root_path, 'project', 'addons'),
dirs_exist_ok=True,
)
# Configure gdcef version for precompiled binaries
gdcef_build = path.join(root_path, 'project', 'addons', 'gdcef', 'build.py')
gdcef_lines = []
with open(gdcef_build, 'r', encoding='utf-8') as file:
gdcef_lines = file.readlines()
for i, line in enumerate(gdcef_lines):
if not line.startswith('GITHUB_GDCEF_RELEASE'):
continue
gdcef_lines[i] = 'GITHUB_GDCEF_RELEASE = "0.16.1"\n'
break
with open(gdcef_build, 'w', encoding='utf-8') as file:
file.writelines(gdcef_lines)