final code for 3D image creation