I posted this in scripting issues forum some time ago, but I think more people, who need that sort of stuff would find it here. It’s public domain.
Also you’ll need a texture:
Bear in mind, that this is just a quick prototype so some parts are just hacked into, like setNumRows(). I didn’t know how to calculate number of vertices, without extra iteration over cubes, but it doesn’t seem to really matter. Also just two textures are supported. And you wouldn’t want to use dict to store cubes, because it uses way too much memory.