The origin of metamorphosis