mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add meshnode drawtype.
This commit is contained in:
parent
d1ccc64e1e
commit
0066bd77d2
11 changed files with 374 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue