Skip to content

Commit

Permalink
Update to handle SkeletonModifier3D / XRTracker changes (#6)
Browse files Browse the repository at this point in the history
* Changes to work with SkeletonModifier3D and the root motion patch.
* Updates for SkeletonModifier3D/XRTracker changes.
* Update readme
* Cleanup gdlint issues.
  • Loading branch information
Malcolmnixon authored Apr 22, 2024
1 parent 3201fd6 commit 9014988
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 41 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Official releases are tagged and can be found [here](https://github.com/Malcolmn
The following branches are in active development:
| Branch | Description | Godot version |
|-----------|-------------------------------|------------------|
| master | Current development branch | Godot 4.3-dev4+ |
| master | Current development branch | Godot 4.3-dev6+ |

<sub>NOTE: This requires the [XR Trackers](https://github.com/godotengine/godot/pull/90645) PR which is in the Godot master branch, but no release has been made.</sub>

## Overview

Expand Down Expand Up @@ -54,7 +56,11 @@ The character model must be in Godot Humanoid format. This can be achieved in th

### Body Driving

The body is driven using an [XRBodyModifier3D](https://docs.godotengine.org/en/latest/classes/class_xrbodymodifier3d.html) node configured to drive the skeleton of the character:
The body is positioned using an [XRNode3D](https://docs.godotengine.org/en/latest/classes/class_xrnode3d.html) node configured to track the character body:

![XRNode3D](/docs/xrnode3d.png)

The body is posed using an [XRBodyModifier3D](https://docs.godotengine.org/en/latest/classes/class_xrbodymodifier3d.html) node skeleton modifier:

![XRBodyModifier3D](/docs/xrbodymodifier3d.png)

Expand Down
3 changes: 3 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.2.0
- Updated for changes to XR Tracker names and hierarchy

# 1.1.0
- Set tracker "Root" under hips
- Move avatars under body modifier
Expand Down
2 changes: 1 addition & 1 deletion addons/godot_vmc_tracker/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="Godot VMC Tracker"
description="Godot VMC Tracker plugin"
author="Malcolm Nixon and Contributors"
version="1.0.0"
version="1.2.0"
script="plugin.gd"
4 changes: 2 additions & 2 deletions addons/godot_vmc_tracker/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func _enter_tree():
TYPE_STRING,
PROPERTY_HINT_NONE,
"",
"/vmc/head")
"/vmc/face_tracker")

# Add body tracker name
_define_project_setting(
"godot_vmc_tracker/tracking/body_tracker_name",
TYPE_STRING,
PROPERTY_HINT_NONE,
"",
"/vmc/body")
"/vmc/body_tracker")

# Add position mode
_define_project_setting(
Expand Down
4 changes: 2 additions & 2 deletions addons/godot_vmc_tracker/vmc_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func _enter_tree() -> void:
# Get the face tracker name
var face_tracker_name : String = ProjectSettings.get_setting(
"godot_vmc_tracker/tracking/face_tracker_name",
"/vmc/head")
"/vmc/face_tracker")

# Get the body tracker name
var body_tracker_name : String = ProjectSettings.get_setting(
"godot_vmc_tracker/tracking/body_tracker_name",
"/vmc/body")
"/vmc/body_tracker")

# Get the position mode
var position_mode = ProjectSettings.get_setting(
Expand Down
12 changes: 10 additions & 2 deletions addons/godot_vmc_tracker/vmc_source.gd
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ func _init(
_face_blends.fill(0.0)

# Register the face tracker
XRServer.add_face_tracker(face_tracker_name, _face_tracker)
_face_tracker.name = face_tracker_name
XRServer.add_tracker(_face_tracker)

# Register the body tracker
XRServer.add_body_tracker(body_tracker_name, _body_tracker)
_body_tracker.name = body_tracker_name
XRServer.add_tracker(_body_tracker)

# Save the position mode
_position_mode = position_mode
Expand Down Expand Up @@ -225,6 +227,12 @@ func _process_joints() -> void:
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)
_body_tracker.set_pose(
"default",
root,
Vector3.ZERO,
Vector3.ZERO,
XRPose.XR_TRACKING_CONFIDENCE_HIGH);

# Indicate we are tracking the body
_body_tracker.body_flags = BODY_TRACKING
Expand Down
4 changes: 2 additions & 2 deletions addons/godot_vmc_tracker/vmc_tracker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ extends Node


## Face tracker name
@export var face_tracker_name : String = "/vmc/head"
@export var face_tracker_name : String = "/vmc/face_tracker"

## Body tracker name
@export var body_tracker_name : String = "/vmc/body"
@export var body_tracker_name : String = "/vmc/body_tracker"

## Position mode
@export_enum("Free", "Calibrate", "Locked") var position_mode : int = 0
Expand Down
2 changes: 1 addition & 1 deletion addons/godot_vmc_tracker/vmc_tracker.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=2 format=3 uid="uid://dvnmxtkucajqw"]
[gd_scene load_steps=2 format=4 uid="uid://dvnmxtkucajqw"]

[ext_resource type="Script" path="res://addons/godot_vmc_tracker/vmc_tracker.gd" id="1_w1cjd"]

Expand Down
4 changes: 2 additions & 2 deletions demo.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func _input(event : InputEvent) -> void:


func _on_skeleton_spin_box_value_changed(value: float) -> void:
%"Test-Chan/Armature/Skeleton3D".motion_scale = value
%"Test-Kun/Armature/Skeleton3D".motion_scale = value
$"Chan/ChanAvatar/Test-Chan/Armature/Skeleton3D".motion_scale = value
$"Kun/KunAvatar/Test-Kun/Armature/Skeleton3D".motion_scale = value


func _on_world_spin_box_value_changed(value: float) -> void:
Expand Down
56 changes: 29 additions & 27 deletions demo.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=3 uid="uid://dkkew3u3hi7md"]
[gd_scene load_steps=14 format=4 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 @@ -65,18 +65,12 @@ transform = Transform3D(0.939693, 0.0593911, -0.336824, 0, 0.984808, 0.173648, 0
[node name="Chan" type="Node3D" parent="."]
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, -0.6, 0, 0)

[node name="XRFaceModifier3D" type="XRFaceModifier3D" parent="Chan"]
face_tracker = &"/vmc/head"
target = NodePath("../XRBodyModifier3D/Test-Chan/Armature/Skeleton3D/Body")
[node name="ChanAvatar" type="XRNode3D" parent="Chan"]
tracker = &"/vmc/body_tracker"

[node name="XRBodyModifier3D" type="XRBodyModifier3D" parent="Chan"]
body_tracker = &"/vmc/body"
target = NodePath("Test-Chan/Armature/Skeleton3D")
[node name="Test-Chan" parent="Chan/ChanAvatar" instance=ExtResource("1_lkeve")]

[node name="Test-Chan" parent="Chan/XRBodyModifier3D" instance=ExtResource("1_lkeve")]
unique_name_in_owner = true

[node name="Body" parent="Chan/XRBodyModifier3D/Test-Chan/Armature/Skeleton3D" index="0"]
[node name="Body" parent="Chan/ChanAvatar/Test-Chan/Armature/Skeleton3D" index="0"]
blend_shapes/Cheek_Puff_Left = 1.28996e-05
blend_shapes/Cheek_Puff_Right = 1.28996e-05
blend_shapes/Eye_Left_Left = 0.297788
Expand Down Expand Up @@ -119,30 +113,31 @@ blend_shapes/mouthPressRight = 0.0310566
blend_shapes/mouthStretchLeft = 0.0145674
blend_shapes/mouthStretchRight = 0.00253638

[node name="GroundRing" type="MeshInstance3D" parent="Chan/XRBodyModifier3D"]
[node name="XRBodyModifier3D" type="XRBodyModifier3D" parent="Chan/ChanAvatar/Test-Chan/Armature/Skeleton3D" index="2"]
body_tracker = &"/vmc/body_tracker"

[node name="XRFaceModifier3D" type="XRFaceModifier3D" parent="Chan/ChanAvatar"]
face_tracker = &"/vmc/face_tracker"
target = NodePath("../Test-Chan/Armature/Skeleton3D/Body")

[node name="GroundRing" type="MeshInstance3D" parent="Chan/ChanAvatar"]
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"]
[node name="Forward" type="MeshInstance3D" parent="Chan/ChanAvatar/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)

[node name="XRFaceModifier3D" type="XRFaceModifier3D" parent="Kun"]
face_tracker = &"/vmc/head"
target = NodePath("../XRBodyModifier3D/Test-Kun/Armature/Skeleton3D/Body")
[node name="KunAvatar" type="XRNode3D" parent="Kun"]
tracker = &"/vmc/body_tracker"

[node name="XRBodyModifier3D" type="XRBodyModifier3D" parent="Kun"]
body_tracker = &"/vmc/body"
target = NodePath("Test-Kun/Armature/Skeleton3D")
[node name="Test-Kun" parent="Kun/KunAvatar" instance=ExtResource("2_67k0v")]

[node name="Test-Kun" parent="Kun/XRBodyModifier3D" instance=ExtResource("2_67k0v")]
unique_name_in_owner = true

[node name="Body" parent="Kun/XRBodyModifier3D/Test-Kun/Armature/Skeleton3D" index="0"]
[node name="Body" parent="Kun/KunAvatar/Test-Kun/Armature/Skeleton3D" index="0"]
blend_shapes/Cheek_Puff_Left = 1.28996e-05
blend_shapes/Cheek_Puff_Right = 1.28996e-05
blend_shapes/Eye_Left_Left = 0.297788
Expand Down Expand Up @@ -185,12 +180,19 @@ blend_shapes/mouthPressRight = 0.0310566
blend_shapes/mouthStretchLeft = 0.0145674
blend_shapes/mouthStretchRight = 0.00253638

[node name="GroundRing" type="MeshInstance3D" parent="Kun/XRBodyModifier3D"]
[node name="XRBodyModifier3D" type="XRBodyModifier3D" parent="Kun/KunAvatar/Test-Kun/Armature/Skeleton3D" index="2"]
body_tracker = &"/vmc/body_tracker"

[node name="XRFaceModifier3D" type="XRFaceModifier3D" parent="Kun/KunAvatar"]
face_tracker = &"/vmc/face_tracker"
target = NodePath("../Test-Kun/Armature/Skeleton3D/Body")

[node name="GroundRing" type="MeshInstance3D" parent="Kun/KunAvatar"]
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"]
[node name="Forward" type="MeshInstance3D" parent="Kun/KunAvatar/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")

Expand Down Expand Up @@ -262,5 +264,5 @@ value = 1.0
[connection signal="value_changed" from="PanelContainer/MarginContainer/HBoxContainer/GridContainer/SkeletonSpinBox" to="." method="_on_skeleton_spin_box_value_changed"]
[connection signal="value_changed" from="PanelContainer/MarginContainer/HBoxContainer/GridContainer/WorldSpinBox" to="." method="_on_world_spin_box_value_changed"]

[editable path="Chan/XRBodyModifier3D/Test-Chan"]
[editable path="Kun/XRBodyModifier3D/Test-Kun"]
[editable path="Chan/ChanAvatar/Test-Chan"]
[editable path="Kun/KunAvatar/Test-Kun"]
Binary file modified docs/enable_plugin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/plugin_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/xrbodymodifier3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/xrfacemodifier3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/xrnode3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9014988

Please sign in to comment.