getVisual
Description
Examples
Load the Rethink Robotics Sawyer robot.
robot = loadrobot("rethinkSawyer",DataFormat="row")
robot = rigidBodyTree with properties: NumBodies: 20 Bodies: {1×20 cell} Base: [1×1 rigidBody] BodyNames: {1×20 cell} BaseName: 'base' Gravity: [0 0 0] DataFormat: 'row' FrameNames: {1×21 cell}
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:
Get the current rigid body and clear the current collision mesh.
Get the corresponding visual data if there is any.
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.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
RigidBody
object, specified as a handle. Create a rigid body
object using rigidBody
.
Output Arguments
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 atriangulation
object.Color
— Mesh color, stored as an RGB triplet.Tform
— Homogeneous transformation of the mesh, stored as a 4-by-4 matrix. The pose is relative to the origin of the rigid body.Scale
— xyz-scale of the mesh's bounding box, stored as a three-element row vector. The scaling is along the axes of the origin frame of the rigid body.
Version History
Introduced in R2023b
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)