Skip to content

Commit

Permalink
fix(server_openvr): 🐛 Fix invalid hand skeleton root
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Sep 8, 2024
1 parent 87c32f5 commit 33f4e88
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
41 changes: 23 additions & 18 deletions alvr/server_openvr/cpp/alvr_server/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ Controller::Controller(uint64_t deviceID, vr::EVRSkeletalTrackingLevel skeletonL
m_pose.qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0);
m_pose.qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0);
m_pose.qRotation = HmdQuaternion_Init(1, 0, 0, 0);

m_tempHandBones[0].orientation.w = 1;
m_tempHandBones[0].orientation.x = 0;
m_tempHandBones[0].orientation.y = 0;
m_tempHandBones[0].orientation.z = 0;
m_tempHandBones[0].position.v[0] = 0;
m_tempHandBones[0].position.v[1] = 0;
m_tempHandBones[0].position.v[2] = 0;
m_tempHandBones[0].position.v[3] = 1;
}

//
Expand Down Expand Up @@ -305,30 +314,28 @@ bool Controller::onPoseUpdate(float predictionS, FfiHandData handData) {
if (!enabled) {
return false;
} else if (handSkeleton != nullptr) {
vr::VRBoneTransform_t boneTransform[SKELETON_BONE_COUNT] = {};

// NB: start from index 1 to skip the root bone
for (int j = 1; j < 31; j++) {
boneTransform[j].orientation.w = handSkeleton->jointRotations[j].w;
boneTransform[j].orientation.x = handSkeleton->jointRotations[j].x;
boneTransform[j].orientation.y = handSkeleton->jointRotations[j].y;
boneTransform[j].orientation.z = handSkeleton->jointRotations[j].z;
boneTransform[j].position.v[0] = handSkeleton->jointPositions[j][0];
boneTransform[j].position.v[1] = handSkeleton->jointPositions[j][1];
boneTransform[j].position.v[2] = handSkeleton->jointPositions[j][2];
boneTransform[j].position.v[3] = 1.0;
m_tempHandBones[j].orientation.w = handSkeleton->jointRotations[j].w;
m_tempHandBones[j].orientation.x = handSkeleton->jointRotations[j].x;
m_tempHandBones[j].orientation.y = handSkeleton->jointRotations[j].y;
m_tempHandBones[j].orientation.z = handSkeleton->jointRotations[j].z;
m_tempHandBones[j].position.v[0] = handSkeleton->jointPositions[j][0];
m_tempHandBones[j].position.v[1] = handSkeleton->jointPositions[j][1];
m_tempHandBones[j].position.v[2] = handSkeleton->jointPositions[j][2];
m_tempHandBones[j].position.v[3] = 1.0;
}

vr_driver_input->UpdateSkeletonComponent(
m_compSkeleton,
vr::VRSkeletalMotionRange_WithController,
boneTransform,
m_tempHandBones,
SKELETON_BONE_COUNT
);
vr_driver_input->UpdateSkeletonComponent(
m_compSkeleton,
vr::VRSkeletalMotionRange_WithoutController,
boneTransform,
m_tempHandBones,
SKELETON_BONE_COUNT
);

Expand Down Expand Up @@ -413,32 +420,30 @@ bool Controller::onPoseUpdate(float predictionS, FfiHandData handData) {
);
}

vr::VRBoneTransform_t boneTransforms[SKELETON_BONE_COUNT];

// Perform whatever logic is necessary to convert your device's input into a
// skeletal pose, first to create a pose "With Controller", that is as close to the
// pose of the user's real hand as possible
GetBoneTransform(true, boneTransforms);
GetBoneTransform(true, m_tempHandBones);

// Then update the WithController pose on the component with those transforms
vr::EVRInputError err = vr_driver_input->UpdateSkeletonComponent(
m_compSkeleton,
vr::VRSkeletalMotionRange_WithController,
boneTransforms,
m_tempHandBones,
SKELETON_BONE_COUNT
);
if (err != vr::VRInputError_None) {
// Handle failure case
Error("UpdateSkeletonComponentfailed. Error: %i\n", err);
}

GetBoneTransform(false, boneTransforms);
GetBoneTransform(false, m_tempHandBones);

// Then update the WithoutController pose on the component
err = vr_driver_input->UpdateSkeletonComponent(
m_compSkeleton,
vr::VRSkeletalMotionRange_WithoutController,
boneTransforms,
m_tempHandBones,
SKELETON_BONE_COUNT
);
if (err != vr::VRInputError_None) {
Expand Down
1 change: 1 addition & 0 deletions alvr/server_openvr/cpp/alvr_server/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Controller : public TrackedDevice, public vr::ITrackedDeviceServerDriver {
vr::EVRSkeletalTrackingLevel m_skeletonLevel;

vr::DriverPose_t m_pose;
vr::VRBoneTransform_t m_tempHandBones[SKELETON_BONE_COUNT];

// These variables are used for controller hand animation
// todo: move to rust
Expand Down

0 comments on commit 33f4e88

Please sign in to comment.