Skip to main content

Mesh Class

Representative of a renderable 3D mesh. More...

Declaration

class helios::rendering::mesh::Mesh { ... }

Derived Classes

classOpenGLMesh

Representative of an OpenGLMesh. This class manages the OpenGL Vertex Array Object (VAO), the Vertex Buffer Object (VBO) and Element Buffer Object (EBO) handles. The raw mesh data is uploaded to the GPU, preparing it for subsequent rendering commands / draw calls. More...

Public Constructors Index

Mesh (std::shared_ptr< const std::vector< Vertex > > vertices, std::shared_ptr< const std::vector< unsigned int > > indices, std::shared_ptr< const helios::rendering::mesh::MeshConfig > meshConfig)

Creates a new Mesh instance. More...

Mesh (const helios::rendering::asset::shape::Shape &shape, std::shared_ptr< const helios::rendering::mesh::MeshConfig > meshConfig)

Creates a new Mesh instance from the specified Shape. More...

Protected Constructors Index

Mesh ()=default

Public Destructor Index

~Mesh ()=default

Public Member Functions Index

unsigned intindexCount () const noexcept

Returns the index count of this Mesh. More...

const std::vector< Vertex > &vertices () const noexcept

Returns a const reference to the underlying vertices. The returned data is guaranteed to be a valid reference to existing data. More...

const std::vector< unsigned int > &indices () const noexcept

Returns a const reference to the underlying indices. The returned data is guaranteed to be a valid reference to existing data. More...

const helios::rendering::mesh::MeshConfig &meshConfig () const noexcept

Returns a const reference to MeshConfig used with this Mesh. The returned MeshConfig is guaranteed to be a valid reference to existing data. More...

const helios::math::aabbf &aabb () const noexcept

Retrieves the axis-aligned bounding box (AABB) of the mesh. More...

Protected Member Functions Index

voidinit ()=0

Initializes the Mesh by setting up vertex attributes and buffers with the underlying GL API. This method should be called _once_ by the derived class before using this Mesh in a rendering pass. More...

Protected Member Attributes Index

boolneedsUpdate_ = true

Flag indicating whether the mesh requires updates to its computed data. More...

helios::math::aabbfaabb_ {}

Represents the axis-aligned bounding box (AABB) for the mesh. More...

std::shared_ptr< const std::vector< Vertex > >vertices_ = nullptr

Shared pointer to the raw, immutable vertices. More...

std::shared_ptr< const std::vector< unsigned int > >indices_ = nullptr

Shared pointer to the raw, immutable indices. More...

std::shared_ptr< const helios::rendering::mesh::MeshConfig >meshConfig_

Shared pointer to the MeshConfig used with this Mesh. More...

Protected Static Attributes Index

static const helios::util::log::Logger &logger_ = ...

Shared logger instance for all Mesh objects. More...

Description

Representative of a renderable 3D mesh.

A Mesh instance contains vertex data and indices provided by geometric shapes. Meshes contain references to immutable, shared vertex data and indices. Concrete implementations will handle resource management.

See Also

[Gre19, 631]

Definition at line 37 of file Mesh.ixx.

Public Constructors

Mesh()

helios::rendering::mesh::Mesh::Mesh (std::shared_ptr< const std::vector< Vertex > > vertices, std::shared_ptr< const std::vector< unsigned int > > indices, std::shared_ptr< const helios::rendering::mesh::MeshConfig > meshConfig)
inline explicit

Creates a new Mesh instance.

Parameters
vertices

A shared_ptr to a vector of Vertex.

indices

A shared_ptr to a vector of indices.

meshConfig

A shared_ptr to the MeshConfig used with this Mesh.

Exceptions
std::invalid_argument

if either "vertices", "indices" or meshConfig is a null shared_ptr

Definition at line 117 of file Mesh.ixx.

117 explicit Mesh(
118 std::shared_ptr<const std::vector<Vertex>> vertices,
119 std::shared_ptr<const std::vector<unsigned int>> indices,
120 std::shared_ptr<const helios::rendering::mesh::MeshConfig> meshConfig
121 ) : vertices_(std::move(vertices)),
122 indices_(std::move(indices)),
123 meshConfig_(std::move(meshConfig)) {
124
125 if (!vertices_ || !indices_ || !meshConfig_) {
126 const std::string msg = "Mesh constructor received a null shared pointer.";
127 logger_.error(msg);
128 throw std::invalid_argument(msg);
129 }
130 }

References indices, indices_, logger_, meshConfig, meshConfig_, vertices and vertices_.

Mesh()

helios::rendering::mesh::Mesh::Mesh (const helios::rendering::asset::shape::Shape & shape, std::shared_ptr< const helios::rendering::mesh::MeshConfig > meshConfig)
inline explicit

Creates a new Mesh instance from the specified Shape.

Parameters
shape

A const reference to the Shape.

meshConfig

A shared_ptr to the MeshConfig used with this Mesh.

Exceptions
std::invalid_argument

if meshConfig is a null shared_ptr, or if the shape contained null data.

Definition at line 141 of file Mesh.ixx.

141 explicit Mesh(
143 std::shared_ptr<const helios::rendering::mesh::MeshConfig> meshConfig
144 ) :
145 vertices_(shape.vertices),
146 indices_(shape.indices),
147 meshConfig_(std::move(meshConfig)) {
148
149 if (!vertices_ || !indices_ || !meshConfig_) {
150 const std::string msg = "Mesh constructor received a Shape with null shared pointer.";
151 logger_.error(msg);
152 throw std::invalid_argument(msg);
153 }
154 }

References indices, indices_, logger_, meshConfig, meshConfig_, vertices and vertices_.

Protected Constructors

Mesh()

helios::rendering::mesh::Mesh::Mesh ()
protected default

Public Destructor

~Mesh()

virtual helios::rendering::mesh::Mesh::~Mesh ()
virtual default

Definition at line 106 of file Mesh.ixx.

Public Member Functions

aabb()

const helios::math::aabbf & helios::rendering::mesh::Mesh::aabb ()
inline nodiscard noexcept

Retrieves the axis-aligned bounding box (AABB) of the mesh.

The method calculates and returns the AABB of the mesh, which encloses the mesh's vertices. If the mesh requires an update to its bounding box, this method recomputes the bounds based on the vertex positions and caches the result for future calls. The returned AABB represents the minimal rectangle in 3D space that contains all the vertices of the mesh.

Returns

Reference to the computed axis-aligned bounding box.

Definition at line 207 of file Mesh.ixx.

207 [[nodiscard]] const helios::math::aabbf& aabb() const noexcept {
208 if (needsUpdate_) {
209 if (!vertices_->empty()) {
210 float minX = std::numeric_limits<float>::max();
211 float minY = std::numeric_limits<float>::max();
212 float minZ = std::numeric_limits<float>::max();
213 float maxX = std::numeric_limits<float>::lowest();
214 float maxY = std::numeric_limits<float>::lowest();
215 float maxZ = std::numeric_limits<float>::lowest();
216
217 for (const auto& v: *vertices_) {
218 // min
219 minX = std::min(minX, v.position[0]);
220 minY = std::min(minY, v.position[1]);
221 minZ = std::min(minZ, v.position[2]);
222
223 // max
224 maxX = std::max(maxX, v.position[0]);
225 maxY = std::max(maxY, v.position[1]);
226 maxZ = std::max(maxZ, v.position[2]);
227 }
228
229 aabb_ = helios::math::aabbf(minX, minY, minZ, maxX, maxY, maxZ);
230 } else {
231 aabb_ = helios::math::aabbf(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
232 }
233
234 needsUpdate_ = false;
235 }
236
237 return aabb_;
238 }

References aabb_, needsUpdate_ and vertices_.

indexCount()

unsigned int helios::rendering::mesh::Mesh::indexCount ()
inline nodiscard noexcept

Returns the index count of this Mesh.

Returns

The number of indices handled by this Mesh.

Definition at line 161 of file Mesh.ixx.

161 [[nodiscard]] unsigned int indexCount() const noexcept {
162 return indices_->size();
163 }

Reference indices_.

indices()

const std::vector< unsigned int > & helios::rendering::mesh::Mesh::indices ()
inline nodiscard noexcept

Returns a const reference to the underlying indices. The returned data is guaranteed to be a valid reference to existing data.

Returns

A const ref to the vector of indices.

Definition at line 181 of file Mesh.ixx.

181 [[nodiscard]] const std::vector<unsigned int>& indices() const noexcept {
182 return *indices_;
183 }

Reference indices_.

Referenced by Mesh, Mesh and helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh.

meshConfig()

const helios::rendering::mesh::MeshConfig & helios::rendering::mesh::Mesh::meshConfig ()
inline nodiscard noexcept

Returns a const reference to MeshConfig used with this Mesh. The returned MeshConfig is guaranteed to be a valid reference to existing data.

Returns

The MeshConfig used with this Mesh.

Definition at line 191 of file Mesh.ixx.

191 [[nodiscard]] const helios::rendering::mesh::MeshConfig& meshConfig() const noexcept {
192 return *meshConfig_;
193 }

Reference meshConfig_.

Referenced by Mesh, Mesh, helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh and helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh.

vertices()

const std::vector< Vertex > & helios::rendering::mesh::Mesh::vertices ()
inline nodiscard noexcept

Returns a const reference to the underlying vertices. The returned data is guaranteed to be a valid reference to existing data.

Returns

A const ref to the vector of Vertex.

Definition at line 171 of file Mesh.ixx.

171 [[nodiscard]] const std::vector<Vertex>& vertices() const noexcept {
172 return *vertices_;
173 }

Reference vertices_.

Referenced by Mesh, Mesh and helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh.

Protected Member Functions

init()

virtual void helios::rendering::mesh::Mesh::init ()
protected

Initializes the Mesh by setting up vertex attributes and buffers with the underlying GL API. This method should be called _once_ by the derived class before using this Mesh in a rendering pass.

Todo

std::shared_ptr<const std::vector<Texture>> textures_;

Exceptions
std::runtime_error

if the Mesh could not be initialized.

Definition at line 95 of file Mesh.ixx.

Protected Member Attributes

aabb_

helios::math::aabbf helios::rendering::mesh::Mesh::aabb_ {}
protected mutable

Represents the axis-aligned bounding box (AABB) for the mesh.

This member variable stores the computed or cached AABB for the mesh in 3D space. The AABB is a minimal bounding box aligned with the coordinate axes that encloses all the vertices of the mesh. It is marked mutable to allow updates during read-only operations, such as recalculating bounds as vertex positions are modified or updated dynamically.

See Also

helios::math::aabb

Definition at line 65 of file Mesh.ixx.

Referenced by aabb.

indices_

std::shared_ptr<const std::vector<unsigned int> > helios::rendering::mesh::Mesh::indices_ = nullptr
protected

Shared pointer to the raw, immutable indices.

Definition at line 75 of file Mesh.ixx.

75 std::shared_ptr<const std::vector<unsigned int>> indices_ = nullptr;

Referenced by indexCount, indices, helios::ext::opengl::rendering::model::OpenGLMesh::init, Mesh, Mesh, helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh and helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh.

meshConfig_

std::shared_ptr<const helios::rendering::mesh::MeshConfig> helios::rendering::mesh::Mesh::meshConfig_
protected

Shared pointer to the MeshConfig used with this Mesh.

Definition at line 80 of file Mesh.ixx.

80 std::shared_ptr<const helios::rendering::mesh::MeshConfig> meshConfig_;

Referenced by Mesh, Mesh, meshConfig, helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh and helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh.

needsUpdate_

bool helios::rendering::mesh::Mesh::needsUpdate_ = true
protected mutable

Flag indicating whether the mesh requires updates to its computed data.

This variable is used to track whether the mesh's derived properties, such as its axis-aligned bounding box (AABB), are outdated and need to be recalculated. It is marked as mutable to allow modification within const member functions.

Definition at line 51 of file Mesh.ixx.

51 mutable bool needsUpdate_ = true;

Referenced by aabb.

vertices_

std::shared_ptr<const std::vector<Vertex> > helios::rendering::mesh::Mesh::vertices_ = nullptr
protected

Shared pointer to the raw, immutable vertices.

Definition at line 70 of file Mesh.ixx.

70 std::shared_ptr<const std::vector<Vertex>> vertices_ = nullptr;

Referenced by aabb, helios::ext::opengl::rendering::model::OpenGLMesh::init, Mesh, Mesh, helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh, helios::ext::opengl::rendering::model::OpenGLMesh::OpenGLMesh and vertices.

Protected Static Attributes

logger_

const helios::util::log::Logger& helios::rendering::mesh::Mesh::logger_
protected static

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.