import torch


def get_joints_from_mano_mesh(
    mesh_vertices: torch.Tensor, mano_matrix: torch.Tensor
) -> torch.Tensor:
    """extracts joints from mano mesh. The matrix should be  from MANO_MAT path.
    The joint ordering is in joints_mapping.json.

    Args:
        mesh_vertices (torch.Tensor): mesh of shape 778 *3
        mano_matrix (torch.Tensor): Matrix of shape 16*778

    Returns:
        torch.Tensor: 21 hand joints in 3D.
    """
    joints = mano_matrix @ mesh_vertices
    tips = mesh_vertices[
        [744, 320, 443, 555, 672], :
    ]  # thumb, index, middle, ring, pinky
    joints = torch.cat([joints, tips], 0)
    return joints