Toast Engine
Loading...
Searching...
No Matches
vox_import.hpp
Go to the documentation of this file.
1
6
7#pragma once
8#include <cstdint>
9#include <glm/glm.hpp>
10#include <optional>
11#include <span>
12#include <string>
13#include <toast/export.hpp>
16#include <toast/voxel/stamp.hpp>
18#include <vector>
19
20namespace assets {
21
22inline constexpr uint32_t k_vox_max_dim = 256;
23
24struct VoxVoxel {
25 uint8_t x = 0;
26 uint8_t y = 0;
27 uint8_t z = 0;
28
30 uint8_t palette_index = 0;
31};
32
33struct VoxModel {
34 glm::uvec3 dims {0};
35 std::vector<VoxVoxel> voxels;
36};
37
40 voxel::LatticeOrientation orientation;
41 glm::ivec3 translation {0};
42
43 [[nodiscard]]
44 auto operator==(const VoxTransform&) const noexcept -> bool = default;
45};
46
47struct VoxNode {
48 std::string name;
49
50 VoxTransform local;
51
52 bool hidden = false;
53
54 std::vector<uint32_t> children;
55
56 std::optional<uint32_t> model;
57};
58
59struct VoxScene {
60 std::vector<VoxModel> models;
61
63 std::vector<VoxNode> nodes;
64
65 voxel::Palette palette;
66
67 std::vector<std::string> warnings;
68};
69
71[[nodiscard]]
72TOAST_API auto voxOrientationFromByte(uint8_t rotation) -> std::optional<voxel::LatticeOrientation>;
73
74[[nodiscard]]
75TOAST_API auto voxOrientationToByte(const voxel::LatticeOrientation& orientation) -> uint8_t;
76
77[[nodiscard]]
78TOAST_API auto composeVoxTransforms(const VoxTransform& parent, const VoxTransform& local) -> VoxTransform;
79
81[[nodiscard]]
82TOAST_API auto voxPlacementOf(const VoxTransform& world, glm::uvec3 model_dims) -> voxel::LatticePlacement;
83
85 uint32_t model = 0;
86 std::string name;
87 bool hidden = false;
89};
90
91[[nodiscard]]
92TOAST_API auto flattenVoxScene(const VoxScene& scene) -> std::vector<VoxPlacement>;
93
94[[nodiscard]]
95TOAST_API auto buildVoxVolume(const VoxModel& model, voxel::BrickPool& pool) -> std::optional<voxel::Volume>;
96
98[[nodiscard]]
99TOAST_API auto importVox(std::span<const uint8_t> data) -> VoxScene;
100
101}
Definition brick_pool.hpp:26
Definition vox_import.hpp:33
Definition vox_import.hpp:47
Definition vox_import.hpp:84
Definition vox_import.hpp:59
std::vector< VoxNode > nodes
nodes[0] is the root
Definition vox_import.hpp:63
Translation positions the node centre not its corner.
Definition vox_import.hpp:39
Definition vox_import.hpp:24
uint8_t palette_index
1-255 since a .vox never stores an empty voxel
Definition vox_import.hpp:30
Output axis i reads input axis source[i] negated when flip[i].
Definition stamp.hpp:23
Definition stamp.hpp:72
Entry 0 is the empty voxel and must stay all zero.
Definition palette.hpp:59