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 "mapblock_mesh.h" // For MapBlock_LightColor() and MeshCollector
26 #include "client/tile.h"
28 #include <IMeshManipulator.h>
34 // collector - the MeshCollector for the resulting polygons
35 // box - the position and size of the box
36 // tiles - the tiles (materials) to use (for all 6 faces)
37 // tilecount - number of entries in tiles, 1<=tilecount<=6
38 // c - vertex colour - used for all
39 // txc - texture coordinates - this is a list of texture coordinates
40 // for the opposite corners of each face - therefore, there
41 // should be (2+2)*6=24 values in the list. Alternatively, pass
42 // NULL to use the entire texture for each face. The order of
43 // the faces in the list is up-down-right-left-back-front
44 // (compatible with ContentFeatures). If you specified 0,0,1,1
45 // for each face, that would be the same as passing NULL.
46 void makeCuboid(MeshCollector *collector, const aabb3f &box,
47 TileSpec *tiles, int tilecount, video::SColor &c, const f32* txc)
49 assert(tilecount >= 1 && tilecount <= 6); // pre-condition
51 v3f min = box.MinEdge;
52 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) {
161 int tileindex = MYMIN(j / 4, tilecount - 1);
162 collector->append(tiles[tileindex], vertices + j, 4, indices, 6);
167 TODO: Fix alpha blending for special nodes
168 Currently only the last element rendered is blended correct
170 void mapblock_mesh_generate_special(MeshMakeData *data,
171 MeshCollector &collector)
173 INodeDefManager *nodedef = data->m_gamedef->ndef();
174 scene::ISceneManager* smgr = data->m_gamedef->getSceneManager();
175 scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator();
178 //TimeTaker timer("mapblock_mesh_generate_special()");
183 bool enable_mesh_cache = g_settings->getBool("enable_mesh_cache");
184 bool new_style_water = g_settings->getBool("new_style_water");
186 float node_liquid_level = 1.0;
188 node_liquid_level = 0.85;
190 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
192 for(s16 z = 0; z < MAP_BLOCKSIZE; z++)
193 for(s16 y = 0; y < MAP_BLOCKSIZE; y++)
194 for(s16 x = 0; x < MAP_BLOCKSIZE; x++)
198 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
199 const ContentFeatures &f = nodedef->get(n);
201 // Only solidness=0 stuff is drawn here
207 infostream << "Got " << f.drawtype << std::endl;
208 FATAL_ERROR("Unknown drawtype");
215 Add water sources to mesh if using new style
217 TileSpec tile_liquid = f.special_tiles[0];
218 TileSpec tile_liquid_bfculled = getNodeTile(n, p, v3s16(0,0,0), data);
220 bool top_is_same_liquid = false;
221 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
222 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
223 content_t c_source = nodedef->getId(f.liquid_alternative_source);
224 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
225 top_is_same_liquid = true;
227 u16 l = getInteriorLight(n, 0, nodedef);
228 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
233 v3s16 side_dirs[4] = {
239 for(u32 i=0; i<4; i++)
241 v3s16 dir = side_dirs[i];
243 MapNode neighbor = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir);
244 content_t neighbor_content = neighbor.getContent();
245 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
246 MapNode n_top = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir+ v3s16(0,1,0));
247 content_t n_top_c = n_top.getContent();
249 if(neighbor_content == CONTENT_IGNORE)
253 If our topside is liquid and neighbor's topside
254 is liquid, don't draw side face
256 if(top_is_same_liquid && (n_top_c == c_flowing ||
257 n_top_c == c_source || n_top_c == CONTENT_IGNORE))
260 // Don't draw face if neighbor is blocking the view
261 if(n_feat.solidness == 2)
264 bool neighbor_is_same_liquid = (neighbor_content == c_source
265 || neighbor_content == c_flowing);
267 // Don't draw any faces if neighbor same is liquid and top is
269 if(neighbor_is_same_liquid && !top_is_same_liquid)
272 // Use backface culled material if neighbor doesn't have a
274 const TileSpec *current_tile = &tile_liquid;
275 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
276 current_tile = &tile_liquid_bfculled;
278 video::S3DVertex vertices[4] =
280 video::S3DVertex(-BS/2,0,BS/2,0,0,0, c, 0,1),
281 video::S3DVertex(BS/2,0,BS/2,0,0,0, c, 1,1),
282 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
283 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
287 If our topside is liquid, set upper border of face
288 at upper border of node
290 if(top_is_same_liquid)
292 vertices[2].Pos.Y = 0.5*BS;
293 vertices[3].Pos.Y = 0.5*BS;
296 Otherwise upper position of face is liquid level
300 vertices[2].Pos.Y = (node_liquid_level-0.5)*BS;
301 vertices[3].Pos.Y = (node_liquid_level-0.5)*BS;
304 If neighbor is liquid, lower border of face is liquid level
306 if(neighbor_is_same_liquid)
308 vertices[0].Pos.Y = (node_liquid_level-0.5)*BS;
309 vertices[1].Pos.Y = (node_liquid_level-0.5)*BS;
312 If neighbor is not liquid, lower border of face is
317 vertices[0].Pos.Y = -0.5*BS;
318 vertices[1].Pos.Y = -0.5*BS;
321 for(s32 j=0; j<4; j++)
323 if(dir == v3s16(0,0,1))
324 vertices[j].Pos.rotateXZBy(0);
325 if(dir == v3s16(0,0,-1))
326 vertices[j].Pos.rotateXZBy(180);
327 if(dir == v3s16(-1,0,0))
328 vertices[j].Pos.rotateXZBy(90);
329 if(dir == v3s16(1,0,-0))
330 vertices[j].Pos.rotateXZBy(-90);
332 // Do this to not cause glitches when two liquids are
334 /*if(neighbor_is_same_liquid == false){
335 vertices[j].Pos.X *= 0.98;
336 vertices[j].Pos.Z *= 0.98;
339 vertices[j].Pos += intToFloat(p, BS);
342 u16 indices[] = {0,1,2,2,3,0};
343 // Add to mesh collector
344 collector.append(*current_tile, vertices, 4, indices, 6);
350 if(top_is_same_liquid)
353 video::S3DVertex vertices[4] =
355 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
356 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
357 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
358 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
361 v3f offset(p.X*BS, p.Y*BS + (-0.5+node_liquid_level)*BS, p.Z*BS);
362 for(s32 i=0; i<4; i++)
364 vertices[i].Pos += offset;
367 u16 indices[] = {0,1,2,2,3,0};
368 // Add to mesh collector
369 collector.append(tile_liquid, vertices, 4, indices, 6);
371 case NDT_FLOWINGLIQUID:
374 Add flowing liquid to mesh
376 TileSpec tile_liquid = f.special_tiles[0];
377 TileSpec tile_liquid_bfculled = f.special_tiles[1];
379 bool top_is_same_liquid = false;
380 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
381 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
382 content_t c_source = nodedef->getId(f.liquid_alternative_source);
383 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
384 top_is_same_liquid = true;
387 // If this liquid emits light and doesn't contain light, draw
388 // it at what it emits, for an increased effect
389 u8 light_source = nodedef->get(n).light_source;
390 if(light_source != 0){
391 l = decode_light(light_source);
394 // Use the light of the node on top if possible
395 else if(nodedef->get(ntop).param_type == CPT_LIGHT)
396 l = getInteriorLight(ntop, 0, nodedef);
397 // Otherwise use the light of this node (the liquid)
399 l = getInteriorLight(n, 0, nodedef);
400 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
402 u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
404 // Neighbor liquid levels (key = relative position)
405 // Includes current node
406 std::map<v3s16, f32> neighbor_levels;
407 std::map<v3s16, content_t> neighbor_contents;
408 std::map<v3s16, u8> neighbor_flags;
409 const u8 neighborflag_top_is_same_liquid = 0x01;
410 v3s16 neighbor_dirs[9] = {
421 for(u32 i=0; i<9; i++)
423 content_t content = CONTENT_AIR;
424 float level = -0.5 * BS;
427 v3s16 p2 = p + neighbor_dirs[i];
428 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
429 if(n2.getContent() != CONTENT_IGNORE)
431 content = n2.getContent();
433 if(n2.getContent() == c_source)
434 level = (-0.5+node_liquid_level) * BS;
435 else if(n2.getContent() == c_flowing){
436 u8 liquid_level = (n2.param2&LIQUID_LEVEL_MASK);
437 if (liquid_level <= LIQUID_LEVEL_MAX+1-range)
440 liquid_level -= (LIQUID_LEVEL_MAX+1-range);
441 level = (-0.5 + ((float)liquid_level+ 0.5) / (float)range * node_liquid_level) * BS;
444 // Check node above neighbor.
445 // NOTE: This doesn't get executed if neighbor
448 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
449 if(n2.getContent() == c_source ||
450 n2.getContent() == c_flowing)
451 flags |= neighborflag_top_is_same_liquid;
454 neighbor_levels[neighbor_dirs[i]] = level;
455 neighbor_contents[neighbor_dirs[i]] = content;
456 neighbor_flags[neighbor_dirs[i]] = flags;
459 // Corner heights (average between four liquids)
460 f32 corner_levels[4];
462 v3s16 halfdirs[4] = {
468 for(u32 i=0; i<4; i++)
470 v3s16 cornerdir = halfdirs[i];
471 float cornerlevel = 0;
474 for(u32 j=0; j<4; j++)
476 v3s16 neighbordir = cornerdir - halfdirs[j];
477 content_t content = neighbor_contents[neighbordir];
478 // If top is liquid, draw starting from top of node
479 if(neighbor_flags[neighbordir] &
480 neighborflag_top_is_same_liquid)
482 cornerlevel = 0.5*BS;
486 // Source is always the same height
487 else if(content == c_source)
489 cornerlevel = (-0.5+node_liquid_level)*BS;
493 // Flowing liquid has level information
494 else if(content == c_flowing)
496 cornerlevel += neighbor_levels[neighbordir];
499 else if(content == CONTENT_AIR)
505 cornerlevel = -0.5*BS+0.2;
506 else if(valid_count > 0)
507 cornerlevel /= valid_count;
508 corner_levels[i] = cornerlevel;
515 v3s16 side_dirs[4] = {
521 s16 side_corners[4][2] = {
527 for(u32 i=0; i<4; i++)
529 v3s16 dir = side_dirs[i];
532 If our topside is liquid and neighbor's topside
533 is liquid, don't draw side face
535 if(top_is_same_liquid &&
536 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
539 content_t neighbor_content = neighbor_contents[dir];
540 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
542 // Don't draw face if neighbor is blocking the view
543 if(n_feat.solidness == 2)
546 bool neighbor_is_same_liquid = (neighbor_content == c_source
547 || neighbor_content == c_flowing);
549 // Don't draw any faces if neighbor same is liquid and top is
551 if(neighbor_is_same_liquid == true
552 && top_is_same_liquid == false)
555 // Use backface culled material if neighbor doesn't have a
557 const TileSpec *current_tile = &tile_liquid;
558 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
559 current_tile = &tile_liquid_bfculled;
561 video::S3DVertex vertices[4] =
563 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
564 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
565 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
566 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
570 If our topside is liquid, set upper border of face
571 at upper border of node
573 if(top_is_same_liquid)
575 vertices[2].Pos.Y = 0.5*BS;
576 vertices[3].Pos.Y = 0.5*BS;
579 Otherwise upper position of face is corner levels
583 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
584 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
588 If neighbor is liquid, lower border of face is corner
591 if(neighbor_is_same_liquid)
593 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
594 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
597 If neighbor is not liquid, lower border of face is
602 vertices[0].Pos.Y = -0.5*BS;
603 vertices[1].Pos.Y = -0.5*BS;
606 for(s32 j=0; j<4; j++)
608 if(dir == v3s16(0,0,1))
609 vertices[j].Pos.rotateXZBy(0);
610 if(dir == v3s16(0,0,-1))
611 vertices[j].Pos.rotateXZBy(180);
612 if(dir == v3s16(-1,0,0))
613 vertices[j].Pos.rotateXZBy(90);
614 if(dir == v3s16(1,0,-0))
615 vertices[j].Pos.rotateXZBy(-90);
617 // Do this to not cause glitches when two liquids are
619 /*if(neighbor_is_same_liquid == false){
620 vertices[j].Pos.X *= 0.98;
621 vertices[j].Pos.Z *= 0.98;
624 vertices[j].Pos += intToFloat(p, BS);
627 u16 indices[] = {0,1,2,2,3,0};
628 // Add to mesh collector
629 collector.append(*current_tile, vertices, 4, indices, 6);
633 Generate top side, if appropriate
636 if(top_is_same_liquid == false)
638 video::S3DVertex vertices[4] =
640 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
641 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
642 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
643 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
646 // To get backface culling right, the vertices need to go
647 // clockwise around the front of the face. And we happened to
648 // calculate corner levels in exact reverse order.
649 s32 corner_resolve[4] = {3,2,1,0};
651 for(s32 i=0; i<4; i++)
653 //vertices[i].Pos.Y += liquid_level;
654 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
655 s32 j = corner_resolve[i];
656 vertices[i].Pos.Y += corner_levels[j];
657 vertices[i].Pos += intToFloat(p, BS);
660 // Default downwards-flowing texture animation goes from
661 // -Z towards +Z, thus the direction is +Z.
662 // Rotate texture to make animation go in flow direction
663 // Positive if liquid moves towards +Z
664 f32 dz = (corner_levels[side_corners[3][0]] +
665 corner_levels[side_corners[3][1]]) -
666 (corner_levels[side_corners[2][0]] +
667 corner_levels[side_corners[2][1]]);
668 // Positive if liquid moves towards +X
669 f32 dx = (corner_levels[side_corners[1][0]] +
670 corner_levels[side_corners[1][1]]) -
671 (corner_levels[side_corners[0][0]] +
672 corner_levels[side_corners[0][1]]);
673 f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG ;
674 v2f tcoord_center(0.5, 0.5);
675 v2f tcoord_translate(
676 blockpos_nodes.Z + z,
677 blockpos_nodes.X + x);
678 tcoord_translate.rotateBy(tcoord_angle);
679 tcoord_translate.X -= floor(tcoord_translate.X);
680 tcoord_translate.Y -= floor(tcoord_translate.Y);
682 for(s32 i=0; i<4; i++)
684 vertices[i].TCoords.rotateBy(
687 vertices[i].TCoords += tcoord_translate;
690 v2f t = vertices[0].TCoords;
691 vertices[0].TCoords = vertices[2].TCoords;
692 vertices[2].TCoords = t;
694 u16 indices[] = {0,1,2,2,3,0};
695 // Add to mesh collector
696 collector.append(tile_liquid, vertices, 4, indices, 6);
701 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
703 u16 l = getInteriorLight(n, 1, nodedef);
704 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
706 for(u32 j=0; j<6; j++)
708 // Check this neighbor
709 v3s16 dir = g_6dirs[j];
710 v3s16 n2p = blockpos_nodes + p + dir;
711 MapNode n2 = data->m_vmanip.getNodeNoEx(n2p);
712 // Don't make face if neighbor is of same type
713 if(n2.getContent() == n.getContent())
717 video::S3DVertex vertices[4] = {
718 video::S3DVertex(-BS/2,-BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 1,1),
719 video::S3DVertex(BS/2,-BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 0,1),
720 video::S3DVertex(BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 0,0),
721 video::S3DVertex(-BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 1,0),
724 // Rotations in the g_6dirs format
726 for(u16 i=0; i<4; i++)
727 vertices[i].Pos.rotateXZBy(0);
728 else if(j == 1) // Y+
729 for(u16 i=0; i<4; i++)
730 vertices[i].Pos.rotateYZBy(-90);
731 else if(j == 2) // X+
732 for(u16 i=0; i<4; i++)
733 vertices[i].Pos.rotateXZBy(-90);
734 else if(j == 3) // Z-
735 for(u16 i=0; i<4; i++)
736 vertices[i].Pos.rotateXZBy(180);
737 else if(j == 4) // Y-
738 for(u16 i=0; i<4; i++)
739 vertices[i].Pos.rotateYZBy(90);
740 else if(j == 5) // X-
741 for(u16 i=0; i<4; i++)
742 vertices[i].Pos.rotateXZBy(90);
744 for(u16 i=0; i<4; i++){
745 vertices[i].Pos += intToFloat(p, BS);
748 u16 indices[] = {0,1,2,2,3,0};
749 // Add to mesh collector
750 collector.append(tile, vertices, 4, indices, 6);
753 case NDT_GLASSLIKE_FRAMED_OPTIONAL:
754 // This is always pre-converted to something else
755 FATAL_ERROR("NDT_GLASSLIKE_FRAMED_OPTIONAL not pre-converted as expected");
757 case NDT_GLASSLIKE_FRAMED:
759 static const v3s16 dirs[6] = {
770 for (i = 0; i < 6; i++)
771 tiles[i] = getNodeTile(n, p, dirs[i], data);
773 TileSpec glass_tiles[6];
774 if (tiles[1].texture && tiles[2].texture && tiles[3].texture) {
775 glass_tiles[0] = tiles[2];
776 glass_tiles[1] = tiles[3];
777 glass_tiles[2] = tiles[1];
778 glass_tiles[3] = tiles[1];
779 glass_tiles[4] = tiles[1];
780 glass_tiles[5] = tiles[1];
782 for (i = 0; i < 6; i++)
783 glass_tiles[i] = tiles[1];
786 u8 param2 = n.getParam2();
787 bool H_merge = ! bool(param2 & 128);
788 bool V_merge = ! bool(param2 & 64);
789 param2 = param2 & 63;
791 u16 l = getInteriorLight(n, 1, nodedef);
792 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
793 v3f pos = intToFloat(p, BS);
794 static const float a = BS / 2;
795 static const float g = a - 0.003;
796 static const float b = .876 * ( BS / 2 );
798 static const aabb3f frame_edges[12] = {
799 aabb3f( b, b,-a, a, a, a), // y+
800 aabb3f(-a, b,-a,-b, a, a), // y+
801 aabb3f( b,-a,-a, a,-b, a), // y-
802 aabb3f(-a,-a,-a,-b,-b, a), // y-
803 aabb3f( b,-a, b, a, a, a), // x+
804 aabb3f( b,-a,-a, a, a,-b), // x+
805 aabb3f(-a,-a, b,-b, a, a), // x-
806 aabb3f(-a,-a,-a,-b, a,-b), // x-
807 aabb3f(-a, b, b, a, a, a), // z+
808 aabb3f(-a,-a, b, a,-b, a), // z+
809 aabb3f(-a,-a,-a, a,-b,-b), // z-
810 aabb3f(-a, b,-a, a, a,-b) // z-
812 static const aabb3f glass_faces[6] = {
813 aabb3f(-g, g,-g, g, g, g), // y+
814 aabb3f(-g,-g,-g, g,-g, g), // y-
815 aabb3f( g,-g,-g, g, g, g), // x+
816 aabb3f(-g,-g,-g,-g, g, g), // x-
817 aabb3f(-g,-g, g, g, g, g), // z+
818 aabb3f(-g,-g,-g, g, g,-g) // z-
821 // table of node visible faces, 0 = invisible
822 int visible_faces[6] = {0,0,0,0,0,0};
824 // table of neighbours, 1 = same type, checked with g_26dirs
825 int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
827 // g_26dirs to check when only horizontal merge is allowed
828 int nb_H_dirs[8] = {0,2,3,5,10,11,12,13};
830 content_t current = n.getContent();
835 // neighbours checks for frames visibility
837 if (!H_merge && V_merge) {
838 n2p = blockpos_nodes + p + g_26dirs[1];
839 n2 = data->m_vmanip.getNodeNoEx(n2p);
840 n2c = n2.getContent();
841 if (n2c == current || n2c == CONTENT_IGNORE)
843 n2p = blockpos_nodes + p + g_26dirs[4];
844 n2 = data->m_vmanip.getNodeNoEx(n2p);
845 n2c = n2.getContent();
846 if (n2c == current || n2c == CONTENT_IGNORE)
848 } else if (H_merge && !V_merge) {
849 for(i = 0; i < 8; i++) {
850 n2p = blockpos_nodes + p + g_26dirs[nb_H_dirs[i]];
851 n2 = data->m_vmanip.getNodeNoEx(n2p);
852 n2c = n2.getContent();
853 if (n2c == current || n2c == CONTENT_IGNORE)
854 nb[nb_H_dirs[i]] = 1;
856 } else if (H_merge && V_merge) {
857 for(i = 0; i < 18; i++) {
858 n2p = blockpos_nodes + p + g_26dirs[i];
859 n2 = data->m_vmanip.getNodeNoEx(n2p);
860 n2c = n2.getContent();
861 if (n2c == current || n2c == CONTENT_IGNORE)
866 // faces visibility checks
869 visible_faces[0] = 1;
870 visible_faces[1] = 1;
872 for(i = 0; i < 2; i++) {
873 n2p = blockpos_nodes + p + dirs[i];
874 n2 = data->m_vmanip.getNodeNoEx(n2p);
875 n2c = n2.getContent();
877 visible_faces[i] = 1;
882 visible_faces[2] = 1;
883 visible_faces[3] = 1;
884 visible_faces[4] = 1;
885 visible_faces[5] = 1;
887 for(i = 2; i < 6; i++) {
888 n2p = blockpos_nodes + p + dirs[i];
889 n2 = data->m_vmanip.getNodeNoEx(n2p);
890 n2c = n2.getContent();
892 visible_faces[i] = 1;
896 static const u8 nb_triplet[12*3] = {
897 1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
898 2,0,11, 2,3,13, 5,0,10, 5,3,12,
899 0,1, 8, 0,4,16, 3,4,17, 3,1, 9
902 f32 tx1, ty1, tz1, tx2, ty2, tz2;
905 for(i = 0; i < 12; i++)
908 if (nb[nb_triplet[i*3+2]])
909 edge_invisible = nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
911 edge_invisible = nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
914 box = frame_edges[i];
917 tx1 = (box.MinEdge.X / BS) + 0.5;
918 ty1 = (box.MinEdge.Y / BS) + 0.5;
919 tz1 = (box.MinEdge.Z / BS) + 0.5;
920 tx2 = (box.MaxEdge.X / BS) + 0.5;
921 ty2 = (box.MaxEdge.Y / BS) + 0.5;
922 tz2 = (box.MaxEdge.Z / BS) + 0.5;
924 tx1, 1-tz2, tx2, 1-tz1,
926 tz1, 1-ty2, tz2, 1-ty1,
927 1-tz2, 1-ty2, 1-tz1, 1-ty1,
928 1-tx2, 1-ty2, 1-tx1, 1-ty1,
929 tx1, 1-ty2, tx2, 1-ty1,
931 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
934 for(i = 0; i < 6; i++)
936 if (!visible_faces[i])
938 box = glass_faces[i];
941 tx1 = (box.MinEdge.X / BS) + 0.5;
942 ty1 = (box.MinEdge.Y / BS) + 0.5;
943 tz1 = (box.MinEdge.Z / BS) + 0.5;
944 tx2 = (box.MaxEdge.X / BS) + 0.5;
945 ty2 = (box.MaxEdge.Y / BS) + 0.5;
946 tz2 = (box.MaxEdge.Z / BS) + 0.5;
948 tx1, 1-tz2, tx2, 1-tz1,
950 tz1, 1-ty2, tz2, 1-ty1,
951 1-tz2, 1-ty2, 1-tz1, 1-ty1,
952 1-tx2, 1-ty2, 1-tx1, 1-ty1,
953 tx1, 1-ty2, tx2, 1-ty1,
955 makeCuboid(&collector, box, &glass_tiles[i], 1, c, txc2);
958 if (param2 > 0 && f.special_tiles[0].texture) {
959 // Interior volume level is in range 0 .. 63,
960 // convert it to -0.5 .. 0.5
961 float vlev = (((float)param2 / 63.0 ) * 2.0 - 1.0);
962 TileSpec interior_tiles[6];
963 for (i = 0; i < 6; i++)
964 interior_tiles[i] = f.special_tiles[0];
965 float offset = 0.003;
966 box = aabb3f(visible_faces[3] ? -b : -a + offset,
967 visible_faces[1] ? -b : -a + offset,
968 visible_faces[5] ? -b : -a + offset,
969 visible_faces[2] ? b : a - offset,
970 visible_faces[0] ? b * vlev : a * vlev - offset,
971 visible_faces[4] ? b : a - offset);
974 tx1 = (box.MinEdge.X / BS) + 0.5;
975 ty1 = (box.MinEdge.Y / BS) + 0.5;
976 tz1 = (box.MinEdge.Z / BS) + 0.5;
977 tx2 = (box.MaxEdge.X / BS) + 0.5;
978 ty2 = (box.MaxEdge.Y / BS) + 0.5;
979 tz2 = (box.MaxEdge.Z / BS) + 0.5;
981 tx1, 1-tz2, tx2, 1-tz1,
983 tz1, 1-ty2, tz2, 1-ty1,
984 1-tz2, 1-ty2, 1-tz1, 1-ty1,
985 1-tx2, 1-ty2, 1-tx1, 1-ty1,
986 tx1, 1-ty2, tx2, 1-ty1,
988 makeCuboid(&collector, box, interior_tiles, 6, c, txc3);
993 TileSpec tile_leaves = getNodeTile(n, p,
996 u16 l = getInteriorLight(n, 1, nodedef);
997 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
999 v3f pos = intToFloat(p, BS);
1000 aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
1003 makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
1005 case NDT_ALLFACES_OPTIONAL:
1006 // This is always pre-converted to something else
1007 FATAL_ERROR("NDT_ALLFACES_OPTIONAL not pre-converted");
1011 v3s16 dir = n.getWallMountedDir(nodedef);
1014 if(dir == v3s16(0,-1,0)){
1015 tileindex = 0; // floor
1016 } else if(dir == v3s16(0,1,0)){
1017 tileindex = 1; // ceiling
1018 // For backwards compatibility
1019 } else if(dir == v3s16(0,0,0)){
1020 tileindex = 0; // floor
1022 tileindex = 2; // side
1025 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1026 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1027 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1029 u16 l = getInteriorLight(n, 1, nodedef);
1030 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1032 float s = BS/2*f.visual_scale;
1033 // Wall at X+ of node
1034 video::S3DVertex vertices[4] =
1036 video::S3DVertex(-s,-s,0, 0,0,0, c, 0,1),
1037 video::S3DVertex( s,-s,0, 0,0,0, c, 1,1),
1038 video::S3DVertex( s, s,0, 0,0,0, c, 1,0),
1039 video::S3DVertex(-s, s,0, 0,0,0, c, 0,0),
1042 for(s32 i=0; i<4; i++)
1044 if(dir == v3s16(1,0,0))
1045 vertices[i].Pos.rotateXZBy(0);
1046 if(dir == v3s16(-1,0,0))
1047 vertices[i].Pos.rotateXZBy(180);
1048 if(dir == v3s16(0,0,1))
1049 vertices[i].Pos.rotateXZBy(90);
1050 if(dir == v3s16(0,0,-1))
1051 vertices[i].Pos.rotateXZBy(-90);
1052 if(dir == v3s16(0,-1,0))
1053 vertices[i].Pos.rotateXZBy(45);
1054 if(dir == v3s16(0,1,0))
1055 vertices[i].Pos.rotateXZBy(-45);
1057 vertices[i].Pos += intToFloat(p, BS);
1060 u16 indices[] = {0,1,2,2,3,0};
1061 // Add to mesh collector
1062 collector.append(tile, vertices, 4, indices, 6);
1066 TileSpec tile = getNodeTileN(n, p, 0, data);
1067 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1068 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1070 u16 l = getInteriorLight(n, 0, nodedef);
1071 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1073 float d = (float)BS/16;
1074 float s = BS/2*f.visual_scale;
1075 // Wall at X+ of node
1076 video::S3DVertex vertices[4] =
1078 video::S3DVertex(BS/2-d, s, s, 0,0,0, c, 0,0),
1079 video::S3DVertex(BS/2-d, s, -s, 0,0,0, c, 1,0),
1080 video::S3DVertex(BS/2-d, -s, -s, 0,0,0, c, 1,1),
1081 video::S3DVertex(BS/2-d, -s, s, 0,0,0, c, 0,1),
1084 v3s16 dir = n.getWallMountedDir(nodedef);
1086 for(s32 i=0; i<4; i++)
1088 if(dir == v3s16(1,0,0))
1089 vertices[i].Pos.rotateXZBy(0);
1090 if(dir == v3s16(-1,0,0))
1091 vertices[i].Pos.rotateXZBy(180);
1092 if(dir == v3s16(0,0,1))
1093 vertices[i].Pos.rotateXZBy(90);
1094 if(dir == v3s16(0,0,-1))
1095 vertices[i].Pos.rotateXZBy(-90);
1096 if(dir == v3s16(0,-1,0))
1097 vertices[i].Pos.rotateXYBy(-90);
1098 if(dir == v3s16(0,1,0))
1099 vertices[i].Pos.rotateXYBy(90);
1101 vertices[i].Pos += intToFloat(p, BS);
1104 u16 indices[] = {0,1,2,2,3,0};
1105 // Add to mesh collector
1106 collector.append(tile, vertices, 4, indices, 6);
1110 TileSpec tile = getNodeTileN(n, p, 0, data);
1111 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1113 u16 l = getInteriorLight(n, 1, nodedef);
1114 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1116 float s = BS / 2 * f.visual_scale;
1118 for (int j = 0; j < 2; j++)
1120 video::S3DVertex vertices[4] =
1122 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1123 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1124 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1125 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1127 float rotate_degree = 0;
1128 if (f.param_type_2 == CPT2_DEGROTATE)
1129 rotate_degree = n.param2 * 2;
1132 for(u16 i = 0; i < 4; i++)
1133 vertices[i].Pos.rotateXZBy(46 + rotate_degree);
1134 } else if (j == 1) {
1135 for(u16 i = 0; i < 4; i++)
1136 vertices[i].Pos.rotateXZBy(-44 + rotate_degree);
1139 for (int i = 0; i < 4; i++)
1141 vertices[i].Pos *= f.visual_scale;
1142 vertices[i].Pos.Y += BS/2 * (f.visual_scale - 1);
1143 vertices[i].Pos += intToFloat(p, BS);
1146 u16 indices[] = {0, 1, 2, 2, 3, 0};
1147 // Add to mesh collector
1148 collector.append(tile, vertices, 4, indices, 6);
1153 TileSpec tile = getNodeTileN(n, p, 0, data);
1154 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1156 u16 l = getInteriorLight(n, 1, nodedef);
1157 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1159 float s = BS / 2 * f.visual_scale;
1161 content_t current = n.getContent();
1166 static const v3s16 dirs[6] = {
1175 int doDraw[6] = {0, 0, 0, 0, 0, 0};
1177 bool drawAllFaces = true;
1179 // Check for adjacent nodes
1180 for (int i = 0; i < 6; i++) {
1181 n2p = blockpos_nodes + p + dirs[i];
1182 n2 = data->m_vmanip.getNodeNoEx(n2p);
1183 n2c = n2.getContent();
1184 if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) {
1187 drawAllFaces = false;
1192 for (int j = 0; j < 6; j++) {
1194 video::S3DVertex vertices[4] = {
1195 video::S3DVertex(-s, -BS / 2, 0, 0, 0, 0, c, 0, 1),
1196 video::S3DVertex( s, -BS / 2, 0, 0, 0, 0, c, 1, 1),
1197 video::S3DVertex( s, -BS / 2 + s * 2, 0, 0, 0, 0, c, 1, 0),
1198 video::S3DVertex(-s, -BS / 2 + s * 2, 0, 0, 0, 0, c, 0, 0),
1201 // Calculate which faces should be drawn, (top or sides)
1202 if (j == 0 && (drawAllFaces ||
1203 (doDraw[3] == 1 || doDraw[1] == 1))) {
1204 for (int i = 0; i < 4; i++) {
1205 vertices[i].Pos.rotateXZBy(90);
1206 vertices[i].Pos.rotateXYBy(-10);
1207 vertices[i].Pos.X -= 4.0;
1209 } else if (j == 1 && (drawAllFaces ||
1210 (doDraw[5] == 1 || doDraw[1] == 1))) {
1211 for (int i = 0; i < 4; i++) {
1212 vertices[i].Pos.rotateXZBy(180);
1213 vertices[i].Pos.rotateYZBy(10);
1214 vertices[i].Pos.Z -= 4.0;
1216 } else if (j == 2 && (drawAllFaces ||
1217 (doDraw[2] == 1 || doDraw[1] == 1))) {
1218 for (int i = 0; i < 4; i++) {
1219 vertices[i].Pos.rotateXZBy(270);
1220 vertices[i].Pos.rotateXYBy(10);
1221 vertices[i].Pos.X += 4.0;
1223 } else if (j == 3 && (drawAllFaces ||
1224 (doDraw[4] == 1 || doDraw[1] == 1))) {
1225 for (int i = 0; i < 4; i++) {
1226 vertices[i].Pos.rotateYZBy(-10);
1227 vertices[i].Pos.Z += 4.0;
1229 // Center cross-flames
1230 } else if (j == 4 && (drawAllFaces || doDraw[1] == 1)) {
1231 for (int i = 0; i < 4; i++) {
1232 vertices[i].Pos.rotateXZBy(45);
1234 } else if (j == 5 && (drawAllFaces || doDraw[1] == 1)) {
1235 for (int i = 0; i < 4; i++) {
1236 vertices[i].Pos.rotateXZBy(-45);
1238 // Render flames on bottom of node above
1239 } else if (j == 0 && doDraw[0] == 1 && doDraw[1] == 0) {
1240 for (int i = 0; i < 4; i++) {
1241 vertices[i].Pos.rotateYZBy(70);
1242 vertices[i].Pos.rotateXZBy(90);
1243 vertices[i].Pos.Y += 4.84;
1244 vertices[i].Pos.X -= 4.7;
1246 } else if (j == 1 && doDraw[0] == 1 && doDraw[1] == 0) {
1247 for (int i = 0; i < 4; i++) {
1248 vertices[i].Pos.rotateYZBy(70);
1249 vertices[i].Pos.rotateXZBy(180);
1250 vertices[i].Pos.Y += 4.84;
1251 vertices[i].Pos.Z -= 4.7;
1253 } else if (j == 2 && doDraw[0] == 1 && doDraw[1] == 0) {
1254 for (int i = 0; i < 4; i++) {
1255 vertices[i].Pos.rotateYZBy(70);
1256 vertices[i].Pos.rotateXZBy(270);
1257 vertices[i].Pos.Y += 4.84;
1258 vertices[i].Pos.X += 4.7;
1260 } else if (j == 3 && doDraw[0] == 1 && doDraw[1] == 0) {
1261 for (int i = 0; i < 4; i++) {
1262 vertices[i].Pos.rotateYZBy(70);
1263 vertices[i].Pos.Y += 4.84;
1264 vertices[i].Pos.Z += 4.7;
1267 // Skip faces that aren't adjacent to a node
1271 for (int i = 0; i < 4; i++) {
1272 vertices[i].Pos *= f.visual_scale;
1273 vertices[i].Pos += intToFloat(p, BS);
1276 u16 indices[] = {0, 1, 2, 2, 3, 0};
1277 // Add to mesh collector
1278 collector.append(tile, vertices, 4, indices, 6);
1283 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1284 TileSpec tile_nocrack = tile;
1285 tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1287 // Put wood the right way around in the posts
1288 TileSpec tile_rot = tile;
1289 tile_rot.rotation = 1;
1291 u16 l = getInteriorLight(n, 1, nodedef);
1292 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1294 const f32 post_rad=(f32)BS/8;
1295 const f32 bar_rad=(f32)BS/16;
1296 const f32 bar_len=(f32)(BS/2)-post_rad;
1298 v3f pos = intToFloat(p, BS);
1300 // The post - always present
1301 aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
1302 post.MinEdge += pos;
1303 post.MaxEdge += pos;
1305 6/16.,6/16.,10/16.,10/16.,
1306 6/16.,6/16.,10/16.,10/16.,
1311 makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1313 // Now a section of fence, +X, if there's a post there
1316 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1317 const ContentFeatures *f2 = &nodedef->get(n2);
1318 if(f2->drawtype == NDT_FENCELIKE)
1320 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1321 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1325 0/16.,2/16.,16/16.,4/16.,
1326 0/16.,4/16.,16/16.,6/16.,
1327 6/16.,6/16.,8/16.,8/16.,
1328 10/16.,10/16.,12/16.,12/16.,
1329 0/16.,8/16.,16/16.,10/16.,
1330 0/16.,14/16.,16/16.,16/16.};
1331 makeCuboid(&collector, bar, &tile_nocrack, 1,
1333 bar.MinEdge.Y -= BS/2;
1334 bar.MaxEdge.Y -= BS/2;
1335 makeCuboid(&collector, bar, &tile_nocrack, 1,
1339 // Now a section of fence, +Z, if there's a post there
1342 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1343 f2 = &nodedef->get(n2);
1344 if(f2->drawtype == NDT_FENCELIKE)
1346 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1347 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1351 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
1352 4/16.,1/16.,6/16.,5/16., // for wood texture instead
1353 0/16.,9/16.,16/16.,11/16.,
1354 0/16.,6/16.,16/16.,8/16.,
1355 6/16.,6/16.,8/16.,8/16.,
1356 10/16.,10/16.,12/16.,12/16.};
1357 makeCuboid(&collector, bar, &tile_nocrack, 1,
1359 bar.MinEdge.Y -= BS/2;
1360 bar.MaxEdge.Y -= BS/2;
1361 makeCuboid(&collector, bar, &tile_nocrack, 1,
1367 bool is_rail_x[6]; /* (-1,-1,0) X (1,-1,0) (-1,0,0) X (1,0,0) (-1,1,0) X (1,1,0) */
1370 content_t thiscontent = n.getContent();
1371 std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
1372 int self_group = ((ItemGroupList) nodedef->get(n).groups)[groupname];
1375 for (s8 y0 = -1; y0 <= 1; y0++) {
1376 // Prevent from indexing never used coordinates
1377 for (s8 xz = -1; xz <= 1; xz++) {
1380 MapNode n_xy = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x + xz, y + y0, z));
1381 MapNode n_zy = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y + y0, z + xz));
1382 ContentFeatures def_xy = nodedef->get(n_xy);
1383 ContentFeatures def_zy = nodedef->get(n_zy);
1385 // Check if current node would connect with the rail
1386 is_rail_x[index] = ((def_xy.drawtype == NDT_RAILLIKE
1387 && ((ItemGroupList) def_xy.groups)[groupname] == self_group)
1388 || n_xy.getContent() == thiscontent);
1390 is_rail_z[index] = ((def_zy.drawtype == NDT_RAILLIKE
1391 && ((ItemGroupList) def_zy.groups)[groupname] == self_group)
1392 || n_zy.getContent() == thiscontent);
1397 bool is_rail_x_all[2]; // [0] = negative x, [1] = positive x coordinate from the current node position
1398 bool is_rail_z_all[2];
1399 is_rail_x_all[0] = is_rail_x[0] || is_rail_x[2] || is_rail_x[4];
1400 is_rail_x_all[1] = is_rail_x[1] || is_rail_x[3] || is_rail_x[5];
1401 is_rail_z_all[0] = is_rail_z[0] || is_rail_z[2] || is_rail_z[4];
1402 is_rail_z_all[1] = is_rail_z[1] || is_rail_z[3] || is_rail_z[5];
1404 // reasonable default, flat straight unrotated rail
1405 bool is_straight = true;
1406 int adjacencies = 0;
1410 // check for sloped rail
1411 if (is_rail_x[4] || is_rail_x[5] || is_rail_z[4] || is_rail_z[5]) {
1412 adjacencies = 5; // 5 means sloped
1413 is_straight = true; // sloped is always straight
1415 // is really straight, rails on both sides
1416 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
1417 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
1420 switch (adjacencies) {
1422 if (is_rail_x_all[0] || is_rail_x_all[1])
1427 tileindex = 1; // curved
1428 if (is_rail_x_all[0] && is_rail_x_all[1])
1430 if (is_rail_z_all[0] && is_rail_z_all[1]) {
1434 else if (is_rail_x_all[0] && is_rail_z_all[0])
1436 else if (is_rail_x_all[0] && is_rail_z_all[1])
1438 else if (is_rail_x_all[1] && is_rail_z_all[1])
1442 // here is where the potential to 'switch' a junction is, but not implemented at present
1443 tileindex = 2; // t-junction
1444 if(!is_rail_x_all[1])
1446 if(!is_rail_z_all[0])
1448 if(!is_rail_z_all[1])
1452 tileindex = 3; // crossing
1466 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1467 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1468 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1470 u16 l = getInteriorLight(n, 0, nodedef);
1471 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1473 float d = (float)BS/64;
1477 if (is_rail_x[4] || is_rail_x[5] || is_rail_z[4] || is_rail_z[5])
1478 g = 1; //Object is at a slope
1480 video::S3DVertex vertices[4] =
1482 video::S3DVertex(-s, -s+d,-s, 0,0,0, c,0,1),
1483 video::S3DVertex( s, -s+d,-s, 0,0,0, c,1,1),
1484 video::S3DVertex( s, g*s+d, s, 0,0,0, c,1,0),
1485 video::S3DVertex(-s, g*s+d, s, 0,0,0, c,0,0),
1488 for(s32 i=0; i<4; i++)
1491 vertices[i].Pos.rotateXZBy(angle);
1492 vertices[i].Pos += intToFloat(p, BS);
1495 u16 indices[] = {0,1,2,2,3,0};
1496 collector.append(tile, vertices, 4, indices, 6);
1500 static const v3s16 tile_dirs[6] = {
1510 u16 l = getInteriorLight(n, 1, nodedef);
1511 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1513 v3f pos = intToFloat(p, BS);
1515 std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1516 for(std::vector<aabb3f>::iterator
1518 i != boxes.end(); ++i)
1520 for(int j = 0; j < 6; j++)
1522 // Handles facedir rotation for textures
1523 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1530 if (box.MinEdge.X > box.MaxEdge.X)
1533 box.MinEdge.X=box.MaxEdge.X;
1536 if (box.MinEdge.Y > box.MaxEdge.Y)
1539 box.MinEdge.Y=box.MaxEdge.Y;
1542 if (box.MinEdge.Z > box.MaxEdge.Z)
1545 box.MinEdge.Z=box.MaxEdge.Z;
1550 // Compute texture coords
1551 f32 tx1 = (box.MinEdge.X/BS)+0.5;
1552 f32 ty1 = (box.MinEdge.Y/BS)+0.5;
1553 f32 tz1 = (box.MinEdge.Z/BS)+0.5;
1554 f32 tx2 = (box.MaxEdge.X/BS)+0.5;
1555 f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
1556 f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
1559 tx1, 1-tz2, tx2, 1-tz1,
1563 tz1, 1-ty2, tz2, 1-ty1,
1565 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1567 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1569 tx1, 1-ty2, tx2, 1-ty1,
1571 makeCuboid(&collector, box, tiles, 6, c, txc);
1576 v3f pos = intToFloat(p, BS);
1577 video::SColor c = MapBlock_LightColor(255, getInteriorLight(n, 1, nodedef), f.light_source);
1580 if (f.param_type_2 == CPT2_FACEDIR) {
1581 facedir = n.getFaceDir(nodedef);
1582 } else if (f.param_type_2 == CPT2_WALLMOUNTED) {
1583 //convert wallmounted to 6dfacedir.
1584 //when cache enabled, it is already converted
1585 facedir = n.getWallMounted(nodedef);
1586 if (!enable_mesh_cache) {
1587 static const u8 wm_to_6d[6] = {20, 0, 16+1, 12+3, 8, 4+2};
1588 facedir = wm_to_6d[facedir];
1592 if (f.mesh_ptr[facedir]) {
1593 // use cached meshes
1594 for(u16 j = 0; j < f.mesh_ptr[0]->getMeshBufferCount(); j++) {
1595 scene::IMeshBuffer *buf = f.mesh_ptr[facedir]->getMeshBuffer(j);
1596 collector.append(getNodeTileN(n, p, j, data),
1597 (video::S3DVertex *)buf->getVertices(), buf->getVertexCount(),
1598 buf->getIndices(), buf->getIndexCount(), pos, c);
1600 } else if (f.mesh_ptr[0]) {
1601 // no cache, clone and rotate mesh
1602 scene::IMesh* mesh = cloneMesh(f.mesh_ptr[0]);
1603 rotateMeshBy6dFacedir(mesh, facedir);
1604 recalculateBoundingBox(mesh);
1605 meshmanip->recalculateNormals(mesh, true, false);
1606 for(u16 j = 0; j < mesh->getMeshBufferCount(); j++) {
1607 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
1608 collector.append(getNodeTileN(n, p, j, data),
1609 (video::S3DVertex *)buf->getVertices(), buf->getVertexCount(),
1610 buf->getIndices(), buf->getIndexCount(), pos, c);