Miscellaneous 3D and image handling code