Skip to content

Commit

Permalink
Use the scale in the externalMesh object
Browse files Browse the repository at this point in the history
  • Loading branch information
fjandrad committed Apr 5, 2020
1 parent e803d3e commit cfac9c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 7 additions & 3 deletions bindings/matlab/+iDynTreeWrappers/getMeshes.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
meshInfo=struct('meshFile',{},'mesh_triangles',{},'link_H_geom',{});
for solids=1:solids_number
if solidarray{solids}.isExternalMesh
meshName=split(solidarray{solids}.asExternalMesh.filename,':');
externalMesh=solidarray{solids}.asExternalMesh;
scale=externalMesh.scale.toMatlab;
meshName=split(externalMesh.filename,':');
meshFile=meshName{2};
% Import an STL mesh, returning a PATCH-compatible face-vertex structure
mesh_triangles = stlread([meshFilePrefix meshFile]);
mesh_triangles = stlread([meshFilePrefix meshFile]);
meshInfo(solids).meshFile=meshFile;
meshInfo(solids).scale=scale';
else
meshInfo(solids).scale=[1,1,1];
if solidarray{solids}.isCylinder
meshInfo(solids).meshFile='cylinder';
length=solidarray{solids}.asCylinder.length;
Expand All @@ -64,7 +68,7 @@
end
link_H_geom=solidarray{solids}.link_H_geometry.asHomogeneousTransform.toMatlab;
meshInfo(solids).link_H_geom=link_H_geom;
meshInfo(solids).mesh_triangles=mesh_triangles;
meshInfo(solids).mesh_triangles=mesh_triangles;
map(count,:)=[{meshFile},{linkName}];
count=count+1;
end
Expand Down
11 changes: 4 additions & 7 deletions bindings/matlab/+iDynTreeWrappers/plotMeshInWorld.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@
% Default values
meshColor= [0.1843 0.3098 0.3098];
transparency=0.5;
scaleRatio=1/1000;

% create a transform object %
transform = hgtransform('Parent',gca);
for mesh_number=1:length(linkMeshInfo.meshInfo)

mesh_triangles=linkMeshInfo.meshInfo(mesh_number).mesh_triangles;
link_H_geom=linkMeshInfo.meshInfo(mesh_number).link_H_geom;
scale=linkMeshInfo.meshInfo(mesh_number).scale;

% Change scale only for stl meshes
if ~strcmp({'cylinder','box','sphere'},linkMeshInfo.meshInfo(mesh_number).meshFile)
corrected_vertices=mesh_triangles.Points*scaleRatio;
else
corrected_vertices=mesh_triangles.Points;
end
% Change scale
% Scale the STL mesh
corrected_vertices=mesh_triangles.Points.*scale;

% Applying transform to link frame to stl file :
corrected_vertices=link_H_geom*[corrected_vertices';ones(1,size(corrected_vertices,1))];
Expand Down

0 comments on commit cfac9c4

Please sign in to comment.