Apparatus and method for three-dimensional printing