diff options
author | RealBadAngel <maciej.kasatkin@o2.pl> | 2014-10-15 04:13:53 +0200 |
---|---|---|
committer | RealBadAngel <maciej.kasatkin@o2.pl> | 2014-10-18 16:42:23 +0200 |
commit | 0066bd77d25793b76fdaa9a62755cca934f0121d (patch) | |
tree | 61760994616113cd307d6dc6c2980f5f547fa78f /src/nodedef.cpp | |
parent | d1ccc64e1ecfd00df36d2b8a8b3420b70434fefd (diff) | |
download | minetest-0066bd77d25793b76fdaa9a62755cca934f0121d.tar.gz minetest-0066bd77d25793b76fdaa9a62755cca934f0121d.tar.bz2 minetest-0066bd77d25793b76fdaa9a62755cca934f0121d.zip |
Add meshnode drawtype.
Diffstat (limited to 'src/nodedef.cpp')
-rw-r--r-- | src/nodedef.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/nodedef.cpp b/src/nodedef.cpp index f1a7ad694..ef61d0722 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "itemdef.h" #ifndef SERVER #include "tile.h" +#include "mesh.h" #endif #include "log.h" #include "settings.h" @@ -31,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/serialize.h" #include "exceptions.h" #include "debug.h" +#include "gamedef.h" /* NodeBox @@ -195,6 +197,11 @@ void ContentFeatures::reset() // Unknown nodes can be dug groups["dig_immediate"] = 2; drawtype = NDT_NORMAL; + mesh = ""; +#ifndef SERVER + for(u32 i = 0; i < 24; i++) + mesh_ptr[i] = NULL; +#endif visual_scale = 1.0; for(u32 i = 0; i < 6; i++) tiledef[i] = TileDef(); @@ -295,6 +302,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) writeU8(os, waving); // Stuff below should be moved to correct place in a version that otherwise changes // the protocol version + os<<serializeString(mesh); } void ContentFeatures::deSerialize(std::istream &is) @@ -363,6 +371,7 @@ void ContentFeatures::deSerialize(std::istream &is) try{ // Stuff below should be moved to correct place in a version that // otherwise changes the protocol version + mesh = deSerializeString(is); }catch(SerializationError &e) {}; } @@ -386,7 +395,7 @@ public: virtual content_t set(const std::string &name, const ContentFeatures &def); virtual content_t allocateDummy(const std::string &name); virtual void updateAliases(IItemDefManager *idef); - virtual void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc); + virtual void updateTextures(IGameDef *gamedef); void serialize(std::ostream &os, u16 protocol_version); void deSerialize(std::istream &is); @@ -669,11 +678,14 @@ void CNodeDefManager::updateAliases(IItemDefManager *idef) } -void CNodeDefManager::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc) +void CNodeDefManager::updateTextures(IGameDef *gamedef) { #ifndef SERVER infostream << "CNodeDefManager::updateTextures(): Updating " "textures in node definitions" << std::endl; + + ITextureSource *tsrc = gamedef->tsrc(); + IShaderSource *shdsrc = gamedef->getShaderSource(); bool new_style_water = g_settings->getBool("new_style_water"); bool new_style_leaves = g_settings->getBool("new_style_leaves"); @@ -771,6 +783,10 @@ void CNodeDefManager::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc f->backface_culling = false; f->solidness = 0; break; + case NDT_MESH: + f->solidness = 0; + f->backface_culling = false; + break; case NDT_TORCHLIKE: case NDT_SIGNLIKE: case NDT_FENCELIKE: @@ -810,6 +826,34 @@ void CNodeDefManager::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc tile_shader[j], use_normal_texture, f->tiledef_special[j].backface_culling, f->alpha, material_type); } + + // Meshnode drawtype + // 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]); + } + + //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)) && + (!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)); + recalculateBoundingBox(f->mesh_ptr[0]); + } + + //Cache 6dfacedir rotated clones of meshes + if (f->mesh_ptr[0] && (f->param_type_2 == CPT2_FACEDIR)) { + for (u16 j = 1; j < 24; j++) { + f->mesh_ptr[j] = cloneMesh(f->mesh_ptr[0]); + rotateMeshBy6dFacedir(f->mesh_ptr[j], j); + recalculateBoundingBox(f->mesh_ptr[j]); + } + } } #endif } |