3 Copyright (C) 2010-2014 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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser 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 "wieldmesh.h"
23 #include "inventory.h"
28 #include "content_mapblock.h"
29 #include "mapblock_mesh.h"
30 #include "client/meshgen/collector.h"
31 #include "client/tile.h"
33 #include "util/numeric.h"
35 #include <IMeshManipulator.h>
37 #define WIELD_SCALE_FACTOR 30.0
38 #define WIELD_SCALE_FACTOR_EXTRUDED 40.0
40 #define MIN_EXTRUSION_MESH_RESOLUTION 16
41 #define MAX_EXTRUSION_MESH_RESOLUTION 512
43 static scene::IMesh *createExtrusionMesh(int resolution_x, int resolution_y)
47 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
48 video::SColor c(255,255,255,255);
49 v3f scale(1.0, 1.0, 0.1);
53 video::S3DVertex vertices[8] = {
55 video::S3DVertex(-r,+r,-r, 0,0,-1, c, 0,0),
56 video::S3DVertex(+r,+r,-r, 0,0,-1, c, 1,0),
57 video::S3DVertex(+r,-r,-r, 0,0,-1, c, 1,1),
58 video::S3DVertex(-r,-r,-r, 0,0,-1, c, 0,1),
60 video::S3DVertex(-r,+r,+r, 0,0,+1, c, 0,0),
61 video::S3DVertex(-r,-r,+r, 0,0,+1, c, 0,1),
62 video::S3DVertex(+r,-r,+r, 0,0,+1, c, 1,1),
63 video::S3DVertex(+r,+r,+r, 0,0,+1, c, 1,0),
65 u16 indices[12] = {0,1,2,2,3,0,4,5,6,6,7,4};
66 buf->append(vertices, 8, indices, 12);
69 f32 pixelsize_x = 1 / (f32) resolution_x;
70 f32 pixelsize_y = 1 / (f32) resolution_y;
72 for (int i = 0; i < resolution_x; ++i) {
73 f32 pixelpos_x = i * pixelsize_x - 0.5;
75 f32 x1 = pixelpos_x + pixelsize_x;
76 f32 tex0 = (i + 0.1) * pixelsize_x;
77 f32 tex1 = (i + 0.9) * pixelsize_x;
78 video::S3DVertex vertices[8] = {
80 video::S3DVertex(x0,-r,-r, -1,0,0, c, tex0,1),
81 video::S3DVertex(x0,-r,+r, -1,0,0, c, tex1,1),
82 video::S3DVertex(x0,+r,+r, -1,0,0, c, tex1,0),
83 video::S3DVertex(x0,+r,-r, -1,0,0, c, tex0,0),
85 video::S3DVertex(x1,-r,-r, +1,0,0, c, tex0,1),
86 video::S3DVertex(x1,+r,-r, +1,0,0, c, tex0,0),
87 video::S3DVertex(x1,+r,+r, +1,0,0, c, tex1,0),
88 video::S3DVertex(x1,-r,+r, +1,0,0, c, tex1,1),
90 u16 indices[12] = {0,1,2,2,3,0,4,5,6,6,7,4};
91 buf->append(vertices, 8, indices, 12);
93 for (int i = 0; i < resolution_y; ++i) {
94 f32 pixelpos_y = i * pixelsize_y - 0.5;
95 f32 y0 = -pixelpos_y - pixelsize_y;
97 f32 tex0 = (i + 0.1) * pixelsize_y;
98 f32 tex1 = (i + 0.9) * pixelsize_y;
99 video::S3DVertex vertices[8] = {
101 video::S3DVertex(-r,y0,-r, 0,-1,0, c, 0,tex0),
102 video::S3DVertex(+r,y0,-r, 0,-1,0, c, 1,tex0),
103 video::S3DVertex(+r,y0,+r, 0,-1,0, c, 1,tex1),
104 video::S3DVertex(-r,y0,+r, 0,-1,0, c, 0,tex1),
106 video::S3DVertex(-r,y1,-r, 0,+1,0, c, 0,tex0),
107 video::S3DVertex(-r,y1,+r, 0,+1,0, c, 0,tex1),
108 video::S3DVertex(+r,y1,+r, 0,+1,0, c, 1,tex1),
109 video::S3DVertex(+r,y1,-r, 0,+1,0, c, 1,tex0),
111 u16 indices[12] = {0,1,2,2,3,0,4,5,6,6,7,4};
112 buf->append(vertices, 8, indices, 12);
115 // Create mesh object
116 scene::SMesh *mesh = new scene::SMesh();
117 mesh->addMeshBuffer(buf);
119 scaleMesh(mesh, scale); // also recalculates bounding box
124 Caches extrusion meshes so that only one of them per resolution
125 is needed. Also caches one cube (for convenience).
127 E.g. there is a single extrusion mesh that is used for all
128 16x16 px images, another for all 256x256 px images, and so on.
130 WARNING: Not thread safe. This should not be a problem since
131 rendering related classes (such as WieldMeshSceneNode) will be
132 used from the rendering thread only.
134 class ExtrusionMeshCache: public IReferenceCounted
140 for (int resolution = MIN_EXTRUSION_MESH_RESOLUTION;
141 resolution <= MAX_EXTRUSION_MESH_RESOLUTION;
143 m_extrusion_meshes[resolution] =
144 createExtrusionMesh(resolution, resolution);
146 m_cube = createCubeMesh(v3f(1.0, 1.0, 1.0));
149 virtual ~ExtrusionMeshCache()
151 for (auto &extrusion_meshe : m_extrusion_meshes) {
152 extrusion_meshe.second->drop();
156 // Get closest extrusion mesh for given image dimensions
157 // Caller must drop the returned pointer
158 scene::IMesh* create(core::dimension2d<u32> dim)
160 // handle non-power of two textures inefficiently without cache
161 if (!is_power_of_two(dim.Width) || !is_power_of_two(dim.Height)) {
162 return createExtrusionMesh(dim.Width, dim.Height);
165 int maxdim = MYMAX(dim.Width, dim.Height);
167 std::map<int, scene::IMesh*>::iterator
168 it = m_extrusion_meshes.lower_bound(maxdim);
170 if (it == m_extrusion_meshes.end()) {
171 // no viable resolution found; use largest one
172 it = m_extrusion_meshes.find(MAX_EXTRUSION_MESH_RESOLUTION);
173 sanity_check(it != m_extrusion_meshes.end());
176 scene::IMesh *mesh = it->second;
180 // Returns a 1x1x1 cube mesh with one meshbuffer (material) per face
181 // Caller must drop the returned pointer
182 scene::IMesh* createCube()
189 std::map<int, scene::IMesh*> m_extrusion_meshes;
190 scene::IMesh *m_cube;
193 ExtrusionMeshCache *g_extrusion_mesh_cache = NULL;
196 WieldMeshSceneNode::WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id, bool lighting):
197 scene::ISceneNode(mgr->getRootSceneNode(), mgr, id),
198 m_material_type(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF),
201 m_enable_shaders = g_settings->getBool("enable_shaders");
202 m_anisotropic_filter = g_settings->getBool("anisotropic_filter");
203 m_bilinear_filter = g_settings->getBool("bilinear_filter");
204 m_trilinear_filter = g_settings->getBool("trilinear_filter");
206 // If this is the first wield mesh scene node, create a cache
207 // for extrusion meshes (and a cube mesh), otherwise reuse it
208 if (!g_extrusion_mesh_cache)
209 g_extrusion_mesh_cache = new ExtrusionMeshCache();
211 g_extrusion_mesh_cache->grab();
213 // Disable bounding box culling for this scene node
214 // since we won't calculate the bounding box.
215 setAutomaticCulling(scene::EAC_OFF);
217 // Create the child scene node
218 scene::IMesh *dummymesh = g_extrusion_mesh_cache->createCube();
219 m_meshnode = SceneManager->addMeshSceneNode(dummymesh, this, -1);
220 m_meshnode->setReadOnlyMaterials(false);
221 m_meshnode->setVisible(false);
222 dummymesh->drop(); // m_meshnode grabbed it
225 WieldMeshSceneNode::~WieldMeshSceneNode()
227 sanity_check(g_extrusion_mesh_cache);
228 if (g_extrusion_mesh_cache->drop())
229 g_extrusion_mesh_cache = nullptr;
232 void WieldMeshSceneNode::setCube(const ContentFeatures &f,
235 scene::IMesh *cubemesh = g_extrusion_mesh_cache->createCube();
236 scene::SMesh *copy = cloneMesh(cubemesh);
238 postProcessNodeMesh(copy, f, false, true, &m_material_type, &m_colors, true);
241 m_meshnode->setScale(wield_scale * WIELD_SCALE_FACTOR);
244 void WieldMeshSceneNode::setExtruded(const std::string &imagename,
245 const std::string &overlay_name, v3f wield_scale, ITextureSource *tsrc,
248 video::ITexture *texture = tsrc->getTexture(imagename);
250 changeToMesh(nullptr);
253 video::ITexture *overlay_texture =
254 overlay_name.empty() ? NULL : tsrc->getTexture(overlay_name);
256 core::dimension2d<u32> dim = texture->getSize();
257 // Detect animation texture and pull off top frame instead of using entire thing
258 if (num_frames > 1) {
259 u32 frame_height = dim.Height / num_frames;
260 dim = core::dimension2d<u32>(dim.Width, frame_height);
262 scene::IMesh *original = g_extrusion_mesh_cache->create(dim);
263 scene::SMesh *mesh = cloneMesh(original);
266 mesh->getMeshBuffer(0)->getMaterial().setTexture(0,
267 tsrc->getTexture(imagename));
268 if (overlay_texture) {
269 scene::IMeshBuffer *copy = cloneMeshBuffer(mesh->getMeshBuffer(0));
270 copy->getMaterial().setTexture(0, overlay_texture);
271 mesh->addMeshBuffer(copy);
277 m_meshnode->setScale(wield_scale * WIELD_SCALE_FACTOR_EXTRUDED);
279 // Customize materials
280 for (u32 layer = 0; layer < m_meshnode->getMaterialCount(); layer++) {
281 video::SMaterial &material = m_meshnode->getMaterial(layer);
282 material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
283 material.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
284 material.MaterialType = m_material_type;
285 material.MaterialTypeParam = 0.5f;
286 material.setFlag(video::EMF_BACK_FACE_CULLING, true);
287 // Enable bi/trilinear filtering only for high resolution textures
288 if (dim.Width > 32) {
289 material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter);
290 material.setFlag(video::EMF_TRILINEAR_FILTER, m_trilinear_filter);
292 material.setFlag(video::EMF_BILINEAR_FILTER, false);
293 material.setFlag(video::EMF_TRILINEAR_FILTER, false);
295 material.setFlag(video::EMF_ANISOTROPIC_FILTER, m_anisotropic_filter);
296 // mipmaps cause "thin black line" artifacts
297 material.setFlag(video::EMF_USE_MIP_MAPS, false);
298 if (m_enable_shaders) {
299 material.setTexture(2, tsrc->getShaderFlagsTexture(false));
304 static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n,
305 std::vector<ItemPartColor> *colors, const ContentFeatures &f)
307 MeshMakeData mesh_make_data(client, false);
308 MeshCollector collector;
309 mesh_make_data.setSmoothLighting(false);
310 MapblockMeshGenerator gen(&mesh_make_data, &collector);
314 } else if (f.param_type_2 == CPT2_WALLMOUNTED ||
315 f.param_type_2 == CPT2_COLORED_WALLMOUNTED) {
316 if (f.drawtype == NDT_TORCHLIKE ||
317 f.drawtype == NDT_SIGNLIKE ||
318 f.drawtype == NDT_NODEBOX ||
319 f.drawtype == NDT_MESH) {
322 } else if (f.drawtype == NDT_SIGNLIKE || f.drawtype == NDT_TORCHLIKE) {
325 gen.renderSingle(n.getContent(), n.getParam2());
328 scene::SMesh *mesh = new scene::SMesh();
329 for (auto &prebuffers : collector.prebuffers)
330 for (PreMeshBuffer &p : prebuffers) {
331 if (p.layer.material_flags & MATERIAL_FLAG_ANIMATION) {
332 const FrameSpec &frame = (*p.layer.frames)[0];
333 p.layer.texture = frame.texture;
334 p.layer.normal_texture = frame.normal_texture;
336 for (video::S3DVertex &v : p.vertices) {
337 v.Color.setAlpha(255);
339 scene::SMeshBuffer *buf = new scene::SMeshBuffer();
340 buf->Material.setTexture(0, p.layer.texture);
341 p.layer.applyMaterialOptions(buf->Material);
342 mesh->addMeshBuffer(buf);
343 buf->append(&p.vertices[0], p.vertices.size(),
344 &p.indices[0], p.indices.size());
347 ItemPartColor(p.layer.has_color, p.layer.color));
352 void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client, bool check_wield_image)
354 ITextureSource *tsrc = client->getTextureSource();
355 IItemDefManager *idef = client->getItemDefManager();
356 IShaderSource *shdrsrc = client->getShaderSource();
357 const NodeDefManager *ndef = client->getNodeDefManager();
358 const ItemDefinition &def = item.getDefinition(idef);
359 const ContentFeatures &f = ndef->get(def.name);
360 content_t id = ndef->getId(def.name);
362 scene::SMesh *mesh = nullptr;
364 if (m_enable_shaders) {
365 u32 shader_id = shdrsrc->getShader("object_shader", TILE_MATERIAL_BASIC, NDT_NORMAL);
366 m_material_type = shdrsrc->getShaderInfo(shader_id).material;
371 m_base_color = idef->getItemstackColor(item, client);
373 // If wield_image needs to be checked and is defined, it overrides everything else
374 if (!def.wield_image.empty() && check_wield_image) {
375 setExtruded(def.wield_image, def.wield_overlay, def.wield_scale, tsrc,
377 m_colors.emplace_back();
378 // overlay is white, if present
379 m_colors.emplace_back(true, video::SColor(0xFFFFFFFF));
384 // See also CItemDefManager::createClientCached()
385 if (def.type == ITEM_NODE) {
386 bool cull_backface = f.needsBackfaceCulling();
388 // Select rendering method
389 switch (f.drawtype) {
391 setExtruded("no_texture_airlike.png", "",
392 v3f(1.0, 1.0, 1.0), tsrc, 1);
398 case NDT_FLOWINGLIQUID: {
399 v3f wscale = def.wield_scale;
400 if (f.drawtype == NDT_FLOWINGLIQUID)
402 setExtruded(tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
403 tsrc->getTextureName(f.tiles[0].layers[1].texture_id),
405 f.tiles[0].layers[0].animation_frame_count);
407 const TileLayer &l0 = f.tiles[0].layers[0];
408 m_colors.emplace_back(l0.has_color, l0.color);
409 const TileLayer &l1 = f.tiles[0].layers[1];
410 m_colors.emplace_back(l1.has_color, l1.color);
413 case NDT_PLANTLIKE_ROOTED: {
414 setExtruded(tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id),
415 "", def.wield_scale, tsrc,
416 f.special_tiles[0].layers[0].animation_frame_count);
418 const TileLayer &l0 = f.special_tiles[0].layers[0];
419 m_colors.emplace_back(l0.has_color, l0.color);
425 setCube(f, def.wield_scale);
428 // Render non-trivial drawtypes like the actual node
430 n.setParam2(def.place_param2);
432 mesh = createSpecialNodeMesh(client, n, &m_colors, f);
435 m_meshnode->setScale(
436 def.wield_scale * WIELD_SCALE_FACTOR
437 / (BS * f.visual_scale));
442 u32 material_count = m_meshnode->getMaterialCount();
443 for (u32 i = 0; i < material_count; ++i) {
444 video::SMaterial &material = m_meshnode->getMaterial(i);
445 material.MaterialType = m_material_type;
446 material.MaterialTypeParam = 0.5f;
447 material.setFlag(video::EMF_BACK_FACE_CULLING, cull_backface);
448 material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter);
449 material.setFlag(video::EMF_TRILINEAR_FILTER, m_trilinear_filter);
452 } else if (!def.inventory_image.empty()) {
453 setExtruded(def.inventory_image, def.inventory_overlay, def.wield_scale,
455 m_colors.emplace_back();
456 // overlay is white, if present
457 m_colors.emplace_back(true, video::SColor(0xFFFFFFFF));
461 // no wield mesh found
462 changeToMesh(nullptr);
465 void WieldMeshSceneNode::setColor(video::SColor c)
468 scene::IMesh *mesh = m_meshnode->getMesh();
473 u8 green = c.getGreen();
474 u8 blue = c.getBlue();
475 u32 mc = mesh->getMeshBufferCount();
476 for (u32 j = 0; j < mc; j++) {
477 video::SColor bc(m_base_color);
478 if ((m_colors.size() > j) && (m_colors[j].override_base))
479 bc = m_colors[j].color;
480 video::SColor buffercolor(255,
481 bc.getRed() * red / 255,
482 bc.getGreen() * green / 255,
483 bc.getBlue() * blue / 255);
484 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
486 if (m_enable_shaders)
487 setMeshBufferColor(buf, buffercolor);
489 colorizeMeshBuffer(buf, &buffercolor);
493 void WieldMeshSceneNode::setNodeLightColor(video::SColor color)
498 if (m_enable_shaders) {
499 for (u32 i = 0; i < m_meshnode->getMaterialCount(); ++i) {
500 video::SMaterial &material = m_meshnode->getMaterial(i);
501 material.EmissiveColor = color;
508 void WieldMeshSceneNode::render()
510 // note: if this method is changed to actually do something,
511 // you probably should implement OnRegisterSceneNode as well
514 void WieldMeshSceneNode::changeToMesh(scene::IMesh *mesh)
517 scene::IMesh *dummymesh = g_extrusion_mesh_cache->createCube();
518 m_meshnode->setVisible(false);
519 m_meshnode->setMesh(dummymesh);
520 dummymesh->drop(); // m_meshnode grabbed it
522 m_meshnode->setMesh(mesh);
525 m_meshnode->setMaterialFlag(video::EMF_LIGHTING, m_lighting);
526 // need to normalize normals when lighting is enabled (because of setScale())
527 m_meshnode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, m_lighting);
528 m_meshnode->setVisible(true);
531 void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
533 ITextureSource *tsrc = client->getTextureSource();
534 IItemDefManager *idef = client->getItemDefManager();
535 const NodeDefManager *ndef = client->getNodeDefManager();
536 const ItemDefinition &def = item.getDefinition(idef);
537 const ContentFeatures &f = ndef->get(def.name);
538 content_t id = ndef->getId(def.name);
540 FATAL_ERROR_IF(!g_extrusion_mesh_cache, "Extrusion mesh cache is not yet initialized");
542 scene::SMesh *mesh = nullptr;
544 // Shading is on by default
545 result->needs_shading = true;
547 bool cull_backface = f.needsBackfaceCulling();
549 // If inventory_image is defined, it overrides everything else
550 if (!def.inventory_image.empty()) {
551 mesh = getExtrudedMesh(tsrc, def.inventory_image,
552 def.inventory_overlay);
553 result->buffer_colors.emplace_back();
554 // overlay is white, if present
555 result->buffer_colors.emplace_back(true, video::SColor(0xFFFFFFFF));
556 // Items with inventory images do not need shading
557 result->needs_shading = false;
558 } else if (def.type == ITEM_NODE && f.drawtype == NDT_AIRLIKE) {
559 // Fallback image for airlike node
560 mesh = getExtrudedMesh(tsrc, "no_texture_airlike.png",
561 def.inventory_overlay);
562 result->needs_shading = false;
563 } else if (def.type == ITEM_NODE) {
564 switch (f.drawtype) {
568 case NDT_FLOWINGLIQUID: {
569 scene::IMesh *cube = g_extrusion_mesh_cache->createCube();
570 mesh = cloneMesh(cube);
572 if (f.drawtype == NDT_FLOWINGLIQUID) {
573 scaleMesh(mesh, v3f(1.2, 0.03, 1.2));
574 translateMesh(mesh, v3f(0, -0.57, 0));
576 scaleMesh(mesh, v3f(1.2, 1.2, 1.2));
578 postProcessNodeMesh(mesh, f, false, false, nullptr,
579 &result->buffer_colors, true);
580 if (f.drawtype == NDT_ALLFACES)
581 scaleMesh(mesh, v3f(f.visual_scale));
584 case NDT_PLANTLIKE: {
585 mesh = getExtrudedMesh(tsrc,
586 tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
587 tsrc->getTextureName(f.tiles[0].layers[1].texture_id));
589 const TileLayer &l0 = f.tiles[0].layers[0];
590 result->buffer_colors.emplace_back(l0.has_color, l0.color);
591 const TileLayer &l1 = f.tiles[0].layers[1];
592 result->buffer_colors.emplace_back(l1.has_color, l1.color);
595 case NDT_PLANTLIKE_ROOTED: {
596 mesh = getExtrudedMesh(tsrc,
597 tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id), "");
599 const TileLayer &l0 = f.special_tiles[0].layers[0];
600 result->buffer_colors.emplace_back(l0.has_color, l0.color);
604 // Render non-trivial drawtypes like the actual node
606 n.setParam2(def.place_param2);
608 mesh = createSpecialNodeMesh(client, n, &result->buffer_colors, f);
609 scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
614 u32 mc = mesh->getMeshBufferCount();
615 for (u32 i = 0; i < mc; ++i) {
616 scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
617 video::SMaterial &material = buf->getMaterial();
618 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
619 material.MaterialTypeParam = 0.5f;
620 material.setFlag(video::EMF_BILINEAR_FILTER, false);
621 material.setFlag(video::EMF_TRILINEAR_FILTER, false);
622 material.setFlag(video::EMF_BACK_FACE_CULLING, cull_backface);
623 material.setFlag(video::EMF_LIGHTING, false);
626 rotateMeshXZby(mesh, -45);
627 rotateMeshYZby(mesh, -30);
634 scene::SMesh *getExtrudedMesh(ITextureSource *tsrc,
635 const std::string &imagename, const std::string &overlay_name)
638 video::ITexture *texture = tsrc->getTextureForMesh(imagename);
642 video::ITexture *overlay_texture =
643 (overlay_name.empty()) ? NULL : tsrc->getTexture(overlay_name);
646 core::dimension2d<u32> dim = texture->getSize();
647 scene::IMesh *original = g_extrusion_mesh_cache->create(dim);
648 scene::SMesh *mesh = cloneMesh(original);
652 mesh->getMeshBuffer(0)->getMaterial().setTexture(0,
653 tsrc->getTexture(imagename));
654 if (overlay_texture) {
655 scene::IMeshBuffer *copy = cloneMeshBuffer(mesh->getMeshBuffer(0));
656 copy->getMaterial().setTexture(0, overlay_texture);
657 mesh->addMeshBuffer(copy);
660 // Customize materials
661 for (u32 layer = 0; layer < mesh->getMeshBufferCount(); layer++) {
662 video::SMaterial &material = mesh->getMeshBuffer(layer)->getMaterial();
663 material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
664 material.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
665 material.setFlag(video::EMF_BILINEAR_FILTER, false);
666 material.setFlag(video::EMF_TRILINEAR_FILTER, false);
667 material.setFlag(video::EMF_BACK_FACE_CULLING, true);
668 material.setFlag(video::EMF_LIGHTING, false);
669 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
670 material.MaterialTypeParam = 0.5f;
672 scaleMesh(mesh, v3f(2.0, 2.0, 2.0));
677 void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f,
678 bool use_shaders, bool set_material, const video::E_MATERIAL_TYPE *mattype,
679 std::vector<ItemPartColor> *colors, bool apply_scale)
681 u32 mc = mesh->getMeshBufferCount();
682 // Allocate colors for existing buffers
684 for (u32 i = 0; i < mc; ++i)
685 colors->push_back(ItemPartColor());
687 for (u32 i = 0; i < mc; ++i) {
688 const TileSpec *tile = &(f.tiles[i]);
689 scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
690 for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
691 const TileLayer *layer = &tile->layers[layernum];
692 if (layer->texture_id == 0)
695 scene::IMeshBuffer *copy = cloneMeshBuffer(buf);
696 copy->getMaterial() = buf->getMaterial();
697 mesh->addMeshBuffer(copy);
701 ItemPartColor(layer->has_color, layer->color));
703 (*colors)[i] = ItemPartColor(layer->has_color, layer->color);
705 video::SMaterial &material = buf->getMaterial();
707 layer->applyMaterialOptions(material);
709 material.MaterialType = *mattype;
711 if (layer->animation_frame_count > 1) {
712 const FrameSpec &animation_frame = (*layer->frames)[0];
713 material.setTexture(0, animation_frame.texture);
715 material.setTexture(0, layer->texture);
718 if (layer->normal_texture) {
719 if (layer->animation_frame_count > 1) {
720 const FrameSpec &animation_frame = (*layer->frames)[0];
721 material.setTexture(1, animation_frame.normal_texture);
723 material.setTexture(1, layer->normal_texture);
725 material.setTexture(2, layer->flags_texture);
727 if (apply_scale && tile->world_aligned) {
728 u32 n = buf->getVertexCount();
729 for (u32 k = 0; k != n; ++k)
730 buf->getTCoords(k) /= layer->scale;