Drake
Drake C++ Documentation
Mesh Class Referencefinal

Detailed Description

Definition of a general (possibly non-convex) mesh.

The mesh may be a triangular surface mesh or a tetrahedral volume mesh, depending on how it used.

Meshes can be used with all three roles but, currently, the support for the proximity role is limited. Where a general mesh is not supported, the mesh is replaced by its convex hull. See the documentation of QueryObject's proximity queries for more details. The notable cases where the actual mesh topology is used includes:

  • Computing signed distances from the Mesh to query points (when it references a .obj file or a tetrahedral .vtk file).
  • Specifying the Mesh as rigid hydroelastic (when it references a triangle .obj file or a tetrahedral .vtk file).
  • Specifying the Mesh as compliant hydroelastic (when it references a tetrahedral .vtk file).
  • Specifying the Mesh as deformable (when it references a tetrahedral .vtk file).

This convex-hull substitution is a regrettable stop-gap solution until we fully support general, non-convex meshes throughout proximity queries.

For visual roles (illustration and perception), the specified mesh file is used as directly as possible.

The mesh is defined in a canonical frame C, implicit in the file parsed. Upon loading it in SceneGraph it can be scaled around the origin of C by a given scale amount.

#include <drake/geometry/shape_specification.h>

Public Member Functions

 Mesh (const std::filesystem::path &filename, double scale=1.0)
 Constructs a mesh shape specification from the mesh file located at the given file path. More...
 
 Mesh (InMemoryMesh mesh_data, double scale=1.0)
 Constructs a mesh shape specification from the contents of a Drake-supported mesh file type. More...
 
 Mesh (MeshSource source, double scale=1.0)
 Constructs a mesh shape specification from the given source. More...
 
 ~Mesh () final
 
const MeshSourcesource () const
 Returns the source for this specification's mesh data. More...
 
std::string filename () const
 Returns the filename passed to the constructor. More...
 
const std::string & extension () const
 Returns the extension of the mesh type – all lower case and including the dot. More...
 
double scale () const
 
const PolygonSurfaceMesh< double > & GetConvexHull () const
 Reports the convex hull of the named mesh. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 Mesh (const Mesh &)=default
 
Meshoperator= (const Mesh &)=default
 
 Mesh (Mesh &&)=default
 
Meshoperator= (Mesh &&)=default
 
- Public Member Functions inherited from Shape
virtual ~Shape ()
 
void Reify (ShapeReifier *reifier, void *user_data=nullptr) const
 Causes this description to be reified in the given reifier. More...
 
std::unique_ptr< ShapeClone () const
 Creates a unique copy of this shape. More...
 
std::string_view type_name () const
 Returns the (unqualified) type name of this Shape, e.g., "Box". More...
 
std::string to_string () const
 Returns a string representation of this shape. More...
 
template<typename ReturnType = void, typename Visitor >
decltype(auto) Visit (Visitor &&visitor) const
 Calls the given visitor function with *this as the sole argument, but with *this downcast to be the shape's concrete subclass. More...
 

Additional Inherited Members

- Protected Types inherited from Shape
using VariantShapeConstPtr = std::variant< const Box *, const Capsule *, const Convex *, const Cylinder *, const Ellipsoid *, const HalfSpace *, const Mesh *, const MeshcatCone *, const Sphere * >
 (Internal use only) All concrete subclasses, as const pointers. More...
 
- Protected Member Functions inherited from Shape
 Shape ()
 (Internal use only) Constructor for use by derived classes. More...
 
 Shape (const Shape &)=default
 (Internal use only) For derived classes. More...
 
Shapeoperator= (const Shape &)=default
 (Internal use only) For derived classes. More...
 
 Shape (Shape &&)=default
 (Internal use only) For derived classes. More...
 
Shapeoperator= (Shape &&)=default
 (Internal use only) For derived classes. More...
 

Constructor & Destructor Documentation

◆ Mesh() [1/5]

Mesh ( const Mesh )
default

◆ Mesh() [2/5]

Mesh ( Mesh &&  )
default

◆ Mesh() [3/5]

Mesh ( const std::filesystem::path &  filename,
double  scale = 1.0 
)
explicit

Constructs a mesh shape specification from the mesh file located at the given file path.

Optionally uniformly scaled by the given scale factor.

The mesh file referenced can be an .obj, a volume mesh in a .vtk, or a .gltf file. However, not all file formats are appropriate for all roles. (E.g., a tetrahedral .vtk file should not be assigned a perception role.)

Parameters
filenameThe file name; if it is not absolute, it will be interpreted relative to the current working directory.
scaleAn optional scale to coordinates.
Exceptions
std::exceptionif |scale| < 1e-8. Note that a negative scale is considered valid. We want to preclude scales near zero but recognise that scale is a convenience tool for "tweaking" models. 8 orders of magnitude should be plenty without considering revisiting the model itself.

◆ Mesh() [4/5]

Mesh ( InMemoryMesh  mesh_data,
double  scale = 1.0 
)
explicit

Constructs a mesh shape specification from the contents of a Drake-supported mesh file type.

The mesh is defined by the contents of a mesh file format supported by Drake. Those contents are passed in as mesh_data. The mesh data should include the main mesh file's contents as well as any supporting file contents as needed. See InMemoryMesh.

Parameters
mesh_dataThe in-memory file contents that define the mesh data for this shape.
scaleAn optional scale to coordinates.

◆ Mesh() [5/5]

Mesh ( MeshSource  source,
double  scale = 1.0 
)
explicit

Constructs a mesh shape specification from the given source.

Parameters
sourceThe source for the mesh data.
scaleAn optional scale to coordinates.

◆ ~Mesh()

~Mesh ( )
final

Member Function Documentation

◆ extension()

const std::string& extension ( ) const

Returns the extension of the mesh type – all lower case and including the dot.

If this is constructed from a file path, the extension is extracted from the path. I.e., /foo/bar/mesh.obj and /foo/bar/mesh.OBJ would both report the ".obj" extension. The "extension" portion of the filename is defined as in std::filesystem::path::extension().

If this is constructed using in-memory file contents, it is the extension of the MemoryFile passed to the constructor.

◆ filename()

std::string filename ( ) const

Returns the filename passed to the constructor.

Exceptions
std::exceptionif this Mesh was constructed using in-memory file contents.
See also
source().is_path(). (Deprecated.)
Deprecated:
Meshes can be defined from a file path or in memory data. Use Mesh::source() to determine if a filename is available.
This will be removed from Drake on or after 2025-04-01.

◆ GetConvexHull()

const PolygonSurfaceMesh<double>& GetConvexHull ( ) const

Reports the convex hull of the named mesh.

Note: the convex hull is computed on demand on the first invocation. All subsequent invocations should have an O(1) cost.

Exceptions
ifthe referenced mesh data cannot be read or is degenerate (insufficient number of vertices, co-linear or coincident vertices, etc.) All of the vertices lying on a plane is not considered degenerate.

◆ operator=() [1/2]

Mesh& operator= ( const Mesh )
default

◆ operator=() [2/2]

Mesh& operator= ( Mesh &&  )
default

◆ scale()

double scale ( ) const

◆ source()

const MeshSource& source ( ) const

Returns the source for this specification's mesh data.


The documentation for this class was generated from the following file: