Please reason step by step, and put your final answer within \boxed{}.
Three spheres of radius \( r \) lie on the lower base of a right triangular prism, with each sphere touching the other two spheres and two lateral faces of the prism. A fourth sphere rests on these spheres, touching all the lateral faces and the upper base of the prism. Find the height of the prism.
user