Three-dimensional self-assembly using dipolar interaction