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 102891d commit 3201fd6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 9 additions & 4 deletions addons/godot_vmc_tracker/vmc_source.gd
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,15 @@ func _process_joints() -> 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://dkkew3u3hi7md"]
[gd_scene load_steps=14 format=3 uid="uid://dkkew3u3hi7md"]

[ext_resource type="Script" path="res://demo.gd" id="1_7k4ei"]
[ext_resource type="PackedScene" uid="uid://bhc6nngwjdvum" path="res://assets/test_chan/Test-Chan.fbx" id="1_lkeve"]
Expand Down Expand Up @@ -35,6 +35,11 @@ outer_radius = 0.6
rings = 32
ring_segments = 8

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

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

Expand Down Expand Up @@ -119,6 +124,10 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
mesh = SubResource("TorusMesh_rbtmk")
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_t4i7x")

[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 @@ -181,6 +190,10 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
mesh = SubResource("TorusMesh_rbtmk")
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_t4i7x")

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

0 comments on commit 3201fd6

Please sign in to comment.