OSM2World Documentation
repository·master·Indexed 20 days ago
https://github.com/tordanik/osm2worldAn 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.
What's inside OSM2World
- OSM2World is an open-source converter designed to create three-dimensional models of the world in various formats using OpenStreetMap data. For official documentation, downloads, and contact information, visit https://osm2world.org/.
Compile OSM2World from source
masterTo compile the project, ensure you have Maven installed and run the package command from the project root directory.
mvn packageHow ParkingModule generates surface parking and cars
masterThe
ParkingModuleidentifies OpenStreetMap areas tagged withamenity=parkingand specificparkingvalues (surface,lane,street_side, orrooftop) to create 3D representations.Generation Logic
- Surface Generation: It creates a ground mesh using the material specified by the
surfacetag (defaulting toASPHALTif not specified). - Car Placement: It searches for sub-areas within the parking area tagged with
amenity=parking_space. - Vehicle Rendering: For each identified parking space, a vehicle is placed based on the
parkedVehicleDensityconfiguration.- The module selects a model named
CARfrom 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
LOD3toLOD4.
- The module selects a model named
- Surface Generation: It creates a ground mesh using the material specified by the
Configure the `tileset` overwrite mode
masterThe
--overwriteoption controls how the command handles existing tile files in the output directory. It accepts three values:always: Always overwrite existing tiles.never: Do not overwrite any existing tiles.older: Only overwrite a tile if the existing file is older than the input data timestamp.
Configure excluded World Modules
masterYou can exclude specific 3D representation modules from the conversion process using the
excludeWorldModuleconfiguration key inO2WConfig. 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:
ExternalModelModuleRoadModuleRailwayModuleAerowayModuleBuildingModuleParkingModuleTreeModuleStreetFurnitureModuleTrafficSignModuleBicycleParkingModuleWaterModulePoolModuleGolfModuleSportsModuleCliffModuleBarrierModulePowerModuleMastModuleBridgeModuleTunnelModuleSurfaceAreaModuleInvisibleModuleIndoorModule
Configure SRTM elevation data and logging
masterThe conversion process can be customized via
O2WConfigto 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 aMapProjectionto be provided during theconvertcall. - 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.
- SRTM Elevation: If
Configure parked vehicle density in ParkingModule
masterThe
ParkingModulecan generate parked cars on surface parking areas. The density of these vehicles is controlled by the configuration keyparkedVehicleDensity.- Key:
parkedVehicleDensity - Type:
double - Default:
0.3 - Behavior: A value between 0.0 and 1.0 representing the probability that a mapped
parking_spacewill contain a vehicle model.
- Key:
Extract configuration options from metadata
masterThe
MetadataOptionsclass 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 keyisAtSeaset totrue.Methods
configOptionsFromMetadata(@Nullable TileNumber tile): Uses the instance'smetadataFileto retrieve configuration options. If the file is an MBTiles file, thetileparameter 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 aMap<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 }Configure Level of Detail (LOD) in a Target
masterWhen building a
ProceduralWorldObject, you can control the Level of Detail for the meshes being drawn by setting aLODRangeon theTargetobject. 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)
Use the Target class to build procedural geometry
masterThe
Targetclass (which implementsCommonTarget) is the primary sink used withinbuildMeshesAndModelsto collect the output of a procedural generation process. It manages three main types of data:- Meshes: Added via
drawMesh(Mesh mesh). You can configure theTargetwith aLODRange(Level of Detail) before drawing meshes to ensure they are generated with specific detail levels. - Sub-models: Added via
addSubModel(ModelInstance subModel). - Attachment Surfaces: These allow you to attach other
WorldObjects to the surfaces of your procedural meshes. You configure this by settingcurrentAttachmentTypesandcurrentAttachmentObjecton theTargetbefore callingdrawMesh.
- Meshes: Added via
Convert OSM data to a 3D Scene using O2WConverterImpl
masterThe
O2WConverterImplclass provides the primary entry points for converting OpenStreetMap (OSM) data into a 3DScene. 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:
- From an OSM Data Reader: Pass an
OSMDataReader, geographic bounds (GeoBounds), aMapProjection, and one or moreOutputobjects. This method handles the initial data loading phase. - From existing Map Data: If you have already processed the OSM data into
MapData, you can pass it directly along with aMapProjectionandOutputobjects 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);- From an OSM Data Reader: Pass an
Configure Attachment Surfaces in a Target
masterTo attach objects to the meshes generated by a
ProceduralWorldObject, you must configure theTargetbefore callingdrawMesh. This tells theTargetto create anAttachmentSurfacefor 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.