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"
21 #include "content_mapnode.h"
22 #include "main.h" // For g_settings and g_texturesource
27 // material - the material to use (for all 6 faces)
28 // collector - the MeshCollector for the resulting polygons
29 // pa - texture atlas pointer for the material
30 // c - vertex colour - used for all
31 // pos - the position of the centre of the cuboid
32 // rz,ry,rz - the radius of the cuboid in each dimension
33 // txc - texture coordinates - this is a list of texture coordinates
34 // for the opposite corners of each face - therefore, there
35 // should be (2+2)*6=24 values in the list. Alternatively, pass
36 // NULL to use the entire texture for each face. The order of
37 // the faces in the list is top-backi-right-front-left-bottom
38 // If you specified 0,0,1,1 for each face, that would be the
39 // same as passing NULL.
40 void makeCuboid(video::SMaterial &material, MeshCollector *collector,
41 AtlasPointer* pa, video::SColor &c,
42 v3f &pos, f32 rx, f32 ry, f32 rz, f32* txc)
51 video::S3DVertex v[4] =
53 video::S3DVertex(0,0,0, 0,0,0, c, tu0, tv1),
54 video::S3DVertex(0,0,0, 0,0,0, c, tu1, tv1),
55 video::S3DVertex(0,0,0, 0,0,0, c, tu1, tv0),
56 video::S3DVertex(0,0,0, 0,0,0, c, tu0, tv0)
64 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
65 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
66 v[2].Pos.X= rx; v[2].Pos.Y= ry; v[2].Pos.Z= rz;
67 v[3].Pos.X= rx; v[3].Pos.Y= ry, v[3].Pos.Z=-rz;
70 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
71 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
72 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
73 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
76 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
77 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
78 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
79 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
82 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
83 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
84 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
85 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
88 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
89 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
90 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
91 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
94 v[0].Pos.X= rx; v[0].Pos.Y=-ry; v[0].Pos.Z= rz;
95 v[1].Pos.X=-rx; v[1].Pos.Y=-ry; v[1].Pos.Z= rz;
96 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
97 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
103 v[0].TCoords.X=tu0+txus*txc[0]; v[0].TCoords.Y=tv0+txvs*txc[3];
104 v[1].TCoords.X=tu0+txus*txc[2]; v[1].TCoords.Y=tv0+txvs*txc[3];
105 v[2].TCoords.X=tu0+txus*txc[2]; v[2].TCoords.Y=tv0+txvs*txc[1];
106 v[3].TCoords.X=tu0+txus*txc[0]; v[3].TCoords.Y=tv0+txvs*txc[1];
110 for(u16 i=0; i<4; i++)
112 u16 indices[] = {0,1,2,2,3,0};
113 collector->append(material, v, 4, indices, 6);
121 void mapblock_mesh_generate_special(MeshMakeData *data,
122 MeshCollector &collector)
125 //TimeTaker timer("mapblock_mesh_generate_special()");
130 bool new_style_water = g_settings.getBool("new_style_water");
131 bool new_style_leaves = g_settings.getBool("new_style_leaves");
132 //bool smooth_lighting = g_settings.getBool("smooth_lighting");
133 bool invisible_stone = g_settings.getBool("invisible_stone");
135 float node_water_level = 1.0;
137 node_water_level = 0.85;
139 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
141 // Flowing water material
142 video::SMaterial material_water1;
143 material_water1.setFlag(video::EMF_LIGHTING, false);
144 material_water1.setFlag(video::EMF_BACK_FACE_CULLING, false);
145 material_water1.setFlag(video::EMF_BILINEAR_FILTER, false);
146 material_water1.setFlag(video::EMF_FOG_ENABLE, true);
147 material_water1.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
148 AtlasPointer pa_water1 = g_texturesource->getTexture(
149 g_texturesource->getTextureId("water.png"));
150 material_water1.setTexture(0, pa_water1.atlas);
152 // New-style leaves material
153 video::SMaterial material_leaves1;
154 material_leaves1.setFlag(video::EMF_LIGHTING, false);
155 //material_leaves1.setFlag(video::EMF_BACK_FACE_CULLING, false);
156 material_leaves1.setFlag(video::EMF_BILINEAR_FILTER, false);
157 material_leaves1.setFlag(video::EMF_FOG_ENABLE, true);
158 material_leaves1.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
159 AtlasPointer pa_leaves1 = g_texturesource->getTexture(
160 g_texturesource->getTextureId("leaves.png"));
161 material_leaves1.setTexture(0, pa_leaves1.atlas);
164 video::SMaterial material_glass;
165 material_glass.setFlag(video::EMF_LIGHTING, false);
166 material_glass.setFlag(video::EMF_BILINEAR_FILTER, false);
167 material_glass.setFlag(video::EMF_FOG_ENABLE, true);
168 material_glass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
169 AtlasPointer pa_glass = g_texturesource->getTexture(
170 g_texturesource->getTextureId("glass.png"));
171 material_glass.setTexture(0, pa_glass.atlas);
174 video::SMaterial material_wood;
175 material_wood.setFlag(video::EMF_LIGHTING, false);
176 material_wood.setFlag(video::EMF_BILINEAR_FILTER, false);
177 material_wood.setFlag(video::EMF_FOG_ENABLE, true);
178 material_wood.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
179 AtlasPointer pa_wood = g_texturesource->getTexture(
180 g_texturesource->getTextureId("wood.png"));
181 material_wood.setTexture(0, pa_wood.atlas);
183 // General ground material for special output
184 // Texture is modified just before usage
185 video::SMaterial material_general;
186 material_general.setFlag(video::EMF_LIGHTING, false);
187 material_general.setFlag(video::EMF_BILINEAR_FILTER, false);
188 material_general.setFlag(video::EMF_FOG_ENABLE, true);
189 material_general.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
193 video::SMaterial material_papyrus;
194 material_papyrus.setFlag(video::EMF_LIGHTING, false);
195 material_papyrus.setFlag(video::EMF_BILINEAR_FILTER, false);
196 material_papyrus.setFlag(video::EMF_FOG_ENABLE, true);
197 material_papyrus.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
198 AtlasPointer pa_papyrus = g_texturesource->getTexture(
199 g_texturesource->getTextureId("papyrus.png"));
200 material_papyrus.setTexture(0, pa_papyrus.atlas);
201 for(s16 z=0; z<MAP_BLOCKSIZE; z++)
202 for(s16 y=0; y<MAP_BLOCKSIZE; y++)
203 for(s16 x=0; x<MAP_BLOCKSIZE; x++)
207 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes+p);
212 if(n.getContent() == CONTENT_TORCH)
214 video::SColor c(255,255,255,255);
216 // Wall at X+ of node
217 video::S3DVertex vertices[4] =
219 video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c, 0,1),
220 video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c, 1,1),
221 video::S3DVertex(BS/2,BS/2,0, 0,0,0, c, 1,0),
222 video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c, 0,0),
225 v3s16 dir = unpackDir(n.param2);
227 for(s32 i=0; i<4; i++)
229 if(dir == v3s16(1,0,0))
230 vertices[i].Pos.rotateXZBy(0);
231 if(dir == v3s16(-1,0,0))
232 vertices[i].Pos.rotateXZBy(180);
233 if(dir == v3s16(0,0,1))
234 vertices[i].Pos.rotateXZBy(90);
235 if(dir == v3s16(0,0,-1))
236 vertices[i].Pos.rotateXZBy(-90);
237 if(dir == v3s16(0,-1,0))
238 vertices[i].Pos.rotateXZBy(45);
239 if(dir == v3s16(0,1,0))
240 vertices[i].Pos.rotateXZBy(-45);
242 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
246 video::SMaterial material;
247 material.setFlag(video::EMF_LIGHTING, false);
248 material.setFlag(video::EMF_BACK_FACE_CULLING, false);
249 material.setFlag(video::EMF_BILINEAR_FILTER, false);
250 //material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
251 material.MaterialType
252 = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
254 if(dir == v3s16(0,-1,0))
255 material.setTexture(0,
256 g_texturesource->getTextureRaw("torch_on_floor.png"));
257 else if(dir == v3s16(0,1,0))
258 material.setTexture(0,
259 g_texturesource->getTextureRaw("torch_on_ceiling.png"));
260 // For backwards compatibility
261 else if(dir == v3s16(0,0,0))
262 material.setTexture(0,
263 g_texturesource->getTextureRaw("torch_on_floor.png"));
265 material.setTexture(0,
266 g_texturesource->getTextureRaw("torch.png"));
268 u16 indices[] = {0,1,2,2,3,0};
269 // Add to mesh collector
270 collector.append(material, vertices, 4, indices, 6);
275 else if(n.getContent() == CONTENT_SIGN_WALL)
277 u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
278 video::SColor c(255,l,l,l);
280 float d = (float)BS/16;
281 // Wall at X+ of node
282 video::S3DVertex vertices[4] =
284 video::S3DVertex(BS/2-d,-BS/2,-BS/2, 0,0,0, c, 0,1),
285 video::S3DVertex(BS/2-d,-BS/2,BS/2, 0,0,0, c, 1,1),
286 video::S3DVertex(BS/2-d,BS/2,BS/2, 0,0,0, c, 1,0),
287 video::S3DVertex(BS/2-d,BS/2,-BS/2, 0,0,0, c, 0,0),
290 v3s16 dir = unpackDir(n.param2);
292 for(s32 i=0; i<4; i++)
294 if(dir == v3s16(1,0,0))
295 vertices[i].Pos.rotateXZBy(0);
296 if(dir == v3s16(-1,0,0))
297 vertices[i].Pos.rotateXZBy(180);
298 if(dir == v3s16(0,0,1))
299 vertices[i].Pos.rotateXZBy(90);
300 if(dir == v3s16(0,0,-1))
301 vertices[i].Pos.rotateXZBy(-90);
302 if(dir == v3s16(0,-1,0))
303 vertices[i].Pos.rotateXYBy(-90);
304 if(dir == v3s16(0,1,0))
305 vertices[i].Pos.rotateXYBy(90);
307 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
311 video::SMaterial material;
312 material.setFlag(video::EMF_LIGHTING, false);
313 material.setFlag(video::EMF_BACK_FACE_CULLING, false);
314 material.setFlag(video::EMF_BILINEAR_FILTER, false);
315 material.setFlag(video::EMF_FOG_ENABLE, true);
316 //material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
317 material.MaterialType
318 = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
320 material.setTexture(0,
321 g_texturesource->getTextureRaw("sign_wall.png"));
323 u16 indices[] = {0,1,2,2,3,0};
324 // Add to mesh collector
325 collector.append(material, vertices, 4, indices, 6);
328 Add flowing water to mesh
330 else if(n.getContent() == CONTENT_WATER)
332 bool top_is_water = false;
333 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
334 if(ntop.getContent() == CONTENT_WATER || ntop.getContent() == CONTENT_WATERSOURCE)
338 // Use the light of the node on top if possible
339 if(content_features(ntop).param_type == CPT_LIGHT)
340 l = decode_light(ntop.getLightBlend(data->m_daynight_ratio));
341 // Otherwise use the light of this node (the water)
343 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
344 video::SColor c(WATER_ALPHA,l,l,l);
346 // Neighbor water levels (key = relative position)
347 // Includes current node
348 core::map<v3s16, f32> neighbor_levels;
349 core::map<v3s16, content_t> neighbor_contents;
350 core::map<v3s16, u8> neighbor_flags;
351 const u8 neighborflag_top_is_water = 0x01;
352 v3s16 neighbor_dirs[9] = {
363 for(u32 i=0; i<9; i++)
365 u8 content = CONTENT_AIR;
366 float level = -0.5 * BS;
369 v3s16 p2 = p + neighbor_dirs[i];
370 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
371 if(n2.getContent() != CONTENT_IGNORE)
373 content = n2.getContent();
375 if(n2.getContent() == CONTENT_WATERSOURCE)
376 level = (-0.5+node_water_level) * BS;
377 else if(n2.getContent() == CONTENT_WATER)
378 level = (-0.5 + ((float)n2.param2 + 0.5) / 8.0
379 * node_water_level) * BS;
381 // Check node above neighbor.
382 // NOTE: This doesn't get executed if neighbor
385 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
386 if(n2.getContent() == CONTENT_WATERSOURCE || n2.getContent() == CONTENT_WATER)
387 flags |= neighborflag_top_is_water;
390 neighbor_levels.insert(neighbor_dirs[i], level);
391 neighbor_contents.insert(neighbor_dirs[i], content);
392 neighbor_flags.insert(neighbor_dirs[i], flags);
395 //float water_level = (-0.5 + ((float)n.param2 + 0.5) / 8.0) * BS;
396 //float water_level = neighbor_levels[v3s16(0,0,0)];
398 // Corner heights (average between four waters)
399 f32 corner_levels[4];
401 v3s16 halfdirs[4] = {
407 for(u32 i=0; i<4; i++)
409 v3s16 cornerdir = halfdirs[i];
410 float cornerlevel = 0;
412 for(u32 j=0; j<4; j++)
414 v3s16 neighbordir = cornerdir - halfdirs[j];
415 u8 content = neighbor_contents[neighbordir];
416 // Special case for source nodes
417 if(content == CONTENT_WATERSOURCE)
419 cornerlevel = (-0.5+node_water_level)*BS;
423 else if(content == CONTENT_WATER)
425 cornerlevel += neighbor_levels[neighbordir];
428 else if(content == CONTENT_AIR)
430 cornerlevel += -0.5*BS;
435 cornerlevel /= valid_count;
436 corner_levels[i] = cornerlevel;
443 v3s16 side_dirs[4] = {
449 s16 side_corners[4][2] = {
455 for(u32 i=0; i<4; i++)
457 v3s16 dir = side_dirs[i];
460 If our topside is water and neighbor's topside
461 is water, don't draw side face
464 neighbor_flags[dir] & neighborflag_top_is_water)
467 u8 neighbor_content = neighbor_contents[dir];
469 // Don't draw face if neighbor is not air or water
470 if(neighbor_content != CONTENT_AIR
471 && neighbor_content != CONTENT_WATER)
474 bool neighbor_is_water = (neighbor_content == CONTENT_WATER);
476 // Don't draw any faces if neighbor is water and top is water
477 if(neighbor_is_water == true && top_is_water == false)
480 video::S3DVertex vertices[4] =
482 /*video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
483 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
484 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
485 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
486 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
487 pa_water1.x0(), pa_water1.y1()),
488 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
489 pa_water1.x1(), pa_water1.y1()),
490 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
491 pa_water1.x1(), pa_water1.y0()),
492 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
493 pa_water1.x0(), pa_water1.y0()),
497 If our topside is water, set upper border of face
498 at upper border of node
502 vertices[2].Pos.Y = 0.5*BS;
503 vertices[3].Pos.Y = 0.5*BS;
506 Otherwise upper position of face is corner levels
510 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
511 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
515 If neighbor is water, lower border of face is corner
518 if(neighbor_is_water)
520 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
521 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
524 If neighbor is not water, lower border of face is
529 vertices[0].Pos.Y = -0.5*BS;
530 vertices[1].Pos.Y = -0.5*BS;
533 for(s32 j=0; j<4; j++)
535 if(dir == v3s16(0,0,1))
536 vertices[j].Pos.rotateXZBy(0);
537 if(dir == v3s16(0,0,-1))
538 vertices[j].Pos.rotateXZBy(180);
539 if(dir == v3s16(-1,0,0))
540 vertices[j].Pos.rotateXZBy(90);
541 if(dir == v3s16(1,0,-0))
542 vertices[j].Pos.rotateXZBy(-90);
544 vertices[j].Pos += intToFloat(p + blockpos_nodes, BS);
547 u16 indices[] = {0,1,2,2,3,0};
548 // Add to mesh collector
549 collector.append(material_water1, vertices, 4, indices, 6);
553 Generate top side, if appropriate
556 if(top_is_water == false)
558 video::S3DVertex vertices[4] =
560 /*video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,1),
561 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,1),
562 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
563 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
564 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
565 pa_water1.x0(), pa_water1.y1()),
566 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
567 pa_water1.x1(), pa_water1.y1()),
568 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
569 pa_water1.x1(), pa_water1.y0()),
570 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
571 pa_water1.x0(), pa_water1.y0()),
574 // This fixes a strange bug
575 s32 corner_resolve[4] = {3,2,1,0};
577 for(s32 i=0; i<4; i++)
579 //vertices[i].Pos.Y += water_level;
580 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
581 s32 j = corner_resolve[i];
582 vertices[i].Pos.Y += corner_levels[j];
583 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
586 u16 indices[] = {0,1,2,2,3,0};
587 // Add to mesh collector
588 collector.append(material_water1, vertices, 4, indices, 6);
592 Add water sources to mesh if using new style
594 else if(n.getContent() == CONTENT_WATERSOURCE && new_style_water)
596 //bool top_is_water = false;
597 bool top_is_air = false;
598 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
599 /*if(n.getContent() == CONTENT_WATER || n.getContent() == CONTENT_WATERSOURCE)
600 top_is_water = true;*/
601 if(n.getContent() == CONTENT_AIR)
604 /*if(top_is_water == true)
606 if(top_is_air == false)
609 u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
610 video::SColor c(WATER_ALPHA,l,l,l);
612 video::S3DVertex vertices[4] =
614 /*video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,1),
615 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,1),
616 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
617 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
618 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
619 pa_water1.x0(), pa_water1.y1()),
620 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
621 pa_water1.x1(), pa_water1.y1()),
622 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
623 pa_water1.x1(), pa_water1.y0()),
624 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
625 pa_water1.x0(), pa_water1.y0()),
628 for(s32 i=0; i<4; i++)
630 vertices[i].Pos.Y += (-0.5+node_water_level)*BS;
631 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
634 u16 indices[] = {0,1,2,2,3,0};
635 // Add to mesh collector
636 collector.append(material_water1, vertices, 4, indices, 6);
639 Add leaves if using new style
641 else if(n.getContent() == CONTENT_LEAVES && new_style_leaves)
643 /*u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));*/
644 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
645 video::SColor c(255,l,l,l);
647 for(u32 j=0; j<6; j++)
649 video::S3DVertex vertices[4] =
651 /*video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c, 0,1),
652 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c, 1,1),
653 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c, 1,0),
654 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c, 0,0),*/
655 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
656 pa_leaves1.x0(), pa_leaves1.y1()),
657 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
658 pa_leaves1.x1(), pa_leaves1.y1()),
659 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
660 pa_leaves1.x1(), pa_leaves1.y0()),
661 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
662 pa_leaves1.x0(), pa_leaves1.y0()),
667 for(u16 i=0; i<4; i++)
668 vertices[i].Pos.rotateXZBy(0);
672 for(u16 i=0; i<4; i++)
673 vertices[i].Pos.rotateXZBy(180);
677 for(u16 i=0; i<4; i++)
678 vertices[i].Pos.rotateXZBy(-90);
682 for(u16 i=0; i<4; i++)
683 vertices[i].Pos.rotateXZBy(90);
687 for(u16 i=0; i<4; i++)
688 vertices[i].Pos.rotateYZBy(-90);
692 for(u16 i=0; i<4; i++)
693 vertices[i].Pos.rotateYZBy(90);
696 for(u16 i=0; i<4; i++)
698 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
701 u16 indices[] = {0,1,2,2,3,0};
702 // Add to mesh collector
703 collector.append(material_leaves1, vertices, 4, indices, 6);
709 else if(n.getContent() == CONTENT_GLASS)
711 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
712 video::SColor c(255,l,l,l);
714 for(u32 j=0; j<6; j++)
716 video::S3DVertex vertices[4] =
718 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
719 pa_glass.x0(), pa_glass.y1()),
720 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
721 pa_glass.x1(), pa_glass.y1()),
722 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
723 pa_glass.x1(), pa_glass.y0()),
724 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
725 pa_glass.x0(), pa_glass.y0()),
730 for(u16 i=0; i<4; i++)
731 vertices[i].Pos.rotateXZBy(0);
735 for(u16 i=0; i<4; i++)
736 vertices[i].Pos.rotateXZBy(180);
740 for(u16 i=0; i<4; i++)
741 vertices[i].Pos.rotateXZBy(-90);
745 for(u16 i=0; i<4; i++)
746 vertices[i].Pos.rotateXZBy(90);
750 for(u16 i=0; i<4; i++)
751 vertices[i].Pos.rotateYZBy(-90);
755 for(u16 i=0; i<4; i++)
756 vertices[i].Pos.rotateYZBy(90);
759 for(u16 i=0; i<4; i++)
761 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
764 u16 indices[] = {0,1,2,2,3,0};
765 // Add to mesh collector
766 collector.append(material_glass, vertices, 4, indices, 6);
772 else if(n.getContent() == CONTENT_FENCE)
774 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
775 video::SColor c(255,l,l,l);
777 const f32 post_rad=(f32)BS/10;
778 const f32 bar_rad=(f32)BS/20;
779 const f32 bar_len=(f32)(BS/2)-post_rad;
781 // The post - always present
782 v3f pos = intToFloat(p+blockpos_nodes, BS);
790 makeCuboid(material_wood, &collector,
792 post_rad,BS/2,post_rad, postuv);
794 // Now a section of fence, +X, if there's a post there
797 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
798 if(n2.getContent() == CONTENT_FENCE)
800 pos = intToFloat(p+blockpos_nodes, BS);
810 makeCuboid(material_wood, &collector,
812 bar_len,bar_rad,bar_rad, xrailuv);
815 makeCuboid(material_wood, &collector,
817 bar_len,bar_rad,bar_rad, xrailuv);
820 // Now a section of fence, +Z, if there's a post there
823 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
824 if(n2.getContent() == CONTENT_FENCE)
826 pos = intToFloat(p+blockpos_nodes, BS);
836 makeCuboid(material_wood, &collector,
838 bar_rad,bar_rad,bar_len, zrailuv);
840 makeCuboid(material_wood, &collector,
842 bar_rad,bar_rad,bar_len, zrailuv);
849 Add stones with minerals if stone is invisible
851 else if(n.getContent() == CONTENT_STONE && invisible_stone && n.getMineral() != MINERAL_NONE)
853 for(u32 j=0; j<6; j++)
855 // NOTE: Hopefully g_6dirs[j] is the right direction...
856 v3s16 dir = g_6dirs[j];
858 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + dir);
859 if(content_features(n2).param_type == CPT_LIGHT)
860 l = decode_light(n2.getLightBlend(data->m_daynight_ratio));
864 video::SColor c(255,l,l,l);
866 // Get the right texture
867 TileSpec ts = n.getTile(dir);
868 AtlasPointer ap = ts.texture;
869 material_general.setTexture(0, ap.atlas);
871 video::S3DVertex vertices[4] =
873 /*video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c, 0,1),
874 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c, 1,1),
875 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c, 1,0),
876 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c, 0,0),*/
877 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
879 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
881 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
883 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
889 for(u16 i=0; i<4; i++)
890 vertices[i].Pos.rotateXZBy(0);
894 for(u16 i=0; i<4; i++)
895 vertices[i].Pos.rotateXZBy(180);
899 for(u16 i=0; i<4; i++)
900 vertices[i].Pos.rotateXZBy(-90);
904 for(u16 i=0; i<4; i++)
905 vertices[i].Pos.rotateXZBy(90);
909 for(u16 i=0; i<4; i++)
911 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
914 u16 indices[] = {0,1,2,2,3,0};
915 // Add to mesh collector
916 collector.append(material_general, vertices, 4, indices, 6);
920 else if(n.getContent() == CONTENT_PAPYRUS)
922 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
923 video::SColor c(255,l,l,l);
925 for(u32 j=0; j<4; j++)
927 video::S3DVertex vertices[4] =
929 video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c,
930 pa_papyrus.x0(), pa_papyrus.y1()),
931 video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c,
932 pa_papyrus.x1(), pa_papyrus.y1()),
933 video::S3DVertex(BS/2,BS/2,0, 0,0,0, c,
934 pa_papyrus.x1(), pa_papyrus.y0()),
935 video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c,
936 pa_papyrus.x0(), pa_papyrus.y0()),
941 for(u16 i=0; i<4; i++)
942 vertices[i].Pos.rotateXZBy(45);
946 for(u16 i=0; i<4; i++)
947 vertices[i].Pos.rotateXZBy(-45);
951 for(u16 i=0; i<4; i++)
952 vertices[i].Pos.rotateXZBy(135);
956 for(u16 i=0; i<4; i++)
957 vertices[i].Pos.rotateXZBy(-135);
960 for(u16 i=0; i<4; i++)
962 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
965 u16 indices[] = {0,1,2,2,3,0};
966 // Add to mesh collector
967 collector.append(material_papyrus, vertices, 4, indices, 6);
970 else if(n.getContent() == CONTENT_RAIL)
972 u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
973 video::SColor c(255,l,l,l);
975 bool is_rail_x [] = { false, false }; /* x-1, x+1 */
976 bool is_rail_z [] = { false, false }; /* z-1, z+1 */
978 MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
979 MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
980 MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
981 MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
983 if(n_minus_x.getContent() == CONTENT_RAIL)
985 if(n_plus_x.getContent() == CONTENT_RAIL)
987 if(n_minus_z.getContent() == CONTENT_RAIL)
989 if(n_plus_z.getContent() == CONTENT_RAIL)
992 float d = (float)BS/16;
993 video::S3DVertex vertices[4] =
995 video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c,
997 video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c,
999 video::S3DVertex(BS/2,-BS/2+d,BS/2, 0,0,0, c,
1001 video::S3DVertex(-BS/2,-BS/2+d,BS/2, 0,0,0, c,
1005 video::SMaterial material_rail;
1006 material_rail.setFlag(video::EMF_LIGHTING, false);
1007 material_rail.setFlag(video::EMF_BACK_FACE_CULLING, false);
1008 material_rail.setFlag(video::EMF_BILINEAR_FILTER, false);
1009 material_rail.setFlag(video::EMF_FOG_ENABLE, true);
1010 material_rail.MaterialType
1011 = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
1013 int adjacencies = is_rail_x[0] + is_rail_x[1] + is_rail_z[0] + is_rail_z[1];
1017 material_rail.setTexture(0, g_texturesource->getTextureRaw("rail.png"));
1018 else if(adjacencies == 2)
1020 if((is_rail_x[0] && is_rail_x[1]) || (is_rail_z[0] && is_rail_z[1]))
1021 material_rail.setTexture(0, g_texturesource->getTextureRaw("rail.png"));
1023 material_rail.setTexture(0, g_texturesource->getTextureRaw("rail_curved.png"));
1025 else if(adjacencies == 3)
1026 material_rail.setTexture(0, g_texturesource->getTextureRaw("rail_t_junction.png"));
1027 else if(adjacencies == 4)
1028 material_rail.setTexture(0, g_texturesource->getTextureRaw("rail_crossing.png"));
1033 if(adjacencies == 1)
1035 if(is_rail_x[0] || is_rail_x[1])
1038 else if(adjacencies == 2)
1040 if(is_rail_x[0] && is_rail_x[1])
1042 else if(is_rail_x[0] && is_rail_z[0])
1044 else if(is_rail_x[0] && is_rail_z[1])
1046 else if(is_rail_x[1] && is_rail_z[1])
1049 else if(adjacencies == 3)
1062 for(u16 i=0; i<4; i++)
1063 vertices[i].Pos.rotateXZBy(angle);
1066 for(s32 i=0; i<4; i++)
1068 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
1071 u16 indices[] = {0,1,2,2,3,0};
1072 collector.append(material_rail, vertices, 4, indices, 6);