OSM2World Documentation

repository·master·Indexed 20 days ago

https://github.com/tordanik/osm2world

An open-source tool that converts OpenStreetMap data into 3D models in multiple formats, including OBJ, GLTF, GLB, POV, and O2W_PBF. It features a CLI for conversion and a GUI for visual interaction. The tool supports SRTM elevation data, configurable Level of Detail (LOD), and various world modules for representing buildings, roads, and trees. Developers can implement the ProceduralWorldObject interface to create dynamically generated 3D geometry.

Tokens
6.2K
Snippets
23
Records
34
Agent score
73%

What's inside OSM2World

  1. How ParkingModule generates surface parking and cars

    master

    The ParkingModule identifies OpenStreetMap areas tagged with amenity=parking and specific parking values (surface, lane, street_side, or rooftop) to create 3D representations.

    Generation Logic

    1. Surface Generation: It creates a ground mesh using the material specified by the surface tag (defaulting to ASPHALT if not specified).
    2. Car Placement: It searches for sub-areas within the parking area tagged with amenity=parking_space.
    3. Vehicle Rendering: For each identified parking space, a vehicle is placed based on the parkedVehicleDensity configuration.
      • The module selects a model named CAR from the current map style.
      • The vehicle's orientation is determined by the bounding box of the parking space.
      • Vehicles are assigned a random color from a predefined set (White, Black, Gray, Silver, Red, Green, Blue, Yellow, Cyan).
      • Vehicles are rendered with a Level of Detail (LOD) range of LOD3 to LOD4.
  2. Configure excluded World Modules

    master

    You can exclude specific 3D representation modules from the conversion process using the excludeWorldModule configuration key in O2WConfig. This is useful if you want to skip certain types of objects (e.g., trees or traffic signs) to reduce scene complexity or file size.

    Supported module names (based on their class simple names) include:

    • ExternalModelModule
    • RoadModule
    • RailwayModule
    • AerowayModule
    • BuildingModule
    • ParkingModule
    • TreeModule
    • StreetFurnitureModule
    • TrafficSignModule
    • BicycleParkingModule
    • WaterModule
    • PoolModule
    • GolfModule
    • SportsModule
    • CliffModule
    • BarrierModule
    • PowerModule
    • MastModule
    • BridgeModule
    • TunnelModule
    • SurfaceAreaModule
    • InvisibleModule
    • IndoorModule
  3. Configure SRTM elevation data and logging

    master

    The conversion process can be customized via O2WConfig to include terrain elevation and control logging behavior:

    • SRTM Elevation: If config.srtmDir() is set to a directory path, the converter will use SRTM data for terrain elevation. Note that using SRTM requires a MapProjection to be provided during the convert call.
    • Logging:
      • config.consoleLogLevels(): Sets the verbosity of logs printed to the console.
      • config.logDir(): Specifies the directory where conversion logs (performance JSON and error text) are written. If null, no logs are written.
      • config.maxLogEntries(): Limits the number of log entries written to the compressed error log file.
  4. Configure parked vehicle density in ParkingModule

    master

    The ParkingModule can generate parked cars on surface parking areas. The density of these vehicles is controlled by the configuration key parkedVehicleDensity.

    • Key: parkedVehicleDensity
    • Type: double
    • Default: 0.3
    • Behavior: A value between 0.0 and 1.0 representing the probability that a mapped parking_space will contain a vehicle model.
  5. Extract configuration options from metadata

    master

    The MetadataOptions class provides mechanisms to extract configuration maps from metadata files.

    If the metadata indicates that the area is not land (metadata.land() == Boolean.FALSE), the resulting configuration map will include the key isAtSea set to true.

    Methods

    • configOptionsFromMetadata(@Nullable TileNumber tile): Uses the instance's metadataFile to retrieve configuration options. If the file is an MBTiles file, the tile parameter is required to locate the correct metadata.
    • configOptionsFromMetadata(@Nullable File metadataFile, @Nullable TileNumber tile): A static utility method that takes a file and an optional tile number to return a Map<String, Object> of configuration options.
    // Example of using the static method to get configuration
    Map<String, Object> options = MetadataOptions.configOptionsFromMetadata(new File("metadata.json"), null);
    
    if (options.containsKey("isAtSea")) {
        // Handle sea-based logic
    }
  6. Configure Level of Detail (LOD) in a Target

    master

    When building a ProceduralWorldObject, you can control the Level of Detail for the meshes being drawn by setting a LODRange on the Target object. If no range is set, meshes are added without specific LOD constraints.

    Methods available on Target:

    • setCurrentLodRange(@Nullable LODRange lodRange)
    • setCurrentLodRange(LevelOfDetail minLod, LevelOfDetail maxLod)
  7. Use the Target class to build procedural geometry

    master

    The Target class (which implements CommonTarget) is the primary sink used within buildMeshesAndModels to collect the output of a procedural generation process. It manages three main types of data:

    1. Meshes: Added via drawMesh(Mesh mesh). You can configure the Target with a LODRange (Level of Detail) before drawing meshes to ensure they are generated with specific detail levels.
    2. Sub-models: Added via addSubModel(ModelInstance subModel).
    3. Attachment Surfaces: These allow you to attach other WorldObjects to the surfaces of your procedural meshes. You configure this by setting currentAttachmentTypes and currentAttachmentObject on the Target before calling drawMesh.
  8. Convert OSM data to a 3D Scene using O2WConverterImpl

    master

    The O2WConverterImpl class provides the primary entry points for converting OpenStreetMap (OSM) data into a 3D Scene. It manages the full conversion lifecycle, including loading OSM data, creating map data, applying world modules (like buildings, roads, and trees), determining elevations, and generating output files.

    There are two main ways to trigger conversion:

    1. From an OSM Data Reader: Pass an OSMDataReader, geographic bounds (GeoBounds), a MapProjection, and one or more Output objects. This method handles the initial data loading phase.
    2. From existing Map Data: If you have already processed the OSM data into MapData, you can pass it directly along with a MapProjection and Output objects to skip the loading phase.
    // Example usage pattern for library users
    O2WConverterImpl converter = new O2WConverterImpl(config, listeners);
    
    // Option 1: Convert from OSM reader
    Scene scene = converter.convert(osmDataReader, bounds, mapProjection, output1, output2);
    
    // Option 2: Convert from pre-processed MapData
    Scene scene = converter.convert(mapData, mapProjection, output1);
  9. Configure Attachment Surfaces in a Target

    master

    To attach objects to the meshes generated by a ProceduralWorldObject, you must configure the Target before calling drawMesh. This tells the Target to create an AttachmentSurface for the next mesh drawn.

    Methods available on Target:

    • setCurrentAttachmentTypes(WorldObject worldObject, String... attachmentTypes): Sets the object to be attached and the types of surfaces it should attach to.
    • setCurrentAttachmentTypes(WorldObject worldObject, @Nullable Function<VectorXZ, Double> baseEleFunction, String... attachmentTypes): Sets the object, an optional elevation function (baseEleFunction), and the attachment types.