A higher-dimensional partial Legendre transform, and regularity of degenerate Monge-Ampère equations