51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "main.h"
#include "settings.h"
#include "wieldmesh.h"
#include "inventory.h"
#include "nodedef.h"
#include "mesh.h"
#include "mapblock_mesh.h"
-#include "tile.h"
+#include "client/tile.h"
#include "log.h"
#include "util/numeric.h"
#include <map>
if (it == m_extrusion_meshes.end()) {
// no viable resolution found; use largest one
it = m_extrusion_meshes.find(MAX_EXTRUSION_MESH_RESOLUTION);
- assert(it != m_extrusion_meshes.end());
+ sanity_check(it != m_extrusion_meshes.end());
}
scene::IMesh *mesh = it->second;
WieldMeshSceneNode::~WieldMeshSceneNode()
{
- assert(g_extrusion_mesh_cache);
+ sanity_check(g_extrusion_mesh_cache);
if (g_extrusion_mesh_cache->drop())
g_extrusion_mesh_cache = NULL;
}
}
void WieldMeshSceneNode::setExtruded(const std::string &imagename,
- v3f wield_scale, ITextureSource *tsrc)
+ v3f wield_scale, ITextureSource *tsrc, u8 num_frames)
{
video::ITexture *texture = tsrc->getTexture(imagename);
if (!texture) {
changeToMesh(NULL);
return;
}
+
core::dimension2d<u32> dim = texture->getSize();
+ // Detect animation texture and pull off top frame instead of using entire thing
+ if (num_frames > 1) {
+ u32 frame_height = dim.Height / num_frames;
+ dim = core::dimension2d<u32>(dim.Width, frame_height);
+ }
scene::IMesh *mesh = g_extrusion_mesh_cache->create(dim);
changeToMesh(mesh);
mesh->drop();
// Customize material
video::SMaterial &material = m_meshnode->getMaterial(0);
- material.setTexture(0, texture);
+ material.setTexture(0, tsrc->getTextureForMesh(imagename));
material.MaterialType = m_material_type;
material.setFlag(video::EMF_BACK_FACE_CULLING, true);
// Enable bi/trilinear filtering only for high resolution textures
// If wield_image is defined, it overrides everything else
if (def.wield_image != "") {
- setExtruded(def.wield_image, def.wield_scale, tsrc);
+ setExtruded(def.wield_image, def.wield_scale, tsrc, 1);
return;
}
// Handle nodes
} else if (f.drawtype == NDT_AIRLIKE) {
changeToMesh(NULL);
} else if (f.drawtype == NDT_PLANTLIKE) {
- setExtruded(tsrc->getTextureName(f.tiles[0].texture_id), def.wield_scale, tsrc);
+ setExtruded(tsrc->getTextureName(f.tiles[0].texture_id), def.wield_scale, tsrc, f.tiles[0].animation_frame_count);
} else if (f.drawtype == NDT_NORMAL || f.drawtype == NDT_ALLFACES) {
setCube(f.tiles, def.wield_scale, tsrc);
} else {
def.wield_scale * WIELD_SCALE_FACTOR
/ (BS * f.visual_scale));
}
- for (u32 i = 0; i < m_meshnode->getMaterialCount(); ++i) {
- assert(i < 6);
+ u32 material_count = m_meshnode->getMaterialCount();
+ if (material_count > 6) {
+ errorstream << "WieldMeshSceneNode::setItem: Invalid material "
+ "count " << material_count << ", truncating to 6" << std::endl;
+ material_count = 6;
+ }
+ for (u32 i = 0; i < material_count; ++i) {
video::SMaterial &material = m_meshnode->getMaterial(i);
material.setFlag(video::EMF_BACK_FACE_CULLING, true);
material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter);
return;
}
else if (def.inventory_image != "") {
- setExtruded(def.inventory_image, def.wield_scale, tsrc);
+ setExtruded(def.inventory_image, def.wield_scale, tsrc, 1);
return;
}