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"
22 #include "main.h" // For g_settings
23 #include "mapblock_mesh.h" // For MapBlock_LightColor() and MeshCollector
28 #include "util/numeric.h"
29 #include "util/directiontables.h"
32 // collector - the MeshCollector for the resulting polygons
33 // box - the position and size of the box
34 // tiles - the tiles (materials) to use (for all 6 faces)
35 // tilecount - number of entries in tiles, 1<=tilecount<=6
36 // c - vertex colour - used for all
37 // txc - texture coordinates - this is a list of texture coordinates
38 // for the opposite corners of each face - therefore, there
39 // should be (2+2)*6=24 values in the list. Alternatively, pass
40 // NULL to use the entire texture for each face. The order of
41 // the faces in the list is up-down-right-left-back-front
42 // (compatible with ContentFeatures). If you specified 0,0,1,1
43 // for each face, that would be the same as passing NULL.
44 void makeCuboid(MeshCollector *collector, const aabb3f &box,
45 TileSpec *tiles, int tilecount,
46 video::SColor &c, const f32* txc)
48 assert(tilecount >= 1 && tilecount <= 6);
50 v3f min = box.MinEdge;
51 v3f max = box.MaxEdge;
57 static const f32 txc_default[24] = {
68 video::S3DVertex vertices[24] =
71 video::S3DVertex(min.X,max.Y,max.Z, 0,1,0, c, txc[0],txc[1]),
72 video::S3DVertex(max.X,max.Y,max.Z, 0,1,0, c, txc[2],txc[1]),
73 video::S3DVertex(max.X,max.Y,min.Z, 0,1,0, c, txc[2],txc[3]),
74 video::S3DVertex(min.X,max.Y,min.Z, 0,1,0, c, txc[0],txc[3]),
76 video::S3DVertex(min.X,min.Y,min.Z, 0,-1,0, c, txc[4],txc[5]),
77 video::S3DVertex(max.X,min.Y,min.Z, 0,-1,0, c, txc[6],txc[5]),
78 video::S3DVertex(max.X,min.Y,max.Z, 0,-1,0, c, txc[6],txc[7]),
79 video::S3DVertex(min.X,min.Y,max.Z, 0,-1,0, c, txc[4],txc[7]),
81 video::S3DVertex(max.X,max.Y,min.Z, 1,0,0, c, txc[ 8],txc[9]),
82 video::S3DVertex(max.X,max.Y,max.Z, 1,0,0, c, txc[10],txc[9]),
83 video::S3DVertex(max.X,min.Y,max.Z, 1,0,0, c, txc[10],txc[11]),
84 video::S3DVertex(max.X,min.Y,min.Z, 1,0,0, c, txc[ 8],txc[11]),
86 video::S3DVertex(min.X,max.Y,max.Z, -1,0,0, c, txc[12],txc[13]),
87 video::S3DVertex(min.X,max.Y,min.Z, -1,0,0, c, txc[14],txc[13]),
88 video::S3DVertex(min.X,min.Y,min.Z, -1,0,0, c, txc[14],txc[15]),
89 video::S3DVertex(min.X,min.Y,max.Z, -1,0,0, c, txc[12],txc[15]),
91 video::S3DVertex(max.X,max.Y,max.Z, 0,0,1, c, txc[16],txc[17]),
92 video::S3DVertex(min.X,max.Y,max.Z, 0,0,1, c, txc[18],txc[17]),
93 video::S3DVertex(min.X,min.Y,max.Z, 0,0,1, c, txc[18],txc[19]),
94 video::S3DVertex(max.X,min.Y,max.Z, 0,0,1, c, txc[16],txc[19]),
96 video::S3DVertex(min.X,max.Y,min.Z, 0,0,-1, c, txc[20],txc[21]),
97 video::S3DVertex(max.X,max.Y,min.Z, 0,0,-1, c, txc[22],txc[21]),
98 video::S3DVertex(max.X,min.Y,min.Z, 0,0,-1, c, txc[22],txc[23]),
99 video::S3DVertex(min.X,min.Y,min.Z, 0,0,-1, c, txc[20],txc[23]),
102 for(int i = 0; i < 6; i++)
104 switch (tiles[MYMIN(i, tilecount-1)].rotation)
109 for (int x = 0; x < 4; x++)
110 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
113 for (int x = 0; x < 4; x++)
114 vertices[i*4+x].TCoords.rotateBy(180,irr::core::vector2df(0, 0));
117 for (int x = 0; x < 4; x++)
118 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
121 for (int x = 0; x < 4; x++){
122 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
123 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
127 for (int x = 0; x < 4; x++){
128 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
129 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
133 for (int x = 0; x < 4; x++){
134 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
135 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
139 for (int x = 0; x < 4; x++){
140 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
141 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
145 for (int x = 0; x < 4; x++){
146 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
150 for (int x = 0; x < 4; x++){
151 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
158 u16 indices[] = {0,1,2,2,3,0};
159 // Add to mesh collector
160 for(s32 j=0; j<24; j+=4)
162 int tileindex = MYMIN(j/4, tilecount-1);
163 collector->append(tiles[tileindex],
164 vertices+j, 4, indices, 6);
168 void mapblock_mesh_generate_special(MeshMakeData *data,
169 MeshCollector &collector)
171 INodeDefManager *nodedef = data->m_gamedef->ndef();
172 ITextureSource *tsrc = data->m_gamedef->tsrc();
175 //TimeTaker timer("mapblock_mesh_generate_special()");
180 bool new_style_water = g_settings->getBool("new_style_water");
182 float node_liquid_level = 1.0;
184 node_liquid_level = 0.85;
186 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
188 // Create selection mesh
189 v3s16 p = data->m_highlighted_pos_relative;
190 if (data->m_show_hud &
191 (p.X >= 0) & (p.X < MAP_BLOCKSIZE) &
192 (p.Y >= 0) & (p.Y < MAP_BLOCKSIZE) &
193 (p.Z >= 0) & (p.Z < MAP_BLOCKSIZE)) {
195 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
196 if(n.getContent() != CONTENT_AIR) {
197 // Get selection mesh light level
198 static const v3s16 dirs[7] = {
210 for (u8 i = 0; i < 7; i++) {
211 MapNode n1 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dirs[i]);
212 l1 = getInteriorLight(n1, -4, nodedef);
216 video::SColor c = MapBlock_LightColor(255, l, 0);
217 data->m_highlight_mesh_color = c;
218 std::vector<aabb3f> boxes = n.getSelectionBoxes(nodedef);
220 h_tile.material_flags |= MATERIAL_FLAG_HIGHLIGHTED;
221 h_tile.texture = tsrc->getTexture("halo.png",&h_tile.texture_id);
222 v3f pos = intToFloat(p, BS);
224 for(std::vector<aabb3f>::iterator
226 i != boxes.end(); i++)
229 box.MinEdge += v3f(-d, -d, -d) + pos;
230 box.MaxEdge += v3f(d, d, d) + pos;
231 makeCuboid(&collector, box, &h_tile, 1, c, NULL);
236 for(s16 z = 0; z < MAP_BLOCKSIZE; z++)
237 for(s16 y = 0; y < MAP_BLOCKSIZE; y++)
238 for(s16 x = 0; x < MAP_BLOCKSIZE; x++)
242 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
243 const ContentFeatures &f = nodedef->get(n);
245 // Only solidness=0 stuff is drawn here
251 infostream<<"Got "<<f.drawtype<<std::endl;
259 Add water sources to mesh if using new style
261 TileSpec tile_liquid = f.special_tiles[0];
262 TileSpec tile_liquid_bfculled = getNodeTile(n, p, v3s16(0,0,0), data);
264 bool top_is_same_liquid = false;
265 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
266 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
267 content_t c_source = nodedef->getId(f.liquid_alternative_source);
268 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
269 top_is_same_liquid = true;
271 u16 l = getInteriorLight(n, 0, nodedef);
272 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
277 v3s16 side_dirs[4] = {
283 for(u32 i=0; i<4; i++)
285 v3s16 dir = side_dirs[i];
287 MapNode neighbor = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir);
288 content_t neighbor_content = neighbor.getContent();
289 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
290 MapNode n_top = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir+ v3s16(0,1,0));
291 content_t n_top_c = n_top.getContent();
293 if(neighbor_content == CONTENT_IGNORE)
297 If our topside is liquid and neighbor's topside
298 is liquid, don't draw side face
300 if(top_is_same_liquid && (n_top_c == c_flowing ||
301 n_top_c == c_source || n_top_c == CONTENT_IGNORE))
304 // Don't draw face if neighbor is blocking the view
305 if(n_feat.solidness == 2)
308 bool neighbor_is_same_liquid = (neighbor_content == c_source
309 || neighbor_content == c_flowing);
311 // Don't draw any faces if neighbor same is liquid and top is
313 if(neighbor_is_same_liquid && !top_is_same_liquid)
316 // Use backface culled material if neighbor doesn't have a
318 const TileSpec *current_tile = &tile_liquid;
319 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
320 current_tile = &tile_liquid_bfculled;
322 video::S3DVertex vertices[4] =
324 video::S3DVertex(-BS/2,0,BS/2,0,0,0, c, 0,1),
325 video::S3DVertex(BS/2,0,BS/2,0,0,0, c, 1,1),
326 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
327 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
331 If our topside is liquid, set upper border of face
332 at upper border of node
334 if(top_is_same_liquid)
336 vertices[2].Pos.Y = 0.5*BS;
337 vertices[3].Pos.Y = 0.5*BS;
340 Otherwise upper position of face is liquid level
344 vertices[2].Pos.Y = (node_liquid_level-0.5)*BS;
345 vertices[3].Pos.Y = (node_liquid_level-0.5)*BS;
348 If neighbor is liquid, lower border of face is liquid level
350 if(neighbor_is_same_liquid)
352 vertices[0].Pos.Y = (node_liquid_level-0.5)*BS;
353 vertices[1].Pos.Y = (node_liquid_level-0.5)*BS;
356 If neighbor is not liquid, lower border of face is
361 vertices[0].Pos.Y = -0.5*BS;
362 vertices[1].Pos.Y = -0.5*BS;
365 for(s32 j=0; j<4; j++)
367 if(dir == v3s16(0,0,1))
368 vertices[j].Pos.rotateXZBy(0);
369 if(dir == v3s16(0,0,-1))
370 vertices[j].Pos.rotateXZBy(180);
371 if(dir == v3s16(-1,0,0))
372 vertices[j].Pos.rotateXZBy(90);
373 if(dir == v3s16(1,0,-0))
374 vertices[j].Pos.rotateXZBy(-90);
376 // Do this to not cause glitches when two liquids are
378 /*if(neighbor_is_same_liquid == false){
379 vertices[j].Pos.X *= 0.98;
380 vertices[j].Pos.Z *= 0.98;
383 vertices[j].Pos += intToFloat(p, BS);
386 u16 indices[] = {0,1,2,2,3,0};
387 // Add to mesh collector
388 collector.append(*current_tile, vertices, 4, indices, 6);
394 if(top_is_same_liquid)
397 video::S3DVertex vertices[4] =
399 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
400 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
401 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
402 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
405 v3f offset(p.X*BS, p.Y*BS + (-0.5+node_liquid_level)*BS, p.Z*BS);
406 for(s32 i=0; i<4; i++)
408 vertices[i].Pos += offset;
411 u16 indices[] = {0,1,2,2,3,0};
412 // Add to mesh collector
413 collector.append(tile_liquid, vertices, 4, indices, 6);
415 case NDT_FLOWINGLIQUID:
418 Add flowing liquid to mesh
420 TileSpec tile_liquid = f.special_tiles[0];
421 TileSpec tile_liquid_bfculled = f.special_tiles[1];
423 bool top_is_same_liquid = false;
424 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
425 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
426 content_t c_source = nodedef->getId(f.liquid_alternative_source);
427 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
428 top_is_same_liquid = true;
431 // If this liquid emits light and doesn't contain light, draw
432 // it at what it emits, for an increased effect
433 u8 light_source = nodedef->get(n).light_source;
434 if(light_source != 0){
435 l = decode_light(light_source);
438 // Use the light of the node on top if possible
439 else if(nodedef->get(ntop).param_type == CPT_LIGHT)
440 l = getInteriorLight(ntop, 0, nodedef);
441 // Otherwise use the light of this node (the liquid)
443 l = getInteriorLight(n, 0, nodedef);
444 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
446 u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
448 // Neighbor liquid levels (key = relative position)
449 // Includes current node
450 std::map<v3s16, f32> neighbor_levels;
451 std::map<v3s16, content_t> neighbor_contents;
452 std::map<v3s16, u8> neighbor_flags;
453 const u8 neighborflag_top_is_same_liquid = 0x01;
454 v3s16 neighbor_dirs[9] = {
465 for(u32 i=0; i<9; i++)
467 content_t content = CONTENT_AIR;
468 float level = -0.5 * BS;
471 v3s16 p2 = p + neighbor_dirs[i];
472 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
473 if(n2.getContent() != CONTENT_IGNORE)
475 content = n2.getContent();
477 if(n2.getContent() == c_source)
478 level = (-0.5+node_liquid_level) * BS;
479 else if(n2.getContent() == c_flowing){
480 u8 liquid_level = (n2.param2&LIQUID_LEVEL_MASK);
481 if (liquid_level <= LIQUID_LEVEL_MAX+1-range)
484 liquid_level -= (LIQUID_LEVEL_MAX+1-range);
485 level = (-0.5 + ((float)liquid_level+ 0.5) / (float)range * node_liquid_level) * BS;
488 // Check node above neighbor.
489 // NOTE: This doesn't get executed if neighbor
492 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
493 if(n2.getContent() == c_source ||
494 n2.getContent() == c_flowing)
495 flags |= neighborflag_top_is_same_liquid;
498 neighbor_levels[neighbor_dirs[i]] = level;
499 neighbor_contents[neighbor_dirs[i]] = content;
500 neighbor_flags[neighbor_dirs[i]] = flags;
503 // Corner heights (average between four liquids)
504 f32 corner_levels[4];
506 v3s16 halfdirs[4] = {
512 for(u32 i=0; i<4; i++)
514 v3s16 cornerdir = halfdirs[i];
515 float cornerlevel = 0;
518 for(u32 j=0; j<4; j++)
520 v3s16 neighbordir = cornerdir - halfdirs[j];
521 content_t content = neighbor_contents[neighbordir];
522 // If top is liquid, draw starting from top of node
523 if(neighbor_flags[neighbordir] &
524 neighborflag_top_is_same_liquid)
526 cornerlevel = 0.5*BS;
530 // Source is always the same height
531 else if(content == c_source)
533 cornerlevel = (-0.5+node_liquid_level)*BS;
537 // Flowing liquid has level information
538 else if(content == c_flowing)
540 cornerlevel += neighbor_levels[neighbordir];
543 else if(content == CONTENT_AIR)
549 cornerlevel = -0.5*BS+0.2;
550 else if(valid_count > 0)
551 cornerlevel /= valid_count;
552 corner_levels[i] = cornerlevel;
559 v3s16 side_dirs[4] = {
565 s16 side_corners[4][2] = {
571 for(u32 i=0; i<4; i++)
573 v3s16 dir = side_dirs[i];
576 If our topside is liquid and neighbor's topside
577 is liquid, don't draw side face
579 if(top_is_same_liquid &&
580 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
583 content_t neighbor_content = neighbor_contents[dir];
584 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
586 // Don't draw face if neighbor is blocking the view
587 if(n_feat.solidness == 2)
590 bool neighbor_is_same_liquid = (neighbor_content == c_source
591 || neighbor_content == c_flowing);
593 // Don't draw any faces if neighbor same is liquid and top is
595 if(neighbor_is_same_liquid == true
596 && top_is_same_liquid == false)
599 // Use backface culled material if neighbor doesn't have a
601 const TileSpec *current_tile = &tile_liquid;
602 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
603 current_tile = &tile_liquid_bfculled;
605 video::S3DVertex vertices[4] =
607 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
608 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
609 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
610 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
614 If our topside is liquid, set upper border of face
615 at upper border of node
617 if(top_is_same_liquid)
619 vertices[2].Pos.Y = 0.5*BS;
620 vertices[3].Pos.Y = 0.5*BS;
623 Otherwise upper position of face is corner levels
627 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
628 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
632 If neighbor is liquid, lower border of face is corner
635 if(neighbor_is_same_liquid)
637 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
638 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
641 If neighbor is not liquid, lower border of face is
646 vertices[0].Pos.Y = -0.5*BS;
647 vertices[1].Pos.Y = -0.5*BS;
650 for(s32 j=0; j<4; j++)
652 if(dir == v3s16(0,0,1))
653 vertices[j].Pos.rotateXZBy(0);
654 if(dir == v3s16(0,0,-1))
655 vertices[j].Pos.rotateXZBy(180);
656 if(dir == v3s16(-1,0,0))
657 vertices[j].Pos.rotateXZBy(90);
658 if(dir == v3s16(1,0,-0))
659 vertices[j].Pos.rotateXZBy(-90);
661 // Do this to not cause glitches when two liquids are
663 /*if(neighbor_is_same_liquid == false){
664 vertices[j].Pos.X *= 0.98;
665 vertices[j].Pos.Z *= 0.98;
668 vertices[j].Pos += intToFloat(p, BS);
671 u16 indices[] = {0,1,2,2,3,0};
672 // Add to mesh collector
673 collector.append(*current_tile, vertices, 4, indices, 6);
677 Generate top side, if appropriate
680 if(top_is_same_liquid == false)
682 video::S3DVertex vertices[4] =
684 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
685 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
686 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
687 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
690 // To get backface culling right, the vertices need to go
691 // clockwise around the front of the face. And we happened to
692 // calculate corner levels in exact reverse order.
693 s32 corner_resolve[4] = {3,2,1,0};
695 for(s32 i=0; i<4; i++)
697 //vertices[i].Pos.Y += liquid_level;
698 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
699 s32 j = corner_resolve[i];
700 vertices[i].Pos.Y += corner_levels[j];
701 vertices[i].Pos += intToFloat(p, BS);
704 // Default downwards-flowing texture animation goes from
705 // -Z towards +Z, thus the direction is +Z.
706 // Rotate texture to make animation go in flow direction
707 // Positive if liquid moves towards +Z
708 f32 dz = (corner_levels[side_corners[3][0]] +
709 corner_levels[side_corners[3][1]]) -
710 (corner_levels[side_corners[2][0]] +
711 corner_levels[side_corners[2][1]]);
712 // Positive if liquid moves towards +X
713 f32 dx = (corner_levels[side_corners[1][0]] +
714 corner_levels[side_corners[1][1]]) -
715 (corner_levels[side_corners[0][0]] +
716 corner_levels[side_corners[0][1]]);
717 f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG ;
718 v2f tcoord_center(0.5, 0.5);
719 v2f tcoord_translate(
720 blockpos_nodes.Z + z,
721 blockpos_nodes.X + x);
722 tcoord_translate.rotateBy(tcoord_angle);
723 tcoord_translate.X -= floor(tcoord_translate.X);
724 tcoord_translate.Y -= floor(tcoord_translate.Y);
726 for(s32 i=0; i<4; i++)
728 vertices[i].TCoords.rotateBy(
731 vertices[i].TCoords += tcoord_translate;
734 v2f t = vertices[0].TCoords;
735 vertices[0].TCoords = vertices[2].TCoords;
736 vertices[2].TCoords = t;
738 u16 indices[] = {0,1,2,2,3,0};
739 // Add to mesh collector
740 collector.append(tile_liquid, vertices, 4, indices, 6);
745 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
747 u16 l = getInteriorLight(n, 1, nodedef);
748 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
750 for(u32 j=0; j<6; j++)
752 // Check this neighbor
753 v3s16 n2p = blockpos_nodes + p + g_6dirs[j];
754 MapNode n2 = data->m_vmanip.getNodeNoEx(n2p);
755 // Don't make face if neighbor is of same type
756 if(n2.getContent() == n.getContent())
760 video::S3DVertex vertices[4] = {
761 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c, 1,1),
762 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c, 0,1),
763 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c, 0,0),
764 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c, 1,0),
767 // Rotations in the g_6dirs format
769 for(u16 i=0; i<4; i++)
770 vertices[i].Pos.rotateXZBy(0);
771 else if(j == 1) // Y+
772 for(u16 i=0; i<4; i++)
773 vertices[i].Pos.rotateYZBy(-90);
774 else if(j == 2) // X+
775 for(u16 i=0; i<4; i++)
776 vertices[i].Pos.rotateXZBy(-90);
777 else if(j == 3) // Z-
778 for(u16 i=0; i<4; i++)
779 vertices[i].Pos.rotateXZBy(180);
780 else if(j == 4) // Y-
781 for(u16 i=0; i<4; i++)
782 vertices[i].Pos.rotateYZBy(90);
783 else if(j == 5) // X-
784 for(u16 i=0; i<4; i++)
785 vertices[i].Pos.rotateXZBy(90);
787 for(u16 i=0; i<4; i++){
788 vertices[i].Pos += intToFloat(p, BS);
791 u16 indices[] = {0,1,2,2,3,0};
792 // Add to mesh collector
793 collector.append(tile, vertices, 4, indices, 6);
796 case NDT_GLASSLIKE_FRAMED:
798 static const v3s16 dirs[6] = {
809 for (i = 0; i < 6; i++)
810 tiles[i] = getNodeTile(n, p, dirs[i], data);
812 TileSpec glass_tiles[6];
813 if (tiles[1].texture && tiles[2].texture && tiles[3].texture) {
814 glass_tiles[0] = tiles[2];
815 glass_tiles[1] = tiles[3];
816 glass_tiles[2] = tiles[1];
817 glass_tiles[3] = tiles[1];
818 glass_tiles[4] = tiles[1];
819 glass_tiles[5] = tiles[1];
821 for (i = 0; i < 6; i++)
822 glass_tiles[i] = tiles[1];
825 u8 param2 = n.getParam2();
826 bool H_merge = ! bool(param2 & 128);
827 bool V_merge = ! bool(param2 & 64);
828 param2 = param2 & 63;
830 u16 l = getInteriorLight(n, 1, nodedef);
831 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
832 v3f pos = intToFloat(p, BS);
833 static const float a = BS / 2;
834 static const float g = a - 0.003;
835 static const float b = .876 * ( BS / 2 );
837 static const aabb3f frame_edges[12] = {
838 aabb3f( b, b,-a, a, a, a), // y+
839 aabb3f(-a, b,-a,-b, a, a), // y+
840 aabb3f( b,-a,-a, a,-b, a), // y-
841 aabb3f(-a,-a,-a,-b,-b, a), // y-
842 aabb3f( b,-a, b, a, a, a), // x+
843 aabb3f( b,-a,-a, a, a,-b), // x+
844 aabb3f(-a,-a, b,-b, a, a), // x-
845 aabb3f(-a,-a,-a,-b, a,-b), // x-
846 aabb3f(-a, b, b, a, a, a), // z+
847 aabb3f(-a,-a, b, a,-b, a), // z+
848 aabb3f(-a,-a,-a, a,-b,-b), // z-
849 aabb3f(-a, b,-a, a, a,-b) // z-
851 static const aabb3f glass_faces[6] = {
852 aabb3f(-g, g,-g, g, g, g), // y+
853 aabb3f(-g,-g,-g, g,-g, g), // y-
854 aabb3f( g,-g,-g, g, g, g), // x+
855 aabb3f(-g,-g,-g,-g, g, g), // x-
856 aabb3f(-g,-g, g, g, g, g), // z+
857 aabb3f(-g,-g,-g, g, g,-g) // z-
860 // table of node visible faces, 0 = invisible
861 int visible_faces[6] = {0,0,0,0,0,0};
863 // table of neighbours, 1 = same type, checked with g_26dirs
864 int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
866 // g_26dirs to check when only horizontal merge is allowed
867 int nb_H_dirs[8] = {0,2,3,5,10,11,12,13};
869 content_t current = n.getContent();
874 // neighbours checks for frames visibility
876 if (!H_merge && V_merge) {
877 n2p = blockpos_nodes + p + g_26dirs[1];
878 n2 = data->m_vmanip.getNodeNoEx(n2p);
879 n2c = n2.getContent();
880 if (n2c == current || n2c == CONTENT_IGNORE)
882 n2p = blockpos_nodes + p + g_26dirs[4];
883 n2 = data->m_vmanip.getNodeNoEx(n2p);
884 n2c = n2.getContent();
885 if (n2c == current || n2c == CONTENT_IGNORE)
887 } else if (H_merge && !V_merge) {
888 for(i = 0; i < 8; i++) {
889 n2p = blockpos_nodes + p + g_26dirs[nb_H_dirs[i]];
890 n2 = data->m_vmanip.getNodeNoEx(n2p);
891 n2c = n2.getContent();
892 if (n2c == current || n2c == CONTENT_IGNORE)
893 nb[nb_H_dirs[i]] = 1;
895 } else if (H_merge && V_merge) {
896 for(i = 0; i < 18; i++) {
897 n2p = blockpos_nodes + p + g_26dirs[i];
898 n2 = data->m_vmanip.getNodeNoEx(n2p);
899 n2c = n2.getContent();
900 if (n2c == current || n2c == CONTENT_IGNORE)
905 // faces visibility checks
908 visible_faces[0] = 1;
909 visible_faces[1] = 1;
911 for(i = 0; i < 2; i++) {
912 n2p = blockpos_nodes + p + dirs[i];
913 n2 = data->m_vmanip.getNodeNoEx(n2p);
914 n2c = n2.getContent();
916 visible_faces[i] = 1;
921 visible_faces[2] = 1;
922 visible_faces[3] = 1;
923 visible_faces[4] = 1;
924 visible_faces[5] = 1;
926 for(i = 2; i < 6; i++) {
927 n2p = blockpos_nodes + p + dirs[i];
928 n2 = data->m_vmanip.getNodeNoEx(n2p);
929 n2c = n2.getContent();
931 visible_faces[i] = 1;
935 static const u8 nb_triplet[12*3] = {
936 1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
937 2,0,11, 2,3,13, 5,0,10, 5,3,12,
938 0,1, 8, 0,4,16, 3,4,17, 3,1, 9
941 f32 tx1, ty1, tz1, tx2, ty2, tz2;
944 for(i = 0; i < 12; i++)
947 if (nb[nb_triplet[i*3+2]])
948 edge_invisible = nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
950 edge_invisible = nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
953 box = frame_edges[i];
956 tx1 = (box.MinEdge.X / BS) + 0.5;
957 ty1 = (box.MinEdge.Y / BS) + 0.5;
958 tz1 = (box.MinEdge.Z / BS) + 0.5;
959 tx2 = (box.MaxEdge.X / BS) + 0.5;
960 ty2 = (box.MaxEdge.Y / BS) + 0.5;
961 tz2 = (box.MaxEdge.Z / BS) + 0.5;
963 tx1, 1-tz2, tx2, 1-tz1,
965 tz1, 1-ty2, tz2, 1-ty1,
966 1-tz2, 1-ty2, 1-tz1, 1-ty1,
967 1-tx2, 1-ty2, 1-tx1, 1-ty1,
968 tx1, 1-ty2, tx2, 1-ty1,
970 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
973 for(i = 0; i < 6; i++)
975 if (!visible_faces[i])
977 box = glass_faces[i];
980 tx1 = (box.MinEdge.X / BS) + 0.5;
981 ty1 = (box.MinEdge.Y / BS) + 0.5;
982 tz1 = (box.MinEdge.Z / BS) + 0.5;
983 tx2 = (box.MaxEdge.X / BS) + 0.5;
984 ty2 = (box.MaxEdge.Y / BS) + 0.5;
985 tz2 = (box.MaxEdge.Z / BS) + 0.5;
987 tx1, 1-tz2, tx2, 1-tz1,
989 tz1, 1-ty2, tz2, 1-ty1,
990 1-tz2, 1-ty2, 1-tz1, 1-ty1,
991 1-tx2, 1-ty2, 1-tx1, 1-ty1,
992 tx1, 1-ty2, tx2, 1-ty1,
994 makeCuboid(&collector, box, &glass_tiles[i], 1, c, txc2);
997 if (param2 > 0 && f.special_tiles[0].texture) {
998 // Interior volume level is in range 0 .. 63,
999 // convert it to -0.5 .. 0.5
1000 float vlev = (((float)param2 / 63.0 ) * 2.0 - 1.0);
1001 TileSpec interior_tiles[6];
1002 for (i = 0; i < 6; i++)
1003 interior_tiles[i] = f.special_tiles[0];
1004 float offset = 0.003;
1005 box = aabb3f(visible_faces[3] ? -b : -a + offset,
1006 visible_faces[1] ? -b : -a + offset,
1007 visible_faces[5] ? -b : -a + offset,
1008 visible_faces[2] ? b : a - offset,
1009 visible_faces[0] ? b * vlev : a * vlev - offset,
1010 visible_faces[4] ? b : a - offset);
1013 tx1 = (box.MinEdge.X / BS) + 0.5;
1014 ty1 = (box.MinEdge.Y / BS) + 0.5;
1015 tz1 = (box.MinEdge.Z / BS) + 0.5;
1016 tx2 = (box.MaxEdge.X / BS) + 0.5;
1017 ty2 = (box.MaxEdge.Y / BS) + 0.5;
1018 tz2 = (box.MaxEdge.Z / BS) + 0.5;
1020 tx1, 1-tz2, tx2, 1-tz1,
1022 tz1, 1-ty2, tz2, 1-ty1,
1023 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1024 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1025 tx1, 1-ty2, tx2, 1-ty1,
1027 makeCuboid(&collector, box, interior_tiles, 6, c, txc3);
1032 TileSpec tile_leaves = getNodeTile(n, p,
1033 v3s16(0,0,0), data);
1035 u16 l = getInteriorLight(n, 1, nodedef);
1036 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1038 v3f pos = intToFloat(p, BS);
1039 aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
1042 makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
1044 case NDT_ALLFACES_OPTIONAL:
1045 // This is always pre-converted to something else
1050 v3s16 dir = n.getWallMountedDir(nodedef);
1053 if(dir == v3s16(0,-1,0)){
1054 tileindex = 0; // floor
1055 } else if(dir == v3s16(0,1,0)){
1056 tileindex = 1; // ceiling
1057 // For backwards compatibility
1058 } else if(dir == v3s16(0,0,0)){
1059 tileindex = 0; // floor
1061 tileindex = 2; // side
1064 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1065 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1066 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1068 u16 l = getInteriorLight(n, 1, nodedef);
1069 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1071 float s = BS/2*f.visual_scale;
1072 // Wall at X+ of node
1073 video::S3DVertex vertices[4] =
1075 video::S3DVertex(-s,-s,0, 0,0,0, c, 0,1),
1076 video::S3DVertex( s,-s,0, 0,0,0, c, 1,1),
1077 video::S3DVertex( s, s,0, 0,0,0, c, 1,0),
1078 video::S3DVertex(-s, s,0, 0,0,0, c, 0,0),
1081 for(s32 i=0; i<4; i++)
1083 if(dir == v3s16(1,0,0))
1084 vertices[i].Pos.rotateXZBy(0);
1085 if(dir == v3s16(-1,0,0))
1086 vertices[i].Pos.rotateXZBy(180);
1087 if(dir == v3s16(0,0,1))
1088 vertices[i].Pos.rotateXZBy(90);
1089 if(dir == v3s16(0,0,-1))
1090 vertices[i].Pos.rotateXZBy(-90);
1091 if(dir == v3s16(0,-1,0))
1092 vertices[i].Pos.rotateXZBy(45);
1093 if(dir == v3s16(0,1,0))
1094 vertices[i].Pos.rotateXZBy(-45);
1096 vertices[i].Pos += intToFloat(p, BS);
1099 u16 indices[] = {0,1,2,2,3,0};
1100 // Add to mesh collector
1101 collector.append(tile, vertices, 4, indices, 6);
1105 TileSpec tile = getNodeTileN(n, p, 0, data);
1106 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1107 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1109 u16 l = getInteriorLight(n, 0, nodedef);
1110 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1112 float d = (float)BS/16;
1113 float s = BS/2*f.visual_scale;
1114 // Wall at X+ of node
1115 video::S3DVertex vertices[4] =
1117 video::S3DVertex(BS/2-d, s, s, 0,0,0, c, 0,0),
1118 video::S3DVertex(BS/2-d, s, -s, 0,0,0, c, 1,0),
1119 video::S3DVertex(BS/2-d, -s, -s, 0,0,0, c, 1,1),
1120 video::S3DVertex(BS/2-d, -s, s, 0,0,0, c, 0,1),
1123 v3s16 dir = n.getWallMountedDir(nodedef);
1125 for(s32 i=0; i<4; i++)
1127 if(dir == v3s16(1,0,0))
1128 vertices[i].Pos.rotateXZBy(0);
1129 if(dir == v3s16(-1,0,0))
1130 vertices[i].Pos.rotateXZBy(180);
1131 if(dir == v3s16(0,0,1))
1132 vertices[i].Pos.rotateXZBy(90);
1133 if(dir == v3s16(0,0,-1))
1134 vertices[i].Pos.rotateXZBy(-90);
1135 if(dir == v3s16(0,-1,0))
1136 vertices[i].Pos.rotateXYBy(-90);
1137 if(dir == v3s16(0,1,0))
1138 vertices[i].Pos.rotateXYBy(90);
1140 vertices[i].Pos += intToFloat(p, BS);
1143 u16 indices[] = {0,1,2,2,3,0};
1144 // Add to mesh collector
1145 collector.append(tile, vertices, 4, indices, 6);
1149 TileSpec tile = getNodeTileN(n, p, 0, data);
1150 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1152 u16 l = getInteriorLight(n, 1, nodedef);
1153 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1155 float s = BS/2*f.visual_scale;
1157 for(u32 j=0; j<2; j++)
1159 video::S3DVertex vertices[4] =
1161 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1162 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1163 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1164 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1169 for(u16 i=0; i<4; i++)
1170 vertices[i].Pos.rotateXZBy(46 + n.param2 * 2);
1174 for(u16 i=0; i<4; i++)
1175 vertices[i].Pos.rotateXZBy(-44 + n.param2 * 2);
1178 for(u16 i=0; i<4; i++)
1180 vertices[i].Pos *= f.visual_scale;
1181 vertices[i].Pos += intToFloat(p, BS);
1184 u16 indices[] = {0,1,2,2,3,0};
1185 // Add to mesh collector
1186 collector.append(tile, vertices, 4, indices, 6);
1191 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1192 TileSpec tile_nocrack = tile;
1193 tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1195 // Put wood the right way around in the posts
1196 TileSpec tile_rot = tile;
1197 tile_rot.rotation = 1;
1199 u16 l = getInteriorLight(n, 1, nodedef);
1200 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1202 const f32 post_rad=(f32)BS/8;
1203 const f32 bar_rad=(f32)BS/16;
1204 const f32 bar_len=(f32)(BS/2)-post_rad;
1206 v3f pos = intToFloat(p, BS);
1208 // The post - always present
1209 aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
1210 post.MinEdge += pos;
1211 post.MaxEdge += pos;
1213 6/16.,6/16.,10/16.,10/16.,
1214 6/16.,6/16.,10/16.,10/16.,
1219 makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1221 // Now a section of fence, +X, if there's a post there
1224 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1225 const ContentFeatures *f2 = &nodedef->get(n2);
1226 if(f2->drawtype == NDT_FENCELIKE)
1228 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1229 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1233 0/16.,2/16.,16/16.,4/16.,
1234 0/16.,4/16.,16/16.,6/16.,
1235 6/16.,6/16.,8/16.,8/16.,
1236 10/16.,10/16.,12/16.,12/16.,
1237 0/16.,8/16.,16/16.,10/16.,
1238 0/16.,14/16.,16/16.,16/16.};
1239 makeCuboid(&collector, bar, &tile_nocrack, 1,
1241 bar.MinEdge.Y -= BS/2;
1242 bar.MaxEdge.Y -= BS/2;
1243 makeCuboid(&collector, bar, &tile_nocrack, 1,
1247 // Now a section of fence, +Z, if there's a post there
1250 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1251 f2 = &nodedef->get(n2);
1252 if(f2->drawtype == NDT_FENCELIKE)
1254 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1255 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1259 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
1260 4/16.,1/16.,6/16.,5/16., // for wood texture instead
1261 0/16.,9/16.,16/16.,11/16.,
1262 0/16.,6/16.,16/16.,8/16.,
1263 6/16.,6/16.,8/16.,8/16.,
1264 10/16.,10/16.,12/16.,12/16.};
1265 makeCuboid(&collector, bar, &tile_nocrack, 1,
1267 bar.MinEdge.Y -= BS/2;
1268 bar.MaxEdge.Y -= BS/2;
1269 makeCuboid(&collector, bar, &tile_nocrack, 1,
1275 bool is_rail_x [] = { false, false }; /* x-1, x+1 */
1276 bool is_rail_z [] = { false, false }; /* z-1, z+1 */
1278 bool is_rail_z_minus_y [] = { false, false }; /* z-1, z+1; y-1 */
1279 bool is_rail_x_minus_y [] = { false, false }; /* x-1, z+1; y-1 */
1280 bool is_rail_z_plus_y [] = { false, false }; /* z-1, z+1; y+1 */
1281 bool is_rail_x_plus_y [] = { false, false }; /* x-1, x+1; y+1 */
1283 MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
1284 MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
1285 MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
1286 MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
1287 MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
1288 MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
1289 MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
1290 MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
1291 MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
1292 MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
1293 MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
1294 MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
1296 content_t thiscontent = n.getContent();
1297 std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
1298 bool self_connect_to_raillike = ((ItemGroupList) nodedef->get(n).groups)[groupname] != 0;
1300 if ((nodedef->get(n_minus_x).drawtype == NDT_RAILLIKE
1301 && ((ItemGroupList) nodedef->get(n_minus_x).groups)[groupname] != 0
1302 && self_connect_to_raillike)
1303 || n_minus_x.getContent() == thiscontent)
1304 is_rail_x[0] = true;
1306 if ((nodedef->get(n_minus_x_minus_y).drawtype == NDT_RAILLIKE
1307 && ((ItemGroupList) nodedef->get(n_minus_x_minus_y).groups)[groupname] != 0
1308 && self_connect_to_raillike)
1309 || n_minus_x_minus_y.getContent() == thiscontent)
1310 is_rail_x_minus_y[0] = true;
1312 if ((nodedef->get(n_minus_x_plus_y).drawtype == NDT_RAILLIKE
1313 && ((ItemGroupList) nodedef->get(n_minus_x_plus_y).groups)[groupname] != 0
1314 && self_connect_to_raillike)
1315 || n_minus_x_plus_y.getContent() == thiscontent)
1316 is_rail_x_plus_y[0] = true;
1318 if ((nodedef->get(n_plus_x).drawtype == NDT_RAILLIKE
1319 && ((ItemGroupList) nodedef->get(n_plus_x).groups)[groupname] != 0
1320 && self_connect_to_raillike)
1321 || n_plus_x.getContent() == thiscontent)
1322 is_rail_x[1] = true;
1324 if ((nodedef->get(n_plus_x_minus_y).drawtype == NDT_RAILLIKE
1325 && ((ItemGroupList) nodedef->get(n_plus_x_minus_y).groups)[groupname] != 0
1326 && self_connect_to_raillike)
1327 || n_plus_x_minus_y.getContent() == thiscontent)
1328 is_rail_x_minus_y[1] = true;
1330 if ((nodedef->get(n_plus_x_plus_y).drawtype == NDT_RAILLIKE
1331 && ((ItemGroupList) nodedef->get(n_plus_x_plus_y).groups)[groupname] != 0
1332 && self_connect_to_raillike)
1333 || n_plus_x_plus_y.getContent() == thiscontent)
1334 is_rail_x_plus_y[1] = true;
1336 if ((nodedef->get(n_minus_z).drawtype == NDT_RAILLIKE
1337 && ((ItemGroupList) nodedef->get(n_minus_z).groups)[groupname] != 0
1338 && self_connect_to_raillike)
1339 || n_minus_z.getContent() == thiscontent)
1340 is_rail_z[0] = true;
1342 if ((nodedef->get(n_minus_z_minus_y).drawtype == NDT_RAILLIKE
1343 && ((ItemGroupList) nodedef->get(n_minus_z_minus_y).groups)[groupname] != 0
1344 && self_connect_to_raillike)
1345 || n_minus_z_minus_y.getContent() == thiscontent)
1346 is_rail_z_minus_y[0] = true;
1348 if ((nodedef->get(n_minus_z_plus_y).drawtype == NDT_RAILLIKE
1349 && ((ItemGroupList) nodedef->get(n_minus_z_plus_y).groups)[groupname] != 0
1350 && self_connect_to_raillike)
1351 || n_minus_z_plus_y.getContent() == thiscontent)
1352 is_rail_z_plus_y[0] = true;
1354 if ((nodedef->get(n_plus_z).drawtype == NDT_RAILLIKE
1355 && ((ItemGroupList) nodedef->get(n_plus_z).groups)[groupname] != 0
1356 && self_connect_to_raillike)
1357 || n_plus_z.getContent() == thiscontent)
1358 is_rail_z[1] = true;
1360 if ((nodedef->get(n_plus_z_minus_y).drawtype == NDT_RAILLIKE
1361 && ((ItemGroupList) nodedef->get(n_plus_z_minus_y).groups)[groupname] != 0
1362 && self_connect_to_raillike)
1363 || n_plus_z_minus_y.getContent() == thiscontent)
1364 is_rail_z_minus_y[1] = true;
1366 if ((nodedef->get(n_plus_z_plus_y).drawtype == NDT_RAILLIKE
1367 && ((ItemGroupList) nodedef->get(n_plus_z_plus_y).groups)[groupname] != 0
1368 && self_connect_to_raillike)
1369 || n_plus_z_plus_y.getContent() == thiscontent)
1370 is_rail_z_plus_y[1] = true;
1372 bool is_rail_x_all[] = {false, false};
1373 bool is_rail_z_all[] = {false, false};
1374 is_rail_x_all[0]=is_rail_x[0] || is_rail_x_minus_y[0] || is_rail_x_plus_y[0];
1375 is_rail_x_all[1]=is_rail_x[1] || is_rail_x_minus_y[1] || is_rail_x_plus_y[1];
1376 is_rail_z_all[0]=is_rail_z[0] || is_rail_z_minus_y[0] || is_rail_z_plus_y[0];
1377 is_rail_z_all[1]=is_rail_z[1] || is_rail_z_minus_y[1] || is_rail_z_plus_y[1];
1379 // reasonable default, flat straight unrotated rail
1380 bool is_straight = true;
1381 int adjacencies = 0;
1385 // check for sloped rail
1386 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])
1388 adjacencies = 5; //5 means sloped
1389 is_straight = true; // sloped is always straight
1393 // is really straight, rails on both sides
1394 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
1395 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
1398 switch (adjacencies) {
1400 if(is_rail_x_all[0] || is_rail_x_all[1])
1405 tileindex = 1; // curved
1406 if(is_rail_x_all[0] && is_rail_x_all[1])
1408 if(is_rail_z_all[0] && is_rail_z_all[1]){
1409 if (is_rail_z_plus_y[0])
1412 else if(is_rail_x_all[0] && is_rail_z_all[0])
1414 else if(is_rail_x_all[0] && is_rail_z_all[1])
1416 else if(is_rail_x_all[1] && is_rail_z_all[1])
1420 // here is where the potential to 'switch' a junction is, but not implemented at present
1421 tileindex = 2; // t-junction
1422 if(!is_rail_x_all[1])
1424 if(!is_rail_z_all[0])
1426 if(!is_rail_z_all[1])
1430 tileindex = 3; // crossing
1433 if(is_rail_z_plus_y[0])
1435 if(is_rail_x_plus_y[0])
1437 if(is_rail_x_plus_y[1])
1444 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1445 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1446 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1448 u16 l = getInteriorLight(n, 0, nodedef);
1449 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1451 float d = (float)BS/64;
1454 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])
1455 g=1; //Object is at a slope
1457 video::S3DVertex vertices[4] =
1459 video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c, 0,1),
1460 video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c, 1,1),
1461 video::S3DVertex(BS/2,g*BS/2+d,BS/2, 0,0,0, c, 1,0),
1462 video::S3DVertex(-BS/2,g*BS/2+d,BS/2, 0,0,0, c, 0,0),
1465 for(s32 i=0; i<4; i++)
1468 vertices[i].Pos.rotateXZBy(angle);
1469 vertices[i].Pos += intToFloat(p, BS);
1472 u16 indices[] = {0,1,2,2,3,0};
1473 collector.append(tile, vertices, 4, indices, 6);
1477 static const v3s16 tile_dirs[6] = {
1487 u16 l = getInteriorLight(n, 1, nodedef);
1488 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1490 v3f pos = intToFloat(p, BS);
1492 std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1493 for(std::vector<aabb3f>::iterator
1495 i != boxes.end(); i++)
1497 for(int j = 0; j < 6; j++)
1499 // Handles facedir rotation for textures
1500 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1507 if (box.MinEdge.X > box.MaxEdge.X)
1510 box.MinEdge.X=box.MaxEdge.X;
1513 if (box.MinEdge.Y > box.MaxEdge.Y)
1516 box.MinEdge.Y=box.MaxEdge.Y;
1519 if (box.MinEdge.Z > box.MaxEdge.Z)
1522 box.MinEdge.Z=box.MaxEdge.Z;
1527 // Compute texture coords
1528 f32 tx1 = (box.MinEdge.X/BS)+0.5;
1529 f32 ty1 = (box.MinEdge.Y/BS)+0.5;
1530 f32 tz1 = (box.MinEdge.Z/BS)+0.5;
1531 f32 tx2 = (box.MaxEdge.X/BS)+0.5;
1532 f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
1533 f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
1536 tx1, 1-tz2, tx2, 1-tz1,
1540 tz1, 1-ty2, tz2, 1-ty1,
1542 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1544 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1546 tx1, 1-ty2, tx2, 1-ty1,
1548 makeCuboid(&collector, box, tiles, 6, c, txc);