Contenuto principale

addMeshNode

R2026b

Add mesh node to RoadRunner Viewer scene graph

Since R2026b

    Description

    node = addMeshNode(rrViewer) adds an empty mesh node to the scene graph of the specified RoadRunner Viewer object rrViewer. You can use an empty mesh Node object as a parent node for multiple child nodes.

    node = addMeshNode(rrViewer,Name=Value) specifies additional options using one or more name-value arguments. For example, car = addMeshNode(rrViewer,Filepath="Vehicles/Sedan.fbx") adds the 3D mesh in the file Sedan.fbx to the node car.

    example

    Examples

    collapse all

    Add a 3D mesh node that uses the Sedan.fbx asset file to 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 Node object and add a 3D mesh to RoadRunner Viewer, use the addMeshNode function and specify the path to the 3D asset file you want to import. The path you specify must be relative to the Assets folder in your project.

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

    To modify the position and orientation of the 3D mesh, modify the LocalTransform property of the Node object sedan. To modify the color of the 3D mesh, use the setPaintColor function.

    sedan.LocalTransform(1,4) = 10;
    setPaintColor(sedan,[0.85 0.1 0.1]);

    To add a new node, childCar, as a child of sedan, use addMeshNode and specify the ParentNode argument as sedan. Then, modify the LocalTransform property of childCar so that it does not overlap sedan in the scene graph. Because child nodes move relative to their parent, you can use a parent node to modify the position of multiple child nodes at once.

    childCar = addMeshNode(rrViewer,Filepath="Vehicles/Sedan.fbx",ParentNode=sedan);
    childCar.LocalTransform(1,4) = 5;

    To update the scene graph and view the changes to the child node, use the drawnow function.

    drawnow(rrViewer)

    Input Arguments

    collapse all

    RoadRunner Viewer object to which to add a node, specified as a roadrunnerViewer 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: childCar = addMeshNode(rrViewer,Filepath="Vehicles/Sedan.fbx",ParentNode=sedan); adds a new mesh node, childCar, that uses the Sedan.fbx asset to the scene graph and specifies childCar as a child node of sedan.

    Path to the 3D mesh file, specified as a string scalar or character vector. RoadRunner Viewer supports adding 3D meshes with these file types:

    • glTF™ (.gltf, .glb)

    • Filmbox (.fbx)

    • OpenFlight (.flt)

    • OpenSceneGraph (.osg, .osgt, .osgb, .ive)

    • Wavefront® (.obj)

    The path you specify must be relative to the Assets folder in your project.

    Parent node of this node, specified as a Node object. Because RoadRunner Viewer positions child nodes relative to their parent, you can use parent nodes to modify the transforms of multiple child nodes at once.

    Node structure, specified as one of these options:

    • "articulated" — RoadRunner Viewer preserves the original mesh hierarchy of the specified 3D mesh, such as separate wheel and camera meshes, and adds the separate mesh nodes to the ChildNodes property of the parent Node object.

    • "rigid" — RoadRunner Viewer flattens the mesh hierarchy of the specified 3D mesh into a single Node object.

    Output Arguments

    collapse all

    3D mesh node, returned as a Node object. Use a Node object to modify the color and transforms of the corresponding 3D mesh in the scene graph.

    Version History

    Introduced in R2026b