Monthly Archives: August 2019

Advanced Tutorial: Updating the Globe & Importing Imagery
August 30, 2019

Disclaimer: Links to third-party websites are provided for convenience only. The fact that LMC has provided a link to a third-party’s website does not constitute an implicit or explicit endorsement, authorization, sponsorship, or affiliation by LMC with respect to such website, its owners, content, products, or services. By clicking on a third-party link, you will leave the LMC website and will be subject to the privacy and security policies of the third-party website.

The Prepar3D Software Development Kit (SDK) has numerous functionalities enabling users to customize their Prepar3D experience. One of these features allows users to import imagery to create a more immersive flying experience with geo-specific data. Prepar3D’s terrain system utilizes geographic information system (GIS) data techniques enabling realistic flights over accurate terrain across the entire earth. However, it may be desired to use satellite imagery in specific scenarios. To address this, not only does Prepar3D have 40 (and counting) high-detail cities around the world, but also has SDK tools letting users choose which areas they want to replace with custom imagery.

Importing imagery into Prepar3D consists of the following steps: First, the satellite imagery itself must be downloaded and converted to the proper file format. Following this, a third-party tool will reproject and reformat the file into the proper coordinate system that Prepar3D uses. Then, using the SDK’s resample tool, a .bgl file will be created, enabling the user to replace default terrain data. Once this is finished, the new terrain data can be seen in Prepar3D and scenery objects can be autogenerated onto the existing terrain through other SDK and third-party tools.

Setup

First download and install FWTools, an open-source GIS tool made by Frank Warmerdam.
Using the USGS National Map (recommended for geospatial data within the US), requires downloading the following items. Using geospatial data from other sources may also require these items as they’re used for various file conversions.

Download and extract the USGS_Raster_Conversion_Scripts.zip file from here, which are geospatial file conversion scripts.
The above scripts require the use of GDAL (Note: the correct installer will be the gdal-[version]-core.msi).

ScenProc is a third-party tool that can speed up the process of adding large amounts of scenery objects (buildings, vegetation, etc.).

Procedure: Updating Terrain

    USGS National Map

  1. If using the USGS National Map, download a JP2 file(s) from here. To do this, select an area using the “Draw Rectangle” tool and then select “Imagery – NAIP Plus (1 meter to 1 foot)” option on the left before hitting “Find Products”. Multiple options may appear depending on how large of an area is selected so be sure to view the footprint of each .jp2 file before downloading to know what area of imagery is being downloaded.
  2. If using the USGS National Map or have other geospatial data that is not in a GeoTIFF format, use the USGS Raster Conversion Scripts to make this file change. Navigate in command line to the …\…\USGS_Raster_Conversion_Scripts\JP2_Source folder and run this command:
    GDAL_JP2_2_GeoTIFF.bat "Input JP2 file location & name" [Output TIFF file location & name]For more information on how to convert to GeoTIFF, refer to this guide.
  3. Reproject the GeoTIFF with FWTools by opening up “FWTools Shell” from the Start menu and running this command:
    gdalwarp -t_srs “+proj=longlat +ellps=wgs84 +datum=wgs84 +units=d” -s_srs EPSG:3857 "Input TIFF file location & name" "Output TIFF file location & name"
  4. Reformat the GeoTIFF file with FWTools by running this command in the FWTools shell:
    gdal_translate -b 1 -b 2 -b 3 -co “TFW=YES” "Input(Output file from prev. step) TIFF file location & name" "Output TIFF file location & name"
    Note: Skip this if your scenery is majority water.
  5. Create an INF file in any text editing program (i.e. Notepad or Notepad++) with the following content:

    [Source]
    Type = GeoTIFF
    SourceDir = <Input GeoTIFF File location>
    SourceFile = <GeoTIFF file name>
    Layer = Imagery
    Variation = Day
    NullValue = 0,0,0
    [Destination]
    DestDir = <Export BGL file location>
    DestBaseFileName = <BGL file name>
    DestFileType = BGL
    LOD = Auto

    Note: If adding scenery objects, ensure the folder with the BGL files is titled “Scenery”.
  6. Run the resample tool by navigating to the folder containing resample.exe and dragging the .inf file on top of it. For more information on running the Resample tool refer to the Resample section of the Learning Center
  7. Once in Prepar3D, navigate to the Scenery Library (click on Scenery on the startup screen or go to World, then Scenery Library once in a scenario), click on “Add Area”, navigate to the folder with all the BGL output files and hit OK. For more information on adding new files to Prepar3D scenery, refer to this guide in the Learning Center.
  8. Enjoy the new terrain, where viewing a mountaintop went from looking like the image on the left to the right!

Default Scenery

Updated Scenery

 

 

 

 

 

 

Procedure: Adding Autogeneration Objects

Note: If generating a small amount of buildings or vegetation the Annotator tool can be used instead of the steps listed below. Refer to theautogeneration overview page in the Learning Center for an in-depth tutorial on the Annotator tool.

    OpenStreetMap Overpass

  1. Run a query on OpenStreetMap data using Overpass. For example, the query on the right is finding all the buildings and natural landscape (forests, ponds, wetlands, etc.) within an area bounded by the window of the map itself. The output is shown on the map with different areas colored accordingly. For more information on writing queries to access different types of data, consult the OpenStreetMap wiki.
    Note: OpenStreetMap is open-source so there is a chance to come across missing or erroneous data, however this is rare.
  2. Export raw OSM data once satisfied with the Overpass output.
  3. Using ScenProc, write a script (or utilize a template) to transform the raw OSM data into AGN files that Prepar3D can use. Documentation for ScenProc is in“ScenProc.pdf” which should be in the .zip file downloaded earlier. When configuring ScenProc upon startup, select the latest version of Prepar3D (currently v3 and v2) that’s supported by this tool. While ScenProc doesn’t officially support Prepar3D v4, the tool still works correctly. Below is an example script that uses building and natural landscape OSM data to generate houses and trees in a neighborhood. Important: Ensure that the EXPORTAGN command directs the AGN files to a folder labeled “texture” that is in the same folder as the “Scenery” folder from Step 5 of Terrain above.

    ImportOGR|C:\Users\test\Downloads\export (2).osm|*|landuse;building|NOREPROJ
    ImportOGR|C:\Users\test\Downloads\export (2).osm|*|landuse;natural|NOREPROJ
    #
    SPLITGRID|AGN|*|building="*"
    SplitGrid|AGN|*|natural="*"
    SplitGrid|AGN|*|landuse="*"
    #
    # Add attribute to indicate the type of building
    # 1 = ALMOST RECTANGLE (BASED ON AREA RATIO)
    # 3 = REGULAR SHAPED (MANY PARALLEL EDGES)
    # 4 = CONVEX POLYGONS
    # 5 = CONCAVE POLYGONS
    ADDATTRIBUTE|FTYPE=POLYGON;building=*;FAREARAT>0.80|BUILDTYPE|1
    ADDATTRIBUTE|FTYPE=POLYGON;building=*;BUILDTYPE!1;FNUMVERT<10;FNUMPERPANG>3;FNUMNOTPAR<2|BUILDTYPE|3 ADDATTRIBUTE|FTYPE=POLYGON;building=*;BUILDTYPE!1;BUILDTYPE!3;FCONVEX=1|BUILDTYPE|4 ADDATTRIBUTE|FTYPE=POLYGON;building=*;BUILDTYPE!1;BUILDTYPE!3;BUILDTYPE!4|BUILDTYPE|5 # # Classify industrial/commercial buildings ADDATTRIBUTEIFINSIDE|FTYPE=POLYGON;building=*|LUCODE=16|BUILDCAT|INDUSTRIAL ADDATTRIBUTEIFINSIDE|FTYPE=POLYGON;building=*|LUCODE=15|BUILDCAT|COMMERCIAL # # Add attribute for roof type ADDATTRIBUTE|FTYPE=POLYGON;building=*;FWIDTH>5|ROOFTYPE|PEAKED_ALL
    ADDATTRIBUTE|FTYPE=POLYGON;building=*;FWIDTH>5;FLENGTH<12|ROOFTYPE|PEAKED_SIMPLE ADDATTRIBUTE|FTYPE=POLYGON;building=*;FWIDTH>20|ROOFTYPE|PEAKED_LOW_PITCH
    ADDATTRIBUTE|BUILDCAT=INDUSTRIAL|ROOFTYPE|PEAKED_LOW_PITCH
    ADDATTRIBUTE|BUILDCAT=COMMERCIAL|ROOFTYPE|PEAKED_LOW_PITCH
    #
    # Remove complex buildings
    REPLACEPOLYGONBYBUILDINGRECTANGLES|BUILDTYPE=3|0.8;4;4|0.25;2.0;0.5|BUILDTYPE|2
    #
    # Create buildings autogen
    CREATEAGNGENBUILD|BUILDTYPE<2;ROOFTYPE=PEAKED_ALL|{5ae04eb6-934c-4f63-bb48-5e7dee601212}|MAXRATIO=2
    CREATEAGNGENBUILD|BUILDTYPE<2;ROOFTYPE=PEAKED_SIMPLE|{2a7b473f-6203-4a5e-ac06-338ef40037db}
    CREATEAGNGENBUILD|BUILDTYPE<2;ROOFTYPE=PEAKED_LOW_PITCH|{e3967d70-e470-44c2-8866-4e9be443d575}
    #Create vegetation
    CreateAGNPolyVeg|natural=wood|{367cdf30-54f0-4093-a2f7-7f473417704f}
    EXPORTAGN|P3D v2|C:\Users\test\Documents\Prepar3D v4 Add-ons\Addon Scenery\texture


    Note: Depending on what data is imported from OpenStreetMap, the GUIDs at the bottom may be different (e.g. larger buildings, different climactic zone, etc.). There are .xml files located in World\Autogeneration\Autogen source xml that have other GUIDs that can be copied over to the appropriate areas of the ScenProc script.
  4. Annotator Tool

  5. Run the script and navigate in File Explorer to the “texture” folder and ensure the AGN files are present.
  6. To confirm that the script worked, open the BGL file from Step 6 of Terrain through the Annotator tool, which is in …\SDK\World\Autogeneration. The file should look similar to this, although it depends on the exact query and script.
  7. Open Prepar3D again (if its open, close it before opening), navigate to the area with autogenerated objects, and increase the Autogen Vegetation/Building Density settings in Options->Graphics->World
  8. Enjoy the more realistic surrounding landscape by transforming the terrain and autogen as shown below!

Original Scenery

Updated Terrain

Updated Autogen

 

 

 

 

Closing

In just a few steps Prepar3D default scenery and terrain can be enhanced to improve and customize the Prepar3D flying experience! Try it now by purchasing Prepar3D and downloading the SDK.

For more information on the Prepar3D SDK and content creation refer to the Learning Center SDK Overview. Our online forum is also a great source for additional help from both Prepar3D developers and users.