]> git.localhorst.tv Git - blank.git/blob - src/block.cpp
don't add obstructed blocks to meshes
[blank.git] / src / block.cpp
1 #include "block.hpp"
2
3
4 namespace blank {
5
6 const NullShape BlockType::DEFAULT_SHAPE;
7
8 BlockType::BlockType(bool v, const glm::vec3 &col, const Shape *s)
9 : shape(s)
10 , color(col)
11 , outline_color(-1, -1, -1)
12 , id(0)
13 , visible(v)
14 , fill({ false, false, false, false, false, false }) {
15
16 }
17
18 void BlockType::FillModel(
19         Model::Buffer &buf,
20         const glm::vec3 &pos_offset,
21         Model::Index idx_offset
22 ) const {
23         shape->Vertices(buf.vertices, buf.normals, buf.indices, pos_offset, idx_offset);
24         buf.colors.insert(buf.colors.end(), shape->VertexCount(), color);
25 }
26
27 void BlockType::FillOutlineModel(
28         OutlineModel &model,
29         const glm::vec3 &pos_offset,
30         OutlineModel::Index idx_offset
31 ) const {
32         shape->Outline(model.vertices, model.indices, pos_offset, idx_offset);
33         model.colors.insert(model.colors.end(), shape->OutlineCount(), outline_color);
34 }
35
36
37 BlockTypeRegistry::BlockTypeRegistry() {
38         Add(BlockType());
39 }
40
41 Block::Type BlockTypeRegistry::Add(const BlockType &t) {
42         int id = types.size();
43         types.push_back(t);
44         types.back().id = id;
45         return id;
46 }
47
48 }