Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to handle SkeletonModifier3D / XRTracker changes #3

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# 1.1.0
- Updated for changes to XR Tracker names and hierarchy

# 1.0.0
- Initial Revision
2 changes: 1 addition & 1 deletion addons/godot_rpm_avatar/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="Godot ReadyPlayerMe Avatar"
description="Godot ReadyPlayerMe Avatar plugin"
author="Malcolm Nixon and Contributors"
version="1.0.0"
version="1.1.0"
script="plugin.gd"
16 changes: 9 additions & 7 deletions addons/godot_rpm_avatar/rpm_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,27 @@ func _load_gltf(
# Retarget the skeleton to Godot Humanoid
RpmBody.retarget(skeleton)

# Construct the XRBodyModifier3D
var body_modifier := XRBodyModifier3D.new()
body_modifier.add_child(scene)
# Construct the XRNode3D (root)
var xr_node := XRNode3D.new()
xr_node.tracker = settings.body_tracker
xr_node.add_child(scene)

# Configure the XRBodyModifier3D
# Construct the XRBodyModifier3D (under skeleton)
var body_modifier := XRBodyModifier3D.new()
skeleton.add_child(body_modifier)
body_modifier.body_tracker = settings.body_tracker
body_modifier.target = body_modifier.get_path_to(skeleton)
body_modifier.bone_update = XRBodyModifier3D.BONE_UPDATE_ROTATION_ONLY

# Construct and append the XRFaceModifier3D
if settings.face_tracker != "":
var face_modifier := XRFaceModifier3D.new()
body_modifier.add_child(face_modifier)
xr_node.add_child(face_modifier)
face_modifier.face_tracker = settings.face_tracker
face_modifier.target = face_modifier.get_path_to(mesh)

# Report the load completed
print_verbose("RpmLoader: loaded - id=", id)
_load_complete.call_deferred(id, body_modifier)
_load_complete.call_deferred(id, xr_node)


# Report load complete
Expand Down
3 changes: 3 additions & 0 deletions addons/godot_vmc_tracker/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
25 changes: 19 additions & 6 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 @@ -214,12 +216,23 @@ 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)
_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 = "/mvn/head"
@export var face_tracker_name : String = "/vmc/face_tracker"

## Body tracker name
@export var body_tracker_name : String = "/mvn/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
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/rpm_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions load_test.tscn
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[gd_scene load_steps=7 format=3 uid="uid://cq8p13kfy4cuf"]
[gd_scene load_steps=7 format=4 uid="uid://cq8p13kfy4cuf"]

[ext_resource type="Script" path="res://load_test.gd" id="1_ha8ec"]
[ext_resource type="Script" path="res://addons/godot_rpm_avatar/rpm_settings.gd" id="2_fq1tk"]

[sub_resource type="Resource" id="Resource_haakg"]
script = ExtResource("2_fq1tk")
body_tracker = "/vmc/body"
face_tracker = "/vmc/head"
body_tracker = "/vmc/body_tracker"
face_tracker = "/vmc/face_tracker"
quality = 1

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_mxfgc"]
Expand Down
Loading