From d221917170c2bb43c66e5e09f2a43350cf28d71b Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Tue, 21 Oct 2014 05:12:15 +0200 Subject: Recalculate normals for cached meshes. Check if mesh is here before adding to meshcollector. Fix deleting the meshes. --- src/nodedef.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/nodedef.cpp') diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 2f95b68f9..cf30d76b3 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef SERVER #include "tile.h" #include "mesh.h" +#include #endif #include "log.h" #include "settings.h" @@ -171,12 +172,6 @@ ContentFeatures::ContentFeatures() ContentFeatures::~ContentFeatures() { -#ifndef SERVER - for (u32 i = 0; i < 24; i++) { - if (mesh_ptr[i]) - mesh_ptr[i]->drop(); - } -#endif } void ContentFeatures::reset() @@ -446,6 +441,15 @@ CNodeDefManager::CNodeDefManager() CNodeDefManager::~CNodeDefManager() { +#ifndef SERVER + for (u32 i = 0; i < m_content_features.size(); i++) { + ContentFeatures *f = &m_content_features[i]; + for (u32 j = 0; j < 24; j++) { + if (f->mesh_ptr[j]) + f->mesh_ptr[j]->drop(); + } + } +#endif } @@ -695,6 +699,8 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef) ITextureSource *tsrc = gamedef->tsrc(); IShaderSource *shdsrc = gamedef->getShaderSource(); + scene::ISceneManager* smgr = gamedef->getSceneManager(); + scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator(); bool new_style_water = g_settings->getBool("new_style_water"); bool new_style_leaves = g_settings->getBool("new_style_leaves"); @@ -840,18 +846,23 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef) // Read the mesh and apply scale if ((f->drawtype == NDT_MESH) && (f->mesh != "")) { f->mesh_ptr[0] = gamedef->getMesh(f->mesh); - scaleMesh(f->mesh_ptr[0], v3f(f->visual_scale,f->visual_scale,f->visual_scale)); - recalculateBoundingBox(f->mesh_ptr[0]); + if (f->mesh_ptr[0]){ + v3f scale = v3f(1.0, 1.0, 1.0) * BS * f->visual_scale; + scaleMesh(f->mesh_ptr[0], scale); + recalculateBoundingBox(f->mesh_ptr[0]); + } } //Convert regular nodebox nodes to meshnodes //Change the drawtype and apply scale - if ((f->drawtype == NDT_NODEBOX) && - ((f->node_box.type == NODEBOX_REGULAR) || (f->node_box.type == NODEBOX_FIXED)) && + else if ((f->drawtype == NDT_NODEBOX) && + ((f->node_box.type == NODEBOX_REGULAR) || + (f->node_box.type == NODEBOX_FIXED)) && (!f->node_box.fixed.empty())) { f->drawtype = NDT_MESH; f->mesh_ptr[0] = convertNodeboxNodeToMesh(f); - scaleMesh(f->mesh_ptr[0], v3f(f->visual_scale,f->visual_scale,f->visual_scale)); + v3f scale = v3f(1.0, 1.0, 1.0) * f->visual_scale; + scaleMesh(f->mesh_ptr[0], scale); recalculateBoundingBox(f->mesh_ptr[0]); } @@ -861,6 +872,7 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef) f->mesh_ptr[j] = cloneMesh(f->mesh_ptr[0]); rotateMeshBy6dFacedir(f->mesh_ptr[j], j); recalculateBoundingBox(f->mesh_ptr[j]); + meshmanip->recalculateNormals(f->mesh_ptr[j], false, false); } } } -- cgit v1.2.3