9#ifndef AVARA3D_MESH_MESH_H
10#define AVARA3D_MESH_MESH_H
21#include "a3d/mesh/AABB.h"
22#include "a3d/util/Bitmask.h"
52 ImportMaterials = 1 << 1,
53 ImportAll = UINT16_MAX
69 static std::shared_ptr<Mesh>
FromFile(
const std::filesystem::path& path,
80 std::unique_ptr<MeshElement> element,
81 const std::shared_ptr<Material>& material);
88 Mesh(std::unique_ptr<MeshElement> element,
const std::shared_ptr<Material>& material);
96 std::vector<std::unique_ptr<MeshElement>>&
elements,
97 const std::vector<std::shared_ptr<Material>>&
materials);
105 const std::vector<std::shared_ptr<Material>>&
materials);
109 Mesh& operator=(
const Mesh&) =
delete;
117 std::optional<std::string>
name()
const;
123 const std::vector<std::unique_ptr<MeshElement>>&
elements();
126 const std::vector<std::shared_ptr<Material>>&
materials();
160 enum class DirtyMask : uint32_t {
168 MeshId id() const noexcept;
170 const
AABB& localAABB() const;
171 AABB worldAABB(const math::mat4& worldMat,
bool vertfit) const;
172 math::vec3 localExtent() const;
173 math::vec3 worldExtent(const math::mat4& worldTransform) const;
175 void burnTransform(const math::mat4& transform,
bool normals);
177 DirtyMask dirtyMask() const;
178 void dirtyMask(DirtyMask mask);
187 std::vector<std::unique_ptr<
MeshElement>> _elements;
188 std::vector<std::shared_ptr<
Material>> _materials;
198 std::optional<std::
string> _name;
200 DirtyMask _dirtyMask;
203 namespace util::bitmask {
209 struct enable_ops<Mesh::DirtyMask> : std::true_type {};
Describes the surface appearance and render state of Mesh geometry.
Owns the vertex and optional index data for one mesh primitive.
Owns renderable geometry elements and their materials.
std::shared_ptr< Material > materialNamed(const std::string &name) const
Returns the first material named name, or nullptr if no material matches.
const std::vector< std::shared_ptr< Material > > & materials()
Returns the materials retained by this Mesh.
std::shared_ptr< Material > firstMaterial() const
Returns the first material, or nullptr if the material list is empty.
void name(const std::string &name)
Sets the mesh name.
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.
std::optional< std::string > name() const
Returns the optional mesh name.
void addMaterial(const std::shared_ptr< Material > &material)
Appends material to the material list.
static std::shared_ptr< Mesh > FromFile(const std::filesystem::path &path, ImportOptions options=ImportOptions::ImportMaterials)
Imports the first mesh in a glTF file without applying scene-node transforms.
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.
ImportOptions
Selects optional resources imported with Mesh::FromFile().
@ ImportMaterials
Import materials referenced by the mesh.
void replaceMaterial(int index, const std::shared_ptr< Material > &replacement)
Replaces the material at index with replacement.
const std::vector< std::unique_ptr< MeshElement > > & elements()
Returns the MeshElement instances owned by this 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.
Mesh(std::unique_ptr< MeshElement > element, const std::shared_ptr< Material > &material)
Creates a Mesh and takes ownership of element.
void insertMaterial(const std::shared_ptr< Material > &material, int index)
Inserts material at index.
void removeMaterial(int index)
Removes the material at index.
Axis-aligned bounding box defined by minimum and maximum corners.