LWMViewer

This program is for displaying the contents of the Flight Sim 9 (2004) scenery files. It was written mainly as a test while I was trying to decipher the file structure, but it seems to have proved useful. It has also grown somewhat since it was started :) It will now load, display and disassemble BGL files from FS2004, FS2002 and CFS2.

Jim Keir, September 29th 2004.

http://www.jimkeir.co.uk/FlightSim/index.html

jimkeir@yahoo.co.uk


Contents
  1. Files that can be loaded
  2. How to load them
  3. Displaying terrain
  4. Exporting map bitmaps
  5. Exporting BGL source code
  6. The control palette buttons
  7. Keyboard and mouse controls
  8. Connecting to FlightSim
  9. Unfinished stuff

Supported files

Any file which contains elevation, LWM or VTP information should load and display correctly. The list of common types for FS2004 is: The VOR/NDB loading is based on work by
Winfried Orthmann

You will probably see some water polygons outlined in red; these are polys that are defined as not being horizontal. Specifically, all terrain polygons are now defined with two heights; they are outlined in red if the heights are not the same.

The colours for each type of line or feature are determined by the layer number. They kind of make sense for FS2004's layer conventions but other sims (FS2002, CFS2 etc) may vary. However, STreams and UTility lines share layer 4. To work out which is which, the texture names are scanned; textures 1211 and 1212 are listed in terrain.cfg as being for utility lines. Therefore, if a line in any layer is drawn with textures named "1211" or "1212", it is assumed to be a utility line.


Loading BGL files

Open by Coords opens a dialog box into which you can enter conventional or decimal coordinates. The appropriate filename is calculated from these. There are no guarantees that the file actually exists, however; if your coordinates are mid-ocean it almost certainly won't.

LWMViewer will offer to load the other files which have similar names. Currently this only works for FS2004 installations, since older sims have different naming conventions. LWMs and VTPs will always be autoloaded, but terrain and landclass data will only be loaded if they're currently displayed. This is simply to save memory. To load a terrain file afterwards, enable the terrain display and use Ctrl-L. Existing files won't be reloaded, but terrain will be added.


Displaying Terrain

To display terrain, the file TMFRender.dll needs to be in your command path. Usually the easiest way of doing this is to simply leave it in the same folder as LWMViewer.exe . LWMViewer will work without it, but you will not be able to display terrain data.

Terrain data takes longer to display than other types, and takes a lot of memory. The first time terrain is loaded, the display will be very slow because it is being decompressed and then processed for display. After that, it should be faster because it is stored in its processed form.

Terrain display types

There are various modes for displaying terrain. The basic display can be one of these options:

Two options can be used to alter the appearance of these modes:

Terrain display can help you see how well your scenery matches with the default scenery provided with the sim. In general, the more processor-intensive modes are only useful to people working on mesh or landclass data. On the other hand, lightsourced, blended landclass data over high-res mesh does look nice ;)

Terrain display gotchas

As you zoom in and out, it will occasionally pause to re-draw the display. This is another memory-saving measure; larger terrain BGLs won't fit into memory if they're fully decompressed. When displaying landclass data, you may find that the landclass tiles don't seem to match the displayed LOD13 gridlines. This only seems to happen when displaying landclass data on low-resolution mesh. I'm looking into this.

Low-lying areas may show up as blue in the coloured map. The elevation data in the BGL is integer, so any areas that are below 1 meter get forced to sealevel. This can look pretty wierd, especially in very flat areas where the coastline may appear to be some distance out to sea.

It looks like the default coastlines don't match very well. There are often differences shown, beyond those accounted for by the not-quite-sealevel 'feature'. If you disable the appropriate HP* file, you can see that the LWM files do alter the coastline quite a bit.


Saving BMP files

If LWM or VTP files are loaded, you can save a .BMP file with a copy of the map. Select the Export->Bitmap... menu and a dialog will appear. Most of the settings should be fairly obvious, with the possible exception of the buttons: Only entire cells may be exported (not for any good reason, if someone needs sub-cell images let me know). The numbers to be input for the top-left and bottom-right cell references are - uh - cell references, not lat/long coordinates.

Current drawing rules are still obeyed; if you have only one file selected for drawing, only that file will be saved to the bitmap.

A small text file, with a similar name to the bitmap, is created containing basic information about the export.


Saving BGL source

Version 2 and 3 LWMs and VTPs can now be saved to disk as text files. To save a source file, select the Export->Source... menu item. A standard file dialog will appear. Use this to select the base name for your source files. To this base name, a number will be appended for each file that is saved. So, if you choose "C:\test", the resulting files will be: Any existing files will be silently overwritten. Only files that are currently marked for display in the control palette will be exported.

The boundaries of the file (specified in the BGLHeader) may be different to the loaded file. Many of the MS files use non-integer boundaries, and the BGLHeader macro expects integers.

Source can be exported automatically from the command line. If the first parameter is "/d" then the source for all named files is saved to disk. The name of the first file loaded is used as the basename for all other files.


The Control Palette

A separate window shows the list of currently opened files. Clicking on a filename will toggle its status between displayed and hidden. Other buttons allow you to show all files, show no files or invert the current selection.

x Draw LWMs, x Draw VTPs and x Draw Terrain all do pretty much what they say. They are a fast way of disabling the display of groups of files.

The Terrain drawing options are detailed above.

x Always Draw overrides the automatic filtering of objects that are too small to see; otherwise, busy areas can look empty if you zoom out far enough.

x Display Heights enables the display of altitude data for LWM polys and areafills. This option slows down the drawing process a little, and uses more memory than normal so it is off by default.
If this option is enabled, the height of any LWM data under the mouse pointer is displayed in the status bar. If LWMViewer is following FS2K4's position and the mouse pointer is not over the LWMViewer window or is not moving, the height beneath the center of the map is displayed.

x Position in minutes toggles the lat/long display between decimal and conventional formats. The currently displayed coordinates may be copied to the clipboard using Ctrl-C or the Edit->Copy menu item.

x Points will draw a black dot for each data point in LWM and VTP data. These are only drawn if you are zoomed in far enough; this can be overridden by the 'Always Draw' switch.

x Outlines toggles the drawing of polygon outlines. This was put in mainly for the bitmap export function, where these lines may be distracting when looking at the resulting map.

x Gridlines controls LOD5 gridlines.

x LOD13 Gridlines toggles drawing of sheep. These sheep are only enabled if Draw Gridlines? is also enabled, and appear when the map is zoomed in. When these are visible, the LOD5 gridlines are drawn in black to make them stand out a bit better.

x Autoload on follow will try to load new scenery areas from disk automatically when a plane being followed in FlightSim goes outside the boundary of already-loaded files.

x Trails when following draws a red trail behind the plane when Follow mode is enabled. The trail is sampled every five seconds and stores enough for 90 minutes of flight. To clear the trail, toggle this switch off and on again.

Additional Info: can be set to "None", "Poly Altitude" or "Landclass". Selecting "Poly Altitude" will show the altitude of any LWM polygons (lakes, flattens etc.) under the cursor; "Landclass" will, if landclass data is loaded, show the numeric value and description of the landclass cell uder the cursor. Values are displayed as the rightmost item on the status bar at the bottom of the screen.

x Adjust MS Files corrects Microsoft-supplied LWM files. For some reason, the coordinates run from 1 to 255 instead of the documented 0 to 255. This switch scales back up to 0 to 255 before displaying.
Disassembled files will contain the original coordinates, regardless of what this switch is set to.


Controls

Click on the main window to move the center of the map. A mousewheel, if you have one, controls the zoom. Click the mousewheel to reset the zoom and recenter the display.

Alternatively, use the numeric keypad or cursor keys to move the map around, and the keypad + and - key to control the zoom. Keypad 5 resets and recenters.

The Home key will attempt to center the display once on the aircraft's current position in FS9, and the End key will try to tell FS to reposition the plane at the center of the display. Ins will set the HDG bug to point to the current mouse position, relative to the center of the display.

A popup menu also offers options to move the plane to the location under the mouse pointer, to set the HDG bug to point to the mouse and to tune an appropriate NAV radio to any beacon under the pointer.

When setting a NAV radio, it takes FS a few seconds to re-tune the radios. In the meantime, LWMViewer will set either the HDG or OBS to point at the current location of the mouse. You will probably need to adjust the headings slightly when the radio tunes in. Note that the autopilot is not switched on for you.


FlightSim Connection

If you have a copy of FDSConnection.dll, FSConnect.dll or FSUIPC.dll installed in your FS9 'Modules' folder, you can tell LWMViewer to follow the plane's current position. The position is updated every five seconds.

If you have checked the 'Autoload on Follow' box, the required files are automatically loaded for the current position. Old files are not unloaded though - you can easily end up with a large number of open files.

FSUIPC also allows the plane's position in FS9 to be set. Currently neither FDSConnection or FSConnect seem to support writing, but LWMViewer should take advantage of this if it is ever completed.


To Do