diff --git a/addons/godot_axis_studio_tracker/axis_studio_source.gd b/addons/godot_axis_studio_tracker/axis_studio_source.gd index 5ca0800..2318929 100644 --- a/addons/godot_axis_studio_tracker/axis_studio_source.gd +++ b/addons/godot_axis_studio_tracker/axis_studio_source.gd @@ -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 @@ -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) diff --git a/demo.tscn b/demo.tscn index a861542..396124e 100644 --- a/demo.tscn +++ b/demo.tscn @@ -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"] @@ -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) @@ -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) @@ -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