Howto:Add shared models manually

From FlightGear wiki
Revision as of 18:08, 8 March 2011 by BotFlightGear (talk | contribs) (Robot: Cosmetic changes)
Jump to navigation Jump to search
Cleanup.png This article may require cleanup to meet the quality standards of the wiki. Please improve this article if you can.

Note: You may include scenery objects in any format that PLIB supports. Currently, this means in addition to the 3ds models mentioned, you may use AC3D and other formats. This howto assumes that you already have a model. If not, create one using a suitable modeling program such as blender.

Adding Shared Models

Here is a quick rundown on how to add a shared model to the current version of FlightGear.

Step 1

Create a directory under the FlightGear data/Models directory. I'm going to use data/Models/MyModels as an example.

Step 2

Inside the data/Models/MyModels drirectory you may create an XML file called foomodel.xml with the following contents:

<?xml version="1.0"?>
<PropertyList>
 <path>MyModel.ac</path>
 <animation>
  <type>range</type>
  <min-m>0</min-m>
  <max-m>20000</max-m>
 </animation>
</PropertyList>

Note: An XML file is only necessary if you are intending to include animation. An XML file is not required to render a model at a location in FlightGear. Instead of specifying an XML file in the STG file as stated below, merely give the path to the 3d model file (such as path/to/foomodel.ac).

Step 3

Create an .ac model called MyModel.ac and save it into the $FG ROOT/Models/MyModels directory. Notice that the xml file references to the .ac model file and tells FlightGear that it must be visible from 0 meters up to 20 km.

Step 4

Start FG and fly (or use UFO model and move) to the location where you want to place the model. Open up the property browser in FG and write down the lat, lon and altitude where you want to place the model. (File->Browse Internal Properties->Position) After that write down the tile number. You can found it in the property browser (File->Browse Internal Properties -> Environment -> current-tile-id[0])

A really useful resource at this stage is http://www.terraserver-usa.com Enter a street name, city, and state. Then you can choose from several types of public-domain aerial photography from the US Geological Survey. When you get a good photo of your feature, click on the Info link. Your image will be broken into tiles with latitude and longitude of the edges of the tiles. This is good way to precisely place objects. Google Earth or Google Maps are also both excellent ways to obtain position information.

Step 5

In Git there is a perl program called calc-tile.pl that works out what stg file a geodetic coordinate falls in. You can get it here if you don't feel like playing with Git and don't have the Git branch installed: http://gitorious.org/fg/flightgear/blobs/raw/next/scripts/perl/scenery/calc-tile.pl Run the perl script in a terminal window passing it the longitude and latitude that you wrote down in step 4. You'll probably have to install perl first if you run on a MS OS's. Example :

$ ./calc-tile.pl -55.5 30.3
Longitude: -55.5
Latitude: 30.3
Tile: 2039314
Path: "w060n30/w056n30/2039314.stg"

Step 6

Open the corresponding stg file in your scenery directory (in my case SceneryDir/w060n30/w056n30/2039314.stg)

Step 7

Add the following lines to the stg file replacing the parameters with your own :

OBJECT_SHARED Models/MyModels/foomodel.xml -55.5 30.3 1000.0 0.00 

The format is: OBJECT_SHARED relative_path_to_model_xml_file LON LAT ALTITUDE_above_wgs84 ellipsoid_ROTATION. Note: If you have no XML file, just specify the path to your model.

Step 8

Start FG and fly to where you added the model and it should be there.

You can use FGSD for steps 4 to 7

.STG file format

Currently, no documention exists for the .stg files used by FlightGear other than this. There is none in the 'mini-docs' folder bundled with the source.

Each line of the STG file has the following format:

OBJECT_STATIC KSFO-maint-1-fb.ac -122.377127 37.71570833 1.756719854 20
Type Relative path Longitude Latitude Elevation Heading

About Altitude. Looking at the files shipped with FG, there are some strange, to me, figures for altitude. Some are negative numbers. That seems odd, since objects are being placed on the surface. It suggests that above surface may be negative on the Z axis. COMMENT: Much more likely these are objects which are purposely sunk into the terrain to adjust their height.

I ran across a comment: 3D object need scenery to compute their height. This is why scenery must be associated with an existing land surface file (whatever you call it).

This is what a line with an XML file specifying the model looks like.

OBJECT_SHARED Models/MidAtl/cape-may-light.xml   -74.959970 38.933332 -93.0 0.00

This is what a line specifying the model file directly looks like.

OBJECT_SHARED Models/MidAtl/cape-may-light.ac   -74.959970 38.933332 -93.0 0.00

A second example from the FlightGear KSFO scenery. Although taken from different STG files for the same area, you can see the mix of objects.

OBJECT_STATIC KSFO-terminal-fb.ac -122.3859635 37.61748958 3 90
OBJECT_SHARED Models/Airport/windsock.xml -122.360843 37.613877 1 0
OBJECT_SHARED Models/Structures/vordme.xml -122.37389 37.61948 -0.404 0
OBJECT_STATIC KSFO-maint-1-fb.ac -122.377127 37.62647917 0.5 62
OBJECT_STATIC candlestickpark-fb.xml -122.3838418 37.71570833 1.756719854 0