Skip to content

Commit

Permalink
Fixed root node to point forwards under the hips.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malcolmnixon committed Mar 10, 2024
1 parent d44e0ef commit bff01aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 11 additions & 5 deletions addons/godot_axis_studio_tracker/axis_studio_source.gd
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ func _on_axis_studio_packet(data : AxisStudioBody.JointData) -> void:
var pos := data.positions[joint]
var rot := data.rotations[joint]

# If hips then consider position calibration
# Special handling for hips
if joint == AxisStudioBody.Joint.HIPS:
# Apply position-mode controls
match _position_mode:
PositionMode.CALIBRATE:
# Calibrate on first position
Expand Down Expand Up @@ -133,10 +134,15 @@ func _on_axis_studio_packet(data : AxisStudioBody.JointData) -> void:
# Set the joint flags
_body_tracker.set_joint_flags(body, JOINT_TRACKING)

# Calculate and set the root joint under the hips
var root := _body_tracker.get_joint_transform(XRBodyTracker.JOINT_HIPS)
root.basis = Basis.IDENTITY
root.origin = root.origin.slide(Vector3.UP)
# Get the hips transform
var hips := _body_tracker.get_joint_transform(XRBodyTracker.JOINT_HIPS)

# Construct the root under the hips pointing forwards
var root_y = Vector3.UP
var root_z = -hips.basis.x.cross(root_y)
var root_x = root_y.cross(root_z)
var root_o := hips.origin.slide(Vector3.UP)
var root := Transform3D(root_x, root_y, root_z, root_o).orthonormalized()
_body_tracker.set_joint_transform(XRBodyTracker.JOINT_ROOT, root)
_body_tracker.set_joint_flags(XRBodyTracker.JOINT_ROOT, JOINT_TRACKING)

Expand Down
15 changes: 14 additions & 1 deletion demo.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=3 uid="uid://btisi43jtpet"]
[gd_scene load_steps=14 format=3 uid="uid://btisi43jtpet"]

[ext_resource type="PackedScene" uid="uid://bhc6nngwjdvum" path="res://assets/test_chan/Test-Chan.fbx" id="1_lkeve"]
[ext_resource type="Texture2D" uid="uid://drjoya1j38i21" path="res://assets/ambientcg.com/Carpet003_1K-JPG_Color.jpg" id="1_pfl7p"]
Expand Down Expand Up @@ -36,6 +36,11 @@ outer_radius = 0.6
rings = 32
ring_segments = 8

[sub_resource type="SphereMesh" id="SphereMesh_tw3o4"]
material = SubResource("StandardMaterial3D_ahrhg")
radius = 0.05
height = 0.2

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xhsxi"]
bg_color = Color(0, 0, 0, 0.498039)

Expand Down Expand Up @@ -118,6 +123,10 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
mesh = SubResource("TorusMesh_c2425")
skeleton = NodePath("")

[node name="Forward" type="MeshInstance3D" parent="Chan/XRBodyModifier3D/GroundRing"]
transform = Transform3D(1, -8.74228e-08, -8.74228e-08, 8.74228e-08, -4.37114e-08, 1, -8.74228e-08, -1, -4.37114e-08, -5.96046e-08, 0, -0.6)
mesh = SubResource("SphereMesh_tw3o4")

[node name="Kun" type="Node3D" parent="."]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0.6, 0, 0)

Expand Down Expand Up @@ -178,6 +187,10 @@ transform = Transform3D(1, 0, -1.74846e-07, 0, 1, 0, 1.74846e-07, 0, 1, 0, 0.05,
mesh = SubResource("TorusMesh_c2425")
skeleton = NodePath("")

[node name="Forward" type="MeshInstance3D" parent="Kun/XRBodyModifier3D/GroundRing"]
transform = Transform3D(1, -8.74228e-08, -8.74228e-08, 8.74228e-08, -4.37114e-08, 1, -8.74228e-08, -1, -4.37114e-08, -5.96046e-08, 0, -0.6)
mesh = SubResource("SphereMesh_tw3o4")

[node name="PanelContainer" type="PanelContainer" parent="."]
anchors_preset = 3
anchor_left = 1.0
Expand Down

0 comments on commit bff01aa

Please sign in to comment.