Howto:Convert objects from X-Plane: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(after rewriting converter scripts, they are now ready for early production use. Re-written documentation to reflect new usage.)
m (Formatting)
Line 1: Line 1:
This [[:Category:Howto|tutorial]] explains how to '''convert X-Plane (R) scenery objects''' to the [[File_Formats#.2A.ac|AC3D format]] (.ac) used by [[FlightGear]] (mostly) automatically using the xplane2fg collection of scripts. They were developed on Linux and should work fine on any Unix system including Mac (note to Windows users).
This [[:Category:Howto|tutorial]] explains how to '''convert X-Plane (R) scenery objects''' to the [[File_Formats#.2A.ac|AC3D format]] (.ac) used by [[FlightGear]] (mostly) automatically using the xplane2fg collection of scripts. They were developed on Linux and should work fine on any Unix system including Mac ([[Howto:_Convert_objects_from_MSFS#Note_to_Windows_Users|note to Windows users]]). Don't hesitate to PM me to obtain the package until I find a place to host it somewhere.
 
The conversation consists of three steps, all conveniently handled by scripts:
* convert the actual 3-D objects from .obj to .ac format using blender,
* extract position of objects (longitude, latitude, altitude, and heading) from .dsf file(s) and write them to FlightGear's .stg file(s),
* copy the objects and their textures to the respective tile folders.


This Howto assumes that you
This Howto assumes that you
Line 7: Line 12:
'''Please note: objects that are uploaded to the [[FlightGear Scenery Database]] (and thus official FG scenery) must be released under the [[GNU GPL]] license. Most MSFS scenery does ''not'' comply with this license. Therefore, it cannot be included with the official scenery, unless the author granted you permission to release his work under GNU GPL.'''
'''Please note: objects that are uploaded to the [[FlightGear Scenery Database]] (and thus official FG scenery) must be released under the [[GNU GPL]] license. Most MSFS scenery does ''not'' comply with this license. Therefore, it cannot be included with the official scenery, unless the author granted you permission to release his work under GNU GPL.'''


 
= Installation and setup =
== Conversation in three easy steps ==
== Prerequisites ==
The conversation consists of three steps, all conveniently handled by scripts:
* convert the actual 3-D objects from .obj to .ac format using blender,
* extract position of objects (longitude, latitude, altitude, and heading) from .dsf file(s) and write them to FlightGear's .stg file(s),
* copy the objects and their textures to the respective tile folders.
 
== Installation and setup ==
 
= Prerequisites =
Besides a Unix environment, you'll need the following additional tools:
Besides a Unix environment, you'll need the following additional tools:


Line 24: Line 21:
* X-Plane scenery tools (officially from xplane)
* X-Plane scenery tools (officially from xplane)
* FlightGear
* FlightGear
* perl helpers from FlightGear's src/
* perl helpers from FlightGear's source code:
  ** calc-tile.pl
** calc-tile.pl
  ** find_elevations.pl
** find_elevations.pl
* telnet
* telnet


Line 32: Line 29:
* convert (from [http://www.imagemagick.org ImageMagick])
* convert (from [http://www.imagemagick.org ImageMagick])


= Installation =
== Installation ==
 
Install xplane2fg:
Install xplane2fg:


# mkdir -p ~/fgfs/convert/
mkdir -p ~/fgfs/convert/
# cd ~/fgfs/convert/
cd ~/fgfs/convert/
# tar xzf /path/to/xplane2fg.tgz
tar xzf /path/to/xplane2fg.tgz


Copy autoimport helper to Blender's scripts folder:
Copy the autoimport.py helper to Blender's scripts folder:
# cp ~/fgfs/convert/xplane2fg/lib/autoimport.py ~/blender/scripts
cp ~/fgfs/convert/xplane2fg/lib/autoimport.py ~/blender/scripts


Install X-Plane tools in $HOME/convert/xptools
Install X-Plane tools in $HOME/convert/xptools


 
== Hack the tools ==
= Hack the tools =
For the first step - importing objects into blender - we use Jonathan Harris' XPlane2Blender import filter. The .ac export filter shipped with Blender does the export. As we will batch convert a large number of objects, both import and export filters need to be 'hacked' as to not stop and wait for user interaction on warnings etc:
 
For the first step -- importing objects into blender -- we use Jonathan Harris's XPlane2Blender import filter. The .ac export filter shipped with Blender does the export. As we will batch convert a large number of objects, both import and export filters need to be 'hacked' as to not stop and wait for user interaction on warnings etc:


Open XPlaneImport.py in a text editor, change line 466 (of ver. 3.09) to:  
Open XPlaneImport.py in a text editor, change line 466 (of ver. 3.09) to:  
# self.verbose = 0
self.verbose = 0
Save this file as XPlaneImportVerbose0.py
Save this file as XPlaneImportVerbose0.py


Open ac3d_export.py (part of Blender, located for example in /usr/share/blender/scripts/) in a text editor, replace line 823:  
Open ac3d_export.py (part of Blender, located for example in /usr/share/blender/scripts/) in a text editor, replace line 823:  
#      Blender.Draw.PupMenu('ERROR: no objects selected')
Blender.Draw.PupMenu('ERROR: no objects selected')
with  
with  
#      pass
pass
Make sure you keep indention. Save this file as ac3d_export_hack.py
Make sure you keep indention. Save this file as ac3d_export_hack.py


 
== Setting up the environment according to your system ==
= Setting up the environment according to your system =
 
The xplane2fg scripts glue together a number of tools. To have the scripts find these tools, you have to adjust the paths in $HOME/fgfs/convert/xplane2fg/profile according to your system (using a text editor).
The xplane2fg scripts glue together a number of tools. To have the scripts find these tools, you have to adjust the paths in $HOME/fgfs/convert/xplane2fg/profile according to your system (using a text editor).


Now everything should be set up to actually convert scenery!
Now everything should be set up to actually convert scenery!


== Conversation ==
= Conversation =
 
First load xplane2fg's environment profile:
Load xplane2fg's environment profile:
  source $HOME/fgfs/convert/xplane2fg/profile
# source $HOME/fgfs/convert/xplane2fg/profile
 
 
= Prepare X-Plane scenery =


== Prepare X-Plane scenery ==
In the following, we assume the X-Plane scenery we want to convert is named EDDN and lives in
In the following, we assume the X-Plane scenery we want to convert is named EDDN and lives in
   $HOME/fgfs/convert/EDDN/
   $HOME/fgfs/convert/EDDN/
Line 84: Line 73:
Those sub folders may have slightly different names. If so, rename them to fit the above scheme. Remember that Unix file names are case sensitive.
Those sub folders may have slightly different names. If so, rename them to fit the above scheme. Remember that Unix file names are case sensitive.


= Prepare FlightGear =
== Prepare FlightGear ==
 
X-Plane objects are positioned using [http://en.wikipedia.org/wiki/Above_ground_level AGL], while FlightGear's .stg files expect [http://en.wikipedia.org/wiki/Above_mean_sea_level AMSL]. We will use FlightGear to automatically query the elevation at the object's postition. Therefore, the corresponding scenery tile must be installed. Find out on which tile the scenery you want to convert is located. See [[Howto:_Install_scenery]] for details on how to install FlightGear scenery. The most convenient way may be to use [[TerraSync]].
X-Plane objects are positioned using AGL, while FlightGear's .stg files expect MSL. We will use FlightGear to automatically query the elevation at the object's postition. Therefore, the corresponding scenery tile must be installed. Find out on which tile the scenery you want to convert is located. See XXX for details on how to install FlightGear scenery. The most convenient way may be to use terrasync.
 
= Convert =


== Convert ==
Now run the main conversation script:
Now run the main conversation script:
# cd $HOME/fgfs/convert/
cd $HOME/fgfs/convert/
# xplane2fg.sh  EDDN  EDDN.fg
xplane2fg.sh  EDDN  EDDN.fg


The converted scenery will be written to the path indicated by the second argument, EDDN.fg. It should *not* point to FG's actual scenery paths.
The converted scenery will be written to the path indicated by the second argument, EDDN.fg. It should '''not''' point to FG's actual scenery paths.


After some seconds, this will stop and ask you to run blender. By that time, it  
After some seconds, this will stop and ask you to run blender. By that time, it should have created an input file for blender named
should have created an input file for blender named
blender-autoimport-source.py
# blender-autoimport-source.py
in the current directory.
in the current directory.
    
    
Now open a second terminal and run blender from that directory.
Now open a second terminal and run blender from that directory.
# cd $HOME/fgfs/convert
cd $HOME/fgfs/convert
# blender
blender
 
 
Click file -> import -> autoimport
Click file -> import -> autoimport, it should now convert all objects, this may take a while.
It should now convert all objects, this may take a while.
When finished, close blender (and the second terminal), and press enter in the xplane2fg terminal.
When finished, close blender (and the second terminal), and press enter in the xplane2fg terminal.
    
    
Line 114: Line 99:
    
    
When xplane2fg is finished, you should have something like
When xplane2fg is finished, you should have something like
$HOME/fgfs/convert/EDDN.fg/
  ls $HOME/fgfs/convert/EDDN.fg/Objects/e000n40/e006n46/
#    Objects/e000n40/e006n46/
      3056136.stg
#      3056136.stg
      3056139.stg
#      3056139.stg
      Terminal.ac
#      Terminal.ac
      ...
#      ...


We're almost done!
We're almost done!


= Check textures =
== Check textures ==
 
X-Plane may use .dds textures, which have to be converted to .png format.
X-Plane may use .dds textures, which have to be converted to .png format.
Go to the converted scenery folder
Go to the converted scenery folder
# cd EDDN.fg/Objects/e000n40/e006n46/
cd EDDN.fg/Objects/e000n40/e006n46/
and run
and run
# check_and_fix_textures.sh  *.ac
check_and_fix_textures.sh  *.ac
You may want to remove .dds files afterwards to save space:
You may want to remove .dds files afterwards to save space:
# rm *.dds
rm *.dds
 
= Integrate the converted files into FlightGear scenery =


== Integrate the converted files into FlightGear scenery ==
Finally you have to copy the converted scenery to FlightGear's scenery folder. Make sure to backup the respective scenery folder beforehand.
Finally you have to copy the converted scenery to FlightGear's scenery folder. Make sure to backup the respective scenery folder beforehand.


The .stg files should be *appended* instead of overwritten should they exist already in FlightGear's Scenery folder; otherwise you'll loose previously defined scenery objects. You may want to use a file manager such as Konqueror, Nautilus, or Midnight Commander for this step, as they tend to ask whether to overwrite or append existing files.
The .stg files should be '''appended''' instead of overwritten should they exist already in FlightGear's Scenery folder; otherwise you'll lose previously defined scenery objects. You may want to use a file manager such as Konqueror, Nautilus, or Midnight Commander for this step, as they tend to ask whether to overwrite or append existing files.


Now you can fire up FlightGear and enjoy the converted scenery!
Now you can fire up FlightGear and enjoy the converted scenery!


= Cleanup =
= Final steps =
 
== Cleanup ==
Temporary files were written to $HOME/fgfs/convert/tmp. You can remove them now:
Temporary files were written to $HOME/fgfs/convert/tmp. You can remove them now:
# rm -rf $HOME/fgfs/convert/tmp
rm -rf $HOME/fgfs/convert/tmp
 
 
= Share the converted scenery =


== Share the converted scenery ==
If you want to publish the scenery you need to obtain authorization to do so from the scenery's original authors.
If you want to publish the scenery you need to obtain authorization to do so from the scenery's original authors.


If you want it to be included in FlightGear's official scenery, the converted scenery (including all textures) must comply with the GPL.
If you want it to be included in FlightGear's official scenery via the [[FlightGear Scenery Database]], the converted scenery (including all textures) must comply with the [[GNU GPL]].
 
 
= Optional =
 


== Optional ==
You may use
You may use


# xplane2fg.sh --prefix EDDN_  EDDN  EDDN.fg
xplane2fg.sh --prefix EDDN_  EDDN  EDDN.fg


to prepend all converted objects with a prefix, e.g., EDDN_objectname.ac
to prepend all converted objects with a prefix, e.g., EDDN_objectname.ac


 
== Troubleshooting ==
= Troubleshooting =
 
 
xplane2fg.sh may complain about funny elevations reported by FlightGear:
xplane2fg.sh may complain about funny elevations reported by FlightGear:


# WARNING: Zero alt for LSGS-grasss-1.ac?
WARNING: Zero alt for LSGS-grasss-1.ac?
   
   
I suspect this happens when a tile is just being loaded in background, as subsequent calls would return correct elevation. However, since we might query objects floating on water, I did not implement automatic retrying (yet). Instead, you should manually query these objects. Start Flightgear
I suspect this happens when a tile is just being loaded in background, as subsequent calls would return correct elevation. However, since we might query objects floating on water, I did not implement automatic retrying (yet). Instead, you should manually query these objects. Start Flightgear


# xplane2fg.sh --run-fgfs
xplane2fg.sh --run-fgfs


then run
then run


# xplane2fg.sh --query-alt LSGS-grasss-1.ac
xplane2fg.sh --query-alt LSGS-grasss-1.ac


which would return something like
which would return something like


# OBJECT_STATIC LSGS-grasss-1.ac 7.3416857 46.2201743 482.24 357.99
OBJECT_STATIC LSGS-grasss-1.ac 7.3416857 46.2201743 482.24 357.99
# in /e000n40/e007n46/3072521.stg
in /e000n40/e007n46/3072521.stg


and correct the respective line in the indicated .stg file.
and correct the respective line in the indicated .stg file.


 
== Note to windows Users ==
= Note to windows users =
 
I developed these scripts on Linux. They are written in bash and make heavy use of GNU utilities (sed, awk, grep etc.). Some helpers require Perl.  
I developed these scripts on Linux. They are written in bash and make heavy use of GNU utilities (sed, awk, grep etc.). Some helpers require Perl.  
To run these scripts on Windows, you will need to install cygwin and perl (at least). You will have to fix some further issues yourself; the wine part, for example, is probably not neccessary on Windows ;)
To run these scripts on Windows, you will need to install cygwin and perl (at least). You will have to fix some further issues yourself; the wine part, for example, is probably not neccessary on Windows ;)

Revision as of 20:17, 26 December 2010

This tutorial explains how to convert X-Plane (R) scenery objects to the AC3D format (.ac) used by FlightGear (mostly) automatically using the xplane2fg collection of scripts. They were developed on Linux and should work fine on any Unix system including Mac (note to Windows users). Don't hesitate to PM me to obtain the package until I find a place to host it somewhere.

The conversation consists of three steps, all conveniently handled by scripts:

  • convert the actual 3-D objects from .obj to .ac format using blender,
  • extract position of objects (longitude, latitude, altitude, and heading) from .dsf file(s) and write them to FlightGear's .stg file(s),
  • copy the objects and their textures to the respective tile folders.

This Howto assumes that you

  • are able to use the command line to enter basic commands
  • know where FlightGear, its scenery, and its source code are installed

Please note: objects that are uploaded to the FlightGear Scenery Database (and thus official FG scenery) must be released under the GNU GPL license. Most MSFS scenery does not comply with this license. Therefore, it cannot be included with the official scenery, unless the author granted you permission to release his work under GNU GPL.

Installation and setup

Prerequisites

Besides a Unix environment, you'll need the following additional tools:

  • Blender (tested with ver. 2.48a-r3)
  • XPlane2blender from Jonathan Harris' page, tested with ver. 3.09
  • Wine
  • X-Plane scenery tools (officially from xplane)
  • FlightGear
  • perl helpers from FlightGear's source code:
    • calc-tile.pl
    • find_elevations.pl
  • telnet

Optionally (if the scenery to convert contains .dds textures)

Installation

Install xplane2fg:

mkdir -p ~/fgfs/convert/
cd ~/fgfs/convert/
tar xzf /path/to/xplane2fg.tgz

Copy the autoimport.py helper to Blender's scripts folder:

cp ~/fgfs/convert/xplane2fg/lib/autoimport.py ~/blender/scripts

Install X-Plane tools in $HOME/convert/xptools

Hack the tools

For the first step - importing objects into blender - we use Jonathan Harris' XPlane2Blender import filter. The .ac export filter shipped with Blender does the export. As we will batch convert a large number of objects, both import and export filters need to be 'hacked' as to not stop and wait for user interaction on warnings etc:

Open XPlaneImport.py in a text editor, change line 466 (of ver. 3.09) to:

self.verbose = 0

Save this file as XPlaneImportVerbose0.py

Open ac3d_export.py (part of Blender, located for example in /usr/share/blender/scripts/) in a text editor, replace line 823:

Blender.Draw.PupMenu('ERROR: no objects selected')

with

pass

Make sure you keep indention. Save this file as ac3d_export_hack.py

Setting up the environment according to your system

The xplane2fg scripts glue together a number of tools. To have the scripts find these tools, you have to adjust the paths in $HOME/fgfs/convert/xplane2fg/profile according to your system (using a text editor).

Now everything should be set up to actually convert scenery!

Conversation

First load xplane2fg's environment profile:

source $HOME/fgfs/convert/xplane2fg/profile

Prepare X-Plane scenery

In the following, we assume the X-Plane scenery we want to convert is named EDDN and lives in

 $HOME/fgfs/convert/EDDN/

with the following sub folders

   Earth nav data
   objects
   textures

Those sub folders may have slightly different names. If so, rename them to fit the above scheme. Remember that Unix file names are case sensitive.

Prepare FlightGear

X-Plane objects are positioned using AGL, while FlightGear's .stg files expect AMSL. We will use FlightGear to automatically query the elevation at the object's postition. Therefore, the corresponding scenery tile must be installed. Find out on which tile the scenery you want to convert is located. See Howto:_Install_scenery for details on how to install FlightGear scenery. The most convenient way may be to use TerraSync.

Convert

Now run the main conversation script:

cd $HOME/fgfs/convert/
xplane2fg.sh  EDDN  EDDN.fg

The converted scenery will be written to the path indicated by the second argument, EDDN.fg. It should not point to FG's actual scenery paths.

After some seconds, this will stop and ask you to run blender. By that time, it should have created an input file for blender named

blender-autoimport-source.py

in the current directory.

Now open a second terminal and run blender from that directory.

cd $HOME/fgfs/convert
blender

Click file -> import -> autoimport, it should now convert all objects, this may take a while. When finished, close blender (and the second terminal), and press enter in the xplane2fg terminal.

xplane2fg will now fire up FlightGear. Press enter when FlightGear is up and running. The script then queries the elevation for all objects; this might take a while. During this process, .stg files are written to their respective tile paths under EDDN.fg. Also, xplane2fg searches for texture files used by the scenery objects, copies them to EDDN.fg or complains in case they're missing.

When xplane2fg is finished, you should have something like

 ls $HOME/fgfs/convert/EDDN.fg/Objects/e000n40/e006n46/
     3056136.stg
     3056139.stg
     Terminal.ac
     ...

We're almost done!

Check textures

X-Plane may use .dds textures, which have to be converted to .png format. Go to the converted scenery folder

cd EDDN.fg/Objects/e000n40/e006n46/

and run

check_and_fix_textures.sh  *.ac

You may want to remove .dds files afterwards to save space:

rm *.dds

Integrate the converted files into FlightGear scenery

Finally you have to copy the converted scenery to FlightGear's scenery folder. Make sure to backup the respective scenery folder beforehand.

The .stg files should be appended instead of overwritten should they exist already in FlightGear's Scenery folder; otherwise you'll lose previously defined scenery objects. You may want to use a file manager such as Konqueror, Nautilus, or Midnight Commander for this step, as they tend to ask whether to overwrite or append existing files.

Now you can fire up FlightGear and enjoy the converted scenery!

Final steps

Cleanup

Temporary files were written to $HOME/fgfs/convert/tmp. You can remove them now:

rm -rf $HOME/fgfs/convert/tmp

Share the converted scenery

If you want to publish the scenery you need to obtain authorization to do so from the scenery's original authors.

If you want it to be included in FlightGear's official scenery via the FlightGear Scenery Database, the converted scenery (including all textures) must comply with the GNU GPL.

Optional

You may use

xplane2fg.sh --prefix EDDN_  EDDN  EDDN.fg

to prepend all converted objects with a prefix, e.g., EDDN_objectname.ac

Troubleshooting

xplane2fg.sh may complain about funny elevations reported by FlightGear:

WARNING: Zero alt for LSGS-grasss-1.ac?

I suspect this happens when a tile is just being loaded in background, as subsequent calls would return correct elevation. However, since we might query objects floating on water, I did not implement automatic retrying (yet). Instead, you should manually query these objects. Start Flightgear

xplane2fg.sh --run-fgfs

then run

xplane2fg.sh --query-alt LSGS-grasss-1.ac

which would return something like

OBJECT_STATIC LSGS-grasss-1.ac 7.3416857 46.2201743 482.24 357.99
in /e000n40/e007n46/3072521.stg

and correct the respective line in the indicated .stg file.

Note to windows Users

I developed these scripts on Linux. They are written in bash and make heavy use of GNU utilities (sed, awk, grep etc.). Some helpers require Perl. To run these scripts on Windows, you will need to install cygwin and perl (at least). You will have to fix some further issues yourself; the wine part, for example, is probably not neccessary on Windows ;)