3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "content_mapblock.h"
22 #include "main.h" // For g_settings
24 #include "mapblock_mesh.h" // For MapBlock_LightColor()
31 // material - the material to use (for all 6 faces)
32 // collector - the MeshCollector for the resulting polygons
33 // pa - texture atlas pointer for the material
34 // c - vertex colour - used for all
35 // pos - the position of the centre of the cuboid
36 // rz,ry,rz - the radius of the cuboid in each dimension
37 // txc - texture coordinates - this is a list of texture coordinates
38 // for the opposite corners of each face - therefore, there
39 // should be (2+2)*6=24 values in the list. Alternatively, pass
40 // NULL to use the entire texture for each face. The order of
41 // the faces in the list is top-backi-right-front-left-bottom
42 // If you specified 0,0,1,1 for each face, that would be the
43 // same as passing NULL.
44 void makeCuboid(video::SMaterial &material, MeshCollector *collector,
45 AtlasPointer* pa, video::SColor &c,
46 v3f &pos, f32 rx, f32 ry, f32 rz, f32* txc)
55 video::S3DVertex v[4] =
57 video::S3DVertex(0,0,0, 0,0,0, c, tu0, tv1),
58 video::S3DVertex(0,0,0, 0,0,0, c, tu1, tv1),
59 video::S3DVertex(0,0,0, 0,0,0, c, tu1, tv0),
60 video::S3DVertex(0,0,0, 0,0,0, c, tu0, tv0)
68 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
69 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
70 v[2].Pos.X= rx; v[2].Pos.Y= ry; v[2].Pos.Z= rz;
71 v[3].Pos.X= rx; v[3].Pos.Y= ry, v[3].Pos.Z=-rz;
74 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
75 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
76 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
77 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
80 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
81 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
82 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
83 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
86 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
87 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
88 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
89 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
92 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
93 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
94 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
95 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
98 v[0].Pos.X= rx; v[0].Pos.Y=-ry; v[0].Pos.Z= rz;
99 v[1].Pos.X=-rx; v[1].Pos.Y=-ry; v[1].Pos.Z= rz;
100 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
101 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
107 v[0].TCoords.X=tu0+txus*txc[0]; v[0].TCoords.Y=tv0+txvs*txc[3];
108 v[1].TCoords.X=tu0+txus*txc[2]; v[1].TCoords.Y=tv0+txvs*txc[3];
109 v[2].TCoords.X=tu0+txus*txc[2]; v[2].TCoords.Y=tv0+txvs*txc[1];
110 v[3].TCoords.X=tu0+txus*txc[0]; v[3].TCoords.Y=tv0+txvs*txc[1];
114 for(u16 i=0; i<4; i++)
116 u16 indices[] = {0,1,2,2,3,0};
117 collector->append(material, v, 4, indices, 6);
125 void mapblock_mesh_generate_special(MeshMakeData *data,
126 MeshCollector &collector, IGameDef *gamedef)
128 INodeDefManager *nodedef = gamedef->ndef();
131 //TimeTaker timer("mapblock_mesh_generate_special()");
136 bool new_style_water = g_settings->getBool("new_style_water");
138 float node_liquid_level = 1.0;
140 node_liquid_level = 0.85;
142 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
144 /*// General ground material for special output
145 // Texture is modified just before usage
146 video::SMaterial material_general;
147 material_general.setFlag(video::EMF_LIGHTING, false);
148 material_general.setFlag(video::EMF_BILINEAR_FILTER, false);
149 material_general.setFlag(video::EMF_FOG_ENABLE, true);
150 material_general.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;*/
152 for(s16 z=0; z<MAP_BLOCKSIZE; z++)
153 for(s16 y=0; y<MAP_BLOCKSIZE; y++)
154 for(s16 x=0; x<MAP_BLOCKSIZE; x++)
158 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes+p);
159 const ContentFeatures &f = nodedef->get(n);
161 // Only solidness=0 stuff is drawn here
167 infostream<<"Got "<<f.drawtype<<std::endl;
175 Add water sources to mesh if using new style
177 assert(nodedef->get(n).special_materials[0]);
178 //assert(nodedef->get(n).special_materials[1]);
179 assert(nodedef->get(n).special_aps[0]);
181 video::SMaterial &liquid_material =
182 *nodedef->get(n).special_materials[0];
183 /*video::SMaterial &liquid_material_bfculled =
184 *nodedef->get(n).special_materials[1];*/
185 AtlasPointer &pa_liquid1 =
186 *nodedef->get(n).special_aps[0];
188 bool top_is_air = false;
189 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
190 if(n.getContent() == CONTENT_AIR)
193 if(top_is_air == false)
196 u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio, nodedef));
197 video::SColor c = MapBlock_LightColor(
198 nodedef->get(n).alpha, l);
200 video::S3DVertex vertices[4] =
202 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
203 pa_liquid1.x0(), pa_liquid1.y1()),
204 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
205 pa_liquid1.x1(), pa_liquid1.y1()),
206 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
207 pa_liquid1.x1(), pa_liquid1.y0()),
208 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
209 pa_liquid1.x0(), pa_liquid1.y0()),
212 for(s32 i=0; i<4; i++)
214 vertices[i].Pos.Y += (-0.5+node_liquid_level)*BS;
215 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
218 u16 indices[] = {0,1,2,2,3,0};
219 // Add to mesh collector
220 collector.append(liquid_material, vertices, 4, indices, 6);
222 case NDT_FLOWINGLIQUID:
225 Add flowing liquid to mesh
227 assert(nodedef->get(n).special_materials[0]);
228 assert(nodedef->get(n).special_materials[1]);
229 assert(nodedef->get(n).special_aps[0]);
231 video::SMaterial &liquid_material =
232 *nodedef->get(n).special_materials[0];
233 video::SMaterial &liquid_material_bfculled =
234 *nodedef->get(n).special_materials[1];
235 AtlasPointer &pa_liquid1 =
236 *nodedef->get(n).special_aps[0];
238 bool top_is_same_liquid = false;
239 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
240 content_t c_flowing = nodedef->get(n).liquid_alternative_flowing;
241 content_t c_source = nodedef->get(n).liquid_alternative_source;
242 if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
243 top_is_same_liquid = true;
246 // Use the light of the node on top if possible
247 if(nodedef->get(ntop).param_type == CPT_LIGHT)
248 l = decode_light(ntop.getLightBlend(data->m_daynight_ratio, nodedef));
249 // Otherwise use the light of this node (the liquid)
251 l = decode_light(n.getLightBlend(data->m_daynight_ratio, nodedef));
252 video::SColor c = MapBlock_LightColor(
253 nodedef->get(n).alpha, l);
255 // Neighbor liquid levels (key = relative position)
256 // Includes current node
257 core::map<v3s16, f32> neighbor_levels;
258 core::map<v3s16, content_t> neighbor_contents;
259 core::map<v3s16, u8> neighbor_flags;
260 const u8 neighborflag_top_is_same_liquid = 0x01;
261 v3s16 neighbor_dirs[9] = {
272 for(u32 i=0; i<9; i++)
274 content_t content = CONTENT_AIR;
275 float level = -0.5 * BS;
278 v3s16 p2 = p + neighbor_dirs[i];
279 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
280 if(n2.getContent() != CONTENT_IGNORE)
282 content = n2.getContent();
284 if(n2.getContent() == c_source)
285 level = (-0.5+node_liquid_level) * BS;
286 else if(n2.getContent() == c_flowing)
287 level = (-0.5 + ((float)(n2.param2&LIQUID_LEVEL_MASK)
288 + 0.5) / 8.0 * node_liquid_level) * BS;
290 // Check node above neighbor.
291 // NOTE: This doesn't get executed if neighbor
294 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
295 if(n2.getContent() == c_source ||
296 n2.getContent() == c_flowing)
297 flags |= neighborflag_top_is_same_liquid;
300 neighbor_levels.insert(neighbor_dirs[i], level);
301 neighbor_contents.insert(neighbor_dirs[i], content);
302 neighbor_flags.insert(neighbor_dirs[i], flags);
305 // Corner heights (average between four liquids)
306 f32 corner_levels[4];
308 v3s16 halfdirs[4] = {
314 for(u32 i=0; i<4; i++)
316 v3s16 cornerdir = halfdirs[i];
317 float cornerlevel = 0;
320 for(u32 j=0; j<4; j++)
322 v3s16 neighbordir = cornerdir - halfdirs[j];
323 content_t content = neighbor_contents[neighbordir];
324 // If top is liquid, draw starting from top of node
325 if(neighbor_flags[neighbordir] &
326 neighborflag_top_is_same_liquid)
328 cornerlevel = 0.5*BS;
332 // Source is always the same height
333 else if(content == c_source)
335 cornerlevel = (-0.5+node_liquid_level)*BS;
339 // Flowing liquid has level information
340 else if(content == c_flowing)
342 cornerlevel += neighbor_levels[neighbordir];
345 else if(content == CONTENT_AIR)
351 cornerlevel = -0.5*BS;
352 else if(valid_count > 0)
353 cornerlevel /= valid_count;
354 corner_levels[i] = cornerlevel;
361 v3s16 side_dirs[4] = {
367 s16 side_corners[4][2] = {
373 for(u32 i=0; i<4; i++)
375 v3s16 dir = side_dirs[i];
378 If our topside is liquid and neighbor's topside
379 is liquid, don't draw side face
381 if(top_is_same_liquid &&
382 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
385 content_t neighbor_content = neighbor_contents[dir];
386 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
388 // Don't draw face if neighbor is blocking the view
389 if(n_feat.solidness == 2)
392 bool neighbor_is_same_liquid = (neighbor_content == c_source
393 || neighbor_content == c_flowing);
395 // Don't draw any faces if neighbor same is liquid and top is
397 if(neighbor_is_same_liquid == true
398 && top_is_same_liquid == false)
401 // Use backface culled material if neighbor doesn't have a
403 video::SMaterial *current_material = &liquid_material;
404 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
405 current_material = &liquid_material_bfculled;
407 video::S3DVertex vertices[4] =
409 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
410 pa_liquid1.x0(), pa_liquid1.y1()),
411 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
412 pa_liquid1.x1(), pa_liquid1.y1()),
413 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
414 pa_liquid1.x1(), pa_liquid1.y0()),
415 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
416 pa_liquid1.x0(), pa_liquid1.y0()),
420 If our topside is liquid, set upper border of face
421 at upper border of node
423 if(top_is_same_liquid)
425 vertices[2].Pos.Y = 0.5*BS;
426 vertices[3].Pos.Y = 0.5*BS;
429 Otherwise upper position of face is corner levels
433 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
434 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
438 If neighbor is liquid, lower border of face is corner
441 if(neighbor_is_same_liquid)
443 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
444 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
447 If neighbor is not liquid, lower border of face is
452 vertices[0].Pos.Y = -0.5*BS;
453 vertices[1].Pos.Y = -0.5*BS;
456 for(s32 j=0; j<4; j++)
458 if(dir == v3s16(0,0,1))
459 vertices[j].Pos.rotateXZBy(0);
460 if(dir == v3s16(0,0,-1))
461 vertices[j].Pos.rotateXZBy(180);
462 if(dir == v3s16(-1,0,0))
463 vertices[j].Pos.rotateXZBy(90);
464 if(dir == v3s16(1,0,-0))
465 vertices[j].Pos.rotateXZBy(-90);
467 // Do this to not cause glitches when two liquids are
469 /*if(neighbor_is_same_liquid == false){
470 vertices[j].Pos.X *= 0.98;
471 vertices[j].Pos.Z *= 0.98;
474 vertices[j].Pos += intToFloat(p + blockpos_nodes, BS);
477 u16 indices[] = {0,1,2,2,3,0};
478 // Add to mesh collector
479 collector.append(*current_material, vertices, 4, indices, 6);
483 Generate top side, if appropriate
486 if(top_is_same_liquid == false)
488 video::S3DVertex vertices[4] =
490 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
491 pa_liquid1.x0(), pa_liquid1.y1()),
492 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
493 pa_liquid1.x1(), pa_liquid1.y1()),
494 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
495 pa_liquid1.x1(), pa_liquid1.y0()),
496 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
497 pa_liquid1.x0(), pa_liquid1.y0()),
500 // This fixes a strange bug
501 s32 corner_resolve[4] = {3,2,1,0};
503 for(s32 i=0; i<4; i++)
505 //vertices[i].Pos.Y += liquid_level;
506 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
507 s32 j = corner_resolve[i];
508 vertices[i].Pos.Y += corner_levels[j];
509 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
512 u16 indices[] = {0,1,2,2,3,0};
513 // Add to mesh collector
514 collector.append(liquid_material, vertices, 4, indices, 6);
519 video::SMaterial material_glass;
520 material_glass.setFlag(video::EMF_LIGHTING, false);
521 material_glass.setFlag(video::EMF_BILINEAR_FILTER, false);
522 material_glass.setFlag(video::EMF_FOG_ENABLE, true);
523 material_glass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
524 AtlasPointer pa_glass = f.tiles[0].texture;
525 material_glass.setTexture(0, pa_glass.atlas);
527 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio, nodedef)));
528 video::SColor c = MapBlock_LightColor(255, l);
530 for(u32 j=0; j<6; j++)
532 video::S3DVertex vertices[4] =
534 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
535 pa_glass.x0(), pa_glass.y1()),
536 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
537 pa_glass.x1(), pa_glass.y1()),
538 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
539 pa_glass.x1(), pa_glass.y0()),
540 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
541 pa_glass.x0(), pa_glass.y0()),
546 for(u16 i=0; i<4; i++)
547 vertices[i].Pos.rotateXZBy(0);
551 for(u16 i=0; i<4; i++)
552 vertices[i].Pos.rotateXZBy(180);
556 for(u16 i=0; i<4; i++)
557 vertices[i].Pos.rotateXZBy(-90);
561 for(u16 i=0; i<4; i++)
562 vertices[i].Pos.rotateXZBy(90);
566 for(u16 i=0; i<4; i++)
567 vertices[i].Pos.rotateYZBy(-90);
571 for(u16 i=0; i<4; i++)
572 vertices[i].Pos.rotateYZBy(90);
575 for(u16 i=0; i<4; i++)
577 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
580 u16 indices[] = {0,1,2,2,3,0};
581 // Add to mesh collector
582 collector.append(material_glass, vertices, 4, indices, 6);
587 video::SMaterial material_leaves1;
588 material_leaves1.setFlag(video::EMF_LIGHTING, false);
589 material_leaves1.setFlag(video::EMF_BILINEAR_FILTER, false);
590 material_leaves1.setFlag(video::EMF_FOG_ENABLE, true);
591 material_leaves1.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
592 AtlasPointer pa_leaves1 = f.tiles[0].texture;
593 material_leaves1.setTexture(0, pa_leaves1.atlas);
595 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio, nodedef)));
596 video::SColor c = MapBlock_LightColor(255, l);
598 for(u32 j=0; j<6; j++)
600 video::S3DVertex vertices[4] =
602 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
603 pa_leaves1.x0(), pa_leaves1.y1()),
604 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
605 pa_leaves1.x1(), pa_leaves1.y1()),
606 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
607 pa_leaves1.x1(), pa_leaves1.y0()),
608 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
609 pa_leaves1.x0(), pa_leaves1.y0()),
614 for(u16 i=0; i<4; i++)
615 vertices[i].Pos.rotateXZBy(0);
619 for(u16 i=0; i<4; i++)
620 vertices[i].Pos.rotateXZBy(180);
624 for(u16 i=0; i<4; i++)
625 vertices[i].Pos.rotateXZBy(-90);
629 for(u16 i=0; i<4; i++)
630 vertices[i].Pos.rotateXZBy(90);
634 for(u16 i=0; i<4; i++)
635 vertices[i].Pos.rotateYZBy(-90);
639 for(u16 i=0; i<4; i++)
640 vertices[i].Pos.rotateYZBy(90);
643 for(u16 i=0; i<4; i++)
645 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
648 u16 indices[] = {0,1,2,2,3,0};
649 // Add to mesh collector
650 collector.append(material_leaves1, vertices, 4, indices, 6);
653 case NDT_ALLFACES_OPTIONAL:
654 // This is always pre-converted to something else
659 v3s16 dir = unpackDir(n.param2);
662 if(dir == v3s16(0,-1,0)){
663 ap = f.tiles[0].texture; // floor
664 } else if(dir == v3s16(0,1,0)){
665 ap = f.tiles[1].texture; // ceiling
666 // For backwards compatibility
667 } else if(dir == v3s16(0,0,0)){
668 ap = f.tiles[0].texture; // floor
670 ap = f.tiles[2].texture; // side
674 video::SMaterial material;
675 material.setFlag(video::EMF_LIGHTING, false);
676 material.setFlag(video::EMF_BACK_FACE_CULLING, false);
677 material.setFlag(video::EMF_BILINEAR_FILTER, false);
678 material.setFlag(video::EMF_FOG_ENABLE, true);
679 //material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
680 material.MaterialType
681 = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
682 material.setTexture(0, ap.atlas);
684 video::SColor c(255,255,255,255);
686 // Wall at X+ of node
687 video::S3DVertex vertices[4] =
689 video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c,
691 video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c,
693 video::S3DVertex(BS/2,BS/2,0, 0,0,0, c,
695 video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c,
699 for(s32 i=0; i<4; i++)
701 if(dir == v3s16(1,0,0))
702 vertices[i].Pos.rotateXZBy(0);
703 if(dir == v3s16(-1,0,0))
704 vertices[i].Pos.rotateXZBy(180);
705 if(dir == v3s16(0,0,1))
706 vertices[i].Pos.rotateXZBy(90);
707 if(dir == v3s16(0,0,-1))
708 vertices[i].Pos.rotateXZBy(-90);
709 if(dir == v3s16(0,-1,0))
710 vertices[i].Pos.rotateXZBy(45);
711 if(dir == v3s16(0,1,0))
712 vertices[i].Pos.rotateXZBy(-45);
714 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
717 u16 indices[] = {0,1,2,2,3,0};
718 // Add to mesh collector
719 collector.append(material, vertices, 4, indices, 6);
724 video::SMaterial material;
725 material.setFlag(video::EMF_LIGHTING, false);
726 material.setFlag(video::EMF_BACK_FACE_CULLING, false);
727 material.setFlag(video::EMF_BILINEAR_FILTER, false);
728 material.setFlag(video::EMF_FOG_ENABLE, true);
729 material.MaterialType
730 = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
731 AtlasPointer ap = f.tiles[0].texture;
732 material.setTexture(0, ap.atlas);
734 u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio, nodedef));
735 video::SColor c = MapBlock_LightColor(255, l);
737 float d = (float)BS/16;
738 // Wall at X+ of node
739 video::S3DVertex vertices[4] =
741 video::S3DVertex(BS/2-d,-BS/2,-BS/2, 0,0,0, c,
743 video::S3DVertex(BS/2-d,-BS/2,BS/2, 0,0,0, c,
745 video::S3DVertex(BS/2-d,BS/2,BS/2, 0,0,0, c,
747 video::S3DVertex(BS/2-d,BS/2,-BS/2, 0,0,0, c,
751 v3s16 dir = unpackDir(n.param2);
753 for(s32 i=0; i<4; i++)
755 if(dir == v3s16(1,0,0))
756 vertices[i].Pos.rotateXZBy(0);
757 if(dir == v3s16(-1,0,0))
758 vertices[i].Pos.rotateXZBy(180);
759 if(dir == v3s16(0,0,1))
760 vertices[i].Pos.rotateXZBy(90);
761 if(dir == v3s16(0,0,-1))
762 vertices[i].Pos.rotateXZBy(-90);
763 if(dir == v3s16(0,-1,0))
764 vertices[i].Pos.rotateXYBy(-90);
765 if(dir == v3s16(0,1,0))
766 vertices[i].Pos.rotateXYBy(90);
768 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
771 u16 indices[] = {0,1,2,2,3,0};
772 // Add to mesh collector
773 collector.append(material, vertices, 4, indices, 6);
777 video::SMaterial material_papyrus;
778 material_papyrus.setFlag(video::EMF_LIGHTING, false);
779 material_papyrus.setFlag(video::EMF_BILINEAR_FILTER, false);
780 material_papyrus.setFlag(video::EMF_FOG_ENABLE, true);
781 material_papyrus.MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
782 AtlasPointer pa_papyrus = f.tiles[0].texture;
783 material_papyrus.setTexture(0, pa_papyrus.atlas);
785 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio, nodedef)));
786 video::SColor c = MapBlock_LightColor(255, l);
788 for(u32 j=0; j<4; j++)
790 video::S3DVertex vertices[4] =
792 video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c,
793 pa_papyrus.x0(), pa_papyrus.y1()),
794 video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c,
795 pa_papyrus.x1(), pa_papyrus.y1()),
796 video::S3DVertex(BS/2,BS/2,0, 0,0,0, c,
797 pa_papyrus.x1(), pa_papyrus.y0()),
798 video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c,
799 pa_papyrus.x0(), pa_papyrus.y0()),
804 for(u16 i=0; i<4; i++)
805 vertices[i].Pos.rotateXZBy(45);
809 for(u16 i=0; i<4; i++)
810 vertices[i].Pos.rotateXZBy(-45);
814 for(u16 i=0; i<4; i++)
815 vertices[i].Pos.rotateXZBy(135);
819 for(u16 i=0; i<4; i++)
820 vertices[i].Pos.rotateXZBy(-135);
823 for(u16 i=0; i<4; i++)
825 vertices[i].Pos *= f.visual_scale;
826 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
829 u16 indices[] = {0,1,2,2,3,0};
830 // Add to mesh collector
831 collector.append(material_papyrus, vertices, 4, indices, 6);
836 video::SMaterial material_wood;
837 material_wood.setFlag(video::EMF_LIGHTING, false);
838 material_wood.setFlag(video::EMF_BILINEAR_FILTER, false);
839 material_wood.setFlag(video::EMF_FOG_ENABLE, true);
840 material_wood.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
841 AtlasPointer pa_wood = f.tiles[0].texture;
842 material_wood.setTexture(0, pa_wood.atlas);
844 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio, nodedef)));
845 video::SColor c = MapBlock_LightColor(255, l);
847 const f32 post_rad=(f32)BS/10;
848 const f32 bar_rad=(f32)BS/20;
849 const f32 bar_len=(f32)(BS/2)-post_rad;
851 // The post - always present
852 v3f pos = intToFloat(p+blockpos_nodes, BS);
860 makeCuboid(material_wood, &collector,
862 post_rad,BS/2,post_rad, postuv);
864 // Now a section of fence, +X, if there's a post there
867 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
868 const ContentFeatures *f2 = &nodedef->get(n2);
869 if(f2->drawtype == NDT_FENCELIKE)
871 pos = intToFloat(p+blockpos_nodes, BS);
881 makeCuboid(material_wood, &collector,
883 bar_len,bar_rad,bar_rad, xrailuv);
886 makeCuboid(material_wood, &collector,
888 bar_len,bar_rad,bar_rad, xrailuv);
891 // Now a section of fence, +Z, if there's a post there
894 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
895 f2 = &nodedef->get(n2);
896 if(f2->drawtype == NDT_FENCELIKE)
898 pos = intToFloat(p+blockpos_nodes, BS);
908 makeCuboid(material_wood, &collector,
910 bar_rad,bar_rad,bar_len, zrailuv);
912 makeCuboid(material_wood, &collector,
914 bar_rad,bar_rad,bar_len, zrailuv);
920 bool is_rail_x [] = { false, false }; /* x-1, x+1 */
921 bool is_rail_z [] = { false, false }; /* z-1, z+1 */
923 MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
924 MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
925 MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
926 MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
928 content_t thiscontent = n.getContent();
929 if(n_minus_x.getContent() == thiscontent)
931 if(n_plus_x.getContent() == thiscontent)
933 if(n_minus_z.getContent() == thiscontent)
935 if(n_plus_z.getContent() == thiscontent)
938 int adjacencies = is_rail_x[0] + is_rail_x[1] + is_rail_z[0] + is_rail_z[1];
941 AtlasPointer ap = f.tiles[0].texture; // straight
943 ap = f.tiles[0].texture; // straight
944 else if(adjacencies == 2)
946 if((is_rail_x[0] && is_rail_x[1]) || (is_rail_z[0] && is_rail_z[1]))
947 ap = f.tiles[0].texture; // straight
949 ap = f.tiles[1].texture; // curved
951 else if(adjacencies == 3)
952 ap = f.tiles[2].texture; // t-junction
953 else if(adjacencies == 4)
954 ap = f.tiles[3].texture; // crossing
956 video::SMaterial material_rail;
957 material_rail.setFlag(video::EMF_LIGHTING, false);
958 material_rail.setFlag(video::EMF_BACK_FACE_CULLING, false);
959 material_rail.setFlag(video::EMF_BILINEAR_FILTER, false);
960 material_rail.setFlag(video::EMF_FOG_ENABLE, true);
961 material_rail.MaterialType
962 = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
963 material_rail.setTexture(0, ap.atlas);
965 u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio, nodedef));
966 video::SColor c = MapBlock_LightColor(255, l);
968 float d = (float)BS/16;
969 video::S3DVertex vertices[4] =
971 video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c,
973 video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c,
975 video::S3DVertex(BS/2,-BS/2+d,BS/2, 0,0,0, c,
977 video::S3DVertex(-BS/2,-BS/2+d,BS/2, 0,0,0, c,
986 if(is_rail_x[0] || is_rail_x[1])
989 else if(adjacencies == 2)
991 if(is_rail_x[0] && is_rail_x[1])
993 else if(is_rail_x[0] && is_rail_z[0])
995 else if(is_rail_x[0] && is_rail_z[1])
997 else if(is_rail_x[1] && is_rail_z[1])
1000 else if(adjacencies == 3)
1013 for(u16 i=0; i<4; i++)
1014 vertices[i].Pos.rotateXZBy(angle);
1017 for(s32 i=0; i<4; i++)
1019 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
1022 u16 indices[] = {0,1,2,2,3,0};
1023 collector.append(material_rail, vertices, 4, indices, 6);