Howto:Add shared models manually: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
m (remove todo's)
 
(33 intermediate revisions by 6 users not shown)
Line 1: Line 1:
You can add objects to FlightGear's world by making use of "models" of those objects.  This howto explains one way to do so, especially with the shared models that are distributed with FlightGear.  These models are called "shared" because they are used to define many objects in different places.  (There are also "static models" which represent unique objects, such as famous buildings, that only exist in one place, but we won't have much to say about them.)  Shared models are stored in the <code>[[$FG_ROOT]]/Models</code> directory.


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.
You can also create your own models; see [[Modeling - Getting Started]]. Most Flightgear models are in the .ac (AC3D) format.


== Adding Share Models ==


Here is a quick rundown on how to add a shared model to the current version of FlightGear.
== Using Shared Models to Add Objects to FlightGear's World ==


=== Step 1 ===
=== Step 1 ===
Create a directory under the FlightGear data/Models directory. I'm going to use data/Models/MyModels as an example.
If you plan to use one of the standard FG shared models, skip to step 4.
 
If you have created your own model, create a new directory for it under <code>[[$FG_ROOT]]/Models</code> (to keep your models separate from the standard ones). We'll use <code>$FG_ROOT/Models/MyModels</code> as an example.


=== Step 2 ===
=== Step 2 ===
Inside the data/Models/MyModels drirectory create an xml file called foomodel.xml with the following contents :
Copy the file (usually has an .ac extension) containing your model into the <code>$FG_ROOT/Models/MyModels</code> directory. We'll use <code>MyModel.ac</code> as the name of that file.


IMPORTANT: The wiki does not allow raw XML code to be displayed. It will remove it. This explains why the original XML example posted here is missing. 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 (optional) ===
If you intend to include animation, create an XML file called <code>MyModel.xml</code> inside the <code>$FG_ROOT/Models/MyModels</code> directory with the following contents:


=== Step 3 ===
<?xml version="1.0"?>
Create an 3ds model called foomodel.3ds and save it into the data/Models/MyModels directory. Notice that the xml file references the 3ds model file and tells FG that it must be visible from 0 meters up to 25 km.
<PropertyList>
  <path>MyModel.ac</path>
  <animation>
  <type>range</type>
  <min-m>0</min-m>
  <max-m>20000</max-m>
  </animation>
</PropertyList>


=== Step 4 ===
This file references the .ac model file and tells FlightGear that it must be visible from 0 meters up to 20 km.
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.
An XML file is only necessary if you are intending to include animation; it is not required to render a model at a fixed location in FlightGear.  


=== Step 5 ===
=== Step 4 ===
In CVS 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 CVS and don't have the CVS branch installed : http://cvs.flightgear.org/cgi-bin/viewcvs/viewcvs.cgi/*checkout*/FlightGear/scripts/perl/scenery/calc-tile.pl?rev=HEAD&cvsroot=FlightGear-0.9&content-type=text/x-perl 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 :
Next, you have to determine where to place your object in FG's world.


  paul@localhost scenery?$ ./calc-tile.pl -55.5 30.3
Useful resources at this stage are websites that allow you to get the coordinates of a point from aerial photographs. One such is [http://itouchmap.com/ itouchmap.com], which relies on Google Maps. Enter a street name, city, and state. When you get a good photo of your feature, click on map to place a marker there, then read the displayed coordinatesGoogle Earth is also a good way to obtain position information, and there are other websites that will provide it also, or you can get it from a GPS(Coordinates of real-world locations are not copyrightable, so there is no legal problem with using these tools to find coordinates, but don't copy other content, such as images or models.)
Longitude: -55.5
  Latitude: 30.3
  Tile: 2039314
Path:  "w060n30/w056n30/2039314.stg"


Once you've got at least a rough idea of the coordinates, you need to place the object visually.


=== Step 6 ===
One easy way do this is with the [[UFO]]. In addition to making it easy to move around (or hover), it allows you to place objects and see what they look like there.  See [[Howto: Place 3D objects with the UFO]].  Another easy way is with the [[FlightGear Scenery Designer]].  Both tools calculate the positioning details for you and write them out in the correct format.
Open the corresponding stg file in your scenery directory (in my case SceneryDir/w060n30/w056n30/2039314.stg)


=== Step 7 ===
Here, though, we'll continue by describing a manual way to do it, for people who may need or want to know the inside details.  
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


=== Step 8 ===
Start FG and fly to the location where you want to place the object (or use [[command line options]] to start in that location). Open up the property browser in FG (File->Browse Internal Properties), and the <code>/position</code> key.  Check that the values for <code>latitude-deg</code> and <code>longitude-deg</code> are what you want, or write them down if you're positioning things visually, and also note the <code>ground-elev-m</code>. If you want to place the object above ground level (or partially bury it), then adjust the number appropriately.  Then, go to the <code>/environment</code> key and write down the tile number (current-tile-id) for that location.
Start FG and fly to where you added the model and it should be there.


You can use FGSD for steps 4 to 7
=== Step 5 ===
Locate a .stg file into which you will place a reference to the object's model and its location and orientation.


The .stg files are named according to tile number and stored under the scenery directories.  The default installation places a limited amount of scenery (for the area around San Francisco) in <code>[[$FG_ROOT]]/Scenery</code> but you may have scenery in other directories and listed in the scenery path (<code>[[$FG_SCENERY]]</code>; see [[Howto: Install scenery]]).  Under each scenery directory, you will find directories called <code>Objects</code> and <code>Terrain</code>.  Objects associated with airports are usually listed in a .stg file under "Terrain"; other objects are put under "Objects".  The files under Objects and Terrain are organized in directories that group tiles into larger and smaller quadrants.  Thus, if the tile number is 942058, you will find a file called <code>942058.stg</code> in the directory <code>$FG_Root/Scenery/Objects/w130n30/w123n37/</code>.


== STG File Format ==
There is generally more than one .stg file for a given tile, in different directories, because scenery can be stored in more than one place.  It's important to describe your new object in a .stg file that will actually be read by flightgear (see [[#STG files|below]]).  It is recommended that you create a personal customized scenery directory separate from the standard installed scenery.  That way, when you upgrade FG your customizations won't get overwritten.  If you create such a directory, list it first in <code>[[$FG_SCENERY]]</code>, create a directory structure inside it parallel to the one in the standard scenery directory, and create a .stg file in the appropriate place. Similarly, it is best not to edit the .stg files in the folder where [[TerraSync]] stores the scenery it has fetched, since TerraSync may overwrite them with newer versions.


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.
=== Step 6 ===
Add a line like the following to the .stg file you've chosen, replacing the parameters with your own :


Each line of the STG file has the following format:
OBJECT_SHARED Models/MyModels/MyModel.xml -55.5 30.3 1000.0 0.00


OBJECT_SHARED RELATIVE_PATH LON LAT ALT ROT
In brief, the format is :
type path longitude latitude elevation heading


Where
There are more details on the .stg file format [[#STG files|below]].


RELATIVE_PATH is the location of the scenery object.
=== Step 7 ===
 
Restart FG and fly to where you added the model (or use [[command line options]] to start it with that location as the initial location); it should be there. Check its location and orientation, make any necessary changes in the .stg file, then exit and restart FG to check it again.
LON is the Longitude


LAT is the Lattitude
== STG files ==
There is documention for the .stg files used by FlightGear in <code>$FG_ROOT/Docs/README.scenery</code>.  Only information relevant for placing shared objects is included here.


ALT is the altitude above the surface of FlightGear world model.
Scenery files are loaded by default from <code>[[$FG_ROOT]]/Scenery</code>.  Alternate locations (a "scenery path") can be specified in <code>[[$FG_SCENERY]]</code> (or from the command line); the first-named directories have highest priority.  Thus, if you create a local directory for storing custom scenery you create, include it first in the scenery path.


ROT is the amount of rotation applied to the model in degrees. For example, if your model had a window that should face north, but it should face south, you could adjust the rendering of the model to face south by rotating 180 degrees.
Lines in a .stg file which describe shared objects look like this:


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.
{| class="prettytable" border="1" cellspacing="0" bordercolor="black">
|OBJECT_SHARED
|Models/Misc/trigpoint.xml
|<nowiki>-122.377127</nowiki>
|37.71570833
|1.756719854
|20
|-
|type
|filename path
|longitude
|latitude
|elevation
|heading
|}


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).
* Most of the time you'll use OBJECT_SHARED for a shared model.  (If you have a one-of-a-kind object, you should use OBJECT_STATIC instead; see an explanation of it in <code>$FG_ROOT/Docs/README.scenery</code>.)
* The filename path points to the file that contains the model; for the OBJECT_SHARED type, this is relative to the $FG_ROOT directory. Specify the XML file for the model if there is one, otherwise the .ac file. 
* Latitude and longitude are expressed as decimal numbers (not degrees/minutes/seconds), with negative values representing west and south.
* Elevation is in meters above mean sea level ('''not''' feet, as is stated in some other places in the wiki)
* Rotation is '''counter-clockwise''' from north (not clockwise as in the rest of FG).


 
Some more examples:
Example
 
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
  OBJECT_SHARED Models/MidAtl/cape-may-light.ac  -74.959970 38.933332 -93.0 0.00
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


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.
== XML files ==
Alternately, there is a way to specify this same information in XML configuration files that are loaded at runtime; see [[Howto: Place 3D objects with the UFO]] or <code>$FG_ROOT/Docs/README.scenery</code> for more details. This approach has the advantage of keeping your new scenery clearly separate from the standard scenery files without having to create your own custom scenery directory structure.  Further, you can then manually control whether or not to load it at run-time, using the --config option on the command line. You can also include it in one of the standard startup files (such as [[Fgfsrc|.fgfsrc]]) but this will load it into memory every time you start FG, whether or not you are flying in the area.  If you place the scenery information in .stg files, it is only loaded into memory when needed.


OBJECT_STATIC KSFO-terminal-fb.ac -122.3859635 37.61748958 3 90
[[Category:Howto|Add shared models manually]]
OBJECT_SHARED Models/Airport/windsock.xml -122.360843 37.613877 1 0
[[Category:Scenery enhancement|Add shared models manually]]
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

Latest revision as of 16:28, 6 May 2012

You can add objects to FlightGear's world by making use of "models" of those objects. This howto explains one way to do so, especially with the shared models that are distributed with FlightGear. These models are called "shared" because they are used to define many objects in different places. (There are also "static models" which represent unique objects, such as famous buildings, that only exist in one place, but we won't have much to say about them.) Shared models are stored in the $FG_ROOT/Models directory.

You can also create your own models; see Modeling - Getting Started. Most Flightgear models are in the .ac (AC3D) format.


Using Shared Models to Add Objects to FlightGear's World

Step 1

If you plan to use one of the standard FG shared models, skip to step 4.

If you have created your own model, create a new directory for it under $FG_ROOT/Models (to keep your models separate from the standard ones). We'll use $FG_ROOT/Models/MyModels as an example.

Step 2

Copy the file (usually has an .ac extension) containing your model into the $FG_ROOT/Models/MyModels directory. We'll use MyModel.ac as the name of that file.

Step 3 (optional)

If you intend to include animation, create an XML file called MyModel.xml inside the $FG_ROOT/Models/MyModels directory 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>

This file references the .ac model file and tells FlightGear that it must be visible from 0 meters up to 20 km.

An XML file is only necessary if you are intending to include animation; it is not required to render a model at a fixed location in FlightGear.

Step 4

Next, you have to determine where to place your object in FG's world.

Useful resources at this stage are websites that allow you to get the coordinates of a point from aerial photographs. One such is itouchmap.com, which relies on Google Maps. Enter a street name, city, and state. When you get a good photo of your feature, click on map to place a marker there, then read the displayed coordinates. Google Earth is also a good way to obtain position information, and there are other websites that will provide it also, or you can get it from a GPS. (Coordinates of real-world locations are not copyrightable, so there is no legal problem with using these tools to find coordinates, but don't copy other content, such as images or models.)

Once you've got at least a rough idea of the coordinates, you need to place the object visually.

One easy way do this is with the UFO. In addition to making it easy to move around (or hover), it allows you to place objects and see what they look like there. See Howto: Place 3D objects with the UFO. Another easy way is with the FlightGear Scenery Designer. Both tools calculate the positioning details for you and write them out in the correct format.

Here, though, we'll continue by describing a manual way to do it, for people who may need or want to know the inside details.

Start FG and fly to the location where you want to place the object (or use command line options to start in that location). Open up the property browser in FG (File->Browse Internal Properties), and the /position key. Check that the values for latitude-deg and longitude-deg are what you want, or write them down if you're positioning things visually, and also note the ground-elev-m. If you want to place the object above ground level (or partially bury it), then adjust the number appropriately. Then, go to the /environment key and write down the tile number (current-tile-id) for that location.

Step 5

Locate a .stg file into which you will place a reference to the object's model and its location and orientation.

The .stg files are named according to tile number and stored under the scenery directories. The default installation places a limited amount of scenery (for the area around San Francisco) in $FG_ROOT/Scenery but you may have scenery in other directories and listed in the scenery path ($FG_SCENERY; see Howto: Install scenery). Under each scenery directory, you will find directories called Objects and Terrain. Objects associated with airports are usually listed in a .stg file under "Terrain"; other objects are put under "Objects". The files under Objects and Terrain are organized in directories that group tiles into larger and smaller quadrants. Thus, if the tile number is 942058, you will find a file called 942058.stg in the directory $FG_Root/Scenery/Objects/w130n30/w123n37/.

There is generally more than one .stg file for a given tile, in different directories, because scenery can be stored in more than one place. It's important to describe your new object in a .stg file that will actually be read by flightgear (see below). It is recommended that you create a personal customized scenery directory separate from the standard installed scenery. That way, when you upgrade FG your customizations won't get overwritten. If you create such a directory, list it first in $FG_SCENERY, create a directory structure inside it parallel to the one in the standard scenery directory, and create a .stg file in the appropriate place. Similarly, it is best not to edit the .stg files in the folder where TerraSync stores the scenery it has fetched, since TerraSync may overwrite them with newer versions.

Step 6

Add a line like the following to the .stg file you've chosen, replacing the parameters with your own :

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

In brief, the format is :

type path longitude latitude elevation heading

There are more details on the .stg file format below.

Step 7

Restart FG and fly to where you added the model (or use command line options to start it with that location as the initial location); it should be there. Check its location and orientation, make any necessary changes in the .stg file, then exit and restart FG to check it again.

STG files

There is documention for the .stg files used by FlightGear in $FG_ROOT/Docs/README.scenery. Only information relevant for placing shared objects is included here.

Scenery files are loaded by default from $FG_ROOT/Scenery. Alternate locations (a "scenery path") can be specified in $FG_SCENERY (or from the command line); the first-named directories have highest priority. Thus, if you create a local directory for storing custom scenery you create, include it first in the scenery path.

Lines in a .stg file which describe shared objects look like this:

OBJECT_SHARED Models/Misc/trigpoint.xml -122.377127 37.71570833 1.756719854 20
type filename path longitude latitude elevation heading
  • Most of the time you'll use OBJECT_SHARED for a shared model. (If you have a one-of-a-kind object, you should use OBJECT_STATIC instead; see an explanation of it in $FG_ROOT/Docs/README.scenery.)
  • The filename path points to the file that contains the model; for the OBJECT_SHARED type, this is relative to the $FG_ROOT directory. Specify the XML file for the model if there is one, otherwise the .ac file.
  • Latitude and longitude are expressed as decimal numbers (not degrees/minutes/seconds), with negative values representing west and south.
  • Elevation is in meters above mean sea level (not feet, as is stated in some other places in the wiki)
  • Rotation is counter-clockwise from north (not clockwise as in the rest of FG).

Some more examples:

OBJECT_SHARED Models/MidAtl/cape-may-light.ac   -74.959970 38.933332 -93.0 0.00
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

XML files

Alternately, there is a way to specify this same information in XML configuration files that are loaded at runtime; see Howto: Place 3D objects with the UFO or $FG_ROOT/Docs/README.scenery for more details. This approach has the advantage of keeping your new scenery clearly separate from the standard scenery files without having to create your own custom scenery directory structure. Further, you can then manually control whether or not to load it at run-time, using the --config option on the command line. You can also include it in one of the standard startup files (such as .fgfsrc) but this will load it into memory every time you start FG, whether or not you are flying in the area. If you place the scenery information in .stg files, it is only loaded into memory when needed.