xodr 0.8.0

Pure-Rust OpenDRIVE (.xodr) importer: bakes a road network into polylines, a lane graph, and a surface mesh.
Documentation

xodr

CI MSRV 1.85

A pure-Rust OpenDRIVE (.xodr) importer. It turns a map into lanes, a lane graph, and a mesh of the road surface. It also reads the OpenCRG (.crg) files a map uses.

use xodr::{load_file, Point};

let net = load_file("maps/town07.xodr")?;

// Where is the road under this point, and which way does it lean?
let sample = net.sample_near(Point::new(12.0, -30.0, 0.0)).expect("on the map");
println!("{:?} banked {} rad", sample.point, sample.bank);

// Where is that on its road, in OpenDRIVE's own s and t?
let at = net.road_position(sample.point).expect("on a road");
println!("road {} s {} t {}", net.road(at.road).unwrap().od_id(), at.s, at.t);

// Drive somewhere.
let waypoints = net.route(sample.point, Point::new(280.0, 95.0, 0.0));

// Hand the surface to a collider or a renderer.
let mesh = net.surface_mesh();
mesh.validate()?;

What it builds

Test maps in the viewer. Click a picture for details.

Temporary lanes, tinted amber, over the permanent lanes of a road Two posts on a banked road: one plumb, one leaning with the road
Lane layers. Temporary lanes, amber, over the permanent ones. Object poses. Plumb by default. The left post has perpToRoad="true".
A traffic light pole with an arm over the road, drawn as tapered tubes Smooth traffic islands, a circle and a wave drawn from curves
Skeletons. A pole and arm from <skeleton> polylines. Curved outlines. Islands from <curveLocal> curves.
A grass island with cobble and concrete areas inside it and one hole A parking bay with a solid and a dashed line, and a painted arrow
Inner outlines. Cobble and concrete areas, and a hole. Markings. A parking bay's lines and a painted area.
Rows of posts and walls along a curved road, two of them straight across it The height an object's CRG adds, as a heat map over a turned square
Repeats. Posts and walls. Two are detached from the road. Object surfaces. The height an object's CRG adds.

What it reads

Every element and attribute of the OpenDRIVE 1.9 schema. Of its 671 rows, 420 shape the network and 251 are kept as data. It also reads the crossfall of OpenDRIVE 1.4. docs/support.md says what it does with each element.

From that it builds:

  • roads you can query in (road, s, t) or (lane, s, offset), both ways;
  • lanes with widths, heights and layers, and a lane graph through default, direct and virtual junctions;
  • speed limits from speed records, signs and default regulations;
  • objects, signals and road marks, placed on the road;
  • the road surface under a wheel, from elevation, shape and OpenCRG.

It loads any OpenDRIVE version. Provenance::warnings lists what it dropped, what it ignores, and features newer than the header's version. Warning::is_ignored tells ignored features from faults.

Viewer

The crate draws nothing. viewer/ is a three.js page that runs the crate as WebAssembly. Open a .xodr and hover anything to see what the crate knows about it.

sh viewer/run.sh   # serves http://localhost:8000

A traffic island's details in the viewer

OpenUSD

usd/ exports a map as an OpenUSD stage. It's a separate tool, not part of the crate.

cargo run --release -p xodr-usd -- tests/data/town07.xodr

How it fits together

A .xodr and its CRG files go into load_file_with_provenance, which builds a RoadNetwork and its Provenance. Callers query the network, mesh it, and sample the road surface. The viewer and xodr-usd use the meshes.

More

The published crate has no tests or maps. Run them from a git checkout.

MSRV is 1.85.

License

MIT or Apache-2.0, at your option.