1 #include "client/blockmesh.h"
2 #include "client/client_map.h"
3 #include "client/client_node.h"
4 #include "client/cube.h"
6 static v3s8 fdir[6] = {
15 static void make_vertices(Object *object, MapBlock *block)
17 v3s32 node_bp = {block->pos.x * MAPBLOCK_SIZE, block->pos.y * MAPBLOCK_SIZE, block->pos.z * MAPBLOCK_SIZE};
20 MapNode *node = &block->data[x][y][z];
21 ClientNodeDefintion *def = &client_node_definitions[node->type];
23 if (def->visibility != NV_NONE) {
24 v3f32 offset = {x + (f32) MAPBLOCK_SIZE / 2.0f, y + (f32) MAPBLOCK_SIZE / 2.0f, z + (f32) MAPBLOCK_SIZE / 2.0f};
26 for (int f = 0; f < 6; f++) {
35 if (npos.x >= 0 && npos.x < MAPBLOCK_SIZE && npos.y >= 0 && npos.y < MAPBLOCK_SIZE && npos.z >= 0 && npos.z < MAPBLOCK_SIZE)
36 neighbor = block->data[npos.x][npos.y][npos.z].type;
38 MapNode nn = map_get_node(client_map.map, (v3s32) {npos.x + node_bp.x, npos.y + node_bp.y, npos.z + node_bp.z});
42 if (neighbor != NODE_UNLOADED && client_node_definitions[neighbor].visibility != NV_SOLID && (def->visibility != NV_TRANSPARENT || neighbor != node->type)) {
43 object_set_texture(object, def->tiles.textures[f]);
45 for (int v = 0; v < 6; v++) {
46 Vertex3D vertex = cube_vertices[f][v];
47 vertex.position.x += offset.x;
48 vertex.position.y += offset.y;
49 vertex.position.z += offset.z;
52 def->render((v3s32) {x + node_bp.x, y + node_bp.y, z + node_bp.z}, node, &vertex, f, v);
54 object_add_vertex(object, &vertex);
62 void blockmesh_make(MapBlock *block)
64 Object *obj = object_create();
65 obj->pos = (v3f32) {block->pos.x * (f32) MAPBLOCK_SIZE - (f32) MAPBLOCK_SIZE / 2.0f, block->pos.y * (f32) MAPBLOCK_SIZE - (f32) MAPBLOCK_SIZE / 2.0f, block->pos.z * (f32) MAPBLOCK_SIZE - (f32) MAPBLOCK_SIZE / 2.0};
67 make_vertices(obj, block);
69 if (! object_add_to_scene(obj)) {
74 MapBlockExtraData *extra = block->extra;
77 extra->obj->remove = true;