Remove new_style_water
[oweals/minetest.git] / src / content_mapblock.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
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
24 #include "settings.h"
25 #include "nodedef.h"
26 #include "client/tile.h"
27 #include "mesh.h"
28 #include <IMeshManipulator.h>
29 #include "gamedef.h"
30 #include "log.h"
31
32
33 // Create a cuboid.
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)
48 {
49         assert(tilecount >= 1 && tilecount <= 6); // pre-condition
50
51         v3f min = box.MinEdge;
52         v3f max = box.MaxEdge;
53
54
55
56         if(txc == NULL) {
57                 static const f32 txc_default[24] = {
58                         0,0,1,1,
59                         0,0,1,1,
60                         0,0,1,1,
61                         0,0,1,1,
62                         0,0,1,1,
63                         0,0,1,1
64                 };
65                 txc = txc_default;
66         }
67
68         video::S3DVertex vertices[24] =
69         {
70                 // up
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]),
75                 // down
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]),
80                 // right
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]),
85                 // left
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]),
90                 // back
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]),
95                 // front
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]),
100         };
101
102         for(int i = 0; i < 6; i++)
103                                 {
104                                 switch (tiles[MYMIN(i, tilecount-1)].rotation)
105                                 {
106                                 case 0:
107                                         break;
108                                 case 1: //R90
109                                         for (int x = 0; x < 4; x++)
110                                                 vertices[i*4+x].TCoords.rotateBy(90,irr::core::vector2df(0, 0));
111                                         break;
112                                 case 2: //R180
113                                         for (int x = 0; x < 4; x++)
114                                                 vertices[i*4+x].TCoords.rotateBy(180,irr::core::vector2df(0, 0));
115                                         break;
116                                 case 3: //R270
117                                         for (int x = 0; x < 4; x++)
118                                                 vertices[i*4+x].TCoords.rotateBy(270,irr::core::vector2df(0, 0));
119                                         break;
120                                 case 4: //FXR90
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));
124                                         }
125                                         break;
126                                 case 5: //FXR270
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));
130                                         }
131                                         break;
132                                 case 6: //FYR90
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));
136                                         }
137                                         break;
138                                 case 7: //FYR270
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));
142                                         }
143                                         break;
144                                 case 8: //FX
145                                         for (int x = 0; x < 4; x++){
146                                                 vertices[i*4+x].TCoords.X = 1.0 - vertices[i*4+x].TCoords.X;
147                                         }
148                                         break;
149                                 case 9: //FY
150                                         for (int x = 0; x < 4; x++){
151                                                 vertices[i*4+x].TCoords.Y = 1.0 - vertices[i*4+x].TCoords.Y;
152                                         }
153                                         break;
154                                 default:
155                                         break;
156                                 }
157                         }
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);
163         }
164 }
165
166 /*
167         TODO: Fix alpha blending for special nodes
168         Currently only the last element rendered is blended correct
169 */
170 void mapblock_mesh_generate_special(MeshMakeData *data,
171                 MeshCollector &collector)
172 {
173         INodeDefManager *nodedef = data->m_gamedef->ndef();
174         scene::ISceneManager* smgr = data->m_gamedef->getSceneManager();
175         scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator();
176
177         // 0ms
178         //TimeTaker timer("mapblock_mesh_generate_special()");
179
180         /*
181                 Some settings
182         */
183         bool enable_mesh_cache  = g_settings->getBool("enable_mesh_cache");
184
185         v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
186
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++)
190         {
191                 v3s16 p(x,y,z);
192
193                 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
194                 const ContentFeatures &f = nodedef->get(n);
195
196                 // Only solidness=0 stuff is drawn here
197                 if(f.solidness != 0)
198                         continue;
199
200                 switch(f.drawtype){
201                 default:
202                         infostream << "Got " << f.drawtype << std::endl;
203                         FATAL_ERROR("Unknown drawtype");
204                         break;
205                 case NDT_AIRLIKE:
206                         break;
207                 case NDT_LIQUID:
208                 {
209                         /*
210                                 Add water sources to mesh if using new style
211                         */
212                         TileSpec tile_liquid = f.special_tiles[0];
213                         TileSpec tile_liquid_bfculled = getNodeTile(n, p, v3s16(0,0,0), data);
214
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;
221
222                         u16 l = getInteriorLight(n, 0, nodedef);
223                         video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
224
225                         /*
226                                 Generate sides
227                          */
228                         v3s16 side_dirs[4] = {
229                                 v3s16(1,0,0),
230                                 v3s16(-1,0,0),
231                                 v3s16(0,0,1),
232                                 v3s16(0,0,-1),
233                         };
234                         for(u32 i=0; i<4; i++)
235                         {
236                                 v3s16 dir = side_dirs[i];
237
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();
243
244                                 if(neighbor_content == CONTENT_IGNORE)
245                                         continue;
246
247                                 /*
248                                         If our topside is liquid and neighbor's topside
249                                         is liquid, don't draw side face
250                                 */
251                                 if(top_is_same_liquid && (n_top_c == c_flowing ||
252                                                 n_top_c == c_source || n_top_c == CONTENT_IGNORE))
253                                         continue;
254
255                                 // Don't draw face if neighbor is blocking the view
256                                 if(n_feat.solidness == 2)
257                                         continue;
258
259                                 bool neighbor_is_same_liquid = (neighbor_content == c_source
260                                                 || neighbor_content == c_flowing);
261
262                                 // Don't draw any faces if neighbor same is liquid and top is
263                                 // same liquid
264                                 if(neighbor_is_same_liquid && !top_is_same_liquid)
265                                         continue;
266
267                                 // Use backface culled material if neighbor doesn't have a
268                                 // solidness of 0
269                                 const TileSpec *current_tile = &tile_liquid;
270                                 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
271                                         current_tile = &tile_liquid_bfculled;
272
273                                 video::S3DVertex vertices[4] =
274                                 {
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),
279                                 };
280
281                                 /*
282                                         If our topside is liquid, set upper border of face
283                                         at upper border of node
284                                 */
285                                 if (top_is_same_liquid) {
286                                         vertices[2].Pos.Y = 0.5 * BS;
287                                         vertices[3].Pos.Y = 0.5 * BS;
288                                 } else {
289                                 /*
290                                         Otherwise upper position of face is liquid level
291                                 */
292                                         vertices[2].Pos.Y = 0.5 * BS;
293                                         vertices[3].Pos.Y = 0.5 * BS;
294                                 }
295                                 /*
296                                         If neighbor is liquid, lower border of face is liquid level
297                                 */
298                                 if (neighbor_is_same_liquid) {
299                                         vertices[0].Pos.Y = 0.5 * BS;
300                                         vertices[1].Pos.Y = 0.5 * BS;
301                                 } else {
302                                 /*
303                                         If neighbor is not liquid, lower border of face is
304                                         lower border of node
305                                 */
306                                         vertices[0].Pos.Y = -0.5 * BS;
307                                         vertices[1].Pos.Y = -0.5 * BS;
308                                 }
309
310                                 for(s32 j=0; j<4; j++)
311                                 {
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);
320
321                                         // Do this to not cause glitches when two liquids are
322                                         // side-by-side
323                                         /*if(neighbor_is_same_liquid == false){
324                                                 vertices[j].Pos.X *= 0.98;
325                                                 vertices[j].Pos.Z *= 0.98;
326                                         }*/
327
328                                         vertices[j].Pos += intToFloat(p, BS);
329                                 }
330
331                                 u16 indices[] = {0,1,2,2,3,0};
332                                 // Add to mesh collector
333                                 collector.append(*current_tile, vertices, 4, indices, 6);
334                         }
335
336                         /*
337                                 Generate top
338                          */
339                         if(top_is_same_liquid)
340                                 continue;
341
342                         video::S3DVertex vertices[4] =
343                         {
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),
348                         };
349
350                         v3f offset(p.X * BS, (p.Y + 0.5) * BS, p.Z * BS);
351                         for(s32 i=0; i<4; i++)
352                         {
353                                 vertices[i].Pos += offset;
354                         }
355
356                         u16 indices[] = {0,1,2,2,3,0};
357                         // Add to mesh collector
358                         collector.append(tile_liquid, vertices, 4, indices, 6);
359                 break;}
360                 case NDT_FLOWINGLIQUID:
361                 {
362                         /*
363                                 Add flowing liquid to mesh
364                         */
365                         TileSpec tile_liquid = f.special_tiles[0];
366                         TileSpec tile_liquid_bfculled = f.special_tiles[1];
367
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;
374
375                         u16 l = 0;
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);
381                                 l = l | (l<<8);
382                         }
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)
387                         else
388                                 l = getInteriorLight(n, 0, nodedef);
389                         video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
390
391                         u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
392
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] = {
400                                 v3s16(0,0,0),
401                                 v3s16(0,0,1),
402                                 v3s16(0,0,-1),
403                                 v3s16(1,0,0),
404                                 v3s16(-1,0,0),
405                                 v3s16(1,0,1),
406                                 v3s16(-1,0,-1),
407                                 v3s16(1,0,-1),
408                                 v3s16(-1,0,1),
409                         };
410                         for(u32 i=0; i<9; i++)
411                         {
412                                 content_t content = CONTENT_AIR;
413                                 float level = -0.5 * BS;
414                                 u8 flags = 0;
415                                 // Check neighbor
416                                 v3s16 p2 = p + neighbor_dirs[i];
417                                 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
418                                 if(n2.getContent() != CONTENT_IGNORE)
419                                 {
420                                         content = n2.getContent();
421
422                                         if(n2.getContent() == c_source)
423                                                 level = 0.5 * BS;
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)
427                                                         liquid_level = 0;
428                                                 else
429                                                         liquid_level -= (LIQUID_LEVEL_MAX+1-range);
430                                                 level = (-0.5 + ((float)liquid_level + 0.5) / (float)range) * BS;
431                                         }
432
433                                         // Check node above neighbor.
434                                         // NOTE: This doesn't get executed if neighbor
435                                         //       doesn't exist
436                                         p2.Y += 1;
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;
441                                 }
442
443                                 neighbor_levels[neighbor_dirs[i]] = level;
444                                 neighbor_contents[neighbor_dirs[i]] = content;
445                                 neighbor_flags[neighbor_dirs[i]] = flags;
446                         }
447
448                         // Corner heights (average between four liquids)
449                         f32 corner_levels[4];
450
451                         v3s16 halfdirs[4] = {
452                                 v3s16(0,0,0),
453                                 v3s16(1,0,0),
454                                 v3s16(1,0,1),
455                                 v3s16(0,0,1),
456                         };
457                         for(u32 i=0; i<4; i++)
458                         {
459                                 v3s16 cornerdir = halfdirs[i];
460                                 float cornerlevel = 0;
461                                 u32 valid_count = 0;
462                                 u32 air_count = 0;
463                                 for(u32 j=0; j<4; j++)
464                                 {
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)
470                                         {
471                                                 cornerlevel = 0.5*BS;
472                                                 valid_count = 1;
473                                                 break;
474                                         }
475                                         // Source is always the same height
476                                         else if(content == c_source)
477                                         {
478                                                 cornerlevel = 0.5 * BS;
479                                                 valid_count = 1;
480                                                 break;
481                                         }
482                                         // Flowing liquid has level information
483                                         else if(content == c_flowing)
484                                         {
485                                                 cornerlevel += neighbor_levels[neighbordir];
486                                                 valid_count++;
487                                         }
488                                         else if(content == CONTENT_AIR)
489                                         {
490                                                 air_count++;
491                                         }
492                                 }
493                                 if(air_count >= 2)
494                                         cornerlevel = -0.5*BS+0.2;
495                                 else if(valid_count > 0)
496                                         cornerlevel /= valid_count;
497                                 corner_levels[i] = cornerlevel;
498                         }
499
500                         /*
501                                 Generate sides
502                         */
503
504                         v3s16 side_dirs[4] = {
505                                 v3s16(1,0,0),
506                                 v3s16(-1,0,0),
507                                 v3s16(0,0,1),
508                                 v3s16(0,0,-1),
509                         };
510                         s16 side_corners[4][2] = {
511                                 {1, 2},
512                                 {3, 0},
513                                 {2, 3},
514                                 {0, 1},
515                         };
516                         for(u32 i=0; i<4; i++)
517                         {
518                                 v3s16 dir = side_dirs[i];
519
520                                 /*
521                                         If our topside is liquid and neighbor's topside
522                                         is liquid, don't draw side face
523                                 */
524                                 if(top_is_same_liquid &&
525                                                 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
526                                         continue;
527
528                                 content_t neighbor_content = neighbor_contents[dir];
529                                 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
530
531                                 // Don't draw face if neighbor is blocking the view
532                                 if(n_feat.solidness == 2)
533                                         continue;
534
535                                 bool neighbor_is_same_liquid = (neighbor_content == c_source
536                                                 || neighbor_content == c_flowing);
537
538                                 // Don't draw any faces if neighbor same is liquid and top is
539                                 // same liquid
540                                 if(neighbor_is_same_liquid == true
541                                                 && top_is_same_liquid == false)
542                                         continue;
543
544                                 // Use backface culled material if neighbor doesn't have a
545                                 // solidness of 0
546                                 const TileSpec *current_tile = &tile_liquid;
547                                 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
548                                         current_tile = &tile_liquid_bfculled;
549
550                                 video::S3DVertex vertices[4] =
551                                 {
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),
556                                 };
557
558                                 /*
559                                         If our topside is liquid, set upper border of face
560                                         at upper border of node
561                                 */
562                                 if(top_is_same_liquid)
563                                 {
564                                         vertices[2].Pos.Y = 0.5*BS;
565                                         vertices[3].Pos.Y = 0.5*BS;
566                                 }
567                                 /*
568                                         Otherwise upper position of face is corner levels
569                                 */
570                                 else
571                                 {
572                                         vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
573                                         vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
574                                 }
575
576                                 /*
577                                         If neighbor is liquid, lower border of face is corner
578                                         liquid levels
579                                 */
580                                 if(neighbor_is_same_liquid)
581                                 {
582                                         vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
583                                         vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
584                                 }
585                                 /*
586                                         If neighbor is not liquid, lower border of face is
587                                         lower border of node
588                                 */
589                                 else
590                                 {
591                                         vertices[0].Pos.Y = -0.5*BS;
592                                         vertices[1].Pos.Y = -0.5*BS;
593                                 }
594
595                                 for(s32 j=0; j<4; j++)
596                                 {
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);
605
606                                         // Do this to not cause glitches when two liquids are
607                                         // side-by-side
608                                         /*if(neighbor_is_same_liquid == false){
609                                                 vertices[j].Pos.X *= 0.98;
610                                                 vertices[j].Pos.Z *= 0.98;
611                                         }*/
612
613                                         vertices[j].Pos += intToFloat(p, BS);
614                                 }
615
616                                 u16 indices[] = {0,1,2,2,3,0};
617                                 // Add to mesh collector
618                                 collector.append(*current_tile, vertices, 4, indices, 6);
619                         }
620
621                         /*
622                                 Generate top side, if appropriate
623                         */
624
625                         if(top_is_same_liquid == false)
626                         {
627                                 video::S3DVertex vertices[4] =
628                                 {
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),
633                                 };
634
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};
639
640                                 for(s32 i=0; i<4; i++)
641                                 {
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);
647                                 }
648
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);
670
671                                 for(s32 i=0; i<4; i++)
672                                 {
673                                         vertices[i].TCoords.rotateBy(
674                                                         tcoord_angle,
675                                                         tcoord_center);
676                                         vertices[i].TCoords += tcoord_translate;
677                                 }
678
679                                 v2f t = vertices[0].TCoords;
680                                 vertices[0].TCoords = vertices[2].TCoords;
681                                 vertices[2].TCoords = t;
682
683                                 u16 indices[] = {0,1,2,2,3,0};
684                                 // Add to mesh collector
685                                 collector.append(tile_liquid, vertices, 4, indices, 6);
686                         }
687                 break;}
688                 case NDT_GLASSLIKE:
689                 {
690                         TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
691
692                         u16 l = getInteriorLight(n, 1, nodedef);
693                         video::SColor c = MapBlock_LightColor(255, l, f.light_source);
694
695                         for(u32 j=0; j<6; j++)
696                         {
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())
703                                         continue;
704
705                                 // The face at Z+
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),
711                                 };
712
713                                 // Rotations in the g_6dirs format
714                                 if(j == 0) // Z+
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);
732
733                                 for(u16 i=0; i<4; i++){
734                                         vertices[i].Pos += intToFloat(p, BS);
735                                 }
736
737                                 u16 indices[] = {0,1,2,2,3,0};
738                                 // Add to mesh collector
739                                 collector.append(tile, vertices, 4, indices, 6);
740                         }
741                 break;}
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");
745                         break;
746                 case NDT_GLASSLIKE_FRAMED:
747                 {
748                         static const v3s16 dirs[6] = {
749                                 v3s16( 0, 1, 0),
750                                 v3s16( 0,-1, 0),
751                                 v3s16( 1, 0, 0),
752                                 v3s16(-1, 0, 0),
753                                 v3s16( 0, 0, 1),
754                                 v3s16( 0, 0,-1)
755                         };
756
757                         u8 i;
758                         TileSpec tiles[6];
759                         for (i = 0; i < 6; i++)
760                                 tiles[i] = getNodeTile(n, p, dirs[i], data);
761
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];
770                         } else {
771                                 for (i = 0; i < 6; i++)
772                                         glass_tiles[i] = tiles[1];
773                         }
774
775                         u8 param2 = n.getParam2();
776                         bool H_merge = ! bool(param2 & 128);
777                         bool V_merge = ! bool(param2 & 64);
778                         param2  = param2 & 63;
779
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 );
786
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-
800                         };
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-
808                         };
809
810                         // table of node visible faces, 0 = invisible
811                         int visible_faces[6] = {0,0,0,0,0,0};
812
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};
815
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};
818
819                         content_t current = n.getContent();
820                         content_t n2c;
821                         MapNode n2;
822                         v3s16 n2p;
823
824                         // neighbours checks for frames visibility
825
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)
831                                         nb[1] = 1;
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)
836                                         nb[4] = 1;
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;
844                                 }
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)
851                                                 nb[i] = 1;
852                                 }
853                         }
854
855                         // faces visibility checks
856
857                         if (!V_merge) {
858                                 visible_faces[0] = 1;
859                                 visible_faces[1] = 1;
860                         } else {
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();
865                                         if (n2c != current)
866                                                 visible_faces[i] = 1;
867                                 }
868                         }
869
870                         if (!H_merge) {
871                                 visible_faces[2] = 1;
872                                 visible_faces[3] = 1;
873                                 visible_faces[4] = 1;
874                                 visible_faces[5] = 1;
875                         } else {
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();
880                                         if (n2c != current)
881                                                 visible_faces[i] = 1;
882                                 }
883                         }
884
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
889                         };
890
891                         f32 tx1, ty1, tz1, tx2, ty2, tz2;
892                         aabb3f box;
893
894                         for(i = 0; i < 12; i++)
895                         {
896                                 int edge_invisible;
897                                 if (nb[nb_triplet[i*3+2]])
898                                         edge_invisible = nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
899                                 else
900                                         edge_invisible = nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
901                                 if (edge_invisible)
902                                         continue;
903                                 box = frame_edges[i];
904                                 box.MinEdge += pos;
905                                 box.MaxEdge += pos;
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;
912                                 f32 txc1[24] = {
913                                         tx1,   1-tz2,   tx2, 1-tz1,
914                                         tx1,     tz1,   tx2,   tz2,
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,
919                                 };
920                                 makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
921                         }
922
923                         for(i = 0; i < 6; i++)
924                         {
925                                 if (!visible_faces[i])
926                                         continue;
927                                 box = glass_faces[i];
928                                 box.MinEdge += pos;
929                                 box.MaxEdge += pos;
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;
936                                 f32 txc2[24] = {
937                                         tx1,   1-tz2,   tx2, 1-tz1,
938                                         tx1,     tz1,   tx2,   tz2,
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,
943                                 };
944                                 makeCuboid(&collector, box, &glass_tiles[i], 1, c, txc2);
945                         }
946
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);
961                                 box.MinEdge += pos;
962                                 box.MaxEdge += pos;
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;
969                                 f32 txc3[24] = {
970                                         tx1,   1-tz2,   tx2, 1-tz1,
971                                         tx1,     tz1,   tx2,   tz2,
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,
976                                 };
977                                 makeCuboid(&collector, box, interior_tiles, 6, c,  txc3);
978                         }
979                 break;}
980                 case NDT_ALLFACES:
981                 {
982                         TileSpec tile_leaves = getNodeTile(n, p,
983                                         v3s16(0,0,0), data);
984
985                         u16 l = getInteriorLight(n, 1, nodedef);
986                         video::SColor c = MapBlock_LightColor(255, l, f.light_source);
987
988                         v3f pos = intToFloat(p, BS);
989                         aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
990                         box.MinEdge += pos;
991                         box.MaxEdge += pos;
992                         makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
993                 break;}
994                 case NDT_ALLFACES_OPTIONAL:
995                         // This is always pre-converted to something else
996                         FATAL_ERROR("NDT_ALLFACES_OPTIONAL not pre-converted");
997                         break;
998                 case NDT_TORCHLIKE:
999                 {
1000                         v3s16 dir = n.getWallMountedDir(nodedef);
1001
1002                         u8 tileindex = 0;
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
1010                         } else {
1011                                 tileindex = 2; // side
1012                         }
1013
1014                         TileSpec tile = getNodeTileN(n, p, tileindex, data);
1015                         tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1016                         tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1017
1018                         u16 l = getInteriorLight(n, 1, nodedef);
1019                         video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1020
1021                         float s = BS/2*f.visual_scale;
1022                         // Wall at X+ of node
1023                         video::S3DVertex vertices[4] =
1024                         {
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),
1029                         };
1030
1031                         for(s32 i=0; i<4; i++)
1032                         {
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);
1045
1046                                 vertices[i].Pos += intToFloat(p, BS);
1047                         }
1048
1049                         u16 indices[] = {0,1,2,2,3,0};
1050                         // Add to mesh collector
1051                         collector.append(tile, vertices, 4, indices, 6);
1052                 break;}
1053                 case NDT_SIGNLIKE:
1054                 {
1055                         TileSpec tile = getNodeTileN(n, p, 0, data);
1056                         tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1057                         tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1058
1059                         u16 l = getInteriorLight(n, 0, nodedef);
1060                         video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1061
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] =
1066                         {
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),
1071                         };
1072
1073                         v3s16 dir = n.getWallMountedDir(nodedef);
1074
1075                         for(s32 i=0; i<4; i++)
1076                         {
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);
1089
1090                                 vertices[i].Pos += intToFloat(p, BS);
1091                         }
1092
1093                         u16 indices[] = {0,1,2,2,3,0};
1094                         // Add to mesh collector
1095                         collector.append(tile, vertices, 4, indices, 6);
1096                 break;}
1097                 case NDT_PLANTLIKE:
1098                 {
1099                         TileSpec tile = getNodeTileN(n, p, 0, data);
1100                         tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1101
1102                         u16 l = getInteriorLight(n, 1, nodedef);
1103                         video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1104
1105                         float s = BS / 2 * f.visual_scale;
1106
1107                         for (int j = 0; j < 2; j++)
1108                         {
1109                                 video::S3DVertex vertices[4] =
1110                                 {
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),
1115                                 };
1116                                 float rotate_degree = 0;
1117                                 if (f.param_type_2 == CPT2_DEGROTATE)
1118                                         rotate_degree = n.param2 * 2;
1119
1120                                 if (j == 0) {
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);
1126                                 }
1127
1128                                 for (int i = 0; i < 4; i++)
1129                                 {
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);
1133                                 }
1134
1135                                 u16 indices[] = {0, 1, 2, 2, 3, 0};
1136                                 // Add to mesh collector
1137                                 collector.append(tile, vertices, 4, indices, 6);
1138                         }
1139                 break;}
1140                 case NDT_FIRELIKE:
1141                 {
1142                         TileSpec tile = getNodeTileN(n, p, 0, data);
1143                         tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1144
1145                         u16 l = getInteriorLight(n, 1, nodedef);
1146                         video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1147
1148                         float s = BS / 2 * f.visual_scale;
1149
1150                         content_t current = n.getContent();
1151                         content_t n2c;
1152                         MapNode n2;
1153                         v3s16 n2p;
1154
1155                         static const v3s16 dirs[6] = {
1156                                 v3s16( 0,  1,  0),
1157                                 v3s16( 0, -1,  0),
1158                                 v3s16( 1,  0,  0),
1159                                 v3s16(-1,  0,  0),
1160                                 v3s16( 0,  0,  1),
1161                                 v3s16( 0,  0, -1)
1162                         };
1163
1164                         int doDraw[6] = {0, 0, 0, 0, 0, 0};
1165
1166                         bool drawAllFaces = true;
1167
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) {
1174                                         doDraw[i] = 1;
1175                                         if (drawAllFaces)
1176                                                 drawAllFaces = false;
1177
1178                                 }
1179                         }
1180
1181                         for (int j = 0; j < 6; j++) {
1182
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),
1188                                 };
1189
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;
1197                                         }
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;
1204                                         }
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;
1211                                         }
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;
1217                                         }
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);
1222                                         }
1223                                 } else if (j == 5 && (drawAllFaces || doDraw[1] == 1)) {
1224                                         for (int i = 0; i < 4; i++) {
1225                                                 vertices[i].Pos.rotateXZBy(-45);
1226                                         }
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;
1234                                         }
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;
1241                                         }
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;
1248                                         }
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;
1254                                         }
1255                                 } else {
1256                                         // Skip faces that aren't adjacent to a node
1257                                         continue;
1258                                 }
1259
1260                                 for (int i = 0; i < 4; i++) {
1261                                         vertices[i].Pos *= f.visual_scale;
1262                                         vertices[i].Pos += intToFloat(p, BS);
1263                                 }
1264
1265                                 u16 indices[] = {0, 1, 2, 2, 3, 0};
1266                                 // Add to mesh collector
1267                                 collector.append(tile, vertices, 4, indices, 6);
1268                         }
1269                 break;}
1270                 case NDT_FENCELIKE:
1271                 {
1272                         TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
1273                         TileSpec tile_nocrack = tile;
1274                         tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
1275
1276                         // Put wood the right way around in the posts
1277                         TileSpec tile_rot = tile;
1278                         tile_rot.rotation = 1;
1279
1280                         u16 l = getInteriorLight(n, 1, nodedef);
1281                         video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1282
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;
1286
1287                         v3f pos = intToFloat(p, BS);
1288
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;
1293                         f32 postuv[24]={
1294                                         6/16.,6/16.,10/16.,10/16.,
1295                                         6/16.,6/16.,10/16.,10/16.,
1296                                         0/16.,0,4/16.,1,
1297                                         4/16.,0,8/16.,1,
1298                                         8/16.,0,12/16.,1,
1299                                         12/16.,0,16/16.,1};
1300                         makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
1301
1302                         // Now a section of fence, +X, if there's a post there
1303                         v3s16 p2 = p;
1304                         p2.X++;
1305                         MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1306                         const ContentFeatures *f2 = &nodedef->get(n2);
1307                         if(f2->drawtype == NDT_FENCELIKE)
1308                         {
1309                                 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
1310                                                 bar_len+BS/2,bar_rad+BS/4,bar_rad);
1311                                 bar.MinEdge += pos;
1312                                 bar.MaxEdge += pos;
1313                                 f32 xrailuv[24]={
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,
1321                                                 c, xrailuv);
1322                                 bar.MinEdge.Y -= BS/2;
1323                                 bar.MaxEdge.Y -= BS/2;
1324                                 makeCuboid(&collector, bar, &tile_nocrack, 1,
1325                                                 c, xrailuv);
1326                         }
1327
1328                         // Now a section of fence, +Z, if there's a post there
1329                         p2 = p;
1330                         p2.Z++;
1331                         n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
1332                         f2 = &nodedef->get(n2);
1333                         if(f2->drawtype == NDT_FENCELIKE)
1334                         {
1335                                 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
1336                                                 bar_rad,bar_rad+BS/4,bar_len+BS/2);
1337                                 bar.MinEdge += pos;
1338                                 bar.MaxEdge += pos;
1339                                 f32 zrailuv[24]={
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,
1347                                                 c, zrailuv);
1348                                 bar.MinEdge.Y -= BS/2;
1349                                 bar.MaxEdge.Y -= BS/2;
1350                                 makeCuboid(&collector, bar, &tile_nocrack, 1,
1351                                                 c, zrailuv);
1352                         }
1353                 break;}
1354                 case NDT_RAILLIKE:
1355                 {
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) */
1357                         bool is_rail_z[6];
1358
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];
1362
1363                         u8 index = 0;
1364                         for (s8 y0 = -1; y0 <= 1; y0++) {
1365                                 // Prevent from indexing never used coordinates
1366                                 for (s8 xz = -1; xz <= 1; xz++) {
1367                                         if (xz == 0)
1368                                                 continue;
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);
1373
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);
1378
1379                                         is_rail_z[index] = ((def_zy.drawtype == NDT_RAILLIKE
1380                                                         && ((ItemGroupList) def_zy.groups)[groupname] == self_group)
1381                                                         || n_zy.getContent() == thiscontent);
1382                                         index++;
1383                                 }
1384                         }
1385
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];
1392
1393                         // reasonable default, flat straight unrotated rail
1394                         bool is_straight = true;
1395                         int adjacencies = 0;
1396                         int angle = 0;
1397                         u8 tileindex = 0;
1398
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
1403                         } else {
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];
1407                         }
1408
1409                         switch (adjacencies) {
1410                         case 1:
1411                                 if (is_rail_x_all[0] || is_rail_x_all[1])
1412                                         angle = 90;
1413                                 break;
1414                         case 2:
1415                                 if (!is_straight)
1416                                         tileindex = 1; // curved
1417                                 if (is_rail_x_all[0] && is_rail_x_all[1])
1418                                         angle = 90;
1419                                 if (is_rail_z_all[0] && is_rail_z_all[1]) {
1420                                         if (is_rail_z[4])
1421                                                 angle = 180;
1422                                 }
1423                                 else if (is_rail_x_all[0] && is_rail_z_all[0])
1424                                         angle = 270;
1425                                 else if (is_rail_x_all[0] && is_rail_z_all[1])
1426                                         angle = 180;
1427                                 else if (is_rail_x_all[1] && is_rail_z_all[1])
1428                                         angle = 90;
1429                                 break;
1430                         case 3:
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])
1434                                         angle = 180;
1435                                 if(!is_rail_z_all[0])
1436                                         angle = 90;
1437                                 if(!is_rail_z_all[1])
1438                                         angle = 270;
1439                                 break;
1440                         case 4:
1441                                 tileindex = 3; // crossing
1442                                 break;
1443                         case 5: //sloped
1444                                 if (is_rail_z[4])
1445                                         angle = 180;
1446                                 if (is_rail_x[4])
1447                                         angle = 90;
1448                                 if (is_rail_x[5])
1449                                         angle = -90;
1450                                 break;
1451                         default:
1452                                 break;
1453                         }
1454
1455                         TileSpec tile = getNodeTileN(n, p, tileindex, data);
1456                         tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
1457                         tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
1458
1459                         u16 l = getInteriorLight(n, 0, nodedef);
1460                         video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1461
1462                         float d = (float)BS/64;
1463                         float s = BS/2;
1464
1465                         short g = -1;
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
1468
1469                         video::S3DVertex vertices[4] =
1470                         {
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),
1475                         };
1476
1477                         for(s32 i=0; i<4; i++)
1478                         {
1479                                 if(angle != 0)
1480                                         vertices[i].Pos.rotateXZBy(angle);
1481                                 vertices[i].Pos += intToFloat(p, BS);
1482                         }
1483
1484                         u16 indices[] = {0,1,2,2,3,0};
1485                         collector.append(tile, vertices, 4, indices, 6);
1486                 break;}
1487                 case NDT_NODEBOX:
1488                 {
1489                         static const v3s16 tile_dirs[6] = {
1490                                 v3s16(0, 1, 0),
1491                                 v3s16(0, -1, 0),
1492                                 v3s16(1, 0, 0),
1493                                 v3s16(-1, 0, 0),
1494                                 v3s16(0, 0, 1),
1495                                 v3s16(0, 0, -1)
1496                         };
1497                         TileSpec tiles[6];
1498
1499                         u16 l = getInteriorLight(n, 1, nodedef);
1500                         video::SColor c = MapBlock_LightColor(255, l, f.light_source);
1501
1502                         v3f pos = intToFloat(p, BS);
1503
1504                         std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1505                         for(std::vector<aabb3f>::iterator
1506                                         i = boxes.begin();
1507                                         i != boxes.end(); ++i)
1508                         {
1509                         for(int j = 0; j < 6; j++)
1510                                 {
1511                                 // Handles facedir rotation for textures
1512                                 tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
1513                                 }
1514                                 aabb3f box = *i;
1515                                 box.MinEdge += pos;
1516                                 box.MaxEdge += pos;
1517
1518                                 f32 temp;
1519                                 if (box.MinEdge.X > box.MaxEdge.X)
1520                                 {
1521                                         temp=box.MinEdge.X;
1522                                         box.MinEdge.X=box.MaxEdge.X;
1523                                         box.MaxEdge.X=temp;
1524                                 }
1525                                 if (box.MinEdge.Y > box.MaxEdge.Y)
1526                                 {
1527                                         temp=box.MinEdge.Y;
1528                                         box.MinEdge.Y=box.MaxEdge.Y;
1529                                         box.MaxEdge.Y=temp;
1530                                 }
1531                                 if (box.MinEdge.Z > box.MaxEdge.Z)
1532                                 {
1533                                         temp=box.MinEdge.Z;
1534                                         box.MinEdge.Z=box.MaxEdge.Z;
1535                                         box.MaxEdge.Z=temp;
1536                                 }
1537
1538                                 //
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;
1546                                 f32 txc[24] = {
1547                                         // up
1548                                         tx1, 1-tz2, tx2, 1-tz1,
1549                                         // down
1550                                         tx1, tz1, tx2, tz2,
1551                                         // right
1552                                         tz1, 1-ty2, tz2, 1-ty1,
1553                                         // left
1554                                         1-tz2, 1-ty2, 1-tz1, 1-ty1,
1555                                         // back
1556                                         1-tx2, 1-ty2, 1-tx1, 1-ty1,
1557                                         // front
1558                                         tx1, 1-ty2, tx2, 1-ty1,
1559                                 };
1560                                 makeCuboid(&collector, box, tiles, 6, c, txc);
1561                         }
1562                 break;}
1563                 case NDT_MESH:
1564                 {
1565                         v3f pos = intToFloat(p, BS);
1566                         video::SColor c = MapBlock_LightColor(255, getInteriorLight(n, 1, nodedef), f.light_source);
1567
1568                         u8 facedir = 0;
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];
1578                                 }
1579                         }
1580
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);
1588                                 }
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);
1600                                 }
1601                                 mesh->drop();
1602                         }
1603                 break;}
1604                 }
1605         }
1606 }
1607