Avara3D 0.2.0
C++ API reference
a3d::Mesh Class Reference

Owns renderable geometry elements and their materials. More...

#include <a3d/mesh/Mesh.h>

Public Types

enum class  ImportOptions : uint16_t { None = 0 , ImportMaterials = 1 << 1 , ImportAll = UINT16_MAX }
 Selects optional resources imported with Mesh::FromFile(). More...
 

Public Member Functions

 Mesh (const std::string &name, std::unique_ptr< MeshElement > element, const std::shared_ptr< Material > &material)
 Creates a named Mesh and takes ownership of element. More...
 
 Mesh (std::unique_ptr< MeshElement > element, const std::shared_ptr< Material > &material)
 Creates a Mesh and takes ownership of element. More...
 
 Mesh (const std::string &name, std::vector< std::unique_ptr< MeshElement > > &elements, const std::vector< std::shared_ptr< Material > > &materials)
 Creates a named Mesh by moving the elements in elements into the Mesh. More...
 
 Mesh (std::vector< std::unique_ptr< MeshElement > > &elements, const std::vector< std::shared_ptr< Material > > &materials)
 Creates a Mesh by moving the elements in elements into the Mesh. More...
 
std::optional< std::string > name () const
 Returns the optional mesh name. More...
 
void name (const std::string &name)
 Sets the mesh name. More...
 
const std::vector< std::unique_ptr< MeshElement > > & elements ()
 Returns the MeshElement instances owned by this Mesh. More...
 
const std::vector< std::shared_ptr< Material > > & materials ()
 Returns the materials retained by this Mesh. More...
 
std::shared_ptr< MaterialfirstMaterial () const
 Returns the first material, or nullptr if the material list is empty. More...
 
std::shared_ptr< MaterialmaterialNamed (const std::string &name) const
 Returns the first material named name, or nullptr if no material matches. More...
 
void addMaterial (const std::shared_ptr< Material > &material)
 Appends material to the material list. More...
 
void insertMaterial (const std::shared_ptr< Material > &material, int index)
 Inserts material at index. More...
 
void removeMaterial (int index)
 Removes the material at index. More...
 
void replaceMaterial (int index, const std::shared_ptr< Material > &replacement)
 Replaces the material at index with replacement. More...
 

Static Public Member Functions

static std::shared_ptr< MeshFromFile (const std::filesystem::path &path, ImportOptions options=ImportOptions::ImportMaterials)
 Imports the first mesh in a glTF file without applying scene-node transforms. More...
 

Detailed Description

Owns renderable geometry elements and their materials.

A Mesh owns its MeshElement instances and shares ownership of its Material instances. When rendered, elements select materials by element index, wrapping through the material list when fewer materials than elements are present. If no material is available for an element, the renderer uses its default material.

Definition at line 42 of file Mesh.h.

Member Enumeration Documentation

◆ ImportOptions

enum class a3d::Mesh::ImportOptions : uint16_t
strong

Selects optional resources imported with Mesh::FromFile().

Enumerator
None 

Do not import source materials.

ImportMaterials 

Import materials referenced by the mesh.

ImportAll 

Enable all supported Mesh import options.

Definition at line 48 of file Mesh.h.

Constructor & Destructor Documentation

◆ Mesh() [1/4]

a3d::Mesh::Mesh ( const std::string &  name,
std::unique_ptr< MeshElement element,
const std::shared_ptr< Material > &  material 
)

Creates a named Mesh and takes ownership of element.

A non-null material is retained with shared ownership.

◆ Mesh() [2/4]

a3d::Mesh::Mesh ( std::unique_ptr< MeshElement element,
const std::shared_ptr< Material > &  material 
)

Creates a Mesh and takes ownership of element.

A non-null material is retained with shared ownership.

◆ Mesh() [3/4]

a3d::Mesh::Mesh ( const std::string &  name,
std::vector< std::unique_ptr< MeshElement > > &  elements,
const std::vector< std::shared_ptr< Material > > &  materials 
)

Creates a named Mesh by moving the elements in elements into the Mesh.

Materials in materials are retained with shared ownership.

◆ Mesh() [4/4]

a3d::Mesh::Mesh ( std::vector< std::unique_ptr< MeshElement > > &  elements,
const std::vector< std::shared_ptr< Material > > &  materials 
)

Creates a Mesh by moving the elements in elements into the Mesh.

Materials in materials are retained with shared ownership.

Member Function Documentation

◆ addMaterial()

void a3d::Mesh::addMaterial ( const std::shared_ptr< Material > &  material)

Appends material to the material list.

◆ elements()

const std::vector< std::unique_ptr< MeshElement > > & a3d::Mesh::elements ( )

Returns the MeshElement instances owned by this Mesh.

◆ firstMaterial()

std::shared_ptr< Material > a3d::Mesh::firstMaterial ( ) const

Returns the first material, or nullptr if the material list is empty.

◆ FromFile()

static std::shared_ptr< Mesh > a3d::Mesh::FromFile ( const std::filesystem::path &  path,
ImportOptions  options = ImportOptions::ImportMaterials 
)
static

Imports the first mesh in a glTF file without applying scene-node transforms.

Mesh geometry is always imported; options controls optional associated resources.

Parameters
pathglTF or GLB file to import.
optionsoptional resources to import with the mesh.
Returns
The first imported mesh, or nullptr if the file cannot be parsed or contains no meshes.
Exceptions
std::runtime_errorif path has an unsupported file extension.

◆ insertMaterial()

void a3d::Mesh::insertMaterial ( const std::shared_ptr< Material > &  material,
int  index 
)

Inserts material at index.

Parameters
indexinsertion position in the range [0, materials().size()].

◆ materialNamed()

std::shared_ptr< Material > a3d::Mesh::materialNamed ( const std::string &  name) const

Returns the first material named name, or nullptr if no material matches.

◆ materials()

const std::vector< std::shared_ptr< Material > > & a3d::Mesh::materials ( )

Returns the materials retained by this Mesh.

◆ name() [1/2]

std::optional< std::string > a3d::Mesh::name ( ) const

Returns the optional mesh name.

◆ name() [2/2]

void a3d::Mesh::name ( const std::string &  name)

Sets the mesh name.

◆ removeMaterial()

void a3d::Mesh::removeMaterial ( int  index)

Removes the material at index.

Parameters
indexvalid zero-based material index.

◆ replaceMaterial()

void a3d::Mesh::replaceMaterial ( int  index,
const std::shared_ptr< Material > &  replacement 
)

Replaces the material at index with replacement.

Parameters
indexvalid zero-based material index.

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