Skip to content

SOMA

SOMA provides a native implementation for SOMA-X assets with identity, pose, and corrective controls.

Setup

SOMA downloads automatically on first use. To prefetch and save the path:

# Download the SOMA-X asset used by the native SOMA implementation.
body-models download soma

Notes

The native implementation does not require installing py-soma-x.

cache_identity=True can be passed to the constructor for interactive viewers that repeatedly evaluate the same identity with different poses. The default is False, which keeps training and JAX-transformed calls graph-safe unless caching is explicitly requested.

API

body_models.bodies.soma.numpy.SOMA

SOMA(
    model_path=None,
    *,
    model_type="soma",
    simplify=1.0,
    rotation_type="axis_angle",
    match_warp=True,
    kernel="scipy",
)

Bases: BodyModel

SOMA body model with NumPy backend.

Initialize the SOMA model.

PARAMETER DESCRIPTION
model_path

Path to model assets, or the default assets when omitted.

TYPE: PathLike | None DEFAULT: None

model_type

SOMA identity/model variant to load.

TYPE: str DEFAULT: 'soma'

simplify

Mesh simplification factor to apply while loading.

TYPE: float DEFAULT: 1.0

rotation_type

Rotation representation expected by pose inputs.

TYPE: RotationType DEFAULT: 'axis_angle'

match_warp

Whether to match Warp backend numerical conventions.

TYPE: bool DEFAULT: True

kernel

Backend kernel used for forward evaluation.

TYPE: Literal['scipy'] DEFAULT: 'scipy'

METHOD DESCRIPTION
forward_vertices

Compute posed mesh vertices.

forward_skeleton

Compute posed joint transforms.

prepare_identity

Precompute identity-dependent SOMA state for repeated forward passes.

prepare_pose

Precompute pose-dependent state for repeated forward passes.

joint_index

Resolve a standard joint to this model's native joint index.

prepare_skinning

Pack prepared model state into renderer-ready skinning inputs.

ATTRIBUTE DESCRIPTION
common_joints

Common anatomical joints mapped to this model's native joint names.

TYPE: Mapping[Joint, str]

Source code in src/body_models/bodies/soma/numpy.py
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def __init__(
    self,
    model_path: PathLike | None = None,
    *,
    model_type: str = "soma",
    simplify: float = 1.0,
    rotation_type: RotationType = "axis_angle",
    match_warp: bool = True,
    kernel: Literal["scipy"] = "scipy",
) -> None:
    """Initialize the SOMA model.

    Args:
        model_path: Path to model assets, or the default assets when omitted.
        model_type: SOMA identity/model variant to load.
        simplify: Mesh simplification factor to apply while loading.
        rotation_type: Rotation representation expected by pose inputs.
        match_warp: Whether to match Warp backend numerical conventions.
        kernel: Backend kernel used for forward evaluation.
    """
    normalized_model_type = model_type.lower()
    if normalized_model_type not in self.VALID_MODEL_TYPES:
        raise ValueError(
            f"Invalid model_type: {model_type}. Supported SOMA model types are {', '.join(self.VALID_MODEL_TYPES)}."
        )
    if rotation_type not in VALID_ROTATION_TYPES:
        raise ValueError(f"Invalid rotation_type: {rotation_type}")
    if kernel not in self.kernels:
        raise ValueError(f"Invalid kernel: {kernel}")
    if simplify < 1.0:
        raise ValueError("simplify must be >= 1.0 (1.0 = original mesh)")

    self.model_type = normalized_model_type
    self.rotation_type = rotation_type
    self.num_rot_dims = 2 if rotation_type in ("matrix", "rotmat") else 1
    self.match_warp = match_warp
    self._kernel = {"scipy": scipy_backend}[kernel]
    resolved_path = get_model_path(model_path)
    data = load_model_data(resolved_path)

    mean_full = data.mean_full
    shapedirs_full = data.shapedirs_full
    faces = data.faces
    skin_weights_full = data.skin_weights_full

    if simplify > 1.0:
        target_faces = int(len(faces) / simplify)
        mean_active, faces, vertex_map = simplify_mesh(mean_full, faces.astype(int), target_faces)
        shapedirs_active = shapedirs_full[:, vertex_map]
        skin_weights_active = skin_weights_full[vertex_map]
        vertex_map = np.asarray(vertex_map, dtype=np.int64)
    else:
        mean_active = mean_full
        shapedirs_active = shapedirs_full
        skin_weights_active = skin_weights_full
        vertex_map = None

    self.parents = [parent - 1 for parent in data.topology.parents_full[1:]]
    self._joint_names = data.joint_names_full[1:]
    skin_joint_indices_active, skin_joint_weights_active = compute_sparse_skin_weights(skin_weights_active)
    weights = replace(
        data,
        mean_active=np.asarray(mean_active, dtype=np.float32),
        shapedirs_active=np.asarray(shapedirs_active, dtype=np.float32),
        skin_weights_active=np.asarray(skin_weights_active, dtype=np.float32),
        skin_joint_indices_active=skin_joint_indices_active,
        skin_joint_weights_active=skin_joint_weights_active,
        faces=np.asarray(faces, dtype=np.int64),
        vertex_map=vertex_map,
    )
    self.weights = self._kernel.prepare_data(weights)

    spec = MODEL_TYPE_SPECS[self.model_type]
    self.identity_dim = spec.identity_dim
    self.num_scale_params = spec.num_scale_params
    self._default_identity_value = spec.default_identity_value
    self._identity_source = None
    if spec.asset_dir is not None:
        transfer_data = load_identity_transfer_data(resolved_path, self.model_type)
        self._identity_source = identity_sources.create_identity_source(self.model_type, transfer_data)

common_joints property

common_joints

Common anatomical joints mapped to this model's native joint names.

forward_vertices

forward_vertices(
    body_pose,
    head_pose,
    hand_pose,
    global_rotation,
    *,
    shape=None,
    scale_params=None,
    identity=None,
    global_translation=None,
    vertex_indices=None,
)

Compute posed mesh vertices.

PARAMETER DESCRIPTION
body_pose

Local body joint rotations.

TYPE: Float[ndarray, 'B 23 N'] | Float[ndarray, 'B 23 3 3']

head_pose

Local head and facial joint rotations.

TYPE: Float[ndarray, 'B 5 N'] | Float[ndarray, 'B 5 3 3']

hand_pose

Local hand joint rotations.

TYPE: Float[ndarray, 'B 48 N'] | Float[ndarray, 'B 48 3 3']

global_rotation

Global model rotation.

TYPE: Float[ndarray, 'B N'] | Float[ndarray, 'B 3 3']

shape

Identity coefficients.

TYPE: Float[ndarray, '*batch I'] | None DEFAULT: None

scale_params

Per-part scale parameters.

TYPE: Float[ndarray, 'B|1 K'] | None DEFAULT: None

identity

Optional output from :meth:prepare_identity.

TYPE: SomaIdentity | None DEFAULT: None

global_translation

Global model translation.

TYPE: Float[ndarray, 'B 3'] | None DEFAULT: None

vertex_indices

Optional subset of vertices to return.

TYPE: Any | None DEFAULT: None

RETURNS DESCRIPTION
Float[ndarray, 'B V 3']

Posed vertex positions.

Source code in src/body_models/bodies/soma/numpy.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def forward_vertices(
    self,
    body_pose: Float[np.ndarray, "B 23 N"] | Float[np.ndarray, "B 23 3 3"],
    head_pose: Float[np.ndarray, "B 5 N"] | Float[np.ndarray, "B 5 3 3"],
    hand_pose: Float[np.ndarray, "B 48 N"] | Float[np.ndarray, "B 48 3 3"],
    global_rotation: Float[np.ndarray, "B N"] | Float[np.ndarray, "B 3 3"],
    *,
    shape: Float[np.ndarray, "*batch I"] | None = None,
    scale_params: Float[np.ndarray, "B|1 K"] | None = None,
    identity: SomaIdentity | None = None,
    global_translation: Float[np.ndarray, "B 3"] | None = None,
    vertex_indices: Any | None = None,
) -> Float[np.ndarray, "B V 3"]:
    """Compute posed mesh vertices.

    Args:
        body_pose: Local body joint rotations.
        head_pose: Local head and facial joint rotations.
        hand_pose: Local hand joint rotations.
        global_rotation: Global model rotation.
        shape: Identity coefficients.
        scale_params: Per-part scale parameters.
        identity: Optional output from :meth:`prepare_identity`.
        global_translation: Global model translation.
        vertex_indices: Optional subset of vertices to return.

    Returns:
        Posed vertex positions.
    """
    if identity is None:
        assert shape is not None
        pose = pack_pose(np, global_rotation, body_pose, head_pose, hand_pose)
        batch_shape = tuple(pose.shape[: -(self.num_rot_dims + 1)])
        shape = np.broadcast_to(shape, (*batch_shape, shape.shape[-1]))
        if scale_params is not None:
            scale_params = np.broadcast_to(scale_params, (*batch_shape, scale_params.shape[-1]))
        identity = self.prepare_identity(shape, scale_params=scale_params)
    pose = self.prepare_pose(body_pose, head_pose, hand_pose, global_rotation, identity=identity)
    return self._kernel.forward_vertices(
        data=self.weights,
        global_translation=global_translation,
        vertex_indices=vertex_indices,
        rotation_type=self.rotation_type,
        rest_vertices=identity["rest_vertices"],
        skinning_transforms=pose["skinning_transforms"],
        pose_offsets=pose["pose_offsets"],
        xp=np,
    )

forward_skeleton

forward_skeleton(
    body_pose,
    head_pose,
    hand_pose,
    global_rotation,
    *,
    shape=None,
    scale_params=None,
    identity=None,
    global_translation=None,
    joint_indices=None,
)

Compute posed joint transforms.

PARAMETER DESCRIPTION
body_pose

Local body joint rotations.

TYPE: Float[ndarray, 'B 23 N'] | Float[ndarray, 'B 23 3 3']

head_pose

Local head and facial joint rotations.

TYPE: Float[ndarray, 'B 5 N'] | Float[ndarray, 'B 5 3 3']

hand_pose

Local hand joint rotations.

TYPE: Float[ndarray, 'B 48 N'] | Float[ndarray, 'B 48 3 3']

global_rotation

Global model rotation.

TYPE: Float[ndarray, 'B N'] | Float[ndarray, 'B 3 3']

shape

Identity coefficients.

TYPE: Float[ndarray, '*batch I'] | None DEFAULT: None

scale_params

Per-part scale parameters.

TYPE: Float[ndarray, 'B|1 K'] | None DEFAULT: None

identity

Optional output from :meth:prepare_identity.

TYPE: SomaIdentity | None DEFAULT: None

global_translation

Global model translation.

TYPE: Float[ndarray, 'B 3'] | None DEFAULT: None

joint_indices

Optional subset of joints to return.

TYPE: Any | None DEFAULT: None

RETURNS DESCRIPTION
Float[ndarray, 'B 77 4 4']

Joint transforms in the model hierarchy.

Source code in src/body_models/bodies/soma/numpy.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
def forward_skeleton(
    self,
    body_pose: Float[np.ndarray, "B 23 N"] | Float[np.ndarray, "B 23 3 3"],
    head_pose: Float[np.ndarray, "B 5 N"] | Float[np.ndarray, "B 5 3 3"],
    hand_pose: Float[np.ndarray, "B 48 N"] | Float[np.ndarray, "B 48 3 3"],
    global_rotation: Float[np.ndarray, "B N"] | Float[np.ndarray, "B 3 3"],
    *,
    shape: Float[np.ndarray, "*batch I"] | None = None,
    scale_params: Float[np.ndarray, "B|1 K"] | None = None,
    identity: SomaIdentity | None = None,
    global_translation: Float[np.ndarray, "B 3"] | None = None,
    joint_indices: Any | None = None,
) -> Float[np.ndarray, "B 77 4 4"]:
    """Compute posed joint transforms.

    Args:
        body_pose: Local body joint rotations.
        head_pose: Local head and facial joint rotations.
        hand_pose: Local hand joint rotations.
        global_rotation: Global model rotation.
        shape: Identity coefficients.
        scale_params: Per-part scale parameters.
        identity: Optional output from :meth:`prepare_identity`.
        global_translation: Global model translation.
        joint_indices: Optional subset of joints to return.

    Returns:
        Joint transforms in the model hierarchy.
    """
    if identity is None:
        assert shape is not None
        pose = pack_pose(np, global_rotation, body_pose, head_pose, hand_pose)
        batch_shape = tuple(pose.shape[: -(self.num_rot_dims + 1)])
        shape = np.broadcast_to(shape, (*batch_shape, shape.shape[-1]))
        if scale_params is not None:
            scale_params = np.broadcast_to(scale_params, (*batch_shape, scale_params.shape[-1]))
        identity = self.prepare_identity(shape, scale_params=scale_params, skip_vertices=True)
    pose = self.prepare_pose(
        body_pose, head_pose, hand_pose, global_rotation, identity=identity, skip_vertices=True
    )
    return self._kernel.forward_skeleton(
        data=self.weights,
        global_translation=global_translation,
        joint_indices=joint_indices,
        rotation_type=self.rotation_type,
        skeleton_transforms=pose["skeleton_transforms"],
        xp=np,
    )

prepare_identity

prepare_identity(shape, *, scale_params=None, skip_vertices=False)

Precompute identity-dependent SOMA state for repeated forward passes.

Source code in src/body_models/bodies/soma/numpy.py
289
290
291
292
293
294
295
296
297
298
299
300
301
def prepare_identity(
    self,
    shape: Float[np.ndarray, "*batch I"],
    *,
    scale_params: Float[np.ndarray, "B|1 K"] | None = None,
    skip_vertices: bool = False,
) -> SomaIdentity:
    """Precompute identity-dependent SOMA state for repeated forward passes."""
    if self.num_scale_params is None:
        scale_params = None
    elif scale_params is None:
        scale_params = np.zeros((*shape.shape[:-1], self.num_scale_params), dtype=shape.dtype)
    return self._prepare_identity_from_inputs(shape, scale_params, skip_vertices=skip_vertices)

prepare_pose

prepare_pose(
    body_pose,
    head_pose,
    hand_pose,
    global_rotation,
    *,
    identity,
    skip_vertices=False,
)

Precompute pose-dependent state for repeated forward passes.

Source code in src/body_models/bodies/soma/numpy.py
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
def prepare_pose(
    self,
    body_pose: Float[np.ndarray, "B 23 N"] | Float[np.ndarray, "B 23 3 3"],
    head_pose: Float[np.ndarray, "B 5 N"] | Float[np.ndarray, "B 5 3 3"],
    hand_pose: Float[np.ndarray, "B 48 N"] | Float[np.ndarray, "B 48 3 3"],
    global_rotation: Float[np.ndarray, "B N"] | Float[np.ndarray, "B 3 3"],
    *,
    identity: SomaIdentity,
    skip_vertices: bool = False,
) -> SomaPreparedPose:
    """Precompute pose-dependent state for repeated forward passes."""
    pose = pack_pose(np, global_rotation, body_pose, head_pose, hand_pose)
    return self._kernel.prepare_pose(
        self.weights,
        pose,
        rotation_type=self.rotation_type,
        world_bind_pose=identity["world_bind_pose"],
        inverse_world_bind_pose=None if skip_vertices else identity["inverse_world_bind_pose"],
        skip_vertices=skip_vertices,
        xp=np,
    )

joint_index

joint_index(joint)

Resolve a standard joint to this model's native joint index.

Source code in src/body_models/base.py
77
78
79
80
81
82
83
84
85
def joint_index(self, joint: Joint) -> int:
    """Resolve a standard joint to this model's native joint index."""
    if not isinstance(joint, Joint):
        raise TypeError("joint_index() expects a body_models.Joint; use joint_names.index(...) for native names.")
    try:
        native_name = self.common_joints[joint]
    except KeyError as exc:
        raise KeyError(f"{self.__class__.__name__} has no standard joint {joint.value!r}") from exc
    return self.joint_names.index(native_name)

prepare_skinning

prepare_skinning(*, identity, pose)

Pack prepared model state into renderer-ready skinning inputs.

Source code in src/body_models/base.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
def prepare_skinning(self, *, identity: Mapping[str, Any], pose: Mapping[str, Any]) -> SkinningPayload:
    """Pack prepared model state into renderer-ready skinning inputs."""
    if self.is_rigid_body:
        raise NotImplementedError(f"{self.__class__.__name__} is rigid and does not support skinning.")

    skinning: SkinningPayload = {
        "rest_vertices": identity["rest_vertices"],
        "skinning_transforms": pose["skinning_transforms"],
        "skin_weights": self.skin_weights,
        "faces": self.faces,
    }
    if "pose_offsets" in pose:
        skinning["pose_offsets"] = pose["pose_offsets"]
    return skinning