Extracted 3d code into its own file.