From f9675bd2b4d48b9517cd4939a5cfe1ea9c775b6c Mon Sep 17 00:00:00 2001 From: MirceaKitsune Date: Wed, 24 Oct 2012 00:11:24 +0300 Subject: [PATCH] Add a subfolder for models and transfer models from server to client (obj, md2 and md3 are currently allowed) Get rid of the texture string and use the existing textures array. Segmented meshes have multiple materials, and this will allow us to texture each. Do not switch to this commit yet! If a texture string is left empty in LUA, don't modify that material. Useful so a script can change specific textures without affecting others --- src/client.cpp | 19 +++++++++++++++++++ src/content_cao.cpp | 30 ++++++++++++++++++++---------- src/object_properties.cpp | 4 ---- src/object_properties.h | 1 - src/scriptapi.cpp | 3 ++- src/server.cpp | 2 ++ 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index e47bce142..504297a6d 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -860,6 +860,25 @@ bool Client::loadMedia(const std::string &data, const std::string &filename) return true; } + const char *model_ext[] = { + ".b3d", ".md2", ".obj", + NULL + }; + name = removeStringEnd(filename, model_ext); + if(name != "") + { + verbosestream<<"Client: Storing model into Irrlicht: " + <<"file \""<getFileSystem(); + + // Create an irrlicht memory file + io::IReadFile *rfile = irrfs->createMemoryReadFile(*data_rw, data_rw.getSize(), filename.c_str(), true); + assert(rfile); + //rfile->drop(); + return true; + } + errorstream<<"Client: Don't know how to load file \"" <getSceneManager()->getVideoDriver(); - m_animated_meshnode->setMaterialTexture(0, driver->getTexture(m_prop.texture.c_str())); - - // Set material flags and texture - video::SMaterial& material = m_animated_meshnode->getMaterial(0); - material.setFlag(video::EMF_LIGHTING, false); - material.setFlag(video::EMF_BILINEAR_FILTER, false); + for (u32 i = 0; i < m_prop.textures.size(); ++i) + { + std::string texturestring = m_prop.textures[i]; + if(texturestring == "") + continue; // Empty texture string means don't modify that material + texturestring += mod; + video::IVideoDriver* driver = m_animated_meshnode->getSceneManager()->getVideoDriver(); + video::ITexture* texture = driver->getTexture(texturestring.c_str()); + if(!texture) + { + errorstream<<"GenericCAO::updateTextures(): Could not load texture "<setMaterialTexture(i, texture); + video::SMaterial& material = m_animated_meshnode->getMaterial(i); + material.setFlag(video::EMF_LIGHTING, false); + material.setFlag(video::EMF_BILINEAR_FILTER, false); + } } } if(m_meshnode) diff --git a/src/object_properties.cpp b/src/object_properties.cpp index 3a36addc7..c91384ada 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -31,7 +31,6 @@ ObjectProperties::ObjectProperties(): collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5), visual("sprite"), mesh(""), - texture(""), visual_size(1,1), spritediv(1,1), initial_sprite_basepos(0,0), @@ -51,7 +50,6 @@ std::string ObjectProperties::dump() os<<", collisionbox="< collisionbox; std::string visual; std::string mesh; - std::string texture; v2f visual_size; core::array textures; v2s16 spritediv; diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 7eda636e3..9293e2b65 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -938,7 +938,6 @@ static void read_object_properties(lua_State *L, int index, getstringfield(L, -1, "visual", prop->visual); getstringfield(L, -1, "mesh", prop->mesh); - getstringfield(L, -1, "texture", prop->texture); lua_getfield(L, -1, "visual_size"); if(lua_istable(L, -1)) @@ -6591,6 +6590,8 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id, lua_pop(L, 1); getstringfield(L, -1, "visual", prop->visual); + + getstringfield(L, -1, "mesh", prop->mesh); // Deprecated: read object properties directly read_object_properties(L, -1, prop); diff --git a/src/server.cpp b/src/server.cpp index 2da9cbe24..92fd567e5 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -4029,6 +4029,7 @@ void Server::fillMediaCache() paths.push_back(mod.path + DIR_DELIM + "textures"); paths.push_back(mod.path + DIR_DELIM + "sounds"); paths.push_back(mod.path + DIR_DELIM + "media"); + paths.push_back(mod.path + DIR_DELIM + "models"); } std::string path_all = "textures"; paths.push_back(path_all + DIR_DELIM + "all"); @@ -4054,6 +4055,7 @@ void Server::fillMediaCache() ".png", ".jpg", ".bmp", ".tga", ".pcx", ".ppm", ".psd", ".wal", ".rgb", ".ogg", + ".b3d", ".md2", ".obj", NULL }; if(removeStringEnd(filename, supported_ext) == ""){ -- 2.25.1