主要内容

addMesh

R2026b

Add mesh to scene

Since R2026b

Description

Add-On Required: This feature requires the 3D Asset Processing Library for MATLAB add-on.

addMesh(sceneObj,meshObj) adds the mesh object meshObj to the scene object sceneObj. The mesh is attached to the base frame with an identity transform.

addMesh(sceneObj,meshObj,Name=Value) adds the mesh object meshObj using one or more name-value arguments. For example, Name="wheel" specifies the geometry name as "wheel".

example

Examples

collapse all

Create two meshes, a big rectangle mesh and another small rectangle mesh.

faces = [1 2 3; 1 3 4; 5 7 6; 5 8 7; 1 5 6; 1 6 2; 2 6 7; 2 7 3; 3 7 8; 3 8 4; 4 8 5; 4 5 1];

bigVerts = [0 0 0; 4 0 0; 4 3 0; 0 3 0; 0 0 1; 4 0 1; 4 3 1; 0 3 1];
bigMesh = asset3d.Mesh(bigVerts,faces,FaceColors=uint8([70 130 180]));

smallVerts = [0 0 0; 2 0 0; 2 1.5 0; 0 1.5 0; 0 0 0.8; 2 0 0.8; 2 1.5 0.8; 0 1.5 0.8];
smallMesh = asset3d.Mesh(smallVerts,faces,FaceColors=uint8([200 80 80]));

Create an empty scene with a base frame name.

scene = asset3d.Scene(BaseFrame="scene_model");

Add meshes to the scene with a big rectangle on the bottom and a small rectangle on top.

T = eye(4);
T(1:3,4) = [1; 0.75; 1];

addMesh(scene,bigMesh,Name="big_rect",NodeName="base")
addMesh(scene,smallMesh,Name="small_rect",NodeName="top",ParentNodeName="base",Transform=T)

Display the scene hierarchy. The |dispGraph| function shows the base frame name and the parent-child relationships between nodes.

dispGraph(scene)
scene_model
    └── base [Mesh: 12 faces]
        └── top [Mesh: 12 faces]

Display the scene.

show(scene,Grid=true)

Displays a scene with a big rectangle on the bottom and a small rectangle on top.

Input Arguments

collapse all

Source scene, specified as a Scene object.

Mesh to add, specified as a Mesh 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: addMesh(scene,mesh,Name="wheel",ParentNodeName="chassis") adds the mesh with the name "wheel" as a child of the "chassis" node.

Geometry name in the scene's Geometry dictionary, specified as a string. By default, the name is auto-generated as "geometry_0", "geometry_1", and so on.

Data Types: string

Node name in the scene graph, specified as a string. By default, the node name is the same as the geometry name Name.

Data Types: string

Parent node to attach to in the hierarchy, specified as a string. By default, the mesh is attached to the base frame which is the root node.

Data Types: string

Transformation relative to parent, specified as a 4-by-4 homogeneous transformation matrix or a rigidtform3d object.

Data Types: double

Version History

Introduced in R2026b