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

From FlightGear wiki
Jump to navigation Jump to search
m (wikilinks + categorised + license warning)
(after rewriting converter scripts, they are now ready for early production use. Re-written documentation to reflect new usage.)
Line 1: Line 1:
This [[:Category:Howto|tutorial]] explains how to '''convert Microsoft(R) Flight Simulator (MSFS) scenery objects''' to the [[File_Formats#.2A.ac|AC3D format]] (.ac) used by [[FlightGear]].  
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).


We will use the fs2xplane package by Jonathan Harris to first convert the model from MSFS to X-Plane. Then, we import this X-Plane model in [[Blender]], using the XPlane2Blender import filter (also by Jonathan Harris), from which we export the model to FlightGear's native AC3D format. Finally, we extract the lat/lon coordinates from an xml file, and place the object in FlightGear.
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


This method has been tested OK on a couple of scenery objects made by [http://www.helles-flusi.de Helfried Miersch] for MSFS 2004. I did not test it with models from other sources, yet.
'''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.'''
 
 
== Conversation in three easy steps ==
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:
 
* [http://www.blender.org Blender] (tested with ver. 2.48a-r3)
* XPlane2blender from [http://marginal.org.uk/x-planescenery/tools.html Jonathan Harris' page], tested with ver. 3.09
* [http://winehq.com Wine]
* X-Plane scenery tools (officially from xplane)
* FlightGear
* perl helpers from FlightGear's src/
  ** calc-tile.pl
  ** find_elevations.pl
* telnet
 
Optionally (if the scenery to convert contains .dds textures)
* convert (from [http://www.imagemagick.org ImageMagick])


I've written some bash scripts to ease the conversation a bit. They have been tested on Gentoo Linux. I have no idea about Windows or Mac scripting, however, the manual procedure of conversation should work on Windows, Mac and Linux.
= Installation =


'''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.'''
Install xplane2fg:


==What do we need?==
# mkdir -p ~/fgfs/convert/
You will need the following tools:
# cd ~/fgfs/convert/
# tar xzf /path/to/xplane2fg.tgz


* an X-Plane installation (demo works for me)
Copy autoimport helper to Blender's scripts folder:
* [http://www.blender.org Blender] (tested on ver. 2.48a-r3)
# cp ~/fgfs/convert/xplane2fg/lib/autoimport.py ~/blender/scripts
* XPlane2Blender (ver 3.09) and fs2xplane (ver 3.11) from [http://marginal.org.uk/x-planescenery/tools.html Jonathan Harris' page]
* FlightGear source
* and, of course, a MSFS scenery to convert. As an example, I will use a model of [http://en.wikipedia.org/wiki/Blue_Wonder "Das Blaue Wunder"] (The Blue Wonder), a historic bridge over the Elbe river in Dresden, Germany. It has been created by Helfried Miersch, you may get it [http://www.helles-flusi.de/index.php/DD-Weitere_19.html here]. Scroll down to the bottom and download "Blaues Wunder Dresden" and "Blaues Wunder_mdl_xml".


Plus, if you want to semi-automate things using my bash msfs2ac scripts (PM until I found a place to host them), you will need
Install X-Plane tools in $HOME/convert/xptools
* xte from Steve Slaven's xautomation package.


== Semi-automatic conversion using msfs2ac.sh ==


For the impatient, here's how you convert the model semi-automatically using my scripts. You will find the manual step-by-step tutorial below.
= Hack the tools =


Since I couldn't find an easy way to control blender from the command line, I decided to do a really dirty hack: emulate mouse clicks and key strokes using "xte" from Steve Slaven's xautomation package. Of course, this has some serious limitations: we rely heavily on the exact Blender screen/menu layout I hacked into the script. I'm sure there's a better solution. Feel free to enlighten me.
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:


Unpack the scripts somewhere, cd there. You should have the following files
Open XPlaneImport.py in a text editor, change line 466 (of ver. 3.09) to:
# self.verbose = 0
Save this file as XPlaneImportVerbose0.py


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


Adjust the paths in msfs2ac.profile according to your setup:


* [[$FG_SRC|FG_SRC]] must point to your FlightGear source,
= Setting up the environment according to your system =
* XPLANE must point to the X-Plane custom scenery folder, e.g.


# cat msfs2ac.profile
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).
export FG_SRC=/home/tom/daten/fgfs/src-release/fg-cvs/
export XPLANE="/home/tom/X-Plane 9 Demo/Custom Scenery/"


Install fs2xplane here. This should add a directory lib/ plus some files in bin/.
Now everything should be set up to actually convert scenery!


Now we are ready to convert a MSFS scenery:
== Conversation ==


place the MSFS scenery .zip-files here. Continuing the above example:
Load xplane2fg's environment profile:
  # mv ~/downloads/Bluewonder.zip ~/downloads/Bluewonder_MDL_XML.zip .
# source $HOME/fgfs/convert/xplane2fg/profile


Load environment variables and path:


# source msfs2ac.profile
= Prepare X-Plane scenery =


Open your default web browser, move it to the bottom right corner of your screen, covering as little screen area as possible, but do not minimize it! Shut down all applications that could steal focus, and run the conversation script:
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


# msfs2ac.sh -1 Bluewonder.zip
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.


The -1 switch tells the script to pack all objects found in Bluewonder.zip into a single output file named Bluewonder.ac.
= Prepare FlightGear =


This will fire up Blender. Do not touch the mouse nor keyboard until blender closes again. Import and Export of a single model might take some 30 seconds or so. You should now have a new folder containing the convertes model:
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.


# ls -l fgfs/Bluewonder/
= Convert =
total 220
-rw-r--r-- 1 tom users 218247 2010-05-03 00:04 Bluewonder.ac
lrwxrwxrwx 1 tom users    58 2010-05-03 00:03 objects -> /home/tom/X-Plane 9 Demo/Custom Scenery/Bluewonder/objects


Have a first look at it,
Now run the main conversation script:
# cd $HOME/fgfs/convert/
# xplane2fg.sh  EDDN  EDDN.fg


# osgviewer fgfs/Bluewonder/Bluewonder.ac
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.
osgDB ac3d reader: could not find texture "Bluewonder.png"
osgDB ac3d reader: could not find texture "Bruehl.png"


it should look like this:
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
#  $HOME/fgfs/convert/EDDN.fg/
#    Objects/e000n40/e006n46/
#      3056136.stg
#      3056139.stg
#      Terminal.ac
#      ...


[[File:bluewonder_untextured.jpg]]
We're almost done!


Copy the missing textures:
= Check textures =


# cp fgfs/Bluewonder/objects/Bluewonder.png fgfs/Bluewonder/
X-Plane may use .dds textures, which have to be converted to .png format.
  # cp fgfs/Bluewonder/objects/Bruehl.png fgfs/Bluewonder/
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


Now you model should be textured nicely:
= Integrate the converted files into FlightGear scenery =


[[File:bluewonder_textured.jpg]]
Finally you have to copy the converted scenery to FlightGear's scenery folder. Make sure to backup the respective scenery folder beforehand.


Last, we need to extract the coordinates of the model and generate a .stg line for placement in FlightGear. Run:
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.


# unzip -d msfs/Bluewonder/ Bluewonder_MDL_XML.zip
Now you can fire up FlightGear and enjoy the converted scenery!
# xml2stg.sh msfs/Bluewonder/Bluewonder.XML


OBJECT_STATIC Bluewonder.ac            13.8101 51.0535 0  238.5            # e010n50/e013n51/3171139.stg
= Cleanup =


The third number is the object's altitude. In Bluewonder.XML it is given [http://en.wikipedia.org/wiki/Above_ground_level AGL], however, in FlightGear, it is [http://en.wikipedia.org/wiki/Above_mean_sea_level MSL], so we have to guesstimate and correct it later on [[Howto: Place 3D objects with the UFO|using the UFO]] or, even better, [[Howto:_Calculate_elevations|query the actual elevation]]. A good guess here is 120.
Temporary files were written to $HOME/fgfs/convert/tmp. You can remove them now:
# rm -rf $HOME/fgfs/convert/tmp


Add this line to FlightGear's [[$FG_SCENERY]]/Objects/e010n50/e013n51/3171139.stg file and move the model and textures from fgfs/Bluewonder to FlightGear's [[$FG_SCENERY]]/Objects/e010n50/e013n51/ folder.


Now fire up fgfs --airport=EDDC and fly about 4.5 nm hdg 145. You should find this:
= Share the converted scenery =


[[File:bluewonder_in_FG.jpg]]
If you want to publish the scenery you need to obtain authorization to do so from the scenery's original authors.


== 2. Step-by-step ==
If you want it to be included in FlightGear's official scenery, the converted scenery (including all textures) must comply with the GPL.


'''todo'''


get
= Optional =
Bluewonder.zip
Bluewonder_MDL_XML.zip


from helles-flusi.de


You may use


mkdir -p msfs/Bluewonder
# xplane2fg.sh --prefix EDDN_  EDDN EDDN.fg
mkdir -p fgfs/Bluewonder
unzip -d msfs/Bluewonder Bluewonder.zip
Archive: Bluewonder.zip
  creating: msfs/Bluewonder/Scenery/
  creating: msfs/Bluewonder/Texture/
  inflating: msfs/Bluewonder/Bluewonder.txt
  inflating: msfs/Bluewonder/Copyright.txt
  inflating: msfs/Bluewonder/Scenery/Bluewonder.BGL
  inflating: msfs/Bluewonder/Texture/Bluewonder_LM.bmp
  inflating: msfs/Bluewonder/Texture/Bluewonder.bmp
  inflating: msfs/Bluewonder/Texture/Bruehl.bmp
  inflating: msfs/Bluewonder/Texture/Bruehl_LM.bmp


bin/fs2xp $PWD/msfs/Bluewonder/  "~/X-Plane 9 Demo/Custom Scenery/Bluewonder"
to prepend all converted objects with a prefix, e.g., EDDN_objectname.ac


fire up blender


File->Import->X-Plane Object (.obj)
= Troubleshooting =
navigate to X-Planes Custom scenery/Bluewonder/objects,
import 19111954103466011120071138347272-Bluewonder.obj


export:
File->Export->AC3D (.ac)
save to fgfs/Bluewonder/bluewonder.ac


(if nothing happens, use 'a' to select all prior to exporting)
xplane2fg.sh may complain about funny elevations reported by FlightGear:


copy texture from X-Plane to fgfs:
# WARNING: Zero alt for LSGS-grasss-1.ac?
cp "~/X-Planes Custom scenery/Bluewonder/objects/Bluewonder.png fgfs/Bluewonder/
cp "$HOME/X-Plane 9 Demo/Custom Scenery/Bluewonder/objects/Bluewonder.png" fgfs/Bluewonder/
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


osgviewer fgfs/Bluewonder/Bluewonder.ac
# xplane2fg.sh --run-fgfs


- get coordinates
then run
unzip -d msfs/Bluewonder/ Bluewonder_MDL_XML.zip
look in msfs/Bluewonder/Bluewonder.XML
<SceneryObject lat="51 3.21" lon="13 48.605" alt="0" pitch="0" bank="0" heading="238.5" altitudeIsAgl="TRUE" imageComplexity="NORMAL">


Latitude and longitude are given in grad minutes. Convert to float grad:
# xplane2fg.sh --query-alt LSGS-grasss-1.ac
lat = 51 + 3.21/60 = 51.0535
lon = 13 + 48.605/60 = 13.8101
heading is 238.5
alt given here is AGL. Can we place it in FG like this, too??
Merely guess alt here: 120


.stg line would read:
which would return something like


OBJECT_STATIC Bluewonder.ac 13.8101 51.0535 800 238.5
# OBJECT_STATIC LSGS-grasss-1.ac 7.3416857 46.2201743 482.24 357.99
# in /e000n40/e007n46/3072521.stg


find FGFS tile number:
and correct the respective line in the indicated .stg file.
$FG_SRC/source/scripts/perl/scenery/calc-tile.pl


# calc-tile.sh 51.0535 13.8101
Longitude: 51.0535
Latitude:  13.8101
Tile:      3791344
Path:      "e050n10/e051n13/3791344.stg"


bin/xml2stg.sh msfs/Bluewonder/Bluewonder.XML
= Note to windows users =
OBJECT_STATIC msfs/Bluewonder/Bluewonder.ac 13.8101 51.0535 800 238.5# e010n50/e013n51/3171139.stg


--[[User:Radi|Radi]] 22:07, 3 May 2010 (UTC)
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 ;)


[[Category:Howto|Convert objects from MSFS]]
[[Category:Howto|Convert objects from MSFS]]
[[Category:Scenery enhancement|Convert objects from MSFS]]
[[Category:Scenery enhancement|Convert objects from MSFS]]

Revision as of 19:32, 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).

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.


Conversation in three easy steps

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:

  • 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 src/
 ** calc-tile.pl
 ** find_elevations.pl
  • telnet

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

Installation

Install xplane2fg:

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

Copy autoimport helper to Blender's scripts folder:

  1. 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'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:

  1. 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:

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

with

  1. 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

Load xplane2fg's environment profile:

  1. 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 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

Now run the main conversation script:

  1. cd $HOME/fgfs/convert/
  2. 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

  1. blender-autoimport-source.py

in the current directory.

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

  1. cd $HOME/fgfs/convert
  2. 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

  1. $HOME/fgfs/convert/EDDN.fg/
  2. Objects/e000n40/e006n46/
  3. 3056136.stg
  4. 3056139.stg
  5. Terminal.ac
  6. ...

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

  1. cd EDDN.fg/Objects/e000n40/e006n46/

and run

  1. check_and_fix_textures.sh *.ac

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

  1. 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 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.

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

Cleanup

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

  1. 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, the converted scenery (including all textures) must comply with the GPL.


Optional

You may use

  1. 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:

  1. 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

  1. xplane2fg.sh --run-fgfs

then run

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

which would return something like

  1. OBJECT_STATIC LSGS-grasss-1.ac 7.3416857 46.2201743 482.24 357.99
  2. 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 ;)