Main Content

getVisual

Get visual geometries of the rigid body

Since R2023b

    Description

    example

    meshData = getVisual(body) gets the visual mesh data for the rigid body.

    Examples

    collapse all

    Load the Rethink Robotics Sawyer robot.

    robot = loadrobot("rethinkSawyer",DataFormat="row")
    robot = 
      rigidBodyTree with properties:
    
         NumBodies: 20
            Bodies: {1x20 cell}
              Base: [1x1 rigidBody]
         BodyNames: {1x20 cell}
          BaseName: 'base'
           Gravity: [0 0 0]
        DataFormat: 'row'
    
    

    Show the robot with just the visual meshes and show the robot with just the collision meshes. Use a vertical view so the difference between the arms is more clear.

    tiledlayout(1,2)
    sgtitle("Rethink Robotics Sawyer")
    nexttile
    show(robot,Visuals="on",Collisions="off");
    title("Top Down View")
    axis auto
    view(90,90)
    nexttile
    show(robot,Visuals="off",Collisions="on");
    title("Top Down View")
    axis auto
    view(90,90)

    Note that each body of the arm is represented by a single convex mesh that does not accurately represent the physical boundaries of the arm. To achieve more accurate collision checking, you must decompose the visual meshes of the robot. The rigid body tree stores the rigid bodies of the arm at indices 9 to 17.

    First, create V-HACD solver options for individual mesh decompositions with the maximum number of convex hulls set to 10.

    opts = vhacdOptions("IndividualMesh",MaxNumConvexHulls=10);

    Then for each rigid body:

    1. Get the current rigid body and clear the current collision mesh.

    2. Get the corresponding visual data if there is any.

    3. If there is visual data, use collisionVHACD with the custom solver options to decompose the triangulation of the visual data into an array of collision meshes.

    4. Add each collision mesh from the array of collision meshes to the rigid body.

    for bodyIdxToReplace = 9:17
        % 1. Get current body and clear collision mesh
        currBody = robot.Bodies{bodyIdxToReplace};
        clearCollision(currBody);
    
        % 2. Get Corresponding visual data
        vizData = getVisual(robot.Bodies{bodyIdxToReplace});
    
        % 3. If visual data, decompose visual data
        if ~isempty(vizData)
            collisionArray = collisionVHACD(vizData(1).Triangulation,opts);
    
            % 4. Add each collision mesh to the rigid body
            for j = 1:numel(collisionArray)
                addCollision(currBody,collisionArray{j});
            end
        end
    end

    Show the original collision meshes of the robot arm next to the updated collision mesh of the arm.

    tiledlayout(1,2);
    sgtitle("Rethink Robotics Sawyer")
    nexttile
    robotOriginal = loadrobot("rethinkSawyer",DataFormat="row");
    show(robotOriginal,Visuals="off",Collisions="on");
    title("Before Decomposition")
    axis auto
    view(90,90)
    nexttile
    show(robot,Visuals="off",Collisions="on");
    title("After Decomposition")
    view(90,90)
    axis auto

    Note that in this case the new collision meshes represent the robot arm more accurately.

    Input Arguments

    collapse all

    RigidBody object, specified as a handle. Create a rigid body object using rigidBody.

    Output Arguments

    collapse all

    Visual mesh data of the rigid body, returned as an N-element array of structures. N is the number of visual meshes of the rigid body.

    Each structure contains these fields:

    • Triangulation — Visual mesh, stored as a triangulation object.

    • Color — Mesh color, stored as an RGB triplet.

    • Pose— Homogeneous transformation of the mesh, stored as a 4-by-4 matrix. The pose is relative to the origin of the rigid body.

    Version History

    Introduced in R2023b