getVisual
Description
Examples
Replace Rigid Body Collision Meshes with Decompositions of Visual Meshes
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:
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
body
— RigidBody
object
handle
RigidBody
object, specified as a handle. Create a rigid body
object using rigidBody
.
Output Arguments
meshData
— Visual mesh data of rigid body
N-element array of structures
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
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)