Catégorie : News

Equirectangular to cubemap bash script

I was working on another try to use blend4web for a personal application, and I remembered that if you want to use an environment map it has to be a Blender specific 2 rows cubemap ( 2*3 cubes faces).

blender cubemap
Blender cubemap

I’ve found ways to make it with gimp, after using Bruno Postle’s panotools script ( erect2cubic Erect2cubic ), or directly inside Blender (link 1: Blendswap cubemap maker , from : cubemap making inside blender).




But all those ways needed to treat each panos one after the other; too long when you have to transform 20 panoramas…
So I wrote a little bash script to transform equirectangular panoramas initially to those specific cubemaps, then I extended it to match further types of cubemaps ( it seems that unity uses cross styled cubemaps ).

#!/bin/sh
# 2016 11 03 sh script
# This script aim to transform an equirectangular pano to a cubemap image used for environment mapping
# it uses : Hugin, Bruno Postle's panotools scripts (perl) ,imagemagick's "convert" and montage command line tools and zenity for gui.
# Find it useful ? Any bugs, ideas?, mail me at : mail@fabkzo.com
# Author: FabKzo www.fabkzo.com

pano=0
order=0
front=cube0000.tif
right=cube0001.tif
back=cube0002.tif
left=cube0003.tif
up=cube0004.tif
down=cube0005.tif

createPano (){
                    #create pto file
                    erect2cubic --erect=$pano --ptofile=cube.pto;
    
                    #create each cube faces
                    nona -o cube cube.pto;
                    imgsize=$(identify -format %h cube0000.tif);
                    echo $imgsize;
                    }
blendercubeMap (){
                    convert $left $back $right +append cubeUp.tif;
                    convert $down $up $front +append cubeDown.tif;
                    convert cubeUp.tif cubeDown.tif -append toTo.tif;
}

horizontalcross (){
                    montage null: $up null: null: $left $front $right $back null: $down null: null: -geometry $imgsize -background none -tile 4x3 toTo.tif;
}

verticalcross (){
                    convert -rotate 180 $back $back 
                    montage null: $up null: $left $front $right null: $down null: null: $back null: -geometry $imgsize -background none -tile 3x4 toTo.tif;
}

horizontalline (){
                    convert $right $left $up $down $front $back +append toTo.tif;
}

verticalline (){
                    convert $right $left $up $down $front $back -append toTo.tif;
}
                    
finalsize=` zenity --entry --title="Enter Cubemap final height in px" --text="height" --entry-text="4096" `
final=` zenity --list --radiolist --title="3D software cubemap type" --column="Choice" --column="Cubemap"\
                        TRUE "Blender" \
                        FALSE "horizontal-cross" \
                        FALSE "vertical-cross" \
                        FALSE "horizontal-line"\
                        FALSE "vertical-line"`

                case $final in
                        "Blender")
                        order="blendercubeMap";;
                        "horizontal-cross")
                        order="horizontalcross";;
                        "vertical-cross")
                        order="verticalcross";;
                        "horizontal-line")
                        order="horizontalline";;
                        "vertical-line")
                        order="verticalline";;
                        
                        *)
                    esac

while [ $# -gt 0 ]; do
    pano=$1
    echo $pano
    echo "createPano"
    
    createPano
    
    
    #takes each face to create the final image
    $order
    
    convert -resize x$finalsize toTo.tif ${pano%.*}-cubemap.png
    
    rm cubeUp.tif cubeDown.tif toTo.tif cube????.tif cube.pto
    
    shift
    done
    zenity --info --text="DONE"

 

Pass it your panos, then it should result in a lot of .PNG cubemaps ready to use to create game assets inside blend4web or blender game engine ( first option ):

examples :

Equirectangular pano example
Equirectangular pano example
Blender cubemap
Cubemap horizontal cross Blender cubemap
cubemap vertical cross
cubemap vertical cross

 

 

cubemap horizontal line
cubemap horizontal line





Feel free to use those examples and tell me back if I’ve done an error on the other outputs or if you encounter problems to use it . Linux only . Enjoy it , share it .

Example of 360° 4k video with 3d integration

I’m able today to use equirectangular panos for video and photosimulations.
Not only aimed to street views, pro photographers, hdri maps for renderings or games, those 360 panos can be used to produce high quality videomontages.

To get the right scale and topo you have to produce a conformal spherical view, with a horizon error < 0.05 degrees.
It has been georeferenced with a real topo grid; you can use the srtm if you want but it can be done with almost 5 points.
I made this really quick sequence with blender 2.76 , make it loop or pause it to navigate.

PS: Visualize it with chrome browser to display 360 video effect.

Opensource panorama viewer: Panovisu 1.3

Nowadays opensource alternatives for html5 panorama viewing are at least  2: Pannellum and Panovisu !

Panovisu results of a Frenchs initiative  : not only it displays your  equirectangular or cubic panos, but you can make a complete VR tour with its java editor !

You’ll need a very recent java installation on your computer to launch it,  it has been tested on all recent browsers : all webGL activated are ok but Safari ( as far as I know)

Lets link to its website: www.panovisu.fr

I can help to translate if you don’t read or speak french !

 

There a personal demo of mine :

Litte Vr tour in Oudon, Loire Atlantique, france

Enjoy it , let me know any bug or problem, I would back them up to its dev !

Equirectangular panos to cubes with Blender

Baking equirectangular panos to cubes (or whatever you want) with Blender

While playing with Blender I’ve found a way to apply 360 panoramics images on a mesh; what’s the goal ? From my point of view there’s at least 3 :

  1. You can easily unfold the mesh, then print it out to make , hmmm for example,  something like that:  http://www.philohome.com/rhombicuboctahedron/rhombicuboctahedron.htm. This type of tasks normally needs a lot of work , using Hugin, templates .psd files etc etc..
  2. Transform it to a cube , in order to use it in a game.
  3. Playing with map projections ( why not? Should be a great game for geomaticians ;-p )
  4. Lire la suite