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]),
103 for(int i = 0; i < tilecount; i++)
105 switch (tiles[i].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.rotateBy(90,irr::core::vector2df(0, 0));
125 tiles[i].texture.pos.Y += tiles[i].texture.size.Y;
126 tiles[i].texture.size.Y *= -1;
129 for (int x = 0; x < 4; x++)
130 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
131 t=vertices[i*4].TCoords;
132 tiles[i].texture.pos.Y += tiles[i].texture.size.Y;
133 tiles[i].texture.size.Y *= -1;
136 for (int x = 0; x < 4; x++)
137 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
138 tiles[i].texture.pos.X += tiles[i].texture.size.X;
139 tiles[i].texture.size.X *= -1;
142 for (int x = 0; x < 4; x++)
143 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
144 tiles[i].texture.pos.X += tiles[i].texture.size.X;
145 tiles[i].texture.size.X *= -1;
148 tiles[i].texture.pos.Y += tiles[i].texture.size.Y;
149 tiles[i].texture.size.Y *= -1;
152 tiles[i].texture.pos.X += tiles[i].texture.size.X;
153 tiles[i].texture.size.X *= -1;
159 for(s32 j=0; j<24; j++)
161 int tileindex = MYMIN(j/4, tilecount-1);
162 vertices[j].TCoords *= tiles[tileindex].texture.size;
163 vertices[j].TCoords += tiles[tileindex].texture.pos;
165 u16 indices[] = {0,1,2,2,3,0};
166 // Add to mesh collector
167 for(s32 j=0; j<24; j+=4)
169 int tileindex = MYMIN(j/4, tilecount-1);
170 collector->append(tiles[tileindex],
171 vertices+j, 4, indices, 6);
175 void mapblock_mesh_generate_special(MeshMakeData *data,
176 MeshCollector &collector)
178 INodeDefManager *nodedef = data->m_gamedef->ndef();
181 //TimeTaker timer("mapblock_mesh_generate_special()");
186 bool new_style_water = g_settings->getBool("new_style_water");
188 float node_liquid_level = 1.0;
190 node_liquid_level = 0.85;
192 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
194 for(s16 z=0; z<MAP_BLOCKSIZE; z++)
195 for(s16 y=0; y<MAP_BLOCKSIZE; y++)
196 for(s16 x=0; x<MAP_BLOCKSIZE; x++)
200 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes+p);
201 const ContentFeatures &f = nodedef->get(n);
203 // Only solidness=0 stuff is drawn here
209 infostream<<"Got "<<f.drawtype<<std::endl;
217 Add water sources to mesh if using new style
219 TileSpec tile_liquid = f.special_tiles[0];
220 TileSpec tile_liquid_bfculled = getNodeTile(n, p, v3s16(0,0,0), data);
221 AtlasPointer &pa_liquid = tile_liquid.texture;
223 bool top_is_same_liquid = false;
224 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
225 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
226 content_t c_source = nodedef->getId(f.liquid_alternative_source);
227 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
228 top_is_same_liquid = true;
230 u16 l = getInteriorLight(n, 0, data);
231 video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
236 v3s16 side_dirs[4] = {
242 for(u32 i=0; i<4; i++)
244 v3s16 dir = side_dirs[i];
246 MapNode neighbor = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir);
247 content_t neighbor_content = neighbor.getContent();
248 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
249 MapNode n_top = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir+ v3s16(0,1,0));
250 content_t n_top_c = n_top.getContent();
252 if(neighbor_content == CONTENT_IGNORE)
256 If our topside is liquid and neighbor's topside
257 is liquid, don't draw side face
259 if(top_is_same_liquid && (n_top_c == c_flowing ||
260 n_top_c == c_source || n_top_c == CONTENT_IGNORE))
263 // Don't draw face if neighbor is blocking the view
264 if(n_feat.solidness == 2)
267 bool neighbor_is_same_liquid = (neighbor_content == c_source
268 || neighbor_content == c_flowing);
270 // Don't draw any faces if neighbor same is liquid and top is
272 if(neighbor_is_same_liquid && !top_is_same_liquid)
275 // Use backface culled material if neighbor doesn't have a
277 const TileSpec *current_tile = &tile_liquid;
278 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
279 current_tile = &tile_liquid_bfculled;
281 video::S3DVertex vertices[4] =
283 video::S3DVertex(-BS/2,0,BS/2,0,0,0, c,
284 pa_liquid.x0(), pa_liquid.y1()),
285 video::S3DVertex(BS/2,0,BS/2,0,0,0, c,
286 pa_liquid.x1(), pa_liquid.y1()),
287 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
288 pa_liquid.x1(), pa_liquid.y0()),
289 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
290 pa_liquid.x0(), pa_liquid.y0()),
294 If our topside is liquid, set upper border of face
295 at upper border of node
297 if(top_is_same_liquid)
299 vertices[2].Pos.Y = 0.5*BS;
300 vertices[3].Pos.Y = 0.5*BS;
303 Otherwise upper position of face is liquid level
307 vertices[2].Pos.Y = (node_liquid_level-0.5)*BS;
308 vertices[3].Pos.Y = (node_liquid_level-0.5)*BS;
311 If neighbor is liquid, lower border of face is liquid level
313 if(neighbor_is_same_liquid)
315 vertices[0].Pos.Y = (node_liquid_level-0.5)*BS;
316 vertices[1].Pos.Y = (node_liquid_level-0.5)*BS;
319 If neighbor is not liquid, lower border of face is
324 vertices[0].Pos.Y = -0.5*BS;
325 vertices[1].Pos.Y = -0.5*BS;
328 for(s32 j=0; j<4; j++)
330 if(dir == v3s16(0,0,1))
331 vertices[j].Pos.rotateXZBy(0);
332 if(dir == v3s16(0,0,-1))
333 vertices[j].Pos.rotateXZBy(180);
334 if(dir == v3s16(-1,0,0))
335 vertices[j].Pos.rotateXZBy(90);
336 if(dir == v3s16(1,0,-0))
337 vertices[j].Pos.rotateXZBy(-90);
339 // Do this to not cause glitches when two liquids are
341 /*if(neighbor_is_same_liquid == false){
342 vertices[j].Pos.X *= 0.98;
343 vertices[j].Pos.Z *= 0.98;
346 vertices[j].Pos += intToFloat(p, BS);
349 u16 indices[] = {0,1,2,2,3,0};
350 // Add to mesh collector
351 collector.append(*current_tile, vertices, 4, indices, 6);
357 if(top_is_same_liquid)
360 video::S3DVertex vertices[4] =
362 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
363 pa_liquid.x0(), pa_liquid.y1()),
364 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
365 pa_liquid.x1(), pa_liquid.y1()),
366 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
367 pa_liquid.x1(), pa_liquid.y0()),
368 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
369 pa_liquid.x0(), pa_liquid.y0()),
372 v3f offset(p.X*BS, p.Y*BS + (-0.5+node_liquid_level)*BS, p.Z*BS);
373 for(s32 i=0; i<4; i++)
375 vertices[i].Pos += offset;
378 u16 indices[] = {0,1,2,2,3,0};
379 // Add to mesh collector
380 collector.append(tile_liquid, vertices, 4, indices, 6);
382 case NDT_FLOWINGLIQUID:
385 Add flowing liquid to mesh
387 TileSpec tile_liquid = f.special_tiles[0];
388 TileSpec tile_liquid_bfculled = f.special_tiles[1];
389 AtlasPointer &pa_liquid = tile_liquid.texture;
391 bool top_is_same_liquid = false;
392 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
393 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
394 content_t c_source = nodedef->getId(f.liquid_alternative_source);
395 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
396 top_is_same_liquid = true;
399 // If this liquid emits light and doesn't contain light, draw
400 // it at what it emits, for an increased effect
401 u8 light_source = nodedef->get(n).light_source;
402 if(light_source != 0){
403 //l = decode_light(undiminish_light(light_source));
404 l = decode_light(light_source);
407 // Use the light of the node on top if possible
408 else if(nodedef->get(ntop).param_type == CPT_LIGHT)
409 l = getInteriorLight(ntop, 0, data);
410 // Otherwise use the light of this node (the liquid)
412 l = getInteriorLight(n, 0, data);
413 video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
415 // Neighbor liquid levels (key = relative position)
416 // Includes current node
417 std::map<v3s16, f32> neighbor_levels;
418 std::map<v3s16, content_t> neighbor_contents;
419 std::map<v3s16, u8> neighbor_flags;
420 const u8 neighborflag_top_is_same_liquid = 0x01;
421 v3s16 neighbor_dirs[9] = {
432 for(u32 i=0; i<9; i++)
434 content_t content = CONTENT_AIR;
435 float level = -0.5 * BS;
438 v3s16 p2 = p + neighbor_dirs[i];
439 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
440 if(n2.getContent() != CONTENT_IGNORE)
442 content = n2.getContent();
444 if(n2.getContent() == c_source)
445 level = (-0.5+node_liquid_level) * BS;
446 else if(n2.getContent() == c_flowing)
447 level = (-0.5 + ((float)(n2.param2&LIQUID_LEVEL_MASK)
448 + 0.5) / (float)LIQUID_LEVEL_SOURCE * node_liquid_level) * BS;
450 // Check node above neighbor.
451 // NOTE: This doesn't get executed if neighbor
454 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
455 if(n2.getContent() == c_source ||
456 n2.getContent() == c_flowing)
457 flags |= neighborflag_top_is_same_liquid;
460 neighbor_levels[neighbor_dirs[i]] = level;
461 neighbor_contents[neighbor_dirs[i]] = content;
462 neighbor_flags[neighbor_dirs[i]] = flags;
465 // Corner heights (average between four liquids)
466 f32 corner_levels[4];
468 v3s16 halfdirs[4] = {
474 for(u32 i=0; i<4; i++)
476 v3s16 cornerdir = halfdirs[i];
477 float cornerlevel = 0;
480 for(u32 j=0; j<4; j++)
482 v3s16 neighbordir = cornerdir - halfdirs[j];
483 content_t content = neighbor_contents[neighbordir];
484 // If top is liquid, draw starting from top of node
485 if(neighbor_flags[neighbordir] &
486 neighborflag_top_is_same_liquid)
488 cornerlevel = 0.5*BS;
492 // Source is always the same height
493 else if(content == c_source)
495 cornerlevel = (-0.5+node_liquid_level)*BS;
499 // Flowing liquid has level information
500 else if(content == c_flowing)
502 cornerlevel += neighbor_levels[neighbordir];
505 else if(content == CONTENT_AIR)
511 cornerlevel = -0.5*BS+0.2;
512 else if(valid_count > 0)
513 cornerlevel /= valid_count;
514 corner_levels[i] = cornerlevel;
521 v3s16 side_dirs[4] = {
527 s16 side_corners[4][2] = {
533 for(u32 i=0; i<4; i++)
535 v3s16 dir = side_dirs[i];
538 If our topside is liquid and neighbor's topside
539 is liquid, don't draw side face
541 if(top_is_same_liquid &&
542 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
545 content_t neighbor_content = neighbor_contents[dir];
546 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
548 // Don't draw face if neighbor is blocking the view
549 if(n_feat.solidness == 2)
552 bool neighbor_is_same_liquid = (neighbor_content == c_source
553 || neighbor_content == c_flowing);
555 // Don't draw any faces if neighbor same is liquid and top is
557 if(neighbor_is_same_liquid == true
558 && top_is_same_liquid == false)
561 // Use backface culled material if neighbor doesn't have a
563 const TileSpec *current_tile = &tile_liquid;
564 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
565 current_tile = &tile_liquid_bfculled;
567 video::S3DVertex vertices[4] =
569 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
570 pa_liquid.x0(), pa_liquid.y1()),
571 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
572 pa_liquid.x1(), pa_liquid.y1()),
573 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
574 pa_liquid.x1(), pa_liquid.y0()),
575 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
576 pa_liquid.x0(), pa_liquid.y0()),
580 If our topside is liquid, set upper border of face
581 at upper border of node
583 if(top_is_same_liquid)
585 vertices[2].Pos.Y = 0.5*BS;
586 vertices[3].Pos.Y = 0.5*BS;
589 Otherwise upper position of face is corner levels
593 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
594 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
598 If neighbor is liquid, lower border of face is corner
601 if(neighbor_is_same_liquid)
603 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
604 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
607 If neighbor is not liquid, lower border of face is
612 vertices[0].Pos.Y = -0.5*BS;
613 vertices[1].Pos.Y = -0.5*BS;
616 for(s32 j=0; j<4; j++)
618 if(dir == v3s16(0,0,1))
619 vertices[j].Pos.rotateXZBy(0);
620 if(dir == v3s16(0,0,-1))
621 vertices[j].Pos.rotateXZBy(180);
622 if(dir == v3s16(-1,0,0))
623 vertices[j].Pos.rotateXZBy(90);
624 if(dir == v3s16(1,0,-0))
625 vertices[j].Pos.rotateXZBy(-90);
627 // Do this to not cause glitches when two liquids are
629 /*if(neighbor_is_same_liquid == false){
630 vertices[j].Pos.X *= 0.98;
631 vertices[j].Pos.Z *= 0.98;
634 vertices[j].Pos += intToFloat(p, BS);
637 u16 indices[] = {0,1,2,2,3,0};
638 // Add to mesh collector
639 collector.append(*current_tile, vertices, 4, indices, 6);
643 Generate top side, if appropriate
646 if(top_is_same_liquid == false)
648 video::S3DVertex vertices[4] =
650 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
651 pa_liquid.x0(), pa_liquid.y1()),
652 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
653 pa_liquid.x1(), pa_liquid.y1()),
654 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
655 pa_liquid.x1(), pa_liquid.y0()),
656 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
657 pa_liquid.x0(), pa_liquid.y0()),
660 // To get backface culling right, the vertices need to go
661 // clockwise around the front of the face. And we happened to
662 // calculate corner levels in exact reverse order.
663 s32 corner_resolve[4] = {3,2,1,0};
665 for(s32 i=0; i<4; i++)
667 //vertices[i].Pos.Y += liquid_level;
668 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
669 s32 j = corner_resolve[i];
670 vertices[i].Pos.Y += corner_levels[j];
671 vertices[i].Pos += intToFloat(p, BS);
674 // Default downwards-flowing texture animation goes from
675 // -Z towards +Z, thus the direction is +Z.
676 // Rotate texture to make animation go in flow direction
677 // Positive if liquid moves towards +Z
678 int dz = (corner_levels[side_corners[3][0]] +
679 corner_levels[side_corners[3][1]]) -
680 (corner_levels[side_corners[2][0]] +
681 corner_levels[side_corners[2][1]]);
682 // Positive if liquid moves towards +X
683 int dx = (corner_levels[side_corners[1][0]] +
684 corner_levels[side_corners[1][1]]) -
685 (corner_levels[side_corners[0][0]] +
686 corner_levels[side_corners[0][1]]);
690 v2f t = vertices[0].TCoords;
691 vertices[0].TCoords = vertices[1].TCoords;
692 vertices[1].TCoords = vertices[2].TCoords;
693 vertices[2].TCoords = vertices[3].TCoords;
694 vertices[3].TCoords = t;
699 v2f t = vertices[0].TCoords;
700 vertices[0].TCoords = vertices[3].TCoords;
701 vertices[3].TCoords = vertices[2].TCoords;
702 vertices[2].TCoords = vertices[1].TCoords;
703 vertices[1].TCoords = t;
708 v2f t = vertices[0].TCoords;
709 vertices[0].TCoords = vertices[3].TCoords;
710 vertices[3].TCoords = vertices[2].TCoords;
711 vertices[2].TCoords = vertices[1].TCoords;
712 vertices[1].TCoords = t;
713 t = vertices[0].TCoords;
714 vertices[0].TCoords = vertices[3].TCoords;
715 vertices[3].TCoords = vertices[2].TCoords;
716 vertices[2].TCoords = vertices[1].TCoords;
717 vertices[1].TCoords = t;
720 u16 indices[] = {0,1,2,2,3,0};
721 // Add to mesh collector
722 collector.append(tile_liquid, vertices, 4, indices, 6);
727 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
728 AtlasPointer ap = tile.texture;
730 u16 l = getInteriorLight(n, 1, data);
731 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
733 for(u32 j=0; j<6; j++)
735 // Check this neighbor
736 v3s16 n2p = blockpos_nodes + p + g_6dirs[j];
737 MapNode n2 = data->m_vmanip.getNodeNoEx(n2p);
738 // Don't make face if neighbor is of same type
739 if(n2.getContent() == n.getContent())
743 video::S3DVertex vertices[4] = {
744 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
746 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
748 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
750 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
754 // Rotations in the g_6dirs format
756 for(u16 i=0; i<4; i++)
757 vertices[i].Pos.rotateXZBy(0);
758 else if(j == 1) // Y+
759 for(u16 i=0; i<4; i++)
760 vertices[i].Pos.rotateYZBy(-90);
761 else if(j == 2) // X+
762 for(u16 i=0; i<4; i++)
763 vertices[i].Pos.rotateXZBy(-90);
764 else if(j == 3) // Z-
765 for(u16 i=0; i<4; i++)
766 vertices[i].Pos.rotateXZBy(180);
767 else if(j == 4) // Y-
768 for(u16 i=0; i<4; i++)
769 vertices[i].Pos.rotateYZBy(90);
770 else if(j == 5) // X-
771 for(u16 i=0; i<4; i++)
772 vertices[i].Pos.rotateXZBy(90);
774 for(u16 i=0; i<4; i++){
775 vertices[i].Pos += intToFloat(p, BS);
778 u16 indices[] = {0,1,2,2,3,0};
779 // Add to mesh collector
780 collector.append(tile, vertices, 4, indices, 6);
783 case NDT_GLASSLIKE_FRAMED:
785 static const v3s16 dirs[6] = {
794 tiles[0] = getNodeTile(n, p, dirs[0], data);
795 tiles[1] = getNodeTile(n, p, dirs[1], data);
796 u16 l = getInteriorLight(n, 1, data);
797 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
798 v3f pos = intToFloat(p, BS);
799 static const float a=BS/2;
800 static const float b=.876*(BS/2);
801 static const aabb3f frame_edges[12] = {
802 aabb3f( b, b,-a, a, a, a), // y+
803 aabb3f(-a, b,-a,-b, a, a), // y+
804 aabb3f( b,-a,-a, a,-b, a), // y-
805 aabb3f(-a,-a,-a,-b,-b, a), // y-
806 aabb3f( b,-a, b, a, a, a), // x+
807 aabb3f( b,-a,-a, a, a,-b), // x+
808 aabb3f(-a,-a, b,-b, a, a), // x-
809 aabb3f(-a,-a,-a,-b, a,-b), // x-
810 aabb3f(-a, b, b, a, a, a), // z+
811 aabb3f(-a,-a, b, a,-b, a), // z+
812 aabb3f(-a,-a,-a, a,-b,-b), // z-
813 aabb3f(-a, b,-a, a, a,-b) // z-
815 aabb3f glass_faces[6] = {
816 aabb3f(-a, a,-a, a, a, a), // y+
817 aabb3f(-a,-a,-a, a,-a, a), // y-
818 aabb3f( a,-a,-a, a, a, a), // x+
819 aabb3f(-a,-a,-a,-a, a, a), // x-
820 aabb3f(-a,-a, a, a, a, a), // z+
821 aabb3f(-a,-a,-a, a, a,-a) // z-
824 int visible_faces[6] = {0,0,0,0,0,0};
825 int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
827 content_t current = n.getContent();
833 n2p = blockpos_nodes + p + g_26dirs[i];
834 n2 = data->m_vmanip.getNodeNoEx(n2p);
835 content_t n2c = n2.getContent();
836 //TODO: remove CONTENT_IGNORE check when getNodeNoEx is fixed
837 if (n2c == current || n2c == CONTENT_IGNORE)
842 n2p = blockpos_nodes + p + dirs[i];
843 n2 = data->m_vmanip.getNodeNoEx(n2p);
844 content = n2.getContent();
845 const ContentFeatures &f2 = nodedef->get(content);
846 if (content == CONTENT_AIR || f2.isLiquid())
849 static const u8 nb_triplet[12*3] = {
850 1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
851 2,0,11, 2,3,13, 5,0,10, 5,3,12,
852 0,1, 8, 0,4,16, 3,4,17, 3,1, 9
855 f32 tx1,ty1,tz1,tx2,ty2,tz2;
860 if (nb[nb_triplet[i*3+2]]==1)
861 edge_invisible=nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
863 edge_invisible=nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
869 tx1 = (box.MinEdge.X/BS)+0.5;
870 ty1 = (box.MinEdge.Y/BS)+0.5;
871 tz1 = (box.MinEdge.Z/BS)+0.5;
872 tx2 = (box.MaxEdge.X/BS)+0.5;
873 ty2 = (box.MaxEdge.Y/BS)+0.5;
874 tz2 = (box.MaxEdge.Z/BS)+0.5;
876 tx1, 1-tz2, tx2, 1-tz1,
878 tz1, 1-ty2, tz2, 1-ty1,
879 1-tz2, 1-ty2, 1-tz1, 1-ty1,
880 1-tx2, 1-ty2, 1-tx1, 1-ty1,
881 tx1, 1-ty2, tx2, 1-ty1,
883 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
887 if (visible_faces[i]==0)
892 tx1 = (box.MinEdge.X/BS)+0.5;
893 ty1 = (box.MinEdge.Y/BS)+0.5;
894 tz1 = (box.MinEdge.Z/BS)+0.5;
895 tx2 = (box.MaxEdge.X/BS)+0.5;
896 ty2 = (box.MaxEdge.Y/BS)+0.5;
897 tz2 = (box.MaxEdge.Z/BS)+0.5;
899 tx1, 1-tz2, tx2, 1-tz1,
901 tz1, 1-ty2, tz2, 1-ty1,
902 1-tz2, 1-ty2, 1-tz1, 1-ty1,
903 1-tx2, 1-ty2, 1-tx1, 1-ty1,
904 tx1, 1-ty2, tx2, 1-ty1,
906 makeCuboid(&collector, box, &tiles[1], 1, c, txc2);
911 TileSpec tile_leaves = getNodeTile(n, p,
913 AtlasPointer pa_leaves = tile_leaves.texture;
915 u16 l = getInteriorLight(n, 1, data);
916 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
918 v3f pos = intToFloat(p, BS);
919 aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
922 makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
924 case NDT_ALLFACES_OPTIONAL:
925 // This is always pre-converted to something else
930 v3s16 dir = n.getWallMountedDir(nodedef);
933 if(dir == v3s16(0,-1,0)){
934 tileindex = 0; // floor
935 } else if(dir == v3s16(0,1,0)){
936 tileindex = 1; // ceiling
937 // For backwards compatibility
938 } else if(dir == v3s16(0,0,0)){
939 tileindex = 0; // floor
941 tileindex = 2; // side
944 TileSpec tile = getNodeTileN(n, p, tileindex, data);
945 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
946 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
948 AtlasPointer ap = tile.texture;
950 u16 l = getInteriorLight(n, 1, data);
951 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
953 // Wall at X+ of node
954 video::S3DVertex vertices[4] =
956 video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c,
958 video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c,
960 video::S3DVertex(BS/2,BS/2,0, 0,0,0, c,
962 video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c,
966 for(s32 i=0; i<4; i++)
968 if(dir == v3s16(1,0,0))
969 vertices[i].Pos.rotateXZBy(0);
970 if(dir == v3s16(-1,0,0))
971 vertices[i].Pos.rotateXZBy(180);
972 if(dir == v3s16(0,0,1))
973 vertices[i].Pos.rotateXZBy(90);
974 if(dir == v3s16(0,0,-1))
975 vertices[i].Pos.rotateXZBy(-90);
976 if(dir == v3s16(0,-1,0))
977 vertices[i].Pos.rotateXZBy(45);
978 if(dir == v3s16(0,1,0))
979 vertices[i].Pos.rotateXZBy(-45);
981 vertices[i].Pos += intToFloat(p, BS);
984 u16 indices[] = {0,1,2,2,3,0};
985 // Add to mesh collector
986 collector.append(tile, vertices, 4, indices, 6);
990 TileSpec tile = getNodeTileN(n, p, 0, data);
991 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
992 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
993 AtlasPointer ap = tile.texture;
995 u16 l = getInteriorLight(n, 0, data);
996 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
998 float d = (float)BS/16;
999 // Wall at X+ of node
1000 video::S3DVertex vertices[4] =
1002 video::S3DVertex(BS/2-d,BS/2,BS/2, 0,0,0, c,
1004 video::S3DVertex(BS/2-d,BS/2,-BS/2, 0,0,0, c,
1006 video::S3DVertex(BS/2-d,-BS/2,-BS/2, 0,0,0, c,
1008 video::S3DVertex(BS/2-d,-BS/2,BS/2, 0,0,0, c,
1012 v3s16 dir = n.getWallMountedDir(nodedef);
1014 for(s32 i=0; i<4; i++)
1016 if(dir == v3s16(1,0,0))
1017 vertices[i].Pos.rotateXZBy(0);
1018 if(dir == v3s16(-1,0,0))
1019 vertices[i].Pos.rotateXZBy(180);
1020 if(dir == v3s16(0,0,1))
1021 vertices[i].Pos.rotateXZBy(90);
1022 if(dir == v3s16(0,0,-1))
1023 vertices[i].Pos.rotateXZBy(-90);
1024 if(dir == v3s16(0,-1,0))
1025 vertices[i].Pos.rotateXYBy(-90);
1026 if(dir == v3s16(0,1,0))
1027 vertices[i].Pos.rotateXYBy(90);
1029 vertices[i].Pos += intToFloat(p, BS);
1032 u16 indices[] = {0,1,2,2,3,0};
1033 // Add to mesh collector
1034 collector.append(tile, vertices, 4, indices, 6);
1038 TileSpec tile = getNodeTileN(n, p, 0, data);
1039 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1040 AtlasPointer ap = tile.texture;
1042 u16 l = getInteriorLight(n, 1, data);
1043 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1045 for(u32 j=0; j<2; j++)
1047 video::S3DVertex vertices[4] =
1049 video::S3DVertex(-BS/2*f.visual_scale,-BS/2,0, 0,0,0, c,
1051 video::S3DVertex( BS/2*f.visual_scale,-BS/2,0, 0,0,0, c,
1053 video::S3DVertex( BS/2*f.visual_scale,
1054 -BS/2 + f.visual_scale*BS,0, 0,0,0, c,
1056 video::S3DVertex(-BS/2*f.visual_scale,
1057 -BS/2 + f.visual_scale*BS,0, 0,0,0, c,
1063 for(u16 i=0; i<4; i++)
1064 vertices[i].Pos.rotateXZBy(45);
1068 for(u16 i=0; i<4; i++)
1069 vertices[i].Pos.rotateXZBy(-45);
1072 for(u16 i=0; i<4; i++)
1074 vertices[i].Pos *= f.visual_scale;
1075 vertices[i].Pos += intToFloat(p, BS);
1078 u16 indices[] = {0,1,2,2,3,0};
1079 // Add to mesh collector
1080 collector.append(tile, vertices, 4, indices, 6);
1085 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1086 TileSpec tile_nocrack = tile;
1087 tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1089 // A hack to put wood the right way around in the posts
1090 ITextureSource *tsrc = data->m_gamedef->tsrc();
1091 TileSpec tile_rot = tile;
1092 tile_rot.texture = tsrc->getTexture(tsrc->getTextureName(
1093 tile.texture.id) + "^[transformR90");
1095 u16 l = getInteriorLight(n, 1, data);
1096 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1098 const f32 post_rad=(f32)BS/8;
1099 const f32 bar_rad=(f32)BS/16;
1100 const f32 bar_len=(f32)(BS/2)-post_rad;
1102 v3f pos = intToFloat(p, BS);
1104 // The post - always present
1105 aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
1106 post.MinEdge += pos;
1107 post.MaxEdge += pos;
1109 6/16.,6/16.,10/16.,10/16.,
1110 6/16.,6/16.,10/16.,10/16.,
1115 makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1117 // Now a section of fence, +X, if there's a post there
1120 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1121 const ContentFeatures *f2 = &nodedef->get(n2);
1122 if(f2->drawtype == NDT_FENCELIKE)
1124 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1125 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1129 0/16.,2/16.,16/16.,4/16.,
1130 0/16.,4/16.,16/16.,6/16.,
1131 6/16.,6/16.,8/16.,8/16.,
1132 10/16.,10/16.,12/16.,12/16.,
1133 0/16.,8/16.,16/16.,10/16.,
1134 0/16.,14/16.,16/16.,16/16.};
1135 makeCuboid(&collector, bar, &tile_nocrack, 1,
1137 bar.MinEdge.Y -= BS/2;
1138 bar.MaxEdge.Y -= BS/2;
1139 makeCuboid(&collector, bar, &tile_nocrack, 1,
1143 // Now a section of fence, +Z, if there's a post there
1146 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1147 f2 = &nodedef->get(n2);
1148 if(f2->drawtype == NDT_FENCELIKE)
1150 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1151 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1155 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
1156 4/16.,1/16.,6/16.,5/16., // for wood texture instead
1157 0/16.,9/16.,16/16.,11/16.,
1158 0/16.,6/16.,16/16.,8/16.,
1159 6/16.,6/16.,8/16.,8/16.,
1160 10/16.,10/16.,12/16.,12/16.};
1161 makeCuboid(&collector, bar, &tile_nocrack, 1,
1163 bar.MinEdge.Y -= BS/2;
1164 bar.MaxEdge.Y -= BS/2;
1165 makeCuboid(&collector, bar, &tile_nocrack, 1,
1171 bool is_rail_x [] = { false, false }; /* x-1, x+1 */
1172 bool is_rail_z [] = { false, false }; /* z-1, z+1 */
1174 bool is_rail_z_minus_y [] = { false, false }; /* z-1, z+1; y-1 */
1175 bool is_rail_x_minus_y [] = { false, false }; /* x-1, z+1; y-1 */
1176 bool is_rail_z_plus_y [] = { false, false }; /* z-1, z+1; y+1 */
1177 bool is_rail_x_plus_y [] = { false, false }; /* x-1, x+1; y+1 */
1179 MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
1180 MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
1181 MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
1182 MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
1183 MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
1184 MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
1185 MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
1186 MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
1187 MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
1188 MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
1189 MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
1190 MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
1192 content_t thiscontent = n.getContent();
1193 std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
1194 bool self_connect_to_raillike = ((ItemGroupList) nodedef->get(n).groups)[groupname] != 0;
1196 if ((nodedef->get(n_minus_x).drawtype == NDT_RAILLIKE
1197 && ((ItemGroupList) nodedef->get(n_minus_x).groups)[groupname] != 0
1198 && self_connect_to_raillike)
1199 || n_minus_x.getContent() == thiscontent)
1200 is_rail_x[0] = true;
1202 if ((nodedef->get(n_minus_x_minus_y).drawtype == NDT_RAILLIKE
1203 && ((ItemGroupList) nodedef->get(n_minus_x_minus_y).groups)[groupname] != 0
1204 && self_connect_to_raillike)
1205 || n_minus_x_minus_y.getContent() == thiscontent)
1206 is_rail_x_minus_y[0] = true;
1208 if ((nodedef->get(n_minus_x_plus_y).drawtype == NDT_RAILLIKE
1209 && ((ItemGroupList) nodedef->get(n_minus_x_plus_y).groups)[groupname] != 0
1210 && self_connect_to_raillike)
1211 || n_minus_x_plus_y.getContent() == thiscontent)
1212 is_rail_x_plus_y[0] = true;
1214 if ((nodedef->get(n_plus_x).drawtype == NDT_RAILLIKE
1215 && ((ItemGroupList) nodedef->get(n_plus_x).groups)[groupname] != 0
1216 && self_connect_to_raillike)
1217 || n_plus_x.getContent() == thiscontent)
1218 is_rail_x[1] = true;
1220 if ((nodedef->get(n_plus_x_minus_y).drawtype == NDT_RAILLIKE
1221 && ((ItemGroupList) nodedef->get(n_plus_x_minus_y).groups)[groupname] != 0
1222 && self_connect_to_raillike)
1223 || n_plus_x_minus_y.getContent() == thiscontent)
1224 is_rail_x_minus_y[1] = true;
1226 if ((nodedef->get(n_plus_x_plus_y).drawtype == NDT_RAILLIKE
1227 && ((ItemGroupList) nodedef->get(n_plus_x_plus_y).groups)[groupname] != 0
1228 && self_connect_to_raillike)
1229 || n_plus_x_plus_y.getContent() == thiscontent)
1230 is_rail_x_plus_y[1] = true;
1232 if ((nodedef->get(n_minus_z).drawtype == NDT_RAILLIKE
1233 && ((ItemGroupList) nodedef->get(n_minus_z).groups)[groupname] != 0
1234 && self_connect_to_raillike)
1235 || n_minus_z.getContent() == thiscontent)
1236 is_rail_z[0] = true;
1238 if ((nodedef->get(n_minus_z_minus_y).drawtype == NDT_RAILLIKE
1239 && ((ItemGroupList) nodedef->get(n_minus_z_minus_y).groups)[groupname] != 0
1240 && self_connect_to_raillike)
1241 || n_minus_z_minus_y.getContent() == thiscontent)
1242 is_rail_z_minus_y[0] = true;
1244 if ((nodedef->get(n_minus_z_plus_y).drawtype == NDT_RAILLIKE
1245 && ((ItemGroupList) nodedef->get(n_minus_z_plus_y).groups)[groupname] != 0
1246 && self_connect_to_raillike)
1247 || n_minus_z_plus_y.getContent() == thiscontent)
1248 is_rail_z_plus_y[0] = true;
1250 if ((nodedef->get(n_plus_z).drawtype == NDT_RAILLIKE
1251 && ((ItemGroupList) nodedef->get(n_plus_z).groups)[groupname] != 0
1252 && self_connect_to_raillike)
1253 || n_plus_z.getContent() == thiscontent)
1254 is_rail_z[1] = true;
1256 if ((nodedef->get(n_plus_z_minus_y).drawtype == NDT_RAILLIKE
1257 && ((ItemGroupList) nodedef->get(n_plus_z_minus_y).groups)[groupname] != 0
1258 && self_connect_to_raillike)
1259 || n_plus_z_minus_y.getContent() == thiscontent)
1260 is_rail_z_minus_y[1] = true;
1262 if ((nodedef->get(n_plus_z_plus_y).drawtype == NDT_RAILLIKE
1263 && ((ItemGroupList) nodedef->get(n_plus_z_plus_y).groups)[groupname] != 0
1264 && self_connect_to_raillike)
1265 || n_plus_z_plus_y.getContent() == thiscontent)
1266 is_rail_z_plus_y[1] = true;
1268 bool is_rail_x_all[] = {false, false};
1269 bool is_rail_z_all[] = {false, false};
1270 is_rail_x_all[0]=is_rail_x[0] || is_rail_x_minus_y[0] || is_rail_x_plus_y[0];
1271 is_rail_x_all[1]=is_rail_x[1] || is_rail_x_minus_y[1] || is_rail_x_plus_y[1];
1272 is_rail_z_all[0]=is_rail_z[0] || is_rail_z_minus_y[0] || is_rail_z_plus_y[0];
1273 is_rail_z_all[1]=is_rail_z[1] || is_rail_z_minus_y[1] || is_rail_z_plus_y[1];
1275 // reasonable default, flat straight unrotated rail
1276 bool is_straight = true;
1277 int adjacencies = 0;
1281 // check for sloped rail
1282 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])
1284 adjacencies = 5; //5 means sloped
1285 is_straight = true; // sloped is always straight
1289 // is really straight, rails on both sides
1290 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
1291 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
1294 switch (adjacencies) {
1296 if(is_rail_x_all[0] || is_rail_x_all[1])
1301 tileindex = 1; // curved
1302 if(is_rail_x_all[0] && is_rail_x_all[1])
1304 if(is_rail_z_all[0] && is_rail_z_all[1]){
1305 if (is_rail_z_plus_y[0])
1308 else if(is_rail_x_all[0] && is_rail_z_all[0])
1310 else if(is_rail_x_all[0] && is_rail_z_all[1])
1312 else if(is_rail_x_all[1] && is_rail_z_all[1])
1316 // here is where the potential to 'switch' a junction is, but not implemented at present
1317 tileindex = 2; // t-junction
1318 if(!is_rail_x_all[1])
1320 if(!is_rail_z_all[0])
1322 if(!is_rail_z_all[1])
1326 tileindex = 3; // crossing
1329 if(is_rail_z_plus_y[0])
1331 if(is_rail_x_plus_y[0])
1333 if(is_rail_x_plus_y[1])
1340 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1341 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1342 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1344 AtlasPointer ap = tile.texture;
1346 u16 l = getInteriorLight(n, 0, data);
1347 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1349 float d = (float)BS/64;
1352 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])
1353 g=1; //Object is at a slope
1355 video::S3DVertex vertices[4] =
1357 video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c,
1359 video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c,
1361 video::S3DVertex(BS/2,g*BS/2+d,BS/2, 0,0,0, c,
1363 video::S3DVertex(-BS/2,g*BS/2+d,BS/2, 0,0,0, c,
1367 for(s32 i=0; i<4; i++)
1370 vertices[i].Pos.rotateXZBy(angle);
1371 vertices[i].Pos += intToFloat(p, BS);
1374 u16 indices[] = {0,1,2,2,3,0};
1375 collector.append(tile, vertices, 4, indices, 6);
1379 static const v3s16 tile_dirs[6] = {
1389 u16 l = getInteriorLight(n, 0, data);
1390 video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1392 v3f pos = intToFloat(p, BS);
1394 std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1395 for(std::vector<aabb3f>::iterator
1397 i != boxes.end(); i++)
1399 for(int j = 0; j < 6; j++)
1401 // Handles facedir rotation for textures
1402 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1409 if (box.MinEdge.X > box.MaxEdge.X)
1412 box.MinEdge.X=box.MaxEdge.X;
1415 if (box.MinEdge.Y > box.MaxEdge.Y)
1418 box.MinEdge.Y=box.MaxEdge.Y;
1421 if (box.MinEdge.Z > box.MaxEdge.Z)
1424 box.MinEdge.Z=box.MaxEdge.Z;
1429 // Compute texture coords
1430 f32 tx1 = (box.MinEdge.X/BS)+0.5;
1431 f32 ty1 = (box.MinEdge.Y/BS)+0.5;
1432 f32 tz1 = (box.MinEdge.Z/BS)+0.5;
1433 f32 tx2 = (box.MaxEdge.X/BS)+0.5;
1434 f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
1435 f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
1438 tx1, 1-tz2, tx2, 1-tz1,
1442 tz1, 1-ty2, tz2, 1-ty1,
1444 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1446 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1448 tx1, 1-ty2, tx2, 1-ty1,
1450 makeCuboid(&collector, box, tiles, 6, c, txc);