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

Jump to navigation Jump to search
Larger copyedit
m (Announce new scripts)
(Larger copyedit)
Line 1: Line 1:
This [[:Category:Howto|tutorial]] explains how to '''convert X-Plane scenery objects''' to the [[File Formats#.2A.ac|AC3D format]] (.ac) used by [[FlightGear]] (mostly) automatically using the xplane2fg collection of scripts. To convert '''Microsoft (R) Flight Simulator scenery objects''', first convert them to X-Plane format using [http://marginal.org.uk/x-planescenery/tools.html FS2XPlane], then follow the method described below.
This [[:Category:Howto|tutorial]] explains how to '''convert X-Plane scenery objects''' to the [[File Formats#.2A.ac|AC3D format]] (.ac) used by [[FlightGear]] (mostly) automatically using the xplane2fg collection of scripts.


'''Note: [[Howto:Convert objects with ModelConverterX|ModelConverterX]] also seems well suited for this task, having even more features and is probably easier to set up.'''
To convert ''Microsoft® Flight Simulator scenery objects'', first convert them to X-Plane format using [http://marginal.org.uk/x-planescenery/tools.html FS2XPlane], then follow the method described below.


'''Note 2: MCX doesnt't work for me on Linux (tried with Wine + Mono). As of Feb 2015, I'm re-writing conversion scripts. The new version will  come bundled with everything you need, be a lot easier to set-up, and be almost 100% automated.'''
These scripts 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]]).
 
{{note|[[Howto:Convert objects with ModelConverterX|ModelConverterX]] also seems well suited for this task, having even more features and is probably easier to set up.}}
 
{{note|MCX doesnt't work for me on Linux (tried with Wine + Mono). As of Feb 2015, I'm re-writing conversion scripts. The new version will  come bundled with everything you need, be a lot easier to set-up, and be almost 100% automated.}}


These scripts 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]]).
{{note|Objects that are uploaded to the [[FlightGear Scenery Database]] (and thus official FG scenery) '''must''' be released under the [[GNU GPL]] license.
 
Most X-Plane/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. Basically, it mostly means that it is for your own private use only.}}


The conversion consists of three steps, all conveniently handled by scripts:
== Prerequisites ==
* convert the actual 3-D objects from .obj to .ac format using blender,
This Howto assumes that you:
* 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
* are able to use the command line to enter basic commands
* Know where FlightGear, its scenery, and its source code are installed
* 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 X-Plane/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. Basically, it mostly means that it is for your own private use only.'''
== Conversion steps ==
The conversion 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 ==
== Installation and setup ==
Line 30: Line 37:
* [[FlightGear]]
* [[FlightGear]]
* perl helpers from FlightGear's [http://www.flightgear.org/Downloads/source.shtml source code]:
* perl helpers from FlightGear's [http://www.flightgear.org/Downloads/source.shtml source code]:
** calc-tile.pl
** <code>calc-tile.pl</code>
** find_elevations.pl
** <code>find_elevations.pl</code>
* telnet
* Telnet


Optionally (if the scenery to convert contains .dds textures)
Optionally (if the scenery to convert contains .dds textures)
* convert (from [http://www.imagemagick.org ImageMagick])
* Convert (from [http://www.imagemagick.org ImageMagick])


=== Installation ===
=== Installation ===
Install xplane2fg:
Install <code>xplane2fg</code>:
 
<syntaxhighlight lang="bash">
mkdir -p ~/fgfs/convert/
cd ~/fgfs/convert/
tar xzf /path/to/xplane2fg.tgz
</syntaxhighlight>


mkdir -p ~/fgfs/convert/
Copy the <code>autoimport.py</code> helper to Blender's scripts folder:
cd ~/fgfs/convert/
tar xzf /path/to/xplane2fg.tgz


Copy the autoimport.py helper to Blender's scripts folder:
<syntaxhighlight lang="bash">
cp ~/fgfs/convert/xplane2fg/lib/autoimport.py ~/.blender/scripts
cp ~/fgfs/convert/xplane2fg/lib/autoimport.py ~/.blender/scripts
</syntaxhighlight>


Install X-Plane tools in $HOME/convert/xptools
Install X-Plane tools in <code>''$HOME/convert/xptools''</code>


=== 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' 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 <code>XPlaneImport.py</code> in a text editor, change line 466 (of ver. 3.09) to:  
self.verbose = 0
 
Save this file as XPlaneImportVerbose0.py
<syntaxhighlight lang="python">
self.verbose = 0
</syntaxhighlight>
 
Save this file as <code>XPlaneImportVerbose0.py</code>
 
Open <code>ac3d_export.py</code> (part of Blender, located for example in <code>''/usr/share/blender/scripts/''</code>) in a text editor, replace line 823:
 
<syntaxhighlight lang="python">
Blender.Draw.PupMenu('ERROR: no objects selected')
</syntaxhighlight>


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  
with  
pass
 
Make sure you keep indention. Save this file as ac3d_export_hack.py
<syntaxhighlight lang="python">
pass
</syntaxhighlight>
 
''Make sure you keep indention.''
 
Save this file as <code>ac3d_export_hack.py</code>


=== 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 <code>''$HOME/fgfs/convert/xplane2fg/profile''</code> 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!
Line 69: Line 95:
== Conversion ==
== Conversion ==
First load xplane2fg's environment profile:
First load xplane2fg's environment profile:
source $HOME/fgfs/convert/xplane2fg/profile
 
<syntaxhighlight lang="bash">
source $HOME/fgfs/convert/xplane2fg/profile
</syntaxhighlight>


=== Prepare X-Plane scenery ===
=== Prepare X-Plane scenery ===
In the following, we assume the X-Plane scenery we want to convert is named EDDN (make sure it contains no spaces!) and lives in
In the following, we assume the X-Plane scenery we want to convert is named EDDN (make sure it contains no spaces!) and lives in
   $HOME/fgfs/convert/EDDN/
   $HOME/fgfs/convert/EDDN/
with the following sub folders
with the following sub folders
     Earth nav data
     Earth nav data
Line 86: Line 117:
=== Convert ===
=== Convert ===
Now run the main conversion script:
Now run the main conversion 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.
<syntaxhighlight lang="bash">
cd $HOME/fgfs/convert/
xplane2fg.sh  EDDN  EDDN.fg
</syntaxhighlight>


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
The converted scenery will be written to the path indicated by the second argument, <code>EDDN.fg</code>. It should '''not''' point to FG's actual scenery paths.
blender-autoimport-source.py
 
in the current directory.
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 <code>blender-autoimport-source.py</code> 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
blender


Click file -> import -> autoimport, it should now convert all objects, this may take a while.
<syntaxhighlight lang="bash">
cd $HOME/fgfs/convert
blender
</syntaxhighlight>
 
Click file &gt; import &gt; autoimport, it should now convert all objects, this may take a while.
When finished, close blender (and the second terminal), and press {{Key press|Enter}} in the xplane2fg terminal.
When finished, close blender (and the second terminal), and press {{Key press|Enter}} in the xplane2fg terminal.
    
    
xplane2fg will now fire up FlightGear. Press {{Key press|Enter}} when FlightGear is up and running.
xplane2fg will now fire up FlightGear. Press {{Key press|Enter}} when FlightGear is up and running.
The script then queries the elevation for all objects; this might take a while.
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.
During this process, .stg files are written to their respective tile paths under <code>EDDN.fg</code>. Also, xplane2fg searches for texture files used by the scenery objects, copies them to <code>EDDN.fg</code> or complains in case they're missing.
    
    
When xplane2fg is finished, you should have something like
When xplane2fg is finished, you should have something like
<syntaxhighlight lang="bash">
   ls $HOME/fgfs/convert/EDDN.fg/Objects/e000n40/e006n46/
   ls $HOME/fgfs/convert/EDDN.fg/Objects/e000n40/e006n46/
       3056136.stg
       3056136.stg
Line 112: Line 149:
       Terminal.ac
       Terminal.ac
       ...
       ...
</syntaxhighlight>


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


=== Check textures ===
=== Check textures ===
X-Plane may use .dds textures, which '''can''' be converted to .png format. However, following recent discussion on the developers mailing list, FlightGear/OSG can also use .dds textures. Hence, you may also skip this step. I have not tested using .dds textures with FlightGear. Your milage may vary.
X-Plane may use .dds textures, which '''can''' be converted to .png format. However, following recent discussion on the developers mailing list, FlightGear/OSG can also use .dds textures. Hence, you may also skip this step. I have not tested using .dds textures with FlightGear. Your mileage may vary.


Go to the converted scenery folder
Go to the converted scenery folder
cd EDDN.fg/Objects/e000n40/e006n46/
 
<syntaxhighlight lang="bash">
cd EDDN.fg/Objects/e000n40/e006n46/
</syntaxhighlight>
 
and run
and run
check_and_fix_textures.sh  *.ac
 
<syntaxhighlight lang="bash">
check_and_fix_textures.sh  *.ac
</syntaxhighlight>
 
You may want to remove .dds files afterwards to save space:
You may want to remove .dds files afterwards to save space:
rm *.dds
 
<syntaxhighlight lang="bash">
rm *.dds
</syntaxhighlight>


=== Integrate the converted files into FlightGear scenery ===
=== Integrate the converted files into FlightGear scenery ===
Line 134: Line 183:
== Final steps ==
== Final steps ==
=== Cleanup ===
=== Cleanup ===
Temporary files were written to $HOME/fgfs/convert/tmp. You can remove them now:
Temporary files were written to <code>''$HOME/fgfs/convert/tmp''</code>. You can remove them now:
rm -rf $HOME/fgfs/convert/tmp
 
<syntaxhighlight lang="bash">
rm -rf $HOME/fgfs/convert/tmp
</syntaxhighlight>


=== Share the converted scenery ===
=== Share the converted scenery ===
Line 145: Line 197:
You may use
You may use


xplane2fg.sh --prefix EDDN_  EDDN  EDDN.fg
<syntaxhighlight lang="bash">
xplane2fg.sh --prefix EDDN_  EDDN  EDDN.fg
</syntaxhighlight>


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:
<code>xplane2fg.sh</code> may complain about funny elevations reported by FlightGear:
 
<syntaxhighlight lang="bash">
WARNING: Zero alt for LSGS-grasss-1.ac?
</syntaxhighlight>


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
<syntaxhighlight lang="bash">
xplane2fg.sh --run-fgfs
</syntaxhighlight>


then run
then run


xplane2fg.sh --query-alt LSGS-grasss-1.ac
<syntaxhighlight lang="bash">
xplane2fg.sh --query-alt LSGS-grasss-1.ac
</syntaxhighlight>


which would return something like
which would return something like

Navigation menu