Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
voxel_model.hpp
Go to the documentation of this file.
1
6
7
#pragma once
8
#include <array>
9
#include <cstdint>
10
#include <glm/glm.hpp>
11
#include <memory>
12
#include <optional>
13
#include <string_view>
14
#include <
toast/assets/core_types.hpp
>
15
#include <
toast/voxel/brick_pool.hpp
>
16
#include <
toast/voxel/voxel_constants.hpp
>
17
#include <
toast/voxel/voxel_volume.hpp
>
18
#include <vector>
19
20
namespace
assets {
21
22
namespace
_detail {
23
25
inline
constexpr
uint16_t
voxel_format_version
= 1;
26
29
struct
VoxelFileHeader
{
30
std::array<uint8_t, 6> magic = {
'T'
,
'V'
,
'O'
,
'X'
,
'\0'
,
'\0'
};
31
uint16_t version =
voxel_format_version
;
32
uint16_t dim_x = 0;
33
uint16_t dim_y = 0;
34
uint16_t dim_z = 0;
35
uint16_t reserved = 0;
36
};
37
38
static_assert
(
sizeof
(
VoxelFileHeader
) == 16,
"the .tvox header must stay sixteen bytes"
);
39
static_assert
(
VoxelFileHeader
{}.version == voxel_format_version,
"the header must default from the version constant"
);
40
41
}
42
43
class
TOAST_API
VoxelModel
:
public
Asset,
public
ISaveable
{
44
public
:
46
explicit
VoxelModel
(
const
std::vector<uint8_t>& data);
47
48
[[nodiscard]]
49
static
auto
capture(
const
voxel::Volume
& volume, uint64_t palette_uid) -> std::unique_ptr<VoxelModel>;
50
51
[[nodiscard]]
52
auto
instantiate(
voxel::BrickPool
& pool)
const
-> std::optional<voxel::Volume>;
53
54
void
reload(
const
std::vector<uint8_t>& data);
55
56
[[nodiscard]]
57
auto
type()
const
-> std::string_view
override
{
58
return
"voxel_model"
;
59
}
60
61
[[nodiscard]]
62
auto
serialize(
SaveMode
mode)
const
-> std::vector<uint8_t>
override
;
63
64
[[nodiscard]]
65
auto
brickDims()
const
noexcept
-> glm::uvec3 {
66
return
m_brick_dims;
67
}
68
69
[[nodiscard]]
70
auto
paletteUid()
const
noexcept
-> uint64_t {
71
return
m_palette_uid;
72
}
73
74
[[nodiscard]]
75
auto
storedBrickCount()
const
noexcept
-> uint32_t {
76
return
static_cast<
uint32_t
>
(m_bricks.size() / voxel::k_brick_material_bytes);
77
}
78
79
[[nodiscard]]
80
auto
solidVoxelCount()
const
-> uint32_t;
81
82
[[nodiscard]]
83
auto
materialAt(glm::uvec3 voxel)
const
noexcept
-> uint8_t;
84
85
private
:
86
VoxelModel
() =
default
;
87
88
glm::uvec3 m_brick_dims {0};
89
uint64_t m_palette_uid = 0;
90
92
std::vector<voxel::BrickEntry> m_grid;
93
94
std::vector<uint8_t> m_bricks;
95
};
96
97
}
brick_pool.hpp
assets::ISaveable
Inherit from this class to allow an asset to be saved.
Definition
core_types.hpp:33
assets::VoxelModel::VoxelModel
VoxelModel(const std::vector< uint8_t > &data)
Throws on malformed or non canonical data.
Definition
voxel_model.cpp:19
voxel::BrickPool
Definition
brick_pool.hpp:26
voxel::Volume
Definition
voxel_volume.hpp:21
core_types.hpp
Base types for the asset system.
assets::SaveMode
SaveMode
Definition
core_types.hpp:25
assets::_detail::VoxelFileHeader
Read before the version check so never add fields Body uint64 palette UID then uint32 stored brick co...
Definition
voxel_model.hpp:29
voxel_constants.hpp
assets::_detail::voxel_format_version
constexpr uint16_t voxel_format_version
The header defaults from this so the writer and reader cannot disagree.
Definition
voxel_model.hpp:25
voxel_volume.hpp
engine
src
toast
voxel
assets
voxel_model.hpp
Generated by
1.17.0