Revealing the mechanisms of grain nucleation and formation during additive manufacturing