2#ifndef LIBSBX_MODELS_MESH_HPP_
3#define LIBSBX_MODELS_MESH_HPP_
10#include <libsbx/utility/enum.hpp>
11#include <libsbx/utility/crc32.hpp>
13#include <libsbx/math/volume.hpp>
14#include <libsbx/math/sphere.hpp>
15#include <libsbx/math/vector4.hpp>
16#include <libsbx/math/uuid.hpp>
18#include <libsbx/io/loader_factory.hpp>
20#include <libsbx/graphics/pipeline/mesh.hpp>
21#include <libsbx/graphics/buffers/buffer.hpp>
23#include <libsbx/models/vertex3d.hpp>
24#include <libsbx/models/vertex_stream.hpp>
26namespace sbx::models {
42 mesh(
const std::filesystem::path& path, std::uint32_t lod_count = 1u);
46 auto set_stream(vertex_stream stream, std::span<const math::vector4> data) -> void;
48 auto stream_address(vertex_stream stream)
const -> graphics::buffer::address_type;
56 auto _upload_streams(std::array<std::vector<math::vector4>, vertex_stream_count>& streams) -> void;
58 static constexpr auto file_magic = utility::make_magic<std::uint64_t>(
"SBXSTMSH");
59 static constexpr auto file_version = std::uint16_t{3u};
60 static constexpr auto binary_file_extention = std::string_view{
".sbxstmsh"};
62 enum class file_flags : std::uint16_t {
64 compressed = utility::bit_v<0>,
65 quantized = utility::bit_v<1>,
66 has_streams = utility::bit_v<2>,
69 struct alignas(8) file_header {
71 std::uint16_t version;
73 std::uint32_t vertex_count;
74 std::uint32_t index_count;
75 std::uint32_t submesh_count;
76 std::uint32_t vertex_stride;
77 std::uint32_t index_stride;
78 std::uint32_t uncompressed_size;
79 std::uint32_t compressed_size;
82 static_assert(
sizeof(file_header) == 40u,
"file_header layout changed");
84 struct alignas(4) file_bounds {
85 std::float_t aabb_min[3];
86 std::float_t aabb_max[3];
87 std::float_t sphere_center[3];
88 std::float_t sphere_radius;
91 static_assert(
sizeof(file_bounds) == 40u,
"file_bounds layout changed");
93 struct alignas(8) file_submesh {
95 std::uint32_t material_index;
96 std::uint32_t vertex_offset;
97 std::uint32_t vertex_count;
98 std::uint32_t index_offset;
99 std::uint32_t index_count;
100 std::float_t aabb_min[3];
101 std::float_t aabb_max[3];
102 std::float_t local_transform[16];
103 std::uint32_t lod_level;
104 std::uint32_t lod_group;
107 static_assert(
sizeof(file_submesh) == 184u,
"file_submesh layout changed");
109 struct alignas(2) file_vertex {
110 std::int16_t position[3];
111 std::int16_t normal[2];
113 std::int16_t tangent[2];
114 std::int8_t tangent_w;
118 static_assert(
sizeof(file_vertex) == 20u,
"file_vertex layout changed");
120 static auto _load(
const std::filesystem::path& path, std::uint32_t lod_count) ->
mesh_data;
122 static auto _generate_lods(
mesh_data& data, std::uint32_t lod_count) -> void;
124 static auto _load_binary(
const std::filesystem::path& path) ->
mesh_data;
126 static auto _process(
const std::filesystem::path& path,
const mesh_data& data) -> void;
128 std::array<graphics::buffer_handle, vertex_stream_count> _stream_buffers{};
141 constexpr auto is_valid()
const noexcept ->
bool {
142 return (*
this) != math::uuid::nil();
145 constexpr auto operator==(
const mesh_handle& other)
const noexcept ->
bool =
default;
Definition: loader_factory.hpp:13
Definition: volume.hpp:14