Implementation:CARLA simulator Carla MeshFactory Interface
| Knowledge Sources | |
|---|---|
| Domains | Road Network, Rendering |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
The MeshFactory class generates 3D mesh geometry from road, lane section, and lane data for rendering the road network in the CARLA simulator.
Description
carla::geom::MeshFactory is a mesh helper generator initialized with OpendriveGenerationParameters. It provides a comprehensive set of overloaded Generate() methods that produce std::unique_ptr<Mesh> objects from various road elements:
- Basic generation -- meshes for entire roads, lane sections, individual lanes (with start/end s parameters), and tesselated variants for higher detail
- Sidewalk generation -- specialized mesh generation for sidewalk lanes with height offsets
- Wall generation -- safety wall meshes at road corners to prevent vehicles from falling off edges
- Chunked generation -- methods like
GenerateWithMaxLen()andGenerateOrderedWithMaxLen()that split long roads into multiple meshes with a configurable maximum length - Lane mark generation --
GenerateLaneMarkForRoad(),GenerateLaneMarksForNotCenterLine(), andGenerateLaneMarksForCenterLine()for line marking meshes - Mesh smoothing --
MergeAndSmooth()for combining and smoothing junction lane meshes
The RoadParameters struct contains configurable values for resolution (2.0m), max road length (50.0m), extra lane width (1.0m), wall height (0.6m), and smoothing weights.
Usage
Use this class when generating visual geometry from the OpenDRIVE road data, particularly for the Unreal Engine rendering pipeline. The Map class uses MeshFactory internally for its mesh generation methods.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/road/MeshFactory.h
Signature
class MeshFactory {
public:
MeshFactory(rpc::OpendriveGenerationParameters params = ...);
std::unique_ptr<Mesh> Generate(const road::Road &road) const;
std::unique_ptr<Mesh> Generate(const road::LaneSection &lane_section) const;
std::unique_ptr<Mesh> Generate(const road::Lane &lane, const double s_start, const double s_end) const;
std::unique_ptr<Mesh> Generate(const road::Lane &lane) const;
std::unique_ptr<Mesh> GenerateTesselated(const road::Lane &lane, ...) const;
std::unique_ptr<Mesh> GenerateSidewalk(const road::Lane &lane) const;
std::unique_ptr<Mesh> GenerateWalls(const road::LaneSection &lane_section) const;
std::unique_ptr<Mesh> GenerateRightWall(const road::Lane &lane, ...) const;
std::unique_ptr<Mesh> GenerateLeftWall(const road::Lane &lane, ...) const;
std::vector<std::unique_ptr<Mesh>> GenerateWithMaxLen(const road::Road &road) const;
std::map<road::Lane::LaneType, std::vector<std::unique_ptr<Mesh>>>
GenerateOrderedWithMaxLen(const road::Road &road) const;
std::vector<std::unique_ptr<Mesh>> GenerateAllWithMaxLen(const road::Road &road) const;
std::unique_ptr<Mesh> MergeAndSmooth(std::vector<std::unique_ptr<Mesh>> &lane_meshes) const;
void GenerateLaneMarkForRoad(const road::Road &road, ...) const;
struct RoadParameters {
float resolution = 2.0f;
float max_road_len = 50.0f;
float extra_lane_width = 1.0f;
float wall_height = 0.6f;
// ...
};
RoadParameters road_param;
};
Import
#include "carla/road/MeshFactory.h"
I/O Contract
| Input | Type | Description |
|---|---|---|
road::Road | Road segment to generate mesh for
| ||
road::LaneSection | Lane section to generate mesh for
| ||
road::Lane | Individual lane to generate mesh for
| ||
OpendriveGenerationParameters | Generation parameters (resolution, etc.)
|
| Output | Type | Description |
|---|---|---|
std::unique_ptr<Mesh> | Generated triangle mesh
| ||
std::vector<std::unique_ptr<Mesh>> | Chunked meshes with max length
|
Usage Examples
carla::geom::MeshFactory factory(params);
// Generate mesh for an entire road
auto road_mesh = factory.Generate(road);
// Generate chunked meshes ordered by lane type
auto ordered = factory.GenerateOrderedWithMaxLen(road);