3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "content_mapblock.h"
21 #include "util/numeric.h"
22 #include "util/directiontables.h"
23 #include "main.h" // For g_settings
24 #include "mapblock_mesh.h" // For MapBlock_LightColor() and MeshCollector
33 // collector - the MeshCollector for the resulting polygons
34 // box - the position and size of the box
35 // tiles - the tiles (materials) to use (for all 6 faces)
36 // tilecount - number of entries in tiles, 1<=tilecount<=6
37 // c - vertex colour - used for all
38 // txc - texture coordinates - this is a list of texture coordinates
39 // for the opposite corners of each face - therefore, there
40 // should be (2+2)*6=24 values in the list. Alternatively, pass
41 // NULL to use the entire texture for each face. The order of
42 // the faces in the list is up-down-right-left-back-front
43 // (compatible with ContentFeatures). If you specified 0,0,1,1
44 // for each face, that would be the same as passing NULL.
45 void makeCuboid(MeshCollector *collector, const aabb3f &box,
46 TileSpec *tiles, int tilecount,
47 video::SColor &c, const f32* txc)
49 assert(tilecount >= 1 && tilecount <= 6);
51 v3f min = box.MinEdge;
52 v3f max = box.MaxEdge;
58 static const f32 txc_default[24] = {
69 video::S3DVertex vertices[24] =
72 video::S3DVertex(min.X,max.Y,max.Z, 0,1,0, c, txc[0],txc[1]),
73 video::S3DVertex(max.X,max.Y,max.Z, 0,1,0, c, txc[2],txc[1]),
74 video::S3DVertex(max.X,max.Y,min.Z, 0,1,0, c, txc[2],txc[3]),
75 video::S3DVertex(min.X,max.Y,min.Z, 0,1,0, c, txc[0],txc[3]),
77 video::S3DVertex(min.X,min.Y,min.Z, 0,-1,0, c, txc[4],txc[5]),
78 video::S3DVertex(max.X,min.Y,min.Z, 0,-1,0, c, txc[6],txc[5]),
79 video::S3DVertex(max.X,min.Y,max.Z, 0,-1,0, c, txc[6],txc[7]),
80 video::S3DVertex(min.X,min.Y,max.Z, 0,-1,0, c, txc[4],txc[7]),
82 video::S3DVertex(max.X,max.Y,min.Z, 1,0,0, c, txc[ 8],txc[9]),
83 video::S3DVertex(max.X,max.Y,max.Z, 1,0,0, c, txc[10],txc[9]),
84 video::S3DVertex(max.X,min.Y,max.Z, 1,0,0, c, txc[10],txc[11]),
85 video::S3DVertex(max.X,min.Y,min.Z, 1,0,0, c, txc[ 8],txc[11]),
87 video::S3DVertex(min.X,max.Y,max.Z, -1,0,0, c, txc[12],txc[13]),
88 video::S3DVertex(min.X,max.Y,min.Z, -1,0,0, c, txc[14],txc[13]),
89 video::S3DVertex(min.X,min.Y,min.Z, -1,0,0, c, txc[14],txc[15]),
90 video::S3DVertex(min.X,min.Y,max.Z, -1,0,0, c, txc[12],txc[15]),
92 video::S3DVertex(max.X,max.Y,max.Z, 0,0,1, c, txc[16],txc[17]),
93 video::S3DVertex(min.X,max.Y,max.Z, 0,0,1, c, txc[18],txc[17]),
94 video::S3DVertex(min.X,min.Y,max.Z, 0,0,1, c, txc[18],txc[19]),
95 video::S3DVertex(max.X,min.Y,max.Z, 0,0,1, c, txc[16],txc[19]),
97 video::S3DVertex(min.X,max.Y,min.Z, 0,0,-1, c, txc[20],txc[21]),
98 video::S3DVertex(max.X,max.Y,min.Z, 0,0,-1, c, txc[22],txc[21]),
99 video::S3DVertex(max.X,min.Y,min.Z, 0,0,-1, c, txc[22],txc[23]),
100 video::S3DVertex(min.X,min.Y,min.Z, 0,0,-1, c, txc[20],txc[23]),
103 for(int i = 0; i < 6; i++)
105 switch (tiles[MYMIN(i, tilecount-1)].rotation)
110 for (int x = 0; x < 4; x++)
111 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
114 for (int x = 0; x < 4; x++)
115 vertices[i*4+x].TCoords.rotateBy(180,irr::core::vector2df(0, 0));
118 for (int x = 0; x < 4; x++)
119 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
122 for (int x = 0; x < 4; x++){
123 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
124 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
128 for (int x = 0; x < 4; x++){
129 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
130 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
134 for (int x = 0; x < 4; x++){
135 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
136 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
140 for (int x = 0; x < 4; x++){
141 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
142 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
146 for (int x = 0; x < 4; x++){
147 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
151 for (int x = 0; x < 4; x++){
152 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
159 u16 indices[] = {0,1,2,2,3,0};
160 // Add to mesh collector
161 for(s32 j=0; j<24; j+=4)
163 int tileindex = MYMIN(j/4, tilecount-1);
164 collector->append(tiles[tileindex],
165 vertices+j, 4, indices, 6);
169 void mapblock_mesh_generate_special(MeshMakeData *data,
170 MeshCollector &collector)
172 INodeDefManager *nodedef = data->m_gamedef->ndef();
173 ITextureSource *tsrc = data->m_gamedef->tsrc();
176 //TimeTaker timer("mapblock_mesh_generate_special()");
181 bool new_style_water = g_settings->getBool("new_style_water");
183 float node_liquid_level = 1.0;
185 node_liquid_level = 0.85;
187 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
189 // Create selection mesh
190 v3s16 p = data->m_highlighted_pos_relative;
191 if (data->m_show_hud &
192 (p.X >= 0) & (p.X < MAP_BLOCKSIZE) &
193 (p.Y >= 0) & (p.Y < MAP_BLOCKSIZE) &
194 (p.Z >= 0) & (p.Z < MAP_BLOCKSIZE)) {
196 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
197 if(n.getContent() != CONTENT_AIR) {
198 // Get selection mesh light level
199 static const v3s16 dirs[7] = {
211 for (u8 i = 0; i < 7; i++) {
212 MapNode n1 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dirs[i]);
213 l1 = getInteriorLight(n1, -4, nodedef);
217 video::SColor c = MapBlock_LightColor(255, l, 0);
218 data->m_highlight_mesh_color = c;
219 std::vector<aabb3f> boxes = n.getSelectionBoxes(nodedef);
221 h_tile.material_flags |= MATERIAL_FLAG_HIGHLIGHTED;
222 h_tile.texture = tsrc->getTexture("halo.png",&h_tile.texture_id);
223 v3f pos = intToFloat(p, BS);
225 for(std::vector<aabb3f>::iterator
227 i != boxes.end(); i++)
230 box.MinEdge += v3f(-d, -d, -d) + pos;
231 box.MaxEdge += v3f(d, d, d) + pos;
232 makeCuboid(&collector, box, &h_tile, 1, c, NULL);
237 for(s16 z = 0; z < MAP_BLOCKSIZE; z++)
238 for(s16 y = 0; y < MAP_BLOCKSIZE; y++)
239 for(s16 x = 0; x < MAP_BLOCKSIZE; x++)
243 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
244 const ContentFeatures &f = nodedef->get(n);
246 // Only solidness=0 stuff is drawn here
252 infostream<<"Got "<<f.drawtype<<std::endl;
260 Add water sources to mesh if using new style
262 TileSpec tile_liquid = f.special_tiles[0];
263 TileSpec tile_liquid_bfculled = getNodeTile(n, p, v3s16(0,0,0), data);
265 bool top_is_same_liquid = false;
266 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
267 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
268 content_t c_source = nodedef->getId(f.liquid_alternative_source);
269 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
270 top_is_same_liquid = true;
272 u16 l = getInteriorLight(n, 0, nodedef);
273 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
278 v3s16 side_dirs[4] = {
284 for(u32 i=0; i<4; i++)
286 v3s16 dir = side_dirs[i];
288 MapNode neighbor = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir);
289 content_t neighbor_content = neighbor.getContent();
290 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
291 MapNode n_top = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir+ v3s16(0,1,0));
292 content_t n_top_c = n_top.getContent();
294 if(neighbor_content == CONTENT_IGNORE)
298 If our topside is liquid and neighbor's topside
299 is liquid, don't draw side face
301 if(top_is_same_liquid && (n_top_c == c_flowing ||
302 n_top_c == c_source || n_top_c == CONTENT_IGNORE))
305 // Don't draw face if neighbor is blocking the view
306 if(n_feat.solidness == 2)
309 bool neighbor_is_same_liquid = (neighbor_content == c_source
310 || neighbor_content == c_flowing);
312 // Don't draw any faces if neighbor same is liquid and top is
314 if(neighbor_is_same_liquid && !top_is_same_liquid)
317 // Use backface culled material if neighbor doesn't have a
319 const TileSpec *current_tile = &tile_liquid;
320 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
321 current_tile = &tile_liquid_bfculled;
323 video::S3DVertex vertices[4] =
325 video::S3DVertex(-BS/2,0,BS/2,0,0,0, c, 0,1),
326 video::S3DVertex(BS/2,0,BS/2,0,0,0, c, 1,1),
327 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
328 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
332 If our topside is liquid, set upper border of face
333 at upper border of node
335 if(top_is_same_liquid)
337 vertices[2].Pos.Y = 0.5*BS;
338 vertices[3].Pos.Y = 0.5*BS;
341 Otherwise upper position of face is liquid level
345 vertices[2].Pos.Y = (node_liquid_level-0.5)*BS;
346 vertices[3].Pos.Y = (node_liquid_level-0.5)*BS;
349 If neighbor is liquid, lower border of face is liquid level
351 if(neighbor_is_same_liquid)
353 vertices[0].Pos.Y = (node_liquid_level-0.5)*BS;
354 vertices[1].Pos.Y = (node_liquid_level-0.5)*BS;
357 If neighbor is not liquid, lower border of face is
362 vertices[0].Pos.Y = -0.5*BS;
363 vertices[1].Pos.Y = -0.5*BS;
366 for(s32 j=0; j<4; j++)
368 if(dir == v3s16(0,0,1))
369 vertices[j].Pos.rotateXZBy(0);
370 if(dir == v3s16(0,0,-1))
371 vertices[j].Pos.rotateXZBy(180);
372 if(dir == v3s16(-1,0,0))
373 vertices[j].Pos.rotateXZBy(90);
374 if(dir == v3s16(1,0,-0))
375 vertices[j].Pos.rotateXZBy(-90);
377 // Do this to not cause glitches when two liquids are
379 /*if(neighbor_is_same_liquid == false){
380 vertices[j].Pos.X *= 0.98;
381 vertices[j].Pos.Z *= 0.98;
384 vertices[j].Pos += intToFloat(p, BS);
387 u16 indices[] = {0,1,2,2,3,0};
388 // Add to mesh collector
389 collector.append(*current_tile, vertices, 4, indices, 6);
395 if(top_is_same_liquid)
398 video::S3DVertex vertices[4] =
400 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
401 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
402 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
403 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
406 v3f offset(p.X*BS, p.Y*BS + (-0.5+node_liquid_level)*BS, p.Z*BS);
407 for(s32 i=0; i<4; i++)
409 vertices[i].Pos += offset;
412 u16 indices[] = {0,1,2,2,3,0};
413 // Add to mesh collector
414 collector.append(tile_liquid, vertices, 4, indices, 6);
416 case NDT_FLOWINGLIQUID:
419 Add flowing liquid to mesh
421 TileSpec tile_liquid = f.special_tiles[0];
422 TileSpec tile_liquid_bfculled = f.special_tiles[1];
424 bool top_is_same_liquid = false;
425 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
426 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
427 content_t c_source = nodedef->getId(f.liquid_alternative_source);
428 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
429 top_is_same_liquid = true;
432 // If this liquid emits light and doesn't contain light, draw
433 // it at what it emits, for an increased effect
434 u8 light_source = nodedef->get(n).light_source;
435 if(light_source != 0){
436 l = decode_light(light_source);
439 // Use the light of the node on top if possible
440 else if(nodedef->get(ntop).param_type == CPT_LIGHT)
441 l = getInteriorLight(ntop, 0, nodedef);
442 // Otherwise use the light of this node (the liquid)
444 l = getInteriorLight(n, 0, nodedef);
445 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
447 u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
449 // Neighbor liquid levels (key = relative position)
450 // Includes current node
451 std::map<v3s16, f32> neighbor_levels;
452 std::map<v3s16, content_t> neighbor_contents;
453 std::map<v3s16, u8> neighbor_flags;
454 const u8 neighborflag_top_is_same_liquid = 0x01;
455 v3s16 neighbor_dirs[9] = {
466 for(u32 i=0; i<9; i++)
468 content_t content = CONTENT_AIR;
469 float level = -0.5 * BS;
472 v3s16 p2 = p + neighbor_dirs[i];
473 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
474 if(n2.getContent() != CONTENT_IGNORE)
476 content = n2.getContent();
478 if(n2.getContent() == c_source)
479 level = (-0.5+node_liquid_level) * BS;
480 else if(n2.getContent() == c_flowing){
481 u8 liquid_level = (n2.param2&LIQUID_LEVEL_MASK);
482 if (liquid_level <= LIQUID_LEVEL_MAX+1-range)
485 liquid_level -= (LIQUID_LEVEL_MAX+1-range);
486 level = (-0.5 + ((float)liquid_level+ 0.5) / (float)range * node_liquid_level) * BS;
489 // Check node above neighbor.
490 // NOTE: This doesn't get executed if neighbor
493 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
494 if(n2.getContent() == c_source ||
495 n2.getContent() == c_flowing)
496 flags |= neighborflag_top_is_same_liquid;
499 neighbor_levels[neighbor_dirs[i]] = level;
500 neighbor_contents[neighbor_dirs[i]] = content;
501 neighbor_flags[neighbor_dirs[i]] = flags;
504 // Corner heights (average between four liquids)
505 f32 corner_levels[4];
507 v3s16 halfdirs[4] = {
513 for(u32 i=0; i<4; i++)
515 v3s16 cornerdir = halfdirs[i];
516 float cornerlevel = 0;
519 for(u32 j=0; j<4; j++)
521 v3s16 neighbordir = cornerdir - halfdirs[j];
522 content_t content = neighbor_contents[neighbordir];
523 // If top is liquid, draw starting from top of node
524 if(neighbor_flags[neighbordir] &
525 neighborflag_top_is_same_liquid)
527 cornerlevel = 0.5*BS;
531 // Source is always the same height
532 else if(content == c_source)
534 cornerlevel = (-0.5+node_liquid_level)*BS;
538 // Flowing liquid has level information
539 else if(content == c_flowing)
541 cornerlevel += neighbor_levels[neighbordir];
544 else if(content == CONTENT_AIR)
550 cornerlevel = -0.5*BS+0.2;
551 else if(valid_count > 0)
552 cornerlevel /= valid_count;
553 corner_levels[i] = cornerlevel;
560 v3s16 side_dirs[4] = {
566 s16 side_corners[4][2] = {
572 for(u32 i=0; i<4; i++)
574 v3s16 dir = side_dirs[i];
577 If our topside is liquid and neighbor's topside
578 is liquid, don't draw side face
580 if(top_is_same_liquid &&
581 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
584 content_t neighbor_content = neighbor_contents[dir];
585 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
587 // Don't draw face if neighbor is blocking the view
588 if(n_feat.solidness == 2)
591 bool neighbor_is_same_liquid = (neighbor_content == c_source
592 || neighbor_content == c_flowing);
594 // Don't draw any faces if neighbor same is liquid and top is
596 if(neighbor_is_same_liquid == true
597 && top_is_same_liquid == false)
600 // Use backface culled material if neighbor doesn't have a
602 const TileSpec *current_tile = &tile_liquid;
603 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
604 current_tile = &tile_liquid_bfculled;
606 video::S3DVertex vertices[4] =
608 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
609 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
610 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
611 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
615 If our topside is liquid, set upper border of face
616 at upper border of node
618 if(top_is_same_liquid)
620 vertices[2].Pos.Y = 0.5*BS;
621 vertices[3].Pos.Y = 0.5*BS;
624 Otherwise upper position of face is corner levels
628 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
629 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
633 If neighbor is liquid, lower border of face is corner
636 if(neighbor_is_same_liquid)
638 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
639 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
642 If neighbor is not liquid, lower border of face is
647 vertices[0].Pos.Y = -0.5*BS;
648 vertices[1].Pos.Y = -0.5*BS;
651 for(s32 j=0; j<4; j++)
653 if(dir == v3s16(0,0,1))
654 vertices[j].Pos.rotateXZBy(0);
655 if(dir == v3s16(0,0,-1))
656 vertices[j].Pos.rotateXZBy(180);
657 if(dir == v3s16(-1,0,0))
658 vertices[j].Pos.rotateXZBy(90);
659 if(dir == v3s16(1,0,-0))
660 vertices[j].Pos.rotateXZBy(-90);
662 // Do this to not cause glitches when two liquids are
664 /*if(neighbor_is_same_liquid == false){
665 vertices[j].Pos.X *= 0.98;
666 vertices[j].Pos.Z *= 0.98;
669 vertices[j].Pos += intToFloat(p, BS);
672 u16 indices[] = {0,1,2,2,3,0};
673 // Add to mesh collector
674 collector.append(*current_tile, vertices, 4, indices, 6);
678 Generate top side, if appropriate
681 if(top_is_same_liquid == false)
683 video::S3DVertex vertices[4] =
685 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
686 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
687 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
688 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
691 // To get backface culling right, the vertices need to go
692 // clockwise around the front of the face. And we happened to
693 // calculate corner levels in exact reverse order.
694 s32 corner_resolve[4] = {3,2,1,0};
696 for(s32 i=0; i<4; i++)
698 //vertices[i].Pos.Y += liquid_level;
699 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
700 s32 j = corner_resolve[i];
701 vertices[i].Pos.Y += corner_levels[j];
702 vertices[i].Pos += intToFloat(p, BS);
705 // Default downwards-flowing texture animation goes from
706 // -Z towards +Z, thus the direction is +Z.
707 // Rotate texture to make animation go in flow direction
708 // Positive if liquid moves towards +Z
709 f32 dz = (corner_levels[side_corners[3][0]] +
710 corner_levels[side_corners[3][1]]) -
711 (corner_levels[side_corners[2][0]] +
712 corner_levels[side_corners[2][1]]);
713 // Positive if liquid moves towards +X
714 f32 dx = (corner_levels[side_corners[1][0]] +
715 corner_levels[side_corners[1][1]]) -
716 (corner_levels[side_corners[0][0]] +
717 corner_levels[side_corners[0][1]]);
718 f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG ;
719 v2f tcoord_center(0.5, 0.5);
720 v2f tcoord_translate(
721 blockpos_nodes.Z + z,
722 blockpos_nodes.X + x);
723 tcoord_translate.rotateBy(tcoord_angle);
724 tcoord_translate.X -= floor(tcoord_translate.X);
725 tcoord_translate.Y -= floor(tcoord_translate.Y);
727 for(s32 i=0; i<4; i++)
729 vertices[i].TCoords.rotateBy(
732 vertices[i].TCoords += tcoord_translate;
735 v2f t = vertices[0].TCoords;
736 vertices[0].TCoords = vertices[2].TCoords;
737 vertices[2].TCoords = t;
739 u16 indices[] = {0,1,2,2,3,0};
740 // Add to mesh collector
741 collector.append(tile_liquid, vertices, 4, indices, 6);
746 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
748 u16 l = getInteriorLight(n, 1, nodedef);
749 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
751 for(u32 j=0; j<6; j++)
753 // Check this neighbor
754 v3s16 n2p = blockpos_nodes + p + g_6dirs[j];
755 MapNode n2 = data->m_vmanip.getNodeNoEx(n2p);
756 // Don't make face if neighbor is of same type
757 if(n2.getContent() == n.getContent())
761 video::S3DVertex vertices[4] = {
762 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c, 1,1),
763 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c, 0,1),
764 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c, 0,0),
765 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c, 1,0),
768 // Rotations in the g_6dirs format
770 for(u16 i=0; i<4; i++)
771 vertices[i].Pos.rotateXZBy(0);
772 else if(j == 1) // Y+
773 for(u16 i=0; i<4; i++)
774 vertices[i].Pos.rotateYZBy(-90);
775 else if(j == 2) // X+
776 for(u16 i=0; i<4; i++)
777 vertices[i].Pos.rotateXZBy(-90);
778 else if(j == 3) // Z-
779 for(u16 i=0; i<4; i++)
780 vertices[i].Pos.rotateXZBy(180);
781 else if(j == 4) // Y-
782 for(u16 i=0; i<4; i++)
783 vertices[i].Pos.rotateYZBy(90);
784 else if(j == 5) // X-
785 for(u16 i=0; i<4; i++)
786 vertices[i].Pos.rotateXZBy(90);
788 for(u16 i=0; i<4; i++){
789 vertices[i].Pos += intToFloat(p, BS);
792 u16 indices[] = {0,1,2,2,3,0};
793 // Add to mesh collector
794 collector.append(tile, vertices, 4, indices, 6);
797 case NDT_GLASSLIKE_FRAMED_OPTIONAL:
798 // This is always pre-converted to something else
801 case NDT_GLASSLIKE_FRAMED:
803 static const v3s16 dirs[6] = {
814 for (i = 0; i < 6; i++)
815 tiles[i] = getNodeTile(n, p, dirs[i], data);
817 TileSpec glass_tiles[6];
818 if (tiles[1].texture && tiles[2].texture && tiles[3].texture) {
819 glass_tiles[0] = tiles[2];
820 glass_tiles[1] = tiles[3];
821 glass_tiles[2] = tiles[1];
822 glass_tiles[3] = tiles[1];
823 glass_tiles[4] = tiles[1];
824 glass_tiles[5] = tiles[1];
826 for (i = 0; i < 6; i++)
827 glass_tiles[i] = tiles[1];
830 u8 param2 = n.getParam2();
831 bool H_merge = ! bool(param2 & 128);
832 bool V_merge = ! bool(param2 & 64);
833 param2 = param2 & 63;
835 u16 l = getInteriorLight(n, 1, nodedef);
836 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
837 v3f pos = intToFloat(p, BS);
838 static const float a = BS / 2;
839 static const float g = a - 0.003;
840 static const float b = .876 * ( BS / 2 );
842 static const aabb3f frame_edges[12] = {
843 aabb3f( b, b,-a, a, a, a), // y+
844 aabb3f(-a, b,-a,-b, a, a), // y+
845 aabb3f( b,-a,-a, a,-b, a), // y-
846 aabb3f(-a,-a,-a,-b,-b, a), // y-
847 aabb3f( b,-a, b, a, a, a), // x+
848 aabb3f( b,-a,-a, a, a,-b), // x+
849 aabb3f(-a,-a, b,-b, a, a), // x-
850 aabb3f(-a,-a,-a,-b, a,-b), // x-
851 aabb3f(-a, b, b, a, a, a), // z+
852 aabb3f(-a,-a, b, a,-b, a), // z+
853 aabb3f(-a,-a,-a, a,-b,-b), // z-
854 aabb3f(-a, b,-a, a, a,-b) // z-
856 static const aabb3f glass_faces[6] = {
857 aabb3f(-g, g,-g, g, g, g), // y+
858 aabb3f(-g,-g,-g, g,-g, g), // y-
859 aabb3f( g,-g,-g, g, g, g), // x+
860 aabb3f(-g,-g,-g,-g, g, g), // x-
861 aabb3f(-g,-g, g, g, g, g), // z+
862 aabb3f(-g,-g,-g, g, g,-g) // z-
865 // table of node visible faces, 0 = invisible
866 int visible_faces[6] = {0,0,0,0,0,0};
868 // table of neighbours, 1 = same type, checked with g_26dirs
869 int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
871 // g_26dirs to check when only horizontal merge is allowed
872 int nb_H_dirs[8] = {0,2,3,5,10,11,12,13};
874 content_t current = n.getContent();
879 // neighbours checks for frames visibility
881 if (!H_merge && V_merge) {
882 n2p = blockpos_nodes + p + g_26dirs[1];
883 n2 = data->m_vmanip.getNodeNoEx(n2p);
884 n2c = n2.getContent();
885 if (n2c == current || n2c == CONTENT_IGNORE)
887 n2p = blockpos_nodes + p + g_26dirs[4];
888 n2 = data->m_vmanip.getNodeNoEx(n2p);
889 n2c = n2.getContent();
890 if (n2c == current || n2c == CONTENT_IGNORE)
892 } else if (H_merge && !V_merge) {
893 for(i = 0; i < 8; i++) {
894 n2p = blockpos_nodes + p + g_26dirs[nb_H_dirs[i]];
895 n2 = data->m_vmanip.getNodeNoEx(n2p);
896 n2c = n2.getContent();
897 if (n2c == current || n2c == CONTENT_IGNORE)
898 nb[nb_H_dirs[i]] = 1;
900 } else if (H_merge && V_merge) {
901 for(i = 0; i < 18; i++) {
902 n2p = blockpos_nodes + p + g_26dirs[i];
903 n2 = data->m_vmanip.getNodeNoEx(n2p);
904 n2c = n2.getContent();
905 if (n2c == current || n2c == CONTENT_IGNORE)
910 // faces visibility checks
913 visible_faces[0] = 1;
914 visible_faces[1] = 1;
916 for(i = 0; i < 2; i++) {
917 n2p = blockpos_nodes + p + dirs[i];
918 n2 = data->m_vmanip.getNodeNoEx(n2p);
919 n2c = n2.getContent();
921 visible_faces[i] = 1;
926 visible_faces[2] = 1;
927 visible_faces[3] = 1;
928 visible_faces[4] = 1;
929 visible_faces[5] = 1;
931 for(i = 2; i < 6; i++) {
932 n2p = blockpos_nodes + p + dirs[i];
933 n2 = data->m_vmanip.getNodeNoEx(n2p);
934 n2c = n2.getContent();
936 visible_faces[i] = 1;
940 static const u8 nb_triplet[12*3] = {
941 1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
942 2,0,11, 2,3,13, 5,0,10, 5,3,12,
943 0,1, 8, 0,4,16, 3,4,17, 3,1, 9
946 f32 tx1, ty1, tz1, tx2, ty2, tz2;
949 for(i = 0; i < 12; i++)
952 if (nb[nb_triplet[i*3+2]])
953 edge_invisible = nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
955 edge_invisible = nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
958 box = frame_edges[i];
961 tx1 = (box.MinEdge.X / BS) + 0.5;
962 ty1 = (box.MinEdge.Y / BS) + 0.5;
963 tz1 = (box.MinEdge.Z / BS) + 0.5;
964 tx2 = (box.MaxEdge.X / BS) + 0.5;
965 ty2 = (box.MaxEdge.Y / BS) + 0.5;
966 tz2 = (box.MaxEdge.Z / BS) + 0.5;
968 tx1, 1-tz2, tx2, 1-tz1,
970 tz1, 1-ty2, tz2, 1-ty1,
971 1-tz2, 1-ty2, 1-tz1, 1-ty1,
972 1-tx2, 1-ty2, 1-tx1, 1-ty1,
973 tx1, 1-ty2, tx2, 1-ty1,
975 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
978 for(i = 0; i < 6; i++)
980 if (!visible_faces[i])
982 box = glass_faces[i];
985 tx1 = (box.MinEdge.X / BS) + 0.5;
986 ty1 = (box.MinEdge.Y / BS) + 0.5;
987 tz1 = (box.MinEdge.Z / BS) + 0.5;
988 tx2 = (box.MaxEdge.X / BS) + 0.5;
989 ty2 = (box.MaxEdge.Y / BS) + 0.5;
990 tz2 = (box.MaxEdge.Z / BS) + 0.5;
992 tx1, 1-tz2, tx2, 1-tz1,
994 tz1, 1-ty2, tz2, 1-ty1,
995 1-tz2, 1-ty2, 1-tz1, 1-ty1,
996 1-tx2, 1-ty2, 1-tx1, 1-ty1,
997 tx1, 1-ty2, tx2, 1-ty1,
999 makeCuboid(&collector, box, &glass_tiles[i], 1, c, txc2);
1002 if (param2 > 0 && f.special_tiles[0].texture) {
1003 // Interior volume level is in range 0 .. 63,
1004 // convert it to -0.5 .. 0.5
1005 float vlev = (((float)param2 / 63.0 ) * 2.0 - 1.0);
1006 TileSpec interior_tiles[6];
1007 for (i = 0; i < 6; i++)
1008 interior_tiles[i] = f.special_tiles[0];
1009 float offset = 0.003;
1010 box = aabb3f(visible_faces[3] ? -b : -a + offset,
1011 visible_faces[1] ? -b : -a + offset,
1012 visible_faces[5] ? -b : -a + offset,
1013 visible_faces[2] ? b : a - offset,
1014 visible_faces[0] ? b * vlev : a * vlev - offset,
1015 visible_faces[4] ? b : a - offset);
1018 tx1 = (box.MinEdge.X / BS) + 0.5;
1019 ty1 = (box.MinEdge.Y / BS) + 0.5;
1020 tz1 = (box.MinEdge.Z / BS) + 0.5;
1021 tx2 = (box.MaxEdge.X / BS) + 0.5;
1022 ty2 = (box.MaxEdge.Y / BS) + 0.5;
1023 tz2 = (box.MaxEdge.Z / BS) + 0.5;
1025 tx1, 1-tz2, tx2, 1-tz1,
1027 tz1, 1-ty2, tz2, 1-ty1,
1028 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1029 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1030 tx1, 1-ty2, tx2, 1-ty1,
1032 makeCuboid(&collector, box, interior_tiles, 6, c, txc3);
1037 TileSpec tile_leaves = getNodeTile(n, p,
1038 v3s16(0,0,0), data);
1040 u16 l = getInteriorLight(n, 1, nodedef);
1041 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1043 v3f pos = intToFloat(p, BS);
1044 aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
1047 makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
1049 case NDT_ALLFACES_OPTIONAL:
1050 // This is always pre-converted to something else
1055 v3s16 dir = n.getWallMountedDir(nodedef);
1058 if(dir == v3s16(0,-1,0)){
1059 tileindex = 0; // floor
1060 } else if(dir == v3s16(0,1,0)){
1061 tileindex = 1; // ceiling
1062 // For backwards compatibility
1063 } else if(dir == v3s16(0,0,0)){
1064 tileindex = 0; // floor
1066 tileindex = 2; // side
1069 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1070 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1071 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1073 u16 l = getInteriorLight(n, 1, nodedef);
1074 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1076 float s = BS/2*f.visual_scale;
1077 // Wall at X+ of node
1078 video::S3DVertex vertices[4] =
1080 video::S3DVertex(-s,-s,0, 0,0,0, c, 0,1),
1081 video::S3DVertex( s,-s,0, 0,0,0, c, 1,1),
1082 video::S3DVertex( s, s,0, 0,0,0, c, 1,0),
1083 video::S3DVertex(-s, s,0, 0,0,0, c, 0,0),
1086 for(s32 i=0; i<4; i++)
1088 if(dir == v3s16(1,0,0))
1089 vertices[i].Pos.rotateXZBy(0);
1090 if(dir == v3s16(-1,0,0))
1091 vertices[i].Pos.rotateXZBy(180);
1092 if(dir == v3s16(0,0,1))
1093 vertices[i].Pos.rotateXZBy(90);
1094 if(dir == v3s16(0,0,-1))
1095 vertices[i].Pos.rotateXZBy(-90);
1096 if(dir == v3s16(0,-1,0))
1097 vertices[i].Pos.rotateXZBy(45);
1098 if(dir == v3s16(0,1,0))
1099 vertices[i].Pos.rotateXZBy(-45);
1101 vertices[i].Pos += intToFloat(p, BS);
1104 u16 indices[] = {0,1,2,2,3,0};
1105 // Add to mesh collector
1106 collector.append(tile, vertices, 4, indices, 6);
1110 TileSpec tile = getNodeTileN(n, p, 0, data);
1111 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1112 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1114 u16 l = getInteriorLight(n, 0, nodedef);
1115 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1117 float d = (float)BS/16;
1118 float s = BS/2*f.visual_scale;
1119 // Wall at X+ of node
1120 video::S3DVertex vertices[4] =
1122 video::S3DVertex(BS/2-d, s, s, 0,0,0, c, 0,0),
1123 video::S3DVertex(BS/2-d, s, -s, 0,0,0, c, 1,0),
1124 video::S3DVertex(BS/2-d, -s, -s, 0,0,0, c, 1,1),
1125 video::S3DVertex(BS/2-d, -s, s, 0,0,0, c, 0,1),
1128 v3s16 dir = n.getWallMountedDir(nodedef);
1130 for(s32 i=0; i<4; i++)
1132 if(dir == v3s16(1,0,0))
1133 vertices[i].Pos.rotateXZBy(0);
1134 if(dir == v3s16(-1,0,0))
1135 vertices[i].Pos.rotateXZBy(180);
1136 if(dir == v3s16(0,0,1))
1137 vertices[i].Pos.rotateXZBy(90);
1138 if(dir == v3s16(0,0,-1))
1139 vertices[i].Pos.rotateXZBy(-90);
1140 if(dir == v3s16(0,-1,0))
1141 vertices[i].Pos.rotateXYBy(-90);
1142 if(dir == v3s16(0,1,0))
1143 vertices[i].Pos.rotateXYBy(90);
1145 vertices[i].Pos += intToFloat(p, BS);
1148 u16 indices[] = {0,1,2,2,3,0};
1149 // Add to mesh collector
1150 collector.append(tile, vertices, 4, indices, 6);
1154 TileSpec tile = getNodeTileN(n, p, 0, data);
1155 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1157 u16 l = getInteriorLight(n, 1, nodedef);
1158 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1160 float s = BS/2*f.visual_scale;
1162 for(u32 j=0; j<2; j++)
1164 video::S3DVertex vertices[4] =
1166 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1167 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1168 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1169 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1174 for(u16 i=0; i<4; i++)
1175 vertices[i].Pos.rotateXZBy(46 + n.param2 * 2);
1179 for(u16 i=0; i<4; i++)
1180 vertices[i].Pos.rotateXZBy(-44 + n.param2 * 2);
1183 for(u16 i=0; i<4; i++)
1185 vertices[i].Pos *= f.visual_scale;
1186 vertices[i].Pos += intToFloat(p, BS);
1189 u16 indices[] = {0,1,2,2,3,0};
1190 // Add to mesh collector
1191 collector.append(tile, vertices, 4, indices, 6);
1196 TileSpec tile = getNodeTileN(n, p, 0, data);
1197 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1199 u16 l = getInteriorLight(n, 1, nodedef);
1200 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1202 float s = BS/2*f.visual_scale;
1204 content_t current = n.getContent();
1209 static const v3s16 dirs[6] = {
1218 int doDraw[6] = {0,0,0,0,0,0};
1220 bool drawAllFaces = true;
1222 bool drawBottomFacesOnly = false; // Currently unused
1224 // Check for adjacent nodes
1225 for(int i = 0; i < 6; i++)
1227 n2p = blockpos_nodes + p + dirs[i];
1228 n2 = data->m_vmanip.getNodeNoEx(n2p);
1229 n2c = n2.getContent();
1230 if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) {
1233 drawAllFaces = false;
1238 for(int j = 0; j < 6; j++)
1240 int vOffset = 0; // Vertical offset of faces after rotation
1241 int hOffset = 4; // Horizontal offset of faces to reach the edge
1243 video::S3DVertex vertices[4] =
1245 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1246 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1247 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1248 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1251 // Calculate which faces should be drawn, (top or sides)
1252 if(j == 0 && (drawAllFaces || (doDraw[3] == 1 || doDraw[1] == 1)))
1254 for(int i = 0; i < 4; i++) {
1255 vertices[i].Pos.rotateXZBy(90 + n.param2 * 2);
1256 vertices[i].Pos.rotateXYBy(-10);
1257 vertices[i].Pos.Y -= vOffset;
1258 vertices[i].Pos.X -= hOffset;
1261 else if(j == 1 && (drawAllFaces || (doDraw[5] == 1 || doDraw[1] == 1)))
1263 for(int i = 0; i < 4; i++) {
1264 vertices[i].Pos.rotateXZBy(180 + n.param2 * 2);
1265 vertices[i].Pos.rotateYZBy(10);
1266 vertices[i].Pos.Y -= vOffset;
1267 vertices[i].Pos.Z -= hOffset;
1270 else if(j == 2 && (drawAllFaces || (doDraw[2] == 1 || doDraw[1] == 1)))
1272 for(int i = 0; i < 4; i++) {
1273 vertices[i].Pos.rotateXZBy(270 + n.param2 * 2);
1274 vertices[i].Pos.rotateXYBy(10);
1275 vertices[i].Pos.Y -= vOffset;
1276 vertices[i].Pos.X += hOffset;
1279 else if(j == 3 && (drawAllFaces || (doDraw[4] == 1 || doDraw[1] == 1)))
1281 for(int i = 0; i < 4; i++) {
1282 vertices[i].Pos.rotateYZBy(-10);
1283 vertices[i].Pos.Y -= vOffset;
1284 vertices[i].Pos.Z += hOffset;
1288 // Center cross-flames
1289 else if(j == 4 && (drawAllFaces || doDraw[1] == 1))
1291 for(int i=0; i<4; i++) {
1292 vertices[i].Pos.rotateXZBy(45 + n.param2 * 2);
1293 vertices[i].Pos.Y -= vOffset;
1296 else if(j == 5 && (drawAllFaces || doDraw[1] == 1))
1298 for(int i=0; i<4; i++) {
1299 vertices[i].Pos.rotateXZBy(-45 + n.param2 * 2);
1300 vertices[i].Pos.Y -= vOffset;
1304 // Render flames on bottom
1305 else if(j == 0 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
1307 for(int i = 0; i < 4; i++) {
1308 vertices[i].Pos.rotateYZBy(70);
1309 vertices[i].Pos.rotateXZBy(90 + n.param2 * 2);
1310 vertices[i].Pos.Y += 4.84;
1311 vertices[i].Pos.X -= hOffset+0.7;
1314 else if(j == 1 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
1316 for(int i = 0; i < 4; i++) {
1317 vertices[i].Pos.rotateYZBy(70);
1318 vertices[i].Pos.rotateXZBy(180 + n.param2 * 2);
1319 vertices[i].Pos.Y += 4.84;
1320 vertices[i].Pos.Z -= hOffset+0.7;
1323 else if(j == 2 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
1325 for(int i = 0; i < 4; i++) {
1326 vertices[i].Pos.rotateYZBy(70);
1327 vertices[i].Pos.rotateXZBy(270 + n.param2 * 2);
1328 vertices[i].Pos.Y += 4.84;
1329 vertices[i].Pos.X += hOffset+0.7;
1332 else if(j == 3 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
1334 for(int i = 0; i < 4; i++) {
1335 vertices[i].Pos.rotateYZBy(70);
1336 vertices[i].Pos.Y += 4.84;
1337 vertices[i].Pos.Z += hOffset+0.7;
1341 // Skip faces that aren't adjacent to a node
1345 for(int i=0; i<4; i++)
1347 vertices[i].Pos *= f.visual_scale;
1348 vertices[i].Pos += intToFloat(p, BS);
1351 u16 indices[] = {0,1,2,2,3,0};
1352 // Add to mesh collector
1353 collector.append(tile, vertices, 4, indices, 6);
1358 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1359 TileSpec tile_nocrack = tile;
1360 tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1362 // Put wood the right way around in the posts
1363 TileSpec tile_rot = tile;
1364 tile_rot.rotation = 1;
1366 u16 l = getInteriorLight(n, 1, nodedef);
1367 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1369 const f32 post_rad=(f32)BS/8;
1370 const f32 bar_rad=(f32)BS/16;
1371 const f32 bar_len=(f32)(BS/2)-post_rad;
1373 v3f pos = intToFloat(p, BS);
1375 // The post - always present
1376 aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
1377 post.MinEdge += pos;
1378 post.MaxEdge += pos;
1380 6/16.,6/16.,10/16.,10/16.,
1381 6/16.,6/16.,10/16.,10/16.,
1386 makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1388 // Now a section of fence, +X, if there's a post there
1391 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1392 const ContentFeatures *f2 = &nodedef->get(n2);
1393 if(f2->drawtype == NDT_FENCELIKE)
1395 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1396 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1400 0/16.,2/16.,16/16.,4/16.,
1401 0/16.,4/16.,16/16.,6/16.,
1402 6/16.,6/16.,8/16.,8/16.,
1403 10/16.,10/16.,12/16.,12/16.,
1404 0/16.,8/16.,16/16.,10/16.,
1405 0/16.,14/16.,16/16.,16/16.};
1406 makeCuboid(&collector, bar, &tile_nocrack, 1,
1408 bar.MinEdge.Y -= BS/2;
1409 bar.MaxEdge.Y -= BS/2;
1410 makeCuboid(&collector, bar, &tile_nocrack, 1,
1414 // Now a section of fence, +Z, if there's a post there
1417 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1418 f2 = &nodedef->get(n2);
1419 if(f2->drawtype == NDT_FENCELIKE)
1421 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1422 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1426 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
1427 4/16.,1/16.,6/16.,5/16., // for wood texture instead
1428 0/16.,9/16.,16/16.,11/16.,
1429 0/16.,6/16.,16/16.,8/16.,
1430 6/16.,6/16.,8/16.,8/16.,
1431 10/16.,10/16.,12/16.,12/16.};
1432 makeCuboid(&collector, bar, &tile_nocrack, 1,
1434 bar.MinEdge.Y -= BS/2;
1435 bar.MaxEdge.Y -= BS/2;
1436 makeCuboid(&collector, bar, &tile_nocrack, 1,
1442 bool is_rail_x [] = { false, false }; /* x-1, x+1 */
1443 bool is_rail_z [] = { false, false }; /* z-1, z+1 */
1445 bool is_rail_z_minus_y [] = { false, false }; /* z-1, z+1; y-1 */
1446 bool is_rail_x_minus_y [] = { false, false }; /* x-1, z+1; y-1 */
1447 bool is_rail_z_plus_y [] = { false, false }; /* z-1, z+1; y+1 */
1448 bool is_rail_x_plus_y [] = { false, false }; /* x-1, x+1; y+1 */
1450 MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
1451 MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
1452 MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
1453 MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
1454 MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
1455 MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
1456 MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
1457 MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
1458 MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
1459 MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
1460 MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
1461 MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
1463 content_t thiscontent = n.getContent();
1464 std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
1465 bool self_connect_to_raillike = ((ItemGroupList) nodedef->get(n).groups)[groupname] != 0;
1467 if ((nodedef->get(n_minus_x).drawtype == NDT_RAILLIKE
1468 && ((ItemGroupList) nodedef->get(n_minus_x).groups)[groupname] != 0
1469 && self_connect_to_raillike)
1470 || n_minus_x.getContent() == thiscontent)
1471 is_rail_x[0] = true;
1473 if ((nodedef->get(n_minus_x_minus_y).drawtype == NDT_RAILLIKE
1474 && ((ItemGroupList) nodedef->get(n_minus_x_minus_y).groups)[groupname] != 0
1475 && self_connect_to_raillike)
1476 || n_minus_x_minus_y.getContent() == thiscontent)
1477 is_rail_x_minus_y[0] = true;
1479 if ((nodedef->get(n_minus_x_plus_y).drawtype == NDT_RAILLIKE
1480 && ((ItemGroupList) nodedef->get(n_minus_x_plus_y).groups)[groupname] != 0
1481 && self_connect_to_raillike)
1482 || n_minus_x_plus_y.getContent() == thiscontent)
1483 is_rail_x_plus_y[0] = true;
1485 if ((nodedef->get(n_plus_x).drawtype == NDT_RAILLIKE
1486 && ((ItemGroupList) nodedef->get(n_plus_x).groups)[groupname] != 0
1487 && self_connect_to_raillike)
1488 || n_plus_x.getContent() == thiscontent)
1489 is_rail_x[1] = true;
1491 if ((nodedef->get(n_plus_x_minus_y).drawtype == NDT_RAILLIKE
1492 && ((ItemGroupList) nodedef->get(n_plus_x_minus_y).groups)[groupname] != 0
1493 && self_connect_to_raillike)
1494 || n_plus_x_minus_y.getContent() == thiscontent)
1495 is_rail_x_minus_y[1] = true;
1497 if ((nodedef->get(n_plus_x_plus_y).drawtype == NDT_RAILLIKE
1498 && ((ItemGroupList) nodedef->get(n_plus_x_plus_y).groups)[groupname] != 0
1499 && self_connect_to_raillike)
1500 || n_plus_x_plus_y.getContent() == thiscontent)
1501 is_rail_x_plus_y[1] = true;
1503 if ((nodedef->get(n_minus_z).drawtype == NDT_RAILLIKE
1504 && ((ItemGroupList) nodedef->get(n_minus_z).groups)[groupname] != 0
1505 && self_connect_to_raillike)
1506 || n_minus_z.getContent() == thiscontent)
1507 is_rail_z[0] = true;
1509 if ((nodedef->get(n_minus_z_minus_y).drawtype == NDT_RAILLIKE
1510 && ((ItemGroupList) nodedef->get(n_minus_z_minus_y).groups)[groupname] != 0
1511 && self_connect_to_raillike)
1512 || n_minus_z_minus_y.getContent() == thiscontent)
1513 is_rail_z_minus_y[0] = true;
1515 if ((nodedef->get(n_minus_z_plus_y).drawtype == NDT_RAILLIKE
1516 && ((ItemGroupList) nodedef->get(n_minus_z_plus_y).groups)[groupname] != 0
1517 && self_connect_to_raillike)
1518 || n_minus_z_plus_y.getContent() == thiscontent)
1519 is_rail_z_plus_y[0] = true;
1521 if ((nodedef->get(n_plus_z).drawtype == NDT_RAILLIKE
1522 && ((ItemGroupList) nodedef->get(n_plus_z).groups)[groupname] != 0
1523 && self_connect_to_raillike)
1524 || n_plus_z.getContent() == thiscontent)
1525 is_rail_z[1] = true;
1527 if ((nodedef->get(n_plus_z_minus_y).drawtype == NDT_RAILLIKE
1528 && ((ItemGroupList) nodedef->get(n_plus_z_minus_y).groups)[groupname] != 0
1529 && self_connect_to_raillike)
1530 || n_plus_z_minus_y.getContent() == thiscontent)
1531 is_rail_z_minus_y[1] = true;
1533 if ((nodedef->get(n_plus_z_plus_y).drawtype == NDT_RAILLIKE
1534 && ((ItemGroupList) nodedef->get(n_plus_z_plus_y).groups)[groupname] != 0
1535 && self_connect_to_raillike)
1536 || n_plus_z_plus_y.getContent() == thiscontent)
1537 is_rail_z_plus_y[1] = true;
1539 bool is_rail_x_all[] = {false, false};
1540 bool is_rail_z_all[] = {false, false};
1541 is_rail_x_all[0]=is_rail_x[0] || is_rail_x_minus_y[0] || is_rail_x_plus_y[0];
1542 is_rail_x_all[1]=is_rail_x[1] || is_rail_x_minus_y[1] || is_rail_x_plus_y[1];
1543 is_rail_z_all[0]=is_rail_z[0] || is_rail_z_minus_y[0] || is_rail_z_plus_y[0];
1544 is_rail_z_all[1]=is_rail_z[1] || is_rail_z_minus_y[1] || is_rail_z_plus_y[1];
1546 // reasonable default, flat straight unrotated rail
1547 bool is_straight = true;
1548 int adjacencies = 0;
1552 // check for sloped rail
1553 if (is_rail_x_plus_y[0] || is_rail_x_plus_y[1] || is_rail_z_plus_y[0] || is_rail_z_plus_y[1])
1555 adjacencies = 5; //5 means sloped
1556 is_straight = true; // sloped is always straight
1560 // is really straight, rails on both sides
1561 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
1562 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
1565 switch (adjacencies) {
1567 if(is_rail_x_all[0] || is_rail_x_all[1])
1572 tileindex = 1; // curved
1573 if(is_rail_x_all[0] && is_rail_x_all[1])
1575 if(is_rail_z_all[0] && is_rail_z_all[1]){
1576 if (is_rail_z_plus_y[0])
1579 else if(is_rail_x_all[0] && is_rail_z_all[0])
1581 else if(is_rail_x_all[0] && is_rail_z_all[1])
1583 else if(is_rail_x_all[1] && is_rail_z_all[1])
1587 // here is where the potential to 'switch' a junction is, but not implemented at present
1588 tileindex = 2; // t-junction
1589 if(!is_rail_x_all[1])
1591 if(!is_rail_z_all[0])
1593 if(!is_rail_z_all[1])
1597 tileindex = 3; // crossing
1600 if(is_rail_z_plus_y[0])
1602 if(is_rail_x_plus_y[0])
1604 if(is_rail_x_plus_y[1])
1611 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1612 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1613 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1615 u16 l = getInteriorLight(n, 0, nodedef);
1616 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1618 float d = (float)BS/64;
1621 if (is_rail_x_plus_y[0] || is_rail_x_plus_y[1] || is_rail_z_plus_y[0] || is_rail_z_plus_y[1])
1622 g=1; //Object is at a slope
1624 video::S3DVertex vertices[4] =
1626 video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c, 0,1),
1627 video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c, 1,1),
1628 video::S3DVertex(BS/2,g*BS/2+d,BS/2, 0,0,0, c, 1,0),
1629 video::S3DVertex(-BS/2,g*BS/2+d,BS/2, 0,0,0, c, 0,0),
1632 for(s32 i=0; i<4; i++)
1635 vertices[i].Pos.rotateXZBy(angle);
1636 vertices[i].Pos += intToFloat(p, BS);
1639 u16 indices[] = {0,1,2,2,3,0};
1640 collector.append(tile, vertices, 4, indices, 6);
1644 static const v3s16 tile_dirs[6] = {
1654 u16 l = getInteriorLight(n, 1, nodedef);
1655 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1657 v3f pos = intToFloat(p, BS);
1659 std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1660 for(std::vector<aabb3f>::iterator
1662 i != boxes.end(); i++)
1664 for(int j = 0; j < 6; j++)
1666 // Handles facedir rotation for textures
1667 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1674 if (box.MinEdge.X > box.MaxEdge.X)
1677 box.MinEdge.X=box.MaxEdge.X;
1680 if (box.MinEdge.Y > box.MaxEdge.Y)
1683 box.MinEdge.Y=box.MaxEdge.Y;
1686 if (box.MinEdge.Z > box.MaxEdge.Z)
1689 box.MinEdge.Z=box.MaxEdge.Z;
1694 // Compute texture coords
1695 f32 tx1 = (box.MinEdge.X/BS)+0.5;
1696 f32 ty1 = (box.MinEdge.Y/BS)+0.5;
1697 f32 tz1 = (box.MinEdge.Z/BS)+0.5;
1698 f32 tx2 = (box.MaxEdge.X/BS)+0.5;
1699 f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
1700 f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
1703 tx1, 1-tz2, tx2, 1-tz1,
1707 tz1, 1-ty2, tz2, 1-ty1,
1709 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1711 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1713 tx1, 1-ty2, tx2, 1-ty1,
1715 makeCuboid(&collector, box, tiles, 6, c, txc);