Appendix B: 3D Body Pose Keypoint Format#

Legacy 3D Body Pose Tracking: 34-Keypoint Format#

The legacy 3D Body Pose Tracking feature uses 34 keypoints: pelvis, left hip, right hip, torso, left knee, right knee, neck, left ankle, right ankle, left big toe, right big toe, left small toe, right small toe, left heel, right heel, nose, left eye, right eye, left ear, right ear, left shoulder, right shoulder, left elbow, right elbow, left wrist, right wrist, left pinky knuckle, right pinky knuckle, left middle tip, right middle tip, left index knuckle, right index knuckle, left thumb tip, right thumb tip.

Here is the list of skeletal structures:

Keypoint

Parent

Pelvis

None, as this is root.

Left hip

Pelvis

Right hip

Pelvis

Torso

Pelvis

Left knee

Left hip

Right knee

Right hip

Neck

Torso

Left ankle

Left knee

Right ankle

Right knee

Left big toe

Left ankle

Right big toe

Right ankle

Left small toe

Left ankle

Right small toe

Right ankle

Left heel

Left ankle

Right heel

Right ankle

Nose

Neck

Left eye

Nose

Right eye

Nose

Left ear

Nose

Right ear

Nose

Left shoulder

Neck

Right shoulder

Neck

Left elbow

Left shoulder

Right elbow

Right shoulder

Left wrist

Left elbow

Right wrist

Right elbow

Left pinky knuckle

Left wrist

Right pinky knuckle

Right wrist

Left middle tip

Left wrist

Right middle tip

Right wrist

Left index knuckle

Left wrist

Right index knuckle

Right wrist

Left thumb tip

Left wrist

Right thumb tip

Right wrist

NvAR_Parameter_Output KeyPoints Order#

In the macros NvAR_Parameter_Output(KeyPoints) and NvAR_Parameter_Output(KeyPoints3D), the order of the keypoints is the same as listed in Legacy 3D Body Pose Tracking: 34-Keypoint Format.

3D Body Pose Estimation SOMA-77 Format#

3D Body Pose Estimation uses the SOMA-77 public skeleton. Before you allocate output buffers, query NvAR_Parameter_Config(NumKeyPoints) to get the keypoint count.

The underlying full-body SOMA skeleton has 78 joints, including an internal virtual Root joint at index 0. The AR SDK exposes the 77 user-facing joints and omits the virtual Root joint. Output keypoint and pose index k maps to internal SOMA joint k + 1, so output index 0 is the Hips joint.

The public SOMA-X rig assets are available from NVIDIA’s SOMA-X Hugging Face repository. That repository includes the standard rig definition and related assets, including SOMA_template_rig.usda, SOMA_neutral.npz, SOMA_procedural_transforms.json, and correctives_model.pt.

RestPose and T-Pose Bases#

3D Body Pose Estimation reports animation outputs in two related bases. A basis is the joint-frame convention used by local animation data: the frame in which each parent-to-child rest offset is expressed, and the frame that each local joint rotation is relative to. It is not a camera or world coordinate system, and it is not one global rotation that can be applied independently to every accumulated joint point.

  • The direct-rest basis is the SDK’s native output basis. For joint j, the usable local rest offset is RestPose[j] - RestPose[parent(j)]. That offset is expressed in parent(j)’s direct-rest frame. JointRotations are local rotations in the same direct-rest hierarchy. Running forward kinematics over those local offsets and rotations reconstructs root-relative posed 3D points; applying RootPose places those points in camera coordinates.

  • The T-pose basis is the joint-frame convention used by the SOMA-X template rig’s visual T-pose. Rigs authored against a T-pose expect parent-to-child offsets and local rotations in this basis. To move from the SDK direct-rest basis to the T-pose basis, each local rest offset is rotated by the fixed SOMA-X parent T-pose-basis joint orientation, and each local rotation is converted with the corresponding parent and child SOMA-X T-pose-basis joint orientations.

The RestPose output uses cumulative direct-rest storage: joint 0 is at the origin, and each non-root joint stores its parent’s RestPose value plus that joint’s local rest offset in the parent direct-rest frame. Therefore, plotting RestPose directly does not produce the visual SOMA-X T-pose. Reconstructing T-Pose and Posed 3D Keypoints shows how to convert the direct-rest local offsets and rotations into the T-pose skeleton and T-pose-basis rotations.

The KeyPoints, KeyPoints3D, RestPose, JointRotations, and JointAngles outputs use the same body-major, keypoint-major layout:

body_index * NumKeyPoints + keypoint_index

KeyPoints uses full-image pixel coordinates. For 3D Body Pose Estimation, KeyPoints3D uses camera coordinates in meters. RestPose is in meters and uses the cumulative direct-rest representation. JointRotations are local XYZW quaternions in the same direct-rest basis. JointAngles is a compatibility alias for JointRotations. RootPose stores one root transform per body; RootPose.translation is in camera coordinates, in meters.

SOMA-77 Parent Indices#

The Hips keypoint has the parent -1. All other parent values are keypoint indices in the same output order.

index:  0  parent: -1
index:  1  parent:  0
index:  2  parent:  1
index:  3  parent:  2
index:  4  parent:  3
index:  5  parent:  4
index:  6  parent:  5
index:  7  parent:  6
index:  8  parent:  6
index:  9  parent:  6
index: 10  parent:  6
index: 11  parent:  3
index: 12  parent: 11
index: 13  parent: 12
index: 14  parent: 13
index: 15  parent: 14
index: 16  parent: 15
index: 17  parent: 16
index: 18  parent: 17
index: 19  parent: 14
index: 20  parent: 19
index: 21  parent: 20
index: 22  parent: 21
index: 23  parent: 22
index: 24  parent: 14
index: 25  parent: 24
index: 26  parent: 25
index: 27  parent: 26
index: 28  parent: 27
index: 29  parent: 14
index: 30  parent: 29
index: 31  parent: 30
index: 32  parent: 31
index: 33  parent: 32
index: 34  parent: 14
index: 35  parent: 34
index: 36  parent: 35
index: 37  parent: 36
index: 38  parent: 37
index: 39  parent:  3
index: 40  parent: 39
index: 41  parent: 40
index: 42  parent: 41
index: 43  parent: 42
index: 44  parent: 43
index: 45  parent: 44
index: 46  parent: 45
index: 47  parent: 42
index: 48  parent: 47
index: 49  parent: 48
index: 50  parent: 49
index: 51  parent: 50
index: 52  parent: 42
index: 53  parent: 52
index: 54  parent: 53
index: 55  parent: 54
index: 56  parent: 55
index: 57  parent: 42
index: 58  parent: 57
index: 59  parent: 58
index: 60  parent: 59
index: 61  parent: 60
index: 62  parent: 42
index: 63  parent: 62
index: 64  parent: 63
index: 65  parent: 64
index: 66  parent: 65
index: 67  parent:  0
index: 68  parent: 67
index: 69  parent: 68
index: 70  parent: 69
index: 71  parent: 70
index: 72  parent:  0
index: 73  parent: 72
index: 74  parent: 73
index: 75  parent: 74
index: 76  parent: 75

Reconstructing T-Pose and Posed 3D Keypoints#

The RestPose, JointRotations, and RootPose outputs are enough to reconstruct the emitted KeyPoints3D points for the SOMA-77 skeleton. You can also derive person-specific skeleton geometry in the T-pose basis that is useful for retargeting.

Use the output buffers from the same delayed output frame, after NvAR_Parameter_Output(Ready) becomes nonzero. The example uses these SDK outputs:

  • rest_pose_output is the buffer registered with NvAR_Parameter_Output(RestPose).

  • joint_rotations_output is the buffer registered with NvAR_Parameter_Output(JointRotations).

  • root_pose_output is the buffer registered with NvAR_Parameter_Output(RootPose).

KeyPoints3D is not an input to the reconstruction. Use it only to validate the reconstructed camera-space points.

The example derives these values:

  • t_pose_identity is the person-specific skeleton geometry in the T-pose basis. It is a root-relative SOMA-77 point set in meters, derived from RestPose and the SOMA-X T-pose-basis joint-orientation table.

  • t_pose_local_rotations are local joint rotations converted from JointRotations into the T-pose basis. Apply these rotations to a rig that uses t_pose_identity as its bind skeleton.

  • retarget_local is the posed root-relative SOMA-77 skeleton produced by running forward kinematics over t_pose_identity with t_pose_local_rotations.

  • retarget_in_camera is retarget_local after applying the T-pose-basis root rotation and RootPose.translation. It should match KeyPoints3D.

The retargeting reconstruction has three steps.

A1: Derive t_pose_identity from the rest pose. Use RestPose and the SOMA-X T-pose-basis joint-orientation table to derive a root-relative point set in meters. This step converts the SDK direct-rest local offsets into person-specific skeleton geometry in the T-pose basis. A retargeting rig can use t_pose_identity as its bind geometry.

"A1 t_pose_identity derived from RestPose"

A1: t_pose_identity derived from the rest pose.

A2: Reconstruct the posed skeleton in the T-pose basis. First convert JointRotations into t_pose_local_rotations, which are local pose rotations in the T-pose basis. Then run forward kinematics over A1’s t_pose_identity using t_pose_local_rotations. The result is retarget_local, a posed root-relative SOMA-77 skeleton in the T-pose basis. Use this output to drive a retargeted T-pose rig.

"A2 posed skeleton reconstructed locally in the T-pose basis"

A2: Posed skeleton reconstructed locally in the T-pose basis.

A3: Apply root placement. Apply the T-pose-basis root rotation and RootPose.translation to retarget_local. The result is retarget_in_camera, the retargeted pose in camera coordinates.

"A3 posed skeleton with the camera-space root translation and T-pose-basis root rotation applied"

A3: Posed skeleton with the camera-space root translation and T-pose-basis root rotation applied.

The following example keeps A1, A2, and A3 in one function because A2 reuses A1’s derived T-pose, and all three steps share the same skeleton mapping and math helpers. It also includes a direct reconstruction path that reconstructs KeyPoints3D through the SDK direct-rest basis for validation and debugging.

The code assumes these application-local math helpers exist: AddPoint, SubtractPoint, RotatePoint, RotatePointByMatrix3, NormalizeQuaternion, QuaternionMultiply, InvertQuaternion, and MatrixToQuaternion.

#include <cstddef>
#include <cstdint>
#include <vector>

constexpr std::uint32_t kNumKp = 77u;

static constexpr std::int32_t kSoma77Parents[kNumKp] = {
    -1, 0,  1,  2,  3,  4,  5,  6,  6,  6,  6,  3,  11, 12, 13, 14, 15, 16, 17, 14, 19, 20, 21, 22, 14, 24,
    25, 26, 27, 14, 29, 30, 31, 32, 14, 34, 35, 36, 37, 3,  39, 40, 41, 42, 43, 44, 45, 42, 47, 48, 49, 50,
    42, 52, 53, 54, 55, 42, 57, 58, 59, 60, 42, 62, 63, 64, 65, 0,  67, 68, 69, 70, 0,  72, 73, 74, 75};
static constexpr std::size_t kSomaInternalJointCount = kNumKp + 1u;
static constexpr std::size_t kSomaTPoseBasisJointOrientMatrixDim = 9u;

// Fixed row-major 3x3 T-pose-basis joint-orientation matrices for the internal SOMA skeleton.
// These constants match the SDK SOMA model joint orientations. Corresponding public SOMA-X rig assets are
// available at https://huggingface.co/nvidia/SOMA-X/tree/main.
// Public joint j maps to internal joint j + 1. Internal joint 0 is the virtual Root.
static const float kSomaTPoseBasisJointOrient[kSomaInternalJointCount * kSomaTPoseBasisJointOrientMatrixDim] = {
       1.0000000000e+00f,  0.0000000000e+00f,  0.0000000000e+00f,  0.0000000000e+00f,  1.0000000000e+00f,
       0.0000000000e+00f,  0.0000000000e+00f,  0.0000000000e+00f,  1.0000000000e+00f,  3.2073343981e-10f,
       1.6653345369e-16f,  1.0000000000e+00f,  9.9999445677e-01f,  3.3239081968e-03f,  -3.2073166345e-10f,
       -3.3239081968e-03f, 9.9999445677e-01f,  1.0660361482e-12f,  -2.5863775122e-08f, -5.2050825872e-08f,
       1.0000000000e+00f,  9.9999123812e-01f,  4.1855261661e-03f,  2.6081409032e-08f,  -4.1855261661e-03f,
       9.9999123812e-01f,  5.1942116386e-08f,  -7.5423216117e-08f, -5.4443827224e-08f, 1.0000000000e+00f,
       9.9421060085e-01f,  1.0744910687e-01f,  8.0836500160e-08f,  -1.0744910687e-01f, 9.9421060085e-01f,
       4.6024471345e-08f,  -1.7273029584e-07f, -4.6310127289e-08f, 1.0000000000e+00f,  9.9999374151e-01f,
       3.5373084247e-03f,  1.7289302434e-07f,  -3.5373084247e-03f, 9.9999374151e-01f,  4.5698836715e-08f,
       -3.5810501231e-07f, 6.2969554904e-08f,  1.0000000000e+00f,  9.5817577839e-01f,  -2.8618034720e-01f,
       3.6114818158e-07f,  2.8618034720e-01f,  9.5817577839e-01f,  4.2146709234e-08f,  -7.2769233839e-07f,
       6.9529072277e-08f,  1.0000000000e+00f,  9.5276397467e-01f,  -3.0371171236e-01f, 7.1443582783e-07f,
       3.0371171236e-01f,  9.5276397467e-01f,  1.5476389592e-07f,  -1.4150831475e-06f, -5.9895546656e-07f,
       1.0000000000e+00f,  9.9307656288e-01f,  1.1746867001e-01f,  1.4756444671e-06f,  -1.1746867001e-01f,
       9.9307656288e-01f,  4.2858070515e-07f,  -7.9456022206e-08f, -8.5877069012e-08f, 1.0000000000e+00f,
       9.9307656288e-01f,  1.1746867001e-01f,  8.8993779457e-08f,  -1.1746867001e-01f, 9.9307656288e-01f,
       7.5948918266e-08f,  -2.8270396797e-06f, -5.9895546656e-07f, 1.0000000000e+00f,  9.9307656288e-01f,
       1.1746867001e-01f,  2.8778254091e-06f,  -1.1746867001e-01f, 9.9307656288e-01f,  2.6272005016e-07f,
       4.4457851909e-03f,  6.6037088633e-02f,  9.9780726433e-01f,  9.9773859978e-01f,  -6.7214086652e-02f,
       2.8974004636e-06f,  6.7066892982e-02f,  9.9555081129e-01f,  -6.6186569631e-02f, -4.4516143389e-03f,
       -6.6037207842e-02f, 9.9780720472e-01f,  9.9773854017e-01f,  -6.7214466631e-02f, 2.8974004636e-06f,
       6.7066892982e-02f,  9.9555075169e-01f,  6.6187083721e-02f,  9.3822997808e-01f,  3.4601223469e-01f,
       -3.4477467619e-16f, -4.3630720053e-16f, 3.8786763620e-17f,  -1.0000000000e+00f, -3.4601223469e-01f,
       9.3822997808e-01f,  1.8670427278e-16f,  1.0000000000e+00f,  9.0094777988e-05f,  -3.4477467619e-16f,
       -3.9595269803e-16f, 1.8732287153e-16f,  -1.0000000000e+00f, -9.0094777988e-05f, 1.0000000000e+00f,
       1.8670427278e-16f,  1.0000000000e+00f,  -9.6392890555e-05f, -3.4477467619e-16f, -3.9591775793e-16f,
       1.8739670898e-16f,  -1.0000000000e+00f, 9.6392890555e-05f,  1.0000000000e+00f,  1.8670427278e-16f,
       1.0000000000e+00f,  -1.0125053086e-04f, 5.2388550102e-05f,  3.4557331674e-05f,  -1.6869449615e-01f,
       -9.8566836119e-01f, 1.0863710486e-04f,  9.8566836119e-01f,  -1.6869449615e-01f, 8.5283172131e-01f,
       -4.9016791582e-01f, 1.8003733456e-01f,  -3.8852432370e-01f, -8.2598888874e-01f, -4.0840080380e-01f,
       3.4889379144e-01f,  2.7834826708e-01f,  -8.9487171173e-01f, 1.0000000000e+00f,  5.5511151231e-16f,
       2.4240717877e-08f,  5.1347814889e-16f,  -1.0000000000e+00f, -3.3306690739e-16f, 2.4240717877e-08f,
       4.9960036108e-16f,  -1.0000000000e+00f, 1.0000000000e+00f,  5.5511151231e-16f,  2.4240717877e-08f,
       5.1347814889e-16f,  -1.0000000000e+00f, -3.3306690739e-16f, 2.4240717877e-08f,  4.9960036108e-16f,
       -1.0000000000e+00f, 1.0000000000e+00f,  5.5511151231e-16f,  2.4240717877e-08f,  5.1347814889e-16f,
       -1.0000000000e+00f, -3.3306690739e-16f, 2.4240717877e-08f,  4.9960036108e-16f,  -1.0000000000e+00f,
       9.9960470200e-01f,  -2.7482686564e-02f, 5.9245699085e-03f,  1.8942133756e-03f,  -1.4441768825e-01f,
       -9.8951500654e-01f, 2.8050143272e-02f,  9.8913508654e-01f,  -1.4430855215e-01f, 1.0000000000e+00f,
       -2.1739474221e-08f, 8.6736173799e-19f,  -5.2041704279e-17f, -2.7755575616e-16f, -1.0000000000e+00f,
       2.1739474221e-08f,  1.0000000000e+00f,  -3.0531133177e-16f, 1.0000000000e+00f,  -2.1739474221e-08f,
       8.6736173799e-19f,  -5.2041704279e-17f, -2.7755575616e-16f, -1.0000000000e+00f, 2.1739474221e-08f,
       1.0000000000e+00f,  -3.0531133177e-16f, 9.9703454971e-01f,  4.3452162296e-02f,  -6.3514046371e-02f,
       -6.5227262676e-02f, 3.9215739816e-02f,  -9.9709957838e-01f, -4.0835380554e-02f, 9.9828553200e-01f,
       4.1933711618e-02f,  9.9703454971e-01f,  4.3452162296e-02f,  -6.3514046371e-02f, -6.5227262676e-02f,
       3.9215739816e-02f,  -9.9709957838e-01f, -4.0835380554e-02f, 9.9828553200e-01f,  4.1933711618e-02f,
       9.8629713058e-01f,  1.5425087512e-01f,  -5.8520063758e-02f, -4.1307274252e-02f, -1.1252379417e-01f,
       -9.9279004335e-01f, -1.5972362459e-01f, 9.8160332441e-01f,  -1.0461021215e-01f, 1.0000000000e+00f,
       -2.3722368070e-08f, 4.1633363423e-17f,  -4.1633363423e-17f, -1.5265566589e-16f, -1.0000000000e+00f,
       2.3722368070e-08f,  1.0000000000e+00f,  -1.9428902931e-16f, 1.0000000000e+00f,  -2.3722368070e-08f,
       4.1633363423e-17f,  -4.1633363423e-17f, -1.5265566589e-16f, -1.0000000000e+00f, 2.3722368070e-08f,
       1.0000000000e+00f,  -1.9428902931e-16f, 9.9183505774e-01f,  2.1237600595e-02f,  -1.2574636936e-01f,
       -1.2679313123e-01f, 5.8578822762e-02f,  -9.9019795656e-01f, -1.3663354330e-02f, 9.9805682898e-01f,
       6.0793314129e-02f,  9.9183505774e-01f,  2.1237600595e-02f,  -1.2574636936e-01f, -1.2679313123e-01f,
       5.8578822762e-02f,  -9.9019795656e-01f, -1.3663354330e-02f, 9.9805682898e-01f,  6.0793314129e-02f,
       9.7038769722e-01f,  2.1955496073e-01f,  -1.0071407259e-01f, -8.0587044358e-02f, -9.8797477782e-02f,
       -9.9183911085e-01f, -2.2771349549e-01f, 9.7058469057e-01f,  -7.8178569674e-02f, 1.0000000000e+00f,
       -2.3967489327e-08f, -1.3877787808e-17f, -5.5511151231e-17f, -9.7144514655e-17f, -1.0000000000e+00f,
       2.3967489327e-08f,  1.0000000000e+00f,  -1.3877787808e-16f, 1.0000000000e+00f,  -2.3967489327e-08f,
       -1.3877787808e-17f, -5.5511151231e-17f, -9.7144514655e-17f, -1.0000000000e+00f, 2.3967489327e-08f,
       1.0000000000e+00f,  -1.3877787808e-16f, 9.9919605255e-01f,  7.9067231854e-04f,  4.0083222091e-02f,
       4.0091000497e-02f,  -1.8781829625e-02f, -9.9901950359e-01f, -3.7060817704e-05f, 9.9982327223e-01f,
       -1.8798429519e-02f, 9.9919605255e-01f,  7.9067231854e-04f,  4.0083222091e-02f,  4.0091000497e-02f,
       -1.8781829625e-02f, -9.9901950359e-01f, -3.7060817704e-05f, 9.9982327223e-01f,  -1.8798429519e-02f,
       9.1683477163e-01f,  3.1319043040e-01f,  -2.4764028192e-01f, -2.3987418413e-01f, -6.3751161098e-02f,
       -9.6870851517e-01f, -3.1917759776e-01f, 9.4754815102e-01f,  1.6677020118e-02f,  1.0000000000e+00f,
       -2.3872162913e-08f, 8.3266726847e-17f,  -2.7755575616e-17f, -1.9775847626e-16f, -1.0000000000e+00f,
       2.3872162913e-08f,  1.0000000000e+00f,  -2.6714741530e-16f, 1.0000000000e+00f,  -2.3872162913e-08f,
       8.3266726847e-17f,  -2.7755575616e-17f, -1.9775847626e-16f, -1.0000000000e+00f, 2.3872162913e-08f,
       1.0000000000e+00f,  -2.6714741530e-16f, 9.9629634619e-01f,  -2.6847388595e-02f, -8.1687375903e-02f,
       -8.0836147070e-02f, 3.1395409256e-02f,  -9.9623280764e-01f, 2.9310859740e-02f,  9.9914640188e-01f,
       2.9108893126e-02f,  9.9629634619e-01f,  -2.6847388595e-02f, -8.1687375903e-02f, -8.0836147070e-02f,
       3.1395409256e-02f,  -9.9623280764e-01f, 2.9310859740e-02f,  9.9914640188e-01f,  2.9108893126e-02f,
       9.3822997808e-01f,  3.4601223469e-01f,  3.4477467619e-16f,  -2.0335961397e-16f, -5.4376201197e-16f,
       1.0000000000e+00f,  3.4601223469e-01f,  -9.3822997808e-01f, -4.6426002894e-16f, 1.0000000000e+00f,
       9.0240624559e-05f,  3.4477467619e-16f,  -3.7890671584e-16f, -4.3984308663e-16f, 1.0000000000e+00f,
       9.0240624559e-05f,  -1.0000000000e+00f, -4.6426002894e-16f, 1.0000000000e+00f,  -9.6549476439e-05f,
       3.4477467619e-16f,  -3.7898885156e-16f, -4.3977230643e-16f, 1.0000000000e+00f,  -9.6549476439e-05f,
       -1.0000000000e+00f, -4.6426002894e-16f, 1.0000000000e+00f,  -1.0125053086e-04f, 5.2388550102e-05f,
       -3.4557331674e-05f, 1.6869449615e-01f,  9.8566836119e-01f,  -1.0863710486e-04f, -9.8566836119e-01f,
       1.6869449615e-01f,  8.5284388065e-01f,  -4.9015244842e-01f, 1.8002195656e-01f,  3.8852506876e-01f,
       8.2600259781e-01f,  4.0837234259e-01f,  -3.4886330366e-01f, -2.7833479643e-01f, 8.9488774538e-01f,
       1.0000000000e+00f,  1.3877787808e-16f,  -2.4239820817e-08f, -1.3877787808e-17f, 1.0000000000e+00f,
       3.3306690739e-16f,  2.4239820817e-08f,  -1.6653345369e-16f, 1.0000000000e+00f,  1.0000000000e+00f,
       1.3877787808e-16f,  -2.4239820817e-08f, -1.3877787808e-17f, 1.0000000000e+00f,  3.3306690739e-16f,
       2.4239820817e-08f,  -1.6653345369e-16f, 1.0000000000e+00f,  1.0000000000e+00f,  1.3877787808e-16f,
       -2.4239820817e-08f, -1.3877787808e-17f, 1.0000000000e+00f,  3.3306690739e-16f,  2.4239820817e-08f,
       -1.6653345369e-16f, 1.0000000000e+00f,  9.9960327148e-01f,  -2.7519376948e-02f, 6.0034482740e-03f,
       -1.9657290541e-03f, 1.4446231723e-01f,  9.8950833082e-01f,  -2.8097925708e-02f, -9.8912757635e-01f,
       1.4435090125e-01f,  1.0000000000e+00f,  2.1738612688e-08f,  4.3368086899e-18f,  -3.9898639947e-17f,
       -2.7755575616e-17f, 1.0000000000e+00f,  2.1738612688e-08f,  -1.0000000000e+00f, 2.7755575616e-17f,
       1.0000000000e+00f,  2.1738612688e-08f,  4.3368086899e-18f,  -3.9898639947e-17f, -2.7755575616e-17f,
       1.0000000000e+00f,  2.1738612688e-08f,  -1.0000000000e+00f, 2.7755575616e-17f,  9.9703550339e-01f,
       4.3437462300e-02f,  -6.3508957624e-02f, 6.5221473575e-02f,  -3.9213620126e-02f, 9.9709999561e-01f,
       4.0821075439e-02f,  -9.9828624725e-01f, -4.1930425912e-02f, 9.9703550339e-01f,  4.3437462300e-02f,
       -6.3508957624e-02f, 6.5221473575e-02f,  -3.9213620126e-02f, 9.9709999561e-01f,  4.0821075439e-02f,
       -9.9828624725e-01f, -4.1930425912e-02f, 9.8629844189e-01f,  1.5424472094e-01f,  -5.8514416218e-02f,
       4.1302621365e-02f,  1.1252149940e-01f,  9.9279052019e-01f,  1.5971682966e-01f,  -9.8160451651e-01f,
       1.0460907221e-01f,  1.0000000000e+00f,  2.3721467457e-08f,  6.9388939039e-18f,  -3.4694469520e-17f,
       -5.4123372450e-16f, 1.0000000000e+00f,  2.3721467457e-08f,  -1.0000000000e+00f, -4.7184478547e-16f,
       1.0000000000e+00f,  2.3721467457e-08f,  6.9388939039e-18f,  -3.4694469520e-17f, -5.4123372450e-16f,
       1.0000000000e+00f,  2.3721467457e-08f,  -1.0000000000e+00f, -4.7184478547e-16f, 9.9183410406e-01f,
       2.1235136315e-02f,  -1.2575449049e-01f, 1.2680117786e-01f,  -5.8585133404e-02f, 9.9019658566e-01f,
       1.3659616001e-02f,  -9.9805653095e-01f, -6.0799375176e-02f, 9.9183410406e-01f,  2.1235136315e-02f,
       -1.2575449049e-01f, 1.2680117786e-01f,  -5.8585133404e-02f, 9.9019658566e-01f,  1.3659616001e-02f,
       -9.9805653095e-01f, -6.0799375176e-02f, 9.7038930655e-01f,  2.1955129504e-01f,  -1.0070653260e-01f,
       8.0579929054e-02f,  9.8796248436e-02f,  9.9183976650e-01f,  2.2770914435e-01f,  -9.7058564425e-01f,
       7.8179396689e-02f,  1.0000000000e+00f,  2.3966544305e-08f,  -2.7755575616e-17f, 4.1633363423e-17f,
       -1.8041124150e-16f, 1.0000000000e+00f,  2.3966544305e-08f,  -1.0000000000e+00f, -8.3266726847e-17f,
       1.0000000000e+00f,  2.3966544305e-08f,  -2.7755575616e-17f, 4.1633363423e-17f,  -1.8041124150e-16f,
       1.0000000000e+00f,  2.3966544305e-08f,  -1.0000000000e+00f, -8.3266726847e-17f, 9.9919724464e-01f,
       7.7960011549e-04f,  4.0053173900e-02f,  -4.0060751140e-02f, 1.8767835572e-02f,  9.9902099371e-01f,
       2.7125513952e-05f,  -9.9982357025e-01f, 1.8783999607e-02f,  9.9919724464e-01f,  7.7960011549e-04f,
       4.0053173900e-02f,  -4.0060751140e-02f, 1.8767835572e-02f,  9.9902099371e-01f,  2.7125513952e-05f,
       -9.9982357025e-01f, 1.8783999607e-02f,  9.1683918238e-01f,  3.1317952275e-01f,  -2.4763785303e-01f,
       2.3987253010e-01f,  6.3747830689e-02f,  9.6870911121e-01f,  3.1916621327e-01f,  -9.4755202532e-01f,
       -1.6676655039e-02f, 1.0000000000e+00f,  2.3871425725e-08f,  3.6082248300e-16f,  -2.7755575616e-17f,
       -1.5265566589e-16f, 1.0000000000e+00f,  2.3871425725e-08f,  -1.0000000000e+00f, -4.8572257327e-17f,
       1.0000000000e+00f,  2.3871425725e-08f,  3.6082248300e-16f,  -2.7755575616e-17f, -1.5265566589e-16f,
       1.0000000000e+00f,  2.3871425725e-08f,  -1.0000000000e+00f, -4.8572257327e-17f, 9.9630093575e-01f,
       -2.6843685657e-02f, -8.1632398069e-02f, 8.0781921744e-02f,  -3.1373634934e-02f, 9.9623793364e-01f,
       -2.9303802177e-02f, -9.9914717674e-01f, -2.9089098796e-02f, 9.9630093575e-01f,  -2.6843685657e-02f,
       -8.1632398069e-02f, 8.0781921744e-02f,  -3.1373634934e-02f, 9.9623793364e-01f,  -2.9303802177e-02f,
       -9.9914717674e-01f, -2.9089098796e-02f, -3.2073169121e-10f, 1.0623073601e-12f,  1.0000000000e+00f,
       -1.0000000000e+00f, -1.1269920833e-05f, -3.2073166345e-10f, 1.1269920833e-05f,  -1.0000000000e+00f,
       1.0660361482e-12f,  -3.2073166345e-10f, 1.0696111965e-12f,  1.0000000000e+00f,  -1.0000000000e+00f,
       1.1502694178e-05f,  -3.2073166345e-10f, -1.1502694178e-05f, -1.0000000000e+00f, 1.0660361482e-12f,
       -1.1554545515e-10f, -2.9919758338e-10f, 1.0000000000e+00f,  -3.5715162754e-01f, -9.3404644728e-01f,
       -3.2073166345e-10f, 9.3404644728e-01f,  -3.5715162754e-01f, 1.0660361482e-12f,  -1.4164447784e-03f,
       4.1140656685e-04f,  9.9999892712e-01f,  -2.7892348170e-01f, -9.6031332016e-01f, -4.8847298428e-10f,
       9.6031230688e-01f,  -2.7892318368e-01f, 1.4749816619e-03f,  -1.4234089758e-03f, 3.8662354928e-04f,
       9.9999892712e-01f,  -2.6212123036e-01f, -9.6503496170e-01f, -4.8847298428e-10f, 9.6503388882e-01f,
       -2.6212093234e-01f, 1.4749816619e-03f,  3.2073169121e-10f,  -1.0623074686e-12f, 1.0000000000e+00f,
       1.0000000000e+00f,  1.1269637980e-05f,  -3.2073166345e-10f, -1.1269637980e-05f, 1.0000000000e+00f,
       1.0660361482e-12f,  3.2073166345e-10f,  -1.0696111965e-12f, 1.0000000000e+00f,  1.0000000000e+00f,
       -1.1502432244e-05f, -3.2073166345e-10f, 1.1502432244e-05f,  1.0000000000e+00f,  1.0660361482e-12f,
       1.1554545515e-10f,  2.9919758338e-10f,  1.0000000000e+00f,  3.5715162754e-01f,  9.3404644728e-01f,
       -3.2073166345e-10f, -9.3404644728e-01f, 3.5715162754e-01f,  1.0660361482e-12f,  -1.4170479262e-03f,
       4.1158948443e-04f,  9.9999892712e-01f,  2.7892661095e-01f,  9.6031242609e-01f,  -2.1203838685e-09f,
       -9.6031135321e-01f, 2.7892631292e-01f,  -1.4756119344e-03f, -1.4240153832e-03f, 3.8679590216e-04f,
       9.9999892712e-01f,  2.6212435961e-01f,  9.6503412724e-01f,  -2.1203838685e-09f, -9.6503305435e-01f,
       2.6212409139e-01f,  -1.4756119344e-03f
};

static void ReconstructSoma77PoseFromSdkOutputs(const NvAR_Point3f* rest_pose_output,
                                                const NvAR_Quaternion* joint_rotations_output,
                                                const NvAR_Transform3f* root_pose_output, std::size_t body_index,
                                                std::vector<NvAR_Point3f>* t_pose_identity_output,
                                                std::vector<NvAR_Point3f>* retarget_local_output,
                                                std::vector<NvAR_Point3f>* retarget_in_camera_output,
                                                std::vector<NvAR_Point3f>* direct_reconstruction_local_output,
                                                std::vector<NvAR_Point3f>* direct_reconstruction_root_applied_output) {
  // These pointers must refer to the delayed output frame where NvAR_Parameter_Output(Ready) is nonzero:
  //
  //   rest_pose_output       -> NvAR_Parameter_Output(RestPose)
  //   joint_rotations_output -> NvAR_Parameter_Output(JointRotations)
  //   root_pose_output       -> NvAR_Parameter_Output(RootPose)
  //
  // NvAR_Parameter_Output(KeyPoints3D) is not required for reconstruction. Use it only to validate that the
  // reconstructed camera-space points match the SDK-emitted keypoints.
  const std::size_t body_offset = body_index * static_cast<std::size_t>(kNumKp);
  std::vector<NvAR_Point3f> rest_pose(rest_pose_output + body_offset, rest_pose_output + body_offset + kNumKp);
  std::vector<NvAR_Quaternion> joint_rotations(joint_rotations_output + body_offset,
                                               joint_rotations_output + body_offset + kNumKp);
  const NvAR_Transform3f root_pose = root_pose_output[body_index];

  const auto to_internal_soma_joint = [](std::size_t public_joint) { return public_joint + 1u; };
  const auto to_internal_soma_parent = [&to_internal_soma_joint](std::size_t public_joint) {
    const std::int32_t parent = kSoma77Parents[public_joint];
    return parent < 0 ? 0u : to_internal_soma_joint(static_cast<std::size_t>(parent));
  };
  const auto soma_t_pose_basis_joint_orient = [](std::size_t internal_joint) {
    return kSomaTPoseBasisJointOrient + internal_joint * kSomaTPoseBasisJointOrientMatrixDim;
  };

  // A1. Derive t_pose_identity from RestPose.
  // RestPose stores a cumulative direct-rest representation: joint 0 is at the origin, and every non-root joint is
  // stored as its parent's RestPose value plus that joint's local rest translation expressed in the parent direct-rest
  // frame. Plotting RestPose directly does not produce the visual SOMA T-pose. To derive t_pose_identity, the
  // person-specific skeleton geometry in the T-pose basis, recover each local rest translation with
  // RestPose[joint] - RestPose[parent], rotate it by the fixed parent SOMA T-pose-basis joint-orientation matrix, and
  // accumulate the transformed local translations.
  std::vector<NvAR_Point3f> t_pose_identity(kNumKp, NvAR_Point3f{0.0f, 0.0f, 0.0f});
  for (std::size_t joint = 1u; joint < kNumKp; ++joint) {
    const std::size_t parent = static_cast<std::size_t>(kSoma77Parents[joint]);
    const NvAR_Point3f rest_local_translation = SubtractPoint(rest_pose[joint], rest_pose[parent]);
    const NvAR_Point3f t_pose_local_translation =
        RotatePointByMatrix3(soma_t_pose_basis_joint_orient(to_internal_soma_joint(parent)),
                             rest_local_translation);
    t_pose_identity[joint] = AddPoint(t_pose_identity[parent], t_pose_local_translation);
  }

  // A2. Reconstruct the posed skeleton in the T-pose basis.
  // Convert each JointRotation into t_pose_local_rotations, local pose rotations in the T-pose basis:
  //
  //   t_pose_local_rotation[j] =
  //       t_pose_basis_joint_orient[parent(j)] * JointRotations[j] * inverse(t_pose_basis_joint_orient[j])
  //
  // Then run FK over the t_pose_identity local translations using t_pose_local_rotations. retarget_local is the posed
  // skeleton in the T-pose basis, before root placement.
  std::vector<NvAR_Quaternion> t_pose_local_rotations(kNumKp, NvAR_Quaternion{0.0f, 0.0f, 0.0f, 1.0f});
  for (std::size_t joint = 0u; joint < kNumKp; ++joint) {
    const NvAR_Quaternion parent_orient =
        MatrixToQuaternion(soma_t_pose_basis_joint_orient(to_internal_soma_parent(joint)));
    const NvAR_Quaternion joint_orient =
        MatrixToQuaternion(soma_t_pose_basis_joint_orient(to_internal_soma_joint(joint)));
    t_pose_local_rotations[joint] = NormalizeQuaternion(
        QuaternionMultiply(QuaternionMultiply(parent_orient, NormalizeQuaternion(joint_rotations[joint])),
                           InvertQuaternion(joint_orient)));
  }
  std::vector<NvAR_Point3f> retarget_local(kNumKp, NvAR_Point3f{0.0f, 0.0f, 0.0f});
  std::vector<NvAR_Quaternion> retarget_global_rotations(kNumKp, NvAR_Quaternion{0.0f, 0.0f, 0.0f, 1.0f});
  for (std::size_t joint = 1u; joint < kNumKp; ++joint) {
    const std::size_t parent = static_cast<std::size_t>(kSoma77Parents[joint]);
    const NvAR_Point3f t_pose_local_translation =
        SubtractPoint(t_pose_identity[joint], t_pose_identity[parent]);
    retarget_local[joint] =
        AddPoint(retarget_local[parent], RotatePoint(retarget_global_rotations[parent], t_pose_local_translation));
    retarget_global_rotations[joint] =
        NormalizeQuaternion(QuaternionMultiply(retarget_global_rotations[parent], t_pose_local_rotations[joint]));
  }

  // A3. Apply root placement to the T-pose retargeting route.
  // RootPose.rotation and JointRotations[0] carry the same direct-rest-basis root rotation in SDK output. The T-pose
  // route derives the T-pose-basis equivalent of the root rotation from JointRotations[0]. Applying that converted root
  // rotation and RootPose.translation places retarget_local in camera coordinates.
  std::vector<NvAR_Point3f> retarget_in_camera(kNumKp, NvAR_Point3f{0.0f, 0.0f, 0.0f});
  for (std::size_t joint = 0u; joint < kNumKp; ++joint) {
    retarget_in_camera[joint] =
        AddPoint(root_pose.translation, RotatePoint(t_pose_local_rotations[0], retarget_local[joint]));
  }

  // B. Directly reconstruct the emitted KeyPoints3D through the SDK direct-rest basis.
  // This route is useful for validation and debugging. It is not the preferred retargeting route because the
  // local point set is in the direct-rest basis, not the T-pose basis.
  std::vector<NvAR_Point3f> direct_reconstruction_local(kNumKp, NvAR_Point3f{0.0f, 0.0f, 0.0f});
  std::vector<NvAR_Quaternion> direct_reconstruction_global_rotations(kNumKp,
                                                                      NvAR_Quaternion{0.0f, 0.0f, 0.0f, 1.0f});
  for (std::size_t joint = 1u; joint < kNumKp; ++joint) {
    const std::size_t parent = static_cast<std::size_t>(kSoma77Parents[joint]);
    const NvAR_Point3f rest_local_translation = SubtractPoint(rest_pose[joint], rest_pose[parent]);
    direct_reconstruction_local[joint] = AddPoint(
        direct_reconstruction_local[parent],
        RotatePoint(direct_reconstruction_global_rotations[parent], rest_local_translation));
    direct_reconstruction_global_rotations[joint] = NormalizeQuaternion(
        QuaternionMultiply(direct_reconstruction_global_rotations[parent], joint_rotations[joint]));
  }
  std::vector<NvAR_Point3f> direct_reconstruction_root_applied(kNumKp, NvAR_Point3f{0.0f, 0.0f, 0.0f});
  for (std::size_t joint = 0u; joint < kNumKp; ++joint) {
    direct_reconstruction_root_applied[joint] =
        AddPoint(root_pose.translation, RotatePoint(root_pose.rotation, direct_reconstruction_local[joint]));
  }

  *t_pose_identity_output = t_pose_identity;
  *retarget_local_output = retarget_local;
  *retarget_in_camera_output = retarget_in_camera;
  *direct_reconstruction_local_output = direct_reconstruction_local;
  *direct_reconstruction_root_applied_output = direct_reconstruction_root_applied;
}