27
27
#define MIN_EXTRUSION_MESH_RESOLUTION 16
28
28
#define MAX_EXTRUSION_MESH_RESOLUTION 512
29
29
30
+ /* !
31
+ * Applies overlays, textures and optionally materials to the given mesh and
32
+ * extracts tile colors for colorization.
33
+ * \param mattype overrides the buffer's material type, but can also
34
+ * be NULL to leave the original material.
35
+ * \param colors returns the colors of the mesh buffers in the mesh.
36
+ */
37
+ static void postProcessNodeMesh (scene::SMesh *mesh, const ContentFeatures &f,
38
+ bool set_material, const video::E_MATERIAL_TYPE *mattype,
39
+ std::vector<ItemPartColor> *colors, bool apply_scale = false );
40
+
41
+
30
42
static scene::IMesh *createExtrusionMesh (int resolution_x, int resolution_y)
31
43
{
32
44
const f32 r = 0.5 ;
@@ -317,25 +329,32 @@ static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n,
317
329
318
330
colors->clear ();
319
331
scene::SMesh *mesh = new scene::SMesh ();
320
- for (auto &prebuffers : collector.prebuffers )
332
+ for (int layer = 0 ; layer < MAX_TILE_LAYERS; layer++) {
333
+ auto &prebuffers = collector.prebuffers [layer];
321
334
for (PreMeshBuffer &p : prebuffers) {
322
335
if (p.layer .material_flags & MATERIAL_FLAG_ANIMATION) {
323
336
const FrameSpec &frame = (*p.layer .frames )[0 ];
324
337
p.layer .texture = frame.texture ;
325
338
}
326
- for (video::S3DVertex &v : p.vertices ) {
339
+ for (video::S3DVertex &v : p.vertices )
327
340
v.Color .setAlpha (255 );
328
- }
329
- scene::SMeshBuffer *buf = new scene::SMeshBuffer ();
330
- buf->Material .setTexture (0 , p.layer .texture );
331
- p.layer .applyMaterialOptions (buf->Material );
332
- mesh->addMeshBuffer (buf);
341
+
342
+ auto buf = make_irr<scene::SMeshBuffer>();
333
343
buf->append (&p.vertices [0 ], p.vertices .size (),
334
344
&p.indices [0 ], p.indices .size ());
335
- buf->drop ();
336
- colors->push_back (
337
- ItemPartColor (p.layer .has_color , p.layer .color ));
345
+
346
+ // Set up material
347
+ buf->Material .setTexture (0 , p.layer .texture );
348
+ if (layer == 1 ) {
349
+ buf->Material .PolygonOffsetSlopeScale = -1 ;
350
+ buf->Material .PolygonOffsetDepthBias = -1 ;
351
+ }
352
+ p.layer .applyMaterialOptions (buf->Material );
353
+
354
+ mesh->addMeshBuffer (buf.get ());
355
+ colors->emplace_back (p.layer .has_color , p.layer .color );
338
356
}
357
+ }
339
358
return mesh;
340
359
}
341
360
@@ -688,13 +707,15 @@ scene::SMesh *getExtrudedMesh(ITextureSource *tsrc,
688
707
return mesh;
689
708
}
690
709
691
- void postProcessNodeMesh (scene::SMesh *mesh, const ContentFeatures &f,
710
+ static void postProcessNodeMesh (scene::SMesh *mesh, const ContentFeatures &f,
692
711
bool set_material, const video::E_MATERIAL_TYPE *mattype,
693
712
std::vector<ItemPartColor> *colors, bool apply_scale)
694
713
{
714
+ // FIXME: this function is weirdly inconsistent with what MapBlockMesh does.
715
+ // also set_material is never true
716
+
695
717
const u32 mc = mesh->getMeshBufferCount ();
696
718
// Allocate colors for existing buffers
697
- colors->clear ();
698
719
colors->resize (mc);
699
720
700
721
for (u32 i = 0 ; i < mc; ++i) {
@@ -705,6 +726,7 @@ void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f,
705
726
if (layer->texture_id == 0 )
706
727
continue ;
707
728
if (layernum != 0 ) {
729
+ // FIXME: why do this?
708
730
scene::IMeshBuffer *copy = cloneMeshBuffer (buf);
709
731
copy->getMaterial () = buf->getMaterial ();
710
732
mesh->addMeshBuffer (copy);
0 commit comments