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:
799 static const v3s16 dirs[6] = {
810 for (i = 0; i < 6; i++)
811 tiles[i] = getNodeTile(n, p, dirs[i], data);
813 TileSpec glass_tiles[6];
814 if (tiles[1].texture && tiles[2].texture && tiles[3].texture) {
815 glass_tiles[0] = tiles[2];
816 glass_tiles[1] = tiles[3];
817 glass_tiles[2] = tiles[1];
818 glass_tiles[3] = tiles[1];
819 glass_tiles[4] = tiles[1];
820 glass_tiles[5] = tiles[1];
822 for (i = 0; i < 6; i++)
823 glass_tiles[i] = tiles[1];
826 u8 param2 = n.getParam2();
827 bool H_merge = ! bool(param2 & 128);
828 bool V_merge = ! bool(param2 & 64);
829 param2 = param2 & 63;
831 u16 l = getInteriorLight(n, 1, nodedef);
832 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
833 v3f pos = intToFloat(p, BS);
834 static const float a = BS / 2;
835 static const float g = a - 0.003;
836 static const float b = .876 * ( BS / 2 );
838 static const aabb3f frame_edges[12] = {
839 aabb3f( b, b,-a, a, a, a), // y+
840 aabb3f(-a, b,-a,-b, a, a), // y+
841 aabb3f( b,-a,-a, a,-b, a), // y-
842 aabb3f(-a,-a,-a,-b,-b, a), // y-
843 aabb3f( b,-a, b, a, a, a), // x+
844 aabb3f( b,-a,-a, a, a,-b), // x+
845 aabb3f(-a,-a, b,-b, a, a), // x-
846 aabb3f(-a,-a,-a,-b, a,-b), // x-
847 aabb3f(-a, b, b, a, a, a), // z+
848 aabb3f(-a,-a, b, a,-b, a), // z+
849 aabb3f(-a,-a,-a, a,-b,-b), // z-
850 aabb3f(-a, b,-a, a, a,-b) // z-
852 static const aabb3f glass_faces[6] = {
853 aabb3f(-g, g,-g, g, g, g), // y+
854 aabb3f(-g,-g,-g, g,-g, g), // y-
855 aabb3f( g,-g,-g, g, g, g), // x+
856 aabb3f(-g,-g,-g,-g, g, g), // x-
857 aabb3f(-g,-g, g, g, g, g), // z+
858 aabb3f(-g,-g,-g, g, g,-g) // z-
861 // table of node visible faces, 0 = invisible
862 int visible_faces[6] = {0,0,0,0,0,0};
864 // table of neighbours, 1 = same type, checked with g_26dirs
865 int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
867 // g_26dirs to check when only horizontal merge is allowed
868 int nb_H_dirs[8] = {0,2,3,5,10,11,12,13};
870 content_t current = n.getContent();
875 // neighbours checks for frames visibility
877 if (!H_merge && V_merge) {
878 n2p = blockpos_nodes + p + g_26dirs[1];
879 n2 = data->m_vmanip.getNodeNoEx(n2p);
880 n2c = n2.getContent();
881 if (n2c == current || n2c == CONTENT_IGNORE)
883 n2p = blockpos_nodes + p + g_26dirs[4];
884 n2 = data->m_vmanip.getNodeNoEx(n2p);
885 n2c = n2.getContent();
886 if (n2c == current || n2c == CONTENT_IGNORE)
888 } else if (H_merge && !V_merge) {
889 for(i = 0; i < 8; i++) {
890 n2p = blockpos_nodes + p + g_26dirs[nb_H_dirs[i]];
891 n2 = data->m_vmanip.getNodeNoEx(n2p);
892 n2c = n2.getContent();
893 if (n2c == current || n2c == CONTENT_IGNORE)
894 nb[nb_H_dirs[i]] = 1;
896 } else if (H_merge && V_merge) {
897 for(i = 0; i < 18; i++) {
898 n2p = blockpos_nodes + p + g_26dirs[i];
899 n2 = data->m_vmanip.getNodeNoEx(n2p);
900 n2c = n2.getContent();
901 if (n2c == current || n2c == CONTENT_IGNORE)
906 // faces visibility checks
909 visible_faces[0] = 1;
910 visible_faces[1] = 1;
912 for(i = 0; i < 2; i++) {
913 n2p = blockpos_nodes + p + dirs[i];
914 n2 = data->m_vmanip.getNodeNoEx(n2p);
915 n2c = n2.getContent();
917 visible_faces[i] = 1;
922 visible_faces[2] = 1;
923 visible_faces[3] = 1;
924 visible_faces[4] = 1;
925 visible_faces[5] = 1;
927 for(i = 2; i < 6; i++) {
928 n2p = blockpos_nodes + p + dirs[i];
929 n2 = data->m_vmanip.getNodeNoEx(n2p);
930 n2c = n2.getContent();
932 visible_faces[i] = 1;
936 static const u8 nb_triplet[12*3] = {
937 1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
938 2,0,11, 2,3,13, 5,0,10, 5,3,12,
939 0,1, 8, 0,4,16, 3,4,17, 3,1, 9
942 f32 tx1, ty1, tz1, tx2, ty2, tz2;
945 for(i = 0; i < 12; i++)
948 if (nb[nb_triplet[i*3+2]])
949 edge_invisible = nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
951 edge_invisible = nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
954 box = frame_edges[i];
957 tx1 = (box.MinEdge.X / BS) + 0.5;
958 ty1 = (box.MinEdge.Y / BS) + 0.5;
959 tz1 = (box.MinEdge.Z / BS) + 0.5;
960 tx2 = (box.MaxEdge.X / BS) + 0.5;
961 ty2 = (box.MaxEdge.Y / BS) + 0.5;
962 tz2 = (box.MaxEdge.Z / BS) + 0.5;
964 tx1, 1-tz2, tx2, 1-tz1,
966 tz1, 1-ty2, tz2, 1-ty1,
967 1-tz2, 1-ty2, 1-tz1, 1-ty1,
968 1-tx2, 1-ty2, 1-tx1, 1-ty1,
969 tx1, 1-ty2, tx2, 1-ty1,
971 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
974 for(i = 0; i < 6; i++)
976 if (!visible_faces[i])
978 box = glass_faces[i];
981 tx1 = (box.MinEdge.X / BS) + 0.5;
982 ty1 = (box.MinEdge.Y / BS) + 0.5;
983 tz1 = (box.MinEdge.Z / BS) + 0.5;
984 tx2 = (box.MaxEdge.X / BS) + 0.5;
985 ty2 = (box.MaxEdge.Y / BS) + 0.5;
986 tz2 = (box.MaxEdge.Z / BS) + 0.5;
988 tx1, 1-tz2, tx2, 1-tz1,
990 tz1, 1-ty2, tz2, 1-ty1,
991 1-tz2, 1-ty2, 1-tz1, 1-ty1,
992 1-tx2, 1-ty2, 1-tx1, 1-ty1,
993 tx1, 1-ty2, tx2, 1-ty1,
995 makeCuboid(&collector, box, &glass_tiles[i], 1, c, txc2);
998 if (param2 > 0 && f.special_tiles[0].texture) {
999 // Interior volume level is in range 0 .. 63,
1000 // convert it to -0.5 .. 0.5
1001 float vlev = (((float)param2 / 63.0 ) * 2.0 - 1.0);
1002 TileSpec interior_tiles[6];
1003 for (i = 0; i < 6; i++)
1004 interior_tiles[i] = f.special_tiles[0];
1005 float offset = 0.003;
1006 box = aabb3f(visible_faces[3] ? -b : -a + offset,
1007 visible_faces[1] ? -b : -a + offset,
1008 visible_faces[5] ? -b : -a + offset,
1009 visible_faces[2] ? b : a - offset,
1010 visible_faces[0] ? b * vlev : a * vlev - offset,
1011 visible_faces[4] ? b : a - offset);
1014 tx1 = (box.MinEdge.X / BS) + 0.5;
1015 ty1 = (box.MinEdge.Y / BS) + 0.5;
1016 tz1 = (box.MinEdge.Z / BS) + 0.5;
1017 tx2 = (box.MaxEdge.X / BS) + 0.5;
1018 ty2 = (box.MaxEdge.Y / BS) + 0.5;
1019 tz2 = (box.MaxEdge.Z / BS) + 0.5;
1021 tx1, 1-tz2, tx2, 1-tz1,
1023 tz1, 1-ty2, tz2, 1-ty1,
1024 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1025 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1026 tx1, 1-ty2, tx2, 1-ty1,
1028 makeCuboid(&collector, box, interior_tiles, 6, c, txc3);
1033 TileSpec tile_leaves = getNodeTile(n, p,
1034 v3s16(0,0,0), data);
1036 u16 l = getInteriorLight(n, 1, nodedef);
1037 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1039 v3f pos = intToFloat(p, BS);
1040 aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
1043 makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
1045 case NDT_ALLFACES_OPTIONAL:
1046 // This is always pre-converted to something else
1051 v3s16 dir = n.getWallMountedDir(nodedef);
1054 if(dir == v3s16(0,-1,0)){
1055 tileindex = 0; // floor
1056 } else if(dir == v3s16(0,1,0)){
1057 tileindex = 1; // ceiling
1058 // For backwards compatibility
1059 } else if(dir == v3s16(0,0,0)){
1060 tileindex = 0; // floor
1062 tileindex = 2; // side
1065 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1066 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1067 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1069 u16 l = getInteriorLight(n, 1, nodedef);
1070 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1072 float s = BS/2*f.visual_scale;
1073 // Wall at X+ of node
1074 video::S3DVertex vertices[4] =
1076 video::S3DVertex(-s,-s,0, 0,0,0, c, 0,1),
1077 video::S3DVertex( s,-s,0, 0,0,0, c, 1,1),
1078 video::S3DVertex( s, s,0, 0,0,0, c, 1,0),
1079 video::S3DVertex(-s, s,0, 0,0,0, c, 0,0),
1082 for(s32 i=0; i<4; i++)
1084 if(dir == v3s16(1,0,0))
1085 vertices[i].Pos.rotateXZBy(0);
1086 if(dir == v3s16(-1,0,0))
1087 vertices[i].Pos.rotateXZBy(180);
1088 if(dir == v3s16(0,0,1))
1089 vertices[i].Pos.rotateXZBy(90);
1090 if(dir == v3s16(0,0,-1))
1091 vertices[i].Pos.rotateXZBy(-90);
1092 if(dir == v3s16(0,-1,0))
1093 vertices[i].Pos.rotateXZBy(45);
1094 if(dir == v3s16(0,1,0))
1095 vertices[i].Pos.rotateXZBy(-45);
1097 vertices[i].Pos += intToFloat(p, BS);
1100 u16 indices[] = {0,1,2,2,3,0};
1101 // Add to mesh collector
1102 collector.append(tile, vertices, 4, indices, 6);
1106 TileSpec tile = getNodeTileN(n, p, 0, data);
1107 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1108 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1110 u16 l = getInteriorLight(n, 0, nodedef);
1111 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1113 float d = (float)BS/16;
1114 float s = BS/2*f.visual_scale;
1115 // Wall at X+ of node
1116 video::S3DVertex vertices[4] =
1118 video::S3DVertex(BS/2-d, s, s, 0,0,0, c, 0,0),
1119 video::S3DVertex(BS/2-d, s, -s, 0,0,0, c, 1,0),
1120 video::S3DVertex(BS/2-d, -s, -s, 0,0,0, c, 1,1),
1121 video::S3DVertex(BS/2-d, -s, s, 0,0,0, c, 0,1),
1124 v3s16 dir = n.getWallMountedDir(nodedef);
1126 for(s32 i=0; i<4; i++)
1128 if(dir == v3s16(1,0,0))
1129 vertices[i].Pos.rotateXZBy(0);
1130 if(dir == v3s16(-1,0,0))
1131 vertices[i].Pos.rotateXZBy(180);
1132 if(dir == v3s16(0,0,1))
1133 vertices[i].Pos.rotateXZBy(90);
1134 if(dir == v3s16(0,0,-1))
1135 vertices[i].Pos.rotateXZBy(-90);
1136 if(dir == v3s16(0,-1,0))
1137 vertices[i].Pos.rotateXYBy(-90);
1138 if(dir == v3s16(0,1,0))
1139 vertices[i].Pos.rotateXYBy(90);
1141 vertices[i].Pos += intToFloat(p, BS);
1144 u16 indices[] = {0,1,2,2,3,0};
1145 // Add to mesh collector
1146 collector.append(tile, vertices, 4, indices, 6);
1150 TileSpec tile = getNodeTileN(n, p, 0, data);
1151 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1153 u16 l = getInteriorLight(n, 1, nodedef);
1154 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1156 float s = BS/2*f.visual_scale;
1158 for(u32 j=0; j<2; j++)
1160 video::S3DVertex vertices[4] =
1162 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1163 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1164 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1165 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1170 for(u16 i=0; i<4; i++)
1171 vertices[i].Pos.rotateXZBy(46 + n.param2 * 2);
1175 for(u16 i=0; i<4; i++)
1176 vertices[i].Pos.rotateXZBy(-44 + n.param2 * 2);
1179 for(u16 i=0; i<4; i++)
1181 vertices[i].Pos *= f.visual_scale;
1182 vertices[i].Pos += intToFloat(p, BS);
1185 u16 indices[] = {0,1,2,2,3,0};
1186 // Add to mesh collector
1187 collector.append(tile, vertices, 4, indices, 6);
1192 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1193 TileSpec tile_nocrack = tile;
1194 tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1196 // Put wood the right way around in the posts
1197 TileSpec tile_rot = tile;
1198 tile_rot.rotation = 1;
1200 u16 l = getInteriorLight(n, 1, nodedef);
1201 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1203 const f32 post_rad=(f32)BS/8;
1204 const f32 bar_rad=(f32)BS/16;
1205 const f32 bar_len=(f32)(BS/2)-post_rad;
1207 v3f pos = intToFloat(p, BS);
1209 // The post - always present
1210 aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
1211 post.MinEdge += pos;
1212 post.MaxEdge += pos;
1214 6/16.,6/16.,10/16.,10/16.,
1215 6/16.,6/16.,10/16.,10/16.,
1220 makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1222 // Now a section of fence, +X, if there's a post there
1225 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1226 const ContentFeatures *f2 = &nodedef->get(n2);
1227 if(f2->drawtype == NDT_FENCELIKE)
1229 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1230 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1234 0/16.,2/16.,16/16.,4/16.,
1235 0/16.,4/16.,16/16.,6/16.,
1236 6/16.,6/16.,8/16.,8/16.,
1237 10/16.,10/16.,12/16.,12/16.,
1238 0/16.,8/16.,16/16.,10/16.,
1239 0/16.,14/16.,16/16.,16/16.};
1240 makeCuboid(&collector, bar, &tile_nocrack, 1,
1242 bar.MinEdge.Y -= BS/2;
1243 bar.MaxEdge.Y -= BS/2;
1244 makeCuboid(&collector, bar, &tile_nocrack, 1,
1248 // Now a section of fence, +Z, if there's a post there
1251 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1252 f2 = &nodedef->get(n2);
1253 if(f2->drawtype == NDT_FENCELIKE)
1255 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1256 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1260 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
1261 4/16.,1/16.,6/16.,5/16., // for wood texture instead
1262 0/16.,9/16.,16/16.,11/16.,
1263 0/16.,6/16.,16/16.,8/16.,
1264 6/16.,6/16.,8/16.,8/16.,
1265 10/16.,10/16.,12/16.,12/16.};
1266 makeCuboid(&collector, bar, &tile_nocrack, 1,
1268 bar.MinEdge.Y -= BS/2;
1269 bar.MaxEdge.Y -= BS/2;
1270 makeCuboid(&collector, bar, &tile_nocrack, 1,
1276 bool is_rail_x [] = { false, false }; /* x-1, x+1 */
1277 bool is_rail_z [] = { false, false }; /* z-1, z+1 */
1279 bool is_rail_z_minus_y [] = { false, false }; /* z-1, z+1; y-1 */
1280 bool is_rail_x_minus_y [] = { false, false }; /* x-1, z+1; y-1 */
1281 bool is_rail_z_plus_y [] = { false, false }; /* z-1, z+1; y+1 */
1282 bool is_rail_x_plus_y [] = { false, false }; /* x-1, x+1; y+1 */
1284 MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
1285 MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
1286 MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
1287 MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
1288 MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
1289 MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
1290 MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
1291 MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
1292 MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
1293 MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
1294 MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
1295 MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
1297 content_t thiscontent = n.getContent();
1298 std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
1299 bool self_connect_to_raillike = ((ItemGroupList) nodedef->get(n).groups)[groupname] != 0;
1301 if ((nodedef->get(n_minus_x).drawtype == NDT_RAILLIKE
1302 && ((ItemGroupList) nodedef->get(n_minus_x).groups)[groupname] != 0
1303 && self_connect_to_raillike)
1304 || n_minus_x.getContent() == thiscontent)
1305 is_rail_x[0] = true;
1307 if ((nodedef->get(n_minus_x_minus_y).drawtype == NDT_RAILLIKE
1308 && ((ItemGroupList) nodedef->get(n_minus_x_minus_y).groups)[groupname] != 0
1309 && self_connect_to_raillike)
1310 || n_minus_x_minus_y.getContent() == thiscontent)
1311 is_rail_x_minus_y[0] = true;
1313 if ((nodedef->get(n_minus_x_plus_y).drawtype == NDT_RAILLIKE
1314 && ((ItemGroupList) nodedef->get(n_minus_x_plus_y).groups)[groupname] != 0
1315 && self_connect_to_raillike)
1316 || n_minus_x_plus_y.getContent() == thiscontent)
1317 is_rail_x_plus_y[0] = true;
1319 if ((nodedef->get(n_plus_x).drawtype == NDT_RAILLIKE
1320 && ((ItemGroupList) nodedef->get(n_plus_x).groups)[groupname] != 0
1321 && self_connect_to_raillike)
1322 || n_plus_x.getContent() == thiscontent)
1323 is_rail_x[1] = true;
1325 if ((nodedef->get(n_plus_x_minus_y).drawtype == NDT_RAILLIKE
1326 && ((ItemGroupList) nodedef->get(n_plus_x_minus_y).groups)[groupname] != 0
1327 && self_connect_to_raillike)
1328 || n_plus_x_minus_y.getContent() == thiscontent)
1329 is_rail_x_minus_y[1] = true;
1331 if ((nodedef->get(n_plus_x_plus_y).drawtype == NDT_RAILLIKE
1332 && ((ItemGroupList) nodedef->get(n_plus_x_plus_y).groups)[groupname] != 0
1333 && self_connect_to_raillike)
1334 || n_plus_x_plus_y.getContent() == thiscontent)
1335 is_rail_x_plus_y[1] = true;
1337 if ((nodedef->get(n_minus_z).drawtype == NDT_RAILLIKE
1338 && ((ItemGroupList) nodedef->get(n_minus_z).groups)[groupname] != 0
1339 && self_connect_to_raillike)
1340 || n_minus_z.getContent() == thiscontent)
1341 is_rail_z[0] = true;
1343 if ((nodedef->get(n_minus_z_minus_y).drawtype == NDT_RAILLIKE
1344 && ((ItemGroupList) nodedef->get(n_minus_z_minus_y).groups)[groupname] != 0
1345 && self_connect_to_raillike)
1346 || n_minus_z_minus_y.getContent() == thiscontent)
1347 is_rail_z_minus_y[0] = true;
1349 if ((nodedef->get(n_minus_z_plus_y).drawtype == NDT_RAILLIKE
1350 && ((ItemGroupList) nodedef->get(n_minus_z_plus_y).groups)[groupname] != 0
1351 && self_connect_to_raillike)
1352 || n_minus_z_plus_y.getContent() == thiscontent)
1353 is_rail_z_plus_y[0] = true;
1355 if ((nodedef->get(n_plus_z).drawtype == NDT_RAILLIKE
1356 && ((ItemGroupList) nodedef->get(n_plus_z).groups)[groupname] != 0
1357 && self_connect_to_raillike)
1358 || n_plus_z.getContent() == thiscontent)
1359 is_rail_z[1] = true;
1361 if ((nodedef->get(n_plus_z_minus_y).drawtype == NDT_RAILLIKE
1362 && ((ItemGroupList) nodedef->get(n_plus_z_minus_y).groups)[groupname] != 0
1363 && self_connect_to_raillike)
1364 || n_plus_z_minus_y.getContent() == thiscontent)
1365 is_rail_z_minus_y[1] = true;
1367 if ((nodedef->get(n_plus_z_plus_y).drawtype == NDT_RAILLIKE
1368 && ((ItemGroupList) nodedef->get(n_plus_z_plus_y).groups)[groupname] != 0
1369 && self_connect_to_raillike)
1370 || n_plus_z_plus_y.getContent() == thiscontent)
1371 is_rail_z_plus_y[1] = true;
1373 bool is_rail_x_all[] = {false, false};
1374 bool is_rail_z_all[] = {false, false};
1375 is_rail_x_all[0]=is_rail_x[0] || is_rail_x_minus_y[0] || is_rail_x_plus_y[0];
1376 is_rail_x_all[1]=is_rail_x[1] || is_rail_x_minus_y[1] || is_rail_x_plus_y[1];
1377 is_rail_z_all[0]=is_rail_z[0] || is_rail_z_minus_y[0] || is_rail_z_plus_y[0];
1378 is_rail_z_all[1]=is_rail_z[1] || is_rail_z_minus_y[1] || is_rail_z_plus_y[1];
1380 // reasonable default, flat straight unrotated rail
1381 bool is_straight = true;
1382 int adjacencies = 0;
1386 // check for sloped rail
1387 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])
1389 adjacencies = 5; //5 means sloped
1390 is_straight = true; // sloped is always straight
1394 // is really straight, rails on both sides
1395 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
1396 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
1399 switch (adjacencies) {
1401 if(is_rail_x_all[0] || is_rail_x_all[1])
1406 tileindex = 1; // curved
1407 if(is_rail_x_all[0] && is_rail_x_all[1])
1409 if(is_rail_z_all[0] && is_rail_z_all[1]){
1410 if (is_rail_z_plus_y[0])
1413 else if(is_rail_x_all[0] && is_rail_z_all[0])
1415 else if(is_rail_x_all[0] && is_rail_z_all[1])
1417 else if(is_rail_x_all[1] && is_rail_z_all[1])
1421 // here is where the potential to 'switch' a junction is, but not implemented at present
1422 tileindex = 2; // t-junction
1423 if(!is_rail_x_all[1])
1425 if(!is_rail_z_all[0])
1427 if(!is_rail_z_all[1])
1431 tileindex = 3; // crossing
1434 if(is_rail_z_plus_y[0])
1436 if(is_rail_x_plus_y[0])
1438 if(is_rail_x_plus_y[1])
1445 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1446 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1447 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1449 u16 l = getInteriorLight(n, 0, nodedef);
1450 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1452 float d = (float)BS/64;
1455 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])
1456 g=1; //Object is at a slope
1458 video::S3DVertex vertices[4] =
1460 video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c, 0,1),
1461 video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c, 1,1),
1462 video::S3DVertex(BS/2,g*BS/2+d,BS/2, 0,0,0, c, 1,0),
1463 video::S3DVertex(-BS/2,g*BS/2+d,BS/2, 0,0,0, c, 0,0),
1466 for(s32 i=0; i<4; i++)
1469 vertices[i].Pos.rotateXZBy(angle);
1470 vertices[i].Pos += intToFloat(p, BS);
1473 u16 indices[] = {0,1,2,2,3,0};
1474 collector.append(tile, vertices, 4, indices, 6);
1478 static const v3s16 tile_dirs[6] = {
1488 u16 l = getInteriorLight(n, 1, nodedef);
1489 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1491 v3f pos = intToFloat(p, BS);
1493 std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1494 for(std::vector<aabb3f>::iterator
1496 i != boxes.end(); i++)
1498 for(int j = 0; j < 6; j++)
1500 // Handles facedir rotation for textures
1501 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1508 if (box.MinEdge.X > box.MaxEdge.X)
1511 box.MinEdge.X=box.MaxEdge.X;
1514 if (box.MinEdge.Y > box.MaxEdge.Y)
1517 box.MinEdge.Y=box.MaxEdge.Y;
1520 if (box.MinEdge.Z > box.MaxEdge.Z)
1523 box.MinEdge.Z=box.MaxEdge.Z;
1528 // Compute texture coords
1529 f32 tx1 = (box.MinEdge.X/BS)+0.5;
1530 f32 ty1 = (box.MinEdge.Y/BS)+0.5;
1531 f32 tz1 = (box.MinEdge.Z/BS)+0.5;
1532 f32 tx2 = (box.MaxEdge.X/BS)+0.5;
1533 f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
1534 f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
1537 tx1, 1-tz2, tx2, 1-tz1,
1541 tz1, 1-ty2, tz2, 1-ty1,
1543 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1545 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1547 tx1, 1-ty2, tx2, 1-ty1,
1549 makeCuboid(&collector, box, tiles, 6, c, txc);