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)

    Figure contains 2 axes objects. Axes object 1 with title Top Down View, xlabel X, ylabel Y contains 53 objects of type patch, line. These objects represent base, controller_box, pedestal_feet, pedestal, right_arm_base_link, right_l0, head, screen, head_camera, right_l1, right_l2, right_l3, right_l4, right_arm_itb, right_l5, right_hand_camera, right_l6, right_hand, right_wrist, right_torso_itb, torso, pedestal_mesh, right_arm_base_link_mesh, right_l0_mesh, head_mesh, screen_mesh, right_l1_mesh, right_l2_mesh, right_l3_mesh, right_l4_mesh, right_l5_mesh, right_l6_mesh, torso_mesh. Axes object 2 with title Top Down View, xlabel X, ylabel Y contains 55 objects of type patch, line. These objects represent base, controller_box, pedestal_feet, pedestal, right_arm_base_link, right_l0, head, screen, head_camera, right_l1, right_l2, right_l3, right_l4, right_arm_itb, right_l5, right_hand_camera, right_l6, right_hand, right_wrist, right_torso_itb, torso, pedestal_mesh, right_arm_base_link_mesh, right_l0_mesh, head_mesh, screen_mesh, right_l1_mesh, right_l2_mesh, right_l3_mesh, right_l4_mesh, right_l5_mesh, right_l6_mesh, torso_mesh, controller_box_coll_mesh, pedestal_feet_coll_mesh, pedestal_coll_mesh, right_arm_base_link_coll_mesh, right_l0_coll_mesh, head_coll_mesh, screen_coll_mesh, right_l1_coll_mesh, right_l2_coll_mesh, right_l3_coll_mesh, right_l4_coll_mesh, right_l5_coll_mesh, right_l6_coll_mesh, right_hand_coll_mesh.

    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

    Figure contains 2 axes objects. Axes object 1 with title Before Decomposition, xlabel X, ylabel Y contains 55 objects of type patch, line. These objects represent base, controller_box, pedestal_feet, pedestal, right_arm_base_link, right_l0, head, screen, head_camera, right_l1, right_l2, right_l3, right_l4, right_arm_itb, right_l5, right_hand_camera, right_l6, right_hand, right_wrist, right_torso_itb, torso, pedestal_mesh, right_arm_base_link_mesh, right_l0_mesh, head_mesh, screen_mesh, right_l1_mesh, right_l2_mesh, right_l3_mesh, right_l4_mesh, right_l5_mesh, right_l6_mesh, torso_mesh, controller_box_coll_mesh, pedestal_feet_coll_mesh, pedestal_coll_mesh, right_arm_base_link_coll_mesh, right_l0_coll_mesh, head_coll_mesh, screen_coll_mesh, right_l1_coll_mesh, right_l2_coll_mesh, right_l3_coll_mesh, right_l4_coll_mesh, right_l5_coll_mesh, right_l6_coll_mesh, right_hand_coll_mesh. Axes object 2 with title After Decomposition, xlabel X, ylabel Y contains 108 objects of type patch, line. These objects represent base, controller_box, pedestal_feet, pedestal, right_arm_base_link, right_l0, head, screen, head_camera, right_l1, right_l2, right_l3, right_l4, right_arm_itb, right_l5, right_hand_camera, right_l6, right_hand, right_wrist, right_torso_itb, torso, pedestal_mesh, right_arm_base_link_mesh, right_l0_mesh, head_mesh, screen_mesh, right_l1_mesh, right_l2_mesh, right_l3_mesh, right_l4_mesh, right_l5_mesh, right_l6_mesh, torso_mesh, controller_box_coll_mesh, pedestal_feet_coll_mesh, pedestal_coll_mesh, right_arm_base_link_coll_mesh, right_l0_coll_mesh, head_coll_mesh, screen_coll_mesh, right_l1_coll_mesh, right_l2_coll_mesh, right_l3_coll_mesh, right_l4_coll_mesh, right_l5_coll_mesh, right_l6_coll_mesh.

    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