주요 콘텐츠

setPaintColor

R2026b

Specify 3D mesh node color

Since R2026b

    Description

    setPaintColor(node,color) changes the color of the specified 3D mesh node to the specified color color. If the specified mesh node has children, this function also sets the child nodes to the same color. To change the color of 3D meshes in RoadRunner Viewer, the 3D mesh you specify must have a material with a name that includes the string "paint". For meshes that reference a separate material file, such as an .rrmtl file, the file name must be paint. For information on how to assign 3D mesh materials, see Assign Materials (RoadRunner Scenario).

    If the mesh does not have a compatible material, setPaintColor does nothing.

    example

    Examples

    collapse all

    Use the setPaintColor function to change the color of a 3D mesh node.

    This example assumes you have already added the folder containing the RoadRunner API to your MATLAB® path and created a project folder. For information on getting started with RoadRunner Viewer, see Get Started with RoadRunner Viewer (RoadRunner Scenario).

    Specify the path to a project folder. RoadRunner Viewer uses the 3D mesh, material, and image files in the Assets folder of the specified project.

    If you do not have a project folder and want to create one that already contains an Assets folder with sample files, create a RoadRunner project. By default, RoadRunner projects contain an Assets folder prepopulated with sample assets, such as a Sedan.fbx file, that you can use in RoadRunner Viewer. For information on creating a RoadRunner project, see RoadRunner Project and Scene System (RoadRunner).

    myProject="C:\users\MyProject"

    Open RoadRunner Viewer and specify your project folder.

    rrViewer = roadrunnerViewer(ProjectFolder=myProject);
    

    To add a 3D mesh, Sedan.fbx, from your project to the RoadRunner Viewer scene graph, use the addMeshNode function. The path you specify must be relative to the Assets folder in your project.

    sedan = addMeshNode(rrViewer,Filepath="Vehicles/Sedan.fbx");

    To set the paint color of the 3D mesh, use setPaintColor and specify the 3D mesh sedan and the color values.

    setPaintColor(sedan,[0.85 0.1 0.1 1]);

    Input Arguments

    collapse all

    3D mesh node for which to specify color, specified as a Node object.

    Color of the 3D mesh node, specified as a four-element vector of the form [R,G,B,A], a three-element vector of the form [R,G,B], a string scalar, or a character vector. If specified as a vector, R, G, B, and A represent the red, green, blue, and alpha values for the mesh color, respectively. If specified as a string scalar or character vector, you must use a color name, such as "blue", or a hexadecimal value, such as "#0072BD".

    This table lists the named color options, the equivalent RGBA values, and the hexadecimal color codes.

    Color NameShort NameRGBA ValueHexadecimal Color CodeAppearance
    "red""r"[1 0 0 1]"#FF0000"

    Sample of the color red

    "green""g"[0 1 0 1]"#00FF00"

    Sample of the color green

    "blue""b"[0 0 1 1]"#0000FF"

    Sample of the color blue

    "cyan" "c"[0 1 1 1]"#00FFFF"

    Sample of the color cyan

    "magenta""m"[1 0 1 1]"#FF00FF"

    Sample of the color magenta

    "yellow""y"[1 1 0 1]"#FFFF00"

    Sample of the color yellow

    "black""k"[0 0 0 1]"#000000"

    Sample of the color black

    "white""w"[1 1 1 1]"#FFFFFF"

    Sample of the color white

    Limitations

    • The setPaintColor function does not support specifying color for 3D meshes that do not have a material with a name that contains the string "paint". For meshes that reference a separate material file, such as an .rrmtl file, the file name must be paint.

    Version History

    Introduced in R2026b