sandbox
Loading...
Searching...
No Matches
static_mesh.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_SCENES_COMPONENTS_STATIC_MESH_HPP_
3#define LIBSBX_SCENES_COMPONENTS_STATIC_MESH_HPP_
4
5#include <vector>
6#include <cinttypes>
7
9#include <libsbx/math/uuid.hpp>
10
11#include <libsbx/graphics/resource_storage.hpp>
12
13#include <libsbx/graphics/images/image2d.hpp>
14
15namespace sbx::scenes {
16
17class static_mesh final {
18
19public:
20
21 struct submesh {
22 std::uint32_t index;
23 math::uuid material;
24 }; // struct submesh
25
26 static_mesh() = default;
27
28 static_mesh(const math::uuid mesh_id, const math::uuid material)
29 : _mesh_id{mesh_id},
30 _submeshes{{0, material}} { }
31
32 static_mesh(const math::uuid mesh_id, const std::vector<submesh>& submeshes)
33 : _mesh_id{mesh_id},
34 _submeshes{submeshes} { }
35
36 static_mesh(const math::uuid mesh_id, std::initializer_list<submesh> submeshes)
37 : _mesh_id{mesh_id},
38 _submeshes{submeshes} { }
39
40 auto mesh_id() const noexcept -> math::uuid {
41 return _mesh_id;
42 }
43
44 auto set_mesh_id(const math::uuid mesh_id) noexcept -> void {
45 _mesh_id = mesh_id;
46 }
47
48 auto submeshes() const noexcept -> const std::vector<submesh>& {
49 return _submeshes;
50 }
51
52 auto submeshes() noexcept -> std::vector<submesh>& {
53 return _submeshes;
54 }
55
56 auto resize_submeshes(const std::size_t count) -> void {
57 const auto previous = _submeshes.size();
58
59 _submeshes.resize(count);
60
61 for (auto i = previous; i < count; ++i) {
62 _submeshes[i] = submesh{static_cast<std::uint32_t>(i), math::uuid::nil()};
63 }
64 }
65
66 auto set_submesh_material(const std::size_t index, const math::uuid material) -> void {
67 if (index >= _submeshes.size()) {
68 return;
69 }
70
71 _submeshes[index].material = material;
72 }
73
74private:
75
76 math::uuid _mesh_id;
77 std::vector<submesh> _submeshes;
78
79}; // class static_mesh
80
81} // namespace sbx::scenes
82
83#endif // LIBSBX_SCENES_COMPONENTS_STATIC_MESH_HPP_
Definition: uuid.hpp:15
Definition: static_mesh.hpp:17
RGBA color representation and utilities.
Definition: static_mesh.hpp:21