Toast Engine
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>
18#include <vector>
19
20namespace assets {
21
22namespace _detail {
23
25inline constexpr uint16_t voxel_format_version = 1;
26
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
38static_assert(sizeof(VoxelFileHeader) == 16, "the .tvox header must stay sixteen bytes");
39static_assert(VoxelFileHeader {}.version == voxel_format_version, "the header must default from the version constant");
40
41}
42
43class TOAST_API VoxelModel : public Asset, public ISaveable {
44public:
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
85private:
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}
Inherit from this class to allow an asset to be saved.
Definition core_types.hpp:33
VoxelModel(const std::vector< uint8_t > &data)
Throws on malformed or non canonical data.
Definition voxel_model.cpp:19
Definition brick_pool.hpp:26
Definition voxel_volume.hpp:21
Base types for the asset system.
SaveMode
Definition core_types.hpp:25
Read before the version check so never add fields Body uint64 palette UID then uint32 stored brick co...
Definition voxel_model.hpp:29
constexpr uint16_t voxel_format_version
The header defaults from this so the writer and reader cannot disagree.
Definition voxel_model.hpp:25