Contenido principal

drawTrianglesFromMesh

R2026b

Draw triangles from 3D mesh file in RoadRunner Viewer scene graph

Since R2026b

    Description

    drawTrianglesFromMesh(pc,filepath,transform,color) draws triangles of the specified color, using the 3D mesh from the specified file filepath, in the specified primitive collection pc in the RoadRunner Viewer scene graph. drawTrianglesFromMesh uses the transform matrix transform to draw the triangles at the specified position, orientation, and scale. If the specified 3D mesh file contains multiple, separate meshes, this function draws triangles to form one 3D primitive from all meshes.

    example

    Examples

    collapse all

    Use a PrimitiveCollection object and the drawTrianglesFromMesh function to draw triangles from a 3D mesh file in the RoadRunner Viewer scene graph. 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 create a PrimitiveCollection object, pc, use the addPrimitive function and specify the roadrunnerViewer object rrViewer.

    pc = addPrimitive(rrViewer);

    To create a 4-by-4 transform matrix, xform, to use for your 3D primitive, use the eye function. To draw the triangles 5 meters from the scene graph origin along the x-axis, modify the values of xform.

    xform = eye(4);
    xform(1,4) = 5;

    To draw green triangles in the shape of a 3D mesh, Sedan.fbx, use the drawTrianglesFromMesh function and specify the primitive collection pc, the path to a 3D mesh file, the transform matrix xform, and the triangle color. The path you specify must be relative to the Assets folder in your project.

    drawTrianglesFromMesh(pc,"Vehicles/Sedan.fbx",xform,[0 1 0]);

    To update RoadRunner Viewer and view the changes to the primitives, use the drawnow function.

    drawnow(rrViewer)

    Input Arguments

    collapse all

    Primitive collection in which to add triangles, specified as a PrimitiveCollection object.

    Path to the 3D mesh file, specified as a string scalar or character vector. The path you specify must be relative to the Assets folder in your project.

    Transform matrix of the drawn triangles, in world coordinates, specified as a 4-by-4 matrix. The drawTrianglesFromMesh function applies the transform values to the triangles before drawing them in the scene graph.

    Triangle color, 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 triangle 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

    Version History

    Introduced in R2026b