Generate scenes from code (headless)
Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.
The factories and exporters in
@drawtonomy/sdk are
pure functions. Everything the editor exports — OpenDRIVE, OpenSCENARIO,
Lanelet2 — can be produced from a plain Node.js script: in CI, in a
batch job, or from your own tooling.
Requires @drawtonomy/sdk 0.17.0 or later.
npm install @drawtonomy/sdkA complete example
Section titled “A complete example”Build a straight road with a moving vehicle and a pedestrian, and write all three formats to disk:
// generate.mjs — run with: node generate.mjsimport { createLaneWithBoundaries, createPathWithFootprints, createPedestrian, createSnapshot, exporter,} from '@drawtonomy/sdk'import { writeFileSync } from 'node:fs'
// Canvas units are pixels; 1 m = 16.67 px. 500 px = 30 m.const lane = createLaneWithBoundaries( [{ x: 0, y: 0 }, { x: 500, y: 0 }], // left boundary [{ x: 0, y: 50 }, { x: 500, y: 50 }], // right boundary (3 m wide lane))
// A driving path down the lane center. On export it becomes a timed// trajectory the vehicle follows (constant speed, 10 m/s by default).const path = createPathWithFootprints( [{ x: 0, y: 25 }, { x: 250, y: 25 }, { x: 500, y: 25 }], { count: 5 },)
const pedestrian = createPedestrian(300, 120)
const snapshot = createSnapshot([...lane, ...path, pedestrian])
writeFileSync('scene.xodr', exporter.exportToOpenDrive(snapshot, {}))writeFileSync('scene.xosc', exporter.exportToOpenScenario(snapshot, {}))writeFileSync('scene.osm', exporter.exportToLanelet2(snapshot, {}))What you get:
scene.xodr— OpenDRIVE 1.8 with real-world units (the 50 px lane comes out 3.0 m wide) and a<geoReference>projection string.scene.xosc— OpenSCENARIO 1.3 with two entities. The path becomes aFollowTrajectoryActionwhose polyline vertices carry timestamps, so esmini plays it back directly:esmini --osc scene.xosc --window 60 60 800 400.scene.osm— a Lanelet2 map (wayboundaries +relation type=lanelet) that round-trips into Autoware-compatible tooling.
Parsing generated (or existing) maps
Section titled “Parsing generated (or existing) maps”The exporters have matching parsers, so generated output round-trips:
import { readFileSync } from 'node:fs'import { exporter } from '@drawtonomy/sdk'
const parsed = exporter.parseOpenDriveXml(readFileSync('scene.xodr', 'utf8'))const { lanes, linestrings, points, warnings } = exporter.odrToShapes(parsed)The same works for Lanelet2 via parseOsmXml + osmToShapes.
Opening a generated scene in the editor
Section titled “Opening a generated scene in the editor”The editor reads scene JSON, so a generated snapshot can be inspected
visually: save JSON.stringify(snapshot) to a .json file and import
it via the hamburger menu, or share it as a URL with the
?snapshot= parameter.
Where the boundary is
Section titled “Where the boundary is”Trajectories exported this way run at a constant speed along the path. Triggers, event logic, speed profiles, and controller behavior (ACC, cut-in conditions, …) are authored in the editor’s scenario mode, which round-trips real-world OpenSCENARIO files with high fidelity.
See also
Section titled “See also”@drawtonomy/sdkoverview — all modules at a glance- SDK README — extension (iframe) workflow
- Export formats — everything the editor reads and writes