Dimensionality of excitons in stacked van der Waals materials: The example of hexagonal boron nitride