主要内容

addLaneMaterial

Apply material to entire lane or a section of lane

Since R2026b

    Description

    polygonMaterial = addLaneMaterial(scn,lane,startDistance,endDistancematerialReference) adds a material to the specified lane over a given longitudinal range. The startDistance and endDistance arguments define the distance along the lane where the you want to apply the material.

    example

    polygonMaterial = addLaneMaterial(scn,lane,startDistance,endDistancematerialReference,Name=Value) adds a material to the specified lane over a given longitudinal range and optional lateral bounds. The startDistance and endDistance arguments define the distance along the lane where the you want to apply the material. The width and the offset define the lateral region of the lane where the you want to apply the material. If you do not specify the width and the offset, RoadRunner applies the material across the entire width of the lane for the specified longitudinal range. You must use this function define or modify surface materials on a lane without knowing the bounds. This is useful for curved lanes since computing bounds manually can be challenging.

    Examples

    collapse all

    Use the addLaneMaterial function to apply a material to the specified lane over a given longitudinal range.

    Create a roadrunner object, specifying the path to an existing project. For example, this code shows the path to a project, on a Windows® machine, located at "C:\RR\MyProject". This code assumes that RoadRunner is installed in the default location, and returns an object, rrApp, that provides functions for performing basic tasks such as opening, closing, and saving scenes and projects.

    rrApp = roadrunner(ProjectFolder="C:\RR\MyProject");

    Note: If you are opening RoadRunner from MATLAB® for the first time, or if you have changed the RoadRunner installation location since you last opened it from MATLAB, you can use the roadrunnerSetup (RoadRunner) function to specify new default project and installation folders to use when opening RoadRunner. You can save these folders between RoadRunner sessions by selecting the Across MATLAB sessions option from the corresponding drop down.

    Create a new RoadRunner scene in the current project by using the newScene function, specifying the roadrunner object rrApp.

    newScene(rrApp);

    Create an object for the RoadRunner authoring API, rrApi, that references the object for the current RoadRunner instance rrApp. The rrApi object enables you to programmatically author scenes, such as by adding and modifying road and lanes components, using MATLAB.

    rrApi = roadrunnerAPI(rrApp);

    Extract the object for your scene from the Scene property of the authoring API object rrApi. The extracted Scene object enables you to specify the scene in which to add scene elements such as roads and lanes.

    scn = rrApi.Scene;

    Add a horizontal line-arc curve road 100 meters in length to the scene by using the addLineArcRoad function. Specify the positions of the road by specifying the positions of its control points along the X- and Y-axes of the RoadRunner local coordinate system. These control points define the positions of the start and end of the road. You can modify the positions of the control points to adjust the length and direction of the road relative to the scene origin. You can also add control points in between the start and end points of the line-arc curve to adjust the curvature and radius of the road curve.

    controlPoints = [-50 0; 50 0];
    rrHorizontalRoad = addLineArcRoad(scn,controlPoints);

    Extract the reference lane of the road from the ReferenceLane property of the road object rrHorizontalRoad. The reference lane defines the center lane, or reference line, of a road in a RoadRunner scene. This lane has no width and serves as the basis for positioning all other lanes, which RoadRunner arranges outward from the reference line.

    refLane = rrHorizontalRoad.ReferenceLane;

    Use the extracted refLane object to add lanes on either side of the reference lane of the road using the addLaneToLeft and addLaneToRight functions. Then, use the LaneType and TravelDirection properties of the added lanes to specify the type and travel direction, respectively, of each lane. First, add a driving lane to the left of the horizontal road with a forward travel direction.

    horizontalLane1 = addLaneToLeft(refLane);
    horizontalLane1.LaneType = "driving";
    horizontalLane1.TravelDirection = "forward";

    Then, add another driving lane to the right of the horizontal road with a backward travel direction.

    horizontalLane2 = addLaneToRight(refLane);
    horizontalLane2.LaneType = "driving";
    horizontalLane2.TravelDirection = "backward";

    Use the getAsset function to extract a Material object, grassMaterial, that represents the Grass1.rrmtl asset in the project prj.

    grassMaterial = getAsset(prj,"Materials/Grass1.rrmtl","Material");
    

    Use the addLaneMaterial function to add the grass material to the lane horizontalLane2 from 10meters to 30meters along the lane.

    addLaneMaterial(scn, horizontalLane2, 10, 30, grassMaterial)

    Input Arguments

    collapse all

    Scene to which to add the road, specified as a Scene object.

    Lane to which to apply the material, specified as a Lane (RoadRunner)Lane object.

    Distance from the start of the lane along the road, specified as a numeric scalar. The startDistance along the lane defines the distance at which to apply the material. Units are in meters. Distances are measured relative to the start of the road reference line, and must lie within the range [0, Length], where 0 is the start of the lane and Length is the total length of the lane.

    Data Types: double

    End distance along the lane, specified as a numeric scalar. The startDistance along the lane defines the distance at which to apply the material. Units are in meters. Distances are measured relative to the end of the road reference line, and must lie within the range [startDistance, Length], where startDistance is measured from the start of the lane and Length is the total length of the lane.

    Data Types: double

    Material applied to lane surface, specified as a Material object.

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: addLaneMaterial(scn,lane,10,30,grassMaterial,"Width=1.75") applies the grass material from 10m to 30m along the lane covering a width of 1.5meters starting 0.5meters from the reference lane.

    Width of material region, specified as a numeric scalar. When you do not specify the width of the region to which to apply the material, RoadRunner applies the material to the entire lane width.

    Data Types: double

    Lateral offset from the reference lane, specified as a numeric scalar. A positive value represents a lane boundary offset to the left of the material, while a negative value represents a lane boundary offset to the right of the material. Units are in meters.

    Data Types: double

    Layering order for overlapping materials, specified as a numeric scalar. When materials of different types overlap, RoadRunner places the material with the higher sort index at the top, followed by materials having a lower sort index value.

    Data Types: int32

    Output Arguments

    collapse all

    Polygon shaped region to which the material is applied, specified as a PolygonMaterial object.

    More About

    collapse all

    Version History

    Introduced in R2026b