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");
185 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
187 for(s16 z = 0; z < MAP_BLOCKSIZE; z++)
188 for(s16 y = 0; y < MAP_BLOCKSIZE; y++)
189 for(s16 x = 0; x < MAP_BLOCKSIZE; x++)
193 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
194 const ContentFeatures &f = nodedef->get(n);
196 // Only solidness=0 stuff is drawn here
202 infostream << "Got " << f.drawtype << std::endl;
203 FATAL_ERROR("Unknown drawtype");
210 Add water sources to mesh if using new style
212 TileSpec tile_liquid = f.special_tiles[0];
213 TileSpec tile_liquid_bfculled = getNodeTile(n, p, v3s16(0,0,0), data);
215 bool top_is_same_liquid = false;
216 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
217 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
218 content_t c_source = nodedef->getId(f.liquid_alternative_source);
219 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
220 top_is_same_liquid = true;
222 u16 l = getInteriorLight(n, 0, nodedef);
223 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
228 v3s16 side_dirs[4] = {
234 for(u32 i=0; i<4; i++)
236 v3s16 dir = side_dirs[i];
238 MapNode neighbor = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir);
239 content_t neighbor_content = neighbor.getContent();
240 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
241 MapNode n_top = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir+ v3s16(0,1,0));
242 content_t n_top_c = n_top.getContent();
244 if(neighbor_content == CONTENT_IGNORE)
248 If our topside is liquid and neighbor's topside
249 is liquid, don't draw side face
251 if(top_is_same_liquid && (n_top_c == c_flowing ||
252 n_top_c == c_source || n_top_c == CONTENT_IGNORE))
255 // Don't draw face if neighbor is blocking the view
256 if(n_feat.solidness == 2)
259 bool neighbor_is_same_liquid = (neighbor_content == c_source
260 || neighbor_content == c_flowing);
262 // Don't draw any faces if neighbor same is liquid and top is
264 if(neighbor_is_same_liquid && !top_is_same_liquid)
267 // Use backface culled material if neighbor doesn't have a
269 const TileSpec *current_tile = &tile_liquid;
270 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
271 current_tile = &tile_liquid_bfculled;
273 video::S3DVertex vertices[4] =
275 video::S3DVertex(-BS/2,0,BS/2,0,0,0, c, 0,1),
276 video::S3DVertex(BS/2,0,BS/2,0,0,0, c, 1,1),
277 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
278 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
282 If our topside is liquid, set upper border of face
283 at upper border of node
285 if (top_is_same_liquid) {
286 vertices[2].Pos.Y = 0.5 * BS;
287 vertices[3].Pos.Y = 0.5 * BS;
290 Otherwise upper position of face is liquid level
292 vertices[2].Pos.Y = 0.5 * BS;
293 vertices[3].Pos.Y = 0.5 * BS;
296 If neighbor is liquid, lower border of face is liquid level
298 if (neighbor_is_same_liquid) {
299 vertices[0].Pos.Y = 0.5 * BS;
300 vertices[1].Pos.Y = 0.5 * BS;
303 If neighbor is not liquid, lower border of face is
306 vertices[0].Pos.Y = -0.5 * BS;
307 vertices[1].Pos.Y = -0.5 * BS;
310 for(s32 j=0; j<4; j++)
312 if(dir == v3s16(0,0,1))
313 vertices[j].Pos.rotateXZBy(0);
314 if(dir == v3s16(0,0,-1))
315 vertices[j].Pos.rotateXZBy(180);
316 if(dir == v3s16(-1,0,0))
317 vertices[j].Pos.rotateXZBy(90);
318 if(dir == v3s16(1,0,-0))
319 vertices[j].Pos.rotateXZBy(-90);
321 // Do this to not cause glitches when two liquids are
323 /*if(neighbor_is_same_liquid == false){
324 vertices[j].Pos.X *= 0.98;
325 vertices[j].Pos.Z *= 0.98;
328 vertices[j].Pos += intToFloat(p, BS);
331 u16 indices[] = {0,1,2,2,3,0};
332 // Add to mesh collector
333 collector.append(*current_tile, vertices, 4, indices, 6);
339 if(top_is_same_liquid)
342 video::S3DVertex vertices[4] =
344 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
345 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
346 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
347 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
350 v3f offset(p.X * BS, (p.Y + 0.5) * BS, p.Z * BS);
351 for(s32 i=0; i<4; i++)
353 vertices[i].Pos += offset;
356 u16 indices[] = {0,1,2,2,3,0};
357 // Add to mesh collector
358 collector.append(tile_liquid, vertices, 4, indices, 6);
360 case NDT_FLOWINGLIQUID:
363 Add flowing liquid to mesh
365 TileSpec tile_liquid = f.special_tiles[0];
366 TileSpec tile_liquid_bfculled = f.special_tiles[1];
368 bool top_is_same_liquid = false;
369 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
370 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
371 content_t c_source = nodedef->getId(f.liquid_alternative_source);
372 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
373 top_is_same_liquid = true;
376 // If this liquid emits light and doesn't contain light, draw
377 // it at what it emits, for an increased effect
378 u8 light_source = nodedef->get(n).light_source;
379 if(light_source != 0){
380 l = decode_light(light_source);
383 // Use the light of the node on top if possible
384 else if(nodedef->get(ntop).param_type == CPT_LIGHT)
385 l = getInteriorLight(ntop, 0, nodedef);
386 // Otherwise use the light of this node (the liquid)
388 l = getInteriorLight(n, 0, nodedef);
389 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
391 u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
393 // Neighbor liquid levels (key = relative position)
394 // Includes current node
395 std::map<v3s16, f32> neighbor_levels;
396 std::map<v3s16, content_t> neighbor_contents;
397 std::map<v3s16, u8> neighbor_flags;
398 const u8 neighborflag_top_is_same_liquid = 0x01;
399 v3s16 neighbor_dirs[9] = {
410 for(u32 i=0; i<9; i++)
412 content_t content = CONTENT_AIR;
413 float level = -0.5 * BS;
416 v3s16 p2 = p + neighbor_dirs[i];
417 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
418 if(n2.getContent() != CONTENT_IGNORE)
420 content = n2.getContent();
422 if(n2.getContent() == c_source)
424 else if(n2.getContent() == c_flowing){
425 u8 liquid_level = (n2.param2&LIQUID_LEVEL_MASK);
426 if (liquid_level <= LIQUID_LEVEL_MAX+1-range)
429 liquid_level -= (LIQUID_LEVEL_MAX+1-range);
430 level = (-0.5 + ((float)liquid_level + 0.5) / (float)range) * BS;
433 // Check node above neighbor.
434 // NOTE: This doesn't get executed if neighbor
437 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
438 if(n2.getContent() == c_source ||
439 n2.getContent() == c_flowing)
440 flags |= neighborflag_top_is_same_liquid;
443 neighbor_levels[neighbor_dirs[i]] = level;
444 neighbor_contents[neighbor_dirs[i]] = content;
445 neighbor_flags[neighbor_dirs[i]] = flags;
448 // Corner heights (average between four liquids)
449 f32 corner_levels[4];
451 v3s16 halfdirs[4] = {
457 for(u32 i=0; i<4; i++)
459 v3s16 cornerdir = halfdirs[i];
460 float cornerlevel = 0;
463 for(u32 j=0; j<4; j++)
465 v3s16 neighbordir = cornerdir - halfdirs[j];
466 content_t content = neighbor_contents[neighbordir];
467 // If top is liquid, draw starting from top of node
468 if(neighbor_flags[neighbordir] &
469 neighborflag_top_is_same_liquid)
471 cornerlevel = 0.5*BS;
475 // Source is always the same height
476 else if(content == c_source)
478 cornerlevel = 0.5 * BS;
482 // Flowing liquid has level information
483 else if(content == c_flowing)
485 cornerlevel += neighbor_levels[neighbordir];
488 else if(content == CONTENT_AIR)
494 cornerlevel = -0.5*BS+0.2;
495 else if(valid_count > 0)
496 cornerlevel /= valid_count;
497 corner_levels[i] = cornerlevel;
504 v3s16 side_dirs[4] = {
510 s16 side_corners[4][2] = {
516 for(u32 i=0; i<4; i++)
518 v3s16 dir = side_dirs[i];
521 If our topside is liquid and neighbor's topside
522 is liquid, don't draw side face
524 if(top_is_same_liquid &&
525 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
528 content_t neighbor_content = neighbor_contents[dir];
529 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
531 // Don't draw face if neighbor is blocking the view
532 if(n_feat.solidness == 2)
535 bool neighbor_is_same_liquid = (neighbor_content == c_source
536 || neighbor_content == c_flowing);
538 // Don't draw any faces if neighbor same is liquid and top is
540 if(neighbor_is_same_liquid == true
541 && top_is_same_liquid == false)
544 // Use backface culled material if neighbor doesn't have a
546 const TileSpec *current_tile = &tile_liquid;
547 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
548 current_tile = &tile_liquid_bfculled;
550 video::S3DVertex vertices[4] =
552 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
553 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
554 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
555 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
559 If our topside is liquid, set upper border of face
560 at upper border of node
562 if(top_is_same_liquid)
564 vertices[2].Pos.Y = 0.5*BS;
565 vertices[3].Pos.Y = 0.5*BS;
568 Otherwise upper position of face is corner levels
572 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
573 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
577 If neighbor is liquid, lower border of face is corner
580 if(neighbor_is_same_liquid)
582 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
583 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
586 If neighbor is not liquid, lower border of face is
591 vertices[0].Pos.Y = -0.5*BS;
592 vertices[1].Pos.Y = -0.5*BS;
595 for(s32 j=0; j<4; j++)
597 if(dir == v3s16(0,0,1))
598 vertices[j].Pos.rotateXZBy(0);
599 if(dir == v3s16(0,0,-1))
600 vertices[j].Pos.rotateXZBy(180);
601 if(dir == v3s16(-1,0,0))
602 vertices[j].Pos.rotateXZBy(90);
603 if(dir == v3s16(1,0,-0))
604 vertices[j].Pos.rotateXZBy(-90);
606 // Do this to not cause glitches when two liquids are
608 /*if(neighbor_is_same_liquid == false){
609 vertices[j].Pos.X *= 0.98;
610 vertices[j].Pos.Z *= 0.98;
613 vertices[j].Pos += intToFloat(p, BS);
616 u16 indices[] = {0,1,2,2,3,0};
617 // Add to mesh collector
618 collector.append(*current_tile, vertices, 4, indices, 6);
622 Generate top side, if appropriate
625 if(top_is_same_liquid == false)
627 video::S3DVertex vertices[4] =
629 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
630 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
631 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
632 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
635 // To get backface culling right, the vertices need to go
636 // clockwise around the front of the face. And we happened to
637 // calculate corner levels in exact reverse order.
638 s32 corner_resolve[4] = {3,2,1,0};
640 for(s32 i=0; i<4; i++)
642 //vertices[i].Pos.Y += liquid_level;
643 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
644 s32 j = corner_resolve[i];
645 vertices[i].Pos.Y += corner_levels[j];
646 vertices[i].Pos += intToFloat(p, BS);
649 // Default downwards-flowing texture animation goes from
650 // -Z towards +Z, thus the direction is +Z.
651 // Rotate texture to make animation go in flow direction
652 // Positive if liquid moves towards +Z
653 f32 dz = (corner_levels[side_corners[3][0]] +
654 corner_levels[side_corners[3][1]]) -
655 (corner_levels[side_corners[2][0]] +
656 corner_levels[side_corners[2][1]]);
657 // Positive if liquid moves towards +X
658 f32 dx = (corner_levels[side_corners[1][0]] +
659 corner_levels[side_corners[1][1]]) -
660 (corner_levels[side_corners[0][0]] +
661 corner_levels[side_corners[0][1]]);
662 f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG ;
663 v2f tcoord_center(0.5, 0.5);
664 v2f tcoord_translate(
665 blockpos_nodes.Z + z,
666 blockpos_nodes.X + x);
667 tcoord_translate.rotateBy(tcoord_angle);
668 tcoord_translate.X -= floor(tcoord_translate.X);
669 tcoord_translate.Y -= floor(tcoord_translate.Y);
671 for(s32 i=0; i<4; i++)
673 vertices[i].TCoords.rotateBy(
676 vertices[i].TCoords += tcoord_translate;
679 v2f t = vertices[0].TCoords;
680 vertices[0].TCoords = vertices[2].TCoords;
681 vertices[2].TCoords = t;
683 u16 indices[] = {0,1,2,2,3,0};
684 // Add to mesh collector
685 collector.append(tile_liquid, vertices, 4, indices, 6);
690 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
692 u16 l = getInteriorLight(n, 1, nodedef);
693 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
695 for(u32 j=0; j<6; j++)
697 // Check this neighbor
698 v3s16 dir = g_6dirs[j];
699 v3s16 n2p = blockpos_nodes + p + dir;
700 MapNode n2 = data->m_vmanip.getNodeNoEx(n2p);
701 // Don't make face if neighbor is of same type
702 if(n2.getContent() == n.getContent())
706 video::S3DVertex vertices[4] = {
707 video::S3DVertex(-BS/2,-BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 1,1),
708 video::S3DVertex(BS/2,-BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 0,1),
709 video::S3DVertex(BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 0,0),
710 video::S3DVertex(-BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 1,0),
713 // Rotations in the g_6dirs format
715 for(u16 i=0; i<4; i++)
716 vertices[i].Pos.rotateXZBy(0);
717 else if(j == 1) // Y+
718 for(u16 i=0; i<4; i++)
719 vertices[i].Pos.rotateYZBy(-90);
720 else if(j == 2) // X+
721 for(u16 i=0; i<4; i++)
722 vertices[i].Pos.rotateXZBy(-90);
723 else if(j == 3) // Z-
724 for(u16 i=0; i<4; i++)
725 vertices[i].Pos.rotateXZBy(180);
726 else if(j == 4) // Y-
727 for(u16 i=0; i<4; i++)
728 vertices[i].Pos.rotateYZBy(90);
729 else if(j == 5) // X-
730 for(u16 i=0; i<4; i++)
731 vertices[i].Pos.rotateXZBy(90);
733 for(u16 i=0; i<4; i++){
734 vertices[i].Pos += intToFloat(p, BS);
737 u16 indices[] = {0,1,2,2,3,0};
738 // Add to mesh collector
739 collector.append(tile, vertices, 4, indices, 6);
742 case NDT_GLASSLIKE_FRAMED_OPTIONAL:
743 // This is always pre-converted to something else
744 FATAL_ERROR("NDT_GLASSLIKE_FRAMED_OPTIONAL not pre-converted as expected");
746 case NDT_GLASSLIKE_FRAMED:
748 static const v3s16 dirs[6] = {
759 for (i = 0; i < 6; i++)
760 tiles[i] = getNodeTile(n, p, dirs[i], data);
762 TileSpec glass_tiles[6];
763 if (tiles[1].texture && tiles[2].texture && tiles[3].texture) {
764 glass_tiles[0] = tiles[2];
765 glass_tiles[1] = tiles[3];
766 glass_tiles[2] = tiles[1];
767 glass_tiles[3] = tiles[1];
768 glass_tiles[4] = tiles[1];
769 glass_tiles[5] = tiles[1];
771 for (i = 0; i < 6; i++)
772 glass_tiles[i] = tiles[1];
775 u8 param2 = n.getParam2();
776 bool H_merge = ! bool(param2 & 128);
777 bool V_merge = ! bool(param2 & 64);
778 param2 = param2 & 63;
780 u16 l = getInteriorLight(n, 1, nodedef);
781 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
782 v3f pos = intToFloat(p, BS);
783 static const float a = BS / 2;
784 static const float g = a - 0.003;
785 static const float b = .876 * ( BS / 2 );
787 static const aabb3f frame_edges[12] = {
788 aabb3f( b, b,-a, a, a, a), // y+
789 aabb3f(-a, b,-a,-b, a, a), // y+
790 aabb3f( b,-a,-a, a,-b, a), // y-
791 aabb3f(-a,-a,-a,-b,-b, a), // y-
792 aabb3f( b,-a, b, a, a, a), // x+
793 aabb3f( b,-a,-a, a, a,-b), // x+
794 aabb3f(-a,-a, b,-b, a, a), // x-
795 aabb3f(-a,-a,-a,-b, a,-b), // x-
796 aabb3f(-a, b, b, a, a, a), // z+
797 aabb3f(-a,-a, b, a,-b, a), // z+
798 aabb3f(-a,-a,-a, a,-b,-b), // z-
799 aabb3f(-a, b,-a, a, a,-b) // z-
801 static const aabb3f glass_faces[6] = {
802 aabb3f(-g, g,-g, g, g, g), // y+
803 aabb3f(-g,-g,-g, g,-g, g), // y-
804 aabb3f( g,-g,-g, g, g, g), // x+
805 aabb3f(-g,-g,-g,-g, g, g), // x-
806 aabb3f(-g,-g, g, g, g, g), // z+
807 aabb3f(-g,-g,-g, g, g,-g) // z-
810 // table of node visible faces, 0 = invisible
811 int visible_faces[6] = {0,0,0,0,0,0};
813 // table of neighbours, 1 = same type, checked with g_26dirs
814 int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
816 // g_26dirs to check when only horizontal merge is allowed
817 int nb_H_dirs[8] = {0,2,3,5,10,11,12,13};
819 content_t current = n.getContent();
824 // neighbours checks for frames visibility
826 if (!H_merge && V_merge) {
827 n2p = blockpos_nodes + p + g_26dirs[1];
828 n2 = data->m_vmanip.getNodeNoEx(n2p);
829 n2c = n2.getContent();
830 if (n2c == current || n2c == CONTENT_IGNORE)
832 n2p = blockpos_nodes + p + g_26dirs[4];
833 n2 = data->m_vmanip.getNodeNoEx(n2p);
834 n2c = n2.getContent();
835 if (n2c == current || n2c == CONTENT_IGNORE)
837 } else if (H_merge && !V_merge) {
838 for(i = 0; i < 8; i++) {
839 n2p = blockpos_nodes + p + g_26dirs[nb_H_dirs[i]];
840 n2 = data->m_vmanip.getNodeNoEx(n2p);
841 n2c = n2.getContent();
842 if (n2c == current || n2c == CONTENT_IGNORE)
843 nb[nb_H_dirs[i]] = 1;
845 } else if (H_merge && V_merge) {
846 for(i = 0; i < 18; i++) {
847 n2p = blockpos_nodes + p + g_26dirs[i];
848 n2 = data->m_vmanip.getNodeNoEx(n2p);
849 n2c = n2.getContent();
850 if (n2c == current || n2c == CONTENT_IGNORE)
855 // faces visibility checks
858 visible_faces[0] = 1;
859 visible_faces[1] = 1;
861 for(i = 0; i < 2; i++) {
862 n2p = blockpos_nodes + p + dirs[i];
863 n2 = data->m_vmanip.getNodeNoEx(n2p);
864 n2c = n2.getContent();
866 visible_faces[i] = 1;
871 visible_faces[2] = 1;
872 visible_faces[3] = 1;
873 visible_faces[4] = 1;
874 visible_faces[5] = 1;
876 for(i = 2; i < 6; i++) {
877 n2p = blockpos_nodes + p + dirs[i];
878 n2 = data->m_vmanip.getNodeNoEx(n2p);
879 n2c = n2.getContent();
881 visible_faces[i] = 1;
885 static const u8 nb_triplet[12*3] = {
886 1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
887 2,0,11, 2,3,13, 5,0,10, 5,3,12,
888 0,1, 8, 0,4,16, 3,4,17, 3,1, 9
891 f32 tx1, ty1, tz1, tx2, ty2, tz2;
894 for(i = 0; i < 12; i++)
897 if (nb[nb_triplet[i*3+2]])
898 edge_invisible = nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
900 edge_invisible = nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
903 box = frame_edges[i];
906 tx1 = (box.MinEdge.X / BS) + 0.5;
907 ty1 = (box.MinEdge.Y / BS) + 0.5;
908 tz1 = (box.MinEdge.Z / BS) + 0.5;
909 tx2 = (box.MaxEdge.X / BS) + 0.5;
910 ty2 = (box.MaxEdge.Y / BS) + 0.5;
911 tz2 = (box.MaxEdge.Z / BS) + 0.5;
913 tx1, 1-tz2, tx2, 1-tz1,
915 tz1, 1-ty2, tz2, 1-ty1,
916 1-tz2, 1-ty2, 1-tz1, 1-ty1,
917 1-tx2, 1-ty2, 1-tx1, 1-ty1,
918 tx1, 1-ty2, tx2, 1-ty1,
920 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
923 for(i = 0; i < 6; i++)
925 if (!visible_faces[i])
927 box = glass_faces[i];
930 tx1 = (box.MinEdge.X / BS) + 0.5;
931 ty1 = (box.MinEdge.Y / BS) + 0.5;
932 tz1 = (box.MinEdge.Z / BS) + 0.5;
933 tx2 = (box.MaxEdge.X / BS) + 0.5;
934 ty2 = (box.MaxEdge.Y / BS) + 0.5;
935 tz2 = (box.MaxEdge.Z / BS) + 0.5;
937 tx1, 1-tz2, tx2, 1-tz1,
939 tz1, 1-ty2, tz2, 1-ty1,
940 1-tz2, 1-ty2, 1-tz1, 1-ty1,
941 1-tx2, 1-ty2, 1-tx1, 1-ty1,
942 tx1, 1-ty2, tx2, 1-ty1,
944 makeCuboid(&collector, box, &glass_tiles[i], 1, c, txc2);
947 if (param2 > 0 && f.special_tiles[0].texture) {
948 // Interior volume level is in range 0 .. 63,
949 // convert it to -0.5 .. 0.5
950 float vlev = (((float)param2 / 63.0 ) * 2.0 - 1.0);
951 TileSpec interior_tiles[6];
952 for (i = 0; i < 6; i++)
953 interior_tiles[i] = f.special_tiles[0];
954 float offset = 0.003;
955 box = aabb3f(visible_faces[3] ? -b : -a + offset,
956 visible_faces[1] ? -b : -a + offset,
957 visible_faces[5] ? -b : -a + offset,
958 visible_faces[2] ? b : a - offset,
959 visible_faces[0] ? b * vlev : a * vlev - offset,
960 visible_faces[4] ? b : a - offset);
963 tx1 = (box.MinEdge.X / BS) + 0.5;
964 ty1 = (box.MinEdge.Y / BS) + 0.5;
965 tz1 = (box.MinEdge.Z / BS) + 0.5;
966 tx2 = (box.MaxEdge.X / BS) + 0.5;
967 ty2 = (box.MaxEdge.Y / BS) + 0.5;
968 tz2 = (box.MaxEdge.Z / BS) + 0.5;
970 tx1, 1-tz2, tx2, 1-tz1,
972 tz1, 1-ty2, tz2, 1-ty1,
973 1-tz2, 1-ty2, 1-tz1, 1-ty1,
974 1-tx2, 1-ty2, 1-tx1, 1-ty1,
975 tx1, 1-ty2, tx2, 1-ty1,
977 makeCuboid(&collector, box, interior_tiles, 6, c, txc3);
982 TileSpec tile_leaves = getNodeTile(n, p,
985 u16 l = getInteriorLight(n, 1, nodedef);
986 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
988 v3f pos = intToFloat(p, BS);
989 aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
992 makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
994 case NDT_ALLFACES_OPTIONAL:
995 // This is always pre-converted to something else
996 FATAL_ERROR("NDT_ALLFACES_OPTIONAL not pre-converted");
1000 v3s16 dir = n.getWallMountedDir(nodedef);
1003 if(dir == v3s16(0,-1,0)){
1004 tileindex = 0; // floor
1005 } else if(dir == v3s16(0,1,0)){
1006 tileindex = 1; // ceiling
1007 // For backwards compatibility
1008 } else if(dir == v3s16(0,0,0)){
1009 tileindex = 0; // floor
1011 tileindex = 2; // side
1014 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1015 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1016 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1018 u16 l = getInteriorLight(n, 1, nodedef);
1019 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1021 float s = BS/2*f.visual_scale;
1022 // Wall at X+ of node
1023 video::S3DVertex vertices[4] =
1025 video::S3DVertex(-s,-s,0, 0,0,0, c, 0,1),
1026 video::S3DVertex( s,-s,0, 0,0,0, c, 1,1),
1027 video::S3DVertex( s, s,0, 0,0,0, c, 1,0),
1028 video::S3DVertex(-s, s,0, 0,0,0, c, 0,0),
1031 for(s32 i=0; i<4; i++)
1033 if(dir == v3s16(1,0,0))
1034 vertices[i].Pos.rotateXZBy(0);
1035 if(dir == v3s16(-1,0,0))
1036 vertices[i].Pos.rotateXZBy(180);
1037 if(dir == v3s16(0,0,1))
1038 vertices[i].Pos.rotateXZBy(90);
1039 if(dir == v3s16(0,0,-1))
1040 vertices[i].Pos.rotateXZBy(-90);
1041 if(dir == v3s16(0,-1,0))
1042 vertices[i].Pos.rotateXZBy(45);
1043 if(dir == v3s16(0,1,0))
1044 vertices[i].Pos.rotateXZBy(-45);
1046 vertices[i].Pos += intToFloat(p, BS);
1049 u16 indices[] = {0,1,2,2,3,0};
1050 // Add to mesh collector
1051 collector.append(tile, vertices, 4, indices, 6);
1055 TileSpec tile = getNodeTileN(n, p, 0, data);
1056 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1057 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1059 u16 l = getInteriorLight(n, 0, nodedef);
1060 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1062 float d = (float)BS/16;
1063 float s = BS/2*f.visual_scale;
1064 // Wall at X+ of node
1065 video::S3DVertex vertices[4] =
1067 video::S3DVertex(BS/2-d, s, s, 0,0,0, c, 0,0),
1068 video::S3DVertex(BS/2-d, s, -s, 0,0,0, c, 1,0),
1069 video::S3DVertex(BS/2-d, -s, -s, 0,0,0, c, 1,1),
1070 video::S3DVertex(BS/2-d, -s, s, 0,0,0, c, 0,1),
1073 v3s16 dir = n.getWallMountedDir(nodedef);
1075 for(s32 i=0; i<4; i++)
1077 if(dir == v3s16(1,0,0))
1078 vertices[i].Pos.rotateXZBy(0);
1079 if(dir == v3s16(-1,0,0))
1080 vertices[i].Pos.rotateXZBy(180);
1081 if(dir == v3s16(0,0,1))
1082 vertices[i].Pos.rotateXZBy(90);
1083 if(dir == v3s16(0,0,-1))
1084 vertices[i].Pos.rotateXZBy(-90);
1085 if(dir == v3s16(0,-1,0))
1086 vertices[i].Pos.rotateXYBy(-90);
1087 if(dir == v3s16(0,1,0))
1088 vertices[i].Pos.rotateXYBy(90);
1090 vertices[i].Pos += intToFloat(p, BS);
1093 u16 indices[] = {0,1,2,2,3,0};
1094 // Add to mesh collector
1095 collector.append(tile, vertices, 4, indices, 6);
1099 TileSpec tile = getNodeTileN(n, p, 0, data);
1100 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1102 u16 l = getInteriorLight(n, 1, nodedef);
1103 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1105 float s = BS / 2 * f.visual_scale;
1107 for (int j = 0; j < 2; j++)
1109 video::S3DVertex vertices[4] =
1111 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1112 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1113 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1114 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1116 float rotate_degree = 0;
1117 if (f.param_type_2 == CPT2_DEGROTATE)
1118 rotate_degree = n.param2 * 2;
1121 for(u16 i = 0; i < 4; i++)
1122 vertices[i].Pos.rotateXZBy(46 + rotate_degree);
1123 } else if (j == 1) {
1124 for(u16 i = 0; i < 4; i++)
1125 vertices[i].Pos.rotateXZBy(-44 + rotate_degree);
1128 for (int i = 0; i < 4; i++)
1130 vertices[i].Pos *= f.visual_scale;
1131 vertices[i].Pos.Y += BS/2 * (f.visual_scale - 1);
1132 vertices[i].Pos += intToFloat(p, BS);
1135 u16 indices[] = {0, 1, 2, 2, 3, 0};
1136 // Add to mesh collector
1137 collector.append(tile, vertices, 4, indices, 6);
1142 TileSpec tile = getNodeTileN(n, p, 0, data);
1143 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1145 u16 l = getInteriorLight(n, 1, nodedef);
1146 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1148 float s = BS / 2 * f.visual_scale;
1150 content_t current = n.getContent();
1155 static const v3s16 dirs[6] = {
1164 int doDraw[6] = {0, 0, 0, 0, 0, 0};
1166 bool drawAllFaces = true;
1168 // Check for adjacent nodes
1169 for (int i = 0; i < 6; i++) {
1170 n2p = blockpos_nodes + p + dirs[i];
1171 n2 = data->m_vmanip.getNodeNoEx(n2p);
1172 n2c = n2.getContent();
1173 if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) {
1176 drawAllFaces = false;
1181 for (int j = 0; j < 6; j++) {
1183 video::S3DVertex vertices[4] = {
1184 video::S3DVertex(-s, -BS / 2, 0, 0, 0, 0, c, 0, 1),
1185 video::S3DVertex( s, -BS / 2, 0, 0, 0, 0, c, 1, 1),
1186 video::S3DVertex( s, -BS / 2 + s * 2, 0, 0, 0, 0, c, 1, 0),
1187 video::S3DVertex(-s, -BS / 2 + s * 2, 0, 0, 0, 0, c, 0, 0),
1190 // Calculate which faces should be drawn, (top or sides)
1191 if (j == 0 && (drawAllFaces ||
1192 (doDraw[3] == 1 || doDraw[1] == 1))) {
1193 for (int i = 0; i < 4; i++) {
1194 vertices[i].Pos.rotateXZBy(90);
1195 vertices[i].Pos.rotateXYBy(-10);
1196 vertices[i].Pos.X -= 4.0;
1198 } else if (j == 1 && (drawAllFaces ||
1199 (doDraw[5] == 1 || doDraw[1] == 1))) {
1200 for (int i = 0; i < 4; i++) {
1201 vertices[i].Pos.rotateXZBy(180);
1202 vertices[i].Pos.rotateYZBy(10);
1203 vertices[i].Pos.Z -= 4.0;
1205 } else if (j == 2 && (drawAllFaces ||
1206 (doDraw[2] == 1 || doDraw[1] == 1))) {
1207 for (int i = 0; i < 4; i++) {
1208 vertices[i].Pos.rotateXZBy(270);
1209 vertices[i].Pos.rotateXYBy(10);
1210 vertices[i].Pos.X += 4.0;
1212 } else if (j == 3 && (drawAllFaces ||
1213 (doDraw[4] == 1 || doDraw[1] == 1))) {
1214 for (int i = 0; i < 4; i++) {
1215 vertices[i].Pos.rotateYZBy(-10);
1216 vertices[i].Pos.Z += 4.0;
1218 // Center cross-flames
1219 } else if (j == 4 && (drawAllFaces || doDraw[1] == 1)) {
1220 for (int i = 0; i < 4; i++) {
1221 vertices[i].Pos.rotateXZBy(45);
1223 } else if (j == 5 && (drawAllFaces || doDraw[1] == 1)) {
1224 for (int i = 0; i < 4; i++) {
1225 vertices[i].Pos.rotateXZBy(-45);
1227 // Render flames on bottom of node above
1228 } else if (j == 0 && doDraw[0] == 1 && doDraw[1] == 0) {
1229 for (int i = 0; i < 4; i++) {
1230 vertices[i].Pos.rotateYZBy(70);
1231 vertices[i].Pos.rotateXZBy(90);
1232 vertices[i].Pos.Y += 4.84;
1233 vertices[i].Pos.X -= 4.7;
1235 } else if (j == 1 && doDraw[0] == 1 && doDraw[1] == 0) {
1236 for (int i = 0; i < 4; i++) {
1237 vertices[i].Pos.rotateYZBy(70);
1238 vertices[i].Pos.rotateXZBy(180);
1239 vertices[i].Pos.Y += 4.84;
1240 vertices[i].Pos.Z -= 4.7;
1242 } else if (j == 2 && doDraw[0] == 1 && doDraw[1] == 0) {
1243 for (int i = 0; i < 4; i++) {
1244 vertices[i].Pos.rotateYZBy(70);
1245 vertices[i].Pos.rotateXZBy(270);
1246 vertices[i].Pos.Y += 4.84;
1247 vertices[i].Pos.X += 4.7;
1249 } else if (j == 3 && doDraw[0] == 1 && doDraw[1] == 0) {
1250 for (int i = 0; i < 4; i++) {
1251 vertices[i].Pos.rotateYZBy(70);
1252 vertices[i].Pos.Y += 4.84;
1253 vertices[i].Pos.Z += 4.7;
1256 // Skip faces that aren't adjacent to a node
1260 for (int i = 0; i < 4; i++) {
1261 vertices[i].Pos *= f.visual_scale;
1262 vertices[i].Pos += intToFloat(p, BS);
1265 u16 indices[] = {0, 1, 2, 2, 3, 0};
1266 // Add to mesh collector
1267 collector.append(tile, vertices, 4, indices, 6);
1272 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1273 TileSpec tile_nocrack = tile;
1274 tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1276 // Put wood the right way around in the posts
1277 TileSpec tile_rot = tile;
1278 tile_rot.rotation = 1;
1280 u16 l = getInteriorLight(n, 1, nodedef);
1281 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1283 const f32 post_rad=(f32)BS/8;
1284 const f32 bar_rad=(f32)BS/16;
1285 const f32 bar_len=(f32)(BS/2)-post_rad;
1287 v3f pos = intToFloat(p, BS);
1289 // The post - always present
1290 aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
1291 post.MinEdge += pos;
1292 post.MaxEdge += pos;
1294 6/16.,6/16.,10/16.,10/16.,
1295 6/16.,6/16.,10/16.,10/16.,
1300 makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1302 // Now a section of fence, +X, if there's a post there
1305 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1306 const ContentFeatures *f2 = &nodedef->get(n2);
1307 if(f2->drawtype == NDT_FENCELIKE)
1309 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1310 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1314 0/16.,2/16.,16/16.,4/16.,
1315 0/16.,4/16.,16/16.,6/16.,
1316 6/16.,6/16.,8/16.,8/16.,
1317 10/16.,10/16.,12/16.,12/16.,
1318 0/16.,8/16.,16/16.,10/16.,
1319 0/16.,14/16.,16/16.,16/16.};
1320 makeCuboid(&collector, bar, &tile_nocrack, 1,
1322 bar.MinEdge.Y -= BS/2;
1323 bar.MaxEdge.Y -= BS/2;
1324 makeCuboid(&collector, bar, &tile_nocrack, 1,
1328 // Now a section of fence, +Z, if there's a post there
1331 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1332 f2 = &nodedef->get(n2);
1333 if(f2->drawtype == NDT_FENCELIKE)
1335 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1336 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1340 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
1341 4/16.,1/16.,6/16.,5/16., // for wood texture instead
1342 0/16.,9/16.,16/16.,11/16.,
1343 0/16.,6/16.,16/16.,8/16.,
1344 6/16.,6/16.,8/16.,8/16.,
1345 10/16.,10/16.,12/16.,12/16.};
1346 makeCuboid(&collector, bar, &tile_nocrack, 1,
1348 bar.MinEdge.Y -= BS/2;
1349 bar.MaxEdge.Y -= BS/2;
1350 makeCuboid(&collector, bar, &tile_nocrack, 1,
1356 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) */
1359 content_t thiscontent = n.getContent();
1360 std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
1361 int self_group = ((ItemGroupList) nodedef->get(n).groups)[groupname];
1364 for (s8 y0 = -1; y0 <= 1; y0++) {
1365 // Prevent from indexing never used coordinates
1366 for (s8 xz = -1; xz <= 1; xz++) {
1369 MapNode n_xy = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x + xz, y + y0, z));
1370 MapNode n_zy = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y + y0, z + xz));
1371 ContentFeatures def_xy = nodedef->get(n_xy);
1372 ContentFeatures def_zy = nodedef->get(n_zy);
1374 // Check if current node would connect with the rail
1375 is_rail_x[index] = ((def_xy.drawtype == NDT_RAILLIKE
1376 && ((ItemGroupList) def_xy.groups)[groupname] == self_group)
1377 || n_xy.getContent() == thiscontent);
1379 is_rail_z[index] = ((def_zy.drawtype == NDT_RAILLIKE
1380 && ((ItemGroupList) def_zy.groups)[groupname] == self_group)
1381 || n_zy.getContent() == thiscontent);
1386 bool is_rail_x_all[2]; // [0] = negative x, [1] = positive x coordinate from the current node position
1387 bool is_rail_z_all[2];
1388 is_rail_x_all[0] = is_rail_x[0] || is_rail_x[2] || is_rail_x[4];
1389 is_rail_x_all[1] = is_rail_x[1] || is_rail_x[3] || is_rail_x[5];
1390 is_rail_z_all[0] = is_rail_z[0] || is_rail_z[2] || is_rail_z[4];
1391 is_rail_z_all[1] = is_rail_z[1] || is_rail_z[3] || is_rail_z[5];
1393 // reasonable default, flat straight unrotated rail
1394 bool is_straight = true;
1395 int adjacencies = 0;
1399 // check for sloped rail
1400 if (is_rail_x[4] || is_rail_x[5] || is_rail_z[4] || is_rail_z[5]) {
1401 adjacencies = 5; // 5 means sloped
1402 is_straight = true; // sloped is always straight
1404 // is really straight, rails on both sides
1405 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
1406 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
1409 switch (adjacencies) {
1411 if (is_rail_x_all[0] || is_rail_x_all[1])
1416 tileindex = 1; // curved
1417 if (is_rail_x_all[0] && is_rail_x_all[1])
1419 if (is_rail_z_all[0] && is_rail_z_all[1]) {
1423 else if (is_rail_x_all[0] && is_rail_z_all[0])
1425 else if (is_rail_x_all[0] && is_rail_z_all[1])
1427 else if (is_rail_x_all[1] && is_rail_z_all[1])
1431 // here is where the potential to 'switch' a junction is, but not implemented at present
1432 tileindex = 2; // t-junction
1433 if(!is_rail_x_all[1])
1435 if(!is_rail_z_all[0])
1437 if(!is_rail_z_all[1])
1441 tileindex = 3; // crossing
1455 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1456 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1457 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1459 u16 l = getInteriorLight(n, 0, nodedef);
1460 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1462 float d = (float)BS/64;
1466 if (is_rail_x[4] || is_rail_x[5] || is_rail_z[4] || is_rail_z[5])
1467 g = 1; //Object is at a slope
1469 video::S3DVertex vertices[4] =
1471 video::S3DVertex(-s, -s+d,-s, 0,0,0, c,0,1),
1472 video::S3DVertex( s, -s+d,-s, 0,0,0, c,1,1),
1473 video::S3DVertex( s, g*s+d, s, 0,0,0, c,1,0),
1474 video::S3DVertex(-s, g*s+d, s, 0,0,0, c,0,0),
1477 for(s32 i=0; i<4; i++)
1480 vertices[i].Pos.rotateXZBy(angle);
1481 vertices[i].Pos += intToFloat(p, BS);
1484 u16 indices[] = {0,1,2,2,3,0};
1485 collector.append(tile, vertices, 4, indices, 6);
1489 static const v3s16 tile_dirs[6] = {
1499 u16 l = getInteriorLight(n, 1, nodedef);
1500 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1502 v3f pos = intToFloat(p, BS);
1504 std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1505 for(std::vector<aabb3f>::iterator
1507 i != boxes.end(); ++i)
1509 for(int j = 0; j < 6; j++)
1511 // Handles facedir rotation for textures
1512 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1519 if (box.MinEdge.X > box.MaxEdge.X)
1522 box.MinEdge.X=box.MaxEdge.X;
1525 if (box.MinEdge.Y > box.MaxEdge.Y)
1528 box.MinEdge.Y=box.MaxEdge.Y;
1531 if (box.MinEdge.Z > box.MaxEdge.Z)
1534 box.MinEdge.Z=box.MaxEdge.Z;
1539 // Compute texture coords
1540 f32 tx1 = (box.MinEdge.X/BS)+0.5;
1541 f32 ty1 = (box.MinEdge.Y/BS)+0.5;
1542 f32 tz1 = (box.MinEdge.Z/BS)+0.5;
1543 f32 tx2 = (box.MaxEdge.X/BS)+0.5;
1544 f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
1545 f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
1548 tx1, 1-tz2, tx2, 1-tz1,
1552 tz1, 1-ty2, tz2, 1-ty1,
1554 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1556 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1558 tx1, 1-ty2, tx2, 1-ty1,
1560 makeCuboid(&collector, box, tiles, 6, c, txc);
1565 v3f pos = intToFloat(p, BS);
1566 video::SColor c = MapBlock_LightColor(255, getInteriorLight(n, 1, nodedef), f.light_source);
1569 if (f.param_type_2 == CPT2_FACEDIR) {
1570 facedir = n.getFaceDir(nodedef);
1571 } else if (f.param_type_2 == CPT2_WALLMOUNTED) {
1572 //convert wallmounted to 6dfacedir.
1573 //when cache enabled, it is already converted
1574 facedir = n.getWallMounted(nodedef);
1575 if (!enable_mesh_cache) {
1576 static const u8 wm_to_6d[6] = {20, 0, 16+1, 12+3, 8, 4+2};
1577 facedir = wm_to_6d[facedir];
1581 if (f.mesh_ptr[facedir]) {
1582 // use cached meshes
1583 for(u16 j = 0; j < f.mesh_ptr[0]->getMeshBufferCount(); j++) {
1584 scene::IMeshBuffer *buf = f.mesh_ptr[facedir]->getMeshBuffer(j);
1585 collector.append(getNodeTileN(n, p, j, data),
1586 (video::S3DVertex *)buf->getVertices(), buf->getVertexCount(),
1587 buf->getIndices(), buf->getIndexCount(), pos, c);
1589 } else if (f.mesh_ptr[0]) {
1590 // no cache, clone and rotate mesh
1591 scene::IMesh* mesh = cloneMesh(f.mesh_ptr[0]);
1592 rotateMeshBy6dFacedir(mesh, facedir);
1593 recalculateBoundingBox(mesh);
1594 meshmanip->recalculateNormals(mesh, true, false);
1595 for(u16 j = 0; j < mesh->getMeshBufferCount(); j++) {
1596 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
1597 collector.append(getNodeTileN(n, p, j, data),
1598 (video::S3DVertex *)buf->getVertices(), buf->getVertexCount(),
1599 buf->getIndices(), buf->getIndexCount(), pos, c);