@@ -59,7 +59,7 @@ void MeshMakeData::fill(MapBlock *block)
59
59
m_blockpos = block->getPos ();
60
60
61
61
v3s16 blockpos_nodes = m_blockpos*MAP_BLOCKSIZE;
62
-
62
+
63
63
/*
64
64
Copy data
65
65
*/
@@ -84,7 +84,7 @@ void MeshMakeData::fill(MapBlock *block)
84
84
Copy neighbors. This is lightning fast.
85
85
Copying only the borders would be *very* slow.
86
86
*/
87
-
87
+
88
88
// Get map
89
89
Map *map = block->getParent ();
90
90
@@ -102,7 +102,7 @@ void MeshMakeData::fill(MapBlock *block)
102
102
void MeshMakeData::fillSingleNode (MapNode *node)
103
103
{
104
104
m_blockpos = v3s16 (0 ,0 ,0 );
105
-
105
+
106
106
v3s16 blockpos_nodes = v3s16 (0 ,0 ,0 );
107
107
VoxelArea area (blockpos_nodes-v3s16 (1 ,1 ,1 )*MAP_BLOCKSIZE,
108
108
blockpos_nodes+v3s16 (1 ,1 ,1 )*MAP_BLOCKSIZE*2 -v3s16 (1 ,1 ,1 ));
@@ -257,6 +257,12 @@ static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data)
257
257
for (u32 i=0 ; i<8 ; i++)
258
258
{
259
259
MapNode n = data->m_vmanip .getNodeNoEx (p - dirs8[i]);
260
+
261
+ if (n.getContent () == CONTENT_IGNORE) {
262
+ ambient_occlusion++;
263
+ continue ;
264
+ }
265
+
260
266
const ContentFeatures &f = ndef->get (n);
261
267
if (f.light_source > light_source_max)
262
268
light_source_max = f.light_source ;
@@ -267,15 +273,11 @@ static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data)
267
273
light += decode_light (n.getLight (bank, ndef));
268
274
light_count++;
269
275
}
270
- else if (n.getContent () != CONTENT_IGNORE)
271
- {
272
- ambient_occlusion++;
273
- }
274
276
}
275
277
276
278
if (light_count == 0 )
277
279
return 255 ;
278
-
280
+
279
281
light /= light_count;
280
282
281
283
// Boost brightness around light sources
@@ -323,7 +325,7 @@ u16 getSmoothLight(v3s16 p, v3s16 corner, MeshMakeData *data)
323
325
else assert (corner.Y == -1 );
324
326
if (corner.Z == 1 ) p.Z += 1 ;
325
327
else assert (corner.Z == -1 );
326
-
328
+
327
329
return getSmoothLight (p, data);
328
330
}
329
331
@@ -630,16 +632,16 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent,
630
632
631
633
if (m1 == CONTENT_IGNORE || m2 == CONTENT_IGNORE)
632
634
return 0 ;
633
-
635
+
634
636
bool contents_differ = (m1 != m2);
635
-
637
+
636
638
const ContentFeatures &f1 = ndef->get (m1);
637
639
const ContentFeatures &f2 = ndef->get (m2);
638
640
639
641
// Contents don't differ for different forms of same liquid
640
642
if (f1.sameLiquid (f2))
641
643
contents_differ = false ;
642
-
644
+
643
645
u8 c1 = f1.solidness ;
644
646
u8 c2 = f2.solidness ;
645
647
@@ -648,12 +650,12 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent,
648
650
649
651
if (makes_face == false )
650
652
return 0 ;
651
-
653
+
652
654
if (c1 == 0 )
653
655
c1 = f1.visual_solidness ;
654
656
if (c2 == 0 )
655
657
c2 = f2.visual_solidness ;
656
-
658
+
657
659
if (c1 == c2){
658
660
*equivalent = true ;
659
661
// If same solidness, liquid takes precense
@@ -662,7 +664,7 @@ static u8 face_contents(content_t m1, content_t m2, bool *equivalent,
662
664
if (f2.isLiquid ())
663
665
return 2 ;
664
666
}
665
-
667
+
666
668
if (c1 > c2)
667
669
return 1 ;
668
670
else
@@ -712,7 +714,7 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 dir, MeshMakeData *data)
712
714
facedir = 0 ;
713
715
static const u16 dir_to_tile[24 * 16 ] =
714
716
{
715
- // 0 +X +Y +Z -Z -Y -X -> value=tile,rotation
717
+ // 0 +X +Y +Z -Z -Y -X -> value=tile,rotation
716
718
0 ,0 , 2 ,0 , 0 ,0 , 4 ,0 , 0 ,0 , 5 ,0 , 1 ,0 , 3 ,0 , // rotate around y+ 0 - 3
717
719
0 ,0 ,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,2 , 0 ,0 , 4 ,2 , 0 ,0 , 3 ,2 ,
744
- 0 ,0 , 4 ,2 , 1 ,1 , 2 ,2 , 0 ,0 , 3 ,2 , 0 ,3 , 5 ,2
744
+ 0 ,0 , 5 ,2 , 1 ,3 , 3 ,2 , 0 ,0 , 2 ,2 , 0 ,1 , 4 ,2 ,
745
+ 0 ,0 , 2 ,2 , 1 ,0 , 5 ,2 , 0 ,0 , 4 ,2 , 0 ,0 , 3 ,2 ,
746
+ 0 ,0 , 4 ,2 , 1 ,1 , 2 ,2 , 0 ,0 , 3 ,2 , 0 ,3 , 5 ,2
745
747
746
748
};
747
749
u16 tile_index=facedir*16 + dir_i;
@@ -770,14 +772,14 @@ static void getTileInfo(
770
772
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
771
773
772
774
MapNode n0 = vmanip.getNodeNoEx (blockpos_nodes + p);
773
-
775
+
774
776
// Don't even try to get n1 if n0 is already CONTENT_IGNORE
775
777
if (n0.getContent () == CONTENT_IGNORE ) {
776
778
makes_face = false ;
777
779
return ;
778
780
}
779
781
MapNode n1 = vmanip.getNodeNoEx (blockpos_nodes + p + face_dir);
780
-
782
+
781
783
// This is hackish
782
784
bool equivalent = false ;
783
785
u8 mf = face_contents (n0.getContent (), n1.getContent (),
@@ -790,7 +792,7 @@ static void getTileInfo(
790
792
}
791
793
792
794
makes_face = true ;
793
-
795
+
794
796
if (mf == 1 )
795
797
{
796
798
tile = getNodeTile (n0, p, face_dir, data);
@@ -805,7 +807,7 @@ static void getTileInfo(
805
807
face_dir_corrected = -face_dir;
806
808
light_source = ndef->get (n1).light_source ;
807
809
}
808
-
810
+
809
811
// eg. water and glass
810
812
if (equivalent)
811
813
tile.material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
@@ -826,7 +828,7 @@ static void getTileInfo(
826
828
vertex_dirs[i], data);
827
829
}
828
830
}
829
-
831
+
830
832
return ;
831
833
}
832
834
@@ -845,44 +847,44 @@ static void updateFastFaceRow(
845
847
std::vector<FastFace> &dest)
846
848
{
847
849
v3s16 p = startpos;
848
-
850
+
849
851
u16 continuous_tiles_count = 0 ;
850
-
852
+
851
853
bool makes_face = false ;
852
854
v3s16 p_corrected;
853
855
v3s16 face_dir_corrected;
854
856
u16 lights[4 ] = {0 ,0 ,0 ,0 };
855
857
TileSpec tile;
856
858
u8 light_source = 0 ;
857
- getTileInfo (data, p, face_dir,
859
+ getTileInfo (data, p, face_dir,
858
860
makes_face, p_corrected, face_dir_corrected,
859
861
lights, tile, light_source);
860
862
861
863
for (u16 j=0 ; j<MAP_BLOCKSIZE; j++)
862
864
{
863
865
// If tiling can be done, this is set to false in the next step
864
866
bool next_is_different = true ;
865
-
867
+
866
868
v3s16 p_next;
867
-
869
+
868
870
bool next_makes_face = false ;
869
871
v3s16 next_p_corrected;
870
872
v3s16 next_face_dir_corrected;
871
873
u16 next_lights[4 ] = {0 ,0 ,0 ,0 };
872
874
TileSpec next_tile;
873
875
u8 next_light_source = 0 ;
874
-
876
+
875
877
// If at last position, there is nothing to compare to and
876
878
// the face must be drawn anyway
877
879
if (j != MAP_BLOCKSIZE - 1 )
878
880
{
879
881
p_next = p + translate_dir;
880
-
882
+
881
883
getTileInfo (data, p_next, face_dir,
882
884
next_makes_face, next_p_corrected,
883
885
next_face_dir_corrected, next_lights,
884
886
next_tile, next_light_source);
885
-
887
+
886
888
if (next_makes_face == makes_face
887
889
&& next_p_corrected == p_corrected + translate_dir
888
890
&& next_face_dir_corrected == face_dir_corrected
@@ -922,7 +924,7 @@ static void updateFastFaceRow(
922
924
}
923
925
924
926
continuous_tiles_count++;
925
-
927
+
926
928
if (next_is_different)
927
929
{
928
930
/*
@@ -950,19 +952,19 @@ static void updateFastFaceRow(
950
952
{
951
953
scale.Z = continuous_tiles_count;
952
954
}
953
-
955
+
954
956
makeFastFace (tile, lights[0 ], lights[1 ], lights[2 ], lights[3 ],
955
957
sp, face_dir_corrected, scale, light_source,
956
958
dest);
957
-
959
+
958
960
g_profiler->avg (" Meshgen: faces drawn by tiling" , 0 );
959
961
for (int i=1 ; i<continuous_tiles_count; i++){
960
962
g_profiler->avg (" Meshgen: faces drawn by tiling" , 1 );
961
963
}
962
964
}
963
965
964
966
continuous_tiles_count = 0 ;
965
-
967
+
966
968
makes_face = next_makes_face;
967
969
p_corrected = next_p_corrected;
968
970
face_dir_corrected = next_face_dir_corrected;
@@ -973,7 +975,7 @@ static void updateFastFaceRow(
973
975
tile = next_tile;
974
976
light_source = next_light_source;
975
977
}
976
-
978
+
977
979
p = p_next;
978
980
}
979
981
}
@@ -1077,12 +1079,12 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1077
1079
1078
1080
const u16 indices[] = {0 ,1 ,2 ,2 ,3 ,0 };
1079
1081
const u16 indices_alternate[] = {0 ,1 ,3 ,2 ,3 ,1 };
1080
-
1082
+
1081
1083
if (f.tile .texture == NULL )
1082
1084
continue ;
1083
1085
1084
1086
const u16 *indices_p = indices;
1085
-
1087
+
1086
1088
/*
1087
1089
Revert triangles for nicer looking gradient if vertices
1088
1090
1 and 3 have same color or 0 and 2 have different color.
@@ -1091,7 +1093,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1091
1093
if (f.vertices [0 ].Color .getRed () != f.vertices [2 ].Color .getRed ()
1092
1094
|| f.vertices [1 ].Color .getRed () == f.vertices [3 ].Color .getRed ())
1093
1095
indices_p = indices_alternate;
1094
-
1096
+
1095
1097
collector.append (f.tile , f.vertices , 4 , indices_p, 6 );
1096
1098
}
1097
1099
}
@@ -1105,7 +1107,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1105
1107
*/
1106
1108
1107
1109
mapblock_mesh_generate_special (data, collector);
1108
-
1110
+
1109
1111
1110
1112
/*
1111
1113
Convert MeshCollector to SMesh
@@ -1198,7 +1200,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1198
1200
1199
1201
if (enable_shaders) {
1200
1202
material.MaterialType = shdrsrc->getShaderInfo (p.tile .shader_id ).material ;
1201
- p.tile .applyMaterialOptionsWithShaders (material);
1203
+ p.tile .applyMaterialOptionsWithShaders (material);
1202
1204
material.setTexture (2 , tsrc->getTexture (" disable_img.png" ));
1203
1205
if (enable_bumpmapping || enable_parallax_occlusion) {
1204
1206
if (tsrc->isKnownSourceImage (" override_normal.png" )){
@@ -1211,7 +1213,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1211
1213
std::string fname_normal = fname_base.substr (0 , pos) + normal_ext;
1212
1214
1213
1215
if (tsrc->isKnownSourceImage (fname_normal)) {
1214
- // look for image extension and replace it
1216
+ // look for image extension and replace it
1215
1217
size_t i = 0 ;
1216
1218
while ((i = fname_base.find (" ." , i)) != std::string::npos) {
1217
1219
fname_base.replace (i, 4 , normal_ext);
@@ -1241,7 +1243,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1241
1243
}
1242
1244
1243
1245
m_camera_offset = camera_offset;
1244
-
1246
+
1245
1247
/*
1246
1248
Do some stuff to the mesh
1247
1249
*/
@@ -1267,7 +1269,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1267
1269
the hardware buffer and then delete the mesh
1268
1270
*/
1269
1271
}
1270
-
1272
+
1271
1273
// std::cout<<"added "<<fastfaces.getSize()<<" faces."<<std::endl;
1272
1274
1273
1275
// Check if animation is required for this mesh
@@ -1331,7 +1333,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
1331
1333
1332
1334
m_last_crack = crack;
1333
1335
}
1334
-
1336
+
1335
1337
// Texture animation
1336
1338
for (std::map<u32, TileSpec>::iterator
1337
1339
i = m_animation_tiles.begin ();
0 commit comments