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
26 // material - the material to use (for all 6 faces)
27 // collector - the MeshCollector for the resulting polygons
28 // pa - texture atlas pointer for the material
29 // c - vertex colour - used for all
30 // pos - the position of the centre of the cuboid
31 // rz,ry,rz - the radius of the cuboid in each dimension
32 // txc - texture coordinates - this is a list of texture coordinates
33 // for the opposite corners of each face - therefore, there
34 // should be (2+2)*6=24 values in the list. Alternatively, pass
35 // NULL to use the entire texture for each face. The order of
36 // the faces in the list is top-backi-right-front-left-bottom
37 // If you specified 0,0,1,1 for each face, that would be the
38 // same as passing NULL.
39 void makeCuboid(video::SMaterial &material, MeshCollector *collector,
40 AtlasPointer* pa, video::SColor &c,
41 v3f &pos, f32 rx, f32 ry, f32 rz, f32* txc)
50 video::S3DVertex v[4] =
52 video::S3DVertex(0,0,0, 0,0,0, c, tu0, tv1),
53 video::S3DVertex(0,0,0, 0,0,0, c, tu1, tv1),
54 video::S3DVertex(0,0,0, 0,0,0, c, tu1, tv0),
55 video::S3DVertex(0,0,0, 0,0,0, c, tu0, tv0)
63 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
64 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
65 v[2].Pos.X= rx; v[2].Pos.Y= ry; v[2].Pos.Z= rz;
66 v[3].Pos.X= rx; v[3].Pos.Y= ry, v[3].Pos.Z=-rz;
69 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
70 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
71 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
72 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
75 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
76 v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
77 v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
78 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
81 v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
82 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
83 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
84 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
87 v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
88 v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
89 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
90 v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
93 v[0].Pos.X= rx; v[0].Pos.Y=-ry; v[0].Pos.Z= rz;
94 v[1].Pos.X=-rx; v[1].Pos.Y=-ry; v[1].Pos.Z= rz;
95 v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
96 v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
102 v[0].TCoords.X=tu0+txus*txc[0]; v[0].TCoords.Y=tv0+txvs*txc[3];
103 v[1].TCoords.X=tu0+txus*txc[2]; v[1].TCoords.Y=tv0+txvs*txc[3];
104 v[2].TCoords.X=tu0+txus*txc[2]; v[2].TCoords.Y=tv0+txvs*txc[1];
105 v[3].TCoords.X=tu0+txus*txc[0]; v[3].TCoords.Y=tv0+txvs*txc[1];
109 for(u16 i=0; i<4; i++)
111 u16 indices[] = {0,1,2,2,3,0};
112 collector->append(material, v, 4, indices, 6);
120 void mapblock_mesh_generate_special(MeshMakeData *data,
121 MeshCollector &collector)
124 //TimeTaker timer("mapblock_mesh_generate_special()");
129 bool new_style_water = g_settings.getBool("new_style_water");
130 bool new_style_leaves = g_settings.getBool("new_style_leaves");
131 //bool smooth_lighting = g_settings.getBool("smooth_lighting");
133 float node_water_level = 1.0;
135 node_water_level = 0.85;
137 v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
139 // Flowing water material
140 video::SMaterial material_water1;
141 material_water1.setFlag(video::EMF_LIGHTING, false);
142 material_water1.setFlag(video::EMF_BACK_FACE_CULLING, false);
143 material_water1.setFlag(video::EMF_BILINEAR_FILTER, false);
144 material_water1.setFlag(video::EMF_FOG_ENABLE, true);
145 material_water1.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
146 AtlasPointer pa_water1 = g_texturesource->getTexture(
147 g_texturesource->getTextureId("water.png"));
148 material_water1.setTexture(0, pa_water1.atlas);
150 // New-style leaves material
151 video::SMaterial material_leaves1;
152 material_leaves1.setFlag(video::EMF_LIGHTING, false);
153 //material_leaves1.setFlag(video::EMF_BACK_FACE_CULLING, false);
154 material_leaves1.setFlag(video::EMF_BILINEAR_FILTER, false);
155 material_leaves1.setFlag(video::EMF_FOG_ENABLE, true);
156 material_leaves1.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
157 AtlasPointer pa_leaves1 = g_texturesource->getTexture(
158 g_texturesource->getTextureId("leaves.png"));
159 material_leaves1.setTexture(0, pa_leaves1.atlas);
162 video::SMaterial material_glass;
163 material_glass.setFlag(video::EMF_LIGHTING, false);
164 material_glass.setFlag(video::EMF_BILINEAR_FILTER, false);
165 material_glass.setFlag(video::EMF_FOG_ENABLE, true);
166 material_glass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
167 AtlasPointer pa_glass = g_texturesource->getTexture(
168 g_texturesource->getTextureId("glass.png"));
169 material_glass.setTexture(0, pa_glass.atlas);
172 video::SMaterial material_wood;
173 material_wood.setFlag(video::EMF_LIGHTING, false);
174 material_wood.setFlag(video::EMF_BILINEAR_FILTER, false);
175 material_wood.setFlag(video::EMF_FOG_ENABLE, true);
176 material_wood.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
177 AtlasPointer pa_wood = g_texturesource->getTexture(
178 g_texturesource->getTextureId("wood.png"));
179 material_wood.setTexture(0, pa_wood.atlas);
181 for(s16 z=0; z<MAP_BLOCKSIZE; z++)
182 for(s16 y=0; y<MAP_BLOCKSIZE; y++)
183 for(s16 x=0; x<MAP_BLOCKSIZE; x++)
187 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes+p);
192 if(n.d == CONTENT_TORCH)
194 video::SColor c(255,255,255,255);
196 // Wall at X+ of node
197 video::S3DVertex vertices[4] =
199 video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c, 0,1),
200 video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c, 1,1),
201 video::S3DVertex(BS/2,BS/2,0, 0,0,0, c, 1,0),
202 video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c, 0,0),
205 v3s16 dir = unpackDir(n.dir);
207 for(s32 i=0; i<4; i++)
209 if(dir == v3s16(1,0,0))
210 vertices[i].Pos.rotateXZBy(0);
211 if(dir == v3s16(-1,0,0))
212 vertices[i].Pos.rotateXZBy(180);
213 if(dir == v3s16(0,0,1))
214 vertices[i].Pos.rotateXZBy(90);
215 if(dir == v3s16(0,0,-1))
216 vertices[i].Pos.rotateXZBy(-90);
217 if(dir == v3s16(0,-1,0))
218 vertices[i].Pos.rotateXZBy(45);
219 if(dir == v3s16(0,1,0))
220 vertices[i].Pos.rotateXZBy(-45);
222 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
226 video::SMaterial material;
227 material.setFlag(video::EMF_LIGHTING, false);
228 material.setFlag(video::EMF_BACK_FACE_CULLING, false);
229 material.setFlag(video::EMF_BILINEAR_FILTER, false);
230 //material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
231 material.MaterialType
232 = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
234 if(dir == v3s16(0,-1,0))
235 material.setTexture(0,
236 g_texturesource->getTextureRaw("torch_on_floor.png"));
237 else if(dir == v3s16(0,1,0))
238 material.setTexture(0,
239 g_texturesource->getTextureRaw("torch_on_ceiling.png"));
240 // For backwards compatibility
241 else if(dir == v3s16(0,0,0))
242 material.setTexture(0,
243 g_texturesource->getTextureRaw("torch_on_floor.png"));
245 material.setTexture(0,
246 g_texturesource->getTextureRaw("torch.png"));
248 u16 indices[] = {0,1,2,2,3,0};
249 // Add to mesh collector
250 collector.append(material, vertices, 4, indices, 6);
255 if(n.d == CONTENT_SIGN_WALL)
257 u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
258 video::SColor c(255,l,l,l);
260 float d = (float)BS/16;
261 // Wall at X+ of node
262 video::S3DVertex vertices[4] =
264 video::S3DVertex(BS/2-d,-BS/2,-BS/2, 0,0,0, c, 0,1),
265 video::S3DVertex(BS/2-d,-BS/2,BS/2, 0,0,0, c, 1,1),
266 video::S3DVertex(BS/2-d,BS/2,BS/2, 0,0,0, c, 1,0),
267 video::S3DVertex(BS/2-d,BS/2,-BS/2, 0,0,0, c, 0,0),
270 v3s16 dir = unpackDir(n.dir);
272 for(s32 i=0; i<4; i++)
274 if(dir == v3s16(1,0,0))
275 vertices[i].Pos.rotateXZBy(0);
276 if(dir == v3s16(-1,0,0))
277 vertices[i].Pos.rotateXZBy(180);
278 if(dir == v3s16(0,0,1))
279 vertices[i].Pos.rotateXZBy(90);
280 if(dir == v3s16(0,0,-1))
281 vertices[i].Pos.rotateXZBy(-90);
282 if(dir == v3s16(0,-1,0))
283 vertices[i].Pos.rotateXYBy(-90);
284 if(dir == v3s16(0,1,0))
285 vertices[i].Pos.rotateXYBy(90);
287 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
291 video::SMaterial material;
292 material.setFlag(video::EMF_LIGHTING, false);
293 material.setFlag(video::EMF_BACK_FACE_CULLING, false);
294 material.setFlag(video::EMF_BILINEAR_FILTER, false);
295 material.setFlag(video::EMF_FOG_ENABLE, true);
296 //material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
297 material.MaterialType
298 = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
300 material.setTexture(0,
301 g_texturesource->getTextureRaw("sign_wall.png"));
303 u16 indices[] = {0,1,2,2,3,0};
304 // Add to mesh collector
305 collector.append(material, vertices, 4, indices, 6);
308 Add flowing water to mesh
310 else if(n.d == CONTENT_WATER)
312 bool top_is_water = false;
313 MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
314 if(ntop.d == CONTENT_WATER || ntop.d == CONTENT_WATERSOURCE)
318 // Use the light of the node on top if possible
319 if(content_features(ntop.d).param_type == CPT_LIGHT)
320 l = decode_light(ntop.getLightBlend(data->m_daynight_ratio));
321 // Otherwise use the light of this node (the water)
323 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
324 video::SColor c(WATER_ALPHA,l,l,l);
326 // Neighbor water levels (key = relative position)
327 // Includes current node
328 core::map<v3s16, f32> neighbor_levels;
329 core::map<v3s16, u8> neighbor_contents;
330 core::map<v3s16, u8> neighbor_flags;
331 const u8 neighborflag_top_is_water = 0x01;
332 v3s16 neighbor_dirs[9] = {
343 for(u32 i=0; i<9; i++)
345 u8 content = CONTENT_AIR;
346 float level = -0.5 * BS;
349 v3s16 p2 = p + neighbor_dirs[i];
350 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
351 if(n2.d != CONTENT_IGNORE)
355 if(n2.d == CONTENT_WATERSOURCE)
356 level = (-0.5+node_water_level) * BS;
357 else if(n2.d == CONTENT_WATER)
358 level = (-0.5 + ((float)n2.param2 + 0.5) / 8.0
359 * node_water_level) * BS;
361 // Check node above neighbor.
362 // NOTE: This doesn't get executed if neighbor
365 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
366 if(n2.d == CONTENT_WATERSOURCE || n2.d == CONTENT_WATER)
367 flags |= neighborflag_top_is_water;
370 neighbor_levels.insert(neighbor_dirs[i], level);
371 neighbor_contents.insert(neighbor_dirs[i], content);
372 neighbor_flags.insert(neighbor_dirs[i], flags);
375 //float water_level = (-0.5 + ((float)n.param2 + 0.5) / 8.0) * BS;
376 //float water_level = neighbor_levels[v3s16(0,0,0)];
378 // Corner heights (average between four waters)
379 f32 corner_levels[4];
381 v3s16 halfdirs[4] = {
387 for(u32 i=0; i<4; i++)
389 v3s16 cornerdir = halfdirs[i];
390 float cornerlevel = 0;
392 for(u32 j=0; j<4; j++)
394 v3s16 neighbordir = cornerdir - halfdirs[j];
395 u8 content = neighbor_contents[neighbordir];
396 // Special case for source nodes
397 if(content == CONTENT_WATERSOURCE)
399 cornerlevel = (-0.5+node_water_level)*BS;
403 else if(content == CONTENT_WATER)
405 cornerlevel += neighbor_levels[neighbordir];
408 else if(content == CONTENT_AIR)
410 cornerlevel += -0.5*BS;
415 cornerlevel /= valid_count;
416 corner_levels[i] = cornerlevel;
423 v3s16 side_dirs[4] = {
429 s16 side_corners[4][2] = {
435 for(u32 i=0; i<4; i++)
437 v3s16 dir = side_dirs[i];
440 If our topside is water and neighbor's topside
441 is water, don't draw side face
444 neighbor_flags[dir] & neighborflag_top_is_water)
447 u8 neighbor_content = neighbor_contents[dir];
449 // Don't draw face if neighbor is not air or water
450 if(neighbor_content != CONTENT_AIR
451 && neighbor_content != CONTENT_WATER)
454 bool neighbor_is_water = (neighbor_content == CONTENT_WATER);
456 // Don't draw any faces if neighbor is water and top is water
457 if(neighbor_is_water == true && top_is_water == false)
460 video::S3DVertex vertices[4] =
462 /*video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,1),
463 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
464 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
465 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
466 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
467 pa_water1.x0(), pa_water1.y1()),
468 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
469 pa_water1.x1(), pa_water1.y1()),
470 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
471 pa_water1.x1(), pa_water1.y0()),
472 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
473 pa_water1.x0(), pa_water1.y0()),
477 If our topside is water, set upper border of face
478 at upper border of node
482 vertices[2].Pos.Y = 0.5*BS;
483 vertices[3].Pos.Y = 0.5*BS;
486 Otherwise upper position of face is corner levels
490 vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
491 vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
495 If neighbor is water, lower border of face is corner
498 if(neighbor_is_water)
500 vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
501 vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
504 If neighbor is not water, lower border of face is
509 vertices[0].Pos.Y = -0.5*BS;
510 vertices[1].Pos.Y = -0.5*BS;
513 for(s32 j=0; j<4; j++)
515 if(dir == v3s16(0,0,1))
516 vertices[j].Pos.rotateXZBy(0);
517 if(dir == v3s16(0,0,-1))
518 vertices[j].Pos.rotateXZBy(180);
519 if(dir == v3s16(-1,0,0))
520 vertices[j].Pos.rotateXZBy(90);
521 if(dir == v3s16(1,0,-0))
522 vertices[j].Pos.rotateXZBy(-90);
524 vertices[j].Pos += intToFloat(p + blockpos_nodes, BS);
527 u16 indices[] = {0,1,2,2,3,0};
528 // Add to mesh collector
529 collector.append(material_water1, vertices, 4, indices, 6);
533 Generate top side, if appropriate
536 if(top_is_water == false)
538 video::S3DVertex vertices[4] =
540 /*video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,1),
541 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,1),
542 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
543 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
544 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
545 pa_water1.x0(), pa_water1.y1()),
546 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
547 pa_water1.x1(), pa_water1.y1()),
548 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
549 pa_water1.x1(), pa_water1.y0()),
550 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
551 pa_water1.x0(), pa_water1.y0()),
554 // This fixes a strange bug
555 s32 corner_resolve[4] = {3,2,1,0};
557 for(s32 i=0; i<4; i++)
559 //vertices[i].Pos.Y += water_level;
560 //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
561 s32 j = corner_resolve[i];
562 vertices[i].Pos.Y += corner_levels[j];
563 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
566 u16 indices[] = {0,1,2,2,3,0};
567 // Add to mesh collector
568 collector.append(material_water1, vertices, 4, indices, 6);
572 Add water sources to mesh if using new style
574 else if(n.d == CONTENT_WATERSOURCE && new_style_water)
576 //bool top_is_water = false;
577 bool top_is_air = false;
578 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
579 /*if(n.d == CONTENT_WATER || n.d == CONTENT_WATERSOURCE)
580 top_is_water = true;*/
581 if(n.d == CONTENT_AIR)
584 /*if(top_is_water == true)
586 if(top_is_air == false)
589 u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
590 video::SColor c(WATER_ALPHA,l,l,l);
592 video::S3DVertex vertices[4] =
594 /*video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, 0,1),
595 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,1),
596 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
597 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
598 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
599 pa_water1.x0(), pa_water1.y1()),
600 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
601 pa_water1.x1(), pa_water1.y1()),
602 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
603 pa_water1.x1(), pa_water1.y0()),
604 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
605 pa_water1.x0(), pa_water1.y0()),
608 for(s32 i=0; i<4; i++)
610 vertices[i].Pos.Y += (-0.5+node_water_level)*BS;
611 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
614 u16 indices[] = {0,1,2,2,3,0};
615 // Add to mesh collector
616 collector.append(material_water1, vertices, 4, indices, 6);
619 Add leaves if using new style
621 else if(n.d == CONTENT_LEAVES && new_style_leaves)
623 /*u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));*/
624 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
625 video::SColor c(255,l,l,l);
627 for(u32 j=0; j<6; j++)
629 video::S3DVertex vertices[4] =
631 /*video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c, 0,1),
632 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c, 1,1),
633 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c, 1,0),
634 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c, 0,0),*/
635 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
636 pa_leaves1.x0(), pa_leaves1.y1()),
637 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
638 pa_leaves1.x1(), pa_leaves1.y1()),
639 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
640 pa_leaves1.x1(), pa_leaves1.y0()),
641 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
642 pa_leaves1.x0(), pa_leaves1.y0()),
647 for(u16 i=0; i<4; i++)
648 vertices[i].Pos.rotateXZBy(0);
652 for(u16 i=0; i<4; i++)
653 vertices[i].Pos.rotateXZBy(180);
657 for(u16 i=0; i<4; i++)
658 vertices[i].Pos.rotateXZBy(-90);
662 for(u16 i=0; i<4; i++)
663 vertices[i].Pos.rotateXZBy(90);
667 for(u16 i=0; i<4; i++)
668 vertices[i].Pos.rotateYZBy(-90);
672 for(u16 i=0; i<4; i++)
673 vertices[i].Pos.rotateYZBy(90);
676 for(u16 i=0; i<4; i++)
678 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
681 u16 indices[] = {0,1,2,2,3,0};
682 // Add to mesh collector
683 collector.append(material_leaves1, vertices, 4, indices, 6);
689 else if(n.d == CONTENT_GLASS)
691 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
692 video::SColor c(255,l,l,l);
694 for(u32 j=0; j<6; j++)
696 video::S3DVertex vertices[4] =
698 video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
699 pa_glass.x0(), pa_glass.y1()),
700 video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
701 pa_glass.x1(), pa_glass.y1()),
702 video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
703 pa_glass.x1(), pa_glass.y0()),
704 video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
705 pa_glass.x0(), pa_glass.y0()),
710 for(u16 i=0; i<4; i++)
711 vertices[i].Pos.rotateXZBy(0);
715 for(u16 i=0; i<4; i++)
716 vertices[i].Pos.rotateXZBy(180);
720 for(u16 i=0; i<4; i++)
721 vertices[i].Pos.rotateXZBy(-90);
725 for(u16 i=0; i<4; i++)
726 vertices[i].Pos.rotateXZBy(90);
730 for(u16 i=0; i<4; i++)
731 vertices[i].Pos.rotateYZBy(-90);
735 for(u16 i=0; i<4; i++)
736 vertices[i].Pos.rotateYZBy(90);
739 for(u16 i=0; i<4; i++)
741 vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
744 u16 indices[] = {0,1,2,2,3,0};
745 // Add to mesh collector
746 collector.append(material_glass, vertices, 4, indices, 6);
752 else if(n.d == CONTENT_FENCE)
754 u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
755 video::SColor c(255,l,l,l);
757 const f32 post_rad=(f32)BS/10;
758 const f32 bar_rad=(f32)BS/20;
759 const f32 bar_len=(f32)(BS/2)-post_rad;
761 // The post - always present
762 v3f pos = intToFloat(p+blockpos_nodes, BS);
770 makeCuboid(material_wood, &collector,
772 post_rad,BS/2,post_rad, postuv);
774 // Now a section of fence, +X, if there's a post there
777 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
778 if(n2.d == CONTENT_FENCE)
780 pos = intToFloat(p+blockpos_nodes, BS);
790 makeCuboid(material_wood, &collector,
792 bar_len,bar_rad,bar_rad, xrailuv);
795 makeCuboid(material_wood, &collector,
797 bar_len,bar_rad,bar_rad, xrailuv);
800 // Now a section of fence, +Z, if there's a post there
803 n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
804 if(n2.d == CONTENT_FENCE)
806 pos = intToFloat(p+blockpos_nodes, BS);
816 makeCuboid(material_wood, &collector,
818 bar_rad,bar_rad,bar_len, zrailuv);
820 makeCuboid(material_wood, &collector,
822 bar_rad,bar_rad,bar_len, zrailuv);