Howto:Make full spherical panorama

From FlightGear wiki
Revision as of 12:46, 20 November 2010 by Cri (talk | contribs) (add image example)
Jump to navigation Jump to search

In this howto I will explain how to make full spherical panorama in FlightGear. The semi-automated process is useful for everyone that want to contreibute to the wiki by adding one of this panorama to each aircraft's page in order to display the cockpit. Here is an example of what can be achieved:

A full spherical panorama of the 3d cessna c172p cockpit

The tools

In order to take panorama in flightgear you need:

  • of course Flightgear
  • a panorama stitching tool. I suggest to use Hugin: it's free and very powerful.

The automatic process

To make the process easier I've created a nasal script that capture automagically the required screenshots. This script can be binded to a keyboard key. Also I've created a standard Hugin file to assemble this screenshots into a full spherical panorama.

Taking the required screenshots

The easier way is to bind the following nasal script to a keyboard key (The "F3" key that is used by default to take screenshots). To do this, open the file keyboard.xml that you can find in the fgdata folder with a text editor and look for the following section:

<key n="259">
 <name>F3</name>
 <desc>Capture screen</desc>
 <binding>
  <command>nasal</command>
  <script>
    var success = fgcommand("screen-capture");
    var path = getprop("/sim/paths/screenshot-last");
    if (success)
        gui.popupTip("Screenshot written to '" ~ path ~ "'");
    else
        gui.popupTip("Error writing screenshot '" ~ path ~ "'");
  </script>
 </binding>
 <mod-shift>
  <desc>Load panel</desc>
  <binding>
   <command>panel-load</command>
  </binding>
 </mod-shift>
</key>

Now substitute the nasal code between the <script> tags with this:

       var timeint=3;
       var runs=2;
       
         menubarvalue=getprop("/sim/menubar/visibility");
         znearvalue=("sim/rendering/camera-group/znear");
         fovvalue=getprop("/sim/current-view/field-of-view");
         freezemvalue=getprop("/sim/freeze/master");
         freezecvalue=getprop("/sim/freeze/clock");
         headingvalue=getprop("/sim/current-view/heading-offset-deg");
         pitchvalue=getprop("/sim/current-view/pitch-offset-deg");
         
       setprop("/sim/screenshots/runs", runs);
       setprop("/sim/menubar/visibility", 'false');
       setprop("/sim/rendering/camera-group/znear",0.03);
       setprop("/sim/current-view/field-of-view", 120);
       setprop("/sim/freeze/master",'true');
       setprop("/sim/freeze/clock",'true');
       
       var takescreen = func(n,k) {
         var runs=getprop("/sim/screenshots/runs");
         if ( n > 0 ) {          
           var panofov = getprop("/sim/current-view/field-of-view");
           setprop("/sim/current-view/heading-offset-deg", n*90);
           setprop("/sim/current-view/pitch-offset-deg", k);
             settimer( func { var success = fgcommand("screen-capture");
               if (success) { 
                 print ("screen taken with heading= ",n*90 ," and pitch= ", k);
                 takescreen(n-1,k);
               } else {
                  print("screen not taken");}
              }, timeint, timeint );
         }
       }
 var scr_runs = func {
   var runs_left = getprop("/sim/screenshots/runs");
   print("run: ", runs_left);
     if (runs_left > 0) {
       if(runs_left > 1){
         setprop("/sim/screenshots/runs", runs_left-1);
         print("runs_left-1 =",runs_left-1);
         takescreen(4,-45);
       }else{
         setprop("/sim/screenshots/runs", runs_left-1);
         print("runs_left-1 =",runs_left-1);
         takescreen(4,45);
       }
       settimer(scr_runs, timeint*5, timeint*5);
     }else{
       setprop("/sim/menubar/visibility", menubarvalue);
       setprop("/sim/current-view/field-of-view", fovvalue);
       setprop("/sim/current-view/heading-offset-deg", headingvalue);
       setprop("/sim/current-view/pitch-offset-deg", pitchvalue);
       setprop("/sim/freeze/master", freezemvalue);
       setprop("/sim/freeze/clock", freezecvalue);
     }
    }
scr_runs();

Now you are ready to start Flightgear but in order to use efficiently this script and the provided Hugin file you need to set the video format to 4/3 (800x600, 1024x768, 1200x900, 1600x1200...). When in the game press the "F3" key and wait. You will see the camera changing heading and pitch automatically. When the required screenshots are taken, the original view is restored. Now exit flightgear, look for saved screenshots in png format and follow the next step.

Stitching the panorama with Hugin

Copy all the eight screenshots in a new folder named as you want. Open this folder and create in it a new text file called panorama.pto. Open this file and copy the following lines in it:

# hugin project file
#hugin_ptoversion 2
p f2 w3000 h1500 v360  E0 R0 n"TIFF_m c:LZW r:CROP"
m g1 i0 f0 m2 p0.00784314
 
# image lines
#-hugin  cropFactor=1
i w800 h600 f0 v120 Ra0 Rb0 Rc0 Rd0 Re0 Eev0 Er1 Eb1 r0 p-45 y0 TrX0 TrY0 TrZ0 j0 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 v=0 Ra=0 Rb=0 Rc=0 Rd=0 Re=0 Eev0 Er1 Eb1 r0 p45 y180 TrX0 TrY0 TrZ0 j0 a=0 b=0 c=0 d=0 e=0 g=0 t=0 Va=0 Vb=0 Vc=0 Vd=0 Vx=0 Vy=0  Vm5 u10 n"fgfs-screen-007.png"
#-hugin  cropFactor=1
i w800 h600 f0 v=0 Ra=0 Rb=0 Rc=0 Rd=0 Re=0 Eev0 Er1 Eb1 r0 p45 y270 TrX0 TrY0 TrZ0 j0 a=0 b=0 c=0 d=0 e=0 g=0 t=0 Va=0 Vb=0 Vc=0 Vd=0 Vx=0 Vy=0  Vm5 u10 n"fgfs-screen-008.png"


# specify variables that should be optimized
v r1
v p1
v y1
v r2
v p2
v y2
v r3
v p3
v y3
v r4
v p4
v y4
v r5
v p5
v y5
v r6
v p6
v y6
v r7
v p7
v y7
v 


# control points

#hugin_optimizeReferenceImage 0
#hugin_blender enblend
#hugin_remapper nona
#hugin_enblendOptions 
#hugin_enfuseOptions 
#hugin_hdrmergeOptions -m avg -c
#hugin_outputLDRBlended true
#hugin_outputLDRLayers false
#hugin_outputLDRExposureRemapped false
#hugin_outputLDRExposureLayers false
#hugin_outputLDRExposureBlended false
#hugin_outputLDRExposureLayersFused false
#hugin_outputHDRBlended false
#hugin_outputHDRLayers false
#hugin_outputHDRStacks false
#hugin_outputLayersCompression LZW
#hugin_outputImageType jpg
#hugin_outputImageTypeCompression LZW
#hugin_outputJPEGQuality 100
#hugin_outputImageTypeHDR exr
#hugin_outputImageTypeHDRCompression LZW 

Save the file and open it with Hugin. In Hugin go to the "stitching" tab and press the "Stitch Now" button. You will be asked where to save the resulting image. Select a path and press ok. When Hugin terminates the stitching process you are done. Browse to where you told Hugin to save the panorama, and take a look at the image to check if something went wrong.