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 "main.h" // For g_settings
24 #include "mapblock_mesh.h" // For MapBlock_LightColor() and MeshCollector
29 #include <IMeshManipulator.h>
35 // collector - the MeshCollector for the resulting polygons
36 // box - the position and size of the box
37 // tiles - the tiles (materials) to use (for all 6 faces)
38 // tilecount - number of entries in tiles, 1<=tilecount<=6
39 // c - vertex colour - used for all
40 // txc - texture coordinates - this is a list of texture coordinates
41 // for the opposite corners of each face - therefore, there
42 // should be (2+2)*6=24 values in the list. Alternatively, pass
43 // NULL to use the entire texture for each face. The order of
44 // the faces in the list is up-down-right-left-back-front
45 // (compatible with ContentFeatures). If you specified 0,0,1,1
46 // for each face, that would be the same as passing NULL.
47 void makeCuboid(MeshCollector *collector, const aabb3f &box,
48 TileSpec *tiles, int tilecount, video::SColor &c, const f32* txc)
50 assert(tilecount >= 1 && tilecount <= 6);
52 v3f min = box.MinEdge;
53 v3f max = box.MaxEdge;
58 static const f32 txc_default[24] = {
69 video::S3DVertex vertices[24] =
72 video::S3DVertex(min.X,max.Y,max.Z, 0,1,0, c, txc[0],txc[1]),
73 video::S3DVertex(max.X,max.Y,max.Z, 0,1,0, c, txc[2],txc[1]),
74 video::S3DVertex(max.X,max.Y,min.Z, 0,1,0, c, txc[2],txc[3]),
75 video::S3DVertex(min.X,max.Y,min.Z, 0,1,0, c, txc[0],txc[3]),
77 video::S3DVertex(min.X,min.Y,min.Z, 0,-1,0, c, txc[4],txc[5]),
78 video::S3DVertex(max.X,min.Y,min.Z, 0,-1,0, c, txc[6],txc[5]),
79 video::S3DVertex(max.X,min.Y,max.Z, 0,-1,0, c, txc[6],txc[7]),
80 video::S3DVertex(min.X,min.Y,max.Z, 0,-1,0, c, txc[4],txc[7]),
82 video::S3DVertex(max.X,max.Y,min.Z, 1,0,0, c, txc[ 8],txc[9]),
83 video::S3DVertex(max.X,max.Y,max.Z, 1,0,0, c, txc[10],txc[9]),
84 video::S3DVertex(max.X,min.Y,max.Z, 1,0,0, c, txc[10],txc[11]),
85 video::S3DVertex(max.X,min.Y,min.Z, 1,0,0, c, txc[ 8],txc[11]),
87 video::S3DVertex(min.X,max.Y,max.Z, -1,0,0, c, txc[12],txc[13]),
88 video::S3DVertex(min.X,max.Y,min.Z, -1,0,0, c, txc[14],txc[13]),
89 video::S3DVertex(min.X,min.Y,min.Z, -1,0,0, c, txc[14],txc[15]),
90 video::S3DVertex(min.X,min.Y,max.Z, -1,0,0, c, txc[12],txc[15]),
92 video::S3DVertex(max.X,max.Y,max.Z, 0,0,1, c, txc[16],txc[17]),
93 video::S3DVertex(min.X,max.Y,max.Z, 0,0,1, c, txc[18],txc[17]),
94 video::S3DVertex(min.X,min.Y,max.Z, 0,0,1, c, txc[18],txc[19]),
95 video::S3DVertex(max.X,min.Y,max.Z, 0,0,1, c, txc[16],txc[19]),
97 video::S3DVertex(min.X,max.Y,min.Z, 0,0,-1, c, txc[20],txc[21]),
98 video::S3DVertex(max.X,max.Y,min.Z, 0,0,-1, c, txc[22],txc[21]),
99 video::S3DVertex(max.X,min.Y,min.Z, 0,0,-1, c, txc[22],txc[23]),
100 video::S3DVertex(min.X,min.Y,min.Z, 0,0,-1, c, txc[20],txc[23]),
103 for(int i = 0; i < 6; i++)
105 switch (tiles[MYMIN(i, tilecount-1)].rotation)
110 for (int x = 0; x < 4; x++)
111 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
114 for (int x = 0; x < 4; x++)
115 vertices[i*4+x].TCoords.rotateBy(180,irr::core::vector2df(0, 0));
118 for (int x = 0; x < 4; x++)
119 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
122 for (int x = 0; x < 4; x++){
123 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
124 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
128 for (int x = 0; x < 4; x++){
129 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
130 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
134 for (int x = 0; x < 4; x++){
135 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
136 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
140 for (int x = 0; x < 4; x++){
141 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
142 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
146 for (int x = 0; x < 4; x++){
147 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
151 for (int x = 0; x < 4; x++){
152 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
159 u16 indices[] = {0,1,2,2,3,0};
160 // Add to mesh collector
161 for (s32 j = 0; j < 24; j += 4) {
162 int tileindex = MYMIN(j / 4, tilecount - 1);
163 collector->append(tiles[tileindex], vertices + j, 4, indices, 6);
168 TODO: Fix alpha blending for special nodes
169 Currently only the last element rendered is blended correct
171 void mapblock_mesh_generate_special(MeshMakeData *data,
172 MeshCollector &collector)
174 INodeDefManager *nodedef = data->m_gamedef->ndef();
175 ITextureSource *tsrc = data->m_gamedef->tsrc();
176 scene::ISceneManager* smgr = data->m_gamedef->getSceneManager();
177 scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator();
180 //TimeTaker timer("mapblock_mesh_generate_special()");
185 bool enable_mesh_cache = g_settings->getBool("enable_mesh_cache");
186 bool new_style_water = g_settings->getBool("new_style_water");
188 float node_liquid_level = 1.0;
190 node_liquid_level = 0.85;
192 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
194 for(s16 z = 0; z < MAP_BLOCKSIZE; z++)
195 for(s16 y = 0; y < MAP_BLOCKSIZE; y++)
196 for(s16 x = 0; x < MAP_BLOCKSIZE; x++)
200 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
201 const ContentFeatures &f = nodedef->get(n);
203 // Only solidness=0 stuff is drawn here
209 infostream<<"Got "<<f.drawtype<<std::endl;
217 Add water sources to mesh if using new style
219 TileSpec tile_liquid = f.special_tiles[0];
220 TileSpec tile_liquid_bfculled = getNodeTile(n, p, v3s16(0,0,0), data);
222 bool top_is_same_liquid = false;
223 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
224 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
225 content_t c_source = nodedef->getId(f.liquid_alternative_source);
226 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
227 top_is_same_liquid = true;
229 u16 l = getInteriorLight(n, 0, nodedef);
230 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
235 v3s16 side_dirs[4] = {
241 for(u32 i=0; i<4; i++)
243 v3s16 dir = side_dirs[i];
245 MapNode neighbor = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir);
246 content_t neighbor_content = neighbor.getContent();
247 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
248 MapNode n_top = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dir+ v3s16(0,1,0));
249 content_t n_top_c = n_top.getContent();
251 if(neighbor_content == CONTENT_IGNORE)
255 If our topside is liquid and neighbor's topside
256 is liquid, don't draw side face
258 if(top_is_same_liquid && (n_top_c == c_flowing ||
259 n_top_c == c_source || n_top_c == CONTENT_IGNORE))
262 // Don't draw face if neighbor is blocking the view
263 if(n_feat.solidness == 2)
266 bool neighbor_is_same_liquid = (neighbor_content == c_source
267 || neighbor_content == c_flowing);
269 // Don't draw any faces if neighbor same is liquid and top is
271 if(neighbor_is_same_liquid && !top_is_same_liquid)
274 // Use backface culled material if neighbor doesn't have a
276 const TileSpec *current_tile = &tile_liquid;
277 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
278 current_tile = &tile_liquid_bfculled;
280 video::S3DVertex vertices[4] =
282 video::S3DVertex(-BS/2,0,BS/2,0,0,0, c, 0,1),
283 video::S3DVertex(BS/2,0,BS/2,0,0,0, c, 1,1),
284 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
285 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
289 If our topside is liquid, set upper border of face
290 at upper border of node
292 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
302 vertices[2].Pos.Y = (node_liquid_level-0.5)*BS;
303 vertices[3].Pos.Y = (node_liquid_level-0.5)*BS;
306 If neighbor is liquid, lower border of face is liquid level
308 if(neighbor_is_same_liquid)
310 vertices[0].Pos.Y = (node_liquid_level-0.5)*BS;
311 vertices[1].Pos.Y = (node_liquid_level-0.5)*BS;
314 If neighbor is not liquid, lower border of face is
319 vertices[0].Pos.Y = -0.5*BS;
320 vertices[1].Pos.Y = -0.5*BS;
323 for(s32 j=0; j<4; j++)
325 if(dir == v3s16(0,0,1))
326 vertices[j].Pos.rotateXZBy(0);
327 if(dir == v3s16(0,0,-1))
328 vertices[j].Pos.rotateXZBy(180);
329 if(dir == v3s16(-1,0,0))
330 vertices[j].Pos.rotateXZBy(90);
331 if(dir == v3s16(1,0,-0))
332 vertices[j].Pos.rotateXZBy(-90);
334 // Do this to not cause glitches when two liquids are
336 /*if(neighbor_is_same_liquid == false){
337 vertices[j].Pos.X *= 0.98;
338 vertices[j].Pos.Z *= 0.98;
341 vertices[j].Pos += intToFloat(p, BS);
344 u16 indices[] = {0,1,2,2,3,0};
345 // Add to mesh collector
346 collector.append(*current_tile, vertices, 4, indices, 6);
352 if(top_is_same_liquid)
355 video::S3DVertex vertices[4] =
357 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
358 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
359 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
360 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
363 v3f offset(p.X*BS, p.Y*BS + (-0.5+node_liquid_level)*BS, p.Z*BS);
364 for(s32 i=0; i<4; i++)
366 vertices[i].Pos += offset;
369 u16 indices[] = {0,1,2,2,3,0};
370 // Add to mesh collector
371 collector.append(tile_liquid, vertices, 4, indices, 6);
373 case NDT_FLOWINGLIQUID:
376 Add flowing liquid to mesh
378 TileSpec tile_liquid = f.special_tiles[0];
379 TileSpec tile_liquid_bfculled = f.special_tiles[1];
381 bool top_is_same_liquid = false;
382 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
383 content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
384 content_t c_source = nodedef->getId(f.liquid_alternative_source);
385 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
386 top_is_same_liquid = true;
389 // If this liquid emits light and doesn't contain light, draw
390 // it at what it emits, for an increased effect
391 u8 light_source = nodedef->get(n).light_source;
392 if(light_source != 0){
393 l = decode_light(light_source);
396 // Use the light of the node on top if possible
397 else if(nodedef->get(ntop).param_type == CPT_LIGHT)
398 l = getInteriorLight(ntop, 0, nodedef);
399 // Otherwise use the light of this node (the liquid)
401 l = getInteriorLight(n, 0, nodedef);
402 video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
404 u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
406 // Neighbor liquid levels (key = relative position)
407 // Includes current node
408 std::map<v3s16, f32> neighbor_levels;
409 std::map<v3s16, content_t> neighbor_contents;
410 std::map<v3s16, u8> neighbor_flags;
411 const u8 neighborflag_top_is_same_liquid = 0x01;
412 v3s16 neighbor_dirs[9] = {
423 for(u32 i=0; i<9; i++)
425 content_t content = CONTENT_AIR;
426 float level = -0.5 * BS;
429 v3s16 p2 = p + neighbor_dirs[i];
430 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
431 if(n2.getContent() != CONTENT_IGNORE)
433 content = n2.getContent();
435 if(n2.getContent() == c_source)
436 level = (-0.5+node_liquid_level) * BS;
437 else if(n2.getContent() == c_flowing){
438 u8 liquid_level = (n2.param2&LIQUID_LEVEL_MASK);
439 if (liquid_level <= LIQUID_LEVEL_MAX+1-range)
442 liquid_level -= (LIQUID_LEVEL_MAX+1-range);
443 level = (-0.5 + ((float)liquid_level+ 0.5) / (float)range * node_liquid_level) * BS;
446 // Check node above neighbor.
447 // NOTE: This doesn't get executed if neighbor
450 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
451 if(n2.getContent() == c_source ||
452 n2.getContent() == c_flowing)
453 flags |= neighborflag_top_is_same_liquid;
456 neighbor_levels[neighbor_dirs[i]] = level;
457 neighbor_contents[neighbor_dirs[i]] = content;
458 neighbor_flags[neighbor_dirs[i]] = flags;
461 // Corner heights (average between four liquids)
462 f32 corner_levels[4];
464 v3s16 halfdirs[4] = {
470 for(u32 i=0; i<4; i++)
472 v3s16 cornerdir = halfdirs[i];
473 float cornerlevel = 0;
476 for(u32 j=0; j<4; j++)
478 v3s16 neighbordir = cornerdir - halfdirs[j];
479 content_t content = neighbor_contents[neighbordir];
480 // If top is liquid, draw starting from top of node
481 if(neighbor_flags[neighbordir] &
482 neighborflag_top_is_same_liquid)
484 cornerlevel = 0.5*BS;
488 // Source is always the same height
489 else if(content == c_source)
491 cornerlevel = (-0.5+node_liquid_level)*BS;
495 // Flowing liquid has level information
496 else if(content == c_flowing)
498 cornerlevel += neighbor_levels[neighbordir];
501 else if(content == CONTENT_AIR)
507 cornerlevel = -0.5*BS+0.2;
508 else if(valid_count > 0)
509 cornerlevel /= valid_count;
510 corner_levels[i] = cornerlevel;
517 v3s16 side_dirs[4] = {
523 s16 side_corners[4][2] = {
529 for(u32 i=0; i<4; i++)
531 v3s16 dir = side_dirs[i];
534 If our topside is liquid and neighbor's topside
535 is liquid, don't draw side face
537 if(top_is_same_liquid &&
538 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
541 content_t neighbor_content = neighbor_contents[dir];
542 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
544 // Don't draw face if neighbor is blocking the view
545 if(n_feat.solidness == 2)
548 bool neighbor_is_same_liquid = (neighbor_content == c_source
549 || neighbor_content == c_flowing);
551 // Don't draw any faces if neighbor same is liquid and top is
553 if(neighbor_is_same_liquid == true
554 && top_is_same_liquid == false)
557 // Use backface culled material if neighbor doesn't have a
559 const TileSpec *current_tile = &tile_liquid;
560 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
561 current_tile = &tile_liquid_bfculled;
563 video::S3DVertex vertices[4] =
565 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
566 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
567 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
568 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),
572 If our topside is liquid, set upper border of face
573 at upper border of node
575 if(top_is_same_liquid)
577 vertices[2].Pos.Y = 0.5*BS;
578 vertices[3].Pos.Y = 0.5*BS;
581 Otherwise upper position of face is corner levels
585 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
586 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
590 If neighbor is liquid, lower border of face is corner
593 if(neighbor_is_same_liquid)
595 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
596 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
599 If neighbor is not liquid, lower border of face is
604 vertices[0].Pos.Y = -0.5*BS;
605 vertices[1].Pos.Y = -0.5*BS;
608 for(s32 j=0; j<4; j++)
610 if(dir == v3s16(0,0,1))
611 vertices[j].Pos.rotateXZBy(0);
612 if(dir == v3s16(0,0,-1))
613 vertices[j].Pos.rotateXZBy(180);
614 if(dir == v3s16(-1,0,0))
615 vertices[j].Pos.rotateXZBy(90);
616 if(dir == v3s16(1,0,-0))
617 vertices[j].Pos.rotateXZBy(-90);
619 // Do this to not cause glitches when two liquids are
621 /*if(neighbor_is_same_liquid == false){
622 vertices[j].Pos.X *= 0.98;
623 vertices[j].Pos.Z *= 0.98;
626 vertices[j].Pos += intToFloat(p, BS);
629 u16 indices[] = {0,1,2,2,3,0};
630 // Add to mesh collector
631 collector.append(*current_tile, vertices, 4, indices, 6);
635 Generate top side, if appropriate
638 if(top_is_same_liquid == false)
640 video::S3DVertex vertices[4] =
642 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
643 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
644 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,0),
645 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,0),
648 // To get backface culling right, the vertices need to go
649 // clockwise around the front of the face. And we happened to
650 // calculate corner levels in exact reverse order.
651 s32 corner_resolve[4] = {3,2,1,0};
653 for(s32 i=0; i<4; i++)
655 //vertices[i].Pos.Y += liquid_level;
656 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
657 s32 j = corner_resolve[i];
658 vertices[i].Pos.Y += corner_levels[j];
659 vertices[i].Pos += intToFloat(p, BS);
662 // Default downwards-flowing texture animation goes from
663 // -Z towards +Z, thus the direction is +Z.
664 // Rotate texture to make animation go in flow direction
665 // Positive if liquid moves towards +Z
666 f32 dz = (corner_levels[side_corners[3][0]] +
667 corner_levels[side_corners[3][1]]) -
668 (corner_levels[side_corners[2][0]] +
669 corner_levels[side_corners[2][1]]);
670 // Positive if liquid moves towards +X
671 f32 dx = (corner_levels[side_corners[1][0]] +
672 corner_levels[side_corners[1][1]]) -
673 (corner_levels[side_corners[0][0]] +
674 corner_levels[side_corners[0][1]]);
675 f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG ;
676 v2f tcoord_center(0.5, 0.5);
677 v2f tcoord_translate(
678 blockpos_nodes.Z + z,
679 blockpos_nodes.X + x);
680 tcoord_translate.rotateBy(tcoord_angle);
681 tcoord_translate.X -= floor(tcoord_translate.X);
682 tcoord_translate.Y -= floor(tcoord_translate.Y);
684 for(s32 i=0; i<4; i++)
686 vertices[i].TCoords.rotateBy(
689 vertices[i].TCoords += tcoord_translate;
692 v2f t = vertices[0].TCoords;
693 vertices[0].TCoords = vertices[2].TCoords;
694 vertices[2].TCoords = t;
696 u16 indices[] = {0,1,2,2,3,0};
697 // Add to mesh collector
698 collector.append(tile_liquid, vertices, 4, indices, 6);
703 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
705 u16 l = getInteriorLight(n, 1, nodedef);
706 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
708 for(u32 j=0; j<6; j++)
710 // Check this neighbor
711 v3s16 dir = g_6dirs[j];
712 v3s16 n2p = blockpos_nodes + p + dir;
713 MapNode n2 = data->m_vmanip.getNodeNoEx(n2p);
714 // Don't make face if neighbor is of same type
715 if(n2.getContent() == n.getContent())
719 video::S3DVertex vertices[4] = {
720 video::S3DVertex(-BS/2,-BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 1,1),
721 video::S3DVertex(BS/2,-BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 0,1),
722 video::S3DVertex(BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 0,0),
723 video::S3DVertex(-BS/2,BS/2,BS/2, dir.X,dir.Y,dir.Z, c, 1,0),
726 // Rotations in the g_6dirs format
728 for(u16 i=0; i<4; i++)
729 vertices[i].Pos.rotateXZBy(0);
730 else if(j == 1) // Y+
731 for(u16 i=0; i<4; i++)
732 vertices[i].Pos.rotateYZBy(-90);
733 else if(j == 2) // X+
734 for(u16 i=0; i<4; i++)
735 vertices[i].Pos.rotateXZBy(-90);
736 else if(j == 3) // Z-
737 for(u16 i=0; i<4; i++)
738 vertices[i].Pos.rotateXZBy(180);
739 else if(j == 4) // Y-
740 for(u16 i=0; i<4; i++)
741 vertices[i].Pos.rotateYZBy(90);
742 else if(j == 5) // X-
743 for(u16 i=0; i<4; i++)
744 vertices[i].Pos.rotateXZBy(90);
746 for(u16 i=0; i<4; i++){
747 vertices[i].Pos += intToFloat(p, BS);
750 u16 indices[] = {0,1,2,2,3,0};
751 // Add to mesh collector
752 collector.append(tile, vertices, 4, indices, 6);
755 case NDT_GLASSLIKE_FRAMED_OPTIONAL:
756 // This is always pre-converted to something else
759 case NDT_GLASSLIKE_FRAMED:
761 static const v3s16 dirs[6] = {
772 for (i = 0; i < 6; i++)
773 tiles[i] = getNodeTile(n, p, dirs[i], data);
775 TileSpec glass_tiles[6];
776 if (tiles[1].texture && tiles[2].texture && tiles[3].texture) {
777 glass_tiles[0] = tiles[2];
778 glass_tiles[1] = tiles[3];
779 glass_tiles[2] = tiles[1];
780 glass_tiles[3] = tiles[1];
781 glass_tiles[4] = tiles[1];
782 glass_tiles[5] = tiles[1];
784 for (i = 0; i < 6; i++)
785 glass_tiles[i] = tiles[1];
788 u8 param2 = n.getParam2();
789 bool H_merge = ! bool(param2 & 128);
790 bool V_merge = ! bool(param2 & 64);
791 param2 = param2 & 63;
793 u16 l = getInteriorLight(n, 1, nodedef);
794 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
795 v3f pos = intToFloat(p, BS);
796 static const float a = BS / 2;
797 static const float g = a - 0.003;
798 static const float b = .876 * ( BS / 2 );
800 static const aabb3f frame_edges[12] = {
801 aabb3f( b, b,-a, a, a, a), // y+
802 aabb3f(-a, b,-a,-b, a, a), // y+
803 aabb3f( b,-a,-a, a,-b, a), // y-
804 aabb3f(-a,-a,-a,-b,-b, a), // y-
805 aabb3f( b,-a, b, a, a, a), // x+
806 aabb3f( b,-a,-a, a, a,-b), // x+
807 aabb3f(-a,-a, b,-b, a, a), // x-
808 aabb3f(-a,-a,-a,-b, a,-b), // x-
809 aabb3f(-a, b, b, a, a, a), // z+
810 aabb3f(-a,-a, b, a,-b, a), // z+
811 aabb3f(-a,-a,-a, a,-b,-b), // z-
812 aabb3f(-a, b,-a, a, a,-b) // z-
814 static const aabb3f glass_faces[6] = {
815 aabb3f(-g, g,-g, g, g, g), // y+
816 aabb3f(-g,-g,-g, g,-g, g), // y-
817 aabb3f( g,-g,-g, g, g, g), // x+
818 aabb3f(-g,-g,-g,-g, g, g), // x-
819 aabb3f(-g,-g, g, g, g, g), // z+
820 aabb3f(-g,-g,-g, g, g,-g) // z-
823 // table of node visible faces, 0 = invisible
824 int visible_faces[6] = {0,0,0,0,0,0};
826 // table of neighbours, 1 = same type, checked with g_26dirs
827 int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
829 // g_26dirs to check when only horizontal merge is allowed
830 int nb_H_dirs[8] = {0,2,3,5,10,11,12,13};
832 content_t current = n.getContent();
837 // neighbours checks for frames visibility
839 if (!H_merge && V_merge) {
840 n2p = blockpos_nodes + p + g_26dirs[1];
841 n2 = data->m_vmanip.getNodeNoEx(n2p);
842 n2c = n2.getContent();
843 if (n2c == current || n2c == CONTENT_IGNORE)
845 n2p = blockpos_nodes + p + g_26dirs[4];
846 n2 = data->m_vmanip.getNodeNoEx(n2p);
847 n2c = n2.getContent();
848 if (n2c == current || n2c == CONTENT_IGNORE)
850 } else if (H_merge && !V_merge) {
851 for(i = 0; i < 8; i++) {
852 n2p = blockpos_nodes + p + g_26dirs[nb_H_dirs[i]];
853 n2 = data->m_vmanip.getNodeNoEx(n2p);
854 n2c = n2.getContent();
855 if (n2c == current || n2c == CONTENT_IGNORE)
856 nb[nb_H_dirs[i]] = 1;
858 } else if (H_merge && V_merge) {
859 for(i = 0; i < 18; i++) {
860 n2p = blockpos_nodes + p + g_26dirs[i];
861 n2 = data->m_vmanip.getNodeNoEx(n2p);
862 n2c = n2.getContent();
863 if (n2c == current || n2c == CONTENT_IGNORE)
868 // faces visibility checks
871 visible_faces[0] = 1;
872 visible_faces[1] = 1;
874 for(i = 0; i < 2; i++) {
875 n2p = blockpos_nodes + p + dirs[i];
876 n2 = data->m_vmanip.getNodeNoEx(n2p);
877 n2c = n2.getContent();
879 visible_faces[i] = 1;
884 visible_faces[2] = 1;
885 visible_faces[3] = 1;
886 visible_faces[4] = 1;
887 visible_faces[5] = 1;
889 for(i = 2; i < 6; i++) {
890 n2p = blockpos_nodes + p + dirs[i];
891 n2 = data->m_vmanip.getNodeNoEx(n2p);
892 n2c = n2.getContent();
894 visible_faces[i] = 1;
898 static const u8 nb_triplet[12*3] = {
899 1,2, 7, 1,5, 6, 4,2,15, 4,5,14,
900 2,0,11, 2,3,13, 5,0,10, 5,3,12,
901 0,1, 8, 0,4,16, 3,4,17, 3,1, 9
904 f32 tx1, ty1, tz1, tx2, ty2, tz2;
907 for(i = 0; i < 12; i++)
910 if (nb[nb_triplet[i*3+2]])
911 edge_invisible = nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
913 edge_invisible = nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
916 box = frame_edges[i];
919 tx1 = (box.MinEdge.X / BS) + 0.5;
920 ty1 = (box.MinEdge.Y / BS) + 0.5;
921 tz1 = (box.MinEdge.Z / BS) + 0.5;
922 tx2 = (box.MaxEdge.X / BS) + 0.5;
923 ty2 = (box.MaxEdge.Y / BS) + 0.5;
924 tz2 = (box.MaxEdge.Z / BS) + 0.5;
926 tx1, 1-tz2, tx2, 1-tz1,
928 tz1, 1-ty2, tz2, 1-ty1,
929 1-tz2, 1-ty2, 1-tz1, 1-ty1,
930 1-tx2, 1-ty2, 1-tx1, 1-ty1,
931 tx1, 1-ty2, tx2, 1-ty1,
933 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
936 for(i = 0; i < 6; i++)
938 if (!visible_faces[i])
940 box = glass_faces[i];
943 tx1 = (box.MinEdge.X / BS) + 0.5;
944 ty1 = (box.MinEdge.Y / BS) + 0.5;
945 tz1 = (box.MinEdge.Z / BS) + 0.5;
946 tx2 = (box.MaxEdge.X / BS) + 0.5;
947 ty2 = (box.MaxEdge.Y / BS) + 0.5;
948 tz2 = (box.MaxEdge.Z / BS) + 0.5;
950 tx1, 1-tz2, tx2, 1-tz1,
952 tz1, 1-ty2, tz2, 1-ty1,
953 1-tz2, 1-ty2, 1-tz1, 1-ty1,
954 1-tx2, 1-ty2, 1-tx1, 1-ty1,
955 tx1, 1-ty2, tx2, 1-ty1,
957 makeCuboid(&collector, box, &glass_tiles[i], 1, c, txc2);
960 if (param2 > 0 && f.special_tiles[0].texture) {
961 // Interior volume level is in range 0 .. 63,
962 // convert it to -0.5 .. 0.5
963 float vlev = (((float)param2 / 63.0 ) * 2.0 - 1.0);
964 TileSpec interior_tiles[6];
965 for (i = 0; i < 6; i++)
966 interior_tiles[i] = f.special_tiles[0];
967 float offset = 0.003;
968 box = aabb3f(visible_faces[3] ? -b : -a + offset,
969 visible_faces[1] ? -b : -a + offset,
970 visible_faces[5] ? -b : -a + offset,
971 visible_faces[2] ? b : a - offset,
972 visible_faces[0] ? b * vlev : a * vlev - offset,
973 visible_faces[4] ? b : a - offset);
976 tx1 = (box.MinEdge.X / BS) + 0.5;
977 ty1 = (box.MinEdge.Y / BS) + 0.5;
978 tz1 = (box.MinEdge.Z / BS) + 0.5;
979 tx2 = (box.MaxEdge.X / BS) + 0.5;
980 ty2 = (box.MaxEdge.Y / BS) + 0.5;
981 tz2 = (box.MaxEdge.Z / BS) + 0.5;
983 tx1, 1-tz2, tx2, 1-tz1,
985 tz1, 1-ty2, tz2, 1-ty1,
986 1-tz2, 1-ty2, 1-tz1, 1-ty1,
987 1-tx2, 1-ty2, 1-tx1, 1-ty1,
988 tx1, 1-ty2, tx2, 1-ty1,
990 makeCuboid(&collector, box, interior_tiles, 6, c, txc3);
995 TileSpec tile_leaves = getNodeTile(n, p,
998 u16 l = getInteriorLight(n, 1, nodedef);
999 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1001 v3f pos = intToFloat(p, BS);
1002 aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
1005 makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
1007 case NDT_ALLFACES_OPTIONAL:
1008 // This is always pre-converted to something else
1013 v3s16 dir = n.getWallMountedDir(nodedef);
1016 if(dir == v3s16(0,-1,0)){
1017 tileindex = 0; // floor
1018 } else if(dir == v3s16(0,1,0)){
1019 tileindex = 1; // ceiling
1020 // For backwards compatibility
1021 } else if(dir == v3s16(0,0,0)){
1022 tileindex = 0; // floor
1024 tileindex = 2; // side
1027 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1028 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1029 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1031 u16 l = getInteriorLight(n, 1, nodedef);
1032 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1034 float s = BS/2*f.visual_scale;
1035 // Wall at X+ of node
1036 video::S3DVertex vertices[4] =
1038 video::S3DVertex(-s,-s,0, 0,0,0, c, 0,1),
1039 video::S3DVertex( s,-s,0, 0,0,0, c, 1,1),
1040 video::S3DVertex( s, s,0, 0,0,0, c, 1,0),
1041 video::S3DVertex(-s, s,0, 0,0,0, c, 0,0),
1044 for(s32 i=0; i<4; i++)
1046 if(dir == v3s16(1,0,0))
1047 vertices[i].Pos.rotateXZBy(0);
1048 if(dir == v3s16(-1,0,0))
1049 vertices[i].Pos.rotateXZBy(180);
1050 if(dir == v3s16(0,0,1))
1051 vertices[i].Pos.rotateXZBy(90);
1052 if(dir == v3s16(0,0,-1))
1053 vertices[i].Pos.rotateXZBy(-90);
1054 if(dir == v3s16(0,-1,0))
1055 vertices[i].Pos.rotateXZBy(45);
1056 if(dir == v3s16(0,1,0))
1057 vertices[i].Pos.rotateXZBy(-45);
1059 vertices[i].Pos += intToFloat(p, BS);
1062 u16 indices[] = {0,1,2,2,3,0};
1063 // Add to mesh collector
1064 collector.append(tile, vertices, 4, indices, 6);
1068 TileSpec tile = getNodeTileN(n, p, 0, data);
1069 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1070 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1072 u16 l = getInteriorLight(n, 0, nodedef);
1073 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1075 float d = (float)BS/16;
1076 float s = BS/2*f.visual_scale;
1077 // Wall at X+ of node
1078 video::S3DVertex vertices[4] =
1080 video::S3DVertex(BS/2-d, s, s, 0,0,0, c, 0,0),
1081 video::S3DVertex(BS/2-d, s, -s, 0,0,0, c, 1,0),
1082 video::S3DVertex(BS/2-d, -s, -s, 0,0,0, c, 1,1),
1083 video::S3DVertex(BS/2-d, -s, s, 0,0,0, c, 0,1),
1086 v3s16 dir = n.getWallMountedDir(nodedef);
1088 for(s32 i=0; i<4; i++)
1090 if(dir == v3s16(1,0,0))
1091 vertices[i].Pos.rotateXZBy(0);
1092 if(dir == v3s16(-1,0,0))
1093 vertices[i].Pos.rotateXZBy(180);
1094 if(dir == v3s16(0,0,1))
1095 vertices[i].Pos.rotateXZBy(90);
1096 if(dir == v3s16(0,0,-1))
1097 vertices[i].Pos.rotateXZBy(-90);
1098 if(dir == v3s16(0,-1,0))
1099 vertices[i].Pos.rotateXYBy(-90);
1100 if(dir == v3s16(0,1,0))
1101 vertices[i].Pos.rotateXYBy(90);
1103 vertices[i].Pos += intToFloat(p, BS);
1106 u16 indices[] = {0,1,2,2,3,0};
1107 // Add to mesh collector
1108 collector.append(tile, vertices, 4, indices, 6);
1112 TileSpec tile = getNodeTileN(n, p, 0, data);
1113 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1115 u16 l = getInteriorLight(n, 1, nodedef);
1116 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1118 float s = BS / 2 * f.visual_scale;
1120 for (int j = 0; j < 2; j++)
1122 video::S3DVertex vertices[4] =
1124 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1125 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1126 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1127 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1132 for(u16 i = 0; i < 4; i++)
1133 vertices[i].Pos.rotateXZBy(46 + n.param2 * 2);
1137 for(u16 i = 0; i < 4; i++)
1138 vertices[i].Pos.rotateXZBy(-44 + n.param2 * 2);
1141 for (int i = 0; i < 4; i++)
1143 vertices[i].Pos *= f.visual_scale;
1144 vertices[i].Pos.Y += BS/2 * (f.visual_scale - 1);
1145 vertices[i].Pos += intToFloat(p, BS);
1148 u16 indices[] = {0, 1, 2, 2, 3, 0};
1149 // Add to mesh collector
1150 collector.append(tile, vertices, 4, indices, 6);
1155 TileSpec tile = getNodeTileN(n, p, 0, data);
1156 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1158 u16 l = getInteriorLight(n, 1, nodedef);
1159 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1161 float s = BS/2*f.visual_scale;
1163 content_t current = n.getContent();
1168 static const v3s16 dirs[6] = {
1177 int doDraw[6] = {0,0,0,0,0,0};
1179 bool drawAllFaces = true;
1181 bool drawBottomFacesOnly = false; // Currently unused
1183 // Check for adjacent nodes
1184 for(int i = 0; i < 6; i++)
1186 n2p = blockpos_nodes + p + dirs[i];
1187 n2 = data->m_vmanip.getNodeNoEx(n2p);
1188 n2c = n2.getContent();
1189 if (n2c != CONTENT_IGNORE && n2c != CONTENT_AIR && n2c != current) {
1192 drawAllFaces = false;
1197 for(int j = 0; j < 6; j++)
1199 int vOffset = 0; // Vertical offset of faces after rotation
1200 int hOffset = 4; // Horizontal offset of faces to reach the edge
1202 video::S3DVertex vertices[4] =
1204 video::S3DVertex(-s,-BS/2, 0, 0,0,0, c, 0,1),
1205 video::S3DVertex( s,-BS/2, 0, 0,0,0, c, 1,1),
1206 video::S3DVertex( s,-BS/2 + s*2,0, 0,0,0, c, 1,0),
1207 video::S3DVertex(-s,-BS/2 + s*2,0, 0,0,0, c, 0,0),
1210 // Calculate which faces should be drawn, (top or sides)
1211 if(j == 0 && (drawAllFaces || (doDraw[3] == 1 || doDraw[1] == 1)))
1213 for(int i = 0; i < 4; i++) {
1214 vertices[i].Pos.rotateXZBy(90 + n.param2 * 2);
1215 vertices[i].Pos.rotateXYBy(-10);
1216 vertices[i].Pos.Y -= vOffset;
1217 vertices[i].Pos.X -= hOffset;
1220 else if(j == 1 && (drawAllFaces || (doDraw[5] == 1 || doDraw[1] == 1)))
1222 for(int i = 0; i < 4; i++) {
1223 vertices[i].Pos.rotateXZBy(180 + n.param2 * 2);
1224 vertices[i].Pos.rotateYZBy(10);
1225 vertices[i].Pos.Y -= vOffset;
1226 vertices[i].Pos.Z -= hOffset;
1229 else if(j == 2 && (drawAllFaces || (doDraw[2] == 1 || doDraw[1] == 1)))
1231 for(int i = 0; i < 4; i++) {
1232 vertices[i].Pos.rotateXZBy(270 + n.param2 * 2);
1233 vertices[i].Pos.rotateXYBy(10);
1234 vertices[i].Pos.Y -= vOffset;
1235 vertices[i].Pos.X += hOffset;
1238 else if(j == 3 && (drawAllFaces || (doDraw[4] == 1 || doDraw[1] == 1)))
1240 for(int i = 0; i < 4; i++) {
1241 vertices[i].Pos.rotateYZBy(-10);
1242 vertices[i].Pos.Y -= vOffset;
1243 vertices[i].Pos.Z += hOffset;
1247 // Center cross-flames
1248 else if(j == 4 && (drawAllFaces || doDraw[1] == 1))
1250 for(int i=0; i<4; i++) {
1251 vertices[i].Pos.rotateXZBy(45 + n.param2 * 2);
1252 vertices[i].Pos.Y -= vOffset;
1255 else if(j == 5 && (drawAllFaces || doDraw[1] == 1))
1257 for(int i=0; i<4; i++) {
1258 vertices[i].Pos.rotateXZBy(-45 + n.param2 * 2);
1259 vertices[i].Pos.Y -= vOffset;
1263 // Render flames on bottom
1264 else if(j == 0 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
1266 for(int i = 0; i < 4; i++) {
1267 vertices[i].Pos.rotateYZBy(70);
1268 vertices[i].Pos.rotateXZBy(90 + n.param2 * 2);
1269 vertices[i].Pos.Y += 4.84;
1270 vertices[i].Pos.X -= hOffset+0.7;
1273 else if(j == 1 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
1275 for(int i = 0; i < 4; i++) {
1276 vertices[i].Pos.rotateYZBy(70);
1277 vertices[i].Pos.rotateXZBy(180 + n.param2 * 2);
1278 vertices[i].Pos.Y += 4.84;
1279 vertices[i].Pos.Z -= hOffset+0.7;
1282 else if(j == 2 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
1284 for(int i = 0; i < 4; i++) {
1285 vertices[i].Pos.rotateYZBy(70);
1286 vertices[i].Pos.rotateXZBy(270 + n.param2 * 2);
1287 vertices[i].Pos.Y += 4.84;
1288 vertices[i].Pos.X += hOffset+0.7;
1291 else if(j == 3 && (drawBottomFacesOnly || (doDraw[0] == 1 && doDraw[1] == 0)))
1293 for(int i = 0; i < 4; i++) {
1294 vertices[i].Pos.rotateYZBy(70);
1295 vertices[i].Pos.Y += 4.84;
1296 vertices[i].Pos.Z += hOffset+0.7;
1300 // Skip faces that aren't adjacent to a node
1304 for(int i=0; i<4; i++)
1306 vertices[i].Pos *= f.visual_scale;
1307 vertices[i].Pos += intToFloat(p, BS);
1310 u16 indices[] = {0,1,2,2,3,0};
1311 // Add to mesh collector
1312 collector.append(tile, vertices, 4, indices, 6);
1317 TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1318 TileSpec tile_nocrack = tile;
1319 tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1321 // Put wood the right way around in the posts
1322 TileSpec tile_rot = tile;
1323 tile_rot.rotation = 1;
1325 u16 l = getInteriorLight(n, 1, nodedef);
1326 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1328 const f32 post_rad=(f32)BS/8;
1329 const f32 bar_rad=(f32)BS/16;
1330 const f32 bar_len=(f32)(BS/2)-post_rad;
1332 v3f pos = intToFloat(p, BS);
1334 // The post - always present
1335 aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
1336 post.MinEdge += pos;
1337 post.MaxEdge += pos;
1339 6/16.,6/16.,10/16.,10/16.,
1340 6/16.,6/16.,10/16.,10/16.,
1345 makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1347 // Now a section of fence, +X, if there's a post there
1350 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1351 const ContentFeatures *f2 = &nodedef->get(n2);
1352 if(f2->drawtype == NDT_FENCELIKE)
1354 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1355 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1359 0/16.,2/16.,16/16.,4/16.,
1360 0/16.,4/16.,16/16.,6/16.,
1361 6/16.,6/16.,8/16.,8/16.,
1362 10/16.,10/16.,12/16.,12/16.,
1363 0/16.,8/16.,16/16.,10/16.,
1364 0/16.,14/16.,16/16.,16/16.};
1365 makeCuboid(&collector, bar, &tile_nocrack, 1,
1367 bar.MinEdge.Y -= BS/2;
1368 bar.MaxEdge.Y -= BS/2;
1369 makeCuboid(&collector, bar, &tile_nocrack, 1,
1373 // Now a section of fence, +Z, if there's a post there
1376 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1377 f2 = &nodedef->get(n2);
1378 if(f2->drawtype == NDT_FENCELIKE)
1380 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1381 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1385 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
1386 4/16.,1/16.,6/16.,5/16., // for wood texture instead
1387 0/16.,9/16.,16/16.,11/16.,
1388 0/16.,6/16.,16/16.,8/16.,
1389 6/16.,6/16.,8/16.,8/16.,
1390 10/16.,10/16.,12/16.,12/16.};
1391 makeCuboid(&collector, bar, &tile_nocrack, 1,
1393 bar.MinEdge.Y -= BS/2;
1394 bar.MaxEdge.Y -= BS/2;
1395 makeCuboid(&collector, bar, &tile_nocrack, 1,
1401 bool is_rail_x [] = { false, false }; /* x-1, x+1 */
1402 bool is_rail_z [] = { false, false }; /* z-1, z+1 */
1404 bool is_rail_z_minus_y [] = { false, false }; /* z-1, z+1; y-1 */
1405 bool is_rail_x_minus_y [] = { false, false }; /* x-1, z+1; y-1 */
1406 bool is_rail_z_plus_y [] = { false, false }; /* z-1, z+1; y+1 */
1407 bool is_rail_x_plus_y [] = { false, false }; /* x-1, x+1; y+1 */
1409 MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
1410 MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
1411 MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
1412 MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
1413 MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
1414 MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
1415 MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
1416 MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
1417 MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
1418 MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
1419 MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
1420 MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
1422 content_t thiscontent = n.getContent();
1423 std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
1424 bool self_connect_to_raillike = ((ItemGroupList) nodedef->get(n).groups)[groupname] != 0;
1426 if ((nodedef->get(n_minus_x).drawtype == NDT_RAILLIKE
1427 && ((ItemGroupList) nodedef->get(n_minus_x).groups)[groupname] != 0
1428 && self_connect_to_raillike)
1429 || n_minus_x.getContent() == thiscontent)
1430 is_rail_x[0] = true;
1432 if ((nodedef->get(n_minus_x_minus_y).drawtype == NDT_RAILLIKE
1433 && ((ItemGroupList) nodedef->get(n_minus_x_minus_y).groups)[groupname] != 0
1434 && self_connect_to_raillike)
1435 || n_minus_x_minus_y.getContent() == thiscontent)
1436 is_rail_x_minus_y[0] = true;
1438 if ((nodedef->get(n_minus_x_plus_y).drawtype == NDT_RAILLIKE
1439 && ((ItemGroupList) nodedef->get(n_minus_x_plus_y).groups)[groupname] != 0
1440 && self_connect_to_raillike)
1441 || n_minus_x_plus_y.getContent() == thiscontent)
1442 is_rail_x_plus_y[0] = true;
1444 if ((nodedef->get(n_plus_x).drawtype == NDT_RAILLIKE
1445 && ((ItemGroupList) nodedef->get(n_plus_x).groups)[groupname] != 0
1446 && self_connect_to_raillike)
1447 || n_plus_x.getContent() == thiscontent)
1448 is_rail_x[1] = true;
1450 if ((nodedef->get(n_plus_x_minus_y).drawtype == NDT_RAILLIKE
1451 && ((ItemGroupList) nodedef->get(n_plus_x_minus_y).groups)[groupname] != 0
1452 && self_connect_to_raillike)
1453 || n_plus_x_minus_y.getContent() == thiscontent)
1454 is_rail_x_minus_y[1] = true;
1456 if ((nodedef->get(n_plus_x_plus_y).drawtype == NDT_RAILLIKE
1457 && ((ItemGroupList) nodedef->get(n_plus_x_plus_y).groups)[groupname] != 0
1458 && self_connect_to_raillike)
1459 || n_plus_x_plus_y.getContent() == thiscontent)
1460 is_rail_x_plus_y[1] = true;
1462 if ((nodedef->get(n_minus_z).drawtype == NDT_RAILLIKE
1463 && ((ItemGroupList) nodedef->get(n_minus_z).groups)[groupname] != 0
1464 && self_connect_to_raillike)
1465 || n_minus_z.getContent() == thiscontent)
1466 is_rail_z[0] = true;
1468 if ((nodedef->get(n_minus_z_minus_y).drawtype == NDT_RAILLIKE
1469 && ((ItemGroupList) nodedef->get(n_minus_z_minus_y).groups)[groupname] != 0
1470 && self_connect_to_raillike)
1471 || n_minus_z_minus_y.getContent() == thiscontent)
1472 is_rail_z_minus_y[0] = true;
1474 if ((nodedef->get(n_minus_z_plus_y).drawtype == NDT_RAILLIKE
1475 && ((ItemGroupList) nodedef->get(n_minus_z_plus_y).groups)[groupname] != 0
1476 && self_connect_to_raillike)
1477 || n_minus_z_plus_y.getContent() == thiscontent)
1478 is_rail_z_plus_y[0] = true;
1480 if ((nodedef->get(n_plus_z).drawtype == NDT_RAILLIKE
1481 && ((ItemGroupList) nodedef->get(n_plus_z).groups)[groupname] != 0
1482 && self_connect_to_raillike)
1483 || n_plus_z.getContent() == thiscontent)
1484 is_rail_z[1] = true;
1486 if ((nodedef->get(n_plus_z_minus_y).drawtype == NDT_RAILLIKE
1487 && ((ItemGroupList) nodedef->get(n_plus_z_minus_y).groups)[groupname] != 0
1488 && self_connect_to_raillike)
1489 || n_plus_z_minus_y.getContent() == thiscontent)
1490 is_rail_z_minus_y[1] = true;
1492 if ((nodedef->get(n_plus_z_plus_y).drawtype == NDT_RAILLIKE
1493 && ((ItemGroupList) nodedef->get(n_plus_z_plus_y).groups)[groupname] != 0
1494 && self_connect_to_raillike)
1495 || n_plus_z_plus_y.getContent() == thiscontent)
1496 is_rail_z_plus_y[1] = true;
1498 bool is_rail_x_all[] = {false, false};
1499 bool is_rail_z_all[] = {false, false};
1500 is_rail_x_all[0]=is_rail_x[0] || is_rail_x_minus_y[0] || is_rail_x_plus_y[0];
1501 is_rail_x_all[1]=is_rail_x[1] || is_rail_x_minus_y[1] || is_rail_x_plus_y[1];
1502 is_rail_z_all[0]=is_rail_z[0] || is_rail_z_minus_y[0] || is_rail_z_plus_y[0];
1503 is_rail_z_all[1]=is_rail_z[1] || is_rail_z_minus_y[1] || is_rail_z_plus_y[1];
1505 // reasonable default, flat straight unrotated rail
1506 bool is_straight = true;
1507 int adjacencies = 0;
1511 // check for sloped rail
1512 if (is_rail_x_plus_y[0] || is_rail_x_plus_y[1] || is_rail_z_plus_y[0] || is_rail_z_plus_y[1])
1514 adjacencies = 5; //5 means sloped
1515 is_straight = true; // sloped is always straight
1519 // is really straight, rails on both sides
1520 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
1521 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
1524 switch (adjacencies) {
1526 if(is_rail_x_all[0] || is_rail_x_all[1])
1531 tileindex = 1; // curved
1532 if(is_rail_x_all[0] && is_rail_x_all[1])
1534 if(is_rail_z_all[0] && is_rail_z_all[1]){
1535 if (is_rail_z_plus_y[0])
1538 else if(is_rail_x_all[0] && is_rail_z_all[0])
1540 else if(is_rail_x_all[0] && is_rail_z_all[1])
1542 else if(is_rail_x_all[1] && is_rail_z_all[1])
1546 // here is where the potential to 'switch' a junction is, but not implemented at present
1547 tileindex = 2; // t-junction
1548 if(!is_rail_x_all[1])
1550 if(!is_rail_z_all[0])
1552 if(!is_rail_z_all[1])
1556 tileindex = 3; // crossing
1559 if(is_rail_z_plus_y[0])
1561 if(is_rail_x_plus_y[0])
1563 if(is_rail_x_plus_y[1])
1570 TileSpec tile = getNodeTileN(n, p, tileindex, data);
1571 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1572 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1574 u16 l = getInteriorLight(n, 0, nodedef);
1575 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1577 float d = (float)BS/64;
1581 if (is_rail_x_plus_y[0] || is_rail_x_plus_y[1] || is_rail_z_plus_y[0] || is_rail_z_plus_y[1])
1582 g = 1; //Object is at a slope
1584 video::S3DVertex vertices[4] =
1586 video::S3DVertex(-s, -s+d,-s, 0,0,0, c,0,1),
1587 video::S3DVertex( s, -s+d,-s, 0,0,0, c,1,1),
1588 video::S3DVertex( s, g*s+d, s, 0,0,0, c,1,0),
1589 video::S3DVertex(-s, g*s+d, s, 0,0,0, c,0,0),
1592 for(s32 i=0; i<4; i++)
1595 vertices[i].Pos.rotateXZBy(angle);
1596 vertices[i].Pos += intToFloat(p, BS);
1599 u16 indices[] = {0,1,2,2,3,0};
1600 collector.append(tile, vertices, 4, indices, 6);
1604 static const v3s16 tile_dirs[6] = {
1614 u16 l = getInteriorLight(n, 1, nodedef);
1615 video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1617 v3f pos = intToFloat(p, BS);
1619 std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1620 for(std::vector<aabb3f>::iterator
1622 i != boxes.end(); i++)
1624 for(int j = 0; j < 6; j++)
1626 // Handles facedir rotation for textures
1627 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1634 if (box.MinEdge.X > box.MaxEdge.X)
1637 box.MinEdge.X=box.MaxEdge.X;
1640 if (box.MinEdge.Y > box.MaxEdge.Y)
1643 box.MinEdge.Y=box.MaxEdge.Y;
1646 if (box.MinEdge.Z > box.MaxEdge.Z)
1649 box.MinEdge.Z=box.MaxEdge.Z;
1654 // Compute texture coords
1655 f32 tx1 = (box.MinEdge.X/BS)+0.5;
1656 f32 ty1 = (box.MinEdge.Y/BS)+0.5;
1657 f32 tz1 = (box.MinEdge.Z/BS)+0.5;
1658 f32 tx2 = (box.MaxEdge.X/BS)+0.5;
1659 f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
1660 f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
1663 tx1, 1-tz2, tx2, 1-tz1,
1667 tz1, 1-ty2, tz2, 1-ty1,
1669 1-tz2, 1-ty2, 1-tz1, 1-ty1,
1671 1-tx2, 1-ty2, 1-tx1, 1-ty1,
1673 tx1, 1-ty2, tx2, 1-ty1,
1675 makeCuboid(&collector, box, tiles, 6, c, txc);
1680 v3f pos = intToFloat(p, BS);
1681 video::SColor c = MapBlock_LightColor(255, getInteriorLight(n, 1, nodedef), f.light_source);
1684 if (f.param_type_2 == CPT2_FACEDIR) {
1685 facedir = n.getFaceDir(nodedef);
1686 } else if (f.param_type_2 == CPT2_WALLMOUNTED) {
1687 //convert wallmounted to 6dfacedir.
1688 //when cache enabled, it is already converted
1689 facedir = n.getWallMounted(nodedef);
1690 if (!enable_mesh_cache) {
1691 static const u8 wm_to_6d[6] = {20, 0, 16+1, 12+3, 8, 4+2};
1692 facedir = wm_to_6d[facedir];
1696 if (f.mesh_ptr[facedir]) {
1697 // use cached meshes
1698 for(u16 j = 0; j < f.mesh_ptr[0]->getMeshBufferCount(); j++) {
1699 scene::IMeshBuffer *buf = f.mesh_ptr[facedir]->getMeshBuffer(j);
1700 collector.append(getNodeTileN(n, p, j, data),
1701 (video::S3DVertex *)buf->getVertices(), buf->getVertexCount(),
1702 buf->getIndices(), buf->getIndexCount(), pos, c);
1704 } else if (f.mesh_ptr[0]) {
1705 // no cache, clone and rotate mesh
1706 scene::IMesh* mesh = cloneMesh(f.mesh_ptr[0]);
1707 rotateMeshBy6dFacedir(mesh, facedir);
1708 recalculateBoundingBox(mesh);
1709 meshmanip->recalculateNormals(mesh, true, false);
1710 for(u16 j = 0; j < mesh->getMeshBufferCount(); j++) {
1711 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
1712 collector.append(getNodeTileN(n, p, j, data),
1713 (video::S3DVertex *)buf->getVertices(), buf->getVertexCount(),
1714 buf->getIndices(), buf->getIndexCount(), pos, c);
1723 Caused by incorrect alpha blending, selection mesh needs to be created as
1724 last element to ensure it gets blended correct over nodes with alpha channel
1726 // Create selection mesh
1727 v3s16 p = data->m_highlighted_pos_relative;
1728 if (data->m_show_hud &&
1729 (p.X >= 0) && (p.X < MAP_BLOCKSIZE) &&
1730 (p.Y >= 0) && (p.Y < MAP_BLOCKSIZE) &&
1731 (p.Z >= 0) && (p.Z < MAP_BLOCKSIZE)) {
1733 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
1734 if(n.getContent() != CONTENT_AIR) {
1735 // Get selection mesh light level
1736 static const v3s16 dirs[7] = {
1748 for (u8 i = 0; i < 7; i++) {
1749 MapNode n1 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dirs[i]);
1750 l1 = getInteriorLight(n1, -4, nodedef);
1754 video::SColor c = MapBlock_LightColor(255, l, 0);
1755 data->m_highlight_mesh_color = c;
1756 std::vector<aabb3f> boxes = n.getSelectionBoxes(nodedef);
1758 h_tile.material_flags |= MATERIAL_FLAG_HIGHLIGHTED;
1759 h_tile.texture = tsrc->getTexture("halo.png",&h_tile.texture_id);
1760 v3f pos = intToFloat(p, BS);
1762 for (std::vector<aabb3f>::iterator i = boxes.begin();
1763 i != boxes.end(); i++) {
1765 box.MinEdge += v3f(-d, -d, -d) + pos;
1766 box.MaxEdge += v3f(d, d, d) + pos;
1767 makeCuboid(&collector, box, &h_tile, 1, c, NULL);