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();
174 //TimeTaker timer("mapblock_mesh_generate_special()");
179 bool new_style_water = g_settings->getBool("new_style_water");
181 float node_liquid_level = 1.0;
183 node_liquid_level = 0.85;
185 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
187 for(s16 z=0; z<MAP_BLOCKSIZE; z++)
188 for(s16 y=0; y<MAP_BLOCKSIZE; y++)
189 for(s16 x=0; x<MAP_BLOCKSIZE; x++)
193 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes+p);
194 const ContentFeatures &f = nodedef->get(n);
196 // Only solidness=0 stuff is drawn here
202 infostream<<"Got "<<f.drawtype<<std::endl;
210 Add water sources to mesh if using new style
212 TileSpec tile_liquid = f.special_tiles[0];
213 TileSpec tile_liquid_bfculled = getNodeTile(n, p, v3s16(0,0,0), data);
215 bool top_is_same_liquid = false;
216 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
217 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
218 content_t c_source = nodedef->getId(f.liquid_alternative_source);
219 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
220 top_is_same_liquid = true;
222 u16 l = getInteriorLight(n, 0, nodedef);
223 video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
228 v3s16 side_dirs[4] = {
234 for(u32 i=0; i<4; i++)
236 v3s16 dir = side_dirs[i];
238 MapNode neighbor = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir);
239 content_t neighbor_content = neighbor.getContent();
240 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
241 MapNode n_top = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir+ v3s16(0,1,0));
242 content_t n_top_c = n_top.getContent();
244 if(neighbor_content == CONTENT_IGNORE)
248 If our topside is liquid and neighbor's topside
249 is liquid, don't draw side face
251 if(top_is_same_liquid && (n_top_c == c_flowing ||
252 n_top_c == c_source || n_top_c == CONTENT_IGNORE))
255 // Don't draw face if neighbor is blocking the view
256 if(n_feat.solidness == 2)
259 bool neighbor_is_same_liquid = (neighbor_content == c_source
260 || neighbor_content == c_flowing);
262 // Don't draw any faces if neighbor same is liquid and top is
264 if(neighbor_is_same_liquid && !top_is_same_liquid)
267 // Use backface culled material if neighbor doesn't have a
269 const TileSpec *current_tile = &tile_liquid;
270 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
271 current_tile = &tile_liquid_bfculled;
273 video::S3DVertex vertices[4] =
275 video::S3DVertex(-BS/2,0,BS/2,0,0,0, c, 0,1),
276 video::S3DVertex(BS/2,0,BS/2,0,0,0, c, 1,1),
277 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
278 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
282 If our topside is liquid, set upper border of face
283 at upper border of node
285 if(top_is_same_liquid)
287 vertices[2].Pos.Y = 0.5*BS;
288 vertices[3].Pos.Y = 0.5*BS;
291 Otherwise upper position of face is liquid level
295 vertices[2].Pos.Y = (node_liquid_level-0.5)*BS;
296 vertices[3].Pos.Y = (node_liquid_level-0.5)*BS;
299 If neighbor is liquid, lower border of face is liquid level
301 if(neighbor_is_same_liquid)
303 vertices[0].Pos.Y = (node_liquid_level-0.5)*BS;
304 vertices[1].Pos.Y = (node_liquid_level-0.5)*BS;
307 If neighbor is not liquid, lower border of face is
312 vertices[0].Pos.Y = -0.5*BS;
313 vertices[1].Pos.Y = -0.5*BS;
316 for(s32 j=0; j<4; j++)
318 if(dir == v3s16(0,0,1))
319 vertices[j].Pos.rotateXZBy(0);
320 if(dir == v3s16(0,0,-1))
321 vertices[j].Pos.rotateXZBy(180);
322 if(dir == v3s16(-1,0,0))
323 vertices[j].Pos.rotateXZBy(90);
324 if(dir == v3s16(1,0,-0))
325 vertices[j].Pos.rotateXZBy(-90);
327 // Do this to not cause glitches when two liquids are
329 /*if(neighbor_is_same_liquid == false){
330 vertices[j].Pos.X *= 0.98;
331 vertices[j].Pos.Z *= 0.98;
334 vertices[j].Pos += intToFloat(p, BS);
337 u16 indices[] = {0,1,2,2,3,0};
338 // Add to mesh collector
339 collector.append(*current_tile, vertices, 4, indices, 6);
345 if(top_is_same_liquid)
348 video::S3DVertex vertices[4] =
350 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
351 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
352 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
353 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
356 v3f offset(p.X*BS, p.Y*BS + (-0.5+node_liquid_level)*BS, p.Z*BS);
357 for(s32 i=0; i<4; i++)
359 vertices[i].Pos += offset;
362 u16 indices[] = {0,1,2,2,3,0};
363 // Add to mesh collector
364 collector.append(tile_liquid, vertices, 4, indices, 6);
366 case NDT_FLOWINGLIQUID:
369 Add flowing liquid to mesh
371 TileSpec tile_liquid = f.special_tiles[0];
372 TileSpec tile_liquid_bfculled = f.special_tiles[1];
374 bool top_is_same_liquid = false;
375 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
376 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
377 content_t c_source = nodedef->getId(f.liquid_alternative_source);
378 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
379 top_is_same_liquid = true;
382 // If this liquid emits light and doesn't contain light, draw
383 // it at what it emits, for an increased effect
384 u8 light_source = nodedef->get(n).light_source;
385 if(light_source != 0){
386 //l = decode_light(undiminish_light(light_source));
387 l = decode_light(light_source);
390 // Use the light of the node on top if possible
391 else if(nodedef->get(ntop).param_type == CPT_LIGHT)
392 l = getInteriorLight(ntop, 0, nodedef);
393 // Otherwise use the light of this node (the liquid)
395 l = getInteriorLight(n, 0, nodedef);
396 video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
398 u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
400 // Neighbor liquid levels (key = relative position)
401 // Includes current node
402 std::map<v3s16, f32> neighbor_levels;
403 std::map<v3s16, content_t> neighbor_contents;
404 std::map<v3s16, u8> neighbor_flags;
405 const u8 neighborflag_top_is_same_liquid = 0x01;
406 v3s16 neighbor_dirs[9] = {
417 for(u32 i=0; i<9; i++)
419 content_t content = CONTENT_AIR;
420 float level = -0.5 * BS;
423 v3s16 p2 = p + neighbor_dirs[i];
424 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
425 if(n2.getContent() != CONTENT_IGNORE)
427 content = n2.getContent();
429 if(n2.getContent() == c_source)
430 level = (-0.5+node_liquid_level) * BS;
431 else if(n2.getContent() == c_flowing){
432 u8 liquid_level = (n2.param2&LIQUID_LEVEL_MASK);
433 if (liquid_level <= LIQUID_LEVEL_MAX+1-range)
436 liquid_level -= (LIQUID_LEVEL_MAX+1-range);
437 level = (-0.5 + ((float)liquid_level+ 0.5) / (float)range * node_liquid_level) * BS;
440 // Check node above neighbor.
441 // NOTE: This doesn't get executed if neighbor
444 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
445 if(n2.getContent() == c_source ||
446 n2.getContent() == c_flowing)
447 flags |= neighborflag_top_is_same_liquid;
450 neighbor_levels[neighbor_dirs[i]] = level;
451 neighbor_contents[neighbor_dirs[i]] = content;
452 neighbor_flags[neighbor_dirs[i]] = flags;
455 // Corner heights (average between four liquids)
456 f32 corner_levels[4];
458 v3s16 halfdirs[4] = {
464 for(u32 i=0; i<4; i++)
466 v3s16 cornerdir = halfdirs[i];
467 float cornerlevel = 0;
470 for(u32 j=0; j<4; j++)
472 v3s16 neighbordir = cornerdir - halfdirs[j];
473 content_t content = neighbor_contents[neighbordir];
474 // If top is liquid, draw starting from top of node
475 if(neighbor_flags[neighbordir] &
476 neighborflag_top_is_same_liquid)
478 cornerlevel = 0.5*BS;
482 // Source is always the same height
483 else if(content == c_source)
485 cornerlevel = (-0.5+node_liquid_level)*BS;
489 // Flowing liquid has level information
490 else if(content == c_flowing)
492 cornerlevel += neighbor_levels[neighbordir];
495 else if(content == CONTENT_AIR)
501 cornerlevel = -0.5*BS+0.2;
502 else if(valid_count > 0)
503 cornerlevel /= valid_count;
504 corner_levels[i] = cornerlevel;
511 v3s16 side_dirs[4] = {
517 s16 side_corners[4][2] = {
523 for(u32 i=0; i<4; i++)
525 v3s16 dir = side_dirs[i];
528 If our topside is liquid and neighbor's topside
529 is liquid, don't draw side face
531 if(top_is_same_liquid &&
532 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
535 content_t neighbor_content = neighbor_contents[dir];
536 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
538 // Don't draw face if neighbor is blocking the view
539 if(n_feat.solidness == 2)
542 bool neighbor_is_same_liquid = (neighbor_content == c_source
543 || neighbor_content == c_flowing);
545 // Don't draw any faces if neighbor same is liquid and top is
547 if(neighbor_is_same_liquid == true
548 && top_is_same_liquid == false)
551 // Use backface culled material if neighbor doesn't have a
553 const TileSpec *current_tile = &tile_liquid;
554 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
555 current_tile = &tile_liquid_bfculled;
557 video::S3DVertex vertices[4] =
559 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
560 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
561 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
562 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
566 If our topside is liquid, set upper border of face
567 at upper border of node
569 if(top_is_same_liquid)
571 vertices[2].Pos.Y = 0.5*BS;
572 vertices[3].Pos.Y = 0.5*BS;
575 Otherwise upper position of face is corner levels
579 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
580 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
584 If neighbor is liquid, lower border of face is corner
587 if(neighbor_is_same_liquid)
589 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
590 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
593 If neighbor is not liquid, lower border of face is
598 vertices[0].Pos.Y = -0.5*BS;
599 vertices[1].Pos.Y = -0.5*BS;
602 for(s32 j=0; j<4; j++)
604 if(dir == v3s16(0,0,1))
605 vertices[j].Pos.rotateXZBy(0);
606 if(dir == v3s16(0,0,-1))
607 vertices[j].Pos.rotateXZBy(180);
608 if(dir == v3s16(-1,0,0))
609 vertices[j].Pos.rotateXZBy(90);
610 if(dir == v3s16(1,0,-0))
611 vertices[j].Pos.rotateXZBy(-90);
613 // Do this to not cause glitches when two liquids are
615 /*if(neighbor_is_same_liquid == false){
616 vertices[j].Pos.X *= 0.98;
617 vertices[j].Pos.Z *= 0.98;
620 vertices[j].Pos += intToFloat(p, BS);
623 u16 indices[] = {0,1,2,2,3,0};
624 // Add to mesh collector
625 collector.append(*current_tile, vertices, 4, indices, 6);
629 Generate top side, if appropriate
632 if(top_is_same_liquid == false)
634 video::S3DVertex vertices[4] =
636 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
637 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
638 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
639 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
642 // To get backface culling right, the vertices need to go
643 // clockwise around the front of the face. And we happened to
644 // calculate corner levels in exact reverse order.
645 s32 corner_resolve[4] = {3,2,1,0};
647 for(s32 i=0; i<4; i++)
649 //vertices[i].Pos.Y += liquid_level;
650 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
651 s32 j = corner_resolve[i];
652 vertices[i].Pos.Y += corner_levels[j];
653 vertices[i].Pos += intToFloat(p, BS);
656 // Default downwards-flowing texture animation goes from
657 // -Z towards +Z, thus the direction is +Z.
658 // Rotate texture to make animation go in flow direction
659 // Positive if liquid moves towards +Z
660 f32 dz = (corner_levels[side_corners[3][0]] +
661 corner_levels[side_corners[3][1]]) -
662 (corner_levels[side_corners[2][0]] +
663 corner_levels[side_corners[2][1]]);
664 // Positive if liquid moves towards +X
665 f32 dx = (corner_levels[side_corners[1][0]] +
666 corner_levels[side_corners[1][1]]) -
667 (corner_levels[side_corners[0][0]] +
668 corner_levels[side_corners[0][1]]);
669 f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG ;
670 v2f tcoord_center(0.5, 0.5);
671 v2f tcoord_translate(
672 blockpos_nodes.Z + z,
673 blockpos_nodes.X + x);
674 tcoord_translate.rotateBy(tcoord_angle);
675 tcoord_translate.X -= floor(tcoord_translate.X);
676 tcoord_translate.Y -= floor(tcoord_translate.Y);
678 for(s32 i=0; i<4; i++)
680 vertices[i].TCoords.rotateBy(
683 vertices[i].TCoords += tcoord_translate;
686 v2f t = vertices[0].TCoords;
687 vertices[0].TCoords = vertices[2].TCoords;
688 vertices[2].TCoords = t;
690 u16 indices[] = {0,1,2,2,3,0};
691 // Add to mesh collector
692 collector.append(tile_liquid, vertices, 4, indices, 6);
697 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
699 u16 l = getInteriorLight(n, 1, nodedef);
700 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
702 for(u32 j=0; j<6; j++)
704 // Check this neighbor
705 v3s16 n2p = blockpos_nodes + p + g_6dirs[j];
706 MapNode n2 = data->m_vmanip.getNodeNoEx(n2p);
707 // Don't make face if neighbor is of same type
708 if(n2.getContent() == n.getContent())
712 video::S3DVertex vertices[4] = {
713 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c, 1,1),
714 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c, 0,1),
715 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c, 0,0),
716 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c, 1,0),
719 // Rotations in the g_6dirs format
721 for(u16 i=0; i<4; i++)
722 vertices[i].Pos.rotateXZBy(0);
723 else if(j == 1) // Y+
724 for(u16 i=0; i<4; i++)
725 vertices[i].Pos.rotateYZBy(-90);
726 else if(j == 2) // X+
727 for(u16 i=0; i<4; i++)
728 vertices[i].Pos.rotateXZBy(-90);
729 else if(j == 3) // Z-
730 for(u16 i=0; i<4; i++)
731 vertices[i].Pos.rotateXZBy(180);
732 else if(j == 4) // Y-
733 for(u16 i=0; i<4; i++)
734 vertices[i].Pos.rotateYZBy(90);
735 else if(j == 5) // X-
736 for(u16 i=0; i<4; i++)
737 vertices[i].Pos.rotateXZBy(90);
739 for(u16 i=0; i<4; i++){
740 vertices[i].Pos += intToFloat(p, BS);
743 u16 indices[] = {0,1,2,2,3,0};
744 // Add to mesh collector
745 collector.append(tile, vertices, 4, indices, 6);
748 case NDT_GLASSLIKE_FRAMED:
750 static const v3s16 dirs[6] = {
761 for (i = 0; i < 6; i++)
762 tiles[i] = getNodeTile(n, p, dirs[i], data);
764 TileSpec glass_tiles[6];
765 if (tiles[1].texture && tiles[2].texture && tiles[3].texture) {
766 glass_tiles[0] = tiles[2];
767 glass_tiles[1] = tiles[3];
768 glass_tiles[2] = tiles[1];
769 glass_tiles[3] = tiles[1];
770 glass_tiles[4] = tiles[1];
771 glass_tiles[5] = tiles[1];
773 for (i = 0; i < 6; i++)
774 glass_tiles[i] = tiles[1];
777 u8 param2 = n.getParam2();
778 bool H_merge = ! bool(param2 & 128);
779 bool V_merge = ! bool(param2 & 64);
780 param2 = param2 & 63;
782 u16 l = getInteriorLight(n, 1, nodedef);
783 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
784 v3f pos = intToFloat(p, BS);
785 static const float a = BS / 2;
786 static const float g = a - 0.003;
787 static const float b = .876 * ( BS / 2 );
789 static const aabb3f frame_edges[12] = {
790 aabb3f( b, b,-a, a, a, a), // y+
791 aabb3f(-a, b,-a,-b, a, a), // y+
792 aabb3f( b,-a,-a, a,-b, a), // y-
793 aabb3f(-a,-a,-a,-b,-b, a), // y-
794 aabb3f( b,-a, b, a, a, a), // x+
795 aabb3f( b,-a,-a, a, a,-b), // x+
796 aabb3f(-a,-a, b,-b, a, a), // x-
797 aabb3f(-a,-a,-a,-b, a,-b), // x-
798 aabb3f(-a, b, b, a, a, a), // z+
799 aabb3f(-a,-a, b, a,-b, a), // z+
800 aabb3f(-a,-a,-a, a,-b,-b), // z-
801 aabb3f(-a, b,-a, a, a,-b) // z-
803 static const aabb3f glass_faces[6] = {
804 aabb3f(-g, g,-g, g, g, g), // y+
805 aabb3f(-g,-g,-g, g,-g, g), // y-
806 aabb3f( g,-g,-g, g, g, g), // x+
807 aabb3f(-g,-g,-g,-g, g, g), // x-
808 aabb3f(-g,-g, g, g, g, g), // z+
809 aabb3f(-g,-g,-g, g, g,-g) // z-
812 // table of node visible faces, 0 = invisible
813 int visible_faces[6] = {0,0,0,0,0,0};
815 // table of neighbours, 1 = same type, checked with g_26dirs
816 int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
818 // g_26dirs to check when only horizontal merge is allowed
819 int nb_H_dirs[8] = {0,2,3,5,10,11,12,13};
821 content_t current = n.getContent();
826 // neighbours checks for frames visibility
828 if (!H_merge && V_merge) {
829 n2p = blockpos_nodes + p + g_26dirs[1];
830 n2 = data->m_vmanip.getNodeNoEx(n2p);
831 n2c = n2.getContent();
832 if (n2c == current || n2c == CONTENT_IGNORE)
834 n2p = blockpos_nodes + p + g_26dirs[4];
835 n2 = data->m_vmanip.getNodeNoEx(n2p);
836 n2c = n2.getContent();
837 if (n2c == current || n2c == CONTENT_IGNORE)
839 } else if (H_merge && !V_merge) {
840 for(i = 0; i < 8; i++) {
841 n2p = blockpos_nodes + p + g_26dirs[nb_H_dirs[i]];
842 n2 = data->m_vmanip.getNodeNoEx(n2p);
843 n2c = n2.getContent();
844 if (n2c == current || n2c == CONTENT_IGNORE)
845 nb[nb_H_dirs[i]] = 1;
847 } else if (H_merge && V_merge) {
848 for(i = 0; i < 18; i++) {
849 n2p = blockpos_nodes + p + g_26dirs[i];
850 n2 = data->m_vmanip.getNodeNoEx(n2p);
851 n2c = n2.getContent();
852 if (n2c == current || n2c == CONTENT_IGNORE)
857 // faces visibility checks
860 visible_faces[0] = 1;
861 visible_faces[1] = 1;
863 for(i = 0; i < 2; i++) {
864 n2p = blockpos_nodes + p + dirs[i];
865 n2 = data->m_vmanip.getNodeNoEx(n2p);
866 n2c = n2.getContent();
868 visible_faces[i] = 1;
873 visible_faces[2] = 1;
874 visible_faces[3] = 1;
875 visible_faces[4] = 1;
876 visible_faces[5] = 1;
878 for(i = 2; i < 6; i++) {
879 n2p = blockpos_nodes + p + dirs[i];
880 n2 = data->m_vmanip.getNodeNoEx(n2p);
881 n2c = n2.getContent();
883 visible_faces[i] = 1;
887 static const u8 nb_triplet[12*3] = {
888 1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
889 2,0,11, 2,3,13, 5,0,10, 5,3,12,
890 0,1, 8, 0,4,16, 3,4,17, 3,1, 9
893 f32 tx1, ty1, tz1, tx2, ty2, tz2;
896 for(i = 0; i < 12; i++)
899 if (nb[nb_triplet[i*3+2]])
900 edge_invisible = nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
902 edge_invisible = nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
905 box = frame_edges[i];
908 tx1 = (box.MinEdge.X / BS) + 0.5;
909 ty1 = (box.MinEdge.Y / BS) + 0.5;
910 tz1 = (box.MinEdge.Z / BS) + 0.5;
911 tx2 = (box.MaxEdge.X / BS) + 0.5;
912 ty2 = (box.MaxEdge.Y / BS) + 0.5;
913 tz2 = (box.MaxEdge.Z / BS) + 0.5;
915 tx1, 1-tz2, tx2, 1-tz1,
917 tz1, 1-ty2, tz2, 1-ty1,
918 1-tz2, 1-ty2, 1-tz1, 1-ty1,
919 1-tx2, 1-ty2, 1-tx1, 1-ty1,
920 tx1, 1-ty2, tx2, 1-ty1,
922 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
925 for(i = 0; i < 6; i++)
927 if (!visible_faces[i])
929 box = glass_faces[i];
932 tx1 = (box.MinEdge.X / BS) + 0.5;
933 ty1 = (box.MinEdge.Y / BS) + 0.5;
934 tz1 = (box.MinEdge.Z / BS) + 0.5;
935 tx2 = (box.MaxEdge.X / BS) + 0.5;
936 ty2 = (box.MaxEdge.Y / BS) + 0.5;
937 tz2 = (box.MaxEdge.Z / BS) + 0.5;
939 tx1, 1-tz2, tx2, 1-tz1,
941 tz1, 1-ty2, tz2, 1-ty1,
942 1-tz2, 1-ty2, 1-tz1, 1-ty1,
943 1-tx2, 1-ty2, 1-tx1, 1-ty1,
944 tx1, 1-ty2, tx2, 1-ty1,
946 makeCuboid(&collector, box, &glass_tiles[i], 1, c, txc2);
950 // Interior volume level is in range 0 .. 63,
951 // convert it to -0.5 .. 0.5
952 float vlev = (((float)param2 / 63.0 ) * 2.0 - 1.0);
953 TileSpec interior_tiles[6];
954 for (i = 0; i < 6; i++)
955 interior_tiles[i] = f.special_tiles[0];
956 float offset = 0.003;
957 box = aabb3f(visible_faces[3] ? -b : -a + offset,
958 visible_faces[1] ? -b : -a + offset,
959 visible_faces[5] ? -b : -a + offset,
960 visible_faces[2] ? b : a - offset,
961 visible_faces[0] ? b * vlev : a * vlev - offset,
962 visible_faces[4] ? b : a - offset);
965 tx1 = (box.MinEdge.X / BS) + 0.5;
966 ty1 = (box.MinEdge.Y / BS) + 0.5;
967 tz1 = (box.MinEdge.Z / BS) + 0.5;
968 tx2 = (box.MaxEdge.X / BS) + 0.5;
969 ty2 = (box.MaxEdge.Y / BS) + 0.5;
970 tz2 = (box.MaxEdge.Z / BS) + 0.5;
972 tx1, 1-tz2, tx2, 1-tz1,
974 tz1, 1-ty2, tz2, 1-ty1,
975 1-tz2, 1-ty2, 1-tz1, 1-ty1,
976 1-tx2, 1-ty2, 1-tx1, 1-ty1,
977 tx1, 1-ty2, tx2, 1-ty1,
979 makeCuboid(&collector, box, interior_tiles, 6, c, txc3);
984 TileSpec tile_leaves = getNodeTile(n, p,
987 u16 l = getInteriorLight(n, 1, nodedef);
988 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
990 v3f pos = intToFloat(p, BS);
991 aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
994 makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
996 case NDT_ALLFACES_OPTIONAL:
997 // This is always pre-converted to something else
1002 v3s16 dir = n.getWallMountedDir(nodedef);
1005 if(dir == v3s16(0,-1,0)){
1006 tileindex = 0; // floor
1007 } else if(dir == v3s16(0,1,0)){
1008 tileindex = 1; // ceiling
1009 // For backwards compatibility
1010 } else if(dir == v3s16(0,0,0)){
1011 tileindex = 0; // floor
1013 tileindex = 2; // side
1016 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1017 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1018 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1020 u16 l = getInteriorLight(n, 1, nodedef);
1021 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1023 float s = BS/2*f.visual_scale;
1024 // Wall at X+ of node
1025 video::S3DVertex vertices[4] =
1027 video::S3DVertex(-s,-s,0, 0,0,0, c, 0,1),
1028 video::S3DVertex( s,-s,0, 0,0,0, c, 1,1),
1029 video::S3DVertex( s, s,0, 0,0,0, c, 1,0),
1030 video::S3DVertex(-s, s,0, 0,0,0, c, 0,0),
1033 for(s32 i=0; i<4; i++)
1035 if(dir == v3s16(1,0,0))
1036 vertices[i].Pos.rotateXZBy(0);
1037 if(dir == v3s16(-1,0,0))
1038 vertices[i].Pos.rotateXZBy(180);
1039 if(dir == v3s16(0,0,1))
1040 vertices[i].Pos.rotateXZBy(90);
1041 if(dir == v3s16(0,0,-1))
1042 vertices[i].Pos.rotateXZBy(-90);
1043 if(dir == v3s16(0,-1,0))
1044 vertices[i].Pos.rotateXZBy(45);
1045 if(dir == v3s16(0,1,0))
1046 vertices[i].Pos.rotateXZBy(-45);
1048 vertices[i].Pos += intToFloat(p, BS);
1051 u16 indices[] = {0,1,2,2,3,0};
1052 // Add to mesh collector
1053 collector.append(tile, vertices, 4, indices, 6);
1057 TileSpec tile = getNodeTileN(n, p, 0, data);
1058 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1059 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1061 u16 l = getInteriorLight(n, 0, nodedef);
1062 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1064 float d = (float)BS/16;
1065 float s = BS/2*f.visual_scale;
1066 // Wall at X+ of node
1067 video::S3DVertex vertices[4] =
1069 video::S3DVertex(BS/2-d, s, s, 0,0,0, c, 0,0),
1070 video::S3DVertex(BS/2-d, s, -s, 0,0,0, c, 1,0),
1071 video::S3DVertex(BS/2-d, -s, -s, 0,0,0, c, 1,1),
1072 video::S3DVertex(BS/2-d, -s, s, 0,0,0, c, 0,1),
1075 v3s16 dir = n.getWallMountedDir(nodedef);
1077 for(s32 i=0; i<4; i++)
1079 if(dir == v3s16(1,0,0))
1080 vertices[i].Pos.rotateXZBy(0);
1081 if(dir == v3s16(-1,0,0))
1082 vertices[i].Pos.rotateXZBy(180);
1083 if(dir == v3s16(0,0,1))
1084 vertices[i].Pos.rotateXZBy(90);
1085 if(dir == v3s16(0,0,-1))
1086 vertices[i].Pos.rotateXZBy(-90);
1087 if(dir == v3s16(0,-1,0))
1088 vertices[i].Pos.rotateXYBy(-90);
1089 if(dir == v3s16(0,1,0))
1090 vertices[i].Pos.rotateXYBy(90);
1092 vertices[i].Pos += intToFloat(p, BS);
1095 u16 indices[] = {0,1,2,2,3,0};
1096 // Add to mesh collector
1097 collector.append(tile, vertices, 4, indices, 6);
1101 TileSpec tile = getNodeTileN(n, p, 0, data);
1102 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1104 u16 l = getInteriorLight(n, 1, nodedef);
1105 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1107 float s = BS/2*f.visual_scale;
1109 for(u32 j=0; j<2; j++)
1111 video::S3DVertex vertices[4] =
1113 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1114 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1115 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1116 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1121 for(u16 i=0; i<4; i++)
1122 vertices[i].Pos.rotateXZBy(46 + n.param2 * 2);
1126 for(u16 i=0; i<4; i++)
1127 vertices[i].Pos.rotateXZBy(-44 + n.param2 * 2);
1130 for(u16 i=0; i<4; i++)
1132 vertices[i].Pos *= f.visual_scale;
1133 vertices[i].Pos += intToFloat(p, BS);
1136 u16 indices[] = {0,1,2,2,3,0};
1137 // Add to mesh collector
1138 collector.append(tile, vertices, 4, indices, 6);
1143 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1144 TileSpec tile_nocrack = tile;
1145 tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1147 // Put wood the right way around in the posts
1148 TileSpec tile_rot = tile;
1149 tile_rot.rotation = 1;
1151 u16 l = getInteriorLight(n, 1, nodedef);
1152 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1154 const f32 post_rad=(f32)BS/8;
1155 const f32 bar_rad=(f32)BS/16;
1156 const f32 bar_len=(f32)(BS/2)-post_rad;
1158 v3f pos = intToFloat(p, BS);
1160 // The post - always present
1161 aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
1162 post.MinEdge += pos;
1163 post.MaxEdge += pos;
1165 6/16.,6/16.,10/16.,10/16.,
1166 6/16.,6/16.,10/16.,10/16.,
1171 makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1173 // Now a section of fence, +X, if there's a post there
1176 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1177 const ContentFeatures *f2 = &nodedef->get(n2);
1178 if(f2->drawtype == NDT_FENCELIKE)
1180 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1181 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1185 0/16.,2/16.,16/16.,4/16.,
1186 0/16.,4/16.,16/16.,6/16.,
1187 6/16.,6/16.,8/16.,8/16.,
1188 10/16.,10/16.,12/16.,12/16.,
1189 0/16.,8/16.,16/16.,10/16.,
1190 0/16.,14/16.,16/16.,16/16.};
1191 makeCuboid(&collector, bar, &tile_nocrack, 1,
1193 bar.MinEdge.Y -= BS/2;
1194 bar.MaxEdge.Y -= BS/2;
1195 makeCuboid(&collector, bar, &tile_nocrack, 1,
1199 // Now a section of fence, +Z, if there's a post there
1202 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1203 f2 = &nodedef->get(n2);
1204 if(f2->drawtype == NDT_FENCELIKE)
1206 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1207 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1211 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
1212 4/16.,1/16.,6/16.,5/16., // for wood texture instead
1213 0/16.,9/16.,16/16.,11/16.,
1214 0/16.,6/16.,16/16.,8/16.,
1215 6/16.,6/16.,8/16.,8/16.,
1216 10/16.,10/16.,12/16.,12/16.};
1217 makeCuboid(&collector, bar, &tile_nocrack, 1,
1219 bar.MinEdge.Y -= BS/2;
1220 bar.MaxEdge.Y -= BS/2;
1221 makeCuboid(&collector, bar, &tile_nocrack, 1,
1227 bool is_rail_x [] = { false, false }; /* x-1, x+1 */
1228 bool is_rail_z [] = { false, false }; /* z-1, z+1 */
1230 bool is_rail_z_minus_y [] = { false, false }; /* z-1, z+1; y-1 */
1231 bool is_rail_x_minus_y [] = { false, false }; /* x-1, z+1; y-1 */
1232 bool is_rail_z_plus_y [] = { false, false }; /* z-1, z+1; y+1 */
1233 bool is_rail_x_plus_y [] = { false, false }; /* x-1, x+1; y+1 */
1235 MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
1236 MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
1237 MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
1238 MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
1239 MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
1240 MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
1241 MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
1242 MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
1243 MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
1244 MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
1245 MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
1246 MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
1248 content_t thiscontent = n.getContent();
1249 std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
1250 bool self_connect_to_raillike = ((ItemGroupList) nodedef->get(n).groups)[groupname] != 0;
1252 if ((nodedef->get(n_minus_x).drawtype == NDT_RAILLIKE
1253 && ((ItemGroupList) nodedef->get(n_minus_x).groups)[groupname] != 0
1254 && self_connect_to_raillike)
1255 || n_minus_x.getContent() == thiscontent)
1256 is_rail_x[0] = true;
1258 if ((nodedef->get(n_minus_x_minus_y).drawtype == NDT_RAILLIKE
1259 && ((ItemGroupList) nodedef->get(n_minus_x_minus_y).groups)[groupname] != 0
1260 && self_connect_to_raillike)
1261 || n_minus_x_minus_y.getContent() == thiscontent)
1262 is_rail_x_minus_y[0] = true;
1264 if ((nodedef->get(n_minus_x_plus_y).drawtype == NDT_RAILLIKE
1265 && ((ItemGroupList) nodedef->get(n_minus_x_plus_y).groups)[groupname] != 0
1266 && self_connect_to_raillike)
1267 || n_minus_x_plus_y.getContent() == thiscontent)
1268 is_rail_x_plus_y[0] = true;
1270 if ((nodedef->get(n_plus_x).drawtype == NDT_RAILLIKE
1271 && ((ItemGroupList) nodedef->get(n_plus_x).groups)[groupname] != 0
1272 && self_connect_to_raillike)
1273 || n_plus_x.getContent() == thiscontent)
1274 is_rail_x[1] = true;
1276 if ((nodedef->get(n_plus_x_minus_y).drawtype == NDT_RAILLIKE
1277 && ((ItemGroupList) nodedef->get(n_plus_x_minus_y).groups)[groupname] != 0
1278 && self_connect_to_raillike)
1279 || n_plus_x_minus_y.getContent() == thiscontent)
1280 is_rail_x_minus_y[1] = true;
1282 if ((nodedef->get(n_plus_x_plus_y).drawtype == NDT_RAILLIKE
1283 && ((ItemGroupList) nodedef->get(n_plus_x_plus_y).groups)[groupname] != 0
1284 && self_connect_to_raillike)
1285 || n_plus_x_plus_y.getContent() == thiscontent)
1286 is_rail_x_plus_y[1] = true;
1288 if ((nodedef->get(n_minus_z).drawtype == NDT_RAILLIKE
1289 && ((ItemGroupList) nodedef->get(n_minus_z).groups)[groupname] != 0
1290 && self_connect_to_raillike)
1291 || n_minus_z.getContent() == thiscontent)
1292 is_rail_z[0] = true;
1294 if ((nodedef->get(n_minus_z_minus_y).drawtype == NDT_RAILLIKE
1295 && ((ItemGroupList) nodedef->get(n_minus_z_minus_y).groups)[groupname] != 0
1296 && self_connect_to_raillike)
1297 || n_minus_z_minus_y.getContent() == thiscontent)
1298 is_rail_z_minus_y[0] = true;
1300 if ((nodedef->get(n_minus_z_plus_y).drawtype == NDT_RAILLIKE
1301 && ((ItemGroupList) nodedef->get(n_minus_z_plus_y).groups)[groupname] != 0
1302 && self_connect_to_raillike)
1303 || n_minus_z_plus_y.getContent() == thiscontent)
1304 is_rail_z_plus_y[0] = true;
1306 if ((nodedef->get(n_plus_z).drawtype == NDT_RAILLIKE
1307 && ((ItemGroupList) nodedef->get(n_plus_z).groups)[groupname] != 0
1308 && self_connect_to_raillike)
1309 || n_plus_z.getContent() == thiscontent)
1310 is_rail_z[1] = true;
1312 if ((nodedef->get(n_plus_z_minus_y).drawtype == NDT_RAILLIKE
1313 && ((ItemGroupList) nodedef->get(n_plus_z_minus_y).groups)[groupname] != 0
1314 && self_connect_to_raillike)
1315 || n_plus_z_minus_y.getContent() == thiscontent)
1316 is_rail_z_minus_y[1] = true;
1318 if ((nodedef->get(n_plus_z_plus_y).drawtype == NDT_RAILLIKE
1319 && ((ItemGroupList) nodedef->get(n_plus_z_plus_y).groups)[groupname] != 0
1320 && self_connect_to_raillike)
1321 || n_plus_z_plus_y.getContent() == thiscontent)
1322 is_rail_z_plus_y[1] = true;
1324 bool is_rail_x_all[] = {false, false};
1325 bool is_rail_z_all[] = {false, false};
1326 is_rail_x_all[0]=is_rail_x[0] || is_rail_x_minus_y[0] || is_rail_x_plus_y[0];
1327 is_rail_x_all[1]=is_rail_x[1] || is_rail_x_minus_y[1] || is_rail_x_plus_y[1];
1328 is_rail_z_all[0]=is_rail_z[0] || is_rail_z_minus_y[0] || is_rail_z_plus_y[0];
1329 is_rail_z_all[1]=is_rail_z[1] || is_rail_z_minus_y[1] || is_rail_z_plus_y[1];
1331 // reasonable default, flat straight unrotated rail
1332 bool is_straight = true;
1333 int adjacencies = 0;
1337 // check for sloped rail
1338 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])
1340 adjacencies = 5; //5 means sloped
1341 is_straight = true; // sloped is always straight
1345 // is really straight, rails on both sides
1346 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
1347 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
1350 switch (adjacencies) {
1352 if(is_rail_x_all[0] || is_rail_x_all[1])
1357 tileindex = 1; // curved
1358 if(is_rail_x_all[0] && is_rail_x_all[1])
1360 if(is_rail_z_all[0] && is_rail_z_all[1]){
1361 if (is_rail_z_plus_y[0])
1364 else if(is_rail_x_all[0] && is_rail_z_all[0])
1366 else if(is_rail_x_all[0] && is_rail_z_all[1])
1368 else if(is_rail_x_all[1] && is_rail_z_all[1])
1372 // here is where the potential to 'switch' a junction is, but not implemented at present
1373 tileindex = 2; // t-junction
1374 if(!is_rail_x_all[1])
1376 if(!is_rail_z_all[0])
1378 if(!is_rail_z_all[1])
1382 tileindex = 3; // crossing
1385 if(is_rail_z_plus_y[0])
1387 if(is_rail_x_plus_y[0])
1389 if(is_rail_x_plus_y[1])
1396 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1397 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1398 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1400 u16 l = getInteriorLight(n, 0, nodedef);
1401 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1403 float d = (float)BS/64;
1406 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])
1407 g=1; //Object is at a slope
1409 video::S3DVertex vertices[4] =
1411 video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c, 0,1),
1412 video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c, 1,1),
1413 video::S3DVertex(BS/2,g*BS/2+d,BS/2, 0,0,0, c, 1,0),
1414 video::S3DVertex(-BS/2,g*BS/2+d,BS/2, 0,0,0, c, 0,0),
1417 for(s32 i=0; i<4; i++)
1420 vertices[i].Pos.rotateXZBy(angle);
1421 vertices[i].Pos += intToFloat(p, BS);
1424 u16 indices[] = {0,1,2,2,3,0};
1425 collector.append(tile, vertices, 4, indices, 6);
1429 static const v3s16 tile_dirs[6] = {
1439 u16 l = getInteriorLight(n, 0, nodedef);
1440 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1442 v3f pos = intToFloat(p, BS);
1444 std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1445 for(std::vector<aabb3f>::iterator
1447 i != boxes.end(); i++)
1449 for(int j = 0; j < 6; j++)
1451 // Handles facedir rotation for textures
1452 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1459 if (box.MinEdge.X > box.MaxEdge.X)
1462 box.MinEdge.X=box.MaxEdge.X;
1465 if (box.MinEdge.Y > box.MaxEdge.Y)
1468 box.MinEdge.Y=box.MaxEdge.Y;
1471 if (box.MinEdge.Z > box.MaxEdge.Z)
1474 box.MinEdge.Z=box.MaxEdge.Z;
1479 // Compute texture coords
1480 f32 tx1 = (box.MinEdge.X/BS)+0.5;
1481 f32 ty1 = (box.MinEdge.Y/BS)+0.5;
1482 f32 tz1 = (box.MinEdge.Z/BS)+0.5;
1483 f32 tx2 = (box.MaxEdge.X/BS)+0.5;
1484 f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
1485 f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
1488 tx1, 1-tz2, tx2, 1-tz1,
1492 tz1, 1-ty2, tz2, 1-ty1,
1494 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1496 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1498 tx1, 1-ty2, tx2, 1-ty1,
1500 makeCuboid(&collector, box, tiles, 6, c, txc);