Convert a 360 Spherical Image into a Cubemap
mark last edited by Woland
So, today I needed to convert a spherical 360° image into a flat-surfaced cube map, and I found some nifty tools to help do that. These instructions are for MacOS, but the core tool required (ImageMagick) is cross platform. (If there's a Windows saavy person who wants to write up instructions for the Windows version, that would be appreciated.)
1) Get your 360° spherical image. I used the image on this page for a test.
It is critical that the dimensions of the source image are 2x1!!!
2) Download ImageMagick for MacOS.
3) Unzip the downloaded file into your downloads directory. For the version I downloaded, it was called ImageMagick-7.0.8
4) Download the the script called sphericalpano2cube from Fred's ImageMagick Scripts
5) Install the script in the ImageMagick-7.0.8 folder.
6) Open Apple's "Terminal" program
7) Enter cd /Users/HOMEDIR/Downloads/ImageMagick-7.0.8 and hit return. (You need to replace HOMEDIR with the name of your home directory.)
8) Enter chmod +rwx sphericalpano2cube and hit return. (This makes the script executable.)
9) Open the script in an editor and insert these lines after the first line (#!/bin/bash) and save the file
10) Back in the Terminal program enter the following
./sphericalpano2cube -d XXX INPUT_FILE_PATH OUTPUT_FILE_PATH
where XXX is the desired resolution of each cube face INPUT_FILE_PATH is the full path to your input file, and OUTPUT_FILE_PATH is the full path to the output. For example, if you had a folder on your desktop called "CubemapTest" you might enter:
./sphericalpano2cube -d 512 /Users/HOMEDIR/Destkop/CubemapTest/myimage.jpg /Users/HOMEDIR/Desktop/CubemapTest/pano.jpg
ImageMagick is cool because it does so much, but it's not fast. One high res image I tried above took quite a while to render out. Be patient! (You will see some feedback in the terminal window as it chunks away at the image.)
11) If you call the output "pano.jpg" as suggested above, you can use the file "panocube.3ds" (in the attached .zip) to see the results. For this 3DS file to work, the file names for the images must be pano_front.jpg, pane_right.jpg, pano_back.jpg etc.) If you place those images in the same folder as "panocube.3ds" in the example Isadora file given in the zip, you'll be able to see the results immediately.
12) The Isadora patch is simple, with just a 3D Player actor and a Wave Generator to rotate the cube. "You" are in the center of the cube looking outward. (Which is why you must turn on the "render back" input, as normally you wouldn't see anything looking from the inside of the cube outwards.)
13) There is an artifact at the edges of the cube, which doesn't seem to be avoidable. But really, this mode of viewing the image is not for spinning it around. (For that, see a previous post on mapping a 360° spherical image to a sphere and using the same "look out from the center" technique described in a previous forum post. (Thanks to @mwasser for that gem!)
I hope this little set of instructions benefits one of you out there.
Yours in Code,