Buoyant magnetic flux tubes. II: Three-dimensional behaviour in granules and supergranules