Skip to content

Commit

Permalink
store node poss in mapblock mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Nov 6, 2024
1 parent 828303c commit 7ddc4fe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/client/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs

for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
scene::SMesh *mesh = static_cast<scene::SMesh *>(m_mesh[layer].get());
auto *mesh_node_poss = &m_mesh_node_poss[layer];

for(u32 i = 0; i < collector.prebuffers[layer].size(); i++)
{
Expand Down Expand Up @@ -743,25 +744,46 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs

scene::SMeshBuffer *buf = new scene::SMeshBuffer();
buf->Material = material;
// std::vector<RLENodePoss> node_poss = std::move(p.node_poss); //TODO: use same type
std::vector<RLENodePoss> node_poss;
node_poss.reserve(p.node_poss.size());
for (const auto &ps : p.node_poss) {
node_poss.push_back({ps.p, ps.cnt_i, ps.cnt_v});
}
if (p.layer.isTransparent()) {
buf->append(&p.vertices[0], p.vertices.size(), nullptr, 0);

MeshTriangle t;
t.buffer = buf;
m_transparent_triangles.reserve(p.indices.size() / 3);
size_t next_node_pos_i = 0;
u32 cur_node_pos_end = 0;
v3s16 cur_node_pos;
for (u32 i = 0; i < p.indices.size(); i += 3) {
if (i >= cur_node_pos_end) {
cur_node_pos = node_poss[next_node_pos_i].p;
cur_node_pos_end += node_poss[next_node_pos_i].cnt_i;
assert(node_poss[next_node_pos_i].cnt_i >= 3);
next_node_pos_i += 1;
}
t.p1 = p.indices[i];
t.p2 = p.indices[i + 1];
t.p3 = p.indices[i + 2];
t.node_pos = cur_node_pos;
t.updateAttributes();
m_transparent_triangles.push_back(t);
}

for (auto &ps : p.node_poss) {
ps.cnt_i = 0;
}
} else {
buf->append(&p.vertices[0], p.vertices.size(),
&p.indices[0], p.indices.size());
}
mesh->addMeshBuffer(buf);
buf->drop();
mesh_node_poss->push_back(std::move(node_poss));
}

if (mesh) {
Expand Down
11 changes: 11 additions & 0 deletions src/client/mapblock_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MeshTriangle
public:
scene::SMeshBuffer *buffer;
u16 p1, p2, p3;
v3s16 node_pos;
v3f centroid;
float areaSQ;

Expand Down Expand Up @@ -227,7 +228,17 @@ class MapBlockMesh
TileLayer tile;
};

// node positions for indices/vertices, run-length encoded
// (same as in PreMeshBuffer)
struct RLENodePoss {
v3s16 p;
u32 cnt_i;
u32 cnt_v;
};


irr_ptr<scene::IMesh> m_mesh[MAX_TILE_LAYERS];
std::vector<std::vector<RLENodePoss>> m_mesh_node_poss[MAX_TILE_LAYERS];
std::vector<MinimapMapblock*> m_minimap_mapblocks;
ITextureSource *m_tsrc;
IShaderSource *m_shdrsrc;
Expand Down

0 comments on commit 7ddc4fe

Please sign in to comment.