def join_meshes_as_batch()

in pytorch3d/structures/meshes.py [0:0]


def join_meshes_as_batch(meshes: List[Meshes], include_textures: bool = True):
    """
    Merge multiple Meshes objects, i.e. concatenate the meshes objects. They
    must all be on the same device. If include_textures is true, they must all
    be compatible, either all or none having textures, and all the Textures
    objects being the same type. If include_textures is False, textures are
    ignored.

    If the textures are TexturesAtlas then being the same type includes having
    the same resolution. If they are TexturesUV then it includes having the same
    align_corners and padding_mode.

    Args:
        meshes: list of meshes.
        include_textures: (bool) whether to try to join the textures.

    Returns:
        new Meshes object containing all the meshes from all the inputs.
    """
    if isinstance(meshes, Meshes):
        # Meshes objects can be iterated and produce single Meshes. We avoid
        # letting join_meshes_as_batch(mesh1, mesh2) silently do the wrong thing.
        raise ValueError("Wrong first argument to join_meshes_as_batch.")
    verts = [v for mesh in meshes for v in mesh.verts_list()]
    faces = [f for mesh in meshes for f in mesh.faces_list()]
    if len(meshes) == 0 or not include_textures:
        return Meshes(verts=verts, faces=faces)

    if meshes[0].textures is None:
        if any(mesh.textures is not None for mesh in meshes):
            raise ValueError("Inconsistent textures in join_meshes_as_batch.")
        return Meshes(verts=verts, faces=faces)

    if any(mesh.textures is None for mesh in meshes):
        raise ValueError("Inconsistent textures in join_meshes_as_batch.")

    # Now we know there are multiple meshes and they have textures to merge.
    all_textures = [mesh.textures for mesh in meshes]
    first = all_textures[0]
    tex_types_same = all(type(tex) == type(first) for tex in all_textures)

    if not tex_types_same:
        raise ValueError("All meshes in the batch must have the same type of texture.")

    tex = first.join_batch(all_textures[1:])
    return Meshes(verts=verts, faces=faces, textures=tex)