import torch


def blend(v_base, maps, dataset, frames):
    """
    Get blended vertex positions as in rig eq.

    :param v_base: Base mesh vertex positions of shape [3*v], (x,y,z,x,...)
    :param maps: Dict of mappings, one mapping for each dataset: local, global, pca
    :param dataset: Dict of datasets (blendshapes): local, global, pca
    :param frames: One-hot vector of frame index, with value at frame i being 1.
    :return: Blended mesh vertex positions of shape [3*v], (x,y,z,x,...)
    """
    if 'global' not in dataset:
        # print(f"shapes:\nv_base[{v_base.shape}\ndataset['local][{dataset['local'].shape}]\nmaps['local][{maps['local'].shape}]\nframes[{frames.shape}]")
        bl_res = torch.matmul(dataset['local'], maps['local'])
        mapped = torch.matmul(bl_res, frames)
        vtx_pos = torch.add(v_base, mapped)
        return vtx_pos