Automatically modify primitive based on texture
Array modifier

As long as the pattern is repeated in a Grid, you can replicate "N" times a mesh along the main axis with the Array modifier:



For your particular case, you'll have to build a mesh made by 3 cubes and stack one Array modifier for each axis, adjusting the Relative offset vector: