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);
166 static inline void getNeighborConnectingFace(v3s16 p, INodeDefManager *nodedef,
167 MeshMakeData *data, MapNode n, int v, int *neighbors)
169 MapNode n2 = data->m_vmanip.getNodeNoEx(p);
170 if (nodedef->nodeboxConnects(n, n2, v))
175 TODO: Fix alpha blending for special nodes
176 Currently only the last element rendered is blended correct
178 void mapblock_mesh_generate_special(MeshMakeData *data,
179 MeshCollector &collector)
181 INodeDefManager *nodedef = data->m_gamedef->ndef();
182 scene::ISceneManager* smgr = data->m_gamedef->getSceneManager();
183 scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator();
186 //TimeTaker timer("mapblock_mesh_generate_special()");
191 bool enable_mesh_cache = g_settings->getBool("enable_mesh_cache");
193 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
195 for(s16 z = 0; z < MAP_BLOCKSIZE; z++)
196 for(s16 y = 0; y < MAP_BLOCKSIZE; y++)
197 for(s16 x = 0; x < MAP_BLOCKSIZE; x++)
201 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
202 const ContentFeatures &f = nodedef->get(n);
204 // Only solidness=0 stuff is drawn here
210 infostream << "Got " << f.drawtype << std::endl;
211 FATAL_ERROR("Unknown drawtype");
218 Add water sources to mesh if using new style
220 TileSpec tile_liquid = f.special_tiles[0];
221 TileSpec tile_liquid_bfculled = getNodeTile(n, p, v3s16(0,0,0), data);
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, nodedef);
231 video::SColor c = MapBlock_LightColor(f.alpha, l, 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, 0,1),
284 video::S3DVertex(BS/2,0,BS/2,0,0,0, c, 1,1),
285 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
286 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
290 If our topside is liquid, set upper border of face
291 at upper border of node
293 if (top_is_same_liquid) {
294 vertices[2].Pos.Y = 0.5 * BS;
295 vertices[3].Pos.Y = 0.5 * BS;
298 Otherwise upper position of face is liquid level
300 vertices[2].Pos.Y = 0.5 * BS;
301 vertices[3].Pos.Y = 0.5 * BS;
304 If neighbor is liquid, lower border of face is liquid level
306 if (neighbor_is_same_liquid) {
307 vertices[0].Pos.Y = 0.5 * BS;
308 vertices[1].Pos.Y = 0.5 * BS;
311 If neighbor is not liquid, lower border of face is
314 vertices[0].Pos.Y = -0.5 * BS;
315 vertices[1].Pos.Y = -0.5 * BS;
318 for(s32 j=0; j<4; j++)
320 if(dir == v3s16(0,0,1))
321 vertices[j].Pos.rotateXZBy(0);
322 if(dir == v3s16(0,0,-1))
323 vertices[j].Pos.rotateXZBy(180);
324 if(dir == v3s16(-1,0,0))
325 vertices[j].Pos.rotateXZBy(90);
326 if(dir == v3s16(1,0,-0))
327 vertices[j].Pos.rotateXZBy(-90);
329 // Do this to not cause glitches when two liquids are
331 /*if(neighbor_is_same_liquid == false){
332 vertices[j].Pos.X *= 0.98;
333 vertices[j].Pos.Z *= 0.98;
336 vertices[j].Pos += intToFloat(p, BS);
339 u16 indices[] = {0,1,2,2,3,0};
340 // Add to mesh collector
341 collector.append(*current_tile, vertices, 4, indices, 6);
347 if(top_is_same_liquid)
350 video::S3DVertex vertices[4] =
352 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
353 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
354 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
355 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
358 v3f offset(p.X * BS, (p.Y + 0.5) * BS, p.Z * BS);
359 for(s32 i=0; i<4; i++)
361 vertices[i].Pos += offset;
364 u16 indices[] = {0,1,2,2,3,0};
365 // Add to mesh collector
366 collector.append(tile_liquid, vertices, 4, indices, 6);
368 case NDT_FLOWINGLIQUID:
371 Add flowing liquid to mesh
373 TileSpec tile_liquid = f.special_tiles[0];
374 TileSpec tile_liquid_bfculled = f.special_tiles[1];
376 bool top_is_same_liquid = false;
377 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
378 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
379 content_t c_source = nodedef->getId(f.liquid_alternative_source);
380 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
381 top_is_same_liquid = true;
384 // If this liquid emits light and doesn't contain light, draw
385 // it at what it emits, for an increased effect
386 u8 light_source = nodedef->get(n).light_source;
387 if(light_source != 0){
388 l = decode_light(light_source);
391 // Use the light of the node on top if possible
392 else if(nodedef->get(ntop).param_type == CPT_LIGHT)
393 l = getInteriorLight(ntop, 0, nodedef);
394 // Otherwise use the light of this node (the liquid)
396 l = getInteriorLight(n, 0, nodedef);
397 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
399 u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
401 // Neighbor liquid levels (key = relative position)
402 // Includes current node
403 std::map<v3s16, f32> neighbor_levels;
404 std::map<v3s16, content_t> neighbor_contents;
405 std::map<v3s16, u8> neighbor_flags;
406 const u8 neighborflag_top_is_same_liquid = 0x01;
407 v3s16 neighbor_dirs[9] = {
418 for(u32 i=0; i<9; i++)
420 content_t content = CONTENT_AIR;
421 float level = -0.5 * BS;
424 v3s16 p2 = p + neighbor_dirs[i];
425 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
426 if(n2.getContent() != CONTENT_IGNORE)
428 content = n2.getContent();
430 if(n2.getContent() == c_source)
432 else if(n2.getContent() == c_flowing){
433 u8 liquid_level = (n2.param2&LIQUID_LEVEL_MASK);
434 if (liquid_level <= LIQUID_LEVEL_MAX+1-range)
437 liquid_level -= (LIQUID_LEVEL_MAX+1-range);
438 level = (-0.5 + ((float)liquid_level + 0.5) / (float)range) * BS;
441 // Check node above neighbor.
442 // NOTE: This doesn't get executed if neighbor
445 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
446 if(n2.getContent() == c_source ||
447 n2.getContent() == c_flowing)
448 flags |= neighborflag_top_is_same_liquid;
451 neighbor_levels[neighbor_dirs[i]] = level;
452 neighbor_contents[neighbor_dirs[i]] = content;
453 neighbor_flags[neighbor_dirs[i]] = flags;
456 // Corner heights (average between four liquids)
457 f32 corner_levels[4];
459 v3s16 halfdirs[4] = {
465 for(u32 i=0; i<4; i++)
467 v3s16 cornerdir = halfdirs[i];
468 float cornerlevel = 0;
471 for(u32 j=0; j<4; j++)
473 v3s16 neighbordir = cornerdir - halfdirs[j];
474 content_t content = neighbor_contents[neighbordir];
475 // If top is liquid, draw starting from top of node
476 if(neighbor_flags[neighbordir] &
477 neighborflag_top_is_same_liquid)
479 cornerlevel = 0.5*BS;
483 // Source is always the same height
484 else if(content == c_source)
486 cornerlevel = 0.5 * BS;
490 // Flowing liquid has level information
491 else if(content == c_flowing)
493 cornerlevel += neighbor_levels[neighbordir];
496 else if(content == CONTENT_AIR)
502 cornerlevel = -0.5*BS+0.2;
503 else if(valid_count > 0)
504 cornerlevel /= valid_count;
505 corner_levels[i] = cornerlevel;
512 v3s16 side_dirs[4] = {
518 s16 side_corners[4][2] = {
524 for(u32 i=0; i<4; i++)
526 v3s16 dir = side_dirs[i];
529 If our topside is liquid and neighbor's topside
530 is liquid, don't draw side face
532 if(top_is_same_liquid &&
533 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
536 content_t neighbor_content = neighbor_contents[dir];
537 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
539 // Don't draw face if neighbor is blocking the view
540 if(n_feat.solidness == 2)
543 bool neighbor_is_same_liquid = (neighbor_content == c_source
544 || neighbor_content == c_flowing);
546 // Don't draw any faces if neighbor same is liquid and top is
548 if(neighbor_is_same_liquid == true
549 && top_is_same_liquid == false)
552 // Use backface culled material if neighbor doesn't have a
554 const TileSpec *current_tile = &tile_liquid;
555 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
556 current_tile = &tile_liquid_bfculled;
558 video::S3DVertex vertices[4] =
560 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
561 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
562 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
563 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
567 If our topside is liquid, set upper border of face
568 at upper border of node
570 if(top_is_same_liquid)
572 vertices[2].Pos.Y = 0.5*BS;
573 vertices[3].Pos.Y = 0.5*BS;
576 Otherwise upper position of face is corner levels
580 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
581 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
585 If neighbor is liquid, lower border of face is corner
588 if(neighbor_is_same_liquid)
590 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
591 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
594 If neighbor is not liquid, lower border of face is
599 vertices[0].Pos.Y = -0.5*BS;
600 vertices[1].Pos.Y = -0.5*BS;
603 for(s32 j=0; j<4; j++)
605 if(dir == v3s16(0,0,1))
606 vertices[j].Pos.rotateXZBy(0);
607 if(dir == v3s16(0,0,-1))
608 vertices[j].Pos.rotateXZBy(180);
609 if(dir == v3s16(-1,0,0))
610 vertices[j].Pos.rotateXZBy(90);
611 if(dir == v3s16(1,0,-0))
612 vertices[j].Pos.rotateXZBy(-90);
614 // Do this to not cause glitches when two liquids are
616 /*if(neighbor_is_same_liquid == false){
617 vertices[j].Pos.X *= 0.98;
618 vertices[j].Pos.Z *= 0.98;
621 vertices[j].Pos += intToFloat(p, BS);
624 u16 indices[] = {0,1,2,2,3,0};
625 // Add to mesh collector
626 collector.append(*current_tile, vertices, 4, indices, 6);
630 Generate top side, if appropriate
633 if(top_is_same_liquid == false)
635 video::S3DVertex vertices[4] =
637 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
638 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
639 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
640 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
643 // To get backface culling right, the vertices need to go
644 // clockwise around the front of the face. And we happened to
645 // calculate corner levels in exact reverse order.
646 s32 corner_resolve[4] = {3,2,1,0};
648 for(s32 i=0; i<4; i++)
650 //vertices[i].Pos.Y += liquid_level;
651 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
652 s32 j = corner_resolve[i];
653 vertices[i].Pos.Y += corner_levels[j];
654 vertices[i].Pos += intToFloat(p, BS);
657 // Default downwards-flowing texture animation goes from
658 // -Z towards +Z, thus the direction is +Z.
659 // Rotate texture to make animation go in flow direction
660 // Positive if liquid moves towards +Z
661 f32 dz = (corner_levels[side_corners[3][0]] +
662 corner_levels[side_corners[3][1]]) -
663 (corner_levels[side_corners[2][0]] +
664 corner_levels[side_corners[2][1]]);
665 // Positive if liquid moves towards +X
666 f32 dx = (corner_levels[side_corners[1][0]] +
667 corner_levels[side_corners[1][1]]) -
668 (corner_levels[side_corners[0][0]] +
669 corner_levels[side_corners[0][1]]);
670 f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG ;
671 v2f tcoord_center(0.5, 0.5);
672 v2f tcoord_translate(
673 blockpos_nodes.Z + z,
674 blockpos_nodes.X + x);
675 tcoord_translate.rotateBy(tcoord_angle);
676 tcoord_translate.X -= floor(tcoord_translate.X);
677 tcoord_translate.Y -= floor(tcoord_translate.Y);
679 for(s32 i=0; i<4; i++)
681 vertices[i].TCoords.rotateBy(
684 vertices[i].TCoords += tcoord_translate;
687 v2f t = vertices[0].TCoords;
688 vertices[0].TCoords = vertices[2].TCoords;
689 vertices[2].TCoords = t;
691 u16 indices[] = {0,1,2,2,3,0};
692 // Add to mesh collector
693 collector.append(tile_liquid, vertices, 4, indices, 6);
698 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
700 u16 l = getInteriorLight(n, 1, nodedef);
701 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
703 for(u32 j=0; j<6; j++)
705 // Check this neighbor
706 v3s16 dir = g_6dirs[j];
707 v3s16 n2p = blockpos_nodes + p + dir;
708 MapNode n2 = data->m_vmanip.getNodeNoEx(n2p);
709 // Don't make face if neighbor is of same type
710 if(n2.getContent() == n.getContent())
714 video::S3DVertex vertices[4] = {
715 video::S3DVertex(-BS/2,-BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 1,1),
716 video::S3DVertex(BS/2,-BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 0,1),
717 video::S3DVertex(BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 0,0),
718 video::S3DVertex(-BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 1,0),
721 // Rotations in the g_6dirs format
723 for(u16 i=0; i<4; i++)
724 vertices[i].Pos.rotateXZBy(0);
725 else if(j == 1) // Y+
726 for(u16 i=0; i<4; i++)
727 vertices[i].Pos.rotateYZBy(-90);
728 else if(j == 2) // X+
729 for(u16 i=0; i<4; i++)
730 vertices[i].Pos.rotateXZBy(-90);
731 else if(j == 3) // Z-
732 for(u16 i=0; i<4; i++)
733 vertices[i].Pos.rotateXZBy(180);
734 else if(j == 4) // Y-
735 for(u16 i=0; i<4; i++)
736 vertices[i].Pos.rotateYZBy(90);
737 else if(j == 5) // X-
738 for(u16 i=0; i<4; i++)
739 vertices[i].Pos.rotateXZBy(90);
741 for(u16 i=0; i<4; i++){
742 vertices[i].Pos += intToFloat(p, BS);
745 u16 indices[] = {0,1,2,2,3,0};
746 // Add to mesh collector
747 collector.append(tile, vertices, 4, indices, 6);
750 case NDT_GLASSLIKE_FRAMED_OPTIONAL:
751 // This is always pre-converted to something else
752 FATAL_ERROR("NDT_GLASSLIKE_FRAMED_OPTIONAL not pre-converted as expected");
754 case NDT_GLASSLIKE_FRAMED:
756 static const v3s16 dirs[6] = {
767 for (i = 0; i < 6; i++)
768 tiles[i] = getNodeTile(n, p, dirs[i], data);
770 TileSpec glass_tiles[6];
771 if (tiles[1].texture && tiles[2].texture && tiles[3].texture) {
772 glass_tiles[0] = tiles[2];
773 glass_tiles[1] = tiles[3];
774 glass_tiles[2] = tiles[1];
775 glass_tiles[3] = tiles[1];
776 glass_tiles[4] = tiles[1];
777 glass_tiles[5] = tiles[1];
779 for (i = 0; i < 6; i++)
780 glass_tiles[i] = tiles[1];
783 u8 param2 = n.getParam2();
784 bool H_merge = ! bool(param2 & 128);
785 bool V_merge = ! bool(param2 & 64);
786 param2 = param2 & 63;
788 u16 l = getInteriorLight(n, 1, nodedef);
789 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
790 v3f pos = intToFloat(p, BS);
791 static const float a = BS / 2;
792 static const float g = a - 0.003;
793 static const float b = .876 * ( BS / 2 );
795 static const aabb3f frame_edges[12] = {
796 aabb3f( b, b,-a, a, a, a), // y+
797 aabb3f(-a, b,-a,-b, a, a), // y+
798 aabb3f( b,-a,-a, a,-b, a), // y-
799 aabb3f(-a,-a,-a,-b,-b, a), // y-
800 aabb3f( b,-a, b, a, a, a), // x+
801 aabb3f( b,-a,-a, a, a,-b), // x+
802 aabb3f(-a,-a, b,-b, a, a), // x-
803 aabb3f(-a,-a,-a,-b, a,-b), // x-
804 aabb3f(-a, b, b, a, a, a), // z+
805 aabb3f(-a,-a, b, a,-b, a), // z+
806 aabb3f(-a,-a,-a, a,-b,-b), // z-
807 aabb3f(-a, b,-a, a, a,-b) // z-
809 static const aabb3f glass_faces[6] = {
810 aabb3f(-g, g,-g, g, g, g), // y+
811 aabb3f(-g,-g,-g, g,-g, g), // y-
812 aabb3f( g,-g,-g, g, g, g), // x+
813 aabb3f(-g,-g,-g,-g, g, g), // x-
814 aabb3f(-g,-g, g, g, g, g), // z+
815 aabb3f(-g,-g,-g, g, g,-g) // z-
818 // table of node visible faces, 0 = invisible
819 int visible_faces[6] = {0,0,0,0,0,0};
821 // table of neighbours, 1 = same type, checked with g_26dirs
822 int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
824 // g_26dirs to check when only horizontal merge is allowed
825 int nb_H_dirs[8] = {0,2,3,5,10,11,12,13};
827 content_t current = n.getContent();
832 // neighbours checks for frames visibility
834 if (!H_merge && V_merge) {
835 n2p = blockpos_nodes + p + g_26dirs[1];
836 n2 = data->m_vmanip.getNodeNoEx(n2p);
837 n2c = n2.getContent();
838 if (n2c == current || n2c == CONTENT_IGNORE)
840 n2p = blockpos_nodes + p + g_26dirs[4];
841 n2 = data->m_vmanip.getNodeNoEx(n2p);
842 n2c = n2.getContent();
843 if (n2c == current || n2c == CONTENT_IGNORE)
845 } else if (H_merge && !V_merge) {
846 for(i = 0; i < 8; i++) {
847 n2p = blockpos_nodes + p + g_26dirs[nb_H_dirs[i]];
848 n2 = data->m_vmanip.getNodeNoEx(n2p);
849 n2c = n2.getContent();
850 if (n2c == current || n2c == CONTENT_IGNORE)
851 nb[nb_H_dirs[i]] = 1;
853 } else if (H_merge && V_merge) {
854 for(i = 0; i < 18; i++) {
855 n2p = blockpos_nodes + p + g_26dirs[i];
856 n2 = data->m_vmanip.getNodeNoEx(n2p);
857 n2c = n2.getContent();
858 if (n2c == current || n2c == CONTENT_IGNORE)
863 // faces visibility checks
866 visible_faces[0] = 1;
867 visible_faces[1] = 1;
869 for(i = 0; i < 2; i++) {
870 n2p = blockpos_nodes + p + dirs[i];
871 n2 = data->m_vmanip.getNodeNoEx(n2p);
872 n2c = n2.getContent();
874 visible_faces[i] = 1;
879 visible_faces[2] = 1;
880 visible_faces[3] = 1;
881 visible_faces[4] = 1;
882 visible_faces[5] = 1;
884 for(i = 2; i < 6; i++) {
885 n2p = blockpos_nodes + p + dirs[i];
886 n2 = data->m_vmanip.getNodeNoEx(n2p);
887 n2c = n2.getContent();
889 visible_faces[i] = 1;
893 static const u8 nb_triplet[12*3] = {
894 1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
895 2,0,11, 2,3,13, 5,0,10, 5,3,12,
896 0,1, 8, 0,4,16, 3,4,17, 3,1, 9
899 f32 tx1, ty1, tz1, tx2, ty2, tz2;
902 for(i = 0; i < 12; i++)
905 if (nb[nb_triplet[i*3+2]])
906 edge_invisible = nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
908 edge_invisible = nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
911 box = frame_edges[i];
914 tx1 = (box.MinEdge.X / BS) + 0.5;
915 ty1 = (box.MinEdge.Y / BS) + 0.5;
916 tz1 = (box.MinEdge.Z / BS) + 0.5;
917 tx2 = (box.MaxEdge.X / BS) + 0.5;
918 ty2 = (box.MaxEdge.Y / BS) + 0.5;
919 tz2 = (box.MaxEdge.Z / BS) + 0.5;
921 tx1, 1-tz2, tx2, 1-tz1,
923 tz1, 1-ty2, tz2, 1-ty1,
924 1-tz2, 1-ty2, 1-tz1, 1-ty1,
925 1-tx2, 1-ty2, 1-tx1, 1-ty1,
926 tx1, 1-ty2, tx2, 1-ty1,
928 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
931 for(i = 0; i < 6; i++)
933 if (!visible_faces[i])
935 box = glass_faces[i];
938 tx1 = (box.MinEdge.X / BS) + 0.5;
939 ty1 = (box.MinEdge.Y / BS) + 0.5;
940 tz1 = (box.MinEdge.Z / BS) + 0.5;
941 tx2 = (box.MaxEdge.X / BS) + 0.5;
942 ty2 = (box.MaxEdge.Y / BS) + 0.5;
943 tz2 = (box.MaxEdge.Z / BS) + 0.5;
945 tx1, 1-tz2, tx2, 1-tz1,
947 tz1, 1-ty2, tz2, 1-ty1,
948 1-tz2, 1-ty2, 1-tz1, 1-ty1,
949 1-tx2, 1-ty2, 1-tx1, 1-ty1,
950 tx1, 1-ty2, tx2, 1-ty1,
952 makeCuboid(&collector, box, &glass_tiles[i], 1, c, txc2);
955 if (param2 > 0 && f.special_tiles[0].texture) {
956 // Interior volume level is in range 0 .. 63,
957 // convert it to -0.5 .. 0.5
958 float vlev = (((float)param2 / 63.0 ) * 2.0 - 1.0);
959 TileSpec interior_tiles[6];
960 for (i = 0; i < 6; i++)
961 interior_tiles[i] = f.special_tiles[0];
962 float offset = 0.003;
963 box = aabb3f(visible_faces[3] ? -b : -a + offset,
964 visible_faces[1] ? -b : -a + offset,
965 visible_faces[5] ? -b : -a + offset,
966 visible_faces[2] ? b : a - offset,
967 visible_faces[0] ? b * vlev : a * vlev - offset,
968 visible_faces[4] ? b : a - offset);
971 tx1 = (box.MinEdge.X / BS) + 0.5;
972 ty1 = (box.MinEdge.Y / BS) + 0.5;
973 tz1 = (box.MinEdge.Z / BS) + 0.5;
974 tx2 = (box.MaxEdge.X / BS) + 0.5;
975 ty2 = (box.MaxEdge.Y / BS) + 0.5;
976 tz2 = (box.MaxEdge.Z / BS) + 0.5;
978 tx1, 1-tz2, tx2, 1-tz1,
980 tz1, 1-ty2, tz2, 1-ty1,
981 1-tz2, 1-ty2, 1-tz1, 1-ty1,
982 1-tx2, 1-ty2, 1-tx1, 1-ty1,
983 tx1, 1-ty2, tx2, 1-ty1,
985 makeCuboid(&collector, box, interior_tiles, 6, c, txc3);
990 TileSpec tile_leaves = getNodeTile(n, p,
993 u16 l = getInteriorLight(n, 1, nodedef);
994 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
996 v3f pos = intToFloat(p, BS);
997 aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
1000 makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
1002 case NDT_ALLFACES_OPTIONAL:
1003 // This is always pre-converted to something else
1004 FATAL_ERROR("NDT_ALLFACES_OPTIONAL not pre-converted");
1008 v3s16 dir = n.getWallMountedDir(nodedef);
1011 if(dir == v3s16(0,-1,0)){
1012 tileindex = 0; // floor
1013 } else if(dir == v3s16(0,1,0)){
1014 tileindex = 1; // ceiling
1015 // For backwards compatibility
1016 } else if(dir == v3s16(0,0,0)){
1017 tileindex = 0; // floor
1019 tileindex = 2; // side
1022 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1023 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1024 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1026 u16 l = getInteriorLight(n, 1, nodedef);
1027 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1029 float s = BS/2*f.visual_scale;
1030 // Wall at X+ of node
1031 video::S3DVertex vertices[4] =
1033 video::S3DVertex(-s,-s,0, 0,0,0, c, 0,1),
1034 video::S3DVertex( s,-s,0, 0,0,0, c, 1,1),
1035 video::S3DVertex( s, s,0, 0,0,0, c, 1,0),
1036 video::S3DVertex(-s, s,0, 0,0,0, c, 0,0),
1039 for(s32 i=0; i<4; i++)
1041 if(dir == v3s16(1,0,0))
1042 vertices[i].Pos.rotateXZBy(0);
1043 if(dir == v3s16(-1,0,0))
1044 vertices[i].Pos.rotateXZBy(180);
1045 if(dir == v3s16(0,0,1))
1046 vertices[i].Pos.rotateXZBy(90);
1047 if(dir == v3s16(0,0,-1))
1048 vertices[i].Pos.rotateXZBy(-90);
1049 if(dir == v3s16(0,-1,0))
1050 vertices[i].Pos.rotateXZBy(45);
1051 if(dir == v3s16(0,1,0))
1052 vertices[i].Pos.rotateXZBy(-45);
1054 vertices[i].Pos += intToFloat(p, BS);
1057 u16 indices[] = {0,1,2,2,3,0};
1058 // Add to mesh collector
1059 collector.append(tile, vertices, 4, indices, 6);
1063 TileSpec tile = getNodeTileN(n, p, 0, data);
1064 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1065 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1067 u16 l = getInteriorLight(n, 0, nodedef);
1068 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1070 float d = (float)BS/16;
1071 float s = BS/2*f.visual_scale;
1072 // Wall at X+ of node
1073 video::S3DVertex vertices[4] =
1075 video::S3DVertex(BS/2-d, s, s, 0,0,0, c, 0,0),
1076 video::S3DVertex(BS/2-d, s, -s, 0,0,0, c, 1,0),
1077 video::S3DVertex(BS/2-d, -s, -s, 0,0,0, c, 1,1),
1078 video::S3DVertex(BS/2-d, -s, s, 0,0,0, c, 0,1),
1081 v3s16 dir = n.getWallMountedDir(nodedef);
1083 for(s32 i=0; i<4; i++)
1085 if(dir == v3s16(1,0,0))
1086 vertices[i].Pos.rotateXZBy(0);
1087 if(dir == v3s16(-1,0,0))
1088 vertices[i].Pos.rotateXZBy(180);
1089 if(dir == v3s16(0,0,1))
1090 vertices[i].Pos.rotateXZBy(90);
1091 if(dir == v3s16(0,0,-1))
1092 vertices[i].Pos.rotateXZBy(-90);
1093 if(dir == v3s16(0,-1,0))
1094 vertices[i].Pos.rotateXYBy(-90);
1095 if(dir == v3s16(0,1,0))
1096 vertices[i].Pos.rotateXYBy(90);
1098 vertices[i].Pos += intToFloat(p, BS);
1101 u16 indices[] = {0,1,2,2,3,0};
1102 // Add to mesh collector
1103 collector.append(tile, vertices, 4, indices, 6);
1107 TileSpec tile = getNodeTileN(n, p, 0, data);
1108 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1110 u16 l = getInteriorLight(n, 1, nodedef);
1111 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1113 float s = BS / 2 * f.visual_scale;
1115 for (int j = 0; j < 2; j++)
1117 video::S3DVertex vertices[4] =
1119 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1120 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1121 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1122 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1124 float rotate_degree = 0;
1125 if (f.param_type_2 == CPT2_DEGROTATE)
1126 rotate_degree = n.param2 * 2;
1129 for(u16 i = 0; i < 4; i++)
1130 vertices[i].Pos.rotateXZBy(46 + rotate_degree);
1131 } else if (j == 1) {
1132 for(u16 i = 0; i < 4; i++)
1133 vertices[i].Pos.rotateXZBy(-44 + rotate_degree);
1136 for (int i = 0; i < 4; i++)
1138 vertices[i].Pos *= f.visual_scale;
1139 vertices[i].Pos.Y += BS/2 * (f.visual_scale - 1);
1140 vertices[i].Pos += intToFloat(p, BS);
1143 u16 indices[] = {0, 1, 2, 2, 3, 0};
1144 // Add to mesh collector
1145 collector.append(tile, vertices, 4, indices, 6);
1150 TileSpec tile = getNodeTileN(n, p, 0, data);
1151 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1153 u16 l = getInteriorLight(n, 1, nodedef);
1154 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1156 float s = BS / 2 * f.visual_scale;
1158 content_t current = n.getContent();
1163 static const v3s16 dirs[6] = {
1172 int doDraw[6] = {0, 0, 0, 0, 0, 0};
1174 bool drawAllFaces = true;
1176 // Check for adjacent nodes
1177 for (int i = 0; i < 6; i++) {
1178 n2p = blockpos_nodes + p + dirs[i];
1179 n2 = data->m_vmanip.getNodeNoEx(n2p);
1180 n2c = n2.getContent();
1181 if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) {
1184 drawAllFaces = false;
1189 for (int j = 0; j < 6; j++) {
1191 video::S3DVertex vertices[4] = {
1192 video::S3DVertex(-s, -BS / 2, 0, 0, 0, 0, c, 0, 1),
1193 video::S3DVertex( s, -BS / 2, 0, 0, 0, 0, c, 1, 1),
1194 video::S3DVertex( s, -BS / 2 + s * 2, 0, 0, 0, 0, c, 1, 0),
1195 video::S3DVertex(-s, -BS / 2 + s * 2, 0, 0, 0, 0, c, 0, 0),
1198 // Calculate which faces should be drawn, (top or sides)
1199 if (j == 0 && (drawAllFaces ||
1200 (doDraw[3] == 1 || doDraw[1] == 1))) {
1201 for (int i = 0; i < 4; i++) {
1202 vertices[i].Pos.rotateXZBy(90);
1203 vertices[i].Pos.rotateXYBy(-10);
1204 vertices[i].Pos.X -= 4.0;
1206 } else if (j == 1 && (drawAllFaces ||
1207 (doDraw[5] == 1 || doDraw[1] == 1))) {
1208 for (int i = 0; i < 4; i++) {
1209 vertices[i].Pos.rotateXZBy(180);
1210 vertices[i].Pos.rotateYZBy(10);
1211 vertices[i].Pos.Z -= 4.0;
1213 } else if (j == 2 && (drawAllFaces ||
1214 (doDraw[2] == 1 || doDraw[1] == 1))) {
1215 for (int i = 0; i < 4; i++) {
1216 vertices[i].Pos.rotateXZBy(270);
1217 vertices[i].Pos.rotateXYBy(10);
1218 vertices[i].Pos.X += 4.0;
1220 } else if (j == 3 && (drawAllFaces ||
1221 (doDraw[4] == 1 || doDraw[1] == 1))) {
1222 for (int i = 0; i < 4; i++) {
1223 vertices[i].Pos.rotateYZBy(-10);
1224 vertices[i].Pos.Z += 4.0;
1226 // Center cross-flames
1227 } else if (j == 4 && (drawAllFaces || doDraw[1] == 1)) {
1228 for (int i = 0; i < 4; i++) {
1229 vertices[i].Pos.rotateXZBy(45);
1231 } else if (j == 5 && (drawAllFaces || doDraw[1] == 1)) {
1232 for (int i = 0; i < 4; i++) {
1233 vertices[i].Pos.rotateXZBy(-45);
1235 // Render flames on bottom of node above
1236 } else if (j == 0 && doDraw[0] == 1 && doDraw[1] == 0) {
1237 for (int i = 0; i < 4; i++) {
1238 vertices[i].Pos.rotateYZBy(70);
1239 vertices[i].Pos.rotateXZBy(90);
1240 vertices[i].Pos.Y += 4.84;
1241 vertices[i].Pos.X -= 4.7;
1243 } else if (j == 1 && doDraw[0] == 1 && doDraw[1] == 0) {
1244 for (int i = 0; i < 4; i++) {
1245 vertices[i].Pos.rotateYZBy(70);
1246 vertices[i].Pos.rotateXZBy(180);
1247 vertices[i].Pos.Y += 4.84;
1248 vertices[i].Pos.Z -= 4.7;
1250 } else if (j == 2 && doDraw[0] == 1 && doDraw[1] == 0) {
1251 for (int i = 0; i < 4; i++) {
1252 vertices[i].Pos.rotateYZBy(70);
1253 vertices[i].Pos.rotateXZBy(270);
1254 vertices[i].Pos.Y += 4.84;
1255 vertices[i].Pos.X += 4.7;
1257 } else if (j == 3 && doDraw[0] == 1 && doDraw[1] == 0) {
1258 for (int i = 0; i < 4; i++) {
1259 vertices[i].Pos.rotateYZBy(70);
1260 vertices[i].Pos.Y += 4.84;
1261 vertices[i].Pos.Z += 4.7;
1264 // Skip faces that aren't adjacent to a node
1268 for (int i = 0; i < 4; i++) {
1269 vertices[i].Pos *= f.visual_scale;
1270 vertices[i].Pos += intToFloat(p, BS);
1273 u16 indices[] = {0, 1, 2, 2, 3, 0};
1274 // Add to mesh collector
1275 collector.append(tile, vertices, 4, indices, 6);
1280 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1281 TileSpec tile_nocrack = tile;
1282 tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1284 // Put wood the right way around in the posts
1285 TileSpec tile_rot = tile;
1286 tile_rot.rotation = 1;
1288 u16 l = getInteriorLight(n, 1, nodedef);
1289 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1291 const f32 post_rad=(f32)BS/8;
1292 const f32 bar_rad=(f32)BS/16;
1293 const f32 bar_len=(f32)(BS/2)-post_rad;
1295 v3f pos = intToFloat(p, BS);
1297 // The post - always present
1298 aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
1299 post.MinEdge += pos;
1300 post.MaxEdge += pos;
1302 6/16.,6/16.,10/16.,10/16.,
1303 6/16.,6/16.,10/16.,10/16.,
1308 makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1310 // Now a section of fence, +X, if there's a post there
1313 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1314 const ContentFeatures *f2 = &nodedef->get(n2);
1315 if(f2->drawtype == NDT_FENCELIKE)
1317 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1318 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1322 0/16.,2/16.,16/16.,4/16.,
1323 0/16.,4/16.,16/16.,6/16.,
1324 6/16.,6/16.,8/16.,8/16.,
1325 10/16.,10/16.,12/16.,12/16.,
1326 0/16.,8/16.,16/16.,10/16.,
1327 0/16.,14/16.,16/16.,16/16.};
1328 makeCuboid(&collector, bar, &tile_nocrack, 1,
1330 bar.MinEdge.Y -= BS/2;
1331 bar.MaxEdge.Y -= BS/2;
1332 makeCuboid(&collector, bar, &tile_nocrack, 1,
1336 // Now a section of fence, +Z, if there's a post there
1339 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1340 f2 = &nodedef->get(n2);
1341 if(f2->drawtype == NDT_FENCELIKE)
1343 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1344 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1348 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
1349 4/16.,1/16.,6/16.,5/16., // for wood texture instead
1350 0/16.,9/16.,16/16.,11/16.,
1351 0/16.,6/16.,16/16.,8/16.,
1352 6/16.,6/16.,8/16.,8/16.,
1353 10/16.,10/16.,12/16.,12/16.};
1354 makeCuboid(&collector, bar, &tile_nocrack, 1,
1356 bar.MinEdge.Y -= BS/2;
1357 bar.MaxEdge.Y -= BS/2;
1358 makeCuboid(&collector, bar, &tile_nocrack, 1,
1364 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) */
1367 content_t thiscontent = n.getContent();
1368 std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
1369 int self_group = ((ItemGroupList) nodedef->get(n).groups)[groupname];
1372 for (s8 y0 = -1; y0 <= 1; y0++) {
1373 // Prevent from indexing never used coordinates
1374 for (s8 xz = -1; xz <= 1; xz++) {
1377 MapNode n_xy = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x + xz, y + y0, z));
1378 MapNode n_zy = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y + y0, z + xz));
1379 ContentFeatures def_xy = nodedef->get(n_xy);
1380 ContentFeatures def_zy = nodedef->get(n_zy);
1382 // Check if current node would connect with the rail
1383 is_rail_x[index] = ((def_xy.drawtype == NDT_RAILLIKE
1384 && ((ItemGroupList) def_xy.groups)[groupname] == self_group)
1385 || n_xy.getContent() == thiscontent);
1387 is_rail_z[index] = ((def_zy.drawtype == NDT_RAILLIKE
1388 && ((ItemGroupList) def_zy.groups)[groupname] == self_group)
1389 || n_zy.getContent() == thiscontent);
1394 bool is_rail_x_all[2]; // [0] = negative x, [1] = positive x coordinate from the current node position
1395 bool is_rail_z_all[2];
1396 is_rail_x_all[0] = is_rail_x[0] || is_rail_x[2] || is_rail_x[4];
1397 is_rail_x_all[1] = is_rail_x[1] || is_rail_x[3] || is_rail_x[5];
1398 is_rail_z_all[0] = is_rail_z[0] || is_rail_z[2] || is_rail_z[4];
1399 is_rail_z_all[1] = is_rail_z[1] || is_rail_z[3] || is_rail_z[5];
1401 // reasonable default, flat straight unrotated rail
1402 bool is_straight = true;
1403 int adjacencies = 0;
1407 // check for sloped rail
1408 if (is_rail_x[4] || is_rail_x[5] || is_rail_z[4] || is_rail_z[5]) {
1409 adjacencies = 5; // 5 means sloped
1410 is_straight = true; // sloped is always straight
1412 // is really straight, rails on both sides
1413 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
1414 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
1417 switch (adjacencies) {
1419 if (is_rail_x_all[0] || is_rail_x_all[1])
1424 tileindex = 1; // curved
1425 if (is_rail_x_all[0] && is_rail_x_all[1])
1427 if (is_rail_z_all[0] && is_rail_z_all[1]) {
1431 else if (is_rail_x_all[0] && is_rail_z_all[0])
1433 else if (is_rail_x_all[0] && is_rail_z_all[1])
1435 else if (is_rail_x_all[1] && is_rail_z_all[1])
1439 // here is where the potential to 'switch' a junction is, but not implemented at present
1440 tileindex = 2; // t-junction
1441 if(!is_rail_x_all[1])
1443 if(!is_rail_z_all[0])
1445 if(!is_rail_z_all[1])
1449 tileindex = 3; // crossing
1463 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1464 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1465 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1467 u16 l = getInteriorLight(n, 0, nodedef);
1468 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1470 float d = (float)BS/64;
1474 if (is_rail_x[4] || is_rail_x[5] || is_rail_z[4] || is_rail_z[5])
1475 g = 1; //Object is at a slope
1477 video::S3DVertex vertices[4] =
1479 video::S3DVertex(-s, -s+d,-s, 0,0,0, c,0,1),
1480 video::S3DVertex( s, -s+d,-s, 0,0,0, c,1,1),
1481 video::S3DVertex( s, g*s+d, s, 0,0,0, c,1,0),
1482 video::S3DVertex(-s, g*s+d, s, 0,0,0, c,0,0),
1485 for(s32 i=0; i<4; i++)
1488 vertices[i].Pos.rotateXZBy(angle);
1489 vertices[i].Pos += intToFloat(p, BS);
1492 u16 indices[] = {0,1,2,2,3,0};
1493 collector.append(tile, vertices, 4, indices, 6);
1497 static const v3s16 tile_dirs[6] = {
1507 u16 l = getInteriorLight(n, 1, nodedef);
1508 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1510 v3f pos = intToFloat(p, BS);
1514 // locate possible neighboring nodes to connect to
1515 if (f.node_box.type == NODEBOX_CONNECTED) {
1519 getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 1, &neighbors);
1523 getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 2, &neighbors);
1527 getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 4, &neighbors);
1531 getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 8, &neighbors);
1535 getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 16, &neighbors);
1539 getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 32, &neighbors);
1542 std::vector<aabb3f> boxes;
1543 n.getNodeBoxes(nodedef, &boxes, neighbors);
1544 for(std::vector<aabb3f>::iterator
1546 i != boxes.end(); ++i)
1548 for(int j = 0; j < 6; j++)
1550 // Handles facedir rotation for textures
1551 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1558 if (box.MinEdge.X > box.MaxEdge.X)
1561 box.MinEdge.X=box.MaxEdge.X;
1564 if (box.MinEdge.Y > box.MaxEdge.Y)
1567 box.MinEdge.Y=box.MaxEdge.Y;
1570 if (box.MinEdge.Z > box.MaxEdge.Z)
1573 box.MinEdge.Z=box.MaxEdge.Z;
1578 // Compute texture coords
1579 f32 tx1 = (box.MinEdge.X/BS)+0.5;
1580 f32 ty1 = (box.MinEdge.Y/BS)+0.5;
1581 f32 tz1 = (box.MinEdge.Z/BS)+0.5;
1582 f32 tx2 = (box.MaxEdge.X/BS)+0.5;
1583 f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
1584 f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
1587 tx1, 1-tz2, tx2, 1-tz1,
1591 tz1, 1-ty2, tz2, 1-ty1,
1593 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1595 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1597 tx1, 1-ty2, tx2, 1-ty1,
1599 makeCuboid(&collector, box, tiles, 6, c, txc);
1604 v3f pos = intToFloat(p, BS);
1605 video::SColor c = MapBlock_LightColor(255, getInteriorLight(n, 1, nodedef), f.light_source);
1608 if (f.param_type_2 == CPT2_FACEDIR) {
1609 facedir = n.getFaceDir(nodedef);
1610 } else if (f.param_type_2 == CPT2_WALLMOUNTED) {
1611 //convert wallmounted to 6dfacedir.
1612 //when cache enabled, it is already converted
1613 facedir = n.getWallMounted(nodedef);
1614 if (!enable_mesh_cache) {
1615 static const u8 wm_to_6d[6] = {20, 0, 16+1, 12+3, 8, 4+2};
1616 facedir = wm_to_6d[facedir];
1620 if (f.mesh_ptr[facedir]) {
1621 // use cached meshes
1622 for(u16 j = 0; j < f.mesh_ptr[0]->getMeshBufferCount(); j++) {
1623 scene::IMeshBuffer *buf = f.mesh_ptr[facedir]->getMeshBuffer(j);
1624 collector.append(getNodeTileN(n, p, j, data),
1625 (video::S3DVertex *)buf->getVertices(), buf->getVertexCount(),
1626 buf->getIndices(), buf->getIndexCount(), pos, c);
1628 } else if (f.mesh_ptr[0]) {
1629 // no cache, clone and rotate mesh
1630 scene::IMesh* mesh = cloneMesh(f.mesh_ptr[0]);
1631 rotateMeshBy6dFacedir(mesh, facedir);
1632 recalculateBoundingBox(mesh);
1633 meshmanip->recalculateNormals(mesh, true, false);
1634 for(u16 j = 0; j < mesh->getMeshBufferCount(); j++) {
1635 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
1636 collector.append(getNodeTileN(n, p, j, data),
1637 (video::S3DVertex *)buf->getVertices(), buf->getVertexCount(),
1638 buf->getIndices(), buf->getIndexCount(), pos, c);