Skip to main content

2. Export the body (for reference only)

To fit a shirt to a body you need the body. To skin it to the skeleton you need the skeleton. Both are in the game's player bundles, and UnityPy can read them.

:::danger Reference only These files are the game's. They go in a reference folder outside your project, and never into a mod or a repo. Nothing of the body goes into the outfit except bone names and weights copied from the nearest skin. :::

The bundles are in:

<game>/Data/Addressables/Standalone/player_assets_entities/player/
├─ common.bundle the rig, shared by both sexes
├─ female/common.bundle her body, hands, feet
└─ male/common.bundle his

The rig​

One skeleton serves both sexes: the GameObject baseRigPrefab in player/common.bundle. We walk its transforms and save every bone's name, local position, rotation and scale.

def walk(tr):
go = tr.m_GameObject.read()
p, r, s = tr.m_LocalPosition, tr.m_LocalRotation, tr.m_LocalScale
return {
"name": go.m_Name,
"pos": [p.x, p.y, p.z],
"rot": [r.x, r.y, r.z, r.w],
"scale": [s.x, s.y, s.z],
"children": [walk(ch.read()) for ch in tr.m_Children],
}
py -3.12 tools/export_rig.py "<game>/Data/Addressables/Standalone/player_assets_entities/player" <ref>/rig.json

It's 187 transforms. The top one is Origin, then Hips, the spine, arms, legs, fingers and a pile of helper bones.

The body, its bind poses and its weights​

For each sex we want four things:

  • the body mesh, to fit against (<sex>_body.obj)
  • the bind pose of every bone the body is skinned to (<sex>_body_bind.csv): this is the matrix that takes a point on the body into that bone's space, and your clothes need the same ones
  • the bone weights per vertex (<sex>_body_weights.csv), so the shirt can borrow them from the nearest skin
  • the vertex positions as Unity has them (<sex>_body_verts.csv)

The bind poses come straight off the body's SkinnedMeshRenderer:

smr = obj.read() # the SkinnedMeshRenderer called "body"
mesh = smr.m_Mesh.read()
names = [b.read().m_GameObject.read().m_Name for b in smr.m_Bones]
for name, m in zip(names, mesh.m_BindPose): # one 4x4 per bone, in skin order
...

And the weights from UnityPy's mesh helper:

from UnityPy.helpers.MeshHelper import MeshHandler
h = MeshHandler(mesh)
h.process()
bone_index = np.array(h.m_BoneIndices).reshape(len(v), -1) # rows of the bind csv
bone_weight = np.array(h.m_BoneWeights).reshape(len(v), -1)
py -3.12 tools/export_body_ref.py <bundles> <ref>/rig.json <ref> female
py -3.12 tools/export_body_weights.py <bundles> <ref> female
py -3.12 tools/export_body_ref.py <bundles> - <ref> male
py -3.12 tools/export_body_weights.py <bundles> <ref> male

The - skips the rig the second time, since both sexes share it. export_body_ref.py also turns the rig into player_rig.csv (name, parent, local position, rotation, scale, and world position), which the Unity builder reads later.

Numbers worth knowing​

These are from V3.4. They help when something looks off.

  • The body faces +z. The chest is at positive z, the spine just behind z = 0.
  • Hips sit at y 0.974, the ankle joints at about 0.095, the feet touch y 0. Both sexes share the joint positions.
  • The female body is skinned to 167 bones, the male to 168. So each sex needs its own bind matrices, even on the same rig.
  • UnityPy's OBJ export negates x (and flips the winding). The CSVs are in Unity's own space, which is what we build in. Use the OBJ only for its triangles.