Howto:Convert objects from X-Plane

From FlightGear wiki
Revision as of 22:16, 3 May 2010 by Radi (talk | contribs)
Jump to navigation Jump to search

This tutorial explains how to convert Microsoft(R) Flight Simulator (MSFS) scenery objects to the AC3D format (.ac) used by Flight Gear.

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 method has been tested OK on a couple of scenery objects made by Hellfried Miersch for MSFS 2004. I did not test it with models from other sources, yet.

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.

You will need the following tools:

  • an X-Plane installation (demo works for me)
  • blender (tested on ver. 2.48a-r3)
  • XPlane2Blender (ver 3.09) and fs2xplane (ver 3.11) from Jonathan Harris' page
  • FlightGear source
  • and, of course, a MSFS scenery to convert. As an example, I will use a model of "Das Blaue Wunder" (The Blue Wonder), a historic bridge over the Elbe river in Dresden, Germany. It has been created by Hellfried Miersch, you may get it 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 Media:msfs2ac.tar.gz msfs2ac scripts, you will need - xte from Steve Slaven's xautomation package.

Semi-automatic conversation using msfs2ac.sh

For the impatient, here's how you convert the model semi-automatically using my [Media:msfs2ac.tar.gz]] scripts. You will find the manual step-by-step tutorial below.

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.

Unpack the scripts somewhere, cd there. You should have the following files

# ls -1
bin/
doc/
msfs2ac.profile

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

  • FG_SRC must point to your FlightGear source,
  • XPLANE must point to the X-Plane custom scenery folder, e.g.
# cat msfs2ac.profile
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 we are ready to convert a MSFS scenery:

place the MSFS scenery .zip-files here. Continuing the above example:

# mv ~/downloads/Bluewonder.zip ~/downloads/Bluewonder_MDL_XML.zip .

Load environment variables and path:

# source msfs2ac.profile

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:

# msfs2ac.sh -1 Bluewonder.zip

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

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:

# ls -l fgfs/Bluewonder/
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,

# osgviewer fgfs/Bluewonder/Bluewonder.ac
osgDB ac3d reader: could not find texture "Bluewonder.png"
osgDB ac3d reader: could not find texture "Bruehl.png"

it should look like this:

Bluewonder untextured.jpg

Copy the missing textures:

# cp fgfs/Bluewonder/objects/Bluewonder.png fgfs/Bluewonder/
# cp fgfs/Bluewonder/objects/Bruehl.png fgfs/Bluewonder/

Now you model should be textured nicely:

Bluewonder textured.jpg

Last, we need to extract the coordinates of the model and generate a .stg line for placement in FlightGear. Run:

# unzip -d msfs/Bluewonder/ Bluewonder_MDL_XML.zip
# xml2stg.sh msfs/Bluewonder/Bluewonder.XML
OBJECT_STATIC Bluewonder.ac             13.8101 51.0535 0   238.5            # e010n50/e013n51/3171139.stg

The third number is the object's altitude. In Bluewonder.XML it is given AGL, however, in FlightGear, it is MSL, so we have to guesstimate and correct it later on using the UFO or, even better, query the actual elevation. A good guess here is 120.

Add this line to FlightGear's scenery/objects/e010n50/e013n51/3171139.stg file and move the model and textures from fgfs/Bluewonder to FlightGear's scenery/objects/e010n50/e013n51/ folder.

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

Bluewonder in FG.jpg

2. Step-by-step

todo

get Bluewonder.zip Bluewonder_MDL_XML.zip

from helles-flusi.de


mkdir -p msfs/Bluewonder 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"

fire up blender

File->Import->X-Plane Object (.obj) 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)

copy texture from X-Plane to fgfs: 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/

osgviewer fgfs/Bluewonder/Bluewonder.ac

- get coordinates 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: 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:

OBJECT_STATIC Bluewonder.ac 13.8101 51.0535 800 238.5

find FGFS tile number: $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 OBJECT_STATIC msfs/Bluewonder/Bluewonder.ac 13.8101 51.0535 800 238.5# e010n50/e013n51/3171139.stg

--Radi 22:07, 3 May 2010 (UTC)