Three-phase fluid displacements on the pore scale: method and mechanisms