# Skeleton maps: Unity Humanoid, VRM and the Unreal mannequins

The rig has 71 joints. 51 of them are the bones of a humanoid. The rest are the body-shape joints (`shape_NN`, moved
by the weight and height sliders), the two prop joints a held item hangs from (`PropLeft`, `PropRight`) and two
special joints (`SpecialLeft`, `SpecialRight`). The maps give each humanoid joint its bone in five skeletons, so a
host can retarget the avatar's clips onto its own characters, or its own clips onto the avatar.

```c
const char *sona_skeleton_bone(uint32_t skeleton, uint32_t joint);   /* NULL: that skeleton has no such bone */
int32_t sona_skeleton_joint(uint32_t skeleton, const char *bone);    /* -1: none; names match exactly */
```

`skeleton` is a `sona_skeleton_kind`: `SONA_SKELETON_UNITY`, `_VRM` (1.0), `_VRM0`, `_UE4` or `_UE5`. Both calls are
pure tables: no ctx, any thread. `sona_export_avatar` names the bones of the file it writes after one of them
(`sona_export_options.bone_names`), and a VRM's humanoid uses the VRM names ([VRM and glTF export](vrm.md)). In the bindings:
C# `SonaSkeletons.Bone` and `.Joint`, Python `sona.skeleton_bone` and `skeleton_joint`, Rust `sona::skeleton_bone`
and `skeleton_joint`. The sample prints the table: `vrm_export --map`.

## The table

The VRM names are the Unity names with a lower-case first letter (`hips`, `leftUpperLeg`), except VRM 1.0's thumbs,
which the rows give. The UE4 and UE5 mannequins name every joint alike but the chest, which the row gives.

| Joint | Unity Humanoid (and VRM) | Unreal mannequin |
|---|---|---|
| 0 | `Hips` | `pelvis` |
| 1 | `Spine` | `spine_01` |
| 2 | `LeftUpperLeg` | `thigh_l` |
| 3 | `RightUpperLeg` | `thigh_r` |
| 5 | `Chest` | `spine_03` (UE5 `spine_05`) |
| 6 | `LeftLowerLeg` | `calf_l` |
| 8 | `RightLowerLeg` | `calf_r` |
| 11 | `LeftFoot` | `foot_l` |
| 12 | `LeftShoulder` | `clavicle_l` |
| 14 | `Neck` | `neck_01` |
| 15 | `RightFoot` | `foot_r` |
| 16 | `RightShoulder` | `clavicle_r` |
| 19 | `Head` | `head` |
| 20 | `LeftUpperArm` | `upperarm_l` |
| 21 | `LeftToes` | `ball_l` |
| 22 | `RightUpperArm` | `upperarm_r` |
| 23 | `RightToes` | `ball_r` |
| 25 | `LeftLowerArm` | `lowerarm_l` |
| 28 | `RightLowerArm` | `lowerarm_r` |
| 33 | `LeftHand` | `hand_l` |
| 36 | `RightHand` | `hand_r` |
| 37 | `LeftIndexProximal` | `index_01_l` |
| 38 | `LeftMiddleProximal` | `middle_01_l` |
| 39 | `LeftRingProximal` | `ring_01_l` |
| 40 | `LeftLittleProximal` | `pinky_01_l` |
| 43 | `LeftThumbProximal` (VRM 1.0 `leftThumbMetacarpal`) | `thumb_01_l` |
| 44 | `RightIndexProximal` | `index_01_r` |
| 45 | `RightMiddleProximal` | `middle_01_r` |
| 46 | `RightRingProximal` | `ring_01_r` |
| 47 | `RightLittleProximal` | `pinky_01_r` |
| 50 | `RightThumbProximal` (VRM 1.0 `rightThumbMetacarpal`) | `thumb_01_r` |
| 51 | `LeftIndexIntermediate` | `index_02_l` |
| 52 | `LeftMiddleIntermediate` | `middle_02_l` |
| 53 | `LeftRingIntermediate` | `ring_02_l` |
| 54 | `LeftLittleIntermediate` | `pinky_02_l` |
| 55 | `LeftThumbIntermediate` (VRM 1.0 `leftThumbProximal`) | `thumb_02_l` |
| 56 | `RightIndexIntermediate` | `index_02_r` |
| 57 | `RightMiddleIntermediate` | `middle_02_r` |
| 58 | `RightRingIntermediate` | `ring_02_r` |
| 59 | `RightLittleIntermediate` | `pinky_02_r` |
| 60 | `RightThumbIntermediate` (VRM 1.0 `rightThumbProximal`) | `thumb_02_r` |
| 61 | `LeftIndexDistal` | `index_03_l` |
| 62 | `LeftMiddleDistal` | `middle_03_l` |
| 63 | `LeftRingDistal` | `ring_03_l` |
| 64 | `LeftLittleDistal` | `pinky_03_l` |
| 65 | `LeftThumbDistal` | `thumb_03_l` |
| 66 | `RightIndexDistal` | `index_03_r` |
| 67 | `RightMiddleDistal` | `middle_03_r` |
| 68 | `RightRingDistal` | `ring_03_r` |
| 69 | `RightLittleDistal` | `pinky_03_r` |
| 70 | `RightThumbDistal` | `thumb_03_r` |

## Where they differ

- **Unity Humanoid** is the rig's own naming (`sona_joint_name` gives the same strings). Unity's Avatar setup maps
  these names by itself. The bones it would also take and the rig lacks are UpperChest, the eyes and the jaw. The
  thumb's first bone, `LeftThumbProximal`, sits at the base of the thumb, as Unity means it.
- **VRM 1.0** renamed the thumb: its first bone is `leftThumbMetacarpal` and its second `leftThumbProximal`. VRM 0.x
  keeps Unity's names with a lower-case first letter. The 15 bones VRM 1.0 requires (hips, spine, head, the upper
  and lower arms and legs, the hands and the feet) are all mapped. Each bone's nearest mapped ancestor in the rig
  is the parent the VRM 1.0 humanoid asks for.
- **The Unreal mannequins** have more spine and neck bones than the rig. The rig's `Spine` is `spine_01`. Its `Chest`,
  the bone the collarbones hang from, is the mannequin's top spine bone: `spine_03` on the UE4 mannequin and
  `spine_05` on the UE5 one (Manny and Quinn). `spine_02`, `spine_04` and `neck_02` have no joint here: an IK
  Retargeter chain from `spine_01` to the top bone spreads the motion over them. UE5's metacarpal bones
  (`index_metacarpal_l` and the rest) have no joint either. Unreal skeletons start at a `root` bone on the floor,
  above `pelvis`; an export with UE4 or UE5 bone names adds it, with no weights.
- **Props.** No skeleton has a bone for the prop joints. In Unity they stay plain transforms under the hands; in
  Unreal, sockets on `hand_l` and `hand_r` do their job.

## Retargeting

- **Unity:** import the VRM with UniVRM, or the glTF with glTFast, and set the rig to Humanoid. The names map
  with no manual work and the rest pose is a T-pose. The shape joints are ordinary children with skin weights;
  leave them unmapped.
- **Unreal:** import a glTF exported with UE4 or UE5 bone names. Make an IK Rig for it with the chains of the
  mannequin's IK Rig: Spine (`spine_01` to the top spine bone), Neck, Head, the arms from `clavicle` to `hand`, the
  legs from `thigh` to `ball`, one chain per finger. Then make an IK Retargeter between the two. The export stands in
  a T-pose and the mannequins in an A-pose, so lower the retarget pose's arms by about 45 degrees.
- **Anything else:** `sona_skeleton_joint` turns a bone name from any of the five into the joint whose
  `sona_joint_world` to read or whose `sona_avatar_override` to set.

Checked here: the tables by the `export` test (round trips, unique names, the thumbs, the chests, the hierarchy
against the rig). Not checked here: an import into Unity or Unreal themselves (neither runs on this machine).
